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 +++++++-------- plugins/wallabag/wallabag.php | 19 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'plugins') 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; } 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/readityourself/config.php.dist | 3 --- plugins/readityourself/readityourself.php | 10 ++++------ plugins/wallabag/README.md | 29 ++++++++++++----------------- plugins/wallabag/config.php.dist | 4 ---- plugins/wallabag/wallabag.php | 10 ++++------ 5 files changed, 20 insertions(+), 36 deletions(-) delete mode 100644 plugins/readityourself/config.php.dist delete mode 100644 plugins/wallabag/config.php.dist (limited to 'plugins') diff --git a/plugins/readityourself/config.php.dist b/plugins/readityourself/config.php.dist deleted file mode 100644 index d6b5cb85..00000000 --- a/plugins/readityourself/config.php.dist +++ /dev/null @@ -1,3 +0,0 @@ -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; diff --git a/plugins/wallabag/README.md b/plugins/wallabag/README.md index 5bc35be1..3f930564 100644 --- a/plugins/wallabag/README.md +++ b/plugins/wallabag/README.md @@ -12,31 +12,26 @@ The directory structure should look like: └── plugins    └── wallabag    ├── README.md - ├── config.php.dist    ├── wallabag.html +    ├── wallabag.meta    ├── wallabag.php -    └── wallabag.png +    ├── wallabag.php +    └── WallabagInstance.php ``` -To enable the plugin, add `'wallabag'` to your list of enabled plugins in `data/options.php` (`PLUGINS` array). -This should look like: +To enable the plugin, you can either: -``` -$GLOBALS['config']['PLUGINS'] = array('qrcode', 'any_other_plugin', 'wallabag') -``` + * enable it in the plugins administration page (`?do=pluginadmin`). + * add `wallabag` to your list of enabled plugins in `data/config.json.php` (`general.enabled_plugins` section). ### Configuration -Copy `config.php.dist` into `config.php` and setup your instance. +Go to the plugin administration page, and edit the following settings (with the plugin enabled). -*Wallabag instance URL* -``` -$GLOBALS['config']['WALLABAG_URL'] = 'http://v2.wallabag.org' ; -``` +**WALLABAG_URL**: *Wallabag instance URL* +Example value: `http://v2.wallabag.org` -*Wallabag version*: either `1` (for 1.x) or `2` (for 2.x) -``` -$GLOBALS['config']['WALLABAG_VERSION'] = 2; -``` +**WALLABAG_VERSION**: *Wallabag version* +Value: either `1` (for 1.x) or `2` (for 2.x) -> Note: these settings can also be set in `data/config.php`. \ No newline at end of file +> Note: these settings can also be set in `data/config.json.php`, in the plugins section. \ No newline at end of file diff --git a/plugins/wallabag/config.php.dist b/plugins/wallabag/config.php.dist deleted file mode 100644 index a602708f..00000000 --- a/plugins/wallabag/config.php.dist +++ /dev/null @@ -1,4 +0,0 @@ -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