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 } 82*06cdf148SAndreas Gohr 83*06cdf148SAndreas Gohr /** 84*06cdf148SAndreas Gohr * Creates an image tag and includes the first found image correctly resized 85*06cdf148SAndreas Gohr * 86*06cdf148SAndreas Gohr * @param string $tag 87*06cdf148SAndreas Gohr * @param array $attributes 88*06cdf148SAndreas Gohr * @param int $w 89*06cdf148SAndreas Gohr * @param int $h 90*06cdf148SAndreas Gohr * @return string 91*06cdf148SAndreas Gohr */ 92*06cdf148SAndreas Gohr public static function getResizedImgTag($tag, $attributes, $w, $h) { 93*06cdf148SAndreas Gohr $attr = ''; 94*06cdf148SAndreas Gohr $medias = array(); 95*06cdf148SAndreas Gohr 96*06cdf148SAndreas Gohr // the attribute having an array defines where the image goes 97*06cdf148SAndreas Gohr foreach($attributes as $attribute => $data) { 98*06cdf148SAndreas Gohr if(is_array($data)) { 99*06cdf148SAndreas Gohr $medias = $data; 100*06cdf148SAndreas Gohr $attr = $attribute; 101*06cdf148SAndreas Gohr } 102*06cdf148SAndreas Gohr } 103*06cdf148SAndreas Gohr // if the image attribute could not be found return 104*06cdf148SAndreas Gohr if(!$attr || !$medias) return ''; 105*06cdf148SAndreas Gohr 106*06cdf148SAndreas Gohr // try all medias until an existing one is found 107*06cdf148SAndreas Gohr $media = ''; 108*06cdf148SAndreas Gohr foreach($medias as $media) { 109*06cdf148SAndreas Gohr if(file_exists(mediaFN($media))) break; 110*06cdf148SAndreas Gohr $media = ''; 111*06cdf148SAndreas Gohr } 112*06cdf148SAndreas Gohr if($media === '') return ''; 113*06cdf148SAndreas Gohr 114*06cdf148SAndreas Gohr // replace the array 115*06cdf148SAndreas Gohr $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); 116*06cdf148SAndreas Gohr $attributes[$attr] = $media; 117*06cdf148SAndreas Gohr 118*06cdf148SAndreas Gohr // return the full tag 119*06cdf148SAndreas Gohr return '<' . $tag . ' ' . buildAttributes($attributes) . ' />'; 120*06cdf148SAndreas Gohr } 1212387fd46SAndreas Gohr} 122