]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #808 from ArthurHoaro/demo-readme
authorArthurHoaro <arthur@hoa.ro>
Sat, 11 Mar 2017 19:32:35 +0000 (20:32 +0100)
committerGitHub <noreply@github.com>
Sat, 11 Mar 2017 19:32:35 +0000 (20:32 +0100)
Shaarli demo moved to shaarli.org

12 files changed:
CHANGELOG.md
application/NetscapeBookmarkUtils.php
application/Updater.php
composer.json
index.php
plugins/piwik/piwik.html [new file with mode: 0644]
plugins/piwik/piwik.php
tests/NetscapeBookmarkUtils/BookmarkImportTest.php
tests/Updater/UpdaterTest.php
tests/utils/config/configJson.json.php
tpl/default/linklist.html
tpl/default/page.header.html

index 1a87a8ca8ab712fa87ac75860228ca880f4d2b3e..44ac06ff093616f251ace6272698384df89ec8cc 100644 (file)
@@ -28,6 +28,7 @@ Theming:
 - Add OpenSearch to feed templates
 - Add `campaign_` to the URL cleanup pattern list
 - Add an AUTHORS file and Makefile target to list authors from Git commit data
+- Link imports are now logged in `data/` folder, and can be debug using `dev.debug=true` setting.
 
 ### Changed
 - Docker: enable nginx URL rewriting for the REST API
index e7148d005776c7c41df62e72e5cba237a6a6f753..ab346f81c2ada769d204ea79d8f5ed21efb90213 100644 (file)
@@ -1,7 +1,13 @@
 <?php
 
+use Psr\Log\LogLevel;
+use Shaarli\Config\ConfigManager;
+use Shaarli\NetscapeBookmarkParser\NetscapeBookmarkParser;
+use Katzgrau\KLogger\Logger;
+
 /**
  * Utilities to import and export bookmarks using the Netscape format
+ * TODO: Not static, use a container.
  */
 class NetscapeBookmarkUtils
 {
@@ -85,14 +91,14 @@ class NetscapeBookmarkUtils
     /**
      * Imports Web bookmarks from an uploaded Netscape bookmark dump
      *
-     * @param array  $post      Server $_POST parameters
-     * @param array  $files     Server $_FILES parameters
-     * @param LinkDB $linkDb    Loaded LinkDB instance
-     * @param string $pagecache Page cache
+     * @param array         $post      Server $_POST parameters
+     * @param array         $files     Server $_FILES parameters
+     * @param LinkDB        $linkDb    Loaded LinkDB instance
+     * @param ConfigManager $conf      instance
      *
      * @return string Summary of the bookmark import status
      */
-    public static function import($post, $files, $linkDb, $pagecache)
+    public static function import($post, $files, $linkDb, $conf)
     {
         $filename = $files['filetoupload']['name'];
         $filesize = $files['filetoupload']['size'];
@@ -119,10 +125,20 @@ class NetscapeBookmarkUtils
         $defaultPrivacy = 0;
 
         $parser = new NetscapeBookmarkParser(
-            true,                       // nested tag support
-            $defaultTags,               // additional user-specified tags
-            strval(1 - $defaultPrivacy) // defaultPub = 1 - defaultPrivacy
+            true,                           // nested tag support
+            $defaultTags,                   // additional user-specified tags
+            strval(1 - $defaultPrivacy),    // defaultPub = 1 - defaultPrivacy
+            $conf->get('resource.data_dir') // log path, will be overridden
+        );
+        $logger = new Logger(
+            $conf->get('resource.data_dir'),
+            ! $conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
+            [
+                'prefix' => 'import.',
+                'extension' => 'log',
+            ]
         );
+        $parser->setLogger($logger);
         $bookmarks = $parser->parseString($data);
 
         $importCount = 0;
@@ -179,7 +195,7 @@ class NetscapeBookmarkUtils
             $importCount++;
         }
 
-        $linkDb->save($pagecache);
+        $linkDb->save($conf->get('resource.page_cache'));
         return self::importStatus(
             $filename,
             $filesize,
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;
+    }
 }
 
 /**
index 57851e53e27fbab99fa5044de0d0bf0c389a30a6..792c43d31cabf74652e6aecb04c768b1cdcf23fd 100644 (file)
@@ -11,7 +11,7 @@
     "keywords": ["bookmark", "link", "share", "web"],
     "require": {
         "php": ">=5.5",
-        "shaarli/netscape-bookmark-parser": "1.*",
+        "shaarli/netscape-bookmark-parser": "^2.0",
         "erusev/parsedown": "1.6",
         "slim/slim": "^3.0",
         "pubsubhubbub/publisher": "dev-master"
index 3c2bb1d2829dee3a6a9d4e4b9edea6bacc5bd1ae..cc7f3ca3497feaf96288b61f718997eb0c3a09cf 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1528,7 +1528,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
             $_POST,
             $_FILES,
             $LINKSDB,
-            $conf->get('resource.page_cache')
+            $conf
         );
         echo '<script>alert("'.$status.'");document.location=\'?do='
              .Router::$PAGE_IMPORT .'\';</script>';
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 0ca07eacb7741e83aebb126e19502da62cbe5fee..5925a8e156865be6c3343ca0e6b937a08cb97cf0 100644 (file)
@@ -2,6 +2,7 @@
 
 require_once 'application/NetscapeBookmarkUtils.php';
 
+use Shaarli\Config\ConfigManager;
 
 /**
  * Utility function to load a file's metadata in a $_FILES-like array
@@ -42,6 +43,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
      */
     protected $pagecache = 'tests';
 
+    /**
+     * @var ConfigManager instance.
+     */
+    protected $conf;
+
     /**
      * @var string Save the current timezone.
      */
@@ -65,6 +71,8 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         // start with an empty datastore
         file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>');
         $this->linkDb = new LinkDB(self::$testDatastore, true, false);
+        $this->conf = new ConfigManager('tests/utils/config/configJson');
+        $this->conf->set('resource.page_cache', $this->pagecache);
     }
 
     public static function tearDownAfterClass()
@@ -81,7 +89,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File empty.htm (0 bytes) has an unknown file format.'
             .' Nothing was imported.',
-            NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL)
+            NetscapeBookmarkUtils::import(NULL, $files, NULL, $this->conf)
         );
         $this->assertEquals(0, count($this->linkDb));
     }
@@ -94,7 +102,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $files = file2array('no_doctype.htm');
         $this->assertEquals(
             'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.',
-            NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL)
+            NetscapeBookmarkUtils::import(NULL, $files, NULL, $this->conf)
         );
         $this->assertEquals(0, count($this->linkDb));
     }
@@ -108,7 +116,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File internet_explorer_encoding.htm (356 bytes) was successfully processed:'
             .' 1 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(1, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -137,7 +145,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_nested.htm (1337 bytes) was successfully processed:'
             .' 8 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(8, count($this->linkDb));
         $this->assertEquals(2, count_private($this->linkDb));
@@ -259,7 +267,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
         );
 
         $this->assertEquals(2, count($this->linkDb));
@@ -304,7 +312,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(1, count_private($this->linkDb));
@@ -348,7 +356,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -372,7 +380,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(2, count_private($this->linkDb));
@@ -398,7 +406,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(2, count_private($this->linkDb));
@@ -418,7 +426,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 2 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -444,7 +452,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -465,7 +473,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 2 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(2, count_private($this->linkDb));
@@ -489,7 +497,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -499,7 +507,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 0 links imported, 0 links overwritten, 2 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -518,7 +526,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -545,7 +553,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File netscape_basic.htm (482 bytes) was successfully processed:'
             .' 2 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(2, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
@@ -570,7 +578,7 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(
             'File same_date.htm (453 bytes) was successfully processed:'
             .' 3 links imported, 0 links overwritten, 0 links skipped.',
-            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
+            NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->conf)
         );
         $this->assertEquals(3, count($this->linkDb));
         $this->assertEquals(0, count_private($this->linkDb));
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 13d38c6680b4a4515192ee0045adcfea05c45b0e..9c9288f30cc696c38115dd1562a1770b3dfe8cb3 100644 (file)
@@ -24,7 +24,7 @@
     },
     "resource": {
         "datastore": "tests\/utils\/config\/datastore.php",
-        "data_dir": "tests\/utils\/config",
+        "data_dir": "sandbox/",
         "raintpl_tpl": "tpl/"
     },
     "plugins": {
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>