16b13307fSandi<?php 26b13307fSandi/** 36b13307fSandi * DokuWiki template functions 46b13307fSandi * 56b13307fSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 66b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 76b13307fSandi */ 824870174SAndreas Gohruse dokuwiki\ActionRouter; 924870174SAndreas Gohruse dokuwiki\Action\Exception\FatalException; 1024870174SAndreas Gohruse dokuwiki\Extension\PluginInterface; 1124870174SAndreas Gohruse dokuwiki\Ui\Admin; 1224870174SAndreas Gohruse dokuwiki\StyleUtils; 1324870174SAndreas Gohruse dokuwiki\Menu\Item\AbstractItem; 1424870174SAndreas Gohruse dokuwiki\Form\Form; 1524870174SAndreas Gohruse dokuwiki\Menu\MobileMenu; 1624870174SAndreas Gohruse dokuwiki\Ui\Subscribe; 17e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 18e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event; 192cd6cc0aSAndreas Gohruse dokuwiki\File\PageResolver; 20e1d9dcc8SAndreas Gohr 216b13307fSandi/** 22ac7a515fSAndreas Gohr * Access a template file 23ac7a515fSAndreas Gohr * 24ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses 25ac7a515fSAndreas Gohr * default template if the custom version doesn't exist. 265a892029SAndreas Gohr * 275a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 28ac7a515fSAndreas Gohr * @param string $file 29ac7a515fSAndreas Gohr * @return string 305a892029SAndreas Gohr */ 31d868eb89SAndreas Gohrfunction template($file) 32d868eb89SAndreas Gohr{ 335a892029SAndreas Gohr global $conf; 345a892029SAndreas Gohr 35ac7a515fSAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 36ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 375a892029SAndreas Gohr 38ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 395a892029SAndreas Gohr} 405a892029SAndreas Gohr 41c4766956SAndreas Gohr/** 42c4766956SAndreas Gohr * Convenience function to access template dir from local FS 43c4766956SAndreas Gohr * 44c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant 45c4766956SAndreas Gohr * 46c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 47afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 48ac7a515fSAndreas Gohr * @return string 49c4766956SAndreas Gohr */ 50d868eb89SAndreas Gohrfunction tpl_incdir($tpl = '') 51d868eb89SAndreas Gohr{ 5275b14482SAndreas Gohr global $conf; 53afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 54afb2c082SAndreas Gohr return DOKU_INC.'lib/tpl/'.$tpl.'/'; 55c4766956SAndreas Gohr} 56c4766956SAndreas Gohr 57c4766956SAndreas Gohr/** 58c4766956SAndreas Gohr * Convenience function to access template dir from web 59c4766956SAndreas Gohr * 60c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 61c4766956SAndreas Gohr * 62c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 63afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 64ac7a515fSAndreas Gohr * @return string 65c4766956SAndreas Gohr */ 66d868eb89SAndreas Gohrfunction tpl_basedir($tpl = '') 67d868eb89SAndreas Gohr{ 6875b14482SAndreas Gohr global $conf; 69afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 70dcd4911eSMichael Hamann return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 71c4766956SAndreas Gohr} 72c4766956SAndreas Gohr 735a892029SAndreas Gohr/** 746b13307fSandi * Print the content 756b13307fSandi * 766b13307fSandi * This function is used for printing all the usual content 776b13307fSandi * (defined by the global $ACT var) by calling the appropriate 786b13307fSandi * outputfunction(s) from html.php 796b13307fSandi * 80ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 81ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 826b13307fSandi * 836b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 8442ea7f44SGerrit Uitslag * 85ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 86ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 87ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 88ac7a515fSAndreas Gohr * @return bool true if any output 896b13307fSandi */ 90d868eb89SAndreas Gohrfunction tpl_content($prependTOC = true) 91d868eb89SAndreas Gohr{ 927ea0913cSchris global $ACT; 93b8595a66SAndreas Gohr global $INFO; 94b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 957ea0913cSchris 967ea0913cSchris ob_start(); 97cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 987ea0913cSchris $html_output = ob_get_clean(); 99cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 10054e95700STom N Harris 10154e95700STom N Harris return !empty($html_output); 1027ea0913cSchris} 1037ea0913cSchris 104ac7a515fSAndreas Gohr/** 105ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 106ac7a515fSAndreas Gohr * 107ac7a515fSAndreas Gohr * @return bool 108ac7a515fSAndreas Gohr */ 109d868eb89SAndreas Gohrfunction tpl_content_core() 110d868eb89SAndreas Gohr{ 11124870174SAndreas Gohr $router = ActionRouter::getInstance(); 112952acff9SAndreas Gohr try { 113952acff9SAndreas Gohr $router->getAction()->tplContent(); 11424870174SAndreas Gohr } catch(FatalException $e) { 115952acff9SAndreas Gohr // there was no content for the action 116952acff9SAndreas Gohr msg(hsc($e->getMessage()), -1); 11754e95700STom N Harris return false; 1186b13307fSandi } 11954e95700STom N Harris return true; 1206b13307fSandi} 1216b13307fSandi 122c19fe9c0Sandi/** 123b8595a66SAndreas Gohr * Places the TOC where the function is called 124b8595a66SAndreas Gohr * 125b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 126b8595a66SAndreas Gohr * a false argument 127b8595a66SAndreas Gohr * 128b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 12942ea7f44SGerrit Uitslag * 130ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 131ac7a515fSAndreas Gohr * @return string 132b8595a66SAndreas Gohr */ 133d868eb89SAndreas Gohrfunction tpl_toc($return = false) 134d868eb89SAndreas Gohr{ 135b8595a66SAndreas Gohr global $TOC; 136b8595a66SAndreas Gohr global $ACT; 137b8595a66SAndreas Gohr global $ID; 138b8595a66SAndreas Gohr global $REV; 139b8595a66SAndreas Gohr global $INFO; 140851f2e89SAnika Henke global $conf; 141ac7a515fSAndreas Gohr global $INPUT; 14224870174SAndreas Gohr $toc = []; 143b8595a66SAndreas Gohr 144b8595a66SAndreas Gohr if(is_array($TOC)) { 145b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 146b8595a66SAndreas Gohr $toc = $TOC; 1473c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 148b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 149e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 150b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 151b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 152b8595a66SAndreas Gohr } else { 1532bb0d541Schris $tocok = true; 154b8595a66SAndreas Gohr } 15524870174SAndreas Gohr $toc = $meta['description']['tableofcontents'] ?? null; 156851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 15724870174SAndreas Gohr $toc = []; 158b8595a66SAndreas Gohr } 159b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 160a61966c5SChristopher Smith // try to load admin plugin TOC 161e1d9dcc8SAndreas Gohr /** @var $plugin AdminPlugin */ 162a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 163b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 164b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 165b8595a66SAndreas Gohr } 166b8595a66SAndreas Gohr } 167b8595a66SAndreas Gohr 168cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false); 169b8595a66SAndreas Gohr $html = html_TOC($toc); 170b8595a66SAndreas Gohr if($return) return $html; 171b8595a66SAndreas Gohr echo $html; 172ac7a515fSAndreas Gohr return ''; 173b8595a66SAndreas Gohr} 174b8595a66SAndreas Gohr 175b8595a66SAndreas Gohr/** 176c19fe9c0Sandi * Handle the admin page contents 177c19fe9c0Sandi * 178c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 17942ea7f44SGerrit Uitslag * 18042ea7f44SGerrit Uitslag * @return bool 181c19fe9c0Sandi */ 182d868eb89SAndreas Gohrfunction tpl_admin() 183d868eb89SAndreas Gohr{ 184f8cc712eSAndreas Gohr global $INFO; 185b8595a66SAndreas Gohr global $TOC; 186ac7a515fSAndreas Gohr global $INPUT; 18711e2ce22Schris 188b8595a66SAndreas Gohr $plugin = null; 189ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 190ac7a515fSAndreas Gohr if(!empty($class)) { 19111e2ce22Schris $pluginlist = plugin_list('admin'); 19211e2ce22Schris 193ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 19411e2ce22Schris // attempt to load the plugin 195e1d9dcc8SAndreas Gohr /** @var $plugin AdminPlugin */ 196a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 19711e2ce22Schris } 19811e2ce22Schris } 19911e2ce22Schris 20024870174SAndreas Gohr if($plugin instanceof PluginInterface) { 201b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 202b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 203f8cc712eSAndreas Gohr $plugin->html(); 204f8cc712eSAndreas Gohr } else { 20524870174SAndreas Gohr $admin = new Admin(); 2060470c28fSAndreas Gohr $admin->show(); 207f8cc712eSAndreas Gohr } 20854e95700STom N Harris return true; 209c19fe9c0Sandi} 2106b13307fSandi 2116b13307fSandi/** 2126b13307fSandi * Print the correct HTML meta headers 2136b13307fSandi * 2146b13307fSandi * This has to go into the head section of your template. 2156b13307fSandi * 2166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 21742ea7f44SGerrit Uitslag * 218ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 219ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 220ac7a515fSAndreas Gohr * @return bool 2216b13307fSandi */ 222d868eb89SAndreas Gohrfunction tpl_metaheaders($alt = true) 223d868eb89SAndreas Gohr{ 2246b13307fSandi global $ID; 225d98d4540SBen Coburn global $REV; 2266b13307fSandi global $INFO; 22772e0dc37SAndreas Gohr global $JSINFO; 2286b13307fSandi global $ACT; 2294bb1b5aeSAndreas Gohr global $QUERY; 2306b13307fSandi global $lang; 231dc57ef04Sandi global $conf; 2329c438d6cSMichael Hamann global $updateVersion; 233585bf44eSChristopher Smith /** @var Input $INPUT */ 234585bf44eSChristopher Smith global $INPUT; 2356b13307fSandi 2367bff22c0SAndreas Gohr // prepare the head array 23724870174SAndreas Gohr $head = []; 2387bff22c0SAndreas Gohr 239202ac28bSMichael Klier // prepare seed for js and css 240cd997f93SAndreas Gohr $tseed = $updateVersion; 241202ac28bSMichael Klier $depends = getConfigFiles('main'); 24284e76a7eSAndreas Gohr $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini"; 243cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 244cd997f93SAndreas Gohr $tseed = md5($tseed); 2457bff22c0SAndreas Gohr 2466b13307fSandi // the usual stuff 24724870174SAndreas Gohr $head['meta'][] = ['name'=> 'generator', 'content'=> 'DokuWiki']; 24863cf4192Ssarehag if(actionOK('search')) { 24924870174SAndreas Gohr $head['link'][] = [ 25024870174SAndreas Gohr 'rel' => 'search', 25124870174SAndreas Gohr 'type'=> 'application/opensearchdescription+xml', 25224870174SAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 25324870174SAndreas Gohr 'title'=> $conf['title'] 25424870174SAndreas Gohr ]; 25563cf4192Ssarehag } 25663cf4192Ssarehag 25724870174SAndreas Gohr $head['link'][] = ['rel'=> 'start', 'href'=> DOKU_BASE]; 2587aedde2eSGina Haeussge if(actionOK('index')) { 25924870174SAndreas Gohr $head['link'][] = [ 26024870174SAndreas Gohr 'rel' => 'contents', 26124870174SAndreas Gohr 'href'=> wl($ID, 'do=index', false, '&'), 262ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 26324870174SAndreas Gohr ]; 2647aedde2eSGina Haeussge } 265f96fa415SAndreas Gohr 2665e0255e3SMichael Große if (actionOK('manifest')) { 26724870174SAndreas Gohr $head['link'][] = [ 26824870174SAndreas Gohr 'rel'=> 'manifest', 26924870174SAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/manifest.php' 27024870174SAndreas Gohr ]; 2715e0255e3SMichael Große } 2725e0255e3SMichael Große 27324870174SAndreas Gohr $styleUtil = new StyleUtils(); 2744593dbd2SAnna Dabrowska $styleIni = $styleUtil->cssStyleini(); 27540ca8540SMichael Große $replacements = $styleIni['replacements']; 27640ca8540SMichael Große if (!empty($replacements['__theme_color__'])) { 27724870174SAndreas Gohr $head['meta'][] = [ 27824870174SAndreas Gohr 'name' => 'theme-color', 27924870174SAndreas Gohr 'content' => $replacements['__theme_color__'] 28024870174SAndreas Gohr ]; 28140ca8540SMichael Große } 28240ca8540SMichael Große 283f96fa415SAndreas Gohr if($alt) { 28454be1338SGerrit Uitslag if(actionOK('rss')) { 28524870174SAndreas Gohr $head['link'][] = [ 28624870174SAndreas Gohr 'rel' => 'alternate', 28724870174SAndreas Gohr 'type'=> 'application/rss+xml', 28824870174SAndreas Gohr 'title'=> $lang['btn_recent'], 28924870174SAndreas Gohr 'href'=> DOKU_BASE.'feed.php' 29024870174SAndreas Gohr ]; 29124870174SAndreas Gohr $head['link'][] = [ 29224870174SAndreas Gohr 'rel' => 'alternate', 29324870174SAndreas Gohr 'type'=> 'application/rss+xml', 294a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 295aac83cd4SPhy 'href' => DOKU_BASE.'feed.php?mode=list&ns='.(isset($INFO) ? $INFO['namespace'] : '') 29624870174SAndreas Gohr ]; 29754be1338SGerrit Uitslag } 298c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 29924870174SAndreas Gohr $head['link'][] = [ 300ac7a515fSAndreas Gohr 'rel' => 'edit', 301715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 302ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 30324870174SAndreas Gohr ]; 304c35f3875SAndreas Gohr } 305c35f3875SAndreas Gohr 30654be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 30724870174SAndreas Gohr $head['link'][] = [ 30824870174SAndreas Gohr 'rel' => 'alternate', 30924870174SAndreas Gohr 'type'=> 'application/rss+xml', 310a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 311ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 31224870174SAndreas Gohr ]; 3134bb1b5aeSAndreas Gohr } 314bae36d94SAndreas Gohr 315bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 31624870174SAndreas Gohr $head['link'][] = [ 31724870174SAndreas Gohr 'rel' => 'alternate', 31824870174SAndreas Gohr 'type'=> 'text/html', 31924870174SAndreas Gohr 'title'=> $lang['plainhtml'], 320ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 32124870174SAndreas Gohr ]; 322bae36d94SAndreas Gohr } 323bae36d94SAndreas Gohr 324bae36d94SAndreas Gohr if(actionOK('export_raw')) { 32524870174SAndreas Gohr $head['link'][] = [ 32624870174SAndreas Gohr 'rel' => 'alternate', 32724870174SAndreas Gohr 'type'=> 'text/plain', 32824870174SAndreas Gohr 'title'=> $lang['wikimarkup'], 329ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 33024870174SAndreas Gohr ]; 331f96fa415SAndreas Gohr } 332bae36d94SAndreas Gohr } 3336b13307fSandi 33463f13cadSDamien Regad // setup robot tags appropriate for different modes 3354f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3366b13307fSandi if($INFO['exists']) { 3376b13307fSandi //delay indexing: 338fb9fa88bSAndreas Gohr if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) { 33924870174SAndreas Gohr $head['meta'][] = ['name'=> 'robots', 'content'=> 'index,follow']; 3406b13307fSandi } else { 34124870174SAndreas Gohr $head['meta'][] = ['name'=> 'robots', 'content'=> 'noindex,nofollow']; 3426b13307fSandi } 34301f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 34401f9be51SAnika Henke if ($ID == $conf['start']) { 34501f9be51SAnika Henke $canonicalUrl = DOKU_URL; 34601f9be51SAnika Henke } 34724870174SAndreas Gohr $head['link'][] = ['rel'=> 'canonical', 'href'=> $canonicalUrl]; 3486b13307fSandi } else { 34924870174SAndreas Gohr $head['meta'][] = ['name'=> 'robots', 'content'=> 'noindex,follow']; 3506b13307fSandi } 3517a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 35224870174SAndreas Gohr $head['meta'][] = ['name'=> 'robots', 'content'=> 'index,follow']; 3536b13307fSandi } else { 35424870174SAndreas Gohr $head['meta'][] = ['name'=> 'robots', 'content'=> 'noindex,nofollow']; 3556b13307fSandi } 3566b13307fSandi 357831800b8SAndreas Gohr // set metadata 358831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 359831800b8SAndreas Gohr // keywords (explicit or implicit) 360bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 36124870174SAndreas Gohr $head['meta'][] = ['name'=> 'keywords', 'content'=> implode(',', $INFO['meta']['subject'])]; 362831800b8SAndreas Gohr } else { 36324870174SAndreas Gohr $head['meta'][] = ['name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)]; 364831800b8SAndreas Gohr } 365831800b8SAndreas Gohr } 366831800b8SAndreas Gohr 36778a6aeb1SAndreas Gohr // load stylesheets 36824870174SAndreas Gohr $head['link'][] = [ 36959305168SPhy 'rel' => 'stylesheet', 370e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 37124870174SAndreas Gohr ]; 372bad31ae9SAndreas Gohr 373aac83cd4SPhy $script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';"; 374585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 37598169a0fSAndreas Gohr $script .= "var SIG=".toolbar_signature().";"; 376c591aabeSAndreas Gohr } 3770c39d46cSMichael Große jsinfo(); 37824870174SAndreas Gohr $script .= 'var JSINFO = ' . json_encode($JSINFO, JSON_THROW_ON_ERROR).';'; 37924870174SAndreas Gohr $head['script'][] = ['_data'=> $script]; 3808bbcb611SAndreas Gohr 38161537d47SAndreas Gohr // load jquery 382fa078663SAndreas Gohr $jquery = getCdnUrls(); 383fa078663SAndreas Gohr foreach($jquery as $src) { 38424870174SAndreas Gohr $head['script'][] = [ 385fc6b11d2SMichael Große '_data' => '', 38624870174SAndreas Gohr 'src' => $src 38724870174SAndreas Gohr ] + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); 38861537d47SAndreas Gohr } 38961537d47SAndreas Gohr 39061537d47SAndreas Gohr // load our javascript dispatcher 39124870174SAndreas Gohr $head['script'][] = [ 392de1dc35bSNicolas Friedli '_data'=> '', 39324870174SAndreas Gohr 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed 39424870174SAndreas Gohr ] + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); 3957bff22c0SAndreas Gohr 3967bff22c0SAndreas Gohr // trigger event here 397cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 39854e95700STom N Harris return true; 3997bff22c0SAndreas Gohr} 4007bff22c0SAndreas Gohr 4017bff22c0SAndreas Gohr/** 4027bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4037bff22c0SAndreas Gohr * 4047bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4057bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4067bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4077bff22c0SAndreas Gohr * 40842ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4091304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4107bff22c0SAndreas Gohr * 4117bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 41242ea7f44SGerrit Uitslag * 41342ea7f44SGerrit Uitslag * @param array $data 4147bff22c0SAndreas Gohr */ 415d868eb89SAndreas Gohrfunction _tpl_metaheaders_action($data) 416d868eb89SAndreas Gohr{ 4177bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 418427bf9a2SAndreas Gohr if($tag == 'script') { 419427bf9a2SAndreas Gohr echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE 420427bf9a2SAndreas Gohr } 4217bff22c0SAndreas Gohr foreach($inst as $attr) { 4229b48e6a1SGerry Weißbach if ( empty($attr) ) { continue; } 4237bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 42426afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 425740897dcSasivery if($tag == 'script' && isset($attr['_data'])) 42609f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 427e226efe1SAndreas Gohr $attr['_data']. 42809f791c4SDominik Eckelmann "\n/*!]]>*/"; 429e226efe1SAndreas Gohr 43024870174SAndreas Gohr echo '>', $attr['_data'] ?? '', '</', $tag, '>'; 4317bff22c0SAndreas Gohr } else { 4327bff22c0SAndreas Gohr echo '/>'; 4337bff22c0SAndreas Gohr } 4347bff22c0SAndreas Gohr echo "\n"; 4357bff22c0SAndreas Gohr } 436427bf9a2SAndreas Gohr if($tag == 'script') { 437427bf9a2SAndreas Gohr echo "<!--<![endif]-->\n"; 438427bf9a2SAndreas Gohr } 4397bff22c0SAndreas Gohr } 4406b13307fSandi} 4416b13307fSandi 4426b13307fSandi/** 4436b13307fSandi * Print a link 4446b13307fSandi * 4455e163278SAndreas Gohr * Just builds a link. 4466b13307fSandi * 4476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 44842ea7f44SGerrit Uitslag * 44942ea7f44SGerrit Uitslag * @param string $url 45042ea7f44SGerrit Uitslag * @param string $name 45142ea7f44SGerrit Uitslag * @param string $more 45221d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 45321d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4546b13307fSandi */ 455d868eb89SAndreas Gohrfunction tpl_link($url, $name, $more = '', $return = false) 456d868eb89SAndreas Gohr{ 45701f17825SAnika Henke $out = '<a href="'.$url.'" '; 4581af98a77SAnika Henke if($more) $out .= ' '.$more; 4591af98a77SAnika Henke $out .= ">$name</a>"; 4601af98a77SAnika Henke if($return) return $out; 4611af98a77SAnika Henke print $out; 46254e95700STom N Harris return true; 4636b13307fSandi} 4646b13307fSandi 4656b13307fSandi/** 46655efc227SAndreas Gohr * Prints a link to a WikiPage 46755efc227SAndreas Gohr * 46855efc227SAndreas Gohr * Wrapper around html_wikilink 46955efc227SAndreas Gohr * 47055efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 47142ea7f44SGerrit Uitslag * 47242ea7f44SGerrit Uitslag * @param string $id page id 47342ea7f44SGerrit Uitslag * @param string|null $name the name of the link 474fb008d31SIain Hallam * @param bool $return 475fb008d31SIain Hallam * @return true|string 47655efc227SAndreas Gohr */ 477d868eb89SAndreas Gohrfunction tpl_pagelink($id, $name = null, $return = false) 478d868eb89SAndreas Gohr{ 479c4a386f1SIain Hallam $out = '<bdi>'.html_wikilink($id, $name).'</bdi>'; 480c4a386f1SIain Hallam if($return) return $out; 481c4a386f1SIain Hallam print $out; 48254e95700STom N Harris return true; 48355efc227SAndreas Gohr} 48455efc227SAndreas Gohr 48555efc227SAndreas Gohr/** 486a3ec5f4aSmatthiasgrimm * get the parent page 487a3ec5f4aSmatthiasgrimm * 488a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 489a3ec5f4aSmatthiasgrimm * returns false if none is available 490a3ec5f4aSmatthiasgrimm * 491377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 49242ea7f44SGerrit Uitslag * 49342ea7f44SGerrit Uitslag * @param string $id page id 49442ea7f44SGerrit Uitslag * @return false|string 495a3ec5f4aSmatthiasgrimm */ 496d868eb89SAndreas Gohrfunction tpl_getparent($id) 497d868eb89SAndreas Gohr{ 4988c6be208SAndreas Gohr $resolver = new PageResolver('root'); 4998c6be208SAndreas Gohr 500377f9e97SAndreas Gohr $parent = getNS($id).':'; 5018c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 502a197105eSmatthiasgrimm if($parent == $id) { 503a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 504a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 5058c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 506377f9e97SAndreas Gohr if($parent == $id) return false; 507a197105eSmatthiasgrimm } 508377f9e97SAndreas Gohr return $parent; 509a3ec5f4aSmatthiasgrimm} 510a3ec5f4aSmatthiasgrimm 511a3ec5f4aSmatthiasgrimm/** 5126b13307fSandi * Print one of the buttons 5136b13307fSandi * 514a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 515a453d131SAdrian Lang * @see tpl_get_action 516e0c26282SGerrit Uitslag * 517e0c26282SGerrit Uitslag * @param string $type 518e0c26282SGerrit Uitslag * @param bool $return 519e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 520affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 5216b13307fSandi */ 522d868eb89SAndreas Gohrfunction tpl_button($type, $return = false) 523d868eb89SAndreas Gohr{ 524affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 525a453d131SAdrian Lang $data = tpl_get_action($type); 526a453d131SAdrian Lang if($data === false) { 527a453d131SAdrian Lang return false; 528a453d131SAdrian Lang } elseif(!is_array($data)) { 529a453d131SAdrian Lang $out = sprintf($data, 'button'); 530409d7af7SAndreas Gohr } else { 531ac7a515fSAndreas Gohr /** 532ac7a515fSAndreas Gohr * @var string $accesskey 533ac7a515fSAndreas Gohr * @var string $id 534ac7a515fSAndreas Gohr * @var string $method 535ac7a515fSAndreas Gohr * @var array $params 536ac7a515fSAndreas Gohr */ 537a453d131SAdrian Lang extract($data); 538a453d131SAdrian Lang if($id === '#dokuwiki__top') { 539a453d131SAdrian Lang $out = html_topbtn(); 540409d7af7SAndreas Gohr } else { 541a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 542409d7af7SAndreas Gohr } 543409d7af7SAndreas Gohr } 5441af98a77SAnika Henke if($return) return $out; 545a453d131SAdrian Lang echo $out; 546a453d131SAdrian Lang return true; 5476b13307fSandi} 5486b13307fSandi 5496b13307fSandi/** 550ed630903Sandi * Like the action buttons but links 551ed630903Sandi * 552a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 553a453d131SAdrian Lang * @see tpl_get_action 554e0c26282SGerrit Uitslag * 55542ea7f44SGerrit Uitslag * @param string $type action command 556e0c26282SGerrit Uitslag * @param string $pre prefix of link 557e0c26282SGerrit Uitslag * @param string $suf suffix of link 558e0c26282SGerrit Uitslag * @param string $inner innerHML of link 55921d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 560e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 561affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 562a453d131SAdrian Lang */ 563d868eb89SAndreas Gohrfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) 564d868eb89SAndreas Gohr{ 565affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 566a453d131SAdrian Lang global $lang; 567a453d131SAdrian Lang $data = tpl_get_action($type); 568a453d131SAdrian Lang if($data === false) { 569a453d131SAdrian Lang return false; 570a453d131SAdrian Lang } elseif(!is_array($data)) { 571a453d131SAdrian Lang $out = sprintf($data, 'link'); 572a453d131SAdrian Lang } else { 573ac7a515fSAndreas Gohr /** 574ac7a515fSAndreas Gohr * @var string $accesskey 575ac7a515fSAndreas Gohr * @var string $id 576ac7a515fSAndreas Gohr * @var string $method 577b1af9014SChristopher Smith * @var bool $nofollow 578ac7a515fSAndreas Gohr * @var array $params 579becfa414SGerrit Uitslag * @var string $replacement 580ac7a515fSAndreas Gohr */ 581a453d131SAdrian Lang extract($data); 582a453d131SAdrian Lang if(strpos($id, '#') === 0) { 583a453d131SAdrian Lang $linktarget = $id; 584a453d131SAdrian Lang } else { 585a453d131SAdrian Lang $linktarget = wl($id, $params); 586a453d131SAdrian Lang } 587a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 588becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 589becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 590becfa414SGerrit Uitslag } 59124870174SAndreas Gohr $akey = ''; 59224870174SAndreas Gohr $addTitle = ''; 593c7e90e3fSAnika Henke if($accesskey) { 594c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 595c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 596c7e90e3fSAnika Henke } 597b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 598ac7a515fSAndreas Gohr $out = tpl_link( 59924870174SAndreas Gohr $linktarget, $pre.($inner ?: $caption).$suf, 600a453d131SAdrian Lang 'class="action '.$type.'" '. 601b1af9014SChristopher Smith $akey.$rel. 602e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 603ac7a515fSAndreas Gohr ); 604a453d131SAdrian Lang } 605a453d131SAdrian Lang if($return) return $out; 606a453d131SAdrian Lang echo $out; 607a453d131SAdrian Lang return true; 608a453d131SAdrian Lang} 609a453d131SAdrian Lang 610a453d131SAdrian Lang/** 611a453d131SAdrian Lang * Check the actions and get data for buttons and links 612ed630903Sandi * 613ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 614a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 615a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 616e0c26282SGerrit Uitslag * 617ac7a515fSAndreas Gohr * @param string $type 618ac7a515fSAndreas Gohr * @return array|bool|string 619affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 620ed630903Sandi */ 621d868eb89SAndreas Gohrfunction tpl_get_action($type) 622d868eb89SAndreas Gohr{ 623affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 624a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 6254c4b65c8SMichael Hamann if($type == 'subscription') $type = 'subscribe'; 6264887c154SAndreas Gohr if($type == 'img_backto') $type = 'imgBackto'; 627409d7af7SAndreas Gohr 6284887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 6294887c154SAndreas Gohr if(class_exists($class)) { 6304887c154SAndreas Gohr try { 63124870174SAndreas Gohr /** @var AbstractItem $item */ 632*73022918SAndreas Gohr $item = new $class(); 6334887c154SAndreas Gohr $data = $item->getLegacyData(); 6347b4365a7SGerrit Uitslag $unknown = false; 6354887c154SAndreas Gohr } catch(\RuntimeException $ignored) { 6364887c154SAndreas Gohr return false; 637b8a111f5SMichael Klier } 638ed630903Sandi } else { 6394887c154SAndreas Gohr global $ID; 64024870174SAndreas Gohr $data = [ 6414887c154SAndreas Gohr 'accesskey' => null, 6424887c154SAndreas Gohr 'type' => $type, 6434887c154SAndreas Gohr 'id' => $ID, 6444887c154SAndreas Gohr 'method' => 'get', 64524870174SAndreas Gohr 'params' => ['do' => $type], 6464887c154SAndreas Gohr 'nofollow' => true, 64724870174SAndreas Gohr 'replacement' => '' 64824870174SAndreas Gohr ]; 6497b4365a7SGerrit Uitslag $unknown = true; 650ed630903Sandi } 6517b4365a7SGerrit Uitslag 652e1d9dcc8SAndreas Gohr $evt = new Event('TPL_ACTION_GET', $data); 6537b4365a7SGerrit Uitslag if($evt->advise_before()) { 6547b4365a7SGerrit Uitslag //handle unknown types 6557b4365a7SGerrit Uitslag if($unknown) { 65638d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6577b4365a7SGerrit Uitslag } 6587b4365a7SGerrit Uitslag } 6597b4365a7SGerrit Uitslag $evt->advise_after(); 6607b4365a7SGerrit Uitslag unset($evt); 6617b4365a7SGerrit Uitslag 6627b4365a7SGerrit Uitslag return $data; 663ed630903Sandi} 664ed630903Sandi 665ed630903Sandi/** 66601f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 66701f17825SAnika Henke * 66801f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 66942ea7f44SGerrit Uitslag * 67042ea7f44SGerrit Uitslag * @param string $type action command 671ac7a515fSAndreas Gohr * @param bool $link link or form button? 672e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 673ac7a515fSAndreas Gohr * @param bool $return return or print 674ac7a515fSAndreas Gohr * @param string $pre prefix for links 675ac7a515fSAndreas Gohr * @param string $suf suffix for links 676ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 677ac7a515fSAndreas Gohr * @return bool|string 678affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 67901f17825SAnika Henke */ 680d868eb89SAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') 681d868eb89SAndreas Gohr{ 682affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 68301f17825SAnika Henke $out = ''; 684ac7a515fSAndreas Gohr if($link) { 685e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 686ac7a515fSAndreas Gohr } else { 687e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 688ac7a515fSAndreas Gohr } 68901f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 69001f17825SAnika Henke 69101f17825SAnika Henke if($return) return $out; 69201f17825SAnika Henke print $out; 69324870174SAndreas Gohr return (bool) $out; 69401f17825SAnika Henke} 69501f17825SAnika Henke 69601f17825SAnika Henke/** 6976b13307fSandi * Print the search form 6986b13307fSandi * 69972645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 70072645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 70172645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 70272645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 70372645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 70472645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 70572645b75SAndreas Gohr * 7066b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 70742ea7f44SGerrit Uitslag * 708ac7a515fSAndreas Gohr * @param bool $ajax 709ac7a515fSAndreas Gohr * @param bool $autocomplete 710ac7a515fSAndreas Gohr * @return bool 7116b13307fSandi */ 712d868eb89SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) 713d868eb89SAndreas Gohr{ 7146b13307fSandi global $lang; 715c1e3b7d9Smatthiasgrimm global $ACT; 716ad4aaef7SAndreas Gohr global $QUERY; 717cbcc2fa5SMichael Große global $ID; 718c1e3b7d9Smatthiasgrimm 719670ff54eSchris // don't print the search form if search action has been disabled 72064276bbcSarbrk1 if(!actionOK('search')) return false; 721670ff54eSchris 72224870174SAndreas Gohr $searchForm = new Form([ 7233c7a3327SMichael Große 'action' => wl(), 7243c7a3327SMichael Große 'method' => 'get', 7253c7a3327SMichael Große 'role' => 'search', 7263c7a3327SMichael Große 'class' => 'search', 7273c7a3327SMichael Große 'id' => 'dw__search', 7287fa270bcSMichael Große ], true); 7293eb2b869SMichael Große $searchForm->addTagOpen('div')->addClass('no'); 7303c7a3327SMichael Große $searchForm->setHiddenField('do', 'search'); 731d22b78c8SMichael Große $searchForm->setHiddenField('id', $ID); 732d22b78c8SMichael Große $searchForm->addTextInput('q') 7333c7a3327SMichael Große ->addClass('edit') 7343c7a3327SMichael Große ->attrs([ 7353c7a3327SMichael Große 'title' => '[F]', 7363c7a3327SMichael Große 'accesskey' => 'f', 7373c7a3327SMichael Große 'placeholder' => $lang['btn_search'], 7383c7a3327SMichael Große 'autocomplete' => $autocomplete ? 'on' : 'off', 7393c7a3327SMichael Große ]) 7403c7a3327SMichael Große ->id('qsearch__in') 7413c7a3327SMichael Große ->val($ACT === 'search' ? $QUERY : '') 7423c7a3327SMichael Große ->useInput(false) 7433c7a3327SMichael Große ; 7443c7a3327SMichael Große $searchForm->addButton('', $lang['btn_search'])->attrs([ 7453c7a3327SMichael Große 'type' => 'submit', 7463c7a3327SMichael Große 'title' => $lang['btn_search'], 7473c7a3327SMichael Große ]); 7483c7a3327SMichael Große if ($ajax) { 7493c7a3327SMichael Große $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup'); 7503c7a3327SMichael Große $searchForm->addTagClose('div'); 7513c7a3327SMichael Große } 7523eb2b869SMichael Große $searchForm->addTagClose('div'); 7533c7a3327SMichael Große 754c6977b3aSSatoshi Sahara echo $searchForm->toHTML('QuickSearch'); 7553c7a3327SMichael Große 75654e95700STom N Harris return true; 7576b13307fSandi} 7586b13307fSandi 7596b13307fSandi/** 7606b13307fSandi * Print the breadcrumbs trace 7616b13307fSandi * 7626b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 76342ea7f44SGerrit Uitslag * 764ac7a515fSAndreas Gohr * @param string $sep Separator between entries 765c4a386f1SIain Hallam * @param bool $return return or print 766c4a386f1SIain Hallam * @return bool|string 7676b13307fSandi */ 768d868eb89SAndreas Gohrfunction tpl_breadcrumbs($sep = null, $return = false) 769d868eb89SAndreas Gohr{ 7706b13307fSandi global $lang; 7716b13307fSandi global $conf; 7726b13307fSandi 7736b13307fSandi //check if enabled 774359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 7756b13307fSandi 776c4a386f1SIain Hallam //set default 777c4a386f1SIain Hallam if(is_null($sep)) $sep = '•'; 778c4a386f1SIain Hallam 779c4a386f1SIain Hallam $out=''; 780c4a386f1SIain Hallam 7816b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 782265e3787Sandi 7832979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 784265e3787Sandi 78540eb54bbSjan //render crumbs, highlight the last one 786c4a386f1SIain Hallam $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 78740eb54bbSjan $last = count($crumbs); 78840eb54bbSjan $i = 0; 789a77f5846Sjan foreach($crumbs as $id => $name) { 79040eb54bbSjan $i++; 791c4a386f1SIain Hallam $out .= $crumbs_sep; 792c4a386f1SIain Hallam if($i == $last) $out .= '<span class="curid">'; 793c4a386f1SIain Hallam $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) . '</bdi>'; 794c4a386f1SIain Hallam if($i == $last) $out .= '</span>'; 7956b13307fSandi } 796c4a386f1SIain Hallam if($return) return $out; 797c4a386f1SIain Hallam print $out; 79824870174SAndreas Gohr return (bool) $out; 7996b13307fSandi} 8006b13307fSandi 8016b13307fSandi/** 8021734437eSandi * Hierarchical breadcrumbs 8031734437eSandi * 80431e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8051734437eSandi * It only makes sense with a deep site structure. 8061734437eSandi * 8071734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 8086bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 80931e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 810f46c9e83SAnika Henke * @author <fredrik@averpil.com> 81108d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 81242ea7f44SGerrit Uitslag * 813ac7a515fSAndreas Gohr * @param string $sep Separator between entries 814c4a386f1SIain Hallam * @param bool $return return or print 815c4a386f1SIain Hallam * @return bool|string 8161734437eSandi */ 817d868eb89SAndreas Gohrfunction tpl_youarehere($sep = null, $return = false) 818d868eb89SAndreas Gohr{ 8191734437eSandi global $conf; 8201734437eSandi global $ID; 8211734437eSandi global $lang; 8221734437eSandi 82331e187f8SSean Coates // check if enabled 82454e95700STom N Harris if(!$conf['youarehere']) return false; 8251734437eSandi 826c4a386f1SIain Hallam //set default 827c4a386f1SIain Hallam if(is_null($sep)) $sep = ' » '; 828c4a386f1SIain Hallam 829c4a386f1SIain Hallam $out = ''; 830c4a386f1SIain Hallam 8311734437eSandi $parts = explode(':', $ID); 832796bafb3SAndreas Gohr $count = count($parts); 8331734437eSandi 834c4a386f1SIain Hallam $out .= '<span class="bchead">'.$lang['youarehere'].' </span>'; 8353940c519SMark 83608d7a575SAndreas Gohr // always print the startpage 837c4a386f1SIain Hallam $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>'; 838796bafb3SAndreas Gohr 839796bafb3SAndreas Gohr // print intermediate namespace links 840796bafb3SAndreas Gohr $part = ''; 841796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 842796bafb3SAndreas Gohr $part .= $parts[$i].':'; 843796bafb3SAndreas Gohr $page = $part; 844796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 845796bafb3SAndreas Gohr 84608d7a575SAndreas Gohr // output 847c4a386f1SIain Hallam $out .= $sep . tpl_pagelink($page, null, true); 84831e187f8SSean Coates } 8491734437eSandi 850796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 8518c6be208SAndreas Gohr if (isset($page)) { 8528c6be208SAndreas Gohr $page = (new PageResolver('root'))->resolveId($page); 8538c6be208SAndreas Gohr if ($page == $part . $parts[$i]) { 854a8c33dedSMichael Große if ($return) return $out; 855a8c33dedSMichael Große print $out; 856a8c33dedSMichael Große return true; 857a8c33dedSMichael Große } 8588c6be208SAndreas Gohr } 859796bafb3SAndreas Gohr $page = $part.$parts[$i]; 860a8c33dedSMichael Große if($page == $conf['start']) { 861a8c33dedSMichael Große if($return) return $out; 862a8c33dedSMichael Große print $out; 863a8c33dedSMichael Große return true; 864a8c33dedSMichael Große } 865c4a386f1SIain Hallam $out .= $sep; 866c4a386f1SIain Hallam $out .= tpl_pagelink($page, null, true); 867c4a386f1SIain Hallam if($return) return $out; 868c4a386f1SIain Hallam print $out; 86924870174SAndreas Gohr return (bool) $out; 8701734437eSandi} 8711734437eSandi 8721734437eSandi/** 8736b13307fSandi * Print info if the user is logged in 874a2488c3cSMatthias Grimm * and show full name in that case 8756b13307fSandi * 8766b13307fSandi * Could be enhanced with a profile link in future? 8776b13307fSandi * 8786b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 87942ea7f44SGerrit Uitslag * 880ac7a515fSAndreas Gohr * @return bool 8816b13307fSandi */ 882d868eb89SAndreas Gohrfunction tpl_userinfo() 883d868eb89SAndreas Gohr{ 8846b13307fSandi global $lang; 885585bf44eSChristopher Smith /** @var Input $INPUT */ 886585bf44eSChristopher Smith global $INPUT; 887585bf44eSChristopher Smith 888585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 889fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 89054e95700STom N Harris return true; 89154e95700STom N Harris } 89254e95700STom N Harris return false; 8936b13307fSandi} 8946b13307fSandi 8956b13307fSandi/** 8966b13307fSandi * Print some info about the current page 8976b13307fSandi * 8986b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 89942ea7f44SGerrit Uitslag * 900ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 901ac7a515fSAndreas Gohr * @return bool|string 9026b13307fSandi */ 903d868eb89SAndreas Gohrfunction tpl_pageinfo($ret = false) 904d868eb89SAndreas Gohr{ 9056b13307fSandi global $conf; 9066b13307fSandi global $lang; 9076b13307fSandi global $INFO; 908c6e92a3cSDavid Lorentsen global $ID; 909c6e92a3cSDavid Lorentsen 910c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 911ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 912ac7a515fSAndreas Gohr return false; 913ac7a515fSAndreas Gohr } 9146b13307fSandi 9156b13307fSandi // prepare date and path 9166b13307fSandi $fn = $INFO['filepath']; 9176b13307fSandi if(!$conf['fullpath']) { 918613bca54SAndreas Gohr if($INFO['rev']) { 919c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'].'/', '', $fn); 9206b13307fSandi } else { 921c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'].'/', '', $fn); 9226b13307fSandi } 9236b13307fSandi } 924bee6dc82Sandi $fn = utf8_decodeFN($fn); 925f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 9266b13307fSandi 927faecdfdfSAndreas Gohr // print it 928faecdfdfSAndreas Gohr if($INFO['exists']) { 9294b0d3916SAndreas Gohr $out = ''; 930d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 931e260f93bSAnika Henke $out .= ' · '; 9324b0d3916SAndreas Gohr $out .= $lang['lastmod']; 933fde860beSGerrit Uitslag $out .= ' '; 9344b0d3916SAndreas Gohr $out .= $date; 9356b13307fSandi if($INFO['editor']) { 9364b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 937d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 9385aa52fafSBen Coburn } else { 9394b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 9406b13307fSandi } 9416b13307fSandi if($INFO['locked']) { 942e260f93bSAnika Henke $out .= ' · '; 9434b0d3916SAndreas Gohr $out .= $lang['lockedby']; 944fde860beSGerrit Uitslag $out .= ' '; 945d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 9466b13307fSandi } 9474b0d3916SAndreas Gohr if($ret) { 9484b0d3916SAndreas Gohr return $out; 9494b0d3916SAndreas Gohr } else { 9504b0d3916SAndreas Gohr echo $out; 95154e95700STom N Harris return true; 9526b13307fSandi } 9534b0d3916SAndreas Gohr } 95454e95700STom N Harris return false; 9556b13307fSandi} 9566b13307fSandi 957820fa24bSandi/** 958a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 95987c434ceSAndreas Gohr * 96087c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 961a6598f23SBen Coburn * the given ID is used. 96287c434ceSAndreas Gohr * 96387c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 96442ea7f44SGerrit Uitslag * 965ac7a515fSAndreas Gohr * @param string $id page id 966ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 967ac7a515fSAndreas Gohr * @return bool|string 96887c434ceSAndreas Gohr */ 969d868eb89SAndreas Gohrfunction tpl_pagetitle($id = null, $ret = false) 970d868eb89SAndreas Gohr{ 971c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 972fffeeafeSChristopher Smith 97387c434ceSAndreas Gohr if(is_null($id)) { 97487c434ceSAndreas Gohr global $ID; 97587c434ceSAndreas Gohr $id = $ID; 97687c434ceSAndreas Gohr } 97787c434ceSAndreas Gohr 97887c434ceSAndreas Gohr $name = $id; 979fe9ec250SChris Smith if(useHeading('navigation')) { 980fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 981fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 982fffeeafeSChristopher Smith } 983fffeeafeSChristopher Smith 984fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 985fffeeafeSChristopher Smith switch ($ACT) { 986fffeeafeSChristopher Smith // admin functions 987fffeeafeSChristopher Smith case 'admin' : 988fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 989fffeeafeSChristopher Smith // try to get the plugin name 990e1d9dcc8SAndreas Gohr /** @var $plugin AdminPlugin */ 991a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 992c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 99324870174SAndreas Gohr $page_title = $plugin_title ?: $plugin->getPluginName(); 994fffeeafeSChristopher Smith } 995fffeeafeSChristopher Smith break; 996fffeeafeSChristopher Smith 997fffeeafeSChristopher Smith // user functions 998fffeeafeSChristopher Smith case 'login' : 999fffeeafeSChristopher Smith case 'profile' : 1000fffeeafeSChristopher Smith case 'register' : 1001fffeeafeSChristopher Smith case 'resendpwd' : 1002fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 1003fffeeafeSChristopher Smith break; 1004fffeeafeSChristopher Smith 1005fffeeafeSChristopher Smith // wiki functions 1006fffeeafeSChristopher Smith case 'search' : 1007fffeeafeSChristopher Smith case 'index' : 1008fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 1009fffeeafeSChristopher Smith break; 1010fffeeafeSChristopher Smith 1011fffeeafeSChristopher Smith // page functions 1012fffeeafeSChristopher Smith case 'edit' : 10132f19acc2Sbleistivt case 'preview' : 1014fffeeafeSChristopher Smith $page_title = "✎ ".$name; 1015fffeeafeSChristopher Smith break; 1016fffeeafeSChristopher Smith 1017fffeeafeSChristopher Smith case 'revisions' : 1018fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 1019fffeeafeSChristopher Smith break; 1020fffeeafeSChristopher Smith 1021fffeeafeSChristopher Smith case 'backlink' : 1022fffeeafeSChristopher Smith case 'recent' : 1023fffeeafeSChristopher Smith case 'subscribe' : 1024fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 1025fffeeafeSChristopher Smith break; 1026fffeeafeSChristopher Smith 1027fffeeafeSChristopher Smith default : // SHOW and anything else not included 1028fffeeafeSChristopher Smith $page_title = $name; 102987c434ceSAndreas Gohr } 1030a6598f23SBen Coburn 1031a6598f23SBen Coburn if($ret) { 1032fffeeafeSChristopher Smith return hsc($page_title); 1033a6598f23SBen Coburn } else { 1034fffeeafeSChristopher Smith print hsc($page_title); 103554e95700STom N Harris return true; 103687c434ceSAndreas Gohr } 1037a6598f23SBen Coburn} 1038340756e4Sandi 103955efc227SAndreas Gohr/** 104055efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 104155efc227SAndreas Gohr * 104255efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 104355efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 104455efc227SAndreas Gohr * 104555efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 104655efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 104755efc227SAndreas Gohr * to the names of the latter one) 104855efc227SAndreas Gohr * 10493df72098SAndreas Gohr * Only allowed in: detail.php 105055efc227SAndreas Gohr * 105155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 105242ea7f44SGerrit Uitslag * 105321d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1054ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1055e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1056ac7a515fSAndreas Gohr * @return string 105755efc227SAndreas Gohr */ 1058d868eb89SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) 1059d868eb89SAndreas Gohr{ 106055efc227SAndreas Gohr // Init Exif Reader 1061a46a7ce3Sasivery global $SRC, $imgMeta; 10623df72098SAndreas Gohr 10633df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 10641eadd9e8SAndreas Gohr if(is_null($src)) return $alt; 10653df72098SAndreas Gohr 1066a46a7ce3Sasivery if(!isset($imgMeta) || $imgMeta === null) $imgMeta = new JpegMeta($src); 1067a46a7ce3Sasivery if($imgMeta === false) return $alt; 1068a46a7ce3Sasivery $info = cleanText($imgMeta->getField($tags)); 106955efc227SAndreas Gohr if($info == false) return $alt; 107055efc227SAndreas Gohr return $info; 107155efc227SAndreas Gohr} 107255efc227SAndreas Gohr 1073a46a7ce3Sasivery 1074a46a7ce3Sasivery/** 1075a46a7ce3Sasivery * Garbage collects up the open JpegMeta object. 1076a46a7ce3Sasivery */ 1077d868eb89SAndreas Gohrfunction tpl_img_close() 1078d868eb89SAndreas Gohr{ 1079a46a7ce3Sasivery global $imgMeta; 1080a46a7ce3Sasivery $imgMeta = null; 1081a46a7ce3Sasivery} 1082a46a7ce3Sasivery 108355efc227SAndreas Gohr/** 1084becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1085becfa414SGerrit Uitslag * 1086becfa414SGerrit Uitslag * @return string html of description list 1087becfa414SGerrit Uitslag */ 1088d868eb89SAndreas Gohrfunction tpl_img_meta() 1089d868eb89SAndreas Gohr{ 1090becfa414SGerrit Uitslag global $lang; 1091becfa414SGerrit Uitslag 1092becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1093becfa414SGerrit Uitslag 1094becfa414SGerrit Uitslag echo '<dl>'; 1095becfa414SGerrit Uitslag foreach($tags as $tag) { 1096becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1097fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1098becfa414SGerrit Uitslag 1099fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1100becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1101becfa414SGerrit Uitslag echo dformat($tag['value']); 1102becfa414SGerrit Uitslag } else { 1103becfa414SGerrit Uitslag echo hsc($tag['value']); 1104becfa414SGerrit Uitslag } 1105becfa414SGerrit Uitslag echo '</dd>'; 1106becfa414SGerrit Uitslag } 1107becfa414SGerrit Uitslag echo '</dl>'; 1108becfa414SGerrit Uitslag} 1109becfa414SGerrit Uitslag 1110becfa414SGerrit Uitslag/** 1111becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1112becfa414SGerrit Uitslag * 1113becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1114becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1115becfa414SGerrit Uitslag * - string type type of value 1116becfa414SGerrit Uitslag * - string value tag value (unescaped) 1117becfa414SGerrit Uitslag */ 1118d868eb89SAndreas Gohrfunction tpl_get_img_meta() 1119d868eb89SAndreas Gohr{ 1120becfa414SGerrit Uitslag 1121becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1122becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 112379e79377SAndreas Gohr if(file_exists($config_file)) { 1124becfa414SGerrit Uitslag include($config_file); 1125becfa414SGerrit Uitslag } 1126becfa414SGerrit Uitslag } 112724870174SAndreas Gohr $tags = []; 1128becfa414SGerrit Uitslag foreach($fields as $tag){ 112924870174SAndreas Gohr $t = []; 1130becfa414SGerrit Uitslag if (!empty($tag[0])) { 113124870174SAndreas Gohr $t = [$tag[0]]; 1132becfa414SGerrit Uitslag } 1133056bf31fSDamien Regad if(isset($tag[3]) && is_array($tag[3])) { 1134becfa414SGerrit Uitslag $t = array_merge($t, $tag[3]); 1135becfa414SGerrit Uitslag } 1136becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1137becfa414SGerrit Uitslag if ($value) { 113824870174SAndreas Gohr $tags[] = ['langkey' => $tag[1], 'type' => $tag[2], 'value' => $value]; 1139becfa414SGerrit Uitslag } 1140becfa414SGerrit Uitslag } 1141becfa414SGerrit Uitslag return $tags; 1142becfa414SGerrit Uitslag} 1143becfa414SGerrit Uitslag 1144becfa414SGerrit Uitslag/** 114555efc227SAndreas Gohr * Prints the image with a link to the full sized version 114655efc227SAndreas Gohr * 114755efc227SAndreas Gohr * Only allowed in: detail.php 1148a02d2933SAndreas Gohr * 1149ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1150a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1151a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1152a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1153a02d2933SAndreas Gohr * @param $params array - additional image attributes 115442ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 115555efc227SAndreas Gohr */ 1156d868eb89SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) 1157d868eb89SAndreas Gohr{ 115855efc227SAndreas Gohr global $IMG; 1159585bf44eSChristopher Smith /** @var Input $INPUT */ 1160ac7a515fSAndreas Gohr global $INPUT; 11615c2eed9aSlisps global $REV; 116265d3a5dbSAndreas Gohr $w = (int) tpl_img_getTag('File.Width'); 116365d3a5dbSAndreas Gohr $h = (int) tpl_img_getTag('File.Height'); 116455efc227SAndreas Gohr 116555efc227SAndreas Gohr //resize to given max values 116623a34783SAndreas Gohr $ratio = 1; 116723a34783SAndreas Gohr if ($w >= $h) { 1168f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 116955efc227SAndreas Gohr $ratio = $maxwidth / $w; 1170f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 117155efc227SAndreas Gohr $ratio = $maxheight / $h; 117255efc227SAndreas Gohr } 117324870174SAndreas Gohr } elseif ($maxheight && $h >= $maxheight) { 117455efc227SAndreas Gohr $ratio = $maxheight / $h; 1175f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 117655efc227SAndreas Gohr $ratio = $maxwidth / $w; 117755efc227SAndreas Gohr } 117855efc227SAndreas Gohr if($ratio) { 117955efc227SAndreas Gohr $w = floor($ratio * $w); 118055efc227SAndreas Gohr $h = floor($ratio * $h); 118155efc227SAndreas Gohr } 118255efc227SAndreas Gohr 11836de3759aSAndreas Gohr //prepare URLs 118424870174SAndreas Gohr $url = ml($IMG, ['cache'=> $INPUT->str('cache'), 'rev'=>$REV], true, '&'); 118524870174SAndreas Gohr $src = ml($IMG, ['cache'=> $INPUT->str('cache'), 'rev'=>$REV, 'w'=> $w, 'h'=> $h], true, '&'); 118655efc227SAndreas Gohr 11872684e50aSAndreas Gohr //prepare attributes 118855efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1189a02d2933SAndreas Gohr if(is_null($params)) { 119024870174SAndreas Gohr $p = []; 1191a02d2933SAndreas Gohr } else { 1192a02d2933SAndreas Gohr $p = $params; 1193a02d2933SAndreas Gohr } 11942684e50aSAndreas Gohr if($w) $p['width'] = $w; 11952684e50aSAndreas Gohr if($h) $p['height'] = $h; 11962684e50aSAndreas Gohr $p['class'] = 'img_detail'; 11972684e50aSAndreas Gohr if($alt) { 11982684e50aSAndreas Gohr $p['alt'] = $alt; 11992684e50aSAndreas Gohr $p['title'] = $alt; 12002684e50aSAndreas Gohr } else { 12012684e50aSAndreas Gohr $p['alt'] = ''; 12022684e50aSAndreas Gohr } 1203a02d2933SAndreas Gohr $p['src'] = $src; 120455efc227SAndreas Gohr 120524870174SAndreas Gohr $data = ['url'=> ($link ? $url : null), 'params'=> $p]; 1206cbb44eabSAndreas Gohr return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1207a02d2933SAndreas Gohr} 1208a02d2933SAndreas Gohr 1209a02d2933SAndreas Gohr/** 1210a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1211ac7a515fSAndreas Gohr * 1212ac7a515fSAndreas Gohr * @param array $data 1213ac7a515fSAndreas Gohr * @return bool 1214a02d2933SAndreas Gohr */ 1215d868eb89SAndreas Gohrfunction _tpl_img_action($data) 1216d868eb89SAndreas Gohr{ 121759f3611bSAnika Henke global $lang; 1218a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1219a02d2933SAndreas Gohr 122059f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1221a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1222a02d2933SAndreas Gohr if($data['url']) print '</a>'; 122354e95700STom N Harris return true; 122455efc227SAndreas Gohr} 122555efc227SAndreas Gohr 12267367b368SAndreas Gohr/** 1227881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 12287367b368SAndreas Gohr * 12297367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 12307367b368SAndreas Gohr * template 1231ac7a515fSAndreas Gohr * 1232ac7a515fSAndreas Gohr * @return bool 12337367b368SAndreas Gohr */ 1234d868eb89SAndreas Gohrfunction tpl_indexerWebBug() 1235d868eb89SAndreas Gohr{ 12367367b368SAndreas Gohr global $ID; 12371dad36f5SAndreas Gohr 123824870174SAndreas Gohr $p = []; 12394af80fe8SMichael Große $p['src'] = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID). 1240e68c51baSAndreas Gohr '&'.time(); 1241881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 12427367b368SAndreas Gohr $p['height'] = 1; 12437367b368SAndreas Gohr $p['alt'] = ''; 12447367b368SAndreas Gohr $att = buildAttributes($p); 12457367b368SAndreas Gohr print "<img $att />"; 124654e95700STom N Harris return true; 12477367b368SAndreas Gohr} 12487367b368SAndreas Gohr 124978d4e784SEsther Brunner/** 125078d4e784SEsther Brunner * tpl_getConf($id) 125178d4e784SEsther Brunner * 125278d4e784SEsther Brunner * use this function to access template configuration variables 1253ac7a515fSAndreas Gohr * 125417448fb8SChristopher Smith * @param string $id name of the value to access 125517448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 125617448fb8SChristopher Smith * @return mixed 125778d4e784SEsther Brunner */ 1258d868eb89SAndreas Gohrfunction tpl_getConf($id, $notset = false) 1259d868eb89SAndreas Gohr{ 126078d4e784SEsther Brunner global $conf; 126117566ac6SAdrian Lang static $tpl_configloaded = false; 126278d4e784SEsther Brunner 126378d4e784SEsther Brunner $tpl = $conf['template']; 126478d4e784SEsther Brunner 126578d4e784SEsther Brunner if(!$tpl_configloaded) { 126678d4e784SEsther Brunner $tconf = tpl_loadConfig(); 126778d4e784SEsther Brunner if($tconf !== false) { 126878d4e784SEsther Brunner foreach($tconf as $key => $value) { 126978d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 127078d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 127178d4e784SEsther Brunner } 127278d4e784SEsther Brunner $tpl_configloaded = true; 127378d4e784SEsther Brunner } 127478d4e784SEsther Brunner } 127578d4e784SEsther Brunner 127624870174SAndreas Gohr return $conf['tpl'][$tpl][$id] ?? $notset; 127717448fb8SChristopher Smith} 127817448fb8SChristopher Smith 127978d4e784SEsther Brunner/** 128078d4e784SEsther Brunner * tpl_loadConfig() 1281ac7a515fSAndreas Gohr * 128278d4e784SEsther Brunner * reads all template configuration variables 128378d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1284ac7a515fSAndreas Gohr * 1285ac7a515fSAndreas Gohr * @return array 128678d4e784SEsther Brunner */ 1287d868eb89SAndreas Gohrfunction tpl_loadConfig() 1288d868eb89SAndreas Gohr{ 128978d4e784SEsther Brunner 1290c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 129124870174SAndreas Gohr $conf = []; 129278d4e784SEsther Brunner 129379e79377SAndreas Gohr if(!file_exists($file)) return false; 129478d4e784SEsther Brunner 129578d4e784SEsther Brunner // load default config file 129678d4e784SEsther Brunner include($file); 129778d4e784SEsther Brunner 129878d4e784SEsther Brunner return $conf; 129978d4e784SEsther Brunner} 130078d4e784SEsther Brunner 130117566ac6SAdrian Lang// language methods 130217566ac6SAdrian Lang/** 130317566ac6SAdrian Lang * tpl_getLang($id) 130417566ac6SAdrian Lang * 130517566ac6SAdrian Lang * use this function to access template language variables 130642ea7f44SGerrit Uitslag * 130742ea7f44SGerrit Uitslag * @param string $id key of language string 130842ea7f44SGerrit Uitslag * @return string 130917566ac6SAdrian Lang */ 1310d868eb89SAndreas Gohrfunction tpl_getLang($id) 1311d868eb89SAndreas Gohr{ 131224870174SAndreas Gohr static $lang = []; 131317566ac6SAdrian Lang 131417566ac6SAdrian Lang if(count($lang) === 0) { 1315dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1316dd7a6159SGerrit Uitslag 1317c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 131817566ac6SAdrian Lang 131924870174SAndreas Gohr $lang = []; 132017566ac6SAdrian Lang 132117566ac6SAdrian Lang // don't include once 132217566ac6SAdrian Lang @include($path . 'en/lang.php'); 1323dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 132479e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1325dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1326dd7a6159SGerrit Uitslag } 132717566ac6SAdrian Lang } 132817566ac6SAdrian Lang 1329dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1330dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1331dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 133279e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1333dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1334dd7a6159SGerrit Uitslag } 1335dd7a6159SGerrit Uitslag } 1336dd7a6159SGerrit Uitslag } 133717566ac6SAdrian Lang } 133824870174SAndreas Gohr return $lang[$id] ?? ''; 133917566ac6SAdrian Lang} 134017566ac6SAdrian Lang 13413df72098SAndreas Gohr/** 1342c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1343e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1344e8ec13b9SKlap-in * 1345e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1346e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1347e8ec13b9SKlap-in */ 1348d868eb89SAndreas Gohrfunction tpl_locale_xhtml($id) 1349d868eb89SAndreas Gohr{ 1350c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1351e8ec13b9SKlap-in} 1352e8ec13b9SKlap-in 1353e8ec13b9SKlap-in/** 1354c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 135542ea7f44SGerrit Uitslag * 135642ea7f44SGerrit Uitslag * @param string $id id of localized text 135742ea7f44SGerrit Uitslag * @return string wiki text 1358e8ec13b9SKlap-in */ 1359d868eb89SAndreas Gohrfunction tpl_localeFN($id) 1360d868eb89SAndreas Gohr{ 1361e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1362e8ec13b9SKlap-in global $conf; 136338fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 136479e79377SAndreas Gohr if (!file_exists($file)){ 1365e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 136679e79377SAndreas Gohr if(!file_exists($file)){ 1367e8ec13b9SKlap-in //fall back to english 1368e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1369e8ec13b9SKlap-in } 1370e8ec13b9SKlap-in } 1371e8ec13b9SKlap-in return $file; 1372e8ec13b9SKlap-in} 1373e8ec13b9SKlap-in 1374e8ec13b9SKlap-in/** 13757abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 13763df72098SAndreas Gohr * 13773df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13783df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13793df72098SAndreas Gohr * a message of referencing pages 13803df72098SAndreas Gohr * 13813df72098SAndreas Gohr * Only allowed in mediamanager.php 13823df72098SAndreas Gohr * 1383c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1384c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 138542ea7f44SGerrit Uitslag * @param string $sort 13868702de7fSGerrit Uitslag * 13873df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13883df72098SAndreas Gohr */ 1389d868eb89SAndreas Gohrfunction tpl_mediaContent($fromajax = false, $sort = 'natural') 1390d868eb89SAndreas Gohr{ 13913df72098SAndreas Gohr global $IMG; 13923df72098SAndreas Gohr global $AUTH; 13933df72098SAndreas Gohr global $INUSE; 13943df72098SAndreas Gohr global $NS; 13953df72098SAndreas Gohr global $JUMPTO; 1396585bf44eSChristopher Smith /** @var Input $INPUT */ 1397ac7a515fSAndreas Gohr global $INPUT; 13983df72098SAndreas Gohr 1399ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 140024870174SAndreas Gohr if(in_array($do, ['save', 'cancel'])) $do = ''; 1401c182313eSAndreas Gohr 1402c182313eSAndreas Gohr if(!$do) { 1403ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1404c182313eSAndreas Gohr $do = 'metaform'; 1405c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1406c182313eSAndreas Gohr $do = 'filesinuse'; 1407c182313eSAndreas Gohr } else { 1408c182313eSAndreas Gohr $do = 'filelist'; 1409c182313eSAndreas Gohr } 1410c182313eSAndreas Gohr } 1411c182313eSAndreas Gohr 1412c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1413c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 141424870174SAndreas Gohr $data = ['do' => $do]; 1415e1d9dcc8SAndreas Gohr $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1416c182313eSAndreas Gohr if($evt->advise_before()) { 1417c182313eSAndreas Gohr $do = $data['do']; 141830fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1419c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1420c182313eSAndreas Gohr } elseif($do == 'filelist') { 142100e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO, false, $sort); 1422c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1423ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1424c182313eSAndreas Gohr } else { 1425c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1426c182313eSAndreas Gohr } 1427c182313eSAndreas Gohr } 1428c182313eSAndreas Gohr $evt->advise_after(); 1429c182313eSAndreas Gohr unset($evt); 1430c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1431c182313eSAndreas Gohr 14323df72098SAndreas Gohr} 14333df72098SAndreas Gohr 14343df72098SAndreas Gohr/** 1435d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1436d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1437d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1438d9162c6cSKate Arzamastseva * 1439d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1440d9162c6cSKate Arzamastseva */ 1441d868eb89SAndreas Gohrfunction tpl_mediaFileList() 1442d868eb89SAndreas Gohr{ 1443d9162c6cSKate Arzamastseva global $AUTH; 1444d9162c6cSKate Arzamastseva global $NS; 1445d9162c6cSKate Arzamastseva global $JUMPTO; 144695b451bcSAdrian Lang global $lang; 1447585bf44eSChristopher Smith /** @var Input $INPUT */ 1448ac7a515fSAndreas Gohr global $INPUT; 1449d9162c6cSKate Arzamastseva 1450ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 145124870174SAndreas Gohr if(!$opened_tab || !in_array($opened_tab, ['files', 'upload', 'search'])) $opened_tab = 'files'; 1452ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1453d9162c6cSKate Arzamastseva 145494add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 145595b451bcSAdrian Lang 1456ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 145723846a98SKate Arzamastseva 145894add303SAnika Henke echo '<div class="panelHeader">'.NL; 145995b451bcSAdrian Lang echo '<h3>'; 146024870174SAndreas Gohr $tabTitle = $NS ?: '['.$lang['mediaroot'].']'; 1461c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 146294add303SAnika Henke echo '</h3>'.NL; 146395b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 146495b451bcSAdrian Lang media_tab_files_options(); 146523846a98SKate Arzamastseva } 146694add303SAnika Henke echo '</div>'.NL; 1467d9162c6cSKate Arzamastseva 146894add303SAnika Henke echo '<div class="panelContent">'.NL; 146995b451bcSAdrian Lang if($opened_tab == 'files') { 147095b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 147195b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 147295b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 147395b451bcSAdrian Lang } elseif($opened_tab == 'search') { 147495b451bcSAdrian Lang media_tab_search($NS, $AUTH); 147595b451bcSAdrian Lang } 147694add303SAnika Henke echo '</div>'.NL; 1477d9162c6cSKate Arzamastseva} 1478d9162c6cSKate Arzamastseva 1479d9162c6cSKate Arzamastseva/** 1480d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1481d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1482d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1483d9162c6cSKate Arzamastseva * list of file revisions 1484d9162c6cSKate Arzamastseva * 1485d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1486f50a239bSTakamura * 1487f50a239bSTakamura * @param string $image 1488f50a239bSTakamura * @param boolean $rev 1489d9162c6cSKate Arzamastseva */ 1490d868eb89SAndreas Gohrfunction tpl_mediaFileDetails($image, $rev) 1491d868eb89SAndreas Gohr{ 1492e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1493585bf44eSChristopher Smith /** @var Input $INPUT */ 1494585bf44eSChristopher Smith global $INPUT; 1495d9162c6cSKate Arzamastseva 149664159a61SAndreas Gohr $removed = ( 149764159a61SAndreas Gohr !file_exists(mediaFN($image)) && 149864159a61SAndreas Gohr file_exists(mediaMetaFN($image, '.changes')) && 149964159a61SAndreas Gohr $conf['mediarevisions'] 150064159a61SAndreas Gohr ); 1501ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 15026dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1503e8a2a143SMichael Hamann $ns = getNS($image); 1504ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 15051eeeced2SKate Arzamastseva 1506ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1507e5d185e1SKate Arzamastseva 150824870174SAndreas Gohr $tab_array = ['view']; 150924870174SAndreas Gohr [, $mime] = mimetype($image); 1510e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1511e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1512e5d185e1SKate Arzamastseva } 1513e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1514e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1515e5d185e1SKate Arzamastseva } 1516e5d185e1SKate Arzamastseva 1517e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1518ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 151923846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1520d9162c6cSKate Arzamastseva 1521ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 152223846a98SKate Arzamastseva 152359f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 152424870174SAndreas Gohr [$ext] = mimetype($image, false); 152595b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 152695b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 152724870174SAndreas Gohr 1528750a0b51SMichael Große $attributes = $rev ? ['rev' => $rev] : []; 152964159a61SAndreas Gohr $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'. 153064159a61SAndreas Gohr $image.'</a>'.'</strong>'; 153108317413SAdrian Lang if($opened_tab === 'view' && $rev) { 153208317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 153308317413SAdrian Lang } else { 1534026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 153508317413SAdrian Lang } 1536b8a84c03SAndreas Gohr 153794add303SAnika Henke echo '</h3></div>'.NL; 153895b451bcSAdrian Lang 153994add303SAnika Henke echo '<div class="panelContent">'.NL; 154095b451bcSAdrian Lang 154123846a98SKate Arzamastseva if($opened_tab == 'view') { 1542e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 154323846a98SKate Arzamastseva 154492cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1545e8a2a143SMichael Hamann media_tab_edit($image, $ns); 154623846a98SKate Arzamastseva 1547e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1548e8a2a143SMichael Hamann media_tab_history($image, $ns); 154923846a98SKate Arzamastseva } 155095b451bcSAdrian Lang 155194add303SAnika Henke echo '</div>'.NL; 1552d9162c6cSKate Arzamastseva} 1553d9162c6cSKate Arzamastseva 1554d9162c6cSKate Arzamastseva/** 15557abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 15563df72098SAndreas Gohr * 15573df72098SAndreas Gohr * Only allowed in mediamanager.php 15583df72098SAndreas Gohr * 15593df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15603df72098SAndreas Gohr */ 1561d868eb89SAndreas Gohrfunction tpl_mediaTree() 1562d868eb89SAndreas Gohr{ 15633df72098SAndreas Gohr global $NS; 156423846a98SKate Arzamastseva ptln('<div id="media__tree">'); 15653df72098SAndreas Gohr media_nstree($NS); 15663df72098SAndreas Gohr ptln('</div>'); 15673df72098SAndreas Gohr} 15683df72098SAndreas Gohr 1569a00de5b5SAndreas Gohr/** 1570a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1571a00de5b5SAndreas Gohr * 1572a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1573a00de5b5SAndreas Gohr * 1574a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 157542ea7f44SGerrit Uitslag * 157642ea7f44SGerrit Uitslag * @param string $empty empty option label 157742ea7f44SGerrit Uitslag * @param string $button submit button label 1578affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 1579a00de5b5SAndreas Gohr */ 1580d868eb89SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') 1581d868eb89SAndreas Gohr{ 1582affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 158324870174SAndreas Gohr $menu = new MobileMenu(); 15841e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1585a00de5b5SAndreas Gohr} 1586a00de5b5SAndreas Gohr 1587066fee30SAndreas Gohr/** 1588066fee30SAndreas Gohr * Print a informational line about the used license 1589066fee30SAndreas Gohr * 1590066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1591ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1592ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1593ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1594ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1595ac7a515fSAndreas Gohr * @return string 1596066fee30SAndreas Gohr */ 1597d868eb89SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) 1598d868eb89SAndreas Gohr{ 1599066fee30SAndreas Gohr global $license; 1600066fee30SAndreas Gohr global $conf; 1601066fee30SAndreas Gohr global $lang; 1602066fee30SAndreas Gohr if(!$conf['license']) return ''; 1603066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1604066fee30SAndreas Gohr $lic = $license[$conf['license']]; 160553e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1606066fee30SAndreas Gohr 160780083a41SAndreas Gohr $out = ''; 160880083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1609066fee30SAndreas Gohr if($img) { 1610066fee30SAndreas Gohr $src = license_img($img); 1611066fee30SAndreas Gohr if($src) { 161253e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 161353e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 161453e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1615066fee30SAndreas Gohr } 1616066fee30SAndreas Gohr } 16174cefd216SMichael Klier if(!$imgonly) { 161853e15c8bSAnika Henke $out .= $lang['license'].' '; 1619d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1620d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 16214cefd216SMichael Klier } 162280083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1623066fee30SAndreas Gohr 1624066fee30SAndreas Gohr if($return) return $out; 1625066fee30SAndreas Gohr echo $out; 1626ac7a515fSAndreas Gohr return ''; 1627066fee30SAndreas Gohr} 1628066fee30SAndreas Gohr 1629a81910eeSAndreas Gohr/** 1630835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1631a81910eeSAndreas Gohr * 1632a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1633a81910eeSAndreas Gohr * template 1634e0c26282SGerrit Uitslag * 16357a112df5SAndreas Gohr * @param string $pageid The page name you want to include 16367a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 16377a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 16387c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1639e0c26282SGerrit Uitslag * @return bool|null|string 1640a81910eeSAndreas Gohr */ 1641d868eb89SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) 1642d868eb89SAndreas Gohr{ 16437a112df5SAndreas Gohr if($propagate) { 16447c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 16457c3e4a67SAndreas Gohr } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 16467a112df5SAndreas Gohr return false; 16477a112df5SAndreas Gohr } 1648c786a1b6SAnika Henke if(!$pageid) return false; 1649835dfcaeSAnika Henke 1650c786a1b6SAnika Henke global $TOC; 16519a2e250aSAndreas Gohr $oldtoc = $TOC; 1652a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 16539a2e250aSAndreas Gohr $TOC = $oldtoc; 1654a81910eeSAndreas Gohr 1655a2e03c82SAndreas Gohr if($print) echo $html; 1656e66d3e6dSAndreas Gohr return $html; 1657e66d3e6dSAndreas Gohr} 1658e66d3e6dSAndreas Gohr 1659e66d3e6dSAndreas Gohr/** 16605b75cd1fSAdrian Lang * Display the subscribe form 16615b75cd1fSAdrian Lang * 16625b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 1663848cb786SSatoshi Sahara * @deprecated 2020-07-23 16645b75cd1fSAdrian Lang */ 1665d868eb89SAndreas Gohrfunction tpl_subscribe() 1666d868eb89SAndreas Gohr{ 166724870174SAndreas Gohr dbg_deprecated(Subscribe::class .'::show()'); 1668*73022918SAndreas Gohr (new Subscribe())->show(); 16695b75cd1fSAdrian Lang} 16705b75cd1fSAdrian Lang 1671d059ba9bSAndreas Gohr/** 1672d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1673d059ba9bSAndreas Gohr * 1674d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1675d059ba9bSAndreas Gohr * 1676d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1677d059ba9bSAndreas Gohr */ 1678d868eb89SAndreas Gohrfunction tpl_flush() 1679d868eb89SAndreas Gohr{ 1680c2009796SZemoj if( ob_get_level() > 0 ) ob_flush(); 1681d059ba9bSAndreas Gohr flush(); 1682d059ba9bSAndreas Gohr} 1683d059ba9bSAndreas Gohr 1684afca7e7eSAnika Henke/** 1685378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1686afca7e7eSAnika Henke * 1687378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1688378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1689378325f9SAndreas Gohr * 169042ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1691378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1692ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 16936dc405e1SAndreas Gohr * @param bool $fallback use fallback image if target isn't found or return 'false' if potential 16946dc405e1SAndreas Gohr * false result is required 1695ac7a515fSAndreas Gohr * @return string 169642ea7f44SGerrit Uitslag * 1697378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1698afca7e7eSAnika Henke */ 1699d868eb89SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) 1700d868eb89SAndreas Gohr{ 1701ac7a515fSAndreas Gohr $img = ''; 1702ac7a515fSAndreas Gohr $file = ''; 1703ac7a515fSAndreas Gohr $ismedia = false; 1704378325f9SAndreas Gohr // loop through candidates until a match was found: 1705378325f9SAndreas Gohr foreach($search as $img) { 1706378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1707378325f9SAndreas Gohr $file = mediaFN($img); 1708378325f9SAndreas Gohr $ismedia = true; 1709378325f9SAndreas Gohr } else { 1710c4766956SAndreas Gohr $file = tpl_incdir().$img; 1711378325f9SAndreas Gohr $ismedia = false; 17121f13e33dSAnika Henke } 17130f747863Slupo49 1714378325f9SAndreas Gohr if(file_exists($file)) break; 1715872a6d29SAnika Henke } 1716378325f9SAndreas Gohr 171708a13262SSimon DELAGE // manage non existing target 171808a13262SSimon DELAGE if (!file_exists($file)) { 171908a13262SSimon DELAGE // give result for fallback image 172024870174SAndreas Gohr if ($fallback) { 1721c238d757SSimon DELAGE $file = DOKU_INC . 'lib/images/blank.gif'; 172208a13262SSimon DELAGE // stop process if false result is required (if $fallback is false) 172308a13262SSimon DELAGE } else { 172408a13262SSimon DELAGE return false; 172508a13262SSimon DELAGE } 172608a13262SSimon DELAGE } 1727ca5b6a64SSimon DELAGE 1728378325f9SAndreas Gohr // fetch image data if requested 1729378325f9SAndreas Gohr if(!is_null($imginfo)) { 1730378325f9SAndreas Gohr $imginfo = getimagesize($file); 1731378325f9SAndreas Gohr } 1732378325f9SAndreas Gohr 1733378325f9SAndreas Gohr // build URL 1734378325f9SAndreas Gohr if($ismedia) { 1735378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1736378325f9SAndreas Gohr } else { 1737c4766956SAndreas Gohr $url = tpl_basedir().$img; 1738378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1739378325f9SAndreas Gohr } 1740378325f9SAndreas Gohr 1741378325f9SAndreas Gohr return $url; 1742a7e5f74cSlupo49} 17431f13e33dSAnika Henke 1744872a6d29SAnika Henke/** 1745e5d4768dSAndreas Gohr * PHP include a file 1746e5d4768dSAndreas Gohr * 1747e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1748e5d4768dSAndreas Gohr * file in the template's root directory. 1749e5d4768dSAndreas Gohr * 1750e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1751e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1752e5d4768dSAndreas Gohr * default. 1753e5d4768dSAndreas Gohr * 1754e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1755e5d4768dSAndreas Gohr * to this function! 1756e5d4768dSAndreas Gohr * 1757e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1758e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 175942ea7f44SGerrit Uitslag * 176042ea7f44SGerrit Uitslag * @param string $file 1761e5d4768dSAndreas Gohr */ 1762d868eb89SAndreas Gohrfunction tpl_includeFile($file) 1763d868eb89SAndreas Gohr{ 1764e5d4768dSAndreas Gohr global $config_cascade; 176524870174SAndreas Gohr foreach(['protected', 'local', 'default'] as $config_group) { 1766e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1767e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1768e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1769e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1770f3a1225fSAnika Henke include("$dir/$file"); 1771e5d4768dSAndreas Gohr return; 1772e5d4768dSAndreas Gohr } 1773e5d4768dSAndreas Gohr } 1774e5d4768dSAndreas Gohr } 1775e5d4768dSAndreas Gohr 1776e5d4768dSAndreas Gohr // still here? try the template dir 1777e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1778e5d4768dSAndreas Gohr if(file_exists($file)) { 1779f3a1225fSAnika Henke include($file); 1780e5d4768dSAndreas Gohr } 1781e5d4768dSAndreas Gohr} 1782e5d4768dSAndreas Gohr 1783e5d4768dSAndreas Gohr/** 1784872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1785872a6d29SAnika Henke * 1786872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 178742ea7f44SGerrit Uitslag * 1788ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1789ac7a515fSAndreas Gohr * @return string 1790872a6d29SAnika Henke */ 1791d868eb89SAndreas Gohrfunction tpl_favicon($types = ['favicon']) 1792d868eb89SAndreas Gohr{ 1793872a6d29SAnika Henke 1794872a6d29SAnika Henke $return = ''; 1795872a6d29SAnika Henke 1796872a6d29SAnika Henke foreach($types as $type) { 1797872a6d29SAnika Henke switch($type) { 1798872a6d29SAnika Henke case 'favicon': 179924870174SAndreas Gohr $look = [':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico']; 1800378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1801872a6d29SAnika Henke break; 1802872a6d29SAnika Henke case 'mobile': 180324870174SAndreas Gohr $look = [':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png']; 1804378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1805872a6d29SAnika Henke break; 1806872a6d29SAnika Henke case 'generic': 1807872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 180824870174SAndreas Gohr $look = [':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg']; 1809378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1810872a6d29SAnika Henke break; 1811872a6d29SAnika Henke } 1812872a6d29SAnika Henke } 1813872a6d29SAnika Henke 1814872a6d29SAnika Henke return $return; 1815afca7e7eSAnika Henke} 1816afca7e7eSAnika Henke 1817d9162c6cSKate Arzamastseva/** 1818d9162c6cSKate Arzamastseva * Prints full-screen media manager 1819d9162c6cSKate Arzamastseva * 1820d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1821d9162c6cSKate Arzamastseva */ 1822d868eb89SAndreas Gohrfunction tpl_media() 1823d868eb89SAndreas Gohr{ 1824ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 182588a71175SKate Arzamastseva $fullscreen = true; 182695b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1827d9162c6cSKate Arzamastseva 1828ac7a515fSAndreas Gohr $rev = ''; 1829ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 183098f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 183198f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 18329c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 183398f03b57SKate Arzamastseva 183494add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1835bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1836d9162c6cSKate Arzamastseva html_msgarea(); 183794add303SAnika Henke 183894add303SAnika Henke echo '<div class="panel namespaces">'.NL; 183994add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 184095b451bcSAdrian Lang echo '<div class="panelHeader">'; 1841ba340a70SAnika Henke echo $lang['media_namespaces']; 184294add303SAnika Henke echo '</div>'.NL; 184395b451bcSAdrian Lang 184494add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 184595b451bcSAdrian Lang media_nstree($NS); 184694add303SAnika Henke echo '</div>'.NL; 184794add303SAnika Henke echo '</div>'.NL; 1848fa8e5c77SKate Arzamastseva 184994add303SAnika Henke echo '<div class="panel filelist">'.NL; 1850035e07f1SKate Arzamastseva tpl_mediaFileList(); 185194add303SAnika Henke echo '</div>'.NL; 1852fa8e5c77SKate Arzamastseva 185394add303SAnika Henke echo '<div class="panel file">'.NL; 185494add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1855035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 185694add303SAnika Henke echo '</div>'.NL; 1857ba340a70SAnika Henke 185894add303SAnika Henke echo '</div>'.NL; 1859d9162c6cSKate Arzamastseva} 1860afca7e7eSAnika Henke 1861c71db656SAnika Henke/** 1862c71db656SAnika Henke * Return useful layout classes 1863c71db656SAnika Henke * 1864c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 186542ea7f44SGerrit Uitslag * 186642ea7f44SGerrit Uitslag * @return string 1867c71db656SAnika Henke */ 1868d868eb89SAndreas Gohrfunction tpl_classes() 1869d868eb89SAndreas Gohr{ 1870c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1871585bf44eSChristopher Smith /** @var Input $INPUT */ 1872585bf44eSChristopher Smith global $INPUT; 1873585bf44eSChristopher Smith 187424870174SAndreas Gohr $classes = [ 1875c71db656SAnika Henke 'dokuwiki', 1876c71db656SAnika Henke 'mode_'.$ACT, 1877c71db656SAnika Henke 'tpl_'.$conf['template'], 1878585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 187990eb1b7bSEduardo Mozart de Oliveira (isset($INFO['exists']) && $INFO['exists']) ? '' : 'notFound', 188024870174SAndreas Gohr ($ID == $conf['start']) ? 'home' : '' 188124870174SAndreas Gohr ]; 188224870174SAndreas Gohr return implode(' ', $classes); 1883c71db656SAnika Henke} 1884c71db656SAnika Henke 188584dd2b1aSGerrit Uitslag/** 188684dd2b1aSGerrit Uitslag * Create event for tools menues 188784dd2b1aSGerrit Uitslag * 188884dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 188984dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 189084dd2b1aSGerrit Uitslag * @param array $items 189184dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 1892affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 189384dd2b1aSGerrit Uitslag */ 1894d868eb89SAndreas Gohrfunction tpl_toolsevent($toolsname, $items, $view = 'main') 1895d868eb89SAndreas Gohr{ 1896affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 189724870174SAndreas Gohr $data = ['view' => $view, 'items' => $items]; 189884dd2b1aSGerrit Uitslag 189984dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 1900e1d9dcc8SAndreas Gohr $evt = new Event($hook, $data); 190184dd2b1aSGerrit Uitslag if($evt->advise_before()) { 190224870174SAndreas Gohr foreach($evt->data['items'] as $html) echo $html; 190384dd2b1aSGerrit Uitslag } 190484dd2b1aSGerrit Uitslag $evt->advise_after(); 190584dd2b1aSGerrit Uitslag} 190684dd2b1aSGerrit Uitslag 1907e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1908