12387fd46SAndreas Gohr<?php 22387fd46SAndreas Gohr 32387fd46SAndreas Gohrnamespace dokuwiki\template\sprintdoc; 42387fd46SAndreas Gohr 52387fd46SAndreas Gohr/** 62387fd46SAndreas Gohr * Class Template 72387fd46SAndreas Gohr * 82387fd46SAndreas Gohr * provides additional logic for the sprintdoc template 92387fd46SAndreas Gohr * 102387fd46SAndreas Gohr * @package dokuwiki\template\sprintdoc 112387fd46SAndreas Gohr */ 122387fd46SAndreas Gohrclass Template { 132387fd46SAndreas Gohr 142387fd46SAndreas Gohr /** 152387fd46SAndreas Gohr * @var array loaded plugins 162387fd46SAndreas Gohr */ 172387fd46SAndreas Gohr protected $plugins = array( 182387fd46SAndreas Gohr 'sqlite' => null, 192387fd46SAndreas Gohr 'tagging' => null, 201f3641a8SMichael Große 'magicmatcher' => null, 212387fd46SAndreas Gohr ); 222387fd46SAndreas Gohr 232387fd46SAndreas Gohr /** 242387fd46SAndreas Gohr * Get the singleton instance 252387fd46SAndreas Gohr * 262387fd46SAndreas Gohr * @return Template 272387fd46SAndreas Gohr */ 282387fd46SAndreas Gohr public static function getInstance() { 292387fd46SAndreas Gohr static $instance = null; 302387fd46SAndreas Gohr if($instance === null) $instance = new Template(); 312387fd46SAndreas Gohr return $instance; 322387fd46SAndreas Gohr } 332387fd46SAndreas Gohr 342387fd46SAndreas Gohr /** 352387fd46SAndreas Gohr * Template constructor. 362387fd46SAndreas Gohr */ 372387fd46SAndreas Gohr protected function __construct() { 382387fd46SAndreas Gohr $this->initializePlugins(); 39cad2e674SAndreas Gohr 40cad2e674SAndreas Gohr /** @var \Doku_Event_Handler */ 41cad2e674SAndreas Gohr global $EVENT_HANDLER; 42cad2e674SAndreas Gohr $EVENT_HANDLER->register_hook('PLUGIN_TPLINC_LOCATIONS_SET', 'BEFORE', $this, 'registerIncludes'); 43cad2e674SAndreas Gohr } 44cad2e674SAndreas Gohr 45cad2e674SAndreas Gohr /** 46cad2e674SAndreas Gohr * Makes include position info available to the tplinc plugin 47cad2e674SAndreas Gohr * 48cad2e674SAndreas Gohr * @param \Doku_Event $event 49cad2e674SAndreas Gohr */ 50cad2e674SAndreas Gohr public function registerIncludes(\Doku_Event $event) { 51cad2e674SAndreas Gohr $event->data['footer'] = 'Footer below the page content'; 52485e7ff4SMichael Große $event->data['sidebarfooter'] = 'Footer below the sidebar'; 53485e7ff4SMichael Große $event->data['sidebarheader'] = 'Header above the sidebar'; 54cad2e674SAndreas Gohr } 55cad2e674SAndreas Gohr 56cad2e674SAndreas Gohr /** 57cad2e674SAndreas Gohr * Get the content to include from the tplinc plugin 58cad2e674SAndreas Gohr * 59cad2e674SAndreas Gohr * prefix and postfix are only added when there actually is any content 60cad2e674SAndreas Gohr * 61cad2e674SAndreas Gohr * @param string $location 62cad2e674SAndreas Gohr * @param string $pre prepend this before the content 63cad2e674SAndreas Gohr * @param string $post append this to the content 64cad2e674SAndreas Gohr * @return string 65cad2e674SAndreas Gohr */ 66cad2e674SAndreas Gohr public function getInclude($location, $pre = '', $post = '') { 67cad2e674SAndreas Gohr if(!$this->plugins['tplinc']) return ''; 68cad2e674SAndreas Gohr $content = $this->plugins['tplinc']->renderIncludes($location); 69cad2e674SAndreas Gohr if($content === '') return ''; 70cad2e674SAndreas Gohr return $pre . $content . $post; 712387fd46SAndreas Gohr } 722387fd46SAndreas Gohr 732387fd46SAndreas Gohr /** 742387fd46SAndreas Gohr * Load all the plugins we support directly 752387fd46SAndreas Gohr */ 762387fd46SAndreas Gohr protected function initializePlugins() { 772387fd46SAndreas Gohr $this->plugins['sqlite'] = plugin_load('helper', 'sqlite'); 782387fd46SAndreas Gohr if($this->plugins['sqlite']) { 792387fd46SAndreas Gohr $this->plugins['tagging'] = plugin_load('helper', 'tagging'); 801f3641a8SMichael Große $this->plugins['magicmatcher'] = plugin_load('syntax', 'magicmatcher_issuelist'); 812387fd46SAndreas Gohr } 82cad2e674SAndreas Gohr $this->plugins['tplinc'] = plugin_load('helper', 'tplinc'); 832387fd46SAndreas Gohr } 842387fd46SAndreas Gohr 852387fd46SAndreas Gohr /** 862387fd46SAndreas Gohr * Get all the tabs to display 872387fd46SAndreas Gohr * 882387fd46SAndreas Gohr * @return array 892387fd46SAndreas Gohr */ 902387fd46SAndreas Gohr public function getMetaBoxTabs() { 912387fd46SAndreas Gohr global $lang; 922387fd46SAndreas Gohr $tabs = array(); 932387fd46SAndreas Gohr 942387fd46SAndreas Gohr $toc = tpl_toc(true); 952387fd46SAndreas Gohr if($toc) { 962387fd46SAndreas Gohr $tabs[] = array( 972387fd46SAndreas Gohr 'id' => 'spr__tab-toc', 982387fd46SAndreas Gohr 'label' => $lang['toc'], 992387fd46SAndreas Gohr 'tab' => $toc, 1002387fd46SAndreas Gohr 'count' => null, 1012387fd46SAndreas Gohr ); 1022387fd46SAndreas Gohr } 1032387fd46SAndreas Gohr 1042387fd46SAndreas Gohr if($this->plugins['tagging']) { 1052387fd46SAndreas Gohr $tabs[] = array( 1062387fd46SAndreas Gohr 'id' => 'spr__tab-tags', 1072387fd46SAndreas Gohr 'label' => tpl_getLang('tab_tags'), 1082387fd46SAndreas Gohr 'tab' => $this->plugins['tagging']->tpl_tags(false), 1092387fd46SAndreas Gohr 'count' => null, // FIXME 1102387fd46SAndreas Gohr ); 1112387fd46SAndreas Gohr } 1122387fd46SAndreas Gohr 1131f3641a8SMichael Große if ($this->plugins['magicmatcher']) { 1141f3641a8SMichael Große $tabs[] = array( 1151f3641a8SMichael Große 'id' => 'spr__tab-issues', 1169cae5e77SMichael Große 'label' => tpl_getLang('tab_issues'), 1171f3641a8SMichael Große 'tab' => $this->plugins['magicmatcher']->getIssueListHTML(), 1181f3641a8SMichael Große 'count' => $this->plugins['magicmatcher']->getCountIssues(), 1191f3641a8SMichael Große ); 1201f3641a8SMichael Große } 1212387fd46SAndreas Gohr 1222387fd46SAndreas Gohr return $tabs; 1232387fd46SAndreas Gohr } 12406cdf148SAndreas Gohr 12506cdf148SAndreas Gohr /** 12606cdf148SAndreas Gohr * Creates an image tag and includes the first found image correctly resized 12706cdf148SAndreas Gohr * 12806cdf148SAndreas Gohr * @param string $tag 12906cdf148SAndreas Gohr * @param array $attributes 13006cdf148SAndreas Gohr * @param int $w 13106cdf148SAndreas Gohr * @param int $h 13206cdf148SAndreas Gohr * @return string 13306cdf148SAndreas Gohr */ 13406cdf148SAndreas Gohr public static function getResizedImgTag($tag, $attributes, $w, $h) { 13506cdf148SAndreas Gohr $attr = ''; 13606cdf148SAndreas Gohr $medias = array(); 13706cdf148SAndreas Gohr 13806cdf148SAndreas Gohr // the attribute having an array defines where the image goes 13906cdf148SAndreas Gohr foreach($attributes as $attribute => $data) { 14006cdf148SAndreas Gohr if(is_array($data)) { 14106cdf148SAndreas Gohr $medias = $data; 14206cdf148SAndreas Gohr $attr = $attribute; 14306cdf148SAndreas Gohr } 14406cdf148SAndreas Gohr } 14506cdf148SAndreas Gohr // if the image attribute could not be found return 14606cdf148SAndreas Gohr if(!$attr || !$medias) return ''; 14706cdf148SAndreas Gohr 14806cdf148SAndreas Gohr // try all medias until an existing one is found 14906cdf148SAndreas Gohr $media = ''; 15006cdf148SAndreas Gohr foreach($medias as $media) { 15106cdf148SAndreas Gohr if(file_exists(mediaFN($media))) break; 15206cdf148SAndreas Gohr $media = ''; 15306cdf148SAndreas Gohr } 15406cdf148SAndreas Gohr if($media === '') return ''; 15506cdf148SAndreas Gohr 15606cdf148SAndreas Gohr // replace the array 15706cdf148SAndreas Gohr $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); 15806cdf148SAndreas Gohr $attributes[$attr] = $media; 15906cdf148SAndreas Gohr 16006cdf148SAndreas Gohr // return the full tag 1619dbc42beSAndreas Gohr return '<' . $tag . ' ' . buildAttributes($attributes) . ' />' . "\n"; 16206cdf148SAndreas Gohr } 1633a6eaa0bSAndreas Gohr 1643a6eaa0bSAndreas Gohr /** 1653a6eaa0bSAndreas Gohr * Embed the main logo 1663a6eaa0bSAndreas Gohr * 1673a6eaa0bSAndreas Gohr * Tries a few different locations 1683a6eaa0bSAndreas Gohr */ 1693a6eaa0bSAndreas Gohr public function mainLogo() { 1703a6eaa0bSAndreas Gohr global $conf; 1713a6eaa0bSAndreas Gohr 172e17d84d6SAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 173e17d84d6SAndreas Gohr $linkit = (strcmp(wl(), $_SERVER['REQUEST_URI']) !== 0); 174e17d84d6SAndreas Gohr if($linkit) { 175e17d84d6SAndreas Gohr $title = $conf['title'] . tpl_getLang('adjunct_linked_logo_text'); 176e17d84d6SAndreas Gohr } else { 177e17d84d6SAndreas Gohr $title = tpl_getLang('adjunct_start_logo_text') . $conf['title']; 178e17d84d6SAndreas Gohr } 179e17d84d6SAndreas Gohr 1803a6eaa0bSAndreas Gohr $desktop = self::getResizedImgTag( 1813a6eaa0bSAndreas Gohr 'img', 1823a6eaa0bSAndreas Gohr array( 1833a6eaa0bSAndreas Gohr 'class' => 'mobile-hide', 184*e302d67fSMichael Große 'src' => array('wiki:logo-wide.png', 'wiki:logo.png'), 185e17d84d6SAndreas Gohr 'alt' => $title, 1863a6eaa0bSAndreas Gohr ), 1873a6eaa0bSAndreas Gohr 0, 0 1883a6eaa0bSAndreas Gohr ); 1893a6eaa0bSAndreas Gohr $mobile = self::getResizedImgTag( 1903a6eaa0bSAndreas Gohr 'img', 1913a6eaa0bSAndreas Gohr array( 1923a6eaa0bSAndreas Gohr 'class' => 'mobile-only', 193*e302d67fSMichael Große 'src' => array('wiki:logo-32x32.png', 'wiki:favicon.png', 'wiki:logo-square.png', 'wiki:logo.png'), 194e17d84d6SAndreas Gohr 'alt' => $title, 1953a6eaa0bSAndreas Gohr ), 1963a6eaa0bSAndreas Gohr 32, 32 1973a6eaa0bSAndreas Gohr ); 1983a6eaa0bSAndreas Gohr 1993a6eaa0bSAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 200e17d84d6SAndreas Gohr if($linkit) { 2013a6eaa0bSAndreas Gohr tpl_link(wl(), $desktop, 'accesskey="h" title="[H]"'); 2023a6eaa0bSAndreas Gohr tpl_link(wl(), $mobile, 'accesskey="h" title="[H]"'); 203e17d84d6SAndreas Gohr } else { 204e17d84d6SAndreas Gohr echo $desktop; 205e17d84d6SAndreas Gohr echo $mobile; 2063a6eaa0bSAndreas Gohr } 2073a6eaa0bSAndreas Gohr } 2082387fd46SAndreas Gohr} 209