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 245f96fa415SAndreas Gohr if($alt) { 24654be1338SGerrit Uitslag if(actionOK('rss')) { 247ac7a515fSAndreas Gohr $head['link'][] = array( 248ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 249a1288caeSGerrit Uitslag 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php' 250ac7a515fSAndreas Gohr ); 251ac7a515fSAndreas Gohr $head['link'][] = array( 252ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 253a1288caeSGerrit Uitslag 'title'=> $lang['currentns'], 254ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] 255ac7a515fSAndreas Gohr ); 25654be1338SGerrit Uitslag } 257c35f3875SAndreas Gohr if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 258ac7a515fSAndreas Gohr $head['link'][] = array( 259ac7a515fSAndreas Gohr 'rel' => 'edit', 260715bdf1fSAndreas Gohr 'title'=> $lang['btn_edit'], 261ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 262ac7a515fSAndreas Gohr ); 263c35f3875SAndreas Gohr } 264c35f3875SAndreas Gohr 26554be1338SGerrit Uitslag if(actionOK('rss') && $ACT == 'search') { 266ac7a515fSAndreas Gohr $head['link'][] = array( 267ac7a515fSAndreas Gohr 'rel' => 'alternate', 'type'=> 'application/rss+xml', 268a1288caeSGerrit Uitslag 'title'=> $lang['searchresult'], 269ac7a515fSAndreas Gohr 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY 270ac7a515fSAndreas Gohr ); 2714bb1b5aeSAndreas Gohr } 272bae36d94SAndreas Gohr 273bae36d94SAndreas Gohr if(actionOK('export_xhtml')) { 274ac7a515fSAndreas Gohr $head['link'][] = array( 275a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'], 276ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'xhtml', '', false, '&') 277ac7a515fSAndreas Gohr ); 278bae36d94SAndreas Gohr } 279bae36d94SAndreas Gohr 280bae36d94SAndreas Gohr if(actionOK('export_raw')) { 281ac7a515fSAndreas Gohr $head['link'][] = array( 282a1288caeSGerrit Uitslag 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'], 283ac7a515fSAndreas Gohr 'href'=> exportlink($ID, 'raw', '', false, '&') 284ac7a515fSAndreas Gohr ); 285f96fa415SAndreas Gohr } 286bae36d94SAndreas Gohr } 2876b13307fSandi 2886b13307fSandi // setup robot tags apropriate for different modes 2894f2e0004STim Weber if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 2906b13307fSandi if($INFO['exists']) { 2916b13307fSandi //delay indexing: 292fb9fa88bSAndreas Gohr if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) { 2937bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 2946b13307fSandi } else { 2957bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 2966b13307fSandi } 29701f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 29801f9be51SAnika Henke if ($ID == $conf['start']) { 29901f9be51SAnika Henke $canonicalUrl = DOKU_URL; 30001f9be51SAnika Henke } 30101f9be51SAnika Henke $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl); 3026b13307fSandi } else { 3037bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); 3046b13307fSandi } 3057a24876fSAndreas Gohr } elseif(defined('DOKU_MEDIADETAIL')) { 3067bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); 3076b13307fSandi } else { 3087bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); 3096b13307fSandi } 3106b13307fSandi 311831800b8SAndreas Gohr // set metadata 312831800b8SAndreas Gohr if($ACT == 'show' || $ACT == 'export_xhtml') { 313831800b8SAndreas Gohr // keywords (explicit or implicit) 314bb4866bdSchris if(!empty($INFO['meta']['subject'])) { 3157bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); 316831800b8SAndreas Gohr } else { 3177bff22c0SAndreas Gohr $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); 318831800b8SAndreas Gohr } 319831800b8SAndreas Gohr } 320831800b8SAndreas Gohr 32178a6aeb1SAndreas Gohr // load stylesheets 322ac7a515fSAndreas Gohr $head['link'][] = array( 323ac7a515fSAndreas Gohr 'rel' => 'stylesheet', 'type'=> 'text/css', 324e283bd6cSAnika Henke 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed 325ac7a515fSAndreas Gohr ); 326bad31ae9SAndreas Gohr 3278bbcb611SAndreas Gohr // make $INFO and other vars available to JavaScripts 328463d4a65SAndreas Gohr $json = new JSON(); 32972e0dc37SAndreas Gohr $script = "var NS='".$INFO['namespace']."';"; 330585bf44eSChristopher Smith if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 33172e0dc37SAndreas Gohr $script .= "var SIG='".toolbar_signature()."';"; 332c591aabeSAndreas Gohr } 333*10cf78c4SMichael Große _tpl_ensureJSINFO(); 33472e0dc37SAndreas Gohr $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; 33585f81679SAdrian Lang $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); 3368bbcb611SAndreas Gohr 33761537d47SAndreas Gohr // load jquery 338fa078663SAndreas Gohr $jquery = getCdnUrls(); 339fa078663SAndreas Gohr foreach($jquery as $src) { 34061537d47SAndreas Gohr $head['script'][] = array( 341fa078663SAndreas Gohr 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src 34261537d47SAndreas Gohr ); 34361537d47SAndreas Gohr } 34461537d47SAndreas Gohr 34561537d47SAndreas Gohr // load our javascript dispatcher 346ac7a515fSAndreas Gohr $head['script'][] = array( 347ac7a515fSAndreas Gohr 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', 348e283bd6cSAnika Henke 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed 349ac7a515fSAndreas Gohr ); 3507bff22c0SAndreas Gohr 3517bff22c0SAndreas Gohr // trigger event here 352016b6153SAndreas Gohr trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 35354e95700STom N Harris return true; 3547bff22c0SAndreas Gohr} 3557bff22c0SAndreas Gohr 356*10cf78c4SMichael Großefunction _tpl_ensureJSINFO() { 357*10cf78c4SMichael Große global $JSINFO, $ID, $INFO; 358*10cf78c4SMichael Große 359*10cf78c4SMichael Große if (!is_array($JSINFO)) { 360*10cf78c4SMichael Große $JSINFO = []; 361*10cf78c4SMichael Große } 362*10cf78c4SMichael Große //export minimal info to JS, plugins can add more 363*10cf78c4SMichael Große $JSINFO['id'] = $ID; 364*10cf78c4SMichael Große $JSINFO['namespace'] = (string) $INFO['namespace']; 365*10cf78c4SMichael Große $JSINFO['ACT'] = act_clean($ACT); 366*10cf78c4SMichael Große $JSINFO['DOKU_UHN'] = (int) useHeading('navigation'); 367*10cf78c4SMichael Große $JSINFO['DOKU_UHC'] = (int) useHeading('content'); 368*10cf78c4SMichael Große} 369*10cf78c4SMichael Große 3707bff22c0SAndreas Gohr/** 3717bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 3727bff22c0SAndreas Gohr * 3737bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 3747bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 3757bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 3767bff22c0SAndreas Gohr * 37742ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 3781304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 3797bff22c0SAndreas Gohr * 3807bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 38142ea7f44SGerrit Uitslag * 38242ea7f44SGerrit Uitslag * @param array $data 3837bff22c0SAndreas Gohr */ 3847bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) { 3857bff22c0SAndreas Gohr foreach($data as $tag => $inst) { 386427bf9a2SAndreas Gohr if($tag == 'script') { 387427bf9a2SAndreas Gohr echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE 388427bf9a2SAndreas Gohr } 3897bff22c0SAndreas Gohr foreach($inst as $attr) { 3909b48e6a1SGerry Weißbach if ( empty($attr) ) { continue; } 3917bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 39226afa874SMikhail I. Izmestev if(isset($attr['_data']) || $tag == 'script') { 393e226efe1SAndreas Gohr if($tag == 'script' && $attr['_data']) 39409f791c4SDominik Eckelmann $attr['_data'] = "/*<![CDATA[*/". 395e226efe1SAndreas Gohr $attr['_data']. 39609f791c4SDominik Eckelmann "\n/*!]]>*/"; 397e226efe1SAndreas Gohr 3981304d1dbSAndreas Gohr echo '>', $attr['_data'], '</', $tag, '>'; 3997bff22c0SAndreas Gohr } else { 4007bff22c0SAndreas Gohr echo '/>'; 4017bff22c0SAndreas Gohr } 4027bff22c0SAndreas Gohr echo "\n"; 4037bff22c0SAndreas Gohr } 404427bf9a2SAndreas Gohr if($tag == 'script') { 405427bf9a2SAndreas Gohr echo "<!--<![endif]-->\n"; 406427bf9a2SAndreas Gohr } 4077bff22c0SAndreas Gohr } 4086b13307fSandi} 4096b13307fSandi 4106b13307fSandi/** 4116b13307fSandi * Print a link 4126b13307fSandi * 4135e163278SAndreas Gohr * Just builds a link. 4146b13307fSandi * 4156b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 41642ea7f44SGerrit Uitslag * 41742ea7f44SGerrit Uitslag * @param string $url 41842ea7f44SGerrit Uitslag * @param string $name 41942ea7f44SGerrit Uitslag * @param string $more 42021d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 42121d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4226b13307fSandi */ 4231af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) { 42401f17825SAnika Henke $out = '<a href="'.$url.'" '; 4251af98a77SAnika Henke if($more) $out .= ' '.$more; 4261af98a77SAnika Henke $out .= ">$name</a>"; 4271af98a77SAnika Henke if($return) return $out; 4281af98a77SAnika Henke print $out; 42954e95700STom N Harris return true; 4306b13307fSandi} 4316b13307fSandi 4326b13307fSandi/** 43355efc227SAndreas Gohr * Prints a link to a WikiPage 43455efc227SAndreas Gohr * 43555efc227SAndreas Gohr * Wrapper around html_wikilink 43655efc227SAndreas Gohr * 43755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 43842ea7f44SGerrit Uitslag * 43942ea7f44SGerrit Uitslag * @param string $id page id 44042ea7f44SGerrit Uitslag * @param string|null $name the name of the link 44121d806cdSGerrit Uitslag * @return bool true 44255efc227SAndreas Gohr */ 4430b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) { 444d317fb5dSAnika Henke print '<bdi>'.html_wikilink($id, $name).'</bdi>'; 44554e95700STom N Harris return true; 44655efc227SAndreas Gohr} 44755efc227SAndreas Gohr 44855efc227SAndreas Gohr/** 449a3ec5f4aSmatthiasgrimm * get the parent page 450a3ec5f4aSmatthiasgrimm * 451a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 452a3ec5f4aSmatthiasgrimm * returns false if none is available 453a3ec5f4aSmatthiasgrimm * 454377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 45542ea7f44SGerrit Uitslag * 45642ea7f44SGerrit Uitslag * @param string $id page id 45742ea7f44SGerrit Uitslag * @return false|string 458a3ec5f4aSmatthiasgrimm */ 459377f9e97SAndreas Gohrfunction tpl_getparent($id) { 460377f9e97SAndreas Gohr $parent = getNS($id).':'; 461377f9e97SAndreas Gohr resolve_pageid('', $parent, $exists); 462a197105eSmatthiasgrimm if($parent == $id) { 463a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 464a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos).':'; 465a197105eSmatthiasgrimm resolve_pageid('', $parent, $exists); 466377f9e97SAndreas Gohr if($parent == $id) return false; 467a197105eSmatthiasgrimm } 468377f9e97SAndreas Gohr return $parent; 469a3ec5f4aSmatthiasgrimm} 470a3ec5f4aSmatthiasgrimm 471a3ec5f4aSmatthiasgrimm/** 4726b13307fSandi * Print one of the buttons 4736b13307fSandi * 474a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 475a453d131SAdrian Lang * @see tpl_get_action 476e0c26282SGerrit Uitslag * 477e0c26282SGerrit Uitslag * @param string $type 478e0c26282SGerrit Uitslag * @param bool $return 479e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 480affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 4816b13307fSandi */ 4821af98a77SAnika Henkefunction tpl_button($type, $return = false) { 483affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 484a453d131SAdrian Lang $data = tpl_get_action($type); 485a453d131SAdrian Lang if($data === false) { 486a453d131SAdrian Lang return false; 487a453d131SAdrian Lang } elseif(!is_array($data)) { 488a453d131SAdrian Lang $out = sprintf($data, 'button'); 489409d7af7SAndreas Gohr } else { 490ac7a515fSAndreas Gohr /** 491ac7a515fSAndreas Gohr * @var string $accesskey 492ac7a515fSAndreas Gohr * @var string $id 493ac7a515fSAndreas Gohr * @var string $method 494ac7a515fSAndreas Gohr * @var array $params 495ac7a515fSAndreas Gohr */ 496a453d131SAdrian Lang extract($data); 497a453d131SAdrian Lang if($id === '#dokuwiki__top') { 498a453d131SAdrian Lang $out = html_topbtn(); 499409d7af7SAndreas Gohr } else { 500a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 501409d7af7SAndreas Gohr } 502409d7af7SAndreas Gohr } 5031af98a77SAnika Henke if($return) return $out; 504a453d131SAdrian Lang echo $out; 505a453d131SAdrian Lang return true; 5066b13307fSandi} 5076b13307fSandi 5086b13307fSandi/** 509ed630903Sandi * Like the action buttons but links 510ed630903Sandi * 511a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 512a453d131SAdrian Lang * @see tpl_get_action 513e0c26282SGerrit Uitslag * 51442ea7f44SGerrit Uitslag * @param string $type action command 515e0c26282SGerrit Uitslag * @param string $pre prefix of link 516e0c26282SGerrit Uitslag * @param string $suf suffix of link 517e0c26282SGerrit Uitslag * @param string $inner innerHML of link 51821d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 519e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 520affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 521a453d131SAdrian Lang */ 522a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { 523affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 524a453d131SAdrian Lang global $lang; 525a453d131SAdrian Lang $data = tpl_get_action($type); 526a453d131SAdrian Lang if($data === false) { 527a453d131SAdrian Lang return false; 528a453d131SAdrian Lang } elseif(!is_array($data)) { 529a453d131SAdrian Lang $out = sprintf($data, 'link'); 530a453d131SAdrian Lang } else { 531ac7a515fSAndreas Gohr /** 532ac7a515fSAndreas Gohr * @var string $accesskey 533ac7a515fSAndreas Gohr * @var string $id 534ac7a515fSAndreas Gohr * @var string $method 535b1af9014SChristopher Smith * @var bool $nofollow 536ac7a515fSAndreas Gohr * @var array $params 537becfa414SGerrit Uitslag * @var string $replacement 538ac7a515fSAndreas Gohr */ 539a453d131SAdrian Lang extract($data); 540a453d131SAdrian Lang if(strpos($id, '#') === 0) { 541a453d131SAdrian Lang $linktarget = $id; 542a453d131SAdrian Lang } else { 543a453d131SAdrian Lang $linktarget = wl($id, $params); 544a453d131SAdrian Lang } 545a453d131SAdrian Lang $caption = $lang['btn_'.$type]; 546becfa414SGerrit Uitslag if(strpos($caption, '%s')){ 547becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 548becfa414SGerrit Uitslag } 549c7e90e3fSAnika Henke $akey = $addTitle = ''; 550c7e90e3fSAnika Henke if($accesskey) { 551c7e90e3fSAnika Henke $akey = 'accesskey="'.$accesskey.'" '; 552c7e90e3fSAnika Henke $addTitle = ' ['.strtoupper($accesskey).']'; 553c7e90e3fSAnika Henke } 554b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 555ac7a515fSAndreas Gohr $out = tpl_link( 556ac7a515fSAndreas Gohr $linktarget, $pre.(($inner) ? $inner : $caption).$suf, 557a453d131SAdrian Lang 'class="action '.$type.'" '. 558b1af9014SChristopher Smith $akey.$rel. 559e0c26282SGerrit Uitslag 'title="'.hsc($caption).$addTitle.'"', true 560ac7a515fSAndreas Gohr ); 561a453d131SAdrian Lang } 562a453d131SAdrian Lang if($return) return $out; 563a453d131SAdrian Lang echo $out; 564a453d131SAdrian Lang return true; 565a453d131SAdrian Lang} 566a453d131SAdrian Lang 567a453d131SAdrian Lang/** 568a453d131SAdrian Lang * Check the actions and get data for buttons and links 569ed630903Sandi * 570ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org> 571a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 572a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de> 573e0c26282SGerrit Uitslag * 574ac7a515fSAndreas Gohr * @param string $type 575ac7a515fSAndreas Gohr * @return array|bool|string 576affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 577ed630903Sandi */ 578a453d131SAdrian Langfunction tpl_get_action($type) { 579affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 580a453d131SAdrian Lang if($type == 'history') $type = 'revisions'; 5814c4b65c8SMichael Hamann if($type == 'subscription') $type = 'subscribe'; 5824887c154SAndreas Gohr if($type == 'img_backto') $type = 'imgBackto'; 583409d7af7SAndreas Gohr 5844887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 5854887c154SAndreas Gohr if(class_exists($class)) { 5864887c154SAndreas Gohr try { 5874887c154SAndreas Gohr /** @var \dokuwiki\Menu\Item\AbstractItem $item */ 5884887c154SAndreas Gohr $item = new $class; 5894887c154SAndreas Gohr $data = $item->getLegacyData(); 5907b4365a7SGerrit Uitslag $unknown = false; 5914887c154SAndreas Gohr } catch(\RuntimeException $ignored) { 5924887c154SAndreas Gohr return false; 593b8a111f5SMichael Klier } 594ed630903Sandi } else { 5954887c154SAndreas Gohr global $ID; 5964887c154SAndreas Gohr $data = array( 5974887c154SAndreas Gohr 'accesskey' => null, 5984887c154SAndreas Gohr 'type' => $type, 5994887c154SAndreas Gohr 'id' => $ID, 6004887c154SAndreas Gohr 'method' => 'get', 6014887c154SAndreas Gohr 'params' => array('do' => $type), 6024887c154SAndreas Gohr 'nofollow' => true, 6034887c154SAndreas Gohr 'replacement' => '', 604becfa414SGerrit Uitslag ); 6057b4365a7SGerrit Uitslag $unknown = true; 606ed630903Sandi } 6077b4365a7SGerrit Uitslag 6083131073dSGerrit Uitslag $evt = new Doku_Event('TPL_ACTION_GET', $data); 6097b4365a7SGerrit Uitslag if($evt->advise_before()) { 6107b4365a7SGerrit Uitslag //handle unknown types 6117b4365a7SGerrit Uitslag if($unknown) { 61238d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6137b4365a7SGerrit Uitslag } 6147b4365a7SGerrit Uitslag } 6157b4365a7SGerrit Uitslag $evt->advise_after(); 6167b4365a7SGerrit Uitslag unset($evt); 6177b4365a7SGerrit Uitslag 6187b4365a7SGerrit Uitslag return $data; 619ed630903Sandi} 620ed630903Sandi 621ed630903Sandi/** 62201f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 62301f17825SAnika Henke * 62401f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org> 62542ea7f44SGerrit Uitslag * 62642ea7f44SGerrit Uitslag * @param string $type action command 627ac7a515fSAndreas Gohr * @param bool $link link or form button? 628e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 629ac7a515fSAndreas Gohr * @param bool $return return or print 630ac7a515fSAndreas Gohr * @param string $pre prefix for links 631ac7a515fSAndreas Gohr * @param string $suf suffix for links 632ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 633ac7a515fSAndreas Gohr * @return bool|string 634affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 63501f17825SAnika Henke */ 636ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { 637affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 63801f17825SAnika Henke $out = ''; 639ac7a515fSAndreas Gohr if($link) { 640e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 641ac7a515fSAndreas Gohr } else { 642e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 643ac7a515fSAndreas Gohr } 64401f17825SAnika Henke if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 64501f17825SAnika Henke 64601f17825SAnika Henke if($return) return $out; 64701f17825SAnika Henke print $out; 64801f17825SAnika Henke return $out ? true : false; 64901f17825SAnika Henke} 65001f17825SAnika Henke 65101f17825SAnika Henke/** 6526b13307fSandi * Print the search form 6536b13307fSandi * 65472645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 65572645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 65672645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 65772645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 65872645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 65972645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 66072645b75SAndreas Gohr * 6616b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 66242ea7f44SGerrit Uitslag * 663ac7a515fSAndreas Gohr * @param bool $ajax 664ac7a515fSAndreas Gohr * @param bool $autocomplete 665ac7a515fSAndreas Gohr * @return bool 6666b13307fSandi */ 66772645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) { 6686b13307fSandi global $lang; 669c1e3b7d9Smatthiasgrimm global $ACT; 670ad4aaef7SAndreas Gohr global $QUERY; 671c1e3b7d9Smatthiasgrimm 672670ff54eSchris // don't print the search form if search action has been disabled 67364276bbcSarbrk1 if(!actionOK('search')) return false; 674670ff54eSchris 6759805efa0SAnika Henke print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">'; 6766b13307fSandi print '<input type="hidden" name="do" value="search" />'; 677c1e3b7d9Smatthiasgrimm print '<input type="text" '; 678ad4aaef7SAndreas Gohr if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; 679001ea14eSRainbow Spike print 'placeholder="'.$lang['btn_search'].'" '; 68072645b75SAndreas Gohr if(!$autocomplete) print 'autocomplete="off" '; 68107493d05SAnika Henke print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; 682ae614416SAnika Henke print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>'; 68324a33b42SAndreas Gohr if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; 6844beabca9SAnika Henke print '</div></form>'; 68554e95700STom N Harris return true; 6866b13307fSandi} 6876b13307fSandi 6886b13307fSandi/** 6896b13307fSandi * Print the breadcrumbs trace 6906b13307fSandi * 6916b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 69242ea7f44SGerrit Uitslag * 693ac7a515fSAndreas Gohr * @param string $sep Separator between entries 694ac7a515fSAndreas Gohr * @return bool 6956b13307fSandi */ 696e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') { 6976b13307fSandi global $lang; 6986b13307fSandi global $conf; 6996b13307fSandi 7006b13307fSandi //check if enabled 701359fab8bSMichael Hamann if(!$conf['breadcrumbs']) return false; 7026b13307fSandi 7036b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 704265e3787Sandi 7052979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; 706265e3787Sandi 70740eb54bbSjan //render crumbs, highlight the last one 708fde860beSGerrit Uitslag print '<span class="bchead">'.$lang['breadcrumb'].'</span>'; 70940eb54bbSjan $last = count($crumbs); 71040eb54bbSjan $i = 0; 711a77f5846Sjan foreach($crumbs as $id => $name) { 71240eb54bbSjan $i++; 7132979a10bSKatriel Traum echo $crumbs_sep; 71492795d04Sandi if($i == $last) print '<span class="curid">'; 715d317fb5dSAnika Henke print '<bdi>'; 716e26fd1eeSAndreas Gohr tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"'); 717d317fb5dSAnika Henke print '</bdi>'; 71892795d04Sandi if($i == $last) print '</span>'; 7196b13307fSandi } 72054e95700STom N Harris return true; 7216b13307fSandi} 7226b13307fSandi 7236b13307fSandi/** 7241734437eSandi * Hierarchical breadcrumbs 7251734437eSandi * 72631e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 7271734437eSandi * It only makes sense with a deep site structure. 7281734437eSandi * 7291734437eSandi * @author Andreas Gohr <andi@splitbrain.org> 7306bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com> 73131e187f8SSean Coates * @author Sean Coates <sean@caedmon.net> 732f46c9e83SAnika Henke * @author <fredrik@averpil.com> 73308d7a575SAndreas Gohr * @todo May behave strangely in RTL languages 73442ea7f44SGerrit Uitslag * 735ac7a515fSAndreas Gohr * @param string $sep Separator between entries 736ac7a515fSAndreas Gohr * @return bool 7371734437eSandi */ 73808d7a575SAndreas Gohrfunction tpl_youarehere($sep = ' » ') { 7391734437eSandi global $conf; 7401734437eSandi global $ID; 7411734437eSandi global $lang; 7421734437eSandi 74331e187f8SSean Coates // check if enabled 74454e95700STom N Harris if(!$conf['youarehere']) return false; 7451734437eSandi 7461734437eSandi $parts = explode(':', $ID); 747796bafb3SAndreas Gohr $count = count($parts); 7481734437eSandi 74908d7a575SAndreas Gohr echo '<span class="bchead">'.$lang['youarehere'].' </span>'; 7503940c519SMark 75108d7a575SAndreas Gohr // always print the startpage 75208d7a575SAndreas Gohr echo '<span class="home">'; 75308d7a575SAndreas Gohr tpl_pagelink(':'.$conf['start']); 75408d7a575SAndreas Gohr echo '</span>'; 755796bafb3SAndreas Gohr 756796bafb3SAndreas Gohr // print intermediate namespace links 757796bafb3SAndreas Gohr $part = ''; 758796bafb3SAndreas Gohr for($i = 0; $i < $count - 1; $i++) { 759796bafb3SAndreas Gohr $part .= $parts[$i].':'; 760796bafb3SAndreas Gohr $page = $part; 761796bafb3SAndreas Gohr if($page == $conf['start']) continue; // Skip startpage 762796bafb3SAndreas Gohr 76308d7a575SAndreas Gohr // output 76408d7a575SAndreas Gohr echo $sep; 76508d7a575SAndreas Gohr tpl_pagelink($page); 76631e187f8SSean Coates } 7671734437eSandi 768796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 769e013f48dSAnika Henke resolve_pageid('', $page, $exists); 77008d7a575SAndreas Gohr if(isset($page) && $page == $part.$parts[$i]) return true; 771796bafb3SAndreas Gohr $page = $part.$parts[$i]; 77208d7a575SAndreas Gohr if($page == $conf['start']) return true; 77308d7a575SAndreas Gohr echo $sep; 77408d7a575SAndreas Gohr tpl_pagelink($page); 77554e95700STom N Harris return true; 7761734437eSandi} 7771734437eSandi 7781734437eSandi/** 7796b13307fSandi * Print info if the user is logged in 780a2488c3cSMatthias Grimm * and show full name in that case 7816b13307fSandi * 7826b13307fSandi * Could be enhanced with a profile link in future? 7836b13307fSandi * 7846b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 78542ea7f44SGerrit Uitslag * 786ac7a515fSAndreas Gohr * @return bool 7876b13307fSandi */ 7886b13307fSandifunction tpl_userinfo() { 7896b13307fSandi global $lang; 790585bf44eSChristopher Smith /** @var Input $INPUT */ 791585bf44eSChristopher Smith global $INPUT; 792585bf44eSChristopher Smith 793585bf44eSChristopher Smith if($INPUT->server->str('REMOTE_USER')) { 794fde860beSGerrit Uitslag print $lang['loggedinas'].' '.userlink(); 79554e95700STom N Harris return true; 79654e95700STom N Harris } 79754e95700STom N Harris return false; 7986b13307fSandi} 7996b13307fSandi 8006b13307fSandi/** 8016b13307fSandi * Print some info about the current page 8026b13307fSandi * 8036b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 80442ea7f44SGerrit Uitslag * 805ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 806ac7a515fSAndreas Gohr * @return bool|string 8076b13307fSandi */ 8084b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) { 8096b13307fSandi global $conf; 8106b13307fSandi global $lang; 8116b13307fSandi global $INFO; 812c6e92a3cSDavid Lorentsen global $ID; 813c6e92a3cSDavid Lorentsen 814c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 815ac7a515fSAndreas Gohr if(!auth_quickaclcheck($ID)) { 816ac7a515fSAndreas Gohr return false; 817ac7a515fSAndreas Gohr } 8186b13307fSandi 8196b13307fSandi // prepare date and path 8206b13307fSandi $fn = $INFO['filepath']; 8216b13307fSandi if(!$conf['fullpath']) { 822613bca54SAndreas Gohr if($INFO['rev']) { 823c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'].'/', '', $fn); 8246b13307fSandi } else { 825c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'].'/', '', $fn); 8266b13307fSandi } 8276b13307fSandi } 828bee6dc82Sandi $fn = utf8_decodeFN($fn); 829f2263577SAndreas Gohr $date = dformat($INFO['lastmod']); 8306b13307fSandi 831faecdfdfSAndreas Gohr // print it 832faecdfdfSAndreas Gohr if($INFO['exists']) { 8334b0d3916SAndreas Gohr $out = ''; 834d317fb5dSAnika Henke $out .= '<bdi>'.$fn.'</bdi>'; 835e260f93bSAnika Henke $out .= ' · '; 8364b0d3916SAndreas Gohr $out .= $lang['lastmod']; 837fde860beSGerrit Uitslag $out .= ' '; 8384b0d3916SAndreas Gohr $out .= $date; 8396b13307fSandi if($INFO['editor']) { 8404b0d3916SAndreas Gohr $out .= ' '.$lang['by'].' '; 841d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>'; 8425aa52fafSBen Coburn } else { 8434b0d3916SAndreas Gohr $out .= ' ('.$lang['external_edit'].')'; 8446b13307fSandi } 8456b13307fSandi if($INFO['locked']) { 846e260f93bSAnika Henke $out .= ' · '; 8474b0d3916SAndreas Gohr $out .= $lang['lockedby']; 848fde860beSGerrit Uitslag $out .= ' '; 849d317fb5dSAnika Henke $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>'; 8506b13307fSandi } 8514b0d3916SAndreas Gohr if($ret) { 8524b0d3916SAndreas Gohr return $out; 8534b0d3916SAndreas Gohr } else { 8544b0d3916SAndreas Gohr echo $out; 85554e95700STom N Harris return true; 8566b13307fSandi } 8574b0d3916SAndreas Gohr } 85854e95700STom N Harris return false; 8596b13307fSandi} 8606b13307fSandi 861820fa24bSandi/** 862a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 86387c434ceSAndreas Gohr * 86487c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 865a6598f23SBen Coburn * the given ID is used. 86687c434ceSAndreas Gohr * 86787c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 86842ea7f44SGerrit Uitslag * 869ac7a515fSAndreas Gohr * @param string $id page id 870ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 871ac7a515fSAndreas Gohr * @return bool|string 87287c434ceSAndreas Gohr */ 873a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) { 874c248bda1SChristopher Smith global $ACT, $INPUT, $conf, $lang; 875fffeeafeSChristopher Smith 87687c434ceSAndreas Gohr if(is_null($id)) { 87787c434ceSAndreas Gohr global $ID; 87887c434ceSAndreas Gohr $id = $ID; 87987c434ceSAndreas Gohr } 88087c434ceSAndreas Gohr 88187c434ceSAndreas Gohr $name = $id; 882fe9ec250SChris Smith if(useHeading('navigation')) { 883fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 884fffeeafeSChristopher Smith if($first_heading) $name = $first_heading; 885fffeeafeSChristopher Smith } 886fffeeafeSChristopher Smith 887fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 888fffeeafeSChristopher Smith switch ($ACT) { 889fffeeafeSChristopher Smith // admin functions 890fffeeafeSChristopher Smith case 'admin' : 891fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 892fffeeafeSChristopher Smith // try to get the plugin name 893a61966c5SChristopher Smith /** @var $plugin DokuWiki_Admin_Plugin */ 894a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()){ 895c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 896a61966c5SChristopher Smith $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); 897fffeeafeSChristopher Smith } 898fffeeafeSChristopher Smith break; 899fffeeafeSChristopher Smith 900fffeeafeSChristopher Smith // user functions 901fffeeafeSChristopher Smith case 'login' : 902fffeeafeSChristopher Smith case 'profile' : 903fffeeafeSChristopher Smith case 'register' : 904fffeeafeSChristopher Smith case 'resendpwd' : 905fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 906fffeeafeSChristopher Smith break; 907fffeeafeSChristopher Smith 908fffeeafeSChristopher Smith // wiki functions 909fffeeafeSChristopher Smith case 'search' : 910fffeeafeSChristopher Smith case 'index' : 911fffeeafeSChristopher Smith $page_title = $lang['btn_'.$ACT]; 912fffeeafeSChristopher Smith break; 913fffeeafeSChristopher Smith 914fffeeafeSChristopher Smith // page functions 915fffeeafeSChristopher Smith case 'edit' : 916fffeeafeSChristopher Smith $page_title = "✎ ".$name; 917fffeeafeSChristopher Smith break; 918fffeeafeSChristopher Smith 919fffeeafeSChristopher Smith case 'revisions' : 920fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 921fffeeafeSChristopher Smith break; 922fffeeafeSChristopher Smith 923fffeeafeSChristopher Smith case 'backlink' : 924fffeeafeSChristopher Smith case 'recent' : 925fffeeafeSChristopher Smith case 'subscribe' : 926fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_'.$ACT]; 927fffeeafeSChristopher Smith break; 928fffeeafeSChristopher Smith 929fffeeafeSChristopher Smith default : // SHOW and anything else not included 930fffeeafeSChristopher Smith $page_title = $name; 93187c434ceSAndreas Gohr } 932a6598f23SBen Coburn 933a6598f23SBen Coburn if($ret) { 934fffeeafeSChristopher Smith return hsc($page_title); 935a6598f23SBen Coburn } else { 936fffeeafeSChristopher Smith print hsc($page_title); 93754e95700STom N Harris return true; 93887c434ceSAndreas Gohr } 939a6598f23SBen Coburn} 940340756e4Sandi 94155efc227SAndreas Gohr/** 94255efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 94355efc227SAndreas Gohr * 94455efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 94555efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 94655efc227SAndreas Gohr * 94755efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 94855efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 94955efc227SAndreas Gohr * to the names of the latter one) 95055efc227SAndreas Gohr * 9513df72098SAndreas Gohr * Only allowed in: detail.php 95255efc227SAndreas Gohr * 95355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 95442ea7f44SGerrit Uitslag * 95521d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 956ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 957e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 958ac7a515fSAndreas Gohr * @return string 95955efc227SAndreas Gohr */ 9603df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) { 96155efc227SAndreas Gohr // Init Exif Reader 96255efc227SAndreas Gohr global $SRC; 9633df72098SAndreas Gohr 9643df72098SAndreas Gohr if(is_null($src)) $src = $SRC; 9653df72098SAndreas Gohr 96655efc227SAndreas Gohr static $meta = null; 9673df72098SAndreas Gohr if(is_null($meta)) $meta = new JpegMeta($src); 96855efc227SAndreas Gohr if($meta === false) return $alt; 96988945224SChristopher Smith $info = cleanText($meta->getField($tags)); 97055efc227SAndreas Gohr if($info == false) return $alt; 97155efc227SAndreas Gohr return $info; 97255efc227SAndreas Gohr} 97355efc227SAndreas Gohr 97455efc227SAndreas Gohr/** 975becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image 976becfa414SGerrit Uitslag * 977becfa414SGerrit Uitslag * @return string html of description list 978becfa414SGerrit Uitslag */ 979becfa414SGerrit Uitslagfunction tpl_img_meta() { 980becfa414SGerrit Uitslag global $lang; 981becfa414SGerrit Uitslag 982becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 983becfa414SGerrit Uitslag 984becfa414SGerrit Uitslag echo '<dl>'; 985becfa414SGerrit Uitslag foreach($tags as $tag) { 986becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 987fde860beSGerrit Uitslag if(!$label) $label = $tag['langkey'] . ':'; 988becfa414SGerrit Uitslag 989fde860beSGerrit Uitslag echo '<dt>'.$label.'</dt><dd>'; 990becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 991becfa414SGerrit Uitslag echo dformat($tag['value']); 992becfa414SGerrit Uitslag } else { 993becfa414SGerrit Uitslag echo hsc($tag['value']); 994becfa414SGerrit Uitslag } 995becfa414SGerrit Uitslag echo '</dd>'; 996becfa414SGerrit Uitslag } 997becfa414SGerrit Uitslag echo '</dl>'; 998becfa414SGerrit Uitslag} 999becfa414SGerrit Uitslag 1000becfa414SGerrit Uitslag/** 1001becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1002becfa414SGerrit Uitslag * 1003becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1004becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1005becfa414SGerrit Uitslag * - string type type of value 1006becfa414SGerrit Uitslag * - string value tag value (unescaped) 1007becfa414SGerrit Uitslag */ 1008becfa414SGerrit Uitslagfunction tpl_get_img_meta() { 1009becfa414SGerrit Uitslag 1010becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1011becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 101279e79377SAndreas Gohr if(file_exists($config_file)) { 1013becfa414SGerrit Uitslag include($config_file); 1014becfa414SGerrit Uitslag } 1015becfa414SGerrit Uitslag } 1016becfa414SGerrit Uitslag /** @var array $fields the included array with metadata */ 1017becfa414SGerrit Uitslag 1018becfa414SGerrit Uitslag $tags = array(); 1019becfa414SGerrit Uitslag foreach($fields as $tag){ 1020becfa414SGerrit Uitslag $t = array(); 1021becfa414SGerrit Uitslag if (!empty($tag[0])) { 1022becfa414SGerrit Uitslag $t = array($tag[0]); 1023becfa414SGerrit Uitslag } 1024becfa414SGerrit Uitslag if(is_array($tag[3])) { 1025becfa414SGerrit Uitslag $t = array_merge($t,$tag[3]); 1026becfa414SGerrit Uitslag } 1027becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1028becfa414SGerrit Uitslag if ($value) { 1029becfa414SGerrit Uitslag $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); 1030becfa414SGerrit Uitslag } 1031becfa414SGerrit Uitslag } 1032becfa414SGerrit Uitslag return $tags; 1033becfa414SGerrit Uitslag} 1034becfa414SGerrit Uitslag 1035becfa414SGerrit Uitslag/** 103655efc227SAndreas Gohr * Prints the image with a link to the full sized version 103755efc227SAndreas Gohr * 103855efc227SAndreas Gohr * Only allowed in: detail.php 1039a02d2933SAndreas Gohr * 1040ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 1041a02d2933SAndreas Gohr * @param $maxwidth int - maximal width of the image 1042a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image 1043a02d2933SAndreas Gohr * @param $link bool - link to the orginal size? 1044a02d2933SAndreas Gohr * @param $params array - additional image attributes 104542ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 104655efc227SAndreas Gohr */ 1047a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) { 104855efc227SAndreas Gohr global $IMG; 1049585bf44eSChristopher Smith /** @var Input $INPUT */ 1050ac7a515fSAndreas Gohr global $INPUT; 10515c2eed9aSlisps global $REV; 105265d3a5dbSAndreas Gohr $w = (int) tpl_img_getTag('File.Width'); 105365d3a5dbSAndreas Gohr $h = (int) tpl_img_getTag('File.Height'); 105455efc227SAndreas Gohr 105555efc227SAndreas Gohr //resize to given max values 105623a34783SAndreas Gohr $ratio = 1; 105723a34783SAndreas Gohr if($w >= $h) { 1058f8925855Sjoe.lapp if($maxwidth && $w >= $maxwidth) { 105955efc227SAndreas Gohr $ratio = $maxwidth / $w; 1060f8925855Sjoe.lapp } elseif($maxheight && $h > $maxheight) { 106155efc227SAndreas Gohr $ratio = $maxheight / $h; 106255efc227SAndreas Gohr } 106355efc227SAndreas Gohr } else { 1064f8925855Sjoe.lapp if($maxheight && $h >= $maxheight) { 106555efc227SAndreas Gohr $ratio = $maxheight / $h; 1066f8925855Sjoe.lapp } elseif($maxwidth && $w > $maxwidth) { 106755efc227SAndreas Gohr $ratio = $maxwidth / $w; 106855efc227SAndreas Gohr } 106955efc227SAndreas Gohr } 107055efc227SAndreas Gohr if($ratio) { 107155efc227SAndreas Gohr $w = floor($ratio * $w); 107255efc227SAndreas Gohr $h = floor($ratio * $h); 107355efc227SAndreas Gohr } 107455efc227SAndreas Gohr 10756de3759aSAndreas Gohr //prepare URLs 10765c2eed9aSlisps $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&'); 10775c2eed9aSlisps $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&'); 107855efc227SAndreas Gohr 10792684e50aSAndreas Gohr //prepare attributes 108055efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1081a02d2933SAndreas Gohr if(is_null($params)) { 10822684e50aSAndreas Gohr $p = array(); 1083a02d2933SAndreas Gohr } else { 1084a02d2933SAndreas Gohr $p = $params; 1085a02d2933SAndreas Gohr } 10862684e50aSAndreas Gohr if($w) $p['width'] = $w; 10872684e50aSAndreas Gohr if($h) $p['height'] = $h; 10882684e50aSAndreas Gohr $p['class'] = 'img_detail'; 10892684e50aSAndreas Gohr if($alt) { 10902684e50aSAndreas Gohr $p['alt'] = $alt; 10912684e50aSAndreas Gohr $p['title'] = $alt; 10922684e50aSAndreas Gohr } else { 10932684e50aSAndreas Gohr $p['alt'] = ''; 10942684e50aSAndreas Gohr } 1095a02d2933SAndreas Gohr $p['src'] = $src; 109655efc227SAndreas Gohr 1097a02d2933SAndreas Gohr $data = array('url'=> ($link ? $url : null), 'params'=> $p); 1098a02d2933SAndreas Gohr return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1099a02d2933SAndreas Gohr} 1100a02d2933SAndreas Gohr 1101a02d2933SAndreas Gohr/** 1102a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1103ac7a515fSAndreas Gohr * 1104ac7a515fSAndreas Gohr * @param array $data 1105ac7a515fSAndreas Gohr * @return bool 1106a02d2933SAndreas Gohr */ 1107ac7a515fSAndreas Gohrfunction _tpl_img_action($data) { 110859f3611bSAnika Henke global $lang; 1109a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1110a02d2933SAndreas Gohr 111159f3611bSAnika Henke if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; 1112a02d2933SAndreas Gohr print '<img '.$p.'/>'; 1113a02d2933SAndreas Gohr if($data['url']) print '</a>'; 111454e95700STom N Harris return true; 111555efc227SAndreas Gohr} 111655efc227SAndreas Gohr 11177367b368SAndreas Gohr/** 1118881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 11197367b368SAndreas Gohr * 11207367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php 11217367b368SAndreas Gohr * template 1122ac7a515fSAndreas Gohr * 1123ac7a515fSAndreas Gohr * @return bool 11247367b368SAndreas Gohr */ 11257367b368SAndreas Gohrfunction tpl_indexerWebBug() { 11267367b368SAndreas Gohr global $ID; 11271dad36f5SAndreas Gohr 11287367b368SAndreas Gohr $p = array(); 1129b6c6979fSAndreas Gohr $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). 1130e68c51baSAndreas Gohr '&'.time(); 1131881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 11327367b368SAndreas Gohr $p['height'] = 1; 11337367b368SAndreas Gohr $p['alt'] = ''; 11347367b368SAndreas Gohr $att = buildAttributes($p); 11357367b368SAndreas Gohr print "<img $att />"; 113654e95700STom N Harris return true; 11377367b368SAndreas Gohr} 11387367b368SAndreas Gohr 113978d4e784SEsther Brunner/** 114078d4e784SEsther Brunner * tpl_getConf($id) 114178d4e784SEsther Brunner * 114278d4e784SEsther Brunner * use this function to access template configuration variables 1143ac7a515fSAndreas Gohr * 114417448fb8SChristopher Smith * @param string $id name of the value to access 114517448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 114617448fb8SChristopher Smith * @return mixed 114778d4e784SEsther Brunner */ 114817448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) { 114978d4e784SEsther Brunner global $conf; 115017566ac6SAdrian Lang static $tpl_configloaded = false; 115178d4e784SEsther Brunner 115278d4e784SEsther Brunner $tpl = $conf['template']; 115378d4e784SEsther Brunner 115478d4e784SEsther Brunner if(!$tpl_configloaded) { 115578d4e784SEsther Brunner $tconf = tpl_loadConfig(); 115678d4e784SEsther Brunner if($tconf !== false) { 115778d4e784SEsther Brunner foreach($tconf as $key => $value) { 115878d4e784SEsther Brunner if(isset($conf['tpl'][$tpl][$key])) continue; 115978d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 116078d4e784SEsther Brunner } 116178d4e784SEsther Brunner $tpl_configloaded = true; 116278d4e784SEsther Brunner } 116378d4e784SEsther Brunner } 116478d4e784SEsther Brunner 116517448fb8SChristopher Smith if(isset($conf['tpl'][$tpl][$id])){ 116678d4e784SEsther Brunner return $conf['tpl'][$tpl][$id]; 116778d4e784SEsther Brunner } 116878d4e784SEsther Brunner 116917448fb8SChristopher Smith return $notset; 117017448fb8SChristopher Smith} 117117448fb8SChristopher Smith 117278d4e784SEsther Brunner/** 117378d4e784SEsther Brunner * tpl_loadConfig() 1174ac7a515fSAndreas Gohr * 117578d4e784SEsther Brunner * reads all template configuration variables 117678d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1177ac7a515fSAndreas Gohr * 1178ac7a515fSAndreas Gohr * @return array 117978d4e784SEsther Brunner */ 118078d4e784SEsther Brunnerfunction tpl_loadConfig() { 118178d4e784SEsther Brunner 1182c4766956SAndreas Gohr $file = tpl_incdir().'/conf/default.php'; 118378d4e784SEsther Brunner $conf = array(); 118478d4e784SEsther Brunner 118579e79377SAndreas Gohr if(!file_exists($file)) return false; 118678d4e784SEsther Brunner 118778d4e784SEsther Brunner // load default config file 118878d4e784SEsther Brunner include($file); 118978d4e784SEsther Brunner 119078d4e784SEsther Brunner return $conf; 119178d4e784SEsther Brunner} 119278d4e784SEsther Brunner 119317566ac6SAdrian Lang// language methods 119417566ac6SAdrian Lang/** 119517566ac6SAdrian Lang * tpl_getLang($id) 119617566ac6SAdrian Lang * 119717566ac6SAdrian Lang * use this function to access template language variables 119842ea7f44SGerrit Uitslag * 119942ea7f44SGerrit Uitslag * @param string $id key of language string 120042ea7f44SGerrit Uitslag * @return string 120117566ac6SAdrian Lang */ 120217566ac6SAdrian Langfunction tpl_getLang($id) { 120317566ac6SAdrian Lang static $lang = array(); 120417566ac6SAdrian Lang 120517566ac6SAdrian Lang if(count($lang) === 0) { 1206dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1207dd7a6159SGerrit Uitslag 1208c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 120917566ac6SAdrian Lang 121017566ac6SAdrian Lang $lang = array(); 121117566ac6SAdrian Lang 121217566ac6SAdrian Lang // don't include once 121317566ac6SAdrian Lang @include($path . 'en/lang.php'); 1214dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 121579e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1216dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1217dd7a6159SGerrit Uitslag } 121817566ac6SAdrian Lang } 121917566ac6SAdrian Lang 1220dd7a6159SGerrit Uitslag if($conf['lang'] != 'en') { 1221dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1222dd7a6159SGerrit Uitslag foreach($config_cascade['lang']['template'] as $config_file) { 122379e79377SAndreas Gohr if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1224dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1225dd7a6159SGerrit Uitslag } 1226dd7a6159SGerrit Uitslag } 1227dd7a6159SGerrit Uitslag } 122817566ac6SAdrian Lang } 122917566ac6SAdrian Lang return $lang[$id]; 123017566ac6SAdrian Lang} 123117566ac6SAdrian Lang 12323df72098SAndreas Gohr/** 1233c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1234e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1235e8ec13b9SKlap-in * 1236e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1237e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1238e8ec13b9SKlap-in */ 1239e8ec13b9SKlap-infunction tpl_locale_xhtml($id) { 1240c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1241e8ec13b9SKlap-in} 1242e8ec13b9SKlap-in 1243e8ec13b9SKlap-in/** 1244c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 124542ea7f44SGerrit Uitslag * 124642ea7f44SGerrit Uitslag * @param string $id id of localized text 124742ea7f44SGerrit Uitslag * @return string wiki text 1248e8ec13b9SKlap-in */ 1249c5c17fdaSKlap-infunction tpl_localeFN($id) { 1250e8ec13b9SKlap-in $path = tpl_incdir().'lang/'; 1251e8ec13b9SKlap-in global $conf; 125238fb1fc7SGerrit Uitslag $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt'; 125379e79377SAndreas Gohr if (!file_exists($file)){ 1254e8ec13b9SKlap-in $file = $path.$conf['lang'].'/'.$id.'.txt'; 125579e79377SAndreas Gohr if(!file_exists($file)){ 1256e8ec13b9SKlap-in //fall back to english 1257e8ec13b9SKlap-in $file = $path.'en/'.$id.'.txt'; 1258e8ec13b9SKlap-in } 1259e8ec13b9SKlap-in } 1260e8ec13b9SKlap-in return $file; 1261e8ec13b9SKlap-in} 1262e8ec13b9SKlap-in 1263e8ec13b9SKlap-in/** 12647abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 12653df72098SAndreas Gohr * 12663df72098SAndreas Gohr * Depending on the user's actions this may be a list of 12673df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 12683df72098SAndreas Gohr * a message of referencing pages 12693df72098SAndreas Gohr * 12703df72098SAndreas Gohr * Only allowed in mediamanager.php 12713df72098SAndreas Gohr * 1272c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1273c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 127442ea7f44SGerrit Uitslag * @param string $sort 12758702de7fSGerrit Uitslag * 12763df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 12773df72098SAndreas Gohr */ 127800e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') { 12793df72098SAndreas Gohr global $IMG; 12803df72098SAndreas Gohr global $AUTH; 12813df72098SAndreas Gohr global $INUSE; 12823df72098SAndreas Gohr global $NS; 12833df72098SAndreas Gohr global $JUMPTO; 1284585bf44eSChristopher Smith /** @var Input $INPUT */ 1285ac7a515fSAndreas Gohr global $INPUT; 12863df72098SAndreas Gohr 1287ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 1288c182313eSAndreas Gohr if(in_array($do, array('save', 'cancel'))) $do = ''; 1289c182313eSAndreas Gohr 1290c182313eSAndreas Gohr if(!$do) { 1291ac7a515fSAndreas Gohr if($INPUT->bool('edit')) { 1292c182313eSAndreas Gohr $do = 'metaform'; 1293c182313eSAndreas Gohr } elseif(is_array($INUSE)) { 1294c182313eSAndreas Gohr $do = 'filesinuse'; 1295c182313eSAndreas Gohr } else { 1296c182313eSAndreas Gohr $do = 'filelist'; 1297c182313eSAndreas Gohr } 1298c182313eSAndreas Gohr } 1299c182313eSAndreas Gohr 1300c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1301c182313eSAndreas Gohr if(!$fromajax) ptln('<div id="media__content">'); 1302c182313eSAndreas Gohr $data = array('do' => $do); 1303c182313eSAndreas Gohr $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1304c182313eSAndreas Gohr if($evt->advise_before()) { 1305c182313eSAndreas Gohr $do = $data['do']; 130630fd72fbSKate Arzamastseva if($do == 'filesinuse') { 1307c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1308c182313eSAndreas Gohr } elseif($do == 'filelist') { 130900e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO,false,$sort); 1310c9f56829SAndreas Gohr } elseif($do == 'searchlist') { 1311ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1312c182313eSAndreas Gohr } else { 1313c182313eSAndreas Gohr msg('Unknown action '.hsc($do), -1); 1314c182313eSAndreas Gohr } 1315c182313eSAndreas Gohr } 1316c182313eSAndreas Gohr $evt->advise_after(); 1317c182313eSAndreas Gohr unset($evt); 1318c182313eSAndreas Gohr if(!$fromajax) ptln('</div>'); 1319c182313eSAndreas Gohr 13203df72098SAndreas Gohr} 13213df72098SAndreas Gohr 13223df72098SAndreas Gohr/** 1323d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1324d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1325d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1326d9162c6cSKate Arzamastseva * 1327d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1328d9162c6cSKate Arzamastseva */ 1329035e07f1SKate Arzamastsevafunction tpl_mediaFileList() { 1330d9162c6cSKate Arzamastseva global $AUTH; 1331d9162c6cSKate Arzamastseva global $NS; 1332d9162c6cSKate Arzamastseva global $JUMPTO; 133395b451bcSAdrian Lang global $lang; 1334585bf44eSChristopher Smith /** @var Input $INPUT */ 1335ac7a515fSAndreas Gohr global $INPUT; 1336d9162c6cSKate Arzamastseva 1337ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 1338e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files'; 1339ac7a515fSAndreas Gohr if($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1340d9162c6cSKate Arzamastseva 134194add303SAnika Henke echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL; 134295b451bcSAdrian Lang 1343ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 134423846a98SKate Arzamastseva 134594add303SAnika Henke echo '<div class="panelHeader">'.NL; 134695b451bcSAdrian Lang echo '<h3>'; 1347026d14a9SAnika Henke $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']'; 1348c98f205eSAdrian Lang printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>'); 134994add303SAnika Henke echo '</h3>'.NL; 135095b451bcSAdrian Lang if($opened_tab === 'search' || $opened_tab === 'files') { 135195b451bcSAdrian Lang media_tab_files_options(); 135223846a98SKate Arzamastseva } 135394add303SAnika Henke echo '</div>'.NL; 1354d9162c6cSKate Arzamastseva 135594add303SAnika Henke echo '<div class="panelContent">'.NL; 135695b451bcSAdrian Lang if($opened_tab == 'files') { 135795b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 135895b451bcSAdrian Lang } elseif($opened_tab == 'upload') { 135995b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 136095b451bcSAdrian Lang } elseif($opened_tab == 'search') { 136195b451bcSAdrian Lang media_tab_search($NS, $AUTH); 136295b451bcSAdrian Lang } 136394add303SAnika Henke echo '</div>'.NL; 1364d9162c6cSKate Arzamastseva} 1365d9162c6cSKate Arzamastseva 1366d9162c6cSKate Arzamastseva/** 1367d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1368d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1369d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1370d9162c6cSKate Arzamastseva * list of file revisions 1371d9162c6cSKate Arzamastseva * 1372d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1373f50a239bSTakamura * 1374f50a239bSTakamura * @param string $image 1375f50a239bSTakamura * @param boolean $rev 1376d9162c6cSKate Arzamastseva */ 1377035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) { 1378e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1379585bf44eSChristopher Smith /** @var Input $INPUT */ 1380585bf44eSChristopher Smith global $INPUT; 1381d9162c6cSKate Arzamastseva 138292cac9a9SKate Arzamastseva $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']); 1383ac7a515fSAndreas Gohr if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 13846dd095f5SKate Arzamastseva if($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1385e8a2a143SMichael Hamann $ns = getNS($image); 1386ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 13871eeeced2SKate Arzamastseva 1388ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1389e5d185e1SKate Arzamastseva 1390e5d185e1SKate Arzamastseva $tab_array = array('view'); 1391ac7a515fSAndreas Gohr list(, $mime) = mimetype($image); 1392e5d185e1SKate Arzamastseva if($mime == 'image/jpeg') { 1393e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1394e5d185e1SKate Arzamastseva } 1395e5d185e1SKate Arzamastseva if($conf['mediarevisions']) { 1396e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1397e5d185e1SKate Arzamastseva } 1398e5d185e1SKate Arzamastseva 1399e5d185e1SKate Arzamastseva if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1400ac7a515fSAndreas Gohr if($INPUT->bool('edit')) $opened_tab = 'edit'; 140123846a98SKate Arzamastseva if($do == 'restore') $opened_tab = 'view'; 1402d9162c6cSKate Arzamastseva 1403ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 140423846a98SKate Arzamastseva 140559f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 1406ac7a515fSAndreas Gohr list($ext) = mimetype($image, false); 140795b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 140895b451bcSAdrian Lang $class = 'select mediafile mf_'.$class; 1409750a0b51SMichael Große $attributes = $rev ? ['rev' => $rev] : []; 1410750a0b51SMichael Große $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; 141108317413SAdrian Lang if($opened_tab === 'view' && $rev) { 141208317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 141308317413SAdrian Lang } else { 1414026d14a9SAnika Henke printf($lang['media_'.$opened_tab], $tabTitle); 141508317413SAdrian Lang } 1416b8a84c03SAndreas Gohr 141794add303SAnika Henke echo '</h3></div>'.NL; 141895b451bcSAdrian Lang 141994add303SAnika Henke echo '<div class="panelContent">'.NL; 142095b451bcSAdrian Lang 142123846a98SKate Arzamastseva if($opened_tab == 'view') { 1422e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 142323846a98SKate Arzamastseva 142492cac9a9SKate Arzamastseva } elseif($opened_tab == 'edit' && !$removed) { 1425e8a2a143SMichael Hamann media_tab_edit($image, $ns); 142623846a98SKate Arzamastseva 1427e5d185e1SKate Arzamastseva } elseif($opened_tab == 'history' && $conf['mediarevisions']) { 1428e8a2a143SMichael Hamann media_tab_history($image, $ns); 142923846a98SKate Arzamastseva } 143095b451bcSAdrian Lang 143194add303SAnika Henke echo '</div>'.NL; 1432d9162c6cSKate Arzamastseva} 1433d9162c6cSKate Arzamastseva 1434d9162c6cSKate Arzamastseva/** 14357abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 14363df72098SAndreas Gohr * 14373df72098SAndreas Gohr * Only allowed in mediamanager.php 14383df72098SAndreas Gohr * 14393df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14403df72098SAndreas Gohr */ 1441fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() { 14423df72098SAndreas Gohr global $NS; 144323846a98SKate Arzamastseva ptln('<div id="media__tree">'); 14443df72098SAndreas Gohr media_nstree($NS); 14453df72098SAndreas Gohr ptln('</div>'); 14463df72098SAndreas Gohr} 14473df72098SAndreas Gohr 1448a00de5b5SAndreas Gohr/** 1449a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1450a00de5b5SAndreas Gohr * 1451a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1452a00de5b5SAndreas Gohr * 1453a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 145442ea7f44SGerrit Uitslag * 145542ea7f44SGerrit Uitslag * @param string $empty empty option label 145642ea7f44SGerrit Uitslag * @param string $button submit button label 1457affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 1458a00de5b5SAndreas Gohr */ 1459a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') { 1460affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 14611e875dcdSAndreas Gohr $menu = new \dokuwiki\Menu\MobileMenu(); 14621e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1463a00de5b5SAndreas Gohr} 1464a00de5b5SAndreas Gohr 1465066fee30SAndreas Gohr/** 1466066fee30SAndreas Gohr * Print a informational line about the used license 1467066fee30SAndreas Gohr * 1468066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1469ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1470ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1471ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1472ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1473ac7a515fSAndreas Gohr * @return string 1474066fee30SAndreas Gohr */ 147580083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) { 1476066fee30SAndreas Gohr global $license; 1477066fee30SAndreas Gohr global $conf; 1478066fee30SAndreas Gohr global $lang; 1479066fee30SAndreas Gohr if(!$conf['license']) return ''; 1480066fee30SAndreas Gohr if(!is_array($license[$conf['license']])) return ''; 1481066fee30SAndreas Gohr $lic = $license[$conf['license']]; 148253e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; 1483066fee30SAndreas Gohr 148480083a41SAndreas Gohr $out = ''; 148580083a41SAndreas Gohr if($wrap) $out .= '<div class="license">'; 1486066fee30SAndreas Gohr if($img) { 1487066fee30SAndreas Gohr $src = license_img($img); 1488066fee30SAndreas Gohr if($src) { 148953e15c8bSAnika Henke $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; 149053e15c8bSAnika Henke $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; 149153e15c8bSAnika Henke if(!$imgonly) $out .= ' '; 1492066fee30SAndreas Gohr } 1493066fee30SAndreas Gohr } 14944cefd216SMichael Klier if(!$imgonly) { 149553e15c8bSAnika Henke $out .= $lang['license'].' '; 1496d317fb5dSAnika Henke $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; 1497d317fb5dSAnika Henke $out .= '>'.$lic['name'].'</a></bdi>'; 14984cefd216SMichael Klier } 149980083a41SAndreas Gohr if($wrap) $out .= '</div>'; 1500066fee30SAndreas Gohr 1501066fee30SAndreas Gohr if($return) return $out; 1502066fee30SAndreas Gohr echo $out; 1503ac7a515fSAndreas Gohr return ''; 1504066fee30SAndreas Gohr} 1505066fee30SAndreas Gohr 1506a81910eeSAndreas Gohr/** 1507835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1508a81910eeSAndreas Gohr * 1509a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1510a81910eeSAndreas Gohr * template 1511e0c26282SGerrit Uitslag * 15127a112df5SAndreas Gohr * @param string $pageid The page name you want to include 15137a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 15147a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 15157c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1516e0c26282SGerrit Uitslag * @return bool|null|string 1517a81910eeSAndreas Gohr */ 15187c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) { 15197a112df5SAndreas Gohr if($propagate) { 15207c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 15217c3e4a67SAndreas Gohr } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 15227a112df5SAndreas Gohr return false; 15237a112df5SAndreas Gohr } 1524c786a1b6SAnika Henke if(!$pageid) return false; 1525835dfcaeSAnika Henke 1526c786a1b6SAnika Henke global $TOC; 15279a2e250aSAndreas Gohr $oldtoc = $TOC; 1528a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 15299a2e250aSAndreas Gohr $TOC = $oldtoc; 1530a81910eeSAndreas Gohr 1531a2e03c82SAndreas Gohr if($print) echo $html; 1532e66d3e6dSAndreas Gohr return $html; 1533e66d3e6dSAndreas Gohr} 1534e66d3e6dSAndreas Gohr 1535e66d3e6dSAndreas Gohr/** 15365b75cd1fSAdrian Lang * Display the subscribe form 15375b75cd1fSAdrian Lang * 15385b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 15395b75cd1fSAdrian Lang */ 15405b75cd1fSAdrian Langfunction tpl_subscribe() { 15415b75cd1fSAdrian Lang global $INFO; 15425b75cd1fSAdrian Lang global $ID; 15435b75cd1fSAdrian Lang global $lang; 15446b8f02cfSAdrian Lang global $conf; 154540c347dbSAdrian Lang $stime_days = $conf['subscribe_time'] / 60 / 60 / 24; 15465b75cd1fSAdrian Lang 15475b75cd1fSAdrian Lang echo p_locale_xhtml('subscr_form'); 15485b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_current_header'].'</h2>'; 154915741132SAndreas Gohr echo '<div class="level2">'; 15505b75cd1fSAdrian Lang if($INFO['subscribed'] === false) { 15515b75cd1fSAdrian Lang echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>'; 15525b75cd1fSAdrian Lang } else { 15535b75cd1fSAdrian Lang echo '<ul>'; 15545b75cd1fSAdrian Lang foreach($INFO['subscribed'] as $sub) { 1555056c2049SAndreas Gohr echo '<li><div class="li">'; 15565b75cd1fSAdrian Lang if($sub['target'] !== $ID) { 1557056c2049SAndreas Gohr echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>'; 15585b75cd1fSAdrian Lang } else { 1559056c2049SAndreas Gohr echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>'; 15605b75cd1fSAdrian Lang } 156140c347dbSAdrian Lang $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days); 156215741132SAndreas Gohr if(!$sstl) $sstl = hsc($sub['style']); 1563056c2049SAndreas Gohr echo ' ('.$sstl.') '; 156415741132SAndreas Gohr 1565ac7a515fSAndreas Gohr echo '<a href="'.wl( 1566ac7a515fSAndreas Gohr $ID, 1567ac7a515fSAndreas Gohr array( 1568ac7a515fSAndreas Gohr 'do' => 'subscribe', 156966d2bed9SAdrian Lang 'sub_target'=> $sub['target'], 157066d2bed9SAdrian Lang 'sub_style' => $sub['style'], 157166d2bed9SAdrian Lang 'sub_action'=> 'unsubscribe', 1572ac7a515fSAndreas Gohr 'sectok' => getSecurityToken() 1573ac7a515fSAndreas Gohr ) 1574ac7a515fSAndreas Gohr ). 157566d2bed9SAdrian Lang '" class="unsubscribe">'.$lang['subscr_m_unsubscribe']. 157666d2bed9SAdrian Lang '</a></div></li>'; 15775b75cd1fSAdrian Lang } 15785b75cd1fSAdrian Lang echo '</ul>'; 15795b75cd1fSAdrian Lang } 158015741132SAndreas Gohr echo '</div>'; 15815b75cd1fSAdrian Lang 158215741132SAndreas Gohr // Add new subscription form 15835b75cd1fSAdrian Lang echo '<h2>'.$lang['subscr_m_new_header'].'</h2>'; 158415741132SAndreas Gohr echo '<div class="level2">'; 15855b75cd1fSAdrian Lang $ns = getNS($ID).':'; 158615741132SAndreas Gohr $targets = array( 158715741132SAndreas Gohr $ID => '<code class="page">'.prettyprint_id($ID).'</code>', 158815741132SAndreas Gohr $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', 158915741132SAndreas Gohr ); 159015741132SAndreas Gohr $styles = array( 159115741132SAndreas Gohr 'every' => $lang['subscr_style_every'], 15926b8f02cfSAdrian Lang 'digest' => sprintf($lang['subscr_style_digest'], $stime_days), 15936b8f02cfSAdrian Lang 'list' => sprintf($lang['subscr_style_list'], $stime_days), 159415741132SAndreas Gohr ); 159515741132SAndreas Gohr 1596056c2049SAndreas Gohr $form = new Doku_Form(array('id' => 'subscribe__form')); 1597056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_subscribe']); 1598056c2049SAndreas Gohr $form->addRadioSet('sub_target', $targets); 1599056c2049SAndreas Gohr $form->startFieldset($lang['subscr_m_receive']); 1600056c2049SAndreas Gohr $form->addRadioSet('sub_style', $styles); 1601056c2049SAndreas Gohr $form->addHidden('sub_action', 'subscribe'); 1602056c2049SAndreas Gohr $form->addHidden('do', 'subscribe'); 1603056c2049SAndreas Gohr $form->addHidden('id', $ID); 1604056c2049SAndreas Gohr $form->endFieldset(); 16055b75cd1fSAdrian Lang $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe'])); 16065b75cd1fSAdrian Lang html_form('SUBSCRIBE', $form); 160715741132SAndreas Gohr echo '</div>'; 16085b75cd1fSAdrian Lang} 16095b75cd1fSAdrian Lang 1610d059ba9bSAndreas Gohr/** 1611d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1612d059ba9bSAndreas Gohr * 1613d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1614d059ba9bSAndreas Gohr * 1615d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1616d059ba9bSAndreas Gohr */ 1617d059ba9bSAndreas Gohrfunction tpl_flush() { 1618d059ba9bSAndreas Gohr ob_flush(); 1619d059ba9bSAndreas Gohr flush(); 1620d059ba9bSAndreas Gohr} 1621d059ba9bSAndreas Gohr 1622afca7e7eSAnika Henke/** 1623378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1624afca7e7eSAnika Henke * 1625378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1626378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1627378325f9SAndreas Gohr * 162842ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1629378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1630ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 1631ac7a515fSAndreas Gohr * @return string 163242ea7f44SGerrit Uitslag * 1633378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1634afca7e7eSAnika Henke */ 1635378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) { 1636ac7a515fSAndreas Gohr $img = ''; 1637ac7a515fSAndreas Gohr $file = ''; 1638ac7a515fSAndreas Gohr $ismedia = false; 1639378325f9SAndreas Gohr // loop through candidates until a match was found: 1640378325f9SAndreas Gohr foreach($search as $img) { 1641378325f9SAndreas Gohr if(substr($img, 0, 1) == ':') { 1642378325f9SAndreas Gohr $file = mediaFN($img); 1643378325f9SAndreas Gohr $ismedia = true; 1644378325f9SAndreas Gohr } else { 1645c4766956SAndreas Gohr $file = tpl_incdir().$img; 1646378325f9SAndreas Gohr $ismedia = false; 16471f13e33dSAnika Henke } 16480f747863Slupo49 1649378325f9SAndreas Gohr if(file_exists($file)) break; 1650872a6d29SAnika Henke } 1651378325f9SAndreas Gohr 1652378325f9SAndreas Gohr // fetch image data if requested 1653378325f9SAndreas Gohr if(!is_null($imginfo)) { 1654378325f9SAndreas Gohr $imginfo = getimagesize($file); 1655378325f9SAndreas Gohr } 1656378325f9SAndreas Gohr 1657378325f9SAndreas Gohr // build URL 1658378325f9SAndreas Gohr if($ismedia) { 1659378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1660378325f9SAndreas Gohr } else { 1661c4766956SAndreas Gohr $url = tpl_basedir().$img; 1662378325f9SAndreas Gohr if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); 1663378325f9SAndreas Gohr } 1664378325f9SAndreas Gohr 1665378325f9SAndreas Gohr return $url; 1666a7e5f74cSlupo49} 16671f13e33dSAnika Henke 1668872a6d29SAnika Henke/** 1669e5d4768dSAndreas Gohr * PHP include a file 1670e5d4768dSAndreas Gohr * 1671e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1672e5d4768dSAndreas Gohr * file in the template's root directory. 1673e5d4768dSAndreas Gohr * 1674e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1675e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1676e5d4768dSAndreas Gohr * default. 1677e5d4768dSAndreas Gohr * 1678e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1679e5d4768dSAndreas Gohr * to this function! 1680e5d4768dSAndreas Gohr * 1681e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org> 1682e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 168342ea7f44SGerrit Uitslag * 168442ea7f44SGerrit Uitslag * @param string $file 1685e5d4768dSAndreas Gohr */ 1686e5d4768dSAndreas Gohrfunction tpl_includeFile($file) { 1687e5d4768dSAndreas Gohr global $config_cascade; 1688e5d4768dSAndreas Gohr foreach(array('protected', 'local', 'default') as $config_group) { 1689e5d4768dSAndreas Gohr if(empty($config_cascade['main'][$config_group])) continue; 1690e5d4768dSAndreas Gohr foreach($config_cascade['main'][$config_group] as $conf_file) { 1691e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1692e5d4768dSAndreas Gohr if(file_exists("$dir/$file")) { 1693f3a1225fSAnika Henke include("$dir/$file"); 1694e5d4768dSAndreas Gohr return; 1695e5d4768dSAndreas Gohr } 1696e5d4768dSAndreas Gohr } 1697e5d4768dSAndreas Gohr } 1698e5d4768dSAndreas Gohr 1699e5d4768dSAndreas Gohr // still here? try the template dir 1700e5d4768dSAndreas Gohr $file = tpl_incdir().$file; 1701e5d4768dSAndreas Gohr if(file_exists($file)) { 1702f3a1225fSAnika Henke include($file); 1703e5d4768dSAndreas Gohr } 1704e5d4768dSAndreas Gohr} 1705e5d4768dSAndreas Gohr 1706e5d4768dSAndreas Gohr/** 1707872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1708872a6d29SAnika Henke * 1709872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org> 171042ea7f44SGerrit Uitslag * 1711ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1712ac7a515fSAndreas Gohr * @return string 1713872a6d29SAnika Henke */ 1714872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) { 1715872a6d29SAnika Henke 1716872a6d29SAnika Henke $return = ''; 1717872a6d29SAnika Henke 1718872a6d29SAnika Henke foreach($types as $type) { 1719872a6d29SAnika Henke switch($type) { 1720872a6d29SAnika Henke case 'favicon': 1721378325f9SAndreas Gohr $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); 1722378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1723872a6d29SAnika Henke break; 1724872a6d29SAnika Henke case 'mobile': 1725cab75975SAnika Henke $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'); 1726378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL; 1727872a6d29SAnika Henke break; 1728872a6d29SAnika Henke case 'generic': 1729872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 1730378325f9SAndreas Gohr $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); 1731378325f9SAndreas Gohr $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; 1732872a6d29SAnika Henke break; 1733872a6d29SAnika Henke } 1734872a6d29SAnika Henke } 1735872a6d29SAnika Henke 1736872a6d29SAnika Henke return $return; 1737afca7e7eSAnika Henke} 1738afca7e7eSAnika Henke 1739d9162c6cSKate Arzamastseva/** 1740d9162c6cSKate Arzamastseva * Prints full-screen media manager 1741d9162c6cSKate Arzamastseva * 1742d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1743d9162c6cSKate Arzamastseva */ 1744d9162c6cSKate Arzamastsevafunction tpl_media() { 1745ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 174688a71175SKate Arzamastseva $fullscreen = true; 174795b451bcSAdrian Lang require_once DOKU_INC.'lib/exe/mediamanager.php'; 1748d9162c6cSKate Arzamastseva 1749ac7a515fSAndreas Gohr $rev = ''; 1750ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 175198f03b57SKate Arzamastseva if(isset($IMG)) $image = $IMG; 175298f03b57SKate Arzamastseva if(isset($JUMPTO)) $image = $JUMPTO; 17539c1bd4bcSKate Arzamastseva if(isset($REV) && !$JUMPTO) $rev = $REV; 175498f03b57SKate Arzamastseva 175594add303SAnika Henke echo '<div id="mediamanager__page">'.NL; 1756bc314c58SAnika Henke echo '<h1>'.$lang['btn_media'].'</h1>'.NL; 1757d9162c6cSKate Arzamastseva html_msgarea(); 175894add303SAnika Henke 175994add303SAnika Henke echo '<div class="panel namespaces">'.NL; 176094add303SAnika Henke echo '<h2>'.$lang['namespaces'].'</h2>'.NL; 176195b451bcSAdrian Lang echo '<div class="panelHeader">'; 1762ba340a70SAnika Henke echo $lang['media_namespaces']; 176394add303SAnika Henke echo '</div>'.NL; 176495b451bcSAdrian Lang 176594add303SAnika Henke echo '<div class="panelContent" id="media__tree">'.NL; 176695b451bcSAdrian Lang media_nstree($NS); 176794add303SAnika Henke echo '</div>'.NL; 176894add303SAnika Henke echo '</div>'.NL; 1769fa8e5c77SKate Arzamastseva 177094add303SAnika Henke echo '<div class="panel filelist">'.NL; 1771035e07f1SKate Arzamastseva tpl_mediaFileList(); 177294add303SAnika Henke echo '</div>'.NL; 1773fa8e5c77SKate Arzamastseva 177494add303SAnika Henke echo '<div class="panel file">'.NL; 177594add303SAnika Henke echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL; 1776035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 177794add303SAnika Henke echo '</div>'.NL; 1778ba340a70SAnika Henke 177994add303SAnika Henke echo '</div>'.NL; 1780d9162c6cSKate Arzamastseva} 1781afca7e7eSAnika Henke 1782c71db656SAnika Henke/** 1783c71db656SAnika Henke * Return useful layout classes 1784c71db656SAnika Henke * 1785c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org> 178642ea7f44SGerrit Uitslag * 178742ea7f44SGerrit Uitslag * @return string 1788c71db656SAnika Henke */ 1789c71db656SAnika Henkefunction tpl_classes() { 1790c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1791585bf44eSChristopher Smith /** @var Input $INPUT */ 1792585bf44eSChristopher Smith global $INPUT; 1793585bf44eSChristopher Smith 1794c71db656SAnika Henke $classes = array( 1795c71db656SAnika Henke 'dokuwiki', 1796c71db656SAnika Henke 'mode_'.$ACT, 1797c71db656SAnika Henke 'tpl_'.$conf['template'], 1798585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 179939f00629SAnika Henke $INFO['exists'] ? '' : 'notFound', 1800c71db656SAnika Henke ($ID == $conf['start']) ? 'home' : '', 1801c71db656SAnika Henke ); 1802c71db656SAnika Henke return join(' ', $classes); 1803c71db656SAnika Henke} 1804c71db656SAnika Henke 180584dd2b1aSGerrit Uitslag/** 180684dd2b1aSGerrit Uitslag * Create event for tools menues 180784dd2b1aSGerrit Uitslag * 180884dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 180984dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 181084dd2b1aSGerrit Uitslag * @param array $items 181184dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 1812affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 181384dd2b1aSGerrit Uitslag */ 181484dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') { 1815affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 181684dd2b1aSGerrit Uitslag $data = array( 181784dd2b1aSGerrit Uitslag 'view' => $view, 181884dd2b1aSGerrit Uitslag 'items' => $items 181984dd2b1aSGerrit Uitslag ); 182084dd2b1aSGerrit Uitslag 182184dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 182284dd2b1aSGerrit Uitslag $evt = new Doku_Event($hook, $data); 182384dd2b1aSGerrit Uitslag if($evt->advise_before()) { 182484dd2b1aSGerrit Uitslag foreach($evt->data['items'] as $k => $html) echo $html; 182584dd2b1aSGerrit Uitslag } 182684dd2b1aSGerrit Uitslag $evt->advise_after(); 182784dd2b1aSGerrit Uitslag} 182884dd2b1aSGerrit Uitslag 1829e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1830a00de5b5SAndreas Gohr 1831