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/readityourself/readityourself.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'plugins/readityourself/readityourself.php') diff --git a/plugins/readityourself/readityourself.php b/plugins/readityourself/readityourself.php index c8df4c4f..9ca73e01 100644 --- a/plugins/readityourself/readityourself.php +++ b/plugins/readityourself/readityourself.php @@ -8,12 +8,9 @@ // it seems kinda dead. // Not tested. -// don't raise unnecessary warnings -if (is_file(PluginManager::$PLUGINS_PATH . '/readityourself/config.php')) { - include PluginManager::$PLUGINS_PATH . '/readityourself/config.php'; -} - -if (empty($GLOBALS['plugins']['READITYOUSELF_URL'])) { +$conf = ConfigManager::getInstance(); +$riyUrl = $conf->get('plugins.READITYOUSELF_URL'); +if (empty($riyUrl)) { $GLOBALS['plugin_errors'][] = 'Readityourself plugin error: '. 'Please define "$GLOBALS[\'plugins\'][\'READITYOUSELF_URL\']" '. 'in "plugins/readityourself/config.php" or in your Shaarli config.php file.'; @@ -28,14 +25,16 @@ if (empty($GLOBALS['plugins']['READITYOUSELF_URL'])) { */ function hook_readityourself_render_linklist($data) { - if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) { + $conf = ConfigManager::getInstance(); + $riyUrl = $conf->get('plugins.READITYOUSELF_URL'); + if (empty($riyUrl)) { return $data; } $readityourself_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readityourself/readityourself.html'); foreach ($data['links'] as &$value) { - $readityourself = sprintf($readityourself_html, $GLOBALS['plugins']['READITYOUSELF_URL'], $value['url'], PluginManager::$PLUGINS_PATH); + $readityourself = sprintf($readityourself_html, $riyUrl, $value['url'], PluginManager::$PLUGINS_PATH); $value['link_plugin'][] = $readityourself; } -- 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/readityourself/readityourself.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'plugins/readityourself/readityourself.php') diff --git a/plugins/readityourself/readityourself.php b/plugins/readityourself/readityourself.php index 9ca73e01..4bfcf501 100644 --- a/plugins/readityourself/readityourself.php +++ b/plugins/readityourself/readityourself.php @@ -8,24 +8,22 @@ // it seems kinda dead. // Not tested. -$conf = ConfigManager::getInstance(); $riyUrl = $conf->get('plugins.READITYOUSELF_URL'); if (empty($riyUrl)) { $GLOBALS['plugin_errors'][] = 'Readityourself plugin error: '. - 'Please define "$GLOBALS[\'plugins\'][\'READITYOUSELF_URL\']" '. - 'in "plugins/readityourself/config.php" or in your Shaarli config.php file.'; + 'Please define the "READITYOUSELF_URL" setting in the plugin administration page.'; } /** * Add readityourself 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 readityourself plugin. */ -function hook_readityourself_render_linklist($data) +function hook_readityourself_render_linklist($data, $conf) { - $conf = ConfigManager::getInstance(); $riyUrl = $conf->get('plugins.READITYOUSELF_URL'); if (empty($riyUrl)) { 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/readityourself/readityourself.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'plugins/readityourself/readityourself.php') 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); + } } /** -- cgit v1.2.3