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