]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/isso/isso.php
79e7380b66f543ade34bb080e027cba26990a7bf
[github/shaarli/Shaarli.git] / plugins / isso / isso.php
1 <?php
2
3 /**
4 * Plugin Isso.
5 */
6
7 use Shaarli\Config\ConfigManager;
8 use Shaarli\Plugin\PluginManager;
9 use Shaarli\Render\TemplatePage;
10
11 /**
12 * Display an error everywhere if the plugin is enabled without configuration.
13 *
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)) {
22 $error = t('Isso plugin error: '.
23 'Please define the "ISSO_SERVER" setting in the plugin administration page.');
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']);
47 $issoHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/isso/isso.html');
48
49 $isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']);
50 $data['plugin_end_zone'][] = $isso;
51 } else {
52 $button = '<span><a href="'. ($data['_BASE_PATH_'] ?? '') . '/shaare/%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 }
66
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_'] == TemplatePage::LINKLIST) {
80 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/isso/isso.css';
81 }
82
83 return $data;
84 }
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 }