From: VirtualTam Date: Mon, 17 Oct 2016 15:58:39 +0000 (+0200) Subject: Merge pull request #662 from virtualtam/fix/feed/self-link X-Git-Tag: v0.8.1~24 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=8406a4b670957b7d0450f6ea5e4f2e61c7114e8f;hp=44a718090d716e53c0e78bf3a0225fd2fb30071e;p=github%2Fshaarli%2FShaarli.git Merge pull request #662 from virtualtam/fix/feed/self-link Fix: return the proper value for the "self" feed attribute --- diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 42932f32..32c7f9f1 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -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); diff --git a/application/PluginManager.php b/application/PluginManager.php index 1e132a7f..59ece4fa 100644 --- a/application/PluginManager.php +++ b/application/PluginManager.php @@ -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; + } } /** diff --git a/index.php b/index.php index 5bc13d49..f7e73bde 100644 --- 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'] : ''; diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 18834e53..7335c9d4 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -14,6 +14,23 @@ * 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. diff --git a/plugins/readityourself/readityourself.php b/plugins/readityourself/readityourself.php index 4bfcf501..961c5bda 100644 --- a/plugins/readityourself/readityourself.php +++ b/plugins/readityourself/readityourself.php @@ -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); + } } /** diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index ec09c8a1..641e4cc2 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php @@ -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); + } } /** diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php index d73e666a..532db146 100644 --- a/tests/plugins/PluginReadityourselfTest.php +++ b/tests/plugins/PluginReadityourselfTest.php @@ -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. */ diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 302ee296..2c268cbd 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php @@ -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. */ diff --git a/tpl/daily.html b/tpl/daily.html index dde1f376..b82ad483 100644 --- a/tpl/daily.html +++ b/tpl/daily.html @@ -42,10 +42,10 @@
{if="$linksToDisplay"} - {loop="cols"} + {loop="$cols"} {if="isset($value[0])"}
- {loop="value"} + {loop="$value"} {$link=$value}
{/if}
    - {loop="links"} + {loop="$links"}
    {$value.url|thumbnail}
    @@ -110,7 +110,7 @@ {$value.url}
    {if="$value.tags"}
    - {loop="value.taglist"}{$value} {/loop} + {loop="$value.taglist"}{$value} {/loop}
    {/if} diff --git a/tpl/page.header.html b/tpl/page.header.html index 0012c689..eac2ed4a 100644 --- a/tpl/page.header.html +++ b/tpl/page.header.html @@ -43,7 +43,7 @@ {if="!empty($plugin_errors) && isLoggedIn()"}
      - {loop="plugin_errors"} + {loop="$plugin_errors"}
    • {$value}
    • {/loop}
    diff --git a/tpl/picwall.html b/tpl/picwall.html index 230c948b..4e227e37 100644 --- a/tpl/picwall.html +++ b/tpl/picwall.html @@ -14,7 +14,7 @@
    - {loop="linksToDisplay"} + {loop="$linksToDisplay"}
    {$value.thumbnail}{$value.title} {loop="$value.picwall_plugin"} diff --git a/tpl/tagcloud.html b/tpl/tagcloud.html index e449f293..05e45273 100644 --- a/tpl/tagcloud.html +++ b/tpl/tagcloud.html @@ -11,7 +11,7 @@
    - {loop="tags"} + {loop="$tags"} {$value.count}{$key} {loop="$value.tag_plugin"}