]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Use the configuration manager for wallabag and readityourself plugin
authorArthurHoaro <arthur@hoa.ro>
Sun, 29 May 2016 12:41:30 +0000 (14:41 +0200)
committerArthurHoaro <arthur@hoa.ro>
Sat, 11 Jun 2016 07:30:56 +0000 (09:30 +0200)
plugins/readityourself/readityourself.php
plugins/wallabag/wallabag.php
tests/plugins/PluginReadityourselfTest.php
tests/plugins/PluginWallabagTest.php

index c8df4c4fc8595078a17dc3be6e955382d61d9746..9ca73e01098ea08aaadfab52432797be86442428 100644 (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 @@ 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;
     }
 
index 0d6fc66de5fdf5df269455a0365c18f3fabcd557..4726d9369fab4ef8dd9ef0bada8e323a626d3aac 100644 (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 @@ 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');
 
index 8bf17bf1c5b36ea10040bbf5aba3dfb549d8254a..bc5da042206e1b583d178a0ac60f7d8c1d915cd9 100644 (file)
@@ -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,
index 5d3a60e02d109fec041f433070a38a8b2f6fede3..e6f8a8b64b518502c57903a86d79c6c2c031e7c4 100644 (file)
@@ -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')));
     }
 }