xref: /dokuwiki/inc/template.php (revision 3c7a332778d22c09f4d37358d71b9a17a14f9d8a)
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
245f96fa415SAndreas Gohr    if($alt) {
24654be1338SGerrit Uitslag        if(actionOK('rss')) {
247ac7a515fSAndreas Gohr            $head['link'][] = array(
248ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
249a1288caeSGerrit Uitslag                'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
250ac7a515fSAndreas Gohr            );
251ac7a515fSAndreas Gohr            $head['link'][] = array(
252ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
253a1288caeSGerrit Uitslag                'title'=> $lang['currentns'],
254ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
255ac7a515fSAndreas Gohr            );
25654be1338SGerrit Uitslag        }
257c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
258ac7a515fSAndreas Gohr            $head['link'][] = array(
259ac7a515fSAndreas Gohr                'rel'  => 'edit',
260715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
261ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
262ac7a515fSAndreas Gohr            );
263c35f3875SAndreas Gohr        }
264c35f3875SAndreas Gohr
26554be1338SGerrit Uitslag        if(actionOK('rss') && $ACT == 'search') {
266ac7a515fSAndreas Gohr            $head['link'][] = array(
267ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
268a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
269ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
270ac7a515fSAndreas Gohr            );
2714bb1b5aeSAndreas Gohr        }
272bae36d94SAndreas Gohr
273bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
274ac7a515fSAndreas Gohr            $head['link'][] = array(
275a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
276ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
277ac7a515fSAndreas Gohr            );
278bae36d94SAndreas Gohr        }
279bae36d94SAndreas Gohr
280bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
281ac7a515fSAndreas Gohr            $head['link'][] = array(
282a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
283ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
284ac7a515fSAndreas Gohr            );
285f96fa415SAndreas Gohr        }
286bae36d94SAndreas Gohr    }
2876b13307fSandi
2886b13307fSandi    // setup robot tags apropriate for different modes
2894f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
2906b13307fSandi        if($INFO['exists']) {
2916b13307fSandi            //delay indexing:
292fb9fa88bSAndreas Gohr            if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
2937bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
2946b13307fSandi            } else {
2957bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
2966b13307fSandi            }
29701f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
29801f9be51SAnika Henke            if ($ID == $conf['start']) {
29901f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
30001f9be51SAnika Henke            }
30101f9be51SAnika Henke            $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
3026b13307fSandi        } else {
3037bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3046b13307fSandi        }
3057a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3067bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3076b13307fSandi    } else {
3087bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3096b13307fSandi    }
3106b13307fSandi
311831800b8SAndreas Gohr    // set metadata
312831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
313831800b8SAndreas Gohr        // keywords (explicit or implicit)
314bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3157bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
316831800b8SAndreas Gohr        } else {
3177bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
318831800b8SAndreas Gohr        }
319831800b8SAndreas Gohr    }
320831800b8SAndreas Gohr
32178a6aeb1SAndreas Gohr    // load stylesheets
322ac7a515fSAndreas Gohr    $head['link'][] = array(
323ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
324e283bd6cSAnika Henke        'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
325ac7a515fSAndreas Gohr    );
326bad31ae9SAndreas Gohr
3278bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
328463d4a65SAndreas Gohr    $json   = new JSON();
32972e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
330585bf44eSChristopher Smith    if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
33172e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
332c591aabeSAndreas Gohr    }
33372e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
33485f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
3358bbcb611SAndreas Gohr
33661537d47SAndreas Gohr    // load jquery
337fa078663SAndreas Gohr    $jquery = getCdnUrls();
338fa078663SAndreas Gohr    foreach($jquery as $src) {
33961537d47SAndreas Gohr        $head['script'][] = array(
340fa078663SAndreas Gohr            'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src
34161537d47SAndreas Gohr        );
34261537d47SAndreas Gohr    }
34361537d47SAndreas Gohr
34461537d47SAndreas Gohr    // load our javascript dispatcher
345ac7a515fSAndreas Gohr    $head['script'][] = array(
346ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
347e283bd6cSAnika Henke        'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
348ac7a515fSAndreas Gohr    );
3497bff22c0SAndreas Gohr
3507bff22c0SAndreas Gohr    // trigger event here
351016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
35254e95700STom N Harris    return true;
3537bff22c0SAndreas Gohr}
3547bff22c0SAndreas Gohr
3557bff22c0SAndreas Gohr/**
3567bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3577bff22c0SAndreas Gohr *
3587bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3597bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3607bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3617bff22c0SAndreas Gohr *
36242ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
3631304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3647bff22c0SAndreas Gohr *
3657bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
36642ea7f44SGerrit Uitslag *
36742ea7f44SGerrit Uitslag * @param array $data
3687bff22c0SAndreas Gohr */
3697bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
3707bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
371427bf9a2SAndreas Gohr        if($tag == 'script') {
372427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
373427bf9a2SAndreas Gohr        }
3747bff22c0SAndreas Gohr        foreach($inst as $attr) {
3759b48e6a1SGerry Weißbach            if ( empty($attr) ) { continue; }
3767bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
37726afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
378e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
37909f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
380e226efe1SAndreas Gohr                        $attr['_data'].
38109f791c4SDominik Eckelmann                        "\n/*!]]>*/";
382e226efe1SAndreas Gohr
3831304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
3847bff22c0SAndreas Gohr            } else {
3857bff22c0SAndreas Gohr                echo '/>';
3867bff22c0SAndreas Gohr            }
3877bff22c0SAndreas Gohr            echo "\n";
3887bff22c0SAndreas Gohr        }
389427bf9a2SAndreas Gohr        if($tag == 'script') {
390427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
391427bf9a2SAndreas Gohr        }
3927bff22c0SAndreas Gohr    }
3936b13307fSandi}
3946b13307fSandi
3956b13307fSandi/**
3966b13307fSandi * Print a link
3976b13307fSandi *
3985e163278SAndreas Gohr * Just builds a link.
3996b13307fSandi *
4006b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
40142ea7f44SGerrit Uitslag *
40242ea7f44SGerrit Uitslag * @param string $url
40342ea7f44SGerrit Uitslag * @param string $name
40442ea7f44SGerrit Uitslag * @param string $more
40521d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
40621d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
4076b13307fSandi */
4081af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
40901f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4101af98a77SAnika Henke    if($more) $out .= ' '.$more;
4111af98a77SAnika Henke    $out .= ">$name</a>";
4121af98a77SAnika Henke    if($return) return $out;
4131af98a77SAnika Henke    print $out;
41454e95700STom N Harris    return true;
4156b13307fSandi}
4166b13307fSandi
4176b13307fSandi/**
41855efc227SAndreas Gohr * Prints a link to a WikiPage
41955efc227SAndreas Gohr *
42055efc227SAndreas Gohr * Wrapper around html_wikilink
42155efc227SAndreas Gohr *
42255efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
42342ea7f44SGerrit Uitslag *
42442ea7f44SGerrit Uitslag * @param string      $id   page id
42542ea7f44SGerrit Uitslag * @param string|null $name the name of the link
426fb008d31SIain Hallam * @param bool        $return
427fb008d31SIain Hallam * @return true|string
42855efc227SAndreas Gohr */
429c4a386f1SIain Hallamfunction tpl_pagelink($id, $name = null, $return = false) {
430c4a386f1SIain Hallam    $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
431c4a386f1SIain Hallam    if($return) return $out;
432c4a386f1SIain Hallam    print $out;
43354e95700STom N Harris    return true;
43455efc227SAndreas Gohr}
43555efc227SAndreas Gohr
43655efc227SAndreas Gohr/**
437a3ec5f4aSmatthiasgrimm * get the parent page
438a3ec5f4aSmatthiasgrimm *
439a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
440a3ec5f4aSmatthiasgrimm * returns false if none is available
441a3ec5f4aSmatthiasgrimm *
442377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
44342ea7f44SGerrit Uitslag *
44442ea7f44SGerrit Uitslag * @param string $id page id
44542ea7f44SGerrit Uitslag * @return false|string
446a3ec5f4aSmatthiasgrimm */
447377f9e97SAndreas Gohrfunction tpl_getparent($id) {
448377f9e97SAndreas Gohr    $parent = getNS($id).':';
449377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
450a197105eSmatthiasgrimm    if($parent == $id) {
451a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
452a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
453a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
454377f9e97SAndreas Gohr        if($parent == $id) return false;
455a197105eSmatthiasgrimm    }
456377f9e97SAndreas Gohr    return $parent;
457a3ec5f4aSmatthiasgrimm}
458a3ec5f4aSmatthiasgrimm
459a3ec5f4aSmatthiasgrimm/**
4606b13307fSandi * Print one of the buttons
4616b13307fSandi *
462a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
463a453d131SAdrian Lang * @see    tpl_get_action
464e0c26282SGerrit Uitslag *
465e0c26282SGerrit Uitslag * @param string $type
466e0c26282SGerrit Uitslag * @param bool $return
467e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
468affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
4696b13307fSandi */
4701af98a77SAnika Henkefunction tpl_button($type, $return = false) {
471affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
472a453d131SAdrian Lang    $data = tpl_get_action($type);
473a453d131SAdrian Lang    if($data === false) {
474a453d131SAdrian Lang        return false;
475a453d131SAdrian Lang    } elseif(!is_array($data)) {
476a453d131SAdrian Lang        $out = sprintf($data, 'button');
477409d7af7SAndreas Gohr    } else {
478ac7a515fSAndreas Gohr        /**
479ac7a515fSAndreas Gohr         * @var string $accesskey
480ac7a515fSAndreas Gohr         * @var string $id
481ac7a515fSAndreas Gohr         * @var string $method
482ac7a515fSAndreas Gohr         * @var array  $params
483ac7a515fSAndreas Gohr         */
484a453d131SAdrian Lang        extract($data);
485a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
486a453d131SAdrian Lang            $out = html_topbtn();
487409d7af7SAndreas Gohr        } else {
488a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
489409d7af7SAndreas Gohr        }
490409d7af7SAndreas Gohr    }
4911af98a77SAnika Henke    if($return) return $out;
492a453d131SAdrian Lang    echo $out;
493a453d131SAdrian Lang    return true;
4946b13307fSandi}
4956b13307fSandi
4966b13307fSandi/**
497ed630903Sandi * Like the action buttons but links
498ed630903Sandi *
499a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
500a453d131SAdrian Lang * @see    tpl_get_action
501e0c26282SGerrit Uitslag *
50242ea7f44SGerrit Uitslag * @param string $type    action command
503e0c26282SGerrit Uitslag * @param string $pre     prefix of link
504e0c26282SGerrit Uitslag * @param string $suf     suffix of link
505e0c26282SGerrit Uitslag * @param string $inner   innerHML of link
50621d806cdSGerrit Uitslag * @param bool   $return  if true it returns html, otherwise prints
507e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
508affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
509a453d131SAdrian Lang */
510a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
511affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
512a453d131SAdrian Lang    global $lang;
513a453d131SAdrian Lang    $data = tpl_get_action($type);
514a453d131SAdrian Lang    if($data === false) {
515a453d131SAdrian Lang        return false;
516a453d131SAdrian Lang    } elseif(!is_array($data)) {
517a453d131SAdrian Lang        $out = sprintf($data, 'link');
518a453d131SAdrian Lang    } else {
519ac7a515fSAndreas Gohr        /**
520ac7a515fSAndreas Gohr         * @var string $accesskey
521ac7a515fSAndreas Gohr         * @var string $id
522ac7a515fSAndreas Gohr         * @var string $method
523b1af9014SChristopher Smith         * @var bool   $nofollow
524ac7a515fSAndreas Gohr         * @var array  $params
525becfa414SGerrit Uitslag         * @var string $replacement
526ac7a515fSAndreas Gohr         */
527a453d131SAdrian Lang        extract($data);
528a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
529a453d131SAdrian Lang            $linktarget = $id;
530a453d131SAdrian Lang        } else {
531a453d131SAdrian Lang            $linktarget = wl($id, $params);
532a453d131SAdrian Lang        }
533a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
534becfa414SGerrit Uitslag        if(strpos($caption, '%s')){
535becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
536becfa414SGerrit Uitslag        }
537c7e90e3fSAnika Henke        $akey    = $addTitle = '';
538c7e90e3fSAnika Henke        if($accesskey) {
539c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
540c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
541c7e90e3fSAnika Henke        }
542b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
543ac7a515fSAndreas Gohr        $out = tpl_link(
544ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
545a453d131SAdrian Lang            'class="action '.$type.'" '.
546b1af9014SChristopher Smith                $akey.$rel.
547e0c26282SGerrit Uitslag                'title="'.hsc($caption).$addTitle.'"', true
548ac7a515fSAndreas Gohr        );
549a453d131SAdrian Lang    }
550a453d131SAdrian Lang    if($return) return $out;
551a453d131SAdrian Lang    echo $out;
552a453d131SAdrian Lang    return true;
553a453d131SAdrian Lang}
554a453d131SAdrian Lang
555a453d131SAdrian Lang/**
556a453d131SAdrian Lang * Check the actions and get data for buttons and links
557ed630903Sandi *
558ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
559a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
560a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
561e0c26282SGerrit Uitslag *
562ac7a515fSAndreas Gohr * @param string $type
563ac7a515fSAndreas Gohr * @return array|bool|string
564affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
565ed630903Sandi */
566a453d131SAdrian Langfunction tpl_get_action($type) {
567affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
568a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
5694c4b65c8SMichael Hamann    if($type == 'subscription') $type = 'subscribe';
5704887c154SAndreas Gohr    if($type == 'img_backto') $type = 'imgBackto';
571409d7af7SAndreas Gohr
5724887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
5734887c154SAndreas Gohr    if(class_exists($class)) {
5744887c154SAndreas Gohr        try {
5754887c154SAndreas Gohr            /** @var \dokuwiki\Menu\Item\AbstractItem $item */
5764887c154SAndreas Gohr            $item = new $class;
5774887c154SAndreas Gohr            $data = $item->getLegacyData();
5787b4365a7SGerrit Uitslag            $unknown = false;
5794887c154SAndreas Gohr        } catch(\RuntimeException $ignored) {
5804887c154SAndreas Gohr            return false;
581b8a111f5SMichael Klier        }
582ed630903Sandi    } else {
5834887c154SAndreas Gohr        global $ID;
5844887c154SAndreas Gohr        $data = array(
5854887c154SAndreas Gohr            'accesskey' => null,
5864887c154SAndreas Gohr            'type' => $type,
5874887c154SAndreas Gohr            'id' => $ID,
5884887c154SAndreas Gohr            'method' => 'get',
5894887c154SAndreas Gohr            'params' => array('do' => $type),
5904887c154SAndreas Gohr            'nofollow' => true,
5914887c154SAndreas Gohr            'replacement' => '',
592becfa414SGerrit Uitslag        );
5937b4365a7SGerrit Uitslag        $unknown = true;
594ed630903Sandi    }
5957b4365a7SGerrit Uitslag
5963131073dSGerrit Uitslag    $evt = new Doku_Event('TPL_ACTION_GET', $data);
5977b4365a7SGerrit Uitslag    if($evt->advise_before()) {
5987b4365a7SGerrit Uitslag        //handle unknown types
5997b4365a7SGerrit Uitslag        if($unknown) {
60038d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6017b4365a7SGerrit Uitslag        }
6027b4365a7SGerrit Uitslag    }
6037b4365a7SGerrit Uitslag    $evt->advise_after();
6047b4365a7SGerrit Uitslag    unset($evt);
6057b4365a7SGerrit Uitslag
6067b4365a7SGerrit Uitslag    return $data;
607ed630903Sandi}
608ed630903Sandi
609ed630903Sandi/**
61001f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
61101f17825SAnika Henke *
61201f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
61342ea7f44SGerrit Uitslag *
61442ea7f44SGerrit Uitslag * @param string        $type action command
615ac7a515fSAndreas Gohr * @param bool          $link link or form button?
616e0c26282SGerrit Uitslag * @param string|bool   $wrapper HTML element wrapper
617ac7a515fSAndreas Gohr * @param bool          $return return or print
618ac7a515fSAndreas Gohr * @param string        $pre prefix for links
619ac7a515fSAndreas Gohr * @param string        $suf suffix for links
620ac7a515fSAndreas Gohr * @param string        $inner inner HTML for links
621ac7a515fSAndreas Gohr * @return bool|string
622affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
62301f17825SAnika Henke */
624ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
625affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
62601f17825SAnika Henke    $out = '';
627ac7a515fSAndreas Gohr    if($link) {
628e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
629ac7a515fSAndreas Gohr    } else {
630e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
631ac7a515fSAndreas Gohr    }
63201f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
63301f17825SAnika Henke
63401f17825SAnika Henke    if($return) return $out;
63501f17825SAnika Henke    print $out;
63601f17825SAnika Henke    return $out ? true : false;
63701f17825SAnika Henke}
63801f17825SAnika Henke
63901f17825SAnika Henke/**
6406b13307fSandi * Print the search form
6416b13307fSandi *
64272645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
64372645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
64472645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
64572645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
64672645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
64772645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
64872645b75SAndreas Gohr *
6496b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
65042ea7f44SGerrit Uitslag *
651ac7a515fSAndreas Gohr * @param bool $ajax
652ac7a515fSAndreas Gohr * @param bool $autocomplete
653ac7a515fSAndreas Gohr * @return bool
6546b13307fSandi */
65572645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
6566b13307fSandi    global $lang;
657c1e3b7d9Smatthiasgrimm    global $ACT;
658ad4aaef7SAndreas Gohr    global $QUERY;
659c1e3b7d9Smatthiasgrimm
660670ff54eSchris    // don't print the search form if search action has been disabled
66164276bbcSarbrk1    if(!actionOK('search')) return false;
662670ff54eSchris
663*3c7a3327SMichael Große    $searchForm = new dokuwiki\Form\Form([
664*3c7a3327SMichael Große        'action' => wl(),
665*3c7a3327SMichael Große        'method' => 'get',
666*3c7a3327SMichael Große        'role' => 'search',
667*3c7a3327SMichael Große        'class' => 'search',
668*3c7a3327SMichael Große        'id' => 'dw__search',
669*3c7a3327SMichael Große    ]);
670*3c7a3327SMichael Große    $searchForm->setHiddenField('do', 'search');
671*3c7a3327SMichael Große    $searchForm->addTextInput('id')
672*3c7a3327SMichael Große        ->addClass('edit')
673*3c7a3327SMichael Große        ->attrs([
674*3c7a3327SMichael Große            'title' => '[F]',
675*3c7a3327SMichael Große            'accesskey' => 'f',
676*3c7a3327SMichael Große            'placeholder' => $lang['btn_search'],
677*3c7a3327SMichael Große            'autocomplete' => $autocomplete ? 'on' : 'off',
678*3c7a3327SMichael Große        ])
679*3c7a3327SMichael Große        ->id('qsearch__in')
680*3c7a3327SMichael Große        ->val($ACT === 'search' ? $QUERY : '')
681*3c7a3327SMichael Große        ->useInput(false)
682*3c7a3327SMichael Große    ;
683*3c7a3327SMichael Große    $searchForm->addButton('', $lang['btn_search'])->attrs([
684*3c7a3327SMichael Große        'type' => 'submit',
685*3c7a3327SMichael Große        'title' => $lang['btn_search'],
686*3c7a3327SMichael Große    ]);
687*3c7a3327SMichael Große    if ($ajax) {
688*3c7a3327SMichael Große        $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
689*3c7a3327SMichael Große        $searchForm->addTagClose('div');
690*3c7a3327SMichael Große    }
691*3c7a3327SMichael Große
692*3c7a3327SMichael Große    echo $searchForm->toHTML();
693*3c7a3327SMichael Große
69454e95700STom N Harris    return true;
6956b13307fSandi}
6966b13307fSandi
6976b13307fSandi/**
6986b13307fSandi * Print the breadcrumbs trace
6996b13307fSandi *
7006b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
70142ea7f44SGerrit Uitslag *
702ac7a515fSAndreas Gohr * @param string $sep Separator between entries
703c4a386f1SIain Hallam * @param bool   $return return or print
704c4a386f1SIain Hallam * @return bool|string
7056b13307fSandi */
706c4a386f1SIain Hallamfunction tpl_breadcrumbs($sep = null, $return = false) {
7076b13307fSandi    global $lang;
7086b13307fSandi    global $conf;
7096b13307fSandi
7106b13307fSandi    //check if enabled
711359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
7126b13307fSandi
713c4a386f1SIain Hallam    //set default
714c4a386f1SIain Hallam    if(is_null($sep)) $sep = '•';
715c4a386f1SIain Hallam
716c4a386f1SIain Hallam    $out='';
717c4a386f1SIain Hallam
7186b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
719265e3787Sandi
7202979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
721265e3787Sandi
72240eb54bbSjan    //render crumbs, highlight the last one
723c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
72440eb54bbSjan    $last = count($crumbs);
72540eb54bbSjan    $i    = 0;
726a77f5846Sjan    foreach($crumbs as $id => $name) {
72740eb54bbSjan        $i++;
728c4a386f1SIain Hallam        $out .= $crumbs_sep;
729c4a386f1SIain Hallam        if($i == $last) $out .= '<span class="curid">';
730c4a386f1SIain Hallam        $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) .  '</bdi>';
731c4a386f1SIain Hallam        if($i == $last) $out .= '</span>';
7326b13307fSandi    }
733c4a386f1SIain Hallam    if($return) return $out;
734c4a386f1SIain Hallam    print $out;
735c4a386f1SIain Hallam    return $out ? true : false;
7366b13307fSandi}
7376b13307fSandi
7386b13307fSandi/**
7391734437eSandi * Hierarchical breadcrumbs
7401734437eSandi *
74131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7421734437eSandi * It only makes sense with a deep site structure.
7431734437eSandi *
7441734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7456bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
74631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
747f46c9e83SAnika Henke * @author <fredrik@averpil.com>
74808d7a575SAndreas Gohr * @todo   May behave strangely in RTL languages
74942ea7f44SGerrit Uitslag *
750ac7a515fSAndreas Gohr * @param string $sep Separator between entries
751c4a386f1SIain Hallam * @param bool   $return return or print
752c4a386f1SIain Hallam * @return bool|string
7531734437eSandi */
754c4a386f1SIain Hallamfunction tpl_youarehere($sep = null, $return = false) {
7551734437eSandi    global $conf;
7561734437eSandi    global $ID;
7571734437eSandi    global $lang;
7581734437eSandi
75931e187f8SSean Coates    // check if enabled
76054e95700STom N Harris    if(!$conf['youarehere']) return false;
7611734437eSandi
762c4a386f1SIain Hallam    //set default
763c4a386f1SIain Hallam    if(is_null($sep)) $sep = ' » ';
764c4a386f1SIain Hallam
765c4a386f1SIain Hallam    $out = '';
766c4a386f1SIain Hallam
7671734437eSandi    $parts = explode(':', $ID);
768796bafb3SAndreas Gohr    $count = count($parts);
7691734437eSandi
770c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
7713940c519SMark
77208d7a575SAndreas Gohr    // always print the startpage
773c4a386f1SIain Hallam    $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
774796bafb3SAndreas Gohr
775796bafb3SAndreas Gohr    // print intermediate namespace links
776796bafb3SAndreas Gohr    $part = '';
777796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
778796bafb3SAndreas Gohr        $part .= $parts[$i].':';
779796bafb3SAndreas Gohr        $page = $part;
780796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
781796bafb3SAndreas Gohr
78208d7a575SAndreas Gohr        // output
783c4a386f1SIain Hallam        $out .= $sep . tpl_pagelink($page, null, true);
78431e187f8SSean Coates    }
7851734437eSandi
786796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
787e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
78808d7a575SAndreas Gohr    if(isset($page) && $page == $part.$parts[$i]) return true;
789796bafb3SAndreas Gohr    $page = $part.$parts[$i];
79008d7a575SAndreas Gohr    if($page == $conf['start']) return true;
791c4a386f1SIain Hallam    $out .= $sep;
792c4a386f1SIain Hallam    $out .= tpl_pagelink($page, null, true);
793c4a386f1SIain Hallam    if($return) return $out;
794c4a386f1SIain Hallam    print $out;
795c4a386f1SIain Hallam    return $out ? true : false;
7961734437eSandi}
7971734437eSandi
7981734437eSandi/**
7996b13307fSandi * Print info if the user is logged in
800a2488c3cSMatthias Grimm * and show full name in that case
8016b13307fSandi *
8026b13307fSandi * Could be enhanced with a profile link in future?
8036b13307fSandi *
8046b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
80542ea7f44SGerrit Uitslag *
806ac7a515fSAndreas Gohr * @return bool
8076b13307fSandi */
8086b13307fSandifunction tpl_userinfo() {
8096b13307fSandi    global $lang;
810585bf44eSChristopher Smith    /** @var Input $INPUT */
811585bf44eSChristopher Smith    global $INPUT;
812585bf44eSChristopher Smith
813585bf44eSChristopher Smith    if($INPUT->server->str('REMOTE_USER')) {
814fde860beSGerrit Uitslag        print $lang['loggedinas'].' '.userlink();
81554e95700STom N Harris        return true;
81654e95700STom N Harris    }
81754e95700STom N Harris    return false;
8186b13307fSandi}
8196b13307fSandi
8206b13307fSandi/**
8216b13307fSandi * Print some info about the current page
8226b13307fSandi *
8236b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
82442ea7f44SGerrit Uitslag *
825ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
826ac7a515fSAndreas Gohr * @return bool|string
8276b13307fSandi */
8284b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
8296b13307fSandi    global $conf;
8306b13307fSandi    global $lang;
8316b13307fSandi    global $INFO;
832c6e92a3cSDavid Lorentsen    global $ID;
833c6e92a3cSDavid Lorentsen
834c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
835ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
836ac7a515fSAndreas Gohr        return false;
837ac7a515fSAndreas Gohr    }
8386b13307fSandi
8396b13307fSandi    // prepare date and path
8406b13307fSandi    $fn = $INFO['filepath'];
8416b13307fSandi    if(!$conf['fullpath']) {
842613bca54SAndreas Gohr        if($INFO['rev']) {
843c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'].'/', '', $fn);
8446b13307fSandi        } else {
845c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'].'/', '', $fn);
8466b13307fSandi        }
8476b13307fSandi    }
848bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
849f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
8506b13307fSandi
851faecdfdfSAndreas Gohr    // print it
852faecdfdfSAndreas Gohr    if($INFO['exists']) {
8534b0d3916SAndreas Gohr        $out = '';
854d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
855e260f93bSAnika Henke        $out .= ' · ';
8564b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
857fde860beSGerrit Uitslag        $out .= ' ';
8584b0d3916SAndreas Gohr        $out .= $date;
8596b13307fSandi        if($INFO['editor']) {
8604b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
861d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
8625aa52fafSBen Coburn        } else {
8634b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
8646b13307fSandi        }
8656b13307fSandi        if($INFO['locked']) {
866e260f93bSAnika Henke            $out .= ' · ';
8674b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
868fde860beSGerrit Uitslag            $out .= ' ';
869d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
8706b13307fSandi        }
8714b0d3916SAndreas Gohr        if($ret) {
8724b0d3916SAndreas Gohr            return $out;
8734b0d3916SAndreas Gohr        } else {
8744b0d3916SAndreas Gohr            echo $out;
87554e95700STom N Harris            return true;
8766b13307fSandi        }
8774b0d3916SAndreas Gohr    }
87854e95700STom N Harris    return false;
8796b13307fSandi}
8806b13307fSandi
881820fa24bSandi/**
882a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
88387c434ceSAndreas Gohr *
88487c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
885a6598f23SBen Coburn * the given ID is used.
88687c434ceSAndreas Gohr *
88787c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
88842ea7f44SGerrit Uitslag *
889ac7a515fSAndreas Gohr * @param string $id page id
890ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
891ac7a515fSAndreas Gohr * @return bool|string
89287c434ceSAndreas Gohr */
893a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
894c248bda1SChristopher Smith    global $ACT, $INPUT, $conf, $lang;
895fffeeafeSChristopher Smith
89687c434ceSAndreas Gohr    if(is_null($id)) {
89787c434ceSAndreas Gohr        global $ID;
89887c434ceSAndreas Gohr        $id = $ID;
89987c434ceSAndreas Gohr    }
90087c434ceSAndreas Gohr
90187c434ceSAndreas Gohr    $name = $id;
902fe9ec250SChris Smith    if(useHeading('navigation')) {
903fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
904fffeeafeSChristopher Smith        if($first_heading) $name = $first_heading;
905fffeeafeSChristopher Smith    }
906fffeeafeSChristopher Smith
907fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
908fffeeafeSChristopher Smith    switch ($ACT) {
909fffeeafeSChristopher Smith        // admin functions
910fffeeafeSChristopher Smith        case 'admin' :
911fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
912fffeeafeSChristopher Smith            // try to get the plugin name
913a61966c5SChristopher Smith            /** @var $plugin DokuWiki_Admin_Plugin */
914a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()){
915c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
916a61966c5SChristopher Smith                $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
917fffeeafeSChristopher Smith            }
918fffeeafeSChristopher Smith            break;
919fffeeafeSChristopher Smith
920fffeeafeSChristopher Smith        // user functions
921fffeeafeSChristopher Smith        case 'login' :
922fffeeafeSChristopher Smith        case 'profile' :
923fffeeafeSChristopher Smith        case 'register' :
924fffeeafeSChristopher Smith        case 'resendpwd' :
925fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
926fffeeafeSChristopher Smith            break;
927fffeeafeSChristopher Smith
928fffeeafeSChristopher Smith         // wiki functions
929fffeeafeSChristopher Smith        case 'search' :
930fffeeafeSChristopher Smith        case 'index' :
931fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
932fffeeafeSChristopher Smith            break;
933fffeeafeSChristopher Smith
934fffeeafeSChristopher Smith        // page functions
935fffeeafeSChristopher Smith        case 'edit' :
936fffeeafeSChristopher Smith            $page_title = "✎ ".$name;
937fffeeafeSChristopher Smith            break;
938fffeeafeSChristopher Smith
939fffeeafeSChristopher Smith        case 'revisions' :
940fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
941fffeeafeSChristopher Smith            break;
942fffeeafeSChristopher Smith
943fffeeafeSChristopher Smith        case 'backlink' :
944fffeeafeSChristopher Smith        case 'recent' :
945fffeeafeSChristopher Smith        case 'subscribe' :
946fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_'.$ACT];
947fffeeafeSChristopher Smith            break;
948fffeeafeSChristopher Smith
949fffeeafeSChristopher Smith        default : // SHOW and anything else not included
950fffeeafeSChristopher Smith            $page_title = $name;
95187c434ceSAndreas Gohr    }
952a6598f23SBen Coburn
953a6598f23SBen Coburn    if($ret) {
954fffeeafeSChristopher Smith        return hsc($page_title);
955a6598f23SBen Coburn    } else {
956fffeeafeSChristopher Smith        print hsc($page_title);
95754e95700STom N Harris        return true;
95887c434ceSAndreas Gohr    }
959a6598f23SBen Coburn}
960340756e4Sandi
96155efc227SAndreas Gohr/**
96255efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
96355efc227SAndreas Gohr *
96455efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
96555efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
96655efc227SAndreas Gohr *
96755efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
96855efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
96955efc227SAndreas Gohr * to the names of the latter one)
97055efc227SAndreas Gohr *
9713df72098SAndreas Gohr * Only allowed in: detail.php
97255efc227SAndreas Gohr *
97355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
97442ea7f44SGerrit Uitslag *
97521d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
976ac7a515fSAndreas Gohr * @param string       $alt  alternative output if no data was found
977e0c26282SGerrit Uitslag * @param null|string  $src  the image src, uses global $SRC if not given
978ac7a515fSAndreas Gohr * @return string
97955efc227SAndreas Gohr */
9803df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
98155efc227SAndreas Gohr    // Init Exif Reader
98255efc227SAndreas Gohr    global $SRC;
9833df72098SAndreas Gohr
9843df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
9853df72098SAndreas Gohr
98655efc227SAndreas Gohr    static $meta = null;
9873df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
98855efc227SAndreas Gohr    if($meta === false) return $alt;
98988945224SChristopher Smith    $info = cleanText($meta->getField($tags));
99055efc227SAndreas Gohr    if($info == false) return $alt;
99155efc227SAndreas Gohr    return $info;
99255efc227SAndreas Gohr}
99355efc227SAndreas Gohr
99455efc227SAndreas Gohr/**
995becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
996becfa414SGerrit Uitslag *
997becfa414SGerrit Uitslag * @return string html of description list
998becfa414SGerrit Uitslag */
999becfa414SGerrit Uitslagfunction tpl_img_meta() {
1000becfa414SGerrit Uitslag    global $lang;
1001becfa414SGerrit Uitslag
1002becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1003becfa414SGerrit Uitslag
1004becfa414SGerrit Uitslag    echo '<dl>';
1005becfa414SGerrit Uitslag    foreach($tags as $tag) {
1006becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1007fde860beSGerrit Uitslag        if(!$label) $label = $tag['langkey'] . ':';
1008becfa414SGerrit Uitslag
1009fde860beSGerrit Uitslag        echo '<dt>'.$label.'</dt><dd>';
1010becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1011becfa414SGerrit Uitslag            echo dformat($tag['value']);
1012becfa414SGerrit Uitslag        } else {
1013becfa414SGerrit Uitslag            echo hsc($tag['value']);
1014becfa414SGerrit Uitslag        }
1015becfa414SGerrit Uitslag        echo '</dd>';
1016becfa414SGerrit Uitslag    }
1017becfa414SGerrit Uitslag    echo '</dl>';
1018becfa414SGerrit Uitslag}
1019becfa414SGerrit Uitslag
1020becfa414SGerrit Uitslag/**
1021becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1022becfa414SGerrit Uitslag *
1023becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1024becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1025becfa414SGerrit Uitslag *   - string type     type of value
1026becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1027becfa414SGerrit Uitslag */
1028becfa414SGerrit Uitslagfunction tpl_get_img_meta() {
1029becfa414SGerrit Uitslag
1030becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1031becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
103279e79377SAndreas Gohr        if(file_exists($config_file)) {
1033becfa414SGerrit Uitslag            include($config_file);
1034becfa414SGerrit Uitslag        }
1035becfa414SGerrit Uitslag    }
1036becfa414SGerrit Uitslag    /** @var array $fields the included array with metadata */
1037becfa414SGerrit Uitslag
1038becfa414SGerrit Uitslag    $tags = array();
1039becfa414SGerrit Uitslag    foreach($fields as $tag){
1040becfa414SGerrit Uitslag        $t = array();
1041becfa414SGerrit Uitslag        if (!empty($tag[0])) {
1042becfa414SGerrit Uitslag            $t = array($tag[0]);
1043becfa414SGerrit Uitslag        }
1044becfa414SGerrit Uitslag        if(is_array($tag[3])) {
1045becfa414SGerrit Uitslag            $t = array_merge($t,$tag[3]);
1046becfa414SGerrit Uitslag        }
1047becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1048becfa414SGerrit Uitslag        if ($value) {
1049becfa414SGerrit Uitslag            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1050becfa414SGerrit Uitslag        }
1051becfa414SGerrit Uitslag    }
1052becfa414SGerrit Uitslag    return $tags;
1053becfa414SGerrit Uitslag}
1054becfa414SGerrit Uitslag
1055becfa414SGerrit Uitslag/**
105655efc227SAndreas Gohr * Prints the image with a link to the full sized version
105755efc227SAndreas Gohr *
105855efc227SAndreas Gohr * Only allowed in: detail.php
1059a02d2933SAndreas Gohr *
1060ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1061a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1062a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1063a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1064a02d2933SAndreas Gohr * @param $params array  - additional image attributes
106542ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
106655efc227SAndreas Gohr */
1067a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
106855efc227SAndreas Gohr    global $IMG;
1069585bf44eSChristopher Smith    /** @var Input $INPUT */
1070ac7a515fSAndreas Gohr    global $INPUT;
10715c2eed9aSlisps    global $REV;
107265d3a5dbSAndreas Gohr    $w = (int) tpl_img_getTag('File.Width');
107365d3a5dbSAndreas Gohr    $h = (int) tpl_img_getTag('File.Height');
107455efc227SAndreas Gohr
107555efc227SAndreas Gohr    //resize to given max values
107623a34783SAndreas Gohr    $ratio = 1;
107723a34783SAndreas Gohr    if($w >= $h) {
1078f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
107955efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1080f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
108155efc227SAndreas Gohr            $ratio = $maxheight / $h;
108255efc227SAndreas Gohr        }
108355efc227SAndreas Gohr    } else {
1084f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
108555efc227SAndreas Gohr            $ratio = $maxheight / $h;
1086f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
108755efc227SAndreas Gohr            $ratio = $maxwidth / $w;
108855efc227SAndreas Gohr        }
108955efc227SAndreas Gohr    }
109055efc227SAndreas Gohr    if($ratio) {
109155efc227SAndreas Gohr        $w = floor($ratio * $w);
109255efc227SAndreas Gohr        $h = floor($ratio * $h);
109355efc227SAndreas Gohr    }
109455efc227SAndreas Gohr
10956de3759aSAndreas Gohr    //prepare URLs
10965c2eed9aSlisps    $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
10975c2eed9aSlisps    $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
109855efc227SAndreas Gohr
10992684e50aSAndreas Gohr    //prepare attributes
110055efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1101a02d2933SAndreas Gohr    if(is_null($params)) {
11022684e50aSAndreas Gohr        $p = array();
1103a02d2933SAndreas Gohr    } else {
1104a02d2933SAndreas Gohr        $p = $params;
1105a02d2933SAndreas Gohr    }
11062684e50aSAndreas Gohr    if($w) $p['width'] = $w;
11072684e50aSAndreas Gohr    if($h) $p['height'] = $h;
11082684e50aSAndreas Gohr    $p['class'] = 'img_detail';
11092684e50aSAndreas Gohr    if($alt) {
11102684e50aSAndreas Gohr        $p['alt']   = $alt;
11112684e50aSAndreas Gohr        $p['title'] = $alt;
11122684e50aSAndreas Gohr    } else {
11132684e50aSAndreas Gohr        $p['alt'] = '';
11142684e50aSAndreas Gohr    }
1115a02d2933SAndreas Gohr    $p['src'] = $src;
111655efc227SAndreas Gohr
1117a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1118a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1119a02d2933SAndreas Gohr}
1120a02d2933SAndreas Gohr
1121a02d2933SAndreas Gohr/**
1122a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1123ac7a515fSAndreas Gohr *
1124ac7a515fSAndreas Gohr * @param array $data
1125ac7a515fSAndreas Gohr * @return bool
1126a02d2933SAndreas Gohr */
1127ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
112859f3611bSAnika Henke    global $lang;
1129a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1130a02d2933SAndreas Gohr
113159f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1132a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1133a02d2933SAndreas Gohr    if($data['url']) print '</a>';
113454e95700STom N Harris    return true;
113555efc227SAndreas Gohr}
113655efc227SAndreas Gohr
11377367b368SAndreas Gohr/**
1138881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11397367b368SAndreas Gohr *
11407367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11417367b368SAndreas Gohr * template
1142ac7a515fSAndreas Gohr *
1143ac7a515fSAndreas Gohr * @return bool
11447367b368SAndreas Gohr */
11457367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11467367b368SAndreas Gohr    global $ID;
11471dad36f5SAndreas Gohr
11487367b368SAndreas Gohr    $p           = array();
1149b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1150e68c51baSAndreas Gohr        '&'.time();
1151881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11527367b368SAndreas Gohr    $p['height'] = 1;
11537367b368SAndreas Gohr    $p['alt']    = '';
11547367b368SAndreas Gohr    $att         = buildAttributes($p);
11557367b368SAndreas Gohr    print "<img $att />";
115654e95700STom N Harris    return true;
11577367b368SAndreas Gohr}
11587367b368SAndreas Gohr
115978d4e784SEsther Brunner/**
116078d4e784SEsther Brunner * tpl_getConf($id)
116178d4e784SEsther Brunner *
116278d4e784SEsther Brunner * use this function to access template configuration variables
1163ac7a515fSAndreas Gohr *
116417448fb8SChristopher Smith * @param string $id      name of the value to access
116517448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
116617448fb8SChristopher Smith * @return mixed
116778d4e784SEsther Brunner */
116817448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
116978d4e784SEsther Brunner    global $conf;
117017566ac6SAdrian Lang    static $tpl_configloaded = false;
117178d4e784SEsther Brunner
117278d4e784SEsther Brunner    $tpl = $conf['template'];
117378d4e784SEsther Brunner
117478d4e784SEsther Brunner    if(!$tpl_configloaded) {
117578d4e784SEsther Brunner        $tconf = tpl_loadConfig();
117678d4e784SEsther Brunner        if($tconf !== false) {
117778d4e784SEsther Brunner            foreach($tconf as $key => $value) {
117878d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
117978d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
118078d4e784SEsther Brunner            }
118178d4e784SEsther Brunner            $tpl_configloaded = true;
118278d4e784SEsther Brunner        }
118378d4e784SEsther Brunner    }
118478d4e784SEsther Brunner
118517448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
118678d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
118778d4e784SEsther Brunner    }
118878d4e784SEsther Brunner
118917448fb8SChristopher Smith    return $notset;
119017448fb8SChristopher Smith}
119117448fb8SChristopher Smith
119278d4e784SEsther Brunner/**
119378d4e784SEsther Brunner * tpl_loadConfig()
1194ac7a515fSAndreas Gohr *
119578d4e784SEsther Brunner * reads all template configuration variables
119678d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1197ac7a515fSAndreas Gohr *
1198ac7a515fSAndreas Gohr * @return array
119978d4e784SEsther Brunner */
120078d4e784SEsther Brunnerfunction tpl_loadConfig() {
120178d4e784SEsther Brunner
1202c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
120378d4e784SEsther Brunner    $conf = array();
120478d4e784SEsther Brunner
120579e79377SAndreas Gohr    if(!file_exists($file)) return false;
120678d4e784SEsther Brunner
120778d4e784SEsther Brunner    // load default config file
120878d4e784SEsther Brunner    include($file);
120978d4e784SEsther Brunner
121078d4e784SEsther Brunner    return $conf;
121178d4e784SEsther Brunner}
121278d4e784SEsther Brunner
121317566ac6SAdrian Lang// language methods
121417566ac6SAdrian Lang/**
121517566ac6SAdrian Lang * tpl_getLang($id)
121617566ac6SAdrian Lang *
121717566ac6SAdrian Lang * use this function to access template language variables
121842ea7f44SGerrit Uitslag *
121942ea7f44SGerrit Uitslag * @param string $id key of language string
122042ea7f44SGerrit Uitslag * @return string
122117566ac6SAdrian Lang */
122217566ac6SAdrian Langfunction tpl_getLang($id) {
122317566ac6SAdrian Lang    static $lang = array();
122417566ac6SAdrian Lang
122517566ac6SAdrian Lang    if(count($lang) === 0) {
1226dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1227dd7a6159SGerrit Uitslag
1228c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
122917566ac6SAdrian Lang
123017566ac6SAdrian Lang        $lang = array();
123117566ac6SAdrian Lang
123217566ac6SAdrian Lang        // don't include once
123317566ac6SAdrian Lang        @include($path . 'en/lang.php');
1234dd7a6159SGerrit Uitslag        foreach($config_cascade['lang']['template'] as $config_file) {
123579e79377SAndreas Gohr            if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1236dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1237dd7a6159SGerrit Uitslag            }
123817566ac6SAdrian Lang        }
123917566ac6SAdrian Lang
1240dd7a6159SGerrit Uitslag        if($conf['lang'] != 'en') {
1241dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1242dd7a6159SGerrit Uitslag            foreach($config_cascade['lang']['template'] as $config_file) {
124379e79377SAndreas Gohr                if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1244dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1245dd7a6159SGerrit Uitslag                }
1246dd7a6159SGerrit Uitslag            }
1247dd7a6159SGerrit Uitslag        }
124817566ac6SAdrian Lang    }
124917566ac6SAdrian Lang    return $lang[$id];
125017566ac6SAdrian Lang}
125117566ac6SAdrian Lang
12523df72098SAndreas Gohr/**
1253c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1254e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1255e8ec13b9SKlap-in *
1256e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1257e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1258e8ec13b9SKlap-in */
1259e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1260c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1261e8ec13b9SKlap-in}
1262e8ec13b9SKlap-in
1263e8ec13b9SKlap-in/**
1264c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
126542ea7f44SGerrit Uitslag *
126642ea7f44SGerrit Uitslag * @param string $id id of localized text
126742ea7f44SGerrit Uitslag * @return string wiki text
1268e8ec13b9SKlap-in */
1269c5c17fdaSKlap-infunction tpl_localeFN($id) {
1270e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1271e8ec13b9SKlap-in    global $conf;
127238fb1fc7SGerrit Uitslag    $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
127379e79377SAndreas Gohr    if (!file_exists($file)){
1274e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
127579e79377SAndreas Gohr        if(!file_exists($file)){
1276e8ec13b9SKlap-in            //fall back to english
1277e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1278e8ec13b9SKlap-in        }
1279e8ec13b9SKlap-in    }
1280e8ec13b9SKlap-in    return $file;
1281e8ec13b9SKlap-in}
1282e8ec13b9SKlap-in
1283e8ec13b9SKlap-in/**
12847abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
12853df72098SAndreas Gohr *
12863df72098SAndreas Gohr * Depending on the user's actions this may be a list of
12873df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
12883df72098SAndreas Gohr * a message of referencing pages
12893df72098SAndreas Gohr *
12903df72098SAndreas Gohr * Only allowed in mediamanager.php
12913df72098SAndreas Gohr *
1292c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1293c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
129442ea7f44SGerrit Uitslag * @param string $sort
12958702de7fSGerrit Uitslag *
12963df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
12973df72098SAndreas Gohr */
129800e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
12993df72098SAndreas Gohr    global $IMG;
13003df72098SAndreas Gohr    global $AUTH;
13013df72098SAndreas Gohr    global $INUSE;
13023df72098SAndreas Gohr    global $NS;
13033df72098SAndreas Gohr    global $JUMPTO;
1304585bf44eSChristopher Smith    /** @var Input $INPUT */
1305ac7a515fSAndreas Gohr    global $INPUT;
13063df72098SAndreas Gohr
1307ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1308c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1309c182313eSAndreas Gohr
1310c182313eSAndreas Gohr    if(!$do) {
1311ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1312c182313eSAndreas Gohr            $do = 'metaform';
1313c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1314c182313eSAndreas Gohr            $do = 'filesinuse';
1315c182313eSAndreas Gohr        } else {
1316c182313eSAndreas Gohr            $do = 'filelist';
1317c182313eSAndreas Gohr        }
1318c182313eSAndreas Gohr    }
1319c182313eSAndreas Gohr
1320c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1321c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1322c182313eSAndreas Gohr    $data = array('do' => $do);
1323c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1324c182313eSAndreas Gohr    if($evt->advise_before()) {
1325c182313eSAndreas Gohr        $do = $data['do'];
132630fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1327c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1328c182313eSAndreas Gohr        } elseif($do == 'filelist') {
132900e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1330c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1331ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1332c182313eSAndreas Gohr        } else {
1333c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1334c182313eSAndreas Gohr        }
1335c182313eSAndreas Gohr    }
1336c182313eSAndreas Gohr    $evt->advise_after();
1337c182313eSAndreas Gohr    unset($evt);
1338c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1339c182313eSAndreas Gohr
13403df72098SAndreas Gohr}
13413df72098SAndreas Gohr
13423df72098SAndreas Gohr/**
1343d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1344d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1345d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1346d9162c6cSKate Arzamastseva *
1347d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1348d9162c6cSKate Arzamastseva */
1349035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1350d9162c6cSKate Arzamastseva    global $AUTH;
1351d9162c6cSKate Arzamastseva    global $NS;
1352d9162c6cSKate Arzamastseva    global $JUMPTO;
135395b451bcSAdrian Lang    global $lang;
1354585bf44eSChristopher Smith    /** @var Input $INPUT */
1355ac7a515fSAndreas Gohr    global $INPUT;
1356d9162c6cSKate Arzamastseva
1357ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1358e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1359ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1360d9162c6cSKate Arzamastseva
136194add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
136295b451bcSAdrian Lang
1363ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
136423846a98SKate Arzamastseva
136594add303SAnika Henke    echo '<div class="panelHeader">'.NL;
136695b451bcSAdrian Lang    echo '<h3>';
1367026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1368c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
136994add303SAnika Henke    echo '</h3>'.NL;
137095b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
137195b451bcSAdrian Lang        media_tab_files_options();
137223846a98SKate Arzamastseva    }
137394add303SAnika Henke    echo '</div>'.NL;
1374d9162c6cSKate Arzamastseva
137594add303SAnika Henke    echo '<div class="panelContent">'.NL;
137695b451bcSAdrian Lang    if($opened_tab == 'files') {
137795b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
137895b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
137995b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
138095b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
138195b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
138295b451bcSAdrian Lang    }
138394add303SAnika Henke    echo '</div>'.NL;
1384d9162c6cSKate Arzamastseva}
1385d9162c6cSKate Arzamastseva
1386d9162c6cSKate Arzamastseva/**
1387d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1388d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1389d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1390d9162c6cSKate Arzamastseva * list of file revisions
1391d9162c6cSKate Arzamastseva *
1392d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1393f50a239bSTakamura *
1394f50a239bSTakamura * @param string $image
1395f50a239bSTakamura * @param boolean $rev
1396d9162c6cSKate Arzamastseva */
1397035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1398e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1399585bf44eSChristopher Smith    /** @var Input $INPUT */
1400585bf44eSChristopher Smith    global $INPUT;
1401d9162c6cSKate Arzamastseva
140292cac9a9SKate Arzamastseva    $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1403ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
14046dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1405e8a2a143SMichael Hamann    $ns = getNS($image);
1406ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
14071eeeced2SKate Arzamastseva
1408ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1409e5d185e1SKate Arzamastseva
1410e5d185e1SKate Arzamastseva    $tab_array = array('view');
1411ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1412e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1413e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1414e5d185e1SKate Arzamastseva    }
1415e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1416e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1417e5d185e1SKate Arzamastseva    }
1418e5d185e1SKate Arzamastseva
1419e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1420ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
142123846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1422d9162c6cSKate Arzamastseva
1423ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
142423846a98SKate Arzamastseva
142559f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1426ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
142795b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
142895b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
1429750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
1430750a0b51SMichael Große    $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
143108317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
143208317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
143308317413SAdrian Lang    } else {
1434026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
143508317413SAdrian Lang    }
1436b8a84c03SAndreas Gohr
143794add303SAnika Henke    echo '</h3></div>'.NL;
143895b451bcSAdrian Lang
143994add303SAnika Henke    echo '<div class="panelContent">'.NL;
144095b451bcSAdrian Lang
144123846a98SKate Arzamastseva    if($opened_tab == 'view') {
1442e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
144323846a98SKate Arzamastseva
144492cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
1445e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
144623846a98SKate Arzamastseva
1447e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1448e8a2a143SMichael Hamann        media_tab_history($image, $ns);
144923846a98SKate Arzamastseva    }
145095b451bcSAdrian Lang
145194add303SAnika Henke    echo '</div>'.NL;
1452d9162c6cSKate Arzamastseva}
1453d9162c6cSKate Arzamastseva
1454d9162c6cSKate Arzamastseva/**
14557abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
14563df72098SAndreas Gohr *
14573df72098SAndreas Gohr * Only allowed in mediamanager.php
14583df72098SAndreas Gohr *
14593df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14603df72098SAndreas Gohr */
1461fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14623df72098SAndreas Gohr    global $NS;
146323846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14643df72098SAndreas Gohr    media_nstree($NS);
14653df72098SAndreas Gohr    ptln('</div>');
14663df72098SAndreas Gohr}
14673df72098SAndreas Gohr
1468a00de5b5SAndreas Gohr/**
1469a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1470a00de5b5SAndreas Gohr *
1471a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1472a00de5b5SAndreas Gohr *
1473a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
147442ea7f44SGerrit Uitslag *
147542ea7f44SGerrit Uitslag * @param string $empty empty option label
147642ea7f44SGerrit Uitslag * @param string $button submit button label
1477affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1478a00de5b5SAndreas Gohr */
1479a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1480affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
14811e875dcdSAndreas Gohr    $menu = new \dokuwiki\Menu\MobileMenu();
14821e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1483a00de5b5SAndreas Gohr}
1484a00de5b5SAndreas Gohr
1485066fee30SAndreas Gohr/**
1486066fee30SAndreas Gohr * Print a informational line about the used license
1487066fee30SAndreas Gohr *
1488066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1489ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1490ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1491ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1492ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1493ac7a515fSAndreas Gohr * @return string
1494066fee30SAndreas Gohr */
149580083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1496066fee30SAndreas Gohr    global $license;
1497066fee30SAndreas Gohr    global $conf;
1498066fee30SAndreas Gohr    global $lang;
1499066fee30SAndreas Gohr    if(!$conf['license']) return '';
1500066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1501066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
150253e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1503066fee30SAndreas Gohr
150480083a41SAndreas Gohr    $out = '';
150580083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1506066fee30SAndreas Gohr    if($img) {
1507066fee30SAndreas Gohr        $src = license_img($img);
1508066fee30SAndreas Gohr        if($src) {
150953e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
151053e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
151153e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1512066fee30SAndreas Gohr        }
1513066fee30SAndreas Gohr    }
15144cefd216SMichael Klier    if(!$imgonly) {
151553e15c8bSAnika Henke        $out .= $lang['license'].' ';
1516d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1517d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
15184cefd216SMichael Klier    }
151980083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1520066fee30SAndreas Gohr
1521066fee30SAndreas Gohr    if($return) return $out;
1522066fee30SAndreas Gohr    echo $out;
1523ac7a515fSAndreas Gohr    return '';
1524066fee30SAndreas Gohr}
1525066fee30SAndreas Gohr
1526a81910eeSAndreas Gohr/**
1527835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1528a81910eeSAndreas Gohr *
1529a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1530a81910eeSAndreas Gohr * template
1531e0c26282SGerrit Uitslag *
15327a112df5SAndreas Gohr * @param string $pageid The page name you want to include
15337a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
15347a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
15357c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1536e0c26282SGerrit Uitslag * @return bool|null|string
1537a81910eeSAndreas Gohr */
15387c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
15397a112df5SAndreas Gohr    if($propagate) {
15407c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
15417c3e4a67SAndreas Gohr    } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
15427a112df5SAndreas Gohr        return false;
15437a112df5SAndreas Gohr    }
1544c786a1b6SAnika Henke    if(!$pageid) return false;
1545835dfcaeSAnika Henke
1546c786a1b6SAnika Henke    global $TOC;
15479a2e250aSAndreas Gohr    $oldtoc = $TOC;
1548a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
15499a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1550a81910eeSAndreas Gohr
1551a2e03c82SAndreas Gohr    if($print) echo $html;
1552e66d3e6dSAndreas Gohr    return $html;
1553e66d3e6dSAndreas Gohr}
1554e66d3e6dSAndreas Gohr
1555e66d3e6dSAndreas Gohr/**
15565b75cd1fSAdrian Lang * Display the subscribe form
15575b75cd1fSAdrian Lang *
15585b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15595b75cd1fSAdrian Lang */
15605b75cd1fSAdrian Langfunction tpl_subscribe() {
15615b75cd1fSAdrian Lang    global $INFO;
15625b75cd1fSAdrian Lang    global $ID;
15635b75cd1fSAdrian Lang    global $lang;
15646b8f02cfSAdrian Lang    global $conf;
156540c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15665b75cd1fSAdrian Lang
15675b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15685b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
156915741132SAndreas Gohr    echo '<div class="level2">';
15705b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
15715b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
15725b75cd1fSAdrian Lang    } else {
15735b75cd1fSAdrian Lang        echo '<ul>';
15745b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1575056c2049SAndreas Gohr            echo '<li><div class="li">';
15765b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1577056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
15785b75cd1fSAdrian Lang            } else {
1579056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
15805b75cd1fSAdrian Lang            }
158140c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
158215741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1583056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
158415741132SAndreas Gohr
1585ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1586ac7a515fSAndreas Gohr                $ID,
1587ac7a515fSAndreas Gohr                array(
1588ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
158966d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
159066d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
159166d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1592ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1593ac7a515fSAndreas Gohr                )
1594ac7a515fSAndreas Gohr            ).
159566d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
159666d2bed9SAdrian Lang                '</a></div></li>';
15975b75cd1fSAdrian Lang        }
15985b75cd1fSAdrian Lang        echo '</ul>';
15995b75cd1fSAdrian Lang    }
160015741132SAndreas Gohr    echo '</div>';
16015b75cd1fSAdrian Lang
160215741132SAndreas Gohr    // Add new subscription form
16035b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
160415741132SAndreas Gohr    echo '<div class="level2">';
16055b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
160615741132SAndreas Gohr    $targets = array(
160715741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
160815741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
160915741132SAndreas Gohr    );
161015741132SAndreas Gohr    $styles  = array(
161115741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
16126b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
16136b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
161415741132SAndreas Gohr    );
161515741132SAndreas Gohr
1616056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1617056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1618056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1619056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1620056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1621056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1622056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1623056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1624056c2049SAndreas Gohr    $form->endFieldset();
16255b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
16265b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
162715741132SAndreas Gohr    echo '</div>';
16285b75cd1fSAdrian Lang}
16295b75cd1fSAdrian Lang
1630d059ba9bSAndreas Gohr/**
1631d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1632d059ba9bSAndreas Gohr *
1633d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1634d059ba9bSAndreas Gohr *
1635d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1636d059ba9bSAndreas Gohr */
1637d059ba9bSAndreas Gohrfunction tpl_flush() {
1638d059ba9bSAndreas Gohr    ob_flush();
1639d059ba9bSAndreas Gohr    flush();
1640d059ba9bSAndreas Gohr}
1641d059ba9bSAndreas Gohr
1642afca7e7eSAnika Henke/**
1643378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1644afca7e7eSAnika Henke *
1645378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1646378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1647378325f9SAndreas Gohr *
164842ea7f44SGerrit Uitslag * @param  string[] $search       locations to look at
1649378325f9SAndreas Gohr * @param  bool     $abs           if to use absolute URL
1650ac7a515fSAndreas Gohr * @param  array   &$imginfo   filled with getimagesize()
1651ac7a515fSAndreas Gohr * @return string
165242ea7f44SGerrit Uitslag *
1653378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1654afca7e7eSAnika Henke */
1655378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1656ac7a515fSAndreas Gohr    $img     = '';
1657ac7a515fSAndreas Gohr    $file    = '';
1658ac7a515fSAndreas Gohr    $ismedia = false;
1659378325f9SAndreas Gohr    // loop through candidates until a match was found:
1660378325f9SAndreas Gohr    foreach($search as $img) {
1661378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1662378325f9SAndreas Gohr            $file    = mediaFN($img);
1663378325f9SAndreas Gohr            $ismedia = true;
1664378325f9SAndreas Gohr        } else {
1665c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1666378325f9SAndreas Gohr            $ismedia = false;
16671f13e33dSAnika Henke        }
16680f747863Slupo49
1669378325f9SAndreas Gohr        if(file_exists($file)) break;
1670872a6d29SAnika Henke    }
1671378325f9SAndreas Gohr
1672378325f9SAndreas Gohr    // fetch image data if requested
1673378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1674378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1675378325f9SAndreas Gohr    }
1676378325f9SAndreas Gohr
1677378325f9SAndreas Gohr    // build URL
1678378325f9SAndreas Gohr    if($ismedia) {
1679378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1680378325f9SAndreas Gohr    } else {
1681c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1682378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1683378325f9SAndreas Gohr    }
1684378325f9SAndreas Gohr
1685378325f9SAndreas Gohr    return $url;
1686a7e5f74cSlupo49}
16871f13e33dSAnika Henke
1688872a6d29SAnika Henke/**
1689e5d4768dSAndreas Gohr * PHP include a file
1690e5d4768dSAndreas Gohr *
1691e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1692e5d4768dSAndreas Gohr * file in the template's root directory.
1693e5d4768dSAndreas Gohr *
1694e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1695e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1696e5d4768dSAndreas Gohr * default.
1697e5d4768dSAndreas Gohr *
1698e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1699e5d4768dSAndreas Gohr * to this function!
1700e5d4768dSAndreas Gohr *
1701e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1702e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
170342ea7f44SGerrit Uitslag *
170442ea7f44SGerrit Uitslag * @param string $file
1705e5d4768dSAndreas Gohr */
1706e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1707e5d4768dSAndreas Gohr    global $config_cascade;
1708e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1709e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1710e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1711e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1712e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1713f3a1225fSAnika Henke                include("$dir/$file");
1714e5d4768dSAndreas Gohr                return;
1715e5d4768dSAndreas Gohr            }
1716e5d4768dSAndreas Gohr        }
1717e5d4768dSAndreas Gohr    }
1718e5d4768dSAndreas Gohr
1719e5d4768dSAndreas Gohr    // still here? try the template dir
1720e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1721e5d4768dSAndreas Gohr    if(file_exists($file)) {
1722f3a1225fSAnika Henke        include($file);
1723e5d4768dSAndreas Gohr    }
1724e5d4768dSAndreas Gohr}
1725e5d4768dSAndreas Gohr
1726e5d4768dSAndreas Gohr/**
1727872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1728872a6d29SAnika Henke *
1729872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
173042ea7f44SGerrit Uitslag *
1731ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1732ac7a515fSAndreas Gohr * @return string
1733872a6d29SAnika Henke */
1734872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1735872a6d29SAnika Henke
1736872a6d29SAnika Henke    $return = '';
1737872a6d29SAnika Henke
1738872a6d29SAnika Henke    foreach($types as $type) {
1739872a6d29SAnika Henke        switch($type) {
1740872a6d29SAnika Henke            case 'favicon':
1741378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1742378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1743872a6d29SAnika Henke                break;
1744872a6d29SAnika Henke            case 'mobile':
1745cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1746378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1747872a6d29SAnika Henke                break;
1748872a6d29SAnika Henke            case 'generic':
1749872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1750378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1751378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1752872a6d29SAnika Henke                break;
1753872a6d29SAnika Henke        }
1754872a6d29SAnika Henke    }
1755872a6d29SAnika Henke
1756872a6d29SAnika Henke    return $return;
1757afca7e7eSAnika Henke}
1758afca7e7eSAnika Henke
1759d9162c6cSKate Arzamastseva/**
1760d9162c6cSKate Arzamastseva * Prints full-screen media manager
1761d9162c6cSKate Arzamastseva *
1762d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1763d9162c6cSKate Arzamastseva */
1764d9162c6cSKate Arzamastsevafunction tpl_media() {
1765ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
176688a71175SKate Arzamastseva    $fullscreen = true;
176795b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1768d9162c6cSKate Arzamastseva
1769ac7a515fSAndreas Gohr    $rev   = '';
1770ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
177198f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
177298f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
17739c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
177498f03b57SKate Arzamastseva
177594add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1776bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1777d9162c6cSKate Arzamastseva    html_msgarea();
177894add303SAnika Henke
177994add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
178094add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
178195b451bcSAdrian Lang    echo '<div class="panelHeader">';
1782ba340a70SAnika Henke    echo $lang['media_namespaces'];
178394add303SAnika Henke    echo '</div>'.NL;
178495b451bcSAdrian Lang
178594add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
178695b451bcSAdrian Lang    media_nstree($NS);
178794add303SAnika Henke    echo '</div>'.NL;
178894add303SAnika Henke    echo '</div>'.NL;
1789fa8e5c77SKate Arzamastseva
179094add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1791035e07f1SKate Arzamastseva    tpl_mediaFileList();
179294add303SAnika Henke    echo '</div>'.NL;
1793fa8e5c77SKate Arzamastseva
179494add303SAnika Henke    echo '<div class="panel file">'.NL;
179594add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1796035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
179794add303SAnika Henke    echo '</div>'.NL;
1798ba340a70SAnika Henke
179994add303SAnika Henke    echo '</div>'.NL;
1800d9162c6cSKate Arzamastseva}
1801afca7e7eSAnika Henke
1802c71db656SAnika Henke/**
1803c71db656SAnika Henke * Return useful layout classes
1804c71db656SAnika Henke *
1805c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
180642ea7f44SGerrit Uitslag *
180742ea7f44SGerrit Uitslag * @return string
1808c71db656SAnika Henke */
1809c71db656SAnika Henkefunction tpl_classes() {
1810c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1811585bf44eSChristopher Smith    /** @var Input $INPUT */
1812585bf44eSChristopher Smith    global $INPUT;
1813585bf44eSChristopher Smith
1814c71db656SAnika Henke    $classes = array(
1815c71db656SAnika Henke        'dokuwiki',
1816c71db656SAnika Henke        'mode_'.$ACT,
1817c71db656SAnika Henke        'tpl_'.$conf['template'],
1818585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
181939f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1820c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1821c71db656SAnika Henke    );
1822c71db656SAnika Henke    return join(' ', $classes);
1823c71db656SAnika Henke}
1824c71db656SAnika Henke
182584dd2b1aSGerrit Uitslag/**
182684dd2b1aSGerrit Uitslag * Create event for tools menues
182784dd2b1aSGerrit Uitslag *
182884dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
182984dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
183084dd2b1aSGerrit Uitslag * @param array $items
183184dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1832affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
183384dd2b1aSGerrit Uitslag */
183484dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') {
1835affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
183684dd2b1aSGerrit Uitslag    $data = array(
183784dd2b1aSGerrit Uitslag        'view' => $view,
183884dd2b1aSGerrit Uitslag        'items' => $items
183984dd2b1aSGerrit Uitslag    );
184084dd2b1aSGerrit Uitslag
184184dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
184284dd2b1aSGerrit Uitslag    $evt = new Doku_Event($hook, $data);
184384dd2b1aSGerrit Uitslag    if($evt->advise_before()) {
184484dd2b1aSGerrit Uitslag        foreach($evt->data['items'] as $k => $html) echo $html;
184584dd2b1aSGerrit Uitslag    }
184684dd2b1aSGerrit Uitslag    $evt->advise_after();
184784dd2b1aSGerrit Uitslag}
184884dd2b1aSGerrit Uitslag
1849e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1850a00de5b5SAndreas Gohr
1851