]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #779 from ArthurHoaro/feature/import-parser-logs
authorArthurHoaro <arthur@hoa.ro>
Sat, 11 Mar 2017 13:23:05 +0000 (14:23 +0100)
committerGitHub <noreply@github.com>
Sat, 11 Mar 2017 13:23:05 +0000 (14:23 +0100)
Link imports are now logged in `data/` folder, and can be debug using…

application/Updater.php
plugins/piwik/piwik.html [new file with mode: 0644]
plugins/piwik/piwik.php
tests/Updater/UpdaterTest.php
tpl/default/linklist.html
tpl/default/page.header.html

index 27cb2f0a43e29b2e4879d91cac672b4a16e3159f..fd7e2073089eaca16a51fee881a1a68b45cc05df 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 use Shaarli\Config\ConfigJson;
 use Shaarli\Config\ConfigPhp;
+use Shaarli\Config\ConfigManager;
 
 /**
  * Class Updater.
@@ -363,6 +364,22 @@ class Updater
 
         return true;
     }
+
+    /**
+     * Add 'http://' to Piwik URL the setting is set.
+     *
+     * @return bool true if the update is successful, false otherwise.
+     */
+    public function updateMethodPiwikUrl()
+    {
+        if (! $this->conf->exists('plugins.PIWIK_URL') || startsWith($this->conf->get('plugins.PIWIK_URL'), 'http')) {
+            return true;
+        }
+
+        $this->conf->set('plugins.PIWIK_URL', 'http://'. $this->conf->get('plugins.PIWIK_URL'));
+        $this->conf->write($this->isLoggedIn);
+        return true;
+    }
 }
 
 /**
diff --git a/plugins/piwik/piwik.html b/plugins/piwik/piwik.html
new file mode 100644 (file)
index 0000000..0881d7c
--- /dev/null
@@ -0,0 +1,15 @@
+<!-- Piwik -->
+<script type="text/javascript">
+  var _paq = _paq || [];
+  _paq.push(['trackPageView']);
+  _paq.push(['enableLinkTracking']);
+  (function() {
+    var u="%s/";
+    _paq.push(['setTrackerUrl', u+'piwik.php']);
+    _paq.push(['setSiteId', '%s']);
+    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
+  })();
+</script>
+<noscript><p><img src="%s/piwik.php?idsite=%s" style="border:0;" alt="" /></p></noscript>
+<!-- End Piwik Code -->
\ No newline at end of file
index 7c44909c6e47cf1223e3f26dfcbd6dd89a5bfc4d..4a2b48a121fcd4249fe2c257beb35fb28150d16e 100644 (file)
@@ -50,22 +50,13 @@ function hook_piwik_render_footer($data, $conf)
     }
 
     // Free elements at the end of the page.
-    $data['endofpage'][] = '<!-- Piwik -->' .
-'<script type="text/javascript">' .
-'  var _paq = _paq || [];' .
-'  _paq.push([\'trackPageView\']);' .
-'  _paq.push([\'enableLinkTracking\']);' .
-'  (function() {' .
-'    var u="//' . $piwikUrl . '/";' .
-'    _paq.push([\'setTrackerUrl\', u+\'piwik.php\']);' .
-'    _paq.push([\'setSiteId\', \'' . $piwikSiteid . '\']);' .
-'    var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0];' .
-'    g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'piwik.js\'; s.parentNode.insertBefore(g,s);' .
-'  })();' .
-'</script>' .
-'<noscript><p><img src="//' . $piwikUrl . '/piwik.php?idsite=' . $piwikSiteid . '" style="border:0;" alt="" /></p></noscript>' .
-'<!-- End Piwik Code -->';
+    $data['endofpage'][] = sprintf(
+        file_get_contents(PluginManager::$PLUGINS_PATH . '/piwik/piwik.html'),
+        $piwikUrl,
+        $piwikSiteid,
+        $piwikUrl,
+        $piwikSiteid
+    );
 
     return $data;
 }
-
index 448405a3fd5b4d34cb369575bc3b265eaade4f17..b522d616b4dc658ab72d285234f9e4354af58633 100644 (file)
@@ -574,4 +574,45 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $this->assertTrue($updater->updateMethodEscapeMarkdown());
         $this->assertFalse($this->conf->get('security.markdown_escape'));
     }
+
+    /**
+     * Test updateMethodPiwikUrl with valid data
+     */
+    public function testUpdatePiwikUrlValid()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $url = 'mypiwik.tld';
+        $this->conf->set('plugins.PIWIK_URL', $url);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodPiwikUrl());
+        $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL'));
+
+        // reload from file
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL'));
+    }
+
+    /**
+     * Test updateMethodPiwikUrl without setting
+     */
+    public function testUpdatePiwikUrlEmpty()
+    {
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodPiwikUrl());
+        $this->assertEmpty($this->conf->get('plugins.PIWIK_URL'));
+    }
+
+    /**
+     * Test updateMethodPiwikUrl: valid URL, nothing to do
+     */
+    public function testUpdatePiwikUrlNothingToDo()
+    {
+        $url = 'https://mypiwik.tld';
+        $this->conf->set('plugins.PIWIK_URL', $url);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodPiwikUrl());
+        $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL'));
+    }
 }
index 94370203bf2b2b8cf0fe014129569db4907b2008..57ef4567a8ee754c1f308c3b153e6d0188223b86 100644 (file)
@@ -34,7 +34,7 @@
                {if="!empty($search_tags)"}
                value="{$search_tags}"
                {/if}
-        autocomplete="off" data-multiple data-minChars="1"
+        autocomplete="off" data-multiple data-autofirst data-minChars="1"
         data-list="{loop="$tags"}{$key}, {/loop}"
         >
         <button type="submit" class="search-button"><i class="fa fa-search"></i></button>
index b76fc03e003a111221085b0440d2caf3cc809e2a..03ca6843e4a6c61984be516ca7b747421a6eae0b 100644 (file)
@@ -2,7 +2,7 @@
   <div class="pure-u-lg-0 pure-u-1">
     <div class="pure-menu">
       <a href="{$titleLink}" class="pure-menu-link">
-        <i class="fa fa-home"></i>
+        <img src="img/icon.png" width="16" height="16" class="head-logo" alt="logo" />
         {$shaarlititle}
       </a>
       <a href="#" class="menu-toggle" id="menu-toggle"><s class="bar"></s><s class="bar"></s></a>
                  {if="!empty($search_tags)"}
                  value="{$search_tags}"
                  {/if}
-          autocomplete="off" data-multiple data-minChars="1"
+          autocomplete="off" data-multiple data-autofirst data-minChars="1"
           data-list="{loop="$tags"}{$key}, {/loop}"
           >
           <button type="submit" class="search-button"><i class="fa fa-search"></i></button>