Use the configuration manager for wallabag and readityourself plugin

This commit is contained in:
ArthurHoaro 2016-05-29 14:41:30 +02:00
parent d93d51b213
commit eeea1c3daa
4 changed files with 22 additions and 23 deletions

View file

@ -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 @@
*/
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;
}

View file

@ -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 @@
*/
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');

View file

@ -25,7 +25,8 @@ function setUp()
*/
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 @@ function testReadityourselfLinklist()
*/
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,

View file

@ -25,7 +25,8 @@ function setUp()
*/
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 @@ function testWallabagLinklist()
// 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')));
}
}