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 11906cdf148SAndreas Gohr return '<' . $tag . ' ' . buildAttributes($attributes) . ' />'; 12006cdf148SAndreas Gohr } 121*3a6eaa0bSAndreas Gohr 122*3a6eaa0bSAndreas Gohr /** 123*3a6eaa0bSAndreas Gohr * Embed the main logo 124*3a6eaa0bSAndreas Gohr * 125*3a6eaa0bSAndreas Gohr * Tries a few different locations 126*3a6eaa0bSAndreas Gohr */ 127*3a6eaa0bSAndreas Gohr public function mainLogo() { 128*3a6eaa0bSAndreas Gohr global $conf; 129*3a6eaa0bSAndreas Gohr 130*3a6eaa0bSAndreas Gohr $desktop = self::getResizedImgTag( 131*3a6eaa0bSAndreas Gohr 'img', 132*3a6eaa0bSAndreas Gohr array( 133*3a6eaa0bSAndreas Gohr 'class' => 'mobile-hide', 134*3a6eaa0bSAndreas Gohr 'src' => array(tpl_getConf('logo'), 'wiki:logo-wide.png', 'wiki:logo.png'), 135*3a6eaa0bSAndreas Gohr 'alt' => tpl_getLang('adjunct_start_logo_text') . $conf['title'], 136*3a6eaa0bSAndreas Gohr ), 137*3a6eaa0bSAndreas Gohr 0, 0 138*3a6eaa0bSAndreas Gohr ); 139*3a6eaa0bSAndreas Gohr $mobile = self::getResizedImgTag( 140*3a6eaa0bSAndreas Gohr 'img', 141*3a6eaa0bSAndreas Gohr array( 142*3a6eaa0bSAndreas Gohr 'class' => 'mobile-only', 143*3a6eaa0bSAndreas Gohr 'src' => array('wiki:logo-32x32.png', 'wiki:favicon.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')), 144*3a6eaa0bSAndreas Gohr 'alt' => tpl_getLang('adjunct_start_logo_text') . $conf['title'], 145*3a6eaa0bSAndreas Gohr ), 146*3a6eaa0bSAndreas Gohr 32, 32 147*3a6eaa0bSAndreas Gohr ); 148*3a6eaa0bSAndreas Gohr 149*3a6eaa0bSAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 150*3a6eaa0bSAndreas Gohr if(strcmp(wl(), $_SERVER['REQUEST_URI']) === 0) { 151*3a6eaa0bSAndreas Gohr echo $desktop; 152*3a6eaa0bSAndreas Gohr echo $mobile; 153*3a6eaa0bSAndreas Gohr } else { 154*3a6eaa0bSAndreas Gohr tpl_link(wl(), $desktop, 'accesskey="h" title="[H]"'); 155*3a6eaa0bSAndreas Gohr tpl_link(wl(), $mobile, 'accesskey="h" title="[H]"'); 156*3a6eaa0bSAndreas Gohr } 157*3a6eaa0bSAndreas Gohr } 1582387fd46SAndreas Gohr} 159