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 ]; 29624870174SAndreas Gohr $head['link'][] = [ 29724870174SAndreas Gohr 'rel' => 'alternate', 29824870174SAndreas Gohr 'type' => 'application/rss+xml', 299a1288caeSGerrit Uitslag 'title' => $lang['currentns'], 300aac83cd4SPhy 'href' => DOKU_BASE . 'feed.php?mode=list&ns=' . (isset($INFO) ? $INFO['namespace'] : '') 30124870174SAndreas Gohr ]; 30254be1338SGerrit Uitslag } 303c35f3875SAndreas Gohr if (($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { 30424870174SAndreas Gohr $head['link'][] = [ 305ac7a515fSAndreas Gohr 'rel' => 'edit', 306715bdf1fSAndreas Gohr 'title' => $lang['btn_edit'], 307ac7a515fSAndreas Gohr 'href' => wl($ID, 'do=edit', false, '&') 30824870174SAndreas Gohr ]; 309c35f3875SAndreas Gohr } 310c35f3875SAndreas Gohr 31154be1338SGerrit Uitslag if (actionOK('rss') && $ACT == 'search') { 31224870174SAndreas Gohr $head['link'][] = [ 31324870174SAndreas Gohr 'rel' => 'alternate', 31424870174SAndreas Gohr 'type' => 'application/rss+xml', 315a1288caeSGerrit Uitslag 'title' => $lang['searchresult'], 316ac7a515fSAndreas Gohr 'href' => DOKU_BASE . 'feed.php?mode=search&q=' . $QUERY 31724870174SAndreas Gohr ]; 3184bb1b5aeSAndreas Gohr } 319bae36d94SAndreas Gohr 320bae36d94SAndreas Gohr if (actionOK('export_xhtml')) { 32124870174SAndreas Gohr $head['link'][] = [ 32224870174SAndreas Gohr 'rel' => 'alternate', 32324870174SAndreas Gohr 'type' => 'text/html', 32424870174SAndreas Gohr 'title' => $lang['plainhtml'], 325ac7a515fSAndreas Gohr 'href' => exportlink($ID, 'xhtml', '', false, '&') 32624870174SAndreas Gohr ]; 327bae36d94SAndreas Gohr } 328bae36d94SAndreas Gohr 329bae36d94SAndreas Gohr if (actionOK('export_raw')) { 33024870174SAndreas Gohr $head['link'][] = [ 33124870174SAndreas Gohr 'rel' => 'alternate', 33224870174SAndreas Gohr 'type' => 'text/plain', 33324870174SAndreas Gohr 'title' => $lang['wikimarkup'], 334ac7a515fSAndreas Gohr 'href' => exportlink($ID, 'raw', '', false, '&') 33524870174SAndreas Gohr ]; 336f96fa415SAndreas Gohr } 337bae36d94SAndreas Gohr } 3386b13307fSandi 33963f13cadSDamien Regad // setup robot tags appropriate for different modes 3404f2e0004STim Weber if (($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { 3416b13307fSandi if ($INFO['exists']) { 3426b13307fSandi //delay indexing: 343fb9fa88bSAndreas Gohr if ((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID)) { 34424870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow']; 3456b13307fSandi } else { 34624870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow']; 3476b13307fSandi } 34801f9be51SAnika Henke $canonicalUrl = wl($ID, '', true, '&'); 34901f9be51SAnika Henke if ($ID == $conf['start']) { 35001f9be51SAnika Henke $canonicalUrl = DOKU_URL; 35101f9be51SAnika Henke } 35224870174SAndreas Gohr $head['link'][] = ['rel' => 'canonical', 'href' => $canonicalUrl]; 3536b13307fSandi } else { 35424870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,follow']; 3556b13307fSandi } 3567a24876fSAndreas Gohr } elseif (defined('DOKU_MEDIADETAIL')) { 35724870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow']; 3586b13307fSandi } else { 35924870174SAndreas Gohr $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow']; 3606b13307fSandi } 3616b13307fSandi 362831800b8SAndreas Gohr // set metadata 363831800b8SAndreas Gohr if ($ACT == 'show' || $ACT == 'export_xhtml') { 364831800b8SAndreas Gohr // keywords (explicit or implicit) 365bb4866bdSchris if (!empty($INFO['meta']['subject'])) { 36624870174SAndreas Gohr $head['meta'][] = ['name' => 'keywords', 'content' => implode(',', $INFO['meta']['subject'])]; 367831800b8SAndreas Gohr } else { 36824870174SAndreas Gohr $head['meta'][] = ['name' => 'keywords', 'content' => str_replace(':', ',', $ID)]; 369831800b8SAndreas Gohr } 370831800b8SAndreas Gohr } 371831800b8SAndreas Gohr 37278a6aeb1SAndreas Gohr // load stylesheets 37324870174SAndreas Gohr $head['link'][] = [ 37459305168SPhy 'rel' => 'stylesheet', 375e283bd6cSAnika Henke 'href' => DOKU_BASE . 'lib/exe/css.php?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed 37624870174SAndreas Gohr ]; 377bad31ae9SAndreas Gohr 378aac83cd4SPhy $script = "var NS='" . (isset($INFO) ? $INFO['namespace'] : '') . "';"; 379585bf44eSChristopher Smith if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { 38098169a0fSAndreas Gohr $script .= "var SIG=" . toolbar_signature() . ";"; 381c591aabeSAndreas Gohr } 3820c39d46cSMichael Große jsinfo(); 38324870174SAndreas Gohr $script .= 'var JSINFO = ' . json_encode($JSINFO, JSON_THROW_ON_ERROR) . ';'; 384e0aa6775SAndreas Gohr $script .= '(function(H){H.className=H.className.replace(/\bno-js\b/,\'js\')})(document.documentElement);'; 38524870174SAndreas Gohr $head['script'][] = ['_data' => $script]; 3868bbcb611SAndreas Gohr 38761537d47SAndreas Gohr // load jquery 388fa078663SAndreas Gohr $jquery = getCdnUrls(); 389fa078663SAndreas Gohr foreach ($jquery as $src) { 39024870174SAndreas Gohr $head['script'][] = [ 391fc6b11d2SMichael Große '_data' => '', 39224870174SAndreas Gohr 'src' => $src 39324870174SAndreas Gohr ] + ($conf['defer_js'] ? ['defer' => 'defer'] : []); 39461537d47SAndreas Gohr } 39561537d47SAndreas Gohr 39661537d47SAndreas Gohr // load our javascript dispatcher 39724870174SAndreas Gohr $head['script'][] = [ 398de1dc35bSNicolas Friedli '_data' => '', 39924870174SAndreas Gohr 'src' => DOKU_BASE . 'lib/exe/js.php' . '?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed 40024870174SAndreas Gohr ] + ($conf['defer_js'] ? ['defer' => 'defer'] : []); 4017bff22c0SAndreas Gohr 4027bff22c0SAndreas Gohr // trigger event here 403cbb44eabSAndreas Gohr Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); 40454e95700STom N Harris return true; 4057bff22c0SAndreas Gohr} 4067bff22c0SAndreas Gohr 4077bff22c0SAndreas Gohr/** 4087bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders 4097bff22c0SAndreas Gohr * 4107bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple 4117bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML 4127bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array. 4137bff22c0SAndreas Gohr * 41442ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special 4151304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically. 4167bff22c0SAndreas Gohr * 417e5d413b0SAndreas Gohr * Inline scripts will use any nonce provided in the environment variable 'NONCE'. 418e5d413b0SAndreas Gohr * 41942ea7f44SGerrit Uitslag * @param array $data 4204dc42f7fSGerrit Uitslag * 4214dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 4227bff22c0SAndreas Gohr */ 423d868eb89SAndreas Gohrfunction _tpl_metaheaders_action($data) 424d868eb89SAndreas Gohr{ 425e5d413b0SAndreas Gohr $nonce = getenv('NONCE'); 4267bff22c0SAndreas Gohr foreach ($data as $tag => $inst) { 4277bff22c0SAndreas Gohr foreach ($inst as $attr) { 428177d6836SAndreas Gohr if (empty($attr)) { 429d4f83172SAndreas Gohr continue; 430d4f83172SAndreas Gohr } 431e5d413b0SAndreas Gohr if ($nonce && $tag == 'script' && !empty($attr['_data'])) { 432e5d413b0SAndreas Gohr $attr['nonce'] = $nonce; // add nonce to inline script tags 433e5d413b0SAndreas Gohr } 4347bff22c0SAndreas Gohr echo '<', $tag, ' ', buildAttributes($attr); 43526afa874SMikhail I. Izmestev if (isset($attr['_data']) || $tag == 'script') { 43624870174SAndreas Gohr echo '>', $attr['_data'] ?? '', '</', $tag, '>'; 4377bff22c0SAndreas Gohr } else { 4387bff22c0SAndreas Gohr echo '/>'; 4397bff22c0SAndreas Gohr } 4407bff22c0SAndreas Gohr echo "\n"; 4417bff22c0SAndreas Gohr } 4427bff22c0SAndreas Gohr } 4436b13307fSandi} 4446b13307fSandi 4456b13307fSandi/** 446a77ab274SAndreas Gohr * Output the given script as inline script tag 447a77ab274SAndreas Gohr * 448a77ab274SAndreas Gohr * This function will add the nonce attribute if a nonce is available. 449a77ab274SAndreas Gohr * 450a77ab274SAndreas Gohr * The script is NOT automatically escaped! 451a77ab274SAndreas Gohr * 452a77ab274SAndreas Gohr * @param string $script 453a77ab274SAndreas Gohr * @param bool $return Return or print directly? 454a77ab274SAndreas Gohr * @return string|void 455a77ab274SAndreas Gohr */ 456a77ab274SAndreas Gohrfunction tpl_inlineScript($script, $return = false) 457a77ab274SAndreas Gohr{ 458a77ab274SAndreas Gohr $nonce = getenv('NONCE'); 459a77ab274SAndreas Gohr if ($nonce) { 460a77ab274SAndreas Gohr $script = '<script nonce="' . $nonce . '">' . $script . '</script>'; 461a77ab274SAndreas Gohr } else { 462a77ab274SAndreas Gohr $script = '<script>' . $script . '</script>'; 463a77ab274SAndreas Gohr } 464a77ab274SAndreas Gohr 465a77ab274SAndreas Gohr if ($return) return $script; 466a77ab274SAndreas Gohr echo $script; 467a77ab274SAndreas Gohr} 468a77ab274SAndreas Gohr 469a77ab274SAndreas Gohr/** 4706b13307fSandi * Print a link 4716b13307fSandi * 4725e163278SAndreas Gohr * Just builds a link. 4736b13307fSandi * 47442ea7f44SGerrit Uitslag * @param string $url 47542ea7f44SGerrit Uitslag * @param string $name 47642ea7f44SGerrit Uitslag * @param string $more 47721d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print 47821d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed 4794dc42f7fSGerrit Uitslag * 4804dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 4816b13307fSandi */ 482d868eb89SAndreas Gohrfunction tpl_link($url, $name, $more = '', $return = false) 483d868eb89SAndreas Gohr{ 48401f17825SAnika Henke $out = '<a href="' . $url . '" '; 4851af98a77SAnika Henke if ($more) $out .= ' ' . $more; 4861af98a77SAnika Henke $out .= ">$name</a>"; 4871af98a77SAnika Henke if ($return) return $out; 48826dfc232SAndreas Gohr echo $out; 48954e95700STom N Harris return true; 4906b13307fSandi} 4916b13307fSandi 4926b13307fSandi/** 49355efc227SAndreas Gohr * Prints a link to a WikiPage 49455efc227SAndreas Gohr * 49555efc227SAndreas Gohr * Wrapper around html_wikilink 49655efc227SAndreas Gohr * 49742ea7f44SGerrit Uitslag * @param string $id page id 49842ea7f44SGerrit Uitslag * @param string|null $name the name of the link 499fb008d31SIain Hallam * @param bool $return 500fb008d31SIain Hallam * @return true|string 5014dc42f7fSGerrit Uitslag * 5024dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 50355efc227SAndreas Gohr */ 504d868eb89SAndreas Gohrfunction tpl_pagelink($id, $name = null, $return = false) 505d868eb89SAndreas Gohr{ 506c4a386f1SIain Hallam $out = '<bdi>' . html_wikilink($id, $name) . '</bdi>'; 507c4a386f1SIain Hallam if ($return) return $out; 50826dfc232SAndreas Gohr echo $out; 50954e95700STom N Harris return true; 51055efc227SAndreas Gohr} 51155efc227SAndreas Gohr 51255efc227SAndreas Gohr/** 513a3ec5f4aSmatthiasgrimm * get the parent page 514a3ec5f4aSmatthiasgrimm * 515a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent. 516a3ec5f4aSmatthiasgrimm * returns false if none is available 517a3ec5f4aSmatthiasgrimm * 51842ea7f44SGerrit Uitslag * @param string $id page id 51942ea7f44SGerrit Uitslag * @return false|string 5204dc42f7fSGerrit Uitslag * 5214dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 522a3ec5f4aSmatthiasgrimm */ 523d868eb89SAndreas Gohrfunction tpl_getparent($id) 524d868eb89SAndreas Gohr{ 5258c6be208SAndreas Gohr $resolver = new PageResolver('root'); 5268c6be208SAndreas Gohr 527377f9e97SAndreas Gohr $parent = getNS($id) . ':'; 5288c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 529a197105eSmatthiasgrimm if ($parent == $id) { 530a197105eSmatthiasgrimm $pos = strrpos(getNS($id), ':'); 531a197105eSmatthiasgrimm $parent = substr($parent, 0, $pos) . ':'; 5328c6be208SAndreas Gohr $parent = $resolver->resolveId($parent); 533377f9e97SAndreas Gohr if ($parent == $id) return false; 534a197105eSmatthiasgrimm } 535377f9e97SAndreas Gohr return $parent; 536a3ec5f4aSmatthiasgrimm} 537a3ec5f4aSmatthiasgrimm 538a3ec5f4aSmatthiasgrimm/** 5396b13307fSandi * Print one of the buttons 5406b13307fSandi * 541e0c26282SGerrit Uitslag * @param string $type 542e0c26282SGerrit Uitslag * @param bool $return 543e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed 5444dc42f7fSGerrit Uitslag * @see tpl_get_action 5454dc42f7fSGerrit Uitslag * 5464dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de> 547affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 5486b13307fSandi */ 549d868eb89SAndreas Gohrfunction tpl_button($type, $return = false) 550d868eb89SAndreas Gohr{ 551affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 552a453d131SAdrian Lang $data = tpl_get_action($type); 553a453d131SAdrian Lang if ($data === false) { 554a453d131SAdrian Lang return false; 555a453d131SAdrian Lang } elseif (!is_array($data)) { 556a453d131SAdrian Lang $out = sprintf($data, 'button'); 557409d7af7SAndreas Gohr } else { 558ac7a515fSAndreas Gohr /** 559ac7a515fSAndreas Gohr * @var string $accesskey 560ac7a515fSAndreas Gohr * @var string $id 561ac7a515fSAndreas Gohr * @var string $method 562ac7a515fSAndreas Gohr * @var array $params 563ac7a515fSAndreas Gohr */ 564a453d131SAdrian Lang extract($data); 565a453d131SAdrian Lang if ($id === '#dokuwiki__top') { 566a453d131SAdrian Lang $out = html_topbtn(); 567409d7af7SAndreas Gohr } else { 568a453d131SAdrian Lang $out = html_btn($type, $id, $accesskey, $params, $method); 569409d7af7SAndreas Gohr } 570409d7af7SAndreas Gohr } 5711af98a77SAnika Henke if ($return) return $out; 572a453d131SAdrian Lang echo $out; 573a453d131SAdrian Lang return true; 5746b13307fSandi} 5756b13307fSandi 5766b13307fSandi/** 577ed630903Sandi * Like the action buttons but links 578ed630903Sandi * 57942ea7f44SGerrit Uitslag * @param string $type action command 580e0c26282SGerrit Uitslag * @param string $pre prefix of link 581e0c26282SGerrit Uitslag * @param string $suf suffix of link 582e0c26282SGerrit Uitslag * @param string $inner innerHML of link 58321d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints 584e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed 5854dc42f7fSGerrit Uitslag * 5864dc42f7fSGerrit Uitslag * @see tpl_get_action 5874dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de> 588affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 589a453d131SAdrian Lang */ 590d868eb89SAndreas Gohrfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) 591d868eb89SAndreas Gohr{ 592affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 593a453d131SAdrian Lang global $lang; 594a453d131SAdrian Lang $data = tpl_get_action($type); 595a453d131SAdrian Lang if ($data === false) { 596a453d131SAdrian Lang return false; 597a453d131SAdrian Lang } elseif (!is_array($data)) { 598a453d131SAdrian Lang $out = sprintf($data, 'link'); 599a453d131SAdrian Lang } else { 600ac7a515fSAndreas Gohr /** 601ac7a515fSAndreas Gohr * @var string $accesskey 602ac7a515fSAndreas Gohr * @var string $id 603ac7a515fSAndreas Gohr * @var string $method 604b1af9014SChristopher Smith * @var bool $nofollow 605ac7a515fSAndreas Gohr * @var array $params 606becfa414SGerrit Uitslag * @var string $replacement 607ac7a515fSAndreas Gohr */ 608a453d131SAdrian Lang extract($data); 609093fe67eSAndreas Gohr if (str_starts_with($id, '#')) { 610a453d131SAdrian Lang $linktarget = $id; 611a453d131SAdrian Lang } else { 612a453d131SAdrian Lang $linktarget = wl($id, $params); 613a453d131SAdrian Lang } 614a453d131SAdrian Lang $caption = $lang['btn_' . $type]; 615becfa414SGerrit Uitslag if (strpos($caption, '%s')) { 616becfa414SGerrit Uitslag $caption = sprintf($caption, $replacement); 617becfa414SGerrit Uitslag } 61824870174SAndreas Gohr $akey = ''; 61924870174SAndreas Gohr $addTitle = ''; 620c7e90e3fSAnika Henke if ($accesskey) { 621c7e90e3fSAnika Henke $akey = 'accesskey="' . $accesskey . '" '; 622c7e90e3fSAnika Henke $addTitle = ' [' . strtoupper($accesskey) . ']'; 623c7e90e3fSAnika Henke } 624b1af9014SChristopher Smith $rel = $nofollow ? 'rel="nofollow" ' : ''; 625ac7a515fSAndreas Gohr $out = tpl_link( 626dccd6b2bSAndreas Gohr $linktarget, 627dccd6b2bSAndreas Gohr $pre . ($inner ?: $caption) . $suf, 628a453d131SAdrian Lang 'class="action ' . $type . '" ' . 629b1af9014SChristopher Smith $akey . $rel . 630dccd6b2bSAndreas Gohr 'title="' . hsc($caption) . $addTitle . '"', 631dccd6b2bSAndreas Gohr true 632ac7a515fSAndreas Gohr ); 633a453d131SAdrian Lang } 634a453d131SAdrian Lang if ($return) return $out; 635a453d131SAdrian Lang echo $out; 636a453d131SAdrian Lang return true; 637a453d131SAdrian Lang} 638a453d131SAdrian Lang 639a453d131SAdrian Lang/** 640a453d131SAdrian Lang * Check the actions and get data for buttons and links 641ed630903Sandi * 642ac7a515fSAndreas Gohr * @param string $type 643ac7a515fSAndreas Gohr * @return array|bool|string 6444dc42f7fSGerrit Uitslag * 6454dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de> 6464dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 6474dc42f7fSGerrit Uitslag * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 648affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 649ed630903Sandi */ 650d868eb89SAndreas Gohrfunction tpl_get_action($type) 651d868eb89SAndreas Gohr{ 652affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 653a453d131SAdrian Lang if ($type == 'history') $type = 'revisions'; 6544c4b65c8SMichael Hamann if ($type == 'subscription') $type = 'subscribe'; 6554887c154SAndreas Gohr if ($type == 'img_backto') $type = 'imgBackto'; 656409d7af7SAndreas Gohr 6574887c154SAndreas Gohr $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type); 6584887c154SAndreas Gohr if (class_exists($class)) { 6594887c154SAndreas Gohr try { 66024870174SAndreas Gohr /** @var AbstractItem $item */ 66173022918SAndreas Gohr $item = new $class(); 6624887c154SAndreas Gohr $data = $item->getLegacyData(); 6637b4365a7SGerrit Uitslag $unknown = false; 664093fe67eSAndreas Gohr } catch (RuntimeException) { 6654887c154SAndreas Gohr return false; 666b8a111f5SMichael Klier } 667ed630903Sandi } else { 6684887c154SAndreas Gohr global $ID; 66924870174SAndreas Gohr $data = [ 6704887c154SAndreas Gohr 'accesskey' => null, 6714887c154SAndreas Gohr 'type' => $type, 6724887c154SAndreas Gohr 'id' => $ID, 6734887c154SAndreas Gohr 'method' => 'get', 67424870174SAndreas Gohr 'params' => ['do' => $type], 6754887c154SAndreas Gohr 'nofollow' => true, 67624870174SAndreas Gohr 'replacement' => '' 67724870174SAndreas Gohr ]; 6787b4365a7SGerrit Uitslag $unknown = true; 679ed630903Sandi } 6807b4365a7SGerrit Uitslag 681e1d9dcc8SAndreas Gohr $evt = new Event('TPL_ACTION_GET', $data); 6827b4365a7SGerrit Uitslag if ($evt->advise_before()) { 6837b4365a7SGerrit Uitslag //handle unknown types 6847b4365a7SGerrit Uitslag if ($unknown) { 68538d2ca46SGerrit Uitslag $data = '[unknown %s type]'; 6867b4365a7SGerrit Uitslag } 6877b4365a7SGerrit Uitslag } 6887b4365a7SGerrit Uitslag $evt->advise_after(); 6897b4365a7SGerrit Uitslag unset($evt); 6907b4365a7SGerrit Uitslag 6917b4365a7SGerrit Uitslag return $data; 692ed630903Sandi} 693ed630903Sandi 694ed630903Sandi/** 69501f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink() 69601f17825SAnika Henke * 69742ea7f44SGerrit Uitslag * @param string $type action command 698ac7a515fSAndreas Gohr * @param bool $link link or form button? 699e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper 700ac7a515fSAndreas Gohr * @param bool $return return or print 701ac7a515fSAndreas Gohr * @param string $pre prefix for links 702ac7a515fSAndreas Gohr * @param string $suf suffix for links 703ac7a515fSAndreas Gohr * @param string $inner inner HTML for links 704ac7a515fSAndreas Gohr * @return bool|string 7054dc42f7fSGerrit Uitslag * 7064dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 707affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 70801f17825SAnika Henke */ 709d868eb89SAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') 710d868eb89SAndreas Gohr{ 711affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 71201f17825SAnika Henke $out = ''; 713ac7a515fSAndreas Gohr if ($link) { 714e0c26282SGerrit Uitslag $out .= tpl_actionlink($type, $pre, $suf, $inner, true); 715ac7a515fSAndreas Gohr } else { 716e0c26282SGerrit Uitslag $out .= tpl_button($type, true); 717ac7a515fSAndreas Gohr } 71801f17825SAnika Henke if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>"; 71901f17825SAnika Henke 72001f17825SAnika Henke if ($return) return $out; 72126dfc232SAndreas Gohr echo $out; 72224870174SAndreas Gohr return (bool)$out; 72301f17825SAnika Henke} 72401f17825SAnika Henke 72501f17825SAnika Henke/** 7266b13307fSandi * Print the search form 7276b13307fSandi * 72872645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will 72972645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place 73072645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary 73172645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an 73272645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in 73372645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox) 73472645b75SAndreas Gohr * 735ac7a515fSAndreas Gohr * @param bool $ajax 736ac7a515fSAndreas Gohr * @param bool $autocomplete 737ac7a515fSAndreas Gohr * @return bool 7384dc42f7fSGerrit Uitslag * 7394dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 7406b13307fSandi */ 741d868eb89SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) 742d868eb89SAndreas Gohr{ 7436b13307fSandi global $lang; 744c1e3b7d9Smatthiasgrimm global $ACT; 745ad4aaef7SAndreas Gohr global $QUERY; 746cbcc2fa5SMichael Große global $ID; 747c1e3b7d9Smatthiasgrimm 748670ff54eSchris // don't print the search form if search action has been disabled 74964276bbcSarbrk1 if (!actionOK('search')) return false; 750670ff54eSchris 75124870174SAndreas Gohr $searchForm = new Form([ 7523c7a3327SMichael Große 'action' => wl(), 7533c7a3327SMichael Große 'method' => 'get', 7543c7a3327SMichael Große 'role' => 'search', 7553c7a3327SMichael Große 'class' => 'search', 7563c7a3327SMichael Große 'id' => 'dw__search', 7577fa270bcSMichael Große ], true); 7583eb2b869SMichael Große $searchForm->addTagOpen('div')->addClass('no'); 7593c7a3327SMichael Große $searchForm->setHiddenField('do', 'search'); 760d22b78c8SMichael Große $searchForm->setHiddenField('id', $ID); 761d22b78c8SMichael Große $searchForm->addTextInput('q') 7623c7a3327SMichael Große ->addClass('edit') 7633c7a3327SMichael Große ->attrs([ 7643c7a3327SMichael Große 'title' => '[F]', 7653c7a3327SMichael Große 'accesskey' => 'f', 7663c7a3327SMichael Große 'placeholder' => $lang['btn_search'], 7673c7a3327SMichael Große 'autocomplete' => $autocomplete ? 'on' : 'off', 7683c7a3327SMichael Große ]) 7693c7a3327SMichael Große ->id('qsearch__in') 7703c7a3327SMichael Große ->val($ACT === 'search' ? $QUERY : '') 7714dc42f7fSGerrit Uitslag ->useInput(false); 7723c7a3327SMichael Große $searchForm->addButton('', $lang['btn_search'])->attrs([ 7733c7a3327SMichael Große 'type' => 'submit', 7743c7a3327SMichael Große 'title' => $lang['btn_search'], 7753c7a3327SMichael Große ]); 7763c7a3327SMichael Große if ($ajax) { 7773c7a3327SMichael Große $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup'); 7783c7a3327SMichael Große $searchForm->addTagClose('div'); 7793c7a3327SMichael Große } 7803eb2b869SMichael Große $searchForm->addTagClose('div'); 7813c7a3327SMichael Große 782c6977b3aSSatoshi Sahara echo $searchForm->toHTML('QuickSearch'); 7833c7a3327SMichael Große 78454e95700STom N Harris return true; 7856b13307fSandi} 7866b13307fSandi 7876b13307fSandi/** 7886b13307fSandi * Print the breadcrumbs trace 7896b13307fSandi * 790ac7a515fSAndreas Gohr * @param string $sep Separator between entries 791c4a386f1SIain Hallam * @param bool $return return or print 792c4a386f1SIain Hallam * @return bool|string 7934dc42f7fSGerrit Uitslag * 7944dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 7956b13307fSandi */ 796d868eb89SAndreas Gohrfunction tpl_breadcrumbs($sep = null, $return = false) 797d868eb89SAndreas Gohr{ 7986b13307fSandi global $lang; 7996b13307fSandi global $conf; 8006b13307fSandi 8016b13307fSandi //check if enabled 802359fab8bSMichael Hamann if (!$conf['breadcrumbs']) return false; 8036b13307fSandi 804c4a386f1SIain Hallam //set default 805c4a386f1SIain Hallam if (is_null($sep)) $sep = '•'; 806c4a386f1SIain Hallam 807c4a386f1SIain Hallam $out = ''; 808c4a386f1SIain Hallam 8096b13307fSandi $crumbs = breadcrumbs(); //setup crumb trace 810265e3787Sandi 8112979a10bSKatriel Traum $crumbs_sep = ' <span class="bcsep">' . $sep . '</span> '; 812265e3787Sandi 81340eb54bbSjan //render crumbs, highlight the last one 814c4a386f1SIain Hallam $out .= '<span class="bchead">' . $lang['breadcrumb'] . '</span>'; 81540eb54bbSjan $last = count($crumbs); 81640eb54bbSjan $i = 0; 817a77f5846Sjan foreach ($crumbs as $id => $name) { 81840eb54bbSjan $i++; 819c4a386f1SIain Hallam $out .= $crumbs_sep; 820c4a386f1SIain Hallam if ($i == $last) $out .= '<span class="curid">'; 821c4a386f1SIain Hallam $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="' . $id . '"', true) . '</bdi>'; 822c4a386f1SIain Hallam if ($i == $last) $out .= '</span>'; 8236b13307fSandi } 824c4a386f1SIain Hallam if ($return) return $out; 82526dfc232SAndreas Gohr echo $out; 82624870174SAndreas Gohr return (bool)$out; 8276b13307fSandi} 8286b13307fSandi 8296b13307fSandi/** 8301734437eSandi * Hierarchical breadcrumbs 8311734437eSandi * 83231e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs. 8331734437eSandi * It only makes sense with a deep site structure. 8341734437eSandi * 835ac7a515fSAndreas Gohr * @param string $sep Separator between entries 836c4a386f1SIain Hallam * @param bool $return return or print 837c4a386f1SIain Hallam * @return bool|string 8384dc42f7fSGerrit Uitslag * 8394dc42f7fSGerrit Uitslag * @todo May behave strangely in RTL languages 8404dc42f7fSGerrit Uitslag * @author <fredrik@averpil.com> 8414dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 8424dc42f7fSGerrit Uitslag * @author Nigel McNie <oracle.shinoda@gmail.com> 8434dc42f7fSGerrit Uitslag * @author Sean Coates <sean@caedmon.net> 8441734437eSandi */ 845d868eb89SAndreas Gohrfunction tpl_youarehere($sep = null, $return = false) 846d868eb89SAndreas Gohr{ 8471734437eSandi global $conf; 8481734437eSandi global $ID; 8491734437eSandi global $lang; 8501734437eSandi 85131e187f8SSean Coates // check if enabled 85254e95700STom N Harris if (!$conf['youarehere']) return false; 8531734437eSandi 854c4a386f1SIain Hallam //set default 855c4a386f1SIain Hallam if (is_null($sep)) $sep = ' » '; 856c4a386f1SIain Hallam 857c4a386f1SIain Hallam $out = ''; 858c4a386f1SIain Hallam 8591734437eSandi $parts = explode(':', $ID); 860796bafb3SAndreas Gohr $count = count($parts); 8611734437eSandi 862c4a386f1SIain Hallam $out .= '<span class="bchead">' . $lang['youarehere'] . ' </span>'; 8633940c519SMark 86408d7a575SAndreas Gohr // always print the startpage 865c4a386f1SIain Hallam $out .= '<span class="home">' . tpl_pagelink(':' . $conf['start'], null, true) . '</span>'; 866796bafb3SAndreas Gohr 867796bafb3SAndreas Gohr // print intermediate namespace links 868796bafb3SAndreas Gohr $part = ''; 869796bafb3SAndreas Gohr for ($i = 0; $i < $count - 1; $i++) { 870796bafb3SAndreas Gohr $part .= $parts[$i] . ':'; 871796bafb3SAndreas Gohr $page = $part; 872796bafb3SAndreas Gohr if ($page == $conf['start']) continue; // Skip startpage 873796bafb3SAndreas Gohr 87408d7a575SAndreas Gohr // output 875c4a386f1SIain Hallam $out .= $sep . tpl_pagelink($page, null, true); 87631e187f8SSean Coates } 8771734437eSandi 878796bafb3SAndreas Gohr // print current page, skipping start page, skipping for namespace index 8798c6be208SAndreas Gohr if (isset($page)) { 8808c6be208SAndreas Gohr $page = (new PageResolver('root'))->resolveId($page); 8818c6be208SAndreas Gohr if ($page == $part . $parts[$i]) { 882a8c33dedSMichael Große if ($return) return $out; 88326dfc232SAndreas Gohr echo $out; 884a8c33dedSMichael Große return true; 885a8c33dedSMichael Große } 8868c6be208SAndreas Gohr } 887796bafb3SAndreas Gohr $page = $part . $parts[$i]; 888a8c33dedSMichael Große if ($page == $conf['start']) { 889a8c33dedSMichael Große if ($return) return $out; 89026dfc232SAndreas Gohr echo $out; 891a8c33dedSMichael Große return true; 892a8c33dedSMichael Große } 893c4a386f1SIain Hallam $out .= $sep; 894c4a386f1SIain Hallam $out .= tpl_pagelink($page, null, true); 895c4a386f1SIain Hallam if ($return) return $out; 89626dfc232SAndreas Gohr echo $out; 89724870174SAndreas Gohr return (bool)$out; 8981734437eSandi} 8991734437eSandi 9001734437eSandi/** 9016b13307fSandi * Print info if the user is logged in 902a2488c3cSMatthias Grimm * and show full name in that case 9036b13307fSandi * 9046b13307fSandi * Could be enhanced with a profile link in future? 9056b13307fSandi * 906ac7a515fSAndreas Gohr * @return bool 9074dc42f7fSGerrit Uitslag * 9084dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 9096b13307fSandi */ 910d868eb89SAndreas Gohrfunction tpl_userinfo() 911d868eb89SAndreas Gohr{ 9126b13307fSandi global $lang; 913585bf44eSChristopher Smith /** @var Input $INPUT */ 914585bf44eSChristopher Smith global $INPUT; 915585bf44eSChristopher Smith 916585bf44eSChristopher Smith if ($INPUT->server->str('REMOTE_USER')) { 91726dfc232SAndreas Gohr echo $lang['loggedinas'] . ' ' . userlink(); 91854e95700STom N Harris return true; 91954e95700STom N Harris } 92054e95700STom N Harris return false; 9216b13307fSandi} 9226b13307fSandi 9236b13307fSandi/** 9246b13307fSandi * Print some info about the current page 9256b13307fSandi * 926ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it 927ac7a515fSAndreas Gohr * @return bool|string 9284dc42f7fSGerrit Uitslag * 9294dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 9306b13307fSandi */ 931d868eb89SAndreas Gohrfunction tpl_pageinfo($ret = false) 932d868eb89SAndreas Gohr{ 9336b13307fSandi global $conf; 9346b13307fSandi global $lang; 9356b13307fSandi global $INFO; 936c6e92a3cSDavid Lorentsen global $ID; 937c6e92a3cSDavid Lorentsen 938c6e92a3cSDavid Lorentsen // return if we are not allowed to view the page 939ac7a515fSAndreas Gohr if (!auth_quickaclcheck($ID)) { 940ac7a515fSAndreas Gohr return false; 941ac7a515fSAndreas Gohr } 9426b13307fSandi 9436b13307fSandi // prepare date and path 9446b13307fSandi $fn = $INFO['filepath']; 9456b13307fSandi if (!$conf['fullpath']) { 946613bca54SAndreas Gohr if ($INFO['rev']) { 947c83f69baSSatoshi Sahara $fn = str_replace($conf['olddir'] . '/', '', $fn); 9486b13307fSandi } else { 949c83f69baSSatoshi Sahara $fn = str_replace($conf['datadir'] . '/', '', $fn); 9506b13307fSandi } 9516b13307fSandi } 952bee6dc82Sandi $fn = utf8_decodeFN($fn); 9537370732eSSascha Leib $dateLocal = dformat($INFO['lastmod']); 9547370732eSSascha Leib $dateIso = date(DATE_ISO8601, $INFO['lastmod']); 9556b13307fSandi 956faecdfdfSAndreas Gohr // print it 957faecdfdfSAndreas Gohr if ($INFO['exists']) { 9584dc42f7fSGerrit Uitslag $out = '<bdi>' . $fn . '</bdi>'; 959e260f93bSAnika Henke $out .= ' · '; 9604b0d3916SAndreas Gohr $out .= $lang['lastmod']; 961fde860beSGerrit Uitslag $out .= ' '; 9627370732eSSascha Leib $out .= '<time datetime="' . $dateIso . '">' . $dateLocal . '</time>'; 9636b13307fSandi if ($INFO['editor']) { 9644b0d3916SAndreas Gohr $out .= ' ' . $lang['by'] . ' '; 965d317fb5dSAnika Henke $out .= '<bdi>' . editorinfo($INFO['editor']) . '</bdi>'; 9665aa52fafSBen Coburn } else { 9674b0d3916SAndreas Gohr $out .= ' (' . $lang['external_edit'] . ')'; 9686b13307fSandi } 9696b13307fSandi if ($INFO['locked']) { 970e260f93bSAnika Henke $out .= ' · '; 9714b0d3916SAndreas Gohr $out .= $lang['lockedby']; 972fde860beSGerrit Uitslag $out .= ' '; 973d317fb5dSAnika Henke $out .= '<bdi>' . editorinfo($INFO['locked']) . '</bdi>'; 9746b13307fSandi } 9754b0d3916SAndreas Gohr if ($ret) { 9764b0d3916SAndreas Gohr return $out; 9774b0d3916SAndreas Gohr } else { 9784b0d3916SAndreas Gohr echo $out; 97954e95700STom N Harris return true; 9806b13307fSandi } 9814b0d3916SAndreas Gohr } 98254e95700STom N Harris return false; 9836b13307fSandi} 9846b13307fSandi 985820fa24bSandi/** 986a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given). 98787c434ceSAndreas Gohr * 98887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else 989a6598f23SBen Coburn * the given ID is used. 99087c434ceSAndreas Gohr * 991ac7a515fSAndreas Gohr * @param string $id page id 992ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing 993ac7a515fSAndreas Gohr * @return bool|string 9944dc42f7fSGerrit Uitslag * 9954dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 99687c434ceSAndreas Gohr */ 997d868eb89SAndreas Gohrfunction tpl_pagetitle($id = null, $ret = false) 998d868eb89SAndreas Gohr{ 9994dc42f7fSGerrit Uitslag global $ACT, $conf, $lang; 1000fffeeafeSChristopher Smith 100187c434ceSAndreas Gohr if (is_null($id)) { 100287c434ceSAndreas Gohr global $ID; 100387c434ceSAndreas Gohr $id = $ID; 100487c434ceSAndreas Gohr } 100587c434ceSAndreas Gohr 100687c434ceSAndreas Gohr $name = $id; 1007fe9ec250SChris Smith if (useHeading('navigation')) { 1008fffeeafeSChristopher Smith $first_heading = p_get_first_heading($id); 1009fffeeafeSChristopher Smith if ($first_heading) $name = $first_heading; 1010fffeeafeSChristopher Smith } 1011fffeeafeSChristopher Smith 1012fffeeafeSChristopher Smith // default page title is the page name, modify with the current action 1013fffeeafeSChristopher Smith switch ($ACT) { 1014fffeeafeSChristopher Smith // admin functions 1015fffeeafeSChristopher Smith case 'admin': 1016fffeeafeSChristopher Smith $page_title = $lang['btn_admin']; 1017fffeeafeSChristopher Smith // try to get the plugin name 10184dc42f7fSGerrit Uitslag /** @var AdminPlugin $plugin */ 1019a61966c5SChristopher Smith if ($plugin = plugin_getRequestAdminPlugin()) { 1020c248bda1SChristopher Smith $plugin_title = $plugin->getMenuText($conf['lang']); 102124870174SAndreas Gohr $page_title = $plugin_title ?: $plugin->getPluginName(); 1022fffeeafeSChristopher Smith } 1023fffeeafeSChristopher Smith break; 1024fffeeafeSChristopher Smith 1025bcedcbabSAndreas Gohr // show action as title 1026fffeeafeSChristopher Smith case 'login': 1027fffeeafeSChristopher Smith case 'profile': 1028fffeeafeSChristopher Smith case 'register': 1029fffeeafeSChristopher Smith case 'resendpwd': 1030fffeeafeSChristopher Smith case 'index': 1031bcedcbabSAndreas Gohr case 'search': 1032fffeeafeSChristopher Smith $page_title = $lang['btn_' . $ACT]; 1033fffeeafeSChristopher Smith break; 1034bcedcbabSAndreas Gohr 1035bcedcbabSAndreas Gohr // add pen during editing 1036fffeeafeSChristopher Smith case 'edit': 10372f19acc2Sbleistivt case 'preview': 1038fffeeafeSChristopher Smith $page_title = "✎ " . $name; 1039fffeeafeSChristopher Smith break; 1040fffeeafeSChristopher Smith 1041bcedcbabSAndreas Gohr // add action to page name 1042fffeeafeSChristopher Smith case 'revisions': 1043fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_revs']; 1044fffeeafeSChristopher Smith break; 1045fffeeafeSChristopher Smith 1046bcedcbabSAndreas Gohr // add action to page name 1047fffeeafeSChristopher Smith case 'backlink': 1048fffeeafeSChristopher Smith case 'recent': 1049fffeeafeSChristopher Smith case 'subscribe': 1050fffeeafeSChristopher Smith $page_title = $name . ' - ' . $lang['btn_' . $ACT]; 1051fffeeafeSChristopher Smith break; 1052fffeeafeSChristopher Smith 1053fffeeafeSChristopher Smith default: // SHOW and anything else not included 1054fffeeafeSChristopher Smith $page_title = $name; 105587c434ceSAndreas Gohr } 1056a6598f23SBen Coburn 1057a6598f23SBen Coburn if ($ret) { 1058fffeeafeSChristopher Smith return hsc($page_title); 1059a6598f23SBen Coburn } else { 106026dfc232SAndreas Gohr echo hsc($page_title); 106154e95700STom N Harris return true; 106287c434ceSAndreas Gohr } 1063a6598f23SBen Coburn} 1064340756e4Sandi 106555efc227SAndreas Gohr/** 106655efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image 106755efc227SAndreas Gohr * 106855efc227SAndreas Gohr * If $tags is an array all given tags are tried until a 106955efc227SAndreas Gohr * value is found. If no value is found $alt is returned. 107055efc227SAndreas Gohr * 107155efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames 107255efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC 107355efc227SAndreas Gohr * to the names of the latter one) 107455efc227SAndreas Gohr * 10753df72098SAndreas Gohr * Only allowed in: detail.php 107655efc227SAndreas Gohr * 107721d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try 1078ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found 1079e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given 1080ac7a515fSAndreas Gohr * @return string 10814dc42f7fSGerrit Uitslag * 10824dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 108355efc227SAndreas Gohr */ 1084d868eb89SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) 1085d868eb89SAndreas Gohr{ 108655efc227SAndreas Gohr // Init Exif Reader 1087a46a7ce3Sasivery global $SRC, $imgMeta; 10883df72098SAndreas Gohr 10893df72098SAndreas Gohr if (is_null($src)) $src = $SRC; 10901eadd9e8SAndreas Gohr if (is_null($src)) return $alt; 10913df72098SAndreas Gohr 10924dc42f7fSGerrit Uitslag if (!isset($imgMeta)) { 10934dc42f7fSGerrit Uitslag $imgMeta = new JpegMeta($src); 10944dc42f7fSGerrit Uitslag } 1095a46a7ce3Sasivery if ($imgMeta === false) return $alt; 1096a46a7ce3Sasivery $info = cleanText($imgMeta->getField($tags)); 10974dc42f7fSGerrit Uitslag if (!$info) return $alt; 109855efc227SAndreas Gohr return $info; 109955efc227SAndreas Gohr} 110055efc227SAndreas Gohr 1101a46a7ce3Sasivery 1102a46a7ce3Sasivery/** 1103a46a7ce3Sasivery * Garbage collects up the open JpegMeta object. 1104a46a7ce3Sasivery */ 1105d868eb89SAndreas Gohrfunction tpl_img_close() 1106d868eb89SAndreas Gohr{ 1107a46a7ce3Sasivery global $imgMeta; 1108a46a7ce3Sasivery $imgMeta = null; 1109a46a7ce3Sasivery} 1110a46a7ce3Sasivery 111155efc227SAndreas Gohr/** 11124dc42f7fSGerrit Uitslag * Prints a html description list of the metatags of the current image 1113becfa414SGerrit Uitslag */ 1114d868eb89SAndreas Gohrfunction tpl_img_meta() 1115d868eb89SAndreas Gohr{ 1116becfa414SGerrit Uitslag global $lang; 1117becfa414SGerrit Uitslag 1118becfa414SGerrit Uitslag $tags = tpl_get_img_meta(); 1119becfa414SGerrit Uitslag 1120becfa414SGerrit Uitslag echo '<dl>'; 1121becfa414SGerrit Uitslag foreach ($tags as $tag) { 1122becfa414SGerrit Uitslag $label = $lang[$tag['langkey']]; 1123fde860beSGerrit Uitslag if (!$label) $label = $tag['langkey'] . ':'; 1124becfa414SGerrit Uitslag 1125fde860beSGerrit Uitslag echo '<dt>' . $label . '</dt><dd>'; 1126becfa414SGerrit Uitslag if ($tag['type'] == 'date') { 1127becfa414SGerrit Uitslag echo dformat($tag['value']); 1128becfa414SGerrit Uitslag } else { 1129becfa414SGerrit Uitslag echo hsc($tag['value']); 1130becfa414SGerrit Uitslag } 1131becfa414SGerrit Uitslag echo '</dd>'; 1132becfa414SGerrit Uitslag } 1133becfa414SGerrit Uitslag echo '</dl>'; 1134becfa414SGerrit Uitslag} 1135becfa414SGerrit Uitslag 1136becfa414SGerrit Uitslag/** 1137becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html 1138becfa414SGerrit Uitslag * 1139becfa414SGerrit Uitslag * @return array with arrays containing the entries: 1140becfa414SGerrit Uitslag * - string langkey key to lookup in the $lang var, if not found printed as is 1141becfa414SGerrit Uitslag * - string type type of value 1142becfa414SGerrit Uitslag * - string value tag value (unescaped) 1143becfa414SGerrit Uitslag */ 1144d868eb89SAndreas Gohrfunction tpl_get_img_meta() 1145d868eb89SAndreas Gohr{ 1146becfa414SGerrit Uitslag 1147becfa414SGerrit Uitslag $config_files = getConfigFiles('mediameta'); 1148becfa414SGerrit Uitslag foreach ($config_files as $config_file) { 114979e79377SAndreas Gohr if (file_exists($config_file)) { 1150becfa414SGerrit Uitslag include($config_file); 1151becfa414SGerrit Uitslag } 1152becfa414SGerrit Uitslag } 115324870174SAndreas Gohr $tags = []; 1154becfa414SGerrit Uitslag foreach ($fields as $tag) { 115524870174SAndreas Gohr $t = []; 1156becfa414SGerrit Uitslag if (!empty($tag[0])) { 115724870174SAndreas Gohr $t = [$tag[0]]; 1158becfa414SGerrit Uitslag } 1159056bf31fSDamien Regad if (isset($tag[3]) && is_array($tag[3])) { 1160becfa414SGerrit Uitslag $t = array_merge($t, $tag[3]); 1161becfa414SGerrit Uitslag } 1162becfa414SGerrit Uitslag $value = tpl_img_getTag($t); 1163becfa414SGerrit Uitslag if ($value) { 116424870174SAndreas Gohr $tags[] = ['langkey' => $tag[1], 'type' => $tag[2], 'value' => $value]; 1165becfa414SGerrit Uitslag } 1166becfa414SGerrit Uitslag } 1167becfa414SGerrit Uitslag return $tags; 1168becfa414SGerrit Uitslag} 1169becfa414SGerrit Uitslag 1170becfa414SGerrit Uitslag/** 117155efc227SAndreas Gohr * Prints the image with a link to the full sized version 117255efc227SAndreas Gohr * 117355efc227SAndreas Gohr * Only allowed in: detail.php 1174a02d2933SAndreas Gohr * 1175ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY 11764dc42f7fSGerrit Uitslag * @param int $maxwidth - maximal width of the image 11774dc42f7fSGerrit Uitslag * @param int $maxheight - maximal height of the image 11784dc42f7fSGerrit Uitslag * @param bool $link - link to the orginal size? 11794dc42f7fSGerrit Uitslag * @param array $params - additional image attributes 118042ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY 118155efc227SAndreas Gohr */ 1182d868eb89SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) 1183d868eb89SAndreas Gohr{ 118455efc227SAndreas Gohr global $IMG; 1185585bf44eSChristopher Smith /** @var Input $INPUT */ 1186ac7a515fSAndreas Gohr global $INPUT; 11875c2eed9aSlisps global $REV; 118855efc227SAndreas Gohr 1189*dd9e8e5eSAndreas Gohr // rotation-aware bbox fit; returns [0, 0] for SVG / unreadable files 1190*dd9e8e5eSAndreas Gohr [$w, $h] = (new MediaFile($IMG, $REV))->getDisplayDimensions($maxwidth, $maxheight, false); 119155efc227SAndreas Gohr 11926de3759aSAndreas Gohr //prepare URLs 1193*dd9e8e5eSAndreas Gohr $srcParams = ['cache' => $INPUT->str('cache'), 'rev' => $REV]; 1194*dd9e8e5eSAndreas Gohr if ($maxwidth) $srcParams['w'] = $maxwidth; 1195*dd9e8e5eSAndreas Gohr if ($maxheight) $srcParams['h'] = $maxheight; 1196*dd9e8e5eSAndreas Gohr if ($maxwidth && $maxheight) $srcParams['fit'] = 1; 119724870174SAndreas Gohr $url = ml($IMG, ['cache' => $INPUT->str('cache'), 'rev' => $REV], true, '&'); 1198*dd9e8e5eSAndreas Gohr $src = ml($IMG, $srcParams, true, '&'); 119955efc227SAndreas Gohr 12002684e50aSAndreas Gohr //prepare attributes 120155efc227SAndreas Gohr $alt = tpl_img_getTag('Simple.Title'); 1202a02d2933SAndreas Gohr if (is_null($params)) { 120324870174SAndreas Gohr $p = []; 1204a02d2933SAndreas Gohr } else { 1205a02d2933SAndreas Gohr $p = $params; 1206a02d2933SAndreas Gohr } 12072684e50aSAndreas Gohr if ($w) $p['width'] = $w; 12082684e50aSAndreas Gohr if ($h) $p['height'] = $h; 12092684e50aSAndreas Gohr $p['class'] = 'img_detail'; 12102684e50aSAndreas Gohr if ($alt) { 12112684e50aSAndreas Gohr $p['alt'] = $alt; 12122684e50aSAndreas Gohr $p['title'] = $alt; 12132684e50aSAndreas Gohr } else { 12142684e50aSAndreas Gohr $p['alt'] = ''; 12152684e50aSAndreas Gohr } 1216a02d2933SAndreas Gohr $p['src'] = $src; 121755efc227SAndreas Gohr 121824870174SAndreas Gohr $data = ['url' => ($link ? $url : null), 'params' => $p]; 1219cbb44eabSAndreas Gohr return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); 1220a02d2933SAndreas Gohr} 1221a02d2933SAndreas Gohr 1222a02d2933SAndreas Gohr/** 1223a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY 1224ac7a515fSAndreas Gohr * 1225ac7a515fSAndreas Gohr * @param array $data 1226ac7a515fSAndreas Gohr * @return bool 1227a02d2933SAndreas Gohr */ 1228d868eb89SAndreas Gohrfunction _tpl_img_action($data) 1229d868eb89SAndreas Gohr{ 123059f3611bSAnika Henke global $lang; 1231a02d2933SAndreas Gohr $p = buildAttributes($data['params']); 1232a02d2933SAndreas Gohr 123326dfc232SAndreas Gohr if ($data['url']) echo '<a href="' . hsc($data['url']) . '" title="' . $lang['mediaview'] . '">'; 123426dfc232SAndreas Gohr echo '<img ' . $p . '/>'; 123526dfc232SAndreas Gohr if ($data['url']) echo '</a>'; 123654e95700STom N Harris return true; 123755efc227SAndreas Gohr} 123855efc227SAndreas Gohr 12397367b368SAndreas Gohr/** 1240881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function. 12417367b368SAndreas Gohr * 12424dc42f7fSGerrit Uitslag * Should be called somewhere at the very end of the main.php template 1243ac7a515fSAndreas Gohr * 1244ac7a515fSAndreas Gohr * @return bool 12457367b368SAndreas Gohr */ 1246d868eb89SAndreas Gohrfunction tpl_indexerWebBug() 1247d868eb89SAndreas Gohr{ 12487367b368SAndreas Gohr global $ID; 12491dad36f5SAndreas Gohr 125024870174SAndreas Gohr $p = []; 12514af80fe8SMichael Große $p['src'] = DOKU_BASE . 'lib/exe/taskrunner.php?id=' . rawurlencode($ID) . 1252e68c51baSAndreas Gohr '&' . time(); 1253881f2ee2SAndreas Haerter $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers... 12547367b368SAndreas Gohr $p['height'] = 1; 12557367b368SAndreas Gohr $p['alt'] = ''; 12567367b368SAndreas Gohr $att = buildAttributes($p); 125726dfc232SAndreas Gohr echo "<img $att />"; 125854e95700STom N Harris return true; 12597367b368SAndreas Gohr} 12607367b368SAndreas Gohr 126178d4e784SEsther Brunner/** 126278d4e784SEsther Brunner * tpl_getConf($id) 126378d4e784SEsther Brunner * 126478d4e784SEsther Brunner * use this function to access template configuration variables 1265ac7a515fSAndreas Gohr * 126617448fb8SChristopher Smith * @param string $id name of the value to access 126717448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available 126817448fb8SChristopher Smith * @return mixed 126978d4e784SEsther Brunner */ 1270d868eb89SAndreas Gohrfunction tpl_getConf($id, $notset = false) 1271d868eb89SAndreas Gohr{ 127278d4e784SEsther Brunner global $conf; 127317566ac6SAdrian Lang static $tpl_configloaded = false; 127478d4e784SEsther Brunner 127578d4e784SEsther Brunner $tpl = $conf['template']; 127678d4e784SEsther Brunner 127778d4e784SEsther Brunner if (!$tpl_configloaded) { 127878d4e784SEsther Brunner $tconf = tpl_loadConfig(); 127978d4e784SEsther Brunner if ($tconf !== false) { 128078d4e784SEsther Brunner foreach ($tconf as $key => $value) { 128178d4e784SEsther Brunner if (isset($conf['tpl'][$tpl][$key])) continue; 128278d4e784SEsther Brunner $conf['tpl'][$tpl][$key] = $value; 128378d4e784SEsther Brunner } 128478d4e784SEsther Brunner $tpl_configloaded = true; 128578d4e784SEsther Brunner } 128678d4e784SEsther Brunner } 128778d4e784SEsther Brunner 128824870174SAndreas Gohr return $conf['tpl'][$tpl][$id] ?? $notset; 128917448fb8SChristopher Smith} 129017448fb8SChristopher Smith 129178d4e784SEsther Brunner/** 129278d4e784SEsther Brunner * tpl_loadConfig() 1293ac7a515fSAndreas Gohr * 129478d4e784SEsther Brunner * reads all template configuration variables 129578d4e784SEsther Brunner * this function is automatically called by tpl_getConf() 1296ac7a515fSAndreas Gohr * 12974dc42f7fSGerrit Uitslag * @return false|array 129878d4e784SEsther Brunner */ 1299d868eb89SAndreas Gohrfunction tpl_loadConfig() 1300d868eb89SAndreas Gohr{ 130178d4e784SEsther Brunner 1302c4766956SAndreas Gohr $file = tpl_incdir() . '/conf/default.php'; 130324870174SAndreas Gohr $conf = []; 130478d4e784SEsther Brunner 130579e79377SAndreas Gohr if (!file_exists($file)) return false; 130678d4e784SEsther Brunner 130778d4e784SEsther Brunner // load default config file 130878d4e784SEsther Brunner include($file); 130978d4e784SEsther Brunner 131078d4e784SEsther Brunner return $conf; 131178d4e784SEsther Brunner} 131278d4e784SEsther Brunner 131317566ac6SAdrian Lang// language methods 13144dc42f7fSGerrit Uitslag 131517566ac6SAdrian Lang/** 131617566ac6SAdrian Lang * tpl_getLang($id) 131717566ac6SAdrian Lang * 131817566ac6SAdrian Lang * use this function to access template language variables 131942ea7f44SGerrit Uitslag * 132042ea7f44SGerrit Uitslag * @param string $id key of language string 132142ea7f44SGerrit Uitslag * @return string 132217566ac6SAdrian Lang */ 1323d868eb89SAndreas Gohrfunction tpl_getLang($id) 1324d868eb89SAndreas Gohr{ 132524870174SAndreas Gohr static $lang = []; 132617566ac6SAdrian Lang 132717566ac6SAdrian Lang if (count($lang) === 0) { 1328dd7a6159SGerrit Uitslag global $conf, $config_cascade; // definitely don't invoke "global $lang" 1329dd7a6159SGerrit Uitslag 1330c4766956SAndreas Gohr $path = tpl_incdir() . 'lang/'; 133117566ac6SAdrian Lang 133224870174SAndreas Gohr $lang = []; 133317566ac6SAdrian Lang 133417566ac6SAdrian Lang // don't include once 133517566ac6SAdrian Lang @include($path . 'en/lang.php'); 1336dd7a6159SGerrit Uitslag foreach ($config_cascade['lang']['template'] as $config_file) { 133779e79377SAndreas Gohr if (file_exists($config_file . $conf['template'] . '/en/lang.php')) { 1338dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/en/lang.php'); 1339dd7a6159SGerrit Uitslag } 134017566ac6SAdrian Lang } 134117566ac6SAdrian Lang 1342dd7a6159SGerrit Uitslag if ($conf['lang'] != 'en') { 1343dd7a6159SGerrit Uitslag @include($path . $conf['lang'] . '/lang.php'); 1344dd7a6159SGerrit Uitslag foreach ($config_cascade['lang']['template'] as $config_file) { 134579e79377SAndreas Gohr if (file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) { 1346dd7a6159SGerrit Uitslag include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php'); 1347dd7a6159SGerrit Uitslag } 1348dd7a6159SGerrit Uitslag } 1349dd7a6159SGerrit Uitslag } 135017566ac6SAdrian Lang } 135124870174SAndreas Gohr return $lang[$id] ?? ''; 135217566ac6SAdrian Lang} 135317566ac6SAdrian Lang 13543df72098SAndreas Gohr/** 1355c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display 1356e8ec13b9SKlap-in * template equivalent of p_locale_xhtml() 1357e8ec13b9SKlap-in * 1358e8ec13b9SKlap-in * @param string $id id of language dependent wiki page 1359e8ec13b9SKlap-in * @return string parsed contents of the wiki page in xhtml format 1360e8ec13b9SKlap-in */ 1361d868eb89SAndreas Gohrfunction tpl_locale_xhtml($id) 1362d868eb89SAndreas Gohr{ 1363c5c17fdaSKlap-in return p_cached_output(tpl_localeFN($id)); 1364e8ec13b9SKlap-in} 1365e8ec13b9SKlap-in 1366e8ec13b9SKlap-in/** 1367c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename 136842ea7f44SGerrit Uitslag * 136942ea7f44SGerrit Uitslag * @param string $id id of localized text 137042ea7f44SGerrit Uitslag * @return string wiki text 1371e8ec13b9SKlap-in */ 1372d868eb89SAndreas Gohrfunction tpl_localeFN($id) 1373d868eb89SAndreas Gohr{ 1374e8ec13b9SKlap-in $path = tpl_incdir() . 'lang/'; 1375e8ec13b9SKlap-in global $conf; 137638fb1fc7SGerrit Uitslag $file = DOKU_CONF . 'template_lang/' . $conf['template'] . '/' . $conf['lang'] . '/' . $id . '.txt'; 137779e79377SAndreas Gohr if (!file_exists($file)) { 1378e8ec13b9SKlap-in $file = $path . $conf['lang'] . '/' . $id . '.txt'; 137979e79377SAndreas Gohr if (!file_exists($file)) { 1380e8ec13b9SKlap-in //fall back to english 1381e8ec13b9SKlap-in $file = $path . 'en/' . $id . '.txt'; 1382e8ec13b9SKlap-in } 1383e8ec13b9SKlap-in } 1384e8ec13b9SKlap-in return $file; 1385e8ec13b9SKlap-in} 1386e8ec13b9SKlap-in 1387e8ec13b9SKlap-in/** 13887abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup 13893df72098SAndreas Gohr * 13903df72098SAndreas Gohr * Depending on the user's actions this may be a list of 13913df72098SAndreas Gohr * files in a namespace, the meta editing dialog or 13923df72098SAndreas Gohr * a message of referencing pages 13933df72098SAndreas Gohr * 13943df72098SAndreas Gohr * Only allowed in mediamanager.php 13953df72098SAndreas Gohr * 1396c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT 1397c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax 139842ea7f44SGerrit Uitslag * @param string $sort 13998702de7fSGerrit Uitslag * 14003df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 14013df72098SAndreas Gohr */ 1402d868eb89SAndreas Gohrfunction tpl_mediaContent($fromajax = false, $sort = 'natural') 1403d868eb89SAndreas Gohr{ 14043df72098SAndreas Gohr global $IMG; 14053df72098SAndreas Gohr global $AUTH; 14063df72098SAndreas Gohr global $INUSE; 14073df72098SAndreas Gohr global $NS; 14083df72098SAndreas Gohr global $JUMPTO; 1409585bf44eSChristopher Smith /** @var Input $INPUT */ 1410ac7a515fSAndreas Gohr global $INPUT; 14113df72098SAndreas Gohr 1412ac7a515fSAndreas Gohr $do = $INPUT->extract('do')->str('do'); 141324870174SAndreas Gohr if (in_array($do, ['save', 'cancel'])) $do = ''; 1414c182313eSAndreas Gohr 1415c182313eSAndreas Gohr if (!$do) { 1416ac7a515fSAndreas Gohr if ($INPUT->bool('edit')) { 1417c182313eSAndreas Gohr $do = 'metaform'; 1418c182313eSAndreas Gohr } elseif (is_array($INUSE)) { 1419c182313eSAndreas Gohr $do = 'filesinuse'; 1420c182313eSAndreas Gohr } else { 1421c182313eSAndreas Gohr $do = 'filelist'; 1422c182313eSAndreas Gohr } 1423c182313eSAndreas Gohr } 1424c182313eSAndreas Gohr 1425c182313eSAndreas Gohr // output the content pane, wrapped in an event. 1426a664aabaSAndreas Gohr if (!$fromajax) echo '<div id="media__content">'; 142724870174SAndreas Gohr $data = ['do' => $do]; 1428e1d9dcc8SAndreas Gohr $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); 1429c182313eSAndreas Gohr if ($evt->advise_before()) { 1430c182313eSAndreas Gohr $do = $data['do']; 143130fd72fbSKate Arzamastseva if ($do == 'filesinuse') { 1432c182313eSAndreas Gohr media_filesinuse($INUSE, $IMG); 1433c182313eSAndreas Gohr } elseif ($do == 'filelist') { 143400e3e394SChristopher Smith media_filelist($NS, $AUTH, $JUMPTO, false, $sort); 1435c9f56829SAndreas Gohr } elseif ($do == 'searchlist') { 1436ac7a515fSAndreas Gohr media_searchlist($INPUT->str('q'), $NS, $AUTH); 1437c182313eSAndreas Gohr } else { 1438c182313eSAndreas Gohr msg('Unknown action ' . hsc($do), -1); 1439c182313eSAndreas Gohr } 1440c182313eSAndreas Gohr } 1441c182313eSAndreas Gohr $evt->advise_after(); 1442c182313eSAndreas Gohr unset($evt); 1443a664aabaSAndreas Gohr if (!$fromajax) echo '</div>'; 14443df72098SAndreas Gohr} 14453df72098SAndreas Gohr 14463df72098SAndreas Gohr/** 1447d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager 1448d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of 1449d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form 1450d9162c6cSKate Arzamastseva * 1451d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1452d9162c6cSKate Arzamastseva */ 1453d868eb89SAndreas Gohrfunction tpl_mediaFileList() 1454d868eb89SAndreas Gohr{ 1455d9162c6cSKate Arzamastseva global $AUTH; 1456d9162c6cSKate Arzamastseva global $NS; 1457d9162c6cSKate Arzamastseva global $JUMPTO; 145895b451bcSAdrian Lang global $lang; 1459585bf44eSChristopher Smith /** @var Input $INPUT */ 1460ac7a515fSAndreas Gohr global $INPUT; 1461d9162c6cSKate Arzamastseva 1462ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_files'); 146324870174SAndreas Gohr if (!$opened_tab || !in_array($opened_tab, ['files', 'upload', 'search'])) $opened_tab = 'files'; 1464ac7a515fSAndreas Gohr if ($INPUT->str('mediado') == 'update') $opened_tab = 'upload'; 1465d9162c6cSKate Arzamastseva 146694add303SAnika Henke echo '<h2 class="a11y">' . $lang['mediaselect'] . '</h2>' . NL; 146795b451bcSAdrian Lang 1468ed69a2aeSKate Arzamastseva media_tabs_files($opened_tab); 146923846a98SKate Arzamastseva 147094add303SAnika Henke echo '<div class="panelHeader">' . NL; 147195b451bcSAdrian Lang echo '<h3>'; 147224870174SAndreas Gohr $tabTitle = $NS ?: '[' . $lang['mediaroot'] . ']'; 1473c98f205eSAdrian Lang printf($lang['media_' . $opened_tab], '<strong>' . hsc($tabTitle) . '</strong>'); 147494add303SAnika Henke echo '</h3>' . NL; 147595b451bcSAdrian Lang if ($opened_tab === 'search' || $opened_tab === 'files') { 147695b451bcSAdrian Lang media_tab_files_options(); 147723846a98SKate Arzamastseva } 147894add303SAnika Henke echo '</div>' . NL; 1479d9162c6cSKate Arzamastseva 148094add303SAnika Henke echo '<div class="panelContent">' . NL; 148195b451bcSAdrian Lang if ($opened_tab == 'files') { 148295b451bcSAdrian Lang media_tab_files($NS, $AUTH, $JUMPTO); 148395b451bcSAdrian Lang } elseif ($opened_tab == 'upload') { 148495b451bcSAdrian Lang media_tab_upload($NS, $AUTH, $JUMPTO); 148595b451bcSAdrian Lang } elseif ($opened_tab == 'search') { 148695b451bcSAdrian Lang media_tab_search($NS, $AUTH); 148795b451bcSAdrian Lang } 148894add303SAnika Henke echo '</div>' . NL; 1489d9162c6cSKate Arzamastseva} 1490d9162c6cSKate Arzamastseva 1491d9162c6cSKate Arzamastseva/** 1492d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager 1493d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the 1494d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or 1495d9162c6cSKate Arzamastseva * list of file revisions 1496d9162c6cSKate Arzamastseva * 1497f50a239bSTakamura * @param string $image 1498f50a239bSTakamura * @param boolean $rev 14994dc42f7fSGerrit Uitslag * 15004dc42f7fSGerrit Uitslag * @author Kate Arzamastseva <pshns@ukr.net> 1501d9162c6cSKate Arzamastseva */ 1502d868eb89SAndreas Gohrfunction tpl_mediaFileDetails($image, $rev) 1503d868eb89SAndreas Gohr{ 1504e8a2a143SMichael Hamann global $conf, $DEL, $lang; 1505585bf44eSChristopher Smith /** @var Input $INPUT */ 1506585bf44eSChristopher Smith global $INPUT; 1507d9162c6cSKate Arzamastseva 150864159a61SAndreas Gohr $removed = ( 150964159a61SAndreas Gohr !file_exists(mediaFN($image)) && 151064159a61SAndreas Gohr file_exists(mediaMetaFN($image, '.changes')) && 151164159a61SAndreas Gohr $conf['mediarevisions'] 151264159a61SAndreas Gohr ); 1513ac7a515fSAndreas Gohr if (!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return; 15146dd095f5SKate Arzamastseva if ($rev && !file_exists(mediaFN($image, $rev))) $rev = false; 1515e8a2a143SMichael Hamann $ns = getNS($image); 1516ac7a515fSAndreas Gohr $do = $INPUT->str('mediado'); 15171eeeced2SKate Arzamastseva 1518ac7a515fSAndreas Gohr $opened_tab = $INPUT->str('tab_details'); 1519e5d185e1SKate Arzamastseva 152024870174SAndreas Gohr $tab_array = ['view']; 152124870174SAndreas Gohr [, $mime] = mimetype($image); 1522e5d185e1SKate Arzamastseva if ($mime == 'image/jpeg') { 1523e5d185e1SKate Arzamastseva $tab_array[] = 'edit'; 1524e5d185e1SKate Arzamastseva } 1525e5d185e1SKate Arzamastseva if ($conf['mediarevisions']) { 1526e5d185e1SKate Arzamastseva $tab_array[] = 'history'; 1527e5d185e1SKate Arzamastseva } 1528e5d185e1SKate Arzamastseva 1529e5d185e1SKate Arzamastseva if (!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view'; 1530ac7a515fSAndreas Gohr if ($INPUT->bool('edit')) $opened_tab = 'edit'; 153123846a98SKate Arzamastseva if ($do == 'restore') $opened_tab = 'view'; 1532d9162c6cSKate Arzamastseva 1533ed69a2aeSKate Arzamastseva media_tabs_details($image, $opened_tab); 153423846a98SKate Arzamastseva 153559f3611bSAnika Henke echo '<div class="panelHeader"><h3>'; 153624870174SAndreas Gohr [$ext] = mimetype($image, false); 153795b451bcSAdrian Lang $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); 153895b451bcSAdrian Lang $class = 'select mediafile mf_' . $class; 153924870174SAndreas Gohr 1540750a0b51SMichael Große $attributes = $rev ? ['rev' => $rev] : []; 154190fb952cSAndreas Gohr $tabTitle = sprintf( 154290fb952cSAndreas Gohr '<strong><a href="%s" class="%s" title="%s">%s</a></strong>', 154390fb952cSAndreas Gohr ml($image, $attributes), 154490fb952cSAndreas Gohr $class, 154590fb952cSAndreas Gohr $lang['mediaview'], 154690fb952cSAndreas Gohr $image 154790fb952cSAndreas Gohr ); 154808317413SAdrian Lang if ($opened_tab === 'view' && $rev) { 154908317413SAdrian Lang printf($lang['media_viewold'], $tabTitle, dformat($rev)); 155008317413SAdrian Lang } else { 1551026d14a9SAnika Henke printf($lang['media_' . $opened_tab], $tabTitle); 155208317413SAdrian Lang } 1553b8a84c03SAndreas Gohr 155494add303SAnika Henke echo '</h3></div>' . NL; 155595b451bcSAdrian Lang 155694add303SAnika Henke echo '<div class="panelContent">' . NL; 155795b451bcSAdrian Lang 155823846a98SKate Arzamastseva if ($opened_tab == 'view') { 1559e8a2a143SMichael Hamann media_tab_view($image, $ns, null, $rev); 156092cac9a9SKate Arzamastseva } elseif ($opened_tab == 'edit' && !$removed) { 1561e8a2a143SMichael Hamann media_tab_edit($image, $ns); 1562e5d185e1SKate Arzamastseva } elseif ($opened_tab == 'history' && $conf['mediarevisions']) { 1563e8a2a143SMichael Hamann media_tab_history($image, $ns); 156423846a98SKate Arzamastseva } 156595b451bcSAdrian Lang 156694add303SAnika Henke echo '</div>' . NL; 1567d9162c6cSKate Arzamastseva} 1568d9162c6cSKate Arzamastseva 1569d9162c6cSKate Arzamastseva/** 15707abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup 15713df72098SAndreas Gohr * 15723df72098SAndreas Gohr * Only allowed in mediamanager.php 15733df72098SAndreas Gohr * 15743df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15753df72098SAndreas Gohr */ 1576d868eb89SAndreas Gohrfunction tpl_mediaTree() 1577d868eb89SAndreas Gohr{ 15783df72098SAndreas Gohr global $NS; 1579a664aabaSAndreas Gohr echo '<div id="media__tree">'; 15803df72098SAndreas Gohr media_nstree($NS); 1581a664aabaSAndreas Gohr echo '</div>'; 15823df72098SAndreas Gohr} 15833df72098SAndreas Gohr 1584a00de5b5SAndreas Gohr/** 1585a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions 1586a00de5b5SAndreas Gohr * 1587a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs 1588a00de5b5SAndreas Gohr * 158942ea7f44SGerrit Uitslag * @param string $empty empty option label 159042ea7f44SGerrit Uitslag * @param string $button submit button label 15914dc42f7fSGerrit Uitslag * 15924dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 1593affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 1594a00de5b5SAndreas Gohr */ 1595d868eb89SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '>') 1596d868eb89SAndreas Gohr{ 1597affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 159824870174SAndreas Gohr $menu = new MobileMenu(); 15991e875dcdSAndreas Gohr echo $menu->getDropdown($empty, $button); 1600a00de5b5SAndreas Gohr} 1601a00de5b5SAndreas Gohr 1602066fee30SAndreas Gohr/** 1603066fee30SAndreas Gohr * Print a informational line about the used license 1604066fee30SAndreas Gohr * 1605ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge) 1606ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description? 1607ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML 1608ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"? 1609ac7a515fSAndreas Gohr * @return string 16104dc42f7fSGerrit Uitslag * 16114dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 1612066fee30SAndreas Gohr */ 1613d868eb89SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) 1614d868eb89SAndreas Gohr{ 1615066fee30SAndreas Gohr global $license; 1616066fee30SAndreas Gohr global $conf; 1617066fee30SAndreas Gohr global $lang; 1618066fee30SAndreas Gohr if (!$conf['license']) return ''; 1619066fee30SAndreas Gohr if (!is_array($license[$conf['license']])) return ''; 1620066fee30SAndreas Gohr $lic = $license[$conf['license']]; 162153e15c8bSAnika Henke $target = ($conf['target']['extern']) ? ' target="' . $conf['target']['extern'] . '"' : ''; 1622066fee30SAndreas Gohr 162380083a41SAndreas Gohr $out = ''; 162480083a41SAndreas Gohr if ($wrap) $out .= '<div class="license">'; 1625066fee30SAndreas Gohr if ($img) { 1626066fee30SAndreas Gohr $src = license_img($img); 1627066fee30SAndreas Gohr if ($src) { 162853e15c8bSAnika Henke $out .= '<a href="' . $lic['url'] . '" rel="license"' . $target; 162953e15c8bSAnika Henke $out .= '><img src="' . DOKU_BASE . $src . '" alt="' . $lic['name'] . '" /></a>'; 163053e15c8bSAnika Henke if (!$imgonly) $out .= ' '; 1631066fee30SAndreas Gohr } 1632066fee30SAndreas Gohr } 16334cefd216SMichael Klier if (!$imgonly) { 163453e15c8bSAnika Henke $out .= $lang['license'] . ' '; 1635d317fb5dSAnika Henke $out .= '<bdi><a href="' . $lic['url'] . '" rel="license" class="urlextern"' . $target; 1636d317fb5dSAnika Henke $out .= '>' . $lic['name'] . '</a></bdi>'; 16374cefd216SMichael Klier } 163880083a41SAndreas Gohr if ($wrap) $out .= '</div>'; 1639066fee30SAndreas Gohr 1640066fee30SAndreas Gohr if ($return) return $out; 1641066fee30SAndreas Gohr echo $out; 1642ac7a515fSAndreas Gohr return ''; 1643066fee30SAndreas Gohr} 1644066fee30SAndreas Gohr 1645a81910eeSAndreas Gohr/** 1646835dfcaeSAnika Henke * Includes the rendered HTML of a given page 1647a81910eeSAndreas Gohr * 1648a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a 1649a81910eeSAndreas Gohr * template 1650e0c26282SGerrit Uitslag * 16517a112df5SAndreas Gohr * @param string $pageid The page name you want to include 16527a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only 16537a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too? 16547c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out? 1655e0c26282SGerrit Uitslag * @return bool|null|string 1656a81910eeSAndreas Gohr */ 1657d868eb89SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) 1658d868eb89SAndreas Gohr{ 16597a112df5SAndreas Gohr if ($propagate) { 16607c3e4a67SAndreas Gohr $pageid = page_findnearest($pageid, $useacl); 16617c3e4a67SAndreas Gohr } elseif ($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) { 16627a112df5SAndreas Gohr return false; 16637a112df5SAndreas Gohr } 1664c786a1b6SAnika Henke if (!$pageid) return false; 1665835dfcaeSAnika Henke 1666c786a1b6SAnika Henke global $TOC; 16679a2e250aSAndreas Gohr $oldtoc = $TOC; 1668a81910eeSAndreas Gohr $html = p_wiki_xhtml($pageid, '', false); 16699a2e250aSAndreas Gohr $TOC = $oldtoc; 1670a81910eeSAndreas Gohr 1671a2e03c82SAndreas Gohr if ($print) echo $html; 1672e66d3e6dSAndreas Gohr return $html; 1673e66d3e6dSAndreas Gohr} 1674e66d3e6dSAndreas Gohr 1675e66d3e6dSAndreas Gohr/** 16765b75cd1fSAdrian Lang * Display the subscribe form 16775b75cd1fSAdrian Lang * 16785b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 1679848cb786SSatoshi Sahara * @deprecated 2020-07-23 16805b75cd1fSAdrian Lang */ 1681d868eb89SAndreas Gohrfunction tpl_subscribe() 1682d868eb89SAndreas Gohr{ 168324870174SAndreas Gohr dbg_deprecated(Subscribe::class . '::show()'); 168473022918SAndreas Gohr (new Subscribe())->show(); 16855b75cd1fSAdrian Lang} 16865b75cd1fSAdrian Lang 1687d059ba9bSAndreas Gohr/** 1688d059ba9bSAndreas Gohr * Tries to send already created content right to the browser 1689d059ba9bSAndreas Gohr * 1690d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush() 1691d059ba9bSAndreas Gohr * 1692d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1693d059ba9bSAndreas Gohr */ 1694d868eb89SAndreas Gohrfunction tpl_flush() 1695d868eb89SAndreas Gohr{ 1696c2009796SZemoj if (ob_get_level() > 0) ob_flush(); 1697d059ba9bSAndreas Gohr flush(); 1698d059ba9bSAndreas Gohr} 1699d059ba9bSAndreas Gohr 1700afca7e7eSAnika Henke/** 1701378325f9SAndreas Gohr * Tries to find a ressource file in the given locations. 1702afca7e7eSAnika Henke * 1703378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media 1704378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template 1705378325f9SAndreas Gohr * 170642ea7f44SGerrit Uitslag * @param string[] $search locations to look at 1707378325f9SAndreas Gohr * @param bool $abs if to use absolute URL 1708ac7a515fSAndreas Gohr * @param array &$imginfo filled with getimagesize() 17096dc405e1SAndreas Gohr * @param bool $fallback use fallback image if target isn't found or return 'false' if potential 17106dc405e1SAndreas Gohr * false result is required 1711ac7a515fSAndreas Gohr * @return string 171242ea7f44SGerrit Uitslag * 1713378325f9SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1714afca7e7eSAnika Henke */ 1715d868eb89SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true) 1716d868eb89SAndreas Gohr{ 1717ac7a515fSAndreas Gohr $img = ''; 1718ac7a515fSAndreas Gohr $file = ''; 1719ac7a515fSAndreas Gohr $ismedia = false; 1720378325f9SAndreas Gohr // loop through candidates until a match was found: 1721378325f9SAndreas Gohr foreach ($search as $img) { 17226c16a3a9Sfiwswe if (str_starts_with($img, ':')) { 1723378325f9SAndreas Gohr $file = mediaFN($img); 1724378325f9SAndreas Gohr $ismedia = true; 1725378325f9SAndreas Gohr } else { 1726c4766956SAndreas Gohr $file = tpl_incdir() . $img; 1727378325f9SAndreas Gohr $ismedia = false; 17281f13e33dSAnika Henke } 17290f747863Slupo49 1730378325f9SAndreas Gohr if (file_exists($file)) break; 1731872a6d29SAnika Henke } 1732378325f9SAndreas Gohr 173308a13262SSimon DELAGE // manage non existing target 173408a13262SSimon DELAGE if (!file_exists($file)) { 173508a13262SSimon DELAGE // give result for fallback image 173624870174SAndreas Gohr if ($fallback) { 1737e44b94a4SAndreas Gohr $file = DOKU_INC . 'lib/images/blank.gif'; 173808a13262SSimon DELAGE // stop process if false result is required (if $fallback is false) 173908a13262SSimon DELAGE } else { 174008a13262SSimon DELAGE return false; 174108a13262SSimon DELAGE } 174208a13262SSimon DELAGE } 1743ca5b6a64SSimon DELAGE 1744378325f9SAndreas Gohr // fetch image data if requested 1745378325f9SAndreas Gohr if (!is_null($imginfo)) { 1746378325f9SAndreas Gohr $imginfo = getimagesize($file); 1747378325f9SAndreas Gohr } 1748378325f9SAndreas Gohr 1749378325f9SAndreas Gohr // build URL 1750378325f9SAndreas Gohr if ($ismedia) { 1751378325f9SAndreas Gohr $url = ml($img, '', true, '', $abs); 1752378325f9SAndreas Gohr } else { 1753c4766956SAndreas Gohr $url = tpl_basedir() . $img; 1754378325f9SAndreas Gohr if ($abs) $url = DOKU_URL . substr($url, strlen(DOKU_REL)); 1755378325f9SAndreas Gohr } 1756378325f9SAndreas Gohr 1757378325f9SAndreas Gohr return $url; 1758a7e5f74cSlupo49} 17591f13e33dSAnika Henke 1760872a6d29SAnika Henke/** 1761e5d4768dSAndreas Gohr * PHP include a file 1762e5d4768dSAndreas Gohr * 1763e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use 1764e5d4768dSAndreas Gohr * file in the template's root directory. 1765e5d4768dSAndreas Gohr * 1766e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given 1767e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local, 1768e5d4768dSAndreas Gohr * default. 1769e5d4768dSAndreas Gohr * 1770e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input 1771e5d4768dSAndreas Gohr * to this function! 1772e5d4768dSAndreas Gohr * 177342ea7f44SGerrit Uitslag * @param string $file 17744dc42f7fSGerrit Uitslag * 17754dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org> 17764dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1777e5d4768dSAndreas Gohr */ 1778d868eb89SAndreas Gohrfunction tpl_includeFile($file) 1779d868eb89SAndreas Gohr{ 1780e5d4768dSAndreas Gohr global $config_cascade; 178124870174SAndreas Gohr foreach (['protected', 'local', 'default'] as $config_group) { 1782e5d4768dSAndreas Gohr if (empty($config_cascade['main'][$config_group])) continue; 1783e5d4768dSAndreas Gohr foreach ($config_cascade['main'][$config_group] as $conf_file) { 1784e5d4768dSAndreas Gohr $dir = dirname($conf_file); 1785e5d4768dSAndreas Gohr if (file_exists("$dir/$file")) { 1786f3a1225fSAnika Henke include("$dir/$file"); 1787e5d4768dSAndreas Gohr return; 1788e5d4768dSAndreas Gohr } 1789e5d4768dSAndreas Gohr } 1790e5d4768dSAndreas Gohr } 1791e5d4768dSAndreas Gohr 1792e5d4768dSAndreas Gohr // still here? try the template dir 1793e5d4768dSAndreas Gohr $file = tpl_incdir() . $file; 1794e5d4768dSAndreas Gohr if (file_exists($file)) { 1795f3a1225fSAnika Henke include($file); 1796e5d4768dSAndreas Gohr } 1797e5d4768dSAndreas Gohr} 1798e5d4768dSAndreas Gohr 1799e5d4768dSAndreas Gohr/** 1800872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic) 1801872a6d29SAnika Henke * 1802ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic) 1803ac7a515fSAndreas Gohr * @return string 18044dc42f7fSGerrit Uitslag * 18054dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1806872a6d29SAnika Henke */ 1807d868eb89SAndreas Gohrfunction tpl_favicon($types = ['favicon']) 1808d868eb89SAndreas Gohr{ 1809872a6d29SAnika Henke 1810872a6d29SAnika Henke $return = ''; 1811872a6d29SAnika Henke 1812872a6d29SAnika Henke foreach ($types as $type) { 1813872a6d29SAnika Henke switch ($type) { 1814872a6d29SAnika Henke case 'favicon': 181524870174SAndreas Gohr $look = [':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico']; 1816378325f9SAndreas Gohr $return .= '<link rel="shortcut icon" href="' . tpl_getMediaFile($look) . '" />' . NL; 1817872a6d29SAnika Henke break; 1818872a6d29SAnika Henke case 'mobile': 181924870174SAndreas Gohr $look = [':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png']; 1820378325f9SAndreas Gohr $return .= '<link rel="apple-touch-icon" href="' . tpl_getMediaFile($look) . '" />' . NL; 1821872a6d29SAnika Henke break; 1822872a6d29SAnika Henke case 'generic': 1823872a6d29SAnika Henke // ideal world solution, which doesn't work in any browser yet 182424870174SAndreas Gohr $look = [':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg']; 1825378325f9SAndreas Gohr $return .= '<link rel="icon" href="' . tpl_getMediaFile($look) . '" type="image/svg+xml" />' . NL; 1826872a6d29SAnika Henke break; 1827872a6d29SAnika Henke } 1828872a6d29SAnika Henke } 1829872a6d29SAnika Henke 1830872a6d29SAnika Henke return $return; 1831afca7e7eSAnika Henke} 1832afca7e7eSAnika Henke 1833d9162c6cSKate Arzamastseva/** 1834d9162c6cSKate Arzamastseva * Prints full-screen media manager 1835d9162c6cSKate Arzamastseva * 1836d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net> 1837d9162c6cSKate Arzamastseva */ 1838d868eb89SAndreas Gohrfunction tpl_media() 1839d868eb89SAndreas Gohr{ 1840ac7a515fSAndreas Gohr global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT; 184188a71175SKate Arzamastseva $fullscreen = true; 184295b451bcSAdrian Lang require_once DOKU_INC . 'lib/exe/mediamanager.php'; 1843d9162c6cSKate Arzamastseva 1844ac7a515fSAndreas Gohr $rev = ''; 1845ac7a515fSAndreas Gohr $image = cleanID($INPUT->str('image')); 184698f03b57SKate Arzamastseva if (isset($IMG)) $image = $IMG; 184798f03b57SKate Arzamastseva if (isset($JUMPTO)) $image = $JUMPTO; 18489c1bd4bcSKate Arzamastseva if (isset($REV) && !$JUMPTO) $rev = $REV; 184998f03b57SKate Arzamastseva 185094add303SAnika Henke echo '<div id="mediamanager__page">' . NL; 1851bc314c58SAnika Henke echo '<h1>' . $lang['btn_media'] . '</h1>' . NL; 1852d9162c6cSKate Arzamastseva html_msgarea(); 185394add303SAnika Henke 185494add303SAnika Henke echo '<div class="panel namespaces">' . NL; 185594add303SAnika Henke echo '<h2>' . $lang['namespaces'] . '</h2>' . NL; 185695b451bcSAdrian Lang echo '<div class="panelHeader">'; 1857ba340a70SAnika Henke echo $lang['media_namespaces']; 185894add303SAnika Henke echo '</div>' . NL; 185995b451bcSAdrian Lang 186094add303SAnika Henke echo '<div class="panelContent" id="media__tree">' . NL; 186195b451bcSAdrian Lang media_nstree($NS); 186294add303SAnika Henke echo '</div>' . NL; 186394add303SAnika Henke echo '</div>' . NL; 1864fa8e5c77SKate Arzamastseva 186594add303SAnika Henke echo '<div class="panel filelist">' . NL; 1866035e07f1SKate Arzamastseva tpl_mediaFileList(); 186794add303SAnika Henke echo '</div>' . NL; 1868fa8e5c77SKate Arzamastseva 186994add303SAnika Henke echo '<div class="panel file">' . NL; 187094add303SAnika Henke echo '<h2 class="a11y">' . $lang['media_file'] . '</h2>' . NL; 1871035e07f1SKate Arzamastseva tpl_mediaFileDetails($image, $rev); 187294add303SAnika Henke echo '</div>' . NL; 1873ba340a70SAnika Henke 187494add303SAnika Henke echo '</div>' . NL; 1875d9162c6cSKate Arzamastseva} 1876afca7e7eSAnika Henke 1877c71db656SAnika Henke/** 1878c71db656SAnika Henke * Return useful layout classes 1879c71db656SAnika Henke * 188042ea7f44SGerrit Uitslag * @return string 18814dc42f7fSGerrit Uitslag * 18824dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1883c71db656SAnika Henke */ 1884d868eb89SAndreas Gohrfunction tpl_classes() 1885d868eb89SAndreas Gohr{ 1886c71db656SAnika Henke global $ACT, $conf, $ID, $INFO; 1887585bf44eSChristopher Smith /** @var Input $INPUT */ 1888585bf44eSChristopher Smith global $INPUT; 1889585bf44eSChristopher Smith 189024870174SAndreas Gohr $classes = [ 1891c71db656SAnika Henke 'dokuwiki', 1892c71db656SAnika Henke 'mode_' . $ACT, 1893c71db656SAnika Henke 'tpl_' . $conf['template'], 1894585bf44eSChristopher Smith $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '', 189590eb1b7bSEduardo Mozart de Oliveira (isset($INFO['exists']) && $INFO['exists']) ? '' : 'notFound', 189624870174SAndreas Gohr ($ID == $conf['start']) ? 'home' : '' 189724870174SAndreas Gohr ]; 189824870174SAndreas Gohr return implode(' ', $classes); 1899c71db656SAnika Henke} 1900c71db656SAnika Henke 190184dd2b1aSGerrit Uitslag/** 190284dd2b1aSGerrit Uitslag * Create event for tools menues 190384dd2b1aSGerrit Uitslag * 190484dd2b1aSGerrit Uitslag * @param string $toolsname name of menu 190584dd2b1aSGerrit Uitslag * @param array $items 190684dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ... 19074dc42f7fSGerrit Uitslag * 19084dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org> 1909affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus 191084dd2b1aSGerrit Uitslag */ 1911d868eb89SAndreas Gohrfunction tpl_toolsevent($toolsname, $items, $view = 'main') 1912d868eb89SAndreas Gohr{ 1913affc7ddfSAndreas Gohr dbg_deprecated('see devel:menus'); 191424870174SAndreas Gohr $data = ['view' => $view, 'items' => $items]; 191584dd2b1aSGerrit Uitslag 191684dd2b1aSGerrit Uitslag $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY'; 1917e1d9dcc8SAndreas Gohr $evt = new Event($hook, $data); 191884dd2b1aSGerrit Uitslag if ($evt->advise_before()) { 191924870174SAndreas Gohr foreach ($evt->data['items'] as $html) echo $html; 192084dd2b1aSGerrit Uitslag } 192184dd2b1aSGerrit Uitslag $evt->advise_after(); 192284dd2b1aSGerrit Uitslag} 1923