xref: /dokuwiki/inc/template.php (revision a8c33ded53a4e05ef3de7fc852a1a3ba0dfb7246)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki template functions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
106b13307fSandi
116b13307fSandi/**
12ac7a515fSAndreas Gohr * Access a template file
13ac7a515fSAndreas Gohr *
14ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
15ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
165a892029SAndreas Gohr *
175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
18ac7a515fSAndreas Gohr * @param string $file
19ac7a515fSAndreas Gohr * @return string
205a892029SAndreas Gohr */
21ac7a515fSAndreas Gohrfunction template($file) {
225a892029SAndreas Gohr    global $conf;
235a892029SAndreas Gohr
24ac7a515fSAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
25ac7a515fSAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
265a892029SAndreas Gohr
27ac7a515fSAndreas Gohr    return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
285a892029SAndreas Gohr}
295a892029SAndreas Gohr
30c4766956SAndreas Gohr/**
31c4766956SAndreas Gohr * Convenience function to access template dir from local FS
32c4766956SAndreas Gohr *
33c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
34c4766956SAndreas Gohr *
35c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
36afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
37ac7a515fSAndreas Gohr * @return string
38c4766956SAndreas Gohr */
39afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') {
4075b14482SAndreas Gohr    global $conf;
41afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
42afb2c082SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$tpl.'/';
43c4766956SAndreas Gohr}
44c4766956SAndreas Gohr
45c4766956SAndreas Gohr/**
46c4766956SAndreas Gohr * Convenience function to access template dir from web
47c4766956SAndreas Gohr *
48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
49c4766956SAndreas Gohr *
50c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
51afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
52ac7a515fSAndreas Gohr * @return string
53c4766956SAndreas Gohr */
5499dca513SAndreas Gohrfunction tpl_basedir($tpl='') {
5575b14482SAndreas Gohr    global $conf;
56afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
57dcd4911eSMichael Hamann    return DOKU_BASE.'lib/tpl/'.$tpl.'/';
58c4766956SAndreas Gohr}
59c4766956SAndreas Gohr
605a892029SAndreas Gohr/**
616b13307fSandi * Print the content
626b13307fSandi *
636b13307fSandi * This function is used for printing all the usual content
646b13307fSandi * (defined by the global $ACT var) by calling the appropriate
656b13307fSandi * outputfunction(s) from html.php
666b13307fSandi *
67ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
68ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
696b13307fSandi *
706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7142ea7f44SGerrit Uitslag *
72ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
73ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
74ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
75ac7a515fSAndreas Gohr * @return bool true if any output
766b13307fSandi */
77b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) {
787ea0913cSchris    global $ACT;
79b8595a66SAndreas Gohr    global $INFO;
80b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
817ea0913cSchris
827ea0913cSchris    ob_start();
83746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
847ea0913cSchris    $html_output = ob_get_clean();
85746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
8654e95700STom N Harris
8754e95700STom N Harris    return !empty($html_output);
887ea0913cSchris}
897ea0913cSchris
90ac7a515fSAndreas Gohr/**
91ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
92ac7a515fSAndreas Gohr *
93ac7a515fSAndreas Gohr * @return bool
94ac7a515fSAndreas Gohr */
957ea0913cSchrisfunction tpl_content_core() {
96952acff9SAndreas Gohr    $router = \dokuwiki\ActionRouter::getInstance();
97952acff9SAndreas Gohr    try {
98952acff9SAndreas Gohr        $router->getAction()->tplContent();
99952acff9SAndreas Gohr    } catch(\dokuwiki\Action\Exception\FatalException $e) {
100952acff9SAndreas Gohr        // there was no content for the action
101952acff9SAndreas Gohr        msg(hsc($e->getMessage()), -1);
10254e95700STom N Harris        return false;
1036b13307fSandi    }
10454e95700STom N Harris    return true;
1056b13307fSandi}
1066b13307fSandi
107c19fe9c0Sandi/**
108b8595a66SAndreas Gohr * Places the TOC where the function is called
109b8595a66SAndreas Gohr *
110b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
111b8595a66SAndreas Gohr * a false argument
112b8595a66SAndreas Gohr *
113b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11442ea7f44SGerrit Uitslag *
115ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
116ac7a515fSAndreas Gohr * @return string
117b8595a66SAndreas Gohr */
118b8595a66SAndreas Gohrfunction tpl_toc($return = false) {
119b8595a66SAndreas Gohr    global $TOC;
120b8595a66SAndreas Gohr    global $ACT;
121b8595a66SAndreas Gohr    global $ID;
122b8595a66SAndreas Gohr    global $REV;
123b8595a66SAndreas Gohr    global $INFO;
124851f2e89SAnika Henke    global $conf;
125ac7a515fSAndreas Gohr    global $INPUT;
126b8595a66SAndreas Gohr    $toc = array();
127b8595a66SAndreas Gohr
128b8595a66SAndreas Gohr    if(is_array($TOC)) {
129b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
130b8595a66SAndreas Gohr        $toc = $TOC;
1313c86d7c9SAndreas Gohr    } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
132b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
133e0c26282SGerrit Uitslag        $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
134b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])) {
135b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
136b8595a66SAndreas Gohr        } else {
1372bb0d541Schris            $tocok = true;
138b8595a66SAndreas Gohr        }
139f87b5dbbSChristopher Smith        $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
140851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
141b8595a66SAndreas Gohr            $toc = array();
142b8595a66SAndreas Gohr        }
143b8595a66SAndreas Gohr    } elseif($ACT == 'admin') {
144a61966c5SChristopher Smith        // try to load admin plugin TOC
145ac7a515fSAndreas Gohr        /** @var $plugin DokuWiki_Admin_Plugin */
146a61966c5SChristopher Smith        if ($plugin = plugin_getRequestAdminPlugin()) {
147b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
148b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
149b8595a66SAndreas Gohr        }
150b8595a66SAndreas Gohr    }
151b8595a66SAndreas Gohr
1520b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
153b8595a66SAndreas Gohr    $html = html_TOC($toc);
154b8595a66SAndreas Gohr    if($return) return $html;
155b8595a66SAndreas Gohr    echo $html;
156ac7a515fSAndreas Gohr    return '';
157b8595a66SAndreas Gohr}
158b8595a66SAndreas Gohr
159b8595a66SAndreas Gohr/**
160c19fe9c0Sandi * Handle the admin page contents
161c19fe9c0Sandi *
162c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
16342ea7f44SGerrit Uitslag *
16442ea7f44SGerrit Uitslag * @return bool
165c19fe9c0Sandi */
166c19fe9c0Sandifunction tpl_admin() {
167f8cc712eSAndreas Gohr    global $INFO;
168b8595a66SAndreas Gohr    global $TOC;
169ac7a515fSAndreas Gohr    global $INPUT;
17011e2ce22Schris
171b8595a66SAndreas Gohr    $plugin = null;
172ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
173ac7a515fSAndreas Gohr    if(!empty($class)) {
17411e2ce22Schris        $pluginlist = plugin_list('admin');
17511e2ce22Schris
176ac7a515fSAndreas Gohr        if(in_array($class, $pluginlist)) {
17711e2ce22Schris            // attempt to load the plugin
178ac7a515fSAndreas Gohr            /** @var $plugin DokuWiki_Admin_Plugin */
179a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
18011e2ce22Schris        }
18111e2ce22Schris    }
18211e2ce22Schris
183b8595a66SAndreas Gohr    if($plugin !== null) {
184b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
185b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
186f8cc712eSAndreas Gohr        $plugin->html();
187f8cc712eSAndreas Gohr    } else {
1880470c28fSAndreas Gohr        $admin = new dokuwiki\Ui\Admin();
1890470c28fSAndreas Gohr        $admin->show();
190f8cc712eSAndreas Gohr    }
19154e95700STom N Harris    return true;
192c19fe9c0Sandi}
1936b13307fSandi
1946b13307fSandi/**
1956b13307fSandi * Print the correct HTML meta headers
1966b13307fSandi *
1976b13307fSandi * This has to go into the head section of your template.
1986b13307fSandi *
1996b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
20042ea7f44SGerrit Uitslag *
201ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
202ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
203ac7a515fSAndreas Gohr * @return bool
2046b13307fSandi */
205f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) {
2066b13307fSandi    global $ID;
207d98d4540SBen Coburn    global $REV;
2086b13307fSandi    global $INFO;
20972e0dc37SAndreas Gohr    global $JSINFO;
2106b13307fSandi    global $ACT;
2114bb1b5aeSAndreas Gohr    global $QUERY;
2126b13307fSandi    global $lang;
213dc57ef04Sandi    global $conf;
2149c438d6cSMichael Hamann    global $updateVersion;
215585bf44eSChristopher Smith    /** @var Input $INPUT */
216585bf44eSChristopher Smith    global $INPUT;
2176b13307fSandi
2187bff22c0SAndreas Gohr    // prepare the head array
2197bff22c0SAndreas Gohr    $head = array();
2207bff22c0SAndreas Gohr
221202ac28bSMichael Klier    // prepare seed for js and css
222cd997f93SAndreas Gohr    $tseed   = $updateVersion;
223202ac28bSMichael Klier    $depends = getConfigFiles('main');
22484e76a7eSAndreas Gohr    $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
225cd997f93SAndreas Gohr    foreach($depends as $f) $tseed .= @filemtime($f);
226cd997f93SAndreas Gohr    $tseed   = md5($tseed);
2277bff22c0SAndreas Gohr
2286b13307fSandi    // the usual stuff
2293f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
23063cf4192Ssarehag    if(actionOK('search')) {
231ac7a515fSAndreas Gohr        $head['link'][] = array(
232ac7a515fSAndreas Gohr            'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
233ac7a515fSAndreas Gohr            'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
234ac7a515fSAndreas Gohr        );
23563cf4192Ssarehag    }
23663cf4192Ssarehag
237f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
2387aedde2eSGina Haeussge    if(actionOK('index')) {
239ac7a515fSAndreas Gohr        $head['link'][] = array(
240ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
241ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
242ac7a515fSAndreas Gohr        );
2437aedde2eSGina Haeussge    }
244f96fa415SAndreas Gohr
2455e0255e3SMichael Große    if (actionOK('manifest')) {
2465e0255e3SMichael Große        $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
2475e0255e3SMichael Große    }
2485e0255e3SMichael Große
24940ca8540SMichael Große    $styleUtil = new \dokuwiki\StyleUtils();
25040ca8540SMichael Große    $styleIni = $styleUtil->cssStyleini($conf['template']);
25140ca8540SMichael Große    $replacements = $styleIni['replacements'];
25240ca8540SMichael Große    if (!empty($replacements['__theme_color__'])) {
25340ca8540SMichael Große        $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']);
25440ca8540SMichael Große    }
25540ca8540SMichael Große
256f96fa415SAndreas Gohr    if($alt) {
25754be1338SGerrit Uitslag        if(actionOK('rss')) {
258ac7a515fSAndreas Gohr            $head['link'][] = array(
259ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
260a1288caeSGerrit Uitslag                'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
261ac7a515fSAndreas Gohr            );
262ac7a515fSAndreas Gohr            $head['link'][] = array(
263ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
264a1288caeSGerrit Uitslag                'title'=> $lang['currentns'],
265ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
266ac7a515fSAndreas Gohr            );
26754be1338SGerrit Uitslag        }
268c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
269ac7a515fSAndreas Gohr            $head['link'][] = array(
270ac7a515fSAndreas Gohr                'rel'  => 'edit',
271715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
272ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
273ac7a515fSAndreas Gohr            );
274c35f3875SAndreas Gohr        }
275c35f3875SAndreas Gohr
27654be1338SGerrit Uitslag        if(actionOK('rss') && $ACT == 'search') {
277ac7a515fSAndreas Gohr            $head['link'][] = array(
278ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
279a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
280ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
281ac7a515fSAndreas Gohr            );
2824bb1b5aeSAndreas Gohr        }
283bae36d94SAndreas Gohr
284bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
285ac7a515fSAndreas Gohr            $head['link'][] = array(
286a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
287ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
288ac7a515fSAndreas Gohr            );
289bae36d94SAndreas Gohr        }
290bae36d94SAndreas Gohr
291bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
292ac7a515fSAndreas Gohr            $head['link'][] = array(
293a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
294ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
295ac7a515fSAndreas Gohr            );
296f96fa415SAndreas Gohr        }
297bae36d94SAndreas Gohr    }
2986b13307fSandi
2996b13307fSandi    // setup robot tags apropriate for different modes
3004f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3016b13307fSandi        if($INFO['exists']) {
3026b13307fSandi            //delay indexing:
303fb9fa88bSAndreas Gohr            if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
3047bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3056b13307fSandi            } else {
3067bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3076b13307fSandi            }
30801f9be51SAnika Henke            $canonicalUrl = wl($ID, '', true, '&');
30901f9be51SAnika Henke            if ($ID == $conf['start']) {
31001f9be51SAnika Henke                $canonicalUrl = DOKU_URL;
31101f9be51SAnika Henke            }
31201f9be51SAnika Henke            $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
3136b13307fSandi        } else {
3147bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3156b13307fSandi        }
3167a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3177bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3186b13307fSandi    } else {
3197bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3206b13307fSandi    }
3216b13307fSandi
322831800b8SAndreas Gohr    // set metadata
323831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
324831800b8SAndreas Gohr        // keywords (explicit or implicit)
325bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3267bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
327831800b8SAndreas Gohr        } else {
3287bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
329831800b8SAndreas Gohr        }
330831800b8SAndreas Gohr    }
331831800b8SAndreas Gohr
33278a6aeb1SAndreas Gohr    // load stylesheets
333ac7a515fSAndreas Gohr    $head['link'][] = array(
334ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
335e283bd6cSAnika Henke        'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
336ac7a515fSAndreas Gohr    );
337bad31ae9SAndreas Gohr
33872e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
339585bf44eSChristopher Smith    if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
34072e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
341c591aabeSAndreas Gohr    }
3420c39d46cSMichael Große    jsinfo();
3431d739e3dSMichael Große    $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
34485f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
3458bbcb611SAndreas Gohr
34661537d47SAndreas Gohr    // load jquery
347fa078663SAndreas Gohr    $jquery = getCdnUrls();
348fa078663SAndreas Gohr    foreach($jquery as $src) {
34961537d47SAndreas Gohr        $head['script'][] = array(
350fa078663SAndreas Gohr            'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => $src
35161537d47SAndreas Gohr        );
35261537d47SAndreas Gohr    }
35361537d47SAndreas Gohr
35461537d47SAndreas Gohr    // load our javascript dispatcher
355ac7a515fSAndreas Gohr    $head['script'][] = array(
356ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
357e283bd6cSAnika Henke        'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
358ac7a515fSAndreas Gohr    );
3597bff22c0SAndreas Gohr
3607bff22c0SAndreas Gohr    // trigger event here
361016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
36254e95700STom N Harris    return true;
3637bff22c0SAndreas Gohr}
3647bff22c0SAndreas Gohr
3657bff22c0SAndreas Gohr/**
3667bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3677bff22c0SAndreas Gohr *
3687bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3697bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3707bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3717bff22c0SAndreas Gohr *
37242ea7f44SGerrit Uitslag * For tags having a body attribute specify the body data in the special
3731304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3747bff22c0SAndreas Gohr *
3757bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
37642ea7f44SGerrit Uitslag *
37742ea7f44SGerrit Uitslag * @param array $data
3787bff22c0SAndreas Gohr */
3797bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
3807bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
381427bf9a2SAndreas Gohr        if($tag == 'script') {
382427bf9a2SAndreas Gohr            echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
383427bf9a2SAndreas Gohr        }
3847bff22c0SAndreas Gohr        foreach($inst as $attr) {
3859b48e6a1SGerry Weißbach            if ( empty($attr) ) { continue; }
3867bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
38726afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
388e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
38909f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
390e226efe1SAndreas Gohr                        $attr['_data'].
39109f791c4SDominik Eckelmann                        "\n/*!]]>*/";
392e226efe1SAndreas Gohr
3931304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
3947bff22c0SAndreas Gohr            } else {
3957bff22c0SAndreas Gohr                echo '/>';
3967bff22c0SAndreas Gohr            }
3977bff22c0SAndreas Gohr            echo "\n";
3987bff22c0SAndreas Gohr        }
399427bf9a2SAndreas Gohr        if($tag == 'script') {
400427bf9a2SAndreas Gohr            echo "<!--<![endif]-->\n";
401427bf9a2SAndreas Gohr        }
4027bff22c0SAndreas Gohr    }
4036b13307fSandi}
4046b13307fSandi
4056b13307fSandi/**
4066b13307fSandi * Print a link
4076b13307fSandi *
4085e163278SAndreas Gohr * Just builds a link.
4096b13307fSandi *
4106b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
41142ea7f44SGerrit Uitslag *
41242ea7f44SGerrit Uitslag * @param string $url
41342ea7f44SGerrit Uitslag * @param string $name
41442ea7f44SGerrit Uitslag * @param string $more
41521d806cdSGerrit Uitslag * @param bool $return if true return the link html, otherwise print
41621d806cdSGerrit Uitslag * @return bool|string html of the link, or true if printed
4176b13307fSandi */
4181af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
41901f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4201af98a77SAnika Henke    if($more) $out .= ' '.$more;
4211af98a77SAnika Henke    $out .= ">$name</a>";
4221af98a77SAnika Henke    if($return) return $out;
4231af98a77SAnika Henke    print $out;
42454e95700STom N Harris    return true;
4256b13307fSandi}
4266b13307fSandi
4276b13307fSandi/**
42855efc227SAndreas Gohr * Prints a link to a WikiPage
42955efc227SAndreas Gohr *
43055efc227SAndreas Gohr * Wrapper around html_wikilink
43155efc227SAndreas Gohr *
43255efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
43342ea7f44SGerrit Uitslag *
43442ea7f44SGerrit Uitslag * @param string      $id   page id
43542ea7f44SGerrit Uitslag * @param string|null $name the name of the link
436fb008d31SIain Hallam * @param bool        $return
437fb008d31SIain Hallam * @return true|string
43855efc227SAndreas Gohr */
439c4a386f1SIain Hallamfunction tpl_pagelink($id, $name = null, $return = false) {
440c4a386f1SIain Hallam    $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
441c4a386f1SIain Hallam    if($return) return $out;
442c4a386f1SIain Hallam    print $out;
44354e95700STom N Harris    return true;
44455efc227SAndreas Gohr}
44555efc227SAndreas Gohr
44655efc227SAndreas Gohr/**
447a3ec5f4aSmatthiasgrimm * get the parent page
448a3ec5f4aSmatthiasgrimm *
449a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
450a3ec5f4aSmatthiasgrimm * returns false if none is available
451a3ec5f4aSmatthiasgrimm *
452377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
45342ea7f44SGerrit Uitslag *
45442ea7f44SGerrit Uitslag * @param string $id page id
45542ea7f44SGerrit Uitslag * @return false|string
456a3ec5f4aSmatthiasgrimm */
457377f9e97SAndreas Gohrfunction tpl_getparent($id) {
458377f9e97SAndreas Gohr    $parent = getNS($id).':';
459377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
460a197105eSmatthiasgrimm    if($parent == $id) {
461a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
462a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
463a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
464377f9e97SAndreas Gohr        if($parent == $id) return false;
465a197105eSmatthiasgrimm    }
466377f9e97SAndreas Gohr    return $parent;
467a3ec5f4aSmatthiasgrimm}
468a3ec5f4aSmatthiasgrimm
469a3ec5f4aSmatthiasgrimm/**
4706b13307fSandi * Print one of the buttons
4716b13307fSandi *
472a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
473a453d131SAdrian Lang * @see    tpl_get_action
474e0c26282SGerrit Uitslag *
475e0c26282SGerrit Uitslag * @param string $type
476e0c26282SGerrit Uitslag * @param bool $return
477e0c26282SGerrit Uitslag * @return bool|string html, or false if no data, true if printed
478affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
4796b13307fSandi */
4801af98a77SAnika Henkefunction tpl_button($type, $return = false) {
481affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
482a453d131SAdrian Lang    $data = tpl_get_action($type);
483a453d131SAdrian Lang    if($data === false) {
484a453d131SAdrian Lang        return false;
485a453d131SAdrian Lang    } elseif(!is_array($data)) {
486a453d131SAdrian Lang        $out = sprintf($data, 'button');
487409d7af7SAndreas Gohr    } else {
488ac7a515fSAndreas Gohr        /**
489ac7a515fSAndreas Gohr         * @var string $accesskey
490ac7a515fSAndreas Gohr         * @var string $id
491ac7a515fSAndreas Gohr         * @var string $method
492ac7a515fSAndreas Gohr         * @var array  $params
493ac7a515fSAndreas Gohr         */
494a453d131SAdrian Lang        extract($data);
495a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
496a453d131SAdrian Lang            $out = html_topbtn();
497409d7af7SAndreas Gohr        } else {
498a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
499409d7af7SAndreas Gohr        }
500409d7af7SAndreas Gohr    }
5011af98a77SAnika Henke    if($return) return $out;
502a453d131SAdrian Lang    echo $out;
503a453d131SAdrian Lang    return true;
5046b13307fSandi}
5056b13307fSandi
5066b13307fSandi/**
507ed630903Sandi * Like the action buttons but links
508ed630903Sandi *
509a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
510a453d131SAdrian Lang * @see    tpl_get_action
511e0c26282SGerrit Uitslag *
51242ea7f44SGerrit Uitslag * @param string $type    action command
513e0c26282SGerrit Uitslag * @param string $pre     prefix of link
514e0c26282SGerrit Uitslag * @param string $suf     suffix of link
515e0c26282SGerrit Uitslag * @param string $inner   innerHML of link
51621d806cdSGerrit Uitslag * @param bool   $return  if true it returns html, otherwise prints
517e0c26282SGerrit Uitslag * @return bool|string html or false if no data, true if printed
518affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
519a453d131SAdrian Lang */
520a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
521affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
522a453d131SAdrian Lang    global $lang;
523a453d131SAdrian Lang    $data = tpl_get_action($type);
524a453d131SAdrian Lang    if($data === false) {
525a453d131SAdrian Lang        return false;
526a453d131SAdrian Lang    } elseif(!is_array($data)) {
527a453d131SAdrian Lang        $out = sprintf($data, 'link');
528a453d131SAdrian Lang    } else {
529ac7a515fSAndreas Gohr        /**
530ac7a515fSAndreas Gohr         * @var string $accesskey
531ac7a515fSAndreas Gohr         * @var string $id
532ac7a515fSAndreas Gohr         * @var string $method
533b1af9014SChristopher Smith         * @var bool   $nofollow
534ac7a515fSAndreas Gohr         * @var array  $params
535becfa414SGerrit Uitslag         * @var string $replacement
536ac7a515fSAndreas Gohr         */
537a453d131SAdrian Lang        extract($data);
538a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
539a453d131SAdrian Lang            $linktarget = $id;
540a453d131SAdrian Lang        } else {
541a453d131SAdrian Lang            $linktarget = wl($id, $params);
542a453d131SAdrian Lang        }
543a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
544becfa414SGerrit Uitslag        if(strpos($caption, '%s')){
545becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
546becfa414SGerrit Uitslag        }
547c7e90e3fSAnika Henke        $akey    = $addTitle = '';
548c7e90e3fSAnika Henke        if($accesskey) {
549c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
550c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
551c7e90e3fSAnika Henke        }
552b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
553ac7a515fSAndreas Gohr        $out = tpl_link(
554ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
555a453d131SAdrian Lang            'class="action '.$type.'" '.
556b1af9014SChristopher Smith                $akey.$rel.
557e0c26282SGerrit Uitslag                'title="'.hsc($caption).$addTitle.'"', true
558ac7a515fSAndreas Gohr        );
559a453d131SAdrian Lang    }
560a453d131SAdrian Lang    if($return) return $out;
561a453d131SAdrian Lang    echo $out;
562a453d131SAdrian Lang    return true;
563a453d131SAdrian Lang}
564a453d131SAdrian Lang
565a453d131SAdrian Lang/**
566a453d131SAdrian Lang * Check the actions and get data for buttons and links
567ed630903Sandi *
568ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
569a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
570a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
571e0c26282SGerrit Uitslag *
572ac7a515fSAndreas Gohr * @param string $type
573ac7a515fSAndreas Gohr * @return array|bool|string
574affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
575ed630903Sandi */
576a453d131SAdrian Langfunction tpl_get_action($type) {
577affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
578a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
5794c4b65c8SMichael Hamann    if($type == 'subscription') $type = 'subscribe';
5804887c154SAndreas Gohr    if($type == 'img_backto') $type = 'imgBackto';
581409d7af7SAndreas Gohr
5824887c154SAndreas Gohr    $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
5834887c154SAndreas Gohr    if(class_exists($class)) {
5844887c154SAndreas Gohr        try {
5854887c154SAndreas Gohr            /** @var \dokuwiki\Menu\Item\AbstractItem $item */
5864887c154SAndreas Gohr            $item = new $class;
5874887c154SAndreas Gohr            $data = $item->getLegacyData();
5887b4365a7SGerrit Uitslag            $unknown = false;
5894887c154SAndreas Gohr        } catch(\RuntimeException $ignored) {
5904887c154SAndreas Gohr            return false;
591b8a111f5SMichael Klier        }
592ed630903Sandi    } else {
5934887c154SAndreas Gohr        global $ID;
5944887c154SAndreas Gohr        $data = array(
5954887c154SAndreas Gohr            'accesskey' => null,
5964887c154SAndreas Gohr            'type' => $type,
5974887c154SAndreas Gohr            'id' => $ID,
5984887c154SAndreas Gohr            'method' => 'get',
5994887c154SAndreas Gohr            'params' => array('do' => $type),
6004887c154SAndreas Gohr            'nofollow' => true,
6014887c154SAndreas Gohr            'replacement' => '',
602becfa414SGerrit Uitslag        );
6037b4365a7SGerrit Uitslag        $unknown = true;
604ed630903Sandi    }
6057b4365a7SGerrit Uitslag
6063131073dSGerrit Uitslag    $evt = new Doku_Event('TPL_ACTION_GET', $data);
6077b4365a7SGerrit Uitslag    if($evt->advise_before()) {
6087b4365a7SGerrit Uitslag        //handle unknown types
6097b4365a7SGerrit Uitslag        if($unknown) {
61038d2ca46SGerrit Uitslag            $data = '[unknown %s type]';
6117b4365a7SGerrit Uitslag        }
6127b4365a7SGerrit Uitslag    }
6137b4365a7SGerrit Uitslag    $evt->advise_after();
6147b4365a7SGerrit Uitslag    unset($evt);
6157b4365a7SGerrit Uitslag
6167b4365a7SGerrit Uitslag    return $data;
617ed630903Sandi}
618ed630903Sandi
619ed630903Sandi/**
62001f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
62101f17825SAnika Henke *
62201f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
62342ea7f44SGerrit Uitslag *
62442ea7f44SGerrit Uitslag * @param string        $type action command
625ac7a515fSAndreas Gohr * @param bool          $link link or form button?
626e0c26282SGerrit Uitslag * @param string|bool   $wrapper HTML element wrapper
627ac7a515fSAndreas Gohr * @param bool          $return return or print
628ac7a515fSAndreas Gohr * @param string        $pre prefix for links
629ac7a515fSAndreas Gohr * @param string        $suf suffix for links
630ac7a515fSAndreas Gohr * @param string        $inner inner HTML for links
631ac7a515fSAndreas Gohr * @return bool|string
632affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
63301f17825SAnika Henke */
634ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
635affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
63601f17825SAnika Henke    $out = '';
637ac7a515fSAndreas Gohr    if($link) {
638e0c26282SGerrit Uitslag        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
639ac7a515fSAndreas Gohr    } else {
640e0c26282SGerrit Uitslag        $out .= tpl_button($type, true);
641ac7a515fSAndreas Gohr    }
64201f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
64301f17825SAnika Henke
64401f17825SAnika Henke    if($return) return $out;
64501f17825SAnika Henke    print $out;
64601f17825SAnika Henke    return $out ? true : false;
64701f17825SAnika Henke}
64801f17825SAnika Henke
64901f17825SAnika Henke/**
6506b13307fSandi * Print the search form
6516b13307fSandi *
65272645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
65372645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
65472645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
65572645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
65672645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
65772645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
65872645b75SAndreas Gohr *
6596b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
66042ea7f44SGerrit Uitslag *
661ac7a515fSAndreas Gohr * @param bool $ajax
662ac7a515fSAndreas Gohr * @param bool $autocomplete
663ac7a515fSAndreas Gohr * @return bool
6646b13307fSandi */
66572645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
6666b13307fSandi    global $lang;
667c1e3b7d9Smatthiasgrimm    global $ACT;
668ad4aaef7SAndreas Gohr    global $QUERY;
669cbcc2fa5SMichael Große    global $ID;
670c1e3b7d9Smatthiasgrimm
671670ff54eSchris    // don't print the search form if search action has been disabled
67264276bbcSarbrk1    if(!actionOK('search')) return false;
673670ff54eSchris
6743c7a3327SMichael Große    $searchForm = new dokuwiki\Form\Form([
6753c7a3327SMichael Große        'action' => wl(),
6763c7a3327SMichael Große        'method' => 'get',
6773c7a3327SMichael Große        'role' => 'search',
6783c7a3327SMichael Große        'class' => 'search',
6793c7a3327SMichael Große        'id' => 'dw__search',
6807fa270bcSMichael Große    ], true);
6813eb2b869SMichael Große    $searchForm->addTagOpen('div')->addClass('no');
6823c7a3327SMichael Große    $searchForm->setHiddenField('do', 'search');
683d22b78c8SMichael Große    $searchForm->setHiddenField('id', $ID);
684d22b78c8SMichael Große    $searchForm->addTextInput('q')
6853c7a3327SMichael Große        ->addClass('edit')
6863c7a3327SMichael Große        ->attrs([
6873c7a3327SMichael Große            'title' => '[F]',
6883c7a3327SMichael Große            'accesskey' => 'f',
6893c7a3327SMichael Große            'placeholder' => $lang['btn_search'],
6903c7a3327SMichael Große            'autocomplete' => $autocomplete ? 'on' : 'off',
6913c7a3327SMichael Große        ])
6923c7a3327SMichael Große        ->id('qsearch__in')
6933c7a3327SMichael Große        ->val($ACT === 'search' ? $QUERY : '')
6943c7a3327SMichael Große        ->useInput(false)
6953c7a3327SMichael Große    ;
6963c7a3327SMichael Große    $searchForm->addButton('', $lang['btn_search'])->attrs([
6973c7a3327SMichael Große        'type' => 'submit',
6983c7a3327SMichael Große        'title' => $lang['btn_search'],
6993c7a3327SMichael Große    ]);
7003c7a3327SMichael Große    if ($ajax) {
7013c7a3327SMichael Große        $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
7023c7a3327SMichael Große        $searchForm->addTagClose('div');
7033c7a3327SMichael Große    }
7043eb2b869SMichael Große    $searchForm->addTagClose('div');
70516ece95cSMichael Große    trigger_event('FORM_QUICKSEARCH_OUTPUT', $searchForm);
7063c7a3327SMichael Große
7073c7a3327SMichael Große    echo $searchForm->toHTML();
7083c7a3327SMichael Große
70954e95700STom N Harris    return true;
7106b13307fSandi}
7116b13307fSandi
7126b13307fSandi/**
7136b13307fSandi * Print the breadcrumbs trace
7146b13307fSandi *
7156b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
71642ea7f44SGerrit Uitslag *
717ac7a515fSAndreas Gohr * @param string $sep Separator between entries
718c4a386f1SIain Hallam * @param bool   $return return or print
719c4a386f1SIain Hallam * @return bool|string
7206b13307fSandi */
721c4a386f1SIain Hallamfunction tpl_breadcrumbs($sep = null, $return = false) {
7226b13307fSandi    global $lang;
7236b13307fSandi    global $conf;
7246b13307fSandi
7256b13307fSandi    //check if enabled
726359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
7276b13307fSandi
728c4a386f1SIain Hallam    //set default
729c4a386f1SIain Hallam    if(is_null($sep)) $sep = '•';
730c4a386f1SIain Hallam
731c4a386f1SIain Hallam    $out='';
732c4a386f1SIain Hallam
7336b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
734265e3787Sandi
7352979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
736265e3787Sandi
73740eb54bbSjan    //render crumbs, highlight the last one
738c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
73940eb54bbSjan    $last = count($crumbs);
74040eb54bbSjan    $i    = 0;
741a77f5846Sjan    foreach($crumbs as $id => $name) {
74240eb54bbSjan        $i++;
743c4a386f1SIain Hallam        $out .= $crumbs_sep;
744c4a386f1SIain Hallam        if($i == $last) $out .= '<span class="curid">';
745c4a386f1SIain Hallam        $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) .  '</bdi>';
746c4a386f1SIain Hallam        if($i == $last) $out .= '</span>';
7476b13307fSandi    }
748c4a386f1SIain Hallam    if($return) return $out;
749c4a386f1SIain Hallam    print $out;
750c4a386f1SIain Hallam    return $out ? true : false;
7516b13307fSandi}
7526b13307fSandi
7536b13307fSandi/**
7541734437eSandi * Hierarchical breadcrumbs
7551734437eSandi *
75631e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7571734437eSandi * It only makes sense with a deep site structure.
7581734437eSandi *
7591734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7606bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
76131e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
762f46c9e83SAnika Henke * @author <fredrik@averpil.com>
76308d7a575SAndreas Gohr * @todo   May behave strangely in RTL languages
76442ea7f44SGerrit Uitslag *
765ac7a515fSAndreas Gohr * @param string $sep Separator between entries
766c4a386f1SIain Hallam * @param bool   $return return or print
767c4a386f1SIain Hallam * @return bool|string
7681734437eSandi */
769c4a386f1SIain Hallamfunction tpl_youarehere($sep = null, $return = false) {
7701734437eSandi    global $conf;
7711734437eSandi    global $ID;
7721734437eSandi    global $lang;
7731734437eSandi
77431e187f8SSean Coates    // check if enabled
77554e95700STom N Harris    if(!$conf['youarehere']) return false;
7761734437eSandi
777c4a386f1SIain Hallam    //set default
778c4a386f1SIain Hallam    if(is_null($sep)) $sep = ' » ';
779c4a386f1SIain Hallam
780c4a386f1SIain Hallam    $out = '';
781c4a386f1SIain Hallam
7821734437eSandi    $parts = explode(':', $ID);
783796bafb3SAndreas Gohr    $count = count($parts);
7841734437eSandi
785c4a386f1SIain Hallam    $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
7863940c519SMark
78708d7a575SAndreas Gohr    // always print the startpage
788c4a386f1SIain Hallam    $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
789796bafb3SAndreas Gohr
790796bafb3SAndreas Gohr    // print intermediate namespace links
791796bafb3SAndreas Gohr    $part = '';
792796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
793796bafb3SAndreas Gohr        $part .= $parts[$i].':';
794796bafb3SAndreas Gohr        $page = $part;
795796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
796796bafb3SAndreas Gohr
79708d7a575SAndreas Gohr        // output
798c4a386f1SIain Hallam        $out .= $sep . tpl_pagelink($page, null, true);
79931e187f8SSean Coates    }
8001734437eSandi
801796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
802e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
803*a8c33dedSMichael Große    if (isset($page) && $page == $part.$parts[$i]) {
804*a8c33dedSMichael Große        if($return) return $out;
805*a8c33dedSMichael Große        print $out;
806*a8c33dedSMichael Große        return true;
807*a8c33dedSMichael Große    }
808796bafb3SAndreas Gohr    $page = $part.$parts[$i];
809*a8c33dedSMichael Große    if($page == $conf['start']) {
810*a8c33dedSMichael Große        if($return) return $out;
811*a8c33dedSMichael Große        print $out;
812*a8c33dedSMichael Große        return true;
813*a8c33dedSMichael Große    }
814c4a386f1SIain Hallam    $out .= $sep;
815c4a386f1SIain Hallam    $out .= tpl_pagelink($page, null, true);
816c4a386f1SIain Hallam    if($return) return $out;
817c4a386f1SIain Hallam    print $out;
818c4a386f1SIain Hallam    return $out ? true : false;
8191734437eSandi}
8201734437eSandi
8211734437eSandi/**
8226b13307fSandi * Print info if the user is logged in
823a2488c3cSMatthias Grimm * and show full name in that case
8246b13307fSandi *
8256b13307fSandi * Could be enhanced with a profile link in future?
8266b13307fSandi *
8276b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
82842ea7f44SGerrit Uitslag *
829ac7a515fSAndreas Gohr * @return bool
8306b13307fSandi */
8316b13307fSandifunction tpl_userinfo() {
8326b13307fSandi    global $lang;
833585bf44eSChristopher Smith    /** @var Input $INPUT */
834585bf44eSChristopher Smith    global $INPUT;
835585bf44eSChristopher Smith
836585bf44eSChristopher Smith    if($INPUT->server->str('REMOTE_USER')) {
837fde860beSGerrit Uitslag        print $lang['loggedinas'].' '.userlink();
83854e95700STom N Harris        return true;
83954e95700STom N Harris    }
84054e95700STom N Harris    return false;
8416b13307fSandi}
8426b13307fSandi
8436b13307fSandi/**
8446b13307fSandi * Print some info about the current page
8456b13307fSandi *
8466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
84742ea7f44SGerrit Uitslag *
848ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
849ac7a515fSAndreas Gohr * @return bool|string
8506b13307fSandi */
8514b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
8526b13307fSandi    global $conf;
8536b13307fSandi    global $lang;
8546b13307fSandi    global $INFO;
855c6e92a3cSDavid Lorentsen    global $ID;
856c6e92a3cSDavid Lorentsen
857c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
858ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
859ac7a515fSAndreas Gohr        return false;
860ac7a515fSAndreas Gohr    }
8616b13307fSandi
8626b13307fSandi    // prepare date and path
8636b13307fSandi    $fn = $INFO['filepath'];
8646b13307fSandi    if(!$conf['fullpath']) {
865613bca54SAndreas Gohr        if($INFO['rev']) {
866c83f69baSSatoshi Sahara            $fn = str_replace($conf['olddir'].'/', '', $fn);
8676b13307fSandi        } else {
868c83f69baSSatoshi Sahara            $fn = str_replace($conf['datadir'].'/', '', $fn);
8696b13307fSandi        }
8706b13307fSandi    }
871bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
872f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
8736b13307fSandi
874faecdfdfSAndreas Gohr    // print it
875faecdfdfSAndreas Gohr    if($INFO['exists']) {
8764b0d3916SAndreas Gohr        $out = '';
877d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
878e260f93bSAnika Henke        $out .= ' · ';
8794b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
880fde860beSGerrit Uitslag        $out .= ' ';
8814b0d3916SAndreas Gohr        $out .= $date;
8826b13307fSandi        if($INFO['editor']) {
8834b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
884d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
8855aa52fafSBen Coburn        } else {
8864b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
8876b13307fSandi        }
8886b13307fSandi        if($INFO['locked']) {
889e260f93bSAnika Henke            $out .= ' · ';
8904b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
891fde860beSGerrit Uitslag            $out .= ' ';
892d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
8936b13307fSandi        }
8944b0d3916SAndreas Gohr        if($ret) {
8954b0d3916SAndreas Gohr            return $out;
8964b0d3916SAndreas Gohr        } else {
8974b0d3916SAndreas Gohr            echo $out;
89854e95700STom N Harris            return true;
8996b13307fSandi        }
9004b0d3916SAndreas Gohr    }
90154e95700STom N Harris    return false;
9026b13307fSandi}
9036b13307fSandi
904820fa24bSandi/**
905a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
90687c434ceSAndreas Gohr *
90787c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
908a6598f23SBen Coburn * the given ID is used.
90987c434ceSAndreas Gohr *
91087c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
91142ea7f44SGerrit Uitslag *
912ac7a515fSAndreas Gohr * @param string $id page id
913ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
914ac7a515fSAndreas Gohr * @return bool|string
91587c434ceSAndreas Gohr */
916a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
917c248bda1SChristopher Smith    global $ACT, $INPUT, $conf, $lang;
918fffeeafeSChristopher Smith
91987c434ceSAndreas Gohr    if(is_null($id)) {
92087c434ceSAndreas Gohr        global $ID;
92187c434ceSAndreas Gohr        $id = $ID;
92287c434ceSAndreas Gohr    }
92387c434ceSAndreas Gohr
92487c434ceSAndreas Gohr    $name = $id;
925fe9ec250SChris Smith    if(useHeading('navigation')) {
926fffeeafeSChristopher Smith        $first_heading = p_get_first_heading($id);
927fffeeafeSChristopher Smith        if($first_heading) $name = $first_heading;
928fffeeafeSChristopher Smith    }
929fffeeafeSChristopher Smith
930fffeeafeSChristopher Smith    // default page title is the page name, modify with the current action
931fffeeafeSChristopher Smith    switch ($ACT) {
932fffeeafeSChristopher Smith        // admin functions
933fffeeafeSChristopher Smith        case 'admin' :
934fffeeafeSChristopher Smith            $page_title = $lang['btn_admin'];
935fffeeafeSChristopher Smith            // try to get the plugin name
936a61966c5SChristopher Smith            /** @var $plugin DokuWiki_Admin_Plugin */
937a61966c5SChristopher Smith            if ($plugin = plugin_getRequestAdminPlugin()){
938c248bda1SChristopher Smith                $plugin_title = $plugin->getMenuText($conf['lang']);
939a61966c5SChristopher Smith                $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
940fffeeafeSChristopher Smith            }
941fffeeafeSChristopher Smith            break;
942fffeeafeSChristopher Smith
943fffeeafeSChristopher Smith        // user functions
944fffeeafeSChristopher Smith        case 'login' :
945fffeeafeSChristopher Smith        case 'profile' :
946fffeeafeSChristopher Smith        case 'register' :
947fffeeafeSChristopher Smith        case 'resendpwd' :
948fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
949fffeeafeSChristopher Smith            break;
950fffeeafeSChristopher Smith
951fffeeafeSChristopher Smith         // wiki functions
952fffeeafeSChristopher Smith        case 'search' :
953fffeeafeSChristopher Smith        case 'index' :
954fffeeafeSChristopher Smith            $page_title = $lang['btn_'.$ACT];
955fffeeafeSChristopher Smith            break;
956fffeeafeSChristopher Smith
957fffeeafeSChristopher Smith        // page functions
958fffeeafeSChristopher Smith        case 'edit' :
959fffeeafeSChristopher Smith            $page_title = "✎ ".$name;
960fffeeafeSChristopher Smith            break;
961fffeeafeSChristopher Smith
962fffeeafeSChristopher Smith        case 'revisions' :
963fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_revs'];
964fffeeafeSChristopher Smith            break;
965fffeeafeSChristopher Smith
966fffeeafeSChristopher Smith        case 'backlink' :
967fffeeafeSChristopher Smith        case 'recent' :
968fffeeafeSChristopher Smith        case 'subscribe' :
969fffeeafeSChristopher Smith            $page_title = $name . ' - ' . $lang['btn_'.$ACT];
970fffeeafeSChristopher Smith            break;
971fffeeafeSChristopher Smith
972fffeeafeSChristopher Smith        default : // SHOW and anything else not included
973fffeeafeSChristopher Smith            $page_title = $name;
97487c434ceSAndreas Gohr    }
975a6598f23SBen Coburn
976a6598f23SBen Coburn    if($ret) {
977fffeeafeSChristopher Smith        return hsc($page_title);
978a6598f23SBen Coburn    } else {
979fffeeafeSChristopher Smith        print hsc($page_title);
98054e95700STom N Harris        return true;
98187c434ceSAndreas Gohr    }
982a6598f23SBen Coburn}
983340756e4Sandi
98455efc227SAndreas Gohr/**
98555efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
98655efc227SAndreas Gohr *
98755efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
98855efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
98955efc227SAndreas Gohr *
99055efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
99155efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
99255efc227SAndreas Gohr * to the names of the latter one)
99355efc227SAndreas Gohr *
9943df72098SAndreas Gohr * Only allowed in: detail.php
99555efc227SAndreas Gohr *
99655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
99742ea7f44SGerrit Uitslag *
99821d806cdSGerrit Uitslag * @param array|string $tags tag or array of tags to try
999ac7a515fSAndreas Gohr * @param string       $alt  alternative output if no data was found
1000e0c26282SGerrit Uitslag * @param null|string  $src  the image src, uses global $SRC if not given
1001ac7a515fSAndreas Gohr * @return string
100255efc227SAndreas Gohr */
10033df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
100455efc227SAndreas Gohr    // Init Exif Reader
100555efc227SAndreas Gohr    global $SRC;
10063df72098SAndreas Gohr
10073df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
10083df72098SAndreas Gohr
100955efc227SAndreas Gohr    static $meta = null;
10103df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
101155efc227SAndreas Gohr    if($meta === false) return $alt;
101288945224SChristopher Smith    $info = cleanText($meta->getField($tags));
101355efc227SAndreas Gohr    if($info == false) return $alt;
101455efc227SAndreas Gohr    return $info;
101555efc227SAndreas Gohr}
101655efc227SAndreas Gohr
101755efc227SAndreas Gohr/**
1018becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
1019becfa414SGerrit Uitslag *
1020becfa414SGerrit Uitslag * @return string html of description list
1021becfa414SGerrit Uitslag */
1022becfa414SGerrit Uitslagfunction tpl_img_meta() {
1023becfa414SGerrit Uitslag    global $lang;
1024becfa414SGerrit Uitslag
1025becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1026becfa414SGerrit Uitslag
1027becfa414SGerrit Uitslag    echo '<dl>';
1028becfa414SGerrit Uitslag    foreach($tags as $tag) {
1029becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1030fde860beSGerrit Uitslag        if(!$label) $label = $tag['langkey'] . ':';
1031becfa414SGerrit Uitslag
1032fde860beSGerrit Uitslag        echo '<dt>'.$label.'</dt><dd>';
1033becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1034becfa414SGerrit Uitslag            echo dformat($tag['value']);
1035becfa414SGerrit Uitslag        } else {
1036becfa414SGerrit Uitslag            echo hsc($tag['value']);
1037becfa414SGerrit Uitslag        }
1038becfa414SGerrit Uitslag        echo '</dd>';
1039becfa414SGerrit Uitslag    }
1040becfa414SGerrit Uitslag    echo '</dl>';
1041becfa414SGerrit Uitslag}
1042becfa414SGerrit Uitslag
1043becfa414SGerrit Uitslag/**
1044becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1045becfa414SGerrit Uitslag *
1046becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1047becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1048becfa414SGerrit Uitslag *   - string type     type of value
1049becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1050becfa414SGerrit Uitslag */
1051becfa414SGerrit Uitslagfunction tpl_get_img_meta() {
1052becfa414SGerrit Uitslag
1053becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1054becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
105579e79377SAndreas Gohr        if(file_exists($config_file)) {
1056becfa414SGerrit Uitslag            include($config_file);
1057becfa414SGerrit Uitslag        }
1058becfa414SGerrit Uitslag    }
1059becfa414SGerrit Uitslag    /** @var array $fields the included array with metadata */
1060becfa414SGerrit Uitslag
1061becfa414SGerrit Uitslag    $tags = array();
1062becfa414SGerrit Uitslag    foreach($fields as $tag){
1063becfa414SGerrit Uitslag        $t = array();
1064becfa414SGerrit Uitslag        if (!empty($tag[0])) {
1065becfa414SGerrit Uitslag            $t = array($tag[0]);
1066becfa414SGerrit Uitslag        }
1067becfa414SGerrit Uitslag        if(is_array($tag[3])) {
1068becfa414SGerrit Uitslag            $t = array_merge($t,$tag[3]);
1069becfa414SGerrit Uitslag        }
1070becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1071becfa414SGerrit Uitslag        if ($value) {
1072becfa414SGerrit Uitslag            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1073becfa414SGerrit Uitslag        }
1074becfa414SGerrit Uitslag    }
1075becfa414SGerrit Uitslag    return $tags;
1076becfa414SGerrit Uitslag}
1077becfa414SGerrit Uitslag
1078becfa414SGerrit Uitslag/**
107955efc227SAndreas Gohr * Prints the image with a link to the full sized version
108055efc227SAndreas Gohr *
108155efc227SAndreas Gohr * Only allowed in: detail.php
1082a02d2933SAndreas Gohr *
1083ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1084a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1085a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1086a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1087a02d2933SAndreas Gohr * @param $params array  - additional image attributes
108842ea7f44SGerrit Uitslag * @return bool Result of TPL_IMG_DISPLAY
108955efc227SAndreas Gohr */
1090a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
109155efc227SAndreas Gohr    global $IMG;
1092585bf44eSChristopher Smith    /** @var Input $INPUT */
1093ac7a515fSAndreas Gohr    global $INPUT;
10945c2eed9aSlisps    global $REV;
109565d3a5dbSAndreas Gohr    $w = (int) tpl_img_getTag('File.Width');
109665d3a5dbSAndreas Gohr    $h = (int) tpl_img_getTag('File.Height');
109755efc227SAndreas Gohr
109855efc227SAndreas Gohr    //resize to given max values
109923a34783SAndreas Gohr    $ratio = 1;
110023a34783SAndreas Gohr    if($w >= $h) {
1101f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
110255efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1103f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
110455efc227SAndreas Gohr            $ratio = $maxheight / $h;
110555efc227SAndreas Gohr        }
110655efc227SAndreas Gohr    } else {
1107f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
110855efc227SAndreas Gohr            $ratio = $maxheight / $h;
1109f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
111055efc227SAndreas Gohr            $ratio = $maxwidth / $w;
111155efc227SAndreas Gohr        }
111255efc227SAndreas Gohr    }
111355efc227SAndreas Gohr    if($ratio) {
111455efc227SAndreas Gohr        $w = floor($ratio * $w);
111555efc227SAndreas Gohr        $h = floor($ratio * $h);
111655efc227SAndreas Gohr    }
111755efc227SAndreas Gohr
11186de3759aSAndreas Gohr    //prepare URLs
11195c2eed9aSlisps    $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
11205c2eed9aSlisps    $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
112155efc227SAndreas Gohr
11222684e50aSAndreas Gohr    //prepare attributes
112355efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1124a02d2933SAndreas Gohr    if(is_null($params)) {
11252684e50aSAndreas Gohr        $p = array();
1126a02d2933SAndreas Gohr    } else {
1127a02d2933SAndreas Gohr        $p = $params;
1128a02d2933SAndreas Gohr    }
11292684e50aSAndreas Gohr    if($w) $p['width'] = $w;
11302684e50aSAndreas Gohr    if($h) $p['height'] = $h;
11312684e50aSAndreas Gohr    $p['class'] = 'img_detail';
11322684e50aSAndreas Gohr    if($alt) {
11332684e50aSAndreas Gohr        $p['alt']   = $alt;
11342684e50aSAndreas Gohr        $p['title'] = $alt;
11352684e50aSAndreas Gohr    } else {
11362684e50aSAndreas Gohr        $p['alt'] = '';
11372684e50aSAndreas Gohr    }
1138a02d2933SAndreas Gohr    $p['src'] = $src;
113955efc227SAndreas Gohr
1140a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1141a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1142a02d2933SAndreas Gohr}
1143a02d2933SAndreas Gohr
1144a02d2933SAndreas Gohr/**
1145a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1146ac7a515fSAndreas Gohr *
1147ac7a515fSAndreas Gohr * @param array $data
1148ac7a515fSAndreas Gohr * @return bool
1149a02d2933SAndreas Gohr */
1150ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
115159f3611bSAnika Henke    global $lang;
1152a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1153a02d2933SAndreas Gohr
115459f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1155a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1156a02d2933SAndreas Gohr    if($data['url']) print '</a>';
115754e95700STom N Harris    return true;
115855efc227SAndreas Gohr}
115955efc227SAndreas Gohr
11607367b368SAndreas Gohr/**
1161881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11627367b368SAndreas Gohr *
11637367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11647367b368SAndreas Gohr * template
1165ac7a515fSAndreas Gohr *
1166ac7a515fSAndreas Gohr * @return bool
11677367b368SAndreas Gohr */
11687367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11697367b368SAndreas Gohr    global $ID;
11701dad36f5SAndreas Gohr
11717367b368SAndreas Gohr    $p           = array();
1172b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1173e68c51baSAndreas Gohr        '&'.time();
1174881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11757367b368SAndreas Gohr    $p['height'] = 1;
11767367b368SAndreas Gohr    $p['alt']    = '';
11777367b368SAndreas Gohr    $att         = buildAttributes($p);
11787367b368SAndreas Gohr    print "<img $att />";
117954e95700STom N Harris    return true;
11807367b368SAndreas Gohr}
11817367b368SAndreas Gohr
118278d4e784SEsther Brunner/**
118378d4e784SEsther Brunner * tpl_getConf($id)
118478d4e784SEsther Brunner *
118578d4e784SEsther Brunner * use this function to access template configuration variables
1186ac7a515fSAndreas Gohr *
118717448fb8SChristopher Smith * @param string $id      name of the value to access
118817448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
118917448fb8SChristopher Smith * @return mixed
119078d4e784SEsther Brunner */
119117448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
119278d4e784SEsther Brunner    global $conf;
119317566ac6SAdrian Lang    static $tpl_configloaded = false;
119478d4e784SEsther Brunner
119578d4e784SEsther Brunner    $tpl = $conf['template'];
119678d4e784SEsther Brunner
119778d4e784SEsther Brunner    if(!$tpl_configloaded) {
119878d4e784SEsther Brunner        $tconf = tpl_loadConfig();
119978d4e784SEsther Brunner        if($tconf !== false) {
120078d4e784SEsther Brunner            foreach($tconf as $key => $value) {
120178d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
120278d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
120378d4e784SEsther Brunner            }
120478d4e784SEsther Brunner            $tpl_configloaded = true;
120578d4e784SEsther Brunner        }
120678d4e784SEsther Brunner    }
120778d4e784SEsther Brunner
120817448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
120978d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
121078d4e784SEsther Brunner    }
121178d4e784SEsther Brunner
121217448fb8SChristopher Smith    return $notset;
121317448fb8SChristopher Smith}
121417448fb8SChristopher Smith
121578d4e784SEsther Brunner/**
121678d4e784SEsther Brunner * tpl_loadConfig()
1217ac7a515fSAndreas Gohr *
121878d4e784SEsther Brunner * reads all template configuration variables
121978d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1220ac7a515fSAndreas Gohr *
1221ac7a515fSAndreas Gohr * @return array
122278d4e784SEsther Brunner */
122378d4e784SEsther Brunnerfunction tpl_loadConfig() {
122478d4e784SEsther Brunner
1225c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
122678d4e784SEsther Brunner    $conf = array();
122778d4e784SEsther Brunner
122879e79377SAndreas Gohr    if(!file_exists($file)) return false;
122978d4e784SEsther Brunner
123078d4e784SEsther Brunner    // load default config file
123178d4e784SEsther Brunner    include($file);
123278d4e784SEsther Brunner
123378d4e784SEsther Brunner    return $conf;
123478d4e784SEsther Brunner}
123578d4e784SEsther Brunner
123617566ac6SAdrian Lang// language methods
123717566ac6SAdrian Lang/**
123817566ac6SAdrian Lang * tpl_getLang($id)
123917566ac6SAdrian Lang *
124017566ac6SAdrian Lang * use this function to access template language variables
124142ea7f44SGerrit Uitslag *
124242ea7f44SGerrit Uitslag * @param string $id key of language string
124342ea7f44SGerrit Uitslag * @return string
124417566ac6SAdrian Lang */
124517566ac6SAdrian Langfunction tpl_getLang($id) {
124617566ac6SAdrian Lang    static $lang = array();
124717566ac6SAdrian Lang
124817566ac6SAdrian Lang    if(count($lang) === 0) {
1249dd7a6159SGerrit Uitslag        global $conf, $config_cascade; // definitely don't invoke "global $lang"
1250dd7a6159SGerrit Uitslag
1251c4766956SAndreas Gohr        $path = tpl_incdir() . 'lang/';
125217566ac6SAdrian Lang
125317566ac6SAdrian Lang        $lang = array();
125417566ac6SAdrian Lang
125517566ac6SAdrian Lang        // don't include once
125617566ac6SAdrian Lang        @include($path . 'en/lang.php');
1257dd7a6159SGerrit Uitslag        foreach($config_cascade['lang']['template'] as $config_file) {
125879e79377SAndreas Gohr            if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1259dd7a6159SGerrit Uitslag                include($config_file . $conf['template'] . '/en/lang.php');
1260dd7a6159SGerrit Uitslag            }
126117566ac6SAdrian Lang        }
126217566ac6SAdrian Lang
1263dd7a6159SGerrit Uitslag        if($conf['lang'] != 'en') {
1264dd7a6159SGerrit Uitslag            @include($path . $conf['lang'] . '/lang.php');
1265dd7a6159SGerrit Uitslag            foreach($config_cascade['lang']['template'] as $config_file) {
126679e79377SAndreas Gohr                if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1267dd7a6159SGerrit Uitslag                    include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1268dd7a6159SGerrit Uitslag                }
1269dd7a6159SGerrit Uitslag            }
1270dd7a6159SGerrit Uitslag        }
127117566ac6SAdrian Lang    }
127217566ac6SAdrian Lang    return $lang[$id];
127317566ac6SAdrian Lang}
127417566ac6SAdrian Lang
12753df72098SAndreas Gohr/**
1276c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1277e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1278e8ec13b9SKlap-in *
1279e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1280e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1281e8ec13b9SKlap-in */
1282e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1283c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1284e8ec13b9SKlap-in}
1285e8ec13b9SKlap-in
1286e8ec13b9SKlap-in/**
1287c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
128842ea7f44SGerrit Uitslag *
128942ea7f44SGerrit Uitslag * @param string $id id of localized text
129042ea7f44SGerrit Uitslag * @return string wiki text
1291e8ec13b9SKlap-in */
1292c5c17fdaSKlap-infunction tpl_localeFN($id) {
1293e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1294e8ec13b9SKlap-in    global $conf;
129538fb1fc7SGerrit Uitslag    $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
129679e79377SAndreas Gohr    if (!file_exists($file)){
1297e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
129879e79377SAndreas Gohr        if(!file_exists($file)){
1299e8ec13b9SKlap-in            //fall back to english
1300e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1301e8ec13b9SKlap-in        }
1302e8ec13b9SKlap-in    }
1303e8ec13b9SKlap-in    return $file;
1304e8ec13b9SKlap-in}
1305e8ec13b9SKlap-in
1306e8ec13b9SKlap-in/**
13077abc270fSGerrit Uitslag * prints the "main content" in the mediamanager popup
13083df72098SAndreas Gohr *
13093df72098SAndreas Gohr * Depending on the user's actions this may be a list of
13103df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
13113df72098SAndreas Gohr * a message of referencing pages
13123df72098SAndreas Gohr *
13133df72098SAndreas Gohr * Only allowed in mediamanager.php
13143df72098SAndreas Gohr *
1315c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1316c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
131742ea7f44SGerrit Uitslag * @param string $sort
13188702de7fSGerrit Uitslag *
13193df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13203df72098SAndreas Gohr */
132100e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
13223df72098SAndreas Gohr    global $IMG;
13233df72098SAndreas Gohr    global $AUTH;
13243df72098SAndreas Gohr    global $INUSE;
13253df72098SAndreas Gohr    global $NS;
13263df72098SAndreas Gohr    global $JUMPTO;
1327585bf44eSChristopher Smith    /** @var Input $INPUT */
1328ac7a515fSAndreas Gohr    global $INPUT;
13293df72098SAndreas Gohr
1330ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1331c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1332c182313eSAndreas Gohr
1333c182313eSAndreas Gohr    if(!$do) {
1334ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1335c182313eSAndreas Gohr            $do = 'metaform';
1336c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1337c182313eSAndreas Gohr            $do = 'filesinuse';
1338c182313eSAndreas Gohr        } else {
1339c182313eSAndreas Gohr            $do = 'filelist';
1340c182313eSAndreas Gohr        }
1341c182313eSAndreas Gohr    }
1342c182313eSAndreas Gohr
1343c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1344c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1345c182313eSAndreas Gohr    $data = array('do' => $do);
1346c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1347c182313eSAndreas Gohr    if($evt->advise_before()) {
1348c182313eSAndreas Gohr        $do = $data['do'];
134930fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1350c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1351c182313eSAndreas Gohr        } elseif($do == 'filelist') {
135200e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1353c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1354ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1355c182313eSAndreas Gohr        } else {
1356c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1357c182313eSAndreas Gohr        }
1358c182313eSAndreas Gohr    }
1359c182313eSAndreas Gohr    $evt->advise_after();
1360c182313eSAndreas Gohr    unset($evt);
1361c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1362c182313eSAndreas Gohr
13633df72098SAndreas Gohr}
13643df72098SAndreas Gohr
13653df72098SAndreas Gohr/**
1366d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1367d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1368d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1369d9162c6cSKate Arzamastseva *
1370d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1371d9162c6cSKate Arzamastseva */
1372035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1373d9162c6cSKate Arzamastseva    global $AUTH;
1374d9162c6cSKate Arzamastseva    global $NS;
1375d9162c6cSKate Arzamastseva    global $JUMPTO;
137695b451bcSAdrian Lang    global $lang;
1377585bf44eSChristopher Smith    /** @var Input $INPUT */
1378ac7a515fSAndreas Gohr    global $INPUT;
1379d9162c6cSKate Arzamastseva
1380ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1381e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1382ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1383d9162c6cSKate Arzamastseva
138494add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
138595b451bcSAdrian Lang
1386ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
138723846a98SKate Arzamastseva
138894add303SAnika Henke    echo '<div class="panelHeader">'.NL;
138995b451bcSAdrian Lang    echo '<h3>';
1390026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1391c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
139294add303SAnika Henke    echo '</h3>'.NL;
139395b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
139495b451bcSAdrian Lang        media_tab_files_options();
139523846a98SKate Arzamastseva    }
139694add303SAnika Henke    echo '</div>'.NL;
1397d9162c6cSKate Arzamastseva
139894add303SAnika Henke    echo '<div class="panelContent">'.NL;
139995b451bcSAdrian Lang    if($opened_tab == 'files') {
140095b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
140195b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
140295b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
140395b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
140495b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
140595b451bcSAdrian Lang    }
140694add303SAnika Henke    echo '</div>'.NL;
1407d9162c6cSKate Arzamastseva}
1408d9162c6cSKate Arzamastseva
1409d9162c6cSKate Arzamastseva/**
1410d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1411d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1412d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1413d9162c6cSKate Arzamastseva * list of file revisions
1414d9162c6cSKate Arzamastseva *
1415d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1416f50a239bSTakamura *
1417f50a239bSTakamura * @param string $image
1418f50a239bSTakamura * @param boolean $rev
1419d9162c6cSKate Arzamastseva */
1420035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1421e8a2a143SMichael Hamann    global $conf, $DEL, $lang;
1422585bf44eSChristopher Smith    /** @var Input $INPUT */
1423585bf44eSChristopher Smith    global $INPUT;
1424d9162c6cSKate Arzamastseva
142592cac9a9SKate Arzamastseva    $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1426ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
14276dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1428e8a2a143SMichael Hamann    $ns = getNS($image);
1429ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
14301eeeced2SKate Arzamastseva
1431ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1432e5d185e1SKate Arzamastseva
1433e5d185e1SKate Arzamastseva    $tab_array = array('view');
1434ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1435e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1436e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1437e5d185e1SKate Arzamastseva    }
1438e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1439e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1440e5d185e1SKate Arzamastseva    }
1441e5d185e1SKate Arzamastseva
1442e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1443ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
144423846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1445d9162c6cSKate Arzamastseva
1446ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
144723846a98SKate Arzamastseva
144859f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1449ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
145095b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
145195b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
1452750a0b51SMichael Große    $attributes = $rev ? ['rev' => $rev] : [];
1453750a0b51SMichael Große    $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
145408317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
145508317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
145608317413SAdrian Lang    } else {
1457026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
145808317413SAdrian Lang    }
1459b8a84c03SAndreas Gohr
146094add303SAnika Henke    echo '</h3></div>'.NL;
146195b451bcSAdrian Lang
146294add303SAnika Henke    echo '<div class="panelContent">'.NL;
146395b451bcSAdrian Lang
146423846a98SKate Arzamastseva    if($opened_tab == 'view') {
1465e8a2a143SMichael Hamann        media_tab_view($image, $ns, null, $rev);
146623846a98SKate Arzamastseva
146792cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
1468e8a2a143SMichael Hamann        media_tab_edit($image, $ns);
146923846a98SKate Arzamastseva
1470e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1471e8a2a143SMichael Hamann        media_tab_history($image, $ns);
147223846a98SKate Arzamastseva    }
147395b451bcSAdrian Lang
147494add303SAnika Henke    echo '</div>'.NL;
1475d9162c6cSKate Arzamastseva}
1476d9162c6cSKate Arzamastseva
1477d9162c6cSKate Arzamastseva/**
14787abc270fSGerrit Uitslag * prints the namespace tree in the mediamanager popup
14793df72098SAndreas Gohr *
14803df72098SAndreas Gohr * Only allowed in mediamanager.php
14813df72098SAndreas Gohr *
14823df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14833df72098SAndreas Gohr */
1484fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14853df72098SAndreas Gohr    global $NS;
148623846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14873df72098SAndreas Gohr    media_nstree($NS);
14883df72098SAndreas Gohr    ptln('</div>');
14893df72098SAndreas Gohr}
14903df72098SAndreas Gohr
1491a00de5b5SAndreas Gohr/**
1492a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1493a00de5b5SAndreas Gohr *
1494a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1495a00de5b5SAndreas Gohr *
1496a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
149742ea7f44SGerrit Uitslag *
149842ea7f44SGerrit Uitslag * @param string $empty empty option label
149942ea7f44SGerrit Uitslag * @param string $button submit button label
1500affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
1501a00de5b5SAndreas Gohr */
1502a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1503affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
15041e875dcdSAndreas Gohr    $menu = new \dokuwiki\Menu\MobileMenu();
15051e875dcdSAndreas Gohr    echo $menu->getDropdown($empty, $button);
1506a00de5b5SAndreas Gohr}
1507a00de5b5SAndreas Gohr
1508066fee30SAndreas Gohr/**
1509066fee30SAndreas Gohr * Print a informational line about the used license
1510066fee30SAndreas Gohr *
1511066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1512ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1513ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1514ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1515ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1516ac7a515fSAndreas Gohr * @return string
1517066fee30SAndreas Gohr */
151880083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1519066fee30SAndreas Gohr    global $license;
1520066fee30SAndreas Gohr    global $conf;
1521066fee30SAndreas Gohr    global $lang;
1522066fee30SAndreas Gohr    if(!$conf['license']) return '';
1523066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1524066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
152553e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1526066fee30SAndreas Gohr
152780083a41SAndreas Gohr    $out = '';
152880083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1529066fee30SAndreas Gohr    if($img) {
1530066fee30SAndreas Gohr        $src = license_img($img);
1531066fee30SAndreas Gohr        if($src) {
153253e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
153353e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
153453e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1535066fee30SAndreas Gohr        }
1536066fee30SAndreas Gohr    }
15374cefd216SMichael Klier    if(!$imgonly) {
153853e15c8bSAnika Henke        $out .= $lang['license'].' ';
1539d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1540d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
15414cefd216SMichael Klier    }
154280083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1543066fee30SAndreas Gohr
1544066fee30SAndreas Gohr    if($return) return $out;
1545066fee30SAndreas Gohr    echo $out;
1546ac7a515fSAndreas Gohr    return '';
1547066fee30SAndreas Gohr}
1548066fee30SAndreas Gohr
1549a81910eeSAndreas Gohr/**
1550835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1551a81910eeSAndreas Gohr *
1552a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1553a81910eeSAndreas Gohr * template
1554e0c26282SGerrit Uitslag *
15557a112df5SAndreas Gohr * @param string $pageid The page name you want to include
15567a112df5SAndreas Gohr * @param bool $print Should the content be printed or returned only
15577a112df5SAndreas Gohr * @param bool $propagate Search higher namespaces, too?
15587c3e4a67SAndreas Gohr * @param bool $useacl Include the page only if the ACLs check out?
1559e0c26282SGerrit Uitslag * @return bool|null|string
1560a81910eeSAndreas Gohr */
15617c3e4a67SAndreas Gohrfunction tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
15627a112df5SAndreas Gohr    if($propagate) {
15637c3e4a67SAndreas Gohr        $pageid = page_findnearest($pageid, $useacl);
15647c3e4a67SAndreas Gohr    } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
15657a112df5SAndreas Gohr        return false;
15667a112df5SAndreas Gohr    }
1567c786a1b6SAnika Henke    if(!$pageid) return false;
1568835dfcaeSAnika Henke
1569c786a1b6SAnika Henke    global $TOC;
15709a2e250aSAndreas Gohr    $oldtoc = $TOC;
1571a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
15729a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1573a81910eeSAndreas Gohr
1574a2e03c82SAndreas Gohr    if($print) echo $html;
1575e66d3e6dSAndreas Gohr    return $html;
1576e66d3e6dSAndreas Gohr}
1577e66d3e6dSAndreas Gohr
1578e66d3e6dSAndreas Gohr/**
15795b75cd1fSAdrian Lang * Display the subscribe form
15805b75cd1fSAdrian Lang *
15815b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15825b75cd1fSAdrian Lang */
15835b75cd1fSAdrian Langfunction tpl_subscribe() {
15845b75cd1fSAdrian Lang    global $INFO;
15855b75cd1fSAdrian Lang    global $ID;
15865b75cd1fSAdrian Lang    global $lang;
15876b8f02cfSAdrian Lang    global $conf;
158840c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15895b75cd1fSAdrian Lang
15905b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15915b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
159215741132SAndreas Gohr    echo '<div class="level2">';
15935b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
15945b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
15955b75cd1fSAdrian Lang    } else {
15965b75cd1fSAdrian Lang        echo '<ul>';
15975b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1598056c2049SAndreas Gohr            echo '<li><div class="li">';
15995b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1600056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
16015b75cd1fSAdrian Lang            } else {
1602056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
16035b75cd1fSAdrian Lang            }
160440c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
160515741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1606056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
160715741132SAndreas Gohr
1608ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1609ac7a515fSAndreas Gohr                $ID,
1610ac7a515fSAndreas Gohr                array(
1611ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
161266d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
161366d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
161466d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1615ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1616ac7a515fSAndreas Gohr                )
1617ac7a515fSAndreas Gohr            ).
161866d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
161966d2bed9SAdrian Lang                '</a></div></li>';
16205b75cd1fSAdrian Lang        }
16215b75cd1fSAdrian Lang        echo '</ul>';
16225b75cd1fSAdrian Lang    }
162315741132SAndreas Gohr    echo '</div>';
16245b75cd1fSAdrian Lang
162515741132SAndreas Gohr    // Add new subscription form
16265b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
162715741132SAndreas Gohr    echo '<div class="level2">';
16285b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
162915741132SAndreas Gohr    $targets = array(
163015741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
163115741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
163215741132SAndreas Gohr    );
163315741132SAndreas Gohr    $styles  = array(
163415741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
16356b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
16366b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
163715741132SAndreas Gohr    );
163815741132SAndreas Gohr
1639056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1640056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1641056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1642056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1643056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1644056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1645056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1646056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1647056c2049SAndreas Gohr    $form->endFieldset();
16485b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
16495b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
165015741132SAndreas Gohr    echo '</div>';
16515b75cd1fSAdrian Lang}
16525b75cd1fSAdrian Lang
1653d059ba9bSAndreas Gohr/**
1654d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1655d059ba9bSAndreas Gohr *
1656d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1657d059ba9bSAndreas Gohr *
1658d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1659d059ba9bSAndreas Gohr */
1660d059ba9bSAndreas Gohrfunction tpl_flush() {
1661d059ba9bSAndreas Gohr    ob_flush();
1662d059ba9bSAndreas Gohr    flush();
1663d059ba9bSAndreas Gohr}
1664d059ba9bSAndreas Gohr
1665afca7e7eSAnika Henke/**
1666378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1667afca7e7eSAnika Henke *
1668378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1669378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1670378325f9SAndreas Gohr *
167142ea7f44SGerrit Uitslag * @param  string[] $search       locations to look at
1672378325f9SAndreas Gohr * @param  bool     $abs           if to use absolute URL
1673ac7a515fSAndreas Gohr * @param  array   &$imginfo   filled with getimagesize()
1674ac7a515fSAndreas Gohr * @return string
167542ea7f44SGerrit Uitslag *
1676378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1677afca7e7eSAnika Henke */
1678378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1679ac7a515fSAndreas Gohr    $img     = '';
1680ac7a515fSAndreas Gohr    $file    = '';
1681ac7a515fSAndreas Gohr    $ismedia = false;
1682378325f9SAndreas Gohr    // loop through candidates until a match was found:
1683378325f9SAndreas Gohr    foreach($search as $img) {
1684378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1685378325f9SAndreas Gohr            $file    = mediaFN($img);
1686378325f9SAndreas Gohr            $ismedia = true;
1687378325f9SAndreas Gohr        } else {
1688c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1689378325f9SAndreas Gohr            $ismedia = false;
16901f13e33dSAnika Henke        }
16910f747863Slupo49
1692378325f9SAndreas Gohr        if(file_exists($file)) break;
1693872a6d29SAnika Henke    }
1694378325f9SAndreas Gohr
1695378325f9SAndreas Gohr    // fetch image data if requested
1696378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1697378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1698378325f9SAndreas Gohr    }
1699378325f9SAndreas Gohr
1700378325f9SAndreas Gohr    // build URL
1701378325f9SAndreas Gohr    if($ismedia) {
1702378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1703378325f9SAndreas Gohr    } else {
1704c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1705378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1706378325f9SAndreas Gohr    }
1707378325f9SAndreas Gohr
1708378325f9SAndreas Gohr    return $url;
1709a7e5f74cSlupo49}
17101f13e33dSAnika Henke
1711872a6d29SAnika Henke/**
1712e5d4768dSAndreas Gohr * PHP include a file
1713e5d4768dSAndreas Gohr *
1714e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1715e5d4768dSAndreas Gohr * file in the template's root directory.
1716e5d4768dSAndreas Gohr *
1717e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1718e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1719e5d4768dSAndreas Gohr * default.
1720e5d4768dSAndreas Gohr *
1721e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1722e5d4768dSAndreas Gohr * to this function!
1723e5d4768dSAndreas Gohr *
1724e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1725e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
172642ea7f44SGerrit Uitslag *
172742ea7f44SGerrit Uitslag * @param string $file
1728e5d4768dSAndreas Gohr */
1729e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1730e5d4768dSAndreas Gohr    global $config_cascade;
1731e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1732e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1733e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1734e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1735e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1736f3a1225fSAnika Henke                include("$dir/$file");
1737e5d4768dSAndreas Gohr                return;
1738e5d4768dSAndreas Gohr            }
1739e5d4768dSAndreas Gohr        }
1740e5d4768dSAndreas Gohr    }
1741e5d4768dSAndreas Gohr
1742e5d4768dSAndreas Gohr    // still here? try the template dir
1743e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1744e5d4768dSAndreas Gohr    if(file_exists($file)) {
1745f3a1225fSAnika Henke        include($file);
1746e5d4768dSAndreas Gohr    }
1747e5d4768dSAndreas Gohr}
1748e5d4768dSAndreas Gohr
1749e5d4768dSAndreas Gohr/**
1750872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1751872a6d29SAnika Henke *
1752872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
175342ea7f44SGerrit Uitslag *
1754ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1755ac7a515fSAndreas Gohr * @return string
1756872a6d29SAnika Henke */
1757872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1758872a6d29SAnika Henke
1759872a6d29SAnika Henke    $return = '';
1760872a6d29SAnika Henke
1761872a6d29SAnika Henke    foreach($types as $type) {
1762872a6d29SAnika Henke        switch($type) {
1763872a6d29SAnika Henke            case 'favicon':
1764378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1765378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1766872a6d29SAnika Henke                break;
1767872a6d29SAnika Henke            case 'mobile':
1768cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1769378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1770872a6d29SAnika Henke                break;
1771872a6d29SAnika Henke            case 'generic':
1772872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1773378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1774378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1775872a6d29SAnika Henke                break;
1776872a6d29SAnika Henke        }
1777872a6d29SAnika Henke    }
1778872a6d29SAnika Henke
1779872a6d29SAnika Henke    return $return;
1780afca7e7eSAnika Henke}
1781afca7e7eSAnika Henke
1782d9162c6cSKate Arzamastseva/**
1783d9162c6cSKate Arzamastseva * Prints full-screen media manager
1784d9162c6cSKate Arzamastseva *
1785d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1786d9162c6cSKate Arzamastseva */
1787d9162c6cSKate Arzamastsevafunction tpl_media() {
1788ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
178988a71175SKate Arzamastseva    $fullscreen = true;
179095b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1791d9162c6cSKate Arzamastseva
1792ac7a515fSAndreas Gohr    $rev   = '';
1793ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
179498f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
179598f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
17969c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
179798f03b57SKate Arzamastseva
179894add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1799bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1800d9162c6cSKate Arzamastseva    html_msgarea();
180194add303SAnika Henke
180294add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
180394add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
180495b451bcSAdrian Lang    echo '<div class="panelHeader">';
1805ba340a70SAnika Henke    echo $lang['media_namespaces'];
180694add303SAnika Henke    echo '</div>'.NL;
180795b451bcSAdrian Lang
180894add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
180995b451bcSAdrian Lang    media_nstree($NS);
181094add303SAnika Henke    echo '</div>'.NL;
181194add303SAnika Henke    echo '</div>'.NL;
1812fa8e5c77SKate Arzamastseva
181394add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1814035e07f1SKate Arzamastseva    tpl_mediaFileList();
181594add303SAnika Henke    echo '</div>'.NL;
1816fa8e5c77SKate Arzamastseva
181794add303SAnika Henke    echo '<div class="panel file">'.NL;
181894add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1819035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
182094add303SAnika Henke    echo '</div>'.NL;
1821ba340a70SAnika Henke
182294add303SAnika Henke    echo '</div>'.NL;
1823d9162c6cSKate Arzamastseva}
1824afca7e7eSAnika Henke
1825c71db656SAnika Henke/**
1826c71db656SAnika Henke * Return useful layout classes
1827c71db656SAnika Henke *
1828c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
182942ea7f44SGerrit Uitslag *
183042ea7f44SGerrit Uitslag * @return string
1831c71db656SAnika Henke */
1832c71db656SAnika Henkefunction tpl_classes() {
1833c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1834585bf44eSChristopher Smith    /** @var Input $INPUT */
1835585bf44eSChristopher Smith    global $INPUT;
1836585bf44eSChristopher Smith
1837c71db656SAnika Henke    $classes = array(
1838c71db656SAnika Henke        'dokuwiki',
1839c71db656SAnika Henke        'mode_'.$ACT,
1840c71db656SAnika Henke        'tpl_'.$conf['template'],
1841585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
184239f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1843c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1844c71db656SAnika Henke    );
1845c71db656SAnika Henke    return join(' ', $classes);
1846c71db656SAnika Henke}
1847c71db656SAnika Henke
184884dd2b1aSGerrit Uitslag/**
184984dd2b1aSGerrit Uitslag * Create event for tools menues
185084dd2b1aSGerrit Uitslag *
185184dd2b1aSGerrit Uitslag * @author Anika Henke <anika@selfthinker.org>
185284dd2b1aSGerrit Uitslag * @param string $toolsname name of menu
185384dd2b1aSGerrit Uitslag * @param array $items
185484dd2b1aSGerrit Uitslag * @param string $view e.g. 'main', 'detail', ...
1855affc7ddfSAndreas Gohr * @deprecated 2017-09-01 see devel:menus
185684dd2b1aSGerrit Uitslag */
185784dd2b1aSGerrit Uitslagfunction tpl_toolsevent($toolsname, $items, $view = 'main') {
1858affc7ddfSAndreas Gohr    dbg_deprecated('see devel:menus');
185984dd2b1aSGerrit Uitslag    $data = array(
186084dd2b1aSGerrit Uitslag        'view' => $view,
186184dd2b1aSGerrit Uitslag        'items' => $items
186284dd2b1aSGerrit Uitslag    );
186384dd2b1aSGerrit Uitslag
186484dd2b1aSGerrit Uitslag    $hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
186584dd2b1aSGerrit Uitslag    $evt = new Doku_Event($hook, $data);
186684dd2b1aSGerrit Uitslag    if($evt->advise_before()) {
186784dd2b1aSGerrit Uitslag        foreach($evt->data['items'] as $k => $html) echo $html;
186884dd2b1aSGerrit Uitslag    }
186984dd2b1aSGerrit Uitslag    $evt->advise_after();
187084dd2b1aSGerrit Uitslag}
187184dd2b1aSGerrit Uitslag
1872e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1873a00de5b5SAndreas Gohr
1874