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        // we need to access the javascript translations
26        $this->setupLocale();
27
28        if ($INFO['subscribed']) {
29            $title = $this->lang['js']['unsubscribe'];
30            $target = $INFO['subscribed'][0]['target'];
31            $class = 'plugin_qsub_subscribed';
32        } else {
33            $title = $this->lang['js']['subscribe'];
34            $target = '';
35            $class = 'plugin_qsub_notsubscribed';
36        }
37
38        // we hide one of the SVGs based on the outer class
39        $svg = inlineSVG(__DIR__ . '/images/bell-ring.svg').inlineSVG(__DIR__ . '/images/bell-outline.svg');
40
41        $link = $submgr->getLinkAttributes('plugin_qsub_');
42        $link['data-target'] = $target;
43        $link['title'] = $title;
44        $link['class'] .= ' ' . $class;
45        $attr = buildAttributes($link);
46
47        return "<a $attr>$svg</a>";
48    }
49}
50