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 */ 86b13307fSandi 9e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 10e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event; 11*8c6be208SAndreas Gohruse dokuwiki\Utils\PageResolver; 12e1d9dcc8SAndreas Gohr 136b13307fSandi/** 14ac7a515fSAndreas Gohr * Access a template file 15ac7a515fSAndreas Gohr * 16ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses 17ac7a515fSAndreas Gohr * default template if the custom version doesn't exist. 185a892029SAndreas Gohr * 195a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 20ac7a515fSAndreas Gohr * @param string $file 21ac7a515fSAndreas Gohr * @return string 225a892029SAndreas Gohr */ 23ac7a515fSAndreas Gohrfunction template($file) { 245a892029SAndreas Gohr global $conf; 255a892029SAndreas Gohr 26ac7a515fSAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 27ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 285a892029SAndreas Gohr 29ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 305a892029SAndreas Gohr} 315a892029SAndreas Gohr 32c4766956SAndreas Gohr/** 33c4766956SAndreas Gohr * Convenience function to access template dir from local FS 34c4766956SAndreas Gohr * 35c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant 36c4766956SAndreas Gohr * 37c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 38afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 39ac7a515fSAndreas Gohr * @return string 40c4766956SAndreas Gohr */ 41afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') { 4275b14482SAndreas Gohr global $conf; 43afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 44afb2c082SAndreas Gohr return DOKU_INC.'lib/tpl/'.$tpl.'/'; 45c4766956SAndreas Gohr} 46c4766956SAndreas Gohr 47c4766956SAndreas Gohr/** 48c4766956SAndreas Gohr * Convenience function to access template dir from web 49c4766956SAndreas Gohr * 50c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 51c4766956SAndreas Gohr * 52c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 53afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 54ac7a515fSAndreas Gohr * @return string 55c4766956SAndreas Gohr */ 5699dca513SAndreas Gohrfunction tpl_basedir($tpl='') { 5775b14482SAndreas Gohr global $conf; 58afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 59dcd4911eSMichael Hamann return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 60c4766956SAndreas Gohr} 61c4766956SAndreas Gohr 625a892029SAndreas Gohr/** 636b13307fSandi * Print the content 646b13307fSandi * 656b13307fSandi * This function is used for printing all the usual content 666b13307fSandi * (defined by the global $ACT var) by calling the appropriate 676b13307fSandi * outputfunction(s) from html.php 686b13307fSandi * 69ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 70ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 716b13307fSandi * 726b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 7342ea7f44SGerrit Uitslag * 74ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 75ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 76ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 77ac7a515fSAndreas Gohr * @return bool true if any output 786b13307fSandi */ 79b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) { 807ea0913cSchris global $ACT; 81b8595a66SAndreas Gohr global $INFO; 82b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 837ea0913cSchris 847ea0913cSchris ob_start(); 85cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 867ea0913cSchris $html_output = ob_get_clean(); 87cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 8854e95700STom N Harris 8954e95700STom N Harris return !empty($html_output); 907ea0913cSchris} 917ea0913cSchris 92ac7a515fSAndreas Gohr/** 93ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 94ac7a515fSAndreas Gohr * 95ac7a515fSAndreas Gohr * @return bool 96ac7a515fSAndreas Gohr */ 977ea0913cSchrisfunction tpl_content_core() { 98952acff9SAndreas Gohr $router = \dokuwiki\ActionRouter::getInstance(); 99952acff9SAndreas Gohr try { 100952acff9SAndreas Gohr $router->getAction()->tplContent(); 101952acff9SAndreas Gohr } catch(\dokuwiki\Action\Exception\FatalException $e) { 102952acff9SAndreas Gohr // there was no content for the action 103952acff9SAndreas Gohr msg(hsc($e->getMessage()), -1); 10454e95700STom N Harris return false; 1056b13307fSandi } 10654e95700STom N Harris return true; 1076b13307fSandi} 1086b13307fSandi 109c19fe9c0Sandi/** 110b8595a66SAndreas Gohr * Places the TOC where the function is called 111b8595a66SAndreas Gohr * 112b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 113b8595a66SAndreas Gohr * a false argument 114b8595a66SAndreas Gohr * 115b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11642ea7f44SGerrit Uitslag * 117ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 118ac7a515fSAndreas Gohr * @return string 119b8595a66SAndreas Gohr */ 120b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 121b8595a66SAndreas Gohr global $TOC; 122b8595a66SAndreas Gohr global $ACT; 123b8595a66SAndreas Gohr global $ID; 124b8595a66SAndreas Gohr global $REV; 125b8595a66SAndreas Gohr global $INFO; 126851f2e89SAnika Henke global $conf; 127ac7a515fSAndreas Gohr global $INPUT; 128b8595a66SAndreas Gohr $toc = array(); 129b8595a66SAndreas Gohr 130b8595a66SAndreas Gohr if(is_array($TOC)) { 131b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 132b8595a66SAndreas Gohr $toc = $TOC; 1333c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 134b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 135e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 136b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 137b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 138b8595a66SAndreas Gohr } else { 1392bb0d541Schris $tocok = true; 140b8595a66SAndreas Gohr } 141f87b5dbbSChristopher Smith $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 142851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 143b8595a66SAndreas Gohr $toc = array(); 144b8595a66SAndreas Gohr } 145b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 146a61966c5SChristopher Smith // try to load admin plugin TOC 147e1d9dcc8SAndreas Gohr /** @var $plugin AdminPlugin */ 148a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 149b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 150b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 151b8595a66SAndreas Gohr } 152b8595a66SAndreas Gohr } 153b8595a66SAndreas Gohr 154cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false); 155b8595a66SAndreas Gohr $html = html_TOC($toc); 156b8595a66SAndreas Gohr if($return) return $html; 157b8595a66SAndreas Gohr echo $html; 158ac7a515fSAndreas Gohr return ''; 159b8595a66SAndreas Gohr} 160b8595a66SAndreas Gohr 161b8595a66SAndreas Gohr/** 162c19fe9c0Sandi * Handle the admin page contents 163c19fe9c0Sandi * 164c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 16542ea7f44SGerrit Uitslag * 16642ea7f44SGerrit Uitslag * @return bool 167c19fe9c0Sandi */ 168c19fe9c0Sandifunction tpl_admin() { 169f8cc712eSAndreas Gohr global $INFO; 170b8595a66SAndreas Gohr global $TOC; 171ac7a515fSAndreas Gohr global $INPUT; 17211e2ce22Schris 173b8595a66SAndreas Gohr $plugin = null; 174ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 175ac7a515fSAndreas Gohr if(!empty($class)) { 17611e2ce22Schris $pluginlist = plugin_list('admin'); 17711e2ce22Schris 178ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 17911e2ce22Schris // attempt to load the plugin 180e1d9dcc8SAndreas Gohr /** @var $plugin AdminPlugin */ 181a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 18211e2ce22Schris } 18311e2ce22Schris } 18411e2ce22Schris 185b8595a66SAndreas Gohr if($plugin !== null) { 186b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 187b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 188f8cc712eSAndreas Gohr $plugin->html(); 189f8cc712eSAndreas Gohr } else { 1900470c28fSAndreas Gohr $admin = new dokuwiki\Ui\Admin(); 1910470c28fSAndreas Gohr $admin->show(); 192f8cc712eSAndreas Gohr } 19354e95700STom N Harris return true; 194c19fe9c0Sandi} 1956b13307fSandi 1966b13307fSandi/** 1976b13307fSandi * Print the correct HTML meta headers 1986b13307fSandi * 1996b13307fSandi * This has to go into the head section of your template. 2006b13307fSandi * 2016b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 20242ea7f44SGerrit Uitslag * 203ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 204ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 205ac7a515fSAndreas Gohr * @return bool 2066b13307fSandi */ 207f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2086b13307fSandi global $ID; 209d98d4540SBen Coburn global $REV; 2106b13307fSandi global $INFO; 21172e0dc37SAndreas Gohr global $JSINFO; 2126b13307fSandi global $ACT; 2134bb1b5aeSAndreas Gohr global $QUERY; 2146b13307fSandi global $lang; 215dc57ef04Sandi global $conf; 2169c438d6cSMichael Hamann global $updateVersion; 217585bf44eSChristopher Smith /** @var Input $INPUT */ 218585bf44eSChristopher Smith global $INPUT; 2196b13307fSandi 2207bff22c0SAndreas Gohr // prepare the head array 2217bff22c0SAndreas Gohr $head = array(); 2227bff22c0SAndreas Gohr 223202ac28bSMichael Klier // prepare seed for js and css 224cd997f93SAndreas Gohr $tseed = $updateVersion; 225202ac28bSMichael Klier $depends = getConfigFiles('main'); 22684e76a7eSAndreas Gohr $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini"; 227cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 228cd997f93SAndreas Gohr $tseed = md5($tseed); 2297bff22c0SAndreas Gohr 2306b13307fSandi // the usual stuff 2313f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 23263cf4192Ssarehag if(actionOK('search')) { 233ac7a515fSAndreas Gohr $head['link'][] = array( 234ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 235ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 236ac7a515fSAndreas Gohr ); 23763cf4192Ssarehag } 23863cf4192Ssarehag 239f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 2407aedde2eSGina Haeussge if(actionOK('index')) { 241ac7a515fSAndreas Gohr $head['link'][] = array( 242ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 243ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 244ac7a515fSAndreas Gohr ); 2457aedde2eSGina Haeussge } 246f96fa415SAndreas Gohr 2475e0255e3SMichael Große if (actionOK('manifest')) { 2485e0255e3SMichael Große $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php'); 2495e0255e3SMichael Große } 2505e0255e3SMichael Große 25140ca8540SMichael Große $styleUtil = new \dokuwiki\StyleUtils(); 2524593dbd2SAnna Dabrowska $styleIni = $styleUtil->cssStyleini(); 25340ca8540SMichael Große $replacements = $styleIni['replacements']; 25440ca8540SMichael Große if (!empty($replacements['__theme_color__'])) { 25540ca8540SMichael Große $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']); 25640ca8540SMichael Große } 25740ca8540SMichael Große 258f96fa415SAndreas Gohr if($alt) { 25954be1338SGerrit Uitslag if(actionOK('rss')) { 260ac7a515fSAndreas Gohr $head['link'][] = array( 261ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 262a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 263ac7a515fSAndreas Gohr ); 264ac7a515fSAndreas Gohr $head['link'][] = array( 265ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 266a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 267aac83cd4SPhy 'href' => DOKU_BASE.'feed.php?mode=list&ns='.(isset($INFO) ? $INFO['namespace'] : '') 268ac7a515fSAndreas Gohr ); 26954be1338SGerrit Uitslag } 270c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 271ac7a515fSAndreas Gohr $head['link'][] = array( 272ac7a515fSAndreas Gohr 'rel' => 'edit', 273715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 274ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 275ac7a515fSAndreas Gohr ); 276c35f3875SAndreas Gohr } 277c35f3875SAndreas Gohr 27854be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 279ac7a515fSAndreas Gohr $head['link'][] = array( 280ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 281a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 282ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 283ac7a515fSAndreas Gohr ); 2844bb1b5aeSAndreas Gohr } 285bae36d94SAndreas Gohr 286bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 287ac7a515fSAndreas Gohr $head['link'][] = array( 288a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 289ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 290ac7a515fSAndreas Gohr ); 291bae36d94SAndreas Gohr } 292bae36d94SAndreas Gohr 293bae36d94SAndreas Gohr if(actionOK('export_raw')) { 294ac7a515fSAndreas Gohr $head['link'][] = array( 295a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 296ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 297ac7a515fSAndreas Gohr ); 298f96fa415SAndreas Gohr } 299bae36d94SAndreas Gohr } 3006b13307fSandi 3016b13307fSandi // setup robot tags apropriate for different modes 3024f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3036b13307fSandi if($INFO['exists']) { 3046b13307fSandi //delay indexing: 305fb9fa88bSAndreas Gohr if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) { 3067bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3076b13307fSandi } else { 3087bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3096b13307fSandi } 31001f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 31101f9be51SAnika Henke if ($ID == $conf['start']) { 31201f9be51SAnika Henke $canonicalUrl = DOKU_URL; 31301f9be51SAnika Henke } 31401f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3156b13307fSandi } else { 3167bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3176b13307fSandi } 3187a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3197bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3206b13307fSandi } else { 3217bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3226b13307fSandi } 3236b13307fSandi 324831800b8SAndreas Gohr // set metadata 325831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 326831800b8SAndreas Gohr // keywords (explicit or implicit) 327bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3287bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 329831800b8SAndreas Gohr } else { 3307bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 331831800b8SAndreas Gohr } 332831800b8SAndreas Gohr } 333831800b8SAndreas Gohr 33478a6aeb1SAndreas Gohr // load stylesheets 335ac7a515fSAndreas Gohr $head['link'][] = array( 33659305168SPhy 'rel' => 'stylesheet', 337e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 338ac7a515fSAndreas Gohr ); 339bad31ae9SAndreas Gohr 340aac83cd4SPhy $script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';"; 341585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 34298169a0fSAndreas Gohr $script .= "var SIG=".toolbar_signature().";"; 343c591aabeSAndreas Gohr } 3440c39d46cSMichael Große jsinfo(); 3451d739e3dSMichael Große $script .= 'var JSINFO = ' . json_encode($JSINFO).';'; 34659305168SPhy $head['script'][] = array('_data'=> $script); 3478bbcb611SAndreas Gohr 34861537d47SAndreas Gohr // load jquery 349fa078663SAndreas Gohr $jquery = getCdnUrls(); 350fa078663SAndreas Gohr foreach($jquery as $src) { 35161537d47SAndreas Gohr $head['script'][] = array( 352fc6b11d2SMichael Große 'charset' => 'utf-8', 353fc6b11d2SMichael Große '_data' => '', 354fc6b11d2SMichael Große 'src' => $src, 355fc6b11d2SMichael Große ) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); 35661537d47SAndreas Gohr } 35761537d47SAndreas Gohr 35861537d47SAndreas Gohr // load our javascript dispatcher 359ac7a515fSAndreas Gohr $head['script'][] = array( 36059305168SPhy 'charset'=> 'utf-8', '_data'=> '', 361cef1629dSRainbow Spike 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed, 362fc6b11d2SMichael Große ) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []); 3637bff22c0SAndreas Gohr 3647bff22c0SAndreas Gohr // trigger event here 365cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 36654e95700STom N Harris return true; 3677bff22c0SAndreas Gohr} 3687bff22c0SAndreas Gohr 3697bff22c0SAndreas Gohr/** 3707bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 3717bff22c0SAndreas Gohr * 3727bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 3737bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 3747bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 3757bff22c0SAndreas Gohr * 37642ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 3771304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 3787bff22c0SAndreas Gohr * 3797bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 38042ea7f44SGerrit Uitslag * 38142ea7f44SGerrit Uitslag * @param array $data 3827bff22c0SAndreas Gohr */ 3837bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 3847bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 385427bf9a2SAndreas Gohr if($tag == 'script') { 386427bf9a2SAndreas Gohr echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE 387427bf9a2SAndreas Gohr } 3887bff22c0SAndreas Gohr foreach($inst as $attr) { 3899b48e6a1SGerry Weißbach if ( empty($attr) ) { continue; } 3907bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 39126afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 392e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 39309f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 394e226efe1SAndreas Gohr $attr['_data']. 39509f791c4SDominik Eckelmann "\n/*!]]>*/"; 396e226efe1SAndreas Gohr 3971304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 3987bff22c0SAndreas Gohr } else { 3997bff22c0SAndreas Gohr echo '/>'; 4007bff22c0SAndreas Gohr } 4017bff22c0SAndreas Gohr echo "\n"; 4027bff22c0SAndreas Gohr } 403427bf9a2SAndreas Gohr if($tag == 'script') { 404427bf9a2SAndreas Gohr echo "<!--<![endif]-->\n"; 405427bf9a2SAndreas Gohr } 4067bff22c0SAndreas Gohr } 4076b13307fSandi} 4086b13307fSandi 4096b13307fSandi/** 4106b13307fSandi * Print a link 4116b13307fSandi * 4125e163278SAndreas Gohr * Just builds a link. 4136b13307fSandi * 4146b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 41542ea7f44SGerrit Uitslag * 41642ea7f44SGerrit Uitslag * @param string $url 41742ea7f44SGerrit Uitslag * @param string $name 41842ea7f44SGerrit Uitslag * @param string $more 41921d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 42021d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4216b13307fSandi */ 4221af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 42301f17825SAnika Henke $out = '<a href="'.$url.'" '; 4241af98a77SAnika Henke if($more) $out .= ' '.$more; 4251af98a77SAnika Henke $out .= ">$name</a>"; 4261af98a77SAnika Henke if($return) return $out; 4271af98a77SAnika Henke print $out; 42854e95700STom N Harris return true; 4296b13307fSandi} 4306b13307fSandi 4316b13307fSandi/** 43255efc227SAndreas Gohr * Prints a link to a WikiPage 43355efc227SAndreas Gohr * 43455efc227SAndreas Gohr * Wrapper around html_wikilink 43555efc227SAndreas Gohr * 43655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 43742ea7f44SGerrit Uitslag * 43842ea7f44SGerrit Uitslag * @param string $id page id 43942ea7f44SGerrit Uitslag * @param string|null $name the name of the link 440fb008d31SIain Hallam * @param bool $return 441fb008d31SIain Hallam * @return true|string 44255efc227SAndreas Gohr */ 443c4a386f1SIain Hallamfunction tpl_pagelink($id, $name = null, $return = false) { 444c4a386f1SIain Hallam $out = '<bdi>'.html_wikilink($id, $name).'</bdi>'; 445c4a386f1SIain Hallam if($return) return $out; 446c4a386f1SIain Hallam print $out; 44754e95700STom N Harris return true; 44855efc227SAndreas Gohr} 44955efc227SAndreas Gohr 45055efc227SAndreas Gohr/** 451a3ec5f4aSmatthiasgrimm * get the parent page 452a3ec5f4aSmatthiasgrimm * 453a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 454a3ec5f4aSmatthiasgrimm * returns false if none is available 455a3ec5f4aSmatthiasgrimm * 456377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 45742ea7f44SGerrit Uitslag * 45842ea7f44SGerrit Uitslag * @param string $id page id 45942ea7f44SGerrit Uitslag * @return false|string 460a3ec5f4aSmatthiasgrimm */ 461377f9e97SAndreas Gohrfunction tpl_getparent($id) { 462*8c6be208SAndreas Gohr $resolver = new PageResolver('root'); 463*8c6be208SAndreas Gohr 464377f9e97SAndreas Gohr $parent = getNS($id).':'; 465*8c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 466a197105eSmatthiasgrimm if($parent == $id) { 467a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 468a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 469*8c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 470377f9e97SAndreas Gohr if($parent == $id) return false; 471a197105eSmatthiasgrimm } 472377f9e97SAndreas Gohr return $parent; 473a3ec5f4aSmatthiasgrimm} 474a3ec5f4aSmatthiasgrimm 475a3ec5f4aSmatthiasgrimm/** 4766b13307fSandi * Print one of the buttons 4776b13307fSandi * 478a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 479a453d131SAdrian Lang * @see tpl_get_action 480e0c26282SGerrit Uitslag * 481e0c26282SGerrit Uitslag * @param string $type 482e0c26282SGerrit Uitslag * @param bool $return 483e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 484affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 4856b13307fSandi */ 4861af98a77SAnika Henkefunction tpl_button($type, $return = false) { 487affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 488a453d131SAdrian Lang $data = tpl_get_action($type); 489a453d131SAdrian Lang if($data === false) { 490a453d131SAdrian Lang return false; 491a453d131SAdrian Lang } elseif(!is_array($data)) { 492a453d131SAdrian Lang $out = sprintf($data, 'button'); 493409d7af7SAndreas Gohr } else { 494ac7a515fSAndreas Gohr /** 495ac7a515fSAndreas Gohr * @var string $accesskey 496ac7a515fSAndreas Gohr * @var string $id 497ac7a515fSAndreas Gohr * @var string $method 498ac7a515fSAndreas Gohr * @var array $params 499ac7a515fSAndreas Gohr */ 500a453d131SAdrian Lang extract($data); 501a453d131SAdrian Lang if($id === '#dokuwiki__top') { 502a453d131SAdrian Lang $out = html_topbtn(); 503409d7af7SAndreas Gohr } else { 504a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 505409d7af7SAndreas Gohr } 506409d7af7SAndreas Gohr } 5071af98a77SAnika Henke if($return) return $out; 508a453d131SAdrian Lang echo $out; 509a453d131SAdrian Lang return true; 5106b13307fSandi} 5116b13307fSandi 5126b13307fSandi/** 513ed630903Sandi * Like the action buttons but links 514ed630903Sandi * 515a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 516a453d131SAdrian Lang * @see tpl_get_action 517e0c26282SGerrit Uitslag * 51842ea7f44SGerrit Uitslag * @param string $type action command 519e0c26282SGerrit Uitslag * @param string $pre prefix of link 520e0c26282SGerrit Uitslag * @param string $suf suffix of link 521e0c26282SGerrit Uitslag * @param string $inner innerHML of link 52221d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 523e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 524affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 525a453d131SAdrian Lang */ 526a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 527affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 528a453d131SAdrian Lang global $lang; 529a453d131SAdrian Lang $data = tpl_get_action($type); 530a453d131SAdrian Lang if($data === false) { 531a453d131SAdrian Lang return false; 532a453d131SAdrian Lang } elseif(!is_array($data)) { 533a453d131SAdrian Lang $out = sprintf($data, 'link'); 534a453d131SAdrian Lang } else { 535ac7a515fSAndreas Gohr /** 536ac7a515fSAndreas Gohr * @var string $accesskey 537ac7a515fSAndreas Gohr * @var string $id 538ac7a515fSAndreas Gohr * @var string $method 539b1af9014SChristopher Smith * @var bool $nofollow 540ac7a515fSAndreas Gohr * @var array $params 541becfa414SGerrit Uitslag * @var string $replacement 542ac7a515fSAndreas Gohr */ 543a453d131SAdrian Lang extract($data); 544a453d131SAdrian Lang if(strpos($id, '#') === 0) { 545a453d131SAdrian Lang $linktarget = $id; 546a453d131SAdrian Lang } else { 547a453d131SAdrian Lang $linktarget = wl($id, $params); 548a453d131SAdrian Lang } 549a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 550becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 551becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 552becfa414SGerrit Uitslag } 553c7e90e3fSAnika Henke $akey = $addTitle = ''; 554c7e90e3fSAnika Henke if($accesskey) { 555c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 556c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 557c7e90e3fSAnika Henke } 558b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 559ac7a515fSAndreas Gohr $out = tpl_link( 560ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 561a453d131SAdrian Lang 'class="action '.$type.'" '. 562b1af9014SChristopher Smith $akey.$rel. 563e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 564ac7a515fSAndreas Gohr ); 565a453d131SAdrian Lang } 566a453d131SAdrian Lang if($return) return $out; 567a453d131SAdrian Lang echo $out; 568a453d131SAdrian Lang return true; 569a453d131SAdrian Lang} 570a453d131SAdrian Lang 571a453d131SAdrian Lang/** 572a453d131SAdrian Lang * Check the actions and get data for buttons and links 573ed630903Sandi * 574ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 575a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 576a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 577e0c26282SGerrit Uitslag * 578ac7a515fSAndreas Gohr * @param string $type 579ac7a515fSAndreas Gohr * @return array|bool|string 580affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 581ed630903Sandi */ 582a453d131SAdrian Langfunction tpl_get_action($type) { 583affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 584a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 5854c4b65c8SMichael Hamann if($type == 'subscription') $type = 'subscribe'; 5864887c154SAndreas Gohr if($type == 'img_backto') $type = 'imgBackto'; 587409d7af7SAndreas Gohr 5884887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 5894887c154SAndreas Gohr if(class_exists($class)) { 5904887c154SAndreas Gohr try { 5914887c154SAndreas Gohr /** @var \dokuwiki\Menu\Item\AbstractItem $item */ 5924887c154SAndreas Gohr $item = new $class; 5934887c154SAndreas Gohr $data = $item->getLegacyData(); 5947b4365a7SGerrit Uitslag $unknown = false; 5954887c154SAndreas Gohr } catch(\RuntimeException $ignored) { 5964887c154SAndreas Gohr return false; 597b8a111f5SMichael Klier } 598ed630903Sandi } else { 5994887c154SAndreas Gohr global $ID; 6004887c154SAndreas Gohr $data = array( 6014887c154SAndreas Gohr 'accesskey' => null, 6024887c154SAndreas Gohr 'type' => $type, 6034887c154SAndreas Gohr 'id' => $ID, 6044887c154SAndreas Gohr 'method' => 'get', 6054887c154SAndreas Gohr 'params' => array('do' => $type), 6064887c154SAndreas Gohr 'nofollow' => true, 6074887c154SAndreas Gohr 'replacement' => '', 608becfa414SGerrit Uitslag ); 6097b4365a7SGerrit Uitslag $unknown = true; 610ed630903Sandi } 6117b4365a7SGerrit Uitslag 612e1d9dcc8SAndreas Gohr $evt = new Event('TPL_ACTION_GET', $data); 6137b4365a7SGerrit Uitslag if($evt->advise_before()) { 6147b4365a7SGerrit Uitslag //handle unknown types 6157b4365a7SGerrit Uitslag if($unknown) { 61638d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6177b4365a7SGerrit Uitslag } 6187b4365a7SGerrit Uitslag } 6197b4365a7SGerrit Uitslag $evt->advise_after(); 6207b4365a7SGerrit Uitslag unset($evt); 6217b4365a7SGerrit Uitslag 6227b4365a7SGerrit Uitslag return $data; 623ed630903Sandi} 624ed630903Sandi 625ed630903Sandi/** 62601f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 62701f17825SAnika Henke * 62801f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 62942ea7f44SGerrit Uitslag * 63042ea7f44SGerrit Uitslag * @param string $type action command 631ac7a515fSAndreas Gohr * @param bool $link link or form button? 632e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 633ac7a515fSAndreas Gohr * @param bool $return return or print 634ac7a515fSAndreas Gohr * @param string $pre prefix for links 635ac7a515fSAndreas Gohr * @param string $suf suffix for links 636ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 637ac7a515fSAndreas Gohr * @return bool|string 638affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 63901f17825SAnika Henke */ 640ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 641affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 64201f17825SAnika Henke $out = ''; 643ac7a515fSAndreas Gohr if($link) { 644e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 645ac7a515fSAndreas Gohr } else { 646e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 647ac7a515fSAndreas Gohr } 64801f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 64901f17825SAnika Henke 65001f17825SAnika Henke if($return) return $out; 65101f17825SAnika Henke print $out; 65201f17825SAnika Henke return $out ? true : false; 65301f17825SAnika Henke} 65401f17825SAnika Henke 65501f17825SAnika Henke/** 6566b13307fSandi * Print the search form 6576b13307fSandi * 65872645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 65972645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 66072645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 66172645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 66272645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 66372645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 66472645b75SAndreas Gohr * 6656b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 66642ea7f44SGerrit Uitslag * 667ac7a515fSAndreas Gohr * @param bool $ajax 668ac7a515fSAndreas Gohr * @param bool $autocomplete 669ac7a515fSAndreas Gohr * @return bool 6706b13307fSandi */ 67172645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 6726b13307fSandi global $lang; 673c1e3b7d9Smatthiasgrimm global $ACT; 674ad4aaef7SAndreas Gohr global $QUERY; 675cbcc2fa5SMichael Große global $ID; 676c1e3b7d9Smatthiasgrimm 677670ff54eSchris // don't print the search form if search action has been disabled 67864276bbcSarbrk1 if(!actionOK('search')) return false; 679670ff54eSchris 6803c7a3327SMichael Große $searchForm = new dokuwiki\Form\Form([ 6813c7a3327SMichael Große 'action' => wl(), 6823c7a3327SMichael Große 'method' => 'get', 6833c7a3327SMichael Große 'role' => 'search', 6843c7a3327SMichael Große 'class' => 'search', 6853c7a3327SMichael Große 'id' => 'dw__search', 6867fa270bcSMichael Große ], true); 6873eb2b869SMichael Große $searchForm->addTagOpen('div')->addClass('no'); 6883c7a3327SMichael Große $searchForm->setHiddenField('do', 'search'); 689d22b78c8SMichael Große $searchForm->setHiddenField('id', $ID); 690d22b78c8SMichael Große $searchForm->addTextInput('q') 6913c7a3327SMichael Große ->addClass('edit') 6923c7a3327SMichael Große ->attrs([ 6933c7a3327SMichael Große 'title' => '[F]', 6943c7a3327SMichael Große 'accesskey' => 'f', 6953c7a3327SMichael Große 'placeholder' => $lang['btn_search'], 6963c7a3327SMichael Große 'autocomplete' => $autocomplete ? 'on' : 'off', 6973c7a3327SMichael Große ]) 6983c7a3327SMichael Große ->id('qsearch__in') 6993c7a3327SMichael Große ->val($ACT === 'search' ? $QUERY : '') 7003c7a3327SMichael Große ->useInput(false) 7013c7a3327SMichael Große ; 7023c7a3327SMichael Große $searchForm->addButton('', $lang['btn_search'])->attrs([ 7033c7a3327SMichael Große 'type' => 'submit', 7043c7a3327SMichael Große 'title' => $lang['btn_search'], 7053c7a3327SMichael Große ]); 7063c7a3327SMichael Große if ($ajax) { 7073c7a3327SMichael Große $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup'); 7083c7a3327SMichael Große $searchForm->addTagClose('div'); 7093c7a3327SMichael Große } 7103eb2b869SMichael Große $searchForm->addTagClose('div'); 711cbb44eabSAndreas Gohr Event::createAndTrigger('FORM_QUICKSEARCH_OUTPUT', $searchForm); 7123c7a3327SMichael Große 7133c7a3327SMichael Große echo $searchForm->toHTML(); 7143c7a3327SMichael Große 71554e95700STom N Harris return true; 7166b13307fSandi} 7176b13307fSandi 7186b13307fSandi/** 7196b13307fSandi * Print the breadcrumbs trace 7206b13307fSandi * 7216b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 72242ea7f44SGerrit Uitslag * 723ac7a515fSAndreas Gohr * @param string $sep Separator between entries 724c4a386f1SIain Hallam * @param bool $return return or print 725c4a386f1SIain Hallam * @return bool|string 7266b13307fSandi */ 727c4a386f1SIain Hallamfunction tpl_breadcrumbs($sep = null, $return = false) { 7286b13307fSandi global $lang; 7296b13307fSandi global $conf; 7306b13307fSandi 7316b13307fSandi //check if enabled 732359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 7336b13307fSandi 734c4a386f1SIain Hallam //set default 735c4a386f1SIain Hallam if(is_null($sep)) $sep = '•'; 736c4a386f1SIain Hallam 737c4a386f1SIain Hallam $out=''; 738c4a386f1SIain Hallam 7396b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 740265e3787Sandi 7412979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 742265e3787Sandi 74340eb54bbSjan //render crumbs, highlight the last one 744c4a386f1SIain Hallam $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 74540eb54bbSjan $last = count($crumbs); 74640eb54bbSjan $i = 0; 747a77f5846Sjan foreach($crumbs as $id => $name) { 74840eb54bbSjan $i++; 749c4a386f1SIain Hallam $out .= $crumbs_sep; 750c4a386f1SIain Hallam if($i == $last) $out .= '<span class="curid">'; 751c4a386f1SIain Hallam $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) . '</bdi>'; 752c4a386f1SIain Hallam if($i == $last) $out .= '</span>'; 7536b13307fSandi } 754c4a386f1SIain Hallam if($return) return $out; 755c4a386f1SIain Hallam print $out; 756c4a386f1SIain Hallam return $out ? true : false; 7576b13307fSandi} 7586b13307fSandi 7596b13307fSandi/** 7601734437eSandi * Hierarchical breadcrumbs 7611734437eSandi * 76231e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 7631734437eSandi * It only makes sense with a deep site structure. 7641734437eSandi * 7651734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 7666bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 76731e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 768f46c9e83SAnika Henke * @author <fredrik@averpil.com> 76908d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 77042ea7f44SGerrit Uitslag * 771ac7a515fSAndreas Gohr * @param string $sep Separator between entries 772c4a386f1SIain Hallam * @param bool $return return or print 773c4a386f1SIain Hallam * @return bool|string 7741734437eSandi */ 775c4a386f1SIain Hallamfunction tpl_youarehere($sep = null, $return = false) { 7761734437eSandi global $conf; 7771734437eSandi global $ID; 7781734437eSandi global $lang; 7791734437eSandi 78031e187f8SSean Coates // check if enabled 78154e95700STom N Harris if(!$conf['youarehere']) return false; 7821734437eSandi 783c4a386f1SIain Hallam //set default 784c4a386f1SIain Hallam if(is_null($sep)) $sep = ' » '; 785c4a386f1SIain Hallam 786c4a386f1SIain Hallam $out = ''; 787c4a386f1SIain Hallam 7881734437eSandi $parts = explode(':', $ID); 789796bafb3SAndreas Gohr $count = count($parts); 7901734437eSandi 791c4a386f1SIain Hallam $out .= '<span class="bchead">'.$lang['youarehere'].' </span>'; 7923940c519SMark 79308d7a575SAndreas Gohr // always print the startpage 794c4a386f1SIain Hallam $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>'; 795796bafb3SAndreas Gohr 796796bafb3SAndreas Gohr // print intermediate namespace links 797796bafb3SAndreas Gohr $part = ''; 798796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 799796bafb3SAndreas Gohr $part .= $parts[$i].':'; 800796bafb3SAndreas Gohr $page = $part; 801796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 802796bafb3SAndreas Gohr 80308d7a575SAndreas Gohr // output 804c4a386f1SIain Hallam $out .= $sep . tpl_pagelink($page, null, true); 80531e187f8SSean Coates } 8061734437eSandi 807796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 808*8c6be208SAndreas Gohr if (isset($page)) { 809*8c6be208SAndreas Gohr $page = (new PageResolver('root'))->resolveId($page); 810*8c6be208SAndreas Gohr if ($page == $part . $parts[$i]) { 811a8c33dedSMichael Große if ($return) return $out; 812a8c33dedSMichael Große print $out; 813a8c33dedSMichael Große return true; 814a8c33dedSMichael Große } 815*8c6be208SAndreas Gohr } 816796bafb3SAndreas Gohr $page = $part.$parts[$i]; 817a8c33dedSMichael Große if($page == $conf['start']) { 818a8c33dedSMichael Große if($return) return $out; 819a8c33dedSMichael Große print $out; 820a8c33dedSMichael Große return true; 821a8c33dedSMichael Große } 822c4a386f1SIain Hallam $out .= $sep; 823c4a386f1SIain Hallam $out .= tpl_pagelink($page, null, true); 824c4a386f1SIain Hallam if($return) return $out; 825c4a386f1SIain Hallam print $out; 826c4a386f1SIain Hallam return $out ? true : false; 8271734437eSandi} 8281734437eSandi 8291734437eSandi/** 8306b13307fSandi * Print info if the user is logged in 831a2488c3cSMatthias Grimm * and show full name in that case 8326b13307fSandi * 8336b13307fSandi * Could be enhanced with a profile link in future? 8346b13307fSandi * 8356b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 83642ea7f44SGerrit Uitslag * 837ac7a515fSAndreas Gohr * @return bool 8386b13307fSandi */ 8396b13307fSandifunction tpl_userinfo() { 8406b13307fSandi global $lang; 841585bf44eSChristopher Smith /** @var Input $INPUT */ 842585bf44eSChristopher Smith global $INPUT; 843585bf44eSChristopher Smith 844585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 845fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 84654e95700STom N Harris return true; 84754e95700STom N Harris } 84854e95700STom N Harris return false; 8496b13307fSandi} 8506b13307fSandi 8516b13307fSandi/** 8526b13307fSandi * Print some info about the current page 8536b13307fSandi * 8546b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 85542ea7f44SGerrit Uitslag * 856ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 857ac7a515fSAndreas Gohr * @return bool|string 8586b13307fSandi */ 8594b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 8606b13307fSandi global $conf; 8616b13307fSandi global $lang; 8626b13307fSandi global $INFO; 863c6e92a3cSDavid Lorentsen global $ID; 864c6e92a3cSDavid Lorentsen 865c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 866ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 867ac7a515fSAndreas Gohr return false; 868ac7a515fSAndreas Gohr } 8696b13307fSandi 8706b13307fSandi // prepare date and path 8716b13307fSandi $fn = $INFO['filepath']; 8726b13307fSandi if(!$conf['fullpath']) { 873613bca54SAndreas Gohr if($INFO['rev']) { 874c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'].'/', '', $fn); 8756b13307fSandi } else { 876c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'].'/', '', $fn); 8776b13307fSandi } 8786b13307fSandi } 879bee6dc82Sandi $fn = utf8_decodeFN($fn); 880f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 8816b13307fSandi 882faecdfdfSAndreas Gohr // print it 883faecdfdfSAndreas Gohr if($INFO['exists']) { 8844b0d3916SAndreas Gohr $out = ''; 885d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 886e260f93bSAnika Henke $out .= ' · '; 8874b0d3916SAndreas Gohr $out .= $lang['lastmod']; 888fde860beSGerrit Uitslag $out .= ' '; 8894b0d3916SAndreas Gohr $out .= $date; 8906b13307fSandi if($INFO['editor']) { 8914b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 892d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 8935aa52fafSBen Coburn } else { 8944b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 8956b13307fSandi } 8966b13307fSandi if($INFO['locked']) { 897e260f93bSAnika Henke $out .= ' · '; 8984b0d3916SAndreas Gohr $out .= $lang['lockedby']; 899fde860beSGerrit Uitslag $out .= ' '; 900d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 9016b13307fSandi } 9024b0d3916SAndreas Gohr if($ret) { 9034b0d3916SAndreas Gohr return $out; 9044b0d3916SAndreas Gohr } else { 9054b0d3916SAndreas Gohr echo $out; 90654e95700STom N Harris return true; 9076b13307fSandi } 9084b0d3916SAndreas Gohr } 90954e95700STom N Harris return false; 9106b13307fSandi} 9116b13307fSandi 912820fa24bSandi/** 913a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 91487c434ceSAndreas Gohr * 91587c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 916a6598f23SBen Coburn * the given ID is used. 91787c434ceSAndreas Gohr * 91887c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 91942ea7f44SGerrit Uitslag * 920ac7a515fSAndreas Gohr * @param string $id page id 921ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 922ac7a515fSAndreas Gohr * @return bool|string 92387c434ceSAndreas Gohr */ 924a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 925c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 926fffeeafeSChristopher Smith 92787c434ceSAndreas Gohr if(is_null($id)) { 92887c434ceSAndreas Gohr global $ID; 92987c434ceSAndreas Gohr $id = $ID; 93087c434ceSAndreas Gohr } 93187c434ceSAndreas Gohr 93287c434ceSAndreas Gohr $name = $id; 933fe9ec250SChris Smith if(useHeading('navigation')) { 934fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 935fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 936fffeeafeSChristopher Smith } 937fffeeafeSChristopher Smith 938fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 939fffeeafeSChristopher Smith switch ($ACT) { 940fffeeafeSChristopher Smith // admin functions 941fffeeafeSChristopher Smith case 'admin' : 942fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 943fffeeafeSChristopher Smith // try to get the plugin name 944e1d9dcc8SAndreas Gohr /** @var $plugin AdminPlugin */ 945a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 946c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 947a61966c5SChristopher Smith $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); 948fffeeafeSChristopher Smith } 949fffeeafeSChristopher Smith break; 950fffeeafeSChristopher Smith 951fffeeafeSChristopher Smith // user functions 952fffeeafeSChristopher Smith case 'login' : 953fffeeafeSChristopher Smith case 'profile' : 954fffeeafeSChristopher Smith case 'register' : 955fffeeafeSChristopher Smith case 'resendpwd' : 956fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 957fffeeafeSChristopher Smith break; 958fffeeafeSChristopher Smith 959fffeeafeSChristopher Smith // wiki functions 960fffeeafeSChristopher Smith case 'search' : 961fffeeafeSChristopher Smith case 'index' : 962fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 963fffeeafeSChristopher Smith break; 964fffeeafeSChristopher Smith 965fffeeafeSChristopher Smith // page functions 966fffeeafeSChristopher Smith case 'edit' : 9672f19acc2Sbleistivt case 'preview' : 968fffeeafeSChristopher Smith $page_title = "✎ ".$name; 969fffeeafeSChristopher Smith break; 970fffeeafeSChristopher Smith 971fffeeafeSChristopher Smith case 'revisions' : 972fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 973fffeeafeSChristopher Smith break; 974fffeeafeSChristopher Smith 975fffeeafeSChristopher Smith case 'backlink' : 976fffeeafeSChristopher Smith case 'recent' : 977fffeeafeSChristopher Smith case 'subscribe' : 978fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 979fffeeafeSChristopher Smith break; 980fffeeafeSChristopher Smith 981fffeeafeSChristopher Smith default : // SHOW and anything else not included 982fffeeafeSChristopher Smith $page_title = $name; 98387c434ceSAndreas Gohr } 984a6598f23SBen Coburn 985a6598f23SBen Coburn if($ret) { 986fffeeafeSChristopher Smith return hsc($page_title); 987a6598f23SBen Coburn } else { 988fffeeafeSChristopher Smith print hsc($page_title); 98954e95700STom N Harris return true; 99087c434ceSAndreas Gohr } 991a6598f23SBen Coburn} 992340756e4Sandi 99355efc227SAndreas Gohr/** 99455efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 99555efc227SAndreas Gohr * 99655efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 99755efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 99855efc227SAndreas Gohr * 99955efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 100055efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 100155efc227SAndreas Gohr * to the names of the latter one) 100255efc227SAndreas Gohr * 10033df72098SAndreas Gohr * Only allowed in: detail.php 100455efc227SAndreas Gohr * 100555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 100642ea7f44SGerrit Uitslag * 100721d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1008ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1009e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1010ac7a515fSAndreas Gohr * @return string 101155efc227SAndreas Gohr */ 10123df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 101355efc227SAndreas Gohr // Init Exif Reader 101455efc227SAndreas Gohr global $SRC; 10153df72098SAndreas Gohr 10163df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 10173df72098SAndreas Gohr 101855efc227SAndreas Gohr static $meta = null; 10193df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 102055efc227SAndreas Gohr if($meta === false) return $alt; 102188945224SChristopher Smith $info = cleanText($meta->getField($tags)); 102255efc227SAndreas Gohr if($info == false) return $alt; 102355efc227SAndreas Gohr return $info; 102455efc227SAndreas Gohr} 102555efc227SAndreas Gohr 102655efc227SAndreas Gohr/** 1027becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 1028becfa414SGerrit Uitslag * 1029becfa414SGerrit Uitslag * @return string html of description list 1030becfa414SGerrit Uitslag */ 1031becfa414SGerrit Uitslagfunction tpl_img_meta() { 1032becfa414SGerrit Uitslag global $lang; 1033becfa414SGerrit Uitslag 1034becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1035becfa414SGerrit Uitslag 1036becfa414SGerrit Uitslag echo '<dl>'; 1037becfa414SGerrit Uitslag foreach($tags as $tag) { 1038becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1039fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 1040becfa414SGerrit Uitslag 1041fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 1042becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1043becfa414SGerrit Uitslag echo dformat($tag['value']); 1044becfa414SGerrit Uitslag } else { 1045becfa414SGerrit Uitslag echo hsc($tag['value']); 1046becfa414SGerrit Uitslag } 1047becfa414SGerrit Uitslag echo '</dd>'; 1048becfa414SGerrit Uitslag } 1049becfa414SGerrit Uitslag echo '</dl>'; 1050becfa414SGerrit Uitslag} 1051becfa414SGerrit Uitslag 1052becfa414SGerrit Uitslag/** 1053becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1054becfa414SGerrit Uitslag * 1055becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1056becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1057becfa414SGerrit Uitslag * - string type type of value 1058becfa414SGerrit Uitslag * - string value tag value (unescaped) 1059becfa414SGerrit Uitslag */ 1060becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1061becfa414SGerrit Uitslag 1062becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1063becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 106479e79377SAndreas Gohr if(file_exists($config_file)) { 1065becfa414SGerrit Uitslag include($config_file); 1066becfa414SGerrit Uitslag } 1067becfa414SGerrit Uitslag } 1068becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1069becfa414SGerrit Uitslag 1070becfa414SGerrit Uitslag $tags = array(); 1071becfa414SGerrit Uitslag foreach($fields as $tag){ 1072becfa414SGerrit Uitslag $t = array(); 1073becfa414SGerrit Uitslag if (!empty($tag[0])) { 1074becfa414SGerrit Uitslag $t = array($tag[0]); 1075becfa414SGerrit Uitslag } 1076becfa414SGerrit Uitslag if(is_array($tag[3])) { 1077becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1078becfa414SGerrit Uitslag } 1079becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1080becfa414SGerrit Uitslag if ($value) { 1081becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1082becfa414SGerrit Uitslag } 1083becfa414SGerrit Uitslag } 1084becfa414SGerrit Uitslag return $tags; 1085becfa414SGerrit Uitslag} 1086becfa414SGerrit Uitslag 1087becfa414SGerrit Uitslag/** 108855efc227SAndreas Gohr * Prints the image with a link to the full sized version 108955efc227SAndreas Gohr * 109055efc227SAndreas Gohr * Only allowed in: detail.php 1091a02d2933SAndreas Gohr * 1092ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1093a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1094a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1095a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1096a02d2933SAndreas Gohr * @param $params array - additional image attributes 109742ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 109855efc227SAndreas Gohr */ 1099a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 110055efc227SAndreas Gohr global $IMG; 1101585bf44eSChristopher Smith /** @var Input $INPUT */ 1102ac7a515fSAndreas Gohr global $INPUT; 11035c2eed9aSlisps global $REV; 110465d3a5dbSAndreas Gohr $w = (int) tpl_img_getTag('File.Width'); 110565d3a5dbSAndreas Gohr $h = (int) tpl_img_getTag('File.Height'); 110655efc227SAndreas Gohr 110755efc227SAndreas Gohr //resize to given max values 110823a34783SAndreas Gohr $ratio = 1; 110923a34783SAndreas Gohr if($w >= $h) { 1110f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 111155efc227SAndreas Gohr $ratio = $maxwidth / $w; 1112f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 111355efc227SAndreas Gohr $ratio = $maxheight / $h; 111455efc227SAndreas Gohr } 111555efc227SAndreas Gohr } else { 1116f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 111755efc227SAndreas Gohr $ratio = $maxheight / $h; 1118f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 111955efc227SAndreas Gohr $ratio = $maxwidth / $w; 112055efc227SAndreas Gohr } 112155efc227SAndreas Gohr } 112255efc227SAndreas Gohr if($ratio) { 112355efc227SAndreas Gohr $w = floor($ratio * $w); 112455efc227SAndreas Gohr $h = floor($ratio * $h); 112555efc227SAndreas Gohr } 112655efc227SAndreas Gohr 11276de3759aSAndreas Gohr //prepare URLs 11285c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 11295c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 113055efc227SAndreas Gohr 11312684e50aSAndreas Gohr //prepare attributes 113255efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1133a02d2933SAndreas Gohr if(is_null($params)) { 11342684e50aSAndreas Gohr $p = array(); 1135a02d2933SAndreas Gohr } else { 1136a02d2933SAndreas Gohr $p = $params; 1137a02d2933SAndreas Gohr } 11382684e50aSAndreas Gohr if($w) $p['width'] = $w; 11392684e50aSAndreas Gohr if($h) $p['height'] = $h; 11402684e50aSAndreas Gohr $p['class'] = 'img_detail'; 11412684e50aSAndreas Gohr if($alt) { 11422684e50aSAndreas Gohr $p['alt'] = $alt; 11432684e50aSAndreas Gohr $p['title'] = $alt; 11442684e50aSAndreas Gohr } else { 11452684e50aSAndreas Gohr $p['alt'] = ''; 11462684e50aSAndreas Gohr } 1147a02d2933SAndreas Gohr $p['src'] = $src; 114855efc227SAndreas Gohr 1149a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1150cbb44eabSAndreas Gohr return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1151a02d2933SAndreas Gohr} 1152a02d2933SAndreas Gohr 1153a02d2933SAndreas Gohr/** 1154a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1155ac7a515fSAndreas Gohr * 1156ac7a515fSAndreas Gohr * @param array $data 1157ac7a515fSAndreas Gohr * @return bool 1158a02d2933SAndreas Gohr */ 1159ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 116059f3611bSAnika Henke global $lang; 1161a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1162a02d2933SAndreas Gohr 116359f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1164a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1165a02d2933SAndreas Gohr if($data['url']) print '</a>'; 116654e95700STom N Harris return true; 116755efc227SAndreas Gohr} 116855efc227SAndreas Gohr 11697367b368SAndreas Gohr/** 1170881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 11717367b368SAndreas Gohr * 11727367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 11737367b368SAndreas Gohr * template 1174ac7a515fSAndreas Gohr * 1175ac7a515fSAndreas Gohr * @return bool 11767367b368SAndreas Gohr */ 11777367b368SAndreas Gohrfunction tpl_indexerWebBug() { 11787367b368SAndreas Gohr global $ID; 11791dad36f5SAndreas Gohr 11807367b368SAndreas Gohr $p = array(); 11814af80fe8SMichael Große $p['src'] = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID). 1182e68c51baSAndreas Gohr '&'.time(); 1183881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 11847367b368SAndreas Gohr $p['height'] = 1; 11857367b368SAndreas Gohr $p['alt'] = ''; 11867367b368SAndreas Gohr $att = buildAttributes($p); 11877367b368SAndreas Gohr print "<img $att />"; 118854e95700STom N Harris return true; 11897367b368SAndreas Gohr} 11907367b368SAndreas Gohr 119178d4e784SEsther Brunner/** 119278d4e784SEsther Brunner * tpl_getConf($id) 119378d4e784SEsther Brunner * 119478d4e784SEsther Brunner * use this function to access template configuration variables 1195ac7a515fSAndreas Gohr * 119617448fb8SChristopher Smith * @param string $id name of the value to access 119717448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 119817448fb8SChristopher Smith * @return mixed 119978d4e784SEsther Brunner */ 120017448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 120178d4e784SEsther Brunner global $conf; 120217566ac6SAdrian Lang static $tpl_configloaded = false; 120378d4e784SEsther Brunner 120478d4e784SEsther Brunner $tpl = $conf['template']; 120578d4e784SEsther Brunner 120678d4e784SEsther Brunner if(!$tpl_configloaded) { 120778d4e784SEsther Brunner $tconf = tpl_loadConfig(); 120878d4e784SEsther Brunner if($tconf !== false) { 120978d4e784SEsther Brunner foreach($tconf as $key => $value) { 121078d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 121178d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 121278d4e784SEsther Brunner } 121378d4e784SEsther Brunner $tpl_configloaded = true; 121478d4e784SEsther Brunner } 121578d4e784SEsther Brunner } 121678d4e784SEsther Brunner 121717448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 121878d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 121978d4e784SEsther Brunner } 122078d4e784SEsther Brunner 122117448fb8SChristopher Smith return $notset; 122217448fb8SChristopher Smith} 122317448fb8SChristopher Smith 122478d4e784SEsther Brunner/** 122578d4e784SEsther Brunner * tpl_loadConfig() 1226ac7a515fSAndreas Gohr * 122778d4e784SEsther Brunner * reads all template configuration variables 122878d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1229ac7a515fSAndreas Gohr * 1230ac7a515fSAndreas Gohr * @return array 123178d4e784SEsther Brunner */ 123278d4e784SEsther Brunnerfunction tpl_loadConfig() { 123378d4e784SEsther Brunner 1234c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 123578d4e784SEsther Brunner $conf = array(); 123678d4e784SEsther Brunner 123779e79377SAndreas Gohr if(!file_exists($file)) return false; 123878d4e784SEsther Brunner 123978d4e784SEsther Brunner // load default config file 124078d4e784SEsther Brunner include($file); 124178d4e784SEsther Brunner 124278d4e784SEsther Brunner return $conf; 124378d4e784SEsther Brunner} 124478d4e784SEsther Brunner 124517566ac6SAdrian Lang// language methods 124617566ac6SAdrian Lang/** 124717566ac6SAdrian Lang * tpl_getLang($id) 124817566ac6SAdrian Lang * 124917566ac6SAdrian Lang * use this function to access template language variables 125042ea7f44SGerrit Uitslag * 125142ea7f44SGerrit Uitslag * @param string $id key of language string 125242ea7f44SGerrit Uitslag * @return string 125317566ac6SAdrian Lang */ 125417566ac6SAdrian Langfunction tpl_getLang($id) { 125517566ac6SAdrian Lang static $lang = array(); 125617566ac6SAdrian Lang 125717566ac6SAdrian Lang if(count($lang) === 0) { 1258dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1259dd7a6159SGerrit Uitslag 1260c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 126117566ac6SAdrian Lang 126217566ac6SAdrian Lang $lang = array(); 126317566ac6SAdrian Lang 126417566ac6SAdrian Lang // don't include once 126517566ac6SAdrian Lang @include($path . 'en/lang.php'); 1266dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 126779e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1268dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1269dd7a6159SGerrit Uitslag } 127017566ac6SAdrian Lang } 127117566ac6SAdrian Lang 1272dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1273dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1274dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 127579e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1276dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1277dd7a6159SGerrit Uitslag } 1278dd7a6159SGerrit Uitslag } 1279dd7a6159SGerrit Uitslag } 128017566ac6SAdrian Lang } 128117566ac6SAdrian Lang return $lang[$id]; 128217566ac6SAdrian Lang} 128317566ac6SAdrian Lang 12843df72098SAndreas Gohr/** 1285c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1286e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1287e8ec13b9SKlap-in * 1288e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1289e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1290e8ec13b9SKlap-in */ 1291e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1292c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1293e8ec13b9SKlap-in} 1294e8ec13b9SKlap-in 1295e8ec13b9SKlap-in/** 1296c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 129742ea7f44SGerrit Uitslag * 129842ea7f44SGerrit Uitslag * @param string $id id of localized text 129942ea7f44SGerrit Uitslag * @return string wiki text 1300e8ec13b9SKlap-in */ 1301c5c17fdaSKlap-infunction tpl_localeFN($id) { 1302e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1303e8ec13b9SKlap-in global $conf; 130438fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 130579e79377SAndreas Gohr if (!file_exists($file)){ 1306e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 130779e79377SAndreas Gohr if(!file_exists($file)){ 1308e8ec13b9SKlap-in //fall back to english 1309e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1310e8ec13b9SKlap-in } 1311e8ec13b9SKlap-in } 1312e8ec13b9SKlap-in return $file; 1313e8ec13b9SKlap-in} 1314e8ec13b9SKlap-in 1315e8ec13b9SKlap-in/** 13167abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 13173df72098SAndreas Gohr * 13183df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13193df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13203df72098SAndreas Gohr * a message of referencing pages 13213df72098SAndreas Gohr * 13223df72098SAndreas Gohr * Only allowed in mediamanager.php 13233df72098SAndreas Gohr * 1324c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1325c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 132642ea7f44SGerrit Uitslag * @param string $sort 13278702de7fSGerrit Uitslag * 13283df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13293df72098SAndreas Gohr */ 133000e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 13313df72098SAndreas Gohr global $IMG; 13323df72098SAndreas Gohr global $AUTH; 13333df72098SAndreas Gohr global $INUSE; 13343df72098SAndreas Gohr global $NS; 13353df72098SAndreas Gohr global $JUMPTO; 1336585bf44eSChristopher Smith /** @var Input $INPUT */ 1337ac7a515fSAndreas Gohr global $INPUT; 13383df72098SAndreas Gohr 1339ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1340c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1341c182313eSAndreas Gohr 1342c182313eSAndreas Gohr if(!$do) { 1343ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1344c182313eSAndreas Gohr $do = 'metaform'; 1345c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1346c182313eSAndreas Gohr $do = 'filesinuse'; 1347c182313eSAndreas Gohr } else { 1348c182313eSAndreas Gohr $do = 'filelist'; 1349c182313eSAndreas Gohr } 1350c182313eSAndreas Gohr } 1351c182313eSAndreas Gohr 1352c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1353c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1354c182313eSAndreas Gohr $data = array('do' => $do); 1355e1d9dcc8SAndreas Gohr $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1356c182313eSAndreas Gohr if($evt->advise_before()) { 1357c182313eSAndreas Gohr $do = $data['do']; 135830fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1359c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1360c182313eSAndreas Gohr } elseif($do == 'filelist') { 136100e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1362c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1363ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1364c182313eSAndreas Gohr } else { 1365c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1366c182313eSAndreas Gohr } 1367c182313eSAndreas Gohr } 1368c182313eSAndreas Gohr $evt->advise_after(); 1369c182313eSAndreas Gohr unset($evt); 1370c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1371c182313eSAndreas Gohr 13723df72098SAndreas Gohr} 13733df72098SAndreas Gohr 13743df72098SAndreas Gohr/** 1375d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1376d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1377d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1378d9162c6cSKate Arzamastseva * 1379d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1380d9162c6cSKate Arzamastseva */ 1381035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1382d9162c6cSKate Arzamastseva global $AUTH; 1383d9162c6cSKate Arzamastseva global $NS; 1384d9162c6cSKate Arzamastseva global $JUMPTO; 138595b451bcSAdrian Lang global $lang; 1386585bf44eSChristopher Smith /** @var Input $INPUT */ 1387ac7a515fSAndreas Gohr global $INPUT; 1388d9162c6cSKate Arzamastseva 1389ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1390e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1391ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1392d9162c6cSKate Arzamastseva 139394add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 139495b451bcSAdrian Lang 1395ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 139623846a98SKate Arzamastseva 139794add303SAnika Henke echo '<div class="panelHeader">'.NL; 139895b451bcSAdrian Lang echo '<h3>'; 1399026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1400c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 140194add303SAnika Henke echo '</h3>'.NL; 140295b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 140395b451bcSAdrian Lang media_tab_files_options(); 140423846a98SKate Arzamastseva } 140594add303SAnika Henke echo '</div>'.NL; 1406d9162c6cSKate Arzamastseva 140794add303SAnika Henke echo '<div class="panelContent">'.NL; 140895b451bcSAdrian Lang if($opened_tab == 'files') { 140995b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 141095b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 141195b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 141295b451bcSAdrian Lang } elseif($opened_tab == 'search') { 141395b451bcSAdrian Lang media_tab_search($NS, $AUTH); 141495b451bcSAdrian Lang } 141594add303SAnika Henke echo '</div>'.NL; 1416d9162c6cSKate Arzamastseva} 1417d9162c6cSKate Arzamastseva 1418d9162c6cSKate Arzamastseva/** 1419d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1420d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1421d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1422d9162c6cSKate Arzamastseva * list of file revisions 1423d9162c6cSKate Arzamastseva * 1424d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1425f50a239bSTakamura * 1426f50a239bSTakamura * @param string $image 1427f50a239bSTakamura * @param boolean $rev 1428d9162c6cSKate Arzamastseva */ 1429035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1430e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1431585bf44eSChristopher Smith /** @var Input $INPUT */ 1432585bf44eSChristopher Smith global $INPUT; 1433d9162c6cSKate Arzamastseva 143464159a61SAndreas Gohr $removed = ( 143564159a61SAndreas Gohr !file_exists(mediaFN($image)) && 143664159a61SAndreas Gohr file_exists(mediaMetaFN($image, '.changes')) && 143764159a61SAndreas Gohr $conf['mediarevisions'] 143864159a61SAndreas Gohr ); 1439ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 14406dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1441e8a2a143SMichael Hamann $ns = getNS($image); 1442ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 14431eeeced2SKate Arzamastseva 1444ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1445e5d185e1SKate Arzamastseva 1446e5d185e1SKate Arzamastseva $tab_array = array('view'); 1447ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1448e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1449e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1450e5d185e1SKate Arzamastseva } 1451e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1452e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1453e5d185e1SKate Arzamastseva } 1454e5d185e1SKate Arzamastseva 1455e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1456ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 145723846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1458d9162c6cSKate Arzamastseva 1459ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 146023846a98SKate Arzamastseva 146159f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1462ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 146395b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 146495b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 1465750a0b51SMichael Große $attributes = $rev ? ['rev' => $rev] : []; 146664159a61SAndreas Gohr $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'. 146764159a61SAndreas Gohr $image.'</a>'.'</strong>'; 146808317413SAdrian Lang if($opened_tab === 'view' && $rev) { 146908317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 147008317413SAdrian Lang } else { 1471026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 147208317413SAdrian Lang } 1473b8a84c03SAndreas Gohr 147494add303SAnika Henke echo '</h3></div>'.NL; 147595b451bcSAdrian Lang 147694add303SAnika Henke echo '<div class="panelContent">'.NL; 147795b451bcSAdrian Lang 147823846a98SKate Arzamastseva if($opened_tab == 'view') { 1479e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 148023846a98SKate Arzamastseva 148192cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1482e8a2a143SMichael Hamann media_tab_edit($image, $ns); 148323846a98SKate Arzamastseva 1484e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1485e8a2a143SMichael Hamann media_tab_history($image, $ns); 148623846a98SKate Arzamastseva } 148795b451bcSAdrian Lang 148894add303SAnika Henke echo '</div>'.NL; 1489d9162c6cSKate Arzamastseva} 1490d9162c6cSKate Arzamastseva 1491d9162c6cSKate Arzamastseva/** 14927abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 14933df72098SAndreas Gohr * 14943df72098SAndreas Gohr * Only allowed in mediamanager.php 14953df72098SAndreas Gohr * 14963df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14973df72098SAndreas Gohr */ 1498fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 14993df72098SAndreas Gohr global $NS; 150023846a98SKate Arzamastseva ptln('<div id="media__tree">'); 15013df72098SAndreas Gohr media_nstree($NS); 15023df72098SAndreas Gohr ptln('</div>'); 15033df72098SAndreas Gohr} 15043df72098SAndreas Gohr 1505a00de5b5SAndreas Gohr/** 1506a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1507a00de5b5SAndreas Gohr * 1508a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1509a00de5b5SAndreas Gohr * 1510a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 151142ea7f44SGerrit Uitslag * 151242ea7f44SGerrit Uitslag * @param string $empty empty option label 151342ea7f44SGerrit Uitslag * @param string $button submit button label 1514affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 1515a00de5b5SAndreas Gohr */ 1516a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1517affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 15181e875dcdSAndreas Gohr $menu = new \dokuwiki\Menu\MobileMenu(); 15191e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1520a00de5b5SAndreas Gohr} 1521a00de5b5SAndreas Gohr 1522066fee30SAndreas Gohr/** 1523066fee30SAndreas Gohr * Print a informational line about the used license 1524066fee30SAndreas Gohr * 1525066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1526ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1527ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1528ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1529ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1530ac7a515fSAndreas Gohr * @return string 1531066fee30SAndreas Gohr */ 153280083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1533066fee30SAndreas Gohr global $license; 1534066fee30SAndreas Gohr global $conf; 1535066fee30SAndreas Gohr global $lang; 1536066fee30SAndreas Gohr if(!$conf['license']) return ''; 1537066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1538066fee30SAndreas Gohr $lic = $license[$conf['license']]; 153953e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1540066fee30SAndreas Gohr 154180083a41SAndreas Gohr $out = ''; 154280083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1543066fee30SAndreas Gohr if($img) { 1544066fee30SAndreas Gohr $src = license_img($img); 1545066fee30SAndreas Gohr if($src) { 154653e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 154753e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 154853e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1549066fee30SAndreas Gohr } 1550066fee30SAndreas Gohr } 15514cefd216SMichael Klier if(!$imgonly) { 155253e15c8bSAnika Henke $out .= $lang['license'].' '; 1553d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1554d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 15554cefd216SMichael Klier } 155680083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1557066fee30SAndreas Gohr 1558066fee30SAndreas Gohr if($return) return $out; 1559066fee30SAndreas Gohr echo $out; 1560ac7a515fSAndreas Gohr return ''; 1561066fee30SAndreas Gohr} 1562066fee30SAndreas Gohr 1563a81910eeSAndreas Gohr/** 1564835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1565a81910eeSAndreas Gohr * 1566a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1567a81910eeSAndreas Gohr * template 1568e0c26282SGerrit Uitslag * 15697a112df5SAndreas Gohr * @param string $pageid The page name you want to include 15707a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 15717a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 15727c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1573e0c26282SGerrit Uitslag * @return bool|null|string 1574a81910eeSAndreas Gohr */ 15757c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { 15767a112df5SAndreas Gohr if($propagate) { 15777c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 15787c3e4a67SAndreas Gohr } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 15797a112df5SAndreas Gohr return false; 15807a112df5SAndreas Gohr } 1581c786a1b6SAnika Henke if(!$pageid) return false; 1582835dfcaeSAnika Henke 1583c786a1b6SAnika Henke global $TOC; 15849a2e250aSAndreas Gohr $oldtoc = $TOC; 1585a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 15869a2e250aSAndreas Gohr $TOC = $oldtoc; 1587a81910eeSAndreas Gohr 1588a2e03c82SAndreas Gohr if($print) echo $html; 1589e66d3e6dSAndreas Gohr return $html; 1590e66d3e6dSAndreas Gohr} 1591e66d3e6dSAndreas Gohr 1592e66d3e6dSAndreas Gohr/** 15935b75cd1fSAdrian Lang * Display the subscribe form 15945b75cd1fSAdrian Lang * 15955b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 15965b75cd1fSAdrian Lang */ 15975b75cd1fSAdrian Langfunction tpl_subscribe() { 15985b75cd1fSAdrian Lang global $INFO; 15995b75cd1fSAdrian Lang global $ID; 16005b75cd1fSAdrian Lang global $lang; 16016b8f02cfSAdrian Lang global $conf; 160240c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 16035b75cd1fSAdrian Lang 16045b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 16055b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 160615741132SAndreas Gohr echo '<div class="level2">'; 16075b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 16085b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 16095b75cd1fSAdrian Lang } else { 16105b75cd1fSAdrian Lang echo '<ul>'; 16115b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1612056c2049SAndreas Gohr echo '<li><div class="li">'; 16135b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1614056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 16155b75cd1fSAdrian Lang } else { 1616056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 16175b75cd1fSAdrian Lang } 161840c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 161915741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1620056c2049SAndreas Gohr echo ' ('.$sstl.') '; 162115741132SAndreas Gohr 1622ac7a515fSAndreas Gohr echo '<a href="'.wl( 1623ac7a515fSAndreas Gohr $ID, 1624ac7a515fSAndreas Gohr array( 1625ac7a515fSAndreas Gohr 'do' => 'subscribe', 162666d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 162766d2bed9SAdrian Lang 'sub_style' => $sub['style'], 162866d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1629ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1630ac7a515fSAndreas Gohr ) 1631ac7a515fSAndreas Gohr ). 163266d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 163366d2bed9SAdrian Lang '</a></div></li>'; 16345b75cd1fSAdrian Lang } 16355b75cd1fSAdrian Lang echo '</ul>'; 16365b75cd1fSAdrian Lang } 163715741132SAndreas Gohr echo '</div>'; 16385b75cd1fSAdrian Lang 163915741132SAndreas Gohr // Add new subscription form 16405b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 164115741132SAndreas Gohr echo '<div class="level2">'; 16425b75cd1fSAdrian Lang $ns = getNS($ID).':'; 164315741132SAndreas Gohr $targets = array( 164415741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 164515741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 164615741132SAndreas Gohr ); 164715741132SAndreas Gohr $styles = array( 164815741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 16496b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 16506b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 165115741132SAndreas Gohr ); 165215741132SAndreas Gohr 1653056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1654056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1655056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1656056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1657056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1658056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1659056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1660056c2049SAndreas Gohr $form->addHidden('id', $ID); 1661056c2049SAndreas Gohr $form->endFieldset(); 16625b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 16635b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 166415741132SAndreas Gohr echo '</div>'; 16655b75cd1fSAdrian Lang} 16665b75cd1fSAdrian Lang 1667d059ba9bSAndreas Gohr/** 1668d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1669d059ba9bSAndreas Gohr * 1670d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1671d059ba9bSAndreas Gohr * 1672d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1673d059ba9bSAndreas Gohr */ 1674d059ba9bSAndreas Gohrfunction tpl_flush() { 1675c2009796SZemoj if( ob_get_level() > 0 ) ob_flush(); 1676d059ba9bSAndreas Gohr flush(); 1677d059ba9bSAndreas Gohr} 1678d059ba9bSAndreas Gohr 1679afca7e7eSAnika Henke/** 1680378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1681afca7e7eSAnika Henke * 1682378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1683378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1684378325f9SAndreas Gohr * 168542ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1686378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1687ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 16886dc405e1SAndreas Gohr * @param bool $fallback use fallback image if target isn't found or return 'false' if potential 16896dc405e1SAndreas Gohr * false result is required 1690ac7a515fSAndreas Gohr * @return string 169142ea7f44SGerrit Uitslag * 1692378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1693afca7e7eSAnika Henke */ 1694c238d757SSimon DELAGEfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) { 1695ac7a515fSAndreas Gohr $img = ''; 1696ac7a515fSAndreas Gohr $file = ''; 1697ac7a515fSAndreas Gohr $ismedia = false; 1698378325f9SAndreas Gohr // loop through candidates until a match was found: 1699378325f9SAndreas Gohr foreach($search as $img) { 1700378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1701378325f9SAndreas Gohr $file = mediaFN($img); 1702378325f9SAndreas Gohr $ismedia = true; 1703378325f9SAndreas Gohr } else { 1704c4766956SAndreas Gohr $file = tpl_incdir().$img; 1705378325f9SAndreas Gohr $ismedia = false; 17061f13e33dSAnika Henke } 17070f747863Slupo49 1708378325f9SAndreas Gohr if(file_exists($file)) break; 1709872a6d29SAnika Henke } 1710378325f9SAndreas Gohr 171108a13262SSimon DELAGE // manage non existing target 171208a13262SSimon DELAGE if (!file_exists($file)) { 171308a13262SSimon DELAGE // give result for fallback image 1714c238d757SSimon DELAGE if ($fallback === true) { 1715c238d757SSimon DELAGE $file = DOKU_INC . 'lib/images/blank.gif'; 171608a13262SSimon DELAGE // stop process if false result is required (if $fallback is false) 171708a13262SSimon DELAGE } else { 171808a13262SSimon DELAGE return false; 171908a13262SSimon DELAGE } 172008a13262SSimon DELAGE } 1721ca5b6a64SSimon DELAGE 1722378325f9SAndreas Gohr // fetch image data if requested 1723378325f9SAndreas Gohr if(!is_null($imginfo)) { 1724378325f9SAndreas Gohr $imginfo = getimagesize($file); 1725378325f9SAndreas Gohr } 1726378325f9SAndreas Gohr 1727378325f9SAndreas Gohr // build URL 1728378325f9SAndreas Gohr if($ismedia) { 1729378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1730378325f9SAndreas Gohr } else { 1731c4766956SAndreas Gohr $url = tpl_basedir().$img; 1732378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1733378325f9SAndreas Gohr } 1734378325f9SAndreas Gohr 1735378325f9SAndreas Gohr return $url; 1736a7e5f74cSlupo49} 17371f13e33dSAnika Henke 1738872a6d29SAnika Henke/** 1739e5d4768dSAndreas Gohr * PHP include a file 1740e5d4768dSAndreas Gohr * 1741e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1742e5d4768dSAndreas Gohr * file in the template's root directory. 1743e5d4768dSAndreas Gohr * 1744e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1745e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1746e5d4768dSAndreas Gohr * default. 1747e5d4768dSAndreas Gohr * 1748e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1749e5d4768dSAndreas Gohr * to this function! 1750e5d4768dSAndreas Gohr * 1751e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1752e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 175342ea7f44SGerrit Uitslag * 175442ea7f44SGerrit Uitslag * @param string $file 1755e5d4768dSAndreas Gohr */ 1756e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1757e5d4768dSAndreas Gohr global $config_cascade; 1758e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1759e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1760e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1761e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1762e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1763f3a1225fSAnika Henke include("$dir/$file"); 1764e5d4768dSAndreas Gohr return; 1765e5d4768dSAndreas Gohr } 1766e5d4768dSAndreas Gohr } 1767e5d4768dSAndreas Gohr } 1768e5d4768dSAndreas Gohr 1769e5d4768dSAndreas Gohr // still here? try the template dir 1770e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1771e5d4768dSAndreas Gohr if(file_exists($file)) { 1772f3a1225fSAnika Henke include($file); 1773e5d4768dSAndreas Gohr } 1774e5d4768dSAndreas Gohr} 1775e5d4768dSAndreas Gohr 1776e5d4768dSAndreas Gohr/** 1777872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1778872a6d29SAnika Henke * 1779872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 178042ea7f44SGerrit Uitslag * 1781ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1782ac7a515fSAndreas Gohr * @return string 1783872a6d29SAnika Henke */ 1784872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1785872a6d29SAnika Henke 1786872a6d29SAnika Henke $return = ''; 1787872a6d29SAnika Henke 1788872a6d29SAnika Henke foreach($types as $type) { 1789872a6d29SAnika Henke switch($type) { 1790872a6d29SAnika Henke case 'favicon': 1791378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1792378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1793872a6d29SAnika Henke break; 1794872a6d29SAnika Henke case 'mobile': 1795cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1796378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1797872a6d29SAnika Henke break; 1798872a6d29SAnika Henke case 'generic': 1799872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1800378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1801378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1802872a6d29SAnika Henke break; 1803872a6d29SAnika Henke } 1804872a6d29SAnika Henke } 1805872a6d29SAnika Henke 1806872a6d29SAnika Henke return $return; 1807afca7e7eSAnika Henke} 1808afca7e7eSAnika Henke 1809d9162c6cSKate Arzamastseva/** 1810d9162c6cSKate Arzamastseva * Prints full-screen media manager 1811d9162c6cSKate Arzamastseva * 1812d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1813d9162c6cSKate Arzamastseva */ 1814d9162c6cSKate Arzamastsevafunction tpl_media() { 1815ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 181688a71175SKate Arzamastseva $fullscreen = true; 181795b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1818d9162c6cSKate Arzamastseva 1819ac7a515fSAndreas Gohr $rev = ''; 1820ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 182198f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 182298f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 18239c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 182498f03b57SKate Arzamastseva 182594add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1826bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1827d9162c6cSKate Arzamastseva html_msgarea(); 182894add303SAnika Henke 182994add303SAnika Henke echo '<div class="panel namespaces">'.NL; 183094add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 183195b451bcSAdrian Lang echo '<div class="panelHeader">'; 1832ba340a70SAnika Henke echo $lang['media_namespaces']; 183394add303SAnika Henke echo '</div>'.NL; 183495b451bcSAdrian Lang 183594add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 183695b451bcSAdrian Lang media_nstree($NS); 183794add303SAnika Henke echo '</div>'.NL; 183894add303SAnika Henke echo '</div>'.NL; 1839fa8e5c77SKate Arzamastseva 184094add303SAnika Henke echo '<div class="panel filelist">'.NL; 1841035e07f1SKate Arzamastseva tpl_mediaFileList(); 184294add303SAnika Henke echo '</div>'.NL; 1843fa8e5c77SKate Arzamastseva 184494add303SAnika Henke echo '<div class="panel file">'.NL; 184594add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1846035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 184794add303SAnika Henke echo '</div>'.NL; 1848ba340a70SAnika Henke 184994add303SAnika Henke echo '</div>'.NL; 1850d9162c6cSKate Arzamastseva} 1851afca7e7eSAnika Henke 1852c71db656SAnika Henke/** 1853c71db656SAnika Henke * Return useful layout classes 1854c71db656SAnika Henke * 1855c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 185642ea7f44SGerrit Uitslag * 185742ea7f44SGerrit Uitslag * @return string 1858c71db656SAnika Henke */ 1859c71db656SAnika Henkefunction tpl_classes() { 1860c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1861585bf44eSChristopher Smith /** @var Input $INPUT */ 1862585bf44eSChristopher Smith global $INPUT; 1863585bf44eSChristopher Smith 1864c71db656SAnika Henke $classes = array( 1865c71db656SAnika Henke 'dokuwiki', 1866c71db656SAnika Henke 'mode_'.$ACT, 1867c71db656SAnika Henke 'tpl_'.$conf['template'], 1868585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 186968491db9SPhy (isset($INFO) && $INFO['exists']) ? '' : 'notFound', 1870c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1871c71db656SAnika Henke ); 1872c71db656SAnika Henke return join(' ', $classes); 1873c71db656SAnika Henke} 1874c71db656SAnika Henke 187584dd2b1aSGerrit Uitslag/** 187684dd2b1aSGerrit Uitslag * Create event for tools menues 187784dd2b1aSGerrit Uitslag * 187884dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 187984dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 188084dd2b1aSGerrit Uitslag * @param array $items 188184dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 1882affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 188384dd2b1aSGerrit Uitslag */ 188484dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') { 1885affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 188684dd2b1aSGerrit Uitslag $data = array( 188784dd2b1aSGerrit Uitslag 'view' => $view, 188884dd2b1aSGerrit Uitslag 'items' => $items 188984dd2b1aSGerrit Uitslag ); 189084dd2b1aSGerrit Uitslag 189184dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 1892e1d9dcc8SAndreas Gohr $evt = new Event($hook, $data); 189384dd2b1aSGerrit Uitslag if($evt->advise_before()) { 189484dd2b1aSGerrit Uitslag foreach($evt->data['items'] as $k => $html) echo $html; 189584dd2b1aSGerrit Uitslag } 189684dd2b1aSGerrit Uitslag $evt->advise_after(); 189784dd2b1aSGerrit Uitslag} 189884dd2b1aSGerrit Uitslag 1899e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1900a00de5b5SAndreas Gohr 1901