xref: /dokuwiki/inc/template.php (revision cbb44eabe033d70affb048ec0daf4e579e09dd20)
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
9e1d9dcc8SAndreas Gohruse dokuwiki\Extension\AdminPlugin;
10e1d9dcc8SAndreas Gohruse dokuwiki\Extension\Event;
11e1d9dcc8SAndreas Gohr
126b13307fSandi/**
13ac7a515fSAndreas Gohr * Access a template file
14ac7a515fSAndreas Gohr *
15ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
16ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
175a892029SAndreas Gohr *
185a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
19ac7a515fSAndreas Gohr * @param string $file
20ac7a515fSAndreas Gohr * @return string
215a892029SAndreas Gohr */
22ac7a515fSAndreas Gohrfunction template($file) {
235a892029SAndreas Gohr    global $conf;
245a892029SAndreas Gohr
25ac7a515fSAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
26ac7a515fSAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
275a892029SAndreas Gohr
28ac7a515fSAndreas Gohr    return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
295a892029SAndreas Gohr}
305a892029SAndreas Gohr
31c4766956SAndreas Gohr/**
32c4766956SAndreas Gohr * Convenience function to access template dir from local FS
33c4766956SAndreas Gohr *
34c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
35c4766956SAndreas Gohr *
36c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
37afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
38ac7a515fSAndreas Gohr * @return string
39c4766956SAndreas Gohr */
40afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') {
4175b14482SAndreas Gohr    global $conf;
42afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
43afb2c082SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$tpl.'/';
44c4766956SAndreas Gohr}
45c4766956SAndreas Gohr
46c4766956SAndreas Gohr/**
47c4766956SAndreas Gohr * Convenience function to access template dir from web
48c4766956SAndreas Gohr *
49c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
50c4766956SAndreas Gohr *
51c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
52afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
53ac7a515fSAndreas Gohr * @return string
54c4766956SAndreas Gohr */
5599dca513SAndreas Gohrfunction tpl_basedir($tpl='') {
5675b14482SAndreas Gohr    global $conf;
57afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
58dcd4911eSMichael Hamann    return DOKU_BASE.'lib/tpl/'.$tpl.'/';
59c4766956SAndreas Gohr}
60c4766956SAndreas Gohr
615a892029SAndreas Gohr/**
626b13307fSandi * Print the content
636b13307fSandi *
646b13307fSandi * This function is used for printing all the usual content
656b13307fSandi * (defined by the global $ACT var) by calling the appropriate
666b13307fSandi * outputfunction(s) from html.php
676b13307fSandi *
68ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
69ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
706b13307fSandi *
716b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7242ea7f44SGerrit Uitslag *
73ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
74ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
75ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
76ac7a515fSAndreas Gohr * @return bool true if any output
776b13307fSandi */
78b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) {
797ea0913cSchris    global $ACT;
80b8595a66SAndreas Gohr    global $INFO;
81b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
827ea0913cSchris
837ea0913cSchris    ob_start();
84*cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
857ea0913cSchris    $html_output = ob_get_clean();
86*cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
8754e95700STom N Harris
8854e95700STom N Harris    return !empty($html_output);
897ea0913cSchris}
907ea0913cSchris
91ac7a515fSAndreas Gohr/**
92ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
93ac7a515fSAndreas Gohr *
94ac7a515fSAndreas Gohr * @return bool
95ac7a515fSAndreas Gohr */
967ea0913cSchrisfunction tpl_content_core() {
97952acff9SAndreas Gohr    $router = \dokuwiki\ActionRouter::getInstance();
98952acff9SAndreas Gohr    try {
99952acff9SAndreas Gohr        $router->getAction()->tplContent();
100952acff9SAndreas Gohr    } catch(\dokuwiki\Action\Exception\FatalException $e) {
101952acff9SAndreas Gohr        // there was no content for the action
102952acff9SAndreas Gohr        msg(hsc($e->getMessage()), -1);
10354e95700STom N Harris        return false;
1046b13307fSandi    }
10554e95700STom N Harris    return true;
1066b13307fSandi}
1076b13307fSandi
108c19fe9c0Sandi/**
109b8595a66SAndreas Gohr * Places the TOC where the function is called
110b8595a66SAndreas Gohr *
111b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
112b8595a66SAndreas Gohr * a false argument
113b8595a66SAndreas Gohr *
114b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11542ea7f44SGerrit Uitslag *
116ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
117ac7a515fSAndreas Gohr * @return string
118b8595a66SAndreas Gohr */
119b8595a66SAndreas Gohrfunction tpl_toc($return = false) {
120b8595a66SAndreas Gohr    global $TOC;
121b8595a66SAndreas Gohr    global $ACT;
122b8595a66SAndreas Gohr    global $ID;
123b8595a66SAndreas Gohr    global $REV;
124b8595a66SAndreas Gohr    global $INFO;
125851f2e89SAnika Henke    global $conf;
126ac7a515fSAndreas Gohr    global $INPUT;
127b8595a66SAndreas Gohr    $toc = array();
128b8595a66SAndreas Gohr
129b8595a66SAndreas Gohr    if(is_array($TOC)) {
130b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
131b8595a66SAndreas Gohr        $toc = $TOC;
1323c86d7c9SAndreas Gohr    } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
133b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
134e0c26282SGerrit Uitslag        $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
135b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])) {
136b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
137b8595a66SAndreas Gohr        } else {
1382bb0d541Schris            $tocok = true;
139b8595a66SAndreas Gohr        }
140f87b5dbbSChristopher Smith        $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
141851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
142b8595a66SAndreas Gohr            $toc = array();
143b8595a66SAndreas Gohr        }
144b8595a66SAndreas Gohr    } elseif($ACT == 'admin') {
145a61966c5SChristopher Smith        // try to load admin plugin TOC
146e1d9dcc8SAndreas Gohr        /** @var $plugin AdminPlugin */
147a61966c5SChristopher Smith        if ($plugin = plugin_getRequestAdminPlugin()) {
148b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
149b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
150b8595a66SAndreas Gohr        }
151b8595a66SAndreas Gohr    }
152b8595a66SAndreas Gohr
153*cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
154b8595a66SAndreas Gohr    $html = html_TOC($toc);
155b8595a66SAndreas Gohr    if($return) return $html;
156b8595a66SAndreas Gohr    echo $html;
157ac7a515fSAndreas Gohr    return '';
158b8595a66SAndreas Gohr}
159b8595a66SAndreas Gohr
160b8595a66SAndreas Gohr/**
161c19fe9c0Sandi * Handle the admin page contents
162c19fe9c0Sandi *
163c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
16442ea7f44SGerrit Uitslag *
16542ea7f44SGerrit Uitslag * @return bool
166c19fe9c0Sandi */
167c19fe9c0Sandifunction tpl_admin() {
168f8cc712eSAndreas Gohr    global $INFO;
169b8595a66SAndreas Gohr    global $TOC;
170ac7a515fSAndreas Gohr    global $INPUT;
17111e2ce22Schris
172b8595a66SAndreas Gohr    $plugin = null;
173ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
174ac7a515fSAndreas Gohr    if(!empty($class)) {
17511e2ce22Schris        $pluginlist = plugin_list('admin');
17611e2ce22Schris
177ac7a515fSAndreas Gohr        if(in_array($class, $pluginlist)) {
17811e2ce22Schris            // attempt to load the plugin
179e1d9dcc8SAndreas Gohr            /** @var $plugin AdminPlugin */
180a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
18111e2ce22Schris        }
18211e2ce22Schris    }
18311e2ce22Schris
184b8595a66SAndreas Gohr    if($plugin !== null) {
185b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
186b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
187f8cc712eSAndreas Gohr        $plugin->html();
188f8cc712eSAndreas Gohr    } else {
1890470c28fSAndreas Gohr        $admin = new dokuwiki\Ui\Admin();
1900470c28fSAndreas Gohr        $admin->show();
191f8cc712eSAndreas Gohr    }
19254e95700STom N Harris    return true;
193c19fe9c0Sandi}
1946b13307fSandi
1956b13307fSandi/**
1966b13307fSandi * Print the correct HTML meta headers
1976b13307fSandi *
1986b13307fSandi * This has to go into the head section of your template.
1996b13307fSandi *
2006b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
20142ea7f44SGerrit Uitslag *
202ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
203ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
204ac7a515fSAndreas Gohr * @return bool
2056b13307fSandi */
206f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) {
2076b13307fSandi    global $ID;
208d98d4540SBen Coburn    global $REV;
2096b13307fSandi    global $INFO;
21072e0dc37SAndreas Gohr    global $JSINFO;
2116b13307fSandi    global $ACT;
2124bb1b5aeSAndreas Gohr    global $QUERY;
2136b13307fSandi    global $lang;
214dc57ef04Sandi    global $conf;
2159c438d6cSMichael Hamann    global $updateVersion;
216585bf44eSChristopher Smith    /** @var Input $INPUT */
217585bf44eSChristopher Smith    global $INPUT;
2186b13307fSandi
2197bff22c0SAndreas Gohr    // prepare the head array
2207bff22c0SAndreas Gohr    $head = array();
2217bff22c0SAndreas Gohr
222202ac28bSMichael Klier    // prepare seed for js and css
223cd997f93SAndreas Gohr    $tseed   = $updateVersion;
224202ac28bSMichael Klier    $depends = getConfigFiles('main');
22584e76a7eSAndreas Gohr    $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
226cd997f93SAndreas Gohr    foreach($depends as $f) $tseed .= @filemtime($f);
227cd997f93SAndreas Gohr    $tseed   = md5($tseed);
2287bff22c0SAndreas Gohr
2296b13307fSandi    // the usual stuff
2303f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
23163cf4192Ssarehag    if(actionOK('search')) {
232ac7a515fSAndreas Gohr        $head['link'][] = array(
233ac7a515fSAndreas Gohr            'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
234ac7a515fSAndreas Gohr            'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
235ac7a515fSAndreas Gohr        );
23663cf4192Ssarehag    }
23763cf4192Ssarehag
238f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
2397aedde2eSGina Haeussge    if(actionOK('index')) {
240ac7a515fSAndreas Gohr        $head['link'][] = array(
241ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
242ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
243ac7a515fSAndreas Gohr        );
2447aedde2eSGina Haeussge    }
245f96fa415SAndreas Gohr
2465e0255e3SMichael Große    if (actionOK('manifest')) {
2475e0255e3SMichael Große        $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
2485e0255e3SMichael Große    }
2495e0255e3SMichael Große
25040ca8540SMichael Große    $styleUtil = new \dokuwiki\StyleUtils();
2514593dbd2SAnna Dabrowska    $styleIni = $styleUtil->cssStyleini();
25240ca8540SMichael Große    $replacements = $styleIni['replacements'];
25340ca8540SMichael Große    if (!empty($replacements['__theme_color__'])) {
25440ca8540SMichael Große        $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']);
25540ca8540SMichael Große    }
25640ca8540SMichael Große
257f96fa415SAndreas Gohr    if($alt) {
25854be1338SGerrit Uitslag        if(actionOK('rss')) {
259ac7a515fSAndreas Gohr            $head['link'][] = array(
260ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
261a1288caeSGerrit Uitslag                'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
262ac7a515fSAndreas Gohr            );
263ac7a515fSAndreas Gohr            $head['link'][] = array(
264ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
265a1288caeSGerrit Uitslag                'title'=> $lang['currentns'],
266ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
267ac7a515fSAndreas Gohr            );
26854be1338SGerrit Uitslag        }
269c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
270ac7a515fSAndreas Gohr            $head['link'][] = array(
271ac7a515fSAndreas Gohr                'rel'  => 'edit',
272715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
273ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
274ac7a515fSAndreas Gohr            );
275c35f3875SAndreas Gohr        }
276c35f3875SAndreas Gohr
27754be1338SGerrit Uitslag        if(actionOK('rss') && $ACT == 'search') {
278ac7a515fSAndreas Gohr            $head['link'][] = array(
279ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
280a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
281ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
282ac7a515fSAndreas Gohr            );
2834bb1b5aeSAndreas Gohr        }
284bae36d94SAndreas Gohr
285bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
286ac7a515fSAndreas Gohr            $head['link'][] = array(
287a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
288ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
289ac7a515fSAndreas Gohr            );
290bae36d94SAndreas Gohr        }
291bae36d94SAndreas Gohr
292bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
293ac7a515fSAndreas Gohr            $head['link'][] = array(
294a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
295ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
296ac7a515fSAndreas Gohr            );
297f96fa415SAndreas Gohr        }
298bae36d94SAndreas Gohr    }
2996b13307fSandi
3006b13307fSandi    // setup robot tags apropriate for different modes
3014f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3026b13307fSandi        if($INFO['exists']) {
3036b13307fSandi            //delay indexing:
304fb9fa88bSAndreas Gohr            if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
3057bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3066b13307fSandi            } else {
3077bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3086b13307fSandi            }
30901f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
31001f9be51SAnika Henke            if ($ID == $conf['start']) {
31101f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
31201f9be51SAnika Henke            }
31301f9be51SAnika Henke            $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
3146b13307fSandi        } else {
3157bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3166b13307fSandi        }
3177a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3187bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3196b13307fSandi    } else {
3207bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3216b13307fSandi    }
3226b13307fSandi
323831800b8SAndreas Gohr    // set metadata
324831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
325831800b8SAndreas Gohr        // keywords (explicit or implicit)
326bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3277bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
328831800b8SAndreas Gohr        } else {
3297bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
330831800b8SAndreas Gohr        }
331831800b8SAndreas Gohr    }
332831800b8SAndreas Gohr
33378a6aeb1SAndreas Gohr    // load stylesheets
334ac7a515fSAndreas Gohr    $head['link'][] = array(
335ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
336e283bd6cSAnika Henke        'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
337ac7a515fSAndreas Gohr    );
338bad31ae9SAndreas Gohr
33972e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
340585bf44eSChristopher Smith    if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
34172e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
342c591aabeSAndreas Gohr    }
3430c39d46cSMichael Große    jsinfo();
3441d739e3dSMichael Große    $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
34585f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
3468bbcb611SAndreas Gohr
34761537d47SAndreas Gohr    // load jquery
348fa078663SAndreas Gohr    $jquery = getCdnUrls();
349fa078663SAndreas Gohr    foreach($jquery as $src) {
35061537d47SAndreas Gohr        $head['script'][] = array(
351fa078663SAndreas Gohr            'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src
35261537d47SAndreas Gohr        );
35361537d47SAndreas Gohr    }
35461537d47SAndreas Gohr
35561537d47SAndreas Gohr    // load our javascript dispatcher
356ac7a515fSAndreas Gohr    $head['script'][] = array(
357ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
358e283bd6cSAnika Henke        'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
359ac7a515fSAndreas Gohr    );
3607bff22c0SAndreas Gohr
3617bff22c0SAndreas Gohr    // trigger event here
362*cbb44eabSAndreas Gohr    Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
36354e95700STom N Harris    return true;
3647bff22c0SAndreas Gohr}
3657bff22c0SAndreas Gohr
3667bff22c0SAndreas Gohr/**
3677bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3687bff22c0SAndreas Gohr *
3697bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3707bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3717bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3727bff22c0SAndreas Gohr *
37342ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
3741304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3757bff22c0SAndreas Gohr *
3767bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
37742ea7f44SGerrit Uitslag *
37842ea7f44SGerrit Uitslag * @param array $data
3797bff22c0SAndreas Gohr */
3807bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
3817bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
382427bf9a2SAndreas Gohr        if($tag == 'script') {
383427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
384427bf9a2SAndreas Gohr        }
3857bff22c0SAndreas Gohr        foreach($inst as $attr) {
3869b48e6a1SGerry Weißbach            if ( empty($attr) ) { continue; }
3877bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
38826afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
389e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
39009f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
391e226efe1SAndreas Gohr                        $attr['_data'].
39209f791c4SDominik Eckelmann                        "\n/*!]]>*/";
393e226efe1SAndreas Gohr
3941304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
3957bff22c0SAndreas Gohr            } else {
3967bff22c0SAndreas Gohr                echo '/>';
3977bff22c0SAndreas Gohr            }
3987bff22c0SAndreas Gohr            echo "\n";
3997bff22c0SAndreas Gohr        }
400427bf9a2SAndreas Gohr        if($tag == 'script') {
401427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
402427bf9a2SAndreas Gohr        }
4037bff22c0SAndreas Gohr    }
4046b13307fSandi}
4056b13307fSandi
4066b13307fSandi/**
4076b13307fSandi * Print a link
4086b13307fSandi *
4095e163278SAndreas Gohr * Just builds a link.
4106b13307fSandi *
4116b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
41242ea7f44SGerrit Uitslag *
41342ea7f44SGerrit Uitslag * @param string $url
41442ea7f44SGerrit Uitslag * @param string $name
41542ea7f44SGerrit Uitslag * @param string $more
41621d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
41721d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
4186b13307fSandi */
4191af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
42001f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4211af98a77SAnika Henke    if($more) $out .= ' '.$more;
4221af98a77SAnika Henke    $out .= ">$name</a>";
4231af98a77SAnika Henke    if($return) return $out;
4241af98a77SAnika Henke    print $out;
42554e95700STom N Harris    return true;
4266b13307fSandi}
4276b13307fSandi
4286b13307fSandi/**
42955efc227SAndreas Gohr * Prints a link to a WikiPage
43055efc227SAndreas Gohr *
43155efc227SAndreas Gohr * Wrapper around html_wikilink
43255efc227SAndreas Gohr *
43355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
43442ea7f44SGerrit Uitslag *
43542ea7f44SGerrit Uitslag * @param string      $id   page id
43642ea7f44SGerrit Uitslag * @param string|null $name the name of the link
437fb008d31SIain Hallam * @param bool        $return
438fb008d31SIain Hallam * @return true|string
43955efc227SAndreas Gohr */
440c4a386f1SIain Hallamfunction tpl_pagelink($id, $name = null, $return = false) {
441c4a386f1SIain Hallam    $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
442c4a386f1SIain Hallam    if($return) return $out;
443c4a386f1SIain Hallam    print $out;
44454e95700STom N Harris    return true;
44555efc227SAndreas Gohr}
44655efc227SAndreas Gohr
44755efc227SAndreas Gohr/**
448a3ec5f4aSmatthiasgrimm * get the parent page
449a3ec5f4aSmatthiasgrimm *
450a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
451a3ec5f4aSmatthiasgrimm * returns false if none is available
452a3ec5f4aSmatthiasgrimm *
453377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
45442ea7f44SGerrit Uitslag *
45542ea7f44SGerrit Uitslag * @param string $id page id
45642ea7f44SGerrit Uitslag * @return false|string
457a3ec5f4aSmatthiasgrimm */
458377f9e97SAndreas Gohrfunction tpl_getparent($id) {
459377f9e97SAndreas Gohr    $parent = getNS($id).':';
460377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
461a197105eSmatthiasgrimm    if($parent == $id) {
462a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
463a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
464a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
465377f9e97SAndreas Gohr        if($parent == $id) return false;
466a197105eSmatthiasgrimm    }
467377f9e97SAndreas Gohr    return $parent;
468a3ec5f4aSmatthiasgrimm}
469a3ec5f4aSmatthiasgrimm
470a3ec5f4aSmatthiasgrimm/**
4716b13307fSandi * Print one of the buttons
4726b13307fSandi *
473a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
474a453d131SAdrian Lang * @see    tpl_get_action
475e0c26282SGerrit Uitslag *
476e0c26282SGerrit Uitslag * @param string $type
477e0c26282SGerrit Uitslag * @param bool $return
478e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
479affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
4806b13307fSandi */
4811af98a77SAnika Henkefunction tpl_button($type, $return = false) {
482affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
483a453d131SAdrian Lang    $data = tpl_get_action($type);
484a453d131SAdrian Lang    if($data === false) {
485a453d131SAdrian Lang        return false;
486a453d131SAdrian Lang    } elseif(!is_array($data)) {
487a453d131SAdrian Lang        $out = sprintf($data, 'button');
488409d7af7SAndreas Gohr    } else {
489ac7a515fSAndreas Gohr        /**
490ac7a515fSAndreas Gohr         * @var string $accesskey
491ac7a515fSAndreas Gohr         * @var string $id
492ac7a515fSAndreas Gohr         * @var string $method
493ac7a515fSAndreas Gohr         * @var array  $params
494ac7a515fSAndreas Gohr         */
495a453d131SAdrian Lang        extract($data);
496a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
497a453d131SAdrian Lang            $out = html_topbtn();
498409d7af7SAndreas Gohr        } else {
499a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
500409d7af7SAndreas Gohr        }
501409d7af7SAndreas Gohr    }
5021af98a77SAnika Henke    if($return) return $out;
503a453d131SAdrian Lang    echo $out;
504a453d131SAdrian Lang    return true;
5056b13307fSandi}
5066b13307fSandi
5076b13307fSandi/**
508ed630903Sandi * Like the action buttons but links
509ed630903Sandi *
510a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
511a453d131SAdrian Lang * @see    tpl_get_action
512e0c26282SGerrit Uitslag *
51342ea7f44SGerrit Uitslag * @param string $type    action command
514e0c26282SGerrit Uitslag * @param string $pre     prefix of link
515e0c26282SGerrit Uitslag * @param string $suf     suffix of link
516e0c26282SGerrit Uitslag * @param string $inner   innerHML of link
51721d806cdSGerrit Uitslag * @param bool   $return  if true it returns html, otherwise prints
518e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
519affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
520a453d131SAdrian Lang */
521a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
522affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
523a453d131SAdrian Lang    global $lang;
524a453d131SAdrian Lang    $data = tpl_get_action($type);
525a453d131SAdrian Lang    if($data === false) {
526a453d131SAdrian Lang        return false;
527a453d131SAdrian Lang    } elseif(!is_array($data)) {
528a453d131SAdrian Lang        $out = sprintf($data, 'link');
529a453d131SAdrian Lang    } else {
530ac7a515fSAndreas Gohr        /**
531ac7a515fSAndreas Gohr         * @var string $accesskey
532ac7a515fSAndreas Gohr         * @var string $id
533ac7a515fSAndreas Gohr         * @var string $method
534b1af9014SChristopher Smith         * @var bool   $nofollow
535ac7a515fSAndreas Gohr         * @var array  $params
536becfa414SGerrit Uitslag         * @var string $replacement
537ac7a515fSAndreas Gohr         */
538a453d131SAdrian Lang        extract($data);
539a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
540a453d131SAdrian Lang            $linktarget = $id;
541a453d131SAdrian Lang        } else {
542a453d131SAdrian Lang            $linktarget = wl($id, $params);
543a453d131SAdrian Lang        }
544a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
545becfa414SGerrit Uitslag        if(strpos($caption, '%s')){
546becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
547becfa414SGerrit Uitslag        }
548c7e90e3fSAnika Henke        $akey    = $addTitle = '';
549c7e90e3fSAnika Henke        if($accesskey) {
550c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
551c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
552c7e90e3fSAnika Henke        }
553b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
554ac7a515fSAndreas Gohr        $out = tpl_link(
555ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
556a453d131SAdrian Lang            'class="action '.$type.'" '.
557b1af9014SChristopher Smith                $akey.$rel.
558e0c26282SGerrit Uitslag                'title="'.hsc($caption).$addTitle.'"', true
559ac7a515fSAndreas Gohr        );
560a453d131SAdrian Lang    }
561a453d131SAdrian Lang    if($return) return $out;
562a453d131SAdrian Lang    echo $out;
563a453d131SAdrian Lang    return true;
564a453d131SAdrian Lang}
565a453d131SAdrian Lang
566a453d131SAdrian Lang/**
567a453d131SAdrian Lang * Check the actions and get data for buttons and links
568ed630903Sandi *
569ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
570a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
571a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
572e0c26282SGerrit Uitslag *
573ac7a515fSAndreas Gohr * @param string $type
574ac7a515fSAndreas Gohr * @return array|bool|string
575affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
576ed630903Sandi */
577a453d131SAdrian Langfunction tpl_get_action($type) {
578affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
579a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
5804c4b65c8SMichael Hamann    if($type == 'subscription') $type = 'subscribe';
5814887c154SAndreas Gohr    if($type == 'img_backto') $type = 'imgBackto';
582409d7af7SAndreas Gohr
5834887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
5844887c154SAndreas Gohr    if(class_exists($class)) {
5854887c154SAndreas Gohr        try {
5864887c154SAndreas Gohr            /** @var \dokuwiki\Menu\Item\AbstractItem $item */
5874887c154SAndreas Gohr            $item = new $class;
5884887c154SAndreas Gohr            $data = $item->getLegacyData();
5897b4365a7SGerrit Uitslag            $unknown = false;
5904887c154SAndreas Gohr        } catch(\RuntimeException $ignored) {
5914887c154SAndreas Gohr            return false;
592b8a111f5SMichael Klier        }
593ed630903Sandi    } else {
5944887c154SAndreas Gohr        global $ID;
5954887c154SAndreas Gohr        $data = array(
5964887c154SAndreas Gohr            'accesskey' => null,
5974887c154SAndreas Gohr            'type' => $type,
5984887c154SAndreas Gohr            'id' => $ID,
5994887c154SAndreas Gohr            'method' => 'get',
6004887c154SAndreas Gohr            'params' => array('do' => $type),
6014887c154SAndreas Gohr            'nofollow' => true,
6024887c154SAndreas Gohr            'replacement' => '',
603becfa414SGerrit Uitslag        );
6047b4365a7SGerrit Uitslag        $unknown = true;
605ed630903Sandi    }
6067b4365a7SGerrit Uitslag
607e1d9dcc8SAndreas Gohr    $evt = new Event('TPL_ACTION_GET', $data);
6087b4365a7SGerrit Uitslag    if($evt->advise_before()) {
6097b4365a7SGerrit Uitslag        //handle unknown types
6107b4365a7SGerrit Uitslag        if($unknown) {
61138d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6127b4365a7SGerrit Uitslag        }
6137b4365a7SGerrit Uitslag    }
6147b4365a7SGerrit Uitslag    $evt->advise_after();
6157b4365a7SGerrit Uitslag    unset($evt);
6167b4365a7SGerrit Uitslag
6177b4365a7SGerrit Uitslag    return $data;
618ed630903Sandi}
619ed630903Sandi
620ed630903Sandi/**
62101f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
62201f17825SAnika Henke *
62301f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
62442ea7f44SGerrit Uitslag *
62542ea7f44SGerrit Uitslag * @param string        $type action command
626ac7a515fSAndreas Gohr * @param bool          $link link or form button?
627e0c26282SGerrit Uitslag * @param string|bool   $wrapper HTML element wrapper
628ac7a515fSAndreas Gohr * @param bool          $return return or print
629ac7a515fSAndreas Gohr * @param string        $pre prefix for links
630ac7a515fSAndreas Gohr * @param string        $suf suffix for links
631ac7a515fSAndreas Gohr * @param string        $inner inner HTML for links
632ac7a515fSAndreas Gohr * @return bool|string
633affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
63401f17825SAnika Henke */
635ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
636affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
63701f17825SAnika Henke    $out = '';
638ac7a515fSAndreas Gohr    if($link) {
639e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
640ac7a515fSAndreas Gohr    } else {
641e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
642ac7a515fSAndreas Gohr    }
64301f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
64401f17825SAnika Henke
64501f17825SAnika Henke    if($return) return $out;
64601f17825SAnika Henke    print $out;
64701f17825SAnika Henke    return $out ? true : false;
64801f17825SAnika Henke}
64901f17825SAnika Henke
65001f17825SAnika Henke/**
6516b13307fSandi * Print the search form
6526b13307fSandi *
65372645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
65472645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
65572645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
65672645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
65772645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
65872645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
65972645b75SAndreas Gohr *
6606b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
66142ea7f44SGerrit Uitslag *
662ac7a515fSAndreas Gohr * @param bool $ajax
663ac7a515fSAndreas Gohr * @param bool $autocomplete
664ac7a515fSAndreas Gohr * @return bool
6656b13307fSandi */
66672645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
6676b13307fSandi    global $lang;
668c1e3b7d9Smatthiasgrimm    global $ACT;
669ad4aaef7SAndreas Gohr    global $QUERY;
670cbcc2fa5SMichael Große    global $ID;
671c1e3b7d9Smatthiasgrimm
672670ff54eSchris    // don't print the search form if search action has been disabled
67364276bbcSarbrk1    if(!actionOK('search')) return false;
674670ff54eSchris
6753c7a3327SMichael Große    $searchForm = new dokuwiki\Form\Form([
6763c7a3327SMichael Große        'action' => wl(),
6773c7a3327SMichael Große        'method' => 'get',
6783c7a3327SMichael Große        'role' => 'search',
6793c7a3327SMichael Große        'class' => 'search',
6803c7a3327SMichael Große        'id' => 'dw__search',
6817fa270bcSMichael Große    ], true);
6823eb2b869SMichael Große    $searchForm->addTagOpen('div')->addClass('no');
6833c7a3327SMichael Große    $searchForm->setHiddenField('do', 'search');
684d22b78c8SMichael Große    $searchForm->setHiddenField('id', $ID);
685d22b78c8SMichael Große    $searchForm->addTextInput('q')
6863c7a3327SMichael Große        ->addClass('edit')
6873c7a3327SMichael Große        ->attrs([
6883c7a3327SMichael Große            'title' => '[F]',
6893c7a3327SMichael Große            'accesskey' => 'f',
6903c7a3327SMichael Große            'placeholder' => $lang['btn_search'],
6913c7a3327SMichael Große            'autocomplete' => $autocomplete ? 'on' : 'off',
6923c7a3327SMichael Große        ])
6933c7a3327SMichael Große        ->id('qsearch__in')
6943c7a3327SMichael Große        ->val($ACT === 'search' ? $QUERY : '')
6953c7a3327SMichael Große        ->useInput(false)
6963c7a3327SMichael Große    ;
6973c7a3327SMichael Große    $searchForm->addButton('', $lang['btn_search'])->attrs([
6983c7a3327SMichael Große        'type' => 'submit',
6993c7a3327SMichael Große        'title' => $lang['btn_search'],
7003c7a3327SMichael Große    ]);
7013c7a3327SMichael Große    if ($ajax) {
7023c7a3327SMichael Große        $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
7033c7a3327SMichael Große        $searchForm->addTagClose('div');
7043c7a3327SMichael Große    }
7053eb2b869SMichael Große    $searchForm->addTagClose('div');
706*cbb44eabSAndreas Gohr    Event::createAndTrigger('FORM_QUICKSEARCH_OUTPUT', $searchForm);
7073c7a3327SMichael Große
7083c7a3327SMichael Große    echo $searchForm->toHTML();
7093c7a3327SMichael Große
71054e95700STom N Harris    return true;
7116b13307fSandi}
7126b13307fSandi
7136b13307fSandi/**
7146b13307fSandi * Print the breadcrumbs trace
7156b13307fSandi *
7166b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
71742ea7f44SGerrit Uitslag *
718ac7a515fSAndreas Gohr * @param string $sep Separator between entries
719c4a386f1SIain Hallam * @param bool   $return return or print
720c4a386f1SIain Hallam * @return bool|string
7216b13307fSandi */
722c4a386f1SIain Hallamfunction tpl_breadcrumbs($sep = null, $return = false) {
7236b13307fSandi    global $lang;
7246b13307fSandi    global $conf;
7256b13307fSandi
7266b13307fSandi    //check if enabled
727359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
7286b13307fSandi
729c4a386f1SIain Hallam    //set default
730c4a386f1SIain Hallam    if(is_null($sep)) $sep = '•';
731c4a386f1SIain Hallam
732c4a386f1SIain Hallam    $out='';
733c4a386f1SIain Hallam
7346b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
735265e3787Sandi
7362979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
737265e3787Sandi
73840eb54bbSjan    //render crumbs, highlight the last one
739c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
74040eb54bbSjan    $last = count($crumbs);
74140eb54bbSjan    $i    = 0;
742a77f5846Sjan    foreach($crumbs as $id => $name) {
74340eb54bbSjan        $i++;
744c4a386f1SIain Hallam        $out .= $crumbs_sep;
745c4a386f1SIain Hallam        if($i == $last) $out .= '<span class="curid">';
746c4a386f1SIain Hallam        $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) .  '</bdi>';
747c4a386f1SIain Hallam        if($i == $last) $out .= '</span>';
7486b13307fSandi    }
749c4a386f1SIain Hallam    if($return) return $out;
750c4a386f1SIain Hallam    print $out;
751c4a386f1SIain Hallam    return $out ? true : false;
7526b13307fSandi}
7536b13307fSandi
7546b13307fSandi/**
7551734437eSandi * Hierarchical breadcrumbs
7561734437eSandi *
75731e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7581734437eSandi * It only makes sense with a deep site structure.
7591734437eSandi *
7601734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7616bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
76231e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
763f46c9e83SAnika Henke * @author <fredrik@averpil.com>
76408d7a575SAndreas Gohr * @todo   May behave strangely in RTL languages
76542ea7f44SGerrit Uitslag *
766ac7a515fSAndreas Gohr * @param string $sep Separator between entries
767c4a386f1SIain Hallam * @param bool   $return return or print
768c4a386f1SIain Hallam * @return bool|string
7691734437eSandi */
770c4a386f1SIain Hallamfunction tpl_youarehere($sep = null, $return = false) {
7711734437eSandi    global $conf;
7721734437eSandi    global $ID;
7731734437eSandi    global $lang;
7741734437eSandi
77531e187f8SSean Coates    // check if enabled
77654e95700STom N Harris    if(!$conf['youarehere']) return false;
7771734437eSandi
778c4a386f1SIain Hallam    //set default
779c4a386f1SIain Hallam    if(is_null($sep)) $sep = ' » ';
780c4a386f1SIain Hallam
781c4a386f1SIain Hallam    $out = '';
782c4a386f1SIain Hallam
7831734437eSandi    $parts = explode(':', $ID);
784796bafb3SAndreas Gohr    $count = count($parts);
7851734437eSandi
786c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
7873940c519SMark
78808d7a575SAndreas Gohr    // always print the startpage
789c4a386f1SIain Hallam    $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
790796bafb3SAndreas Gohr
791796bafb3SAndreas Gohr    // print intermediate namespace links
792796bafb3SAndreas Gohr    $part = '';
793796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
794796bafb3SAndreas Gohr        $part .= $parts[$i].':';
795796bafb3SAndreas Gohr        $page = $part;
796796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
797796bafb3SAndreas Gohr
79808d7a575SAndreas Gohr        // output
799c4a386f1SIain Hallam        $out .= $sep . tpl_pagelink($page, null, true);
80031e187f8SSean Coates    }
8011734437eSandi
802796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
803e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
804a8c33dedSMichael Große    if (isset($page) && $page == $part.$parts[$i]) {
805a8c33dedSMichael Große        if($return) return $out;
806a8c33dedSMichael Große        print $out;
807a8c33dedSMichael Große        return true;
808a8c33dedSMichael Große    }
809796bafb3SAndreas Gohr    $page = $part.$parts[$i];
810a8c33dedSMichael Große    if($page == $conf['start']) {
811a8c33dedSMichael Große        if($return) return $out;
812a8c33dedSMichael Große        print $out;
813a8c33dedSMichael Große        return true;
814a8c33dedSMichael Große    }
815c4a386f1SIain Hallam    $out .= $sep;
816c4a386f1SIain Hallam    $out .= tpl_pagelink($page, null, true);
817c4a386f1SIain Hallam    if($return) return $out;
818c4a386f1SIain Hallam    print $out;
819c4a386f1SIain Hallam    return $out ? true : false;
8201734437eSandi}
8211734437eSandi
8221734437eSandi/**
8236b13307fSandi * Print info if the user is logged in
824a2488c3cSMatthias Grimm * and show full name in that case
8256b13307fSandi *
8266b13307fSandi * Could be enhanced with a profile link in future?
8276b13307fSandi *
8286b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
82942ea7f44SGerrit Uitslag *
830ac7a515fSAndreas Gohr * @return bool
8316b13307fSandi */
8326b13307fSandifunction tpl_userinfo() {
8336b13307fSandi    global $lang;
834585bf44eSChristopher Smith    /** @var Input $INPUT */
835585bf44eSChristopher Smith    global $INPUT;
836585bf44eSChristopher Smith
837585bf44eSChristopher Smith    if($INPUT->server->str('REMOTE_USER')) {
838fde860beSGerrit Uitslag        print $lang['loggedinas'].' '.userlink();
83954e95700STom N Harris        return true;
84054e95700STom N Harris    }
84154e95700STom N Harris    return false;
8426b13307fSandi}
8436b13307fSandi
8446b13307fSandi/**
8456b13307fSandi * Print some info about the current page
8466b13307fSandi *
8476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
84842ea7f44SGerrit Uitslag *
849ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
850ac7a515fSAndreas Gohr * @return bool|string
8516b13307fSandi */
8524b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
8536b13307fSandi    global $conf;
8546b13307fSandi    global $lang;
8556b13307fSandi    global $INFO;
856c6e92a3cSDavid Lorentsen    global $ID;
857c6e92a3cSDavid Lorentsen
858c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
859ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
860ac7a515fSAndreas Gohr        return false;
861ac7a515fSAndreas Gohr    }
8626b13307fSandi
8636b13307fSandi    // prepare date and path
8646b13307fSandi    $fn = $INFO['filepath'];
8656b13307fSandi    if(!$conf['fullpath']) {
866613bca54SAndreas Gohr        if($INFO['rev']) {
867c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'].'/', '', $fn);
8686b13307fSandi        } else {
869c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'].'/', '', $fn);
8706b13307fSandi        }
8716b13307fSandi    }
872bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
873f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
8746b13307fSandi
875faecdfdfSAndreas Gohr    // print it
876faecdfdfSAndreas Gohr    if($INFO['exists']) {
8774b0d3916SAndreas Gohr        $out = '';
878d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
879e260f93bSAnika Henke        $out .= ' · ';
8804b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
881fde860beSGerrit Uitslag        $out .= ' ';
8824b0d3916SAndreas Gohr        $out .= $date;
8836b13307fSandi        if($INFO['editor']) {
8844b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
885d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
8865aa52fafSBen Coburn        } else {
8874b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
8886b13307fSandi        }
8896b13307fSandi        if($INFO['locked']) {
890e260f93bSAnika Henke            $out .= ' · ';
8914b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
892fde860beSGerrit Uitslag            $out .= ' ';
893d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
8946b13307fSandi        }
8954b0d3916SAndreas Gohr        if($ret) {
8964b0d3916SAndreas Gohr            return $out;
8974b0d3916SAndreas Gohr        } else {
8984b0d3916SAndreas Gohr            echo $out;
89954e95700STom N Harris            return true;
9006b13307fSandi        }
9014b0d3916SAndreas Gohr    }
90254e95700STom N Harris    return false;
9036b13307fSandi}
9046b13307fSandi
905820fa24bSandi/**
906a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
90787c434ceSAndreas Gohr *
90887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
909a6598f23SBen Coburn * the given ID is used.
91087c434ceSAndreas Gohr *
91187c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
91242ea7f44SGerrit Uitslag *
913ac7a515fSAndreas Gohr * @param string $id page id
914ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
915ac7a515fSAndreas Gohr * @return bool|string
91687c434ceSAndreas Gohr */
917a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
918c248bda1SChristopher Smith    global $ACT, $INPUT, $conf, $lang;
919fffeeafeSChristopher Smith
92087c434ceSAndreas Gohr    if(is_null($id)) {
92187c434ceSAndreas Gohr        global $ID;
92287c434ceSAndreas Gohr        $id = $ID;
92387c434ceSAndreas Gohr    }
92487c434ceSAndreas Gohr
92587c434ceSAndreas Gohr    $name = $id;
926fe9ec250SChris Smith    if(useHeading('navigation')) {
927fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
928fffeeafeSChristopher Smith        if($first_heading) $name = $first_heading;
929fffeeafeSChristopher Smith    }
930fffeeafeSChristopher Smith
931fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
932fffeeafeSChristopher Smith    switch ($ACT) {
933fffeeafeSChristopher Smith        // admin functions
934fffeeafeSChristopher Smith        case 'admin' :
935fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
936fffeeafeSChristopher Smith            // try to get the plugin name
937e1d9dcc8SAndreas Gohr            /** @var $plugin AdminPlugin */
938a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()){
939c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
940a61966c5SChristopher Smith                $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
941fffeeafeSChristopher Smith            }
942fffeeafeSChristopher Smith            break;
943fffeeafeSChristopher Smith
944fffeeafeSChristopher Smith        // user functions
945fffeeafeSChristopher Smith        case 'login' :
946fffeeafeSChristopher Smith        case 'profile' :
947fffeeafeSChristopher Smith        case 'register' :
948fffeeafeSChristopher Smith        case 'resendpwd' :
949fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
950fffeeafeSChristopher Smith            break;
951fffeeafeSChristopher Smith
952fffeeafeSChristopher Smith         // wiki functions
953fffeeafeSChristopher Smith        case 'search' :
954fffeeafeSChristopher Smith        case 'index' :
955fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
956fffeeafeSChristopher Smith            break;
957fffeeafeSChristopher Smith
958fffeeafeSChristopher Smith        // page functions
959fffeeafeSChristopher Smith        case 'edit' :
960fffeeafeSChristopher Smith            $page_title = "✎ ".$name;
961fffeeafeSChristopher Smith            break;
962fffeeafeSChristopher Smith
963fffeeafeSChristopher Smith        case 'revisions' :
964fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
965fffeeafeSChristopher Smith            break;
966fffeeafeSChristopher Smith
967fffeeafeSChristopher Smith        case 'backlink' :
968fffeeafeSChristopher Smith        case 'recent' :
969fffeeafeSChristopher Smith        case 'subscribe' :
970fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_'.$ACT];
971fffeeafeSChristopher Smith            break;
972fffeeafeSChristopher Smith
973fffeeafeSChristopher Smith        default : // SHOW and anything else not included
974fffeeafeSChristopher Smith            $page_title = $name;
97587c434ceSAndreas Gohr    }
976a6598f23SBen Coburn
977a6598f23SBen Coburn    if($ret) {
978fffeeafeSChristopher Smith        return hsc($page_title);
979a6598f23SBen Coburn    } else {
980fffeeafeSChristopher Smith        print hsc($page_title);
98154e95700STom N Harris        return true;
98287c434ceSAndreas Gohr    }
983a6598f23SBen Coburn}
984340756e4Sandi
98555efc227SAndreas Gohr/**
98655efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
98755efc227SAndreas Gohr *
98855efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
98955efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
99055efc227SAndreas Gohr *
99155efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
99255efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
99355efc227SAndreas Gohr * to the names of the latter one)
99455efc227SAndreas Gohr *
9953df72098SAndreas Gohr * Only allowed in: detail.php
99655efc227SAndreas Gohr *
99755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
99842ea7f44SGerrit Uitslag *
99921d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
1000ac7a515fSAndreas Gohr * @param string       $alt  alternative output if no data was found
1001e0c26282SGerrit Uitslag * @param null|string  $src  the image src, uses global $SRC if not given
1002ac7a515fSAndreas Gohr * @return string
100355efc227SAndreas Gohr */
10043df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
100555efc227SAndreas Gohr    // Init Exif Reader
100655efc227SAndreas Gohr    global $SRC;
10073df72098SAndreas Gohr
10083df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
10093df72098SAndreas Gohr
101055efc227SAndreas Gohr    static $meta = null;
10113df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
101255efc227SAndreas Gohr    if($meta === false) return $alt;
101388945224SChristopher Smith    $info = cleanText($meta->getField($tags));
101455efc227SAndreas Gohr    if($info == false) return $alt;
101555efc227SAndreas Gohr    return $info;
101655efc227SAndreas Gohr}
101755efc227SAndreas Gohr
101855efc227SAndreas Gohr/**
1019becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
1020becfa414SGerrit Uitslag *
1021becfa414SGerrit Uitslag * @return string html of description list
1022becfa414SGerrit Uitslag */
1023becfa414SGerrit Uitslagfunction tpl_img_meta() {
1024becfa414SGerrit Uitslag    global $lang;
1025becfa414SGerrit Uitslag
1026becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1027becfa414SGerrit Uitslag
1028becfa414SGerrit Uitslag    echo '<dl>';
1029becfa414SGerrit Uitslag    foreach($tags as $tag) {
1030becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1031fde860beSGerrit Uitslag        if(!$label) $label = $tag['langkey'] . ':';
1032becfa414SGerrit Uitslag
1033fde860beSGerrit Uitslag        echo '<dt>'.$label.'</dt><dd>';
1034becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1035becfa414SGerrit Uitslag            echo dformat($tag['value']);
1036becfa414SGerrit Uitslag        } else {
1037becfa414SGerrit Uitslag            echo hsc($tag['value']);
1038becfa414SGerrit Uitslag        }
1039becfa414SGerrit Uitslag        echo '</dd>';
1040becfa414SGerrit Uitslag    }
1041becfa414SGerrit Uitslag    echo '</dl>';
1042becfa414SGerrit Uitslag}
1043becfa414SGerrit Uitslag
1044becfa414SGerrit Uitslag/**
1045becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1046becfa414SGerrit Uitslag *
1047becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1048becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1049becfa414SGerrit Uitslag *   - string type     type of value
1050becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1051becfa414SGerrit Uitslag */
1052becfa414SGerrit Uitslagfunction tpl_get_img_meta() {
1053becfa414SGerrit Uitslag
1054becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1055becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
105679e79377SAndreas Gohr        if(file_exists($config_file)) {
1057becfa414SGerrit Uitslag            include($config_file);
1058becfa414SGerrit Uitslag        }
1059becfa414SGerrit Uitslag    }
1060becfa414SGerrit Uitslag    /** @var array $fields the included array with metadata */
1061becfa414SGerrit Uitslag
1062becfa414SGerrit Uitslag    $tags = array();
1063becfa414SGerrit Uitslag    foreach($fields as $tag){
1064becfa414SGerrit Uitslag        $t = array();
1065becfa414SGerrit Uitslag        if (!empty($tag[0])) {
1066becfa414SGerrit Uitslag            $t = array($tag[0]);
1067becfa414SGerrit Uitslag        }
1068becfa414SGerrit Uitslag        if(is_array($tag[3])) {
1069becfa414SGerrit Uitslag            $t = array_merge($t,$tag[3]);
1070becfa414SGerrit Uitslag        }
1071becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1072becfa414SGerrit Uitslag        if ($value) {
1073becfa414SGerrit Uitslag            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1074becfa414SGerrit Uitslag        }
1075becfa414SGerrit Uitslag    }
1076becfa414SGerrit Uitslag    return $tags;
1077becfa414SGerrit Uitslag}
1078becfa414SGerrit Uitslag
1079becfa414SGerrit Uitslag/**
108055efc227SAndreas Gohr * Prints the image with a link to the full sized version
108155efc227SAndreas Gohr *
108255efc227SAndreas Gohr * Only allowed in: detail.php
1083a02d2933SAndreas Gohr *
1084ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1085a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1086a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1087a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1088a02d2933SAndreas Gohr * @param $params array  - additional image attributes
108942ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
109055efc227SAndreas Gohr */
1091a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
109255efc227SAndreas Gohr    global $IMG;
1093585bf44eSChristopher Smith    /** @var Input $INPUT */
1094ac7a515fSAndreas Gohr    global $INPUT;
10955c2eed9aSlisps    global $REV;
109665d3a5dbSAndreas Gohr    $w = (int) tpl_img_getTag('File.Width');
109765d3a5dbSAndreas Gohr    $h = (int) tpl_img_getTag('File.Height');
109855efc227SAndreas Gohr
109955efc227SAndreas Gohr    //resize to given max values
110023a34783SAndreas Gohr    $ratio = 1;
110123a34783SAndreas Gohr    if($w >= $h) {
1102f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
110355efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1104f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
110555efc227SAndreas Gohr            $ratio = $maxheight / $h;
110655efc227SAndreas Gohr        }
110755efc227SAndreas Gohr    } else {
1108f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
110955efc227SAndreas Gohr            $ratio = $maxheight / $h;
1110f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
111155efc227SAndreas Gohr            $ratio = $maxwidth / $w;
111255efc227SAndreas Gohr        }
111355efc227SAndreas Gohr    }
111455efc227SAndreas Gohr    if($ratio) {
111555efc227SAndreas Gohr        $w = floor($ratio * $w);
111655efc227SAndreas Gohr        $h = floor($ratio * $h);
111755efc227SAndreas Gohr    }
111855efc227SAndreas Gohr
11196de3759aSAndreas Gohr    //prepare URLs
11205c2eed9aSlisps    $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
11215c2eed9aSlisps    $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
112255efc227SAndreas Gohr
11232684e50aSAndreas Gohr    //prepare attributes
112455efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1125a02d2933SAndreas Gohr    if(is_null($params)) {
11262684e50aSAndreas Gohr        $p = array();
1127a02d2933SAndreas Gohr    } else {
1128a02d2933SAndreas Gohr        $p = $params;
1129a02d2933SAndreas Gohr    }
11302684e50aSAndreas Gohr    if($w) $p['width'] = $w;
11312684e50aSAndreas Gohr    if($h) $p['height'] = $h;
11322684e50aSAndreas Gohr    $p['class'] = 'img_detail';
11332684e50aSAndreas Gohr    if($alt) {
11342684e50aSAndreas Gohr        $p['alt']   = $alt;
11352684e50aSAndreas Gohr        $p['title'] = $alt;
11362684e50aSAndreas Gohr    } else {
11372684e50aSAndreas Gohr        $p['alt'] = '';
11382684e50aSAndreas Gohr    }
1139a02d2933SAndreas Gohr    $p['src'] = $src;
114055efc227SAndreas Gohr
1141a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1142*cbb44eabSAndreas Gohr    return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1143a02d2933SAndreas Gohr}
1144a02d2933SAndreas Gohr
1145a02d2933SAndreas Gohr/**
1146a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1147ac7a515fSAndreas Gohr *
1148ac7a515fSAndreas Gohr * @param array $data
1149ac7a515fSAndreas Gohr * @return bool
1150a02d2933SAndreas Gohr */
1151ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
115259f3611bSAnika Henke    global $lang;
1153a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1154a02d2933SAndreas Gohr
115559f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1156a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1157a02d2933SAndreas Gohr    if($data['url']) print '</a>';
115854e95700STom N Harris    return true;
115955efc227SAndreas Gohr}
116055efc227SAndreas Gohr
11617367b368SAndreas Gohr/**
1162881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11637367b368SAndreas Gohr *
11647367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11657367b368SAndreas Gohr * template
1166ac7a515fSAndreas Gohr *
1167ac7a515fSAndreas Gohr * @return bool
11687367b368SAndreas Gohr */
11697367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11707367b368SAndreas Gohr    global $ID;
11711dad36f5SAndreas Gohr
11727367b368SAndreas Gohr    $p           = array();
11734af80fe8SMichael Große    $p['src']    = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID).
1174e68c51baSAndreas Gohr        '&'.time();
1175881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11767367b368SAndreas Gohr    $p['height'] = 1;
11777367b368SAndreas Gohr    $p['alt']    = '';
11787367b368SAndreas Gohr    $att         = buildAttributes($p);
11797367b368SAndreas Gohr    print "<img $att />";
118054e95700STom N Harris    return true;
11817367b368SAndreas Gohr}
11827367b368SAndreas Gohr
118378d4e784SEsther Brunner/**
118478d4e784SEsther Brunner * tpl_getConf($id)
118578d4e784SEsther Brunner *
118678d4e784SEsther Brunner * use this function to access template configuration variables
1187ac7a515fSAndreas Gohr *
118817448fb8SChristopher Smith * @param string $id      name of the value to access
118917448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
119017448fb8SChristopher Smith * @return mixed
119178d4e784SEsther Brunner */
119217448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
119378d4e784SEsther Brunner    global $conf;
119417566ac6SAdrian Lang    static $tpl_configloaded = false;
119578d4e784SEsther Brunner
119678d4e784SEsther Brunner    $tpl = $conf['template'];
119778d4e784SEsther Brunner
119878d4e784SEsther Brunner    if(!$tpl_configloaded) {
119978d4e784SEsther Brunner        $tconf = tpl_loadConfig();
120078d4e784SEsther Brunner        if($tconf !== false) {
120178d4e784SEsther Brunner            foreach($tconf as $key => $value) {
120278d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
120378d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
120478d4e784SEsther Brunner            }
120578d4e784SEsther Brunner            $tpl_configloaded = true;
120678d4e784SEsther Brunner        }
120778d4e784SEsther Brunner    }
120878d4e784SEsther Brunner
120917448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
121078d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
121178d4e784SEsther Brunner    }
121278d4e784SEsther Brunner
121317448fb8SChristopher Smith    return $notset;
121417448fb8SChristopher Smith}
121517448fb8SChristopher Smith
121678d4e784SEsther Brunner/**
121778d4e784SEsther Brunner * tpl_loadConfig()
1218ac7a515fSAndreas Gohr *
121978d4e784SEsther Brunner * reads all template configuration variables
122078d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1221ac7a515fSAndreas Gohr *
1222ac7a515fSAndreas Gohr * @return array
122378d4e784SEsther Brunner */
122478d4e784SEsther Brunnerfunction tpl_loadConfig() {
122578d4e784SEsther Brunner
1226c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
122778d4e784SEsther Brunner    $conf = array();
122878d4e784SEsther Brunner
122979e79377SAndreas Gohr    if(!file_exists($file)) return false;
123078d4e784SEsther Brunner
123178d4e784SEsther Brunner    // load default config file
123278d4e784SEsther Brunner    include($file);
123378d4e784SEsther Brunner
123478d4e784SEsther Brunner    return $conf;
123578d4e784SEsther Brunner}
123678d4e784SEsther Brunner
123717566ac6SAdrian Lang// language methods
123817566ac6SAdrian Lang/**
123917566ac6SAdrian Lang * tpl_getLang($id)
124017566ac6SAdrian Lang *
124117566ac6SAdrian Lang * use this function to access template language variables
124242ea7f44SGerrit Uitslag *
124342ea7f44SGerrit Uitslag * @param string $id key of language string
124442ea7f44SGerrit Uitslag * @return string
124517566ac6SAdrian Lang */
124617566ac6SAdrian Langfunction tpl_getLang($id) {
124717566ac6SAdrian Lang    static $lang = array();
124817566ac6SAdrian Lang
124917566ac6SAdrian Lang    if(count($lang) === 0) {
1250dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1251dd7a6159SGerrit Uitslag
1252c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
125317566ac6SAdrian Lang
125417566ac6SAdrian Lang        $lang = array();
125517566ac6SAdrian Lang
125617566ac6SAdrian Lang        // don't include once
125717566ac6SAdrian Lang        @include($path . 'en/lang.php');
1258dd7a6159SGerrit Uitslag        foreach($config_cascade['lang']['template'] as $config_file) {
125979e79377SAndreas Gohr            if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1260dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1261dd7a6159SGerrit Uitslag            }
126217566ac6SAdrian Lang        }
126317566ac6SAdrian Lang
1264dd7a6159SGerrit Uitslag        if($conf['lang'] != 'en') {
1265dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1266dd7a6159SGerrit Uitslag            foreach($config_cascade['lang']['template'] as $config_file) {
126779e79377SAndreas Gohr                if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1268dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1269dd7a6159SGerrit Uitslag                }
1270dd7a6159SGerrit Uitslag            }
1271dd7a6159SGerrit Uitslag        }
127217566ac6SAdrian Lang    }
127317566ac6SAdrian Lang    return $lang[$id];
127417566ac6SAdrian Lang}
127517566ac6SAdrian Lang
12763df72098SAndreas Gohr/**
1277c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1278e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1279e8ec13b9SKlap-in *
1280e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1281e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1282e8ec13b9SKlap-in */
1283e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1284c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1285e8ec13b9SKlap-in}
1286e8ec13b9SKlap-in
1287e8ec13b9SKlap-in/**
1288c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
128942ea7f44SGerrit Uitslag *
129042ea7f44SGerrit Uitslag * @param string $id id of localized text
129142ea7f44SGerrit Uitslag * @return string wiki text
1292e8ec13b9SKlap-in */
1293c5c17fdaSKlap-infunction tpl_localeFN($id) {
1294e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1295e8ec13b9SKlap-in    global $conf;
129638fb1fc7SGerrit Uitslag    $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
129779e79377SAndreas Gohr    if (!file_exists($file)){
1298e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
129979e79377SAndreas Gohr        if(!file_exists($file)){
1300e8ec13b9SKlap-in            //fall back to english
1301e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1302e8ec13b9SKlap-in        }
1303e8ec13b9SKlap-in    }
1304e8ec13b9SKlap-in    return $file;
1305e8ec13b9SKlap-in}
1306e8ec13b9SKlap-in
1307e8ec13b9SKlap-in/**
13087abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
13093df72098SAndreas Gohr *
13103df72098SAndreas Gohr * Depending on the user's actions this may be a list of
13113df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
13123df72098SAndreas Gohr * a message of referencing pages
13133df72098SAndreas Gohr *
13143df72098SAndreas Gohr * Only allowed in mediamanager.php
13153df72098SAndreas Gohr *
1316c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1317c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
131842ea7f44SGerrit Uitslag * @param string $sort
13198702de7fSGerrit Uitslag *
13203df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13213df72098SAndreas Gohr */
132200e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
13233df72098SAndreas Gohr    global $IMG;
13243df72098SAndreas Gohr    global $AUTH;
13253df72098SAndreas Gohr    global $INUSE;
13263df72098SAndreas Gohr    global $NS;
13273df72098SAndreas Gohr    global $JUMPTO;
1328585bf44eSChristopher Smith    /** @var Input $INPUT */
1329ac7a515fSAndreas Gohr    global $INPUT;
13303df72098SAndreas Gohr
1331ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1332c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1333c182313eSAndreas Gohr
1334c182313eSAndreas Gohr    if(!$do) {
1335ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1336c182313eSAndreas Gohr            $do = 'metaform';
1337c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1338c182313eSAndreas Gohr            $do = 'filesinuse';
1339c182313eSAndreas Gohr        } else {
1340c182313eSAndreas Gohr            $do = 'filelist';
1341c182313eSAndreas Gohr        }
1342c182313eSAndreas Gohr    }
1343c182313eSAndreas Gohr
1344c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1345c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1346c182313eSAndreas Gohr    $data = array('do' => $do);
1347e1d9dcc8SAndreas Gohr    $evt  = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1348c182313eSAndreas Gohr    if($evt->advise_before()) {
1349c182313eSAndreas Gohr        $do = $data['do'];
135030fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1351c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1352c182313eSAndreas Gohr        } elseif($do == 'filelist') {
135300e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1354c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1355ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1356c182313eSAndreas Gohr        } else {
1357c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1358c182313eSAndreas Gohr        }
1359c182313eSAndreas Gohr    }
1360c182313eSAndreas Gohr    $evt->advise_after();
1361c182313eSAndreas Gohr    unset($evt);
1362c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1363c182313eSAndreas Gohr
13643df72098SAndreas Gohr}
13653df72098SAndreas Gohr
13663df72098SAndreas Gohr/**
1367d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1368d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1369d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1370d9162c6cSKate Arzamastseva *
1371d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1372d9162c6cSKate Arzamastseva */
1373035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1374d9162c6cSKate Arzamastseva    global $AUTH;
1375d9162c6cSKate Arzamastseva    global $NS;
1376d9162c6cSKate Arzamastseva    global $JUMPTO;
137795b451bcSAdrian Lang    global $lang;
1378585bf44eSChristopher Smith    /** @var Input $INPUT */
1379ac7a515fSAndreas Gohr    global $INPUT;
1380d9162c6cSKate Arzamastseva
1381ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1382e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1383ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1384d9162c6cSKate Arzamastseva
138594add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
138695b451bcSAdrian Lang
1387ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
138823846a98SKate Arzamastseva
138994add303SAnika Henke    echo '<div class="panelHeader">'.NL;
139095b451bcSAdrian Lang    echo '<h3>';
1391026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1392c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
139394add303SAnika Henke    echo '</h3>'.NL;
139495b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
139595b451bcSAdrian Lang        media_tab_files_options();
139623846a98SKate Arzamastseva    }
139794add303SAnika Henke    echo '</div>'.NL;
1398d9162c6cSKate Arzamastseva
139994add303SAnika Henke    echo '<div class="panelContent">'.NL;
140095b451bcSAdrian Lang    if($opened_tab == 'files') {
140195b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
140295b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
140395b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
140495b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
140595b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
140695b451bcSAdrian Lang    }
140794add303SAnika Henke    echo '</div>'.NL;
1408d9162c6cSKate Arzamastseva}
1409d9162c6cSKate Arzamastseva
1410d9162c6cSKate Arzamastseva/**
1411d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1412d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1413d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1414d9162c6cSKate Arzamastseva * list of file revisions
1415d9162c6cSKate Arzamastseva *
1416d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1417f50a239bSTakamura *
1418f50a239bSTakamura * @param string $image
1419f50a239bSTakamura * @param boolean $rev
1420d9162c6cSKate Arzamastseva */
1421035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1422e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1423585bf44eSChristopher Smith    /** @var Input $INPUT */
1424585bf44eSChristopher Smith    global $INPUT;
1425d9162c6cSKate Arzamastseva
142664159a61SAndreas Gohr    $removed = (
142764159a61SAndreas Gohr        !file_exists(mediaFN($image)) &&
142864159a61SAndreas Gohr        file_exists(mediaMetaFN($image, '.changes')) &&
142964159a61SAndreas Gohr        $conf['mediarevisions']
143064159a61SAndreas Gohr    );
1431ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
14326dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1433e8a2a143SMichael Hamann    $ns = getNS($image);
1434ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
14351eeeced2SKate Arzamastseva
1436ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1437e5d185e1SKate Arzamastseva
1438e5d185e1SKate Arzamastseva    $tab_array = array('view');
1439ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1440e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1441e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1442e5d185e1SKate Arzamastseva    }
1443e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1444e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1445e5d185e1SKate Arzamastseva    }
1446e5d185e1SKate Arzamastseva
1447e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1448ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
144923846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1450d9162c6cSKate Arzamastseva
1451ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
145223846a98SKate Arzamastseva
145359f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1454ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
145595b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
145695b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
1457750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
145864159a61SAndreas Gohr    $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.
145964159a61SAndreas Gohr        $image.'</a>'.'</strong>';
146008317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
146108317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
146208317413SAdrian Lang    } else {
1463026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
146408317413SAdrian Lang    }
1465b8a84c03SAndreas Gohr
146694add303SAnika Henke    echo '</h3></div>'.NL;
146795b451bcSAdrian Lang
146894add303SAnika Henke    echo '<div class="panelContent">'.NL;
146995b451bcSAdrian Lang
147023846a98SKate Arzamastseva    if($opened_tab == 'view') {
1471e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
147223846a98SKate Arzamastseva
147392cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
1474e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
147523846a98SKate Arzamastseva
1476e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1477e8a2a143SMichael Hamann        media_tab_history($image, $ns);
147823846a98SKate Arzamastseva    }
147995b451bcSAdrian Lang
148094add303SAnika Henke    echo '</div>'.NL;
1481d9162c6cSKate Arzamastseva}
1482d9162c6cSKate Arzamastseva
1483d9162c6cSKate Arzamastseva/**
14847abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
14853df72098SAndreas Gohr *
14863df72098SAndreas Gohr * Only allowed in mediamanager.php
14873df72098SAndreas Gohr *
14883df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14893df72098SAndreas Gohr */
1490fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14913df72098SAndreas Gohr    global $NS;
149223846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14933df72098SAndreas Gohr    media_nstree($NS);
14943df72098SAndreas Gohr    ptln('</div>');
14953df72098SAndreas Gohr}
14963df72098SAndreas Gohr
1497a00de5b5SAndreas Gohr/**
1498a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1499a00de5b5SAndreas Gohr *
1500a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1501a00de5b5SAndreas Gohr *
1502a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
150342ea7f44SGerrit Uitslag *
150442ea7f44SGerrit Uitslag * @param string $empty empty option label
150542ea7f44SGerrit Uitslag * @param string $button submit button label
1506affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1507a00de5b5SAndreas Gohr */
1508a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1509affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
15101e875dcdSAndreas Gohr    $menu = new \dokuwiki\Menu\MobileMenu();
15111e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1512a00de5b5SAndreas Gohr}
1513a00de5b5SAndreas Gohr
1514066fee30SAndreas Gohr/**
1515066fee30SAndreas Gohr * Print a informational line about the used license
1516066fee30SAndreas Gohr *
1517066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1518ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1519ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1520ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1521ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1522ac7a515fSAndreas Gohr * @return string
1523066fee30SAndreas Gohr */
152480083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1525066fee30SAndreas Gohr    global $license;
1526066fee30SAndreas Gohr    global $conf;
1527066fee30SAndreas Gohr    global $lang;
1528066fee30SAndreas Gohr    if(!$conf['license']) return '';
1529066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1530066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
153153e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1532066fee30SAndreas Gohr
153380083a41SAndreas Gohr    $out = '';
153480083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1535066fee30SAndreas Gohr    if($img) {
1536066fee30SAndreas Gohr        $src = license_img($img);
1537066fee30SAndreas Gohr        if($src) {
153853e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
153953e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
154053e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1541066fee30SAndreas Gohr        }
1542066fee30SAndreas Gohr    }
15434cefd216SMichael Klier    if(!$imgonly) {
154453e15c8bSAnika Henke        $out .= $lang['license'].' ';
1545d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1546d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
15474cefd216SMichael Klier    }
154880083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1549066fee30SAndreas Gohr
1550066fee30SAndreas Gohr    if($return) return $out;
1551066fee30SAndreas Gohr    echo $out;
1552ac7a515fSAndreas Gohr    return '';
1553066fee30SAndreas Gohr}
1554066fee30SAndreas Gohr
1555a81910eeSAndreas Gohr/**
1556835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1557a81910eeSAndreas Gohr *
1558a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1559a81910eeSAndreas Gohr * template
1560e0c26282SGerrit Uitslag *
15617a112df5SAndreas Gohr * @param string $pageid The page name you want to include
15627a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
15637a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
15647c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1565e0c26282SGerrit Uitslag * @return bool|null|string
1566a81910eeSAndreas Gohr */
15677c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
15687a112df5SAndreas Gohr    if($propagate) {
15697c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
15707c3e4a67SAndreas Gohr    } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
15717a112df5SAndreas Gohr        return false;
15727a112df5SAndreas Gohr    }
1573c786a1b6SAnika Henke    if(!$pageid) return false;
1574835dfcaeSAnika Henke
1575c786a1b6SAnika Henke    global $TOC;
15769a2e250aSAndreas Gohr    $oldtoc = $TOC;
1577a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
15789a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1579a81910eeSAndreas Gohr
1580a2e03c82SAndreas Gohr    if($print) echo $html;
1581e66d3e6dSAndreas Gohr    return $html;
1582e66d3e6dSAndreas Gohr}
1583e66d3e6dSAndreas Gohr
1584e66d3e6dSAndreas Gohr/**
15855b75cd1fSAdrian Lang * Display the subscribe form
15865b75cd1fSAdrian Lang *
15875b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15885b75cd1fSAdrian Lang */
15895b75cd1fSAdrian Langfunction tpl_subscribe() {
15905b75cd1fSAdrian Lang    global $INFO;
15915b75cd1fSAdrian Lang    global $ID;
15925b75cd1fSAdrian Lang    global $lang;
15936b8f02cfSAdrian Lang    global $conf;
159440c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15955b75cd1fSAdrian Lang
15965b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15975b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
159815741132SAndreas Gohr    echo '<div class="level2">';
15995b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
16005b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
16015b75cd1fSAdrian Lang    } else {
16025b75cd1fSAdrian Lang        echo '<ul>';
16035b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1604056c2049SAndreas Gohr            echo '<li><div class="li">';
16055b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1606056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
16075b75cd1fSAdrian Lang            } else {
1608056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
16095b75cd1fSAdrian Lang            }
161040c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
161115741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1612056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
161315741132SAndreas Gohr
1614ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1615ac7a515fSAndreas Gohr                $ID,
1616ac7a515fSAndreas Gohr                array(
1617ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
161866d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
161966d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
162066d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1621ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1622ac7a515fSAndreas Gohr                )
1623ac7a515fSAndreas Gohr            ).
162466d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
162566d2bed9SAdrian Lang                '</a></div></li>';
16265b75cd1fSAdrian Lang        }
16275b75cd1fSAdrian Lang        echo '</ul>';
16285b75cd1fSAdrian Lang    }
162915741132SAndreas Gohr    echo '</div>';
16305b75cd1fSAdrian Lang
163115741132SAndreas Gohr    // Add new subscription form
16325b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
163315741132SAndreas Gohr    echo '<div class="level2">';
16345b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
163515741132SAndreas Gohr    $targets = array(
163615741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
163715741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
163815741132SAndreas Gohr    );
163915741132SAndreas Gohr    $styles  = array(
164015741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
16416b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
16426b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
164315741132SAndreas Gohr    );
164415741132SAndreas Gohr
1645056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1646056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1647056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1648056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1649056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1650056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1651056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1652056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1653056c2049SAndreas Gohr    $form->endFieldset();
16545b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
16555b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
165615741132SAndreas Gohr    echo '</div>';
16575b75cd1fSAdrian Lang}
16585b75cd1fSAdrian Lang
1659d059ba9bSAndreas Gohr/**
1660d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1661d059ba9bSAndreas Gohr *
1662d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1663d059ba9bSAndreas Gohr *
1664d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1665d059ba9bSAndreas Gohr */
1666d059ba9bSAndreas Gohrfunction tpl_flush() {
1667d059ba9bSAndreas Gohr    ob_flush();
1668d059ba9bSAndreas Gohr    flush();
1669d059ba9bSAndreas Gohr}
1670d059ba9bSAndreas Gohr
1671afca7e7eSAnika Henke/**
1672378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1673afca7e7eSAnika Henke *
1674378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1675378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1676378325f9SAndreas Gohr *
167742ea7f44SGerrit Uitslag * @param  string[] $search       locations to look at
1678378325f9SAndreas Gohr * @param  bool     $abs           if to use absolute URL
1679ac7a515fSAndreas Gohr * @param  array   &$imginfo   filled with getimagesize()
1680ac7a515fSAndreas Gohr * @return string
168142ea7f44SGerrit Uitslag *
1682378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1683afca7e7eSAnika Henke */
1684378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1685ac7a515fSAndreas Gohr    $img     = '';
1686ac7a515fSAndreas Gohr    $file    = '';
1687ac7a515fSAndreas Gohr    $ismedia = false;
1688378325f9SAndreas Gohr    // loop through candidates until a match was found:
1689378325f9SAndreas Gohr    foreach($search as $img) {
1690378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1691378325f9SAndreas Gohr            $file    = mediaFN($img);
1692378325f9SAndreas Gohr            $ismedia = true;
1693378325f9SAndreas Gohr        } else {
1694c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1695378325f9SAndreas Gohr            $ismedia = false;
16961f13e33dSAnika Henke        }
16970f747863Slupo49
1698378325f9SAndreas Gohr        if(file_exists($file)) break;
1699872a6d29SAnika Henke    }
1700378325f9SAndreas Gohr
1701378325f9SAndreas Gohr    // fetch image data if requested
1702378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1703378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1704378325f9SAndreas Gohr    }
1705378325f9SAndreas Gohr
1706378325f9SAndreas Gohr    // build URL
1707378325f9SAndreas Gohr    if($ismedia) {
1708378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1709378325f9SAndreas Gohr    } else {
1710c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1711378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1712378325f9SAndreas Gohr    }
1713378325f9SAndreas Gohr
1714378325f9SAndreas Gohr    return $url;
1715a7e5f74cSlupo49}
17161f13e33dSAnika Henke
1717872a6d29SAnika Henke/**
1718e5d4768dSAndreas Gohr * PHP include a file
1719e5d4768dSAndreas Gohr *
1720e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1721e5d4768dSAndreas Gohr * file in the template's root directory.
1722e5d4768dSAndreas Gohr *
1723e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1724e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1725e5d4768dSAndreas Gohr * default.
1726e5d4768dSAndreas Gohr *
1727e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1728e5d4768dSAndreas Gohr * to this function!
1729e5d4768dSAndreas Gohr *
1730e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1731e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
173242ea7f44SGerrit Uitslag *
173342ea7f44SGerrit Uitslag * @param string $file
1734e5d4768dSAndreas Gohr */
1735e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1736e5d4768dSAndreas Gohr    global $config_cascade;
1737e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1738e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1739e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1740e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1741e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1742f3a1225fSAnika Henke                include("$dir/$file");
1743e5d4768dSAndreas Gohr                return;
1744e5d4768dSAndreas Gohr            }
1745e5d4768dSAndreas Gohr        }
1746e5d4768dSAndreas Gohr    }
1747e5d4768dSAndreas Gohr
1748e5d4768dSAndreas Gohr    // still here? try the template dir
1749e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1750e5d4768dSAndreas Gohr    if(file_exists($file)) {
1751f3a1225fSAnika Henke        include($file);
1752e5d4768dSAndreas Gohr    }
1753e5d4768dSAndreas Gohr}
1754e5d4768dSAndreas Gohr
1755e5d4768dSAndreas Gohr/**
1756872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1757872a6d29SAnika Henke *
1758872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
175942ea7f44SGerrit Uitslag *
1760ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1761ac7a515fSAndreas Gohr * @return string
1762872a6d29SAnika Henke */
1763872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1764872a6d29SAnika Henke
1765872a6d29SAnika Henke    $return = '';
1766872a6d29SAnika Henke
1767872a6d29SAnika Henke    foreach($types as $type) {
1768872a6d29SAnika Henke        switch($type) {
1769872a6d29SAnika Henke            case 'favicon':
1770378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1771378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1772872a6d29SAnika Henke                break;
1773872a6d29SAnika Henke            case 'mobile':
1774cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1775378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1776872a6d29SAnika Henke                break;
1777872a6d29SAnika Henke            case 'generic':
1778872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1779378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1780378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1781872a6d29SAnika Henke                break;
1782872a6d29SAnika Henke        }
1783872a6d29SAnika Henke    }
1784872a6d29SAnika Henke
1785872a6d29SAnika Henke    return $return;
1786afca7e7eSAnika Henke}
1787afca7e7eSAnika Henke
1788d9162c6cSKate Arzamastseva/**
1789d9162c6cSKate Arzamastseva * Prints full-screen media manager
1790d9162c6cSKate Arzamastseva *
1791d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1792d9162c6cSKate Arzamastseva */
1793d9162c6cSKate Arzamastsevafunction tpl_media() {
1794ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
179588a71175SKate Arzamastseva    $fullscreen = true;
179695b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1797d9162c6cSKate Arzamastseva
1798ac7a515fSAndreas Gohr    $rev   = '';
1799ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
180098f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
180198f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
18029c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
180398f03b57SKate Arzamastseva
180494add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1805bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1806d9162c6cSKate Arzamastseva    html_msgarea();
180794add303SAnika Henke
180894add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
180994add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
181095b451bcSAdrian Lang    echo '<div class="panelHeader">';
1811ba340a70SAnika Henke    echo $lang['media_namespaces'];
181294add303SAnika Henke    echo '</div>'.NL;
181395b451bcSAdrian Lang
181494add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
181595b451bcSAdrian Lang    media_nstree($NS);
181694add303SAnika Henke    echo '</div>'.NL;
181794add303SAnika Henke    echo '</div>'.NL;
1818fa8e5c77SKate Arzamastseva
181994add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1820035e07f1SKate Arzamastseva    tpl_mediaFileList();
182194add303SAnika Henke    echo '</div>'.NL;
1822fa8e5c77SKate Arzamastseva
182394add303SAnika Henke    echo '<div class="panel file">'.NL;
182494add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1825035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
182694add303SAnika Henke    echo '</div>'.NL;
1827ba340a70SAnika Henke
182894add303SAnika Henke    echo '</div>'.NL;
1829d9162c6cSKate Arzamastseva}
1830afca7e7eSAnika Henke
1831c71db656SAnika Henke/**
1832c71db656SAnika Henke * Return useful layout classes
1833c71db656SAnika Henke *
1834c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
183542ea7f44SGerrit Uitslag *
183642ea7f44SGerrit Uitslag * @return string
1837c71db656SAnika Henke */
1838c71db656SAnika Henkefunction tpl_classes() {
1839c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1840585bf44eSChristopher Smith    /** @var Input $INPUT */
1841585bf44eSChristopher Smith    global $INPUT;
1842585bf44eSChristopher Smith
1843c71db656SAnika Henke    $classes = array(
1844c71db656SAnika Henke        'dokuwiki',
1845c71db656SAnika Henke        'mode_'.$ACT,
1846c71db656SAnika Henke        'tpl_'.$conf['template'],
1847585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
184839f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1849c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1850c71db656SAnika Henke    );
1851c71db656SAnika Henke    return join(' ', $classes);
1852c71db656SAnika Henke}
1853c71db656SAnika Henke
185484dd2b1aSGerrit Uitslag/**
185584dd2b1aSGerrit Uitslag * Create event for tools menues
185684dd2b1aSGerrit Uitslag *
185784dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
185884dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
185984dd2b1aSGerrit Uitslag * @param array $items
186084dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1861affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
186284dd2b1aSGerrit Uitslag */
186384dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') {
1864affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
186584dd2b1aSGerrit Uitslag    $data = array(
186684dd2b1aSGerrit Uitslag        'view' => $view,
186784dd2b1aSGerrit Uitslag        'items' => $items
186884dd2b1aSGerrit Uitslag    );
186984dd2b1aSGerrit Uitslag
187084dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
1871e1d9dcc8SAndreas Gohr    $evt = new Event($hook, $data);
187284dd2b1aSGerrit Uitslag    if($evt->advise_before()) {
187384dd2b1aSGerrit Uitslag        foreach($evt->data['items'] as $k => $html) echo $html;
187484dd2b1aSGerrit Uitslag    }
187584dd2b1aSGerrit Uitslag    $evt->advise_after();
187684dd2b1aSGerrit Uitslag}
187784dd2b1aSGerrit Uitslag
1878e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1879a00de5b5SAndreas Gohr
1880