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, 20*1f3641a8SMichael 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(); 392387fd46SAndreas Gohr } 402387fd46SAndreas Gohr 412387fd46SAndreas Gohr /** 422387fd46SAndreas Gohr * Load all the plugins we support directly 432387fd46SAndreas Gohr */ 442387fd46SAndreas Gohr protected function initializePlugins() { 452387fd46SAndreas Gohr $this->plugins['sqlite'] = plugin_load('helper', 'sqlite'); 462387fd46SAndreas Gohr if($this->plugins['sqlite']) { 472387fd46SAndreas Gohr $this->plugins['tagging'] = plugin_load('helper', 'tagging'); 48*1f3641a8SMichael Große $this->plugins['magicmatcher'] = plugin_load('syntax', 'magicmatcher_issuelist'); 492387fd46SAndreas Gohr } 502387fd46SAndreas Gohr } 512387fd46SAndreas Gohr 522387fd46SAndreas Gohr /** 532387fd46SAndreas Gohr * Get all the tabs to display 542387fd46SAndreas Gohr * 552387fd46SAndreas Gohr * @return array 562387fd46SAndreas Gohr */ 572387fd46SAndreas Gohr public function getMetaBoxTabs() { 582387fd46SAndreas Gohr global $lang; 592387fd46SAndreas Gohr $tabs = array(); 602387fd46SAndreas Gohr 612387fd46SAndreas Gohr $toc = tpl_toc(true); 622387fd46SAndreas Gohr if($toc) { 632387fd46SAndreas Gohr $tabs[] = array( 642387fd46SAndreas Gohr 'id' => 'spr__tab-toc', 652387fd46SAndreas Gohr 'label' => $lang['toc'], 662387fd46SAndreas Gohr 'tab' => $toc, 672387fd46SAndreas Gohr 'count' => null, 682387fd46SAndreas Gohr ); 692387fd46SAndreas Gohr } 702387fd46SAndreas Gohr 712387fd46SAndreas Gohr if($this->plugins['tagging']) { 722387fd46SAndreas Gohr $tabs[] = array( 732387fd46SAndreas Gohr 'id' => 'spr__tab-tags', 742387fd46SAndreas Gohr 'label' => tpl_getLang('tab_tags'), 752387fd46SAndreas Gohr 'tab' => $this->plugins['tagging']->tpl_tags(false), 762387fd46SAndreas Gohr 'count' => null, // FIXME 772387fd46SAndreas Gohr ); 782387fd46SAndreas Gohr } 792387fd46SAndreas Gohr 80*1f3641a8SMichael Große if ($this->plugins['magicmatcher']) { 81*1f3641a8SMichael Große $tabs[] = array( 82*1f3641a8SMichael Große 'id' => 'spr__tab-issues', 83*1f3641a8SMichael Große 'label' => 'Issues', // FIXME 84*1f3641a8SMichael Große 'tab' => $this->plugins['magicmatcher']->getIssueListHTML(), 85*1f3641a8SMichael Große 'count' => $this->plugins['magicmatcher']->getCountIssues(), 86*1f3641a8SMichael Große ); 87*1f3641a8SMichael Große } 882387fd46SAndreas Gohr 892387fd46SAndreas Gohr return $tabs; 902387fd46SAndreas Gohr } 9106cdf148SAndreas Gohr 9206cdf148SAndreas Gohr /** 9306cdf148SAndreas Gohr * Creates an image tag and includes the first found image correctly resized 9406cdf148SAndreas Gohr * 9506cdf148SAndreas Gohr * @param string $tag 9606cdf148SAndreas Gohr * @param array $attributes 9706cdf148SAndreas Gohr * @param int $w 9806cdf148SAndreas Gohr * @param int $h 9906cdf148SAndreas Gohr * @return string 10006cdf148SAndreas Gohr */ 10106cdf148SAndreas Gohr public static function getResizedImgTag($tag, $attributes, $w, $h) { 10206cdf148SAndreas Gohr $attr = ''; 10306cdf148SAndreas Gohr $medias = array(); 10406cdf148SAndreas Gohr 10506cdf148SAndreas Gohr // the attribute having an array defines where the image goes 10606cdf148SAndreas Gohr foreach($attributes as $attribute => $data) { 10706cdf148SAndreas Gohr if(is_array($data)) { 10806cdf148SAndreas Gohr $medias = $data; 10906cdf148SAndreas Gohr $attr = $attribute; 11006cdf148SAndreas Gohr } 11106cdf148SAndreas Gohr } 11206cdf148SAndreas Gohr // if the image attribute could not be found return 11306cdf148SAndreas Gohr if(!$attr || !$medias) return ''; 11406cdf148SAndreas Gohr 11506cdf148SAndreas Gohr // try all medias until an existing one is found 11606cdf148SAndreas Gohr $media = ''; 11706cdf148SAndreas Gohr foreach($medias as $media) { 11806cdf148SAndreas Gohr if(file_exists(mediaFN($media))) break; 11906cdf148SAndreas Gohr $media = ''; 12006cdf148SAndreas Gohr } 12106cdf148SAndreas Gohr if($media === '') return ''; 12206cdf148SAndreas Gohr 12306cdf148SAndreas Gohr // replace the array 12406cdf148SAndreas Gohr $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); 12506cdf148SAndreas Gohr $attributes[$attr] = $media; 12606cdf148SAndreas Gohr 12706cdf148SAndreas Gohr // return the full tag 1289dbc42beSAndreas Gohr return '<' . $tag . ' ' . buildAttributes($attributes) . ' />' . "\n"; 12906cdf148SAndreas Gohr } 1303a6eaa0bSAndreas Gohr 1313a6eaa0bSAndreas Gohr /** 1323a6eaa0bSAndreas Gohr * Embed the main logo 1333a6eaa0bSAndreas Gohr * 1343a6eaa0bSAndreas Gohr * Tries a few different locations 1353a6eaa0bSAndreas Gohr */ 1363a6eaa0bSAndreas Gohr public function mainLogo() { 1373a6eaa0bSAndreas Gohr global $conf; 1383a6eaa0bSAndreas Gohr 139e17d84d6SAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 140e17d84d6SAndreas Gohr $linkit = (strcmp(wl(), $_SERVER['REQUEST_URI']) !== 0); 141e17d84d6SAndreas Gohr if($linkit) { 142e17d84d6SAndreas Gohr $title = $conf['title'] . tpl_getLang('adjunct_linked_logo_text'); 143e17d84d6SAndreas Gohr } else { 144e17d84d6SAndreas Gohr $title = tpl_getLang('adjunct_start_logo_text') . $conf['title']; 145e17d84d6SAndreas Gohr } 146e17d84d6SAndreas Gohr 1473a6eaa0bSAndreas Gohr $desktop = self::getResizedImgTag( 1483a6eaa0bSAndreas Gohr 'img', 1493a6eaa0bSAndreas Gohr array( 1503a6eaa0bSAndreas Gohr 'class' => 'mobile-hide', 1513a6eaa0bSAndreas Gohr 'src' => array(tpl_getConf('logo'), 'wiki:logo-wide.png', 'wiki:logo.png'), 152e17d84d6SAndreas Gohr 'alt' => $title, 1533a6eaa0bSAndreas Gohr ), 1543a6eaa0bSAndreas Gohr 0, 0 1553a6eaa0bSAndreas Gohr ); 1563a6eaa0bSAndreas Gohr $mobile = self::getResizedImgTag( 1573a6eaa0bSAndreas Gohr 'img', 1583a6eaa0bSAndreas Gohr array( 1593a6eaa0bSAndreas Gohr 'class' => 'mobile-only', 1603a6eaa0bSAndreas Gohr 'src' => array('wiki:logo-32x32.png', 'wiki:favicon.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')), 161e17d84d6SAndreas Gohr 'alt' => $title, 1623a6eaa0bSAndreas Gohr ), 1633a6eaa0bSAndreas Gohr 32, 32 1643a6eaa0bSAndreas Gohr ); 1653a6eaa0bSAndreas Gohr 1663a6eaa0bSAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 167e17d84d6SAndreas Gohr if($linkit) { 1683a6eaa0bSAndreas Gohr tpl_link(wl(), $desktop, 'accesskey="h" title="[H]"'); 1693a6eaa0bSAndreas Gohr tpl_link(wl(), $mobile, 'accesskey="h" title="[H]"'); 170e17d84d6SAndreas Gohr } else { 171e17d84d6SAndreas Gohr echo $desktop; 172e17d84d6SAndreas Gohr echo $mobile; 1733a6eaa0bSAndreas Gohr } 1743a6eaa0bSAndreas Gohr } 1752387fd46SAndreas Gohr} 176