16b13307fSandi<?php 2d4f83172SAndreas Gohr 36b13307fSandi/** 46b13307fSandi * DokuWiki template functions 56b13307fSandi * 66b13307fSandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 76b13307fSandi * @author Andreas Gohr <andi@splitbrain.org> 86b13307fSandi */ 9d4f83172SAndreas Gohr 1024870174SAndreas Gohruse dokuwiki\ActionRouter; 1124870174SAndreas Gohruse dokuwiki\Action\Exception\FatalException; 1224870174SAndreas Gohruse dokuwiki\Extension\PluginInterface; 13*dd9e8e5eSAndreas Gohruse dokuwiki\File\MediaFile; 1424870174SAndreas Gohruse dokuwiki\Ui\Admin; 1524870174SAndreas Gohruse dokuwiki\StyleUtils; 1624870174SAndreas Gohruse dokuwiki\Menu\Item\AbstractItem; 1724870174SAndreas Gohruse dokuwiki\Form\Form; 1824870174SAndreas Gohruse dokuwiki\Menu\MobileMenu; 1924870174SAndreas Gohruse dokuwiki\Ui\Subscribe; 20e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 21e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event; 222cd6cc0aSAndreas Gohruse dokuwiki\File\PageResolver; 23e1d9dcc8SAndreas Gohr 246b13307fSandi/** 25ac7a515fSAndreas Gohr * Access a template file 26ac7a515fSAndreas Gohr * 27ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses 28ac7a515fSAndreas Gohr * default template if the custom version doesn't exist. 295a892029SAndreas Gohr * 30ac7a515fSAndreas Gohr * @param string $file 31ac7a515fSAndreas Gohr * @return string 324dc42f7fSGerrit Uitslag * 334dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 345a892029SAndreas Gohr */ 35d868eb89SAndreas Gohrfunction template($file) 36d868eb89SAndreas Gohr{ 375a892029SAndreas Gohr global $conf; 385a892029SAndreas Gohr 39ac7a515fSAndreas Gohr if (@is_readable(DOKU_INC . 'lib/tpl/' . $conf['template'] . '/' . $file)) 40ac7a515fSAndreas Gohr return DOKU_INC . 'lib/tpl/' . $conf['template'] . '/' . $file; 415a892029SAndreas Gohr 42ac7a515fSAndreas Gohr return DOKU_INC . 'lib/tpl/dokuwiki/' . $file; 435a892029SAndreas Gohr} 445a892029SAndreas Gohr 45c4766956SAndreas Gohr/** 46c4766956SAndreas Gohr * Convenience function to access template dir from local FS 47c4766956SAndreas Gohr * 48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant 49c4766956SAndreas Gohr * 50afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 51ac7a515fSAndreas Gohr * @return string 524dc42f7fSGerrit Uitslag * 534dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 54c4766956SAndreas Gohr */ 55d868eb89SAndreas Gohrfunction tpl_incdir($tpl = '') 56d868eb89SAndreas Gohr{ 5775b14482SAndreas Gohr global $conf; 58afb2c082SAndreas Gohr if (!$tpl) $tpl = $conf['template']; 59afb2c082SAndreas Gohr return DOKU_INC . 'lib/tpl/' . $tpl . '/'; 60c4766956SAndreas Gohr} 61c4766956SAndreas Gohr 62c4766956SAndreas Gohr/** 63c4766956SAndreas Gohr * Convenience function to access template dir from web 64c4766956SAndreas Gohr * 65c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant 66c4766956SAndreas Gohr * 67afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one 68ac7a515fSAndreas Gohr * @return string 694dc42f7fSGerrit Uitslag * 704dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 71c4766956SAndreas Gohr */ 72d868eb89SAndreas Gohrfunction tpl_basedir($tpl = '') 73d868eb89SAndreas Gohr{ 7475b14482SAndreas Gohr global $conf; 75afb2c082SAndreas Gohr if (!$tpl) $tpl = $conf['template']; 76dcd4911eSMichael Hamann return DOKU_BASE . 'lib/tpl/' . $tpl . '/'; 77c4766956SAndreas Gohr} 78c4766956SAndreas Gohr 795a892029SAndreas Gohr/** 806b13307fSandi * Print the content 816b13307fSandi * 826b13307fSandi * This function is used for printing all the usual content 836b13307fSandi * (defined by the global $ACT var) by calling the appropriate 846b13307fSandi * outputfunction(s) from html.php 856b13307fSandi * 86ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't 87ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either. 886b13307fSandi * 894dc42f7fSGerrit Uitslag * @param bool $prependTOC should the TOC be displayed here? 904dc42f7fSGerrit Uitslag * @return bool true if any output 9142ea7f44SGerrit Uitslag * 92ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER 93ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY 944dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 956b13307fSandi */ 96d868eb89SAndreas Gohrfunction tpl_content($prependTOC = true) 97d868eb89SAndreas Gohr{ 987ea0913cSchris global $ACT; 99b8595a66SAndreas Gohr global $INFO; 100b8595a66SAndreas Gohr $INFO['prependTOC'] = $prependTOC; 1017ea0913cSchris 1027ea0913cSchris ob_start(); 103cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); 1047ea0913cSchris $html_output = ob_get_clean(); 10534c27e09SAndreas Gohr Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, function ($html_output) { 10634c27e09SAndreas Gohr echo $html_output; 10734c27e09SAndreas Gohr }); 10854e95700STom N Harris 10954e95700STom N Harris return !empty($html_output); 1107ea0913cSchris} 1117ea0913cSchris 112ac7a515fSAndreas Gohr/** 113ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER 114ac7a515fSAndreas Gohr * 115ac7a515fSAndreas Gohr * @return bool 116ac7a515fSAndreas Gohr */ 117d868eb89SAndreas Gohrfunction tpl_content_core() 118d868eb89SAndreas Gohr{ 11924870174SAndreas Gohr $router = ActionRouter::getInstance(); 120952acff9SAndreas Gohr try { 121952acff9SAndreas Gohr $router->getAction()->tplContent(); 12224870174SAndreas Gohr } catch (FatalException $e) { 123952acff9SAndreas Gohr // there was no content for the action 124952acff9SAndreas Gohr msg(hsc($e->getMessage()), -1); 12554e95700STom N Harris return false; 1266b13307fSandi } 12754e95700STom N Harris return true; 1286b13307fSandi} 1296b13307fSandi 130c19fe9c0Sandi/** 131b8595a66SAndreas Gohr * Places the TOC where the function is called 132b8595a66SAndreas Gohr * 133b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with 134b8595a66SAndreas Gohr * a false argument 135b8595a66SAndreas Gohr * 136ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed? 137ac7a515fSAndreas Gohr * @return string 1384dc42f7fSGerrit Uitslag * 1394dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 140b8595a66SAndreas Gohr */ 141d868eb89SAndreas Gohrfunction tpl_toc($return = false) 142d868eb89SAndreas Gohr{ 143b8595a66SAndreas Gohr global $TOC; 144b8595a66SAndreas Gohr global $ACT; 145b8595a66SAndreas Gohr global $ID; 146b8595a66SAndreas Gohr global $REV; 147b8595a66SAndreas Gohr global $INFO; 148851f2e89SAnika Henke global $conf; 14924870174SAndreas Gohr $toc = []; 150b8595a66SAndreas Gohr 151b8595a66SAndreas Gohr if (is_array($TOC)) { 152b8595a66SAndreas Gohr // if a TOC was prepared in global scope, always use it 153b8595a66SAndreas Gohr $toc = $TOC; 1546c16a3a9Sfiwswe } elseif (($ACT == 'show' || str_starts_with($ACT, 'export')) && !$REV && $INFO['exists']) { 155b8595a66SAndreas Gohr // get TOC from metadata, render if neccessary 156e0c26282SGerrit Uitslag $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE); 1574dc42f7fSGerrit Uitslag $tocok = $meta['internal']['toc'] ?? true; 15824870174SAndreas Gohr $toc = $meta['description']['tableofcontents'] ?? null; 159851f2e89SAnika Henke if (!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { 16024870174SAndreas Gohr $toc = []; 161b8595a66SAndreas Gohr } 162b8595a66SAndreas Gohr } elseif ($ACT == 'admin') { 163a61966c5SChristopher Smith // try to load admin plugin TOC 1644dc42f7fSGerrit Uitslag /** @var AdminPlugin $plugin */ 165a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 166b8595a66SAndreas Gohr $toc = $plugin->getTOC(); 167b8595a66SAndreas Gohr $TOC = $toc; // avoid later rebuild 168b8595a66SAndreas Gohr } 169b8595a66SAndreas Gohr } 170b8595a66SAndreas Gohr 171cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false); 172b8595a66SAndreas Gohr $html = html_TOC($toc); 173b8595a66SAndreas Gohr if ($return) return $html; 174b8595a66SAndreas Gohr echo $html; 175ac7a515fSAndreas Gohr return ''; 176b8595a66SAndreas Gohr} 177b8595a66SAndreas Gohr 178b8595a66SAndreas Gohr/** 179c19fe9c0Sandi * Handle the admin page contents 180c19fe9c0Sandi * 18142ea7f44SGerrit Uitslag * @return bool 1824dc42f7fSGerrit Uitslag * 1834dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 184c19fe9c0Sandi */ 185d868eb89SAndreas Gohrfunction tpl_admin() 186d868eb89SAndreas Gohr{ 187f8cc712eSAndreas Gohr global $INFO; 188b8595a66SAndreas Gohr global $TOC; 189ac7a515fSAndreas Gohr global $INPUT; 19011e2ce22Schris 191b8595a66SAndreas Gohr $plugin = null; 192ac7a515fSAndreas Gohr $class = $INPUT->str('page'); 193ac7a515fSAndreas Gohr if (!empty($class)) { 19411e2ce22Schris $pluginlist = plugin_list('admin'); 19511e2ce22Schris 196ac7a515fSAndreas Gohr if (in_array($class, $pluginlist)) { 19711e2ce22Schris // attempt to load the plugin 1984dc42f7fSGerrit Uitslag /** @var AdminPlugin $plugin */ 199a04f2bd5SGerrit Uitslag $plugin = plugin_load('admin', $class); 20011e2ce22Schris } 20111e2ce22Schris } 20211e2ce22Schris 20324870174SAndreas Gohr if ($plugin instanceof PluginInterface) { 204b8595a66SAndreas Gohr if (!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet 205b8595a66SAndreas Gohr if ($INFO['prependTOC']) tpl_toc(); 206f8cc712eSAndreas Gohr $plugin->html(); 207f8cc712eSAndreas Gohr } else { 20824870174SAndreas Gohr $admin = new Admin(); 2090470c28fSAndreas Gohr $admin->show(); 210f8cc712eSAndreas Gohr } 21154e95700STom N Harris return true; 212c19fe9c0Sandi} 2136b13307fSandi 2146b13307fSandi/** 2156b13307fSandi * Print the correct HTML meta headers 2166b13307fSandi * 2176b13307fSandi * This has to go into the head section of your template. 2186b13307fSandi * 219ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added? 220ac7a515fSAndreas Gohr * @return bool 2214dc42f7fSGerrit Uitslag * @throws JsonException 2224dc42f7fSGerrit Uitslag * 2234dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 2244dc42f7fSGerrit Uitslag * @triggers TPL_METAHEADER_OUTPUT 2256b13307fSandi */ 226d868eb89SAndreas Gohrfunction tpl_metaheaders($alt = true) 227d868eb89SAndreas Gohr{ 2286b13307fSandi global $ID; 229d98d4540SBen Coburn global $REV; 2306b13307fSandi global $INFO; 23172e0dc37SAndreas Gohr global $JSINFO; 2326b13307fSandi global $ACT; 2334bb1b5aeSAndreas Gohr global $QUERY; 2346b13307fSandi global $lang; 235dc57ef04Sandi global $conf; 2369c438d6cSMichael Hamann global $updateVersion; 237585bf44eSChristopher Smith /** @var Input $INPUT */ 238585bf44eSChristopher Smith global $INPUT; 2396b13307fSandi 2407bff22c0SAndreas Gohr // prepare the head array 24124870174SAndreas Gohr $head = []; 2427bff22c0SAndreas Gohr 243202ac28bSMichael Klier // prepare seed for js and css 244cd997f93SAndreas Gohr $tseed = $updateVersion; 245202ac28bSMichael Klier $depends = getConfigFiles('main'); 24684e76a7eSAndreas Gohr $depends[] = DOKU_CONF . "tpl/" . $conf['template'] . "/style.ini"; 247cd997f93SAndreas Gohr foreach ($depends as $f) $tseed .= @filemtime($f); 248cd997f93SAndreas Gohr $tseed = md5($tseed); 2497bff22c0SAndreas Gohr 2506b13307fSandi // the usual stuff 25124870174SAndreas Gohr $head['meta'][] = ['name' => 'generator', 'content' => 'DokuWiki']; 25263cf4192Ssarehag if (actionOK('search')) { 25324870174SAndreas Gohr $head['link'][] = [ 25424870174SAndreas Gohr 'rel' => 'search', 25524870174SAndreas Gohr 'type' => 'application/opensearchdescription+xml', 25624870174SAndreas Gohr 'href' => DOKU_BASE . 'lib/exe/opensearch.php', 25724870174SAndreas Gohr 'title' => $conf['title'] 25824870174SAndreas Gohr ]; 25963cf4192Ssarehag } 26063cf4192Ssarehag 26124870174SAndreas Gohr $head['link'][] = ['rel' => 'start', 'href' => DOKU_BASE]; 2627aedde2eSGina Haeussge if (actionOK('index')) { 26324870174SAndreas Gohr $head['link'][] = [ 26424870174SAndreas Gohr 'rel' => 'contents', 26524870174SAndreas Gohr 'href' => wl($ID, 'do=index', false, '&'), 266ac7a515fSAndreas Gohr 'title' => $lang['btn_index'] 26724870174SAndreas Gohr ]; 2687aedde2eSGina Haeussge } 269f96fa415SAndreas Gohr 2705e0255e3SMichael Große if (actionOK('manifest')) { 27124870174SAndreas Gohr $head['link'][] = [ 27224870174SAndreas Gohr 'rel' => 'manifest', 2735ed7baceSAndreas Gohr 'href' => DOKU_BASE . 'lib/exe/manifest.php', 2745ed7baceSAndreas Gohr 'crossorigin' => 'use-credentials' // See issue #4322 27524870174SAndreas Gohr ]; 2765e0255e3SMichael Große } 2775e0255e3SMichael Große 27824870174SAndreas Gohr $styleUtil = new StyleUtils(); 2794593dbd2SAnna Dabrowska $styleIni = $styleUtil->cssStyleini(); 28040ca8540SMichael Große $replacements = $styleIni['replacements']; 28140ca8540SMichael Große if (!empty($replacements['__theme_color__'])) { 28224870174SAndreas Gohr $head['meta'][] = [ 28324870174SAndreas Gohr 'name' => 'theme-color', 28424870174SAndreas Gohr 'content' => $replacements['__theme_color__'] 28524870174SAndreas Gohr ]; 28640ca8540SMichael Große } 28740ca8540SMichael Große 288f96fa415SAndreas Gohr if ($alt) { 28954be1338SGerrit Uitslag if (actionOK('rss')) { 29024870174SAndreas Gohr $head['link'][] = [ 29124870174SAndreas Gohr 'rel' => 'alternate', 29224870174SAndreas Gohr 'type' => 'application/rss+xml', 29324870174SAndreas Gohr 'title' => $lang['btn_recent'], 29424870174SAndreas Gohr 'href' => DOKU_BASE . 'feed.php' 29524870174SAndreas Gohr ]; 29654be1338SGerrit Uitslag } 297c35f3875SAndreas Gohr if (($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 29824870174SAndreas Gohr $head['link'][] = [ 299ac7a515fSAndreas Gohr 'rel' => 'edit', 300715bdf1fSAndreas Gohr 'title' => $lang['btn_edit'], 301ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 30224870174SAndreas Gohr ]; 303c35f3875SAndreas Gohr } 304c35f3875SAndreas Gohr 30554be1338SGerrit Uitslag if (actionOK('rss') && $ACT == 'search') { 30624870174SAndreas Gohr $head['link'][] = [ 30724870174SAndreas Gohr 'rel' => 'alternate', 30824870174SAndreas Gohr 'type' => 'application/rss+xml', 309a1288caeSGerrit Uitslag 'title' => $lang['searchresult'], 310ac7a515fSAndreas Gohr 'href' => DOKU_BASE . 'feed.php?mode=search&q=' . $QUERY 31124870174SAndreas Gohr ]; 3124bb1b5aeSAndreas Gohr } 313bae36d94SAndreas Gohr 314bae36d94SAndreas Gohr if (actionOK('export_xhtml')) { 31524870174SAndreas Gohr $head['link'][] = [ 31624870174SAndreas Gohr 'rel' => 'alternate', 31724870174SAndreas Gohr 'type' => 'text/html', 31824870174SAndreas Gohr 'title' => $lang['plainhtml'], 319ac7a515fSAndreas Gohr 'href' => exportlink($ID, 'xhtml', '', false, '&') 32024870174SAndreas Gohr ]; 321bae36d94SAndreas Gohr } 322bae36d94SAndreas Gohr 323bae36d94SAndreas Gohr if (actionOK('export_raw')) { 32424870174SAndreas Gohr $head['link'][] = [ 32524870174SAndreas Gohr 'rel' => 'alternate', 32624870174SAndreas Gohr 'type' => 'text/plain', 32724870174SAndreas Gohr 'title' => $lang['wikimarkup'], 328ac7a515fSAndreas Gohr 'href' => exportlink($ID, 'raw', '', false, '&') 32924870174SAndreas Gohr ]; 330f96fa415SAndreas Gohr } 331bae36d94SAndreas Gohr } 3326b13307fSandi 33363f13cadSDamien Regad // setup robot tags appropriate for different modes 3344f2e0004STim Weber if (($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3356b13307fSandi if ($INFO['exists']) { 3366b13307fSandi //delay indexing: 337fb9fa88bSAndreas Gohr if ((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID)) { 33824870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow']; 3396b13307fSandi } else { 34024870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow']; 3416b13307fSandi } 34201f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 34301f9be51SAnika Henke if ($ID == $conf['start']) { 34401f9be51SAnika Henke $canonicalUrl = DOKU_URL; 34501f9be51SAnika Henke } 34624870174SAndreas Gohr $head['link'][] = ['rel' => 'canonical', 'href' => $canonicalUrl]; 3476b13307fSandi } else { 34824870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,follow']; 3496b13307fSandi } 3507a24876fSAndreas Gohr } elseif (defined('DOKU_MEDIADETAIL')) { 35124870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow']; 3526b13307fSandi } else { 35324870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow']; 3546b13307fSandi } 3556b13307fSandi 356831800b8SAndreas Gohr // set metadata 357831800b8SAndreas Gohr if ($ACT == 'show' || $ACT == 'export_xhtml') { 358831800b8SAndreas Gohr // keywords (explicit or implicit) 359bb4866bdSchris if (!empty($INFO['meta']['subject'])) { 36024870174SAndreas Gohr $head['meta'][] = ['name' => 'keywords', 'content' => implode(',', $INFO['meta']['subject'])]; 361831800b8SAndreas Gohr } else { 36224870174SAndreas Gohr $head['meta'][] = ['name' => 'keywords', 'content' => str_replace(':', ',', $ID)]; 363831800b8SAndreas Gohr } 364831800b8SAndreas Gohr } 365831800b8SAndreas Gohr 36678a6aeb1SAndreas Gohr // load stylesheets 36724870174SAndreas Gohr $head['link'][] = [ 36859305168SPhy 'rel' => 'stylesheet', 369e283bd6cSAnika Henke 'href' => DOKU_BASE . 'lib/exe/css.php?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed 37024870174SAndreas Gohr ]; 371bad31ae9SAndreas Gohr 372aac83cd4SPhy $script = "var NS='" . (isset($INFO) ? $INFO['namespace'] : '') . "';"; 373585bf44eSChristopher Smith if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 37498169a0fSAndreas Gohr $script .= "var SIG=" . toolbar_signature() . ";"; 375c591aabeSAndreas Gohr } 3760c39d46cSMichael Große jsinfo(); 37724870174SAndreas Gohr $script .= 'var JSINFO = ' . json_encode($JSINFO, JSON_THROW_ON_ERROR) . ';'; 378e0aa6775SAndreas Gohr $script .= '(function(H){H.className=H.className.replace(/\bno-js\b/,\'js\')})(document.documentElement);'; 37924870174SAndreas Gohr $head['script'][] = ['_data' => $script]; 3808bbcb611SAndreas Gohr 38161537d47SAndreas Gohr // load jquery 382fa078663SAndreas Gohr $jquery = getCdnUrls(); 383fa078663SAndreas Gohr foreach ($jquery as $src) { 38424870174SAndreas Gohr $head['script'][] = [ 385fc6b11d2SMichael Große '_data' => '', 38624870174SAndreas Gohr 'src' => $src 38724870174SAndreas Gohr ] + ($conf['defer_js'] ? ['defer' => 'defer'] : []); 38861537d47SAndreas Gohr } 38961537d47SAndreas Gohr 39061537d47SAndreas Gohr // load our javascript dispatcher 39124870174SAndreas Gohr $head['script'][] = [ 392de1dc35bSNicolas Friedli '_data' => '', 39324870174SAndreas Gohr 'src' => DOKU_BASE . 'lib/exe/js.php' . '?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed 39424870174SAndreas Gohr ] + ($conf['defer_js'] ? ['defer' => 'defer'] : []); 3957bff22c0SAndreas Gohr 3967bff22c0SAndreas Gohr // trigger event here 397cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 39854e95700STom N Harris return true; 3997bff22c0SAndreas Gohr} 4007bff22c0SAndreas Gohr 4017bff22c0SAndreas Gohr/** 4027bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4037bff22c0SAndreas Gohr * 4047bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4057bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4067bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4077bff22c0SAndreas Gohr * 40842ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4091304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4107bff22c0SAndreas Gohr * 411e5d413b0SAndreas Gohr * Inline scripts will use any nonce provided in the environment variable 'NONCE'. 412e5d413b0SAndreas Gohr * 41342ea7f44SGerrit Uitslag * @param array $data 4144dc42f7fSGerrit Uitslag * 4154dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 4167bff22c0SAndreas Gohr */ 417d868eb89SAndreas Gohrfunction _tpl_metaheaders_action($data) 418d868eb89SAndreas Gohr{ 419e5d413b0SAndreas Gohr $nonce = getenv('NONCE'); 4207bff22c0SAndreas Gohr foreach ($data as $tag => $inst) { 4217bff22c0SAndreas Gohr foreach ($inst as $attr) { 422177d6836SAndreas Gohr if (empty($attr)) { 423d4f83172SAndreas Gohr continue; 424d4f83172SAndreas Gohr } 425e5d413b0SAndreas Gohr if ($nonce && $tag == 'script' && !empty($attr['_data'])) { 426e5d413b0SAndreas Gohr $attr['nonce'] = $nonce; // add nonce to inline script tags 427e5d413b0SAndreas Gohr } 4287bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 42926afa874SMikhail I. Izmestev if (isset($attr['_data']) || $tag == 'script') { 43024870174SAndreas Gohr echo '>', $attr['_data'] ?? '', '</', $tag, '>'; 4317bff22c0SAndreas Gohr } else { 4327bff22c0SAndreas Gohr echo '/>'; 4337bff22c0SAndreas Gohr } 4347bff22c0SAndreas Gohr echo "\n"; 4357bff22c0SAndreas Gohr } 4367bff22c0SAndreas Gohr } 4376b13307fSandi} 4386b13307fSandi 4396b13307fSandi/** 440a77ab274SAndreas Gohr * Output the given script as inline script tag 441a77ab274SAndreas Gohr * 442a77ab274SAndreas Gohr * This function will add the nonce attribute if a nonce is available. 443a77ab274SAndreas Gohr * 444a77ab274SAndreas Gohr * The script is NOT automatically escaped! 445a77ab274SAndreas Gohr * 446a77ab274SAndreas Gohr * @param string $script 447a77ab274SAndreas Gohr * @param bool $return Return or print directly? 448a77ab274SAndreas Gohr * @return string|void 449a77ab274SAndreas Gohr */ 450a77ab274SAndreas Gohrfunction tpl_inlineScript($script, $return = false) 451a77ab274SAndreas Gohr{ 452a77ab274SAndreas Gohr $nonce = getenv('NONCE'); 453a77ab274SAndreas Gohr if ($nonce) { 454a77ab274SAndreas Gohr $script = '<script nonce="' . $nonce . '">' . $script . '</script>'; 455a77ab274SAndreas Gohr } else { 456a77ab274SAndreas Gohr $script = '<script>' . $script . '</script>'; 457a77ab274SAndreas Gohr } 458a77ab274SAndreas Gohr 459a77ab274SAndreas Gohr if ($return) return $script; 460a77ab274SAndreas Gohr echo $script; 461a77ab274SAndreas Gohr} 462a77ab274SAndreas Gohr 463a77ab274SAndreas Gohr/** 4646b13307fSandi * Print a link 4656b13307fSandi * 4665e163278SAndreas Gohr * Just builds a link. 4676b13307fSandi * 46842ea7f44SGerrit Uitslag * @param string $url 46942ea7f44SGerrit Uitslag * @param string $name 47042ea7f44SGerrit Uitslag * @param string $more 47121d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 47221d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4734dc42f7fSGerrit Uitslag * 4744dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 4756b13307fSandi */ 476d868eb89SAndreas Gohrfunction tpl_link($url, $name, $more = '', $return = false) 477d868eb89SAndreas Gohr{ 47801f17825SAnika Henke $out = '<a href="' . $url . '" '; 4791af98a77SAnika Henke if ($more) $out .= ' ' . $more; 4801af98a77SAnika Henke $out .= ">$name</a>"; 4811af98a77SAnika Henke if ($return) return $out; 48226dfc232SAndreas Gohr echo $out; 48354e95700STom N Harris return true; 4846b13307fSandi} 4856b13307fSandi 4866b13307fSandi/** 48755efc227SAndreas Gohr * Prints a link to a WikiPage 48855efc227SAndreas Gohr * 48955efc227SAndreas Gohr * Wrapper around html_wikilink 49055efc227SAndreas Gohr * 49142ea7f44SGerrit Uitslag * @param string $id page id 49242ea7f44SGerrit Uitslag * @param string|null $name the name of the link 493fb008d31SIain Hallam * @param bool $return 494fb008d31SIain Hallam * @return true|string 4954dc42f7fSGerrit Uitslag * 4964dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 49755efc227SAndreas Gohr */ 498d868eb89SAndreas Gohrfunction tpl_pagelink($id, $name = null, $return = false) 499d868eb89SAndreas Gohr{ 500c4a386f1SIain Hallam $out = '<bdi>' . html_wikilink($id, $name) . '</bdi>'; 501c4a386f1SIain Hallam if ($return) return $out; 50226dfc232SAndreas Gohr echo $out; 50354e95700STom N Harris return true; 50455efc227SAndreas Gohr} 50555efc227SAndreas Gohr 50655efc227SAndreas Gohr/** 507a3ec5f4aSmatthiasgrimm * get the parent page 508a3ec5f4aSmatthiasgrimm * 509a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 510a3ec5f4aSmatthiasgrimm * returns false if none is available 511a3ec5f4aSmatthiasgrimm * 51242ea7f44SGerrit Uitslag * @param string $id page id 51342ea7f44SGerrit Uitslag * @return false|string 5144dc42f7fSGerrit Uitslag * 5154dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 516a3ec5f4aSmatthiasgrimm */ 517d868eb89SAndreas Gohrfunction tpl_getparent($id) 518d868eb89SAndreas Gohr{ 5198c6be208SAndreas Gohr $resolver = new PageResolver('root'); 5208c6be208SAndreas Gohr 521377f9e97SAndreas Gohr $parent = getNS($id) . ':'; 5228c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 523a197105eSmatthiasgrimm if ($parent == $id) { 524a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 525a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos) . ':'; 5268c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 527377f9e97SAndreas Gohr if ($parent == $id) return false; 528a197105eSmatthiasgrimm } 529377f9e97SAndreas Gohr return $parent; 530a3ec5f4aSmatthiasgrimm} 531a3ec5f4aSmatthiasgrimm 532a3ec5f4aSmatthiasgrimm/** 5336b13307fSandi * Print one of the buttons 5346b13307fSandi * 535e0c26282SGerrit Uitslag * @param string $type 536e0c26282SGerrit Uitslag * @param bool $return 537e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 5384dc42f7fSGerrit Uitslag * @see tpl_get_action 5394dc42f7fSGerrit Uitslag * 5404dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de> 541affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 5426b13307fSandi */ 543d868eb89SAndreas Gohrfunction tpl_button($type, $return = false) 544d868eb89SAndreas Gohr{ 545affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 546a453d131SAdrian Lang $data = tpl_get_action($type); 547a453d131SAdrian Lang if ($data === false) { 548a453d131SAdrian Lang return false; 549a453d131SAdrian Lang } elseif (!is_array($data)) { 550a453d131SAdrian Lang $out = sprintf($data, 'button'); 551409d7af7SAndreas Gohr } else { 552ac7a515fSAndreas Gohr /** 553ac7a515fSAndreas Gohr * @var string $accesskey 554ac7a515fSAndreas Gohr * @var string $id 555ac7a515fSAndreas Gohr * @var string $method 556ac7a515fSAndreas Gohr * @var array $params 557ac7a515fSAndreas Gohr */ 558a453d131SAdrian Lang extract($data); 559a453d131SAdrian Lang if ($id === '#dokuwiki__top') { 560a453d131SAdrian Lang $out = html_topbtn(); 561409d7af7SAndreas Gohr } else { 562a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 563409d7af7SAndreas Gohr } 564409d7af7SAndreas Gohr } 5651af98a77SAnika Henke if ($return) return $out; 566a453d131SAdrian Lang echo $out; 567a453d131SAdrian Lang return true; 5686b13307fSandi} 5696b13307fSandi 5706b13307fSandi/** 571ed630903Sandi * Like the action buttons but links 572ed630903Sandi * 57342ea7f44SGerrit Uitslag * @param string $type action command 574e0c26282SGerrit Uitslag * @param string $pre prefix of link 575e0c26282SGerrit Uitslag * @param string $suf suffix of link 576e0c26282SGerrit Uitslag * @param string $inner innerHML of link 57721d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 578e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 5794dc42f7fSGerrit Uitslag * 5804dc42f7fSGerrit Uitslag * @see tpl_get_action 5814dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de> 582affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 583a453d131SAdrian Lang */ 584d868eb89SAndreas Gohrfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) 585d868eb89SAndreas Gohr{ 586affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 587a453d131SAdrian Lang global $lang; 588a453d131SAdrian Lang $data = tpl_get_action($type); 589a453d131SAdrian Lang if ($data === false) { 590a453d131SAdrian Lang return false; 591a453d131SAdrian Lang } elseif (!is_array($data)) { 592a453d131SAdrian Lang $out = sprintf($data, 'link'); 593a453d131SAdrian Lang } else { 594ac7a515fSAndreas Gohr /** 595ac7a515fSAndreas Gohr * @var string $accesskey 596ac7a515fSAndreas Gohr * @var string $id 597ac7a515fSAndreas Gohr * @var string $method 598b1af9014SChristopher Smith * @var bool $nofollow 599ac7a515fSAndreas Gohr * @var array $params 600becfa414SGerrit Uitslag * @var string $replacement 601ac7a515fSAndreas Gohr */ 602a453d131SAdrian Lang extract($data); 603093fe67eSAndreas Gohr if (str_starts_with($id, '#')) { 604a453d131SAdrian Lang $linktarget = $id; 605a453d131SAdrian Lang } else { 606a453d131SAdrian Lang $linktarget = wl($id, $params); 607a453d131SAdrian Lang } 608a453d131SAdrian Lang $caption = $lang['btn_' . $type]; 609becfa414SGerrit Uitslag if (strpos($caption, '%s')) { 610becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 611becfa414SGerrit Uitslag } 61224870174SAndreas Gohr $akey = ''; 61324870174SAndreas Gohr $addTitle = ''; 614c7e90e3fSAnika Henke if ($accesskey) { 615c7e90e3fSAnika Henke $akey = 'accesskey="' . $accesskey . '" '; 616c7e90e3fSAnika Henke $addTitle = ' [' . strtoupper($accesskey) . ']'; 617c7e90e3fSAnika Henke } 618b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 619ac7a515fSAndreas Gohr $out = tpl_link( 620dccd6b2bSAndreas Gohr $linktarget, 621dccd6b2bSAndreas Gohr $pre . ($inner ?: $caption) . $suf, 622a453d131SAdrian Lang 'class="action ' . $type . '" ' . 623b1af9014SChristopher Smith $akey . $rel . 624dccd6b2bSAndreas Gohr 'title="' . hsc($caption) . $addTitle . '"', 625dccd6b2bSAndreas Gohr true 626ac7a515fSAndreas Gohr ); 627a453d131SAdrian Lang } 628a453d131SAdrian Lang if ($return) return $out; 629a453d131SAdrian Lang echo $out; 630a453d131SAdrian Lang return true; 631a453d131SAdrian Lang} 632a453d131SAdrian Lang 633a453d131SAdrian Lang/** 634a453d131SAdrian Lang * Check the actions and get data for buttons and links 635ed630903Sandi * 636ac7a515fSAndreas Gohr * @param string $type 637ac7a515fSAndreas Gohr * @return array|bool|string 6384dc42f7fSGerrit Uitslag * 6394dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de> 6404dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 6414dc42f7fSGerrit Uitslag * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 642affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 643ed630903Sandi */ 644d868eb89SAndreas Gohrfunction tpl_get_action($type) 645d868eb89SAndreas Gohr{ 646affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 647a453d131SAdrian Lang if ($type == 'history') $type = 'revisions'; 6484c4b65c8SMichael Hamann if ($type == 'subscription') $type = 'subscribe'; 6494887c154SAndreas Gohr if ($type == 'img_backto') $type = 'imgBackto'; 650409d7af7SAndreas Gohr 6514887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 6524887c154SAndreas Gohr if (class_exists($class)) { 6534887c154SAndreas Gohr try { 65424870174SAndreas Gohr /** @var AbstractItem $item */ 65573022918SAndreas Gohr $item = new $class(); 6564887c154SAndreas Gohr $data = $item->getLegacyData(); 6577b4365a7SGerrit Uitslag $unknown = false; 658093fe67eSAndreas Gohr } catch (RuntimeException) { 6594887c154SAndreas Gohr return false; 660b8a111f5SMichael Klier } 661ed630903Sandi } else { 6624887c154SAndreas Gohr global $ID; 66324870174SAndreas Gohr $data = [ 6644887c154SAndreas Gohr 'accesskey' => null, 6654887c154SAndreas Gohr 'type' => $type, 6664887c154SAndreas Gohr 'id' => $ID, 6674887c154SAndreas Gohr 'method' => 'get', 66824870174SAndreas Gohr 'params' => ['do' => $type], 6694887c154SAndreas Gohr 'nofollow' => true, 67024870174SAndreas Gohr 'replacement' => '' 67124870174SAndreas Gohr ]; 6727b4365a7SGerrit Uitslag $unknown = true; 673ed630903Sandi } 6747b4365a7SGerrit Uitslag 675e1d9dcc8SAndreas Gohr $evt = new Event('TPL_ACTION_GET', $data); 6767b4365a7SGerrit Uitslag if ($evt->advise_before()) { 6777b4365a7SGerrit Uitslag //handle unknown types 6787b4365a7SGerrit Uitslag if ($unknown) { 67938d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6807b4365a7SGerrit Uitslag } 6817b4365a7SGerrit Uitslag } 6827b4365a7SGerrit Uitslag $evt->advise_after(); 6837b4365a7SGerrit Uitslag unset($evt); 6847b4365a7SGerrit Uitslag 6857b4365a7SGerrit Uitslag return $data; 686ed630903Sandi} 687ed630903Sandi 688ed630903Sandi/** 68901f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 69001f17825SAnika Henke * 69142ea7f44SGerrit Uitslag * @param string $type action command 692ac7a515fSAndreas Gohr * @param bool $link link or form button? 693e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 694ac7a515fSAndreas Gohr * @param bool $return return or print 695ac7a515fSAndreas Gohr * @param string $pre prefix for links 696ac7a515fSAndreas Gohr * @param string $suf suffix for links 697ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 698ac7a515fSAndreas Gohr * @return bool|string 6994dc42f7fSGerrit Uitslag * 7004dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 701affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 70201f17825SAnika Henke */ 703d868eb89SAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') 704d868eb89SAndreas Gohr{ 705affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 70601f17825SAnika Henke $out = ''; 707ac7a515fSAndreas Gohr if ($link) { 708e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 709ac7a515fSAndreas Gohr } else { 710e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 711ac7a515fSAndreas Gohr } 71201f17825SAnika Henke if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 71301f17825SAnika Henke 71401f17825SAnika Henke if ($return) return $out; 71526dfc232SAndreas Gohr echo $out; 71624870174SAndreas Gohr return (bool)$out; 71701f17825SAnika Henke} 71801f17825SAnika Henke 71901f17825SAnika Henke/** 7206b13307fSandi * Print the search form 7216b13307fSandi * 72272645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 72372645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 72472645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 72572645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 72672645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 72772645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 72872645b75SAndreas Gohr * 729ac7a515fSAndreas Gohr * @param bool $ajax 730ac7a515fSAndreas Gohr * @param bool $autocomplete 731ac7a515fSAndreas Gohr * @return bool 7324dc42f7fSGerrit Uitslag * 7334dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 7346b13307fSandi */ 735d868eb89SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) 736d868eb89SAndreas Gohr{ 7376b13307fSandi global $lang; 738c1e3b7d9Smatthiasgrimm global $ACT; 739ad4aaef7SAndreas Gohr global $QUERY; 740cbcc2fa5SMichael Große global $ID; 741c1e3b7d9Smatthiasgrimm 742670ff54eSchris // don't print the search form if search action has been disabled 74364276bbcSarbrk1 if (!actionOK('search')) return false; 744670ff54eSchris 74524870174SAndreas Gohr $searchForm = new Form([ 7463c7a3327SMichael Große 'action' => wl(), 7473c7a3327SMichael Große 'method' => 'get', 7483c7a3327SMichael Große 'role' => 'search', 7493c7a3327SMichael Große 'class' => 'search', 7503c7a3327SMichael Große 'id' => 'dw__search', 7517fa270bcSMichael Große ], true); 7523eb2b869SMichael Große $searchForm->addTagOpen('div')->addClass('no'); 7533c7a3327SMichael Große $searchForm->setHiddenField('do', 'search'); 754d22b78c8SMichael Große $searchForm->setHiddenField('id', $ID); 755d22b78c8SMichael Große $searchForm->addTextInput('q') 7563c7a3327SMichael Große ->addClass('edit') 7573c7a3327SMichael Große ->attrs([ 7583c7a3327SMichael Große 'title' => '[F]', 7593c7a3327SMichael Große 'accesskey' => 'f', 7603c7a3327SMichael Große 'placeholder' => $lang['btn_search'], 7613c7a3327SMichael Große 'autocomplete' => $autocomplete ? 'on' : 'off', 7623c7a3327SMichael Große ]) 7633c7a3327SMichael Große ->id('qsearch__in') 7643c7a3327SMichael Große ->val($ACT === 'search' ? $QUERY : '') 7654dc42f7fSGerrit Uitslag ->useInput(false); 7663c7a3327SMichael Große $searchForm->addButton('', $lang['btn_search'])->attrs([ 7673c7a3327SMichael Große 'type' => 'submit', 7683c7a3327SMichael Große 'title' => $lang['btn_search'], 7693c7a3327SMichael Große ]); 7703c7a3327SMichael Große if ($ajax) { 7713c7a3327SMichael Große $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup'); 7723c7a3327SMichael Große $searchForm->addTagClose('div'); 7733c7a3327SMichael Große } 7743eb2b869SMichael Große $searchForm->addTagClose('div'); 7753c7a3327SMichael Große 776c6977b3aSSatoshi Sahara echo $searchForm->toHTML('QuickSearch'); 7773c7a3327SMichael Große 77854e95700STom N Harris return true; 7796b13307fSandi} 7806b13307fSandi 7816b13307fSandi/** 7826b13307fSandi * Print the breadcrumbs trace 7836b13307fSandi * 784ac7a515fSAndreas Gohr * @param string $sep Separator between entries 785c4a386f1SIain Hallam * @param bool $return return or print 786c4a386f1SIain Hallam * @return bool|string 7874dc42f7fSGerrit Uitslag * 7884dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 7896b13307fSandi */ 790d868eb89SAndreas Gohrfunction tpl_breadcrumbs($sep = null, $return = false) 791d868eb89SAndreas Gohr{ 7926b13307fSandi global $lang; 7936b13307fSandi global $conf; 7946b13307fSandi 7956b13307fSandi //check if enabled 796359fab8bSMichael Hamann if (!$conf['breadcrumbs']) return false; 7976b13307fSandi 798c4a386f1SIain Hallam //set default 799c4a386f1SIain Hallam if (is_null($sep)) $sep = '•'; 800c4a386f1SIain Hallam 801c4a386f1SIain Hallam $out = ''; 802c4a386f1SIain Hallam 8036b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 804265e3787Sandi 8052979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">' . $sep . '</span> '; 806265e3787Sandi 80740eb54bbSjan //render crumbs, highlight the last one 808c4a386f1SIain Hallam $out .= '<span class="bchead">' . $lang['breadcrumb'] . '</span>'; 80940eb54bbSjan $last = count($crumbs); 81040eb54bbSjan $i = 0; 811a77f5846Sjan foreach ($crumbs as $id => $name) { 81240eb54bbSjan $i++; 813c4a386f1SIain Hallam $out .= $crumbs_sep; 814c4a386f1SIain Hallam if ($i == $last) $out .= '<span class="curid">'; 815c4a386f1SIain Hallam $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="' . $id . '"', true) . '</bdi>'; 816c4a386f1SIain Hallam if ($i == $last) $out .= '</span>'; 8176b13307fSandi } 818c4a386f1SIain Hallam if ($return) return $out; 81926dfc232SAndreas Gohr echo $out; 82024870174SAndreas Gohr return (bool)$out; 8216b13307fSandi} 8226b13307fSandi 8236b13307fSandi/** 8241734437eSandi * Hierarchical breadcrumbs 8251734437eSandi * 82631e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8271734437eSandi * It only makes sense with a deep site structure. 8281734437eSandi * 829ac7a515fSAndreas Gohr * @param string $sep Separator between entries 830c4a386f1SIain Hallam * @param bool $return return or print 831c4a386f1SIain Hallam * @return bool|string 8324dc42f7fSGerrit Uitslag * 8334dc42f7fSGerrit Uitslag * @todo May behave strangely in RTL languages 8344dc42f7fSGerrit Uitslag * @author <fredrik@averpil.com> 8354dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 8364dc42f7fSGerrit Uitslag * @author Nigel McNie <oracle.shinoda@gmail.com> 8374dc42f7fSGerrit Uitslag * @author Sean Coates <sean@caedmon.net> 8381734437eSandi */ 839d868eb89SAndreas Gohrfunction tpl_youarehere($sep = null, $return = false) 840d868eb89SAndreas Gohr{ 8411734437eSandi global $conf; 8421734437eSandi global $ID; 8431734437eSandi global $lang; 8441734437eSandi 84531e187f8SSean Coates // check if enabled 84654e95700STom N Harris if (!$conf['youarehere']) return false; 8471734437eSandi 848c4a386f1SIain Hallam //set default 849c4a386f1SIain Hallam if (is_null($sep)) $sep = ' » '; 850c4a386f1SIain Hallam 851c4a386f1SIain Hallam $out = ''; 852c4a386f1SIain Hallam 8531734437eSandi $parts = explode(':', $ID); 854796bafb3SAndreas Gohr $count = count($parts); 8551734437eSandi 856c4a386f1SIain Hallam $out .= '<span class="bchead">' . $lang['youarehere'] . ' </span>'; 8573940c519SMark 85808d7a575SAndreas Gohr // always print the startpage 859c4a386f1SIain Hallam $out .= '<span class="home">' . tpl_pagelink(':' . $conf['start'], null, true) . '</span>'; 860796bafb3SAndreas Gohr 861796bafb3SAndreas Gohr // print intermediate namespace links 862796bafb3SAndreas Gohr $part = ''; 863796bafb3SAndreas Gohr for ($i = 0; $i < $count - 1; $i++) { 864796bafb3SAndreas Gohr $part .= $parts[$i] . ':'; 865796bafb3SAndreas Gohr $page = $part; 866796bafb3SAndreas Gohr if ($page == $conf['start']) continue; // Skip startpage 867796bafb3SAndreas Gohr 86808d7a575SAndreas Gohr // output 869c4a386f1SIain Hallam $out .= $sep . tpl_pagelink($page, null, true); 87031e187f8SSean Coates } 8711734437eSandi 872796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 8738c6be208SAndreas Gohr if (isset($page)) { 8748c6be208SAndreas Gohr $page = (new PageResolver('root'))->resolveId($page); 8758c6be208SAndreas Gohr if ($page == $part . $parts[$i]) { 876a8c33dedSMichael Große if ($return) return $out; 87726dfc232SAndreas Gohr echo $out; 878a8c33dedSMichael Große return true; 879a8c33dedSMichael Große } 8808c6be208SAndreas Gohr } 881796bafb3SAndreas Gohr $page = $part . $parts[$i]; 882a8c33dedSMichael Große if ($page == $conf['start']) { 883a8c33dedSMichael Große if ($return) return $out; 88426dfc232SAndreas Gohr echo $out; 885a8c33dedSMichael Große return true; 886a8c33dedSMichael Große } 887c4a386f1SIain Hallam $out .= $sep; 888c4a386f1SIain Hallam $out .= tpl_pagelink($page, null, true); 889c4a386f1SIain Hallam if ($return) return $out; 89026dfc232SAndreas Gohr echo $out; 89124870174SAndreas Gohr return (bool)$out; 8921734437eSandi} 8931734437eSandi 8941734437eSandi/** 8956b13307fSandi * Print info if the user is logged in 896a2488c3cSMatthias Grimm * and show full name in that case 8976b13307fSandi * 8986b13307fSandi * Could be enhanced with a profile link in future? 8996b13307fSandi * 900ac7a515fSAndreas Gohr * @return bool 9014dc42f7fSGerrit Uitslag * 9024dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 9036b13307fSandi */ 904d868eb89SAndreas Gohrfunction tpl_userinfo() 905d868eb89SAndreas Gohr{ 9066b13307fSandi global $lang; 907585bf44eSChristopher Smith /** @var Input $INPUT */ 908585bf44eSChristopher Smith global $INPUT; 909585bf44eSChristopher Smith 910585bf44eSChristopher Smith if ($INPUT->server->str('REMOTE_USER')) { 91126dfc232SAndreas Gohr echo $lang['loggedinas'] . ' ' . userlink(); 91254e95700STom N Harris return true; 91354e95700STom N Harris } 91454e95700STom N Harris return false; 9156b13307fSandi} 9166b13307fSandi 9176b13307fSandi/** 9186b13307fSandi * Print some info about the current page 9196b13307fSandi * 920ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 921ac7a515fSAndreas Gohr * @return bool|string 9224dc42f7fSGerrit Uitslag * 9234dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 9246b13307fSandi */ 925d868eb89SAndreas Gohrfunction tpl_pageinfo($ret = false) 926d868eb89SAndreas Gohr{ 9276b13307fSandi global $conf; 9286b13307fSandi global $lang; 9296b13307fSandi global $INFO; 930c6e92a3cSDavid Lorentsen global $ID; 931c6e92a3cSDavid Lorentsen 932c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 933ac7a515fSAndreas Gohr if (!auth_quickaclcheck($ID)) { 934ac7a515fSAndreas Gohr return false; 935ac7a515fSAndreas Gohr } 9366b13307fSandi 9376b13307fSandi // prepare date and path 9386b13307fSandi $fn = $INFO['filepath']; 9396b13307fSandi if (!$conf['fullpath']) { 940613bca54SAndreas Gohr if ($INFO['rev']) { 941c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'] . '/', '', $fn); 9426b13307fSandi } else { 943c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'] . '/', '', $fn); 9446b13307fSandi } 9456b13307fSandi } 946bee6dc82Sandi $fn = utf8_decodeFN($fn); 9477370732eSSascha Leib $dateLocal = dformat($INFO['lastmod']); 9487370732eSSascha Leib $dateIso = date(DATE_ISO8601, $INFO['lastmod']); 9496b13307fSandi 950faecdfdfSAndreas Gohr // print it 951faecdfdfSAndreas Gohr if ($INFO['exists']) { 9524dc42f7fSGerrit Uitslag $out = '<bdi>' . $fn . '</bdi>'; 953e260f93bSAnika Henke $out .= ' · '; 9544b0d3916SAndreas Gohr $out .= $lang['lastmod']; 955fde860beSGerrit Uitslag $out .= ' '; 9567370732eSSascha Leib $out .= '<time datetime="' . $dateIso . '">' . $dateLocal . '</time>'; 9576b13307fSandi if ($INFO['editor']) { 9584b0d3916SAndreas Gohr $out .= ' ' . $lang['by'] . ' '; 959d317fb5dSAnika Henke $out .= '<bdi>' . editorinfo($INFO['editor']) . '</bdi>'; 9605aa52fafSBen Coburn } else { 9614b0d3916SAndreas Gohr $out .= ' (' . $lang['external_edit'] . ')'; 9626b13307fSandi } 9636b13307fSandi if ($INFO['locked']) { 964e260f93bSAnika Henke $out .= ' · '; 9654b0d3916SAndreas Gohr $out .= $lang['lockedby']; 966fde860beSGerrit Uitslag $out .= ' '; 967d317fb5dSAnika Henke $out .= '<bdi>' . editorinfo($INFO['locked']) . '</bdi>'; 9686b13307fSandi } 9694b0d3916SAndreas Gohr if ($ret) { 9704b0d3916SAndreas Gohr return $out; 9714b0d3916SAndreas Gohr } else { 9724b0d3916SAndreas Gohr echo $out; 97354e95700STom N Harris return true; 9746b13307fSandi } 9754b0d3916SAndreas Gohr } 97654e95700STom N Harris return false; 9776b13307fSandi} 9786b13307fSandi 979820fa24bSandi/** 980a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 98187c434ceSAndreas Gohr * 98287c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 983a6598f23SBen Coburn * the given ID is used. 98487c434ceSAndreas Gohr * 985ac7a515fSAndreas Gohr * @param string $id page id 986ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 987ac7a515fSAndreas Gohr * @return bool|string 9884dc42f7fSGerrit Uitslag * 9894dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 99087c434ceSAndreas Gohr */ 991d868eb89SAndreas Gohrfunction tpl_pagetitle($id = null, $ret = false) 992d868eb89SAndreas Gohr{ 9934dc42f7fSGerrit Uitslag global $ACT, $conf, $lang; 994fffeeafeSChristopher Smith 99587c434ceSAndreas Gohr if (is_null($id)) { 99687c434ceSAndreas Gohr global $ID; 99787c434ceSAndreas Gohr $id = $ID; 99887c434ceSAndreas Gohr } 99987c434ceSAndreas Gohr 100087c434ceSAndreas Gohr $name = $id; 1001fe9ec250SChris Smith if (useHeading('navigation')) { 1002fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 1003fffeeafeSChristopher Smith if ($first_heading) $name = $first_heading; 1004fffeeafeSChristopher Smith } 1005fffeeafeSChristopher Smith 1006fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 1007fffeeafeSChristopher Smith switch ($ACT) { 1008fffeeafeSChristopher Smith // admin functions 1009fffeeafeSChristopher Smith case 'admin': 1010fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 1011fffeeafeSChristopher Smith // try to get the plugin name 10124dc42f7fSGerrit Uitslag /** @var AdminPlugin $plugin */ 1013a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 1014c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 101524870174SAndreas Gohr $page_title = $plugin_title ?: $plugin->getPluginName(); 1016fffeeafeSChristopher Smith } 1017fffeeafeSChristopher Smith break; 1018fffeeafeSChristopher Smith 1019bcedcbabSAndreas Gohr // show action as title 1020fffeeafeSChristopher Smith case 'login': 1021fffeeafeSChristopher Smith case 'profile': 1022fffeeafeSChristopher Smith case 'register': 1023fffeeafeSChristopher Smith case 'resendpwd': 1024fffeeafeSChristopher Smith case 'index': 1025bcedcbabSAndreas Gohr case 'search': 1026fffeeafeSChristopher Smith $page_title = $lang['btn_' . $ACT]; 1027fffeeafeSChristopher Smith break; 1028bcedcbabSAndreas Gohr 1029bcedcbabSAndreas Gohr // add pen during editing 1030fffeeafeSChristopher Smith case 'edit': 10312f19acc2Sbleistivt case 'preview': 1032fffeeafeSChristopher Smith $page_title = "✎ " . $name; 1033fffeeafeSChristopher Smith break; 1034fffeeafeSChristopher Smith 1035bcedcbabSAndreas Gohr // add action to page name 1036fffeeafeSChristopher Smith case 'revisions': 1037fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 1038fffeeafeSChristopher Smith break; 1039fffeeafeSChristopher Smith 1040bcedcbabSAndreas Gohr // add action to page name 1041fffeeafeSChristopher Smith case 'backlink': 1042fffeeafeSChristopher Smith case 'recent': 1043fffeeafeSChristopher Smith case 'subscribe': 1044fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_' . $ACT]; 1045fffeeafeSChristopher Smith break; 1046fffeeafeSChristopher Smith 1047fffeeafeSChristopher Smith default: // SHOW and anything else not included 1048fffeeafeSChristopher Smith $page_title = $name; 104987c434ceSAndreas Gohr } 1050a6598f23SBen Coburn 1051a6598f23SBen Coburn if ($ret) { 1052fffeeafeSChristopher Smith return hsc($page_title); 1053a6598f23SBen Coburn } else { 105426dfc232SAndreas Gohr echo hsc($page_title); 105554e95700STom N Harris return true; 105687c434ceSAndreas Gohr } 1057a6598f23SBen Coburn} 1058340756e4Sandi 105955efc227SAndreas Gohr/** 106055efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 106155efc227SAndreas Gohr * 106255efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 106355efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 106455efc227SAndreas Gohr * 106555efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 106655efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 106755efc227SAndreas Gohr * to the names of the latter one) 106855efc227SAndreas Gohr * 10693df72098SAndreas Gohr * Only allowed in: detail.php 107055efc227SAndreas Gohr * 107121d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1072ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1073e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1074ac7a515fSAndreas Gohr * @return string 10754dc42f7fSGerrit Uitslag * 10764dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 107755efc227SAndreas Gohr */ 1078d868eb89SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) 1079d868eb89SAndreas Gohr{ 108055efc227SAndreas Gohr // Init Exif Reader 1081a46a7ce3Sasivery global $SRC, $imgMeta; 10823df72098SAndreas Gohr 10833df72098SAndreas Gohr if (is_null($src)) $src = $SRC; 10841eadd9e8SAndreas Gohr if (is_null($src)) return $alt; 10853df72098SAndreas Gohr 10864dc42f7fSGerrit Uitslag if (!isset($imgMeta)) { 10874dc42f7fSGerrit Uitslag $imgMeta = new JpegMeta($src); 10884dc42f7fSGerrit Uitslag } 1089a46a7ce3Sasivery if ($imgMeta === false) return $alt; 1090a46a7ce3Sasivery $info = cleanText($imgMeta->getField($tags)); 10914dc42f7fSGerrit Uitslag if (!$info) return $alt; 109255efc227SAndreas Gohr return $info; 109355efc227SAndreas Gohr} 109455efc227SAndreas Gohr 1095a46a7ce3Sasivery 1096a46a7ce3Sasivery/** 1097a46a7ce3Sasivery * Garbage collects up the open JpegMeta object. 1098a46a7ce3Sasivery */ 1099d868eb89SAndreas Gohrfunction tpl_img_close() 1100d868eb89SAndreas Gohr{ 1101a46a7ce3Sasivery global $imgMeta; 1102a46a7ce3Sasivery $imgMeta = null; 1103a46a7ce3Sasivery} 1104a46a7ce3Sasivery 110555efc227SAndreas Gohr/** 11064dc42f7fSGerrit Uitslag * Prints a html description list of the metatags of the current image 1107becfa414SGerrit Uitslag */ 1108d868eb89SAndreas Gohrfunction tpl_img_meta() 1109d868eb89SAndreas Gohr{ 1110becfa414SGerrit Uitslag global $lang; 1111becfa414SGerrit Uitslag 1112becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1113becfa414SGerrit Uitslag 1114becfa414SGerrit Uitslag echo '<dl>'; 1115becfa414SGerrit Uitslag foreach ($tags as $tag) { 1116becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1117fde860beSGerrit Uitslag if (!$label) $label = $tag['langkey'] . ':'; 1118becfa414SGerrit Uitslag 1119fde860beSGerrit Uitslag echo '<dt>' . $label . '</dt><dd>'; 1120becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1121becfa414SGerrit Uitslag echo dformat($tag['value']); 1122becfa414SGerrit Uitslag } else { 1123becfa414SGerrit Uitslag echo hsc($tag['value']); 1124becfa414SGerrit Uitslag } 1125becfa414SGerrit Uitslag echo '</dd>'; 1126becfa414SGerrit Uitslag } 1127becfa414SGerrit Uitslag echo '</dl>'; 1128becfa414SGerrit Uitslag} 1129becfa414SGerrit Uitslag 1130becfa414SGerrit Uitslag/** 1131becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1132becfa414SGerrit Uitslag * 1133becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1134becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1135becfa414SGerrit Uitslag * - string type type of value 1136becfa414SGerrit Uitslag * - string value tag value (unescaped) 1137becfa414SGerrit Uitslag */ 1138d868eb89SAndreas Gohrfunction tpl_get_img_meta() 1139d868eb89SAndreas Gohr{ 1140becfa414SGerrit Uitslag 1141becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1142becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 114379e79377SAndreas Gohr if (file_exists($config_file)) { 1144becfa414SGerrit Uitslag include($config_file); 1145becfa414SGerrit Uitslag } 1146becfa414SGerrit Uitslag } 114724870174SAndreas Gohr $tags = []; 1148becfa414SGerrit Uitslag foreach ($fields as $tag) { 114924870174SAndreas Gohr $t = []; 1150becfa414SGerrit Uitslag if (!empty($tag[0])) { 115124870174SAndreas Gohr $t = [$tag[0]]; 1152becfa414SGerrit Uitslag } 1153056bf31fSDamien Regad if (isset($tag[3]) && is_array($tag[3])) { 1154becfa414SGerrit Uitslag $t = array_merge($t, $tag[3]); 1155becfa414SGerrit Uitslag } 1156becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1157becfa414SGerrit Uitslag if ($value) { 115824870174SAndreas Gohr $tags[] = ['langkey' => $tag[1], 'type' => $tag[2], 'value' => $value]; 1159becfa414SGerrit Uitslag } 1160becfa414SGerrit Uitslag } 1161becfa414SGerrit Uitslag return $tags; 1162becfa414SGerrit Uitslag} 1163becfa414SGerrit Uitslag 1164becfa414SGerrit Uitslag/** 116555efc227SAndreas Gohr * Prints the image with a link to the full sized version 116655efc227SAndreas Gohr * 116755efc227SAndreas Gohr * Only allowed in: detail.php 1168a02d2933SAndreas Gohr * 1169ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 11704dc42f7fSGerrit Uitslag * @param int $maxwidth - maximal width of the image 11714dc42f7fSGerrit Uitslag * @param int $maxheight - maximal height of the image 11724dc42f7fSGerrit Uitslag * @param bool $link - link to the orginal size? 11734dc42f7fSGerrit Uitslag * @param array $params - additional image attributes 117442ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 117555efc227SAndreas Gohr */ 1176d868eb89SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) 1177d868eb89SAndreas Gohr{ 117855efc227SAndreas Gohr global $IMG; 1179585bf44eSChristopher Smith /** @var Input $INPUT */ 1180ac7a515fSAndreas Gohr global $INPUT; 11815c2eed9aSlisps global $REV; 118255efc227SAndreas Gohr 1183*dd9e8e5eSAndreas Gohr // rotation-aware bbox fit; returns [0, 0] for SVG / unreadable files 1184*dd9e8e5eSAndreas Gohr [$w, $h] = (new MediaFile($IMG, $REV))->getDisplayDimensions($maxwidth, $maxheight, false); 118555efc227SAndreas Gohr 11866de3759aSAndreas Gohr //prepare URLs 1187*dd9e8e5eSAndreas Gohr $srcParams = ['cache' => $INPUT->str('cache'), 'rev' => $REV]; 1188*dd9e8e5eSAndreas Gohr if ($maxwidth) $srcParams['w'] = $maxwidth; 1189*dd9e8e5eSAndreas Gohr if ($maxheight) $srcParams['h'] = $maxheight; 1190*dd9e8e5eSAndreas Gohr if ($maxwidth && $maxheight) $srcParams['fit'] = 1; 119124870174SAndreas Gohr $url = ml($IMG, ['cache' => $INPUT->str('cache'), 'rev' => $REV], true, '&'); 1192*dd9e8e5eSAndreas Gohr $src = ml($IMG, $srcParams, true, '&'); 119355efc227SAndreas Gohr 11942684e50aSAndreas Gohr //prepare attributes 119555efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1196a02d2933SAndreas Gohr if (is_null($params)) { 119724870174SAndreas Gohr $p = []; 1198a02d2933SAndreas Gohr } else { 1199a02d2933SAndreas Gohr $p = $params; 1200a02d2933SAndreas Gohr } 12012684e50aSAndreas Gohr if ($w) $p['width'] = $w; 12022684e50aSAndreas Gohr if ($h) $p['height'] = $h; 12032684e50aSAndreas Gohr $p['class'] = 'img_detail'; 12042684e50aSAndreas Gohr if ($alt) { 12052684e50aSAndreas Gohr $p['alt'] = $alt; 12062684e50aSAndreas Gohr $p['title'] = $alt; 12072684e50aSAndreas Gohr } else { 12082684e50aSAndreas Gohr $p['alt'] = ''; 12092684e50aSAndreas Gohr } 1210a02d2933SAndreas Gohr $p['src'] = $src; 121155efc227SAndreas Gohr 121224870174SAndreas Gohr $data = ['url' => ($link ? $url : null), 'params' => $p]; 1213cbb44eabSAndreas Gohr return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1214a02d2933SAndreas Gohr} 1215a02d2933SAndreas Gohr 1216a02d2933SAndreas Gohr/** 1217a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1218ac7a515fSAndreas Gohr * 1219ac7a515fSAndreas Gohr * @param array $data 1220ac7a515fSAndreas Gohr * @return bool 1221a02d2933SAndreas Gohr */ 1222d868eb89SAndreas Gohrfunction _tpl_img_action($data) 1223d868eb89SAndreas Gohr{ 122459f3611bSAnika Henke global $lang; 1225a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1226a02d2933SAndreas Gohr 122726dfc232SAndreas Gohr if ($data['url']) echo '<a href="' . hsc($data['url']) . '" title="' . $lang['mediaview'] . '">'; 122826dfc232SAndreas Gohr echo '<img ' . $p . '/>'; 122926dfc232SAndreas Gohr if ($data['url']) echo '</a>'; 123054e95700STom N Harris return true; 123155efc227SAndreas Gohr} 123255efc227SAndreas Gohr 12337367b368SAndreas Gohr/** 1234881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 12357367b368SAndreas Gohr * 12364dc42f7fSGerrit Uitslag * Should be called somewhere at the very end of the main.php template 1237ac7a515fSAndreas Gohr * 1238ac7a515fSAndreas Gohr * @return bool 12397367b368SAndreas Gohr */ 1240d868eb89SAndreas Gohrfunction tpl_indexerWebBug() 1241d868eb89SAndreas Gohr{ 12427367b368SAndreas Gohr global $ID; 12431dad36f5SAndreas Gohr 124424870174SAndreas Gohr $p = []; 12454af80fe8SMichael Große $p['src'] = DOKU_BASE . 'lib/exe/taskrunner.php?id=' . rawurlencode($ID) . 1246e68c51baSAndreas Gohr '&' . time(); 1247881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 12487367b368SAndreas Gohr $p['height'] = 1; 12497367b368SAndreas Gohr $p['alt'] = ''; 12507367b368SAndreas Gohr $att = buildAttributes($p); 125126dfc232SAndreas Gohr echo "<img $att />"; 125254e95700STom N Harris return true; 12537367b368SAndreas Gohr} 12547367b368SAndreas Gohr 125578d4e784SEsther Brunner/** 125678d4e784SEsther Brunner * tpl_getConf($id) 125778d4e784SEsther Brunner * 125878d4e784SEsther Brunner * use this function to access template configuration variables 1259ac7a515fSAndreas Gohr * 126017448fb8SChristopher Smith * @param string $id name of the value to access 126117448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 126217448fb8SChristopher Smith * @return mixed 126378d4e784SEsther Brunner */ 1264d868eb89SAndreas Gohrfunction tpl_getConf($id, $notset = false) 1265d868eb89SAndreas Gohr{ 126678d4e784SEsther Brunner global $conf; 126717566ac6SAdrian Lang static $tpl_configloaded = false; 126878d4e784SEsther Brunner 126978d4e784SEsther Brunner $tpl = $conf['template']; 127078d4e784SEsther Brunner 127178d4e784SEsther Brunner if (!$tpl_configloaded) { 127278d4e784SEsther Brunner $tconf = tpl_loadConfig(); 127378d4e784SEsther Brunner if ($tconf !== false) { 127478d4e784SEsther Brunner foreach ($tconf as $key => $value) { 127578d4e784SEsther Brunner if (isset($conf['tpl'][$tpl][$key])) continue; 127678d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 127778d4e784SEsther Brunner } 127878d4e784SEsther Brunner $tpl_configloaded = true; 127978d4e784SEsther Brunner } 128078d4e784SEsther Brunner } 128178d4e784SEsther Brunner 128224870174SAndreas Gohr return $conf['tpl'][$tpl][$id] ?? $notset; 128317448fb8SChristopher Smith} 128417448fb8SChristopher Smith 128578d4e784SEsther Brunner/** 128678d4e784SEsther Brunner * tpl_loadConfig() 1287ac7a515fSAndreas Gohr * 128878d4e784SEsther Brunner * reads all template configuration variables 128978d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1290ac7a515fSAndreas Gohr * 12914dc42f7fSGerrit Uitslag * @return false|array 129278d4e784SEsther Brunner */ 1293d868eb89SAndreas Gohrfunction tpl_loadConfig() 1294d868eb89SAndreas Gohr{ 129578d4e784SEsther Brunner 1296c4766956SAndreas Gohr $file = tpl_incdir() . '/conf/default.php'; 129724870174SAndreas Gohr $conf = []; 129878d4e784SEsther Brunner 129979e79377SAndreas Gohr if (!file_exists($file)) return false; 130078d4e784SEsther Brunner 130178d4e784SEsther Brunner // load default config file 130278d4e784SEsther Brunner include($file); 130378d4e784SEsther Brunner 130478d4e784SEsther Brunner return $conf; 130578d4e784SEsther Brunner} 130678d4e784SEsther Brunner 130717566ac6SAdrian Lang// language methods 13084dc42f7fSGerrit Uitslag 130917566ac6SAdrian Lang/** 131017566ac6SAdrian Lang * tpl_getLang($id) 131117566ac6SAdrian Lang * 131217566ac6SAdrian Lang * use this function to access template language variables 131342ea7f44SGerrit Uitslag * 131442ea7f44SGerrit Uitslag * @param string $id key of language string 131542ea7f44SGerrit Uitslag * @return string 131617566ac6SAdrian Lang */ 1317d868eb89SAndreas Gohrfunction tpl_getLang($id) 1318d868eb89SAndreas Gohr{ 131924870174SAndreas Gohr static $lang = []; 132017566ac6SAdrian Lang 132117566ac6SAdrian Lang if (count($lang) === 0) { 1322dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1323dd7a6159SGerrit Uitslag 1324c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 132517566ac6SAdrian Lang 132624870174SAndreas Gohr $lang = []; 132717566ac6SAdrian Lang 132817566ac6SAdrian Lang // don't include once 132917566ac6SAdrian Lang @include($path . 'en/lang.php'); 1330dd7a6159SGerrit Uitslag foreach ($config_cascade['lang']['template'] as $config_file) { 133179e79377SAndreas Gohr if (file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1332dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1333dd7a6159SGerrit Uitslag } 133417566ac6SAdrian Lang } 133517566ac6SAdrian Lang 1336dd7a6159SGerrit Uitslag if ($conf['lang'] != 'en') { 1337dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1338dd7a6159SGerrit Uitslag foreach ($config_cascade['lang']['template'] as $config_file) { 133979e79377SAndreas Gohr if (file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1340dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1341dd7a6159SGerrit Uitslag } 1342dd7a6159SGerrit Uitslag } 1343dd7a6159SGerrit Uitslag } 134417566ac6SAdrian Lang } 134524870174SAndreas Gohr return $lang[$id] ?? ''; 134617566ac6SAdrian Lang} 134717566ac6SAdrian Lang 13483df72098SAndreas Gohr/** 1349c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1350e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1351e8ec13b9SKlap-in * 1352e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1353e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1354e8ec13b9SKlap-in */ 1355d868eb89SAndreas Gohrfunction tpl_locale_xhtml($id) 1356d868eb89SAndreas Gohr{ 1357c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1358e8ec13b9SKlap-in} 1359e8ec13b9SKlap-in 1360e8ec13b9SKlap-in/** 1361c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 136242ea7f44SGerrit Uitslag * 136342ea7f44SGerrit Uitslag * @param string $id id of localized text 136442ea7f44SGerrit Uitslag * @return string wiki text 1365e8ec13b9SKlap-in */ 1366d868eb89SAndreas Gohrfunction tpl_localeFN($id) 1367d868eb89SAndreas Gohr{ 1368e8ec13b9SKlap-in $path = tpl_incdir() . 'lang/'; 1369e8ec13b9SKlap-in global $conf; 137038fb1fc7SGerrit Uitslag $file = DOKU_CONF . 'template_lang/' . $conf['template'] . '/' . $conf['lang'] . '/' . $id . '.txt'; 137179e79377SAndreas Gohr if (!file_exists($file)) { 1372e8ec13b9SKlap-in $file = $path . $conf['lang'] . '/' . $id . '.txt'; 137379e79377SAndreas Gohr if (!file_exists($file)) { 1374e8ec13b9SKlap-in //fall back to english 1375e8ec13b9SKlap-in $file = $path . 'en/' . $id . '.txt'; 1376e8ec13b9SKlap-in } 1377e8ec13b9SKlap-in } 1378e8ec13b9SKlap-in return $file; 1379e8ec13b9SKlap-in} 1380e8ec13b9SKlap-in 1381e8ec13b9SKlap-in/** 13827abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 13833df72098SAndreas Gohr * 13843df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13853df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13863df72098SAndreas Gohr * a message of referencing pages 13873df72098SAndreas Gohr * 13883df72098SAndreas Gohr * Only allowed in mediamanager.php 13893df72098SAndreas Gohr * 1390c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1391c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 139242ea7f44SGerrit Uitslag * @param string $sort 13938702de7fSGerrit Uitslag * 13943df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 13953df72098SAndreas Gohr */ 1396d868eb89SAndreas Gohrfunction tpl_mediaContent($fromajax = false, $sort = 'natural') 1397d868eb89SAndreas Gohr{ 13983df72098SAndreas Gohr global $IMG; 13993df72098SAndreas Gohr global $AUTH; 14003df72098SAndreas Gohr global $INUSE; 14013df72098SAndreas Gohr global $NS; 14023df72098SAndreas Gohr global $JUMPTO; 1403585bf44eSChristopher Smith /** @var Input $INPUT */ 1404ac7a515fSAndreas Gohr global $INPUT; 14053df72098SAndreas Gohr 1406ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 140724870174SAndreas Gohr if (in_array($do, ['save', 'cancel'])) $do = ''; 1408c182313eSAndreas Gohr 1409c182313eSAndreas Gohr if (!$do) { 1410ac7a515fSAndreas Gohr if ($INPUT->bool('edit')) { 1411c182313eSAndreas Gohr $do = 'metaform'; 1412c182313eSAndreas Gohr } elseif (is_array($INUSE)) { 1413c182313eSAndreas Gohr $do = 'filesinuse'; 1414c182313eSAndreas Gohr } else { 1415c182313eSAndreas Gohr $do = 'filelist'; 1416c182313eSAndreas Gohr } 1417c182313eSAndreas Gohr } 1418c182313eSAndreas Gohr 1419c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1420a664aabaSAndreas Gohr if (!$fromajax) echo '<div id="media__content">'; 142124870174SAndreas Gohr $data = ['do' => $do]; 1422e1d9dcc8SAndreas Gohr $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1423c182313eSAndreas Gohr if ($evt->advise_before()) { 1424c182313eSAndreas Gohr $do = $data['do']; 142530fd72fbSKate Arzamastseva if ($do == 'filesinuse') { 1426c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1427c182313eSAndreas Gohr } elseif ($do == 'filelist') { 142800e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO, false, $sort); 1429c9f56829SAndreas Gohr } elseif ($do == 'searchlist') { 1430ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1431c182313eSAndreas Gohr } else { 1432c182313eSAndreas Gohr msg('Unknown action ' . hsc($do), -1); 1433c182313eSAndreas Gohr } 1434c182313eSAndreas Gohr } 1435c182313eSAndreas Gohr $evt->advise_after(); 1436c182313eSAndreas Gohr unset($evt); 1437a664aabaSAndreas Gohr if (!$fromajax) echo '</div>'; 14383df72098SAndreas Gohr} 14393df72098SAndreas Gohr 14403df72098SAndreas Gohr/** 1441d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1442d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1443d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1444d9162c6cSKate Arzamastseva * 1445d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1446d9162c6cSKate Arzamastseva */ 1447d868eb89SAndreas Gohrfunction tpl_mediaFileList() 1448d868eb89SAndreas Gohr{ 1449d9162c6cSKate Arzamastseva global $AUTH; 1450d9162c6cSKate Arzamastseva global $NS; 1451d9162c6cSKate Arzamastseva global $JUMPTO; 145295b451bcSAdrian Lang global $lang; 1453585bf44eSChristopher Smith /** @var Input $INPUT */ 1454ac7a515fSAndreas Gohr global $INPUT; 1455d9162c6cSKate Arzamastseva 1456ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 145724870174SAndreas Gohr if (!$opened_tab || !in_array($opened_tab, ['files', 'upload', 'search'])) $opened_tab = 'files'; 1458ac7a515fSAndreas Gohr if ($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1459d9162c6cSKate Arzamastseva 146094add303SAnika Henke echo '<h2 class="a11y">' . $lang['mediaselect'] . '</h2>' . NL; 146195b451bcSAdrian Lang 1462ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 146323846a98SKate Arzamastseva 146494add303SAnika Henke echo '<div class="panelHeader">' . NL; 146595b451bcSAdrian Lang echo '<h3>'; 146624870174SAndreas Gohr $tabTitle = $NS ?: '[' . $lang['mediaroot'] . ']'; 1467c98f205eSAdrian Lang printf($lang['media_' . $opened_tab], '<strong>' . hsc($tabTitle) . '</strong>'); 146894add303SAnika Henke echo '</h3>' . NL; 146995b451bcSAdrian Lang if ($opened_tab === 'search' || $opened_tab === 'files') { 147095b451bcSAdrian Lang media_tab_files_options(); 147123846a98SKate Arzamastseva } 147294add303SAnika Henke echo '</div>' . NL; 1473d9162c6cSKate Arzamastseva 147494add303SAnika Henke echo '<div class="panelContent">' . NL; 147595b451bcSAdrian Lang if ($opened_tab == 'files') { 147695b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 147795b451bcSAdrian Lang } elseif ($opened_tab == 'upload') { 147895b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 147995b451bcSAdrian Lang } elseif ($opened_tab == 'search') { 148095b451bcSAdrian Lang media_tab_search($NS, $AUTH); 148195b451bcSAdrian Lang } 148294add303SAnika Henke echo '</div>' . NL; 1483d9162c6cSKate Arzamastseva} 1484d9162c6cSKate Arzamastseva 1485d9162c6cSKate Arzamastseva/** 1486d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1487d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1488d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1489d9162c6cSKate Arzamastseva * list of file revisions 1490d9162c6cSKate Arzamastseva * 1491f50a239bSTakamura * @param string $image 1492f50a239bSTakamura * @param boolean $rev 14934dc42f7fSGerrit Uitslag * 14944dc42f7fSGerrit Uitslag * @author Kate Arzamastseva <pshns@ukr.net> 1495d9162c6cSKate Arzamastseva */ 1496d868eb89SAndreas Gohrfunction tpl_mediaFileDetails($image, $rev) 1497d868eb89SAndreas Gohr{ 1498e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1499585bf44eSChristopher Smith /** @var Input $INPUT */ 1500585bf44eSChristopher Smith global $INPUT; 1501d9162c6cSKate Arzamastseva 150264159a61SAndreas Gohr $removed = ( 150364159a61SAndreas Gohr !file_exists(mediaFN($image)) && 150464159a61SAndreas Gohr file_exists(mediaMetaFN($image, '.changes')) && 150564159a61SAndreas Gohr $conf['mediarevisions'] 150664159a61SAndreas Gohr ); 1507ac7a515fSAndreas Gohr if (!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 15086dd095f5SKate Arzamastseva if ($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1509e8a2a143SMichael Hamann $ns = getNS($image); 1510ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 15111eeeced2SKate Arzamastseva 1512ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1513e5d185e1SKate Arzamastseva 151424870174SAndreas Gohr $tab_array = ['view']; 151524870174SAndreas Gohr [, $mime] = mimetype($image); 1516e5d185e1SKate Arzamastseva if ($mime == 'image/jpeg') { 1517e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1518e5d185e1SKate Arzamastseva } 1519e5d185e1SKate Arzamastseva if ($conf['mediarevisions']) { 1520e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1521e5d185e1SKate Arzamastseva } 1522e5d185e1SKate Arzamastseva 1523e5d185e1SKate Arzamastseva if (!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1524ac7a515fSAndreas Gohr if ($INPUT->bool('edit')) $opened_tab = 'edit'; 152523846a98SKate Arzamastseva if ($do == 'restore') $opened_tab = 'view'; 1526d9162c6cSKate Arzamastseva 1527ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 152823846a98SKate Arzamastseva 152959f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 153024870174SAndreas Gohr [$ext] = mimetype($image, false); 153195b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 153295b451bcSAdrian Lang $class = 'select mediafile mf_' . $class; 153324870174SAndreas Gohr 1534750a0b51SMichael Große $attributes = $rev ? ['rev' => $rev] : []; 153590fb952cSAndreas Gohr $tabTitle = sprintf( 153690fb952cSAndreas Gohr '<strong><a href="%s" class="%s" title="%s">%s</a></strong>', 153790fb952cSAndreas Gohr ml($image, $attributes), 153890fb952cSAndreas Gohr $class, 153990fb952cSAndreas Gohr $lang['mediaview'], 154090fb952cSAndreas Gohr $image 154190fb952cSAndreas Gohr ); 154208317413SAdrian Lang if ($opened_tab === 'view' && $rev) { 154308317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 154408317413SAdrian Lang } else { 1545026d14a9SAnika Henke printf($lang['media_' . $opened_tab], $tabTitle); 154608317413SAdrian Lang } 1547b8a84c03SAndreas Gohr 154894add303SAnika Henke echo '</h3></div>' . NL; 154995b451bcSAdrian Lang 155094add303SAnika Henke echo '<div class="panelContent">' . NL; 155195b451bcSAdrian Lang 155223846a98SKate Arzamastseva if ($opened_tab == 'view') { 1553e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 155492cac9a9SKate Arzamastseva } elseif ($opened_tab == 'edit' && !$removed) { 1555e8a2a143SMichael Hamann media_tab_edit($image, $ns); 1556e5d185e1SKate Arzamastseva } elseif ($opened_tab == 'history' && $conf['mediarevisions']) { 1557e8a2a143SMichael Hamann media_tab_history($image, $ns); 155823846a98SKate Arzamastseva } 155995b451bcSAdrian Lang 156094add303SAnika Henke echo '</div>' . NL; 1561d9162c6cSKate Arzamastseva} 1562d9162c6cSKate Arzamastseva 1563d9162c6cSKate Arzamastseva/** 15647abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 15653df72098SAndreas Gohr * 15663df72098SAndreas Gohr * Only allowed in mediamanager.php 15673df72098SAndreas Gohr * 15683df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15693df72098SAndreas Gohr */ 1570d868eb89SAndreas Gohrfunction tpl_mediaTree() 1571d868eb89SAndreas Gohr{ 15723df72098SAndreas Gohr global $NS; 1573a664aabaSAndreas Gohr echo '<div id="media__tree">'; 15743df72098SAndreas Gohr media_nstree($NS); 1575a664aabaSAndreas Gohr echo '</div>'; 15763df72098SAndreas Gohr} 15773df72098SAndreas Gohr 1578a00de5b5SAndreas Gohr/** 1579a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1580a00de5b5SAndreas Gohr * 1581a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1582a00de5b5SAndreas Gohr * 158342ea7f44SGerrit Uitslag * @param string $empty empty option label 158442ea7f44SGerrit Uitslag * @param string $button submit button label 15854dc42f7fSGerrit Uitslag * 15864dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 1587affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 1588a00de5b5SAndreas Gohr */ 1589d868eb89SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') 1590d868eb89SAndreas Gohr{ 1591affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 159224870174SAndreas Gohr $menu = new MobileMenu(); 15931e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1594a00de5b5SAndreas Gohr} 1595a00de5b5SAndreas Gohr 1596066fee30SAndreas Gohr/** 1597066fee30SAndreas Gohr * Print a informational line about the used license 1598066fee30SAndreas Gohr * 1599ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1600ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1601ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1602ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1603ac7a515fSAndreas Gohr * @return string 16044dc42f7fSGerrit Uitslag * 16054dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 1606066fee30SAndreas Gohr */ 1607d868eb89SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) 1608d868eb89SAndreas Gohr{ 1609066fee30SAndreas Gohr global $license; 1610066fee30SAndreas Gohr global $conf; 1611066fee30SAndreas Gohr global $lang; 1612066fee30SAndreas Gohr if (!$conf['license']) return ''; 1613066fee30SAndreas Gohr if (!is_array($license[$conf['license']])) return ''; 1614066fee30SAndreas Gohr $lic = $license[$conf['license']]; 161553e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="' . $conf['target']['extern'] . '"' : ''; 1616066fee30SAndreas Gohr 161780083a41SAndreas Gohr $out = ''; 161880083a41SAndreas Gohr if ($wrap) $out .= '<div class="license">'; 1619066fee30SAndreas Gohr if ($img) { 1620066fee30SAndreas Gohr $src = license_img($img); 1621066fee30SAndreas Gohr if ($src) { 162253e15c8bSAnika Henke $out .= '<a href="' . $lic['url'] . '" rel="license"' . $target; 162353e15c8bSAnika Henke $out .= '><img src="' . DOKU_BASE . $src . '" alt="' . $lic['name'] . '" /></a>'; 162453e15c8bSAnika Henke if (!$imgonly) $out .= ' '; 1625066fee30SAndreas Gohr } 1626066fee30SAndreas Gohr } 16274cefd216SMichael Klier if (!$imgonly) { 162853e15c8bSAnika Henke $out .= $lang['license'] . ' '; 1629d317fb5dSAnika Henke $out .= '<bdi><a href="' . $lic['url'] . '" rel="license" class="urlextern"' . $target; 1630d317fb5dSAnika Henke $out .= '>' . $lic['name'] . '</a></bdi>'; 16314cefd216SMichael Klier } 163280083a41SAndreas Gohr if ($wrap) $out .= '</div>'; 1633066fee30SAndreas Gohr 1634066fee30SAndreas Gohr if ($return) return $out; 1635066fee30SAndreas Gohr echo $out; 1636ac7a515fSAndreas Gohr return ''; 1637066fee30SAndreas Gohr} 1638066fee30SAndreas Gohr 1639a81910eeSAndreas Gohr/** 1640835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1641a81910eeSAndreas Gohr * 1642a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1643a81910eeSAndreas Gohr * template 1644e0c26282SGerrit Uitslag * 16457a112df5SAndreas Gohr * @param string $pageid The page name you want to include 16467a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 16477a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 16487c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1649e0c26282SGerrit Uitslag * @return bool|null|string 1650a81910eeSAndreas Gohr */ 1651d868eb89SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) 1652d868eb89SAndreas Gohr{ 16537a112df5SAndreas Gohr if ($propagate) { 16547c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 16557c3e4a67SAndreas Gohr } elseif ($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 16567a112df5SAndreas Gohr return false; 16577a112df5SAndreas Gohr } 1658c786a1b6SAnika Henke if (!$pageid) return false; 1659835dfcaeSAnika Henke 1660c786a1b6SAnika Henke global $TOC; 16619a2e250aSAndreas Gohr $oldtoc = $TOC; 1662a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 16639a2e250aSAndreas Gohr $TOC = $oldtoc; 1664a81910eeSAndreas Gohr 1665a2e03c82SAndreas Gohr if ($print) echo $html; 1666e66d3e6dSAndreas Gohr return $html; 1667e66d3e6dSAndreas Gohr} 1668e66d3e6dSAndreas Gohr 1669e66d3e6dSAndreas Gohr/** 16705b75cd1fSAdrian Lang * Display the subscribe form 16715b75cd1fSAdrian Lang * 16725b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 1673848cb786SSatoshi Sahara * @deprecated 2020-07-23 16745b75cd1fSAdrian Lang */ 1675d868eb89SAndreas Gohrfunction tpl_subscribe() 1676d868eb89SAndreas Gohr{ 167724870174SAndreas Gohr dbg_deprecated(Subscribe::class . '::show()'); 167873022918SAndreas Gohr (new Subscribe())->show(); 16795b75cd1fSAdrian Lang} 16805b75cd1fSAdrian Lang 1681d059ba9bSAndreas Gohr/** 1682d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1683d059ba9bSAndreas Gohr * 1684d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1685d059ba9bSAndreas Gohr * 1686d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1687d059ba9bSAndreas Gohr */ 1688d868eb89SAndreas Gohrfunction tpl_flush() 1689d868eb89SAndreas Gohr{ 1690c2009796SZemoj if (ob_get_level() > 0) ob_flush(); 1691d059ba9bSAndreas Gohr flush(); 1692d059ba9bSAndreas Gohr} 1693d059ba9bSAndreas Gohr 1694afca7e7eSAnika Henke/** 1695378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1696afca7e7eSAnika Henke * 1697378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1698378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1699378325f9SAndreas Gohr * 170042ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1701378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1702ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 17036dc405e1SAndreas Gohr * @param bool $fallback use fallback image if target isn't found or return 'false' if potential 17046dc405e1SAndreas Gohr * false result is required 1705ac7a515fSAndreas Gohr * @return string 170642ea7f44SGerrit Uitslag * 1707378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1708afca7e7eSAnika Henke */ 1709d868eb89SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) 1710d868eb89SAndreas Gohr{ 1711ac7a515fSAndreas Gohr $img = ''; 1712ac7a515fSAndreas Gohr $file = ''; 1713ac7a515fSAndreas Gohr $ismedia = false; 1714378325f9SAndreas Gohr // loop through candidates until a match was found: 1715378325f9SAndreas Gohr foreach ($search as $img) { 17166c16a3a9Sfiwswe if (str_starts_with($img, ':')) { 1717378325f9SAndreas Gohr $file = mediaFN($img); 1718378325f9SAndreas Gohr $ismedia = true; 1719378325f9SAndreas Gohr } else { 1720c4766956SAndreas Gohr $file = tpl_incdir() . $img; 1721378325f9SAndreas Gohr $ismedia = false; 17221f13e33dSAnika Henke } 17230f747863Slupo49 1724378325f9SAndreas Gohr if (file_exists($file)) break; 1725872a6d29SAnika Henke } 1726378325f9SAndreas Gohr 172708a13262SSimon DELAGE // manage non existing target 172808a13262SSimon DELAGE if (!file_exists($file)) { 172908a13262SSimon DELAGE // give result for fallback image 173024870174SAndreas Gohr if ($fallback) { 1731e44b94a4SAndreas Gohr $file = DOKU_INC . 'lib/images/blank.gif'; 173208a13262SSimon DELAGE // stop process if false result is required (if $fallback is false) 173308a13262SSimon DELAGE } else { 173408a13262SSimon DELAGE return false; 173508a13262SSimon DELAGE } 173608a13262SSimon DELAGE } 1737ca5b6a64SSimon DELAGE 1738378325f9SAndreas Gohr // fetch image data if requested 1739378325f9SAndreas Gohr if (!is_null($imginfo)) { 1740378325f9SAndreas Gohr $imginfo = getimagesize($file); 1741378325f9SAndreas Gohr } 1742378325f9SAndreas Gohr 1743378325f9SAndreas Gohr // build URL 1744378325f9SAndreas Gohr if ($ismedia) { 1745378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1746378325f9SAndreas Gohr } else { 1747c4766956SAndreas Gohr $url = tpl_basedir() . $img; 1748378325f9SAndreas Gohr if ($abs) $url = DOKU_URL . substr($url, strlen(DOKU_REL)); 1749378325f9SAndreas Gohr } 1750378325f9SAndreas Gohr 1751378325f9SAndreas Gohr return $url; 1752a7e5f74cSlupo49} 17531f13e33dSAnika Henke 1754872a6d29SAnika Henke/** 1755e5d4768dSAndreas Gohr * PHP include a file 1756e5d4768dSAndreas Gohr * 1757e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1758e5d4768dSAndreas Gohr * file in the template's root directory. 1759e5d4768dSAndreas Gohr * 1760e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1761e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1762e5d4768dSAndreas Gohr * default. 1763e5d4768dSAndreas Gohr * 1764e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1765e5d4768dSAndreas Gohr * to this function! 1766e5d4768dSAndreas Gohr * 176742ea7f44SGerrit Uitslag * @param string $file 17684dc42f7fSGerrit Uitslag * 17694dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 17704dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1771e5d4768dSAndreas Gohr */ 1772d868eb89SAndreas Gohrfunction tpl_includeFile($file) 1773d868eb89SAndreas Gohr{ 1774e5d4768dSAndreas Gohr global $config_cascade; 177524870174SAndreas Gohr foreach (['protected', 'local', 'default'] as $config_group) { 1776e5d4768dSAndreas Gohr if (empty($config_cascade['main'][$config_group])) continue; 1777e5d4768dSAndreas Gohr foreach ($config_cascade['main'][$config_group] as $conf_file) { 1778e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1779e5d4768dSAndreas Gohr if (file_exists("$dir/$file")) { 1780f3a1225fSAnika Henke include("$dir/$file"); 1781e5d4768dSAndreas Gohr return; 1782e5d4768dSAndreas Gohr } 1783e5d4768dSAndreas Gohr } 1784e5d4768dSAndreas Gohr } 1785e5d4768dSAndreas Gohr 1786e5d4768dSAndreas Gohr // still here? try the template dir 1787e5d4768dSAndreas Gohr $file = tpl_incdir() . $file; 1788e5d4768dSAndreas Gohr if (file_exists($file)) { 1789f3a1225fSAnika Henke include($file); 1790e5d4768dSAndreas Gohr } 1791e5d4768dSAndreas Gohr} 1792e5d4768dSAndreas Gohr 1793e5d4768dSAndreas Gohr/** 1794872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1795872a6d29SAnika Henke * 1796ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1797ac7a515fSAndreas Gohr * @return string 17984dc42f7fSGerrit Uitslag * 17994dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1800872a6d29SAnika Henke */ 1801d868eb89SAndreas Gohrfunction tpl_favicon($types = ['favicon']) 1802d868eb89SAndreas Gohr{ 1803872a6d29SAnika Henke 1804872a6d29SAnika Henke $return = ''; 1805872a6d29SAnika Henke 1806872a6d29SAnika Henke foreach ($types as $type) { 1807872a6d29SAnika Henke switch ($type) { 1808872a6d29SAnika Henke case 'favicon': 180924870174SAndreas Gohr $look = [':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico']; 1810378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="' . tpl_getMediaFile($look) . '" />' . NL; 1811872a6d29SAnika Henke break; 1812872a6d29SAnika Henke case 'mobile': 181324870174SAndreas Gohr $look = [':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png']; 1814378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="' . tpl_getMediaFile($look) . '" />' . NL; 1815872a6d29SAnika Henke break; 1816872a6d29SAnika Henke case 'generic': 1817872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 181824870174SAndreas Gohr $look = [':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg']; 1819378325f9SAndreas Gohr $return .= '<link rel="icon" href="' . tpl_getMediaFile($look) . '" type="image/svg+xml" />' . NL; 1820872a6d29SAnika Henke break; 1821872a6d29SAnika Henke } 1822872a6d29SAnika Henke } 1823872a6d29SAnika Henke 1824872a6d29SAnika Henke return $return; 1825afca7e7eSAnika Henke} 1826afca7e7eSAnika Henke 1827d9162c6cSKate Arzamastseva/** 1828d9162c6cSKate Arzamastseva * Prints full-screen media manager 1829d9162c6cSKate Arzamastseva * 1830d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1831d9162c6cSKate Arzamastseva */ 1832d868eb89SAndreas Gohrfunction tpl_media() 1833d868eb89SAndreas Gohr{ 1834ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 183588a71175SKate Arzamastseva $fullscreen = true; 183695b451bcSAdrian Lang require_once DOKU_INC . 'lib/exe/mediamanager.php'; 1837d9162c6cSKate Arzamastseva 1838ac7a515fSAndreas Gohr $rev = ''; 1839ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 184098f03b57SKate Arzamastseva if (isset($IMG)) $image = $IMG; 184198f03b57SKate Arzamastseva if (isset($JUMPTO)) $image = $JUMPTO; 18429c1bd4bcSKate Arzamastseva if (isset($REV) && !$JUMPTO) $rev = $REV; 184398f03b57SKate Arzamastseva 184494add303SAnika Henke echo '<div id="mediamanager__page">' . NL; 1845bc314c58SAnika Henke echo '<h1>' . $lang['btn_media'] . '</h1>' . NL; 1846d9162c6cSKate Arzamastseva html_msgarea(); 184794add303SAnika Henke 184894add303SAnika Henke echo '<div class="panel namespaces">' . NL; 184994add303SAnika Henke echo '<h2>' . $lang['namespaces'] . '</h2>' . NL; 185095b451bcSAdrian Lang echo '<div class="panelHeader">'; 1851ba340a70SAnika Henke echo $lang['media_namespaces']; 185294add303SAnika Henke echo '</div>' . NL; 185395b451bcSAdrian Lang 185494add303SAnika Henke echo '<div class="panelContent" id="media__tree">' . NL; 185595b451bcSAdrian Lang media_nstree($NS); 185694add303SAnika Henke echo '</div>' . NL; 185794add303SAnika Henke echo '</div>' . NL; 1858fa8e5c77SKate Arzamastseva 185994add303SAnika Henke echo '<div class="panel filelist">' . NL; 1860035e07f1SKate Arzamastseva tpl_mediaFileList(); 186194add303SAnika Henke echo '</div>' . NL; 1862fa8e5c77SKate Arzamastseva 186394add303SAnika Henke echo '<div class="panel file">' . NL; 186494add303SAnika Henke echo '<h2 class="a11y">' . $lang['media_file'] . '</h2>' . NL; 1865035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 186694add303SAnika Henke echo '</div>' . NL; 1867ba340a70SAnika Henke 186894add303SAnika Henke echo '</div>' . NL; 1869d9162c6cSKate Arzamastseva} 1870afca7e7eSAnika Henke 1871c71db656SAnika Henke/** 1872c71db656SAnika Henke * Return useful layout classes 1873c71db656SAnika Henke * 187442ea7f44SGerrit Uitslag * @return string 18754dc42f7fSGerrit Uitslag * 18764dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1877c71db656SAnika Henke */ 1878d868eb89SAndreas Gohrfunction tpl_classes() 1879d868eb89SAndreas Gohr{ 1880c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1881585bf44eSChristopher Smith /** @var Input $INPUT */ 1882585bf44eSChristopher Smith global $INPUT; 1883585bf44eSChristopher Smith 188424870174SAndreas Gohr $classes = [ 1885c71db656SAnika Henke 'dokuwiki', 1886c71db656SAnika Henke 'mode_' . $ACT, 1887c71db656SAnika Henke 'tpl_' . $conf['template'], 1888585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 188990eb1b7bSEduardo Mozart de Oliveira (isset($INFO['exists']) && $INFO['exists']) ? '' : 'notFound', 189024870174SAndreas Gohr ($ID == $conf['start']) ? 'home' : '' 189124870174SAndreas Gohr ]; 189224870174SAndreas Gohr return implode(' ', $classes); 1893c71db656SAnika Henke} 1894c71db656SAnika Henke 189584dd2b1aSGerrit Uitslag/** 189684dd2b1aSGerrit Uitslag * Create event for tools menues 189784dd2b1aSGerrit Uitslag * 189884dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 189984dd2b1aSGerrit Uitslag * @param array $items 190084dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 19014dc42f7fSGerrit Uitslag * 19024dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1903affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 190484dd2b1aSGerrit Uitslag */ 1905d868eb89SAndreas Gohrfunction tpl_toolsevent($toolsname, $items, $view = 'main') 1906d868eb89SAndreas Gohr{ 1907affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 190824870174SAndreas Gohr $data = ['view' => $view, 'items' => $items]; 190984dd2b1aSGerrit Uitslag 191084dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 1911e1d9dcc8SAndreas Gohr $evt = new Event($hook, $data); 191284dd2b1aSGerrit Uitslag if ($evt->advise_before()) { 191324870174SAndreas Gohr foreach ($evt->data['items'] as $html) echo $html; 191484dd2b1aSGerrit Uitslag } 191584dd2b1aSGerrit Uitslag $evt->advise_after(); 191684dd2b1aSGerrit Uitslag} 1917