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 9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 106b13307fSandi 116b13307fSandi/** 12ac7a515fSAndreas Gohr * Access a template file 13ac7a515fSAndreas Gohr * 14ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses 15ac7a515fSAndreas Gohr * default template if the custom version doesn't exist. 165a892029SAndreas Gohr * 175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 18ac7a515fSAndreas Gohr * @param string $file 19ac7a515fSAndreas Gohr * @return string 205a892029SAndreas Gohr */ 21ac7a515fSAndreas Gohrfunction template($file) { 225a892029SAndreas Gohr global $conf; 235a892029SAndreas Gohr 24ac7a515fSAndreas Gohr if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) 25ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; 265a892029SAndreas Gohr 27ac7a515fSAndreas Gohr return DOKU_INC.'lib/tpl/dokuwiki/'.$file; 285a892029SAndreas Gohr} 295a892029SAndreas Gohr 30c4766956SAndreas Gohr/** 31c4766956SAndreas Gohr * Convenience function to access template dir from local FS 32c4766956SAndreas Gohr * 33c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant 34c4766956SAndreas Gohr * 35c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 36afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 37ac7a515fSAndreas Gohr * @return string 38c4766956SAndreas Gohr */ 39afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') { 4075b14482SAndreas Gohr global $conf; 41afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 42afb2c082SAndreas Gohr return DOKU_INC.'lib/tpl/'.$tpl.'/'; 43c4766956SAndreas Gohr} 44c4766956SAndreas Gohr 45c4766956SAndreas Gohr/** 46c4766956SAndreas Gohr * Convenience function to access template dir from web 47c4766956SAndreas Gohr * 48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 49c4766956SAndreas Gohr * 50c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 51afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 52ac7a515fSAndreas Gohr * @return string 53c4766956SAndreas Gohr */ 5499dca513SAndreas Gohrfunction tpl_basedir($tpl='') { 5575b14482SAndreas Gohr global $conf; 56afb2c082SAndreas Gohr if(!$tpl) $tpl = $conf['template']; 57dcd4911eSMichael Hamann return DOKU_BASE.'lib/tpl/'.$tpl.'/'; 58c4766956SAndreas Gohr} 59c4766956SAndreas Gohr 605a892029SAndreas Gohr/** 616b13307fSandi * Print the content 626b13307fSandi * 636b13307fSandi * This function is used for printing all the usual content 646b13307fSandi * (defined by the global $ACT var) by calling the appropriate 656b13307fSandi * outputfunction(s) from html.php 666b13307fSandi * 67ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 68ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 696b13307fSandi * 706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 7142ea7f44SGerrit Uitslag * 72ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 73ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 74ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here? 75ac7a515fSAndreas Gohr * @return bool true if any output 766b13307fSandi */ 77b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) { 787ea0913cSchris global $ACT; 79b8595a66SAndreas Gohr global $INFO; 80b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 817ea0913cSchris 827ea0913cSchris ob_start(); 83746855cfSBen Coburn trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 847ea0913cSchris $html_output = ob_get_clean(); 85746855cfSBen Coburn trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); 8654e95700STom N Harris 8754e95700STom N Harris return !empty($html_output); 887ea0913cSchris} 897ea0913cSchris 90ac7a515fSAndreas Gohr/** 91ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 92ac7a515fSAndreas Gohr * 93ac7a515fSAndreas Gohr * @return bool 94ac7a515fSAndreas Gohr */ 957ea0913cSchrisfunction tpl_content_core() { 96952acff9SAndreas Gohr $router = \dokuwiki\ActionRouter::getInstance(); 97952acff9SAndreas Gohr try { 98952acff9SAndreas Gohr $router->getAction()->tplContent(); 99952acff9SAndreas Gohr } catch(\dokuwiki\Action\Exception\FatalException $e) { 100952acff9SAndreas Gohr // there was no content for the action 101952acff9SAndreas Gohr msg(hsc($e->getMessage()), -1); 10254e95700STom N Harris return false; 1036b13307fSandi } 10454e95700STom N Harris return true; 1056b13307fSandi} 1066b13307fSandi 107c19fe9c0Sandi/** 108b8595a66SAndreas Gohr * Places the TOC where the function is called 109b8595a66SAndreas Gohr * 110b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 111b8595a66SAndreas Gohr * a false argument 112b8595a66SAndreas Gohr * 113b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11442ea7f44SGerrit Uitslag * 115ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 116ac7a515fSAndreas Gohr * @return string 117b8595a66SAndreas Gohr */ 118b8595a66SAndreas Gohrfunction tpl_toc($return = false) { 119b8595a66SAndreas Gohr global $TOC; 120b8595a66SAndreas Gohr global $ACT; 121b8595a66SAndreas Gohr global $ID; 122b8595a66SAndreas Gohr global $REV; 123b8595a66SAndreas Gohr global $INFO; 124851f2e89SAnika Henke global $conf; 125ac7a515fSAndreas Gohr global $INPUT; 126b8595a66SAndreas Gohr $toc = array(); 127b8595a66SAndreas Gohr 128b8595a66SAndreas Gohr if(is_array($TOC)) { 129b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 130b8595a66SAndreas Gohr $toc = $TOC; 1313c86d7c9SAndreas Gohr } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { 132b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 133e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 134b8595a66SAndreas Gohr if(isset($meta['internal']['toc'])) { 135b8595a66SAndreas Gohr $tocok = $meta['internal']['toc']; 136b8595a66SAndreas Gohr } else { 1372bb0d541Schris $tocok = true; 138b8595a66SAndreas Gohr } 139f87b5dbbSChristopher Smith $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null; 140851f2e89SAnika Henke if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 141b8595a66SAndreas Gohr $toc = array(); 142b8595a66SAndreas Gohr } 143b8595a66SAndreas Gohr } elseif($ACT == 'admin') { 144a61966c5SChristopher Smith // try to load admin plugin TOC 145ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 146a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 147b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 148b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 149b8595a66SAndreas Gohr } 150b8595a66SAndreas Gohr } 151b8595a66SAndreas Gohr 1520b17fdc6SAndreas Gohr trigger_event('TPL_TOC_RENDER', $toc, null, false); 153b8595a66SAndreas Gohr $html = html_TOC($toc); 154b8595a66SAndreas Gohr if($return) return $html; 155b8595a66SAndreas Gohr echo $html; 156ac7a515fSAndreas Gohr return ''; 157b8595a66SAndreas Gohr} 158b8595a66SAndreas Gohr 159b8595a66SAndreas Gohr/** 160c19fe9c0Sandi * Handle the admin page contents 161c19fe9c0Sandi * 162c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org> 16342ea7f44SGerrit Uitslag * 16442ea7f44SGerrit Uitslag * @return bool 165c19fe9c0Sandi */ 166c19fe9c0Sandifunction tpl_admin() { 167f8cc712eSAndreas Gohr global $INFO; 168b8595a66SAndreas Gohr global $TOC; 169ac7a515fSAndreas Gohr global $INPUT; 17011e2ce22Schris 171b8595a66SAndreas Gohr $plugin = null; 172ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 173ac7a515fSAndreas Gohr if(!empty($class)) { 17411e2ce22Schris $pluginlist = plugin_list('admin'); 17511e2ce22Schris 176ac7a515fSAndreas Gohr if(in_array($class, $pluginlist)) { 17711e2ce22Schris // attempt to load the plugin 178ac7a515fSAndreas Gohr /** @var $plugin DokuWiki_Admin_Plugin */ 179a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 18011e2ce22Schris } 18111e2ce22Schris } 18211e2ce22Schris 183b8595a66SAndreas Gohr if($plugin !== null) { 184b8595a66SAndreas Gohr if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 185b8595a66SAndreas Gohr if($INFO['prependTOC']) tpl_toc(); 186f8cc712eSAndreas Gohr $plugin->html(); 187f8cc712eSAndreas Gohr } else { 1880470c28fSAndreas Gohr $admin = new dokuwiki\Ui\Admin(); 1890470c28fSAndreas Gohr $admin->show(); 190f8cc712eSAndreas Gohr } 19154e95700STom N Harris return true; 192c19fe9c0Sandi} 1936b13307fSandi 1946b13307fSandi/** 1956b13307fSandi * Print the correct HTML meta headers 1966b13307fSandi * 1976b13307fSandi * This has to go into the head section of your template. 1986b13307fSandi * 1996b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 20042ea7f44SGerrit Uitslag * 201ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT 202ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 203ac7a515fSAndreas Gohr * @return bool 2046b13307fSandi */ 205f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) { 2066b13307fSandi global $ID; 207d98d4540SBen Coburn global $REV; 2086b13307fSandi global $INFO; 20972e0dc37SAndreas Gohr global $JSINFO; 2106b13307fSandi global $ACT; 2114bb1b5aeSAndreas Gohr global $QUERY; 2126b13307fSandi global $lang; 213dc57ef04Sandi global $conf; 2149c438d6cSMichael Hamann global $updateVersion; 215585bf44eSChristopher Smith /** @var Input $INPUT */ 216585bf44eSChristopher Smith global $INPUT; 2176b13307fSandi 2187bff22c0SAndreas Gohr // prepare the head array 2197bff22c0SAndreas Gohr $head = array(); 2207bff22c0SAndreas Gohr 221202ac28bSMichael Klier // prepare seed for js and css 222cd997f93SAndreas Gohr $tseed = $updateVersion; 223202ac28bSMichael Klier $depends = getConfigFiles('main'); 22484e76a7eSAndreas Gohr $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini"; 225cd997f93SAndreas Gohr foreach($depends as $f) $tseed .= @filemtime($f); 226cd997f93SAndreas Gohr $tseed = md5($tseed); 2277bff22c0SAndreas Gohr 2286b13307fSandi // the usual stuff 2293f803e5eSGina Haeussge $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); 23063cf4192Ssarehag if(actionOK('search')) { 231ac7a515fSAndreas Gohr $head['link'][] = array( 232ac7a515fSAndreas Gohr 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', 233ac7a515fSAndreas Gohr 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] 234ac7a515fSAndreas Gohr ); 23563cf4192Ssarehag } 23663cf4192Ssarehag 237f4f47358SBen Coburn $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); 2387aedde2eSGina Haeussge if(actionOK('index')) { 239ac7a515fSAndreas Gohr $head['link'][] = array( 240ac7a515fSAndreas Gohr 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), 241ac7a515fSAndreas Gohr 'title'=> $lang['btn_index'] 242ac7a515fSAndreas Gohr ); 2437aedde2eSGina Haeussge } 244f96fa415SAndreas Gohr 2455e0255e3SMichael Große if (actionOK('manifest')) { 2465e0255e3SMichael Große $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php'); 2475e0255e3SMichael Große } 2485e0255e3SMichael Große 249*40ca8540SMichael Große $styleUtil = new \dokuwiki\StyleUtils(); 250*40ca8540SMichael Große $styleIni = $styleUtil->cssStyleini($conf['template']); 251*40ca8540SMichael Große $replacements = $styleIni['replacements']; 252*40ca8540SMichael Große if (!empty($replacements['__theme_color__'])) { 253*40ca8540SMichael Große $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']); 254*40ca8540SMichael Große } 255*40ca8540SMichael Große 256f96fa415SAndreas Gohr if($alt) { 25754be1338SGerrit Uitslag if(actionOK('rss')) { 258ac7a515fSAndreas Gohr $head['link'][] = array( 259ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 260a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 261ac7a515fSAndreas Gohr ); 262ac7a515fSAndreas Gohr $head['link'][] = array( 263ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 264a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 265ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 266ac7a515fSAndreas Gohr ); 26754be1338SGerrit Uitslag } 268c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 269ac7a515fSAndreas Gohr $head['link'][] = array( 270ac7a515fSAndreas Gohr 'rel' => 'edit', 271715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 272ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 273ac7a515fSAndreas Gohr ); 274c35f3875SAndreas Gohr } 275c35f3875SAndreas Gohr 27654be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 277ac7a515fSAndreas Gohr $head['link'][] = array( 278ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 279a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 280ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 281ac7a515fSAndreas Gohr ); 2824bb1b5aeSAndreas Gohr } 283bae36d94SAndreas Gohr 284bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 285ac7a515fSAndreas Gohr $head['link'][] = array( 286a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 287ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 288ac7a515fSAndreas Gohr ); 289bae36d94SAndreas Gohr } 290bae36d94SAndreas Gohr 291bae36d94SAndreas Gohr if(actionOK('export_raw')) { 292ac7a515fSAndreas Gohr $head['link'][] = array( 293a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 294ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 295ac7a515fSAndreas Gohr ); 296f96fa415SAndreas Gohr } 297bae36d94SAndreas Gohr } 2986b13307fSandi 2996b13307fSandi // setup robot tags apropriate for different modes 3004f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3016b13307fSandi if($INFO['exists']) { 3026b13307fSandi //delay indexing: 303fb9fa88bSAndreas Gohr if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) { 3047bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3056b13307fSandi } else { 3067bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3076b13307fSandi } 30801f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 30901f9be51SAnika Henke if ($ID == $conf['start']) { 31001f9be51SAnika Henke $canonicalUrl = DOKU_URL; 31101f9be51SAnika Henke } 31201f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3136b13307fSandi } else { 3147bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3156b13307fSandi } 3167a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3177bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3186b13307fSandi } else { 3197bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3206b13307fSandi } 3216b13307fSandi 322831800b8SAndreas Gohr // set metadata 323831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 324831800b8SAndreas Gohr // keywords (explicit or implicit) 325bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3267bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 327831800b8SAndreas Gohr } else { 3287bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 329831800b8SAndreas Gohr } 330831800b8SAndreas Gohr } 331831800b8SAndreas Gohr 33278a6aeb1SAndreas Gohr // load stylesheets 333ac7a515fSAndreas Gohr $head['link'][] = array( 334ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 335e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 336ac7a515fSAndreas Gohr ); 337bad31ae9SAndreas Gohr 3388bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 339463d4a65SAndreas Gohr $json = new JSON(); 34072e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 341585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 34272e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 343c591aabeSAndreas Gohr } 34472e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 34585f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 3468bbcb611SAndreas Gohr 34761537d47SAndreas Gohr // load jquery 348fa078663SAndreas Gohr $jquery = getCdnUrls(); 349fa078663SAndreas Gohr foreach($jquery as $src) { 35061537d47SAndreas Gohr $head['script'][] = array( 351fa078663SAndreas Gohr 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src 35261537d47SAndreas Gohr ); 35361537d47SAndreas Gohr } 35461537d47SAndreas Gohr 35561537d47SAndreas Gohr // load our javascript dispatcher 356ac7a515fSAndreas Gohr $head['script'][] = array( 357ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 358e283bd6cSAnika Henke 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed 359ac7a515fSAndreas Gohr ); 3607bff22c0SAndreas Gohr 3617bff22c0SAndreas Gohr // trigger event here 362016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 36354e95700STom N Harris return true; 3647bff22c0SAndreas Gohr} 3657bff22c0SAndreas Gohr 3667bff22c0SAndreas Gohr/** 3677bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 3687bff22c0SAndreas Gohr * 3697bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 3707bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 3717bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 3727bff22c0SAndreas Gohr * 37342ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 3741304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 3757bff22c0SAndreas Gohr * 3767bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 37742ea7f44SGerrit Uitslag * 37842ea7f44SGerrit Uitslag * @param array $data 3797bff22c0SAndreas Gohr */ 3807bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 3817bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 382427bf9a2SAndreas Gohr if($tag == 'script') { 383427bf9a2SAndreas Gohr echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE 384427bf9a2SAndreas Gohr } 3857bff22c0SAndreas Gohr foreach($inst as $attr) { 3869b48e6a1SGerry Weißbach if ( empty($attr) ) { continue; } 3877bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 38826afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 389e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 39009f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 391e226efe1SAndreas Gohr $attr['_data']. 39209f791c4SDominik Eckelmann "\n/*!]]>*/"; 393e226efe1SAndreas Gohr 3941304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 3957bff22c0SAndreas Gohr } else { 3967bff22c0SAndreas Gohr echo '/>'; 3977bff22c0SAndreas Gohr } 3987bff22c0SAndreas Gohr echo "\n"; 3997bff22c0SAndreas Gohr } 400427bf9a2SAndreas Gohr if($tag == 'script') { 401427bf9a2SAndreas Gohr echo "<!--<![endif]-->\n"; 402427bf9a2SAndreas Gohr } 4037bff22c0SAndreas Gohr } 4046b13307fSandi} 4056b13307fSandi 4066b13307fSandi/** 4076b13307fSandi * Print a link 4086b13307fSandi * 4095e163278SAndreas Gohr * Just builds a link. 4106b13307fSandi * 4116b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 41242ea7f44SGerrit Uitslag * 41342ea7f44SGerrit Uitslag * @param string $url 41442ea7f44SGerrit Uitslag * @param string $name 41542ea7f44SGerrit Uitslag * @param string $more 41621d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 41721d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4186b13307fSandi */ 4191af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 42001f17825SAnika Henke $out = '<a href="'.$url.'" '; 4211af98a77SAnika Henke if($more) $out .= ' '.$more; 4221af98a77SAnika Henke $out .= ">$name</a>"; 4231af98a77SAnika Henke if($return) return $out; 4241af98a77SAnika Henke print $out; 42554e95700STom N Harris return true; 4266b13307fSandi} 4276b13307fSandi 4286b13307fSandi/** 42955efc227SAndreas Gohr * Prints a link to a WikiPage 43055efc227SAndreas Gohr * 43155efc227SAndreas Gohr * Wrapper around html_wikilink 43255efc227SAndreas Gohr * 43355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 43442ea7f44SGerrit Uitslag * 43542ea7f44SGerrit Uitslag * @param string $id page id 43642ea7f44SGerrit Uitslag * @param string|null $name the name of the link 43721d806cdSGerrit Uitslag * @return bool true 43855efc227SAndreas Gohr */ 4390b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 440d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 44154e95700STom N Harris return true; 44255efc227SAndreas Gohr} 44355efc227SAndreas Gohr 44455efc227SAndreas Gohr/** 445a3ec5f4aSmatthiasgrimm * get the parent page 446a3ec5f4aSmatthiasgrimm * 447a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 448a3ec5f4aSmatthiasgrimm * returns false if none is available 449a3ec5f4aSmatthiasgrimm * 450377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 45142ea7f44SGerrit Uitslag * 45242ea7f44SGerrit Uitslag * @param string $id page id 45342ea7f44SGerrit Uitslag * @return false|string 454a3ec5f4aSmatthiasgrimm */ 455377f9e97SAndreas Gohrfunction tpl_getparent($id) { 456377f9e97SAndreas Gohr $parent = getNS($id).':'; 457377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 458a197105eSmatthiasgrimm if($parent == $id) { 459a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 460a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 461a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 462377f9e97SAndreas Gohr if($parent == $id) return false; 463a197105eSmatthiasgrimm } 464377f9e97SAndreas Gohr return $parent; 465a3ec5f4aSmatthiasgrimm} 466a3ec5f4aSmatthiasgrimm 467a3ec5f4aSmatthiasgrimm/** 4686b13307fSandi * Print one of the buttons 4696b13307fSandi * 470a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 471a453d131SAdrian Lang * @see tpl_get_action 472e0c26282SGerrit Uitslag * 473e0c26282SGerrit Uitslag * @param string $type 474e0c26282SGerrit Uitslag * @param bool $return 475e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 476affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 4776b13307fSandi */ 4781af98a77SAnika Henkefunction tpl_button($type, $return = false) { 479affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 480a453d131SAdrian Lang $data = tpl_get_action($type); 481a453d131SAdrian Lang if($data === false) { 482a453d131SAdrian Lang return false; 483a453d131SAdrian Lang } elseif(!is_array($data)) { 484a453d131SAdrian Lang $out = sprintf($data, 'button'); 485409d7af7SAndreas Gohr } else { 486ac7a515fSAndreas Gohr /** 487ac7a515fSAndreas Gohr * @var string $accesskey 488ac7a515fSAndreas Gohr * @var string $id 489ac7a515fSAndreas Gohr * @var string $method 490ac7a515fSAndreas Gohr * @var array $params 491ac7a515fSAndreas Gohr */ 492a453d131SAdrian Lang extract($data); 493a453d131SAdrian Lang if($id === '#dokuwiki__top') { 494a453d131SAdrian Lang $out = html_topbtn(); 495409d7af7SAndreas Gohr } else { 496a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 497409d7af7SAndreas Gohr } 498409d7af7SAndreas Gohr } 4991af98a77SAnika Henke if($return) return $out; 500a453d131SAdrian Lang echo $out; 501a453d131SAdrian Lang return true; 5026b13307fSandi} 5036b13307fSandi 5046b13307fSandi/** 505ed630903Sandi * Like the action buttons but links 506ed630903Sandi * 507a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 508a453d131SAdrian Lang * @see tpl_get_action 509e0c26282SGerrit Uitslag * 51042ea7f44SGerrit Uitslag * @param string $type action command 511e0c26282SGerrit Uitslag * @param string $pre prefix of link 512e0c26282SGerrit Uitslag * @param string $suf suffix of link 513e0c26282SGerrit Uitslag * @param string $inner innerHML of link 51421d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 515e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 516affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 517a453d131SAdrian Lang */ 518a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 519affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 520a453d131SAdrian Lang global $lang; 521a453d131SAdrian Lang $data = tpl_get_action($type); 522a453d131SAdrian Lang if($data === false) { 523a453d131SAdrian Lang return false; 524a453d131SAdrian Lang } elseif(!is_array($data)) { 525a453d131SAdrian Lang $out = sprintf($data, 'link'); 526a453d131SAdrian Lang } else { 527ac7a515fSAndreas Gohr /** 528ac7a515fSAndreas Gohr * @var string $accesskey 529ac7a515fSAndreas Gohr * @var string $id 530ac7a515fSAndreas Gohr * @var string $method 531b1af9014SChristopher Smith * @var bool $nofollow 532ac7a515fSAndreas Gohr * @var array $params 533becfa414SGerrit Uitslag * @var string $replacement 534ac7a515fSAndreas Gohr */ 535a453d131SAdrian Lang extract($data); 536a453d131SAdrian Lang if(strpos($id, '#') === 0) { 537a453d131SAdrian Lang $linktarget = $id; 538a453d131SAdrian Lang } else { 539a453d131SAdrian Lang $linktarget = wl($id, $params); 540a453d131SAdrian Lang } 541a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 542becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 543becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 544becfa414SGerrit Uitslag } 545c7e90e3fSAnika Henke $akey = $addTitle = ''; 546c7e90e3fSAnika Henke if($accesskey) { 547c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 548c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 549c7e90e3fSAnika Henke } 550b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 551ac7a515fSAndreas Gohr $out = tpl_link( 552ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 553a453d131SAdrian Lang 'class="action '.$type.'" '. 554b1af9014SChristopher Smith $akey.$rel. 555e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 556ac7a515fSAndreas Gohr ); 557a453d131SAdrian Lang } 558a453d131SAdrian Lang if($return) return $out; 559a453d131SAdrian Lang echo $out; 560a453d131SAdrian Lang return true; 561a453d131SAdrian Lang} 562a453d131SAdrian Lang 563a453d131SAdrian Lang/** 564a453d131SAdrian Lang * Check the actions and get data for buttons and links 565ed630903Sandi * 566ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 567a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 568a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 569e0c26282SGerrit Uitslag * 570ac7a515fSAndreas Gohr * @param string $type 571ac7a515fSAndreas Gohr * @return array|bool|string 572affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 573ed630903Sandi */ 574a453d131SAdrian Langfunction tpl_get_action($type) { 575affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 576a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 5774c4b65c8SMichael Hamann if($type == 'subscription') $type = 'subscribe'; 5784887c154SAndreas Gohr if($type == 'img_backto') $type = 'imgBackto'; 579409d7af7SAndreas Gohr 5804887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 5814887c154SAndreas Gohr if(class_exists($class)) { 5824887c154SAndreas Gohr try { 5834887c154SAndreas Gohr /** @var \dokuwiki\Menu\Item\AbstractItem $item */ 5844887c154SAndreas Gohr $item = new $class; 5854887c154SAndreas Gohr $data = $item->getLegacyData(); 5867b4365a7SGerrit Uitslag $unknown = false; 5874887c154SAndreas Gohr } catch(\RuntimeException $ignored) { 5884887c154SAndreas Gohr return false; 589b8a111f5SMichael Klier } 590ed630903Sandi } else { 5914887c154SAndreas Gohr global $ID; 5924887c154SAndreas Gohr $data = array( 5934887c154SAndreas Gohr 'accesskey' => null, 5944887c154SAndreas Gohr 'type' => $type, 5954887c154SAndreas Gohr 'id' => $ID, 5964887c154SAndreas Gohr 'method' => 'get', 5974887c154SAndreas Gohr 'params' => array('do' => $type), 5984887c154SAndreas Gohr 'nofollow' => true, 5994887c154SAndreas Gohr 'replacement' => '', 600becfa414SGerrit Uitslag ); 6017b4365a7SGerrit Uitslag $unknown = true; 602ed630903Sandi } 6037b4365a7SGerrit Uitslag 6043131073dSGerrit Uitslag $evt = new Doku_Event('TPL_ACTION_GET', $data); 6057b4365a7SGerrit Uitslag if($evt->advise_before()) { 6067b4365a7SGerrit Uitslag //handle unknown types 6077b4365a7SGerrit Uitslag if($unknown) { 60838d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6097b4365a7SGerrit Uitslag } 6107b4365a7SGerrit Uitslag } 6117b4365a7SGerrit Uitslag $evt->advise_after(); 6127b4365a7SGerrit Uitslag unset($evt); 6137b4365a7SGerrit Uitslag 6147b4365a7SGerrit Uitslag return $data; 615ed630903Sandi} 616ed630903Sandi 617ed630903Sandi/** 61801f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 61901f17825SAnika Henke * 62001f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 62142ea7f44SGerrit Uitslag * 62242ea7f44SGerrit Uitslag * @param string $type action command 623ac7a515fSAndreas Gohr * @param bool $link link or form button? 624e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 625ac7a515fSAndreas Gohr * @param bool $return return or print 626ac7a515fSAndreas Gohr * @param string $pre prefix for links 627ac7a515fSAndreas Gohr * @param string $suf suffix for links 628ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 629ac7a515fSAndreas Gohr * @return bool|string 630affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 63101f17825SAnika Henke */ 632ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 633affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 63401f17825SAnika Henke $out = ''; 635ac7a515fSAndreas Gohr if($link) { 636e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 637ac7a515fSAndreas Gohr } else { 638e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 639ac7a515fSAndreas Gohr } 64001f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 64101f17825SAnika Henke 64201f17825SAnika Henke if($return) return $out; 64301f17825SAnika Henke print $out; 64401f17825SAnika Henke return $out ? true : false; 64501f17825SAnika Henke} 64601f17825SAnika Henke 64701f17825SAnika Henke/** 6486b13307fSandi * Print the search form 6496b13307fSandi * 65072645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 65172645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 65272645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 65372645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 65472645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 65572645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 65672645b75SAndreas Gohr * 6576b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 65842ea7f44SGerrit Uitslag * 659ac7a515fSAndreas Gohr * @param bool $ajax 660ac7a515fSAndreas Gohr * @param bool $autocomplete 661ac7a515fSAndreas Gohr * @return bool 6626b13307fSandi */ 66372645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 6646b13307fSandi global $lang; 665c1e3b7d9Smatthiasgrimm global $ACT; 666ad4aaef7SAndreas Gohr global $QUERY; 667c1e3b7d9Smatthiasgrimm 668670ff54eSchris // don't print the search form if search action has been disabled 66964276bbcSarbrk1 if(!actionOK('search')) return false; 670670ff54eSchris 6719805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 6726b13307fSandi print '<input type="hidden" name="do" value="search" />'; 673c1e3b7d9Smatthiasgrimm print '<input type="text" '; 674ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 675001ea14eSRainbow Spike print 'placeholder="'.$lang['btn_search'].'" '; 67672645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 67707493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 678ae614416SAnika Henke print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>'; 67924a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 6804beabca9SAnika Henke print '</div></form>'; 68154e95700STom N Harris return true; 6826b13307fSandi} 6836b13307fSandi 6846b13307fSandi/** 6856b13307fSandi * Print the breadcrumbs trace 6866b13307fSandi * 6876b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 68842ea7f44SGerrit Uitslag * 689ac7a515fSAndreas Gohr * @param string $sep Separator between entries 690ac7a515fSAndreas Gohr * @return bool 6916b13307fSandi */ 692e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 6936b13307fSandi global $lang; 6946b13307fSandi global $conf; 6956b13307fSandi 6966b13307fSandi //check if enabled 697359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 6986b13307fSandi 6996b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 700265e3787Sandi 7012979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 702265e3787Sandi 70340eb54bbSjan //render crumbs, highlight the last one 704fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 70540eb54bbSjan $last = count($crumbs); 70640eb54bbSjan $i = 0; 707a77f5846Sjan foreach($crumbs as $id => $name) { 70840eb54bbSjan $i++; 7092979a10bSKatriel Traum echo $crumbs_sep; 71092795d04Sandi if($i == $last) print '<span class="curid">'; 711d317fb5dSAnika Henke print '<bdi>'; 712e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 713d317fb5dSAnika Henke print '</bdi>'; 71492795d04Sandi if($i == $last) print '</span>'; 7156b13307fSandi } 71654e95700STom N Harris return true; 7176b13307fSandi} 7186b13307fSandi 7196b13307fSandi/** 7201734437eSandi * Hierarchical breadcrumbs 7211734437eSandi * 72231e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 7231734437eSandi * It only makes sense with a deep site structure. 7241734437eSandi * 7251734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 7266bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 72731e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 728f46c9e83SAnika Henke * @author <fredrik@averpil.com> 72908d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 73042ea7f44SGerrit Uitslag * 731ac7a515fSAndreas Gohr * @param string $sep Separator between entries 732ac7a515fSAndreas Gohr * @return bool 7331734437eSandi */ 73408d7a575SAndreas Gohrfunction tpl_youarehere($sep = ' » ') { 7351734437eSandi global $conf; 7361734437eSandi global $ID; 7371734437eSandi global $lang; 7381734437eSandi 73931e187f8SSean Coates // check if enabled 74054e95700STom N Harris if(!$conf['youarehere']) return false; 7411734437eSandi 7421734437eSandi $parts = explode(':', $ID); 743796bafb3SAndreas Gohr $count = count($parts); 7441734437eSandi 74508d7a575SAndreas Gohr echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 7463940c519SMark 74708d7a575SAndreas Gohr // always print the startpage 74808d7a575SAndreas Gohr echo '<span class="home">'; 74908d7a575SAndreas Gohr tpl_pagelink(':'.$conf['start']); 75008d7a575SAndreas Gohr echo '</span>'; 751796bafb3SAndreas Gohr 752796bafb3SAndreas Gohr // print intermediate namespace links 753796bafb3SAndreas Gohr $part = ''; 754796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 755796bafb3SAndreas Gohr $part .= $parts[$i].':'; 756796bafb3SAndreas Gohr $page = $part; 757796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 758796bafb3SAndreas Gohr 75908d7a575SAndreas Gohr // output 76008d7a575SAndreas Gohr echo $sep; 76108d7a575SAndreas Gohr tpl_pagelink($page); 76231e187f8SSean Coates } 7631734437eSandi 764796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 765e013f48dSAnika Henke resolve_pageid('', $page, $exists); 76608d7a575SAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 767796bafb3SAndreas Gohr $page = $part.$parts[$i]; 76808d7a575SAndreas Gohr if($page == $conf['start']) return true; 76908d7a575SAndreas Gohr echo $sep; 77008d7a575SAndreas Gohr tpl_pagelink($page); 77154e95700STom N Harris return true; 7721734437eSandi} 7731734437eSandi 7741734437eSandi/** 7756b13307fSandi * Print info if the user is logged in 776a2488c3cSMatthias Grimm * and show full name in that case 7776b13307fSandi * 7786b13307fSandi * Could be enhanced with a profile link in future? 7796b13307fSandi * 7806b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 78142ea7f44SGerrit Uitslag * 782ac7a515fSAndreas Gohr * @return bool 7836b13307fSandi */ 7846b13307fSandifunction tpl_userinfo() { 7856b13307fSandi global $lang; 786585bf44eSChristopher Smith /** @var Input $INPUT */ 787585bf44eSChristopher Smith global $INPUT; 788585bf44eSChristopher Smith 789585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 790fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 79154e95700STom N Harris return true; 79254e95700STom N Harris } 79354e95700STom N Harris return false; 7946b13307fSandi} 7956b13307fSandi 7966b13307fSandi/** 7976b13307fSandi * Print some info about the current page 7986b13307fSandi * 7996b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 80042ea7f44SGerrit Uitslag * 801ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 802ac7a515fSAndreas Gohr * @return bool|string 8036b13307fSandi */ 8044b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 8056b13307fSandi global $conf; 8066b13307fSandi global $lang; 8076b13307fSandi global $INFO; 808c6e92a3cSDavid Lorentsen global $ID; 809c6e92a3cSDavid Lorentsen 810c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 811ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 812ac7a515fSAndreas Gohr return false; 813ac7a515fSAndreas Gohr } 8146b13307fSandi 8156b13307fSandi // prepare date and path 8166b13307fSandi $fn = $INFO['filepath']; 8176b13307fSandi if(!$conf['fullpath']) { 818613bca54SAndreas Gohr if($INFO['rev']) { 819c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'].'/', '', $fn); 8206b13307fSandi } else { 821c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'].'/', '', $fn); 8226b13307fSandi } 8236b13307fSandi } 824bee6dc82Sandi $fn = utf8_decodeFN($fn); 825f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 8266b13307fSandi 827faecdfdfSAndreas Gohr // print it 828faecdfdfSAndreas Gohr if($INFO['exists']) { 8294b0d3916SAndreas Gohr $out = ''; 830d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 831e260f93bSAnika Henke $out .= ' · '; 8324b0d3916SAndreas Gohr $out .= $lang['lastmod']; 833fde860beSGerrit Uitslag $out .= ' '; 8344b0d3916SAndreas Gohr $out .= $date; 8356b13307fSandi if($INFO['editor']) { 8364b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 837d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 8385aa52fafSBen Coburn } else { 8394b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 8406b13307fSandi } 8416b13307fSandi if($INFO['locked']) { 842e260f93bSAnika Henke $out .= ' · '; 8434b0d3916SAndreas Gohr $out .= $lang['lockedby']; 844fde860beSGerrit Uitslag $out .= ' '; 845d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 8466b13307fSandi } 8474b0d3916SAndreas Gohr if($ret) { 8484b0d3916SAndreas Gohr return $out; 8494b0d3916SAndreas Gohr } else { 8504b0d3916SAndreas Gohr echo $out; 85154e95700STom N Harris return true; 8526b13307fSandi } 8534b0d3916SAndreas Gohr } 85454e95700STom N Harris return false; 8556b13307fSandi} 8566b13307fSandi 857820fa24bSandi/** 858a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 85987c434ceSAndreas Gohr * 86087c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 861a6598f23SBen Coburn * the given ID is used. 86287c434ceSAndreas Gohr * 86387c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 86442ea7f44SGerrit Uitslag * 865ac7a515fSAndreas Gohr * @param string $id page id 866ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 867ac7a515fSAndreas Gohr * @return bool|string 86887c434ceSAndreas Gohr */ 869a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 870c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 871fffeeafeSChristopher Smith 87287c434ceSAndreas Gohr if(is_null($id)) { 87387c434ceSAndreas Gohr global $ID; 87487c434ceSAndreas Gohr $id = $ID; 87587c434ceSAndreas Gohr } 87687c434ceSAndreas Gohr 87787c434ceSAndreas Gohr $name = $id; 878fe9ec250SChris Smith if(useHeading('navigation')) { 879fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 880fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 881fffeeafeSChristopher Smith } 882fffeeafeSChristopher Smith 883fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 884fffeeafeSChristopher Smith switch ($ACT) { 885fffeeafeSChristopher Smith // admin functions 886fffeeafeSChristopher Smith case 'admin' : 887fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 888fffeeafeSChristopher Smith // try to get the plugin name 889a61966c5SChristopher Smith /** @var $plugin DokuWiki_Admin_Plugin */ 890a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 891c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 892a61966c5SChristopher Smith $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); 893fffeeafeSChristopher Smith } 894fffeeafeSChristopher Smith break; 895fffeeafeSChristopher Smith 896fffeeafeSChristopher Smith // user functions 897fffeeafeSChristopher Smith case 'login' : 898fffeeafeSChristopher Smith case 'profile' : 899fffeeafeSChristopher Smith case 'register' : 900fffeeafeSChristopher Smith case 'resendpwd' : 901fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 902fffeeafeSChristopher Smith break; 903fffeeafeSChristopher Smith 904fffeeafeSChristopher Smith // wiki functions 905fffeeafeSChristopher Smith case 'search' : 906fffeeafeSChristopher Smith case 'index' : 907fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 908fffeeafeSChristopher Smith break; 909fffeeafeSChristopher Smith 910fffeeafeSChristopher Smith // page functions 911fffeeafeSChristopher Smith case 'edit' : 912fffeeafeSChristopher Smith $page_title = "✎ ".$name; 913fffeeafeSChristopher Smith break; 914fffeeafeSChristopher Smith 915fffeeafeSChristopher Smith case 'revisions' : 916fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 917fffeeafeSChristopher Smith break; 918fffeeafeSChristopher Smith 919fffeeafeSChristopher Smith case 'backlink' : 920fffeeafeSChristopher Smith case 'recent' : 921fffeeafeSChristopher Smith case 'subscribe' : 922fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 923fffeeafeSChristopher Smith break; 924fffeeafeSChristopher Smith 925fffeeafeSChristopher Smith default : // SHOW and anything else not included 926fffeeafeSChristopher Smith $page_title = $name; 92787c434ceSAndreas Gohr } 928a6598f23SBen Coburn 929a6598f23SBen Coburn if($ret) { 930fffeeafeSChristopher Smith return hsc($page_title); 931a6598f23SBen Coburn } else { 932fffeeafeSChristopher Smith print hsc($page_title); 93354e95700STom N Harris return true; 93487c434ceSAndreas Gohr } 935a6598f23SBen Coburn} 936340756e4Sandi 93755efc227SAndreas Gohr/** 93855efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 93955efc227SAndreas Gohr * 94055efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 94155efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 94255efc227SAndreas Gohr * 94355efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 94455efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 94555efc227SAndreas Gohr * to the names of the latter one) 94655efc227SAndreas Gohr * 9473df72098SAndreas Gohr * Only allowed in: detail.php 94855efc227SAndreas Gohr * 94955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 95042ea7f44SGerrit Uitslag * 95121d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 952ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 953e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 954ac7a515fSAndreas Gohr * @return string 95555efc227SAndreas Gohr */ 9563df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 95755efc227SAndreas Gohr // Init Exif Reader 95855efc227SAndreas Gohr global $SRC; 9593df72098SAndreas Gohr 9603df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 9613df72098SAndreas Gohr 96255efc227SAndreas Gohr static $meta = null; 9633df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 96455efc227SAndreas Gohr if($meta === false) return $alt; 96588945224SChristopher Smith $info = cleanText($meta->getField($tags)); 96655efc227SAndreas Gohr if($info == false) return $alt; 96755efc227SAndreas Gohr return $info; 96855efc227SAndreas Gohr} 96955efc227SAndreas Gohr 97055efc227SAndreas Gohr/** 971becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 972becfa414SGerrit Uitslag * 973becfa414SGerrit Uitslag * @return string html of description list 974becfa414SGerrit Uitslag */ 975becfa414SGerrit Uitslagfunction tpl_img_meta() { 976becfa414SGerrit Uitslag global $lang; 977becfa414SGerrit Uitslag 978becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 979becfa414SGerrit Uitslag 980becfa414SGerrit Uitslag echo '<dl>'; 981becfa414SGerrit Uitslag foreach($tags as $tag) { 982becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 983fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 984becfa414SGerrit Uitslag 985fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 986becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 987becfa414SGerrit Uitslag echo dformat($tag['value']); 988becfa414SGerrit Uitslag } else { 989becfa414SGerrit Uitslag echo hsc($tag['value']); 990becfa414SGerrit Uitslag } 991becfa414SGerrit Uitslag echo '</dd>'; 992becfa414SGerrit Uitslag } 993becfa414SGerrit Uitslag echo '</dl>'; 994becfa414SGerrit Uitslag} 995becfa414SGerrit Uitslag 996becfa414SGerrit Uitslag/** 997becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 998becfa414SGerrit Uitslag * 999becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1000becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1001becfa414SGerrit Uitslag * - string type type of value 1002becfa414SGerrit Uitslag * - string value tag value (unescaped) 1003becfa414SGerrit Uitslag */ 1004becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1005becfa414SGerrit Uitslag 1006becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1007becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 100879e79377SAndreas Gohr if(file_exists($config_file)) { 1009becfa414SGerrit Uitslag include($config_file); 1010becfa414SGerrit Uitslag } 1011becfa414SGerrit Uitslag } 1012becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1013becfa414SGerrit Uitslag 1014becfa414SGerrit Uitslag $tags = array(); 1015becfa414SGerrit Uitslag foreach($fields as $tag){ 1016becfa414SGerrit Uitslag $t = array(); 1017becfa414SGerrit Uitslag if (!empty($tag[0])) { 1018becfa414SGerrit Uitslag $t = array($tag[0]); 1019becfa414SGerrit Uitslag } 1020becfa414SGerrit Uitslag if(is_array($tag[3])) { 1021becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1022becfa414SGerrit Uitslag } 1023becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1024becfa414SGerrit Uitslag if ($value) { 1025becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1026becfa414SGerrit Uitslag } 1027becfa414SGerrit Uitslag } 1028becfa414SGerrit Uitslag return $tags; 1029becfa414SGerrit Uitslag} 1030becfa414SGerrit Uitslag 1031becfa414SGerrit Uitslag/** 103255efc227SAndreas Gohr * Prints the image with a link to the full sized version 103355efc227SAndreas Gohr * 103455efc227SAndreas Gohr * Only allowed in: detail.php 1035a02d2933SAndreas Gohr * 1036ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1037a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1038a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1039a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1040a02d2933SAndreas Gohr * @param $params array - additional image attributes 104142ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 104255efc227SAndreas Gohr */ 1043a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 104455efc227SAndreas Gohr global $IMG; 1045585bf44eSChristopher Smith /** @var Input $INPUT */ 1046ac7a515fSAndreas Gohr global $INPUT; 10475c2eed9aSlisps global $REV; 104865d3a5dbSAndreas Gohr $w = (int) tpl_img_getTag('File.Width'); 104965d3a5dbSAndreas Gohr $h = (int) tpl_img_getTag('File.Height'); 105055efc227SAndreas Gohr 105155efc227SAndreas Gohr //resize to given max values 105223a34783SAndreas Gohr $ratio = 1; 105323a34783SAndreas Gohr if($w >= $h) { 1054f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 105555efc227SAndreas Gohr $ratio = $maxwidth / $w; 1056f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 105755efc227SAndreas Gohr $ratio = $maxheight / $h; 105855efc227SAndreas Gohr } 105955efc227SAndreas Gohr } else { 1060f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 106155efc227SAndreas Gohr $ratio = $maxheight / $h; 1062f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 106355efc227SAndreas Gohr $ratio = $maxwidth / $w; 106455efc227SAndreas Gohr } 106555efc227SAndreas Gohr } 106655efc227SAndreas Gohr if($ratio) { 106755efc227SAndreas Gohr $w = floor($ratio * $w); 106855efc227SAndreas Gohr $h = floor($ratio * $h); 106955efc227SAndreas Gohr } 107055efc227SAndreas Gohr 10716de3759aSAndreas Gohr //prepare URLs 10725c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 10735c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 107455efc227SAndreas Gohr 10752684e50aSAndreas Gohr //prepare attributes 107655efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1077a02d2933SAndreas Gohr if(is_null($params)) { 10782684e50aSAndreas Gohr $p = array(); 1079a02d2933SAndreas Gohr } else { 1080a02d2933SAndreas Gohr $p = $params; 1081a02d2933SAndreas Gohr } 10822684e50aSAndreas Gohr if($w) $p['width'] = $w; 10832684e50aSAndreas Gohr if($h) $p['height'] = $h; 10842684e50aSAndreas Gohr $p['class'] = 'img_detail'; 10852684e50aSAndreas Gohr if($alt) { 10862684e50aSAndreas Gohr $p['alt'] = $alt; 10872684e50aSAndreas Gohr $p['title'] = $alt; 10882684e50aSAndreas Gohr } else { 10892684e50aSAndreas Gohr $p['alt'] = ''; 10902684e50aSAndreas Gohr } 1091a02d2933SAndreas Gohr $p['src'] = $src; 109255efc227SAndreas Gohr 1093a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1094a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1095a02d2933SAndreas Gohr} 1096a02d2933SAndreas Gohr 1097a02d2933SAndreas Gohr/** 1098a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1099ac7a515fSAndreas Gohr * 1100ac7a515fSAndreas Gohr * @param array $data 1101ac7a515fSAndreas Gohr * @return bool 1102a02d2933SAndreas Gohr */ 1103ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 110459f3611bSAnika Henke global $lang; 1105a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1106a02d2933SAndreas Gohr 110759f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1108a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1109a02d2933SAndreas Gohr if($data['url']) print '</a>'; 111054e95700STom N Harris return true; 111155efc227SAndreas Gohr} 111255efc227SAndreas Gohr 11137367b368SAndreas Gohr/** 1114881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 11157367b368SAndreas Gohr * 11167367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 11177367b368SAndreas Gohr * template 1118ac7a515fSAndreas Gohr * 1119ac7a515fSAndreas Gohr * @return bool 11207367b368SAndreas Gohr */ 11217367b368SAndreas Gohrfunction tpl_indexerWebBug() { 11227367b368SAndreas Gohr global $ID; 11231dad36f5SAndreas Gohr 11247367b368SAndreas Gohr $p = array(); 1125b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1126e68c51baSAndreas Gohr '&'.time(); 1127881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 11287367b368SAndreas Gohr $p['height'] = 1; 11297367b368SAndreas Gohr $p['alt'] = ''; 11307367b368SAndreas Gohr $att = buildAttributes($p); 11317367b368SAndreas Gohr print "<img $att />"; 113254e95700STom N Harris return true; 11337367b368SAndreas Gohr} 11347367b368SAndreas Gohr 113578d4e784SEsther Brunner/** 113678d4e784SEsther Brunner * tpl_getConf($id) 113778d4e784SEsther Brunner * 113878d4e784SEsther Brunner * use this function to access template configuration variables 1139ac7a515fSAndreas Gohr * 114017448fb8SChristopher Smith * @param string $id name of the value to access 114117448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 114217448fb8SChristopher Smith * @return mixed 114378d4e784SEsther Brunner */ 114417448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 114578d4e784SEsther Brunner global $conf; 114617566ac6SAdrian Lang static $tpl_configloaded = false; 114778d4e784SEsther Brunner 114878d4e784SEsther Brunner $tpl = $conf['template']; 114978d4e784SEsther Brunner 115078d4e784SEsther Brunner if(!$tpl_configloaded) { 115178d4e784SEsther Brunner $tconf = tpl_loadConfig(); 115278d4e784SEsther Brunner if($tconf !== false) { 115378d4e784SEsther Brunner foreach($tconf as $key => $value) { 115478d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 115578d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 115678d4e784SEsther Brunner } 115778d4e784SEsther Brunner $tpl_configloaded = true; 115878d4e784SEsther Brunner } 115978d4e784SEsther Brunner } 116078d4e784SEsther Brunner 116117448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 116278d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 116378d4e784SEsther Brunner } 116478d4e784SEsther Brunner 116517448fb8SChristopher Smith return $notset; 116617448fb8SChristopher Smith} 116717448fb8SChristopher Smith 116878d4e784SEsther Brunner/** 116978d4e784SEsther Brunner * tpl_loadConfig() 1170ac7a515fSAndreas Gohr * 117178d4e784SEsther Brunner * reads all template configuration variables 117278d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1173ac7a515fSAndreas Gohr * 1174ac7a515fSAndreas Gohr * @return array 117578d4e784SEsther Brunner */ 117678d4e784SEsther Brunnerfunction tpl_loadConfig() { 117778d4e784SEsther Brunner 1178c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 117978d4e784SEsther Brunner $conf = array(); 118078d4e784SEsther Brunner 118179e79377SAndreas Gohr if(!file_exists($file)) return false; 118278d4e784SEsther Brunner 118378d4e784SEsther Brunner // load default config file 118478d4e784SEsther Brunner include($file); 118578d4e784SEsther Brunner 118678d4e784SEsther Brunner return $conf; 118778d4e784SEsther Brunner} 118878d4e784SEsther Brunner 118917566ac6SAdrian Lang// language methods 119017566ac6SAdrian Lang/** 119117566ac6SAdrian Lang * tpl_getLang($id) 119217566ac6SAdrian Lang * 119317566ac6SAdrian Lang * use this function to access template language variables 119442ea7f44SGerrit Uitslag * 119542ea7f44SGerrit Uitslag * @param string $id key of language string 119642ea7f44SGerrit Uitslag * @return string 119717566ac6SAdrian Lang */ 119817566ac6SAdrian Langfunction tpl_getLang($id) { 119917566ac6SAdrian Lang static $lang = array(); 120017566ac6SAdrian Lang 120117566ac6SAdrian Lang if(count($lang) === 0) { 1202dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1203dd7a6159SGerrit Uitslag 1204c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 120517566ac6SAdrian Lang 120617566ac6SAdrian Lang $lang = array(); 120717566ac6SAdrian Lang 120817566ac6SAdrian Lang // don't include once 120917566ac6SAdrian Lang @include($path . 'en/lang.php'); 1210dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 121179e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1212dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1213dd7a6159SGerrit Uitslag } 121417566ac6SAdrian Lang } 121517566ac6SAdrian Lang 1216dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1217dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1218dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 121979e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1220dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1221dd7a6159SGerrit Uitslag } 1222dd7a6159SGerrit Uitslag } 1223dd7a6159SGerrit Uitslag } 122417566ac6SAdrian Lang } 122517566ac6SAdrian Lang return $lang[$id]; 122617566ac6SAdrian Lang} 122717566ac6SAdrian Lang 12283df72098SAndreas Gohr/** 1229c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1230e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1231e8ec13b9SKlap-in * 1232e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1233e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1234e8ec13b9SKlap-in */ 1235e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1236c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1237e8ec13b9SKlap-in} 1238e8ec13b9SKlap-in 1239e8ec13b9SKlap-in/** 1240c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 124142ea7f44SGerrit Uitslag * 124242ea7f44SGerrit Uitslag * @param string $id id of localized text 124342ea7f44SGerrit Uitslag * @return string wiki text 1244e8ec13b9SKlap-in */ 1245c5c17fdaSKlap-infunction tpl_localeFN($id) { 1246e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1247e8ec13b9SKlap-in global $conf; 124838fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 124979e79377SAndreas Gohr if (!file_exists($file)){ 1250e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 125179e79377SAndreas Gohr if(!file_exists($file)){ 1252e8ec13b9SKlap-in //fall back to english 1253e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1254e8ec13b9SKlap-in } 1255e8ec13b9SKlap-in } 1256e8ec13b9SKlap-in return $file; 1257e8ec13b9SKlap-in} 1258e8ec13b9SKlap-in 1259e8ec13b9SKlap-in/** 12607abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 12613df72098SAndreas Gohr * 12623df72098SAndreas Gohr * Depending on the user's actions this may be a list of 12633df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 12643df72098SAndreas Gohr * a message of referencing pages 12653df72098SAndreas Gohr * 12663df72098SAndreas Gohr * Only allowed in mediamanager.php 12673df72098SAndreas Gohr * 1268c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1269c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 127042ea7f44SGerrit Uitslag * @param string $sort 12718702de7fSGerrit Uitslag * 12723df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 12733df72098SAndreas Gohr */ 127400e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 12753df72098SAndreas Gohr global $IMG; 12763df72098SAndreas Gohr global $AUTH; 12773df72098SAndreas Gohr global $INUSE; 12783df72098SAndreas Gohr global $NS; 12793df72098SAndreas Gohr global $JUMPTO; 1280585bf44eSChristopher Smith /** @var Input $INPUT */ 1281ac7a515fSAndreas Gohr global $INPUT; 12823df72098SAndreas Gohr 1283ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1284c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1285c182313eSAndreas Gohr 1286c182313eSAndreas Gohr if(!$do) { 1287ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1288c182313eSAndreas Gohr $do = 'metaform'; 1289c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1290c182313eSAndreas Gohr $do = 'filesinuse'; 1291c182313eSAndreas Gohr } else { 1292c182313eSAndreas Gohr $do = 'filelist'; 1293c182313eSAndreas Gohr } 1294c182313eSAndreas Gohr } 1295c182313eSAndreas Gohr 1296c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1297c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1298c182313eSAndreas Gohr $data = array('do' => $do); 1299c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1300c182313eSAndreas Gohr if($evt->advise_before()) { 1301c182313eSAndreas Gohr $do = $data['do']; 130230fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1303c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1304c182313eSAndreas Gohr } elseif($do == 'filelist') { 130500e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1306c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1307ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1308c182313eSAndreas Gohr } else { 1309c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1310c182313eSAndreas Gohr } 1311c182313eSAndreas Gohr } 1312c182313eSAndreas Gohr $evt->advise_after(); 1313c182313eSAndreas Gohr unset($evt); 1314c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1315c182313eSAndreas Gohr 13163df72098SAndreas Gohr} 13173df72098SAndreas Gohr 13183df72098SAndreas Gohr/** 1319d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1320d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1321d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1322d9162c6cSKate Arzamastseva * 1323d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1324d9162c6cSKate Arzamastseva */ 1325035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1326d9162c6cSKate Arzamastseva global $AUTH; 1327d9162c6cSKate Arzamastseva global $NS; 1328d9162c6cSKate Arzamastseva global $JUMPTO; 132995b451bcSAdrian Lang global $lang; 1330585bf44eSChristopher Smith /** @var Input $INPUT */ 1331ac7a515fSAndreas Gohr global $INPUT; 1332d9162c6cSKate Arzamastseva 1333ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1334e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1335ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1336d9162c6cSKate Arzamastseva 133794add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 133895b451bcSAdrian Lang 1339ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 134023846a98SKate Arzamastseva 134194add303SAnika Henke echo '<div class="panelHeader">'.NL; 134295b451bcSAdrian Lang echo '<h3>'; 1343026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1344c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 134594add303SAnika Henke echo '</h3>'.NL; 134695b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 134795b451bcSAdrian Lang media_tab_files_options(); 134823846a98SKate Arzamastseva } 134994add303SAnika Henke echo '</div>'.NL; 1350d9162c6cSKate Arzamastseva 135194add303SAnika Henke echo '<div class="panelContent">'.NL; 135295b451bcSAdrian Lang if($opened_tab == 'files') { 135395b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 135495b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 135595b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 135695b451bcSAdrian Lang } elseif($opened_tab == 'search') { 135795b451bcSAdrian Lang media_tab_search($NS, $AUTH); 135895b451bcSAdrian Lang } 135994add303SAnika Henke echo '</div>'.NL; 1360d9162c6cSKate Arzamastseva} 1361d9162c6cSKate Arzamastseva 1362d9162c6cSKate Arzamastseva/** 1363d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1364d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1365d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1366d9162c6cSKate Arzamastseva * list of file revisions 1367d9162c6cSKate Arzamastseva * 1368d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1369f50a239bSTakamura * 1370f50a239bSTakamura * @param string $image 1371f50a239bSTakamura * @param boolean $rev 1372d9162c6cSKate Arzamastseva */ 1373035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1374e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1375585bf44eSChristopher Smith /** @var Input $INPUT */ 1376585bf44eSChristopher Smith global $INPUT; 1377d9162c6cSKate Arzamastseva 137892cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1379ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 13806dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1381e8a2a143SMichael Hamann $ns = getNS($image); 1382ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 13831eeeced2SKate Arzamastseva 1384ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1385e5d185e1SKate Arzamastseva 1386e5d185e1SKate Arzamastseva $tab_array = array('view'); 1387ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1388e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1389e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1390e5d185e1SKate Arzamastseva } 1391e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1392e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1393e5d185e1SKate Arzamastseva } 1394e5d185e1SKate Arzamastseva 1395e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1396ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 139723846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1398d9162c6cSKate Arzamastseva 1399ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 140023846a98SKate Arzamastseva 140159f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1402ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 140395b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 140495b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 1405750a0b51SMichael Große $attributes = $rev ? ['rev' => $rev] : []; 1406750a0b51SMichael Große $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 140708317413SAdrian Lang if($opened_tab === 'view' && $rev) { 140808317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 140908317413SAdrian Lang } else { 1410026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 141108317413SAdrian Lang } 1412b8a84c03SAndreas Gohr 141394add303SAnika Henke echo '</h3></div>'.NL; 141495b451bcSAdrian Lang 141594add303SAnika Henke echo '<div class="panelContent">'.NL; 141695b451bcSAdrian Lang 141723846a98SKate Arzamastseva if($opened_tab == 'view') { 1418e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 141923846a98SKate Arzamastseva 142092cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1421e8a2a143SMichael Hamann media_tab_edit($image, $ns); 142223846a98SKate Arzamastseva 1423e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1424e8a2a143SMichael Hamann media_tab_history($image, $ns); 142523846a98SKate Arzamastseva } 142695b451bcSAdrian Lang 142794add303SAnika Henke echo '</div>'.NL; 1428d9162c6cSKate Arzamastseva} 1429d9162c6cSKate Arzamastseva 1430d9162c6cSKate Arzamastseva/** 14317abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 14323df72098SAndreas Gohr * 14333df72098SAndreas Gohr * Only allowed in mediamanager.php 14343df72098SAndreas Gohr * 14353df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14363df72098SAndreas Gohr */ 1437fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 14383df72098SAndreas Gohr global $NS; 143923846a98SKate Arzamastseva ptln('<div id="media__tree">'); 14403df72098SAndreas Gohr media_nstree($NS); 14413df72098SAndreas Gohr ptln('</div>'); 14423df72098SAndreas Gohr} 14433df72098SAndreas Gohr 1444a00de5b5SAndreas Gohr/** 1445a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1446a00de5b5SAndreas Gohr * 1447a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1448a00de5b5SAndreas Gohr * 1449a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 145042ea7f44SGerrit Uitslag * 145142ea7f44SGerrit Uitslag * @param string $empty empty option label 145242ea7f44SGerrit Uitslag * @param string $button submit button label 1453affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 1454a00de5b5SAndreas Gohr */ 1455a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1456affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 14571e875dcdSAndreas Gohr $menu = new \dokuwiki\Menu\MobileMenu(); 14581e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1459a00de5b5SAndreas Gohr} 1460a00de5b5SAndreas Gohr 1461066fee30SAndreas Gohr/** 1462066fee30SAndreas Gohr * Print a informational line about the used license 1463066fee30SAndreas Gohr * 1464066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1465ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1466ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1467ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1468ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1469ac7a515fSAndreas Gohr * @return string 1470066fee30SAndreas Gohr */ 147180083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1472066fee30SAndreas Gohr global $license; 1473066fee30SAndreas Gohr global $conf; 1474066fee30SAndreas Gohr global $lang; 1475066fee30SAndreas Gohr if(!$conf['license']) return ''; 1476066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1477066fee30SAndreas Gohr $lic = $license[$conf['license']]; 147853e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1479066fee30SAndreas Gohr 148080083a41SAndreas Gohr $out = ''; 148180083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1482066fee30SAndreas Gohr if($img) { 1483066fee30SAndreas Gohr $src = license_img($img); 1484066fee30SAndreas Gohr if($src) { 148553e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 148653e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 148753e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1488066fee30SAndreas Gohr } 1489066fee30SAndreas Gohr } 14904cefd216SMichael Klier if(!$imgonly) { 149153e15c8bSAnika Henke $out .= $lang['license'].' '; 1492d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1493d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 14944cefd216SMichael Klier } 149580083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1496066fee30SAndreas Gohr 1497066fee30SAndreas Gohr if($return) return $out; 1498066fee30SAndreas Gohr echo $out; 1499ac7a515fSAndreas Gohr return ''; 1500066fee30SAndreas Gohr} 1501066fee30SAndreas Gohr 1502a81910eeSAndreas Gohr/** 1503835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1504a81910eeSAndreas Gohr * 1505a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1506a81910eeSAndreas Gohr * template 1507e0c26282SGerrit Uitslag * 15087a112df5SAndreas Gohr * @param string $pageid The page name you want to include 15097a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 15107a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 15117c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1512e0c26282SGerrit Uitslag * @return bool|null|string 1513a81910eeSAndreas Gohr */ 15147c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { 15157a112df5SAndreas Gohr if($propagate) { 15167c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 15177c3e4a67SAndreas Gohr } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 15187a112df5SAndreas Gohr return false; 15197a112df5SAndreas Gohr } 1520c786a1b6SAnika Henke if(!$pageid) return false; 1521835dfcaeSAnika Henke 1522c786a1b6SAnika Henke global $TOC; 15239a2e250aSAndreas Gohr $oldtoc = $TOC; 1524a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 15259a2e250aSAndreas Gohr $TOC = $oldtoc; 1526a81910eeSAndreas Gohr 1527a2e03c82SAndreas Gohr if($print) echo $html; 1528e66d3e6dSAndreas Gohr return $html; 1529e66d3e6dSAndreas Gohr} 1530e66d3e6dSAndreas Gohr 1531e66d3e6dSAndreas Gohr/** 15325b75cd1fSAdrian Lang * Display the subscribe form 15335b75cd1fSAdrian Lang * 15345b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 15355b75cd1fSAdrian Lang */ 15365b75cd1fSAdrian Langfunction tpl_subscribe() { 15375b75cd1fSAdrian Lang global $INFO; 15385b75cd1fSAdrian Lang global $ID; 15395b75cd1fSAdrian Lang global $lang; 15406b8f02cfSAdrian Lang global $conf; 154140c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 15425b75cd1fSAdrian Lang 15435b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 15445b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 154515741132SAndreas Gohr echo '<div class="level2">'; 15465b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 15475b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 15485b75cd1fSAdrian Lang } else { 15495b75cd1fSAdrian Lang echo '<ul>'; 15505b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1551056c2049SAndreas Gohr echo '<li><div class="li">'; 15525b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1553056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 15545b75cd1fSAdrian Lang } else { 1555056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 15565b75cd1fSAdrian Lang } 155740c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 155815741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1559056c2049SAndreas Gohr echo ' ('.$sstl.') '; 156015741132SAndreas Gohr 1561ac7a515fSAndreas Gohr echo '<a href="'.wl( 1562ac7a515fSAndreas Gohr $ID, 1563ac7a515fSAndreas Gohr array( 1564ac7a515fSAndreas Gohr 'do' => 'subscribe', 156566d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 156666d2bed9SAdrian Lang 'sub_style' => $sub['style'], 156766d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1568ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1569ac7a515fSAndreas Gohr ) 1570ac7a515fSAndreas Gohr ). 157166d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 157266d2bed9SAdrian Lang '</a></div></li>'; 15735b75cd1fSAdrian Lang } 15745b75cd1fSAdrian Lang echo '</ul>'; 15755b75cd1fSAdrian Lang } 157615741132SAndreas Gohr echo '</div>'; 15775b75cd1fSAdrian Lang 157815741132SAndreas Gohr // Add new subscription form 15795b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 158015741132SAndreas Gohr echo '<div class="level2">'; 15815b75cd1fSAdrian Lang $ns = getNS($ID).':'; 158215741132SAndreas Gohr $targets = array( 158315741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 158415741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 158515741132SAndreas Gohr ); 158615741132SAndreas Gohr $styles = array( 158715741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 15886b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 15896b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 159015741132SAndreas Gohr ); 159115741132SAndreas Gohr 1592056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1593056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1594056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1595056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1596056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1597056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1598056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1599056c2049SAndreas Gohr $form->addHidden('id', $ID); 1600056c2049SAndreas Gohr $form->endFieldset(); 16015b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 16025b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 160315741132SAndreas Gohr echo '</div>'; 16045b75cd1fSAdrian Lang} 16055b75cd1fSAdrian Lang 1606d059ba9bSAndreas Gohr/** 1607d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1608d059ba9bSAndreas Gohr * 1609d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1610d059ba9bSAndreas Gohr * 1611d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1612d059ba9bSAndreas Gohr */ 1613d059ba9bSAndreas Gohrfunction tpl_flush() { 1614d059ba9bSAndreas Gohr ob_flush(); 1615d059ba9bSAndreas Gohr flush(); 1616d059ba9bSAndreas Gohr} 1617d059ba9bSAndreas Gohr 1618afca7e7eSAnika Henke/** 1619378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1620afca7e7eSAnika Henke * 1621378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1622378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1623378325f9SAndreas Gohr * 162442ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1625378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1626ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1627ac7a515fSAndreas Gohr * @return string 162842ea7f44SGerrit Uitslag * 1629378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1630afca7e7eSAnika Henke */ 1631378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1632ac7a515fSAndreas Gohr $img = ''; 1633ac7a515fSAndreas Gohr $file = ''; 1634ac7a515fSAndreas Gohr $ismedia = false; 1635378325f9SAndreas Gohr // loop through candidates until a match was found: 1636378325f9SAndreas Gohr foreach($search as $img) { 1637378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1638378325f9SAndreas Gohr $file = mediaFN($img); 1639378325f9SAndreas Gohr $ismedia = true; 1640378325f9SAndreas Gohr } else { 1641c4766956SAndreas Gohr $file = tpl_incdir().$img; 1642378325f9SAndreas Gohr $ismedia = false; 16431f13e33dSAnika Henke } 16440f747863Slupo49 1645378325f9SAndreas Gohr if(file_exists($file)) break; 1646872a6d29SAnika Henke } 1647378325f9SAndreas Gohr 1648378325f9SAndreas Gohr // fetch image data if requested 1649378325f9SAndreas Gohr if(!is_null($imginfo)) { 1650378325f9SAndreas Gohr $imginfo = getimagesize($file); 1651378325f9SAndreas Gohr } 1652378325f9SAndreas Gohr 1653378325f9SAndreas Gohr // build URL 1654378325f9SAndreas Gohr if($ismedia) { 1655378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1656378325f9SAndreas Gohr } else { 1657c4766956SAndreas Gohr $url = tpl_basedir().$img; 1658378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1659378325f9SAndreas Gohr } 1660378325f9SAndreas Gohr 1661378325f9SAndreas Gohr return $url; 1662a7e5f74cSlupo49} 16631f13e33dSAnika Henke 1664872a6d29SAnika Henke/** 1665e5d4768dSAndreas Gohr * PHP include a file 1666e5d4768dSAndreas Gohr * 1667e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1668e5d4768dSAndreas Gohr * file in the template's root directory. 1669e5d4768dSAndreas Gohr * 1670e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1671e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1672e5d4768dSAndreas Gohr * default. 1673e5d4768dSAndreas Gohr * 1674e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1675e5d4768dSAndreas Gohr * to this function! 1676e5d4768dSAndreas Gohr * 1677e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1678e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 167942ea7f44SGerrit Uitslag * 168042ea7f44SGerrit Uitslag * @param string $file 1681e5d4768dSAndreas Gohr */ 1682e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1683e5d4768dSAndreas Gohr global $config_cascade; 1684e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1685e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1686e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1687e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1688e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1689f3a1225fSAnika Henke include("$dir/$file"); 1690e5d4768dSAndreas Gohr return; 1691e5d4768dSAndreas Gohr } 1692e5d4768dSAndreas Gohr } 1693e5d4768dSAndreas Gohr } 1694e5d4768dSAndreas Gohr 1695e5d4768dSAndreas Gohr // still here? try the template dir 1696e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1697e5d4768dSAndreas Gohr if(file_exists($file)) { 1698f3a1225fSAnika Henke include($file); 1699e5d4768dSAndreas Gohr } 1700e5d4768dSAndreas Gohr} 1701e5d4768dSAndreas Gohr 1702e5d4768dSAndreas Gohr/** 1703872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1704872a6d29SAnika Henke * 1705872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 170642ea7f44SGerrit Uitslag * 1707ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1708ac7a515fSAndreas Gohr * @return string 1709872a6d29SAnika Henke */ 1710872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1711872a6d29SAnika Henke 1712872a6d29SAnika Henke $return = ''; 1713872a6d29SAnika Henke 1714872a6d29SAnika Henke foreach($types as $type) { 1715872a6d29SAnika Henke switch($type) { 1716872a6d29SAnika Henke case 'favicon': 1717378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1718378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1719872a6d29SAnika Henke break; 1720872a6d29SAnika Henke case 'mobile': 1721cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1722378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1723872a6d29SAnika Henke break; 1724872a6d29SAnika Henke case 'generic': 1725872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1726378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1727378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1728872a6d29SAnika Henke break; 1729872a6d29SAnika Henke } 1730872a6d29SAnika Henke } 1731872a6d29SAnika Henke 1732872a6d29SAnika Henke return $return; 1733afca7e7eSAnika Henke} 1734afca7e7eSAnika Henke 1735d9162c6cSKate Arzamastseva/** 1736d9162c6cSKate Arzamastseva * Prints full-screen media manager 1737d9162c6cSKate Arzamastseva * 1738d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1739d9162c6cSKate Arzamastseva */ 1740d9162c6cSKate Arzamastsevafunction tpl_media() { 1741ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 174288a71175SKate Arzamastseva $fullscreen = true; 174395b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1744d9162c6cSKate Arzamastseva 1745ac7a515fSAndreas Gohr $rev = ''; 1746ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 174798f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 174898f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 17499c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 175098f03b57SKate Arzamastseva 175194add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1752bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1753d9162c6cSKate Arzamastseva html_msgarea(); 175494add303SAnika Henke 175594add303SAnika Henke echo '<div class="panel namespaces">'.NL; 175694add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 175795b451bcSAdrian Lang echo '<div class="panelHeader">'; 1758ba340a70SAnika Henke echo $lang['media_namespaces']; 175994add303SAnika Henke echo '</div>'.NL; 176095b451bcSAdrian Lang 176194add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 176295b451bcSAdrian Lang media_nstree($NS); 176394add303SAnika Henke echo '</div>'.NL; 176494add303SAnika Henke echo '</div>'.NL; 1765fa8e5c77SKate Arzamastseva 176694add303SAnika Henke echo '<div class="panel filelist">'.NL; 1767035e07f1SKate Arzamastseva tpl_mediaFileList(); 176894add303SAnika Henke echo '</div>'.NL; 1769fa8e5c77SKate Arzamastseva 177094add303SAnika Henke echo '<div class="panel file">'.NL; 177194add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1772035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 177394add303SAnika Henke echo '</div>'.NL; 1774ba340a70SAnika Henke 177594add303SAnika Henke echo '</div>'.NL; 1776d9162c6cSKate Arzamastseva} 1777afca7e7eSAnika Henke 1778c71db656SAnika Henke/** 1779c71db656SAnika Henke * Return useful layout classes 1780c71db656SAnika Henke * 1781c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 178242ea7f44SGerrit Uitslag * 178342ea7f44SGerrit Uitslag * @return string 1784c71db656SAnika Henke */ 1785c71db656SAnika Henkefunction tpl_classes() { 1786c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1787585bf44eSChristopher Smith /** @var Input $INPUT */ 1788585bf44eSChristopher Smith global $INPUT; 1789585bf44eSChristopher Smith 1790c71db656SAnika Henke $classes = array( 1791c71db656SAnika Henke 'dokuwiki', 1792c71db656SAnika Henke 'mode_'.$ACT, 1793c71db656SAnika Henke 'tpl_'.$conf['template'], 1794585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 179539f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 1796c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1797c71db656SAnika Henke ); 1798c71db656SAnika Henke return join(' ', $classes); 1799c71db656SAnika Henke} 1800c71db656SAnika Henke 180184dd2b1aSGerrit Uitslag/** 180284dd2b1aSGerrit Uitslag * Create event for tools menues 180384dd2b1aSGerrit Uitslag * 180484dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 180584dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 180684dd2b1aSGerrit Uitslag * @param array $items 180784dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 1808affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 180984dd2b1aSGerrit Uitslag */ 181084dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') { 1811affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 181284dd2b1aSGerrit Uitslag $data = array( 181384dd2b1aSGerrit Uitslag 'view' => $view, 181484dd2b1aSGerrit Uitslag 'items' => $items 181584dd2b1aSGerrit Uitslag ); 181684dd2b1aSGerrit Uitslag 181784dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 181884dd2b1aSGerrit Uitslag $evt = new Doku_Event($hook, $data); 181984dd2b1aSGerrit Uitslag if($evt->advise_before()) { 182084dd2b1aSGerrit Uitslag foreach($evt->data['items'] as $k => $html) echo $html; 182184dd2b1aSGerrit Uitslag } 182284dd2b1aSGerrit Uitslag $evt->advise_after(); 182384dd2b1aSGerrit Uitslag} 182484dd2b1aSGerrit Uitslag 1825e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1826a00de5b5SAndreas Gohr 1827