]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #662 from virtualtam/fix/feed/self-link
authorVirtualTam <virtualtam+github@flibidi.net>
Mon, 17 Oct 2016 15:58:39 +0000 (17:58 +0200)
committerGitHub <noreply@github.com>
Mon, 17 Oct 2016 15:58:39 +0000 (17:58 +0200)
Fix: return the proper value for the "self" feed attribute

17 files changed:
application/PageBuilder.php
application/PluginManager.php
index.php
plugins/demo_plugin/demo_plugin.php
plugins/readityourself/readityourself.php
plugins/wallabag/wallabag.php
tests/plugins/PluginReadityourselfTest.php
tests/plugins/PluginWallabagTest.php
tpl/daily.html
tpl/dailyrss.html
tpl/export.bookmarks.html
tpl/feed.atom.html
tpl/feed.rss.html
tpl/linklist.html
tpl/page.header.html
tpl/picwall.html
tpl/tagcloud.html

index 42932f32681a512f35de7c69ceb137c264f311b9..32c7f9f18b01ba131be61bb778dc3d7a9239b727 100644 (file)
@@ -77,9 +77,6 @@ class PageBuilder
         $this->tpl->assign('openshaarli', $this->conf->get('security.open_shaarli', false));
         $this->tpl->assign('showatom', $this->conf->get('feed.show_atom', false));
         $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
-        if (!empty($GLOBALS['plugin_errors'])) {
-            $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']);
-        }
         $this->tpl->assign('token', getToken($this->conf));
         // To be removed with a proper theme configuration.
         $this->tpl->assign('conf', $this->conf);
index 1e132a7f652c78aa077a86ed3c1013ad58b7c95b..59ece4fa9c735b8c2d150b939d48794fddeb2279 100644 (file)
@@ -24,6 +24,11 @@ class PluginManager
      */
     protected $conf;
 
+    /**
+     * @var array List of plugin errors.
+     */
+    protected $errors;
+
     /**
      * Plugins subdirectory.
      * @var string $PLUGINS_PATH
@@ -44,6 +49,7 @@ class PluginManager
     public function __construct(&$conf)
     {
         $this->conf = $conf;
+        $this->errors = array();
     }
 
     /**
@@ -106,6 +112,7 @@ class PluginManager
 
     /**
      * Load a single plugin from its files.
+     * Call the init function if it exists, and collect errors.
      * Add them in $loadedPlugins if successful.
      *
      * @param string $dir        plugin's directory.
@@ -128,6 +135,14 @@ class PluginManager
         $conf = $this->conf;
         include_once $pluginFilePath;
 
+        $initFunction = $pluginName . '_init';
+        if (function_exists($initFunction)) {
+            $errors = call_user_func($initFunction, $this->conf);
+            if (!empty($errors)) {
+                $this->errors = array_merge($this->errors, $errors);
+            }
+        }
+
         $this->loadedPlugins[] = $pluginName;
     }
 
@@ -195,6 +210,16 @@ class PluginManager
 
         return $metaData;
     }
+
+    /**
+     * Return the list of encountered errors.
+     *
+     * @return array List of errors (empty array if none exists).
+     */
+    public function getErrors()
+    {
+        return $this->errors;
+    }
 }
 
 /**
index 5bc13d49fd812f88d662c1d21bc53e3ae02c2a10..f7e73bde956c161d043d627361b92d7ca6eed519 100644 (file)
--- a/index.php
+++ b/index.php
@@ -778,6 +778,7 @@ function renderPage($conf, $pluginManager)
     $PAGE = new PageBuilder($conf);
     $PAGE->assign('linkcount', count($LINKSDB));
     $PAGE->assign('privateLinkcount', count_private($LINKSDB));
+    $PAGE->assign('plugin_errors', $pluginManager->getErrors());
 
     // Determine which page will be rendered.
     $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : '';
index 18834e5331d91cc9d217c18a284056097bcc23db..7335c9d4665a0429549d7fd3977ca961f81e58fa 100644 (file)
  * and check user status with _LOGGEDIN_.
  */
 
+/**
+ * Initialization function.
+ * It will be called when the plugin is loaded.
+ * This function can be used to return a list of initialization errors.
+ *
+ * @param $conf ConfigManager instance.
+ *
+ * @return array List of errors (optional).
+ */
+function demo_plugin_init($conf)
+{
+    $conf->get('toto', 'nope');
+
+    $errors[] = 'This a demo init error.';
+    return $errors;
+}
+
 /**
  * Hook render_header.
  * Executed on every page redering.
index 4bfcf50115c98211743539850bb6606ecbd1b318..961c5bda0c2f79347e9e69e63d4eedfde776c6cb 100644 (file)
@@ -8,10 +8,21 @@
 // it seems kinda dead.
 // Not tested.
 
-$riyUrl = $conf->get('plugins.READITYOUSELF_URL');
-if (empty($riyUrl)) {
-    $GLOBALS['plugin_errors'][] = 'Readityourself plugin error: '.
-        'Please define the "READITYOUSELF_URL" setting in the plugin administration page.';
+/**
+ * Init function, return an error if the server is not set.
+ *
+ * @param $conf ConfigManager instance.
+ *
+ * @return array Eventual error.
+ */
+function readityourself_init($conf)
+{
+    $riyUrl = $conf->get('plugins.READITYOUSELF_URL');
+    if (empty($riyUrl)) {
+        $error = 'Readityourself plugin error: '.
+            'Please define the "READITYOUSELF_URL" setting in the plugin administration page.';
+        return array($error);
+    }
 }
 
 /**
index ec09c8a14d03dc89e2865efb794756d5ee199102..641e4cc237ed4f20a44fafda7eae1b871bf2e118 100644 (file)
@@ -6,10 +6,21 @@
 
 require_once 'WallabagInstance.php';
 
-$wallabagUrl = $conf->get('plugins.WALLABAG_URL');
-if (empty($wallabagUrl)) {
-    $GLOBALS['plugin_errors'][] = 'Wallabag plugin error: '.
-        'Please define the "WALLABAG_URL" setting in the plugin administration page.';
+/**
+ * Init function, return an error if the server is not set.
+ *
+ * @param $conf ConfigManager instance.
+ *
+ * @return array Eventual error.
+ */
+function wallabag_init($conf)
+{
+    $wallabagUrl = $conf->get('plugins.WALLABAG_URL');
+    if (empty($wallabagUrl)) {
+        $error = 'Wallabag plugin error: '.
+            'Please define the "WALLABAG_URL" setting in the plugin administration page.';
+        return array($error);
+    }
 }
 
 /**
index d73e666a5157c99987e9b273188e375adace5711..532db14626d5e177566ddd8c352f5fab621f91a2 100644 (file)
@@ -4,8 +4,6 @@
  * PluginReadityourselfTest.php.php
  */
 
-// FIXME! add an init method.
-$conf = new ConfigManager('');
 require_once 'plugins/readityourself/readityourself.php';
 
 /**
@@ -22,6 +20,27 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
         PluginManager::$PLUGINS_PATH = 'plugins';
     }
 
+    /**
+     * Test Readityourself init without errors.
+     */
+    function testReadityourselfInitNoError()
+    {
+        $conf = new ConfigManager('');
+        $conf->set('plugins.READITYOUSELF_URL', 'value');
+        $errors = readityourself_init($conf);
+        $this->assertEmpty($errors);
+    }
+
+    /**
+     * Test Readityourself init with errors.
+     */
+    function testReadityourselfInitError()
+    {
+        $conf = new ConfigManager('');
+        $errors = readityourself_init($conf);
+        $this->assertNotEmpty($errors);
+    }
+
     /**
      * Test render_linklist hook.
      */
index 302ee296f023d4f8a97db2270cb08e79d6650e82..2c268cbd1b714b3b9aa1c29891bbf40e8592b24a 100644 (file)
@@ -4,8 +4,6 @@
  * PluginWallabagTest.php.php
  */
 
-// FIXME! add an init method.
-$conf = new ConfigManager('');
 require_once 'plugins/wallabag/wallabag.php';
 
 /**
@@ -22,6 +20,27 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
         PluginManager::$PLUGINS_PATH = 'plugins';
     }
 
+    /**
+     * Test wallabag init without errors.
+     */
+    function testWallabagInitNoError()
+    {
+        $conf = new ConfigManager('');
+        $conf->set('plugins.WALLABAG_URL', 'value');
+        $errors = wallabag_init($conf);
+        $this->assertEmpty($errors);
+    }
+
+    /**
+     * Test wallabag init with errors.
+     */
+    function testWallabagInitError()
+    {
+        $conf = new ConfigManager('');
+        $errors = wallabag_init($conf);
+        $this->assertNotEmpty($errors);
+    }
+
     /**
      * Test render_linklist hook.
      */
index dde1f376022b345212addcf5f9357c02da456401..b82ad4831fe50baf8c92aea3a3d1750a9da81544 100644 (file)
     <div class="clear"></div>
 
     {if="$linksToDisplay"}
-        {loop="cols"}
+        {loop="$cols"}
             {if="isset($value[0])"}
             <div id="daily_col{$counter+1}">
-                {loop="value"}
+                {loop="$value"}
                     {$link=$value}
                     <div class="dailyEntry">
                         <div class="dailyEntryPermalink">
@@ -60,7 +60,7 @@
                         {/if}
                         {if="$link.tags"}
                             <div class="dailyEntryTags">
-                                {loop="link.taglist"}
+                                {loop="$link.taglist"}
                                     {$value} -
                                 {/loop}
                             </div>
index b14a38595c6038620317cea2d0d8157e1261658e..ddbd6c5ea49ba5a0d3b68238471a7c06d3f42e41 100644 (file)
@@ -4,7 +4,7 @@
     <link>{$absurl}</link>
     <pubDate>{$rssdate}</pubDate>
     <description><![CDATA[
-        {loop="links"}
+        {loop="$links"}
                <h3><a href="{$value.url}">{$value.title}</a></h3>
                <small>{if="!$hide_timestamps"}{function="strftime('%c', $value.timestamp)"} - {/if}{if="$value.tags"}{$value.tags}{/if}<br>
                {$value.url}</small><br>
index da7332571d2c6c58bc9c30bdeeb344a211c06c15..127a5c209c1e1a9a1e6926ad83a7fc662686ea39 100644 (file)
@@ -5,6 +5,6 @@
      Do Not Edit! -->{ignore}The RainTPL loop is formatted to avoid generating extra newlines{/ignore}
 <TITLE>{$pagetitle}</TITLE>
 <H1>Shaarli export of {$selection} bookmarks on {$date}</H1>
-<DL><p>{loop="links"}
+<DL><p>{loop="$links"}
 <DT><A HREF="{$value.url}" ADD_DATE="{$value.timestamp}" PRIVATE="{$value.private}" TAGS="{$value.taglist}">{$value.title}</A>{if="$value.description"}{$eol}<DD>{$value.description}{/if}{/loop}
 </DL><p>
index 1932f507cf614178c605ab3ea6f236b3609e1037..40fd421a4244b93f25a4a2486cf30fbe012f3b91 100644 (file)
@@ -17,7 +17,7 @@
   </author>
   <id>{$index_url}</id>
   <generator>Shaarli</generator>
-  {loop="links"}
+  {loop="$links"}
     <entry>
       <title>{$value.title}</title>
       {if="$usepermalinks"}
index 4bfe4196c24abfdc6b4c94bda104adce5fe99824..e18dbf9bcea3f70f6ec4578ff12571e002a06cc8 100644 (file)
@@ -12,7 +12,7 @@
       <!-- PubSubHubbub Discovery -->
       <atom:link rel="hub" href="{$pubsubhub_url}" />
     {/if}
-    {loop="links"}
+    {loop="$links"}
       <item>
         <title>{$value.title}</title>
         <guid isPermaLink="{if="$usepermalinks"}true{else}false{/if}">{$value.guid}</guid>
index 9979f12ab3a357c8b9995b8004c25968a4d6f951..ddfd729ac9500dd3a534e8a3927af8243f38a329 100644 (file)
@@ -63,7 +63,7 @@
         </div>
     {/if}
     <ul>
-        {loop="links"}
+        {loop="$links"}
         <li{if="$value.class"} class="{$value.class}"{/if}>
             <a id="{$value.shorturl}"></a>
             <div class="thumbnail">{$value.url|thumbnail}</div>
                 <a href="{$value.real_url}"><span class="linkurl" title="Short link">{$value.url}</span></a><br>
                 {if="$value.tags"}
                     <div class="linktaglist">
-                    {loop="value.taglist"}<span class="linktag" title="Add tag"><a href="?addtag={$value|urlencode}">{$value}</a></span> {/loop}
+                    {loop="$value.taglist"}<span class="linktag" title="Add tag"><a href="?addtag={$value|urlencode}">{$value}</a></span> {/loop}
                     </div>
                 {/if}
 
index 0012c689f8aa1a872f18af7b14e4d46c9efd3804..eac2ed4aa5acc20ad55d626f0030d1cf85897038 100644 (file)
@@ -43,7 +43,7 @@
 
 {if="!empty($plugin_errors) && isLoggedIn()"}
     <ul class="errors">
-        {loop="plugin_errors"}
+        {loop="$plugin_errors"}
             <li>{$value}</li>
         {/loop}
     </ul>
index 230c948b783d9f1fc550bb594e4709b89b9ddf44..4e227e3744038cd440fed8e89e8d3564ce87e6db 100644 (file)
@@ -14,7 +14,7 @@
 
 <div class="center">
         <div id="picwall_container">
-            {loop="linksToDisplay"}
+            {loop="$linksToDisplay"}
             <div class="picwall_pictureframe">
                    {$value.thumbnail}<a href="{$value.real_url}"><span class="info">{$value.title}</span></a>
                 {loop="$value.picwall_plugin"}
index e449f2939fe095ca1138b4c4f02a6d64289ae83d..05e45273ffa284a61f5a71714bf1e6e93b18fad2 100644 (file)
@@ -11,7 +11,7 @@
     </div>
 
     <div id="cloudtag">
-        {loop="tags"}
+        {loop="$tags"}
             <span class="count">{$value.count}</span><a
                 href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a>
             {loop="$value.tag_plugin"}