xref: /dokuwiki/inc/template.php (revision ac7a515f564d088e043bf190c9a4ced1d5c309db)
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/**
12*ac7a515fSAndreas Gohr * Access a template file
13*ac7a515fSAndreas Gohr *
14*ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
15*ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
165a892029SAndreas Gohr *
175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
18*ac7a515fSAndreas Gohr * @param string $file
19*ac7a515fSAndreas Gohr * @return string
205a892029SAndreas Gohr */
21*ac7a515fSAndreas Gohrfunction template($file) {
225a892029SAndreas Gohr    global $conf;
235a892029SAndreas Gohr
24*ac7a515fSAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
25*ac7a515fSAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
265a892029SAndreas Gohr
27*ac7a515fSAndreas 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>
36*ac7a515fSAndreas Gohr * @return string
37c4766956SAndreas Gohr */
38c4766956SAndreas Gohrfunction tpl_incdir() {
3975b14482SAndreas Gohr    global $conf;
40c4766956SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$conf['template'].'/';
41c4766956SAndreas Gohr}
42c4766956SAndreas Gohr
43c4766956SAndreas Gohr/**
44c4766956SAndreas Gohr * Convenience function to access template dir from web
45c4766956SAndreas Gohr *
46c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
47c4766956SAndreas Gohr *
48c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
49*ac7a515fSAndreas Gohr * @return string
50c4766956SAndreas Gohr */
51c4766956SAndreas Gohrfunction tpl_basedir() {
5275b14482SAndreas Gohr    global $conf;
53c4766956SAndreas Gohr    return DOKU_BASE.'lib/tpl/'.$conf['template'].'/';
54c4766956SAndreas Gohr}
55c4766956SAndreas Gohr
565a892029SAndreas Gohr/**
576b13307fSandi * Print the content
586b13307fSandi *
596b13307fSandi * This function is used for printing all the usual content
606b13307fSandi * (defined by the global $ACT var) by calling the appropriate
616b13307fSandi * outputfunction(s) from html.php
626b13307fSandi *
63ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
64ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
656b13307fSandi *
666b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
67*ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
68*ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
69*ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
70*ac7a515fSAndreas Gohr * @return bool true if any output
716b13307fSandi */
72b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) {
737ea0913cSchris    global $ACT;
74b8595a66SAndreas Gohr    global $INFO;
75b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
767ea0913cSchris
777ea0913cSchris    ob_start();
78746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
797ea0913cSchris    $html_output = ob_get_clean();
80746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
8154e95700STom N Harris
8254e95700STom N Harris    return !empty($html_output);
837ea0913cSchris}
847ea0913cSchris
85*ac7a515fSAndreas Gohr/**
86*ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
87*ac7a515fSAndreas Gohr *
88*ac7a515fSAndreas Gohr * @return bool
89*ac7a515fSAndreas Gohr */
907ea0913cSchrisfunction tpl_content_core() {
916b13307fSandi    global $ACT;
926b13307fSandi    global $TEXT;
936b13307fSandi    global $PRE;
946b13307fSandi    global $SUF;
956b13307fSandi    global $SUM;
966b13307fSandi    global $IDX;
97*ac7a515fSAndreas Gohr    global $INPUT;
986b13307fSandi
996b13307fSandi    switch($ACT) {
1006b13307fSandi        case 'show':
1016b13307fSandi            html_show();
1026b13307fSandi            break;
103*ac7a515fSAndreas Gohr        /** @noinspection PhpMissingBreakStatementInspection */
10445a99335SAdrian Lang        case 'locked':
10545a99335SAdrian Lang            html_locked();
1066b13307fSandi        case 'edit':
10745a99335SAdrian Lang        case 'recover':
1086b13307fSandi            html_edit();
1096b13307fSandi            break;
11045a99335SAdrian Lang        case 'preview':
11145a99335SAdrian Lang            html_edit();
11245a99335SAdrian Lang            html_show($TEXT);
11345a99335SAdrian Lang            break;
114ee4c4a1bSAndreas Gohr        case 'draft':
115ee4c4a1bSAndreas Gohr            html_draft();
116ee4c4a1bSAndreas Gohr            break;
1176b13307fSandi        case 'search':
1186b13307fSandi            html_search();
1196b13307fSandi            break;
1206b13307fSandi        case 'revisions':
121*ac7a515fSAndreas Gohr            html_revisions($INPUT->int('first'));
1226b13307fSandi            break;
1236b13307fSandi        case 'diff':
1246b13307fSandi            html_diff();
1256b13307fSandi            break;
1266b13307fSandi        case 'recent':
127*ac7a515fSAndreas Gohr            html_recent($INPUT->extract('first')->int('first'), $INPUT->str('show_changes'));
1286b13307fSandi            break;
1296b13307fSandi        case 'index':
1306b13307fSandi            html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
1316b13307fSandi            break;
1326b13307fSandi        case 'backlink':
1336b13307fSandi            html_backlinks();
1346b13307fSandi            break;
1356b13307fSandi        case 'conflict':
1366b13307fSandi            html_conflict(con($PRE, $TEXT, $SUF), $SUM);
1376b13307fSandi            html_diff(con($PRE, $TEXT, $SUF), false);
1386b13307fSandi            break;
1396b13307fSandi        case 'login':
1406b13307fSandi            html_login();
1416b13307fSandi            break;
1426b13307fSandi        case 'register':
1436b13307fSandi            html_register();
1446b13307fSandi            break;
1458b06d178Schris        case 'resendpwd':
1468b06d178Schris            html_resendpwd();
1478b06d178Schris            break;
148820fa24bSandi        case 'denied':
1495e991bd8Sandi            print p_locale_xhtml('denied');
150820fa24bSandi            break;
1518b06d178Schris        case 'profile' :
1528b06d178Schris            html_updateprofile();
1538b06d178Schris            break;
154c19fe9c0Sandi        case 'admin':
155c19fe9c0Sandi            tpl_admin();
156c19fe9c0Sandi            break;
1575b75cd1fSAdrian Lang        case 'subscribe':
1585b75cd1fSAdrian Lang            tpl_subscribe();
1595b75cd1fSAdrian Lang            break;
160d9162c6cSKate Arzamastseva        case 'media':
161d9162c6cSKate Arzamastseva            tpl_media();
162d9162c6cSKate Arzamastseva            break;
1636b13307fSandi        default:
16424bb549bSchris            $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT);
16524bb549bSchris            if($evt->advise_before())
166ea67f144Sandi                msg("Failed to handle command: ".hsc($ACT), -1);
16724bb549bSchris            $evt->advise_after();
16824bb549bSchris            unset($evt);
16954e95700STom N Harris            return false;
1706b13307fSandi    }
17154e95700STom N Harris    return true;
1726b13307fSandi}
1736b13307fSandi
174c19fe9c0Sandi/**
175b8595a66SAndreas Gohr * Places the TOC where the function is called
176b8595a66SAndreas Gohr *
177b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
178b8595a66SAndreas Gohr * a false argument
179b8595a66SAndreas Gohr *
180b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
181*ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
182*ac7a515fSAndreas Gohr * @return string
183b8595a66SAndreas Gohr */
184b8595a66SAndreas Gohrfunction tpl_toc($return = false) {
185b8595a66SAndreas Gohr    global $TOC;
186b8595a66SAndreas Gohr    global $ACT;
187b8595a66SAndreas Gohr    global $ID;
188b8595a66SAndreas Gohr    global $REV;
189b8595a66SAndreas Gohr    global $INFO;
190851f2e89SAnika Henke    global $conf;
191*ac7a515fSAndreas Gohr    global $INPUT;
192b8595a66SAndreas Gohr    $toc = array();
193b8595a66SAndreas Gohr
194b8595a66SAndreas Gohr    if(is_array($TOC)) {
195b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
196b8595a66SAndreas Gohr        $toc = $TOC;
1973c86d7c9SAndreas Gohr    } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
198b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
19965aa8490SMichael Hamann        $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE);
200b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])) {
201b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
202b8595a66SAndreas Gohr        } else {
2032bb0d541Schris            $tocok = true;
204b8595a66SAndreas Gohr        }
205b8595a66SAndreas Gohr        $toc = $meta['description']['tableofcontents'];
206851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
207b8595a66SAndreas Gohr            $toc = array();
208b8595a66SAndreas Gohr        }
209b8595a66SAndreas Gohr    } elseif($ACT == 'admin') {
210b8595a66SAndreas Gohr        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
211b8595a66SAndreas Gohr        $plugin = null;
212*ac7a515fSAndreas Gohr        $class  = $INPUT->str('page');
213*ac7a515fSAndreas Gohr        if(!empty($class)) {
214b8595a66SAndreas Gohr            $pluginlist = plugin_list('admin');
215*ac7a515fSAndreas Gohr            if(in_array($class, $pluginlist)) {
216b8595a66SAndreas Gohr                // attempt to load the plugin
217*ac7a515fSAndreas Gohr                /** @var $plugin DokuWiki_Admin_Plugin */
218*ac7a515fSAndreas Gohr                $plugin =& plugin_load('admin', $class);
219b8595a66SAndreas Gohr            }
220b8595a66SAndreas Gohr        }
221*ac7a515fSAndreas Gohr        if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) {
222b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
223b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
224b8595a66SAndreas Gohr        }
225b8595a66SAndreas Gohr    }
226b8595a66SAndreas Gohr
2270b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
228b8595a66SAndreas Gohr    $html = html_TOC($toc);
229b8595a66SAndreas Gohr    if($return) return $html;
230b8595a66SAndreas Gohr    echo $html;
231*ac7a515fSAndreas Gohr    return '';
232b8595a66SAndreas Gohr}
233b8595a66SAndreas Gohr
234b8595a66SAndreas Gohr/**
235c19fe9c0Sandi * Handle the admin page contents
236c19fe9c0Sandi *
237c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
238c19fe9c0Sandi */
239c19fe9c0Sandifunction tpl_admin() {
240f8cc712eSAndreas Gohr    global $INFO;
241b8595a66SAndreas Gohr    global $TOC;
242*ac7a515fSAndreas Gohr    global $INPUT;
24311e2ce22Schris
244b8595a66SAndreas Gohr    $plugin = null;
245*ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
246*ac7a515fSAndreas Gohr    if(!empty($class)) {
24711e2ce22Schris        $pluginlist = plugin_list('admin');
24811e2ce22Schris
249*ac7a515fSAndreas Gohr        if(in_array($class, $pluginlist)) {
25011e2ce22Schris            // attempt to load the plugin
251*ac7a515fSAndreas Gohr            /** @var $plugin DokuWiki_Admin_Plugin */
252*ac7a515fSAndreas Gohr            $plugin =& plugin_load('admin', $class);
25311e2ce22Schris        }
25411e2ce22Schris    }
25511e2ce22Schris
256b8595a66SAndreas Gohr    if($plugin !== null) {
257b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
258b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
259f8cc712eSAndreas Gohr        $plugin->html();
260f8cc712eSAndreas Gohr    } else {
261f8cc712eSAndreas Gohr        html_admin();
262f8cc712eSAndreas Gohr    }
26354e95700STom N Harris    return true;
264c19fe9c0Sandi}
2656b13307fSandi
2666b13307fSandi/**
2676b13307fSandi * Print the correct HTML meta headers
2686b13307fSandi *
2696b13307fSandi * This has to go into the head section of your template.
2706b13307fSandi *
2716b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
272*ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
273*ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
274*ac7a515fSAndreas Gohr * @return bool
2756b13307fSandi */
276f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) {
2776b13307fSandi    global $ID;
278d98d4540SBen Coburn    global $REV;
2796b13307fSandi    global $INFO;
28072e0dc37SAndreas Gohr    global $JSINFO;
2816b13307fSandi    global $ACT;
2824bb1b5aeSAndreas Gohr    global $QUERY;
2836b13307fSandi    global $lang;
284dc57ef04Sandi    global $conf;
2856b13307fSandi
2867bff22c0SAndreas Gohr    // prepare the head array
2877bff22c0SAndreas Gohr    $head = array();
2887bff22c0SAndreas Gohr
289202ac28bSMichael Klier    // prepare seed for js and css
290202ac28bSMichael Klier    $tseed   = 0;
291202ac28bSMichael Klier    $depends = getConfigFiles('main');
292202ac28bSMichael Klier    foreach($depends as $f) {
293202ac28bSMichael Klier        $time = @filemtime($f);
294202ac28bSMichael Klier        if($time > $tseed) $tseed = $time;
295202ac28bSMichael Klier    }
2967bff22c0SAndreas Gohr
2976b13307fSandi    // the usual stuff
2983f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
299*ac7a515fSAndreas Gohr    $head['link'][] = array(
300*ac7a515fSAndreas Gohr        'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
301*ac7a515fSAndreas Gohr        'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
302*ac7a515fSAndreas Gohr    );
303f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
3047aedde2eSGina Haeussge    if(actionOK('index')) {
305*ac7a515fSAndreas Gohr        $head['link'][] = array(
306*ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
307*ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
308*ac7a515fSAndreas Gohr        );
3097aedde2eSGina Haeussge    }
310f96fa415SAndreas Gohr
311f96fa415SAndreas Gohr    if($alt) {
312*ac7a515fSAndreas Gohr        $head['link'][] = array(
313*ac7a515fSAndreas Gohr            'rel'  => 'alternate', 'type'=> 'application/rss+xml',
314*ac7a515fSAndreas Gohr            'title'=> 'Recent Changes', 'href'=> DOKU_BASE.'feed.php'
315*ac7a515fSAndreas Gohr        );
316*ac7a515fSAndreas Gohr        $head['link'][] = array(
317*ac7a515fSAndreas Gohr            'rel'  => 'alternate', 'type'=> 'application/rss+xml',
3187bff22c0SAndreas Gohr            'title'=> 'Current Namespace',
319*ac7a515fSAndreas Gohr            'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
320*ac7a515fSAndreas Gohr        );
321c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
322*ac7a515fSAndreas Gohr            $head['link'][] = array(
323*ac7a515fSAndreas Gohr                'rel'  => 'edit',
324715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
325*ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
326*ac7a515fSAndreas Gohr            );
327c35f3875SAndreas Gohr        }
328c35f3875SAndreas Gohr
3294bb1b5aeSAndreas Gohr        if($ACT == 'search') {
330*ac7a515fSAndreas Gohr            $head['link'][] = array(
331*ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
3324bb1b5aeSAndreas Gohr                'title'=> 'Search Result',
333*ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
334*ac7a515fSAndreas Gohr            );
3354bb1b5aeSAndreas Gohr        }
336bae36d94SAndreas Gohr
337bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
338*ac7a515fSAndreas Gohr            $head['link'][] = array(
339*ac7a515fSAndreas Gohr                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> 'Plain HTML',
340*ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
341*ac7a515fSAndreas Gohr            );
342bae36d94SAndreas Gohr        }
343bae36d94SAndreas Gohr
344bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
345*ac7a515fSAndreas Gohr            $head['link'][] = array(
346*ac7a515fSAndreas Gohr                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> 'Wiki Markup',
347*ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
348*ac7a515fSAndreas Gohr            );
349f96fa415SAndreas Gohr        }
350bae36d94SAndreas Gohr    }
3516b13307fSandi
3526b13307fSandi    // setup robot tags apropriate for different modes
3534f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3546b13307fSandi        if($INFO['exists']) {
3556b13307fSandi            //delay indexing:
3566b13307fSandi            if((time() - $INFO['lastmod']) >= $conf['indexdelay']) {
3577bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3586b13307fSandi            } else {
3597bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3606b13307fSandi            }
36169db0cafSAndreas Gohr            $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&'));
3626b13307fSandi        } else {
3637bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3646b13307fSandi        }
3657a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3667bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3676b13307fSandi    } else {
3687bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3696b13307fSandi    }
3706b13307fSandi
371831800b8SAndreas Gohr    // set metadata
372831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
373831800b8SAndreas Gohr        // date of modification
374831800b8SAndreas Gohr        if($REV) {
3757bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV));
376831800b8SAndreas Gohr        } else {
3777bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod']));
378831800b8SAndreas Gohr        }
379831800b8SAndreas Gohr
380831800b8SAndreas Gohr        // keywords (explicit or implicit)
381bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3827bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
383831800b8SAndreas Gohr        } else {
3847bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
385831800b8SAndreas Gohr        }
386831800b8SAndreas Gohr    }
387831800b8SAndreas Gohr
38878a6aeb1SAndreas Gohr    // load stylesheets
389*ac7a515fSAndreas Gohr    $head['link'][] = array(
390*ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
391*ac7a515fSAndreas Gohr        'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed
392*ac7a515fSAndreas Gohr    );
393bad31ae9SAndreas Gohr
3948bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
395463d4a65SAndreas Gohr    $json   = new JSON();
39672e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
397c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']) {
39872e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
399c591aabeSAndreas Gohr    }
40072e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
40185f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
4028bbcb611SAndreas Gohr
4038bbcb611SAndreas Gohr    // load external javascript
404*ac7a515fSAndreas Gohr    $head['script'][] = array(
405*ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
406*ac7a515fSAndreas Gohr        'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed
407*ac7a515fSAndreas Gohr    );
4087bff22c0SAndreas Gohr
4097bff22c0SAndreas Gohr    // trigger event here
410016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
41154e95700STom N Harris    return true;
4127bff22c0SAndreas Gohr}
4137bff22c0SAndreas Gohr
4147bff22c0SAndreas Gohr/**
4157bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
4167bff22c0SAndreas Gohr *
4177bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
4187bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
4197bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
4207bff22c0SAndreas Gohr *
4217bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
4221304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
4237bff22c0SAndreas Gohr *
4247bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
4257bff22c0SAndreas Gohr */
4267bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
4277bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
4287bff22c0SAndreas Gohr        foreach($inst as $attr) {
4297bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
43026afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
431e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
43209f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
433e226efe1SAndreas Gohr                        $attr['_data'].
43409f791c4SDominik Eckelmann                        "\n/*!]]>*/";
435e226efe1SAndreas Gohr
4361304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
4377bff22c0SAndreas Gohr            } else {
4387bff22c0SAndreas Gohr                echo '/>';
4397bff22c0SAndreas Gohr            }
4407bff22c0SAndreas Gohr            echo "\n";
4417bff22c0SAndreas Gohr        }
4427bff22c0SAndreas Gohr    }
4436b13307fSandi}
4446b13307fSandi
4456b13307fSandi/**
4466b13307fSandi * Print a link
4476b13307fSandi *
4485e163278SAndreas Gohr * Just builds a link.
4496b13307fSandi *
4506b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4516b13307fSandi */
4521af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
45301f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4541af98a77SAnika Henke    if($more) $out .= ' '.$more;
4551af98a77SAnika Henke    $out .= ">$name</a>";
4561af98a77SAnika Henke    if($return) return $out;
4571af98a77SAnika Henke    print $out;
45854e95700STom N Harris    return true;
4596b13307fSandi}
4606b13307fSandi
4616b13307fSandi/**
46255efc227SAndreas Gohr * Prints a link to a WikiPage
46355efc227SAndreas Gohr *
46455efc227SAndreas Gohr * Wrapper around html_wikilink
46555efc227SAndreas Gohr *
46655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
46755efc227SAndreas Gohr */
4680b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) {
46955efc227SAndreas Gohr    print html_wikilink($id, $name);
47054e95700STom N Harris    return true;
47155efc227SAndreas Gohr}
47255efc227SAndreas Gohr
47355efc227SAndreas Gohr/**
474a3ec5f4aSmatthiasgrimm * get the parent page
475a3ec5f4aSmatthiasgrimm *
476a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
477a3ec5f4aSmatthiasgrimm * returns false if none is available
478a3ec5f4aSmatthiasgrimm *
479377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
480a3ec5f4aSmatthiasgrimm */
481377f9e97SAndreas Gohrfunction tpl_getparent($id) {
482377f9e97SAndreas Gohr    $parent = getNS($id).':';
483377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
484a197105eSmatthiasgrimm    if($parent == $id) {
485a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
486a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
487a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
488377f9e97SAndreas Gohr        if($parent == $id) return false;
489a197105eSmatthiasgrimm    }
490377f9e97SAndreas Gohr    return $parent;
491a3ec5f4aSmatthiasgrimm}
492a3ec5f4aSmatthiasgrimm
493a3ec5f4aSmatthiasgrimm/**
4946b13307fSandi * Print one of the buttons
4956b13307fSandi *
496a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
497a453d131SAdrian Lang * @see    tpl_get_action
4986b13307fSandi */
4991af98a77SAnika Henkefunction tpl_button($type, $return = false) {
500a453d131SAdrian Lang    $data = tpl_get_action($type);
501a453d131SAdrian Lang    if($data === false) {
502a453d131SAdrian Lang        return false;
503a453d131SAdrian Lang    } elseif(!is_array($data)) {
504a453d131SAdrian Lang        $out = sprintf($data, 'button');
505409d7af7SAndreas Gohr    } else {
506*ac7a515fSAndreas Gohr        /**
507*ac7a515fSAndreas Gohr         * @var string $accesskey
508*ac7a515fSAndreas Gohr         * @var string $id
509*ac7a515fSAndreas Gohr         * @var string $method
510*ac7a515fSAndreas Gohr         * @var array  $params
511*ac7a515fSAndreas Gohr         */
512a453d131SAdrian Lang        extract($data);
513a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
514a453d131SAdrian Lang            $out = html_topbtn();
515409d7af7SAndreas Gohr        } else {
516a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
517409d7af7SAndreas Gohr        }
518409d7af7SAndreas Gohr    }
5191af98a77SAnika Henke    if($return) return $out;
520a453d131SAdrian Lang    echo $out;
521a453d131SAdrian Lang    return true;
5226b13307fSandi}
5236b13307fSandi
5246b13307fSandi/**
525ed630903Sandi * Like the action buttons but links
526ed630903Sandi *
527a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
528a453d131SAdrian Lang * @see    tpl_get_action
529a453d131SAdrian Lang */
530a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
531a453d131SAdrian Lang    global $lang;
532a453d131SAdrian Lang    $data = tpl_get_action($type);
533a453d131SAdrian Lang    if($data === false) {
534a453d131SAdrian Lang        return false;
535a453d131SAdrian Lang    } elseif(!is_array($data)) {
536a453d131SAdrian Lang        $out = sprintf($data, 'link');
537a453d131SAdrian Lang    } else {
538*ac7a515fSAndreas Gohr        /**
539*ac7a515fSAndreas Gohr         * @var string $accesskey
540*ac7a515fSAndreas Gohr         * @var string $id
541*ac7a515fSAndreas Gohr         * @var string $method
542*ac7a515fSAndreas Gohr         * @var array  $params
543*ac7a515fSAndreas Gohr         */
544a453d131SAdrian Lang        extract($data);
545a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
546a453d131SAdrian Lang            $linktarget = $id;
547a453d131SAdrian Lang        } else {
548a453d131SAdrian Lang            $linktarget = wl($id, $params);
549a453d131SAdrian Lang        }
550a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
551c7e90e3fSAnika Henke        $akey    = $addTitle = '';
552c7e90e3fSAnika Henke        if($accesskey) {
553c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
554c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
555c7e90e3fSAnika Henke        }
556*ac7a515fSAndreas Gohr        $out = tpl_link(
557*ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
558a453d131SAdrian Lang            'class="action '.$type.'" '.
559c7e90e3fSAnika Henke                $akey.'rel="nofollow" '.
560*ac7a515fSAndreas Gohr                'title="'.hsc($caption).$addTitle.'"', 1
561*ac7a515fSAndreas Gohr        );
562a453d131SAdrian Lang    }
563a453d131SAdrian Lang    if($return) return $out;
564a453d131SAdrian Lang    echo $out;
565a453d131SAdrian Lang    return true;
566a453d131SAdrian Lang}
567a453d131SAdrian Lang
568a453d131SAdrian Lang/**
569a453d131SAdrian Lang * Check the actions and get data for buttons and links
570ed630903Sandi *
571a453d131SAdrian Lang * Available actions are
572a453d131SAdrian Lang *
573a453d131SAdrian Lang *  edit        - edit/create/show/draft
574ed630903Sandi *  history     - old revisions
575ed630903Sandi *  recent      - recent changes
576a453d131SAdrian Lang *  login       - login/logout - if ACL enabled
577a453d131SAdrian Lang *  profile     - user profile (if logged in)
578ed630903Sandi *  index       - The index
579ed630903Sandi *  admin       - admin page - if enough rights
580a453d131SAdrian Lang *  top         - back to top
581a453d131SAdrian Lang *  back        - back to parent - if available
582bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
583a453d131SAdrian Lang *  subscribe/subscription- subscribe/unsubscribe
584ed630903Sandi *
585ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
586a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
587a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
588*ac7a515fSAndreas Gohr * @param string $type
589*ac7a515fSAndreas Gohr * @return array|bool|string
590ed630903Sandi */
591a453d131SAdrian Langfunction tpl_get_action($type) {
592ed630903Sandi    global $ID;
593ed630903Sandi    global $INFO;
594ed630903Sandi    global $REV;
595ed630903Sandi    global $ACT;
596ed630903Sandi
59775e487e9SAndreas Gohr    // check disabled actions and fix the badly named ones
598a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
599a453d131SAdrian Lang    if(!actionOK($type)) return false;
600409d7af7SAndreas Gohr
601a453d131SAdrian Lang    $accesskey = null;
6026709e843SAdrian Lang    $id        = $ID;
603a453d131SAdrian Lang    $method    = 'get';
604a453d131SAdrian Lang    $params    = array('do' => $type);
605ed630903Sandi    switch($type) {
606ed630903Sandi        case 'edit':
6070b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
608ed630903Sandi            if($ACT == 'show' || $ACT == 'search') {
609a453d131SAdrian Lang                $method = 'post';
610ed630903Sandi                if($INFO['writable']) {
611a453d131SAdrian Lang                    $accesskey = 'e';
612b8a111f5SMichael Klier                    if(!empty($INFO['draft'])) {
6136709e843SAdrian Lang                        $type         = 'draft';
614a453d131SAdrian Lang                        $params['do'] = 'draft';
615b8a111f5SMichael Klier                    } else {
616a453d131SAdrian Lang                        $params['rev'] = $REV;
617a453d131SAdrian Lang                        if(!$INFO['exists']) {
6186709e843SAdrian Lang                            $type = 'create';
619ed630903Sandi                        }
620b8a111f5SMichael Klier                    }
621ed630903Sandi                } else {
622a453d131SAdrian Lang                    if(!actionOK('source')) return false; //pseudo action
623a453d131SAdrian Lang                    $params['rev'] = $REV;
6246709e843SAdrian Lang                    $type          = 'source';
625a453d131SAdrian Lang                    $accesskey     = 'v';
626ed630903Sandi                }
627ed630903Sandi            } else {
62884148531SMichael Hamann                $params    = array();
6296709e843SAdrian Lang                $type      = 'show';
630a453d131SAdrian Lang                $accesskey = 'v';
631ed630903Sandi            }
6321af98a77SAnika Henke            break;
633a453d131SAdrian Lang        case 'revisions':
6346709e843SAdrian Lang            $type      = 'revs';
635a453d131SAdrian Lang            $accesskey = 'o';
6361af98a77SAnika Henke            break;
637ed630903Sandi        case 'recent':
638a453d131SAdrian Lang            $accesskey = 'r';
6391af98a77SAnika Henke            break;
640ed630903Sandi        case 'index':
641a453d131SAdrian Lang            $accesskey = 'x';
6421af98a77SAnika Henke            break;
643ed630903Sandi        case 'top':
644076f0d72SAnika Henke            $accesskey = 't';
64584148531SMichael Hamann            $params    = array();
646a453d131SAdrian Lang            $id        = '#dokuwiki__top';
6471af98a77SAnika Henke            break;
648a3ec5f4aSmatthiasgrimm        case 'back':
649a453d131SAdrian Lang            $parent = tpl_getparent($ID);
650a453d131SAdrian Lang            if(!$parent) {
651a453d131SAdrian Lang                return false;
652a3ec5f4aSmatthiasgrimm            }
653a453d131SAdrian Lang            $id        = $parent;
65484148531SMichael Hamann            $params    = array();
655a453d131SAdrian Lang            $accesskey = 'b';
6561af98a77SAnika Henke            break;
657ed630903Sandi        case 'login':
658a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
6592380e8a8SAdrian Lang            if(isset($_SERVER['REMOTE_USER'])) {
6603a48618aSAnika Henke                if(!actionOK('logout')) {
6612380e8a8SAdrian Lang                    return false;
6622380e8a8SAdrian Lang                }
663a453d131SAdrian Lang                $params['do'] = 'logout';
664a453d131SAdrian Lang                $type         = 'logout';
665bf413a4eSAnika Henke            }
666bf413a4eSAnika Henke            break;
667bf413a4eSAnika Henke        case 'register':
668bf413a4eSAnika Henke            if($_SERVER['REMOTE_USER']) {
669bf413a4eSAnika Henke                return false;
670bf413a4eSAnika Henke            }
671bf413a4eSAnika Henke            break;
672bf413a4eSAnika Henke        case 'resendpwd':
673bf413a4eSAnika Henke            if($_SERVER['REMOTE_USER']) {
674bf413a4eSAnika Henke                return false;
675ed630903Sandi            }
6761af98a77SAnika Henke            break;
677ed630903Sandi        case 'admin':
678a453d131SAdrian Lang            if(!$INFO['ismanager']) {
679a453d131SAdrian Lang                return false;
680c059e1a6SAndreas Gohr            }
6811af98a77SAnika Henke            break;
6821246e016SAndreas Gohr        case 'revert':
683a453d131SAdrian Lang            if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
684a453d131SAdrian Lang                return false;
6851246e016SAndreas Gohr            }
686a453d131SAdrian Lang            $params['rev']    = $REV;
687a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
6881246e016SAndreas Gohr            break;
689*ac7a515fSAndreas Gohr        /** @noinspection PhpMissingBreakStatementInspection */
690075f000fSChristopher Arndt        case 'subscription':
6916709e843SAdrian Lang            $type         = 'subscribe';
692a453d131SAdrian Lang            $params['do'] = 'subscribe';
6936709e843SAdrian Lang        case 'subscribe':
6943a48618aSAnika Henke            if(!$_SERVER['REMOTE_USER']) {
695a453d131SAdrian Lang                return false;
696b158d625SSteven Danz            }
6971af98a77SAnika Henke            break;
698f00151b4Schris        case 'backlink':
6991af98a77SAnika Henke            break;
7008b06d178Schris        case 'profile':
7013a48618aSAnika Henke            if(!isset($_SERVER['REMOTE_USER'])) {
702a453d131SAdrian Lang                return false;
7038b06d178Schris            }
7041af98a77SAnika Henke            break;
705b9eb2e61SKate Arzamastseva        case 'media':
706b9eb2e61SKate Arzamastseva            break;
707ed630903Sandi        default:
708a453d131SAdrian Lang            return '[unknown %s type]';
7091af98a77SAnika Henke            break;
710ed630903Sandi    }
711a453d131SAdrian Lang    return compact('accesskey', 'type', 'id', 'method', 'params');
712ed630903Sandi}
713ed630903Sandi
714ed630903Sandi/**
71501f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
71601f17825SAnika Henke *
71701f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
718*ac7a515fSAndreas Gohr * @param
719*ac7a515fSAndreas Gohr * @param bool   $link link or form button?
720*ac7a515fSAndreas Gohr * @param bool   $wrapper HTML element wrapper
721*ac7a515fSAndreas Gohr * @param bool   $return return or print
722*ac7a515fSAndreas Gohr * @param string $pre prefix for links
723*ac7a515fSAndreas Gohr * @param string $suf suffix for links
724*ac7a515fSAndreas Gohr * @param string $inner inner HTML for links
725*ac7a515fSAndreas Gohr * @return bool|string
72601f17825SAnika Henke */
727*ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
72801f17825SAnika Henke    $out = '';
729*ac7a515fSAndreas Gohr    if($link) {
730*ac7a515fSAndreas Gohr        $out .= tpl_actionlink($type, $pre, $suf, $inner, 1);
731*ac7a515fSAndreas Gohr    } else {
732*ac7a515fSAndreas Gohr        $out .= tpl_button($type, 1);
733*ac7a515fSAndreas Gohr    }
73401f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
73501f17825SAnika Henke
73601f17825SAnika Henke    if($return) return $out;
73701f17825SAnika Henke    print $out;
73801f17825SAnika Henke    return $out ? true : false;
73901f17825SAnika Henke}
74001f17825SAnika Henke
74101f17825SAnika Henke/**
7426b13307fSandi * Print the search form
7436b13307fSandi *
74472645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
74572645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
74672645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
74772645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
74872645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
74972645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
75072645b75SAndreas Gohr *
7516b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
752*ac7a515fSAndreas Gohr * @param bool $ajax
753*ac7a515fSAndreas Gohr * @param bool $autocomplete
754*ac7a515fSAndreas Gohr * @return bool
7556b13307fSandi */
75672645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
7576b13307fSandi    global $lang;
758c1e3b7d9Smatthiasgrimm    global $ACT;
759ad4aaef7SAndreas Gohr    global $QUERY;
760c1e3b7d9Smatthiasgrimm
761670ff54eSchris    // don't print the search form if search action has been disabled
76254e95700STom N Harris    if(!actionOk('search')) return false;
763670ff54eSchris
764156dbd62SGina Haeussge    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get"><div class="no">';
7656b13307fSandi    print '<input type="hidden" name="do" value="search" />';
766c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
767ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
76872645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
76907493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
77011ea018fSAndreas Gohr    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
77124a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
7724beabca9SAnika Henke    print '</div></form>';
77354e95700STom N Harris    return true;
7746b13307fSandi}
7756b13307fSandi
7766b13307fSandi/**
7776b13307fSandi * Print the breadcrumbs trace
7786b13307fSandi *
7796b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
780*ac7a515fSAndreas Gohr * @param string $sep Separator between entries
781*ac7a515fSAndreas Gohr * @return bool
7826b13307fSandi */
783e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') {
7846b13307fSandi    global $lang;
7856b13307fSandi    global $conf;
7866b13307fSandi
7876b13307fSandi    //check if enabled
788359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
7896b13307fSandi
7906b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
791265e3787Sandi
7922979a10bSKatriel Traum    //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
7932979a10bSKatriel Traum    if($lang['direction'] == 'rtl') {
7942979a10bSKatriel Traum        $crumbs     = array_reverse($crumbs, true);
7952979a10bSKatriel Traum        $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
7962979a10bSKatriel Traum    } else {
7972979a10bSKatriel Traum        $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
7982979a10bSKatriel Traum    }
799265e3787Sandi
80040eb54bbSjan    //render crumbs, highlight the last one
8011b6f3a44SAndreas Gohr    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
80240eb54bbSjan    $last = count($crumbs);
80340eb54bbSjan    $i    = 0;
804a77f5846Sjan    foreach($crumbs as $id => $name) {
80540eb54bbSjan        $i++;
8062979a10bSKatriel Traum        echo $crumbs_sep;
80792795d04Sandi        if($i == $last) print '<span class="curid">';
808e26fd1eeSAndreas Gohr        tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"');
80992795d04Sandi        if($i == $last) print '</span>';
8106b13307fSandi    }
81154e95700STom N Harris    return true;
8126b13307fSandi}
8136b13307fSandi
8146b13307fSandi/**
8151734437eSandi * Hierarchical breadcrumbs
8161734437eSandi *
81731e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8181734437eSandi * It only makes sense with a deep site structure.
8191734437eSandi *
8201734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8216bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
82231e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
823f46c9e83SAnika Henke * @author <fredrik@averpil.com>
8246bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
825*ac7a515fSAndreas Gohr * @param string $sep Separator between entries
826*ac7a515fSAndreas Gohr * @return bool
8271734437eSandi */
828e260f93bSAnika Henkefunction tpl_youarehere($sep = ' » ') {
8291734437eSandi    global $conf;
8301734437eSandi    global $ID;
8311734437eSandi    global $lang;
8321734437eSandi
83331e187f8SSean Coates    // check if enabled
83454e95700STom N Harris    if(!$conf['youarehere']) return false;
8351734437eSandi
8361734437eSandi    $parts = explode(':', $ID);
837796bafb3SAndreas Gohr    $count = count($parts);
8381734437eSandi
8391b6f3a44SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
8401734437eSandi
8411734437eSandi    // always print the startpage
842e013f48dSAnika Henke    tpl_pagelink(':'.$conf['start']);
843796bafb3SAndreas Gohr
844796bafb3SAndreas Gohr    // print intermediate namespace links
845796bafb3SAndreas Gohr    $part = '';
846796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
847796bafb3SAndreas Gohr        $part .= $parts[$i].':';
848796bafb3SAndreas Gohr        $page = $part;
849796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
850796bafb3SAndreas Gohr
851796bafb3SAndreas Gohr        // output
852796bafb3SAndreas Gohr        echo $sep;
853e013f48dSAnika Henke        tpl_pagelink($page);
85431e187f8SSean Coates    }
8551734437eSandi
856796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
857e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
858*ac7a515fSAndreas Gohr    if(isset($page) && $page == $part.$parts[$i]) return true;
859796bafb3SAndreas Gohr    $page = $part.$parts[$i];
860*ac7a515fSAndreas Gohr    if($page == $conf['start']) return true;
861796bafb3SAndreas Gohr    echo $sep;
862e013f48dSAnika Henke    tpl_pagelink($page);
86354e95700STom N Harris    return true;
8641734437eSandi}
8651734437eSandi
8661734437eSandi/**
8676b13307fSandi * Print info if the user is logged in
868a2488c3cSMatthias Grimm * and show full name in that case
8696b13307fSandi *
8706b13307fSandi * Could be enhanced with a profile link in future?
8716b13307fSandi *
8726b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
873*ac7a515fSAndreas Gohr * @return bool
8746b13307fSandi */
8756b13307fSandifunction tpl_userinfo() {
8766b13307fSandi    global $lang;
8773e63b73bSMichael Klier    global $INFO;
878c66972f2SAdrian Lang    if(isset($_SERVER['REMOTE_USER'])) {
879d9e0d8dcSVadim Nevorotin        print $lang['loggedinas'].': '.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')';
88054e95700STom N Harris        return true;
88154e95700STom N Harris    }
88254e95700STom N Harris    return false;
8836b13307fSandi}
8846b13307fSandi
8856b13307fSandi/**
8866b13307fSandi * Print some info about the current page
8876b13307fSandi *
8886b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
889*ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
890*ac7a515fSAndreas Gohr * @return bool|string
8916b13307fSandi */
8924b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
8936b13307fSandi    global $conf;
8946b13307fSandi    global $lang;
8956b13307fSandi    global $INFO;
896c6e92a3cSDavid Lorentsen    global $ID;
897c6e92a3cSDavid Lorentsen
898c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
899*ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
900*ac7a515fSAndreas Gohr        return false;
901*ac7a515fSAndreas Gohr    }
9026b13307fSandi
9036b13307fSandi    // prepare date and path
9046b13307fSandi    $fn = $INFO['filepath'];
9056b13307fSandi    if(!$conf['fullpath']) {
906613bca54SAndreas Gohr        if($INFO['rev']) {
90750fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn);
9086b13307fSandi        } else {
90950fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn);
9106b13307fSandi        }
9116b13307fSandi    }
912bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
913f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
9146b13307fSandi
915faecdfdfSAndreas Gohr    // print it
916faecdfdfSAndreas Gohr    if($INFO['exists']) {
9174b0d3916SAndreas Gohr        $out = '';
9184b0d3916SAndreas Gohr        $out .= $fn;
919e260f93bSAnika Henke        $out .= ' · ';
9204b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
9214b0d3916SAndreas Gohr        $out .= ': ';
9224b0d3916SAndreas Gohr        $out .= $date;
9236b13307fSandi        if($INFO['editor']) {
9244b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
925dc58b6f4SAndy Webber            $out .= editorinfo($INFO['editor']);
9265aa52fafSBen Coburn        } else {
9274b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
9286b13307fSandi        }
9296b13307fSandi        if($INFO['locked']) {
930e260f93bSAnika Henke            $out .= ' · ';
9314b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
9324b0d3916SAndreas Gohr            $out .= ': ';
933dc58b6f4SAndy Webber            $out .= editorinfo($INFO['locked']);
9346b13307fSandi        }
9354b0d3916SAndreas Gohr        if($ret) {
9364b0d3916SAndreas Gohr            return $out;
9374b0d3916SAndreas Gohr        } else {
9384b0d3916SAndreas Gohr            echo $out;
93954e95700STom N Harris            return true;
9406b13307fSandi        }
9414b0d3916SAndreas Gohr    }
94254e95700STom N Harris    return false;
9436b13307fSandi}
9446b13307fSandi
945820fa24bSandi/**
946a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
94787c434ceSAndreas Gohr *
94887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
949a6598f23SBen Coburn * the given ID is used.
95087c434ceSAndreas Gohr *
95187c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
952*ac7a515fSAndreas Gohr * @param string $id page id
953*ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
954*ac7a515fSAndreas Gohr * @return bool|string
95587c434ceSAndreas Gohr */
956a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
95787c434ceSAndreas Gohr    if(is_null($id)) {
95887c434ceSAndreas Gohr        global $ID;
95987c434ceSAndreas Gohr        $id = $ID;
96087c434ceSAndreas Gohr    }
96187c434ceSAndreas Gohr
96287c434ceSAndreas Gohr    $name = $id;
963fe9ec250SChris Smith    if(useHeading('navigation')) {
96487c434ceSAndreas Gohr        $title = p_get_first_heading($id);
96587c434ceSAndreas Gohr        if($title) $name = $title;
96687c434ceSAndreas Gohr    }
967a6598f23SBen Coburn
968a6598f23SBen Coburn    if($ret) {
969a6598f23SBen Coburn        return hsc($name);
970a6598f23SBen Coburn    } else {
97187c434ceSAndreas Gohr        print hsc($name);
97254e95700STom N Harris        return true;
97387c434ceSAndreas Gohr    }
974a6598f23SBen Coburn}
975340756e4Sandi
97655efc227SAndreas Gohr/**
97755efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
97855efc227SAndreas Gohr *
97955efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
98055efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
98155efc227SAndreas Gohr *
98255efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
98355efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
98455efc227SAndreas Gohr * to the names of the latter one)
98555efc227SAndreas Gohr *
9863df72098SAndreas Gohr * Only allowed in: detail.php
98755efc227SAndreas Gohr *
98855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
989*ac7a515fSAndreas Gohr * @param array  $tags tags to try
990*ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found
991*ac7a515fSAndreas Gohr * @param null   $src the image src, uses global $SRC if not given
992*ac7a515fSAndreas Gohr * @return string
99355efc227SAndreas Gohr */
9943df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
99555efc227SAndreas Gohr    // Init Exif Reader
99655efc227SAndreas Gohr    global $SRC;
9973df72098SAndreas Gohr
9983df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
9993df72098SAndreas Gohr
100055efc227SAndreas Gohr    static $meta = null;
10013df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
100255efc227SAndreas Gohr    if($meta === false) return $alt;
100355efc227SAndreas Gohr    $info = $meta->getField($tags);
100455efc227SAndreas Gohr    if($info == false) return $alt;
100555efc227SAndreas Gohr    return $info;
100655efc227SAndreas Gohr}
100755efc227SAndreas Gohr
100855efc227SAndreas Gohr/**
100955efc227SAndreas Gohr * Prints the image with a link to the full sized version
101055efc227SAndreas Gohr *
101155efc227SAndreas Gohr * Only allowed in: detail.php
1012a02d2933SAndreas Gohr *
1013*ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1014a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1015a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1016a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1017a02d2933SAndreas Gohr * @param $params array  - additional image attributes
1018*ac7a515fSAndreas Gohr * @return mixed Result of TPL_IMG_DISPLAY
101955efc227SAndreas Gohr */
1020a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
102155efc227SAndreas Gohr    global $IMG;
1022*ac7a515fSAndreas Gohr    global $INPUT;
102355efc227SAndreas Gohr    $w = tpl_img_getTag('File.Width');
102455efc227SAndreas Gohr    $h = tpl_img_getTag('File.Height');
102555efc227SAndreas Gohr
102655efc227SAndreas Gohr    //resize to given max values
102723a34783SAndreas Gohr    $ratio = 1;
102823a34783SAndreas Gohr    if($w >= $h) {
1029f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
103055efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1031f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
103255efc227SAndreas Gohr            $ratio = $maxheight / $h;
103355efc227SAndreas Gohr        }
103455efc227SAndreas Gohr    } else {
1035f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
103655efc227SAndreas Gohr            $ratio = $maxheight / $h;
1037f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
103855efc227SAndreas Gohr            $ratio = $maxwidth / $w;
103955efc227SAndreas Gohr        }
104055efc227SAndreas Gohr    }
104155efc227SAndreas Gohr    if($ratio) {
104255efc227SAndreas Gohr        $w = floor($ratio * $w);
104355efc227SAndreas Gohr        $h = floor($ratio * $h);
104455efc227SAndreas Gohr    }
104555efc227SAndreas Gohr
10466de3759aSAndreas Gohr    //prepare URLs
1047*ac7a515fSAndreas Gohr    $url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&');
1048*ac7a515fSAndreas Gohr    $src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&');
104955efc227SAndreas Gohr
10502684e50aSAndreas Gohr    //prepare attributes
105155efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1052a02d2933SAndreas Gohr    if(is_null($params)) {
10532684e50aSAndreas Gohr        $p = array();
1054a02d2933SAndreas Gohr    } else {
1055a02d2933SAndreas Gohr        $p = $params;
1056a02d2933SAndreas Gohr    }
10572684e50aSAndreas Gohr    if($w) $p['width'] = $w;
10582684e50aSAndreas Gohr    if($h) $p['height'] = $h;
10592684e50aSAndreas Gohr    $p['class'] = 'img_detail';
10602684e50aSAndreas Gohr    if($alt) {
10612684e50aSAndreas Gohr        $p['alt']   = $alt;
10622684e50aSAndreas Gohr        $p['title'] = $alt;
10632684e50aSAndreas Gohr    } else {
10642684e50aSAndreas Gohr        $p['alt'] = '';
10652684e50aSAndreas Gohr    }
1066a02d2933SAndreas Gohr    $p['src'] = $src;
106755efc227SAndreas Gohr
1068a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1069a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1070a02d2933SAndreas Gohr}
1071a02d2933SAndreas Gohr
1072a02d2933SAndreas Gohr/**
1073a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1074*ac7a515fSAndreas Gohr *
1075*ac7a515fSAndreas Gohr * @param array $data
1076*ac7a515fSAndreas Gohr * @return bool
1077a02d2933SAndreas Gohr */
1078*ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
107959f3611bSAnika Henke    global $lang;
1080a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1081a02d2933SAndreas Gohr
108259f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1083a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1084a02d2933SAndreas Gohr    if($data['url']) print '</a>';
108554e95700STom N Harris    return true;
108655efc227SAndreas Gohr}
108755efc227SAndreas Gohr
10887367b368SAndreas Gohr/**
1089881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
10907367b368SAndreas Gohr *
10917367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
10927367b368SAndreas Gohr * template
1093*ac7a515fSAndreas Gohr *
1094*ac7a515fSAndreas Gohr * @return bool
10957367b368SAndreas Gohr */
10967367b368SAndreas Gohrfunction tpl_indexerWebBug() {
10977367b368SAndreas Gohr    global $ID;
10981dad36f5SAndreas Gohr
10997367b368SAndreas Gohr    $p           = array();
1100b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1101e68c51baSAndreas Gohr        '&'.time();
1102881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11037367b368SAndreas Gohr    $p['height'] = 1;
11047367b368SAndreas Gohr    $p['alt']    = '';
11057367b368SAndreas Gohr    $att         = buildAttributes($p);
11067367b368SAndreas Gohr    print "<img $att />";
110754e95700STom N Harris    return true;
11087367b368SAndreas Gohr}
11097367b368SAndreas Gohr
111078d4e784SEsther Brunner/**
111178d4e784SEsther Brunner * tpl_getConf($id)
111278d4e784SEsther Brunner *
111378d4e784SEsther Brunner * use this function to access template configuration variables
1114*ac7a515fSAndreas Gohr *
1115*ac7a515fSAndreas Gohr * @param string $id
1116*ac7a515fSAndreas Gohr * @return string
111778d4e784SEsther Brunner */
111878d4e784SEsther Brunnerfunction tpl_getConf($id) {
111978d4e784SEsther Brunner    global $conf;
112017566ac6SAdrian Lang    static $tpl_configloaded = false;
112178d4e784SEsther Brunner
112278d4e784SEsther Brunner    $tpl = $conf['template'];
112378d4e784SEsther Brunner
112478d4e784SEsther Brunner    if(!$tpl_configloaded) {
112578d4e784SEsther Brunner        $tconf = tpl_loadConfig();
112678d4e784SEsther Brunner        if($tconf !== false) {
112778d4e784SEsther Brunner            foreach($tconf as $key => $value) {
112878d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
112978d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
113078d4e784SEsther Brunner            }
113178d4e784SEsther Brunner            $tpl_configloaded = true;
113278d4e784SEsther Brunner        }
113378d4e784SEsther Brunner    }
113478d4e784SEsther Brunner
113578d4e784SEsther Brunner    return $conf['tpl'][$tpl][$id];
113678d4e784SEsther Brunner}
113778d4e784SEsther Brunner
113878d4e784SEsther Brunner/**
113978d4e784SEsther Brunner * tpl_loadConfig()
1140*ac7a515fSAndreas Gohr *
114178d4e784SEsther Brunner * reads all template configuration variables
114278d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1143*ac7a515fSAndreas Gohr *
1144*ac7a515fSAndreas Gohr * @return array
114578d4e784SEsther Brunner */
114678d4e784SEsther Brunnerfunction tpl_loadConfig() {
114778d4e784SEsther Brunner
1148c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
114978d4e784SEsther Brunner    $conf = array();
115078d4e784SEsther Brunner
115178d4e784SEsther Brunner    if(!@file_exists($file)) return false;
115278d4e784SEsther Brunner
115378d4e784SEsther Brunner    // load default config file
115478d4e784SEsther Brunner    include($file);
115578d4e784SEsther Brunner
115678d4e784SEsther Brunner    return $conf;
115778d4e784SEsther Brunner}
115878d4e784SEsther Brunner
115917566ac6SAdrian Lang// language methods
116017566ac6SAdrian Lang/**
116117566ac6SAdrian Lang * tpl_getLang($id)
116217566ac6SAdrian Lang *
116317566ac6SAdrian Lang * use this function to access template language variables
116417566ac6SAdrian Lang */
116517566ac6SAdrian Langfunction tpl_getLang($id) {
116617566ac6SAdrian Lang    static $lang = array();
116717566ac6SAdrian Lang
116817566ac6SAdrian Lang    if(count($lang) === 0) {
1169c4766956SAndreas Gohr        $path = tpl_incdir().'lang/';
117017566ac6SAdrian Lang
117117566ac6SAdrian Lang        $lang = array();
117217566ac6SAdrian Lang
117317566ac6SAdrian Lang        global $conf; // definitely don't invoke "global $lang"
117417566ac6SAdrian Lang        // don't include once
117517566ac6SAdrian Lang        @include($path.'en/lang.php');
117617566ac6SAdrian Lang        if($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
117717566ac6SAdrian Lang    }
117817566ac6SAdrian Lang
117917566ac6SAdrian Lang    return $lang[$id];
118017566ac6SAdrian Lang}
118117566ac6SAdrian Lang
11823df72098SAndreas Gohr/**
11833df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
11843df72098SAndreas Gohr *
11853df72098SAndreas Gohr * Depending on the user's actions this may be a list of
11863df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
11873df72098SAndreas Gohr * a message of referencing pages
11883df72098SAndreas Gohr *
11893df72098SAndreas Gohr * Only allowed in mediamanager.php
11903df72098SAndreas Gohr *
1191c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1192c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
11933df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11943df72098SAndreas Gohr */
1195c182313eSAndreas Gohrfunction tpl_mediaContent($fromajax = false) {
11963df72098SAndreas Gohr    global $IMG;
11973df72098SAndreas Gohr    global $AUTH;
11983df72098SAndreas Gohr    global $INUSE;
11993df72098SAndreas Gohr    global $NS;
12003df72098SAndreas Gohr    global $JUMPTO;
1201*ac7a515fSAndreas Gohr    global $INPUT;
12023df72098SAndreas Gohr
1203*ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1204c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1205c182313eSAndreas Gohr
1206c182313eSAndreas Gohr    if(!$do) {
1207*ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1208c182313eSAndreas Gohr            $do = 'metaform';
1209c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1210c182313eSAndreas Gohr            $do = 'filesinuse';
1211c182313eSAndreas Gohr        } else {
1212c182313eSAndreas Gohr            $do = 'filelist';
1213c182313eSAndreas Gohr        }
1214c182313eSAndreas Gohr    }
1215c182313eSAndreas Gohr
1216c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1217c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1218c182313eSAndreas Gohr    $data = array('do' => $do);
1219c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1220c182313eSAndreas Gohr    if($evt->advise_before()) {
1221c182313eSAndreas Gohr        $do = $data['do'];
122230fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1223c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1224c182313eSAndreas Gohr        } elseif($do == 'filelist') {
1225c182313eSAndreas Gohr            media_filelist($NS, $AUTH, $JUMPTO);
1226c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1227*ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1228c182313eSAndreas Gohr        } else {
1229c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1230c182313eSAndreas Gohr        }
1231c182313eSAndreas Gohr    }
1232c182313eSAndreas Gohr    $evt->advise_after();
1233c182313eSAndreas Gohr    unset($evt);
1234c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1235c182313eSAndreas Gohr
12363df72098SAndreas Gohr}
12373df72098SAndreas Gohr
12383df72098SAndreas Gohr/**
1239d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1240d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1241d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1242d9162c6cSKate Arzamastseva *
1243d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1244d9162c6cSKate Arzamastseva */
1245035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1246d9162c6cSKate Arzamastseva    global $AUTH;
1247d9162c6cSKate Arzamastseva    global $NS;
1248d9162c6cSKate Arzamastseva    global $JUMPTO;
124995b451bcSAdrian Lang    global $lang;
1250*ac7a515fSAndreas Gohr    global $INPUT;
1251d9162c6cSKate Arzamastseva
1252*ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1253e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1254*ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1255d9162c6cSKate Arzamastseva
125694add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
125795b451bcSAdrian Lang
1258ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
125923846a98SKate Arzamastseva
126094add303SAnika Henke    echo '<div class="panelHeader">'.NL;
126195b451bcSAdrian Lang    echo '<h3>';
1262026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1263c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
126494add303SAnika Henke    echo '</h3>'.NL;
126595b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
126695b451bcSAdrian Lang        media_tab_files_options();
126723846a98SKate Arzamastseva    }
126894add303SAnika Henke    echo '</div>'.NL;
1269d9162c6cSKate Arzamastseva
127094add303SAnika Henke    echo '<div class="panelContent">'.NL;
127195b451bcSAdrian Lang    if($opened_tab == 'files') {
127295b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
127395b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
127495b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
127595b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
127695b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
127795b451bcSAdrian Lang    }
127894add303SAnika Henke    echo '</div>'.NL;
1279d9162c6cSKate Arzamastseva}
1280d9162c6cSKate Arzamastseva
1281d9162c6cSKate Arzamastseva/**
1282d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1283d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1284d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1285d9162c6cSKate Arzamastseva * list of file revisions
1286d9162c6cSKate Arzamastseva *
1287d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1288d9162c6cSKate Arzamastseva */
1289035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1290*ac7a515fSAndreas Gohr    global $AUTH, $NS, $conf, $DEL, $lang, $INPUT;
1291d9162c6cSKate Arzamastseva
129292cac9a9SKate Arzamastseva    $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1293*ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
12946dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1295*ac7a515fSAndreas Gohr    if(isset($NS) && getNS($image) != $NS) return;
1296*ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
12971eeeced2SKate Arzamastseva
1298*ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1299e5d185e1SKate Arzamastseva
1300e5d185e1SKate Arzamastseva    $tab_array = array('view');
1301*ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1302e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1303e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1304e5d185e1SKate Arzamastseva    }
1305e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1306e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1307e5d185e1SKate Arzamastseva    }
1308e5d185e1SKate Arzamastseva
1309e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1310*ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
131123846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1312d9162c6cSKate Arzamastseva
1313ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
131423846a98SKate Arzamastseva
131559f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1316*ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
131795b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
131895b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
131900c2d4a9SAnika Henke    $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
132008317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
132108317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
132208317413SAdrian Lang    } else {
1323026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
132408317413SAdrian Lang    }
1325b8a84c03SAndreas Gohr
132694add303SAnika Henke    echo '</h3></div>'.NL;
132795b451bcSAdrian Lang
132894add303SAnika Henke    echo '<div class="panelContent">'.NL;
132995b451bcSAdrian Lang
133023846a98SKate Arzamastseva    if($opened_tab == 'view') {
133123846a98SKate Arzamastseva        media_tab_view($image, $NS, $AUTH, $rev);
133223846a98SKate Arzamastseva
133392cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
133423846a98SKate Arzamastseva        media_tab_edit($image, $NS, $AUTH);
133523846a98SKate Arzamastseva
1336e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
133710799f9cSKate Arzamastseva        media_tab_history($image, $NS, $AUTH);
133823846a98SKate Arzamastseva    }
133995b451bcSAdrian Lang
134094add303SAnika Henke    echo '</div>'.NL;
1341d9162c6cSKate Arzamastseva}
1342d9162c6cSKate Arzamastseva
1343d9162c6cSKate Arzamastseva/**
13443df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
13453df72098SAndreas Gohr *
13463df72098SAndreas Gohr * Only allowed in mediamanager.php
13473df72098SAndreas Gohr *
13483df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13493df72098SAndreas Gohr */
1350fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
13513df72098SAndreas Gohr    global $NS;
135223846a98SKate Arzamastseva    ptln('<div id="media__tree">');
13533df72098SAndreas Gohr    media_nstree($NS);
13543df72098SAndreas Gohr    ptln('</div>');
13553df72098SAndreas Gohr}
13563df72098SAndreas Gohr
1357a00de5b5SAndreas Gohr/**
1358a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1359a00de5b5SAndreas Gohr *
1360a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1361a00de5b5SAndreas Gohr *
1362a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1363a00de5b5SAndreas Gohr */
1364a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1365a00de5b5SAndreas Gohr    global $ID;
1366a00de5b5SAndreas Gohr    global $REV;
1367a00de5b5SAndreas Gohr    global $lang;
1368a00de5b5SAndreas Gohr
1369de3eb1d7SAdrian Lang    echo '<form action="'.DOKU_SCRIPT.'" method="post" accept-charset="utf-8">';
13703b9a3b55SAnika Henke    echo '<div class="no">';
1371a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1372a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1373a00de5b5SAndreas Gohr    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1374a00de5b5SAndreas Gohr
13755f17c394SAnika Henke    echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">';
1376a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1377a00de5b5SAndreas Gohr
137861917024SAnika Henke    echo '<optgroup label="'.$lang['page_tools'].'">';
1379396c218fSAndreas Gohr    $act = tpl_get_action('edit');
1380396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1381a00de5b5SAndreas Gohr
1382396c218fSAndreas Gohr    $act = tpl_get_action('revert');
1383396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1384396c218fSAndreas Gohr
13853b9a3b55SAnika Henke    $act = tpl_get_action('revisions');
13863b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
13873b9a3b55SAnika Henke
1388396c218fSAndreas Gohr    $act = tpl_get_action('backlink');
1389396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
13903b9a3b55SAnika Henke
13913b9a3b55SAnika Henke    $act = tpl_get_action('subscribe');
13923b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1393a00de5b5SAndreas Gohr    echo '</optgroup>';
1394a00de5b5SAndreas Gohr
139561917024SAnika Henke    echo '<optgroup label="'.$lang['site_tools'].'">';
1396396c218fSAndreas Gohr    $act = tpl_get_action('recent');
1397396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1398396c218fSAndreas Gohr
13993b9a3b55SAnika Henke    $act = tpl_get_action('media');
14003b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
14013b9a3b55SAnika Henke
1402396c218fSAndreas Gohr    $act = tpl_get_action('index');
1403396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1404a00de5b5SAndreas Gohr    echo '</optgroup>';
1405a00de5b5SAndreas Gohr
140661917024SAnika Henke    echo '<optgroup label="'.$lang['user_tools'].'">';
1407396c218fSAndreas Gohr    $act = tpl_get_action('login');
1408396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1409a00de5b5SAndreas Gohr
14103b9a3b55SAnika Henke    $act = tpl_get_action('register');
1411396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1412a00de5b5SAndreas Gohr
14133b9a3b55SAnika Henke    $act = tpl_get_action('profile');
1414396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1415a00de5b5SAndreas Gohr
1416396c218fSAndreas Gohr    $act = tpl_get_action('admin');
1417396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1418a00de5b5SAndreas Gohr    echo '</optgroup>';
1419a00de5b5SAndreas Gohr
1420a00de5b5SAndreas Gohr    echo '</select>';
1421f22c1964SAndreas Gohr    echo '<input type="submit" value="'.$button.'" />';
14223b9a3b55SAnika Henke    echo '</div>';
1423a00de5b5SAndreas Gohr    echo '</form>';
1424a00de5b5SAndreas Gohr}
1425a00de5b5SAndreas Gohr
1426066fee30SAndreas Gohr/**
1427066fee30SAndreas Gohr * Print a informational line about the used license
1428066fee30SAndreas Gohr *
1429066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1430*ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1431*ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1432*ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1433*ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1434*ac7a515fSAndreas Gohr * @return string
1435066fee30SAndreas Gohr */
143680083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1437066fee30SAndreas Gohr    global $license;
1438066fee30SAndreas Gohr    global $conf;
1439066fee30SAndreas Gohr    global $lang;
1440066fee30SAndreas Gohr    if(!$conf['license']) return '';
1441066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1442066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
144353e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1444066fee30SAndreas Gohr
144580083a41SAndreas Gohr    $out = '';
144680083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1447066fee30SAndreas Gohr    if($img) {
1448066fee30SAndreas Gohr        $src = license_img($img);
1449066fee30SAndreas Gohr        if($src) {
145053e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
145153e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
145253e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1453066fee30SAndreas Gohr        }
1454066fee30SAndreas Gohr    }
14554cefd216SMichael Klier    if(!$imgonly) {
145653e15c8bSAnika Henke        $out .= $lang['license'].' ';
145753e15c8bSAnika Henke        $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1458066fee30SAndreas Gohr        $out .= '>'.$lic['name'].'</a>';
14594cefd216SMichael Klier    }
146080083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1461066fee30SAndreas Gohr
1462066fee30SAndreas Gohr    if($return) return $out;
1463066fee30SAndreas Gohr    echo $out;
1464*ac7a515fSAndreas Gohr    return '';
1465066fee30SAndreas Gohr}
1466066fee30SAndreas Gohr
1467a81910eeSAndreas Gohr/**
1468a81910eeSAndreas Gohr * Includes the rendered XHTML of a given page
1469a81910eeSAndreas Gohr *
1470a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1471a81910eeSAndreas Gohr * template
1472a81910eeSAndreas Gohr */
1473a81910eeSAndreas Gohrfunction tpl_include_page($pageid, $print = true) {
1474a81910eeSAndreas Gohr    global $ID;
14759a2e250aSAndreas Gohr    global $TOC;
1476a81910eeSAndreas Gohr    $oldid  = $ID;
14779a2e250aSAndreas Gohr    $oldtoc = $TOC;
1478a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
1479a81910eeSAndreas Gohr    $ID     = $oldid;
14809a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1481a81910eeSAndreas Gohr
1482a81910eeSAndreas Gohr    if(!$print) return $html;
1483a81910eeSAndreas Gohr    echo $html;
1484e66d3e6dSAndreas Gohr    return $html;
1485e66d3e6dSAndreas Gohr}
1486e66d3e6dSAndreas Gohr
1487e66d3e6dSAndreas Gohr/**
1488e66d3e6dSAndreas Gohr * Include the sidebar, will check current namespaces first
1489e66d3e6dSAndreas Gohr */
1490e66d3e6dSAndreas Gohrfunction tpl_sidebar($print = true) {
1491e66d3e6dSAndreas Gohr    global $conf;
1492e66d3e6dSAndreas Gohr
1493e66d3e6dSAndreas Gohr    $sidebar = page_findnearest($conf['sidebar']);
1494e66d3e6dSAndreas Gohr    if($sidebar) return tpl_include_page($sidebar, $print);
1495e66d3e6dSAndreas Gohr    return '';
1496a81910eeSAndreas Gohr}
1497a81910eeSAndreas Gohr
14985b75cd1fSAdrian Lang/**
14995b75cd1fSAdrian Lang * Display the subscribe form
15005b75cd1fSAdrian Lang *
15015b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15025b75cd1fSAdrian Lang */
15035b75cd1fSAdrian Langfunction tpl_subscribe() {
15045b75cd1fSAdrian Lang    global $INFO;
15055b75cd1fSAdrian Lang    global $ID;
15065b75cd1fSAdrian Lang    global $lang;
15076b8f02cfSAdrian Lang    global $conf;
150840c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15095b75cd1fSAdrian Lang
15105b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15115b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
151215741132SAndreas Gohr    echo '<div class="level2">';
15135b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
15145b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
15155b75cd1fSAdrian Lang    } else {
15165b75cd1fSAdrian Lang        echo '<ul>';
15175b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1518056c2049SAndreas Gohr            echo '<li><div class="li">';
15195b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1520056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
15215b75cd1fSAdrian Lang            } else {
1522056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
15235b75cd1fSAdrian Lang            }
152440c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
152515741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1526056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
152715741132SAndreas Gohr
1528*ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1529*ac7a515fSAndreas Gohr                $ID,
1530*ac7a515fSAndreas Gohr                array(
1531*ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
153266d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
153366d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
153466d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1535*ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1536*ac7a515fSAndreas Gohr                )
1537*ac7a515fSAndreas Gohr            ).
153866d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
153966d2bed9SAdrian Lang                '</a></div></li>';
15405b75cd1fSAdrian Lang        }
15415b75cd1fSAdrian Lang        echo '</ul>';
15425b75cd1fSAdrian Lang    }
154315741132SAndreas Gohr    echo '</div>';
15445b75cd1fSAdrian Lang
154515741132SAndreas Gohr    // Add new subscription form
15465b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
154715741132SAndreas Gohr    echo '<div class="level2">';
15485b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
154915741132SAndreas Gohr    $targets = array(
155015741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
155115741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
155215741132SAndreas Gohr    );
155315741132SAndreas Gohr    $styles  = array(
155415741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
15556b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
15566b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
155715741132SAndreas Gohr    );
155815741132SAndreas Gohr
1559056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1560056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1561056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1562056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1563056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1564056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1565056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1566056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1567056c2049SAndreas Gohr    $form->endFieldset();
15685b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
15695b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
157015741132SAndreas Gohr    echo '</div>';
15715b75cd1fSAdrian Lang}
15725b75cd1fSAdrian Lang
1573d059ba9bSAndreas Gohr/**
1574d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1575d059ba9bSAndreas Gohr *
1576d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1577d059ba9bSAndreas Gohr *
1578d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1579d059ba9bSAndreas Gohr */
1580d059ba9bSAndreas Gohrfunction tpl_flush() {
1581d059ba9bSAndreas Gohr    ob_flush();
1582d059ba9bSAndreas Gohr    flush();
1583d059ba9bSAndreas Gohr}
1584d059ba9bSAndreas Gohr
1585afca7e7eSAnika Henke/**
1586378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1587afca7e7eSAnika Henke *
1588378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1589378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1590378325f9SAndreas Gohr *
1591378325f9SAndreas Gohr * @param  array $search       locations to look at
1592378325f9SAndreas Gohr * @param  bool  $abs           if to use absolute URL
1593*ac7a515fSAndreas Gohr * @param  array &$imginfo   filled with getimagesize()
1594*ac7a515fSAndreas Gohr * @return string
1595378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1596afca7e7eSAnika Henke */
1597378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1598*ac7a515fSAndreas Gohr    $img     = '';
1599*ac7a515fSAndreas Gohr    $file    = '';
1600*ac7a515fSAndreas Gohr    $ismedia = false;
1601378325f9SAndreas Gohr    // loop through candidates until a match was found:
1602378325f9SAndreas Gohr    foreach($search as $img) {
1603378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1604378325f9SAndreas Gohr            $file    = mediaFN($img);
1605378325f9SAndreas Gohr            $ismedia = true;
1606378325f9SAndreas Gohr        } else {
1607c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1608378325f9SAndreas Gohr            $ismedia = false;
16091f13e33dSAnika Henke        }
16100f747863Slupo49
1611378325f9SAndreas Gohr        if(file_exists($file)) break;
1612872a6d29SAnika Henke    }
1613378325f9SAndreas Gohr
1614378325f9SAndreas Gohr    // fetch image data if requested
1615378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1616378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1617378325f9SAndreas Gohr    }
1618378325f9SAndreas Gohr
1619378325f9SAndreas Gohr    // build URL
1620378325f9SAndreas Gohr    if($ismedia) {
1621378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1622378325f9SAndreas Gohr    } else {
1623c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1624378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1625378325f9SAndreas Gohr    }
1626378325f9SAndreas Gohr
1627378325f9SAndreas Gohr    return $url;
1628a7e5f74cSlupo49}
16291f13e33dSAnika Henke
1630872a6d29SAnika Henke/**
1631e5d4768dSAndreas Gohr * PHP include a file
1632e5d4768dSAndreas Gohr *
1633e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1634e5d4768dSAndreas Gohr * file in the template's root directory.
1635e5d4768dSAndreas Gohr *
1636e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1637e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1638e5d4768dSAndreas Gohr * default.
1639e5d4768dSAndreas Gohr *
1640e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1641e5d4768dSAndreas Gohr * to this function!
1642e5d4768dSAndreas Gohr *
1643e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1644e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1645e5d4768dSAndreas Gohr */
1646e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1647e5d4768dSAndreas Gohr    global $config_cascade;
1648e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1649e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1650e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1651e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1652e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1653f3a1225fSAnika Henke                include("$dir/$file");
1654e5d4768dSAndreas Gohr                return;
1655e5d4768dSAndreas Gohr            }
1656e5d4768dSAndreas Gohr        }
1657e5d4768dSAndreas Gohr    }
1658e5d4768dSAndreas Gohr
1659e5d4768dSAndreas Gohr    // still here? try the template dir
1660e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1661e5d4768dSAndreas Gohr    if(file_exists($file)) {
1662f3a1225fSAnika Henke        include($file);
1663e5d4768dSAndreas Gohr    }
1664e5d4768dSAndreas Gohr}
1665e5d4768dSAndreas Gohr
1666e5d4768dSAndreas Gohr/**
166727833958SAnika Henke * Returns icon from data/media root directory if it exists, otherwise
166827833958SAnika Henke * the one in the template's image directory.
166927833958SAnika Henke *
167027833958SAnika Henke * @deprecated Use tpl_getMediaFile() instead
167127833958SAnika Henke * @author Anika Henke <anika@selfthinker.org>
167227833958SAnika Henke */
167327833958SAnika Henkefunction tpl_getFavicon($abs = false, $fileName = 'favicon.ico') {
1674378325f9SAndreas Gohr    $look = array(":wiki:$fileName", ":$fileName", "images/$fileName");
1675378325f9SAndreas Gohr    return tpl_getMediaFile($look, $abs);
167627833958SAnika Henke}
167727833958SAnika Henke
167827833958SAnika Henke/**
1679872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1680872a6d29SAnika Henke *
1681872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
1682*ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1683*ac7a515fSAndreas Gohr * @return string
1684872a6d29SAnika Henke */
1685872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1686872a6d29SAnika Henke
1687872a6d29SAnika Henke    $return = '';
1688872a6d29SAnika Henke
1689872a6d29SAnika Henke    foreach($types as $type) {
1690872a6d29SAnika Henke        switch($type) {
1691872a6d29SAnika Henke            case 'favicon':
1692378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1693378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1694872a6d29SAnika Henke                break;
1695872a6d29SAnika Henke            case 'mobile':
1696378325f9SAndreas Gohr                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.ico');
1697378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1698872a6d29SAnika Henke                break;
1699872a6d29SAnika Henke            case 'generic':
1700872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1701378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1702378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1703872a6d29SAnika Henke                break;
1704872a6d29SAnika Henke        }
1705872a6d29SAnika Henke    }
1706872a6d29SAnika Henke
1707872a6d29SAnika Henke    return $return;
1708afca7e7eSAnika Henke}
1709afca7e7eSAnika Henke
1710d9162c6cSKate Arzamastseva/**
1711d9162c6cSKate Arzamastseva * Prints full-screen media manager
1712d9162c6cSKate Arzamastseva *
1713d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1714d9162c6cSKate Arzamastseva */
1715d9162c6cSKate Arzamastsevafunction tpl_media() {
1716*ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
171788a71175SKate Arzamastseva    $fullscreen = true;
171895b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1719d9162c6cSKate Arzamastseva
1720*ac7a515fSAndreas Gohr    $rev   = '';
1721*ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
172298f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
172398f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
17249c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
172598f03b57SKate Arzamastseva
172694add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1727bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1728d9162c6cSKate Arzamastseva    html_msgarea();
172994add303SAnika Henke
173094add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
173194add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
173295b451bcSAdrian Lang    echo '<div class="panelHeader">';
1733ba340a70SAnika Henke    echo $lang['media_namespaces'];
173494add303SAnika Henke    echo '</div>'.NL;
173595b451bcSAdrian Lang
173694add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
173795b451bcSAdrian Lang    media_nstree($NS);
173894add303SAnika Henke    echo '</div>'.NL;
173994add303SAnika Henke    echo '</div>'.NL;
1740fa8e5c77SKate Arzamastseva
174194add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1742035e07f1SKate Arzamastseva    tpl_mediaFileList();
174394add303SAnika Henke    echo '</div>'.NL;
1744fa8e5c77SKate Arzamastseva
174594add303SAnika Henke    echo '<div class="panel file">'.NL;
174694add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1747035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
174894add303SAnika Henke    echo '</div>'.NL;
1749ba340a70SAnika Henke
175094add303SAnika Henke    echo '</div>'.NL;
1751d9162c6cSKate Arzamastseva}
1752afca7e7eSAnika Henke
1753e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1754a00de5b5SAndreas Gohr
1755