From eeea1c3daa87f133c57c96fa17ed26b02c392636 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 29 May 2016 14:41:30 +0200 Subject: Use the configuration manager for wallabag and readityourself plugin --- plugins/wallabag/wallabag.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'plugins/wallabag/wallabag.php') diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index 0d6fc66d..4726d936 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php @@ -6,12 +6,9 @@ require_once 'WallabagInstance.php'; -// don't raise unnecessary warnings -if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) { - include PluginManager::$PLUGINS_PATH . '/wallabag/config.php'; -} - -if (empty($GLOBALS['plugins']['WALLABAG_URL'])) { +$conf = ConfigManager::getInstance(); +$wallabagUrl = $conf->get('plugins.WALLABAG_URL'); +if (empty($wallabagUrl)) { $GLOBALS['plugin_errors'][] = 'Wallabag plugin error: '. 'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '. 'in "plugins/wallabag/config.php" or in your Shaarli config.php file.'; @@ -26,14 +23,14 @@ if (empty($GLOBALS['plugins']['WALLABAG_URL'])) { */ function hook_wallabag_render_linklist($data) { - if (!isset($GLOBALS['plugins']['WALLABAG_URL'])) { + $conf = ConfigManager::getInstance(); + $wallabagUrl = $conf->get('plugins.WALLABAG_URL'); + if (empty($wallabagUrl)) { return $data; } - $version = isset($GLOBALS['plugins']['WALLABAG_VERSION']) - ? $GLOBALS['plugins']['WALLABAG_VERSION'] - : ''; - $wallabagInstance = new WallabagInstance($GLOBALS['plugins']['WALLABAG_URL'], $version); + $version = $conf->get('plugins.WALLABAG_VERSION'); + $wallabagInstance = new WallabagInstance($wallabagUrl, $version); $wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); -- cgit v1.2.3 From 51def0d84955c7a951bd091eb5eeb3fce9deabd4 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 9 Jun 2016 20:04:32 +0200 Subject: PluginManager no longer uses singleton pattern --- plugins/wallabag/wallabag.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'plugins/wallabag/wallabag.php') diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index 4726d936..ec09c8a1 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php @@ -6,24 +6,22 @@ require_once 'WallabagInstance.php'; -$conf = ConfigManager::getInstance(); $wallabagUrl = $conf->get('plugins.WALLABAG_URL'); if (empty($wallabagUrl)) { $GLOBALS['plugin_errors'][] = 'Wallabag plugin error: '. - 'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '. - 'in "plugins/wallabag/config.php" or in your Shaarli config.php file.'; + 'Please define the "WALLABAG_URL" setting in the plugin administration page.'; } /** * Add wallabag icon to link_plugin when rendering linklist. * - * @param mixed $data - linklist data. + * @param mixed $data Linklist data. + * @param ConfigManager $conf Configuration Manager instance. * * @return mixed - linklist data with wallabag plugin. */ -function hook_wallabag_render_linklist($data) +function hook_wallabag_render_linklist($data, $conf) { - $conf = ConfigManager::getInstance(); $wallabagUrl = $conf->get('plugins.WALLABAG_URL'); if (empty($wallabagUrl)) { return $data; -- cgit v1.2.3 From 7fde6de1212323418401c15efba06026c704ca87 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 14 Oct 2016 13:22:58 +0200 Subject: New init function for plugins, supports errors reporting All plugins can optionally add an init function named `pluginname_init()` which is called when the plugin is loaded. This function is aware of the config, and can return initialization errors, which are displayed in the header template. Note that the previous error system hack no longer work. --- plugins/wallabag/wallabag.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'plugins/wallabag/wallabag.php') 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); + } } /** -- cgit v1.2.3