xref: /dokuwiki/inc/template.php (revision 64159a61e94d0ce680071c8890e144982c3a8cbe)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki template functions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
96b13307fSandi/**
10ac7a515fSAndreas Gohr * Access a template file
11ac7a515fSAndreas Gohr *
12ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
13ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
145a892029SAndreas Gohr *
155a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
16ac7a515fSAndreas Gohr * @param string $file
17ac7a515fSAndreas Gohr * @return string
185a892029SAndreas Gohr */
19ac7a515fSAndreas Gohrfunction template($file) {
205a892029SAndreas Gohr    global $conf;
215a892029SAndreas Gohr
22ac7a515fSAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
23ac7a515fSAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
245a892029SAndreas Gohr
25ac7a515fSAndreas Gohr    return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
265a892029SAndreas Gohr}
275a892029SAndreas Gohr
28c4766956SAndreas Gohr/**
29c4766956SAndreas Gohr * Convenience function to access template dir from local FS
30c4766956SAndreas Gohr *
31c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
32c4766956SAndreas Gohr *
33c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
34afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
35ac7a515fSAndreas Gohr * @return string
36c4766956SAndreas Gohr */
37afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') {
3875b14482SAndreas Gohr    global $conf;
39afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
40afb2c082SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$tpl.'/';
41c4766956SAndreas Gohr}
42c4766956SAndreas Gohr
43c4766956SAndreas Gohr/**
44c4766956SAndreas Gohr * Convenience function to access template dir from web
45c4766956SAndreas Gohr *
46c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
47c4766956SAndreas Gohr *
48c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
49afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
50ac7a515fSAndreas Gohr * @return string
51c4766956SAndreas Gohr */
5299dca513SAndreas Gohrfunction tpl_basedir($tpl='') {
5375b14482SAndreas Gohr    global $conf;
54afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
55dcd4911eSMichael Hamann    return DOKU_BASE.'lib/tpl/'.$tpl.'/';
56c4766956SAndreas Gohr}
57c4766956SAndreas Gohr
585a892029SAndreas Gohr/**
596b13307fSandi * Print the content
606b13307fSandi *
616b13307fSandi * This function is used for printing all the usual content
626b13307fSandi * (defined by the global $ACT var) by calling the appropriate
636b13307fSandi * outputfunction(s) from html.php
646b13307fSandi *
65ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
66ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
676b13307fSandi *
686b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6942ea7f44SGerrit Uitslag *
70ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
71ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
72ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
73ac7a515fSAndreas Gohr * @return bool true if any output
746b13307fSandi */
75b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) {
767ea0913cSchris    global $ACT;
77b8595a66SAndreas Gohr    global $INFO;
78b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
797ea0913cSchris
807ea0913cSchris    ob_start();
81746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
827ea0913cSchris    $html_output = ob_get_clean();
83746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
8454e95700STom N Harris
8554e95700STom N Harris    return !empty($html_output);
867ea0913cSchris}
877ea0913cSchris
88ac7a515fSAndreas Gohr/**
89ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
90ac7a515fSAndreas Gohr *
91ac7a515fSAndreas Gohr * @return bool
92ac7a515fSAndreas Gohr */
937ea0913cSchrisfunction tpl_content_core() {
94952acff9SAndreas Gohr    $router = \dokuwiki\ActionRouter::getInstance();
95952acff9SAndreas Gohr    try {
96952acff9SAndreas Gohr        $router->getAction()->tplContent();
97952acff9SAndreas Gohr    } catch(\dokuwiki\Action\Exception\FatalException $e) {
98952acff9SAndreas Gohr        // there was no content for the action
99952acff9SAndreas Gohr        msg(hsc($e->getMessage()), -1);
10054e95700STom N Harris        return false;
1016b13307fSandi    }
10254e95700STom N Harris    return true;
1036b13307fSandi}
1046b13307fSandi
105c19fe9c0Sandi/**
106b8595a66SAndreas Gohr * Places the TOC where the function is called
107b8595a66SAndreas Gohr *
108b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
109b8595a66SAndreas Gohr * a false argument
110b8595a66SAndreas Gohr *
111b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11242ea7f44SGerrit Uitslag *
113ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
114ac7a515fSAndreas Gohr * @return string
115b8595a66SAndreas Gohr */
116b8595a66SAndreas Gohrfunction tpl_toc($return = false) {
117b8595a66SAndreas Gohr    global $TOC;
118b8595a66SAndreas Gohr    global $ACT;
119b8595a66SAndreas Gohr    global $ID;
120b8595a66SAndreas Gohr    global $REV;
121b8595a66SAndreas Gohr    global $INFO;
122851f2e89SAnika Henke    global $conf;
123ac7a515fSAndreas Gohr    global $INPUT;
124b8595a66SAndreas Gohr    $toc = array();
125b8595a66SAndreas Gohr
126b8595a66SAndreas Gohr    if(is_array($TOC)) {
127b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
128b8595a66SAndreas Gohr        $toc = $TOC;
1293c86d7c9SAndreas Gohr    } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
130b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
131e0c26282SGerrit Uitslag        $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
132b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])) {
133b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
134b8595a66SAndreas Gohr        } else {
1352bb0d541Schris            $tocok = true;
136b8595a66SAndreas Gohr        }
137f87b5dbbSChristopher Smith        $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
138851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
139b8595a66SAndreas Gohr            $toc = array();
140b8595a66SAndreas Gohr        }
141b8595a66SAndreas Gohr    } elseif($ACT == 'admin') {
142a61966c5SChristopher Smith        // try to load admin plugin TOC
143ac7a515fSAndreas Gohr        /** @var $plugin DokuWiki_Admin_Plugin */
144a61966c5SChristopher Smith        if ($plugin = plugin_getRequestAdminPlugin()) {
145b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
146b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
147b8595a66SAndreas Gohr        }
148b8595a66SAndreas Gohr    }
149b8595a66SAndreas Gohr
1500b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
151b8595a66SAndreas Gohr    $html = html_TOC($toc);
152b8595a66SAndreas Gohr    if($return) return $html;
153b8595a66SAndreas Gohr    echo $html;
154ac7a515fSAndreas Gohr    return '';
155b8595a66SAndreas Gohr}
156b8595a66SAndreas Gohr
157b8595a66SAndreas Gohr/**
158c19fe9c0Sandi * Handle the admin page contents
159c19fe9c0Sandi *
160c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
16142ea7f44SGerrit Uitslag *
16242ea7f44SGerrit Uitslag * @return bool
163c19fe9c0Sandi */
164c19fe9c0Sandifunction tpl_admin() {
165f8cc712eSAndreas Gohr    global $INFO;
166b8595a66SAndreas Gohr    global $TOC;
167ac7a515fSAndreas Gohr    global $INPUT;
16811e2ce22Schris
169b8595a66SAndreas Gohr    $plugin = null;
170ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
171ac7a515fSAndreas Gohr    if(!empty($class)) {
17211e2ce22Schris        $pluginlist = plugin_list('admin');
17311e2ce22Schris
174ac7a515fSAndreas Gohr        if(in_array($class, $pluginlist)) {
17511e2ce22Schris            // attempt to load the plugin
176ac7a515fSAndreas Gohr            /** @var $plugin DokuWiki_Admin_Plugin */
177a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
17811e2ce22Schris        }
17911e2ce22Schris    }
18011e2ce22Schris
181b8595a66SAndreas Gohr    if($plugin !== null) {
182b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
183b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
184f8cc712eSAndreas Gohr        $plugin->html();
185f8cc712eSAndreas Gohr    } else {
1860470c28fSAndreas Gohr        $admin = new dokuwiki\Ui\Admin();
1870470c28fSAndreas Gohr        $admin->show();
188f8cc712eSAndreas Gohr    }
18954e95700STom N Harris    return true;
190c19fe9c0Sandi}
1916b13307fSandi
1926b13307fSandi/**
1936b13307fSandi * Print the correct HTML meta headers
1946b13307fSandi *
1956b13307fSandi * This has to go into the head section of your template.
1966b13307fSandi *
1976b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
19842ea7f44SGerrit Uitslag *
199ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
200ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
201ac7a515fSAndreas Gohr * @return bool
2026b13307fSandi */
203f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) {
2046b13307fSandi    global $ID;
205d98d4540SBen Coburn    global $REV;
2066b13307fSandi    global $INFO;
20772e0dc37SAndreas Gohr    global $JSINFO;
2086b13307fSandi    global $ACT;
2094bb1b5aeSAndreas Gohr    global $QUERY;
2106b13307fSandi    global $lang;
211dc57ef04Sandi    global $conf;
2129c438d6cSMichael Hamann    global $updateVersion;
213585bf44eSChristopher Smith    /** @var Input $INPUT */
214585bf44eSChristopher Smith    global $INPUT;
2156b13307fSandi
2167bff22c0SAndreas Gohr    // prepare the head array
2177bff22c0SAndreas Gohr    $head = array();
2187bff22c0SAndreas Gohr
219202ac28bSMichael Klier    // prepare seed for js and css
220cd997f93SAndreas Gohr    $tseed   = $updateVersion;
221202ac28bSMichael Klier    $depends = getConfigFiles('main');
22284e76a7eSAndreas Gohr    $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
223cd997f93SAndreas Gohr    foreach($depends as $f) $tseed .= @filemtime($f);
224cd997f93SAndreas Gohr    $tseed   = md5($tseed);
2257bff22c0SAndreas Gohr
2266b13307fSandi    // the usual stuff
2273f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
22863cf4192Ssarehag    if(actionOK('search')) {
229ac7a515fSAndreas Gohr        $head['link'][] = array(
230ac7a515fSAndreas Gohr            'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
231ac7a515fSAndreas Gohr            'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
232ac7a515fSAndreas Gohr        );
23363cf4192Ssarehag    }
23463cf4192Ssarehag
235f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
2367aedde2eSGina Haeussge    if(actionOK('index')) {
237ac7a515fSAndreas Gohr        $head['link'][] = array(
238ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
239ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
240ac7a515fSAndreas Gohr        );
2417aedde2eSGina Haeussge    }
242f96fa415SAndreas Gohr
2435e0255e3SMichael Große    if (actionOK('manifest')) {
2445e0255e3SMichael Große        $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
2455e0255e3SMichael Große    }
2465e0255e3SMichael Große
24740ca8540SMichael Große    $styleUtil = new \dokuwiki\StyleUtils();
24840ca8540SMichael Große    $styleIni = $styleUtil->cssStyleini($conf['template']);
24940ca8540SMichael Große    $replacements = $styleIni['replacements'];
25040ca8540SMichael Große    if (!empty($replacements['__theme_color__'])) {
25140ca8540SMichael Große        $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']);
25240ca8540SMichael Große    }
25340ca8540SMichael Große
254f96fa415SAndreas Gohr    if($alt) {
25554be1338SGerrit Uitslag        if(actionOK('rss')) {
256ac7a515fSAndreas Gohr            $head['link'][] = array(
257ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
258a1288caeSGerrit Uitslag                'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
259ac7a515fSAndreas Gohr            );
260ac7a515fSAndreas Gohr            $head['link'][] = array(
261ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
262a1288caeSGerrit Uitslag                'title'=> $lang['currentns'],
263ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
264ac7a515fSAndreas Gohr            );
26554be1338SGerrit Uitslag        }
266c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
267ac7a515fSAndreas Gohr            $head['link'][] = array(
268ac7a515fSAndreas Gohr                'rel'  => 'edit',
269715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
270ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
271ac7a515fSAndreas Gohr            );
272c35f3875SAndreas Gohr        }
273c35f3875SAndreas Gohr
27454be1338SGerrit Uitslag        if(actionOK('rss') && $ACT == 'search') {
275ac7a515fSAndreas Gohr            $head['link'][] = array(
276ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
277a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
278ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
279ac7a515fSAndreas Gohr            );
2804bb1b5aeSAndreas Gohr        }
281bae36d94SAndreas Gohr
282bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
283ac7a515fSAndreas Gohr            $head['link'][] = array(
284a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
285ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
286ac7a515fSAndreas Gohr            );
287bae36d94SAndreas Gohr        }
288bae36d94SAndreas Gohr
289bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
290ac7a515fSAndreas Gohr            $head['link'][] = array(
291a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
292ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
293ac7a515fSAndreas Gohr            );
294f96fa415SAndreas Gohr        }
295bae36d94SAndreas Gohr    }
2966b13307fSandi
2976b13307fSandi    // setup robot tags apropriate for different modes
2984f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
2996b13307fSandi        if($INFO['exists']) {
3006b13307fSandi            //delay indexing:
301fb9fa88bSAndreas Gohr            if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
3027bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3036b13307fSandi            } else {
3047bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3056b13307fSandi            }
30601f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
30701f9be51SAnika Henke            if ($ID == $conf['start']) {
30801f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
30901f9be51SAnika Henke            }
31001f9be51SAnika Henke            $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
3116b13307fSandi        } else {
3127bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3136b13307fSandi        }
3147a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3157bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3166b13307fSandi    } else {
3177bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3186b13307fSandi    }
3196b13307fSandi
320831800b8SAndreas Gohr    // set metadata
321831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
322831800b8SAndreas Gohr        // keywords (explicit or implicit)
323bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3247bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
325831800b8SAndreas Gohr        } else {
3267bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
327831800b8SAndreas Gohr        }
328831800b8SAndreas Gohr    }
329831800b8SAndreas Gohr
33078a6aeb1SAndreas Gohr    // load stylesheets
331ac7a515fSAndreas Gohr    $head['link'][] = array(
332ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
333e283bd6cSAnika Henke        'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
334ac7a515fSAndreas Gohr    );
335bad31ae9SAndreas Gohr
33672e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
337585bf44eSChristopher Smith    if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
33872e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
339c591aabeSAndreas Gohr    }
3400c39d46cSMichael Große    jsinfo();
3411d739e3dSMichael Große    $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
34285f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
3438bbcb611SAndreas Gohr
34461537d47SAndreas Gohr    // load jquery
345fa078663SAndreas Gohr    $jquery = getCdnUrls();
346fa078663SAndreas Gohr    foreach($jquery as $src) {
34761537d47SAndreas Gohr        $head['script'][] = array(
348fa078663SAndreas Gohr            'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src
34961537d47SAndreas Gohr        );
35061537d47SAndreas Gohr    }
35161537d47SAndreas Gohr
35261537d47SAndreas Gohr    // load our javascript dispatcher
353ac7a515fSAndreas Gohr    $head['script'][] = array(
354ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
355e283bd6cSAnika Henke        'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
356ac7a515fSAndreas Gohr    );
3577bff22c0SAndreas Gohr
3587bff22c0SAndreas Gohr    // trigger event here
359016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
36054e95700STom N Harris    return true;
3617bff22c0SAndreas Gohr}
3627bff22c0SAndreas Gohr
3637bff22c0SAndreas Gohr/**
3647bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3657bff22c0SAndreas Gohr *
3667bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3677bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3687bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3697bff22c0SAndreas Gohr *
37042ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
3711304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3727bff22c0SAndreas Gohr *
3737bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
37442ea7f44SGerrit Uitslag *
37542ea7f44SGerrit Uitslag * @param array $data
3767bff22c0SAndreas Gohr */
3777bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
3787bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
379427bf9a2SAndreas Gohr        if($tag == 'script') {
380427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
381427bf9a2SAndreas Gohr        }
3827bff22c0SAndreas Gohr        foreach($inst as $attr) {
3839b48e6a1SGerry Weißbach            if ( empty($attr) ) { continue; }
3847bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
38526afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
386e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
38709f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
388e226efe1SAndreas Gohr                        $attr['_data'].
38909f791c4SDominik Eckelmann                        "\n/*!]]>*/";
390e226efe1SAndreas Gohr
3911304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
3927bff22c0SAndreas Gohr            } else {
3937bff22c0SAndreas Gohr                echo '/>';
3947bff22c0SAndreas Gohr            }
3957bff22c0SAndreas Gohr            echo "\n";
3967bff22c0SAndreas Gohr        }
397427bf9a2SAndreas Gohr        if($tag == 'script') {
398427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
399427bf9a2SAndreas Gohr        }
4007bff22c0SAndreas Gohr    }
4016b13307fSandi}
4026b13307fSandi
4036b13307fSandi/**
4046b13307fSandi * Print a link
4056b13307fSandi *
4065e163278SAndreas Gohr * Just builds a link.
4076b13307fSandi *
4086b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
40942ea7f44SGerrit Uitslag *
41042ea7f44SGerrit Uitslag * @param string $url
41142ea7f44SGerrit Uitslag * @param string $name
41242ea7f44SGerrit Uitslag * @param string $more
41321d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
41421d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
4156b13307fSandi */
4161af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
41701f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4181af98a77SAnika Henke    if($more) $out .= ' '.$more;
4191af98a77SAnika Henke    $out .= ">$name</a>";
4201af98a77SAnika Henke    if($return) return $out;
4211af98a77SAnika Henke    print $out;
42254e95700STom N Harris    return true;
4236b13307fSandi}
4246b13307fSandi
4256b13307fSandi/**
42655efc227SAndreas Gohr * Prints a link to a WikiPage
42755efc227SAndreas Gohr *
42855efc227SAndreas Gohr * Wrapper around html_wikilink
42955efc227SAndreas Gohr *
43055efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
43142ea7f44SGerrit Uitslag *
43242ea7f44SGerrit Uitslag * @param string      $id   page id
43342ea7f44SGerrit Uitslag * @param string|null $name the name of the link
434fb008d31SIain Hallam * @param bool        $return
435fb008d31SIain Hallam * @return true|string
43655efc227SAndreas Gohr */
437c4a386f1SIain Hallamfunction tpl_pagelink($id, $name = null, $return = false) {
438c4a386f1SIain Hallam    $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
439c4a386f1SIain Hallam    if($return) return $out;
440c4a386f1SIain Hallam    print $out;
44154e95700STom N Harris    return true;
44255efc227SAndreas Gohr}
44355efc227SAndreas Gohr
44455efc227SAndreas Gohr/**
445a3ec5f4aSmatthiasgrimm * get the parent page
446a3ec5f4aSmatthiasgrimm *
447a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
448a3ec5f4aSmatthiasgrimm * returns false if none is available
449a3ec5f4aSmatthiasgrimm *
450377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
45142ea7f44SGerrit Uitslag *
45242ea7f44SGerrit Uitslag * @param string $id page id
45342ea7f44SGerrit Uitslag * @return false|string
454a3ec5f4aSmatthiasgrimm */
455377f9e97SAndreas Gohrfunction tpl_getparent($id) {
456377f9e97SAndreas Gohr    $parent = getNS($id).':';
457377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
458a197105eSmatthiasgrimm    if($parent == $id) {
459a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
460a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
461a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
462377f9e97SAndreas Gohr        if($parent == $id) return false;
463a197105eSmatthiasgrimm    }
464377f9e97SAndreas Gohr    return $parent;
465a3ec5f4aSmatthiasgrimm}
466a3ec5f4aSmatthiasgrimm
467a3ec5f4aSmatthiasgrimm/**
4686b13307fSandi * Print one of the buttons
4696b13307fSandi *
470a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
471a453d131SAdrian Lang * @see    tpl_get_action
472e0c26282SGerrit Uitslag *
473e0c26282SGerrit Uitslag * @param string $type
474e0c26282SGerrit Uitslag * @param bool $return
475e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
476affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
4776b13307fSandi */
4781af98a77SAnika Henkefunction tpl_button($type, $return = false) {
479affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
480a453d131SAdrian Lang    $data = tpl_get_action($type);
481a453d131SAdrian Lang    if($data === false) {
482a453d131SAdrian Lang        return false;
483a453d131SAdrian Lang    } elseif(!is_array($data)) {
484a453d131SAdrian Lang        $out = sprintf($data, 'button');
485409d7af7SAndreas Gohr    } else {
486ac7a515fSAndreas Gohr        /**
487ac7a515fSAndreas Gohr         * @var string $accesskey
488ac7a515fSAndreas Gohr         * @var string $id
489ac7a515fSAndreas Gohr         * @var string $method
490ac7a515fSAndreas Gohr         * @var array  $params
491ac7a515fSAndreas Gohr         */
492a453d131SAdrian Lang        extract($data);
493a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
494a453d131SAdrian Lang            $out = html_topbtn();
495409d7af7SAndreas Gohr        } else {
496a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
497409d7af7SAndreas Gohr        }
498409d7af7SAndreas Gohr    }
4991af98a77SAnika Henke    if($return) return $out;
500a453d131SAdrian Lang    echo $out;
501a453d131SAdrian Lang    return true;
5026b13307fSandi}
5036b13307fSandi
5046b13307fSandi/**
505ed630903Sandi * Like the action buttons but links
506ed630903Sandi *
507a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
508a453d131SAdrian Lang * @see    tpl_get_action
509e0c26282SGerrit Uitslag *
51042ea7f44SGerrit Uitslag * @param string $type    action command
511e0c26282SGerrit Uitslag * @param string $pre     prefix of link
512e0c26282SGerrit Uitslag * @param string $suf     suffix of link
513e0c26282SGerrit Uitslag * @param string $inner   innerHML of link
51421d806cdSGerrit Uitslag * @param bool   $return  if true it returns html, otherwise prints
515e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
516affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
517a453d131SAdrian Lang */
518a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
519affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
520a453d131SAdrian Lang    global $lang;
521a453d131SAdrian Lang    $data = tpl_get_action($type);
522a453d131SAdrian Lang    if($data === false) {
523a453d131SAdrian Lang        return false;
524a453d131SAdrian Lang    } elseif(!is_array($data)) {
525a453d131SAdrian Lang        $out = sprintf($data, 'link');
526a453d131SAdrian Lang    } else {
527ac7a515fSAndreas Gohr        /**
528ac7a515fSAndreas Gohr         * @var string $accesskey
529ac7a515fSAndreas Gohr         * @var string $id
530ac7a515fSAndreas Gohr         * @var string $method
531b1af9014SChristopher Smith         * @var bool   $nofollow
532ac7a515fSAndreas Gohr         * @var array  $params
533becfa414SGerrit Uitslag         * @var string $replacement
534ac7a515fSAndreas Gohr         */
535a453d131SAdrian Lang        extract($data);
536a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
537a453d131SAdrian Lang            $linktarget = $id;
538a453d131SAdrian Lang        } else {
539a453d131SAdrian Lang            $linktarget = wl($id, $params);
540a453d131SAdrian Lang        }
541a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
542becfa414SGerrit Uitslag        if(strpos($caption, '%s')){
543becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
544becfa414SGerrit Uitslag        }
545c7e90e3fSAnika Henke        $akey    = $addTitle = '';
546c7e90e3fSAnika Henke        if($accesskey) {
547c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
548c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
549c7e90e3fSAnika Henke        }
550b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
551ac7a515fSAndreas Gohr        $out = tpl_link(
552ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
553a453d131SAdrian Lang            'class="action '.$type.'" '.
554b1af9014SChristopher Smith                $akey.$rel.
555e0c26282SGerrit Uitslag                'title="'.hsc($caption).$addTitle.'"', true
556ac7a515fSAndreas Gohr        );
557a453d131SAdrian Lang    }
558a453d131SAdrian Lang    if($return) return $out;
559a453d131SAdrian Lang    echo $out;
560a453d131SAdrian Lang    return true;
561a453d131SAdrian Lang}
562a453d131SAdrian Lang
563a453d131SAdrian Lang/**
564a453d131SAdrian Lang * Check the actions and get data for buttons and links
565ed630903Sandi *
566ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
567a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
568a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
569e0c26282SGerrit Uitslag *
570ac7a515fSAndreas Gohr * @param string $type
571ac7a515fSAndreas Gohr * @return array|bool|string
572affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
573ed630903Sandi */
574a453d131SAdrian Langfunction tpl_get_action($type) {
575affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
576a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
5774c4b65c8SMichael Hamann    if($type == 'subscription') $type = 'subscribe';
5784887c154SAndreas Gohr    if($type == 'img_backto') $type = 'imgBackto';
579409d7af7SAndreas Gohr
5804887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
5814887c154SAndreas Gohr    if(class_exists($class)) {
5824887c154SAndreas Gohr        try {
5834887c154SAndreas Gohr            /** @var \dokuwiki\Menu\Item\AbstractItem $item */
5844887c154SAndreas Gohr            $item = new $class;
5854887c154SAndreas Gohr            $data = $item->getLegacyData();
5867b4365a7SGerrit Uitslag            $unknown = false;
5874887c154SAndreas Gohr        } catch(\RuntimeException $ignored) {
5884887c154SAndreas Gohr            return false;
589b8a111f5SMichael Klier        }
590ed630903Sandi    } else {
5914887c154SAndreas Gohr        global $ID;
5924887c154SAndreas Gohr        $data = array(
5934887c154SAndreas Gohr            'accesskey' => null,
5944887c154SAndreas Gohr            'type' => $type,
5954887c154SAndreas Gohr            'id' => $ID,
5964887c154SAndreas Gohr            'method' => 'get',
5974887c154SAndreas Gohr            'params' => array('do' => $type),
5984887c154SAndreas Gohr            'nofollow' => true,
5994887c154SAndreas Gohr            'replacement' => '',
600becfa414SGerrit Uitslag        );
6017b4365a7SGerrit Uitslag        $unknown = true;
602ed630903Sandi    }
6037b4365a7SGerrit Uitslag
6043131073dSGerrit Uitslag    $evt = new Doku_Event('TPL_ACTION_GET', $data);
6057b4365a7SGerrit Uitslag    if($evt->advise_before()) {
6067b4365a7SGerrit Uitslag        //handle unknown types
6077b4365a7SGerrit Uitslag        if($unknown) {
60838d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6097b4365a7SGerrit Uitslag        }
6107b4365a7SGerrit Uitslag    }
6117b4365a7SGerrit Uitslag    $evt->advise_after();
6127b4365a7SGerrit Uitslag    unset($evt);
6137b4365a7SGerrit Uitslag
6147b4365a7SGerrit Uitslag    return $data;
615ed630903Sandi}
616ed630903Sandi
617ed630903Sandi/**
61801f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
61901f17825SAnika Henke *
62001f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
62142ea7f44SGerrit Uitslag *
62242ea7f44SGerrit Uitslag * @param string        $type action command
623ac7a515fSAndreas Gohr * @param bool          $link link or form button?
624e0c26282SGerrit Uitslag * @param string|bool   $wrapper HTML element wrapper
625ac7a515fSAndreas Gohr * @param bool          $return return or print
626ac7a515fSAndreas Gohr * @param string        $pre prefix for links
627ac7a515fSAndreas Gohr * @param string        $suf suffix for links
628ac7a515fSAndreas Gohr * @param string        $inner inner HTML for links
629ac7a515fSAndreas Gohr * @return bool|string
630affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
63101f17825SAnika Henke */
632ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
633affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
63401f17825SAnika Henke    $out = '';
635ac7a515fSAndreas Gohr    if($link) {
636e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
637ac7a515fSAndreas Gohr    } else {
638e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
639ac7a515fSAndreas Gohr    }
64001f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
64101f17825SAnika Henke
64201f17825SAnika Henke    if($return) return $out;
64301f17825SAnika Henke    print $out;
64401f17825SAnika Henke    return $out ? true : false;
64501f17825SAnika Henke}
64601f17825SAnika Henke
64701f17825SAnika Henke/**
6486b13307fSandi * Print the search form
6496b13307fSandi *
65072645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
65172645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
65272645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
65372645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
65472645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
65572645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
65672645b75SAndreas Gohr *
6576b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
65842ea7f44SGerrit Uitslag *
659ac7a515fSAndreas Gohr * @param bool $ajax
660ac7a515fSAndreas Gohr * @param bool $autocomplete
661ac7a515fSAndreas Gohr * @return bool
6626b13307fSandi */
66372645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
6646b13307fSandi    global $lang;
665c1e3b7d9Smatthiasgrimm    global $ACT;
666ad4aaef7SAndreas Gohr    global $QUERY;
667cbcc2fa5SMichael Große    global $ID;
668c1e3b7d9Smatthiasgrimm
669670ff54eSchris    // don't print the search form if search action has been disabled
67064276bbcSarbrk1    if(!actionOK('search')) return false;
671670ff54eSchris
6723c7a3327SMichael Große    $searchForm = new dokuwiki\Form\Form([
6733c7a3327SMichael Große        'action' => wl(),
6743c7a3327SMichael Große        'method' => 'get',
6753c7a3327SMichael Große        'role' => 'search',
6763c7a3327SMichael Große        'class' => 'search',
6773c7a3327SMichael Große        'id' => 'dw__search',
6787fa270bcSMichael Große    ], true);
6793eb2b869SMichael Große    $searchForm->addTagOpen('div')->addClass('no');
6803c7a3327SMichael Große    $searchForm->setHiddenField('do', 'search');
681d22b78c8SMichael Große    $searchForm->setHiddenField('id', $ID);
682d22b78c8SMichael Große    $searchForm->addTextInput('q')
6833c7a3327SMichael Große        ->addClass('edit')
6843c7a3327SMichael Große        ->attrs([
6853c7a3327SMichael Große            'title' => '[F]',
6863c7a3327SMichael Große            'accesskey' => 'f',
6873c7a3327SMichael Große            'placeholder' => $lang['btn_search'],
6883c7a3327SMichael Große            'autocomplete' => $autocomplete ? 'on' : 'off',
6893c7a3327SMichael Große        ])
6903c7a3327SMichael Große        ->id('qsearch__in')
6913c7a3327SMichael Große        ->val($ACT === 'search' ? $QUERY : '')
6923c7a3327SMichael Große        ->useInput(false)
6933c7a3327SMichael Große    ;
6943c7a3327SMichael Große    $searchForm->addButton('', $lang['btn_search'])->attrs([
6953c7a3327SMichael Große        'type' => 'submit',
6963c7a3327SMichael Große        'title' => $lang['btn_search'],
6973c7a3327SMichael Große    ]);
6983c7a3327SMichael Große    if ($ajax) {
6993c7a3327SMichael Große        $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
7003c7a3327SMichael Große        $searchForm->addTagClose('div');
7013c7a3327SMichael Große    }
7023eb2b869SMichael Große    $searchForm->addTagClose('div');
70316ece95cSMichael Große    trigger_event('FORM_QUICKSEARCH_OUTPUT', $searchForm);
7043c7a3327SMichael Große
7053c7a3327SMichael Große    echo $searchForm->toHTML();
7063c7a3327SMichael Große
70754e95700STom N Harris    return true;
7086b13307fSandi}
7096b13307fSandi
7106b13307fSandi/**
7116b13307fSandi * Print the breadcrumbs trace
7126b13307fSandi *
7136b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
71442ea7f44SGerrit Uitslag *
715ac7a515fSAndreas Gohr * @param string $sep Separator between entries
716c4a386f1SIain Hallam * @param bool   $return return or print
717c4a386f1SIain Hallam * @return bool|string
7186b13307fSandi */
719c4a386f1SIain Hallamfunction tpl_breadcrumbs($sep = null, $return = false) {
7206b13307fSandi    global $lang;
7216b13307fSandi    global $conf;
7226b13307fSandi
7236b13307fSandi    //check if enabled
724359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
7256b13307fSandi
726c4a386f1SIain Hallam    //set default
727c4a386f1SIain Hallam    if(is_null($sep)) $sep = '•';
728c4a386f1SIain Hallam
729c4a386f1SIain Hallam    $out='';
730c4a386f1SIain Hallam
7316b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
732265e3787Sandi
7332979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
734265e3787Sandi
73540eb54bbSjan    //render crumbs, highlight the last one
736c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
73740eb54bbSjan    $last = count($crumbs);
73840eb54bbSjan    $i    = 0;
739a77f5846Sjan    foreach($crumbs as $id => $name) {
74040eb54bbSjan        $i++;
741c4a386f1SIain Hallam        $out .= $crumbs_sep;
742c4a386f1SIain Hallam        if($i == $last) $out .= '<span class="curid">';
743c4a386f1SIain Hallam        $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) .  '</bdi>';
744c4a386f1SIain Hallam        if($i == $last) $out .= '</span>';
7456b13307fSandi    }
746c4a386f1SIain Hallam    if($return) return $out;
747c4a386f1SIain Hallam    print $out;
748c4a386f1SIain Hallam    return $out ? true : false;
7496b13307fSandi}
7506b13307fSandi
7516b13307fSandi/**
7521734437eSandi * Hierarchical breadcrumbs
7531734437eSandi *
75431e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7551734437eSandi * It only makes sense with a deep site structure.
7561734437eSandi *
7571734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7586bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
75931e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
760f46c9e83SAnika Henke * @author <fredrik@averpil.com>
76108d7a575SAndreas Gohr * @todo   May behave strangely in RTL languages
76242ea7f44SGerrit Uitslag *
763ac7a515fSAndreas Gohr * @param string $sep Separator between entries
764c4a386f1SIain Hallam * @param bool   $return return or print
765c4a386f1SIain Hallam * @return bool|string
7661734437eSandi */
767c4a386f1SIain Hallamfunction tpl_youarehere($sep = null, $return = false) {
7681734437eSandi    global $conf;
7691734437eSandi    global $ID;
7701734437eSandi    global $lang;
7711734437eSandi
77231e187f8SSean Coates    // check if enabled
77354e95700STom N Harris    if(!$conf['youarehere']) return false;
7741734437eSandi
775c4a386f1SIain Hallam    //set default
776c4a386f1SIain Hallam    if(is_null($sep)) $sep = ' » ';
777c4a386f1SIain Hallam
778c4a386f1SIain Hallam    $out = '';
779c4a386f1SIain Hallam
7801734437eSandi    $parts = explode(':', $ID);
781796bafb3SAndreas Gohr    $count = count($parts);
7821734437eSandi
783c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
7843940c519SMark
78508d7a575SAndreas Gohr    // always print the startpage
786c4a386f1SIain Hallam    $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
787796bafb3SAndreas Gohr
788796bafb3SAndreas Gohr    // print intermediate namespace links
789796bafb3SAndreas Gohr    $part = '';
790796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
791796bafb3SAndreas Gohr        $part .= $parts[$i].':';
792796bafb3SAndreas Gohr        $page = $part;
793796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
794796bafb3SAndreas Gohr
79508d7a575SAndreas Gohr        // output
796c4a386f1SIain Hallam        $out .= $sep . tpl_pagelink($page, null, true);
79731e187f8SSean Coates    }
7981734437eSandi
799796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
800e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
801a8c33dedSMichael Große    if (isset($page) && $page == $part.$parts[$i]) {
802a8c33dedSMichael Große        if($return) return $out;
803a8c33dedSMichael Große        print $out;
804a8c33dedSMichael Große        return true;
805a8c33dedSMichael Große    }
806796bafb3SAndreas Gohr    $page = $part.$parts[$i];
807a8c33dedSMichael Große    if($page == $conf['start']) {
808a8c33dedSMichael Große        if($return) return $out;
809a8c33dedSMichael Große        print $out;
810a8c33dedSMichael Große        return true;
811a8c33dedSMichael Große    }
812c4a386f1SIain Hallam    $out .= $sep;
813c4a386f1SIain Hallam    $out .= tpl_pagelink($page, null, true);
814c4a386f1SIain Hallam    if($return) return $out;
815c4a386f1SIain Hallam    print $out;
816c4a386f1SIain Hallam    return $out ? true : false;
8171734437eSandi}
8181734437eSandi
8191734437eSandi/**
8206b13307fSandi * Print info if the user is logged in
821a2488c3cSMatthias Grimm * and show full name in that case
8226b13307fSandi *
8236b13307fSandi * Could be enhanced with a profile link in future?
8246b13307fSandi *
8256b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
82642ea7f44SGerrit Uitslag *
827ac7a515fSAndreas Gohr * @return bool
8286b13307fSandi */
8296b13307fSandifunction tpl_userinfo() {
8306b13307fSandi    global $lang;
831585bf44eSChristopher Smith    /** @var Input $INPUT */
832585bf44eSChristopher Smith    global $INPUT;
833585bf44eSChristopher Smith
834585bf44eSChristopher Smith    if($INPUT->server->str('REMOTE_USER')) {
835fde860beSGerrit Uitslag        print $lang['loggedinas'].' '.userlink();
83654e95700STom N Harris        return true;
83754e95700STom N Harris    }
83854e95700STom N Harris    return false;
8396b13307fSandi}
8406b13307fSandi
8416b13307fSandi/**
8426b13307fSandi * Print some info about the current page
8436b13307fSandi *
8446b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
84542ea7f44SGerrit Uitslag *
846ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
847ac7a515fSAndreas Gohr * @return bool|string
8486b13307fSandi */
8494b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
8506b13307fSandi    global $conf;
8516b13307fSandi    global $lang;
8526b13307fSandi    global $INFO;
853c6e92a3cSDavid Lorentsen    global $ID;
854c6e92a3cSDavid Lorentsen
855c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
856ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
857ac7a515fSAndreas Gohr        return false;
858ac7a515fSAndreas Gohr    }
8596b13307fSandi
8606b13307fSandi    // prepare date and path
8616b13307fSandi    $fn = $INFO['filepath'];
8626b13307fSandi    if(!$conf['fullpath']) {
863613bca54SAndreas Gohr        if($INFO['rev']) {
864c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'].'/', '', $fn);
8656b13307fSandi        } else {
866c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'].'/', '', $fn);
8676b13307fSandi        }
8686b13307fSandi    }
869bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
870f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
8716b13307fSandi
872faecdfdfSAndreas Gohr    // print it
873faecdfdfSAndreas Gohr    if($INFO['exists']) {
8744b0d3916SAndreas Gohr        $out = '';
875d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
876e260f93bSAnika Henke        $out .= ' · ';
8774b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
878fde860beSGerrit Uitslag        $out .= ' ';
8794b0d3916SAndreas Gohr        $out .= $date;
8806b13307fSandi        if($INFO['editor']) {
8814b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
882d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
8835aa52fafSBen Coburn        } else {
8844b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
8856b13307fSandi        }
8866b13307fSandi        if($INFO['locked']) {
887e260f93bSAnika Henke            $out .= ' · ';
8884b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
889fde860beSGerrit Uitslag            $out .= ' ';
890d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
8916b13307fSandi        }
8924b0d3916SAndreas Gohr        if($ret) {
8934b0d3916SAndreas Gohr            return $out;
8944b0d3916SAndreas Gohr        } else {
8954b0d3916SAndreas Gohr            echo $out;
89654e95700STom N Harris            return true;
8976b13307fSandi        }
8984b0d3916SAndreas Gohr    }
89954e95700STom N Harris    return false;
9006b13307fSandi}
9016b13307fSandi
902820fa24bSandi/**
903a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
90487c434ceSAndreas Gohr *
90587c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
906a6598f23SBen Coburn * the given ID is used.
90787c434ceSAndreas Gohr *
90887c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
90942ea7f44SGerrit Uitslag *
910ac7a515fSAndreas Gohr * @param string $id page id
911ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
912ac7a515fSAndreas Gohr * @return bool|string
91387c434ceSAndreas Gohr */
914a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
915c248bda1SChristopher Smith    global $ACT, $INPUT, $conf, $lang;
916fffeeafeSChristopher Smith
91787c434ceSAndreas Gohr    if(is_null($id)) {
91887c434ceSAndreas Gohr        global $ID;
91987c434ceSAndreas Gohr        $id = $ID;
92087c434ceSAndreas Gohr    }
92187c434ceSAndreas Gohr
92287c434ceSAndreas Gohr    $name = $id;
923fe9ec250SChris Smith    if(useHeading('navigation')) {
924fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
925fffeeafeSChristopher Smith        if($first_heading) $name = $first_heading;
926fffeeafeSChristopher Smith    }
927fffeeafeSChristopher Smith
928fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
929fffeeafeSChristopher Smith    switch ($ACT) {
930fffeeafeSChristopher Smith        // admin functions
931fffeeafeSChristopher Smith        case 'admin' :
932fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
933fffeeafeSChristopher Smith            // try to get the plugin name
934a61966c5SChristopher Smith            /** @var $plugin DokuWiki_Admin_Plugin */
935a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()){
936c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
937a61966c5SChristopher Smith                $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
938fffeeafeSChristopher Smith            }
939fffeeafeSChristopher Smith            break;
940fffeeafeSChristopher Smith
941fffeeafeSChristopher Smith        // user functions
942fffeeafeSChristopher Smith        case 'login' :
943fffeeafeSChristopher Smith        case 'profile' :
944fffeeafeSChristopher Smith        case 'register' :
945fffeeafeSChristopher Smith        case 'resendpwd' :
946fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
947fffeeafeSChristopher Smith            break;
948fffeeafeSChristopher Smith
949fffeeafeSChristopher Smith         // wiki functions
950fffeeafeSChristopher Smith        case 'search' :
951fffeeafeSChristopher Smith        case 'index' :
952fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
953fffeeafeSChristopher Smith            break;
954fffeeafeSChristopher Smith
955fffeeafeSChristopher Smith        // page functions
956fffeeafeSChristopher Smith        case 'edit' :
957fffeeafeSChristopher Smith            $page_title = "✎ ".$name;
958fffeeafeSChristopher Smith            break;
959fffeeafeSChristopher Smith
960fffeeafeSChristopher Smith        case 'revisions' :
961fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
962fffeeafeSChristopher Smith            break;
963fffeeafeSChristopher Smith
964fffeeafeSChristopher Smith        case 'backlink' :
965fffeeafeSChristopher Smith        case 'recent' :
966fffeeafeSChristopher Smith        case 'subscribe' :
967fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_'.$ACT];
968fffeeafeSChristopher Smith            break;
969fffeeafeSChristopher Smith
970fffeeafeSChristopher Smith        default : // SHOW and anything else not included
971fffeeafeSChristopher Smith            $page_title = $name;
97287c434ceSAndreas Gohr    }
973a6598f23SBen Coburn
974a6598f23SBen Coburn    if($ret) {
975fffeeafeSChristopher Smith        return hsc($page_title);
976a6598f23SBen Coburn    } else {
977fffeeafeSChristopher Smith        print hsc($page_title);
97854e95700STom N Harris        return true;
97987c434ceSAndreas Gohr    }
980a6598f23SBen Coburn}
981340756e4Sandi
98255efc227SAndreas Gohr/**
98355efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
98455efc227SAndreas Gohr *
98555efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
98655efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
98755efc227SAndreas Gohr *
98855efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
98955efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
99055efc227SAndreas Gohr * to the names of the latter one)
99155efc227SAndreas Gohr *
9923df72098SAndreas Gohr * Only allowed in: detail.php
99355efc227SAndreas Gohr *
99455efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
99542ea7f44SGerrit Uitslag *
99621d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
997ac7a515fSAndreas Gohr * @param string       $alt  alternative output if no data was found
998e0c26282SGerrit Uitslag * @param null|string  $src  the image src, uses global $SRC if not given
999ac7a515fSAndreas Gohr * @return string
100055efc227SAndreas Gohr */
10013df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
100255efc227SAndreas Gohr    // Init Exif Reader
100355efc227SAndreas Gohr    global $SRC;
10043df72098SAndreas Gohr
10053df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
10063df72098SAndreas Gohr
100755efc227SAndreas Gohr    static $meta = null;
10083df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
100955efc227SAndreas Gohr    if($meta === false) return $alt;
101088945224SChristopher Smith    $info = cleanText($meta->getField($tags));
101155efc227SAndreas Gohr    if($info == false) return $alt;
101255efc227SAndreas Gohr    return $info;
101355efc227SAndreas Gohr}
101455efc227SAndreas Gohr
101555efc227SAndreas Gohr/**
1016becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
1017becfa414SGerrit Uitslag *
1018becfa414SGerrit Uitslag * @return string html of description list
1019becfa414SGerrit Uitslag */
1020becfa414SGerrit Uitslagfunction tpl_img_meta() {
1021becfa414SGerrit Uitslag    global $lang;
1022becfa414SGerrit Uitslag
1023becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1024becfa414SGerrit Uitslag
1025becfa414SGerrit Uitslag    echo '<dl>';
1026becfa414SGerrit Uitslag    foreach($tags as $tag) {
1027becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1028fde860beSGerrit Uitslag        if(!$label) $label = $tag['langkey'] . ':';
1029becfa414SGerrit Uitslag
1030fde860beSGerrit Uitslag        echo '<dt>'.$label.'</dt><dd>';
1031becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1032becfa414SGerrit Uitslag            echo dformat($tag['value']);
1033becfa414SGerrit Uitslag        } else {
1034becfa414SGerrit Uitslag            echo hsc($tag['value']);
1035becfa414SGerrit Uitslag        }
1036becfa414SGerrit Uitslag        echo '</dd>';
1037becfa414SGerrit Uitslag    }
1038becfa414SGerrit Uitslag    echo '</dl>';
1039becfa414SGerrit Uitslag}
1040becfa414SGerrit Uitslag
1041becfa414SGerrit Uitslag/**
1042becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1043becfa414SGerrit Uitslag *
1044becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1045becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1046becfa414SGerrit Uitslag *   - string type     type of value
1047becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1048becfa414SGerrit Uitslag */
1049becfa414SGerrit Uitslagfunction tpl_get_img_meta() {
1050becfa414SGerrit Uitslag
1051becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1052becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
105379e79377SAndreas Gohr        if(file_exists($config_file)) {
1054becfa414SGerrit Uitslag            include($config_file);
1055becfa414SGerrit Uitslag        }
1056becfa414SGerrit Uitslag    }
1057becfa414SGerrit Uitslag    /** @var array $fields the included array with metadata */
1058becfa414SGerrit Uitslag
1059becfa414SGerrit Uitslag    $tags = array();
1060becfa414SGerrit Uitslag    foreach($fields as $tag){
1061becfa414SGerrit Uitslag        $t = array();
1062becfa414SGerrit Uitslag        if (!empty($tag[0])) {
1063becfa414SGerrit Uitslag            $t = array($tag[0]);
1064becfa414SGerrit Uitslag        }
1065becfa414SGerrit Uitslag        if(is_array($tag[3])) {
1066becfa414SGerrit Uitslag            $t = array_merge($t,$tag[3]);
1067becfa414SGerrit Uitslag        }
1068becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1069becfa414SGerrit Uitslag        if ($value) {
1070becfa414SGerrit Uitslag            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1071becfa414SGerrit Uitslag        }
1072becfa414SGerrit Uitslag    }
1073becfa414SGerrit Uitslag    return $tags;
1074becfa414SGerrit Uitslag}
1075becfa414SGerrit Uitslag
1076becfa414SGerrit Uitslag/**
107755efc227SAndreas Gohr * Prints the image with a link to the full sized version
107855efc227SAndreas Gohr *
107955efc227SAndreas Gohr * Only allowed in: detail.php
1080a02d2933SAndreas Gohr *
1081ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1082a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1083a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1084a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1085a02d2933SAndreas Gohr * @param $params array  - additional image attributes
108642ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
108755efc227SAndreas Gohr */
1088a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
108955efc227SAndreas Gohr    global $IMG;
1090585bf44eSChristopher Smith    /** @var Input $INPUT */
1091ac7a515fSAndreas Gohr    global $INPUT;
10925c2eed9aSlisps    global $REV;
109365d3a5dbSAndreas Gohr    $w = (int) tpl_img_getTag('File.Width');
109465d3a5dbSAndreas Gohr    $h = (int) tpl_img_getTag('File.Height');
109555efc227SAndreas Gohr
109655efc227SAndreas Gohr    //resize to given max values
109723a34783SAndreas Gohr    $ratio = 1;
109823a34783SAndreas Gohr    if($w >= $h) {
1099f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
110055efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1101f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
110255efc227SAndreas Gohr            $ratio = $maxheight / $h;
110355efc227SAndreas Gohr        }
110455efc227SAndreas Gohr    } else {
1105f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
110655efc227SAndreas Gohr            $ratio = $maxheight / $h;
1107f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
110855efc227SAndreas Gohr            $ratio = $maxwidth / $w;
110955efc227SAndreas Gohr        }
111055efc227SAndreas Gohr    }
111155efc227SAndreas Gohr    if($ratio) {
111255efc227SAndreas Gohr        $w = floor($ratio * $w);
111355efc227SAndreas Gohr        $h = floor($ratio * $h);
111455efc227SAndreas Gohr    }
111555efc227SAndreas Gohr
11166de3759aSAndreas Gohr    //prepare URLs
11175c2eed9aSlisps    $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
11185c2eed9aSlisps    $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
111955efc227SAndreas Gohr
11202684e50aSAndreas Gohr    //prepare attributes
112155efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1122a02d2933SAndreas Gohr    if(is_null($params)) {
11232684e50aSAndreas Gohr        $p = array();
1124a02d2933SAndreas Gohr    } else {
1125a02d2933SAndreas Gohr        $p = $params;
1126a02d2933SAndreas Gohr    }
11272684e50aSAndreas Gohr    if($w) $p['width'] = $w;
11282684e50aSAndreas Gohr    if($h) $p['height'] = $h;
11292684e50aSAndreas Gohr    $p['class'] = 'img_detail';
11302684e50aSAndreas Gohr    if($alt) {
11312684e50aSAndreas Gohr        $p['alt']   = $alt;
11322684e50aSAndreas Gohr        $p['title'] = $alt;
11332684e50aSAndreas Gohr    } else {
11342684e50aSAndreas Gohr        $p['alt'] = '';
11352684e50aSAndreas Gohr    }
1136a02d2933SAndreas Gohr    $p['src'] = $src;
113755efc227SAndreas Gohr
1138a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1139a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1140a02d2933SAndreas Gohr}
1141a02d2933SAndreas Gohr
1142a02d2933SAndreas Gohr/**
1143a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1144ac7a515fSAndreas Gohr *
1145ac7a515fSAndreas Gohr * @param array $data
1146ac7a515fSAndreas Gohr * @return bool
1147a02d2933SAndreas Gohr */
1148ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
114959f3611bSAnika Henke    global $lang;
1150a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1151a02d2933SAndreas Gohr
115259f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1153a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1154a02d2933SAndreas Gohr    if($data['url']) print '</a>';
115554e95700STom N Harris    return true;
115655efc227SAndreas Gohr}
115755efc227SAndreas Gohr
11587367b368SAndreas Gohr/**
1159881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11607367b368SAndreas Gohr *
11617367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11627367b368SAndreas Gohr * template
1163ac7a515fSAndreas Gohr *
1164ac7a515fSAndreas Gohr * @return bool
11657367b368SAndreas Gohr */
11667367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11677367b368SAndreas Gohr    global $ID;
11681dad36f5SAndreas Gohr
11697367b368SAndreas Gohr    $p           = array();
1170b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1171e68c51baSAndreas Gohr        '&'.time();
1172881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11737367b368SAndreas Gohr    $p['height'] = 1;
11747367b368SAndreas Gohr    $p['alt']    = '';
11757367b368SAndreas Gohr    $att         = buildAttributes($p);
11767367b368SAndreas Gohr    print "<img $att />";
117754e95700STom N Harris    return true;
11787367b368SAndreas Gohr}
11797367b368SAndreas Gohr
118078d4e784SEsther Brunner/**
118178d4e784SEsther Brunner * tpl_getConf($id)
118278d4e784SEsther Brunner *
118378d4e784SEsther Brunner * use this function to access template configuration variables
1184ac7a515fSAndreas Gohr *
118517448fb8SChristopher Smith * @param string $id      name of the value to access
118617448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
118717448fb8SChristopher Smith * @return mixed
118878d4e784SEsther Brunner */
118917448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
119078d4e784SEsther Brunner    global $conf;
119117566ac6SAdrian Lang    static $tpl_configloaded = false;
119278d4e784SEsther Brunner
119378d4e784SEsther Brunner    $tpl = $conf['template'];
119478d4e784SEsther Brunner
119578d4e784SEsther Brunner    if(!$tpl_configloaded) {
119678d4e784SEsther Brunner        $tconf = tpl_loadConfig();
119778d4e784SEsther Brunner        if($tconf !== false) {
119878d4e784SEsther Brunner            foreach($tconf as $key => $value) {
119978d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
120078d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
120178d4e784SEsther Brunner            }
120278d4e784SEsther Brunner            $tpl_configloaded = true;
120378d4e784SEsther Brunner        }
120478d4e784SEsther Brunner    }
120578d4e784SEsther Brunner
120617448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
120778d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
120878d4e784SEsther Brunner    }
120978d4e784SEsther Brunner
121017448fb8SChristopher Smith    return $notset;
121117448fb8SChristopher Smith}
121217448fb8SChristopher Smith
121378d4e784SEsther Brunner/**
121478d4e784SEsther Brunner * tpl_loadConfig()
1215ac7a515fSAndreas Gohr *
121678d4e784SEsther Brunner * reads all template configuration variables
121778d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1218ac7a515fSAndreas Gohr *
1219ac7a515fSAndreas Gohr * @return array
122078d4e784SEsther Brunner */
122178d4e784SEsther Brunnerfunction tpl_loadConfig() {
122278d4e784SEsther Brunner
1223c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
122478d4e784SEsther Brunner    $conf = array();
122578d4e784SEsther Brunner
122679e79377SAndreas Gohr    if(!file_exists($file)) return false;
122778d4e784SEsther Brunner
122878d4e784SEsther Brunner    // load default config file
122978d4e784SEsther Brunner    include($file);
123078d4e784SEsther Brunner
123178d4e784SEsther Brunner    return $conf;
123278d4e784SEsther Brunner}
123378d4e784SEsther Brunner
123417566ac6SAdrian Lang// language methods
123517566ac6SAdrian Lang/**
123617566ac6SAdrian Lang * tpl_getLang($id)
123717566ac6SAdrian Lang *
123817566ac6SAdrian Lang * use this function to access template language variables
123942ea7f44SGerrit Uitslag *
124042ea7f44SGerrit Uitslag * @param string $id key of language string
124142ea7f44SGerrit Uitslag * @return string
124217566ac6SAdrian Lang */
124317566ac6SAdrian Langfunction tpl_getLang($id) {
124417566ac6SAdrian Lang    static $lang = array();
124517566ac6SAdrian Lang
124617566ac6SAdrian Lang    if(count($lang) === 0) {
1247dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1248dd7a6159SGerrit Uitslag
1249c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
125017566ac6SAdrian Lang
125117566ac6SAdrian Lang        $lang = array();
125217566ac6SAdrian Lang
125317566ac6SAdrian Lang        // don't include once
125417566ac6SAdrian Lang        @include($path . 'en/lang.php');
1255dd7a6159SGerrit Uitslag        foreach($config_cascade['lang']['template'] as $config_file) {
125679e79377SAndreas Gohr            if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1257dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1258dd7a6159SGerrit Uitslag            }
125917566ac6SAdrian Lang        }
126017566ac6SAdrian Lang
1261dd7a6159SGerrit Uitslag        if($conf['lang'] != 'en') {
1262dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1263dd7a6159SGerrit Uitslag            foreach($config_cascade['lang']['template'] as $config_file) {
126479e79377SAndreas Gohr                if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1265dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1266dd7a6159SGerrit Uitslag                }
1267dd7a6159SGerrit Uitslag            }
1268dd7a6159SGerrit Uitslag        }
126917566ac6SAdrian Lang    }
127017566ac6SAdrian Lang    return $lang[$id];
127117566ac6SAdrian Lang}
127217566ac6SAdrian Lang
12733df72098SAndreas Gohr/**
1274c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1275e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1276e8ec13b9SKlap-in *
1277e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1278e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1279e8ec13b9SKlap-in */
1280e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1281c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1282e8ec13b9SKlap-in}
1283e8ec13b9SKlap-in
1284e8ec13b9SKlap-in/**
1285c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
128642ea7f44SGerrit Uitslag *
128742ea7f44SGerrit Uitslag * @param string $id id of localized text
128842ea7f44SGerrit Uitslag * @return string wiki text
1289e8ec13b9SKlap-in */
1290c5c17fdaSKlap-infunction tpl_localeFN($id) {
1291e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1292e8ec13b9SKlap-in    global $conf;
129338fb1fc7SGerrit Uitslag    $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
129479e79377SAndreas Gohr    if (!file_exists($file)){
1295e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
129679e79377SAndreas Gohr        if(!file_exists($file)){
1297e8ec13b9SKlap-in            //fall back to english
1298e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1299e8ec13b9SKlap-in        }
1300e8ec13b9SKlap-in    }
1301e8ec13b9SKlap-in    return $file;
1302e8ec13b9SKlap-in}
1303e8ec13b9SKlap-in
1304e8ec13b9SKlap-in/**
13057abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
13063df72098SAndreas Gohr *
13073df72098SAndreas Gohr * Depending on the user's actions this may be a list of
13083df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
13093df72098SAndreas Gohr * a message of referencing pages
13103df72098SAndreas Gohr *
13113df72098SAndreas Gohr * Only allowed in mediamanager.php
13123df72098SAndreas Gohr *
1313c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1314c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
131542ea7f44SGerrit Uitslag * @param string $sort
13168702de7fSGerrit Uitslag *
13173df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13183df72098SAndreas Gohr */
131900e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
13203df72098SAndreas Gohr    global $IMG;
13213df72098SAndreas Gohr    global $AUTH;
13223df72098SAndreas Gohr    global $INUSE;
13233df72098SAndreas Gohr    global $NS;
13243df72098SAndreas Gohr    global $JUMPTO;
1325585bf44eSChristopher Smith    /** @var Input $INPUT */
1326ac7a515fSAndreas Gohr    global $INPUT;
13273df72098SAndreas Gohr
1328ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1329c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1330c182313eSAndreas Gohr
1331c182313eSAndreas Gohr    if(!$do) {
1332ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1333c182313eSAndreas Gohr            $do = 'metaform';
1334c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1335c182313eSAndreas Gohr            $do = 'filesinuse';
1336c182313eSAndreas Gohr        } else {
1337c182313eSAndreas Gohr            $do = 'filelist';
1338c182313eSAndreas Gohr        }
1339c182313eSAndreas Gohr    }
1340c182313eSAndreas Gohr
1341c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1342c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1343c182313eSAndreas Gohr    $data = array('do' => $do);
1344c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1345c182313eSAndreas Gohr    if($evt->advise_before()) {
1346c182313eSAndreas Gohr        $do = $data['do'];
134730fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1348c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1349c182313eSAndreas Gohr        } elseif($do == 'filelist') {
135000e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1351c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1352ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1353c182313eSAndreas Gohr        } else {
1354c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1355c182313eSAndreas Gohr        }
1356c182313eSAndreas Gohr    }
1357c182313eSAndreas Gohr    $evt->advise_after();
1358c182313eSAndreas Gohr    unset($evt);
1359c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1360c182313eSAndreas Gohr
13613df72098SAndreas Gohr}
13623df72098SAndreas Gohr
13633df72098SAndreas Gohr/**
1364d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1365d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1366d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1367d9162c6cSKate Arzamastseva *
1368d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1369d9162c6cSKate Arzamastseva */
1370035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1371d9162c6cSKate Arzamastseva    global $AUTH;
1372d9162c6cSKate Arzamastseva    global $NS;
1373d9162c6cSKate Arzamastseva    global $JUMPTO;
137495b451bcSAdrian Lang    global $lang;
1375585bf44eSChristopher Smith    /** @var Input $INPUT */
1376ac7a515fSAndreas Gohr    global $INPUT;
1377d9162c6cSKate Arzamastseva
1378ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1379e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1380ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1381d9162c6cSKate Arzamastseva
138294add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
138395b451bcSAdrian Lang
1384ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
138523846a98SKate Arzamastseva
138694add303SAnika Henke    echo '<div class="panelHeader">'.NL;
138795b451bcSAdrian Lang    echo '<h3>';
1388026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1389c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
139094add303SAnika Henke    echo '</h3>'.NL;
139195b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
139295b451bcSAdrian Lang        media_tab_files_options();
139323846a98SKate Arzamastseva    }
139494add303SAnika Henke    echo '</div>'.NL;
1395d9162c6cSKate Arzamastseva
139694add303SAnika Henke    echo '<div class="panelContent">'.NL;
139795b451bcSAdrian Lang    if($opened_tab == 'files') {
139895b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
139995b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
140095b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
140195b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
140295b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
140395b451bcSAdrian Lang    }
140494add303SAnika Henke    echo '</div>'.NL;
1405d9162c6cSKate Arzamastseva}
1406d9162c6cSKate Arzamastseva
1407d9162c6cSKate Arzamastseva/**
1408d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1409d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1410d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1411d9162c6cSKate Arzamastseva * list of file revisions
1412d9162c6cSKate Arzamastseva *
1413d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1414f50a239bSTakamura *
1415f50a239bSTakamura * @param string $image
1416f50a239bSTakamura * @param boolean $rev
1417d9162c6cSKate Arzamastseva */
1418035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1419e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1420585bf44eSChristopher Smith    /** @var Input $INPUT */
1421585bf44eSChristopher Smith    global $INPUT;
1422d9162c6cSKate Arzamastseva
1423*64159a61SAndreas Gohr    $removed = (
1424*64159a61SAndreas Gohr        !file_exists(mediaFN($image)) &&
1425*64159a61SAndreas Gohr        file_exists(mediaMetaFN($image, '.changes')) &&
1426*64159a61SAndreas Gohr        $conf['mediarevisions']
1427*64159a61SAndreas Gohr    );
1428ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
14296dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1430e8a2a143SMichael Hamann    $ns = getNS($image);
1431ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
14321eeeced2SKate Arzamastseva
1433ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1434e5d185e1SKate Arzamastseva
1435e5d185e1SKate Arzamastseva    $tab_array = array('view');
1436ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1437e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1438e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1439e5d185e1SKate Arzamastseva    }
1440e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1441e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1442e5d185e1SKate Arzamastseva    }
1443e5d185e1SKate Arzamastseva
1444e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1445ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
144623846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1447d9162c6cSKate Arzamastseva
1448ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
144923846a98SKate Arzamastseva
145059f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1451ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
145295b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
145395b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
1454750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
1455*64159a61SAndreas Gohr    $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.
1456*64159a61SAndreas Gohr        $image.'</a>'.'</strong>';
145708317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
145808317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
145908317413SAdrian Lang    } else {
1460026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
146108317413SAdrian Lang    }
1462b8a84c03SAndreas Gohr
146394add303SAnika Henke    echo '</h3></div>'.NL;
146495b451bcSAdrian Lang
146594add303SAnika Henke    echo '<div class="panelContent">'.NL;
146695b451bcSAdrian Lang
146723846a98SKate Arzamastseva    if($opened_tab == 'view') {
1468e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
146923846a98SKate Arzamastseva
147092cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
1471e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
147223846a98SKate Arzamastseva
1473e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1474e8a2a143SMichael Hamann        media_tab_history($image, $ns);
147523846a98SKate Arzamastseva    }
147695b451bcSAdrian Lang
147794add303SAnika Henke    echo '</div>'.NL;
1478d9162c6cSKate Arzamastseva}
1479d9162c6cSKate Arzamastseva
1480d9162c6cSKate Arzamastseva/**
14817abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
14823df72098SAndreas Gohr *
14833df72098SAndreas Gohr * Only allowed in mediamanager.php
14843df72098SAndreas Gohr *
14853df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14863df72098SAndreas Gohr */
1487fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14883df72098SAndreas Gohr    global $NS;
148923846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14903df72098SAndreas Gohr    media_nstree($NS);
14913df72098SAndreas Gohr    ptln('</div>');
14923df72098SAndreas Gohr}
14933df72098SAndreas Gohr
1494a00de5b5SAndreas Gohr/**
1495a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1496a00de5b5SAndreas Gohr *
1497a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1498a00de5b5SAndreas Gohr *
1499a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
150042ea7f44SGerrit Uitslag *
150142ea7f44SGerrit Uitslag * @param string $empty empty option label
150242ea7f44SGerrit Uitslag * @param string $button submit button label
1503affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1504a00de5b5SAndreas Gohr */
1505a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1506affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
15071e875dcdSAndreas Gohr    $menu = new \dokuwiki\Menu\MobileMenu();
15081e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1509a00de5b5SAndreas Gohr}
1510a00de5b5SAndreas Gohr
1511066fee30SAndreas Gohr/**
1512066fee30SAndreas Gohr * Print a informational line about the used license
1513066fee30SAndreas Gohr *
1514066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1515ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1516ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1517ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1518ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1519ac7a515fSAndreas Gohr * @return string
1520066fee30SAndreas Gohr */
152180083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1522066fee30SAndreas Gohr    global $license;
1523066fee30SAndreas Gohr    global $conf;
1524066fee30SAndreas Gohr    global $lang;
1525066fee30SAndreas Gohr    if(!$conf['license']) return '';
1526066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1527066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
152853e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1529066fee30SAndreas Gohr
153080083a41SAndreas Gohr    $out = '';
153180083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1532066fee30SAndreas Gohr    if($img) {
1533066fee30SAndreas Gohr        $src = license_img($img);
1534066fee30SAndreas Gohr        if($src) {
153553e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
153653e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
153753e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1538066fee30SAndreas Gohr        }
1539066fee30SAndreas Gohr    }
15404cefd216SMichael Klier    if(!$imgonly) {
154153e15c8bSAnika Henke        $out .= $lang['license'].' ';
1542d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1543d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
15444cefd216SMichael Klier    }
154580083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1546066fee30SAndreas Gohr
1547066fee30SAndreas Gohr    if($return) return $out;
1548066fee30SAndreas Gohr    echo $out;
1549ac7a515fSAndreas Gohr    return '';
1550066fee30SAndreas Gohr}
1551066fee30SAndreas Gohr
1552a81910eeSAndreas Gohr/**
1553835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1554a81910eeSAndreas Gohr *
1555a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1556a81910eeSAndreas Gohr * template
1557e0c26282SGerrit Uitslag *
15587a112df5SAndreas Gohr * @param string $pageid The page name you want to include
15597a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
15607a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
15617c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1562e0c26282SGerrit Uitslag * @return bool|null|string
1563a81910eeSAndreas Gohr */
15647c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
15657a112df5SAndreas Gohr    if($propagate) {
15667c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
15677c3e4a67SAndreas Gohr    } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
15687a112df5SAndreas Gohr        return false;
15697a112df5SAndreas Gohr    }
1570c786a1b6SAnika Henke    if(!$pageid) return false;
1571835dfcaeSAnika Henke
1572c786a1b6SAnika Henke    global $TOC;
15739a2e250aSAndreas Gohr    $oldtoc = $TOC;
1574a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
15759a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1576a81910eeSAndreas Gohr
1577a2e03c82SAndreas Gohr    if($print) echo $html;
1578e66d3e6dSAndreas Gohr    return $html;
1579e66d3e6dSAndreas Gohr}
1580e66d3e6dSAndreas Gohr
1581e66d3e6dSAndreas Gohr/**
15825b75cd1fSAdrian Lang * Display the subscribe form
15835b75cd1fSAdrian Lang *
15845b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15855b75cd1fSAdrian Lang */
15865b75cd1fSAdrian Langfunction tpl_subscribe() {
15875b75cd1fSAdrian Lang    global $INFO;
15885b75cd1fSAdrian Lang    global $ID;
15895b75cd1fSAdrian Lang    global $lang;
15906b8f02cfSAdrian Lang    global $conf;
159140c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15925b75cd1fSAdrian Lang
15935b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15945b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
159515741132SAndreas Gohr    echo '<div class="level2">';
15965b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
15975b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
15985b75cd1fSAdrian Lang    } else {
15995b75cd1fSAdrian Lang        echo '<ul>';
16005b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1601056c2049SAndreas Gohr            echo '<li><div class="li">';
16025b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1603056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
16045b75cd1fSAdrian Lang            } else {
1605056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
16065b75cd1fSAdrian Lang            }
160740c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
160815741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1609056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
161015741132SAndreas Gohr
1611ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1612ac7a515fSAndreas Gohr                $ID,
1613ac7a515fSAndreas Gohr                array(
1614ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
161566d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
161666d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
161766d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1618ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1619ac7a515fSAndreas Gohr                )
1620ac7a515fSAndreas Gohr            ).
162166d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
162266d2bed9SAdrian Lang                '</a></div></li>';
16235b75cd1fSAdrian Lang        }
16245b75cd1fSAdrian Lang        echo '</ul>';
16255b75cd1fSAdrian Lang    }
162615741132SAndreas Gohr    echo '</div>';
16275b75cd1fSAdrian Lang
162815741132SAndreas Gohr    // Add new subscription form
16295b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
163015741132SAndreas Gohr    echo '<div class="level2">';
16315b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
163215741132SAndreas Gohr    $targets = array(
163315741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
163415741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
163515741132SAndreas Gohr    );
163615741132SAndreas Gohr    $styles  = array(
163715741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
16386b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
16396b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
164015741132SAndreas Gohr    );
164115741132SAndreas Gohr
1642056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1643056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1644056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1645056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1646056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1647056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1648056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1649056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1650056c2049SAndreas Gohr    $form->endFieldset();
16515b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
16525b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
165315741132SAndreas Gohr    echo '</div>';
16545b75cd1fSAdrian Lang}
16555b75cd1fSAdrian Lang
1656d059ba9bSAndreas Gohr/**
1657d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1658d059ba9bSAndreas Gohr *
1659d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1660d059ba9bSAndreas Gohr *
1661d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1662d059ba9bSAndreas Gohr */
1663d059ba9bSAndreas Gohrfunction tpl_flush() {
1664d059ba9bSAndreas Gohr    ob_flush();
1665d059ba9bSAndreas Gohr    flush();
1666d059ba9bSAndreas Gohr}
1667d059ba9bSAndreas Gohr
1668afca7e7eSAnika Henke/**
1669378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1670afca7e7eSAnika Henke *
1671378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1672378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1673378325f9SAndreas Gohr *
167442ea7f44SGerrit Uitslag * @param  string[] $search       locations to look at
1675378325f9SAndreas Gohr * @param  bool     $abs           if to use absolute URL
1676ac7a515fSAndreas Gohr * @param  array   &$imginfo   filled with getimagesize()
1677ac7a515fSAndreas Gohr * @return string
167842ea7f44SGerrit Uitslag *
1679378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1680afca7e7eSAnika Henke */
1681378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1682ac7a515fSAndreas Gohr    $img     = '';
1683ac7a515fSAndreas Gohr    $file    = '';
1684ac7a515fSAndreas Gohr    $ismedia = false;
1685378325f9SAndreas Gohr    // loop through candidates until a match was found:
1686378325f9SAndreas Gohr    foreach($search as $img) {
1687378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1688378325f9SAndreas Gohr            $file    = mediaFN($img);
1689378325f9SAndreas Gohr            $ismedia = true;
1690378325f9SAndreas Gohr        } else {
1691c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1692378325f9SAndreas Gohr            $ismedia = false;
16931f13e33dSAnika Henke        }
16940f747863Slupo49
1695378325f9SAndreas Gohr        if(file_exists($file)) break;
1696872a6d29SAnika Henke    }
1697378325f9SAndreas Gohr
1698378325f9SAndreas Gohr    // fetch image data if requested
1699378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1700378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1701378325f9SAndreas Gohr    }
1702378325f9SAndreas Gohr
1703378325f9SAndreas Gohr    // build URL
1704378325f9SAndreas Gohr    if($ismedia) {
1705378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1706378325f9SAndreas Gohr    } else {
1707c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1708378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1709378325f9SAndreas Gohr    }
1710378325f9SAndreas Gohr
1711378325f9SAndreas Gohr    return $url;
1712a7e5f74cSlupo49}
17131f13e33dSAnika Henke
1714872a6d29SAnika Henke/**
1715e5d4768dSAndreas Gohr * PHP include a file
1716e5d4768dSAndreas Gohr *
1717e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1718e5d4768dSAndreas Gohr * file in the template's root directory.
1719e5d4768dSAndreas Gohr *
1720e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1721e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1722e5d4768dSAndreas Gohr * default.
1723e5d4768dSAndreas Gohr *
1724e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1725e5d4768dSAndreas Gohr * to this function!
1726e5d4768dSAndreas Gohr *
1727e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1728e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
172942ea7f44SGerrit Uitslag *
173042ea7f44SGerrit Uitslag * @param string $file
1731e5d4768dSAndreas Gohr */
1732e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1733e5d4768dSAndreas Gohr    global $config_cascade;
1734e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1735e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1736e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1737e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1738e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1739f3a1225fSAnika Henke                include("$dir/$file");
1740e5d4768dSAndreas Gohr                return;
1741e5d4768dSAndreas Gohr            }
1742e5d4768dSAndreas Gohr        }
1743e5d4768dSAndreas Gohr    }
1744e5d4768dSAndreas Gohr
1745e5d4768dSAndreas Gohr    // still here? try the template dir
1746e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1747e5d4768dSAndreas Gohr    if(file_exists($file)) {
1748f3a1225fSAnika Henke        include($file);
1749e5d4768dSAndreas Gohr    }
1750e5d4768dSAndreas Gohr}
1751e5d4768dSAndreas Gohr
1752e5d4768dSAndreas Gohr/**
1753872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1754872a6d29SAnika Henke *
1755872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
175642ea7f44SGerrit Uitslag *
1757ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1758ac7a515fSAndreas Gohr * @return string
1759872a6d29SAnika Henke */
1760872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1761872a6d29SAnika Henke
1762872a6d29SAnika Henke    $return = '';
1763872a6d29SAnika Henke
1764872a6d29SAnika Henke    foreach($types as $type) {
1765872a6d29SAnika Henke        switch($type) {
1766872a6d29SAnika Henke            case 'favicon':
1767378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1768378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1769872a6d29SAnika Henke                break;
1770872a6d29SAnika Henke            case 'mobile':
1771cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1772378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1773872a6d29SAnika Henke                break;
1774872a6d29SAnika Henke            case 'generic':
1775872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1776378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1777378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1778872a6d29SAnika Henke                break;
1779872a6d29SAnika Henke        }
1780872a6d29SAnika Henke    }
1781872a6d29SAnika Henke
1782872a6d29SAnika Henke    return $return;
1783afca7e7eSAnika Henke}
1784afca7e7eSAnika Henke
1785d9162c6cSKate Arzamastseva/**
1786d9162c6cSKate Arzamastseva * Prints full-screen media manager
1787d9162c6cSKate Arzamastseva *
1788d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1789d9162c6cSKate Arzamastseva */
1790d9162c6cSKate Arzamastsevafunction tpl_media() {
1791ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
179288a71175SKate Arzamastseva    $fullscreen = true;
179395b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1794d9162c6cSKate Arzamastseva
1795ac7a515fSAndreas Gohr    $rev   = '';
1796ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
179798f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
179898f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
17999c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
180098f03b57SKate Arzamastseva
180194add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1802bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1803d9162c6cSKate Arzamastseva    html_msgarea();
180494add303SAnika Henke
180594add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
180694add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
180795b451bcSAdrian Lang    echo '<div class="panelHeader">';
1808ba340a70SAnika Henke    echo $lang['media_namespaces'];
180994add303SAnika Henke    echo '</div>'.NL;
181095b451bcSAdrian Lang
181194add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
181295b451bcSAdrian Lang    media_nstree($NS);
181394add303SAnika Henke    echo '</div>'.NL;
181494add303SAnika Henke    echo '</div>'.NL;
1815fa8e5c77SKate Arzamastseva
181694add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1817035e07f1SKate Arzamastseva    tpl_mediaFileList();
181894add303SAnika Henke    echo '</div>'.NL;
1819fa8e5c77SKate Arzamastseva
182094add303SAnika Henke    echo '<div class="panel file">'.NL;
182194add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1822035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
182394add303SAnika Henke    echo '</div>'.NL;
1824ba340a70SAnika Henke
182594add303SAnika Henke    echo '</div>'.NL;
1826d9162c6cSKate Arzamastseva}
1827afca7e7eSAnika Henke
1828c71db656SAnika Henke/**
1829c71db656SAnika Henke * Return useful layout classes
1830c71db656SAnika Henke *
1831c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
183242ea7f44SGerrit Uitslag *
183342ea7f44SGerrit Uitslag * @return string
1834c71db656SAnika Henke */
1835c71db656SAnika Henkefunction tpl_classes() {
1836c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1837585bf44eSChristopher Smith    /** @var Input $INPUT */
1838585bf44eSChristopher Smith    global $INPUT;
1839585bf44eSChristopher Smith
1840c71db656SAnika Henke    $classes = array(
1841c71db656SAnika Henke        'dokuwiki',
1842c71db656SAnika Henke        'mode_'.$ACT,
1843c71db656SAnika Henke        'tpl_'.$conf['template'],
1844585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
184539f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1846c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1847c71db656SAnika Henke    );
1848c71db656SAnika Henke    return join(' ', $classes);
1849c71db656SAnika Henke}
1850c71db656SAnika Henke
185184dd2b1aSGerrit Uitslag/**
185284dd2b1aSGerrit Uitslag * Create event for tools menues
185384dd2b1aSGerrit Uitslag *
185484dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
185584dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
185684dd2b1aSGerrit Uitslag * @param array $items
185784dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1858affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
185984dd2b1aSGerrit Uitslag */
186084dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') {
1861affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
186284dd2b1aSGerrit Uitslag    $data = array(
186384dd2b1aSGerrit Uitslag        'view' => $view,
186484dd2b1aSGerrit Uitslag        'items' => $items
186584dd2b1aSGerrit Uitslag    );
186684dd2b1aSGerrit Uitslag
186784dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
186884dd2b1aSGerrit Uitslag    $evt = new Doku_Event($hook, $data);
186984dd2b1aSGerrit Uitslag    if($evt->advise_before()) {
187084dd2b1aSGerrit Uitslag        foreach($evt->data['items'] as $k => $html) echo $html;
187184dd2b1aSGerrit Uitslag    }
187284dd2b1aSGerrit Uitslag    $evt->advise_after();
187384dd2b1aSGerrit Uitslag}
187484dd2b1aSGerrit Uitslag
1875e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1876a00de5b5SAndreas Gohr
1877