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(); 38*cad2e674SAndreas Gohr 39*cad2e674SAndreas Gohr /** @var \Doku_Event_Handler */ 40*cad2e674SAndreas Gohr global $EVENT_HANDLER; 41*cad2e674SAndreas Gohr $EVENT_HANDLER->register_hook('PLUGIN_TPLINC_LOCATIONS_SET', 'BEFORE', $this, 'registerIncludes'); 42*cad2e674SAndreas Gohr } 43*cad2e674SAndreas Gohr 44*cad2e674SAndreas Gohr /** 45*cad2e674SAndreas Gohr * Makes include position info available to the tplinc plugin 46*cad2e674SAndreas Gohr * 47*cad2e674SAndreas Gohr * @param \Doku_Event $event 48*cad2e674SAndreas Gohr */ 49*cad2e674SAndreas Gohr public function registerIncludes(\Doku_Event $event) { 50*cad2e674SAndreas Gohr $event->data['footer'] = 'Footer below the page content'; 51*cad2e674SAndreas Gohr } 52*cad2e674SAndreas Gohr 53*cad2e674SAndreas Gohr /** 54*cad2e674SAndreas Gohr * Get the content to include from the tplinc plugin 55*cad2e674SAndreas Gohr * 56*cad2e674SAndreas Gohr * prefix and postfix are only added when there actually is any content 57*cad2e674SAndreas Gohr * 58*cad2e674SAndreas Gohr * @param string $location 59*cad2e674SAndreas Gohr * @param string $pre prepend this before the content 60*cad2e674SAndreas Gohr * @param string $post append this to the content 61*cad2e674SAndreas Gohr * @return string 62*cad2e674SAndreas Gohr */ 63*cad2e674SAndreas Gohr public function getInclude($location, $pre = '', $post = '') { 64*cad2e674SAndreas Gohr if(!$this->plugins['tplinc']) return ''; 65*cad2e674SAndreas Gohr $content = $this->plugins['tplinc']->renderIncludes($location); 66*cad2e674SAndreas Gohr if($content === '') return ''; 67*cad2e674SAndreas Gohr return $pre . $content . $post; 682387fd46SAndreas Gohr } 692387fd46SAndreas Gohr 702387fd46SAndreas Gohr /** 712387fd46SAndreas Gohr * Load all the plugins we support directly 722387fd46SAndreas Gohr */ 732387fd46SAndreas Gohr protected function initializePlugins() { 742387fd46SAndreas Gohr $this->plugins['sqlite'] = plugin_load('helper', 'sqlite'); 752387fd46SAndreas Gohr if($this->plugins['sqlite']) { 762387fd46SAndreas Gohr $this->plugins['tagging'] = plugin_load('helper', 'tagging'); 772387fd46SAndreas Gohr } 78*cad2e674SAndreas Gohr $this->plugins['tplinc'] = plugin_load('helper', 'tplinc'); 792387fd46SAndreas Gohr } 802387fd46SAndreas Gohr 812387fd46SAndreas Gohr /** 822387fd46SAndreas Gohr * Get all the tabs to display 832387fd46SAndreas Gohr * 842387fd46SAndreas Gohr * @return array 852387fd46SAndreas Gohr */ 862387fd46SAndreas Gohr public function getMetaBoxTabs() { 872387fd46SAndreas Gohr global $lang; 882387fd46SAndreas Gohr $tabs = array(); 892387fd46SAndreas Gohr 902387fd46SAndreas Gohr $toc = tpl_toc(true); 912387fd46SAndreas Gohr if($toc) { 922387fd46SAndreas Gohr $tabs[] = array( 932387fd46SAndreas Gohr 'id' => 'spr__tab-toc', 942387fd46SAndreas Gohr 'label' => $lang['toc'], 952387fd46SAndreas Gohr 'tab' => $toc, 962387fd46SAndreas Gohr 'count' => null, 972387fd46SAndreas Gohr ); 982387fd46SAndreas Gohr } 992387fd46SAndreas Gohr 1002387fd46SAndreas Gohr if($this->plugins['tagging']) { 1012387fd46SAndreas Gohr $tabs[] = array( 1022387fd46SAndreas Gohr 'id' => 'spr__tab-tags', 1032387fd46SAndreas Gohr 'label' => tpl_getLang('tab_tags'), 1042387fd46SAndreas Gohr 'tab' => $this->plugins['tagging']->tpl_tags(false), 1052387fd46SAndreas Gohr 'count' => null, // FIXME 1062387fd46SAndreas Gohr ); 1072387fd46SAndreas Gohr } 1082387fd46SAndreas Gohr 1092387fd46SAndreas Gohr // fixme add magicmatcher info 1102387fd46SAndreas Gohr 1112387fd46SAndreas Gohr return $tabs; 1122387fd46SAndreas Gohr } 11306cdf148SAndreas Gohr 11406cdf148SAndreas Gohr /** 11506cdf148SAndreas Gohr * Creates an image tag and includes the first found image correctly resized 11606cdf148SAndreas Gohr * 11706cdf148SAndreas Gohr * @param string $tag 11806cdf148SAndreas Gohr * @param array $attributes 11906cdf148SAndreas Gohr * @param int $w 12006cdf148SAndreas Gohr * @param int $h 12106cdf148SAndreas Gohr * @return string 12206cdf148SAndreas Gohr */ 12306cdf148SAndreas Gohr public static function getResizedImgTag($tag, $attributes, $w, $h) { 12406cdf148SAndreas Gohr $attr = ''; 12506cdf148SAndreas Gohr $medias = array(); 12606cdf148SAndreas Gohr 12706cdf148SAndreas Gohr // the attribute having an array defines where the image goes 12806cdf148SAndreas Gohr foreach($attributes as $attribute => $data) { 12906cdf148SAndreas Gohr if(is_array($data)) { 13006cdf148SAndreas Gohr $medias = $data; 13106cdf148SAndreas Gohr $attr = $attribute; 13206cdf148SAndreas Gohr } 13306cdf148SAndreas Gohr } 13406cdf148SAndreas Gohr // if the image attribute could not be found return 13506cdf148SAndreas Gohr if(!$attr || !$medias) return ''; 13606cdf148SAndreas Gohr 13706cdf148SAndreas Gohr // try all medias until an existing one is found 13806cdf148SAndreas Gohr $media = ''; 13906cdf148SAndreas Gohr foreach($medias as $media) { 14006cdf148SAndreas Gohr if(file_exists(mediaFN($media))) break; 14106cdf148SAndreas Gohr $media = ''; 14206cdf148SAndreas Gohr } 14306cdf148SAndreas Gohr if($media === '') return ''; 14406cdf148SAndreas Gohr 14506cdf148SAndreas Gohr // replace the array 14606cdf148SAndreas Gohr $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); 14706cdf148SAndreas Gohr $attributes[$attr] = $media; 14806cdf148SAndreas Gohr 14906cdf148SAndreas Gohr // return the full tag 1509dbc42beSAndreas Gohr return '<' . $tag . ' ' . buildAttributes($attributes) . ' />' . "\n"; 15106cdf148SAndreas Gohr } 1523a6eaa0bSAndreas Gohr 1533a6eaa0bSAndreas Gohr /** 1543a6eaa0bSAndreas Gohr * Embed the main logo 1553a6eaa0bSAndreas Gohr * 1563a6eaa0bSAndreas Gohr * Tries a few different locations 1573a6eaa0bSAndreas Gohr */ 1583a6eaa0bSAndreas Gohr public function mainLogo() { 1593a6eaa0bSAndreas Gohr global $conf; 1603a6eaa0bSAndreas Gohr 161e17d84d6SAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 162e17d84d6SAndreas Gohr $linkit = (strcmp(wl(), $_SERVER['REQUEST_URI']) !== 0); 163e17d84d6SAndreas Gohr if($linkit) { 164e17d84d6SAndreas Gohr $title = $conf['title'] . tpl_getLang('adjunct_linked_logo_text'); 165e17d84d6SAndreas Gohr } else { 166e17d84d6SAndreas Gohr $title = tpl_getLang('adjunct_start_logo_text') . $conf['title']; 167e17d84d6SAndreas Gohr } 168e17d84d6SAndreas Gohr 1693a6eaa0bSAndreas Gohr $desktop = self::getResizedImgTag( 1703a6eaa0bSAndreas Gohr 'img', 1713a6eaa0bSAndreas Gohr array( 1723a6eaa0bSAndreas Gohr 'class' => 'mobile-hide', 1733a6eaa0bSAndreas Gohr 'src' => array(tpl_getConf('logo'), 'wiki:logo-wide.png', 'wiki:logo.png'), 174e17d84d6SAndreas Gohr 'alt' => $title, 1753a6eaa0bSAndreas Gohr ), 1763a6eaa0bSAndreas Gohr 0, 0 1773a6eaa0bSAndreas Gohr ); 1783a6eaa0bSAndreas Gohr $mobile = self::getResizedImgTag( 1793a6eaa0bSAndreas Gohr 'img', 1803a6eaa0bSAndreas Gohr array( 1813a6eaa0bSAndreas Gohr 'class' => 'mobile-only', 1823a6eaa0bSAndreas Gohr 'src' => array('wiki:logo-32x32.png', 'wiki:favicon.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')), 183e17d84d6SAndreas Gohr 'alt' => $title, 1843a6eaa0bSAndreas Gohr ), 1853a6eaa0bSAndreas Gohr 32, 32 1863a6eaa0bSAndreas Gohr ); 1873a6eaa0bSAndreas Gohr 1883a6eaa0bSAndreas Gohr // homepage logo should not link to itself (BITV accessibility requirement) 189e17d84d6SAndreas Gohr if($linkit) { 1903a6eaa0bSAndreas Gohr tpl_link(wl(), $desktop, 'accesskey="h" title="[H]"'); 1913a6eaa0bSAndreas Gohr tpl_link(wl(), $mobile, 'accesskey="h" title="[H]"'); 192e17d84d6SAndreas Gohr } else { 193e17d84d6SAndreas Gohr echo $desktop; 194e17d84d6SAndreas Gohr echo $mobile; 1953a6eaa0bSAndreas Gohr } 1963a6eaa0bSAndreas Gohr } 1972387fd46SAndreas Gohr} 198