xref: /dokuwiki/inc/template.php (revision d4f83172d9533c4d84f450fe22ef630816b21d75)
16b13307fSandi<?php
2*d4f83172SAndreas 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 */
9*d4f83172SAndreas Gohr
1024870174SAndreas Gohruse dokuwiki\ActionRouter;
1124870174SAndreas Gohruse dokuwiki\Action\Exception\FatalException;
1224870174SAndreas Gohruse dokuwiki\Extension\PluginInterface;
1324870174SAndreas Gohruse dokuwiki\Ui\Admin;
1424870174SAndreas Gohruse dokuwiki\StyleUtils;
1524870174SAndreas Gohruse dokuwiki\Menu\Item\AbstractItem;
1624870174SAndreas Gohruse dokuwiki\Form\Form;
1724870174SAndreas Gohruse dokuwiki\Menu\MobileMenu;
1824870174SAndreas Gohruse dokuwiki\Ui\Subscribe;
19e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AdminPlugin;
20e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event;
212cd6cc0aSAndreas Gohruse dokuwiki\File\PageResolver;
22e1d9dcc8SAndreas Gohr
236b13307fSandi/**
24ac7a515fSAndreas Gohr * Access a template file
25ac7a515fSAndreas Gohr *
26ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
27ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
285a892029SAndreas Gohr *
295a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
30ac7a515fSAndreas Gohr * @param string $file
31ac7a515fSAndreas Gohr * @return string
325a892029SAndreas Gohr */
33d868eb89SAndreas Gohrfunction template($file)
34d868eb89SAndreas Gohr{
355a892029SAndreas Gohr    global $conf;
365a892029SAndreas Gohr
37ac7a515fSAndreas Gohr    if (@is_readable(DOKU_INC . 'lib/tpl/' . $conf['template'] . '/' . $file))
38ac7a515fSAndreas Gohr        return DOKU_INC . 'lib/tpl/' . $conf['template'] . '/' . $file;
395a892029SAndreas Gohr
40ac7a515fSAndreas Gohr    return DOKU_INC . 'lib/tpl/dokuwiki/' . $file;
415a892029SAndreas Gohr}
425a892029SAndreas Gohr
43c4766956SAndreas Gohr/**
44c4766956SAndreas Gohr * Convenience function to access template dir from local FS
45c4766956SAndreas Gohr *
46c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
47c4766956SAndreas Gohr *
48c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
49afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
50ac7a515fSAndreas Gohr * @return string
51c4766956SAndreas Gohr */
52d868eb89SAndreas Gohrfunction tpl_incdir($tpl = '')
53d868eb89SAndreas Gohr{
5475b14482SAndreas Gohr    global $conf;
55afb2c082SAndreas Gohr    if (!$tpl) $tpl = $conf['template'];
56afb2c082SAndreas Gohr    return DOKU_INC . 'lib/tpl/' . $tpl . '/';
57c4766956SAndreas Gohr}
58c4766956SAndreas Gohr
59c4766956SAndreas Gohr/**
60c4766956SAndreas Gohr * Convenience function to access template dir from web
61c4766956SAndreas Gohr *
62c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
63c4766956SAndreas Gohr *
64c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
65afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
66ac7a515fSAndreas Gohr * @return string
67c4766956SAndreas Gohr */
68d868eb89SAndreas Gohrfunction tpl_basedir($tpl = '')
69d868eb89SAndreas Gohr{
7075b14482SAndreas Gohr    global $conf;
71afb2c082SAndreas Gohr    if (!$tpl) $tpl = $conf['template'];
72dcd4911eSMichael Hamann    return DOKU_BASE . 'lib/tpl/' . $tpl . '/';
73c4766956SAndreas Gohr}
74c4766956SAndreas Gohr
755a892029SAndreas Gohr/**
766b13307fSandi * Print the content
776b13307fSandi *
786b13307fSandi * This function is used for printing all the usual content
796b13307fSandi * (defined by the global $ACT var) by calling the appropriate
806b13307fSandi * outputfunction(s) from html.php
816b13307fSandi *
82ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
83ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
846b13307fSandi *
856b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8642ea7f44SGerrit Uitslag *
87ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
88ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
89ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
90ac7a515fSAndreas Gohr * @return bool true if any output
916b13307fSandi */
92d868eb89SAndreas Gohrfunction tpl_content($prependTOC = true)
93d868eb89SAndreas Gohr{
947ea0913cSchris    global $ACT;
95b8595a66SAndreas Gohr    global $INFO;
96b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
977ea0913cSchris
987ea0913cSchris    ob_start();
99cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
1007ea0913cSchris    $html_output = ob_get_clean();
101cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
10254e95700STom N Harris
10354e95700STom N Harris    return !empty($html_output);
1047ea0913cSchris}
1057ea0913cSchris
106ac7a515fSAndreas Gohr/**
107ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
108ac7a515fSAndreas Gohr *
109ac7a515fSAndreas Gohr * @return bool
110ac7a515fSAndreas Gohr */
111d868eb89SAndreas Gohrfunction tpl_content_core()
112d868eb89SAndreas Gohr{
11324870174SAndreas Gohr    $router = ActionRouter::getInstance();
114952acff9SAndreas Gohr    try {
115952acff9SAndreas Gohr        $router->getAction()->tplContent();
11624870174SAndreas Gohr    } catch (FatalException $e) {
117952acff9SAndreas Gohr        // there was no content for the action
118952acff9SAndreas Gohr        msg(hsc($e->getMessage()), -1);
11954e95700STom N Harris        return false;
1206b13307fSandi    }
12154e95700STom N Harris    return true;
1226b13307fSandi}
1236b13307fSandi
124c19fe9c0Sandi/**
125b8595a66SAndreas Gohr * Places the TOC where the function is called
126b8595a66SAndreas Gohr *
127b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
128b8595a66SAndreas Gohr * a false argument
129b8595a66SAndreas Gohr *
130b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13142ea7f44SGerrit Uitslag *
132ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
133ac7a515fSAndreas Gohr * @return string
134b8595a66SAndreas Gohr */
135d868eb89SAndreas Gohrfunction tpl_toc($return = false)
136d868eb89SAndreas Gohr{
137b8595a66SAndreas Gohr    global $TOC;
138b8595a66SAndreas Gohr    global $ACT;
139b8595a66SAndreas Gohr    global $ID;
140b8595a66SAndreas Gohr    global $REV;
141b8595a66SAndreas Gohr    global $INFO;
142851f2e89SAnika Henke    global $conf;
143ac7a515fSAndreas Gohr    global $INPUT;
14424870174SAndreas Gohr    $toc = [];
145b8595a66SAndreas Gohr
146b8595a66SAndreas Gohr    if (is_array($TOC)) {
147b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
148b8595a66SAndreas Gohr        $toc = $TOC;
1493c86d7c9SAndreas Gohr    } elseif (($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
150b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
151e0c26282SGerrit Uitslag        $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
152b8595a66SAndreas Gohr        if (isset($meta['internal']['toc'])) {
153b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
154b8595a66SAndreas Gohr        } else {
1552bb0d541Schris            $tocok = true;
156b8595a66SAndreas Gohr        }
15724870174SAndreas Gohr        $toc = $meta['description']['tableofcontents'] ?? null;
158851f2e89SAnika Henke        if (!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
15924870174SAndreas Gohr            $toc = [];
160b8595a66SAndreas Gohr        }
161b8595a66SAndreas Gohr    } elseif ($ACT == 'admin') {
162a61966c5SChristopher Smith        // try to load admin plugin TOC
163e1d9dcc8SAndreas Gohr        /** @var $plugin AdminPlugin */
164a61966c5SChristopher Smith        if ($plugin = plugin_getRequestAdminPlugin()) {
165b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
166b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
167b8595a66SAndreas Gohr        }
168b8595a66SAndreas Gohr    }
169b8595a66SAndreas Gohr
170cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
171b8595a66SAndreas Gohr    $html = html_TOC($toc);
172b8595a66SAndreas Gohr    if ($return) return $html;
173b8595a66SAndreas Gohr    echo $html;
174ac7a515fSAndreas Gohr    return '';
175b8595a66SAndreas Gohr}
176b8595a66SAndreas Gohr
177b8595a66SAndreas Gohr/**
178c19fe9c0Sandi * Handle the admin page contents
179c19fe9c0Sandi *
180c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
18142ea7f44SGerrit Uitslag *
18242ea7f44SGerrit Uitslag * @return bool
183c19fe9c0Sandi */
184d868eb89SAndreas Gohrfunction tpl_admin()
185d868eb89SAndreas Gohr{
186f8cc712eSAndreas Gohr    global $INFO;
187b8595a66SAndreas Gohr    global $TOC;
188ac7a515fSAndreas Gohr    global $INPUT;
18911e2ce22Schris
190b8595a66SAndreas Gohr    $plugin = null;
191ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
192ac7a515fSAndreas Gohr    if (!empty($class)) {
19311e2ce22Schris        $pluginlist = plugin_list('admin');
19411e2ce22Schris
195ac7a515fSAndreas Gohr        if (in_array($class, $pluginlist)) {
19611e2ce22Schris            // attempt to load the plugin
197e1d9dcc8SAndreas Gohr            /** @var $plugin AdminPlugin */
198a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
19911e2ce22Schris        }
20011e2ce22Schris    }
20111e2ce22Schris
20224870174SAndreas Gohr    if ($plugin instanceof PluginInterface) {
203b8595a66SAndreas Gohr        if (!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
204b8595a66SAndreas Gohr        if ($INFO['prependTOC']) tpl_toc();
205f8cc712eSAndreas Gohr        $plugin->html();
206f8cc712eSAndreas Gohr    } else {
20724870174SAndreas Gohr        $admin = new Admin();
2080470c28fSAndreas Gohr        $admin->show();
209f8cc712eSAndreas Gohr    }
21054e95700STom N Harris    return true;
211c19fe9c0Sandi}
2126b13307fSandi
2136b13307fSandi/**
2146b13307fSandi * Print the correct HTML meta headers
2156b13307fSandi *
2166b13307fSandi * This has to go into the head section of your template.
2176b13307fSandi *
2186b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
21942ea7f44SGerrit Uitslag *
220ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
221ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
222ac7a515fSAndreas Gohr * @return bool
2236b13307fSandi */
224d868eb89SAndreas Gohrfunction tpl_metaheaders($alt = true)
225d868eb89SAndreas Gohr{
2266b13307fSandi    global $ID;
227d98d4540SBen Coburn    global $REV;
2286b13307fSandi    global $INFO;
22972e0dc37SAndreas Gohr    global $JSINFO;
2306b13307fSandi    global $ACT;
2314bb1b5aeSAndreas Gohr    global $QUERY;
2326b13307fSandi    global $lang;
233dc57ef04Sandi    global $conf;
2349c438d6cSMichael Hamann    global $updateVersion;
235585bf44eSChristopher Smith    /** @var Input $INPUT */
236585bf44eSChristopher Smith    global $INPUT;
2376b13307fSandi
2387bff22c0SAndreas Gohr    // prepare the head array
23924870174SAndreas Gohr    $head = [];
2407bff22c0SAndreas Gohr
241202ac28bSMichael Klier    // prepare seed for js and css
242cd997f93SAndreas Gohr    $tseed   = $updateVersion;
243202ac28bSMichael Klier    $depends = getConfigFiles('main');
24484e76a7eSAndreas Gohr    $depends[] = DOKU_CONF . "tpl/" . $conf['template'] . "/style.ini";
245cd997f93SAndreas Gohr    foreach ($depends as $f) $tseed .= @filemtime($f);
246cd997f93SAndreas Gohr    $tseed   = md5($tseed);
2477bff22c0SAndreas Gohr
2486b13307fSandi    // the usual stuff
24924870174SAndreas Gohr    $head['meta'][] = ['name' => 'generator', 'content' => 'DokuWiki'];
25063cf4192Ssarehag    if (actionOK('search')) {
25124870174SAndreas Gohr        $head['link'][] = [
25224870174SAndreas Gohr            'rel' => 'search',
25324870174SAndreas Gohr            'type' => 'application/opensearchdescription+xml',
25424870174SAndreas Gohr            'href' => DOKU_BASE . 'lib/exe/opensearch.php',
25524870174SAndreas Gohr            'title' => $conf['title']
25624870174SAndreas Gohr        ];
25763cf4192Ssarehag    }
25863cf4192Ssarehag
25924870174SAndreas Gohr    $head['link'][] = ['rel' => 'start', 'href' => DOKU_BASE];
2607aedde2eSGina Haeussge    if (actionOK('index')) {
26124870174SAndreas Gohr        $head['link'][] = [
26224870174SAndreas Gohr            'rel'  => 'contents',
26324870174SAndreas Gohr            'href' => wl($ID, 'do=index', false, '&'),
264ac7a515fSAndreas Gohr            'title' => $lang['btn_index']
26524870174SAndreas Gohr        ];
2667aedde2eSGina Haeussge    }
267f96fa415SAndreas Gohr
2685e0255e3SMichael Große    if (actionOK('manifest')) {
26924870174SAndreas Gohr        $head['link'][] = [
27024870174SAndreas Gohr            'rel' => 'manifest',
27124870174SAndreas Gohr            'href' => DOKU_BASE . 'lib/exe/manifest.php'
27224870174SAndreas Gohr        ];
2735e0255e3SMichael Große    }
2745e0255e3SMichael Große
27524870174SAndreas Gohr    $styleUtil = new StyleUtils();
2764593dbd2SAnna Dabrowska    $styleIni = $styleUtil->cssStyleini();
27740ca8540SMichael Große    $replacements = $styleIni['replacements'];
27840ca8540SMichael Große    if (!empty($replacements['__theme_color__'])) {
27924870174SAndreas Gohr        $head['meta'][] = [
28024870174SAndreas Gohr            'name' => 'theme-color',
28124870174SAndreas Gohr            'content' => $replacements['__theme_color__']
28224870174SAndreas Gohr        ];
28340ca8540SMichael Große    }
28440ca8540SMichael Große
285f96fa415SAndreas Gohr    if ($alt) {
28654be1338SGerrit Uitslag        if (actionOK('rss')) {
28724870174SAndreas Gohr            $head['link'][] = [
28824870174SAndreas Gohr                'rel'  => 'alternate',
28924870174SAndreas Gohr                'type' => 'application/rss+xml',
29024870174SAndreas Gohr                'title' => $lang['btn_recent'],
29124870174SAndreas Gohr                'href' => DOKU_BASE . 'feed.php'
29224870174SAndreas Gohr            ];
29324870174SAndreas Gohr            $head['link'][] = [
29424870174SAndreas Gohr                'rel'  => 'alternate',
29524870174SAndreas Gohr                'type' => 'application/rss+xml',
296a1288caeSGerrit Uitslag                'title' => $lang['currentns'],
297aac83cd4SPhy                'href' => DOKU_BASE . 'feed.php?mode=list&ns=' . (isset($INFO) ? $INFO['namespace'] : '')
29824870174SAndreas Gohr            ];
29954be1338SGerrit Uitslag        }
300c35f3875SAndreas Gohr        if (($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
30124870174SAndreas Gohr            $head['link'][] = [
302ac7a515fSAndreas Gohr                'rel'  => 'edit',
303715bdf1fSAndreas Gohr                'title' => $lang['btn_edit'],
304ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
30524870174SAndreas Gohr            ];
306c35f3875SAndreas Gohr        }
307c35f3875SAndreas Gohr
30854be1338SGerrit Uitslag        if (actionOK('rss') && $ACT == 'search') {
30924870174SAndreas Gohr            $head['link'][] = [
31024870174SAndreas Gohr                'rel'  => 'alternate',
31124870174SAndreas Gohr                'type' => 'application/rss+xml',
312a1288caeSGerrit Uitslag                'title' => $lang['searchresult'],
313ac7a515fSAndreas Gohr                'href' => DOKU_BASE . 'feed.php?mode=search&q=' . $QUERY
31424870174SAndreas Gohr            ];
3154bb1b5aeSAndreas Gohr        }
316bae36d94SAndreas Gohr
317bae36d94SAndreas Gohr        if (actionOK('export_xhtml')) {
31824870174SAndreas Gohr            $head['link'][] = [
31924870174SAndreas Gohr                'rel' => 'alternate',
32024870174SAndreas Gohr                'type' => 'text/html',
32124870174SAndreas Gohr                'title' => $lang['plainhtml'],
322ac7a515fSAndreas Gohr                'href' => exportlink($ID, 'xhtml', '', false, '&')
32324870174SAndreas Gohr            ];
324bae36d94SAndreas Gohr        }
325bae36d94SAndreas Gohr
326bae36d94SAndreas Gohr        if (actionOK('export_raw')) {
32724870174SAndreas Gohr            $head['link'][] = [
32824870174SAndreas Gohr                'rel' => 'alternate',
32924870174SAndreas Gohr                'type' => 'text/plain',
33024870174SAndreas Gohr                'title' => $lang['wikimarkup'],
331ac7a515fSAndreas Gohr                'href' => exportlink($ID, 'raw', '', false, '&')
33224870174SAndreas Gohr            ];
333f96fa415SAndreas Gohr        }
334bae36d94SAndreas Gohr    }
3356b13307fSandi
33663f13cadSDamien Regad    // setup robot tags appropriate for different modes
3374f2e0004STim Weber    if (($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3386b13307fSandi        if ($INFO['exists']) {
3396b13307fSandi            //delay indexing:
340fb9fa88bSAndreas Gohr            if ((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID)) {
34124870174SAndreas Gohr                $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow'];
3426b13307fSandi            } else {
34324870174SAndreas Gohr                $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow'];
3446b13307fSandi            }
34501f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
34601f9be51SAnika Henke            if ($ID == $conf['start']) {
34701f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
34801f9be51SAnika Henke            }
34924870174SAndreas Gohr            $head['link'][] = ['rel' => 'canonical', 'href' => $canonicalUrl];
3506b13307fSandi        } else {
35124870174SAndreas Gohr            $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,follow'];
3526b13307fSandi        }
3537a24876fSAndreas Gohr    } elseif (defined('DOKU_MEDIADETAIL')) {
35424870174SAndreas Gohr        $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow'];
3556b13307fSandi    } else {
35624870174SAndreas Gohr        $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow'];
3576b13307fSandi    }
3586b13307fSandi
359831800b8SAndreas Gohr    // set metadata
360831800b8SAndreas Gohr    if ($ACT == 'show' || $ACT == 'export_xhtml') {
361831800b8SAndreas Gohr        // keywords (explicit or implicit)
362bb4866bdSchris        if (!empty($INFO['meta']['subject'])) {
36324870174SAndreas Gohr            $head['meta'][] = ['name' => 'keywords', 'content' => implode(',', $INFO['meta']['subject'])];
364831800b8SAndreas Gohr        } else {
36524870174SAndreas Gohr            $head['meta'][] = ['name' => 'keywords', 'content' => str_replace(':', ',', $ID)];
366831800b8SAndreas Gohr        }
367831800b8SAndreas Gohr    }
368831800b8SAndreas Gohr
36978a6aeb1SAndreas Gohr    // load stylesheets
37024870174SAndreas Gohr    $head['link'][] = [
37159305168SPhy        'rel' => 'stylesheet',
372e283bd6cSAnika Henke        'href' => DOKU_BASE . 'lib/exe/css.php?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed
37324870174SAndreas Gohr    ];
374bad31ae9SAndreas Gohr
375aac83cd4SPhy    $script = "var NS='" . (isset($INFO) ? $INFO['namespace'] : '') . "';";
376585bf44eSChristopher Smith    if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
37798169a0fSAndreas Gohr        $script .= "var SIG=" . toolbar_signature() . ";";
378c591aabeSAndreas Gohr    }
3790c39d46cSMichael Große    jsinfo();
38024870174SAndreas Gohr    $script .= 'var JSINFO = ' . json_encode($JSINFO, JSON_THROW_ON_ERROR) . ';';
38124870174SAndreas Gohr    $head['script'][] = ['_data' => $script];
3828bbcb611SAndreas Gohr
38361537d47SAndreas Gohr    // load jquery
384fa078663SAndreas Gohr    $jquery = getCdnUrls();
385fa078663SAndreas Gohr    foreach ($jquery as $src) {
38624870174SAndreas Gohr        $head['script'][] = [
387fc6b11d2SMichael Große                '_data' => '',
38824870174SAndreas Gohr                'src' => $src
38924870174SAndreas Gohr            ] + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
39061537d47SAndreas Gohr    }
39161537d47SAndreas Gohr
39261537d47SAndreas Gohr    // load our javascript dispatcher
39324870174SAndreas Gohr    $head['script'][] = [
394de1dc35bSNicolas Friedli            '_data' => '',
39524870174SAndreas Gohr            'src' => DOKU_BASE . 'lib/exe/js.php' . '?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed
39624870174SAndreas Gohr        ] + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
3977bff22c0SAndreas Gohr
3987bff22c0SAndreas Gohr    // trigger event here
399cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
40054e95700STom N Harris    return true;
4017bff22c0SAndreas Gohr}
4027bff22c0SAndreas Gohr
4037bff22c0SAndreas Gohr/**
4047bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
4057bff22c0SAndreas Gohr *
4067bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
4077bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
4087bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
4097bff22c0SAndreas Gohr *
41042ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
4111304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
4127bff22c0SAndreas Gohr *
4137bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
41442ea7f44SGerrit Uitslag *
41542ea7f44SGerrit Uitslag * @param array $data
4167bff22c0SAndreas Gohr */
417d868eb89SAndreas Gohrfunction _tpl_metaheaders_action($data)
418d868eb89SAndreas Gohr{
4197bff22c0SAndreas Gohr    foreach ($data as $tag => $inst) {
420427bf9a2SAndreas Gohr        if ($tag == 'script') {
421427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
422427bf9a2SAndreas Gohr        }
4237bff22c0SAndreas Gohr        foreach ($inst as $attr) {
424177d6836SAndreas Gohr            if (empty($attr)) {
425*d4f83172SAndreas Gohr                continue;
426*d4f83172SAndreas Gohr            }
4277bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
42826afa874SMikhail I. Izmestev            if (isset($attr['_data']) || $tag == 'script') {
429740897dcSasivery                if ($tag == 'script' && isset($attr['_data']))
43009f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/" .
431e226efe1SAndreas Gohr                        $attr['_data'] .
43209f791c4SDominik Eckelmann                        "\n/*!]]>*/";
433e226efe1SAndreas Gohr
43424870174SAndreas Gohr                echo '>', $attr['_data'] ?? '', '</', $tag, '>';
4357bff22c0SAndreas Gohr            } else {
4367bff22c0SAndreas Gohr                echo '/>';
4377bff22c0SAndreas Gohr            }
4387bff22c0SAndreas Gohr            echo "\n";
4397bff22c0SAndreas Gohr        }
440427bf9a2SAndreas Gohr        if ($tag == 'script') {
441427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
442427bf9a2SAndreas Gohr        }
4437bff22c0SAndreas Gohr    }
4446b13307fSandi}
4456b13307fSandi
4466b13307fSandi/**
4476b13307fSandi * Print a link
4486b13307fSandi *
4495e163278SAndreas Gohr * Just builds a link.
4506b13307fSandi *
4516b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
45242ea7f44SGerrit Uitslag *
45342ea7f44SGerrit Uitslag * @param string $url
45442ea7f44SGerrit Uitslag * @param string $name
45542ea7f44SGerrit Uitslag * @param string $more
45621d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
45721d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
4586b13307fSandi */
459d868eb89SAndreas Gohrfunction tpl_link($url, $name, $more = '', $return = false)
460d868eb89SAndreas Gohr{
46101f17825SAnika Henke    $out = '<a href="' . $url . '" ';
4621af98a77SAnika Henke    if ($more) $out .= ' ' . $more;
4631af98a77SAnika Henke    $out .= ">$name</a>";
4641af98a77SAnika Henke    if ($return) return $out;
46526dfc232SAndreas Gohr    echo $out;
46654e95700STom N Harris    return true;
4676b13307fSandi}
4686b13307fSandi
4696b13307fSandi/**
47055efc227SAndreas Gohr * Prints a link to a WikiPage
47155efc227SAndreas Gohr *
47255efc227SAndreas Gohr * Wrapper around html_wikilink
47355efc227SAndreas Gohr *
47455efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
47542ea7f44SGerrit Uitslag *
47642ea7f44SGerrit Uitslag * @param string      $id   page id
47742ea7f44SGerrit Uitslag * @param string|null $name the name of the link
478fb008d31SIain Hallam * @param bool        $return
479fb008d31SIain Hallam * @return true|string
48055efc227SAndreas Gohr */
481d868eb89SAndreas Gohrfunction tpl_pagelink($id, $name = null, $return = false)
482d868eb89SAndreas Gohr{
483c4a386f1SIain Hallam    $out = '<bdi>' . html_wikilink($id, $name) . '</bdi>';
484c4a386f1SIain Hallam    if ($return) return $out;
48526dfc232SAndreas Gohr    echo $out;
48654e95700STom N Harris    return true;
48755efc227SAndreas Gohr}
48855efc227SAndreas Gohr
48955efc227SAndreas Gohr/**
490a3ec5f4aSmatthiasgrimm * get the parent page
491a3ec5f4aSmatthiasgrimm *
492a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
493a3ec5f4aSmatthiasgrimm * returns false if none is available
494a3ec5f4aSmatthiasgrimm *
495377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
49642ea7f44SGerrit Uitslag *
49742ea7f44SGerrit Uitslag * @param string $id page id
49842ea7f44SGerrit Uitslag * @return false|string
499a3ec5f4aSmatthiasgrimm */
500d868eb89SAndreas Gohrfunction tpl_getparent($id)
501d868eb89SAndreas Gohr{
5028c6be208SAndreas Gohr    $resolver = new PageResolver('root');
5038c6be208SAndreas Gohr
504377f9e97SAndreas Gohr    $parent = getNS($id) . ':';
5058c6be208SAndreas Gohr    $parent = $resolver->resolveId($parent);
506a197105eSmatthiasgrimm    if ($parent == $id) {
507a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
508a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos) . ':';
5098c6be208SAndreas Gohr        $parent = $resolver->resolveId($parent);
510377f9e97SAndreas Gohr        if ($parent == $id) return false;
511a197105eSmatthiasgrimm    }
512377f9e97SAndreas Gohr    return $parent;
513a3ec5f4aSmatthiasgrimm}
514a3ec5f4aSmatthiasgrimm
515a3ec5f4aSmatthiasgrimm/**
5166b13307fSandi * Print one of the buttons
5176b13307fSandi *
518a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
519a453d131SAdrian Lang * @see    tpl_get_action
520e0c26282SGerrit Uitslag *
521e0c26282SGerrit Uitslag * @param string $type
522e0c26282SGerrit Uitslag * @param bool $return
523e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
524affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
5256b13307fSandi */
526d868eb89SAndreas Gohrfunction tpl_button($type, $return = false)
527d868eb89SAndreas Gohr{
528affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
529a453d131SAdrian Lang    $data = tpl_get_action($type);
530a453d131SAdrian Lang    if ($data === false) {
531a453d131SAdrian Lang        return false;
532a453d131SAdrian Lang    } elseif (!is_array($data)) {
533a453d131SAdrian Lang        $out = sprintf($data, 'button');
534409d7af7SAndreas Gohr    } else {
535ac7a515fSAndreas Gohr        /**
536ac7a515fSAndreas Gohr         * @var string $accesskey
537ac7a515fSAndreas Gohr         * @var string $id
538ac7a515fSAndreas Gohr         * @var string $method
539ac7a515fSAndreas Gohr         * @var array  $params
540ac7a515fSAndreas Gohr         */
541a453d131SAdrian Lang        extract($data);
542a453d131SAdrian Lang        if ($id === '#dokuwiki__top') {
543a453d131SAdrian Lang            $out = html_topbtn();
544409d7af7SAndreas Gohr        } else {
545a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
546409d7af7SAndreas Gohr        }
547409d7af7SAndreas Gohr    }
5481af98a77SAnika Henke    if ($return) return $out;
549a453d131SAdrian Lang    echo $out;
550a453d131SAdrian Lang    return true;
5516b13307fSandi}
5526b13307fSandi
5536b13307fSandi/**
554ed630903Sandi * Like the action buttons but links
555ed630903Sandi *
556a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
557a453d131SAdrian Lang * @see    tpl_get_action
558e0c26282SGerrit Uitslag *
55942ea7f44SGerrit Uitslag * @param string $type    action command
560e0c26282SGerrit Uitslag * @param string $pre     prefix of link
561e0c26282SGerrit Uitslag * @param string $suf     suffix of link
562e0c26282SGerrit Uitslag * @param string $inner   innerHML of link
56321d806cdSGerrit Uitslag * @param bool   $return  if true it returns html, otherwise prints
564e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
565affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
566a453d131SAdrian Lang */
567d868eb89SAndreas Gohrfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false)
568d868eb89SAndreas Gohr{
569affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
570a453d131SAdrian Lang    global $lang;
571a453d131SAdrian Lang    $data = tpl_get_action($type);
572a453d131SAdrian Lang    if ($data === false) {
573a453d131SAdrian Lang        return false;
574a453d131SAdrian Lang    } elseif (!is_array($data)) {
575a453d131SAdrian Lang        $out = sprintf($data, 'link');
576a453d131SAdrian Lang    } else {
577ac7a515fSAndreas Gohr        /**
578ac7a515fSAndreas Gohr         * @var string $accesskey
579ac7a515fSAndreas Gohr         * @var string $id
580ac7a515fSAndreas Gohr         * @var string $method
581b1af9014SChristopher Smith         * @var bool   $nofollow
582ac7a515fSAndreas Gohr         * @var array  $params
583becfa414SGerrit Uitslag         * @var string $replacement
584ac7a515fSAndreas Gohr         */
585a453d131SAdrian Lang        extract($data);
586a453d131SAdrian Lang        if (strpos($id, '#') === 0) {
587a453d131SAdrian Lang            $linktarget = $id;
588a453d131SAdrian Lang        } else {
589a453d131SAdrian Lang            $linktarget = wl($id, $params);
590a453d131SAdrian Lang        }
591a453d131SAdrian Lang        $caption = $lang['btn_' . $type];
592becfa414SGerrit Uitslag        if (strpos($caption, '%s')) {
593becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
594becfa414SGerrit Uitslag        }
59524870174SAndreas Gohr        $akey = '';
59624870174SAndreas Gohr        $addTitle = '';
597c7e90e3fSAnika Henke        if ($accesskey) {
598c7e90e3fSAnika Henke            $akey     = 'accesskey="' . $accesskey . '" ';
599c7e90e3fSAnika Henke            $addTitle = ' [' . strtoupper($accesskey) . ']';
600c7e90e3fSAnika Henke        }
601b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
602ac7a515fSAndreas Gohr        $out = tpl_link(
603dccd6b2bSAndreas Gohr            $linktarget,
604dccd6b2bSAndreas Gohr            $pre . ($inner ?: $caption) . $suf,
605a453d131SAdrian Lang            'class="action ' . $type . '" ' .
606b1af9014SChristopher Smith                $akey . $rel .
607dccd6b2bSAndreas Gohr                'title="' . hsc($caption) . $addTitle . '"',
608dccd6b2bSAndreas Gohr            true
609ac7a515fSAndreas Gohr        );
610a453d131SAdrian Lang    }
611a453d131SAdrian Lang    if ($return) return $out;
612a453d131SAdrian Lang    echo $out;
613a453d131SAdrian Lang    return true;
614a453d131SAdrian Lang}
615a453d131SAdrian Lang
616a453d131SAdrian Lang/**
617a453d131SAdrian Lang * Check the actions and get data for buttons and links
618ed630903Sandi *
619ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
620a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
621a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
622e0c26282SGerrit Uitslag *
623ac7a515fSAndreas Gohr * @param string $type
624ac7a515fSAndreas Gohr * @return array|bool|string
625affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
626ed630903Sandi */
627d868eb89SAndreas Gohrfunction tpl_get_action($type)
628d868eb89SAndreas Gohr{
629affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
630a453d131SAdrian Lang    if ($type == 'history') $type = 'revisions';
6314c4b65c8SMichael Hamann    if ($type == 'subscription') $type = 'subscribe';
6324887c154SAndreas Gohr    if ($type == 'img_backto') $type = 'imgBackto';
633409d7af7SAndreas Gohr
6344887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
6354887c154SAndreas Gohr    if (class_exists($class)) {
6364887c154SAndreas Gohr        try {
63724870174SAndreas Gohr            /** @var AbstractItem $item */
63873022918SAndreas Gohr            $item = new $class();
6394887c154SAndreas Gohr            $data = $item->getLegacyData();
6407b4365a7SGerrit Uitslag            $unknown = false;
6414887c154SAndreas Gohr        } catch (\RuntimeException $ignored) {
6424887c154SAndreas Gohr            return false;
643b8a111f5SMichael Klier        }
644ed630903Sandi    } else {
6454887c154SAndreas Gohr        global $ID;
64624870174SAndreas Gohr        $data = [
6474887c154SAndreas Gohr            'accesskey' => null,
6484887c154SAndreas Gohr            'type' => $type,
6494887c154SAndreas Gohr            'id' => $ID,
6504887c154SAndreas Gohr            'method' => 'get',
65124870174SAndreas Gohr            'params' => ['do' => $type],
6524887c154SAndreas Gohr            'nofollow' => true,
65324870174SAndreas Gohr            'replacement' => ''
65424870174SAndreas Gohr        ];
6557b4365a7SGerrit Uitslag        $unknown = true;
656ed630903Sandi    }
6577b4365a7SGerrit Uitslag
658e1d9dcc8SAndreas Gohr    $evt = new Event('TPL_ACTION_GET', $data);
6597b4365a7SGerrit Uitslag    if ($evt->advise_before()) {
6607b4365a7SGerrit Uitslag        //handle unknown types
6617b4365a7SGerrit Uitslag        if ($unknown) {
66238d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6637b4365a7SGerrit Uitslag        }
6647b4365a7SGerrit Uitslag    }
6657b4365a7SGerrit Uitslag    $evt->advise_after();
6667b4365a7SGerrit Uitslag    unset($evt);
6677b4365a7SGerrit Uitslag
6687b4365a7SGerrit Uitslag    return $data;
669ed630903Sandi}
670ed630903Sandi
671ed630903Sandi/**
67201f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
67301f17825SAnika Henke *
67401f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
67542ea7f44SGerrit Uitslag *
67642ea7f44SGerrit Uitslag * @param string        $type action command
677ac7a515fSAndreas Gohr * @param bool          $link link or form button?
678e0c26282SGerrit Uitslag * @param string|bool   $wrapper HTML element wrapper
679ac7a515fSAndreas Gohr * @param bool          $return return or print
680ac7a515fSAndreas Gohr * @param string        $pre prefix for links
681ac7a515fSAndreas Gohr * @param string        $suf suffix for links
682ac7a515fSAndreas Gohr * @param string        $inner inner HTML for links
683ac7a515fSAndreas Gohr * @return bool|string
684affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
68501f17825SAnika Henke */
686d868eb89SAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '')
687d868eb89SAndreas Gohr{
688affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
68901f17825SAnika Henke    $out = '';
690ac7a515fSAndreas Gohr    if ($link) {
691e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
692ac7a515fSAndreas Gohr    } else {
693e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
694ac7a515fSAndreas Gohr    }
69501f17825SAnika Henke    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
69601f17825SAnika Henke
69701f17825SAnika Henke    if ($return) return $out;
69826dfc232SAndreas Gohr    echo $out;
69924870174SAndreas Gohr    return (bool) $out;
70001f17825SAnika Henke}
70101f17825SAnika Henke
70201f17825SAnika Henke/**
7036b13307fSandi * Print the search form
7046b13307fSandi *
70572645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
70672645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
70772645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
70872645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
70972645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
71072645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
71172645b75SAndreas Gohr *
7126b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
71342ea7f44SGerrit Uitslag *
714ac7a515fSAndreas Gohr * @param bool $ajax
715ac7a515fSAndreas Gohr * @param bool $autocomplete
716ac7a515fSAndreas Gohr * @return bool
7176b13307fSandi */
718d868eb89SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true)
719d868eb89SAndreas Gohr{
7206b13307fSandi    global $lang;
721c1e3b7d9Smatthiasgrimm    global $ACT;
722ad4aaef7SAndreas Gohr    global $QUERY;
723cbcc2fa5SMichael Große    global $ID;
724c1e3b7d9Smatthiasgrimm
725670ff54eSchris    // don't print the search form if search action has been disabled
72664276bbcSarbrk1    if (!actionOK('search')) return false;
727670ff54eSchris
72824870174SAndreas Gohr    $searchForm = new Form([
7293c7a3327SMichael Große        'action' => wl(),
7303c7a3327SMichael Große        'method' => 'get',
7313c7a3327SMichael Große        'role' => 'search',
7323c7a3327SMichael Große        'class' => 'search',
7333c7a3327SMichael Große        'id' => 'dw__search',
7347fa270bcSMichael Große    ], true);
7353eb2b869SMichael Große    $searchForm->addTagOpen('div')->addClass('no');
7363c7a3327SMichael Große    $searchForm->setHiddenField('do', 'search');
737d22b78c8SMichael Große    $searchForm->setHiddenField('id', $ID);
738d22b78c8SMichael Große    $searchForm->addTextInput('q')
7393c7a3327SMichael Große        ->addClass('edit')
7403c7a3327SMichael Große        ->attrs([
7413c7a3327SMichael Große            'title' => '[F]',
7423c7a3327SMichael Große            'accesskey' => 'f',
7433c7a3327SMichael Große            'placeholder' => $lang['btn_search'],
7443c7a3327SMichael Große            'autocomplete' => $autocomplete ? 'on' : 'off',
7453c7a3327SMichael Große        ])
7463c7a3327SMichael Große        ->id('qsearch__in')
7473c7a3327SMichael Große        ->val($ACT === 'search' ? $QUERY : '')
7483c7a3327SMichael Große        ->useInput(false)
7493c7a3327SMichael Große    ;
7503c7a3327SMichael Große    $searchForm->addButton('', $lang['btn_search'])->attrs([
7513c7a3327SMichael Große        'type' => 'submit',
7523c7a3327SMichael Große        'title' => $lang['btn_search'],
7533c7a3327SMichael Große    ]);
7543c7a3327SMichael Große    if ($ajax) {
7553c7a3327SMichael Große        $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
7563c7a3327SMichael Große        $searchForm->addTagClose('div');
7573c7a3327SMichael Große    }
7583eb2b869SMichael Große    $searchForm->addTagClose('div');
7593c7a3327SMichael Große
760c6977b3aSSatoshi Sahara    echo $searchForm->toHTML('QuickSearch');
7613c7a3327SMichael Große
76254e95700STom N Harris    return true;
7636b13307fSandi}
7646b13307fSandi
7656b13307fSandi/**
7666b13307fSandi * Print the breadcrumbs trace
7676b13307fSandi *
7686b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
76942ea7f44SGerrit Uitslag *
770ac7a515fSAndreas Gohr * @param string $sep Separator between entries
771c4a386f1SIain Hallam * @param bool   $return return or print
772c4a386f1SIain Hallam * @return bool|string
7736b13307fSandi */
774d868eb89SAndreas Gohrfunction tpl_breadcrumbs($sep = null, $return = false)
775d868eb89SAndreas Gohr{
7766b13307fSandi    global $lang;
7776b13307fSandi    global $conf;
7786b13307fSandi
7796b13307fSandi    //check if enabled
780359fab8bSMichael Hamann    if (!$conf['breadcrumbs']) return false;
7816b13307fSandi
782c4a386f1SIain Hallam    //set default
783c4a386f1SIain Hallam    if (is_null($sep)) $sep = '•';
784c4a386f1SIain Hallam
785c4a386f1SIain Hallam    $out = '';
786c4a386f1SIain Hallam
7876b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
788265e3787Sandi
7892979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">' . $sep . '</span> ';
790265e3787Sandi
79140eb54bbSjan    //render crumbs, highlight the last one
792c4a386f1SIain Hallam    $out .= '<span class="bchead">' . $lang['breadcrumb'] . '</span>';
79340eb54bbSjan    $last = count($crumbs);
79440eb54bbSjan    $i    = 0;
795a77f5846Sjan    foreach ($crumbs as $id => $name) {
79640eb54bbSjan        $i++;
797c4a386f1SIain Hallam        $out .= $crumbs_sep;
798c4a386f1SIain Hallam        if ($i == $last) $out .= '<span class="curid">';
799c4a386f1SIain Hallam        $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="' . $id . '"', true) .  '</bdi>';
800c4a386f1SIain Hallam        if ($i == $last) $out .= '</span>';
8016b13307fSandi    }
802c4a386f1SIain Hallam    if ($return) return $out;
80326dfc232SAndreas Gohr    echo $out;
80424870174SAndreas Gohr    return (bool) $out;
8056b13307fSandi}
8066b13307fSandi
8076b13307fSandi/**
8081734437eSandi * Hierarchical breadcrumbs
8091734437eSandi *
81031e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8111734437eSandi * It only makes sense with a deep site structure.
8121734437eSandi *
8131734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8146bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
81531e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
816f46c9e83SAnika Henke * @author <fredrik@averpil.com>
81708d7a575SAndreas Gohr * @todo   May behave strangely in RTL languages
81842ea7f44SGerrit Uitslag *
819ac7a515fSAndreas Gohr * @param string $sep Separator between entries
820c4a386f1SIain Hallam * @param bool   $return return or print
821c4a386f1SIain Hallam * @return bool|string
8221734437eSandi */
823d868eb89SAndreas Gohrfunction tpl_youarehere($sep = null, $return = false)
824d868eb89SAndreas Gohr{
8251734437eSandi    global $conf;
8261734437eSandi    global $ID;
8271734437eSandi    global $lang;
8281734437eSandi
82931e187f8SSean Coates    // check if enabled
83054e95700STom N Harris    if (!$conf['youarehere']) return false;
8311734437eSandi
832c4a386f1SIain Hallam    //set default
833c4a386f1SIain Hallam    if (is_null($sep)) $sep = ' » ';
834c4a386f1SIain Hallam
835c4a386f1SIain Hallam    $out = '';
836c4a386f1SIain Hallam
8371734437eSandi    $parts = explode(':', $ID);
838796bafb3SAndreas Gohr    $count = count($parts);
8391734437eSandi
840c4a386f1SIain Hallam    $out .= '<span class="bchead">' . $lang['youarehere'] . ' </span>';
8413940c519SMark
84208d7a575SAndreas Gohr    // always print the startpage
843c4a386f1SIain Hallam    $out .= '<span class="home">' . tpl_pagelink(':' . $conf['start'], null, true) . '</span>';
844796bafb3SAndreas Gohr
845796bafb3SAndreas Gohr    // print intermediate namespace links
846796bafb3SAndreas Gohr    $part = '';
847796bafb3SAndreas Gohr    for ($i = 0; $i < $count - 1; $i++) {
848796bafb3SAndreas Gohr        $part .= $parts[$i] . ':';
849796bafb3SAndreas Gohr        $page = $part;
850796bafb3SAndreas Gohr        if ($page == $conf['start']) continue; // Skip startpage
851796bafb3SAndreas Gohr
85208d7a575SAndreas Gohr        // output
853c4a386f1SIain Hallam        $out .= $sep . tpl_pagelink($page, null, true);
85431e187f8SSean Coates    }
8551734437eSandi
856796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
8578c6be208SAndreas Gohr    if (isset($page)) {
8588c6be208SAndreas Gohr        $page = (new PageResolver('root'))->resolveId($page);
8598c6be208SAndreas Gohr        if ($page == $part . $parts[$i]) {
860a8c33dedSMichael Große            if ($return) return $out;
86126dfc232SAndreas Gohr            echo $out;
862a8c33dedSMichael Große            return true;
863a8c33dedSMichael Große        }
8648c6be208SAndreas Gohr    }
865796bafb3SAndreas Gohr    $page = $part . $parts[$i];
866a8c33dedSMichael Große    if ($page == $conf['start']) {
867a8c33dedSMichael Große        if ($return) return $out;
86826dfc232SAndreas Gohr        echo $out;
869a8c33dedSMichael Große        return true;
870a8c33dedSMichael Große    }
871c4a386f1SIain Hallam    $out .= $sep;
872c4a386f1SIain Hallam    $out .= tpl_pagelink($page, null, true);
873c4a386f1SIain Hallam    if ($return) return $out;
87426dfc232SAndreas Gohr    echo $out;
87524870174SAndreas Gohr    return (bool) $out;
8761734437eSandi}
8771734437eSandi
8781734437eSandi/**
8796b13307fSandi * Print info if the user is logged in
880a2488c3cSMatthias Grimm * and show full name in that case
8816b13307fSandi *
8826b13307fSandi * Could be enhanced with a profile link in future?
8836b13307fSandi *
8846b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
88542ea7f44SGerrit Uitslag *
886ac7a515fSAndreas Gohr * @return bool
8876b13307fSandi */
888d868eb89SAndreas Gohrfunction tpl_userinfo()
889d868eb89SAndreas Gohr{
8906b13307fSandi    global $lang;
891585bf44eSChristopher Smith    /** @var Input $INPUT */
892585bf44eSChristopher Smith    global $INPUT;
893585bf44eSChristopher Smith
894585bf44eSChristopher Smith    if ($INPUT->server->str('REMOTE_USER')) {
89526dfc232SAndreas Gohr        echo $lang['loggedinas'] . ' ' . userlink();
89654e95700STom N Harris        return true;
89754e95700STom N Harris    }
89854e95700STom N Harris    return false;
8996b13307fSandi}
9006b13307fSandi
9016b13307fSandi/**
9026b13307fSandi * Print some info about the current page
9036b13307fSandi *
9046b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
90542ea7f44SGerrit Uitslag *
906ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
907ac7a515fSAndreas Gohr * @return bool|string
9086b13307fSandi */
909d868eb89SAndreas Gohrfunction tpl_pageinfo($ret = false)
910d868eb89SAndreas Gohr{
9116b13307fSandi    global $conf;
9126b13307fSandi    global $lang;
9136b13307fSandi    global $INFO;
914c6e92a3cSDavid Lorentsen    global $ID;
915c6e92a3cSDavid Lorentsen
916c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
917ac7a515fSAndreas Gohr    if (!auth_quickaclcheck($ID)) {
918ac7a515fSAndreas Gohr        return false;
919ac7a515fSAndreas Gohr    }
9206b13307fSandi
9216b13307fSandi    // prepare date and path
9226b13307fSandi    $fn = $INFO['filepath'];
9236b13307fSandi    if (!$conf['fullpath']) {
924613bca54SAndreas Gohr        if ($INFO['rev']) {
925c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'] . '/', '', $fn);
9266b13307fSandi        } else {
927c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'] . '/', '', $fn);
9286b13307fSandi        }
9296b13307fSandi    }
930bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
931f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
9326b13307fSandi
933faecdfdfSAndreas Gohr    // print it
934faecdfdfSAndreas Gohr    if ($INFO['exists']) {
9354b0d3916SAndreas Gohr        $out = '';
936d317fb5dSAnika Henke        $out .= '<bdi>' . $fn . '</bdi>';
937e260f93bSAnika Henke        $out .= ' · ';
9384b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
939fde860beSGerrit Uitslag        $out .= ' ';
9404b0d3916SAndreas Gohr        $out .= $date;
9416b13307fSandi        if ($INFO['editor']) {
9424b0d3916SAndreas Gohr            $out .= ' ' . $lang['by'] . ' ';
943d317fb5dSAnika Henke            $out .= '<bdi>' . editorinfo($INFO['editor']) . '</bdi>';
9445aa52fafSBen Coburn        } else {
9454b0d3916SAndreas Gohr            $out .= ' (' . $lang['external_edit'] . ')';
9466b13307fSandi        }
9476b13307fSandi        if ($INFO['locked']) {
948e260f93bSAnika Henke            $out .= ' · ';
9494b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
950fde860beSGerrit Uitslag            $out .= ' ';
951d317fb5dSAnika Henke            $out .= '<bdi>' . editorinfo($INFO['locked']) . '</bdi>';
9526b13307fSandi        }
9534b0d3916SAndreas Gohr        if ($ret) {
9544b0d3916SAndreas Gohr            return $out;
9554b0d3916SAndreas Gohr        } else {
9564b0d3916SAndreas Gohr            echo $out;
95754e95700STom N Harris            return true;
9586b13307fSandi        }
9594b0d3916SAndreas Gohr    }
96054e95700STom N Harris    return false;
9616b13307fSandi}
9626b13307fSandi
963820fa24bSandi/**
964a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
96587c434ceSAndreas Gohr *
96687c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
967a6598f23SBen Coburn * the given ID is used.
96887c434ceSAndreas Gohr *
96987c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
97042ea7f44SGerrit Uitslag *
971ac7a515fSAndreas Gohr * @param string $id page id
972ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
973ac7a515fSAndreas Gohr * @return bool|string
97487c434ceSAndreas Gohr */
975d868eb89SAndreas Gohrfunction tpl_pagetitle($id = null, $ret = false)
976d868eb89SAndreas Gohr{
977c248bda1SChristopher Smith    global $ACT, $INPUT, $conf, $lang;
978fffeeafeSChristopher Smith
97987c434ceSAndreas Gohr    if (is_null($id)) {
98087c434ceSAndreas Gohr        global $ID;
98187c434ceSAndreas Gohr        $id = $ID;
98287c434ceSAndreas Gohr    }
98387c434ceSAndreas Gohr
98487c434ceSAndreas Gohr    $name = $id;
985fe9ec250SChris Smith    if (useHeading('navigation')) {
986fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
987fffeeafeSChristopher Smith        if ($first_heading) $name = $first_heading;
988fffeeafeSChristopher Smith    }
989fffeeafeSChristopher Smith
990fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
991fffeeafeSChristopher Smith    switch ($ACT) {
992fffeeafeSChristopher Smith        // admin functions
993fffeeafeSChristopher Smith        case 'admin':
994fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
995fffeeafeSChristopher Smith            // try to get the plugin name
996e1d9dcc8SAndreas Gohr            /** @var $plugin AdminPlugin */
997a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()) {
998c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
99924870174SAndreas Gohr                $page_title = $plugin_title ?: $plugin->getPluginName();
1000fffeeafeSChristopher Smith            }
1001fffeeafeSChristopher Smith            break;
1002fffeeafeSChristopher Smith
1003fffeeafeSChristopher Smith        // user functions
1004fffeeafeSChristopher Smith        case 'login':
1005fffeeafeSChristopher Smith        case 'profile':
1006fffeeafeSChristopher Smith        case 'register':
1007fffeeafeSChristopher Smith        case 'resendpwd':
1008fffeeafeSChristopher Smith            $page_title = $lang['btn_' . $ACT];
1009fffeeafeSChristopher Smith            break;
1010fffeeafeSChristopher Smith
1011fffeeafeSChristopher Smith         // wiki functions
1012fffeeafeSChristopher Smith        case 'search':
1013fffeeafeSChristopher Smith        case 'index':
1014fffeeafeSChristopher Smith            $page_title = $lang['btn_' . $ACT];
1015fffeeafeSChristopher Smith            break;
1016fffeeafeSChristopher Smith
1017fffeeafeSChristopher Smith        // page functions
1018fffeeafeSChristopher Smith        case 'edit':
10192f19acc2Sbleistivt        case 'preview':
1020fffeeafeSChristopher Smith            $page_title = "✎ " . $name;
1021fffeeafeSChristopher Smith            break;
1022fffeeafeSChristopher Smith
1023fffeeafeSChristopher Smith        case 'revisions':
1024fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
1025fffeeafeSChristopher Smith            break;
1026fffeeafeSChristopher Smith
1027fffeeafeSChristopher Smith        case 'backlink':
1028fffeeafeSChristopher Smith        case 'recent':
1029fffeeafeSChristopher Smith        case 'subscribe':
1030fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_' . $ACT];
1031fffeeafeSChristopher Smith            break;
1032fffeeafeSChristopher Smith
1033fffeeafeSChristopher Smith        default: // SHOW and anything else not included
1034fffeeafeSChristopher Smith            $page_title = $name;
103587c434ceSAndreas Gohr    }
1036a6598f23SBen Coburn
1037a6598f23SBen Coburn    if ($ret) {
1038fffeeafeSChristopher Smith        return hsc($page_title);
1039a6598f23SBen Coburn    } else {
104026dfc232SAndreas Gohr        echo hsc($page_title);
104154e95700STom N Harris        return true;
104287c434ceSAndreas Gohr    }
1043a6598f23SBen Coburn}
1044340756e4Sandi
104555efc227SAndreas Gohr/**
104655efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
104755efc227SAndreas Gohr *
104855efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
104955efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
105055efc227SAndreas Gohr *
105155efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
105255efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
105355efc227SAndreas Gohr * to the names of the latter one)
105455efc227SAndreas Gohr *
10553df72098SAndreas Gohr * Only allowed in: detail.php
105655efc227SAndreas Gohr *
105755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
105842ea7f44SGerrit Uitslag *
105921d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
1060ac7a515fSAndreas Gohr * @param string       $alt  alternative output if no data was found
1061e0c26282SGerrit Uitslag * @param null|string  $src  the image src, uses global $SRC if not given
1062ac7a515fSAndreas Gohr * @return string
106355efc227SAndreas Gohr */
1064d868eb89SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null)
1065d868eb89SAndreas Gohr{
106655efc227SAndreas Gohr    // Init Exif Reader
1067a46a7ce3Sasivery    global $SRC, $imgMeta;
10683df72098SAndreas Gohr
10693df72098SAndreas Gohr    if (is_null($src)) $src = $SRC;
10701eadd9e8SAndreas Gohr    if (is_null($src)) return $alt;
10713df72098SAndreas Gohr
1072a46a7ce3Sasivery    if (!isset($imgMeta) || $imgMeta === null) $imgMeta = new JpegMeta($src);
1073a46a7ce3Sasivery    if ($imgMeta === false) return $alt;
1074a46a7ce3Sasivery    $info = cleanText($imgMeta->getField($tags));
107555efc227SAndreas Gohr    if ($info == false) return $alt;
107655efc227SAndreas Gohr    return $info;
107755efc227SAndreas Gohr}
107855efc227SAndreas Gohr
1079a46a7ce3Sasivery
1080a46a7ce3Sasivery/**
1081a46a7ce3Sasivery * Garbage collects up the open JpegMeta object.
1082a46a7ce3Sasivery */
1083d868eb89SAndreas Gohrfunction tpl_img_close()
1084d868eb89SAndreas Gohr{
1085a46a7ce3Sasivery    global $imgMeta;
1086a46a7ce3Sasivery    $imgMeta = null;
1087a46a7ce3Sasivery}
1088a46a7ce3Sasivery
108955efc227SAndreas Gohr/**
1090becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
1091becfa414SGerrit Uitslag *
1092becfa414SGerrit Uitslag * @return string html of description list
1093becfa414SGerrit Uitslag */
1094d868eb89SAndreas Gohrfunction tpl_img_meta()
1095d868eb89SAndreas Gohr{
1096becfa414SGerrit Uitslag    global $lang;
1097becfa414SGerrit Uitslag
1098becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1099becfa414SGerrit Uitslag
1100becfa414SGerrit Uitslag    echo '<dl>';
1101becfa414SGerrit Uitslag    foreach ($tags as $tag) {
1102becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1103fde860beSGerrit Uitslag        if (!$label) $label = $tag['langkey'] . ':';
1104becfa414SGerrit Uitslag
1105fde860beSGerrit Uitslag        echo '<dt>' . $label . '</dt><dd>';
1106becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1107becfa414SGerrit Uitslag            echo dformat($tag['value']);
1108becfa414SGerrit Uitslag        } else {
1109becfa414SGerrit Uitslag            echo hsc($tag['value']);
1110becfa414SGerrit Uitslag        }
1111becfa414SGerrit Uitslag        echo '</dd>';
1112becfa414SGerrit Uitslag    }
1113becfa414SGerrit Uitslag    echo '</dl>';
1114becfa414SGerrit Uitslag}
1115becfa414SGerrit Uitslag
1116becfa414SGerrit Uitslag/**
1117becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1118becfa414SGerrit Uitslag *
1119becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1120becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1121becfa414SGerrit Uitslag *   - string type     type of value
1122becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1123becfa414SGerrit Uitslag */
1124d868eb89SAndreas Gohrfunction tpl_get_img_meta()
1125d868eb89SAndreas Gohr{
1126becfa414SGerrit Uitslag
1127becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1128becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
112979e79377SAndreas Gohr        if (file_exists($config_file)) {
1130becfa414SGerrit Uitslag            include($config_file);
1131becfa414SGerrit Uitslag        }
1132becfa414SGerrit Uitslag    }
113324870174SAndreas Gohr    $tags = [];
1134becfa414SGerrit Uitslag    foreach ($fields as $tag) {
113524870174SAndreas Gohr        $t = [];
1136becfa414SGerrit Uitslag        if (!empty($tag[0])) {
113724870174SAndreas Gohr            $t = [$tag[0]];
1138becfa414SGerrit Uitslag        }
1139056bf31fSDamien Regad        if (isset($tag[3]) && is_array($tag[3])) {
1140becfa414SGerrit Uitslag            $t = array_merge($t, $tag[3]);
1141becfa414SGerrit Uitslag        }
1142becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1143becfa414SGerrit Uitslag        if ($value) {
114424870174SAndreas Gohr            $tags[] = ['langkey' => $tag[1], 'type' => $tag[2], 'value' => $value];
1145becfa414SGerrit Uitslag        }
1146becfa414SGerrit Uitslag    }
1147becfa414SGerrit Uitslag    return $tags;
1148becfa414SGerrit Uitslag}
1149becfa414SGerrit Uitslag
1150becfa414SGerrit Uitslag/**
115155efc227SAndreas Gohr * Prints the image with a link to the full sized version
115255efc227SAndreas Gohr *
115355efc227SAndreas Gohr * Only allowed in: detail.php
1154a02d2933SAndreas Gohr *
1155ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1156a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1157a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1158a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1159a02d2933SAndreas Gohr * @param $params array  - additional image attributes
116042ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
116155efc227SAndreas Gohr */
1162d868eb89SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null)
1163d868eb89SAndreas Gohr{
116455efc227SAndreas Gohr    global $IMG;
1165585bf44eSChristopher Smith    /** @var Input $INPUT */
1166ac7a515fSAndreas Gohr    global $INPUT;
11675c2eed9aSlisps    global $REV;
116865d3a5dbSAndreas Gohr    $w = (int) tpl_img_getTag('File.Width');
116965d3a5dbSAndreas Gohr    $h = (int) tpl_img_getTag('File.Height');
117055efc227SAndreas Gohr
117155efc227SAndreas Gohr    //resize to given max values
117223a34783SAndreas Gohr    $ratio = 1;
117323a34783SAndreas Gohr    if ($w >= $h) {
1174f8925855Sjoe.lapp        if ($maxwidth && $w >= $maxwidth) {
117555efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1176f8925855Sjoe.lapp        } elseif ($maxheight && $h > $maxheight) {
117755efc227SAndreas Gohr            $ratio = $maxheight / $h;
117855efc227SAndreas Gohr        }
117924870174SAndreas Gohr    } elseif ($maxheight && $h >= $maxheight) {
118055efc227SAndreas Gohr        $ratio = $maxheight / $h;
1181f8925855Sjoe.lapp    } elseif ($maxwidth && $w > $maxwidth) {
118255efc227SAndreas Gohr        $ratio = $maxwidth / $w;
118355efc227SAndreas Gohr    }
118455efc227SAndreas Gohr    if ($ratio) {
118555efc227SAndreas Gohr        $w = floor($ratio * $w);
118655efc227SAndreas Gohr        $h = floor($ratio * $h);
118755efc227SAndreas Gohr    }
118855efc227SAndreas Gohr
11896de3759aSAndreas Gohr    //prepare URLs
119024870174SAndreas Gohr    $url = ml($IMG, ['cache' => $INPUT->str('cache'), 'rev' => $REV], true, '&');
119124870174SAndreas Gohr    $src = ml($IMG, ['cache' => $INPUT->str('cache'), 'rev' => $REV, 'w' => $w, 'h' => $h], true, '&');
119255efc227SAndreas Gohr
11932684e50aSAndreas Gohr    //prepare attributes
119455efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1195a02d2933SAndreas Gohr    if (is_null($params)) {
119624870174SAndreas Gohr        $p = [];
1197a02d2933SAndreas Gohr    } else {
1198a02d2933SAndreas Gohr        $p = $params;
1199a02d2933SAndreas Gohr    }
12002684e50aSAndreas Gohr    if ($w) $p['width'] = $w;
12012684e50aSAndreas Gohr    if ($h) $p['height'] = $h;
12022684e50aSAndreas Gohr    $p['class'] = 'img_detail';
12032684e50aSAndreas Gohr    if ($alt) {
12042684e50aSAndreas Gohr        $p['alt']   = $alt;
12052684e50aSAndreas Gohr        $p['title'] = $alt;
12062684e50aSAndreas Gohr    } else {
12072684e50aSAndreas Gohr        $p['alt'] = '';
12082684e50aSAndreas Gohr    }
1209a02d2933SAndreas Gohr    $p['src'] = $src;
121055efc227SAndreas Gohr
121124870174SAndreas Gohr    $data = ['url' => ($link ? $url : null), 'params' => $p];
1212cbb44eabSAndreas Gohr    return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1213a02d2933SAndreas Gohr}
1214a02d2933SAndreas Gohr
1215a02d2933SAndreas Gohr/**
1216a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1217ac7a515fSAndreas Gohr *
1218ac7a515fSAndreas Gohr * @param array $data
1219ac7a515fSAndreas Gohr * @return bool
1220a02d2933SAndreas Gohr */
1221d868eb89SAndreas Gohrfunction _tpl_img_action($data)
1222d868eb89SAndreas Gohr{
122359f3611bSAnika Henke    global $lang;
1224a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1225a02d2933SAndreas Gohr
122626dfc232SAndreas Gohr    if ($data['url']) echo '<a href="' . hsc($data['url']) . '" title="' . $lang['mediaview'] . '">';
122726dfc232SAndreas Gohr    echo '<img ' . $p . '/>';
122826dfc232SAndreas Gohr    if ($data['url']) echo '</a>';
122954e95700STom N Harris    return true;
123055efc227SAndreas Gohr}
123155efc227SAndreas Gohr
12327367b368SAndreas Gohr/**
1233881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
12347367b368SAndreas Gohr *
12357367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
12367367b368SAndreas Gohr * template
1237ac7a515fSAndreas Gohr *
1238ac7a515fSAndreas Gohr * @return bool
12397367b368SAndreas Gohr */
1240d868eb89SAndreas Gohrfunction tpl_indexerWebBug()
1241d868eb89SAndreas Gohr{
12427367b368SAndreas Gohr    global $ID;
12431dad36f5SAndreas Gohr
124424870174SAndreas Gohr    $p           = [];
12454af80fe8SMichael Große    $p['src']    = DOKU_BASE . 'lib/exe/taskrunner.php?id=' . rawurlencode($ID) .
1246e68c51baSAndreas Gohr        '&' . time();
1247881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
12487367b368SAndreas Gohr    $p['height'] = 1;
12497367b368SAndreas Gohr    $p['alt']    = '';
12507367b368SAndreas Gohr    $att         = buildAttributes($p);
125126dfc232SAndreas Gohr    echo "<img $att />";
125254e95700STom N Harris    return true;
12537367b368SAndreas Gohr}
12547367b368SAndreas Gohr
125578d4e784SEsther Brunner/**
125678d4e784SEsther Brunner * tpl_getConf($id)
125778d4e784SEsther Brunner *
125878d4e784SEsther Brunner * use this function to access template configuration variables
1259ac7a515fSAndreas Gohr *
126017448fb8SChristopher Smith * @param string $id      name of the value to access
126117448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
126217448fb8SChristopher Smith * @return mixed
126378d4e784SEsther Brunner */
1264d868eb89SAndreas Gohrfunction tpl_getConf($id, $notset = false)
1265d868eb89SAndreas Gohr{
126678d4e784SEsther Brunner    global $conf;
126717566ac6SAdrian Lang    static $tpl_configloaded = false;
126878d4e784SEsther Brunner
126978d4e784SEsther Brunner    $tpl = $conf['template'];
127078d4e784SEsther Brunner
127178d4e784SEsther Brunner    if (!$tpl_configloaded) {
127278d4e784SEsther Brunner        $tconf = tpl_loadConfig();
127378d4e784SEsther Brunner        if ($tconf !== false) {
127478d4e784SEsther Brunner            foreach ($tconf as $key => $value) {
127578d4e784SEsther Brunner                if (isset($conf['tpl'][$tpl][$key])) continue;
127678d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
127778d4e784SEsther Brunner            }
127878d4e784SEsther Brunner            $tpl_configloaded = true;
127978d4e784SEsther Brunner        }
128078d4e784SEsther Brunner    }
128178d4e784SEsther Brunner
128224870174SAndreas Gohr    return $conf['tpl'][$tpl][$id] ?? $notset;
128317448fb8SChristopher Smith}
128417448fb8SChristopher Smith
128578d4e784SEsther Brunner/**
128678d4e784SEsther Brunner * tpl_loadConfig()
1287ac7a515fSAndreas Gohr *
128878d4e784SEsther Brunner * reads all template configuration variables
128978d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1290ac7a515fSAndreas Gohr *
1291ac7a515fSAndreas Gohr * @return array
129278d4e784SEsther Brunner */
1293d868eb89SAndreas Gohrfunction tpl_loadConfig()
1294d868eb89SAndreas Gohr{
129578d4e784SEsther Brunner
1296c4766956SAndreas Gohr    $file = tpl_incdir() . '/conf/default.php';
129724870174SAndreas Gohr    $conf = [];
129878d4e784SEsther Brunner
129979e79377SAndreas Gohr    if (!file_exists($file)) return false;
130078d4e784SEsther Brunner
130178d4e784SEsther Brunner    // load default config file
130278d4e784SEsther Brunner    include($file);
130378d4e784SEsther Brunner
130478d4e784SEsther Brunner    return $conf;
130578d4e784SEsther Brunner}
130678d4e784SEsther Brunner
130717566ac6SAdrian Lang// language methods
130817566ac6SAdrian Lang/**
130917566ac6SAdrian Lang * tpl_getLang($id)
131017566ac6SAdrian Lang *
131117566ac6SAdrian Lang * use this function to access template language variables
131242ea7f44SGerrit Uitslag *
131342ea7f44SGerrit Uitslag * @param string $id key of language string
131442ea7f44SGerrit Uitslag * @return string
131517566ac6SAdrian Lang */
1316d868eb89SAndreas Gohrfunction tpl_getLang($id)
1317d868eb89SAndreas Gohr{
131824870174SAndreas Gohr    static $lang = [];
131917566ac6SAdrian Lang
132017566ac6SAdrian Lang    if (count($lang) === 0) {
1321dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1322dd7a6159SGerrit Uitslag
1323c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
132417566ac6SAdrian Lang
132524870174SAndreas Gohr        $lang = [];
132617566ac6SAdrian Lang
132717566ac6SAdrian Lang        // don't include once
132817566ac6SAdrian Lang        @include($path . 'en/lang.php');
1329dd7a6159SGerrit Uitslag        foreach ($config_cascade['lang']['template'] as $config_file) {
133079e79377SAndreas Gohr            if (file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1331dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1332dd7a6159SGerrit Uitslag            }
133317566ac6SAdrian Lang        }
133417566ac6SAdrian Lang
1335dd7a6159SGerrit Uitslag        if ($conf['lang'] != 'en') {
1336dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1337dd7a6159SGerrit Uitslag            foreach ($config_cascade['lang']['template'] as $config_file) {
133879e79377SAndreas Gohr                if (file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1339dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1340dd7a6159SGerrit Uitslag                }
1341dd7a6159SGerrit Uitslag            }
1342dd7a6159SGerrit Uitslag        }
134317566ac6SAdrian Lang    }
134424870174SAndreas Gohr    return $lang[$id] ?? '';
134517566ac6SAdrian Lang}
134617566ac6SAdrian Lang
13473df72098SAndreas Gohr/**
1348c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1349e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1350e8ec13b9SKlap-in *
1351e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1352e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1353e8ec13b9SKlap-in */
1354d868eb89SAndreas Gohrfunction tpl_locale_xhtml($id)
1355d868eb89SAndreas Gohr{
1356c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1357e8ec13b9SKlap-in}
1358e8ec13b9SKlap-in
1359e8ec13b9SKlap-in/**
1360c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
136142ea7f44SGerrit Uitslag *
136242ea7f44SGerrit Uitslag * @param string $id id of localized text
136342ea7f44SGerrit Uitslag * @return string wiki text
1364e8ec13b9SKlap-in */
1365d868eb89SAndreas Gohrfunction tpl_localeFN($id)
1366d868eb89SAndreas Gohr{
1367e8ec13b9SKlap-in    $path = tpl_incdir() . 'lang/';
1368e8ec13b9SKlap-in    global $conf;
136938fb1fc7SGerrit Uitslag    $file = DOKU_CONF . 'template_lang/' . $conf['template'] . '/' . $conf['lang'] . '/' . $id . '.txt';
137079e79377SAndreas Gohr    if (!file_exists($file)) {
1371e8ec13b9SKlap-in        $file = $path . $conf['lang'] . '/' . $id . '.txt';
137279e79377SAndreas Gohr        if (!file_exists($file)) {
1373e8ec13b9SKlap-in            //fall back to english
1374e8ec13b9SKlap-in            $file = $path . 'en/' . $id . '.txt';
1375e8ec13b9SKlap-in        }
1376e8ec13b9SKlap-in    }
1377e8ec13b9SKlap-in    return $file;
1378e8ec13b9SKlap-in}
1379e8ec13b9SKlap-in
1380e8ec13b9SKlap-in/**
13817abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
13823df72098SAndreas Gohr *
13833df72098SAndreas Gohr * Depending on the user's actions this may be a list of
13843df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
13853df72098SAndreas Gohr * a message of referencing pages
13863df72098SAndreas Gohr *
13873df72098SAndreas Gohr * Only allowed in mediamanager.php
13883df72098SAndreas Gohr *
1389c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1390c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
139142ea7f44SGerrit Uitslag * @param string $sort
13928702de7fSGerrit Uitslag *
13933df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13943df72098SAndreas Gohr */
1395d868eb89SAndreas Gohrfunction tpl_mediaContent($fromajax = false, $sort = 'natural')
1396d868eb89SAndreas Gohr{
13973df72098SAndreas Gohr    global $IMG;
13983df72098SAndreas Gohr    global $AUTH;
13993df72098SAndreas Gohr    global $INUSE;
14003df72098SAndreas Gohr    global $NS;
14013df72098SAndreas Gohr    global $JUMPTO;
1402585bf44eSChristopher Smith    /** @var Input $INPUT */
1403ac7a515fSAndreas Gohr    global $INPUT;
14043df72098SAndreas Gohr
1405ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
140624870174SAndreas Gohr    if (in_array($do, ['save', 'cancel'])) $do = '';
1407c182313eSAndreas Gohr
1408c182313eSAndreas Gohr    if (!$do) {
1409ac7a515fSAndreas Gohr        if ($INPUT->bool('edit')) {
1410c182313eSAndreas Gohr            $do = 'metaform';
1411c182313eSAndreas Gohr        } elseif (is_array($INUSE)) {
1412c182313eSAndreas Gohr            $do = 'filesinuse';
1413c182313eSAndreas Gohr        } else {
1414c182313eSAndreas Gohr            $do = 'filelist';
1415c182313eSAndreas Gohr        }
1416c182313eSAndreas Gohr    }
1417c182313eSAndreas Gohr
1418c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1419a664aabaSAndreas Gohr    if (!$fromajax) echo '<div id="media__content">';
142024870174SAndreas Gohr    $data = ['do' => $do];
1421e1d9dcc8SAndreas Gohr    $evt  = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1422c182313eSAndreas Gohr    if ($evt->advise_before()) {
1423c182313eSAndreas Gohr        $do = $data['do'];
142430fd72fbSKate Arzamastseva        if ($do == 'filesinuse') {
1425c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1426c182313eSAndreas Gohr        } elseif ($do == 'filelist') {
142700e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO, false, $sort);
1428c9f56829SAndreas Gohr        } elseif ($do == 'searchlist') {
1429ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1430c182313eSAndreas Gohr        } else {
1431c182313eSAndreas Gohr            msg('Unknown action ' . hsc($do), -1);
1432c182313eSAndreas Gohr        }
1433c182313eSAndreas Gohr    }
1434c182313eSAndreas Gohr    $evt->advise_after();
1435c182313eSAndreas Gohr    unset($evt);
1436a664aabaSAndreas Gohr    if (!$fromajax) echo '</div>';
14373df72098SAndreas Gohr}
14383df72098SAndreas Gohr
14393df72098SAndreas Gohr/**
1440d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1441d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1442d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1443d9162c6cSKate Arzamastseva *
1444d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1445d9162c6cSKate Arzamastseva */
1446d868eb89SAndreas Gohrfunction tpl_mediaFileList()
1447d868eb89SAndreas Gohr{
1448d9162c6cSKate Arzamastseva    global $AUTH;
1449d9162c6cSKate Arzamastseva    global $NS;
1450d9162c6cSKate Arzamastseva    global $JUMPTO;
145195b451bcSAdrian Lang    global $lang;
1452585bf44eSChristopher Smith    /** @var Input $INPUT */
1453ac7a515fSAndreas Gohr    global $INPUT;
1454d9162c6cSKate Arzamastseva
1455ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
145624870174SAndreas Gohr    if (!$opened_tab || !in_array($opened_tab, ['files', 'upload', 'search'])) $opened_tab = 'files';
1457ac7a515fSAndreas Gohr    if ($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1458d9162c6cSKate Arzamastseva
145994add303SAnika Henke    echo '<h2 class="a11y">' . $lang['mediaselect'] . '</h2>' . NL;
146095b451bcSAdrian Lang
1461ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
146223846a98SKate Arzamastseva
146394add303SAnika Henke    echo '<div class="panelHeader">' . NL;
146495b451bcSAdrian Lang    echo '<h3>';
146524870174SAndreas Gohr    $tabTitle = $NS ?: '[' . $lang['mediaroot'] . ']';
1466c98f205eSAdrian Lang    printf($lang['media_' . $opened_tab], '<strong>' . hsc($tabTitle) . '</strong>');
146794add303SAnika Henke    echo '</h3>' . NL;
146895b451bcSAdrian Lang    if ($opened_tab === 'search' || $opened_tab === 'files') {
146995b451bcSAdrian Lang        media_tab_files_options();
147023846a98SKate Arzamastseva    }
147194add303SAnika Henke    echo '</div>' . NL;
1472d9162c6cSKate Arzamastseva
147394add303SAnika Henke    echo '<div class="panelContent">' . NL;
147495b451bcSAdrian Lang    if ($opened_tab == 'files') {
147595b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
147695b451bcSAdrian Lang    } elseif ($opened_tab == 'upload') {
147795b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
147895b451bcSAdrian Lang    } elseif ($opened_tab == 'search') {
147995b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
148095b451bcSAdrian Lang    }
148194add303SAnika Henke    echo '</div>' . NL;
1482d9162c6cSKate Arzamastseva}
1483d9162c6cSKate Arzamastseva
1484d9162c6cSKate Arzamastseva/**
1485d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1486d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1487d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1488d9162c6cSKate Arzamastseva * list of file revisions
1489d9162c6cSKate Arzamastseva *
1490d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1491f50a239bSTakamura *
1492f50a239bSTakamura * @param string $image
1493f50a239bSTakamura * @param boolean $rev
1494d9162c6cSKate Arzamastseva */
1495d868eb89SAndreas Gohrfunction tpl_mediaFileDetails($image, $rev)
1496d868eb89SAndreas Gohr{
1497e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1498585bf44eSChristopher Smith    /** @var Input $INPUT */
1499585bf44eSChristopher Smith    global $INPUT;
1500d9162c6cSKate Arzamastseva
150164159a61SAndreas Gohr    $removed = (
150264159a61SAndreas Gohr        !file_exists(mediaFN($image)) &&
150364159a61SAndreas Gohr        file_exists(mediaMetaFN($image, '.changes')) &&
150464159a61SAndreas Gohr        $conf['mediarevisions']
150564159a61SAndreas Gohr    );
1506ac7a515fSAndreas Gohr    if (!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
15076dd095f5SKate Arzamastseva    if ($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1508e8a2a143SMichael Hamann    $ns = getNS($image);
1509ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
15101eeeced2SKate Arzamastseva
1511ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1512e5d185e1SKate Arzamastseva
151324870174SAndreas Gohr    $tab_array = ['view'];
151424870174SAndreas Gohr    [, $mime] = mimetype($image);
1515e5d185e1SKate Arzamastseva    if ($mime == 'image/jpeg') {
1516e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1517e5d185e1SKate Arzamastseva    }
1518e5d185e1SKate Arzamastseva    if ($conf['mediarevisions']) {
1519e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1520e5d185e1SKate Arzamastseva    }
1521e5d185e1SKate Arzamastseva
1522e5d185e1SKate Arzamastseva    if (!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1523ac7a515fSAndreas Gohr    if ($INPUT->bool('edit')) $opened_tab = 'edit';
152423846a98SKate Arzamastseva    if ($do == 'restore') $opened_tab = 'view';
1525d9162c6cSKate Arzamastseva
1526ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
152723846a98SKate Arzamastseva
152859f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
152924870174SAndreas Gohr    [$ext] = mimetype($image, false);
153095b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
153195b451bcSAdrian Lang    $class    = 'select mediafile mf_' . $class;
153224870174SAndreas Gohr
1533750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
153490fb952cSAndreas Gohr    $tabTitle = sprintf(
153590fb952cSAndreas Gohr        '<strong><a href="%s" class="%s" title="%s">%s</a></strong>',
153690fb952cSAndreas Gohr        ml($image, $attributes),
153790fb952cSAndreas Gohr        $class,
153890fb952cSAndreas Gohr        $lang['mediaview'],
153990fb952cSAndreas Gohr        $image
154090fb952cSAndreas Gohr    );
154108317413SAdrian Lang    if ($opened_tab === 'view' && $rev) {
154208317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
154308317413SAdrian Lang    } else {
1544026d14a9SAnika Henke        printf($lang['media_' . $opened_tab], $tabTitle);
154508317413SAdrian Lang    }
1546b8a84c03SAndreas Gohr
154794add303SAnika Henke    echo '</h3></div>' . NL;
154895b451bcSAdrian Lang
154994add303SAnika Henke    echo '<div class="panelContent">' . NL;
155095b451bcSAdrian Lang
155123846a98SKate Arzamastseva    if ($opened_tab == 'view') {
1552e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
155392cac9a9SKate Arzamastseva    } elseif ($opened_tab == 'edit' && !$removed) {
1554e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
1555e5d185e1SKate Arzamastseva    } elseif ($opened_tab == 'history' && $conf['mediarevisions']) {
1556e8a2a143SMichael Hamann        media_tab_history($image, $ns);
155723846a98SKate Arzamastseva    }
155895b451bcSAdrian Lang
155994add303SAnika Henke    echo '</div>' . NL;
1560d9162c6cSKate Arzamastseva}
1561d9162c6cSKate Arzamastseva
1562d9162c6cSKate Arzamastseva/**
15637abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
15643df72098SAndreas Gohr *
15653df72098SAndreas Gohr * Only allowed in mediamanager.php
15663df72098SAndreas Gohr *
15673df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
15683df72098SAndreas Gohr */
1569d868eb89SAndreas Gohrfunction tpl_mediaTree()
1570d868eb89SAndreas Gohr{
15713df72098SAndreas Gohr    global $NS;
1572a664aabaSAndreas Gohr    echo '<div id="media__tree">';
15733df72098SAndreas Gohr    media_nstree($NS);
1574a664aabaSAndreas Gohr    echo '</div>';
15753df72098SAndreas Gohr}
15763df72098SAndreas Gohr
1577a00de5b5SAndreas Gohr/**
1578a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1579a00de5b5SAndreas Gohr *
1580a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1581a00de5b5SAndreas Gohr *
1582a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
158342ea7f44SGerrit Uitslag *
158442ea7f44SGerrit Uitslag * @param string $empty empty option label
158542ea7f44SGerrit Uitslag * @param string $button submit button label
1586affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1587a00de5b5SAndreas Gohr */
1588d868eb89SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;')
1589d868eb89SAndreas Gohr{
1590affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
159124870174SAndreas Gohr    $menu = new MobileMenu();
15921e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1593a00de5b5SAndreas Gohr}
1594a00de5b5SAndreas Gohr
1595066fee30SAndreas Gohr/**
1596066fee30SAndreas Gohr * Print a informational line about the used license
1597066fee30SAndreas Gohr *
1598066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1599ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1600ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1601ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1602ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1603ac7a515fSAndreas Gohr * @return string
1604066fee30SAndreas Gohr */
1605d868eb89SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true)
1606d868eb89SAndreas Gohr{
1607066fee30SAndreas Gohr    global $license;
1608066fee30SAndreas Gohr    global $conf;
1609066fee30SAndreas Gohr    global $lang;
1610066fee30SAndreas Gohr    if (!$conf['license']) return '';
1611066fee30SAndreas Gohr    if (!is_array($license[$conf['license']])) return '';
1612066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
161353e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="' . $conf['target']['extern'] . '"' : '';
1614066fee30SAndreas Gohr
161580083a41SAndreas Gohr    $out = '';
161680083a41SAndreas Gohr    if ($wrap) $out .= '<div class="license">';
1617066fee30SAndreas Gohr    if ($img) {
1618066fee30SAndreas Gohr        $src = license_img($img);
1619066fee30SAndreas Gohr        if ($src) {
162053e15c8bSAnika Henke            $out .= '<a href="' . $lic['url'] . '" rel="license"' . $target;
162153e15c8bSAnika Henke            $out .= '><img src="' . DOKU_BASE . $src . '" alt="' . $lic['name'] . '" /></a>';
162253e15c8bSAnika Henke            if (!$imgonly) $out .= ' ';
1623066fee30SAndreas Gohr        }
1624066fee30SAndreas Gohr    }
16254cefd216SMichael Klier    if (!$imgonly) {
162653e15c8bSAnika Henke        $out .= $lang['license'] . ' ';
1627d317fb5dSAnika Henke        $out .= '<bdi><a href="' . $lic['url'] . '" rel="license" class="urlextern"' . $target;
1628d317fb5dSAnika Henke        $out .= '>' . $lic['name'] . '</a></bdi>';
16294cefd216SMichael Klier    }
163080083a41SAndreas Gohr    if ($wrap) $out .= '</div>';
1631066fee30SAndreas Gohr
1632066fee30SAndreas Gohr    if ($return) return $out;
1633066fee30SAndreas Gohr    echo $out;
1634ac7a515fSAndreas Gohr    return '';
1635066fee30SAndreas Gohr}
1636066fee30SAndreas Gohr
1637a81910eeSAndreas Gohr/**
1638835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1639a81910eeSAndreas Gohr *
1640a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1641a81910eeSAndreas Gohr * template
1642e0c26282SGerrit Uitslag *
16437a112df5SAndreas Gohr * @param string $pageid The page name you want to include
16447a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
16457a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
16467c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1647e0c26282SGerrit Uitslag * @return bool|null|string
1648a81910eeSAndreas Gohr */
1649d868eb89SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true)
1650d868eb89SAndreas Gohr{
16517a112df5SAndreas Gohr    if ($propagate) {
16527c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
16537c3e4a67SAndreas Gohr    } elseif ($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
16547a112df5SAndreas Gohr        return false;
16557a112df5SAndreas Gohr    }
1656c786a1b6SAnika Henke    if (!$pageid) return false;
1657835dfcaeSAnika Henke
1658c786a1b6SAnika Henke    global $TOC;
16599a2e250aSAndreas Gohr    $oldtoc = $TOC;
1660a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
16619a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1662a81910eeSAndreas Gohr
1663a2e03c82SAndreas Gohr    if ($print) echo $html;
1664e66d3e6dSAndreas Gohr    return $html;
1665e66d3e6dSAndreas Gohr}
1666e66d3e6dSAndreas Gohr
1667e66d3e6dSAndreas Gohr/**
16685b75cd1fSAdrian Lang * Display the subscribe form
16695b75cd1fSAdrian Lang *
16705b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
1671848cb786SSatoshi Sahara * @deprecated 2020-07-23
16725b75cd1fSAdrian Lang */
1673d868eb89SAndreas Gohrfunction tpl_subscribe()
1674d868eb89SAndreas Gohr{
167524870174SAndreas Gohr    dbg_deprecated(Subscribe::class . '::show()');
167673022918SAndreas Gohr    (new Subscribe())->show();
16775b75cd1fSAdrian Lang}
16785b75cd1fSAdrian Lang
1679d059ba9bSAndreas Gohr/**
1680d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1681d059ba9bSAndreas Gohr *
1682d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1683d059ba9bSAndreas Gohr *
1684d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1685d059ba9bSAndreas Gohr */
1686d868eb89SAndreas Gohrfunction tpl_flush()
1687d868eb89SAndreas Gohr{
1688c2009796SZemoj    if (ob_get_level() > 0) ob_flush();
1689d059ba9bSAndreas Gohr    flush();
1690d059ba9bSAndreas Gohr}
1691d059ba9bSAndreas Gohr
1692afca7e7eSAnika Henke/**
1693378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1694afca7e7eSAnika Henke *
1695378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1696378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1697378325f9SAndreas Gohr *
169842ea7f44SGerrit Uitslag * @param  string[] $search       locations to look at
1699378325f9SAndreas Gohr * @param  bool     $abs          if to use absolute URL
1700ac7a515fSAndreas Gohr * @param  array    &$imginfo     filled with getimagesize()
17016dc405e1SAndreas Gohr * @param  bool     $fallback     use fallback image if target isn't found or return 'false' if potential
17026dc405e1SAndreas Gohr *                                false result is required
1703ac7a515fSAndreas Gohr * @return string
170442ea7f44SGerrit Uitslag *
1705378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1706afca7e7eSAnika Henke */
1707d868eb89SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true)
1708d868eb89SAndreas Gohr{
1709ac7a515fSAndreas Gohr    $img     = '';
1710ac7a515fSAndreas Gohr    $file    = '';
1711ac7a515fSAndreas Gohr    $ismedia = false;
1712378325f9SAndreas Gohr    // loop through candidates until a match was found:
1713378325f9SAndreas Gohr    foreach ($search as $img) {
1714378325f9SAndreas Gohr        if (substr($img, 0, 1) == ':') {
1715378325f9SAndreas Gohr            $file    = mediaFN($img);
1716378325f9SAndreas Gohr            $ismedia = true;
1717378325f9SAndreas Gohr        } else {
1718c4766956SAndreas Gohr            $file    = tpl_incdir() . $img;
1719378325f9SAndreas Gohr            $ismedia = false;
17201f13e33dSAnika Henke        }
17210f747863Slupo49
1722378325f9SAndreas Gohr        if (file_exists($file)) break;
1723872a6d29SAnika Henke    }
1724378325f9SAndreas Gohr
172508a13262SSimon DELAGE    // manage non existing target
172608a13262SSimon DELAGE    if (!file_exists($file)) {
172708a13262SSimon DELAGE        // give result for fallback image
172824870174SAndreas Gohr        if ($fallback) {
1729c238d757SSimon DELAGE            $file = DOKU_INC . 'lib/images/blank.gif';
173008a13262SSimon DELAGE            // stop process if false result is required (if $fallback is false)
173108a13262SSimon DELAGE        } else {
173208a13262SSimon DELAGE            return false;
173308a13262SSimon DELAGE        }
173408a13262SSimon DELAGE    }
1735ca5b6a64SSimon DELAGE
1736378325f9SAndreas Gohr    // fetch image data if requested
1737378325f9SAndreas Gohr    if (!is_null($imginfo)) {
1738378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1739378325f9SAndreas Gohr    }
1740378325f9SAndreas Gohr
1741378325f9SAndreas Gohr    // build URL
1742378325f9SAndreas Gohr    if ($ismedia) {
1743378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1744378325f9SAndreas Gohr    } else {
1745c4766956SAndreas Gohr        $url = tpl_basedir() . $img;
1746378325f9SAndreas Gohr        if ($abs) $url = DOKU_URL . substr($url, strlen(DOKU_REL));
1747378325f9SAndreas Gohr    }
1748378325f9SAndreas Gohr
1749378325f9SAndreas Gohr    return $url;
1750a7e5f74cSlupo49}
17511f13e33dSAnika Henke
1752872a6d29SAnika Henke/**
1753e5d4768dSAndreas Gohr * PHP include a file
1754e5d4768dSAndreas Gohr *
1755e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1756e5d4768dSAndreas Gohr * file in the template's root directory.
1757e5d4768dSAndreas Gohr *
1758e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1759e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1760e5d4768dSAndreas Gohr * default.
1761e5d4768dSAndreas Gohr *
1762e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1763e5d4768dSAndreas Gohr * to this function!
1764e5d4768dSAndreas Gohr *
1765e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1766e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
176742ea7f44SGerrit Uitslag *
176842ea7f44SGerrit Uitslag * @param string $file
1769e5d4768dSAndreas Gohr */
1770d868eb89SAndreas Gohrfunction tpl_includeFile($file)
1771d868eb89SAndreas Gohr{
1772e5d4768dSAndreas Gohr    global $config_cascade;
177324870174SAndreas Gohr    foreach (['protected', 'local', 'default'] as $config_group) {
1774e5d4768dSAndreas Gohr        if (empty($config_cascade['main'][$config_group])) continue;
1775e5d4768dSAndreas Gohr        foreach ($config_cascade['main'][$config_group] as $conf_file) {
1776e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1777e5d4768dSAndreas Gohr            if (file_exists("$dir/$file")) {
1778f3a1225fSAnika Henke                include("$dir/$file");
1779e5d4768dSAndreas Gohr                return;
1780e5d4768dSAndreas Gohr            }
1781e5d4768dSAndreas Gohr        }
1782e5d4768dSAndreas Gohr    }
1783e5d4768dSAndreas Gohr
1784e5d4768dSAndreas Gohr    // still here? try the template dir
1785e5d4768dSAndreas Gohr    $file = tpl_incdir() . $file;
1786e5d4768dSAndreas Gohr    if (file_exists($file)) {
1787f3a1225fSAnika Henke        include($file);
1788e5d4768dSAndreas Gohr    }
1789e5d4768dSAndreas Gohr}
1790e5d4768dSAndreas Gohr
1791e5d4768dSAndreas Gohr/**
1792872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1793872a6d29SAnika Henke *
1794872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
179542ea7f44SGerrit Uitslag *
1796ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1797ac7a515fSAndreas Gohr * @return string
1798872a6d29SAnika Henke */
1799d868eb89SAndreas Gohrfunction tpl_favicon($types = ['favicon'])
1800d868eb89SAndreas Gohr{
1801872a6d29SAnika Henke
1802872a6d29SAnika Henke    $return = '';
1803872a6d29SAnika Henke
1804872a6d29SAnika Henke    foreach ($types as $type) {
1805872a6d29SAnika Henke        switch ($type) {
1806872a6d29SAnika Henke            case 'favicon':
180724870174SAndreas Gohr                $look = [':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'];
1808378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="' . tpl_getMediaFile($look) . '" />' . NL;
1809872a6d29SAnika Henke                break;
1810872a6d29SAnika Henke            case 'mobile':
181124870174SAndreas Gohr                $look = [':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'];
1812378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="' . tpl_getMediaFile($look) . '" />' . NL;
1813872a6d29SAnika Henke                break;
1814872a6d29SAnika Henke            case 'generic':
1815872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
181624870174SAndreas Gohr                $look = [':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'];
1817378325f9SAndreas Gohr                $return .= '<link rel="icon" href="' . tpl_getMediaFile($look) . '" type="image/svg+xml" />' . NL;
1818872a6d29SAnika Henke                break;
1819872a6d29SAnika Henke        }
1820872a6d29SAnika Henke    }
1821872a6d29SAnika Henke
1822872a6d29SAnika Henke    return $return;
1823afca7e7eSAnika Henke}
1824afca7e7eSAnika Henke
1825d9162c6cSKate Arzamastseva/**
1826d9162c6cSKate Arzamastseva * Prints full-screen media manager
1827d9162c6cSKate Arzamastseva *
1828d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1829d9162c6cSKate Arzamastseva */
1830d868eb89SAndreas Gohrfunction tpl_media()
1831d868eb89SAndreas Gohr{
1832ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
183388a71175SKate Arzamastseva    $fullscreen = true;
183495b451bcSAdrian Lang    require_once DOKU_INC . 'lib/exe/mediamanager.php';
1835d9162c6cSKate Arzamastseva
1836ac7a515fSAndreas Gohr    $rev   = '';
1837ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
183898f03b57SKate Arzamastseva    if (isset($IMG)) $image = $IMG;
183998f03b57SKate Arzamastseva    if (isset($JUMPTO)) $image = $JUMPTO;
18409c1bd4bcSKate Arzamastseva    if (isset($REV) && !$JUMPTO) $rev = $REV;
184198f03b57SKate Arzamastseva
184294add303SAnika Henke    echo '<div id="mediamanager__page">' . NL;
1843bc314c58SAnika Henke    echo '<h1>' . $lang['btn_media'] . '</h1>' . NL;
1844d9162c6cSKate Arzamastseva    html_msgarea();
184594add303SAnika Henke
184694add303SAnika Henke    echo '<div class="panel namespaces">' . NL;
184794add303SAnika Henke    echo '<h2>' . $lang['namespaces'] . '</h2>' . NL;
184895b451bcSAdrian Lang    echo '<div class="panelHeader">';
1849ba340a70SAnika Henke    echo $lang['media_namespaces'];
185094add303SAnika Henke    echo '</div>' . NL;
185195b451bcSAdrian Lang
185294add303SAnika Henke    echo '<div class="panelContent" id="media__tree">' . NL;
185395b451bcSAdrian Lang    media_nstree($NS);
185494add303SAnika Henke    echo '</div>' . NL;
185594add303SAnika Henke    echo '</div>' . NL;
1856fa8e5c77SKate Arzamastseva
185794add303SAnika Henke    echo '<div class="panel filelist">' . NL;
1858035e07f1SKate Arzamastseva    tpl_mediaFileList();
185994add303SAnika Henke    echo '</div>' . NL;
1860fa8e5c77SKate Arzamastseva
186194add303SAnika Henke    echo '<div class="panel file">' . NL;
186294add303SAnika Henke    echo '<h2 class="a11y">' . $lang['media_file'] . '</h2>' . NL;
1863035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
186494add303SAnika Henke    echo '</div>' . NL;
1865ba340a70SAnika Henke
186694add303SAnika Henke    echo '</div>' . NL;
1867d9162c6cSKate Arzamastseva}
1868afca7e7eSAnika Henke
1869c71db656SAnika Henke/**
1870c71db656SAnika Henke * Return useful layout classes
1871c71db656SAnika Henke *
1872c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
187342ea7f44SGerrit Uitslag *
187442ea7f44SGerrit Uitslag * @return string
1875c71db656SAnika Henke */
1876d868eb89SAndreas Gohrfunction tpl_classes()
1877d868eb89SAndreas Gohr{
1878c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1879585bf44eSChristopher Smith    /** @var Input $INPUT */
1880585bf44eSChristopher Smith    global $INPUT;
1881585bf44eSChristopher Smith
188224870174SAndreas Gohr    $classes = [
1883c71db656SAnika Henke        'dokuwiki',
1884c71db656SAnika Henke        'mode_' . $ACT,
1885c71db656SAnika Henke        'tpl_' . $conf['template'],
1886585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
188790eb1b7bSEduardo Mozart de Oliveira        (isset($INFO['exists']) && $INFO['exists']) ? '' : 'notFound',
188824870174SAndreas Gohr        ($ID == $conf['start']) ? 'home' : ''
188924870174SAndreas Gohr    ];
189024870174SAndreas Gohr    return implode(' ', $classes);
1891c71db656SAnika Henke}
1892c71db656SAnika Henke
189384dd2b1aSGerrit Uitslag/**
189484dd2b1aSGerrit Uitslag * Create event for tools menues
189584dd2b1aSGerrit Uitslag *
189684dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
189784dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
189884dd2b1aSGerrit Uitslag * @param array $items
189984dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1900affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
190184dd2b1aSGerrit Uitslag */
1902d868eb89SAndreas Gohrfunction tpl_toolsevent($toolsname, $items, $view = 'main')
1903d868eb89SAndreas Gohr{
1904affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
190524870174SAndreas Gohr    $data = ['view' => $view, 'items' => $items];
190684dd2b1aSGerrit Uitslag
190784dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
1908e1d9dcc8SAndreas Gohr    $evt = new Event($hook, $data);
190984dd2b1aSGerrit Uitslag    if ($evt->advise_before()) {
191024870174SAndreas Gohr        foreach ($evt->data['items'] as $html) echo $html;
191184dd2b1aSGerrit Uitslag    }
191284dd2b1aSGerrit Uitslag    $evt->advise_after();
191384dd2b1aSGerrit Uitslag}
191484dd2b1aSGerrit Uitslag
1915e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1916