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