]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - plugins/isso/isso.php
Apply PHP Code Beautifier on source code for linter automatic fixes
[github/shaarli/Shaarli.git] / plugins / isso / isso.php
CommitLineData
bf26e7eb
A
1<?php
2
3/**
4 * Plugin Isso.
5 */
6
12266213 7use Shaarli\Config\ConfigManager;
e1850388 8use Shaarli\Plugin\PluginManager;
1a8ac737 9use Shaarli\Render\TemplatePage;
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 */
18function isso_init($conf)
19{
20 $issoUrl = $conf->get('plugins.ISSO_SERVER');
21 if (empty($issoUrl)) {
53054b2b 22 $error = t('Isso plugin error: ' .
12266213 23 'Please define the "ISSO_SERVER" setting in the plugin administration page.');
53054b2b 24 return [$error];
bf26e7eb
A
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 */
37function 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 51 } else {
53054b2b 52 $button = '<span><a href="' . ($data['_BASE_PATH_'] ?? '') . '/shaare/%s#isso-thread">';
0e54e105
A
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 {
53054b2b 57 $button .= '<img class="linklist-plugin-icon" src="' . $data['_ROOT_PATH_'] . '/plugins/isso/comment.png" ';
0e54e105
A
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 */
77function hook_isso_render_includes($data)
78{
1a8ac737 79 if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
0e54e105 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 */
89function 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}