]>
Commit | Line | Data |
---|---|---|
bf26e7eb A |
1 | <?php |
2 | ||
3 | /** | |
4 | * Plugin Isso. | |
5 | */ | |
6 | ||
12266213 | 7 | use Shaarli\Config\ConfigManager; |
e1850388 | 8 | use Shaarli\Plugin\PluginManager; |
a932f486 | 9 | use Shaarli\Router; |
12266213 | 10 | |
bf26e7eb A |
11 | /** |
12 | * Display an error everywhere if the plugin is enabled without configuration. | |
13 | * | |
bf26e7eb A |
14 | * @param $conf ConfigManager instance |
15 | * | |
16 | * @return mixed - linklist data with Isso plugin. | |
17 | */ | |
18 | function isso_init($conf) | |
19 | { | |
20 | $issoUrl = $conf->get('plugins.ISSO_SERVER'); | |
21 | if (empty($issoUrl)) { | |
12266213 A |
22 | $error = t('Isso plugin error: '. |
23 | 'Please define the "ISSO_SERVER" setting in the plugin administration page.'); | |
bf26e7eb A |
24 | return array($error); |
25 | } | |
26 | } | |
27 | ||
28 | /** | |
29 | * Render linklist hook. | |
30 | * Will only display Isso comments on permalinks. | |
31 | * | |
32 | * @param $data array List of links | |
33 | * @param $conf ConfigManager instance | |
34 | * | |
35 | * @return mixed - linklist data with Isso plugin. | |
36 | */ | |
37 | function hook_isso_render_linklist($data, $conf) | |
38 | { | |
39 | $issoUrl = $conf->get('plugins.ISSO_SERVER'); | |
40 | if (empty($issoUrl)) { | |
41 | return $data; | |
42 | } | |
43 | ||
44 | // Only display comments for permalinks. | |
45 | if (count($data['links']) == 1 && empty($data['search_tags']) && empty($data['search_term'])) { | |
46 | $link = reset($data['links']); | |
01878a75 | 47 | $issoHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/isso/isso.html'); |
bf26e7eb | 48 | |
d592daea | 49 | $isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']); |
bf26e7eb | 50 | $data['plugin_end_zone'][] = $isso; |
0e54e105 A |
51 | } else { |
52 | $button = '<span><a href="?%s#isso-thread">'; | |
53 | // For the default theme we use a FontAwesome icon which is better than an image | |
54 | if ($conf->get('resource.theme') === 'default') { | |
55 | $button .= '<i class="linklist-plugin-icon fa fa-comment"></i>'; | |
56 | } else { | |
57 | $button .= '<img class="linklist-plugin-icon" src="plugins/isso/comment.png" '; | |
58 | $button .= 'title="Comment on this shaare" alt="Comments" />'; | |
59 | } | |
60 | $button .= '</a></span>'; | |
61 | foreach ($data['links'] as &$value) { | |
62 | $commentLink = sprintf($button, $value['shorturl']); | |
63 | $value['link_plugin'][] = $commentLink; | |
64 | } | |
65 | } | |
bf26e7eb | 66 | |
0e54e105 A |
67 | return $data; |
68 | } | |
69 | ||
70 | /** | |
71 | * When linklist is displayed, include isso CSS file. | |
72 | * | |
73 | * @param array $data - header data. | |
74 | * | |
75 | * @return mixed - header data with isso CSS file added. | |
76 | */ | |
77 | function hook_isso_render_includes($data) | |
78 | { | |
79 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { | |
80 | $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/isso/isso.css'; | |
bf26e7eb A |
81 | } |
82 | ||
83 | return $data; | |
84 | } | |
12266213 A |
85 | |
86 | /** | |
87 | * This function is never called, but contains translation calls for GNU gettext extraction. | |
88 | */ | |
89 | function isso_dummy_translation() | |
90 | { | |
91 | // meta | |
92 | t('Let visitor comment your shaares on permalinks with Isso.'); | |
93 | t('Isso server URL (without \'http://\')'); | |
94 | } |