aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-10-03 09:43:49 +0200
committerArthurHoaro <arthur@hoa.ro>2016-10-17 09:23:14 +0200
commitbf26e7ebcb5ee69523b93a5ec7b7a65b39acb916 (patch)
treea5a8c57150576404597f2e45877f10c9ea05e59a
parent06eec9bf764662cd328627247a1f43e4abd3c5ad (diff)
downloadShaarli-bf26e7ebcb5ee69523b93a5ec7b7a65b39acb916.tar.gz
Shaarli-bf26e7ebcb5ee69523b93a5ec7b7a65b39acb916.tar.zst
Shaarli-bf26e7ebcb5ee69523b93a5ec7b7a65b39acb916.zip
Isso comments plugin
Use Isso client to let visitors comments on permalinks
-rw-r--r--plugins/isso/isso.css3
-rw-r--r--plugins/isso/isso.html14
-rw-r--r--plugins/isso/isso.meta3
-rw-r--r--plugins/isso/isso.php54
-rw-r--r--tests/plugins/PluginIssoTest.php136
5 files changed, 210 insertions, 0 deletions
diff --git a/plugins/isso/isso.css b/plugins/isso/isso.css
new file mode 100644
index 00000000..b89babc3
--- /dev/null
+++ b/plugins/isso/isso.css
@@ -0,0 +1,3 @@
1#isso-thread > h4 {
2 text-align: center;
3}
diff --git a/plugins/isso/isso.html b/plugins/isso/isso.html
new file mode 100644
index 00000000..babab9b8
--- /dev/null
+++ b/plugins/isso/isso.html
@@ -0,0 +1,14 @@
1<script data-isso="//%s"
2 data-isso-css="true"
3 data-isso-lang="en"
4 data-isso-reply-to-self="true"
5 data-isso-max-comments-top="20"
6 data-isso-max-comments-nested="5"
7 data-isso-reveal-on-click="5"
8 data-isso-avatar="true"
9 data-isso-avatar-bg="#f0f0f0"
10 data-isso-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6 ..."
11 data-isso-vote="true"
12 src="//%s/js/embed.min.js">
13</script>
14<section id="isso-thread" data-isso-id="%s" data-title="%s"></section>
diff --git a/plugins/isso/isso.meta b/plugins/isso/isso.meta
new file mode 100644
index 00000000..62473abc
--- /dev/null
+++ b/plugins/isso/isso.meta
@@ -0,0 +1,3 @@
1description="Let visitor comment your shaares on permalinks with Isso."
2parameters="ISSO_SERVER"
3parameter.ISSO_SERVER="Isso server URL (without 'http://')"
diff --git a/plugins/isso/isso.php b/plugins/isso/isso.php
new file mode 100644
index 00000000..ffb7cfac
--- /dev/null
+++ b/plugins/isso/isso.php
@@ -0,0 +1,54 @@
1<?php
2
3/**
4 * Plugin Isso.
5 */
6
7/**
8 * Display an error everywhere if the plugin is enabled without configuration.
9 *
10 * @param $data array List of links
11 * @param $conf ConfigManager instance
12 *
13 * @return mixed - linklist data with Isso plugin.
14 */
15function isso_init($conf)
16{
17 $issoUrl = $conf->get('plugins.ISSO_SERVER');
18 if (empty($issoUrl)) {
19 $error = 'Isso plugin error: '.
20 'Please define the "ISSO_SERVER" setting in the plugin administration page.';
21 return array($error);
22 }
23}
24
25/**
26 * Render linklist hook.
27 * Will only display Isso comments on permalinks.
28 *
29 * @param $data array List of links
30 * @param $conf ConfigManager instance
31 *
32 * @return mixed - linklist data with Isso plugin.
33 */
34function hook_isso_render_linklist($data, $conf)
35{
36 $issoUrl = $conf->get('plugins.ISSO_SERVER');
37 if (empty($issoUrl)) {
38 return $data;
39 }
40
41 // Only display comments for permalinks.
42 if (count($data['links']) == 1 && empty($data['search_tags']) && empty($data['search_term'])) {
43 $link = reset($data['links']);
44 $isso_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/isso/isso.html');
45
46 $isso = sprintf($isso_html, $issoUrl, $issoUrl, $link['linkdate'], $link['linkdate']);
47 $data['plugin_end_zone'][] = $isso;
48
49 // Hackish way to include this CSS file only when necessary.
50 $data['plugins_includes']['css_files'][] = PluginManager::$PLUGINS_PATH . '/isso/isso.css';
51 }
52
53 return $data;
54}
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
new file mode 100644
index 00000000..1f545c7d
--- /dev/null
+++ b/tests/plugins/PluginIssoTest.php
@@ -0,0 +1,136 @@
1<?php
2
3require_once 'plugins/isso/isso.php';
4
5/**
6 * Class PluginIssoTest
7 *
8 * Test the Isso plugin (comment system).
9 */
10class PluginIssoTest extends PHPUnit_Framework_TestCase
11{
12 /**
13 * Reset plugin path
14 */
15 function setUp()
16 {
17 PluginManager::$PLUGINS_PATH = 'plugins';
18 }
19
20 /**
21 * Test Isso init without errors.
22 */
23 function testWallabagInitNoError()
24 {
25 $conf = new ConfigManager('');
26 $conf->set('plugins.ISSO_SERVER', 'value');
27 $errors = isso_init($conf);
28 $this->assertEmpty($errors);
29 }
30
31 /**
32 * Test Isso init with errors.
33 */
34 function testWallabagInitError()
35 {
36 $conf = new ConfigManager('');
37 $errors = isso_init($conf);
38 $this->assertNotEmpty($errors);
39 }
40
41 /**
42 * Test render_linklist hook with valid settings to display the comment form.
43 */
44 function testIssoDisplayed()
45 {
46 $conf = new ConfigManager('');
47 $conf->set('plugins.ISSO_SERVER', 'value');
48
49 $str = 'http://randomstr.com/test';
50 $data = array(
51 'title' => $str,
52 'links' => array(
53 array(
54 'url' => $str,
55 'linkdate' => 'abc',
56 )
57 )
58 );
59
60 $data = hook_isso_render_linklist($data, $conf);
61
62 // data shouldn't be altered
63 $this->assertEquals($str, $data['title']);
64 $this->assertEquals($str, $data['links'][0]['url']);
65
66 // plugin data
67 $this->assertEquals(1, count($data['plugin_end_zone']));
68 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc'));
69 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
70 }
71
72 /**
73 * Test isso plugin when multiple links are displayed (shouldn't be displayed).
74 */
75 function testIssoMultipleLinks()
76 {
77 $conf = new ConfigManager('');
78 $conf->set('plugins.ISSO_SERVER', 'value');
79
80 $str = 'http://randomstr.com/test';
81 $data = array(
82 'title' => $str,
83 'links' => array(
84 array(
85 'url' => $str,
86 'linkdate' => 'abc',
87 ),
88 array(
89 'url' => $str . '2',
90 'linkdate' => 'abc2',
91 ),
92 )
93 );
94
95 $processed = hook_isso_render_linklist($data, $conf);
96 // data shouldn't be altered
97 $this->assertEquals($data, $processed);
98 }
99
100 /**
101 * Test isso plugin when using search (shouldn't be displayed).
102 */
103 function testIssoNotDisplayedWhenSearch()
104 {
105 $conf = new ConfigManager('');
106 $conf->set('plugins.ISSO_SERVER', 'value');
107
108 $str = 'http://randomstr.com/test';
109 $data = array(
110 'title' => $str,
111 'links' => array(
112 array(
113 'url' => $str,
114 'linkdate' => 'abc',
115 )
116 ),
117 'search_term' => $str
118 );
119
120 $processed = hook_isso_render_linklist($data, $conf);
121
122 // data shouldn't be altered
123 $this->assertEquals($data, $processed);
124 }
125
126 /**
127 * Test isso plugin without server configuration (shouldn't be displayed).
128 */
129 function testIssoWithoutConf()
130 {
131 $data = 'abc';
132 $conf = new ConfigManager('');
133 $processed = hook_isso_render_linklist($data, $conf);
134 $this->assertEquals($data, $processed);
135 }
136}