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