1b2d51c84SAdrian Lang<?php 2b2d51c84SAdrian Lang 36bd6f51fSAndreas Gohrclass helper_plugin_quicksubscribe extends DokuWiki_Plugin 46bd6f51fSAndreas Gohr{ 56bd6f51fSAndreas Gohr /** 66bd6f51fSAndreas Gohr * Returns the quick subscribe icon using an inline SVG 76bd6f51fSAndreas Gohr * 86bd6f51fSAndreas Gohr * @return string 96bd6f51fSAndreas Gohr */ 106bd6f51fSAndreas Gohr function tpl_subscribe() 116bd6f51fSAndreas Gohr { 12b2d51c84SAdrian Lang global $INFO; 136bd6f51fSAndreas Gohr global $ACT; 146bd6f51fSAndreas Gohr 156bd6f51fSAndreas Gohr // only on show 166bd6f51fSAndreas Gohr if($ACT !== 'show') return ''; 176bd6f51fSAndreas Gohr 186bd6f51fSAndreas Gohr // check if subscription is available 196bd6f51fSAndreas Gohr try { 206bd6f51fSAndreas Gohr $submgr = new \dokuwiki\Menu\Item\Subscribe(); 216bd6f51fSAndreas Gohr } catch (\RuntimeException $ignored) { 226bd6f51fSAndreas Gohr return ''; 23b2d51c84SAdrian Lang } 246bd6f51fSAndreas Gohr 25*337272e3SAndreas Gohr // we need to access the javascript translations 26*337272e3SAndreas Gohr $this->setupLocale(); 27*337272e3SAndreas Gohr 286bd6f51fSAndreas Gohr if ($INFO['subscribed']) { 29*337272e3SAndreas Gohr $title = $this->lang['js']['unsubscribe']; 306bd6f51fSAndreas Gohr $target = $INFO['subscribed'][0]['target']; 316bd6f51fSAndreas Gohr $class = 'plugin_qsub_subscribed'; 326bd6f51fSAndreas Gohr } else { 33*337272e3SAndreas Gohr $title = $this->lang['js']['subscribe']; 346bd6f51fSAndreas Gohr $target = ''; 356bd6f51fSAndreas Gohr $class = 'plugin_qsub_notsubscribed'; 366bd6f51fSAndreas Gohr } 376bd6f51fSAndreas Gohr 386bd6f51fSAndreas Gohr // we hide one of the SVGs based on the outer class 396bd6f51fSAndreas Gohr $svg = inlineSVG(__DIR__ . '/images/bell-ring.svg').inlineSVG(__DIR__ . '/images/bell-outline.svg'); 406bd6f51fSAndreas Gohr 416bd6f51fSAndreas Gohr $link = $submgr->getLinkAttributes('plugin_qsub_'); 426bd6f51fSAndreas Gohr $link['data-target'] = $target; 436bd6f51fSAndreas Gohr $link['title'] = $title; 446bd6f51fSAndreas Gohr $link['class'] .= ' ' . $class; 456bd6f51fSAndreas Gohr $attr = buildAttributes($link); 466bd6f51fSAndreas Gohr 476bd6f51fSAndreas Gohr return "<a $attr>$svg</a>"; 48b2d51c84SAdrian Lang } 49b2d51c84SAdrian Lang} 50