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