]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Plugin wallabag: minor improvements 1610/head
authorArthurHoaro <arthur@hoa.ro>
Sat, 24 Oct 2020 14:25:06 +0000 (16:25 +0200)
committerArthurHoaro <arthur@hoa.ro>
Tue, 27 Oct 2020 20:03:29 +0000 (21:03 +0100)
  - hide the wallabag icon for logged out users
  - set API V2 as default parameter
  - fix URL encoding issue with special chars

Fixes #1147

plugins/wallabag/wallabag.php
tests/plugins/PluginWallabagTest.php

index d0df3501d6389b40ce2e1c340675f4debada71ea..8cd3f4adc1dc32891043ece763a960fa3be6cb47 100644 (file)
@@ -22,6 +22,7 @@ function wallabag_init($conf)
             'Please define the "WALLABAG_URL" setting in the plugin administration page.');
         return array($error);
     }
+    $conf->setEmpty('plugins.WALLABAG_URL', '2');
 }
 
 /**
@@ -35,7 +36,7 @@ function wallabag_init($conf)
 function hook_wallabag_render_linklist($data, $conf)
 {
     $wallabagUrl = $conf->get('plugins.WALLABAG_URL');
-    if (empty($wallabagUrl)) {
+    if (empty($wallabagUrl) || !$data['_LOGGEDIN_']) {
         return $data;
     }
 
@@ -51,7 +52,7 @@ function hook_wallabag_render_linklist($data, $conf)
         $wallabag = sprintf(
             $wallabagHtml,
             $wallabagInstance->getWallabagUrl(),
-            urlencode($value['url']),
+            urlencode(unescape($value['url'])),
             $path,
             $linkTitle
         );
index 36317215976e4a5c38fe8bf721525b903d764d8d..9a402fb75a177fd585c65778f9322d811f74adcf 100644 (file)
@@ -49,14 +49,15 @@ class PluginWallabagTest extends \Shaarli\TestCase
         $conf = new ConfigManager('');
         $conf->set('plugins.WALLABAG_URL', 'value');
         $str = 'http://randomstr.com/test';
-        $data = array(
+        $data = [
             'title' => $str,
-            'links' => array(
-                array(
+            'links' => [
+                [
                     'url' => $str,
-                )
-            )
-        );
+                ]
+            ],
+            '_LOGGEDIN_' => true,
+        ];
 
         $data = hook_wallabag_render_linklist($data, $conf);
         $link = $data['links'][0];
@@ -69,4 +70,26 @@ class PluginWallabagTest extends \Shaarli\TestCase
         $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str)));
         $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL')));
     }
+
+    /**
+     * Test render_linklist hook while logged out: no change.
+     */
+    public function testWallabagLinklistLoggedOut(): void
+    {
+        $conf = new ConfigManager('');
+        $str = 'http://randomstr.com/test';
+        $data = [
+            'title' => $str,
+            'links' => [
+                [
+                    'url' => $str,
+                ]
+            ],
+            '_LOGGEDIN_' => false,
+        ];
+
+        $result = hook_wallabag_render_linklist($data, $conf);
+
+        static::assertSame($data, $result);
+    }
 }