xref: /dokuwiki/inc/template.php (revision 585bf44e2b756eac2e1cfce7035ef237bc02a788)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki template functions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
106b13307fSandi
116b13307fSandi/**
12ac7a515fSAndreas Gohr * Access a template file
13ac7a515fSAndreas Gohr *
14ac7a515fSAndreas Gohr * Returns the path to the given file inside the current template, uses
15ac7a515fSAndreas Gohr * default template if the custom version doesn't exist.
165a892029SAndreas Gohr *
175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
18ac7a515fSAndreas Gohr * @param string $file
19ac7a515fSAndreas Gohr * @return string
205a892029SAndreas Gohr */
21ac7a515fSAndreas Gohrfunction template($file) {
225a892029SAndreas Gohr    global $conf;
235a892029SAndreas Gohr
24ac7a515fSAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
25ac7a515fSAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
265a892029SAndreas Gohr
27ac7a515fSAndreas Gohr    return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
285a892029SAndreas Gohr}
295a892029SAndreas Gohr
30c4766956SAndreas Gohr/**
31c4766956SAndreas Gohr * Convenience function to access template dir from local FS
32c4766956SAndreas Gohr *
33c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPLINC constant
34c4766956SAndreas Gohr *
35c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
36afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
37ac7a515fSAndreas Gohr * @return string
38c4766956SAndreas Gohr */
39afb2c082SAndreas Gohrfunction tpl_incdir($tpl='') {
4075b14482SAndreas Gohr    global $conf;
41afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
42afb2c082SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$tpl.'/';
43c4766956SAndreas Gohr}
44c4766956SAndreas Gohr
45c4766956SAndreas Gohr/**
46c4766956SAndreas Gohr * Convenience function to access template dir from web
47c4766956SAndreas Gohr *
48c4766956SAndreas Gohr * This replaces the deprecated DOKU_TPL constant
49c4766956SAndreas Gohr *
50c4766956SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
51afb2c082SAndreas Gohr * @param string $tpl The template to use, default to current one
52ac7a515fSAndreas Gohr * @return string
53c4766956SAndreas Gohr */
5499dca513SAndreas Gohrfunction tpl_basedir($tpl='') {
5575b14482SAndreas Gohr    global $conf;
56afb2c082SAndreas Gohr    if(!$tpl) $tpl = $conf['template'];
57dcd4911eSMichael Hamann    return DOKU_BASE.'lib/tpl/'.$tpl.'/';
58c4766956SAndreas Gohr}
59c4766956SAndreas Gohr
605a892029SAndreas Gohr/**
616b13307fSandi * Print the content
626b13307fSandi *
636b13307fSandi * This function is used for printing all the usual content
646b13307fSandi * (defined by the global $ACT var) by calling the appropriate
656b13307fSandi * outputfunction(s) from html.php
666b13307fSandi *
67ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
68ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
696b13307fSandi *
706b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
71ac7a515fSAndreas Gohr * @triggers TPL_ACT_RENDER
72ac7a515fSAndreas Gohr * @triggers TPL_CONTENT_DISPLAY
73ac7a515fSAndreas Gohr * @param bool $prependTOC should the TOC be displayed here?
74ac7a515fSAndreas Gohr * @return bool true if any output
756b13307fSandi */
76b8595a66SAndreas Gohrfunction tpl_content($prependTOC = true) {
777ea0913cSchris    global $ACT;
78b8595a66SAndreas Gohr    global $INFO;
79b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
807ea0913cSchris
817ea0913cSchris    ob_start();
82746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
837ea0913cSchris    $html_output = ob_get_clean();
84746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
8554e95700STom N Harris
8654e95700STom N Harris    return !empty($html_output);
877ea0913cSchris}
887ea0913cSchris
89ac7a515fSAndreas Gohr/**
90ac7a515fSAndreas Gohr * Default Action of TPL_ACT_RENDER
91ac7a515fSAndreas Gohr *
92ac7a515fSAndreas Gohr * @return bool
93ac7a515fSAndreas Gohr */
947ea0913cSchrisfunction tpl_content_core() {
956b13307fSandi    global $ACT;
966b13307fSandi    global $TEXT;
976b13307fSandi    global $PRE;
986b13307fSandi    global $SUF;
996b13307fSandi    global $SUM;
1006b13307fSandi    global $IDX;
101ac7a515fSAndreas Gohr    global $INPUT;
1026b13307fSandi
1036b13307fSandi    switch($ACT) {
1046b13307fSandi        case 'show':
1056b13307fSandi            html_show();
1066b13307fSandi            break;
107ac7a515fSAndreas Gohr        /** @noinspection PhpMissingBreakStatementInspection */
10845a99335SAdrian Lang        case 'locked':
10945a99335SAdrian Lang            html_locked();
1106b13307fSandi        case 'edit':
11145a99335SAdrian Lang        case 'recover':
1126b13307fSandi            html_edit();
1136b13307fSandi            break;
11445a99335SAdrian Lang        case 'preview':
11545a99335SAdrian Lang            html_edit();
11645a99335SAdrian Lang            html_show($TEXT);
11745a99335SAdrian Lang            break;
118ee4c4a1bSAndreas Gohr        case 'draft':
119ee4c4a1bSAndreas Gohr            html_draft();
120ee4c4a1bSAndreas Gohr            break;
1216b13307fSandi        case 'search':
1226b13307fSandi            html_search();
1236b13307fSandi            break;
1246b13307fSandi        case 'revisions':
125ac7a515fSAndreas Gohr            html_revisions($INPUT->int('first'));
1266b13307fSandi            break;
1276b13307fSandi        case 'diff':
1286b13307fSandi            html_diff();
1296b13307fSandi            break;
1306b13307fSandi        case 'recent':
1313c94d07bSAnika Henke            $show_changes = $INPUT->str('show_changes');
1323c94d07bSAnika Henke            if (empty($show_changes)) {
1333c94d07bSAnika Henke                $show_changes = get_doku_pref('show_changes', $show_changes);
1343c94d07bSAnika Henke            }
1353c94d07bSAnika Henke            html_recent($INPUT->extract('first')->int('first'), $show_changes);
1366b13307fSandi            break;
1376b13307fSandi        case 'index':
1386b13307fSandi            html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
1396b13307fSandi            break;
1406b13307fSandi        case 'backlink':
1416b13307fSandi            html_backlinks();
1426b13307fSandi            break;
1436b13307fSandi        case 'conflict':
1446b13307fSandi            html_conflict(con($PRE, $TEXT, $SUF), $SUM);
1456b13307fSandi            html_diff(con($PRE, $TEXT, $SUF), false);
1466b13307fSandi            break;
1476b13307fSandi        case 'login':
1486b13307fSandi            html_login();
1496b13307fSandi            break;
1506b13307fSandi        case 'register':
1516b13307fSandi            html_register();
1526b13307fSandi            break;
1538b06d178Schris        case 'resendpwd':
1548b06d178Schris            html_resendpwd();
1558b06d178Schris            break;
156820fa24bSandi        case 'denied':
1575e991bd8Sandi            print p_locale_xhtml('denied');
158820fa24bSandi            break;
1598b06d178Schris        case 'profile' :
1608b06d178Schris            html_updateprofile();
1618b06d178Schris            break;
162c19fe9c0Sandi        case 'admin':
163c19fe9c0Sandi            tpl_admin();
164c19fe9c0Sandi            break;
1655b75cd1fSAdrian Lang        case 'subscribe':
1665b75cd1fSAdrian Lang            tpl_subscribe();
1675b75cd1fSAdrian Lang            break;
168d9162c6cSKate Arzamastseva        case 'media':
169d9162c6cSKate Arzamastseva            tpl_media();
170d9162c6cSKate Arzamastseva            break;
1716b13307fSandi        default:
17224bb549bSchris            $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT);
17324bb549bSchris            if($evt->advise_before())
174ea67f144Sandi                msg("Failed to handle command: ".hsc($ACT), -1);
17524bb549bSchris            $evt->advise_after();
17624bb549bSchris            unset($evt);
17754e95700STom N Harris            return false;
1786b13307fSandi    }
17954e95700STom N Harris    return true;
1806b13307fSandi}
1816b13307fSandi
182c19fe9c0Sandi/**
183b8595a66SAndreas Gohr * Places the TOC where the function is called
184b8595a66SAndreas Gohr *
185b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
186b8595a66SAndreas Gohr * a false argument
187b8595a66SAndreas Gohr *
188b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
189ac7a515fSAndreas Gohr * @param bool $return Should the TOC be returned instead to be printed?
190ac7a515fSAndreas Gohr * @return string
191b8595a66SAndreas Gohr */
192b8595a66SAndreas Gohrfunction tpl_toc($return = false) {
193b8595a66SAndreas Gohr    global $TOC;
194b8595a66SAndreas Gohr    global $ACT;
195b8595a66SAndreas Gohr    global $ID;
196b8595a66SAndreas Gohr    global $REV;
197b8595a66SAndreas Gohr    global $INFO;
198851f2e89SAnika Henke    global $conf;
199ac7a515fSAndreas Gohr    global $INPUT;
200b8595a66SAndreas Gohr    $toc = array();
201b8595a66SAndreas Gohr
202b8595a66SAndreas Gohr    if(is_array($TOC)) {
203b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
204b8595a66SAndreas Gohr        $toc = $TOC;
2053c86d7c9SAndreas Gohr    } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
206b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
20765aa8490SMichael Hamann        $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE);
208b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])) {
209b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
210b8595a66SAndreas Gohr        } else {
2112bb0d541Schris            $tocok = true;
212b8595a66SAndreas Gohr        }
213f87b5dbbSChristopher Smith        $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
214851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
215b8595a66SAndreas Gohr            $toc = array();
216b8595a66SAndreas Gohr        }
217b8595a66SAndreas Gohr    } elseif($ACT == 'admin') {
218b8595a66SAndreas Gohr        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
219b8595a66SAndreas Gohr        $plugin = null;
220ac7a515fSAndreas Gohr        $class  = $INPUT->str('page');
221ac7a515fSAndreas Gohr        if(!empty($class)) {
222b8595a66SAndreas Gohr            $pluginlist = plugin_list('admin');
223ac7a515fSAndreas Gohr            if(in_array($class, $pluginlist)) {
224b8595a66SAndreas Gohr                // attempt to load the plugin
225ac7a515fSAndreas Gohr                /** @var $plugin DokuWiki_Admin_Plugin */
226a04f2bd5SGerrit Uitslag                $plugin = plugin_load('admin', $class);
227b8595a66SAndreas Gohr            }
228b8595a66SAndreas Gohr        }
229ac7a515fSAndreas Gohr        if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) {
230b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
231b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
232b8595a66SAndreas Gohr        }
233b8595a66SAndreas Gohr    }
234b8595a66SAndreas Gohr
2350b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
236b8595a66SAndreas Gohr    $html = html_TOC($toc);
237b8595a66SAndreas Gohr    if($return) return $html;
238b8595a66SAndreas Gohr    echo $html;
239ac7a515fSAndreas Gohr    return '';
240b8595a66SAndreas Gohr}
241b8595a66SAndreas Gohr
242b8595a66SAndreas Gohr/**
243c19fe9c0Sandi * Handle the admin page contents
244c19fe9c0Sandi *
245c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
246c19fe9c0Sandi */
247c19fe9c0Sandifunction tpl_admin() {
248f8cc712eSAndreas Gohr    global $INFO;
249b8595a66SAndreas Gohr    global $TOC;
250ac7a515fSAndreas Gohr    global $INPUT;
25111e2ce22Schris
252b8595a66SAndreas Gohr    $plugin = null;
253ac7a515fSAndreas Gohr    $class  = $INPUT->str('page');
254ac7a515fSAndreas Gohr    if(!empty($class)) {
25511e2ce22Schris        $pluginlist = plugin_list('admin');
25611e2ce22Schris
257ac7a515fSAndreas Gohr        if(in_array($class, $pluginlist)) {
25811e2ce22Schris            // attempt to load the plugin
259ac7a515fSAndreas Gohr            /** @var $plugin DokuWiki_Admin_Plugin */
260a04f2bd5SGerrit Uitslag            $plugin = plugin_load('admin', $class);
26111e2ce22Schris        }
26211e2ce22Schris    }
26311e2ce22Schris
264b8595a66SAndreas Gohr    if($plugin !== null) {
265b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
266b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
267f8cc712eSAndreas Gohr        $plugin->html();
268f8cc712eSAndreas Gohr    } else {
269f8cc712eSAndreas Gohr        html_admin();
270f8cc712eSAndreas Gohr    }
27154e95700STom N Harris    return true;
272c19fe9c0Sandi}
2736b13307fSandi
2746b13307fSandi/**
2756b13307fSandi * Print the correct HTML meta headers
2766b13307fSandi *
2776b13307fSandi * This has to go into the head section of your template.
2786b13307fSandi *
2796b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
280ac7a515fSAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
281ac7a515fSAndreas Gohr * @param  bool $alt Should feeds and alternative format links be added?
282ac7a515fSAndreas Gohr * @return bool
2836b13307fSandi */
284f96fa415SAndreas Gohrfunction tpl_metaheaders($alt = true) {
2856b13307fSandi    global $ID;
286d98d4540SBen Coburn    global $REV;
2876b13307fSandi    global $INFO;
28872e0dc37SAndreas Gohr    global $JSINFO;
2896b13307fSandi    global $ACT;
2904bb1b5aeSAndreas Gohr    global $QUERY;
2916b13307fSandi    global $lang;
292dc57ef04Sandi    global $conf;
2939c438d6cSMichael Hamann    global $updateVersion;
294*585bf44eSChristopher Smith    /** @var Input $INPUT */
295*585bf44eSChristopher Smith    global $INPUT;
2966b13307fSandi
2977bff22c0SAndreas Gohr    // prepare the head array
2987bff22c0SAndreas Gohr    $head = array();
2997bff22c0SAndreas Gohr
300202ac28bSMichael Klier    // prepare seed for js and css
301cd997f93SAndreas Gohr    $tseed   = $updateVersion;
302202ac28bSMichael Klier    $depends = getConfigFiles('main');
303cd997f93SAndreas Gohr    foreach($depends as $f) $tseed .= @filemtime($f);
304cd997f93SAndreas Gohr    $tseed   = md5($tseed);
3057bff22c0SAndreas Gohr
3066b13307fSandi    // the usual stuff
3073f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
308ac7a515fSAndreas Gohr    $head['link'][] = array(
309ac7a515fSAndreas Gohr        'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
310ac7a515fSAndreas Gohr        'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
311ac7a515fSAndreas Gohr    );
312f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
3137aedde2eSGina Haeussge    if(actionOK('index')) {
314ac7a515fSAndreas Gohr        $head['link'][] = array(
315ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
316ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
317ac7a515fSAndreas Gohr        );
3187aedde2eSGina Haeussge    }
319f96fa415SAndreas Gohr
320f96fa415SAndreas Gohr    if($alt) {
321ac7a515fSAndreas Gohr        $head['link'][] = array(
322ac7a515fSAndreas Gohr            'rel'  => 'alternate', 'type'=> 'application/rss+xml',
323a1288caeSGerrit Uitslag            'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
324ac7a515fSAndreas Gohr        );
325ac7a515fSAndreas Gohr        $head['link'][] = array(
326ac7a515fSAndreas Gohr            'rel'  => 'alternate', 'type'=> 'application/rss+xml',
327a1288caeSGerrit Uitslag            'title'=> $lang['currentns'],
328ac7a515fSAndreas Gohr            'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
329ac7a515fSAndreas Gohr        );
330c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
331ac7a515fSAndreas Gohr            $head['link'][] = array(
332ac7a515fSAndreas Gohr                'rel'  => 'edit',
333715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
334ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
335ac7a515fSAndreas Gohr            );
336c35f3875SAndreas Gohr        }
337c35f3875SAndreas Gohr
3384bb1b5aeSAndreas Gohr        if($ACT == 'search') {
339ac7a515fSAndreas Gohr            $head['link'][] = array(
340ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
341a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
342ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
343ac7a515fSAndreas Gohr            );
3444bb1b5aeSAndreas Gohr        }
345bae36d94SAndreas Gohr
346bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
347ac7a515fSAndreas Gohr            $head['link'][] = array(
348a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
349ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
350ac7a515fSAndreas Gohr            );
351bae36d94SAndreas Gohr        }
352bae36d94SAndreas Gohr
353bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
354ac7a515fSAndreas Gohr            $head['link'][] = array(
355a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
356ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
357ac7a515fSAndreas Gohr            );
358f96fa415SAndreas Gohr        }
359bae36d94SAndreas Gohr    }
3606b13307fSandi
3616b13307fSandi    // setup robot tags apropriate for different modes
3624f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3636b13307fSandi        if($INFO['exists']) {
3646b13307fSandi            //delay indexing:
3656b13307fSandi            if((time() - $INFO['lastmod']) >= $conf['indexdelay']) {
3667bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3676b13307fSandi            } else {
3687bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3696b13307fSandi            }
37069db0cafSAndreas Gohr            $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&'));
3716b13307fSandi        } else {
3727bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3736b13307fSandi        }
3747a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3757bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3766b13307fSandi    } else {
3777bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3786b13307fSandi    }
3796b13307fSandi
380831800b8SAndreas Gohr    // set metadata
381831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
382831800b8SAndreas Gohr        // date of modification
383831800b8SAndreas Gohr        if($REV) {
3847bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV));
385831800b8SAndreas Gohr        } else {
3867bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod']));
387831800b8SAndreas Gohr        }
388831800b8SAndreas Gohr
389831800b8SAndreas Gohr        // keywords (explicit or implicit)
390bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3917bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
392831800b8SAndreas Gohr        } else {
3937bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
394831800b8SAndreas Gohr        }
395831800b8SAndreas Gohr    }
396831800b8SAndreas Gohr
39778a6aeb1SAndreas Gohr    // load stylesheets
398ac7a515fSAndreas Gohr    $head['link'][] = array(
399ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
400ac7a515fSAndreas Gohr        'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed
401ac7a515fSAndreas Gohr    );
402bad31ae9SAndreas Gohr
4038bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
404463d4a65SAndreas Gohr    $json   = new JSON();
40572e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
406*585bf44eSChristopher Smith    if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
40772e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
408c591aabeSAndreas Gohr    }
40972e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
41085f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
4118bbcb611SAndreas Gohr
4128bbcb611SAndreas Gohr    // load external javascript
413ac7a515fSAndreas Gohr    $head['script'][] = array(
414ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
415ac7a515fSAndreas Gohr        'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed
416ac7a515fSAndreas Gohr    );
4177bff22c0SAndreas Gohr
4187bff22c0SAndreas Gohr    // trigger event here
419016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
42054e95700STom N Harris    return true;
4217bff22c0SAndreas Gohr}
4227bff22c0SAndreas Gohr
4237bff22c0SAndreas Gohr/**
4247bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
4257bff22c0SAndreas Gohr *
4267bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
4277bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
4287bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
4297bff22c0SAndreas Gohr *
4307bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
4311304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
4327bff22c0SAndreas Gohr *
4337bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
4347bff22c0SAndreas Gohr */
4357bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
4367bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
4377bff22c0SAndreas Gohr        foreach($inst as $attr) {
4387bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
43926afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
440e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
44109f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
442e226efe1SAndreas Gohr                        $attr['_data'].
44309f791c4SDominik Eckelmann                        "\n/*!]]>*/";
444e226efe1SAndreas Gohr
4451304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
4467bff22c0SAndreas Gohr            } else {
4477bff22c0SAndreas Gohr                echo '/>';
4487bff22c0SAndreas Gohr            }
4497bff22c0SAndreas Gohr            echo "\n";
4507bff22c0SAndreas Gohr        }
4517bff22c0SAndreas Gohr    }
4526b13307fSandi}
4536b13307fSandi
4546b13307fSandi/**
4556b13307fSandi * Print a link
4566b13307fSandi *
4575e163278SAndreas Gohr * Just builds a link.
4586b13307fSandi *
4596b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4606b13307fSandi */
4611af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
46201f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4631af98a77SAnika Henke    if($more) $out .= ' '.$more;
4641af98a77SAnika Henke    $out .= ">$name</a>";
4651af98a77SAnika Henke    if($return) return $out;
4661af98a77SAnika Henke    print $out;
46754e95700STom N Harris    return true;
4686b13307fSandi}
4696b13307fSandi
4706b13307fSandi/**
47155efc227SAndreas Gohr * Prints a link to a WikiPage
47255efc227SAndreas Gohr *
47355efc227SAndreas Gohr * Wrapper around html_wikilink
47455efc227SAndreas Gohr *
47555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
47655efc227SAndreas Gohr */
4770b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) {
478d317fb5dSAnika Henke    print '<bdi>'.html_wikilink($id, $name).'</bdi>';
47954e95700STom N Harris    return true;
48055efc227SAndreas Gohr}
48155efc227SAndreas Gohr
48255efc227SAndreas Gohr/**
483a3ec5f4aSmatthiasgrimm * get the parent page
484a3ec5f4aSmatthiasgrimm *
485a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
486a3ec5f4aSmatthiasgrimm * returns false if none is available
487a3ec5f4aSmatthiasgrimm *
488377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
489a3ec5f4aSmatthiasgrimm */
490377f9e97SAndreas Gohrfunction tpl_getparent($id) {
491377f9e97SAndreas Gohr    $parent = getNS($id).':';
492377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
493a197105eSmatthiasgrimm    if($parent == $id) {
494a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
495a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
496a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
497377f9e97SAndreas Gohr        if($parent == $id) return false;
498a197105eSmatthiasgrimm    }
499377f9e97SAndreas Gohr    return $parent;
500a3ec5f4aSmatthiasgrimm}
501a3ec5f4aSmatthiasgrimm
502a3ec5f4aSmatthiasgrimm/**
5036b13307fSandi * Print one of the buttons
5046b13307fSandi *
505a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
506a453d131SAdrian Lang * @see    tpl_get_action
5076b13307fSandi */
5081af98a77SAnika Henkefunction tpl_button($type, $return = false) {
509a453d131SAdrian Lang    $data = tpl_get_action($type);
510a453d131SAdrian Lang    if($data === false) {
511a453d131SAdrian Lang        return false;
512a453d131SAdrian Lang    } elseif(!is_array($data)) {
513a453d131SAdrian Lang        $out = sprintf($data, 'button');
514409d7af7SAndreas Gohr    } else {
515ac7a515fSAndreas Gohr        /**
516ac7a515fSAndreas Gohr         * @var string $accesskey
517ac7a515fSAndreas Gohr         * @var string $id
518ac7a515fSAndreas Gohr         * @var string $method
519ac7a515fSAndreas Gohr         * @var array  $params
520ac7a515fSAndreas Gohr         */
521a453d131SAdrian Lang        extract($data);
522a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
523a453d131SAdrian Lang            $out = html_topbtn();
524409d7af7SAndreas Gohr        } else {
525a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
526409d7af7SAndreas Gohr        }
527409d7af7SAndreas Gohr    }
5281af98a77SAnika Henke    if($return) return $out;
529a453d131SAdrian Lang    echo $out;
530a453d131SAdrian Lang    return true;
5316b13307fSandi}
5326b13307fSandi
5336b13307fSandi/**
534ed630903Sandi * Like the action buttons but links
535ed630903Sandi *
536a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
537a453d131SAdrian Lang * @see    tpl_get_action
538a453d131SAdrian Lang */
539a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
540a453d131SAdrian Lang    global $lang;
541a453d131SAdrian Lang    $data = tpl_get_action($type);
542a453d131SAdrian Lang    if($data === false) {
543a453d131SAdrian Lang        return false;
544a453d131SAdrian Lang    } elseif(!is_array($data)) {
545a453d131SAdrian Lang        $out = sprintf($data, 'link');
546a453d131SAdrian Lang    } else {
547ac7a515fSAndreas Gohr        /**
548ac7a515fSAndreas Gohr         * @var string $accesskey
549ac7a515fSAndreas Gohr         * @var string $id
550ac7a515fSAndreas Gohr         * @var string $method
551b1af9014SChristopher Smith         * @var bool   $nofollow
552ac7a515fSAndreas Gohr         * @var array  $params
553ac7a515fSAndreas Gohr         */
554a453d131SAdrian Lang        extract($data);
555a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
556a453d131SAdrian Lang            $linktarget = $id;
557a453d131SAdrian Lang        } else {
558a453d131SAdrian Lang            $linktarget = wl($id, $params);
559a453d131SAdrian Lang        }
560a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
561c7e90e3fSAnika Henke        $akey    = $addTitle = '';
562c7e90e3fSAnika Henke        if($accesskey) {
563c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
564c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
565c7e90e3fSAnika Henke        }
566b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
567ac7a515fSAndreas Gohr        $out = tpl_link(
568ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
569a453d131SAdrian Lang            'class="action '.$type.'" '.
570b1af9014SChristopher Smith                $akey.$rel.
571ac7a515fSAndreas Gohr                'title="'.hsc($caption).$addTitle.'"', 1
572ac7a515fSAndreas Gohr        );
573a453d131SAdrian Lang    }
574a453d131SAdrian Lang    if($return) return $out;
575a453d131SAdrian Lang    echo $out;
576a453d131SAdrian Lang    return true;
577a453d131SAdrian Lang}
578a453d131SAdrian Lang
579a453d131SAdrian Lang/**
580a453d131SAdrian Lang * Check the actions and get data for buttons and links
581ed630903Sandi *
582a453d131SAdrian Lang * Available actions are
583a453d131SAdrian Lang *
584a453d131SAdrian Lang *  edit        - edit/create/show/draft
585ed630903Sandi *  history     - old revisions
586ed630903Sandi *  recent      - recent changes
587a453d131SAdrian Lang *  login       - login/logout - if ACL enabled
588a453d131SAdrian Lang *  profile     - user profile (if logged in)
589ed630903Sandi *  index       - The index
590ed630903Sandi *  admin       - admin page - if enough rights
591a453d131SAdrian Lang *  top         - back to top
592a453d131SAdrian Lang *  back        - back to parent - if available
593bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
594a453d131SAdrian Lang *  subscribe/subscription- subscribe/unsubscribe
595ed630903Sandi *
596ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
597a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
598a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
599ac7a515fSAndreas Gohr * @param string $type
600ac7a515fSAndreas Gohr * @return array|bool|string
601ed630903Sandi */
602a453d131SAdrian Langfunction tpl_get_action($type) {
603ed630903Sandi    global $ID;
604ed630903Sandi    global $INFO;
605ed630903Sandi    global $REV;
606ed630903Sandi    global $ACT;
607b1af9014SChristopher Smith    global $conf;
608*585bf44eSChristopher Smith    /** @var Input $INPUT */
609*585bf44eSChristopher Smith    global $INPUT;
610ed630903Sandi
61175e487e9SAndreas Gohr    // check disabled actions and fix the badly named ones
612a453d131SAdrian Lang    if($type == 'history') $type = 'revisions';
6134c4b65c8SMichael Hamann    if ($type == 'subscription') $type = 'subscribe';
614a453d131SAdrian Lang    if(!actionOK($type)) return false;
615409d7af7SAndreas Gohr
616a453d131SAdrian Lang    $accesskey = null;
6176709e843SAdrian Lang    $id        = $ID;
618a453d131SAdrian Lang    $method    = 'get';
619a453d131SAdrian Lang    $params    = array('do' => $type);
620b1af9014SChristopher Smith    $nofollow  = true;
621ed630903Sandi    switch($type) {
622ed630903Sandi        case 'edit':
6230b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
624ed630903Sandi            if($ACT == 'show' || $ACT == 'search') {
625a453d131SAdrian Lang                $method = 'post';
626ed630903Sandi                if($INFO['writable']) {
627a453d131SAdrian Lang                    $accesskey = 'e';
628b8a111f5SMichael Klier                    if(!empty($INFO['draft'])) {
6296709e843SAdrian Lang                        $type         = 'draft';
630a453d131SAdrian Lang                        $params['do'] = 'draft';
631b8a111f5SMichael Klier                    } else {
632a453d131SAdrian Lang                        $params['rev'] = $REV;
633a453d131SAdrian Lang                        if(!$INFO['exists']) {
6346709e843SAdrian Lang                            $type = 'create';
635ed630903Sandi                        }
636b8a111f5SMichael Klier                    }
637ed630903Sandi                } else {
638a453d131SAdrian Lang                    if(!actionOK('source')) return false; //pseudo action
639a453d131SAdrian Lang                    $params['rev'] = $REV;
6406709e843SAdrian Lang                    $type          = 'source';
641a453d131SAdrian Lang                    $accesskey     = 'v';
642ed630903Sandi                }
643ed630903Sandi            } else {
644d30d4913SChristopher Smith                $params    = array('do' => '');
6456709e843SAdrian Lang                $type      = 'show';
646a453d131SAdrian Lang                $accesskey = 'v';
647ed630903Sandi            }
6481af98a77SAnika Henke            break;
649a453d131SAdrian Lang        case 'revisions':
6506709e843SAdrian Lang            $type      = 'revs';
651a453d131SAdrian Lang            $accesskey = 'o';
6521af98a77SAnika Henke            break;
653ed630903Sandi        case 'recent':
654a453d131SAdrian Lang            $accesskey = 'r';
6551af98a77SAnika Henke            break;
656ed630903Sandi        case 'index':
657a453d131SAdrian Lang            $accesskey = 'x';
658b1af9014SChristopher Smith            // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml)
659b1af9014SChristopher Smith            if ($conf['start'] == $ID && !$conf['sitemap']) {
660b1af9014SChristopher Smith                $nofollow = false;
661b1af9014SChristopher Smith            }
6621af98a77SAnika Henke            break;
663ed630903Sandi        case 'top':
664076f0d72SAnika Henke            $accesskey = 't';
665d30d4913SChristopher Smith            $params    = array('do' => '');
666a453d131SAdrian Lang            $id        = '#dokuwiki__top';
6671af98a77SAnika Henke            break;
668a3ec5f4aSmatthiasgrimm        case 'back':
669a453d131SAdrian Lang            $parent = tpl_getparent($ID);
670a453d131SAdrian Lang            if(!$parent) {
671a453d131SAdrian Lang                return false;
672a3ec5f4aSmatthiasgrimm            }
673a453d131SAdrian Lang            $id        = $parent;
674d30d4913SChristopher Smith            $params    = array('do' => '');
675a453d131SAdrian Lang            $accesskey = 'b';
6761af98a77SAnika Henke            break;
677ed630903Sandi        case 'login':
678a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
679*585bf44eSChristopher Smith            if($INPUT->server->has('REMOTE_USER')) {
6803a48618aSAnika Henke                if(!actionOK('logout')) {
6812380e8a8SAdrian Lang                    return false;
6822380e8a8SAdrian Lang                }
683a453d131SAdrian Lang                $params['do'] = 'logout';
684a453d131SAdrian Lang                $type         = 'logout';
685bf413a4eSAnika Henke            }
686bf413a4eSAnika Henke            break;
687bf413a4eSAnika Henke        case 'register':
688*585bf44eSChristopher Smith            if($INPUT->server->str('REMOTE_USER')) {
689bf413a4eSAnika Henke                return false;
690bf413a4eSAnika Henke            }
691bf413a4eSAnika Henke            break;
692bf413a4eSAnika Henke        case 'resendpwd':
693*585bf44eSChristopher Smith            if($INPUT->server->str('REMOTE_USER')) {
694bf413a4eSAnika Henke                return false;
695ed630903Sandi            }
6961af98a77SAnika Henke            break;
697ed630903Sandi        case 'admin':
698a453d131SAdrian Lang            if(!$INFO['ismanager']) {
699a453d131SAdrian Lang                return false;
700c059e1a6SAndreas Gohr            }
7011af98a77SAnika Henke            break;
7021246e016SAndreas Gohr        case 'revert':
703a453d131SAdrian Lang            if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
704a453d131SAdrian Lang                return false;
7051246e016SAndreas Gohr            }
706a453d131SAdrian Lang            $params['rev']    = $REV;
707a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
7081246e016SAndreas Gohr            break;
7096709e843SAdrian Lang        case 'subscribe':
710*585bf44eSChristopher Smith            if(!$INPUT->server->str('REMOTE_USER')) {
711a453d131SAdrian Lang                return false;
712b158d625SSteven Danz            }
7131af98a77SAnika Henke            break;
714f00151b4Schris        case 'backlink':
7151af98a77SAnika Henke            break;
7168b06d178Schris        case 'profile':
717*585bf44eSChristopher Smith            if(!$INPUT->server->has('REMOTE_USER')) {
718a453d131SAdrian Lang                return false;
7198b06d178Schris            }
7201af98a77SAnika Henke            break;
721b9eb2e61SKate Arzamastseva        case 'media':
722d08527abSAnika Henke            $params['ns'] = getNS($ID);
723b9eb2e61SKate Arzamastseva            break;
724ed630903Sandi        default:
725a453d131SAdrian Lang            return '[unknown %s type]';
7261af98a77SAnika Henke            break;
727ed630903Sandi    }
728b1af9014SChristopher Smith    return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow');
729ed630903Sandi}
730ed630903Sandi
731ed630903Sandi/**
73201f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
73301f17825SAnika Henke *
73401f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
735ac7a515fSAndreas Gohr * @param
736ac7a515fSAndreas Gohr * @param bool   $link link or form button?
737ac7a515fSAndreas Gohr * @param bool   $wrapper HTML element wrapper
738ac7a515fSAndreas Gohr * @param bool   $return return or print
739ac7a515fSAndreas Gohr * @param string $pre prefix for links
740ac7a515fSAndreas Gohr * @param string $suf suffix for links
741ac7a515fSAndreas Gohr * @param string $inner inner HTML for links
742ac7a515fSAndreas Gohr * @return bool|string
74301f17825SAnika Henke */
744ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
74501f17825SAnika Henke    $out = '';
746ac7a515fSAndreas Gohr    if($link) {
747ac7a515fSAndreas Gohr        $out .= tpl_actionlink($type, $pre, $suf, $inner, 1);
748ac7a515fSAndreas Gohr    } else {
749ac7a515fSAndreas Gohr        $out .= tpl_button($type, 1);
750ac7a515fSAndreas Gohr    }
75101f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
75201f17825SAnika Henke
75301f17825SAnika Henke    if($return) return $out;
75401f17825SAnika Henke    print $out;
75501f17825SAnika Henke    return $out ? true : false;
75601f17825SAnika Henke}
75701f17825SAnika Henke
75801f17825SAnika Henke/**
7596b13307fSandi * Print the search form
7606b13307fSandi *
76172645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
76272645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
76372645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
76472645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
76572645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
76672645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
76772645b75SAndreas Gohr *
7686b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
769ac7a515fSAndreas Gohr * @param bool $ajax
770ac7a515fSAndreas Gohr * @param bool $autocomplete
771ac7a515fSAndreas Gohr * @return bool
7726b13307fSandi */
77372645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
7746b13307fSandi    global $lang;
775c1e3b7d9Smatthiasgrimm    global $ACT;
776ad4aaef7SAndreas Gohr    global $QUERY;
777c1e3b7d9Smatthiasgrimm
778670ff54eSchris    // don't print the search form if search action has been disabled
77964276bbcSarbrk1    if(!actionOK('search')) return false;
780670ff54eSchris
7819805efa0SAnika Henke    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">';
7826b13307fSandi    print '<input type="hidden" name="do" value="search" />';
783c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
784ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
78572645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
78607493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
78711ea018fSAndreas Gohr    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
78824a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
7894beabca9SAnika Henke    print '</div></form>';
79054e95700STom N Harris    return true;
7916b13307fSandi}
7926b13307fSandi
7936b13307fSandi/**
7946b13307fSandi * Print the breadcrumbs trace
7956b13307fSandi *
7966b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
797ac7a515fSAndreas Gohr * @param string $sep Separator between entries
798ac7a515fSAndreas Gohr * @return bool
7996b13307fSandi */
800e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') {
8016b13307fSandi    global $lang;
8026b13307fSandi    global $conf;
8036b13307fSandi
8046b13307fSandi    //check if enabled
805359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
8066b13307fSandi
8076b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
808265e3787Sandi
8092979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
810265e3787Sandi
81140eb54bbSjan    //render crumbs, highlight the last one
8121b6f3a44SAndreas Gohr    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
81340eb54bbSjan    $last = count($crumbs);
81440eb54bbSjan    $i    = 0;
815a77f5846Sjan    foreach($crumbs as $id => $name) {
81640eb54bbSjan        $i++;
8172979a10bSKatriel Traum        echo $crumbs_sep;
81892795d04Sandi        if($i == $last) print '<span class="curid">';
819d317fb5dSAnika Henke        print '<bdi>';
820e26fd1eeSAndreas Gohr        tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"');
821d317fb5dSAnika Henke        print '</bdi>';
82292795d04Sandi        if($i == $last) print '</span>';
8236b13307fSandi    }
82454e95700STom N Harris    return true;
8256b13307fSandi}
8266b13307fSandi
8276b13307fSandi/**
8281734437eSandi * Hierarchical breadcrumbs
8291734437eSandi *
83031e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8311734437eSandi * It only makes sense with a deep site structure.
8321734437eSandi *
8331734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8346bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
83531e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
836f46c9e83SAnika Henke * @author <fredrik@averpil.com>
8376bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
838ac7a515fSAndreas Gohr * @param string $sep Separator between entries
839ac7a515fSAndreas Gohr * @return bool
8401734437eSandi */
841e260f93bSAnika Henkefunction tpl_youarehere($sep = ' » ') {
8421734437eSandi    global $conf;
8431734437eSandi    global $ID;
8441734437eSandi    global $lang;
8451734437eSandi
84631e187f8SSean Coates    // check if enabled
84754e95700STom N Harris    if(!$conf['youarehere']) return false;
8481734437eSandi
8491734437eSandi    $parts = explode(':', $ID);
850796bafb3SAndreas Gohr    $count = count($parts);
8511734437eSandi
8521b6f3a44SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
8531734437eSandi
8541734437eSandi    // always print the startpage
855fca4df27SAnika Henke    echo '<span class="home">';
856e013f48dSAnika Henke    tpl_pagelink(':'.$conf['start']);
857fca4df27SAnika Henke    echo '</span>';
858796bafb3SAndreas Gohr
859796bafb3SAndreas Gohr    // print intermediate namespace links
860796bafb3SAndreas Gohr    $part = '';
861796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
862796bafb3SAndreas Gohr        $part .= $parts[$i].':';
863796bafb3SAndreas Gohr        $page = $part;
864796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
865796bafb3SAndreas Gohr
866796bafb3SAndreas Gohr        // output
867796bafb3SAndreas Gohr        echo $sep;
868e013f48dSAnika Henke        tpl_pagelink($page);
86931e187f8SSean Coates    }
8701734437eSandi
871796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
872e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
873ac7a515fSAndreas Gohr    if(isset($page) && $page == $part.$parts[$i]) return true;
874796bafb3SAndreas Gohr    $page = $part.$parts[$i];
875ac7a515fSAndreas Gohr    if($page == $conf['start']) return true;
876796bafb3SAndreas Gohr    echo $sep;
877e013f48dSAnika Henke    tpl_pagelink($page);
87854e95700STom N Harris    return true;
8791734437eSandi}
8801734437eSandi
8811734437eSandi/**
8826b13307fSandi * Print info if the user is logged in
883a2488c3cSMatthias Grimm * and show full name in that case
8846b13307fSandi *
8856b13307fSandi * Could be enhanced with a profile link in future?
8866b13307fSandi *
8876b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
888ac7a515fSAndreas Gohr * @return bool
8896b13307fSandi */
8906b13307fSandifunction tpl_userinfo() {
8916b13307fSandi    global $lang;
8923e63b73bSMichael Klier    global $INFO;
893*585bf44eSChristopher Smith    /** @var Input $INPUT */
894*585bf44eSChristopher Smith    global $INPUT;
895*585bf44eSChristopher Smith
896*585bf44eSChristopher Smith    if($INPUT->server->str('REMOTE_USER')) {
897*585bf44eSChristopher Smith        print $lang['loggedinas'].': <bdi>'.hsc($INFO['userinfo']['name']).'</bdi> (<bdi>'.hsc($INPUT->server->str('REMOTE_USER')).'</bdi>)';
89854e95700STom N Harris        return true;
89954e95700STom N Harris    }
90054e95700STom N Harris    return false;
9016b13307fSandi}
9026b13307fSandi
9036b13307fSandi/**
9046b13307fSandi * Print some info about the current page
9056b13307fSandi *
9066b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
907ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
908ac7a515fSAndreas Gohr * @return bool|string
9096b13307fSandi */
9104b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
9116b13307fSandi    global $conf;
9126b13307fSandi    global $lang;
9136b13307fSandi    global $INFO;
914c6e92a3cSDavid Lorentsen    global $ID;
915c6e92a3cSDavid Lorentsen
916c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
917ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
918ac7a515fSAndreas Gohr        return false;
919ac7a515fSAndreas Gohr    }
9206b13307fSandi
9216b13307fSandi    // prepare date and path
9226b13307fSandi    $fn = $INFO['filepath'];
9236b13307fSandi    if(!$conf['fullpath']) {
924613bca54SAndreas Gohr        if($INFO['rev']) {
92550fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn);
9266b13307fSandi        } else {
92750fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn);
9286b13307fSandi        }
9296b13307fSandi    }
930bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
931f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
9326b13307fSandi
933faecdfdfSAndreas Gohr    // print it
934faecdfdfSAndreas Gohr    if($INFO['exists']) {
9354b0d3916SAndreas Gohr        $out = '';
936d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
937e260f93bSAnika Henke        $out .= ' · ';
9384b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
9394b0d3916SAndreas Gohr        $out .= ': ';
9404b0d3916SAndreas Gohr        $out .= $date;
9416b13307fSandi        if($INFO['editor']) {
9424b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
943d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
9445aa52fafSBen Coburn        } else {
9454b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
9466b13307fSandi        }
9476b13307fSandi        if($INFO['locked']) {
948e260f93bSAnika Henke            $out .= ' · ';
9494b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
9504b0d3916SAndreas Gohr            $out .= ': ';
951d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
9526b13307fSandi        }
9534b0d3916SAndreas Gohr        if($ret) {
9544b0d3916SAndreas Gohr            return $out;
9554b0d3916SAndreas Gohr        } else {
9564b0d3916SAndreas Gohr            echo $out;
95754e95700STom N Harris            return true;
9586b13307fSandi        }
9594b0d3916SAndreas Gohr    }
96054e95700STom N Harris    return false;
9616b13307fSandi}
9626b13307fSandi
963820fa24bSandi/**
964a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
96587c434ceSAndreas Gohr *
96687c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
967a6598f23SBen Coburn * the given ID is used.
96887c434ceSAndreas Gohr *
96987c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
970ac7a515fSAndreas Gohr * @param string $id page id
971ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
972ac7a515fSAndreas Gohr * @return bool|string
97387c434ceSAndreas Gohr */
974a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
97587c434ceSAndreas Gohr    if(is_null($id)) {
97687c434ceSAndreas Gohr        global $ID;
97787c434ceSAndreas Gohr        $id = $ID;
97887c434ceSAndreas Gohr    }
97987c434ceSAndreas Gohr
98087c434ceSAndreas Gohr    $name = $id;
981fe9ec250SChris Smith    if(useHeading('navigation')) {
98287c434ceSAndreas Gohr        $title = p_get_first_heading($id);
98387c434ceSAndreas Gohr        if($title) $name = $title;
98487c434ceSAndreas Gohr    }
985a6598f23SBen Coburn
986a6598f23SBen Coburn    if($ret) {
987a6598f23SBen Coburn        return hsc($name);
988a6598f23SBen Coburn    } else {
98987c434ceSAndreas Gohr        print hsc($name);
99054e95700STom N Harris        return true;
99187c434ceSAndreas Gohr    }
992a6598f23SBen Coburn}
993340756e4Sandi
99455efc227SAndreas Gohr/**
99555efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
99655efc227SAndreas Gohr *
99755efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
99855efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
99955efc227SAndreas Gohr *
100055efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
100155efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
100255efc227SAndreas Gohr * to the names of the latter one)
100355efc227SAndreas Gohr *
10043df72098SAndreas Gohr * Only allowed in: detail.php
100555efc227SAndreas Gohr *
100655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1007ac7a515fSAndreas Gohr * @param array  $tags tags to try
1008ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found
1009ac7a515fSAndreas Gohr * @param null   $src the image src, uses global $SRC if not given
1010ac7a515fSAndreas Gohr * @return string
101155efc227SAndreas Gohr */
10123df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
101355efc227SAndreas Gohr    // Init Exif Reader
101455efc227SAndreas Gohr    global $SRC;
10153df72098SAndreas Gohr
10163df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
10173df72098SAndreas Gohr
101855efc227SAndreas Gohr    static $meta = null;
10193df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
102055efc227SAndreas Gohr    if($meta === false) return $alt;
102155efc227SAndreas Gohr    $info = $meta->getField($tags);
102255efc227SAndreas Gohr    if($info == false) return $alt;
102355efc227SAndreas Gohr    return $info;
102455efc227SAndreas Gohr}
102555efc227SAndreas Gohr
102655efc227SAndreas Gohr/**
102755efc227SAndreas Gohr * Prints the image with a link to the full sized version
102855efc227SAndreas Gohr *
102955efc227SAndreas Gohr * Only allowed in: detail.php
1030a02d2933SAndreas Gohr *
1031ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1032a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1033a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1034a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1035a02d2933SAndreas Gohr * @param $params array  - additional image attributes
1036ac7a515fSAndreas Gohr * @return mixed Result of TPL_IMG_DISPLAY
103755efc227SAndreas Gohr */
1038a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
103955efc227SAndreas Gohr    global $IMG;
1040*585bf44eSChristopher Smith    /** @var Input $INPUT */
1041ac7a515fSAndreas Gohr    global $INPUT;
104255efc227SAndreas Gohr    $w = tpl_img_getTag('File.Width');
104355efc227SAndreas Gohr    $h = tpl_img_getTag('File.Height');
104455efc227SAndreas Gohr
104555efc227SAndreas Gohr    //resize to given max values
104623a34783SAndreas Gohr    $ratio = 1;
104723a34783SAndreas Gohr    if($w >= $h) {
1048f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
104955efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1050f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
105155efc227SAndreas Gohr            $ratio = $maxheight / $h;
105255efc227SAndreas Gohr        }
105355efc227SAndreas Gohr    } else {
1054f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
105555efc227SAndreas Gohr            $ratio = $maxheight / $h;
1056f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
105755efc227SAndreas Gohr            $ratio = $maxwidth / $w;
105855efc227SAndreas Gohr        }
105955efc227SAndreas Gohr    }
106055efc227SAndreas Gohr    if($ratio) {
106155efc227SAndreas Gohr        $w = floor($ratio * $w);
106255efc227SAndreas Gohr        $h = floor($ratio * $h);
106355efc227SAndreas Gohr    }
106455efc227SAndreas Gohr
10656de3759aSAndreas Gohr    //prepare URLs
1066ac7a515fSAndreas Gohr    $url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&');
1067ac7a515fSAndreas Gohr    $src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&');
106855efc227SAndreas Gohr
10692684e50aSAndreas Gohr    //prepare attributes
107055efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1071a02d2933SAndreas Gohr    if(is_null($params)) {
10722684e50aSAndreas Gohr        $p = array();
1073a02d2933SAndreas Gohr    } else {
1074a02d2933SAndreas Gohr        $p = $params;
1075a02d2933SAndreas Gohr    }
10762684e50aSAndreas Gohr    if($w) $p['width'] = $w;
10772684e50aSAndreas Gohr    if($h) $p['height'] = $h;
10782684e50aSAndreas Gohr    $p['class'] = 'img_detail';
10792684e50aSAndreas Gohr    if($alt) {
10802684e50aSAndreas Gohr        $p['alt']   = $alt;
10812684e50aSAndreas Gohr        $p['title'] = $alt;
10822684e50aSAndreas Gohr    } else {
10832684e50aSAndreas Gohr        $p['alt'] = '';
10842684e50aSAndreas Gohr    }
1085a02d2933SAndreas Gohr    $p['src'] = $src;
108655efc227SAndreas Gohr
1087a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1088a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1089a02d2933SAndreas Gohr}
1090a02d2933SAndreas Gohr
1091a02d2933SAndreas Gohr/**
1092a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1093ac7a515fSAndreas Gohr *
1094ac7a515fSAndreas Gohr * @param array $data
1095ac7a515fSAndreas Gohr * @return bool
1096a02d2933SAndreas Gohr */
1097ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
109859f3611bSAnika Henke    global $lang;
1099a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1100a02d2933SAndreas Gohr
110159f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1102a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1103a02d2933SAndreas Gohr    if($data['url']) print '</a>';
110454e95700STom N Harris    return true;
110555efc227SAndreas Gohr}
110655efc227SAndreas Gohr
11077367b368SAndreas Gohr/**
1108881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11097367b368SAndreas Gohr *
11107367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11117367b368SAndreas Gohr * template
1112ac7a515fSAndreas Gohr *
1113ac7a515fSAndreas Gohr * @return bool
11147367b368SAndreas Gohr */
11157367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11167367b368SAndreas Gohr    global $ID;
11171dad36f5SAndreas Gohr
11187367b368SAndreas Gohr    $p           = array();
1119b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1120e68c51baSAndreas Gohr        '&'.time();
1121881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
11227367b368SAndreas Gohr    $p['height'] = 1;
11237367b368SAndreas Gohr    $p['alt']    = '';
11247367b368SAndreas Gohr    $att         = buildAttributes($p);
11257367b368SAndreas Gohr    print "<img $att />";
112654e95700STom N Harris    return true;
11277367b368SAndreas Gohr}
11287367b368SAndreas Gohr
112978d4e784SEsther Brunner/**
113078d4e784SEsther Brunner * tpl_getConf($id)
113178d4e784SEsther Brunner *
113278d4e784SEsther Brunner * use this function to access template configuration variables
1133ac7a515fSAndreas Gohr *
113417448fb8SChristopher Smith * @param string $id      name of the value to access
113517448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
113617448fb8SChristopher Smith * @return mixed
113778d4e784SEsther Brunner */
113817448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
113978d4e784SEsther Brunner    global $conf;
114017566ac6SAdrian Lang    static $tpl_configloaded = false;
114178d4e784SEsther Brunner
114278d4e784SEsther Brunner    $tpl = $conf['template'];
114378d4e784SEsther Brunner
114478d4e784SEsther Brunner    if(!$tpl_configloaded) {
114578d4e784SEsther Brunner        $tconf = tpl_loadConfig();
114678d4e784SEsther Brunner        if($tconf !== false) {
114778d4e784SEsther Brunner            foreach($tconf as $key => $value) {
114878d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
114978d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
115078d4e784SEsther Brunner            }
115178d4e784SEsther Brunner            $tpl_configloaded = true;
115278d4e784SEsther Brunner        }
115378d4e784SEsther Brunner    }
115478d4e784SEsther Brunner
115517448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
115678d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
115778d4e784SEsther Brunner    }
115878d4e784SEsther Brunner
115917448fb8SChristopher Smith    return $notset;
116017448fb8SChristopher Smith}
116117448fb8SChristopher Smith
116278d4e784SEsther Brunner/**
116378d4e784SEsther Brunner * tpl_loadConfig()
1164ac7a515fSAndreas Gohr *
116578d4e784SEsther Brunner * reads all template configuration variables
116678d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1167ac7a515fSAndreas Gohr *
1168ac7a515fSAndreas Gohr * @return array
116978d4e784SEsther Brunner */
117078d4e784SEsther Brunnerfunction tpl_loadConfig() {
117178d4e784SEsther Brunner
1172c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
117378d4e784SEsther Brunner    $conf = array();
117478d4e784SEsther Brunner
117578d4e784SEsther Brunner    if(!@file_exists($file)) return false;
117678d4e784SEsther Brunner
117778d4e784SEsther Brunner    // load default config file
117878d4e784SEsther Brunner    include($file);
117978d4e784SEsther Brunner
118078d4e784SEsther Brunner    return $conf;
118178d4e784SEsther Brunner}
118278d4e784SEsther Brunner
118317566ac6SAdrian Lang// language methods
118417566ac6SAdrian Lang/**
118517566ac6SAdrian Lang * tpl_getLang($id)
118617566ac6SAdrian Lang *
118717566ac6SAdrian Lang * use this function to access template language variables
118817566ac6SAdrian Lang */
118917566ac6SAdrian Langfunction tpl_getLang($id) {
119017566ac6SAdrian Lang    static $lang = array();
119117566ac6SAdrian Lang
119217566ac6SAdrian Lang    if(count($lang) === 0) {
1193c4766956SAndreas Gohr        $path = tpl_incdir().'lang/';
119417566ac6SAdrian Lang
119517566ac6SAdrian Lang        $lang = array();
119617566ac6SAdrian Lang
119717566ac6SAdrian Lang        global $conf; // definitely don't invoke "global $lang"
119817566ac6SAdrian Lang        // don't include once
119917566ac6SAdrian Lang        @include($path.'en/lang.php');
120017566ac6SAdrian Lang        if($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
120117566ac6SAdrian Lang    }
120217566ac6SAdrian Lang
120317566ac6SAdrian Lang    return $lang[$id];
120417566ac6SAdrian Lang}
120517566ac6SAdrian Lang
12063df72098SAndreas Gohr/**
1207c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1208e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1209e8ec13b9SKlap-in *
1210e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1211e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1212e8ec13b9SKlap-in */
1213e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1214c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1215e8ec13b9SKlap-in}
1216e8ec13b9SKlap-in
1217e8ec13b9SKlap-in/**
1218c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
1219e8ec13b9SKlap-in */
1220c5c17fdaSKlap-infunction tpl_localeFN($id) {
1221e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1222e8ec13b9SKlap-in    global $conf;
1223e8ec13b9SKlap-in    $file = DOKU_CONF.'/template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
1224e8ec13b9SKlap-in    if (!@file_exists($file)){
1225e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
1226e8ec13b9SKlap-in        if(!@file_exists($file)){
1227e8ec13b9SKlap-in            //fall back to english
1228e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1229e8ec13b9SKlap-in        }
1230e8ec13b9SKlap-in    }
1231e8ec13b9SKlap-in    return $file;
1232e8ec13b9SKlap-in}
1233e8ec13b9SKlap-in
1234e8ec13b9SKlap-in/**
12353df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
12363df72098SAndreas Gohr *
12373df72098SAndreas Gohr * Depending on the user's actions this may be a list of
12383df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
12393df72098SAndreas Gohr * a message of referencing pages
12403df72098SAndreas Gohr *
12413df72098SAndreas Gohr * Only allowed in mediamanager.php
12423df72098SAndreas Gohr *
1243c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1244c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
12453df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
12463df72098SAndreas Gohr */
124700e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
12483df72098SAndreas Gohr    global $IMG;
12493df72098SAndreas Gohr    global $AUTH;
12503df72098SAndreas Gohr    global $INUSE;
12513df72098SAndreas Gohr    global $NS;
12523df72098SAndreas Gohr    global $JUMPTO;
1253*585bf44eSChristopher Smith    /** @var Input $INPUT */
1254ac7a515fSAndreas Gohr    global $INPUT;
12553df72098SAndreas Gohr
1256ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1257c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1258c182313eSAndreas Gohr
1259c182313eSAndreas Gohr    if(!$do) {
1260ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1261c182313eSAndreas Gohr            $do = 'metaform';
1262c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1263c182313eSAndreas Gohr            $do = 'filesinuse';
1264c182313eSAndreas Gohr        } else {
1265c182313eSAndreas Gohr            $do = 'filelist';
1266c182313eSAndreas Gohr        }
1267c182313eSAndreas Gohr    }
1268c182313eSAndreas Gohr
1269c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1270c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1271c182313eSAndreas Gohr    $data = array('do' => $do);
1272c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1273c182313eSAndreas Gohr    if($evt->advise_before()) {
1274c182313eSAndreas Gohr        $do = $data['do'];
127530fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1276c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1277c182313eSAndreas Gohr        } elseif($do == 'filelist') {
127800e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1279c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1280ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1281c182313eSAndreas Gohr        } else {
1282c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1283c182313eSAndreas Gohr        }
1284c182313eSAndreas Gohr    }
1285c182313eSAndreas Gohr    $evt->advise_after();
1286c182313eSAndreas Gohr    unset($evt);
1287c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1288c182313eSAndreas Gohr
12893df72098SAndreas Gohr}
12903df72098SAndreas Gohr
12913df72098SAndreas Gohr/**
1292d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1293d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1294d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1295d9162c6cSKate Arzamastseva *
1296d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1297d9162c6cSKate Arzamastseva */
1298035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1299d9162c6cSKate Arzamastseva    global $AUTH;
1300d9162c6cSKate Arzamastseva    global $NS;
1301d9162c6cSKate Arzamastseva    global $JUMPTO;
130295b451bcSAdrian Lang    global $lang;
1303*585bf44eSChristopher Smith    /** @var Input $INPUT */
1304ac7a515fSAndreas Gohr    global $INPUT;
1305d9162c6cSKate Arzamastseva
1306ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1307e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1308ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1309d9162c6cSKate Arzamastseva
131094add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
131195b451bcSAdrian Lang
1312ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
131323846a98SKate Arzamastseva
131494add303SAnika Henke    echo '<div class="panelHeader">'.NL;
131595b451bcSAdrian Lang    echo '<h3>';
1316026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1317c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
131894add303SAnika Henke    echo '</h3>'.NL;
131995b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
132095b451bcSAdrian Lang        media_tab_files_options();
132123846a98SKate Arzamastseva    }
132294add303SAnika Henke    echo '</div>'.NL;
1323d9162c6cSKate Arzamastseva
132494add303SAnika Henke    echo '<div class="panelContent">'.NL;
132595b451bcSAdrian Lang    if($opened_tab == 'files') {
132695b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
132795b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
132895b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
132995b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
133095b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
133195b451bcSAdrian Lang    }
133294add303SAnika Henke    echo '</div>'.NL;
1333d9162c6cSKate Arzamastseva}
1334d9162c6cSKate Arzamastseva
1335d9162c6cSKate Arzamastseva/**
1336d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1337d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1338d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1339d9162c6cSKate Arzamastseva * list of file revisions
1340d9162c6cSKate Arzamastseva *
1341d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1342d9162c6cSKate Arzamastseva */
1343035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1344*585bf44eSChristopher Smith    global $AUTH, $NS, $conf, $DEL, $lang;
1345*585bf44eSChristopher Smith    /** @var Input $INPUT */
1346*585bf44eSChristopher Smith    global $INPUT;
1347d9162c6cSKate Arzamastseva
134892cac9a9SKate Arzamastseva    $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1349ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
13506dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1351ac7a515fSAndreas Gohr    if(isset($NS) && getNS($image) != $NS) return;
1352ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
13531eeeced2SKate Arzamastseva
1354ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1355e5d185e1SKate Arzamastseva
1356e5d185e1SKate Arzamastseva    $tab_array = array('view');
1357ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1358e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1359e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1360e5d185e1SKate Arzamastseva    }
1361e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1362e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1363e5d185e1SKate Arzamastseva    }
1364e5d185e1SKate Arzamastseva
1365e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1366ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
136723846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1368d9162c6cSKate Arzamastseva
1369ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
137023846a98SKate Arzamastseva
137159f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1372ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
137395b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
137495b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
137500c2d4a9SAnika Henke    $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
137608317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
137708317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
137808317413SAdrian Lang    } else {
1379026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
138008317413SAdrian Lang    }
1381b8a84c03SAndreas Gohr
138294add303SAnika Henke    echo '</h3></div>'.NL;
138395b451bcSAdrian Lang
138494add303SAnika Henke    echo '<div class="panelContent">'.NL;
138595b451bcSAdrian Lang
138623846a98SKate Arzamastseva    if($opened_tab == 'view') {
138723846a98SKate Arzamastseva        media_tab_view($image, $NS, $AUTH, $rev);
138823846a98SKate Arzamastseva
138992cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
139023846a98SKate Arzamastseva        media_tab_edit($image, $NS, $AUTH);
139123846a98SKate Arzamastseva
1392e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
139310799f9cSKate Arzamastseva        media_tab_history($image, $NS, $AUTH);
139423846a98SKate Arzamastseva    }
139595b451bcSAdrian Lang
139694add303SAnika Henke    echo '</div>'.NL;
1397d9162c6cSKate Arzamastseva}
1398d9162c6cSKate Arzamastseva
1399d9162c6cSKate Arzamastseva/**
14003df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
14013df72098SAndreas Gohr *
14023df72098SAndreas Gohr * Only allowed in mediamanager.php
14033df72098SAndreas Gohr *
14043df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14053df72098SAndreas Gohr */
1406fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14073df72098SAndreas Gohr    global $NS;
140823846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14093df72098SAndreas Gohr    media_nstree($NS);
14103df72098SAndreas Gohr    ptln('</div>');
14113df72098SAndreas Gohr}
14123df72098SAndreas Gohr
1413a00de5b5SAndreas Gohr/**
1414a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1415a00de5b5SAndreas Gohr *
1416a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1417a00de5b5SAndreas Gohr *
1418a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1419a00de5b5SAndreas Gohr */
1420a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1421a00de5b5SAndreas Gohr    global $ID;
1422a00de5b5SAndreas Gohr    global $REV;
1423a00de5b5SAndreas Gohr    global $lang;
1424*585bf44eSChristopher Smith    /** @var Input $INPUT */
1425*585bf44eSChristopher Smith    global $INPUT;
1426a00de5b5SAndreas Gohr
1427e63eccffSAndreas Gohr    echo '<form action="'.script().'" method="get" accept-charset="utf-8">';
14283b9a3b55SAnika Henke    echo '<div class="no">';
1429a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1430a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1431*585bf44eSChristopher Smith    if ($INPUT->server->str('REMOTE_USER')) {
1432a00de5b5SAndreas Gohr        echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
143361efcda1SChristopher Smith    }
1434a00de5b5SAndreas Gohr
14355f17c394SAnika Henke    echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">';
1436a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1437a00de5b5SAndreas Gohr
143861917024SAnika Henke    echo '<optgroup label="'.$lang['page_tools'].'">';
1439396c218fSAndreas Gohr    $act = tpl_get_action('edit');
1440396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1441a00de5b5SAndreas Gohr
1442396c218fSAndreas Gohr    $act = tpl_get_action('revert');
1443396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1444396c218fSAndreas Gohr
14453b9a3b55SAnika Henke    $act = tpl_get_action('revisions');
14463b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
14473b9a3b55SAnika Henke
1448396c218fSAndreas Gohr    $act = tpl_get_action('backlink');
1449396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
14503b9a3b55SAnika Henke
14513b9a3b55SAnika Henke    $act = tpl_get_action('subscribe');
14523b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1453a00de5b5SAndreas Gohr    echo '</optgroup>';
1454a00de5b5SAndreas Gohr
145561917024SAnika Henke    echo '<optgroup label="'.$lang['site_tools'].'">';
1456396c218fSAndreas Gohr    $act = tpl_get_action('recent');
1457396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1458396c218fSAndreas Gohr
14593b9a3b55SAnika Henke    $act = tpl_get_action('media');
14603b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
14613b9a3b55SAnika Henke
1462396c218fSAndreas Gohr    $act = tpl_get_action('index');
1463396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1464a00de5b5SAndreas Gohr    echo '</optgroup>';
1465a00de5b5SAndreas Gohr
146661917024SAnika Henke    echo '<optgroup label="'.$lang['user_tools'].'">';
1467396c218fSAndreas Gohr    $act = tpl_get_action('login');
1468396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1469a00de5b5SAndreas Gohr
14703b9a3b55SAnika Henke    $act = tpl_get_action('register');
1471396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1472a00de5b5SAndreas Gohr
14733b9a3b55SAnika Henke    $act = tpl_get_action('profile');
1474396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1475a00de5b5SAndreas Gohr
1476396c218fSAndreas Gohr    $act = tpl_get_action('admin');
1477396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1478a00de5b5SAndreas Gohr    echo '</optgroup>';
1479a00de5b5SAndreas Gohr
1480a00de5b5SAndreas Gohr    echo '</select>';
1481f22c1964SAndreas Gohr    echo '<input type="submit" value="'.$button.'" />';
14823b9a3b55SAnika Henke    echo '</div>';
1483a00de5b5SAndreas Gohr    echo '</form>';
1484a00de5b5SAndreas Gohr}
1485a00de5b5SAndreas Gohr
1486066fee30SAndreas Gohr/**
1487066fee30SAndreas Gohr * Print a informational line about the used license
1488066fee30SAndreas Gohr *
1489066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1490ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1491ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1492ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1493ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1494ac7a515fSAndreas Gohr * @return string
1495066fee30SAndreas Gohr */
149680083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1497066fee30SAndreas Gohr    global $license;
1498066fee30SAndreas Gohr    global $conf;
1499066fee30SAndreas Gohr    global $lang;
1500066fee30SAndreas Gohr    if(!$conf['license']) return '';
1501066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1502066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
150353e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1504066fee30SAndreas Gohr
150580083a41SAndreas Gohr    $out = '';
150680083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1507066fee30SAndreas Gohr    if($img) {
1508066fee30SAndreas Gohr        $src = license_img($img);
1509066fee30SAndreas Gohr        if($src) {
151053e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
151153e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
151253e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1513066fee30SAndreas Gohr        }
1514066fee30SAndreas Gohr    }
15154cefd216SMichael Klier    if(!$imgonly) {
151653e15c8bSAnika Henke        $out .= $lang['license'].' ';
1517d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1518d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
15194cefd216SMichael Klier    }
152080083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1521066fee30SAndreas Gohr
1522066fee30SAndreas Gohr    if($return) return $out;
1523066fee30SAndreas Gohr    echo $out;
1524ac7a515fSAndreas Gohr    return '';
1525066fee30SAndreas Gohr}
1526066fee30SAndreas Gohr
1527a81910eeSAndreas Gohr/**
1528835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1529a81910eeSAndreas Gohr *
1530a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1531a81910eeSAndreas Gohr * template
1532a81910eeSAndreas Gohr */
1533835dfcaeSAnika Henkefunction tpl_include_page($pageid, $print = true, $propagate = false) {
1534c786a1b6SAnika Henke    if (!$pageid) return false;
1535835dfcaeSAnika Henke    if ($propagate) $pageid = page_findnearest($pageid);
1536835dfcaeSAnika Henke
1537c786a1b6SAnika Henke    global $TOC;
15389a2e250aSAndreas Gohr    $oldtoc = $TOC;
1539a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
15409a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1541a81910eeSAndreas Gohr
1542a81910eeSAndreas Gohr    if(!$print) return $html;
1543a81910eeSAndreas Gohr    echo $html;
1544e66d3e6dSAndreas Gohr    return $html;
1545e66d3e6dSAndreas Gohr}
1546e66d3e6dSAndreas Gohr
1547e66d3e6dSAndreas Gohr/**
15485b75cd1fSAdrian Lang * Display the subscribe form
15495b75cd1fSAdrian Lang *
15505b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
15515b75cd1fSAdrian Lang */
15525b75cd1fSAdrian Langfunction tpl_subscribe() {
15535b75cd1fSAdrian Lang    global $INFO;
15545b75cd1fSAdrian Lang    global $ID;
15555b75cd1fSAdrian Lang    global $lang;
15566b8f02cfSAdrian Lang    global $conf;
155740c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
15585b75cd1fSAdrian Lang
15595b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
15605b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
156115741132SAndreas Gohr    echo '<div class="level2">';
15625b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
15635b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
15645b75cd1fSAdrian Lang    } else {
15655b75cd1fSAdrian Lang        echo '<ul>';
15665b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1567056c2049SAndreas Gohr            echo '<li><div class="li">';
15685b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1569056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
15705b75cd1fSAdrian Lang            } else {
1571056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
15725b75cd1fSAdrian Lang            }
157340c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
157415741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1575056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
157615741132SAndreas Gohr
1577ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1578ac7a515fSAndreas Gohr                $ID,
1579ac7a515fSAndreas Gohr                array(
1580ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
158166d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
158266d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
158366d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1584ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1585ac7a515fSAndreas Gohr                )
1586ac7a515fSAndreas Gohr            ).
158766d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
158866d2bed9SAdrian Lang                '</a></div></li>';
15895b75cd1fSAdrian Lang        }
15905b75cd1fSAdrian Lang        echo '</ul>';
15915b75cd1fSAdrian Lang    }
159215741132SAndreas Gohr    echo '</div>';
15935b75cd1fSAdrian Lang
159415741132SAndreas Gohr    // Add new subscription form
15955b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
159615741132SAndreas Gohr    echo '<div class="level2">';
15975b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
159815741132SAndreas Gohr    $targets = array(
159915741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
160015741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
160115741132SAndreas Gohr    );
160215741132SAndreas Gohr    $styles  = array(
160315741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
16046b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
16056b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
160615741132SAndreas Gohr    );
160715741132SAndreas Gohr
1608056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1609056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1610056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1611056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1612056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1613056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1614056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1615056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1616056c2049SAndreas Gohr    $form->endFieldset();
16175b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
16185b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
161915741132SAndreas Gohr    echo '</div>';
16205b75cd1fSAdrian Lang}
16215b75cd1fSAdrian Lang
1622d059ba9bSAndreas Gohr/**
1623d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1624d059ba9bSAndreas Gohr *
1625d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1626d059ba9bSAndreas Gohr *
1627d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1628d059ba9bSAndreas Gohr */
1629d059ba9bSAndreas Gohrfunction tpl_flush() {
1630d059ba9bSAndreas Gohr    ob_flush();
1631d059ba9bSAndreas Gohr    flush();
1632d059ba9bSAndreas Gohr}
1633d059ba9bSAndreas Gohr
1634afca7e7eSAnika Henke/**
1635378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1636afca7e7eSAnika Henke *
1637378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1638378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1639378325f9SAndreas Gohr *
1640378325f9SAndreas Gohr * @param  array $search       locations to look at
1641378325f9SAndreas Gohr * @param  bool  $abs           if to use absolute URL
1642ac7a515fSAndreas Gohr * @param  array &$imginfo   filled with getimagesize()
1643ac7a515fSAndreas Gohr * @return string
1644378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1645afca7e7eSAnika Henke */
1646378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1647ac7a515fSAndreas Gohr    $img     = '';
1648ac7a515fSAndreas Gohr    $file    = '';
1649ac7a515fSAndreas Gohr    $ismedia = false;
1650378325f9SAndreas Gohr    // loop through candidates until a match was found:
1651378325f9SAndreas Gohr    foreach($search as $img) {
1652378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1653378325f9SAndreas Gohr            $file    = mediaFN($img);
1654378325f9SAndreas Gohr            $ismedia = true;
1655378325f9SAndreas Gohr        } else {
1656c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1657378325f9SAndreas Gohr            $ismedia = false;
16581f13e33dSAnika Henke        }
16590f747863Slupo49
1660378325f9SAndreas Gohr        if(file_exists($file)) break;
1661872a6d29SAnika Henke    }
1662378325f9SAndreas Gohr
1663378325f9SAndreas Gohr    // fetch image data if requested
1664378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1665378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1666378325f9SAndreas Gohr    }
1667378325f9SAndreas Gohr
1668378325f9SAndreas Gohr    // build URL
1669378325f9SAndreas Gohr    if($ismedia) {
1670378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1671378325f9SAndreas Gohr    } else {
1672c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1673378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1674378325f9SAndreas Gohr    }
1675378325f9SAndreas Gohr
1676378325f9SAndreas Gohr    return $url;
1677a7e5f74cSlupo49}
16781f13e33dSAnika Henke
1679872a6d29SAnika Henke/**
1680e5d4768dSAndreas Gohr * PHP include a file
1681e5d4768dSAndreas Gohr *
1682e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1683e5d4768dSAndreas Gohr * file in the template's root directory.
1684e5d4768dSAndreas Gohr *
1685e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1686e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1687e5d4768dSAndreas Gohr * default.
1688e5d4768dSAndreas Gohr *
1689e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1690e5d4768dSAndreas Gohr * to this function!
1691e5d4768dSAndreas Gohr *
1692e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1693e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1694e5d4768dSAndreas Gohr */
1695e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1696e5d4768dSAndreas Gohr    global $config_cascade;
1697e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1698e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1699e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1700e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1701e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1702f3a1225fSAnika Henke                include("$dir/$file");
1703e5d4768dSAndreas Gohr                return;
1704e5d4768dSAndreas Gohr            }
1705e5d4768dSAndreas Gohr        }
1706e5d4768dSAndreas Gohr    }
1707e5d4768dSAndreas Gohr
1708e5d4768dSAndreas Gohr    // still here? try the template dir
1709e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1710e5d4768dSAndreas Gohr    if(file_exists($file)) {
1711f3a1225fSAnika Henke        include($file);
1712e5d4768dSAndreas Gohr    }
1713e5d4768dSAndreas Gohr}
1714e5d4768dSAndreas Gohr
1715e5d4768dSAndreas Gohr/**
1716872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1717872a6d29SAnika Henke *
1718872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
1719ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1720ac7a515fSAndreas Gohr * @return string
1721872a6d29SAnika Henke */
1722872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1723872a6d29SAnika Henke
1724872a6d29SAnika Henke    $return = '';
1725872a6d29SAnika Henke
1726872a6d29SAnika Henke    foreach($types as $type) {
1727872a6d29SAnika Henke        switch($type) {
1728872a6d29SAnika Henke            case 'favicon':
1729378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1730378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1731872a6d29SAnika Henke                break;
1732872a6d29SAnika Henke            case 'mobile':
1733cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1734378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1735872a6d29SAnika Henke                break;
1736872a6d29SAnika Henke            case 'generic':
1737872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1738378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1739378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1740872a6d29SAnika Henke                break;
1741872a6d29SAnika Henke        }
1742872a6d29SAnika Henke    }
1743872a6d29SAnika Henke
1744872a6d29SAnika Henke    return $return;
1745afca7e7eSAnika Henke}
1746afca7e7eSAnika Henke
1747d9162c6cSKate Arzamastseva/**
1748d9162c6cSKate Arzamastseva * Prints full-screen media manager
1749d9162c6cSKate Arzamastseva *
1750d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1751d9162c6cSKate Arzamastseva */
1752d9162c6cSKate Arzamastsevafunction tpl_media() {
1753ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
175488a71175SKate Arzamastseva    $fullscreen = true;
175595b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1756d9162c6cSKate Arzamastseva
1757ac7a515fSAndreas Gohr    $rev   = '';
1758ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
175998f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
176098f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
17619c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
176298f03b57SKate Arzamastseva
176394add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1764bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1765d9162c6cSKate Arzamastseva    html_msgarea();
176694add303SAnika Henke
176794add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
176894add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
176995b451bcSAdrian Lang    echo '<div class="panelHeader">';
1770ba340a70SAnika Henke    echo $lang['media_namespaces'];
177194add303SAnika Henke    echo '</div>'.NL;
177295b451bcSAdrian Lang
177394add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
177495b451bcSAdrian Lang    media_nstree($NS);
177594add303SAnika Henke    echo '</div>'.NL;
177694add303SAnika Henke    echo '</div>'.NL;
1777fa8e5c77SKate Arzamastseva
177894add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1779035e07f1SKate Arzamastseva    tpl_mediaFileList();
178094add303SAnika Henke    echo '</div>'.NL;
1781fa8e5c77SKate Arzamastseva
178294add303SAnika Henke    echo '<div class="panel file">'.NL;
178394add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1784035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
178594add303SAnika Henke    echo '</div>'.NL;
1786ba340a70SAnika Henke
178794add303SAnika Henke    echo '</div>'.NL;
1788d9162c6cSKate Arzamastseva}
1789afca7e7eSAnika Henke
1790c71db656SAnika Henke/**
1791c71db656SAnika Henke * Return useful layout classes
1792c71db656SAnika Henke *
1793c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
1794c71db656SAnika Henke */
1795c71db656SAnika Henkefunction tpl_classes() {
1796c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1797*585bf44eSChristopher Smith    /** @var Input $INPUT */
1798*585bf44eSChristopher Smith    global $INPUT;
1799*585bf44eSChristopher Smith
1800c71db656SAnika Henke    $classes = array(
1801c71db656SAnika Henke        'dokuwiki',
1802c71db656SAnika Henke        'mode_'.$ACT,
1803c71db656SAnika Henke        'tpl_'.$conf['template'],
1804*585bf44eSChristopher Smith        $INPUT->server->bool('REMOTE_USER') ? 'loggedIn' : '',
180539f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1806c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1807c71db656SAnika Henke    );
1808c71db656SAnika Henke    return join(' ', $classes);
1809c71db656SAnika Henke}
1810c71db656SAnika Henke
1811e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1812a00de5b5SAndreas Gohr
1813