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, 202387fd46SAndreas Gohr ); 212387fd46SAndreas Gohr 222387fd46SAndreas Gohr /** 232387fd46SAndreas Gohr * Get the singleton instance 242387fd46SAndreas Gohr * 252387fd46SAndreas Gohr * @return Template 262387fd46SAndreas Gohr */ 272387fd46SAndreas Gohr public static function getInstance() { 282387fd46SAndreas Gohr static $instance = null; 292387fd46SAndreas Gohr if($instance === null) $instance = new Template(); 302387fd46SAndreas Gohr return $instance; 312387fd46SAndreas Gohr } 322387fd46SAndreas Gohr 332387fd46SAndreas Gohr /** 342387fd46SAndreas Gohr * Template constructor. 352387fd46SAndreas Gohr */ 362387fd46SAndreas Gohr protected function __construct() { 372387fd46SAndreas Gohr $this->initializePlugins(); 382387fd46SAndreas Gohr } 392387fd46SAndreas Gohr 402387fd46SAndreas Gohr /** 412387fd46SAndreas Gohr * Load all the plugins we support directly 422387fd46SAndreas Gohr */ 432387fd46SAndreas Gohr protected function initializePlugins() { 442387fd46SAndreas Gohr $this->plugins['sqlite'] = plugin_load('helper', 'sqlite'); 452387fd46SAndreas Gohr if($this->plugins['sqlite']) { 462387fd46SAndreas Gohr $this->plugins['tagging'] = plugin_load('helper', 'tagging'); 472387fd46SAndreas Gohr } 482387fd46SAndreas Gohr } 492387fd46SAndreas Gohr 502387fd46SAndreas Gohr /** 512387fd46SAndreas Gohr * Get all the tabs to display 522387fd46SAndreas Gohr * 532387fd46SAndreas Gohr * @return array 542387fd46SAndreas Gohr */ 552387fd46SAndreas Gohr public function getMetaBoxTabs() { 562387fd46SAndreas Gohr global $lang; 572387fd46SAndreas Gohr $tabs = array(); 582387fd46SAndreas Gohr 592387fd46SAndreas Gohr $toc = tpl_toc(true); 602387fd46SAndreas Gohr if($toc) { 612387fd46SAndreas Gohr $tabs[] = array( 622387fd46SAndreas Gohr 'id' => 'spr__tab-toc', 632387fd46SAndreas Gohr 'label' => $lang['toc'], 642387fd46SAndreas Gohr 'tab' => $toc, 652387fd46SAndreas Gohr 'count' => null, 662387fd46SAndreas Gohr ); 672387fd46SAndreas Gohr } 682387fd46SAndreas Gohr 692387fd46SAndreas Gohr if($this->plugins['tagging']) { 702387fd46SAndreas Gohr $tabs[] = array( 712387fd46SAndreas Gohr 'id' => 'spr__tab-tags', 722387fd46SAndreas Gohr 'label' => tpl_getLang('tab_tags'), 732387fd46SAndreas Gohr 'tab' => $this->plugins['tagging']->tpl_tags(false), 742387fd46SAndreas Gohr 'count' => null, // FIXME 752387fd46SAndreas Gohr ); 762387fd46SAndreas Gohr } 772387fd46SAndreas Gohr 782387fd46SAndreas Gohr // fixme add magicmatcher info 792387fd46SAndreas Gohr 802387fd46SAndreas Gohr return $tabs; 812387fd46SAndreas Gohr } 8206cdf148SAndreas Gohr 8306cdf148SAndreas Gohr /** 8406cdf148SAndreas Gohr * Creates an image tag and includes the first found image correctly resized 8506cdf148SAndreas Gohr * 8606cdf148SAndreas Gohr * @param string $tag 8706cdf148SAndreas Gohr * @param array $attributes 8806cdf148SAndreas Gohr * @param int $w 8906cdf148SAndreas Gohr * @param int $h 9006cdf148SAndreas Gohr * @return string 9106cdf148SAndreas Gohr */ 9206cdf148SAndreas Gohr public static function getResizedImgTag($tag, $attributes, $w, $h) { 9306cdf148SAndreas Gohr $attr = ''; 9406cdf148SAndreas Gohr $medias = array(); 9506cdf148SAndreas Gohr 9606cdf148SAndreas Gohr // the attribute having an array defines where the image goes 9706cdf148SAndreas Gohr foreach($attributes as $attribute => $data) { 9806cdf148SAndreas Gohr if(is_array($data)) { 9906cdf148SAndreas Gohr $medias = $data; 10006cdf148SAndreas Gohr $attr = $attribute; 10106cdf148SAndreas Gohr } 10206cdf148SAndreas Gohr } 10306cdf148SAndreas Gohr // if the image attribute could not be found return 10406cdf148SAndreas Gohr if(!$attr || !$medias) return ''; 10506cdf148SAndreas Gohr 10606cdf148SAndreas Gohr // try all medias until an existing one is found 10706cdf148SAndreas Gohr $media = ''; 10806cdf148SAndreas Gohr foreach($medias as $media) { 10906cdf148SAndreas Gohr if(file_exists(mediaFN($media))) break; 11006cdf148SAndreas Gohr $media = ''; 11106cdf148SAndreas Gohr } 11206cdf148SAndreas Gohr if($media === '') return ''; 11306cdf148SAndreas Gohr 11406cdf148SAndreas Gohr // replace the array 11506cdf148SAndreas Gohr $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); 11606cdf148SAndreas Gohr $attributes[$attr] = $media; 11706cdf148SAndreas Gohr 11806cdf148SAndreas Gohr // return the full tag 1199dbc42beSAndreas Gohr return '<' . $tag . ' ' . buildAttributes($attributes) . ' />' . "\n"; 12006cdf148SAndreas Gohr } 1213a6eaa0bSAndreas Gohr 1223a6eaa0bSAndreas Gohr /** 1233a6eaa0bSAndreas Gohr * Embed the main logo 1243a6eaa0bSAndreas Gohr * 1253a6eaa0bSAndreas Gohr * Tries a few different locations 1263a6eaa0bSAndreas Gohr */ 1273a6eaa0bSAndreas Gohr public function mainLogo() { 1283a6eaa0bSAndreas Gohr global $conf; 1293a6eaa0bSAndreas Gohr 130*e17d84d6SAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 131*e17d84d6SAndreas Gohr $linkit = (strcmp(wl(), $_SERVER['REQUEST_URI']) !== 0); 132*e17d84d6SAndreas Gohr if($linkit) { 133*e17d84d6SAndreas Gohr $title = $conf['title'] . tpl_getLang('adjunct_linked_logo_text'); 134*e17d84d6SAndreas Gohr } else { 135*e17d84d6SAndreas Gohr $title = tpl_getLang('adjunct_start_logo_text') . $conf['title']; 136*e17d84d6SAndreas Gohr } 137*e17d84d6SAndreas Gohr 1383a6eaa0bSAndreas Gohr $desktop = self::getResizedImgTag( 1393a6eaa0bSAndreas Gohr 'img', 1403a6eaa0bSAndreas Gohr array( 1413a6eaa0bSAndreas Gohr 'class' => 'mobile-hide', 1423a6eaa0bSAndreas Gohr 'src' => array(tpl_getConf('logo'), 'wiki:logo-wide.png', 'wiki:logo.png'), 143*e17d84d6SAndreas Gohr 'alt' => $title, 1443a6eaa0bSAndreas Gohr ), 1453a6eaa0bSAndreas Gohr 0, 0 1463a6eaa0bSAndreas Gohr ); 1473a6eaa0bSAndreas Gohr $mobile = self::getResizedImgTag( 1483a6eaa0bSAndreas Gohr 'img', 1493a6eaa0bSAndreas Gohr array( 1503a6eaa0bSAndreas Gohr 'class' => 'mobile-only', 1513a6eaa0bSAndreas Gohr 'src' => array('wiki:logo-32x32.png', 'wiki:favicon.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')), 152*e17d84d6SAndreas Gohr 'alt' => $title, 1533a6eaa0bSAndreas Gohr ), 1543a6eaa0bSAndreas Gohr 32, 32 1553a6eaa0bSAndreas Gohr ); 1563a6eaa0bSAndreas Gohr 1573a6eaa0bSAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 158*e17d84d6SAndreas Gohr if($linkit) { 1593a6eaa0bSAndreas Gohr tpl_link(wl(), $desktop, 'accesskey="h" title="[H]"'); 1603a6eaa0bSAndreas Gohr tpl_link(wl(), $mobile, 'accesskey="h" title="[H]"'); 161*e17d84d6SAndreas Gohr } else { 162*e17d84d6SAndreas Gohr echo $desktop; 163*e17d84d6SAndreas Gohr echo $mobile; 1643a6eaa0bSAndreas Gohr } 1653a6eaa0bSAndreas Gohr } 1662387fd46SAndreas Gohr} 167