xref: /plugin/quicksubscribe/helper.php (revision 6bd6f51f0107da5737b734181560cb6f363639f3)
1<?php
2
3class helper_plugin_quicksubscribe extends DokuWiki_Plugin
4{
5    /**
6     * Returns the quick subscribe icon using an inline SVG
7     *
8     * @return string
9     */
10    function tpl_subscribe()
11    {
12        global $INFO;
13        global $ACT;
14
15        // only on show
16        if($ACT !== 'show') return '';
17
18        // check if subscription is available
19        try {
20            $submgr = new \dokuwiki\Menu\Item\Subscribe();
21        } catch (\RuntimeException $ignored) {
22            return '';
23        }
24
25        if ($INFO['subscribed']) {
26            $title = prettyprint_id($INFO['subscribed'][0]['target']);
27            $target = $INFO['subscribed'][0]['target'];
28            $class = 'plugin_qsub_subscribed';
29        } else {
30            $title = $submgr->getTitle();
31            $target = '';
32            $class = 'plugin_qsub_notsubscribed';
33        }
34
35        // we hide one of the SVGs based on the outer class
36        $svg = inlineSVG(__DIR__ . '/images/bell-ring.svg').inlineSVG(__DIR__ . '/images/bell-outline.svg');
37
38        $link = $submgr->getLinkAttributes('plugin_qsub_');
39        $link['data-target'] = $target;
40        $link['title'] = $title;
41        $link['class'] .= ' ' . $class;
42        $attr = buildAttributes($link);
43
44        return "<a $attr>$svg</a>";
45    }
46}
47