xref: /dokuwiki/inc/template.php (revision 5e0255e36bf156b973d6ab46192daa88891c0027)
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
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
106b13307fSandi
116b13307fSandi/**
12ac7a515fSAndreas Gohr * Access a template file
13ac7a515fSAndreas Gohr *
14ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
15ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
165a892029SAndreas Gohr *
175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
18ac7a515fSAndreas Gohr * @param string $file
19ac7a515fSAndreas Gohr * @return string
205a892029SAndreas Gohr */
21ac7a515fSAndreas Gohrfunction template($file) {
225a892029SAndreas Gohr    global $conf;
235a892029SAndreas Gohr
24ac7a515fSAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
25ac7a515fSAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
265a892029SAndreas Gohr
27ac7a515fSAndreas Gohr    return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
285a892029SAndreas Gohr}
295a892029SAndreas Gohr
30c4766956SAndreas Gohr/**
31c4766956SAndreas Gohr * Convenience function to access template dir from local FS
32c4766956SAndreas Gohr *
33c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
34c4766956SAndreas Gohr *
35c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
36afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
37ac7a515fSAndreas Gohr * @return string
38c4766956SAndreas Gohr */
39afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') {
4075b14482SAndreas Gohr    global $conf;
41afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
42afb2c082SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$tpl.'/';
43c4766956SAndreas Gohr}
44c4766956SAndreas Gohr
45c4766956SAndreas Gohr/**
46c4766956SAndreas Gohr * Convenience function to access template dir from web
47c4766956SAndreas Gohr *
48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
49c4766956SAndreas Gohr *
50c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
51afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
52ac7a515fSAndreas Gohr * @return string
53c4766956SAndreas Gohr */
5499dca513SAndreas Gohrfunction tpl_basedir($tpl='') {
5575b14482SAndreas Gohr    global $conf;
56afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
57dcd4911eSMichael Hamann    return DOKU_BASE.'lib/tpl/'.$tpl.'/';
58c4766956SAndreas Gohr}
59c4766956SAndreas Gohr
605a892029SAndreas Gohr/**
616b13307fSandi * Print the content
626b13307fSandi *
636b13307fSandi * This function is used for printing all the usual content
646b13307fSandi * (defined by the global $ACT var) by calling the appropriate
656b13307fSandi * outputfunction(s) from html.php
666b13307fSandi *
67ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
68ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
696b13307fSandi *
706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7142ea7f44SGerrit Uitslag *
72ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
73ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
74ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
75ac7a515fSAndreas Gohr * @return bool true if any output
766b13307fSandi */
77b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) {
787ea0913cSchris    global $ACT;
79b8595a66SAndreas Gohr    global $INFO;
80b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
817ea0913cSchris
827ea0913cSchris    ob_start();
83746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
847ea0913cSchris    $html_output = ob_get_clean();
85746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
8654e95700STom N Harris
8754e95700STom N Harris    return !empty($html_output);
887ea0913cSchris}
897ea0913cSchris
90ac7a515fSAndreas Gohr/**
91ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
92ac7a515fSAndreas Gohr *
93ac7a515fSAndreas Gohr * @return bool
94ac7a515fSAndreas Gohr */
957ea0913cSchrisfunction tpl_content_core() {
96952acff9SAndreas Gohr    $router = \dokuwiki\ActionRouter::getInstance();
97952acff9SAndreas Gohr    try {
98952acff9SAndreas Gohr        $router->getAction()->tplContent();
99952acff9SAndreas Gohr    } catch(\dokuwiki\Action\Exception\FatalException $e) {
100952acff9SAndreas Gohr        // there was no content for the action
101952acff9SAndreas Gohr        msg(hsc($e->getMessage()), -1);
10254e95700STom N Harris        return false;
1036b13307fSandi    }
10454e95700STom N Harris    return true;
1056b13307fSandi}
1066b13307fSandi
107c19fe9c0Sandi/**
108b8595a66SAndreas Gohr * Places the TOC where the function is called
109b8595a66SAndreas Gohr *
110b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
111b8595a66SAndreas Gohr * a false argument
112b8595a66SAndreas Gohr *
113b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11442ea7f44SGerrit Uitslag *
115ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
116ac7a515fSAndreas Gohr * @return string
117b8595a66SAndreas Gohr */
118b8595a66SAndreas Gohrfunction tpl_toc($return = false) {
119b8595a66SAndreas Gohr    global $TOC;
120b8595a66SAndreas Gohr    global $ACT;
121b8595a66SAndreas Gohr    global $ID;
122b8595a66SAndreas Gohr    global $REV;
123b8595a66SAndreas Gohr    global $INFO;
124851f2e89SAnika Henke    global $conf;
125ac7a515fSAndreas Gohr    global $INPUT;
126b8595a66SAndreas Gohr    $toc = array();
127b8595a66SAndreas Gohr
128b8595a66SAndreas Gohr    if(is_array($TOC)) {
129b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
130b8595a66SAndreas Gohr        $toc = $TOC;
1313c86d7c9SAndreas Gohr    } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
132b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
133e0c26282SGerrit Uitslag        $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
134b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])) {
135b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
136b8595a66SAndreas Gohr        } else {
1372bb0d541Schris            $tocok = true;
138b8595a66SAndreas Gohr        }
139f87b5dbbSChristopher Smith        $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
140851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
141b8595a66SAndreas Gohr            $toc = array();
142b8595a66SAndreas Gohr        }
143b8595a66SAndreas Gohr    } elseif($ACT == 'admin') {
144a61966c5SChristopher Smith        // try to load admin plugin TOC
145ac7a515fSAndreas Gohr        /** @var $plugin DokuWiki_Admin_Plugin */
146a61966c5SChristopher Smith        if ($plugin = plugin_getRequestAdminPlugin()) {
147b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
148b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
149b8595a66SAndreas Gohr        }
150b8595a66SAndreas Gohr    }
151b8595a66SAndreas Gohr
1520b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
153b8595a66SAndreas Gohr    $html = html_TOC($toc);
154b8595a66SAndreas Gohr    if($return) return $html;
155b8595a66SAndreas Gohr    echo $html;
156ac7a515fSAndreas Gohr    return '';
157b8595a66SAndreas Gohr}
158b8595a66SAndreas Gohr
159b8595a66SAndreas Gohr/**
160c19fe9c0Sandi * Handle the admin page contents
161c19fe9c0Sandi *
162c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
16342ea7f44SGerrit Uitslag *
16442ea7f44SGerrit Uitslag * @return bool
165c19fe9c0Sandi */
166c19fe9c0Sandifunction tpl_admin() {
167f8cc712eSAndreas Gohr    global $INFO;
168b8595a66SAndreas Gohr    global $TOC;
169ac7a515fSAndreas Gohr    global $INPUT;
17011e2ce22Schris
171b8595a66SAndreas Gohr    $plugin = null;
172ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
173ac7a515fSAndreas Gohr    if(!empty($class)) {
17411e2ce22Schris        $pluginlist = plugin_list('admin');
17511e2ce22Schris
176ac7a515fSAndreas Gohr        if(in_array($class, $pluginlist)) {
17711e2ce22Schris            // attempt to load the plugin
178ac7a515fSAndreas Gohr            /** @var $plugin DokuWiki_Admin_Plugin */
179a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
18011e2ce22Schris        }
18111e2ce22Schris    }
18211e2ce22Schris
183b8595a66SAndreas Gohr    if($plugin !== null) {
184b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
185b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
186f8cc712eSAndreas Gohr        $plugin->html();
187f8cc712eSAndreas Gohr    } else {
1880470c28fSAndreas Gohr        $admin = new dokuwiki\Ui\Admin();
1890470c28fSAndreas Gohr        $admin->show();
190f8cc712eSAndreas Gohr    }
19154e95700STom N Harris    return true;
192c19fe9c0Sandi}
1936b13307fSandi
1946b13307fSandi/**
1956b13307fSandi * Print the correct HTML meta headers
1966b13307fSandi *
1976b13307fSandi * This has to go into the head section of your template.
1986b13307fSandi *
1996b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
20042ea7f44SGerrit Uitslag *
201ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
202ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
203ac7a515fSAndreas Gohr * @return bool
2046b13307fSandi */
205f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) {
2066b13307fSandi    global $ID;
207d98d4540SBen Coburn    global $REV;
2086b13307fSandi    global $INFO;
20972e0dc37SAndreas Gohr    global $JSINFO;
2106b13307fSandi    global $ACT;
2114bb1b5aeSAndreas Gohr    global $QUERY;
2126b13307fSandi    global $lang;
213dc57ef04Sandi    global $conf;
2149c438d6cSMichael Hamann    global $updateVersion;
215585bf44eSChristopher Smith    /** @var Input $INPUT */
216585bf44eSChristopher Smith    global $INPUT;
2176b13307fSandi
2187bff22c0SAndreas Gohr    // prepare the head array
2197bff22c0SAndreas Gohr    $head = array();
2207bff22c0SAndreas Gohr
221202ac28bSMichael Klier    // prepare seed for js and css
222cd997f93SAndreas Gohr    $tseed   = $updateVersion;
223202ac28bSMichael Klier    $depends = getConfigFiles('main');
22484e76a7eSAndreas Gohr    $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
225cd997f93SAndreas Gohr    foreach($depends as $f) $tseed .= @filemtime($f);
226cd997f93SAndreas Gohr    $tseed   = md5($tseed);
2277bff22c0SAndreas Gohr
2286b13307fSandi    // the usual stuff
2293f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
23063cf4192Ssarehag    if(actionOK('search')) {
231ac7a515fSAndreas Gohr        $head['link'][] = array(
232ac7a515fSAndreas Gohr            'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
233ac7a515fSAndreas Gohr            'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
234ac7a515fSAndreas Gohr        );
23563cf4192Ssarehag    }
23663cf4192Ssarehag
237f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
2387aedde2eSGina Haeussge    if(actionOK('index')) {
239ac7a515fSAndreas Gohr        $head['link'][] = array(
240ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
241ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
242ac7a515fSAndreas Gohr        );
2437aedde2eSGina Haeussge    }
244f96fa415SAndreas Gohr
245*5e0255e3SMichael Große    if (actionOK('manifest')) {
246*5e0255e3SMichael Große        $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
247*5e0255e3SMichael Große    }
248*5e0255e3SMichael Große
249f96fa415SAndreas Gohr    if($alt) {
25054be1338SGerrit Uitslag        if(actionOK('rss')) {
251ac7a515fSAndreas Gohr            $head['link'][] = array(
252ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
253a1288caeSGerrit Uitslag                'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
254ac7a515fSAndreas Gohr            );
255ac7a515fSAndreas Gohr            $head['link'][] = array(
256ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
257a1288caeSGerrit Uitslag                'title'=> $lang['currentns'],
258ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
259ac7a515fSAndreas Gohr            );
26054be1338SGerrit Uitslag        }
261c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
262ac7a515fSAndreas Gohr            $head['link'][] = array(
263ac7a515fSAndreas Gohr                'rel'  => 'edit',
264715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
265ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
266ac7a515fSAndreas Gohr            );
267c35f3875SAndreas Gohr        }
268c35f3875SAndreas Gohr
26954be1338SGerrit Uitslag        if(actionOK('rss') && $ACT == 'search') {
270ac7a515fSAndreas Gohr            $head['link'][] = array(
271ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
272a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
273ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
274ac7a515fSAndreas Gohr            );
2754bb1b5aeSAndreas Gohr        }
276bae36d94SAndreas Gohr
277bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
278ac7a515fSAndreas Gohr            $head['link'][] = array(
279a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
280ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
281ac7a515fSAndreas Gohr            );
282bae36d94SAndreas Gohr        }
283bae36d94SAndreas Gohr
284bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
285ac7a515fSAndreas Gohr            $head['link'][] = array(
286a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
287ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
288ac7a515fSAndreas Gohr            );
289f96fa415SAndreas Gohr        }
290bae36d94SAndreas Gohr    }
2916b13307fSandi
2926b13307fSandi    // setup robot tags apropriate for different modes
2934f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
2946b13307fSandi        if($INFO['exists']) {
2956b13307fSandi            //delay indexing:
296fb9fa88bSAndreas Gohr            if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
2977bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
2986b13307fSandi            } else {
2997bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3006b13307fSandi            }
30101f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
30201f9be51SAnika Henke            if ($ID == $conf['start']) {
30301f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
30401f9be51SAnika Henke            }
30501f9be51SAnika Henke            $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
3066b13307fSandi        } else {
3077bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3086b13307fSandi        }
3097a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3107bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3116b13307fSandi    } else {
3127bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3136b13307fSandi    }
3146b13307fSandi
315831800b8SAndreas Gohr    // set metadata
316831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
317831800b8SAndreas Gohr        // keywords (explicit or implicit)
318bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3197bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
320831800b8SAndreas Gohr        } else {
3217bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
322831800b8SAndreas Gohr        }
323831800b8SAndreas Gohr    }
324831800b8SAndreas Gohr
32578a6aeb1SAndreas Gohr    // load stylesheets
326ac7a515fSAndreas Gohr    $head['link'][] = array(
327ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
328e283bd6cSAnika Henke        'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
329ac7a515fSAndreas Gohr    );
330bad31ae9SAndreas Gohr
3318bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
332463d4a65SAndreas Gohr    $json   = new JSON();
33372e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
334585bf44eSChristopher Smith    if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
33572e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
336c591aabeSAndreas Gohr    }
33772e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
33885f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
3398bbcb611SAndreas Gohr
34061537d47SAndreas Gohr    // load jquery
341fa078663SAndreas Gohr    $jquery = getCdnUrls();
342fa078663SAndreas Gohr    foreach($jquery as $src) {
34361537d47SAndreas Gohr        $head['script'][] = array(
344fa078663SAndreas Gohr            'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src
34561537d47SAndreas Gohr        );
34661537d47SAndreas Gohr    }
34761537d47SAndreas Gohr
34861537d47SAndreas Gohr    // load our javascript dispatcher
349ac7a515fSAndreas Gohr    $head['script'][] = array(
350ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
351e283bd6cSAnika Henke        'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
352ac7a515fSAndreas Gohr    );
3537bff22c0SAndreas Gohr
3547bff22c0SAndreas Gohr    // trigger event here
355016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
35654e95700STom N Harris    return true;
3577bff22c0SAndreas Gohr}
3587bff22c0SAndreas Gohr
3597bff22c0SAndreas Gohr/**
3607bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3617bff22c0SAndreas Gohr *
3627bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3637bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3647bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3657bff22c0SAndreas Gohr *
36642ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
3671304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3687bff22c0SAndreas Gohr *
3697bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
37042ea7f44SGerrit Uitslag *
37142ea7f44SGerrit Uitslag * @param array $data
3727bff22c0SAndreas Gohr */
3737bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
3747bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
375427bf9a2SAndreas Gohr        if($tag == 'script') {
376427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
377427bf9a2SAndreas Gohr        }
3787bff22c0SAndreas Gohr        foreach($inst as $attr) {
3799b48e6a1SGerry Weißbach            if ( empty($attr) ) { continue; }
3807bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
38126afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
382e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
38309f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
384e226efe1SAndreas Gohr                        $attr['_data'].
38509f791c4SDominik Eckelmann                        "\n/*!]]>*/";
386e226efe1SAndreas Gohr
3871304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
3887bff22c0SAndreas Gohr            } else {
3897bff22c0SAndreas Gohr                echo '/>';
3907bff22c0SAndreas Gohr            }
3917bff22c0SAndreas Gohr            echo "\n";
3927bff22c0SAndreas Gohr        }
393427bf9a2SAndreas Gohr        if($tag == 'script') {
394427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
395427bf9a2SAndreas Gohr        }
3967bff22c0SAndreas Gohr    }
3976b13307fSandi}
3986b13307fSandi
3996b13307fSandi/**
4006b13307fSandi * Print a link
4016b13307fSandi *
4025e163278SAndreas Gohr * Just builds a link.
4036b13307fSandi *
4046b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
40542ea7f44SGerrit Uitslag *
40642ea7f44SGerrit Uitslag * @param string $url
40742ea7f44SGerrit Uitslag * @param string $name
40842ea7f44SGerrit Uitslag * @param string $more
40921d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
41021d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
4116b13307fSandi */
4121af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
41301f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4141af98a77SAnika Henke    if($more) $out .= ' '.$more;
4151af98a77SAnika Henke    $out .= ">$name</a>";
4161af98a77SAnika Henke    if($return) return $out;
4171af98a77SAnika Henke    print $out;
41854e95700STom N Harris    return true;
4196b13307fSandi}
4206b13307fSandi
4216b13307fSandi/**
42255efc227SAndreas Gohr * Prints a link to a WikiPage
42355efc227SAndreas Gohr *
42455efc227SAndreas Gohr * Wrapper around html_wikilink
42555efc227SAndreas Gohr *
42655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
42742ea7f44SGerrit Uitslag *
42842ea7f44SGerrit Uitslag * @param string      $id   page id
42942ea7f44SGerrit Uitslag * @param string|null $name the name of the link
43021d806cdSGerrit Uitslag * @return bool true
43155efc227SAndreas Gohr */
4320b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) {
433d317fb5dSAnika Henke    print '<bdi>'.html_wikilink($id, $name).'</bdi>';
43454e95700STom N Harris    return true;
43555efc227SAndreas Gohr}
43655efc227SAndreas Gohr
43755efc227SAndreas Gohr/**
438a3ec5f4aSmatthiasgrimm * get the parent page
439a3ec5f4aSmatthiasgrimm *
440a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
441a3ec5f4aSmatthiasgrimm * returns false if none is available
442a3ec5f4aSmatthiasgrimm *
443377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
44442ea7f44SGerrit Uitslag *
44542ea7f44SGerrit Uitslag * @param string $id page id
44642ea7f44SGerrit Uitslag * @return false|string
447a3ec5f4aSmatthiasgrimm */
448377f9e97SAndreas Gohrfunction tpl_getparent($id) {
449377f9e97SAndreas Gohr    $parent = getNS($id).':';
450377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
451a197105eSmatthiasgrimm    if($parent == $id) {
452a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
453a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
454a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
455377f9e97SAndreas Gohr        if($parent == $id) return false;
456a197105eSmatthiasgrimm    }
457377f9e97SAndreas Gohr    return $parent;
458a3ec5f4aSmatthiasgrimm}
459a3ec5f4aSmatthiasgrimm
460a3ec5f4aSmatthiasgrimm/**
4616b13307fSandi * Print one of the buttons
4626b13307fSandi *
463a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
464a453d131SAdrian Lang * @see    tpl_get_action
465e0c26282SGerrit Uitslag *
466e0c26282SGerrit Uitslag * @param string $type
467e0c26282SGerrit Uitslag * @param bool $return
468e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
469affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
4706b13307fSandi */
4711af98a77SAnika Henkefunction tpl_button($type, $return = false) {
472affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
473a453d131SAdrian Lang    $data = tpl_get_action($type);
474a453d131SAdrian Lang    if($data === false) {
475a453d131SAdrian Lang        return false;
476a453d131SAdrian Lang    } elseif(!is_array($data)) {
477a453d131SAdrian Lang        $out = sprintf($data, 'button');
478409d7af7SAndreas Gohr    } else {
479ac7a515fSAndreas Gohr        /**
480ac7a515fSAndreas Gohr         * @var string $accesskey
481ac7a515fSAndreas Gohr         * @var string $id
482ac7a515fSAndreas Gohr         * @var string $method
483ac7a515fSAndreas Gohr         * @var array  $params
484ac7a515fSAndreas Gohr         */
485a453d131SAdrian Lang        extract($data);
486a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
487a453d131SAdrian Lang            $out = html_topbtn();
488409d7af7SAndreas Gohr        } else {
489a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
490409d7af7SAndreas Gohr        }
491409d7af7SAndreas Gohr    }
4921af98a77SAnika Henke    if($return) return $out;
493a453d131SAdrian Lang    echo $out;
494a453d131SAdrian Lang    return true;
4956b13307fSandi}
4966b13307fSandi
4976b13307fSandi/**
498ed630903Sandi * Like the action buttons but links
499ed630903Sandi *
500a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
501a453d131SAdrian Lang * @see    tpl_get_action
502e0c26282SGerrit Uitslag *
50342ea7f44SGerrit Uitslag * @param string $type    action command
504e0c26282SGerrit Uitslag * @param string $pre     prefix of link
505e0c26282SGerrit Uitslag * @param string $suf     suffix of link
506e0c26282SGerrit Uitslag * @param string $inner   innerHML of link
50721d806cdSGerrit Uitslag * @param bool   $return  if true it returns html, otherwise prints
508e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
509affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
510a453d131SAdrian Lang */
511a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
512affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
513a453d131SAdrian Lang    global $lang;
514a453d131SAdrian Lang    $data = tpl_get_action($type);
515a453d131SAdrian Lang    if($data === false) {
516a453d131SAdrian Lang        return false;
517a453d131SAdrian Lang    } elseif(!is_array($data)) {
518a453d131SAdrian Lang        $out = sprintf($data, 'link');
519a453d131SAdrian Lang    } else {
520ac7a515fSAndreas Gohr        /**
521ac7a515fSAndreas Gohr         * @var string $accesskey
522ac7a515fSAndreas Gohr         * @var string $id
523ac7a515fSAndreas Gohr         * @var string $method
524b1af9014SChristopher Smith         * @var bool   $nofollow
525ac7a515fSAndreas Gohr         * @var array  $params
526becfa414SGerrit Uitslag         * @var string $replacement
527ac7a515fSAndreas Gohr         */
528a453d131SAdrian Lang        extract($data);
529a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
530a453d131SAdrian Lang            $linktarget = $id;
531a453d131SAdrian Lang        } else {
532a453d131SAdrian Lang            $linktarget = wl($id, $params);
533a453d131SAdrian Lang        }
534a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
535becfa414SGerrit Uitslag        if(strpos($caption, '%s')){
536becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
537becfa414SGerrit Uitslag        }
538c7e90e3fSAnika Henke        $akey    = $addTitle = '';
539c7e90e3fSAnika Henke        if($accesskey) {
540c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
541c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
542c7e90e3fSAnika Henke        }
543b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
544ac7a515fSAndreas Gohr        $out = tpl_link(
545ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
546a453d131SAdrian Lang            'class="action '.$type.'" '.
547b1af9014SChristopher Smith                $akey.$rel.
548e0c26282SGerrit Uitslag                'title="'.hsc($caption).$addTitle.'"', true
549ac7a515fSAndreas Gohr        );
550a453d131SAdrian Lang    }
551a453d131SAdrian Lang    if($return) return $out;
552a453d131SAdrian Lang    echo $out;
553a453d131SAdrian Lang    return true;
554a453d131SAdrian Lang}
555a453d131SAdrian Lang
556a453d131SAdrian Lang/**
557a453d131SAdrian Lang * Check the actions and get data for buttons and links
558ed630903Sandi *
559ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
560a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
561a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
562e0c26282SGerrit Uitslag *
563ac7a515fSAndreas Gohr * @param string $type
564ac7a515fSAndreas Gohr * @return array|bool|string
565affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
566ed630903Sandi */
567a453d131SAdrian Langfunction tpl_get_action($type) {
568affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
569a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
5704c4b65c8SMichael Hamann    if($type == 'subscription') $type = 'subscribe';
5714887c154SAndreas Gohr    if($type == 'img_backto') $type = 'imgBackto';
572409d7af7SAndreas Gohr
5734887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
5744887c154SAndreas Gohr    if(class_exists($class)) {
5754887c154SAndreas Gohr        try {
5764887c154SAndreas Gohr            /** @var \dokuwiki\Menu\Item\AbstractItem $item */
5774887c154SAndreas Gohr            $item = new $class;
5784887c154SAndreas Gohr            $data = $item->getLegacyData();
5797b4365a7SGerrit Uitslag            $unknown = false;
5804887c154SAndreas Gohr        } catch(\RuntimeException $ignored) {
5814887c154SAndreas Gohr            return false;
582b8a111f5SMichael Klier        }
583ed630903Sandi    } else {
5844887c154SAndreas Gohr        global $ID;
5854887c154SAndreas Gohr        $data = array(
5864887c154SAndreas Gohr            'accesskey' => null,
5874887c154SAndreas Gohr            'type' => $type,
5884887c154SAndreas Gohr            'id' => $ID,
5894887c154SAndreas Gohr            'method' => 'get',
5904887c154SAndreas Gohr            'params' => array('do' => $type),
5914887c154SAndreas Gohr            'nofollow' => true,
5924887c154SAndreas Gohr            'replacement' => '',
593becfa414SGerrit Uitslag        );
5947b4365a7SGerrit Uitslag        $unknown = true;
595ed630903Sandi    }
5967b4365a7SGerrit Uitslag
5973131073dSGerrit Uitslag    $evt = new Doku_Event('TPL_ACTION_GET', $data);
5987b4365a7SGerrit Uitslag    if($evt->advise_before()) {
5997b4365a7SGerrit Uitslag        //handle unknown types
6007b4365a7SGerrit Uitslag        if($unknown) {
60138d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6027b4365a7SGerrit Uitslag        }
6037b4365a7SGerrit Uitslag    }
6047b4365a7SGerrit Uitslag    $evt->advise_after();
6057b4365a7SGerrit Uitslag    unset($evt);
6067b4365a7SGerrit Uitslag
6077b4365a7SGerrit Uitslag    return $data;
608ed630903Sandi}
609ed630903Sandi
610ed630903Sandi/**
61101f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
61201f17825SAnika Henke *
61301f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
61442ea7f44SGerrit Uitslag *
61542ea7f44SGerrit Uitslag * @param string        $type action command
616ac7a515fSAndreas Gohr * @param bool          $link link or form button?
617e0c26282SGerrit Uitslag * @param string|bool   $wrapper HTML element wrapper
618ac7a515fSAndreas Gohr * @param bool          $return return or print
619ac7a515fSAndreas Gohr * @param string        $pre prefix for links
620ac7a515fSAndreas Gohr * @param string        $suf suffix for links
621ac7a515fSAndreas Gohr * @param string        $inner inner HTML for links
622ac7a515fSAndreas Gohr * @return bool|string
623affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
62401f17825SAnika Henke */
625ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
626affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
62701f17825SAnika Henke    $out = '';
628ac7a515fSAndreas Gohr    if($link) {
629e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
630ac7a515fSAndreas Gohr    } else {
631e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
632ac7a515fSAndreas Gohr    }
63301f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
63401f17825SAnika Henke
63501f17825SAnika Henke    if($return) return $out;
63601f17825SAnika Henke    print $out;
63701f17825SAnika Henke    return $out ? true : false;
63801f17825SAnika Henke}
63901f17825SAnika Henke
64001f17825SAnika Henke/**
6416b13307fSandi * Print the search form
6426b13307fSandi *
64372645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
64472645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
64572645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
64672645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
64772645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
64872645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
64972645b75SAndreas Gohr *
6506b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
65142ea7f44SGerrit Uitslag *
652ac7a515fSAndreas Gohr * @param bool $ajax
653ac7a515fSAndreas Gohr * @param bool $autocomplete
654ac7a515fSAndreas Gohr * @return bool
6556b13307fSandi */
65672645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
6576b13307fSandi    global $lang;
658c1e3b7d9Smatthiasgrimm    global $ACT;
659ad4aaef7SAndreas Gohr    global $QUERY;
660c1e3b7d9Smatthiasgrimm
661670ff54eSchris    // don't print the search form if search action has been disabled
66264276bbcSarbrk1    if(!actionOK('search')) return false;
663670ff54eSchris
6649805efa0SAnika Henke    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">';
6656b13307fSandi    print '<input type="hidden" name="do" value="search" />';
666c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
667ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
668001ea14eSRainbow Spike    print 'placeholder="'.$lang['btn_search'].'" ';
66972645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
67007493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
671ae614416SAnika Henke    print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>';
67224a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6734beabca9SAnika Henke    print '</div></form>';
67454e95700STom N Harris    return true;
6756b13307fSandi}
6766b13307fSandi
6776b13307fSandi/**
6786b13307fSandi * Print the breadcrumbs trace
6796b13307fSandi *
6806b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
68142ea7f44SGerrit Uitslag *
682ac7a515fSAndreas Gohr * @param string $sep Separator between entries
683ac7a515fSAndreas Gohr * @return bool
6846b13307fSandi */
685e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') {
6866b13307fSandi    global $lang;
6876b13307fSandi    global $conf;
6886b13307fSandi
6896b13307fSandi    //check if enabled
690359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
6916b13307fSandi
6926b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
693265e3787Sandi
6942979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
695265e3787Sandi
69640eb54bbSjan    //render crumbs, highlight the last one
697fde860beSGerrit Uitslag    print '<span class="bchead">'.$lang['breadcrumb'].'</span>';
69840eb54bbSjan    $last = count($crumbs);
69940eb54bbSjan    $i    = 0;
700a77f5846Sjan    foreach($crumbs as $id => $name) {
70140eb54bbSjan        $i++;
7022979a10bSKatriel Traum        echo $crumbs_sep;
70392795d04Sandi        if($i == $last) print '<span class="curid">';
704d317fb5dSAnika Henke        print '<bdi>';
705e26fd1eeSAndreas Gohr        tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"');
706d317fb5dSAnika Henke        print '</bdi>';
70792795d04Sandi        if($i == $last) print '</span>';
7086b13307fSandi    }
70954e95700STom N Harris    return true;
7106b13307fSandi}
7116b13307fSandi
7126b13307fSandi/**
7131734437eSandi * Hierarchical breadcrumbs
7141734437eSandi *
71531e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7161734437eSandi * It only makes sense with a deep site structure.
7171734437eSandi *
7181734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7196bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
72031e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
721f46c9e83SAnika Henke * @author <fredrik@averpil.com>
72208d7a575SAndreas Gohr * @todo   May behave strangely in RTL languages
72342ea7f44SGerrit Uitslag *
724ac7a515fSAndreas Gohr * @param string $sep Separator between entries
725ac7a515fSAndreas Gohr * @return bool
7261734437eSandi */
72708d7a575SAndreas Gohrfunction tpl_youarehere($sep = ' » ') {
7281734437eSandi    global $conf;
7291734437eSandi    global $ID;
7301734437eSandi    global $lang;
7311734437eSandi
73231e187f8SSean Coates    // check if enabled
73354e95700STom N Harris    if(!$conf['youarehere']) return false;
7341734437eSandi
7351734437eSandi    $parts = explode(':', $ID);
736796bafb3SAndreas Gohr    $count = count($parts);
7371734437eSandi
73808d7a575SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].' </span>';
7393940c519SMark
74008d7a575SAndreas Gohr    // always print the startpage
74108d7a575SAndreas Gohr    echo '<span class="home">';
74208d7a575SAndreas Gohr    tpl_pagelink(':'.$conf['start']);
74308d7a575SAndreas Gohr    echo '</span>';
744796bafb3SAndreas Gohr
745796bafb3SAndreas Gohr    // print intermediate namespace links
746796bafb3SAndreas Gohr    $part = '';
747796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
748796bafb3SAndreas Gohr        $part .= $parts[$i].':';
749796bafb3SAndreas Gohr        $page = $part;
750796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
751796bafb3SAndreas Gohr
75208d7a575SAndreas Gohr        // output
75308d7a575SAndreas Gohr        echo $sep;
75408d7a575SAndreas Gohr        tpl_pagelink($page);
75531e187f8SSean Coates    }
7561734437eSandi
757796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
758e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
75908d7a575SAndreas Gohr    if(isset($page) && $page == $part.$parts[$i]) return true;
760796bafb3SAndreas Gohr    $page = $part.$parts[$i];
76108d7a575SAndreas Gohr    if($page == $conf['start']) return true;
76208d7a575SAndreas Gohr    echo $sep;
76308d7a575SAndreas Gohr    tpl_pagelink($page);
76454e95700STom N Harris    return true;
7651734437eSandi}
7661734437eSandi
7671734437eSandi/**
7686b13307fSandi * Print info if the user is logged in
769a2488c3cSMatthias Grimm * and show full name in that case
7706b13307fSandi *
7716b13307fSandi * Could be enhanced with a profile link in future?
7726b13307fSandi *
7736b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
77442ea7f44SGerrit Uitslag *
775ac7a515fSAndreas Gohr * @return bool
7766b13307fSandi */
7776b13307fSandifunction tpl_userinfo() {
7786b13307fSandi    global $lang;
779585bf44eSChristopher Smith    /** @var Input $INPUT */
780585bf44eSChristopher Smith    global $INPUT;
781585bf44eSChristopher Smith
782585bf44eSChristopher Smith    if($INPUT->server->str('REMOTE_USER')) {
783fde860beSGerrit Uitslag        print $lang['loggedinas'].' '.userlink();
78454e95700STom N Harris        return true;
78554e95700STom N Harris    }
78654e95700STom N Harris    return false;
7876b13307fSandi}
7886b13307fSandi
7896b13307fSandi/**
7906b13307fSandi * Print some info about the current page
7916b13307fSandi *
7926b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
79342ea7f44SGerrit Uitslag *
794ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
795ac7a515fSAndreas Gohr * @return bool|string
7966b13307fSandi */
7974b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
7986b13307fSandi    global $conf;
7996b13307fSandi    global $lang;
8006b13307fSandi    global $INFO;
801c6e92a3cSDavid Lorentsen    global $ID;
802c6e92a3cSDavid Lorentsen
803c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
804ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
805ac7a515fSAndreas Gohr        return false;
806ac7a515fSAndreas Gohr    }
8076b13307fSandi
8086b13307fSandi    // prepare date and path
8096b13307fSandi    $fn = $INFO['filepath'];
8106b13307fSandi    if(!$conf['fullpath']) {
811613bca54SAndreas Gohr        if($INFO['rev']) {
812c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'].'/', '', $fn);
8136b13307fSandi        } else {
814c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'].'/', '', $fn);
8156b13307fSandi        }
8166b13307fSandi    }
817bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
818f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
8196b13307fSandi
820faecdfdfSAndreas Gohr    // print it
821faecdfdfSAndreas Gohr    if($INFO['exists']) {
8224b0d3916SAndreas Gohr        $out = '';
823d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
824e260f93bSAnika Henke        $out .= ' · ';
8254b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
826fde860beSGerrit Uitslag        $out .= ' ';
8274b0d3916SAndreas Gohr        $out .= $date;
8286b13307fSandi        if($INFO['editor']) {
8294b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
830d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
8315aa52fafSBen Coburn        } else {
8324b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
8336b13307fSandi        }
8346b13307fSandi        if($INFO['locked']) {
835e260f93bSAnika Henke            $out .= ' · ';
8364b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
837fde860beSGerrit Uitslag            $out .= ' ';
838d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
8396b13307fSandi        }
8404b0d3916SAndreas Gohr        if($ret) {
8414b0d3916SAndreas Gohr            return $out;
8424b0d3916SAndreas Gohr        } else {
8434b0d3916SAndreas Gohr            echo $out;
84454e95700STom N Harris            return true;
8456b13307fSandi        }
8464b0d3916SAndreas Gohr    }
84754e95700STom N Harris    return false;
8486b13307fSandi}
8496b13307fSandi
850820fa24bSandi/**
851a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
85287c434ceSAndreas Gohr *
85387c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
854a6598f23SBen Coburn * the given ID is used.
85587c434ceSAndreas Gohr *
85687c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
85742ea7f44SGerrit Uitslag *
858ac7a515fSAndreas Gohr * @param string $id page id
859ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
860ac7a515fSAndreas Gohr * @return bool|string
86187c434ceSAndreas Gohr */
862a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
863c248bda1SChristopher Smith    global $ACT, $INPUT, $conf, $lang;
864fffeeafeSChristopher Smith
86587c434ceSAndreas Gohr    if(is_null($id)) {
86687c434ceSAndreas Gohr        global $ID;
86787c434ceSAndreas Gohr        $id = $ID;
86887c434ceSAndreas Gohr    }
86987c434ceSAndreas Gohr
87087c434ceSAndreas Gohr    $name = $id;
871fe9ec250SChris Smith    if(useHeading('navigation')) {
872fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
873fffeeafeSChristopher Smith        if($first_heading) $name = $first_heading;
874fffeeafeSChristopher Smith    }
875fffeeafeSChristopher Smith
876fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
877fffeeafeSChristopher Smith    switch ($ACT) {
878fffeeafeSChristopher Smith        // admin functions
879fffeeafeSChristopher Smith        case 'admin' :
880fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
881fffeeafeSChristopher Smith            // try to get the plugin name
882a61966c5SChristopher Smith            /** @var $plugin DokuWiki_Admin_Plugin */
883a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()){
884c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
885a61966c5SChristopher Smith                $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
886fffeeafeSChristopher Smith            }
887fffeeafeSChristopher Smith            break;
888fffeeafeSChristopher Smith
889fffeeafeSChristopher Smith        // user functions
890fffeeafeSChristopher Smith        case 'login' :
891fffeeafeSChristopher Smith        case 'profile' :
892fffeeafeSChristopher Smith        case 'register' :
893fffeeafeSChristopher Smith        case 'resendpwd' :
894fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
895fffeeafeSChristopher Smith            break;
896fffeeafeSChristopher Smith
897fffeeafeSChristopher Smith         // wiki functions
898fffeeafeSChristopher Smith        case 'search' :
899fffeeafeSChristopher Smith        case 'index' :
900fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
901fffeeafeSChristopher Smith            break;
902fffeeafeSChristopher Smith
903fffeeafeSChristopher Smith        // page functions
904fffeeafeSChristopher Smith        case 'edit' :
905fffeeafeSChristopher Smith            $page_title = "✎ ".$name;
906fffeeafeSChristopher Smith            break;
907fffeeafeSChristopher Smith
908fffeeafeSChristopher Smith        case 'revisions' :
909fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
910fffeeafeSChristopher Smith            break;
911fffeeafeSChristopher Smith
912fffeeafeSChristopher Smith        case 'backlink' :
913fffeeafeSChristopher Smith        case 'recent' :
914fffeeafeSChristopher Smith        case 'subscribe' :
915fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_'.$ACT];
916fffeeafeSChristopher Smith            break;
917fffeeafeSChristopher Smith
918fffeeafeSChristopher Smith        default : // SHOW and anything else not included
919fffeeafeSChristopher Smith            $page_title = $name;
92087c434ceSAndreas Gohr    }
921a6598f23SBen Coburn
922a6598f23SBen Coburn    if($ret) {
923fffeeafeSChristopher Smith        return hsc($page_title);
924a6598f23SBen Coburn    } else {
925fffeeafeSChristopher Smith        print hsc($page_title);
92654e95700STom N Harris        return true;
92787c434ceSAndreas Gohr    }
928a6598f23SBen Coburn}
929340756e4Sandi
93055efc227SAndreas Gohr/**
93155efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
93255efc227SAndreas Gohr *
93355efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
93455efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
93555efc227SAndreas Gohr *
93655efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
93755efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
93855efc227SAndreas Gohr * to the names of the latter one)
93955efc227SAndreas Gohr *
9403df72098SAndreas Gohr * Only allowed in: detail.php
94155efc227SAndreas Gohr *
94255efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
94342ea7f44SGerrit Uitslag *
94421d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
945ac7a515fSAndreas Gohr * @param string       $alt  alternative output if no data was found
946e0c26282SGerrit Uitslag * @param null|string  $src  the image src, uses global $SRC if not given
947ac7a515fSAndreas Gohr * @return string
94855efc227SAndreas Gohr */
9493df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
95055efc227SAndreas Gohr    // Init Exif Reader
95155efc227SAndreas Gohr    global $SRC;
9523df72098SAndreas Gohr
9533df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
9543df72098SAndreas Gohr
95555efc227SAndreas Gohr    static $meta = null;
9563df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
95755efc227SAndreas Gohr    if($meta === false) return $alt;
95888945224SChristopher Smith    $info = cleanText($meta->getField($tags));
95955efc227SAndreas Gohr    if($info == false) return $alt;
96055efc227SAndreas Gohr    return $info;
96155efc227SAndreas Gohr}
96255efc227SAndreas Gohr
96355efc227SAndreas Gohr/**
964becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
965becfa414SGerrit Uitslag *
966becfa414SGerrit Uitslag * @return string html of description list
967becfa414SGerrit Uitslag */
968becfa414SGerrit Uitslagfunction tpl_img_meta() {
969becfa414SGerrit Uitslag    global $lang;
970becfa414SGerrit Uitslag
971becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
972becfa414SGerrit Uitslag
973becfa414SGerrit Uitslag    echo '<dl>';
974becfa414SGerrit Uitslag    foreach($tags as $tag) {
975becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
976fde860beSGerrit Uitslag        if(!$label) $label = $tag['langkey'] . ':';
977becfa414SGerrit Uitslag
978fde860beSGerrit Uitslag        echo '<dt>'.$label.'</dt><dd>';
979becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
980becfa414SGerrit Uitslag            echo dformat($tag['value']);
981becfa414SGerrit Uitslag        } else {
982becfa414SGerrit Uitslag            echo hsc($tag['value']);
983becfa414SGerrit Uitslag        }
984becfa414SGerrit Uitslag        echo '</dd>';
985becfa414SGerrit Uitslag    }
986becfa414SGerrit Uitslag    echo '</dl>';
987becfa414SGerrit Uitslag}
988becfa414SGerrit Uitslag
989becfa414SGerrit Uitslag/**
990becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
991becfa414SGerrit Uitslag *
992becfa414SGerrit Uitslag * @return array with arrays containing the entries:
993becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
994becfa414SGerrit Uitslag *   - string type     type of value
995becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
996becfa414SGerrit Uitslag */
997becfa414SGerrit Uitslagfunction tpl_get_img_meta() {
998becfa414SGerrit Uitslag
999becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1000becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
100179e79377SAndreas Gohr        if(file_exists($config_file)) {
1002becfa414SGerrit Uitslag            include($config_file);
1003becfa414SGerrit Uitslag        }
1004becfa414SGerrit Uitslag    }
1005becfa414SGerrit Uitslag    /** @var array $fields the included array with metadata */
1006becfa414SGerrit Uitslag
1007becfa414SGerrit Uitslag    $tags = array();
1008becfa414SGerrit Uitslag    foreach($fields as $tag){
1009becfa414SGerrit Uitslag        $t = array();
1010becfa414SGerrit Uitslag        if (!empty($tag[0])) {
1011becfa414SGerrit Uitslag            $t = array($tag[0]);
1012becfa414SGerrit Uitslag        }
1013becfa414SGerrit Uitslag        if(is_array($tag[3])) {
1014becfa414SGerrit Uitslag            $t = array_merge($t,$tag[3]);
1015becfa414SGerrit Uitslag        }
1016becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1017becfa414SGerrit Uitslag        if ($value) {
1018becfa414SGerrit Uitslag            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1019becfa414SGerrit Uitslag        }
1020becfa414SGerrit Uitslag    }
1021becfa414SGerrit Uitslag    return $tags;
1022becfa414SGerrit Uitslag}
1023becfa414SGerrit Uitslag
1024becfa414SGerrit Uitslag/**
102555efc227SAndreas Gohr * Prints the image with a link to the full sized version
102655efc227SAndreas Gohr *
102755efc227SAndreas Gohr * Only allowed in: detail.php
1028a02d2933SAndreas Gohr *
1029ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1030a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1031a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1032a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1033a02d2933SAndreas Gohr * @param $params array  - additional image attributes
103442ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
103555efc227SAndreas Gohr */
1036a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
103755efc227SAndreas Gohr    global $IMG;
1038585bf44eSChristopher Smith    /** @var Input $INPUT */
1039ac7a515fSAndreas Gohr    global $INPUT;
10405c2eed9aSlisps    global $REV;
104165d3a5dbSAndreas Gohr    $w = (int) tpl_img_getTag('File.Width');
104265d3a5dbSAndreas Gohr    $h = (int) tpl_img_getTag('File.Height');
104355efc227SAndreas Gohr
104455efc227SAndreas Gohr    //resize to given max values
104523a34783SAndreas Gohr    $ratio = 1;
104623a34783SAndreas Gohr    if($w >= $h) {
1047f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
104855efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1049f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
105055efc227SAndreas Gohr            $ratio = $maxheight / $h;
105155efc227SAndreas Gohr        }
105255efc227SAndreas Gohr    } else {
1053f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
105455efc227SAndreas Gohr            $ratio = $maxheight / $h;
1055f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
105655efc227SAndreas Gohr            $ratio = $maxwidth / $w;
105755efc227SAndreas Gohr        }
105855efc227SAndreas Gohr    }
105955efc227SAndreas Gohr    if($ratio) {
106055efc227SAndreas Gohr        $w = floor($ratio * $w);
106155efc227SAndreas Gohr        $h = floor($ratio * $h);
106255efc227SAndreas Gohr    }
106355efc227SAndreas Gohr
10646de3759aSAndreas Gohr    //prepare URLs
10655c2eed9aSlisps    $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
10665c2eed9aSlisps    $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
106755efc227SAndreas Gohr
10682684e50aSAndreas Gohr    //prepare attributes
106955efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1070a02d2933SAndreas Gohr    if(is_null($params)) {
10712684e50aSAndreas Gohr        $p = array();
1072a02d2933SAndreas Gohr    } else {
1073a02d2933SAndreas Gohr        $p = $params;
1074a02d2933SAndreas Gohr    }
10752684e50aSAndreas Gohr    if($w) $p['width'] = $w;
10762684e50aSAndreas Gohr    if($h) $p['height'] = $h;
10772684e50aSAndreas Gohr    $p['class'] = 'img_detail';
10782684e50aSAndreas Gohr    if($alt) {
10792684e50aSAndreas Gohr        $p['alt']   = $alt;
10802684e50aSAndreas Gohr        $p['title'] = $alt;
10812684e50aSAndreas Gohr    } else {
10822684e50aSAndreas Gohr        $p['alt'] = '';
10832684e50aSAndreas Gohr    }
1084a02d2933SAndreas Gohr    $p['src'] = $src;
108555efc227SAndreas Gohr
1086a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1087a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1088a02d2933SAndreas Gohr}
1089a02d2933SAndreas Gohr
1090a02d2933SAndreas Gohr/**
1091a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1092ac7a515fSAndreas Gohr *
1093ac7a515fSAndreas Gohr * @param array $data
1094ac7a515fSAndreas Gohr * @return bool
1095a02d2933SAndreas Gohr */
1096ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
109759f3611bSAnika Henke    global $lang;
1098a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1099a02d2933SAndreas Gohr
110059f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1101a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1102a02d2933SAndreas Gohr    if($data['url']) print '</a>';
110354e95700STom N Harris    return true;
110455efc227SAndreas Gohr}
110555efc227SAndreas Gohr
11067367b368SAndreas Gohr/**
1107881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11087367b368SAndreas Gohr *
11097367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11107367b368SAndreas Gohr * template
1111ac7a515fSAndreas Gohr *
1112ac7a515fSAndreas Gohr * @return bool
11137367b368SAndreas Gohr */
11147367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11157367b368SAndreas Gohr    global $ID;
11161dad36f5SAndreas Gohr
11177367b368SAndreas Gohr    $p           = array();
1118b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1119e68c51baSAndreas Gohr        '&'.time();
1120881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11217367b368SAndreas Gohr    $p['height'] = 1;
11227367b368SAndreas Gohr    $p['alt']    = '';
11237367b368SAndreas Gohr    $att         = buildAttributes($p);
11247367b368SAndreas Gohr    print "<img $att />";
112554e95700STom N Harris    return true;
11267367b368SAndreas Gohr}
11277367b368SAndreas Gohr
112878d4e784SEsther Brunner/**
112978d4e784SEsther Brunner * tpl_getConf($id)
113078d4e784SEsther Brunner *
113178d4e784SEsther Brunner * use this function to access template configuration variables
1132ac7a515fSAndreas Gohr *
113317448fb8SChristopher Smith * @param string $id      name of the value to access
113417448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
113517448fb8SChristopher Smith * @return mixed
113678d4e784SEsther Brunner */
113717448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
113878d4e784SEsther Brunner    global $conf;
113917566ac6SAdrian Lang    static $tpl_configloaded = false;
114078d4e784SEsther Brunner
114178d4e784SEsther Brunner    $tpl = $conf['template'];
114278d4e784SEsther Brunner
114378d4e784SEsther Brunner    if(!$tpl_configloaded) {
114478d4e784SEsther Brunner        $tconf = tpl_loadConfig();
114578d4e784SEsther Brunner        if($tconf !== false) {
114678d4e784SEsther Brunner            foreach($tconf as $key => $value) {
114778d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
114878d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
114978d4e784SEsther Brunner            }
115078d4e784SEsther Brunner            $tpl_configloaded = true;
115178d4e784SEsther Brunner        }
115278d4e784SEsther Brunner    }
115378d4e784SEsther Brunner
115417448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
115578d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
115678d4e784SEsther Brunner    }
115778d4e784SEsther Brunner
115817448fb8SChristopher Smith    return $notset;
115917448fb8SChristopher Smith}
116017448fb8SChristopher Smith
116178d4e784SEsther Brunner/**
116278d4e784SEsther Brunner * tpl_loadConfig()
1163ac7a515fSAndreas Gohr *
116478d4e784SEsther Brunner * reads all template configuration variables
116578d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1166ac7a515fSAndreas Gohr *
1167ac7a515fSAndreas Gohr * @return array
116878d4e784SEsther Brunner */
116978d4e784SEsther Brunnerfunction tpl_loadConfig() {
117078d4e784SEsther Brunner
1171c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
117278d4e784SEsther Brunner    $conf = array();
117378d4e784SEsther Brunner
117479e79377SAndreas Gohr    if(!file_exists($file)) return false;
117578d4e784SEsther Brunner
117678d4e784SEsther Brunner    // load default config file
117778d4e784SEsther Brunner    include($file);
117878d4e784SEsther Brunner
117978d4e784SEsther Brunner    return $conf;
118078d4e784SEsther Brunner}
118178d4e784SEsther Brunner
118217566ac6SAdrian Lang// language methods
118317566ac6SAdrian Lang/**
118417566ac6SAdrian Lang * tpl_getLang($id)
118517566ac6SAdrian Lang *
118617566ac6SAdrian Lang * use this function to access template language variables
118742ea7f44SGerrit Uitslag *
118842ea7f44SGerrit Uitslag * @param string $id key of language string
118942ea7f44SGerrit Uitslag * @return string
119017566ac6SAdrian Lang */
119117566ac6SAdrian Langfunction tpl_getLang($id) {
119217566ac6SAdrian Lang    static $lang = array();
119317566ac6SAdrian Lang
119417566ac6SAdrian Lang    if(count($lang) === 0) {
1195dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1196dd7a6159SGerrit Uitslag
1197c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
119817566ac6SAdrian Lang
119917566ac6SAdrian Lang        $lang = array();
120017566ac6SAdrian Lang
120117566ac6SAdrian Lang        // don't include once
120217566ac6SAdrian Lang        @include($path . 'en/lang.php');
1203dd7a6159SGerrit Uitslag        foreach($config_cascade['lang']['template'] as $config_file) {
120479e79377SAndreas Gohr            if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1205dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1206dd7a6159SGerrit Uitslag            }
120717566ac6SAdrian Lang        }
120817566ac6SAdrian Lang
1209dd7a6159SGerrit Uitslag        if($conf['lang'] != 'en') {
1210dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1211dd7a6159SGerrit Uitslag            foreach($config_cascade['lang']['template'] as $config_file) {
121279e79377SAndreas Gohr                if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1213dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1214dd7a6159SGerrit Uitslag                }
1215dd7a6159SGerrit Uitslag            }
1216dd7a6159SGerrit Uitslag        }
121717566ac6SAdrian Lang    }
121817566ac6SAdrian Lang    return $lang[$id];
121917566ac6SAdrian Lang}
122017566ac6SAdrian Lang
12213df72098SAndreas Gohr/**
1222c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1223e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1224e8ec13b9SKlap-in *
1225e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1226e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1227e8ec13b9SKlap-in */
1228e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1229c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1230e8ec13b9SKlap-in}
1231e8ec13b9SKlap-in
1232e8ec13b9SKlap-in/**
1233c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
123442ea7f44SGerrit Uitslag *
123542ea7f44SGerrit Uitslag * @param string $id id of localized text
123642ea7f44SGerrit Uitslag * @return string wiki text
1237e8ec13b9SKlap-in */
1238c5c17fdaSKlap-infunction tpl_localeFN($id) {
1239e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1240e8ec13b9SKlap-in    global $conf;
124138fb1fc7SGerrit Uitslag    $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
124279e79377SAndreas Gohr    if (!file_exists($file)){
1243e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
124479e79377SAndreas Gohr        if(!file_exists($file)){
1245e8ec13b9SKlap-in            //fall back to english
1246e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1247e8ec13b9SKlap-in        }
1248e8ec13b9SKlap-in    }
1249e8ec13b9SKlap-in    return $file;
1250e8ec13b9SKlap-in}
1251e8ec13b9SKlap-in
1252e8ec13b9SKlap-in/**
12537abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
12543df72098SAndreas Gohr *
12553df72098SAndreas Gohr * Depending on the user's actions this may be a list of
12563df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
12573df72098SAndreas Gohr * a message of referencing pages
12583df72098SAndreas Gohr *
12593df72098SAndreas Gohr * Only allowed in mediamanager.php
12603df72098SAndreas Gohr *
1261c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1262c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
126342ea7f44SGerrit Uitslag * @param string $sort
12648702de7fSGerrit Uitslag *
12653df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
12663df72098SAndreas Gohr */
126700e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
12683df72098SAndreas Gohr    global $IMG;
12693df72098SAndreas Gohr    global $AUTH;
12703df72098SAndreas Gohr    global $INUSE;
12713df72098SAndreas Gohr    global $NS;
12723df72098SAndreas Gohr    global $JUMPTO;
1273585bf44eSChristopher Smith    /** @var Input $INPUT */
1274ac7a515fSAndreas Gohr    global $INPUT;
12753df72098SAndreas Gohr
1276ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1277c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1278c182313eSAndreas Gohr
1279c182313eSAndreas Gohr    if(!$do) {
1280ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1281c182313eSAndreas Gohr            $do = 'metaform';
1282c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1283c182313eSAndreas Gohr            $do = 'filesinuse';
1284c182313eSAndreas Gohr        } else {
1285c182313eSAndreas Gohr            $do = 'filelist';
1286c182313eSAndreas Gohr        }
1287c182313eSAndreas Gohr    }
1288c182313eSAndreas Gohr
1289c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1290c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1291c182313eSAndreas Gohr    $data = array('do' => $do);
1292c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1293c182313eSAndreas Gohr    if($evt->advise_before()) {
1294c182313eSAndreas Gohr        $do = $data['do'];
129530fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1296c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1297c182313eSAndreas Gohr        } elseif($do == 'filelist') {
129800e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1299c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1300ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1301c182313eSAndreas Gohr        } else {
1302c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1303c182313eSAndreas Gohr        }
1304c182313eSAndreas Gohr    }
1305c182313eSAndreas Gohr    $evt->advise_after();
1306c182313eSAndreas Gohr    unset($evt);
1307c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1308c182313eSAndreas Gohr
13093df72098SAndreas Gohr}
13103df72098SAndreas Gohr
13113df72098SAndreas Gohr/**
1312d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1313d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1314d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1315d9162c6cSKate Arzamastseva *
1316d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1317d9162c6cSKate Arzamastseva */
1318035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1319d9162c6cSKate Arzamastseva    global $AUTH;
1320d9162c6cSKate Arzamastseva    global $NS;
1321d9162c6cSKate Arzamastseva    global $JUMPTO;
132295b451bcSAdrian Lang    global $lang;
1323585bf44eSChristopher Smith    /** @var Input $INPUT */
1324ac7a515fSAndreas Gohr    global $INPUT;
1325d9162c6cSKate Arzamastseva
1326ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1327e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1328ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1329d9162c6cSKate Arzamastseva
133094add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
133195b451bcSAdrian Lang
1332ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
133323846a98SKate Arzamastseva
133494add303SAnika Henke    echo '<div class="panelHeader">'.NL;
133595b451bcSAdrian Lang    echo '<h3>';
1336026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1337c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
133894add303SAnika Henke    echo '</h3>'.NL;
133995b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
134095b451bcSAdrian Lang        media_tab_files_options();
134123846a98SKate Arzamastseva    }
134294add303SAnika Henke    echo '</div>'.NL;
1343d9162c6cSKate Arzamastseva
134494add303SAnika Henke    echo '<div class="panelContent">'.NL;
134595b451bcSAdrian Lang    if($opened_tab == 'files') {
134695b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
134795b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
134895b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
134995b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
135095b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
135195b451bcSAdrian Lang    }
135294add303SAnika Henke    echo '</div>'.NL;
1353d9162c6cSKate Arzamastseva}
1354d9162c6cSKate Arzamastseva
1355d9162c6cSKate Arzamastseva/**
1356d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1357d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1358d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1359d9162c6cSKate Arzamastseva * list of file revisions
1360d9162c6cSKate Arzamastseva *
1361d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1362f50a239bSTakamura *
1363f50a239bSTakamura * @param string $image
1364f50a239bSTakamura * @param boolean $rev
1365d9162c6cSKate Arzamastseva */
1366035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1367e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1368585bf44eSChristopher Smith    /** @var Input $INPUT */
1369585bf44eSChristopher Smith    global $INPUT;
1370d9162c6cSKate Arzamastseva
137192cac9a9SKate Arzamastseva    $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1372ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
13736dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1374e8a2a143SMichael Hamann    $ns = getNS($image);
1375ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
13761eeeced2SKate Arzamastseva
1377ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1378e5d185e1SKate Arzamastseva
1379e5d185e1SKate Arzamastseva    $tab_array = array('view');
1380ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1381e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1382e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1383e5d185e1SKate Arzamastseva    }
1384e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1385e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1386e5d185e1SKate Arzamastseva    }
1387e5d185e1SKate Arzamastseva
1388e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1389ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
139023846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1391d9162c6cSKate Arzamastseva
1392ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
139323846a98SKate Arzamastseva
139459f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1395ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
139695b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
139795b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
1398750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
1399750a0b51SMichael Große    $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
140008317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
140108317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
140208317413SAdrian Lang    } else {
1403026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
140408317413SAdrian Lang    }
1405b8a84c03SAndreas Gohr
140694add303SAnika Henke    echo '</h3></div>'.NL;
140795b451bcSAdrian Lang
140894add303SAnika Henke    echo '<div class="panelContent">'.NL;
140995b451bcSAdrian Lang
141023846a98SKate Arzamastseva    if($opened_tab == 'view') {
1411e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
141223846a98SKate Arzamastseva
141392cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
1414e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
141523846a98SKate Arzamastseva
1416e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1417e8a2a143SMichael Hamann        media_tab_history($image, $ns);
141823846a98SKate Arzamastseva    }
141995b451bcSAdrian Lang
142094add303SAnika Henke    echo '</div>'.NL;
1421d9162c6cSKate Arzamastseva}
1422d9162c6cSKate Arzamastseva
1423d9162c6cSKate Arzamastseva/**
14247abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
14253df72098SAndreas Gohr *
14263df72098SAndreas Gohr * Only allowed in mediamanager.php
14273df72098SAndreas Gohr *
14283df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14293df72098SAndreas Gohr */
1430fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14313df72098SAndreas Gohr    global $NS;
143223846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14333df72098SAndreas Gohr    media_nstree($NS);
14343df72098SAndreas Gohr    ptln('</div>');
14353df72098SAndreas Gohr}
14363df72098SAndreas Gohr
1437a00de5b5SAndreas Gohr/**
1438a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1439a00de5b5SAndreas Gohr *
1440a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1441a00de5b5SAndreas Gohr *
1442a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
144342ea7f44SGerrit Uitslag *
144442ea7f44SGerrit Uitslag * @param string $empty empty option label
144542ea7f44SGerrit Uitslag * @param string $button submit button label
1446affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1447a00de5b5SAndreas Gohr */
1448a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1449affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
14501e875dcdSAndreas Gohr    $menu = new \dokuwiki\Menu\MobileMenu();
14511e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1452a00de5b5SAndreas Gohr}
1453a00de5b5SAndreas Gohr
1454066fee30SAndreas Gohr/**
1455066fee30SAndreas Gohr * Print a informational line about the used license
1456066fee30SAndreas Gohr *
1457066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1458ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1459ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1460ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1461ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1462ac7a515fSAndreas Gohr * @return string
1463066fee30SAndreas Gohr */
146480083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1465066fee30SAndreas Gohr    global $license;
1466066fee30SAndreas Gohr    global $conf;
1467066fee30SAndreas Gohr    global $lang;
1468066fee30SAndreas Gohr    if(!$conf['license']) return '';
1469066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1470066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
147153e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1472066fee30SAndreas Gohr
147380083a41SAndreas Gohr    $out = '';
147480083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1475066fee30SAndreas Gohr    if($img) {
1476066fee30SAndreas Gohr        $src = license_img($img);
1477066fee30SAndreas Gohr        if($src) {
147853e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
147953e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
148053e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1481066fee30SAndreas Gohr        }
1482066fee30SAndreas Gohr    }
14834cefd216SMichael Klier    if(!$imgonly) {
148453e15c8bSAnika Henke        $out .= $lang['license'].' ';
1485d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1486d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
14874cefd216SMichael Klier    }
148880083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1489066fee30SAndreas Gohr
1490066fee30SAndreas Gohr    if($return) return $out;
1491066fee30SAndreas Gohr    echo $out;
1492ac7a515fSAndreas Gohr    return '';
1493066fee30SAndreas Gohr}
1494066fee30SAndreas Gohr
1495a81910eeSAndreas Gohr/**
1496835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1497a81910eeSAndreas Gohr *
1498a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1499a81910eeSAndreas Gohr * template
1500e0c26282SGerrit Uitslag *
15017a112df5SAndreas Gohr * @param string $pageid The page name you want to include
15027a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
15037a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
15047c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1505e0c26282SGerrit Uitslag * @return bool|null|string
1506a81910eeSAndreas Gohr */
15077c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
15087a112df5SAndreas Gohr    if($propagate) {
15097c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
15107c3e4a67SAndreas Gohr    } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
15117a112df5SAndreas Gohr        return false;
15127a112df5SAndreas Gohr    }
1513c786a1b6SAnika Henke    if(!$pageid) return false;
1514835dfcaeSAnika Henke
1515c786a1b6SAnika Henke    global $TOC;
15169a2e250aSAndreas Gohr    $oldtoc = $TOC;
1517a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
15189a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1519a81910eeSAndreas Gohr
1520a2e03c82SAndreas Gohr    if($print) echo $html;
1521e66d3e6dSAndreas Gohr    return $html;
1522e66d3e6dSAndreas Gohr}
1523e66d3e6dSAndreas Gohr
1524e66d3e6dSAndreas Gohr/**
15255b75cd1fSAdrian Lang * Display the subscribe form
15265b75cd1fSAdrian Lang *
15275b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15285b75cd1fSAdrian Lang */
15295b75cd1fSAdrian Langfunction tpl_subscribe() {
15305b75cd1fSAdrian Lang    global $INFO;
15315b75cd1fSAdrian Lang    global $ID;
15325b75cd1fSAdrian Lang    global $lang;
15336b8f02cfSAdrian Lang    global $conf;
153440c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15355b75cd1fSAdrian Lang
15365b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15375b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
153815741132SAndreas Gohr    echo '<div class="level2">';
15395b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
15405b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
15415b75cd1fSAdrian Lang    } else {
15425b75cd1fSAdrian Lang        echo '<ul>';
15435b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1544056c2049SAndreas Gohr            echo '<li><div class="li">';
15455b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1546056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
15475b75cd1fSAdrian Lang            } else {
1548056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
15495b75cd1fSAdrian Lang            }
155040c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
155115741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1552056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
155315741132SAndreas Gohr
1554ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1555ac7a515fSAndreas Gohr                $ID,
1556ac7a515fSAndreas Gohr                array(
1557ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
155866d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
155966d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
156066d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1561ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1562ac7a515fSAndreas Gohr                )
1563ac7a515fSAndreas Gohr            ).
156466d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
156566d2bed9SAdrian Lang                '</a></div></li>';
15665b75cd1fSAdrian Lang        }
15675b75cd1fSAdrian Lang        echo '</ul>';
15685b75cd1fSAdrian Lang    }
156915741132SAndreas Gohr    echo '</div>';
15705b75cd1fSAdrian Lang
157115741132SAndreas Gohr    // Add new subscription form
15725b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
157315741132SAndreas Gohr    echo '<div class="level2">';
15745b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
157515741132SAndreas Gohr    $targets = array(
157615741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
157715741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
157815741132SAndreas Gohr    );
157915741132SAndreas Gohr    $styles  = array(
158015741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
15816b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
15826b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
158315741132SAndreas Gohr    );
158415741132SAndreas Gohr
1585056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1586056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1587056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1588056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1589056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1590056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1591056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1592056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1593056c2049SAndreas Gohr    $form->endFieldset();
15945b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
15955b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
159615741132SAndreas Gohr    echo '</div>';
15975b75cd1fSAdrian Lang}
15985b75cd1fSAdrian Lang
1599d059ba9bSAndreas Gohr/**
1600d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1601d059ba9bSAndreas Gohr *
1602d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1603d059ba9bSAndreas Gohr *
1604d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1605d059ba9bSAndreas Gohr */
1606d059ba9bSAndreas Gohrfunction tpl_flush() {
1607d059ba9bSAndreas Gohr    ob_flush();
1608d059ba9bSAndreas Gohr    flush();
1609d059ba9bSAndreas Gohr}
1610d059ba9bSAndreas Gohr
1611afca7e7eSAnika Henke/**
1612378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1613afca7e7eSAnika Henke *
1614378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1615378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1616378325f9SAndreas Gohr *
161742ea7f44SGerrit Uitslag * @param  string[] $search       locations to look at
1618378325f9SAndreas Gohr * @param  bool     $abs           if to use absolute URL
1619ac7a515fSAndreas Gohr * @param  array   &$imginfo   filled with getimagesize()
1620ac7a515fSAndreas Gohr * @return string
162142ea7f44SGerrit Uitslag *
1622378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1623afca7e7eSAnika Henke */
1624378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1625ac7a515fSAndreas Gohr    $img     = '';
1626ac7a515fSAndreas Gohr    $file    = '';
1627ac7a515fSAndreas Gohr    $ismedia = false;
1628378325f9SAndreas Gohr    // loop through candidates until a match was found:
1629378325f9SAndreas Gohr    foreach($search as $img) {
1630378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1631378325f9SAndreas Gohr            $file    = mediaFN($img);
1632378325f9SAndreas Gohr            $ismedia = true;
1633378325f9SAndreas Gohr        } else {
1634c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1635378325f9SAndreas Gohr            $ismedia = false;
16361f13e33dSAnika Henke        }
16370f747863Slupo49
1638378325f9SAndreas Gohr        if(file_exists($file)) break;
1639872a6d29SAnika Henke    }
1640378325f9SAndreas Gohr
1641378325f9SAndreas Gohr    // fetch image data if requested
1642378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1643378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1644378325f9SAndreas Gohr    }
1645378325f9SAndreas Gohr
1646378325f9SAndreas Gohr    // build URL
1647378325f9SAndreas Gohr    if($ismedia) {
1648378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1649378325f9SAndreas Gohr    } else {
1650c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1651378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1652378325f9SAndreas Gohr    }
1653378325f9SAndreas Gohr
1654378325f9SAndreas Gohr    return $url;
1655a7e5f74cSlupo49}
16561f13e33dSAnika Henke
1657872a6d29SAnika Henke/**
1658e5d4768dSAndreas Gohr * PHP include a file
1659e5d4768dSAndreas Gohr *
1660e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1661e5d4768dSAndreas Gohr * file in the template's root directory.
1662e5d4768dSAndreas Gohr *
1663e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1664e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1665e5d4768dSAndreas Gohr * default.
1666e5d4768dSAndreas Gohr *
1667e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1668e5d4768dSAndreas Gohr * to this function!
1669e5d4768dSAndreas Gohr *
1670e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1671e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
167242ea7f44SGerrit Uitslag *
167342ea7f44SGerrit Uitslag * @param string $file
1674e5d4768dSAndreas Gohr */
1675e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1676e5d4768dSAndreas Gohr    global $config_cascade;
1677e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1678e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1679e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1680e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1681e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1682f3a1225fSAnika Henke                include("$dir/$file");
1683e5d4768dSAndreas Gohr                return;
1684e5d4768dSAndreas Gohr            }
1685e5d4768dSAndreas Gohr        }
1686e5d4768dSAndreas Gohr    }
1687e5d4768dSAndreas Gohr
1688e5d4768dSAndreas Gohr    // still here? try the template dir
1689e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1690e5d4768dSAndreas Gohr    if(file_exists($file)) {
1691f3a1225fSAnika Henke        include($file);
1692e5d4768dSAndreas Gohr    }
1693e5d4768dSAndreas Gohr}
1694e5d4768dSAndreas Gohr
1695e5d4768dSAndreas Gohr/**
1696872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1697872a6d29SAnika Henke *
1698872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
169942ea7f44SGerrit Uitslag *
1700ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1701ac7a515fSAndreas Gohr * @return string
1702872a6d29SAnika Henke */
1703872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1704872a6d29SAnika Henke
1705872a6d29SAnika Henke    $return = '';
1706872a6d29SAnika Henke
1707872a6d29SAnika Henke    foreach($types as $type) {
1708872a6d29SAnika Henke        switch($type) {
1709872a6d29SAnika Henke            case 'favicon':
1710378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1711378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1712872a6d29SAnika Henke                break;
1713872a6d29SAnika Henke            case 'mobile':
1714cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1715378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1716872a6d29SAnika Henke                break;
1717872a6d29SAnika Henke            case 'generic':
1718872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1719378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1720378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1721872a6d29SAnika Henke                break;
1722872a6d29SAnika Henke        }
1723872a6d29SAnika Henke    }
1724872a6d29SAnika Henke
1725872a6d29SAnika Henke    return $return;
1726afca7e7eSAnika Henke}
1727afca7e7eSAnika Henke
1728d9162c6cSKate Arzamastseva/**
1729d9162c6cSKate Arzamastseva * Prints full-screen media manager
1730d9162c6cSKate Arzamastseva *
1731d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1732d9162c6cSKate Arzamastseva */
1733d9162c6cSKate Arzamastsevafunction tpl_media() {
1734ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
173588a71175SKate Arzamastseva    $fullscreen = true;
173695b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1737d9162c6cSKate Arzamastseva
1738ac7a515fSAndreas Gohr    $rev   = '';
1739ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
174098f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
174198f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
17429c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
174398f03b57SKate Arzamastseva
174494add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1745bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1746d9162c6cSKate Arzamastseva    html_msgarea();
174794add303SAnika Henke
174894add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
174994add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
175095b451bcSAdrian Lang    echo '<div class="panelHeader">';
1751ba340a70SAnika Henke    echo $lang['media_namespaces'];
175294add303SAnika Henke    echo '</div>'.NL;
175395b451bcSAdrian Lang
175494add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
175595b451bcSAdrian Lang    media_nstree($NS);
175694add303SAnika Henke    echo '</div>'.NL;
175794add303SAnika Henke    echo '</div>'.NL;
1758fa8e5c77SKate Arzamastseva
175994add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1760035e07f1SKate Arzamastseva    tpl_mediaFileList();
176194add303SAnika Henke    echo '</div>'.NL;
1762fa8e5c77SKate Arzamastseva
176394add303SAnika Henke    echo '<div class="panel file">'.NL;
176494add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1765035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
176694add303SAnika Henke    echo '</div>'.NL;
1767ba340a70SAnika Henke
176894add303SAnika Henke    echo '</div>'.NL;
1769d9162c6cSKate Arzamastseva}
1770afca7e7eSAnika Henke
1771c71db656SAnika Henke/**
1772c71db656SAnika Henke * Return useful layout classes
1773c71db656SAnika Henke *
1774c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
177542ea7f44SGerrit Uitslag *
177642ea7f44SGerrit Uitslag * @return string
1777c71db656SAnika Henke */
1778c71db656SAnika Henkefunction tpl_classes() {
1779c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1780585bf44eSChristopher Smith    /** @var Input $INPUT */
1781585bf44eSChristopher Smith    global $INPUT;
1782585bf44eSChristopher Smith
1783c71db656SAnika Henke    $classes = array(
1784c71db656SAnika Henke        'dokuwiki',
1785c71db656SAnika Henke        'mode_'.$ACT,
1786c71db656SAnika Henke        'tpl_'.$conf['template'],
1787585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
178839f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1789c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1790c71db656SAnika Henke    );
1791c71db656SAnika Henke    return join(' ', $classes);
1792c71db656SAnika Henke}
1793c71db656SAnika Henke
179484dd2b1aSGerrit Uitslag/**
179584dd2b1aSGerrit Uitslag * Create event for tools menues
179684dd2b1aSGerrit Uitslag *
179784dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
179884dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
179984dd2b1aSGerrit Uitslag * @param array $items
180084dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1801affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
180284dd2b1aSGerrit Uitslag */
180384dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') {
1804affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
180584dd2b1aSGerrit Uitslag    $data = array(
180684dd2b1aSGerrit Uitslag        'view' => $view,
180784dd2b1aSGerrit Uitslag        'items' => $items
180884dd2b1aSGerrit Uitslag    );
180984dd2b1aSGerrit Uitslag
181084dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
181184dd2b1aSGerrit Uitslag    $evt = new Doku_Event($hook, $data);
181284dd2b1aSGerrit Uitslag    if($evt->advise_before()) {
181384dd2b1aSGerrit Uitslag        foreach($evt->data['items'] as $k => $html) echo $html;
181484dd2b1aSGerrit Uitslag    }
181584dd2b1aSGerrit Uitslag    $evt->advise_after();
181684dd2b1aSGerrit Uitslag}
181784dd2b1aSGerrit Uitslag
1818e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1819a00de5b5SAndreas Gohr
1820