1<?php 2 3namespace dokuwiki\template\sprintdoc; 4 5/** 6 * Class Template 7 * 8 * provides additional logic for the sprintdoc template 9 * 10 * @package dokuwiki\template\sprintdoc 11 */ 12class Template { 13 14 /** 15 * @var array loaded plugins 16 */ 17 protected $plugins = array( 18 'sqlite' => null, 19 'tagging' => null, 20 ); 21 22 /** 23 * Get the singleton instance 24 * 25 * @return Template 26 */ 27 public static function getInstance() { 28 static $instance = null; 29 if($instance === null) $instance = new Template(); 30 return $instance; 31 } 32 33 /** 34 * Template constructor. 35 */ 36 protected function __construct() { 37 $this->initializePlugins(); 38 } 39 40 /** 41 * Load all the plugins we support directly 42 */ 43 protected function initializePlugins() { 44 $this->plugins['sqlite'] = plugin_load('helper', 'sqlite'); 45 if($this->plugins['sqlite']) { 46 $this->plugins['tagging'] = plugin_load('helper', 'tagging'); 47 } 48 } 49 50 /** 51 * Get all the tabs to display 52 * 53 * @return array 54 */ 55 public function getMetaBoxTabs() { 56 global $lang; 57 $tabs = array(); 58 59 $toc = tpl_toc(true); 60 if($toc) { 61 $tabs[] = array( 62 'id' => 'spr__tab-toc', 63 'label' => $lang['toc'], 64 'tab' => $toc, 65 'count' => null, 66 ); 67 } 68 69 if($this->plugins['tagging']) { 70 $tabs[] = array( 71 'id' => 'spr__tab-tags', 72 'label' => tpl_getLang('tab_tags'), 73 'tab' => $this->plugins['tagging']->tpl_tags(false), 74 'count' => null, // FIXME 75 ); 76 } 77 78 // fixme add magicmatcher info 79 80 return $tabs; 81 } 82 83 /** 84 * Creates an image tag and includes the first found image correctly resized 85 * 86 * @param string $tag 87 * @param array $attributes 88 * @param int $w 89 * @param int $h 90 * @return string 91 */ 92 public static function getResizedImgTag($tag, $attributes, $w, $h) { 93 $attr = ''; 94 $medias = array(); 95 96 // the attribute having an array defines where the image goes 97 foreach($attributes as $attribute => $data) { 98 if(is_array($data)) { 99 $medias = $data; 100 $attr = $attribute; 101 } 102 } 103 // if the image attribute could not be found return 104 if(!$attr || !$medias) return ''; 105 106 // try all medias until an existing one is found 107 $media = ''; 108 foreach($medias as $media) { 109 if(file_exists(mediaFN($media))) break; 110 $media = ''; 111 } 112 if($media === '') return ''; 113 114 // replace the array 115 $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); 116 $attributes[$attr] = $media; 117 118 // return the full tag 119 return '<' . $tag . ' ' . buildAttributes($attributes) . ' />' . "\n"; 120 } 121 122 /** 123 * Embed the main logo 124 * 125 * Tries a few different locations 126 */ 127 public function mainLogo() { 128 global $conf; 129 130 // homepage logo should not link to itself (BITV accessibility requirement) 131 $linkit = (strcmp(wl(), $_SERVER['REQUEST_URI']) !== 0); 132 if($linkit) { 133 $title = $conf['title'] . tpl_getLang('adjunct_linked_logo_text'); 134 } else { 135 $title = tpl_getLang('adjunct_start_logo_text') . $conf['title']; 136 } 137 138 $desktop = self::getResizedImgTag( 139 'img', 140 array( 141 'class' => 'mobile-hide', 142 'src' => array(tpl_getConf('logo'), 'wiki:logo-wide.png', 'wiki:logo.png'), 143 'alt' => $title, 144 ), 145 0, 0 146 ); 147 $mobile = self::getResizedImgTag( 148 'img', 149 array( 150 'class' => 'mobile-only', 151 'src' => array('wiki:logo-32x32.png', 'wiki:favicon.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')), 152 'alt' => $title, 153 ), 154 32, 32 155 ); 156 157 // homepage logo should not link to itself (BITV accessibility requirement) 158 if($linkit) { 159 tpl_link(wl(), $desktop, 'accesskey="h" title="[H]"'); 160 tpl_link(wl(), $mobile, 'accesskey="h" title="[H]"'); 161 } else { 162 echo $desktop; 163 echo $mobile; 164 } 165 } 166} 167