From eeea1c3daa87f133c57c96fa17ed26b02c392636 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 29 May 2016 14:41:30 +0200 Subject: [PATCH] Use the configuration manager for wallabag and readityourself plugin --- plugins/readityourself/readityourself.php | 15 +++++++-------- plugins/wallabag/wallabag.php | 19 ++++++++----------- tests/plugins/PluginReadityourselfTest.php | 6 ++++-- tests/plugins/PluginWallabagTest.php | 5 +++-- 4 files changed, 22 insertions(+), 23 deletions(-) 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'); diff --git a/tests/plugins/PluginReadityourselfTest.php b/tests/plugins/PluginReadityourselfTest.php index 8bf17bf1..bc5da042 100644 --- a/tests/plugins/PluginReadityourselfTest.php +++ b/tests/plugins/PluginReadityourselfTest.php @@ -25,7 +25,8 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase */ function testReadityourselfLinklist() { - $GLOBALS['plugins']['READITYOUSELF_URL'] = 'value'; + $conf = ConfigManager::getInstance(); + $conf->set('plugins.READITYOUSELF_URL', 'value'); $str = 'http://randomstr.com/test'; $data = array( 'title' => $str, @@ -52,7 +53,8 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase */ function testReadityourselfLinklistWithoutConfig() { - unset($GLOBALS['plugins']['READITYOUSELF_URL']); + $conf = ConfigManager::getInstance(); + $conf->set('plugins.READITYOUSELF_URL', null); $str = 'http://randomstr.com/test'; $data = array( 'title' => $str, diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 5d3a60e0..e6f8a8b6 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php @@ -25,7 +25,8 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase */ function testWallabagLinklist() { - $GLOBALS['plugins']['WALLABAG_URL'] = 'value'; + $conf = ConfigManager::getInstance(); + $conf->set('plugins.WALLABAG_URL', 'value'); $str = 'http://randomstr.com/test'; $data = array( 'title' => $str, @@ -45,7 +46,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase // plugin data $this->assertEquals(1, count($link['link_plugin'])); $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str))); - $this->assertNotFalse(strpos($link['link_plugin'][0], $GLOBALS['plugins']['WALLABAG_URL'])); + $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL'))); } } -- 2.41.0