xref: /dokuwiki/inc/template.php (revision 4dc42f7f535b7adeea17426327a60e242e2a7d4a)
16b13307fSandi<?php
2d4f83172SAndreas Gohr
36b13307fSandi/**
46b13307fSandi * DokuWiki template functions
56b13307fSandi *
66b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
76b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
86b13307fSandi */
9d4f83172SAndreas Gohr
1024870174SAndreas Gohruse dokuwiki\ActionRouter;
1124870174SAndreas Gohruse dokuwiki\Action\Exception\FatalException;
1224870174SAndreas Gohruse dokuwiki\Extension\PluginInterface;
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 *
29ac7a515fSAndreas Gohr * @param string $file
30ac7a515fSAndreas Gohr * @return string
31*4dc42f7fSGerrit Uitslag *
32*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
335a892029SAndreas Gohr */
34d868eb89SAndreas Gohrfunction template($file)
35d868eb89SAndreas Gohr{
365a892029SAndreas Gohr    global $conf;
375a892029SAndreas Gohr
38ac7a515fSAndreas Gohr    if (@is_readable(DOKU_INC . 'lib/tpl/' . $conf['template'] . '/' . $file))
39ac7a515fSAndreas Gohr        return DOKU_INC . 'lib/tpl/' . $conf['template'] . '/' . $file;
405a892029SAndreas Gohr
41ac7a515fSAndreas Gohr    return DOKU_INC . 'lib/tpl/dokuwiki/' . $file;
425a892029SAndreas Gohr}
435a892029SAndreas Gohr
44c4766956SAndreas Gohr/**
45c4766956SAndreas Gohr * Convenience function to access template dir from local FS
46c4766956SAndreas Gohr *
47c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
48c4766956SAndreas Gohr *
49afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
50ac7a515fSAndreas Gohr * @return string
51*4dc42f7fSGerrit Uitslag *
52*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
53c4766956SAndreas Gohr */
54d868eb89SAndreas Gohrfunction tpl_incdir($tpl = '')
55d868eb89SAndreas Gohr{
5675b14482SAndreas Gohr    global $conf;
57afb2c082SAndreas Gohr    if (!$tpl) $tpl = $conf['template'];
58afb2c082SAndreas Gohr    return DOKU_INC . 'lib/tpl/' . $tpl . '/';
59c4766956SAndreas Gohr}
60c4766956SAndreas Gohr
61c4766956SAndreas Gohr/**
62c4766956SAndreas Gohr * Convenience function to access template dir from web
63c4766956SAndreas Gohr *
64c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
65c4766956SAndreas Gohr *
66afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
67ac7a515fSAndreas Gohr * @return string
68*4dc42f7fSGerrit Uitslag *
69*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
70c4766956SAndreas Gohr */
71d868eb89SAndreas Gohrfunction tpl_basedir($tpl = '')
72d868eb89SAndreas Gohr{
7375b14482SAndreas Gohr    global $conf;
74afb2c082SAndreas Gohr    if (!$tpl) $tpl = $conf['template'];
75dcd4911eSMichael Hamann    return DOKU_BASE . 'lib/tpl/' . $tpl . '/';
76c4766956SAndreas Gohr}
77c4766956SAndreas Gohr
785a892029SAndreas Gohr/**
796b13307fSandi * Print the content
806b13307fSandi *
816b13307fSandi * This function is used for printing all the usual content
826b13307fSandi * (defined by the global $ACT var) by calling the appropriate
836b13307fSandi * outputfunction(s) from html.php
846b13307fSandi *
85ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
86ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
876b13307fSandi *
88*4dc42f7fSGerrit Uitslag * @param bool $prependTOC should the TOC be displayed here?
89*4dc42f7fSGerrit Uitslag * @return bool true if any output
9042ea7f44SGerrit Uitslag *
91ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
92ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
93*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
946b13307fSandi */
95d868eb89SAndreas Gohrfunction tpl_content($prependTOC = true)
96d868eb89SAndreas Gohr{
977ea0913cSchris    global $ACT;
98b8595a66SAndreas Gohr    global $INFO;
99b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
1007ea0913cSchris
1017ea0913cSchris    ob_start();
102cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
1037ea0913cSchris    $html_output = ob_get_clean();
104cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
10554e95700STom N Harris
10654e95700STom N Harris    return !empty($html_output);
1077ea0913cSchris}
1087ea0913cSchris
109ac7a515fSAndreas Gohr/**
110ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
111ac7a515fSAndreas Gohr *
112ac7a515fSAndreas Gohr * @return bool
113ac7a515fSAndreas Gohr */
114d868eb89SAndreas Gohrfunction tpl_content_core()
115d868eb89SAndreas Gohr{
11624870174SAndreas Gohr    $router = ActionRouter::getInstance();
117952acff9SAndreas Gohr    try {
118952acff9SAndreas Gohr        $router->getAction()->tplContent();
11924870174SAndreas Gohr    } catch (FatalException $e) {
120952acff9SAndreas Gohr        // there was no content for the action
121952acff9SAndreas Gohr        msg(hsc($e->getMessage()), -1);
12254e95700STom N Harris        return false;
1236b13307fSandi    }
12454e95700STom N Harris    return true;
1256b13307fSandi}
1266b13307fSandi
127c19fe9c0Sandi/**
128b8595a66SAndreas Gohr * Places the TOC where the function is called
129b8595a66SAndreas Gohr *
130b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
131b8595a66SAndreas Gohr * a false argument
132b8595a66SAndreas Gohr *
133ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
134ac7a515fSAndreas Gohr * @return string
135*4dc42f7fSGerrit Uitslag *
136*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
137b8595a66SAndreas Gohr */
138d868eb89SAndreas Gohrfunction tpl_toc($return = false)
139d868eb89SAndreas Gohr{
140b8595a66SAndreas Gohr    global $TOC;
141b8595a66SAndreas Gohr    global $ACT;
142b8595a66SAndreas Gohr    global $ID;
143b8595a66SAndreas Gohr    global $REV;
144b8595a66SAndreas Gohr    global $INFO;
145851f2e89SAnika Henke    global $conf;
14624870174SAndreas Gohr    $toc = [];
147b8595a66SAndreas Gohr
148b8595a66SAndreas Gohr    if (is_array($TOC)) {
149b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
150b8595a66SAndreas Gohr        $toc = $TOC;
1513c86d7c9SAndreas Gohr    } elseif (($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
152b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
153e0c26282SGerrit Uitslag        $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
154*4dc42f7fSGerrit Uitslag        $tocok = $meta['internal']['toc'] ?? true;
15524870174SAndreas Gohr        $toc = $meta['description']['tableofcontents'] ?? null;
156851f2e89SAnika Henke        if (!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
15724870174SAndreas Gohr            $toc = [];
158b8595a66SAndreas Gohr        }
159b8595a66SAndreas Gohr    } elseif ($ACT == 'admin') {
160a61966c5SChristopher Smith        // try to load admin plugin TOC
161*4dc42f7fSGerrit Uitslag        /** @var AdminPlugin $plugin */
162a61966c5SChristopher Smith        if ($plugin = plugin_getRequestAdminPlugin()) {
163b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
164b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
165b8595a66SAndreas Gohr        }
166b8595a66SAndreas Gohr    }
167b8595a66SAndreas Gohr
168cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
169b8595a66SAndreas Gohr    $html = html_TOC($toc);
170b8595a66SAndreas Gohr    if ($return) return $html;
171b8595a66SAndreas Gohr    echo $html;
172ac7a515fSAndreas Gohr    return '';
173b8595a66SAndreas Gohr}
174b8595a66SAndreas Gohr
175b8595a66SAndreas Gohr/**
176c19fe9c0Sandi * Handle the admin page contents
177c19fe9c0Sandi *
17842ea7f44SGerrit Uitslag * @return bool
179*4dc42f7fSGerrit Uitslag *
180*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
181c19fe9c0Sandi */
182d868eb89SAndreas Gohrfunction tpl_admin()
183d868eb89SAndreas Gohr{
184f8cc712eSAndreas Gohr    global $INFO;
185b8595a66SAndreas Gohr    global $TOC;
186ac7a515fSAndreas Gohr    global $INPUT;
18711e2ce22Schris
188b8595a66SAndreas Gohr    $plugin = null;
189ac7a515fSAndreas Gohr    $class = $INPUT->str('page');
190ac7a515fSAndreas Gohr    if (!empty($class)) {
19111e2ce22Schris        $pluginlist = plugin_list('admin');
19211e2ce22Schris
193ac7a515fSAndreas Gohr        if (in_array($class, $pluginlist)) {
19411e2ce22Schris            // attempt to load the plugin
195*4dc42f7fSGerrit Uitslag            /** @var AdminPlugin $plugin */
196a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
19711e2ce22Schris        }
19811e2ce22Schris    }
19911e2ce22Schris
20024870174SAndreas Gohr    if ($plugin instanceof PluginInterface) {
201b8595a66SAndreas Gohr        if (!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
202b8595a66SAndreas Gohr        if ($INFO['prependTOC']) tpl_toc();
203f8cc712eSAndreas Gohr        $plugin->html();
204f8cc712eSAndreas Gohr    } else {
20524870174SAndreas Gohr        $admin = new Admin();
2060470c28fSAndreas Gohr        $admin->show();
207f8cc712eSAndreas Gohr    }
20854e95700STom N Harris    return true;
209c19fe9c0Sandi}
2106b13307fSandi
2116b13307fSandi/**
2126b13307fSandi * Print the correct HTML meta headers
2136b13307fSandi *
2146b13307fSandi * This has to go into the head section of your template.
2156b13307fSandi *
216ac7a515fSAndreas Gohr * @param bool $alt Should feeds and alternative format links be added?
217ac7a515fSAndreas Gohr * @return bool
218*4dc42f7fSGerrit Uitslag * @throws JsonException
219*4dc42f7fSGerrit Uitslag *
220*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
221*4dc42f7fSGerrit Uitslag * @triggers TPL_METAHEADER_OUTPUT
2226b13307fSandi */
223d868eb89SAndreas Gohrfunction tpl_metaheaders($alt = true)
224d868eb89SAndreas Gohr{
2256b13307fSandi    global $ID;
226d98d4540SBen Coburn    global $REV;
2276b13307fSandi    global $INFO;
22872e0dc37SAndreas Gohr    global $JSINFO;
2296b13307fSandi    global $ACT;
2304bb1b5aeSAndreas Gohr    global $QUERY;
2316b13307fSandi    global $lang;
232dc57ef04Sandi    global $conf;
2339c438d6cSMichael Hamann    global $updateVersion;
234585bf44eSChristopher Smith    /** @var Input $INPUT */
235585bf44eSChristopher Smith    global $INPUT;
2366b13307fSandi
2377bff22c0SAndreas Gohr    // prepare the head array
23824870174SAndreas Gohr    $head = [];
2397bff22c0SAndreas Gohr
240202ac28bSMichael Klier    // prepare seed for js and css
241cd997f93SAndreas Gohr    $tseed = $updateVersion;
242202ac28bSMichael Klier    $depends = getConfigFiles('main');
24384e76a7eSAndreas Gohr    $depends[] = DOKU_CONF . "tpl/" . $conf['template'] . "/style.ini";
244cd997f93SAndreas Gohr    foreach ($depends as $f) $tseed .= @filemtime($f);
245cd997f93SAndreas Gohr    $tseed = md5($tseed);
2467bff22c0SAndreas Gohr
2476b13307fSandi    // the usual stuff
24824870174SAndreas Gohr    $head['meta'][] = ['name' => 'generator', 'content' => 'DokuWiki'];
24963cf4192Ssarehag    if (actionOK('search')) {
25024870174SAndreas Gohr        $head['link'][] = [
25124870174SAndreas Gohr            'rel' => 'search',
25224870174SAndreas Gohr            'type' => 'application/opensearchdescription+xml',
25324870174SAndreas Gohr            'href' => DOKU_BASE . 'lib/exe/opensearch.php',
25424870174SAndreas Gohr            'title' => $conf['title']
25524870174SAndreas Gohr        ];
25663cf4192Ssarehag    }
25763cf4192Ssarehag
25824870174SAndreas Gohr    $head['link'][] = ['rel' => 'start', 'href' => DOKU_BASE];
2597aedde2eSGina Haeussge    if (actionOK('index')) {
26024870174SAndreas Gohr        $head['link'][] = [
26124870174SAndreas Gohr            'rel' => 'contents',
26224870174SAndreas Gohr            'href' => wl($ID, 'do=index', false, '&'),
263ac7a515fSAndreas Gohr            'title' => $lang['btn_index']
26424870174SAndreas Gohr        ];
2657aedde2eSGina Haeussge    }
266f96fa415SAndreas Gohr
2675e0255e3SMichael Große    if (actionOK('manifest')) {
26824870174SAndreas Gohr        $head['link'][] = [
26924870174SAndreas Gohr            'rel' => 'manifest',
27024870174SAndreas Gohr            'href' => DOKU_BASE . 'lib/exe/manifest.php'
27124870174SAndreas Gohr        ];
2725e0255e3SMichael Große    }
2735e0255e3SMichael Große
27424870174SAndreas Gohr    $styleUtil = new StyleUtils();
2754593dbd2SAnna Dabrowska    $styleIni = $styleUtil->cssStyleini();
27640ca8540SMichael Große    $replacements = $styleIni['replacements'];
27740ca8540SMichael Große    if (!empty($replacements['__theme_color__'])) {
27824870174SAndreas Gohr        $head['meta'][] = [
27924870174SAndreas Gohr            'name' => 'theme-color',
28024870174SAndreas Gohr            'content' => $replacements['__theme_color__']
28124870174SAndreas Gohr        ];
28240ca8540SMichael Große    }
28340ca8540SMichael Große
284f96fa415SAndreas Gohr    if ($alt) {
28554be1338SGerrit Uitslag        if (actionOK('rss')) {
28624870174SAndreas Gohr            $head['link'][] = [
28724870174SAndreas Gohr                'rel' => 'alternate',
28824870174SAndreas Gohr                'type' => 'application/rss+xml',
28924870174SAndreas Gohr                'title' => $lang['btn_recent'],
29024870174SAndreas Gohr                'href' => DOKU_BASE . 'feed.php'
29124870174SAndreas Gohr            ];
29224870174SAndreas Gohr            $head['link'][] = [
29324870174SAndreas Gohr                'rel' => 'alternate',
29424870174SAndreas Gohr                'type' => 'application/rss+xml',
295a1288caeSGerrit Uitslag                'title' => $lang['currentns'],
296aac83cd4SPhy                'href' => DOKU_BASE . 'feed.php?mode=list&ns=' . (isset($INFO) ? $INFO['namespace'] : '')
29724870174SAndreas Gohr            ];
29854be1338SGerrit Uitslag        }
299c35f3875SAndreas Gohr        if (($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
30024870174SAndreas Gohr            $head['link'][] = [
301ac7a515fSAndreas Gohr                'rel' => 'edit',
302715bdf1fSAndreas Gohr                'title' => $lang['btn_edit'],
303ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
30424870174SAndreas Gohr            ];
305c35f3875SAndreas Gohr        }
306c35f3875SAndreas Gohr
30754be1338SGerrit Uitslag        if (actionOK('rss') && $ACT == 'search') {
30824870174SAndreas Gohr            $head['link'][] = [
30924870174SAndreas Gohr                'rel' => 'alternate',
31024870174SAndreas Gohr                'type' => 'application/rss+xml',
311a1288caeSGerrit Uitslag                'title' => $lang['searchresult'],
312ac7a515fSAndreas Gohr                'href' => DOKU_BASE . 'feed.php?mode=search&q=' . $QUERY
31324870174SAndreas Gohr            ];
3144bb1b5aeSAndreas Gohr        }
315bae36d94SAndreas Gohr
316bae36d94SAndreas Gohr        if (actionOK('export_xhtml')) {
31724870174SAndreas Gohr            $head['link'][] = [
31824870174SAndreas Gohr                'rel' => 'alternate',
31924870174SAndreas Gohr                'type' => 'text/html',
32024870174SAndreas Gohr                'title' => $lang['plainhtml'],
321ac7a515fSAndreas Gohr                'href' => exportlink($ID, 'xhtml', '', false, '&')
32224870174SAndreas Gohr            ];
323bae36d94SAndreas Gohr        }
324bae36d94SAndreas Gohr
325bae36d94SAndreas Gohr        if (actionOK('export_raw')) {
32624870174SAndreas Gohr            $head['link'][] = [
32724870174SAndreas Gohr                'rel' => 'alternate',
32824870174SAndreas Gohr                'type' => 'text/plain',
32924870174SAndreas Gohr                'title' => $lang['wikimarkup'],
330ac7a515fSAndreas Gohr                'href' => exportlink($ID, 'raw', '', false, '&')
33124870174SAndreas Gohr            ];
332f96fa415SAndreas Gohr        }
333bae36d94SAndreas Gohr    }
3346b13307fSandi
33563f13cadSDamien Regad    // setup robot tags appropriate for different modes
3364f2e0004STim Weber    if (($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3376b13307fSandi        if ($INFO['exists']) {
3386b13307fSandi            //delay indexing:
339fb9fa88bSAndreas Gohr            if ((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID)) {
34024870174SAndreas Gohr                $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow'];
3416b13307fSandi            } else {
34224870174SAndreas Gohr                $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow'];
3436b13307fSandi            }
34401f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
34501f9be51SAnika Henke            if ($ID == $conf['start']) {
34601f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
34701f9be51SAnika Henke            }
34824870174SAndreas Gohr            $head['link'][] = ['rel' => 'canonical', 'href' => $canonicalUrl];
3496b13307fSandi        } else {
35024870174SAndreas Gohr            $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,follow'];
3516b13307fSandi        }
3527a24876fSAndreas Gohr    } elseif (defined('DOKU_MEDIADETAIL')) {
35324870174SAndreas Gohr        $head['meta'][] = ['name' => 'robots', 'content' => 'index,follow'];
3546b13307fSandi    } else {
35524870174SAndreas Gohr        $head['meta'][] = ['name' => 'robots', 'content' => 'noindex,nofollow'];
3566b13307fSandi    }
3576b13307fSandi
358831800b8SAndreas Gohr    // set metadata
359831800b8SAndreas Gohr    if ($ACT == 'show' || $ACT == 'export_xhtml') {
360831800b8SAndreas Gohr        // keywords (explicit or implicit)
361bb4866bdSchris        if (!empty($INFO['meta']['subject'])) {
36224870174SAndreas Gohr            $head['meta'][] = ['name' => 'keywords', 'content' => implode(',', $INFO['meta']['subject'])];
363831800b8SAndreas Gohr        } else {
36424870174SAndreas Gohr            $head['meta'][] = ['name' => 'keywords', 'content' => str_replace(':', ',', $ID)];
365831800b8SAndreas Gohr        }
366831800b8SAndreas Gohr    }
367831800b8SAndreas Gohr
36878a6aeb1SAndreas Gohr    // load stylesheets
36924870174SAndreas Gohr    $head['link'][] = [
37059305168SPhy        'rel' => 'stylesheet',
371e283bd6cSAnika Henke        'href' => DOKU_BASE . 'lib/exe/css.php?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed
37224870174SAndreas Gohr    ];
373bad31ae9SAndreas Gohr
374aac83cd4SPhy    $script = "var NS='" . (isset($INFO) ? $INFO['namespace'] : '') . "';";
375585bf44eSChristopher Smith    if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
37698169a0fSAndreas Gohr        $script .= "var SIG=" . toolbar_signature() . ";";
377c591aabeSAndreas Gohr    }
3780c39d46cSMichael Große    jsinfo();
37924870174SAndreas Gohr    $script .= 'var JSINFO = ' . json_encode($JSINFO, JSON_THROW_ON_ERROR) . ';';
38024870174SAndreas Gohr    $head['script'][] = ['_data' => $script];
3818bbcb611SAndreas Gohr
38261537d47SAndreas Gohr    // load jquery
383fa078663SAndreas Gohr    $jquery = getCdnUrls();
384fa078663SAndreas Gohr    foreach ($jquery as $src) {
38524870174SAndreas Gohr        $head['script'][] = [
386fc6b11d2SMichael Große                '_data' => '',
38724870174SAndreas Gohr                'src' => $src
38824870174SAndreas Gohr            ] + ($conf['defer_js'] ? ['defer' => 'defer'] : []);
38961537d47SAndreas Gohr    }
39061537d47SAndreas Gohr
39161537d47SAndreas Gohr    // load our javascript dispatcher
39224870174SAndreas Gohr    $head['script'][] = [
393de1dc35bSNicolas Friedli            '_data' => '',
39424870174SAndreas Gohr            'src' => DOKU_BASE . 'lib/exe/js.php' . '?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed
39524870174SAndreas Gohr        ] + ($conf['defer_js'] ? ['defer' => 'defer'] : []);
3967bff22c0SAndreas Gohr
3977bff22c0SAndreas Gohr    // trigger event here
398cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
39954e95700STom N Harris    return true;
4007bff22c0SAndreas Gohr}
4017bff22c0SAndreas Gohr
4027bff22c0SAndreas Gohr/**
4037bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
4047bff22c0SAndreas Gohr *
4057bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
4067bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
4077bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
4087bff22c0SAndreas Gohr *
40942ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
4101304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
4117bff22c0SAndreas Gohr *
41242ea7f44SGerrit Uitslag * @param array $data
413*4dc42f7fSGerrit Uitslag *
414*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
4157bff22c0SAndreas Gohr */
416d868eb89SAndreas Gohrfunction _tpl_metaheaders_action($data)
417d868eb89SAndreas Gohr{
4187bff22c0SAndreas Gohr    foreach ($data as $tag => $inst) {
419427bf9a2SAndreas Gohr        if ($tag == 'script') {
420427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
421427bf9a2SAndreas Gohr        }
4227bff22c0SAndreas Gohr        foreach ($inst as $attr) {
423177d6836SAndreas Gohr            if (empty($attr)) {
424d4f83172SAndreas Gohr                continue;
425d4f83172SAndreas Gohr            }
4267bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
42726afa874SMikhail I. Izmestev            if (isset($attr['_data']) || $tag == 'script') {
428740897dcSasivery                if ($tag == 'script' && isset($attr['_data']))
42909f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/" .
430e226efe1SAndreas Gohr                        $attr['_data'] .
43109f791c4SDominik Eckelmann                        "\n/*!]]>*/";
432e226efe1SAndreas Gohr
43324870174SAndreas Gohr                echo '>', $attr['_data'] ?? '', '</', $tag, '>';
4347bff22c0SAndreas Gohr            } else {
4357bff22c0SAndreas Gohr                echo '/>';
4367bff22c0SAndreas Gohr            }
4377bff22c0SAndreas Gohr            echo "\n";
4387bff22c0SAndreas Gohr        }
439427bf9a2SAndreas Gohr        if ($tag == 'script') {
440427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
441427bf9a2SAndreas Gohr        }
4427bff22c0SAndreas Gohr    }
4436b13307fSandi}
4446b13307fSandi
4456b13307fSandi/**
4466b13307fSandi * Print a link
4476b13307fSandi *
4485e163278SAndreas Gohr * Just builds a link.
4496b13307fSandi *
45042ea7f44SGerrit Uitslag * @param string $url
45142ea7f44SGerrit Uitslag * @param string $name
45242ea7f44SGerrit Uitslag * @param string $more
45321d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
45421d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
455*4dc42f7fSGerrit Uitslag *
456*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
4576b13307fSandi */
458d868eb89SAndreas Gohrfunction tpl_link($url, $name, $more = '', $return = false)
459d868eb89SAndreas Gohr{
46001f17825SAnika Henke    $out = '<a href="' . $url . '" ';
4611af98a77SAnika Henke    if ($more) $out .= ' ' . $more;
4621af98a77SAnika Henke    $out .= ">$name</a>";
4631af98a77SAnika Henke    if ($return) return $out;
46426dfc232SAndreas Gohr    echo $out;
46554e95700STom N Harris    return true;
4666b13307fSandi}
4676b13307fSandi
4686b13307fSandi/**
46955efc227SAndreas Gohr * Prints a link to a WikiPage
47055efc227SAndreas Gohr *
47155efc227SAndreas Gohr * Wrapper around html_wikilink
47255efc227SAndreas Gohr *
47342ea7f44SGerrit Uitslag * @param string $id page id
47442ea7f44SGerrit Uitslag * @param string|null $name the name of the link
475fb008d31SIain Hallam * @param bool $return
476fb008d31SIain Hallam * @return true|string
477*4dc42f7fSGerrit Uitslag *
478*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
47955efc227SAndreas Gohr */
480d868eb89SAndreas Gohrfunction tpl_pagelink($id, $name = null, $return = false)
481d868eb89SAndreas Gohr{
482c4a386f1SIain Hallam    $out = '<bdi>' . html_wikilink($id, $name) . '</bdi>';
483c4a386f1SIain Hallam    if ($return) return $out;
48426dfc232SAndreas Gohr    echo $out;
48554e95700STom N Harris    return true;
48655efc227SAndreas Gohr}
48755efc227SAndreas Gohr
48855efc227SAndreas Gohr/**
489a3ec5f4aSmatthiasgrimm * get the parent page
490a3ec5f4aSmatthiasgrimm *
491a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
492a3ec5f4aSmatthiasgrimm * returns false if none is available
493a3ec5f4aSmatthiasgrimm *
49442ea7f44SGerrit Uitslag * @param string $id page id
49542ea7f44SGerrit Uitslag * @return false|string
496*4dc42f7fSGerrit Uitslag *
497*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
498a3ec5f4aSmatthiasgrimm */
499d868eb89SAndreas Gohrfunction tpl_getparent($id)
500d868eb89SAndreas Gohr{
5018c6be208SAndreas Gohr    $resolver = new PageResolver('root');
5028c6be208SAndreas Gohr
503377f9e97SAndreas Gohr    $parent = getNS($id) . ':';
5048c6be208SAndreas Gohr    $parent = $resolver->resolveId($parent);
505a197105eSmatthiasgrimm    if ($parent == $id) {
506a197105eSmatthiasgrimm        $pos = strrpos(getNS($id), ':');
507a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos) . ':';
5088c6be208SAndreas Gohr        $parent = $resolver->resolveId($parent);
509377f9e97SAndreas Gohr        if ($parent == $id) return false;
510a197105eSmatthiasgrimm    }
511377f9e97SAndreas Gohr    return $parent;
512a3ec5f4aSmatthiasgrimm}
513a3ec5f4aSmatthiasgrimm
514a3ec5f4aSmatthiasgrimm/**
5156b13307fSandi * Print one of the buttons
5166b13307fSandi *
517e0c26282SGerrit Uitslag * @param string $type
518e0c26282SGerrit Uitslag * @param bool $return
519e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
520*4dc42f7fSGerrit Uitslag * @see    tpl_get_action
521*4dc42f7fSGerrit Uitslag *
522*4dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de>
523affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
5246b13307fSandi */
525d868eb89SAndreas Gohrfunction tpl_button($type, $return = false)
526d868eb89SAndreas Gohr{
527affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
528a453d131SAdrian Lang    $data = tpl_get_action($type);
529a453d131SAdrian Lang    if ($data === false) {
530a453d131SAdrian Lang        return false;
531a453d131SAdrian Lang    } elseif (!is_array($data)) {
532a453d131SAdrian Lang        $out = sprintf($data, 'button');
533409d7af7SAndreas Gohr    } else {
534ac7a515fSAndreas Gohr        /**
535ac7a515fSAndreas Gohr         * @var string $accesskey
536ac7a515fSAndreas Gohr         * @var string $id
537ac7a515fSAndreas Gohr         * @var string $method
538ac7a515fSAndreas Gohr         * @var array $params
539ac7a515fSAndreas Gohr         */
540a453d131SAdrian Lang        extract($data);
541a453d131SAdrian Lang        if ($id === '#dokuwiki__top') {
542a453d131SAdrian Lang            $out = html_topbtn();
543409d7af7SAndreas Gohr        } else {
544a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
545409d7af7SAndreas Gohr        }
546409d7af7SAndreas Gohr    }
5471af98a77SAnika Henke    if ($return) return $out;
548a453d131SAdrian Lang    echo $out;
549a453d131SAdrian Lang    return true;
5506b13307fSandi}
5516b13307fSandi
5526b13307fSandi/**
553ed630903Sandi * Like the action buttons but links
554ed630903Sandi *
55542ea7f44SGerrit Uitslag * @param string $type action command
556e0c26282SGerrit Uitslag * @param string $pre prefix of link
557e0c26282SGerrit Uitslag * @param string $suf suffix of link
558e0c26282SGerrit Uitslag * @param string $inner innerHML of link
55921d806cdSGerrit Uitslag * @param bool $return if true it returns html, otherwise prints
560e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
561*4dc42f7fSGerrit Uitslag *
562*4dc42f7fSGerrit Uitslag * @see    tpl_get_action
563*4dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de>
564affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
565a453d131SAdrian Lang */
566d868eb89SAndreas Gohrfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false)
567d868eb89SAndreas Gohr{
568affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
569a453d131SAdrian Lang    global $lang;
570a453d131SAdrian Lang    $data = tpl_get_action($type);
571a453d131SAdrian Lang    if ($data === false) {
572a453d131SAdrian Lang        return false;
573a453d131SAdrian Lang    } elseif (!is_array($data)) {
574a453d131SAdrian Lang        $out = sprintf($data, 'link');
575a453d131SAdrian Lang    } else {
576ac7a515fSAndreas Gohr        /**
577ac7a515fSAndreas Gohr         * @var string $accesskey
578ac7a515fSAndreas Gohr         * @var string $id
579ac7a515fSAndreas Gohr         * @var string $method
580b1af9014SChristopher Smith         * @var bool $nofollow
581ac7a515fSAndreas Gohr         * @var array $params
582becfa414SGerrit Uitslag         * @var string $replacement
583ac7a515fSAndreas Gohr         */
584a453d131SAdrian Lang        extract($data);
585a453d131SAdrian Lang        if (strpos($id, '#') === 0) {
586a453d131SAdrian Lang            $linktarget = $id;
587a453d131SAdrian Lang        } else {
588a453d131SAdrian Lang            $linktarget = wl($id, $params);
589a453d131SAdrian Lang        }
590a453d131SAdrian Lang        $caption = $lang['btn_' . $type];
591becfa414SGerrit Uitslag        if (strpos($caption, '%s')) {
592becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
593becfa414SGerrit Uitslag        }
59424870174SAndreas Gohr        $akey = '';
59524870174SAndreas Gohr        $addTitle = '';
596c7e90e3fSAnika Henke        if ($accesskey) {
597c7e90e3fSAnika Henke            $akey = 'accesskey="' . $accesskey . '" ';
598c7e90e3fSAnika Henke            $addTitle = ' [' . strtoupper($accesskey) . ']';
599c7e90e3fSAnika Henke        }
600b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
601ac7a515fSAndreas Gohr        $out = tpl_link(
602dccd6b2bSAndreas Gohr            $linktarget,
603dccd6b2bSAndreas Gohr            $pre . ($inner ?: $caption) . $suf,
604a453d131SAdrian Lang            'class="action ' . $type . '" ' .
605b1af9014SChristopher Smith            $akey . $rel .
606dccd6b2bSAndreas Gohr            'title="' . hsc($caption) . $addTitle . '"',
607dccd6b2bSAndreas Gohr            true
608ac7a515fSAndreas Gohr        );
609a453d131SAdrian Lang    }
610a453d131SAdrian Lang    if ($return) return $out;
611a453d131SAdrian Lang    echo $out;
612a453d131SAdrian Lang    return true;
613a453d131SAdrian Lang}
614a453d131SAdrian Lang
615a453d131SAdrian Lang/**
616a453d131SAdrian Lang * Check the actions and get data for buttons and links
617ed630903Sandi *
618ac7a515fSAndreas Gohr * @param string $type
619ac7a515fSAndreas Gohr * @return array|bool|string
620*4dc42f7fSGerrit Uitslag *
621*4dc42f7fSGerrit Uitslag * @author Adrian Lang <mail@adrianlang.de>
622*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
623*4dc42f7fSGerrit Uitslag * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
624affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
625ed630903Sandi */
626d868eb89SAndreas Gohrfunction tpl_get_action($type)
627d868eb89SAndreas Gohr{
628affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
629a453d131SAdrian Lang    if ($type == 'history') $type = 'revisions';
6304c4b65c8SMichael Hamann    if ($type == 'subscription') $type = 'subscribe';
6314887c154SAndreas Gohr    if ($type == 'img_backto') $type = 'imgBackto';
632409d7af7SAndreas Gohr
6334887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
6344887c154SAndreas Gohr    if (class_exists($class)) {
6354887c154SAndreas Gohr        try {
63624870174SAndreas Gohr            /** @var AbstractItem $item */
63773022918SAndreas Gohr            $item = new $class();
6384887c154SAndreas Gohr            $data = $item->getLegacyData();
6397b4365a7SGerrit Uitslag            $unknown = false;
640*4dc42f7fSGerrit Uitslag        } catch (RuntimeException $ignored) {
6414887c154SAndreas Gohr            return false;
642b8a111f5SMichael Klier        }
643ed630903Sandi    } else {
6444887c154SAndreas Gohr        global $ID;
64524870174SAndreas Gohr        $data = [
6464887c154SAndreas Gohr            'accesskey' => null,
6474887c154SAndreas Gohr            'type' => $type,
6484887c154SAndreas Gohr            'id' => $ID,
6494887c154SAndreas Gohr            'method' => 'get',
65024870174SAndreas Gohr            'params' => ['do' => $type],
6514887c154SAndreas Gohr            'nofollow' => true,
65224870174SAndreas Gohr            'replacement' => ''
65324870174SAndreas Gohr        ];
6547b4365a7SGerrit Uitslag        $unknown = true;
655ed630903Sandi    }
6567b4365a7SGerrit Uitslag
657e1d9dcc8SAndreas Gohr    $evt = new Event('TPL_ACTION_GET', $data);
6587b4365a7SGerrit Uitslag    if ($evt->advise_before()) {
6597b4365a7SGerrit Uitslag        //handle unknown types
6607b4365a7SGerrit Uitslag        if ($unknown) {
66138d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6627b4365a7SGerrit Uitslag        }
6637b4365a7SGerrit Uitslag    }
6647b4365a7SGerrit Uitslag    $evt->advise_after();
6657b4365a7SGerrit Uitslag    unset($evt);
6667b4365a7SGerrit Uitslag
6677b4365a7SGerrit Uitslag    return $data;
668ed630903Sandi}
669ed630903Sandi
670ed630903Sandi/**
67101f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
67201f17825SAnika Henke *
67342ea7f44SGerrit Uitslag * @param string $type action command
674ac7a515fSAndreas Gohr * @param bool $link link or form button?
675e0c26282SGerrit Uitslag * @param string|bool $wrapper HTML element wrapper
676ac7a515fSAndreas Gohr * @param bool $return return or print
677ac7a515fSAndreas Gohr * @param string $pre prefix for links
678ac7a515fSAndreas Gohr * @param string $suf suffix for links
679ac7a515fSAndreas Gohr * @param string $inner inner HTML for links
680ac7a515fSAndreas Gohr * @return bool|string
681*4dc42f7fSGerrit Uitslag *
682*4dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
683affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
68401f17825SAnika Henke */
685d868eb89SAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '')
686d868eb89SAndreas Gohr{
687affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
68801f17825SAnika Henke    $out = '';
689ac7a515fSAndreas Gohr    if ($link) {
690e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
691ac7a515fSAndreas Gohr    } else {
692e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
693ac7a515fSAndreas Gohr    }
69401f17825SAnika Henke    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
69501f17825SAnika Henke
69601f17825SAnika Henke    if ($return) return $out;
69726dfc232SAndreas Gohr    echo $out;
69824870174SAndreas Gohr    return (bool)$out;
69901f17825SAnika Henke}
70001f17825SAnika Henke
70101f17825SAnika Henke/**
7026b13307fSandi * Print the search form
7036b13307fSandi *
70472645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
70572645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
70672645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
70772645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
70872645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
70972645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
71072645b75SAndreas Gohr *
711ac7a515fSAndreas Gohr * @param bool $ajax
712ac7a515fSAndreas Gohr * @param bool $autocomplete
713ac7a515fSAndreas Gohr * @return bool
714*4dc42f7fSGerrit Uitslag *
715*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
7166b13307fSandi */
717d868eb89SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true)
718d868eb89SAndreas Gohr{
7196b13307fSandi    global $lang;
720c1e3b7d9Smatthiasgrimm    global $ACT;
721ad4aaef7SAndreas Gohr    global $QUERY;
722cbcc2fa5SMichael Große    global $ID;
723c1e3b7d9Smatthiasgrimm
724670ff54eSchris    // don't print the search form if search action has been disabled
72564276bbcSarbrk1    if (!actionOK('search')) return false;
726670ff54eSchris
72724870174SAndreas Gohr    $searchForm = new Form([
7283c7a3327SMichael Große        'action' => wl(),
7293c7a3327SMichael Große        'method' => 'get',
7303c7a3327SMichael Große        'role' => 'search',
7313c7a3327SMichael Große        'class' => 'search',
7323c7a3327SMichael Große        'id' => 'dw__search',
7337fa270bcSMichael Große    ], true);
7343eb2b869SMichael Große    $searchForm->addTagOpen('div')->addClass('no');
7353c7a3327SMichael Große    $searchForm->setHiddenField('do', 'search');
736d22b78c8SMichael Große    $searchForm->setHiddenField('id', $ID);
737d22b78c8SMichael Große    $searchForm->addTextInput('q')
7383c7a3327SMichael Große        ->addClass('edit')
7393c7a3327SMichael Große        ->attrs([
7403c7a3327SMichael Große            'title' => '[F]',
7413c7a3327SMichael Große            'accesskey' => 'f',
7423c7a3327SMichael Große            'placeholder' => $lang['btn_search'],
7433c7a3327SMichael Große            'autocomplete' => $autocomplete ? 'on' : 'off',
7443c7a3327SMichael Große        ])
7453c7a3327SMichael Große        ->id('qsearch__in')
7463c7a3327SMichael Große        ->val($ACT === 'search' ? $QUERY : '')
747*4dc42f7fSGerrit Uitslag        ->useInput(false);
7483c7a3327SMichael Große    $searchForm->addButton('', $lang['btn_search'])->attrs([
7493c7a3327SMichael Große        'type' => 'submit',
7503c7a3327SMichael Große        'title' => $lang['btn_search'],
7513c7a3327SMichael Große    ]);
7523c7a3327SMichael Große    if ($ajax) {
7533c7a3327SMichael Große        $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
7543c7a3327SMichael Große        $searchForm->addTagClose('div');
7553c7a3327SMichael Große    }
7563eb2b869SMichael Große    $searchForm->addTagClose('div');
7573c7a3327SMichael Große
758c6977b3aSSatoshi Sahara    echo $searchForm->toHTML('QuickSearch');
7593c7a3327SMichael Große
76054e95700STom N Harris    return true;
7616b13307fSandi}
7626b13307fSandi
7636b13307fSandi/**
7646b13307fSandi * Print the breadcrumbs trace
7656b13307fSandi *
766ac7a515fSAndreas Gohr * @param string $sep Separator between entries
767c4a386f1SIain Hallam * @param bool $return return or print
768c4a386f1SIain Hallam * @return bool|string
769*4dc42f7fSGerrit Uitslag *
770*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
7716b13307fSandi */
772d868eb89SAndreas Gohrfunction tpl_breadcrumbs($sep = null, $return = false)
773d868eb89SAndreas Gohr{
7746b13307fSandi    global $lang;
7756b13307fSandi    global $conf;
7766b13307fSandi
7776b13307fSandi    //check if enabled
778359fab8bSMichael Hamann    if (!$conf['breadcrumbs']) return false;
7796b13307fSandi
780c4a386f1SIain Hallam    //set default
781c4a386f1SIain Hallam    if (is_null($sep)) $sep = '•';
782c4a386f1SIain Hallam
783c4a386f1SIain Hallam    $out = '';
784c4a386f1SIain Hallam
7856b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
786265e3787Sandi
7872979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">' . $sep . '</span> ';
788265e3787Sandi
78940eb54bbSjan    //render crumbs, highlight the last one
790c4a386f1SIain Hallam    $out .= '<span class="bchead">' . $lang['breadcrumb'] . '</span>';
79140eb54bbSjan    $last = count($crumbs);
79240eb54bbSjan    $i = 0;
793a77f5846Sjan    foreach ($crumbs as $id => $name) {
79440eb54bbSjan        $i++;
795c4a386f1SIain Hallam        $out .= $crumbs_sep;
796c4a386f1SIain Hallam        if ($i == $last) $out .= '<span class="curid">';
797c4a386f1SIain Hallam        $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="' . $id . '"', true) . '</bdi>';
798c4a386f1SIain Hallam        if ($i == $last) $out .= '</span>';
7996b13307fSandi    }
800c4a386f1SIain Hallam    if ($return) return $out;
80126dfc232SAndreas Gohr    echo $out;
80224870174SAndreas Gohr    return (bool)$out;
8036b13307fSandi}
8046b13307fSandi
8056b13307fSandi/**
8061734437eSandi * Hierarchical breadcrumbs
8071734437eSandi *
80831e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8091734437eSandi * It only makes sense with a deep site structure.
8101734437eSandi *
811ac7a515fSAndreas Gohr * @param string $sep Separator between entries
812c4a386f1SIain Hallam * @param bool $return return or print
813c4a386f1SIain Hallam * @return bool|string
814*4dc42f7fSGerrit Uitslag *
815*4dc42f7fSGerrit Uitslag * @todo   May behave strangely in RTL languages
816*4dc42f7fSGerrit Uitslag * @author <fredrik@averpil.com>
817*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
818*4dc42f7fSGerrit Uitslag * @author Nigel McNie <oracle.shinoda@gmail.com>
819*4dc42f7fSGerrit Uitslag * @author Sean Coates <sean@caedmon.net>
8201734437eSandi */
821d868eb89SAndreas Gohrfunction tpl_youarehere($sep = null, $return = false)
822d868eb89SAndreas Gohr{
8231734437eSandi    global $conf;
8241734437eSandi    global $ID;
8251734437eSandi    global $lang;
8261734437eSandi
82731e187f8SSean Coates    // check if enabled
82854e95700STom N Harris    if (!$conf['youarehere']) return false;
8291734437eSandi
830c4a386f1SIain Hallam    //set default
831c4a386f1SIain Hallam    if (is_null($sep)) $sep = ' » ';
832c4a386f1SIain Hallam
833c4a386f1SIain Hallam    $out = '';
834c4a386f1SIain Hallam
8351734437eSandi    $parts = explode(':', $ID);
836796bafb3SAndreas Gohr    $count = count($parts);
8371734437eSandi
838c4a386f1SIain Hallam    $out .= '<span class="bchead">' . $lang['youarehere'] . ' </span>';
8393940c519SMark
84008d7a575SAndreas Gohr    // always print the startpage
841c4a386f1SIain Hallam    $out .= '<span class="home">' . tpl_pagelink(':' . $conf['start'], null, true) . '</span>';
842796bafb3SAndreas Gohr
843796bafb3SAndreas Gohr    // print intermediate namespace links
844796bafb3SAndreas Gohr    $part = '';
845796bafb3SAndreas Gohr    for ($i = 0; $i < $count - 1; $i++) {
846796bafb3SAndreas Gohr        $part .= $parts[$i] . ':';
847796bafb3SAndreas Gohr        $page = $part;
848796bafb3SAndreas Gohr        if ($page == $conf['start']) continue; // Skip startpage
849796bafb3SAndreas Gohr
85008d7a575SAndreas Gohr        // output
851c4a386f1SIain Hallam        $out .= $sep . tpl_pagelink($page, null, true);
85231e187f8SSean Coates    }
8531734437eSandi
854796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
8558c6be208SAndreas Gohr    if (isset($page)) {
8568c6be208SAndreas Gohr        $page = (new PageResolver('root'))->resolveId($page);
8578c6be208SAndreas Gohr        if ($page == $part . $parts[$i]) {
858a8c33dedSMichael Große            if ($return) return $out;
85926dfc232SAndreas Gohr            echo $out;
860a8c33dedSMichael Große            return true;
861a8c33dedSMichael Große        }
8628c6be208SAndreas Gohr    }
863796bafb3SAndreas Gohr    $page = $part . $parts[$i];
864a8c33dedSMichael Große    if ($page == $conf['start']) {
865a8c33dedSMichael Große        if ($return) return $out;
86626dfc232SAndreas Gohr        echo $out;
867a8c33dedSMichael Große        return true;
868a8c33dedSMichael Große    }
869c4a386f1SIain Hallam    $out .= $sep;
870c4a386f1SIain Hallam    $out .= tpl_pagelink($page, null, true);
871c4a386f1SIain Hallam    if ($return) return $out;
87226dfc232SAndreas Gohr    echo $out;
87324870174SAndreas Gohr    return (bool)$out;
8741734437eSandi}
8751734437eSandi
8761734437eSandi/**
8776b13307fSandi * Print info if the user is logged in
878a2488c3cSMatthias Grimm * and show full name in that case
8796b13307fSandi *
8806b13307fSandi * Could be enhanced with a profile link in future?
8816b13307fSandi *
882ac7a515fSAndreas Gohr * @return bool
883*4dc42f7fSGerrit Uitslag *
884*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
8856b13307fSandi */
886d868eb89SAndreas Gohrfunction tpl_userinfo()
887d868eb89SAndreas Gohr{
8886b13307fSandi    global $lang;
889585bf44eSChristopher Smith    /** @var Input $INPUT */
890585bf44eSChristopher Smith    global $INPUT;
891585bf44eSChristopher Smith
892585bf44eSChristopher Smith    if ($INPUT->server->str('REMOTE_USER')) {
89326dfc232SAndreas Gohr        echo $lang['loggedinas'] . ' ' . userlink();
89454e95700STom N Harris        return true;
89554e95700STom N Harris    }
89654e95700STom N Harris    return false;
8976b13307fSandi}
8986b13307fSandi
8996b13307fSandi/**
9006b13307fSandi * Print some info about the current page
9016b13307fSandi *
902ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
903ac7a515fSAndreas Gohr * @return bool|string
904*4dc42f7fSGerrit Uitslag *
905*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
9066b13307fSandi */
907d868eb89SAndreas Gohrfunction tpl_pageinfo($ret = false)
908d868eb89SAndreas Gohr{
9096b13307fSandi    global $conf;
9106b13307fSandi    global $lang;
9116b13307fSandi    global $INFO;
912c6e92a3cSDavid Lorentsen    global $ID;
913c6e92a3cSDavid Lorentsen
914c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
915ac7a515fSAndreas Gohr    if (!auth_quickaclcheck($ID)) {
916ac7a515fSAndreas Gohr        return false;
917ac7a515fSAndreas Gohr    }
9186b13307fSandi
9196b13307fSandi    // prepare date and path
9206b13307fSandi    $fn = $INFO['filepath'];
9216b13307fSandi    if (!$conf['fullpath']) {
922613bca54SAndreas Gohr        if ($INFO['rev']) {
923c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'] . '/', '', $fn);
9246b13307fSandi        } else {
925c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'] . '/', '', $fn);
9266b13307fSandi        }
9276b13307fSandi    }
928bee6dc82Sandi    $fn = utf8_decodeFN($fn);
929f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
9306b13307fSandi
931faecdfdfSAndreas Gohr    // print it
932faecdfdfSAndreas Gohr    if ($INFO['exists']) {
933*4dc42f7fSGerrit Uitslag        $out = '<bdi>' . $fn . '</bdi>';
934e260f93bSAnika Henke        $out .= ' · ';
9354b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
936fde860beSGerrit Uitslag        $out .= ' ';
9374b0d3916SAndreas Gohr        $out .= $date;
9386b13307fSandi        if ($INFO['editor']) {
9394b0d3916SAndreas Gohr            $out .= ' ' . $lang['by'] . ' ';
940d317fb5dSAnika Henke            $out .= '<bdi>' . editorinfo($INFO['editor']) . '</bdi>';
9415aa52fafSBen Coburn        } else {
9424b0d3916SAndreas Gohr            $out .= ' (' . $lang['external_edit'] . ')';
9436b13307fSandi        }
9446b13307fSandi        if ($INFO['locked']) {
945e260f93bSAnika Henke            $out .= ' · ';
9464b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
947fde860beSGerrit Uitslag            $out .= ' ';
948d317fb5dSAnika Henke            $out .= '<bdi>' . editorinfo($INFO['locked']) . '</bdi>';
9496b13307fSandi        }
9504b0d3916SAndreas Gohr        if ($ret) {
9514b0d3916SAndreas Gohr            return $out;
9524b0d3916SAndreas Gohr        } else {
9534b0d3916SAndreas Gohr            echo $out;
95454e95700STom N Harris            return true;
9556b13307fSandi        }
9564b0d3916SAndreas Gohr    }
95754e95700STom N Harris    return false;
9586b13307fSandi}
9596b13307fSandi
960820fa24bSandi/**
961a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
96287c434ceSAndreas Gohr *
96387c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
964a6598f23SBen Coburn * the given ID is used.
96587c434ceSAndreas Gohr *
966ac7a515fSAndreas Gohr * @param string $id page id
967ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing
968ac7a515fSAndreas Gohr * @return bool|string
969*4dc42f7fSGerrit Uitslag *
970*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
97187c434ceSAndreas Gohr */
972d868eb89SAndreas Gohrfunction tpl_pagetitle($id = null, $ret = false)
973d868eb89SAndreas Gohr{
974*4dc42f7fSGerrit Uitslag    global $ACT, $conf, $lang;
975fffeeafeSChristopher Smith
97687c434ceSAndreas Gohr    if (is_null($id)) {
97787c434ceSAndreas Gohr        global $ID;
97887c434ceSAndreas Gohr        $id = $ID;
97987c434ceSAndreas Gohr    }
98087c434ceSAndreas Gohr
98187c434ceSAndreas Gohr    $name = $id;
982fe9ec250SChris Smith    if (useHeading('navigation')) {
983fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
984fffeeafeSChristopher Smith        if ($first_heading) $name = $first_heading;
985fffeeafeSChristopher Smith    }
986fffeeafeSChristopher Smith
987fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
988fffeeafeSChristopher Smith    switch ($ACT) {
989fffeeafeSChristopher Smith        // admin functions
990fffeeafeSChristopher Smith        case 'admin':
991fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
992fffeeafeSChristopher Smith            // try to get the plugin name
993*4dc42f7fSGerrit Uitslag            /** @var AdminPlugin $plugin */
994a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()) {
995c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
99624870174SAndreas Gohr                $page_title = $plugin_title ?: $plugin->getPluginName();
997fffeeafeSChristopher Smith            }
998fffeeafeSChristopher Smith            break;
999fffeeafeSChristopher Smith
1000fffeeafeSChristopher Smith        // user functions
1001fffeeafeSChristopher Smith        case 'login':
1002fffeeafeSChristopher Smith        case 'profile':
1003fffeeafeSChristopher Smith        case 'register':
1004fffeeafeSChristopher Smith        case 'resendpwd':
1005fffeeafeSChristopher Smith            $page_title = $lang['btn_' . $ACT];
1006fffeeafeSChristopher Smith            break;
1007fffeeafeSChristopher Smith
1008fffeeafeSChristopher Smith        // wiki functions
1009fffeeafeSChristopher Smith        case 'search':
1010fffeeafeSChristopher Smith        case 'index':
1011fffeeafeSChristopher Smith            $page_title = $lang['btn_' . $ACT];
1012fffeeafeSChristopher Smith            break;
1013fffeeafeSChristopher Smith
1014fffeeafeSChristopher Smith        // page functions
1015fffeeafeSChristopher Smith        case 'edit':
10162f19acc2Sbleistivt        case 'preview':
1017fffeeafeSChristopher Smith            $page_title = "✎ " . $name;
1018fffeeafeSChristopher Smith            break;
1019fffeeafeSChristopher Smith
1020fffeeafeSChristopher Smith        case 'revisions':
1021fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
1022fffeeafeSChristopher Smith            break;
1023fffeeafeSChristopher Smith
1024fffeeafeSChristopher Smith        case 'backlink':
1025fffeeafeSChristopher Smith        case 'recent':
1026fffeeafeSChristopher Smith        case 'subscribe':
1027fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_' . $ACT];
1028fffeeafeSChristopher Smith            break;
1029fffeeafeSChristopher Smith
1030fffeeafeSChristopher Smith        default: // SHOW and anything else not included
1031fffeeafeSChristopher Smith            $page_title = $name;
103287c434ceSAndreas Gohr    }
1033a6598f23SBen Coburn
1034a6598f23SBen Coburn    if ($ret) {
1035fffeeafeSChristopher Smith        return hsc($page_title);
1036a6598f23SBen Coburn    } else {
103726dfc232SAndreas Gohr        echo hsc($page_title);
103854e95700STom N Harris        return true;
103987c434ceSAndreas Gohr    }
1040a6598f23SBen Coburn}
1041340756e4Sandi
104255efc227SAndreas Gohr/**
104355efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
104455efc227SAndreas Gohr *
104555efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
104655efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
104755efc227SAndreas Gohr *
104855efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
104955efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
105055efc227SAndreas Gohr * to the names of the latter one)
105155efc227SAndreas Gohr *
10523df72098SAndreas Gohr * Only allowed in: detail.php
105355efc227SAndreas Gohr *
105421d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
1055ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found
1056e0c26282SGerrit Uitslag * @param null|string $src the image src, uses global $SRC if not given
1057ac7a515fSAndreas Gohr * @return string
1058*4dc42f7fSGerrit Uitslag *
1059*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
106055efc227SAndreas Gohr */
1061d868eb89SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null)
1062d868eb89SAndreas Gohr{
106355efc227SAndreas Gohr    // Init Exif Reader
1064a46a7ce3Sasivery    global $SRC, $imgMeta;
10653df72098SAndreas Gohr
10663df72098SAndreas Gohr    if (is_null($src)) $src = $SRC;
10671eadd9e8SAndreas Gohr    if (is_null($src)) return $alt;
10683df72098SAndreas Gohr
1069*4dc42f7fSGerrit Uitslag    if (!isset($imgMeta)) {
1070*4dc42f7fSGerrit Uitslag        $imgMeta = new JpegMeta($src);
1071*4dc42f7fSGerrit Uitslag    }
1072a46a7ce3Sasivery    if ($imgMeta === false) return $alt;
1073a46a7ce3Sasivery    $info = cleanText($imgMeta->getField($tags));
1074*4dc42f7fSGerrit Uitslag    if (!$info) return $alt;
107555efc227SAndreas Gohr    return $info;
107655efc227SAndreas Gohr}
107755efc227SAndreas Gohr
1078a46a7ce3Sasivery
1079a46a7ce3Sasivery/**
1080a46a7ce3Sasivery * Garbage collects up the open JpegMeta object.
1081a46a7ce3Sasivery */
1082d868eb89SAndreas Gohrfunction tpl_img_close()
1083d868eb89SAndreas Gohr{
1084a46a7ce3Sasivery    global $imgMeta;
1085a46a7ce3Sasivery    $imgMeta = null;
1086a46a7ce3Sasivery}
1087a46a7ce3Sasivery
108855efc227SAndreas Gohr/**
1089*4dc42f7fSGerrit Uitslag * Prints a html description list of the metatags of the current image
1090becfa414SGerrit Uitslag */
1091d868eb89SAndreas Gohrfunction tpl_img_meta()
1092d868eb89SAndreas Gohr{
1093becfa414SGerrit Uitslag    global $lang;
1094becfa414SGerrit Uitslag
1095becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1096becfa414SGerrit Uitslag
1097becfa414SGerrit Uitslag    echo '<dl>';
1098becfa414SGerrit Uitslag    foreach ($tags as $tag) {
1099becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1100fde860beSGerrit Uitslag        if (!$label) $label = $tag['langkey'] . ':';
1101becfa414SGerrit Uitslag
1102fde860beSGerrit Uitslag        echo '<dt>' . $label . '</dt><dd>';
1103becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1104becfa414SGerrit Uitslag            echo dformat($tag['value']);
1105becfa414SGerrit Uitslag        } else {
1106becfa414SGerrit Uitslag            echo hsc($tag['value']);
1107becfa414SGerrit Uitslag        }
1108becfa414SGerrit Uitslag        echo '</dd>';
1109becfa414SGerrit Uitslag    }
1110becfa414SGerrit Uitslag    echo '</dl>';
1111becfa414SGerrit Uitslag}
1112becfa414SGerrit Uitslag
1113becfa414SGerrit Uitslag/**
1114becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1115becfa414SGerrit Uitslag *
1116becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1117becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1118becfa414SGerrit Uitslag *   - string type     type of value
1119becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1120becfa414SGerrit Uitslag */
1121d868eb89SAndreas Gohrfunction tpl_get_img_meta()
1122d868eb89SAndreas Gohr{
1123becfa414SGerrit Uitslag
1124becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1125becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
112679e79377SAndreas Gohr        if (file_exists($config_file)) {
1127becfa414SGerrit Uitslag            include($config_file);
1128becfa414SGerrit Uitslag        }
1129becfa414SGerrit Uitslag    }
113024870174SAndreas Gohr    $tags = [];
1131becfa414SGerrit Uitslag    foreach ($fields as $tag) {
113224870174SAndreas Gohr        $t = [];
1133becfa414SGerrit Uitslag        if (!empty($tag[0])) {
113424870174SAndreas Gohr            $t = [$tag[0]];
1135becfa414SGerrit Uitslag        }
1136056bf31fSDamien Regad        if (isset($tag[3]) && is_array($tag[3])) {
1137becfa414SGerrit Uitslag            $t = array_merge($t, $tag[3]);
1138becfa414SGerrit Uitslag        }
1139becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1140becfa414SGerrit Uitslag        if ($value) {
114124870174SAndreas Gohr            $tags[] = ['langkey' => $tag[1], 'type' => $tag[2], 'value' => $value];
1142becfa414SGerrit Uitslag        }
1143becfa414SGerrit Uitslag    }
1144becfa414SGerrit Uitslag    return $tags;
1145becfa414SGerrit Uitslag}
1146becfa414SGerrit Uitslag
1147becfa414SGerrit Uitslag/**
114855efc227SAndreas Gohr * Prints the image with a link to the full sized version
114955efc227SAndreas Gohr *
115055efc227SAndreas Gohr * Only allowed in: detail.php
1151a02d2933SAndreas Gohr *
1152ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1153*4dc42f7fSGerrit Uitslag * @param int $maxwidth - maximal width of the image
1154*4dc42f7fSGerrit Uitslag * @param int $maxheight - maximal height of the image
1155*4dc42f7fSGerrit Uitslag * @param bool $link - link to the orginal size?
1156*4dc42f7fSGerrit Uitslag * @param array $params - additional image attributes
115742ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
115855efc227SAndreas Gohr */
1159d868eb89SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null)
1160d868eb89SAndreas Gohr{
116155efc227SAndreas Gohr    global $IMG;
1162585bf44eSChristopher Smith    /** @var Input $INPUT */
1163ac7a515fSAndreas Gohr    global $INPUT;
11645c2eed9aSlisps    global $REV;
116565d3a5dbSAndreas Gohr    $w = (int)tpl_img_getTag('File.Width');
116665d3a5dbSAndreas Gohr    $h = (int)tpl_img_getTag('File.Height');
116755efc227SAndreas Gohr
116855efc227SAndreas Gohr    //resize to given max values
116923a34783SAndreas Gohr    $ratio = 1;
117023a34783SAndreas Gohr    if ($w >= $h) {
1171f8925855Sjoe.lapp        if ($maxwidth && $w >= $maxwidth) {
117255efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1173f8925855Sjoe.lapp        } elseif ($maxheight && $h > $maxheight) {
117455efc227SAndreas Gohr            $ratio = $maxheight / $h;
117555efc227SAndreas Gohr        }
117624870174SAndreas Gohr    } elseif ($maxheight && $h >= $maxheight) {
117755efc227SAndreas Gohr        $ratio = $maxheight / $h;
1178f8925855Sjoe.lapp    } elseif ($maxwidth && $w > $maxwidth) {
117955efc227SAndreas Gohr        $ratio = $maxwidth / $w;
118055efc227SAndreas Gohr    }
118155efc227SAndreas Gohr    if ($ratio) {
118255efc227SAndreas Gohr        $w = floor($ratio * $w);
118355efc227SAndreas Gohr        $h = floor($ratio * $h);
118455efc227SAndreas Gohr    }
118555efc227SAndreas Gohr
11866de3759aSAndreas Gohr    //prepare URLs
118724870174SAndreas Gohr    $url = ml($IMG, ['cache' => $INPUT->str('cache'), 'rev' => $REV], true, '&');
118824870174SAndreas Gohr    $src = ml($IMG, ['cache' => $INPUT->str('cache'), 'rev' => $REV, 'w' => $w, 'h' => $h], true, '&');
118955efc227SAndreas Gohr
11902684e50aSAndreas Gohr    //prepare attributes
119155efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1192a02d2933SAndreas Gohr    if (is_null($params)) {
119324870174SAndreas Gohr        $p = [];
1194a02d2933SAndreas Gohr    } else {
1195a02d2933SAndreas Gohr        $p = $params;
1196a02d2933SAndreas Gohr    }
11972684e50aSAndreas Gohr    if ($w) $p['width'] = $w;
11982684e50aSAndreas Gohr    if ($h) $p['height'] = $h;
11992684e50aSAndreas Gohr    $p['class'] = 'img_detail';
12002684e50aSAndreas Gohr    if ($alt) {
12012684e50aSAndreas Gohr        $p['alt'] = $alt;
12022684e50aSAndreas Gohr        $p['title'] = $alt;
12032684e50aSAndreas Gohr    } else {
12042684e50aSAndreas Gohr        $p['alt'] = '';
12052684e50aSAndreas Gohr    }
1206a02d2933SAndreas Gohr    $p['src'] = $src;
120755efc227SAndreas Gohr
120824870174SAndreas Gohr    $data = ['url' => ($link ? $url : null), 'params' => $p];
1209cbb44eabSAndreas Gohr    return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1210a02d2933SAndreas Gohr}
1211a02d2933SAndreas Gohr
1212a02d2933SAndreas Gohr/**
1213a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1214ac7a515fSAndreas Gohr *
1215ac7a515fSAndreas Gohr * @param array $data
1216ac7a515fSAndreas Gohr * @return bool
1217a02d2933SAndreas Gohr */
1218d868eb89SAndreas Gohrfunction _tpl_img_action($data)
1219d868eb89SAndreas Gohr{
122059f3611bSAnika Henke    global $lang;
1221a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1222a02d2933SAndreas Gohr
122326dfc232SAndreas Gohr    if ($data['url']) echo '<a href="' . hsc($data['url']) . '" title="' . $lang['mediaview'] . '">';
122426dfc232SAndreas Gohr    echo '<img ' . $p . '/>';
122526dfc232SAndreas Gohr    if ($data['url']) echo '</a>';
122654e95700STom N Harris    return true;
122755efc227SAndreas Gohr}
122855efc227SAndreas Gohr
12297367b368SAndreas Gohr/**
1230881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
12317367b368SAndreas Gohr *
1232*4dc42f7fSGerrit Uitslag * Should be called somewhere at the very end of the main.php template
1233ac7a515fSAndreas Gohr *
1234ac7a515fSAndreas Gohr * @return bool
12357367b368SAndreas Gohr */
1236d868eb89SAndreas Gohrfunction tpl_indexerWebBug()
1237d868eb89SAndreas Gohr{
12387367b368SAndreas Gohr    global $ID;
12391dad36f5SAndreas Gohr
124024870174SAndreas Gohr    $p = [];
12414af80fe8SMichael Große    $p['src'] = DOKU_BASE . 'lib/exe/taskrunner.php?id=' . rawurlencode($ID) .
1242e68c51baSAndreas Gohr        '&' . time();
1243881f2ee2SAndreas Haerter    $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers...
12447367b368SAndreas Gohr    $p['height'] = 1;
12457367b368SAndreas Gohr    $p['alt'] = '';
12467367b368SAndreas Gohr    $att = buildAttributes($p);
124726dfc232SAndreas Gohr    echo "<img $att />";
124854e95700STom N Harris    return true;
12497367b368SAndreas Gohr}
12507367b368SAndreas Gohr
125178d4e784SEsther Brunner/**
125278d4e784SEsther Brunner * tpl_getConf($id)
125378d4e784SEsther Brunner *
125478d4e784SEsther Brunner * use this function to access template configuration variables
1255ac7a515fSAndreas Gohr *
125617448fb8SChristopher Smith * @param string $id name of the value to access
125717448fb8SChristopher Smith * @param mixed $notset what to return if the setting is not available
125817448fb8SChristopher Smith * @return mixed
125978d4e784SEsther Brunner */
1260d868eb89SAndreas Gohrfunction tpl_getConf($id, $notset = false)
1261d868eb89SAndreas Gohr{
126278d4e784SEsther Brunner    global $conf;
126317566ac6SAdrian Lang    static $tpl_configloaded = false;
126478d4e784SEsther Brunner
126578d4e784SEsther Brunner    $tpl = $conf['template'];
126678d4e784SEsther Brunner
126778d4e784SEsther Brunner    if (!$tpl_configloaded) {
126878d4e784SEsther Brunner        $tconf = tpl_loadConfig();
126978d4e784SEsther Brunner        if ($tconf !== false) {
127078d4e784SEsther Brunner            foreach ($tconf as $key => $value) {
127178d4e784SEsther Brunner                if (isset($conf['tpl'][$tpl][$key])) continue;
127278d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
127378d4e784SEsther Brunner            }
127478d4e784SEsther Brunner            $tpl_configloaded = true;
127578d4e784SEsther Brunner        }
127678d4e784SEsther Brunner    }
127778d4e784SEsther Brunner
127824870174SAndreas Gohr    return $conf['tpl'][$tpl][$id] ?? $notset;
127917448fb8SChristopher Smith}
128017448fb8SChristopher Smith
128178d4e784SEsther Brunner/**
128278d4e784SEsther Brunner * tpl_loadConfig()
1283ac7a515fSAndreas Gohr *
128478d4e784SEsther Brunner * reads all template configuration variables
128578d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1286ac7a515fSAndreas Gohr *
1287*4dc42f7fSGerrit Uitslag * @return false|array
128878d4e784SEsther Brunner */
1289d868eb89SAndreas Gohrfunction tpl_loadConfig()
1290d868eb89SAndreas Gohr{
129178d4e784SEsther Brunner
1292c4766956SAndreas Gohr    $file = tpl_incdir() . '/conf/default.php';
129324870174SAndreas Gohr    $conf = [];
129478d4e784SEsther Brunner
129579e79377SAndreas Gohr    if (!file_exists($file)) return false;
129678d4e784SEsther Brunner
129778d4e784SEsther Brunner    // load default config file
129878d4e784SEsther Brunner    include($file);
129978d4e784SEsther Brunner
130078d4e784SEsther Brunner    return $conf;
130178d4e784SEsther Brunner}
130278d4e784SEsther Brunner
130317566ac6SAdrian Lang// language methods
1304*4dc42f7fSGerrit Uitslag
130517566ac6SAdrian Lang/**
130617566ac6SAdrian Lang * tpl_getLang($id)
130717566ac6SAdrian Lang *
130817566ac6SAdrian Lang * use this function to access template language variables
130942ea7f44SGerrit Uitslag *
131042ea7f44SGerrit Uitslag * @param string $id key of language string
131142ea7f44SGerrit Uitslag * @return string
131217566ac6SAdrian Lang */
1313d868eb89SAndreas Gohrfunction tpl_getLang($id)
1314d868eb89SAndreas Gohr{
131524870174SAndreas Gohr    static $lang = [];
131617566ac6SAdrian Lang
131717566ac6SAdrian Lang    if (count($lang) === 0) {
1318dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1319dd7a6159SGerrit Uitslag
1320c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
132117566ac6SAdrian Lang
132224870174SAndreas Gohr        $lang = [];
132317566ac6SAdrian Lang
132417566ac6SAdrian Lang        // don't include once
132517566ac6SAdrian Lang        @include($path . 'en/lang.php');
1326dd7a6159SGerrit Uitslag        foreach ($config_cascade['lang']['template'] as $config_file) {
132779e79377SAndreas Gohr            if (file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1328dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1329dd7a6159SGerrit Uitslag            }
133017566ac6SAdrian Lang        }
133117566ac6SAdrian Lang
1332dd7a6159SGerrit Uitslag        if ($conf['lang'] != 'en') {
1333dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1334dd7a6159SGerrit Uitslag            foreach ($config_cascade['lang']['template'] as $config_file) {
133579e79377SAndreas Gohr                if (file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1336dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1337dd7a6159SGerrit Uitslag                }
1338dd7a6159SGerrit Uitslag            }
1339dd7a6159SGerrit Uitslag        }
134017566ac6SAdrian Lang    }
134124870174SAndreas Gohr    return $lang[$id] ?? '';
134217566ac6SAdrian Lang}
134317566ac6SAdrian Lang
13443df72098SAndreas Gohr/**
1345c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1346e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1347e8ec13b9SKlap-in *
1348e8ec13b9SKlap-in * @param string $id id of language dependent wiki page
1349e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1350e8ec13b9SKlap-in */
1351d868eb89SAndreas Gohrfunction tpl_locale_xhtml($id)
1352d868eb89SAndreas Gohr{
1353c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1354e8ec13b9SKlap-in}
1355e8ec13b9SKlap-in
1356e8ec13b9SKlap-in/**
1357c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
135842ea7f44SGerrit Uitslag *
135942ea7f44SGerrit Uitslag * @param string $id id of localized text
136042ea7f44SGerrit Uitslag * @return string wiki text
1361e8ec13b9SKlap-in */
1362d868eb89SAndreas Gohrfunction tpl_localeFN($id)
1363d868eb89SAndreas Gohr{
1364e8ec13b9SKlap-in    $path = tpl_incdir() . 'lang/';
1365e8ec13b9SKlap-in    global $conf;
136638fb1fc7SGerrit Uitslag    $file = DOKU_CONF . 'template_lang/' . $conf['template'] . '/' . $conf['lang'] . '/' . $id . '.txt';
136779e79377SAndreas Gohr    if (!file_exists($file)) {
1368e8ec13b9SKlap-in        $file = $path . $conf['lang'] . '/' . $id . '.txt';
136979e79377SAndreas Gohr        if (!file_exists($file)) {
1370e8ec13b9SKlap-in            //fall back to english
1371e8ec13b9SKlap-in            $file = $path . 'en/' . $id . '.txt';
1372e8ec13b9SKlap-in        }
1373e8ec13b9SKlap-in    }
1374e8ec13b9SKlap-in    return $file;
1375e8ec13b9SKlap-in}
1376e8ec13b9SKlap-in
1377e8ec13b9SKlap-in/**
13787abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
13793df72098SAndreas Gohr *
13803df72098SAndreas Gohr * Depending on the user's actions this may be a list of
13813df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
13823df72098SAndreas Gohr * a message of referencing pages
13833df72098SAndreas Gohr *
13843df72098SAndreas Gohr * Only allowed in mediamanager.php
13853df72098SAndreas Gohr *
1386c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1387c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
138842ea7f44SGerrit Uitslag * @param string $sort
13898702de7fSGerrit Uitslag *
13903df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13913df72098SAndreas Gohr */
1392d868eb89SAndreas Gohrfunction tpl_mediaContent($fromajax = false, $sort = 'natural')
1393d868eb89SAndreas Gohr{
13943df72098SAndreas Gohr    global $IMG;
13953df72098SAndreas Gohr    global $AUTH;
13963df72098SAndreas Gohr    global $INUSE;
13973df72098SAndreas Gohr    global $NS;
13983df72098SAndreas Gohr    global $JUMPTO;
1399585bf44eSChristopher Smith    /** @var Input $INPUT */
1400ac7a515fSAndreas Gohr    global $INPUT;
14013df72098SAndreas Gohr
1402ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
140324870174SAndreas Gohr    if (in_array($do, ['save', 'cancel'])) $do = '';
1404c182313eSAndreas Gohr
1405c182313eSAndreas Gohr    if (!$do) {
1406ac7a515fSAndreas Gohr        if ($INPUT->bool('edit')) {
1407c182313eSAndreas Gohr            $do = 'metaform';
1408c182313eSAndreas Gohr        } elseif (is_array($INUSE)) {
1409c182313eSAndreas Gohr            $do = 'filesinuse';
1410c182313eSAndreas Gohr        } else {
1411c182313eSAndreas Gohr            $do = 'filelist';
1412c182313eSAndreas Gohr        }
1413c182313eSAndreas Gohr    }
1414c182313eSAndreas Gohr
1415c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1416a664aabaSAndreas Gohr    if (!$fromajax) echo '<div id="media__content">';
141724870174SAndreas Gohr    $data = ['do' => $do];
1418e1d9dcc8SAndreas Gohr    $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1419c182313eSAndreas Gohr    if ($evt->advise_before()) {
1420c182313eSAndreas Gohr        $do = $data['do'];
142130fd72fbSKate Arzamastseva        if ($do == 'filesinuse') {
1422c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1423c182313eSAndreas Gohr        } elseif ($do == 'filelist') {
142400e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO, false, $sort);
1425c9f56829SAndreas Gohr        } elseif ($do == 'searchlist') {
1426ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1427c182313eSAndreas Gohr        } else {
1428c182313eSAndreas Gohr            msg('Unknown action ' . hsc($do), -1);
1429c182313eSAndreas Gohr        }
1430c182313eSAndreas Gohr    }
1431c182313eSAndreas Gohr    $evt->advise_after();
1432c182313eSAndreas Gohr    unset($evt);
1433a664aabaSAndreas Gohr    if (!$fromajax) echo '</div>';
14343df72098SAndreas Gohr}
14353df72098SAndreas Gohr
14363df72098SAndreas Gohr/**
1437d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1438d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1439d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1440d9162c6cSKate Arzamastseva *
1441d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1442d9162c6cSKate Arzamastseva */
1443d868eb89SAndreas Gohrfunction tpl_mediaFileList()
1444d868eb89SAndreas Gohr{
1445d9162c6cSKate Arzamastseva    global $AUTH;
1446d9162c6cSKate Arzamastseva    global $NS;
1447d9162c6cSKate Arzamastseva    global $JUMPTO;
144895b451bcSAdrian Lang    global $lang;
1449585bf44eSChristopher Smith    /** @var Input $INPUT */
1450ac7a515fSAndreas Gohr    global $INPUT;
1451d9162c6cSKate Arzamastseva
1452ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
145324870174SAndreas Gohr    if (!$opened_tab || !in_array($opened_tab, ['files', 'upload', 'search'])) $opened_tab = 'files';
1454ac7a515fSAndreas Gohr    if ($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1455d9162c6cSKate Arzamastseva
145694add303SAnika Henke    echo '<h2 class="a11y">' . $lang['mediaselect'] . '</h2>' . NL;
145795b451bcSAdrian Lang
1458ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
145923846a98SKate Arzamastseva
146094add303SAnika Henke    echo '<div class="panelHeader">' . NL;
146195b451bcSAdrian Lang    echo '<h3>';
146224870174SAndreas Gohr    $tabTitle = $NS ?: '[' . $lang['mediaroot'] . ']';
1463c98f205eSAdrian Lang    printf($lang['media_' . $opened_tab], '<strong>' . hsc($tabTitle) . '</strong>');
146494add303SAnika Henke    echo '</h3>' . NL;
146595b451bcSAdrian Lang    if ($opened_tab === 'search' || $opened_tab === 'files') {
146695b451bcSAdrian Lang        media_tab_files_options();
146723846a98SKate Arzamastseva    }
146894add303SAnika Henke    echo '</div>' . NL;
1469d9162c6cSKate Arzamastseva
147094add303SAnika Henke    echo '<div class="panelContent">' . NL;
147195b451bcSAdrian Lang    if ($opened_tab == 'files') {
147295b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
147395b451bcSAdrian Lang    } elseif ($opened_tab == 'upload') {
147495b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
147595b451bcSAdrian Lang    } elseif ($opened_tab == 'search') {
147695b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
147795b451bcSAdrian Lang    }
147894add303SAnika Henke    echo '</div>' . NL;
1479d9162c6cSKate Arzamastseva}
1480d9162c6cSKate Arzamastseva
1481d9162c6cSKate Arzamastseva/**
1482d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1483d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1484d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1485d9162c6cSKate Arzamastseva * list of file revisions
1486d9162c6cSKate Arzamastseva *
1487f50a239bSTakamura * @param string $image
1488f50a239bSTakamura * @param boolean $rev
1489*4dc42f7fSGerrit Uitslag *
1490*4dc42f7fSGerrit Uitslag * @author Kate Arzamastseva <pshns@ukr.net>
1491d9162c6cSKate Arzamastseva */
1492d868eb89SAndreas Gohrfunction tpl_mediaFileDetails($image, $rev)
1493d868eb89SAndreas Gohr{
1494e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1495585bf44eSChristopher Smith    /** @var Input $INPUT */
1496585bf44eSChristopher Smith    global $INPUT;
1497d9162c6cSKate Arzamastseva
149864159a61SAndreas Gohr    $removed = (
149964159a61SAndreas Gohr        !file_exists(mediaFN($image)) &&
150064159a61SAndreas Gohr        file_exists(mediaMetaFN($image, '.changes')) &&
150164159a61SAndreas Gohr        $conf['mediarevisions']
150264159a61SAndreas Gohr    );
1503ac7a515fSAndreas Gohr    if (!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
15046dd095f5SKate Arzamastseva    if ($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1505e8a2a143SMichael Hamann    $ns = getNS($image);
1506ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
15071eeeced2SKate Arzamastseva
1508ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1509e5d185e1SKate Arzamastseva
151024870174SAndreas Gohr    $tab_array = ['view'];
151124870174SAndreas Gohr    [, $mime] = mimetype($image);
1512e5d185e1SKate Arzamastseva    if ($mime == 'image/jpeg') {
1513e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1514e5d185e1SKate Arzamastseva    }
1515e5d185e1SKate Arzamastseva    if ($conf['mediarevisions']) {
1516e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1517e5d185e1SKate Arzamastseva    }
1518e5d185e1SKate Arzamastseva
1519e5d185e1SKate Arzamastseva    if (!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1520ac7a515fSAndreas Gohr    if ($INPUT->bool('edit')) $opened_tab = 'edit';
152123846a98SKate Arzamastseva    if ($do == 'restore') $opened_tab = 'view';
1522d9162c6cSKate Arzamastseva
1523ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
152423846a98SKate Arzamastseva
152559f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
152624870174SAndreas Gohr    [$ext] = mimetype($image, false);
152795b451bcSAdrian Lang    $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
152895b451bcSAdrian Lang    $class = 'select mediafile mf_' . $class;
152924870174SAndreas Gohr
1530750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
153190fb952cSAndreas Gohr    $tabTitle = sprintf(
153290fb952cSAndreas Gohr        '<strong><a href="%s" class="%s" title="%s">%s</a></strong>',
153390fb952cSAndreas Gohr        ml($image, $attributes),
153490fb952cSAndreas Gohr        $class,
153590fb952cSAndreas Gohr        $lang['mediaview'],
153690fb952cSAndreas Gohr        $image
153790fb952cSAndreas Gohr    );
153808317413SAdrian Lang    if ($opened_tab === 'view' && $rev) {
153908317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
154008317413SAdrian Lang    } else {
1541026d14a9SAnika Henke        printf($lang['media_' . $opened_tab], $tabTitle);
154208317413SAdrian Lang    }
1543b8a84c03SAndreas Gohr
154494add303SAnika Henke    echo '</h3></div>' . NL;
154595b451bcSAdrian Lang
154694add303SAnika Henke    echo '<div class="panelContent">' . NL;
154795b451bcSAdrian Lang
154823846a98SKate Arzamastseva    if ($opened_tab == 'view') {
1549e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
155092cac9a9SKate Arzamastseva    } elseif ($opened_tab == 'edit' && !$removed) {
1551e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
1552e5d185e1SKate Arzamastseva    } elseif ($opened_tab == 'history' && $conf['mediarevisions']) {
1553e8a2a143SMichael Hamann        media_tab_history($image, $ns);
155423846a98SKate Arzamastseva    }
155595b451bcSAdrian Lang
155694add303SAnika Henke    echo '</div>' . NL;
1557d9162c6cSKate Arzamastseva}
1558d9162c6cSKate Arzamastseva
1559d9162c6cSKate Arzamastseva/**
15607abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
15613df72098SAndreas Gohr *
15623df72098SAndreas Gohr * Only allowed in mediamanager.php
15633df72098SAndreas Gohr *
15643df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
15653df72098SAndreas Gohr */
1566d868eb89SAndreas Gohrfunction tpl_mediaTree()
1567d868eb89SAndreas Gohr{
15683df72098SAndreas Gohr    global $NS;
1569a664aabaSAndreas Gohr    echo '<div id="media__tree">';
15703df72098SAndreas Gohr    media_nstree($NS);
1571a664aabaSAndreas Gohr    echo '</div>';
15723df72098SAndreas Gohr}
15733df72098SAndreas Gohr
1574a00de5b5SAndreas Gohr/**
1575a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1576a00de5b5SAndreas Gohr *
1577a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1578a00de5b5SAndreas Gohr *
157942ea7f44SGerrit Uitslag * @param string $empty empty option label
158042ea7f44SGerrit Uitslag * @param string $button submit button label
1581*4dc42f7fSGerrit Uitslag *
1582*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
1583affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1584a00de5b5SAndreas Gohr */
1585d868eb89SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;')
1586d868eb89SAndreas Gohr{
1587affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
158824870174SAndreas Gohr    $menu = new MobileMenu();
15891e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1590a00de5b5SAndreas Gohr}
1591a00de5b5SAndreas Gohr
1592066fee30SAndreas Gohr/**
1593066fee30SAndreas Gohr * Print a informational line about the used license
1594066fee30SAndreas Gohr *
1595ac7a515fSAndreas Gohr * @param string $img print image? (|button|badge)
1596ac7a515fSAndreas Gohr * @param bool $imgonly skip the textual description?
1597ac7a515fSAndreas Gohr * @param bool $return when true don't print, but return HTML
1598ac7a515fSAndreas Gohr * @param bool $wrap wrap in div with class="license"?
1599ac7a515fSAndreas Gohr * @return string
1600*4dc42f7fSGerrit Uitslag *
1601*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
1602066fee30SAndreas Gohr */
1603d868eb89SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true)
1604d868eb89SAndreas Gohr{
1605066fee30SAndreas Gohr    global $license;
1606066fee30SAndreas Gohr    global $conf;
1607066fee30SAndreas Gohr    global $lang;
1608066fee30SAndreas Gohr    if (!$conf['license']) return '';
1609066fee30SAndreas Gohr    if (!is_array($license[$conf['license']])) return '';
1610066fee30SAndreas Gohr    $lic = $license[$conf['license']];
161153e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="' . $conf['target']['extern'] . '"' : '';
1612066fee30SAndreas Gohr
161380083a41SAndreas Gohr    $out = '';
161480083a41SAndreas Gohr    if ($wrap) $out .= '<div class="license">';
1615066fee30SAndreas Gohr    if ($img) {
1616066fee30SAndreas Gohr        $src = license_img($img);
1617066fee30SAndreas Gohr        if ($src) {
161853e15c8bSAnika Henke            $out .= '<a href="' . $lic['url'] . '" rel="license"' . $target;
161953e15c8bSAnika Henke            $out .= '><img src="' . DOKU_BASE . $src . '" alt="' . $lic['name'] . '" /></a>';
162053e15c8bSAnika Henke            if (!$imgonly) $out .= ' ';
1621066fee30SAndreas Gohr        }
1622066fee30SAndreas Gohr    }
16234cefd216SMichael Klier    if (!$imgonly) {
162453e15c8bSAnika Henke        $out .= $lang['license'] . ' ';
1625d317fb5dSAnika Henke        $out .= '<bdi><a href="' . $lic['url'] . '" rel="license" class="urlextern"' . $target;
1626d317fb5dSAnika Henke        $out .= '>' . $lic['name'] . '</a></bdi>';
16274cefd216SMichael Klier    }
162880083a41SAndreas Gohr    if ($wrap) $out .= '</div>';
1629066fee30SAndreas Gohr
1630066fee30SAndreas Gohr    if ($return) return $out;
1631066fee30SAndreas Gohr    echo $out;
1632ac7a515fSAndreas Gohr    return '';
1633066fee30SAndreas Gohr}
1634066fee30SAndreas Gohr
1635a81910eeSAndreas Gohr/**
1636835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1637a81910eeSAndreas Gohr *
1638a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1639a81910eeSAndreas Gohr * template
1640e0c26282SGerrit Uitslag *
16417a112df5SAndreas Gohr * @param string $pageid The page name you want to include
16427a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
16437a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
16447c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1645e0c26282SGerrit Uitslag * @return bool|null|string
1646a81910eeSAndreas Gohr */
1647d868eb89SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true)
1648d868eb89SAndreas Gohr{
16497a112df5SAndreas Gohr    if ($propagate) {
16507c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
16517c3e4a67SAndreas Gohr    } elseif ($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
16527a112df5SAndreas Gohr        return false;
16537a112df5SAndreas Gohr    }
1654c786a1b6SAnika Henke    if (!$pageid) return false;
1655835dfcaeSAnika Henke
1656c786a1b6SAnika Henke    global $TOC;
16579a2e250aSAndreas Gohr    $oldtoc = $TOC;
1658a81910eeSAndreas Gohr    $html = p_wiki_xhtml($pageid, '', false);
16599a2e250aSAndreas Gohr    $TOC = $oldtoc;
1660a81910eeSAndreas Gohr
1661a2e03c82SAndreas Gohr    if ($print) echo $html;
1662e66d3e6dSAndreas Gohr    return $html;
1663e66d3e6dSAndreas Gohr}
1664e66d3e6dSAndreas Gohr
1665e66d3e6dSAndreas Gohr/**
16665b75cd1fSAdrian Lang * Display the subscribe form
16675b75cd1fSAdrian Lang *
16685b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
1669848cb786SSatoshi Sahara * @deprecated 2020-07-23
16705b75cd1fSAdrian Lang */
1671d868eb89SAndreas Gohrfunction tpl_subscribe()
1672d868eb89SAndreas Gohr{
167324870174SAndreas Gohr    dbg_deprecated(Subscribe::class . '::show()');
167473022918SAndreas Gohr    (new Subscribe())->show();
16755b75cd1fSAdrian Lang}
16765b75cd1fSAdrian Lang
1677d059ba9bSAndreas Gohr/**
1678d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1679d059ba9bSAndreas Gohr *
1680d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1681d059ba9bSAndreas Gohr *
1682d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1683d059ba9bSAndreas Gohr */
1684d868eb89SAndreas Gohrfunction tpl_flush()
1685d868eb89SAndreas Gohr{
1686c2009796SZemoj    if (ob_get_level() > 0) ob_flush();
1687d059ba9bSAndreas Gohr    flush();
1688d059ba9bSAndreas Gohr}
1689d059ba9bSAndreas Gohr
1690afca7e7eSAnika Henke/**
1691378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1692afca7e7eSAnika Henke *
1693378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1694378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1695378325f9SAndreas Gohr *
169642ea7f44SGerrit Uitslag * @param string[] $search locations to look at
1697378325f9SAndreas Gohr * @param bool $abs if to use absolute URL
1698ac7a515fSAndreas Gohr * @param array    &$imginfo filled with getimagesize()
16996dc405e1SAndreas Gohr * @param bool $fallback use fallback image if target isn't found or return 'false' if potential
17006dc405e1SAndreas Gohr *                                false result is required
1701ac7a515fSAndreas Gohr * @return string
170242ea7f44SGerrit Uitslag *
1703378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1704afca7e7eSAnika Henke */
1705d868eb89SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = true)
1706d868eb89SAndreas Gohr{
1707ac7a515fSAndreas Gohr    $img = '';
1708ac7a515fSAndreas Gohr    $file = '';
1709ac7a515fSAndreas Gohr    $ismedia = false;
1710378325f9SAndreas Gohr    // loop through candidates until a match was found:
1711378325f9SAndreas Gohr    foreach ($search as $img) {
1712378325f9SAndreas Gohr        if (substr($img, 0, 1) == ':') {
1713378325f9SAndreas Gohr            $file = mediaFN($img);
1714378325f9SAndreas Gohr            $ismedia = true;
1715378325f9SAndreas Gohr        } else {
1716c4766956SAndreas Gohr            $file = tpl_incdir() . $img;
1717378325f9SAndreas Gohr            $ismedia = false;
17181f13e33dSAnika Henke        }
17190f747863Slupo49
1720378325f9SAndreas Gohr        if (file_exists($file)) break;
1721872a6d29SAnika Henke    }
1722378325f9SAndreas Gohr
172308a13262SSimon DELAGE    // manage non existing target
172408a13262SSimon DELAGE    if (!file_exists($file)) {
172508a13262SSimon DELAGE        // give result for fallback image
172624870174SAndreas Gohr        if ($fallback) {
1727c238d757SSimon DELAGE            $file = DOKU_INC . 'lib/images/blank.gif';
172808a13262SSimon DELAGE            // stop process if false result is required (if $fallback is false)
172908a13262SSimon DELAGE        } else {
173008a13262SSimon DELAGE            return false;
173108a13262SSimon DELAGE        }
173208a13262SSimon DELAGE    }
1733ca5b6a64SSimon DELAGE
1734378325f9SAndreas Gohr    // fetch image data if requested
1735378325f9SAndreas Gohr    if (!is_null($imginfo)) {
1736378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1737378325f9SAndreas Gohr    }
1738378325f9SAndreas Gohr
1739378325f9SAndreas Gohr    // build URL
1740378325f9SAndreas Gohr    if ($ismedia) {
1741378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1742378325f9SAndreas Gohr    } else {
1743c4766956SAndreas Gohr        $url = tpl_basedir() . $img;
1744378325f9SAndreas Gohr        if ($abs) $url = DOKU_URL . substr($url, strlen(DOKU_REL));
1745378325f9SAndreas Gohr    }
1746378325f9SAndreas Gohr
1747378325f9SAndreas Gohr    return $url;
1748a7e5f74cSlupo49}
17491f13e33dSAnika Henke
1750872a6d29SAnika Henke/**
1751e5d4768dSAndreas Gohr * PHP include a file
1752e5d4768dSAndreas Gohr *
1753e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1754e5d4768dSAndreas Gohr * file in the template's root directory.
1755e5d4768dSAndreas Gohr *
1756e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1757e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1758e5d4768dSAndreas Gohr * default.
1759e5d4768dSAndreas Gohr *
1760e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1761e5d4768dSAndreas Gohr * to this function!
1762e5d4768dSAndreas Gohr *
176342ea7f44SGerrit Uitslag * @param string $file
1764*4dc42f7fSGerrit Uitslag *
1765*4dc42f7fSGerrit Uitslag * @author Andreas Gohr <andi@splitbrain.org>
1766*4dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
1767e5d4768dSAndreas Gohr */
1768d868eb89SAndreas Gohrfunction tpl_includeFile($file)
1769d868eb89SAndreas Gohr{
1770e5d4768dSAndreas Gohr    global $config_cascade;
177124870174SAndreas Gohr    foreach (['protected', 'local', 'default'] as $config_group) {
1772e5d4768dSAndreas Gohr        if (empty($config_cascade['main'][$config_group])) continue;
1773e5d4768dSAndreas Gohr        foreach ($config_cascade['main'][$config_group] as $conf_file) {
1774e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1775e5d4768dSAndreas Gohr            if (file_exists("$dir/$file")) {
1776f3a1225fSAnika Henke                include("$dir/$file");
1777e5d4768dSAndreas Gohr                return;
1778e5d4768dSAndreas Gohr            }
1779e5d4768dSAndreas Gohr        }
1780e5d4768dSAndreas Gohr    }
1781e5d4768dSAndreas Gohr
1782e5d4768dSAndreas Gohr    // still here? try the template dir
1783e5d4768dSAndreas Gohr    $file = tpl_incdir() . $file;
1784e5d4768dSAndreas Gohr    if (file_exists($file)) {
1785f3a1225fSAnika Henke        include($file);
1786e5d4768dSAndreas Gohr    }
1787e5d4768dSAndreas Gohr}
1788e5d4768dSAndreas Gohr
1789e5d4768dSAndreas Gohr/**
1790872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1791872a6d29SAnika Henke *
1792ac7a515fSAndreas Gohr * @param array $types - list of icon types to display (favicon|mobile|generic)
1793ac7a515fSAndreas Gohr * @return string
1794*4dc42f7fSGerrit Uitslag *
1795*4dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
1796872a6d29SAnika Henke */
1797d868eb89SAndreas Gohrfunction tpl_favicon($types = ['favicon'])
1798d868eb89SAndreas Gohr{
1799872a6d29SAnika Henke
1800872a6d29SAnika Henke    $return = '';
1801872a6d29SAnika Henke
1802872a6d29SAnika Henke    foreach ($types as $type) {
1803872a6d29SAnika Henke        switch ($type) {
1804872a6d29SAnika Henke            case 'favicon':
180524870174SAndreas Gohr                $look = [':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'];
1806378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="' . tpl_getMediaFile($look) . '" />' . NL;
1807872a6d29SAnika Henke                break;
1808872a6d29SAnika Henke            case 'mobile':
180924870174SAndreas Gohr                $look = [':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png'];
1810378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="' . tpl_getMediaFile($look) . '" />' . NL;
1811872a6d29SAnika Henke                break;
1812872a6d29SAnika Henke            case 'generic':
1813872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
181424870174SAndreas Gohr                $look = [':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'];
1815378325f9SAndreas Gohr                $return .= '<link rel="icon" href="' . tpl_getMediaFile($look) . '" type="image/svg+xml" />' . NL;
1816872a6d29SAnika Henke                break;
1817872a6d29SAnika Henke        }
1818872a6d29SAnika Henke    }
1819872a6d29SAnika Henke
1820872a6d29SAnika Henke    return $return;
1821afca7e7eSAnika Henke}
1822afca7e7eSAnika Henke
1823d9162c6cSKate Arzamastseva/**
1824d9162c6cSKate Arzamastseva * Prints full-screen media manager
1825d9162c6cSKate Arzamastseva *
1826d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1827d9162c6cSKate Arzamastseva */
1828d868eb89SAndreas Gohrfunction tpl_media()
1829d868eb89SAndreas Gohr{
1830ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
183188a71175SKate Arzamastseva    $fullscreen = true;
183295b451bcSAdrian Lang    require_once DOKU_INC . 'lib/exe/mediamanager.php';
1833d9162c6cSKate Arzamastseva
1834ac7a515fSAndreas Gohr    $rev = '';
1835ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
183698f03b57SKate Arzamastseva    if (isset($IMG)) $image = $IMG;
183798f03b57SKate Arzamastseva    if (isset($JUMPTO)) $image = $JUMPTO;
18389c1bd4bcSKate Arzamastseva    if (isset($REV) && !$JUMPTO) $rev = $REV;
183998f03b57SKate Arzamastseva
184094add303SAnika Henke    echo '<div id="mediamanager__page">' . NL;
1841bc314c58SAnika Henke    echo '<h1>' . $lang['btn_media'] . '</h1>' . NL;
1842d9162c6cSKate Arzamastseva    html_msgarea();
184394add303SAnika Henke
184494add303SAnika Henke    echo '<div class="panel namespaces">' . NL;
184594add303SAnika Henke    echo '<h2>' . $lang['namespaces'] . '</h2>' . NL;
184695b451bcSAdrian Lang    echo '<div class="panelHeader">';
1847ba340a70SAnika Henke    echo $lang['media_namespaces'];
184894add303SAnika Henke    echo '</div>' . NL;
184995b451bcSAdrian Lang
185094add303SAnika Henke    echo '<div class="panelContent" id="media__tree">' . NL;
185195b451bcSAdrian Lang    media_nstree($NS);
185294add303SAnika Henke    echo '</div>' . NL;
185394add303SAnika Henke    echo '</div>' . NL;
1854fa8e5c77SKate Arzamastseva
185594add303SAnika Henke    echo '<div class="panel filelist">' . NL;
1856035e07f1SKate Arzamastseva    tpl_mediaFileList();
185794add303SAnika Henke    echo '</div>' . NL;
1858fa8e5c77SKate Arzamastseva
185994add303SAnika Henke    echo '<div class="panel file">' . NL;
186094add303SAnika Henke    echo '<h2 class="a11y">' . $lang['media_file'] . '</h2>' . NL;
1861035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
186294add303SAnika Henke    echo '</div>' . NL;
1863ba340a70SAnika Henke
186494add303SAnika Henke    echo '</div>' . NL;
1865d9162c6cSKate Arzamastseva}
1866afca7e7eSAnika Henke
1867c71db656SAnika Henke/**
1868c71db656SAnika Henke * Return useful layout classes
1869c71db656SAnika Henke *
187042ea7f44SGerrit Uitslag * @return string
1871*4dc42f7fSGerrit Uitslag *
1872*4dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
1873c71db656SAnika Henke */
1874d868eb89SAndreas Gohrfunction tpl_classes()
1875d868eb89SAndreas Gohr{
1876c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1877585bf44eSChristopher Smith    /** @var Input $INPUT */
1878585bf44eSChristopher Smith    global $INPUT;
1879585bf44eSChristopher Smith
188024870174SAndreas Gohr    $classes = [
1881c71db656SAnika Henke        'dokuwiki',
1882c71db656SAnika Henke        'mode_' . $ACT,
1883c71db656SAnika Henke        'tpl_' . $conf['template'],
1884585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
188590eb1b7bSEduardo Mozart de Oliveira        (isset($INFO['exists']) && $INFO['exists']) ? '' : 'notFound',
188624870174SAndreas Gohr        ($ID == $conf['start']) ? 'home' : ''
188724870174SAndreas Gohr    ];
188824870174SAndreas Gohr    return implode(' ', $classes);
1889c71db656SAnika Henke}
1890c71db656SAnika Henke
189184dd2b1aSGerrit Uitslag/**
189284dd2b1aSGerrit Uitslag * Create event for tools menues
189384dd2b1aSGerrit Uitslag *
189484dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
189584dd2b1aSGerrit Uitslag * @param array $items
189684dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1897*4dc42f7fSGerrit Uitslag *
1898*4dc42f7fSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
1899affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
190084dd2b1aSGerrit Uitslag */
1901d868eb89SAndreas Gohrfunction tpl_toolsevent($toolsname, $items, $view = 'main')
1902d868eb89SAndreas Gohr{
1903affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
190424870174SAndreas Gohr    $data = ['view' => $view, 'items' => $items];
190584dd2b1aSGerrit Uitslag
190684dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
1907e1d9dcc8SAndreas Gohr    $evt = new Event($hook, $data);
190884dd2b1aSGerrit Uitslag    if ($evt->advise_before()) {
190924870174SAndreas Gohr        foreach ($evt->data['items'] as $html) echo $html;
191084dd2b1aSGerrit Uitslag    }
191184dd2b1aSGerrit Uitslag    $evt->advise_after();
191284dd2b1aSGerrit Uitslag}
1913