aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-24 16:25:06 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-27 21:03:29 +0100
commit358cb20bcba3cb7b0ce2a3000fb7026465a10386 (patch)
tree2e99206786b5ef423aff418947b53a577460246a
parent820cae27cfcc94af552818f3f1e5342e00478f6c (diff)
downloadShaarli-358cb20bcba3cb7b0ce2a3000fb7026465a10386.tar.gz
Shaarli-358cb20bcba3cb7b0ce2a3000fb7026465a10386.tar.zst
Shaarli-358cb20bcba3cb7b0ce2a3000fb7026465a10386.zip
Plugin wallabag: minor improvements
- hide the wallabag icon for logged out users - set API V2 as default parameter - fix URL encoding issue with special chars Fixes #1147
-rw-r--r--plugins/wallabag/wallabag.php5
-rw-r--r--tests/plugins/PluginWallabagTest.php35
2 files changed, 32 insertions, 8 deletions
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php
index d0df3501..8cd3f4ad 100644
--- a/plugins/wallabag/wallabag.php
+++ b/plugins/wallabag/wallabag.php
@@ -22,6 +22,7 @@ function wallabag_init($conf)
22 'Please define the "WALLABAG_URL" setting in the plugin administration page.'); 22 'Please define the "WALLABAG_URL" setting in the plugin administration page.');
23 return array($error); 23 return array($error);
24 } 24 }
25 $conf->setEmpty('plugins.WALLABAG_URL', '2');
25} 26}
26 27
27/** 28/**
@@ -35,7 +36,7 @@ function wallabag_init($conf)
35function hook_wallabag_render_linklist($data, $conf) 36function hook_wallabag_render_linklist($data, $conf)
36{ 37{
37 $wallabagUrl = $conf->get('plugins.WALLABAG_URL'); 38 $wallabagUrl = $conf->get('plugins.WALLABAG_URL');
38 if (empty($wallabagUrl)) { 39 if (empty($wallabagUrl) || !$data['_LOGGEDIN_']) {
39 return $data; 40 return $data;
40 } 41 }
41 42
@@ -51,7 +52,7 @@ function hook_wallabag_render_linklist($data, $conf)
51 $wallabag = sprintf( 52 $wallabag = sprintf(
52 $wallabagHtml, 53 $wallabagHtml,
53 $wallabagInstance->getWallabagUrl(), 54 $wallabagInstance->getWallabagUrl(),
54 urlencode($value['url']), 55 urlencode(unescape($value['url'])),
55 $path, 56 $path,
56 $linkTitle 57 $linkTitle
57 ); 58 );
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 36317215..9a402fb7 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -49,14 +49,15 @@ class PluginWallabagTest extends \Shaarli\TestCase
49 $conf = new ConfigManager(''); 49 $conf = new ConfigManager('');
50 $conf->set('plugins.WALLABAG_URL', 'value'); 50 $conf->set('plugins.WALLABAG_URL', 'value');
51 $str = 'http://randomstr.com/test'; 51 $str = 'http://randomstr.com/test';
52 $data = array( 52 $data = [
53 'title' => $str, 53 'title' => $str,
54 'links' => array( 54 'links' => [
55 array( 55 [
56 'url' => $str, 56 'url' => $str,
57 ) 57 ]
58 ) 58 ],
59 ); 59 '_LOGGEDIN_' => true,
60 ];
60 61
61 $data = hook_wallabag_render_linklist($data, $conf); 62 $data = hook_wallabag_render_linklist($data, $conf);
62 $link = $data['links'][0]; 63 $link = $data['links'][0];
@@ -69,4 +70,26 @@ class PluginWallabagTest extends \Shaarli\TestCase
69 $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str))); 70 $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str)));
70 $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL'))); 71 $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL')));
71 } 72 }
73
74 /**
75 * Test render_linklist hook while logged out: no change.
76 */
77 public function testWallabagLinklistLoggedOut(): void
78 {
79 $conf = new ConfigManager('');
80 $str = 'http://randomstr.com/test';
81 $data = [
82 'title' => $str,
83 'links' => [
84 [
85 'url' => $str,
86 ]
87 ],
88 '_LOGGEDIN_' => false,
89 ];
90
91 $result = hook_wallabag_render_linklist($data, $conf);
92
93 static::assertSame($data, $result);
94 }
72} 95}