xref: /dokuwiki/inc/template.php (revision becfa414b5b024ded4e094b1c113a72f39d8b763)
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        }
213b8595a66SAndreas Gohr        $toc = $meta['description']['tableofcontents'];
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;
2946b13307fSandi
2957bff22c0SAndreas Gohr    // prepare the head array
2967bff22c0SAndreas Gohr    $head = array();
2977bff22c0SAndreas Gohr
298202ac28bSMichael Klier    // prepare seed for js and css
299cd997f93SAndreas Gohr    $tseed   = $updateVersion;
300202ac28bSMichael Klier    $depends = getConfigFiles('main');
301cd997f93SAndreas Gohr    foreach($depends as $f) $tseed .= @filemtime($f);
302cd997f93SAndreas Gohr    $tseed   = md5($tseed);
3037bff22c0SAndreas Gohr
3046b13307fSandi    // the usual stuff
3053f803e5eSGina Haeussge    $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
306ac7a515fSAndreas Gohr    $head['link'][] = array(
307ac7a515fSAndreas Gohr        'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
308ac7a515fSAndreas Gohr        'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
309ac7a515fSAndreas Gohr    );
310f4f47358SBen Coburn    $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
3117aedde2eSGina Haeussge    if(actionOK('index')) {
312ac7a515fSAndreas Gohr        $head['link'][] = array(
313ac7a515fSAndreas Gohr            'rel'  => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
314ac7a515fSAndreas Gohr            'title'=> $lang['btn_index']
315ac7a515fSAndreas Gohr        );
3167aedde2eSGina Haeussge    }
317f96fa415SAndreas Gohr
318f96fa415SAndreas Gohr    if($alt) {
319ac7a515fSAndreas Gohr        $head['link'][] = array(
320ac7a515fSAndreas Gohr            'rel'  => 'alternate', 'type'=> 'application/rss+xml',
321a1288caeSGerrit Uitslag            'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
322ac7a515fSAndreas Gohr        );
323ac7a515fSAndreas Gohr        $head['link'][] = array(
324ac7a515fSAndreas Gohr            'rel'  => 'alternate', 'type'=> 'application/rss+xml',
325a1288caeSGerrit Uitslag            'title'=> $lang['currentns'],
326ac7a515fSAndreas Gohr            'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']
327ac7a515fSAndreas Gohr        );
328c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
329ac7a515fSAndreas Gohr            $head['link'][] = array(
330ac7a515fSAndreas Gohr                'rel'  => 'edit',
331715bdf1fSAndreas Gohr                'title'=> $lang['btn_edit'],
332ac7a515fSAndreas Gohr                'href' => wl($ID, 'do=edit', false, '&')
333ac7a515fSAndreas Gohr            );
334c35f3875SAndreas Gohr        }
335c35f3875SAndreas Gohr
3364bb1b5aeSAndreas Gohr        if($ACT == 'search') {
337ac7a515fSAndreas Gohr            $head['link'][] = array(
338ac7a515fSAndreas Gohr                'rel'  => 'alternate', 'type'=> 'application/rss+xml',
339a1288caeSGerrit Uitslag                'title'=> $lang['searchresult'],
340ac7a515fSAndreas Gohr                'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
341ac7a515fSAndreas Gohr            );
3424bb1b5aeSAndreas Gohr        }
343bae36d94SAndreas Gohr
344bae36d94SAndreas Gohr        if(actionOK('export_xhtml')) {
345ac7a515fSAndreas Gohr            $head['link'][] = array(
346a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
347ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'xhtml', '', false, '&')
348ac7a515fSAndreas Gohr            );
349bae36d94SAndreas Gohr        }
350bae36d94SAndreas Gohr
351bae36d94SAndreas Gohr        if(actionOK('export_raw')) {
352ac7a515fSAndreas Gohr            $head['link'][] = array(
353a1288caeSGerrit Uitslag                'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
354ac7a515fSAndreas Gohr                'href'=> exportlink($ID, 'raw', '', false, '&')
355ac7a515fSAndreas Gohr            );
356f96fa415SAndreas Gohr        }
357bae36d94SAndreas Gohr    }
3586b13307fSandi
3596b13307fSandi    // setup robot tags apropriate for different modes
3604f2e0004STim Weber    if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
3616b13307fSandi        if($INFO['exists']) {
3626b13307fSandi            //delay indexing:
3636b13307fSandi            if((time() - $INFO['lastmod']) >= $conf['indexdelay']) {
3647bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3656b13307fSandi            } else {
3667bff22c0SAndreas Gohr                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3676b13307fSandi            }
36869db0cafSAndreas Gohr            $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&'));
3696b13307fSandi        } else {
3707bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
3716b13307fSandi        }
3727a24876fSAndreas Gohr    } elseif(defined('DOKU_MEDIADETAIL')) {
3737bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
3746b13307fSandi    } else {
3757bff22c0SAndreas Gohr        $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
3766b13307fSandi    }
3776b13307fSandi
378831800b8SAndreas Gohr    // set metadata
379831800b8SAndreas Gohr    if($ACT == 'show' || $ACT == 'export_xhtml') {
380831800b8SAndreas Gohr        // date of modification
381831800b8SAndreas Gohr        if($REV) {
3827bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV));
383831800b8SAndreas Gohr        } else {
3847bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod']));
385831800b8SAndreas Gohr        }
386831800b8SAndreas Gohr
387831800b8SAndreas Gohr        // keywords (explicit or implicit)
388bb4866bdSchris        if(!empty($INFO['meta']['subject'])) {
3897bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
390831800b8SAndreas Gohr        } else {
3917bff22c0SAndreas Gohr            $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
392831800b8SAndreas Gohr        }
393831800b8SAndreas Gohr    }
394831800b8SAndreas Gohr
39578a6aeb1SAndreas Gohr    // load stylesheets
396ac7a515fSAndreas Gohr    $head['link'][] = array(
397ac7a515fSAndreas Gohr        'rel' => 'stylesheet', 'type'=> 'text/css',
398ac7a515fSAndreas Gohr        'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed
399ac7a515fSAndreas Gohr    );
400bad31ae9SAndreas Gohr
4018bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
402463d4a65SAndreas Gohr    $json   = new JSON();
40372e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
404443e135dSChristopher Smith    if($conf['useacl'] && !empty($_SERVER['REMOTE_USER'])) {
40572e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
406c591aabeSAndreas Gohr    }
40772e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
40885f81679SAdrian Lang    $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script);
4098bbcb611SAndreas Gohr
4108bbcb611SAndreas Gohr    // load external javascript
411ac7a515fSAndreas Gohr    $head['script'][] = array(
412ac7a515fSAndreas Gohr        'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
413ac7a515fSAndreas Gohr        'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed
414ac7a515fSAndreas Gohr    );
4157bff22c0SAndreas Gohr
4167bff22c0SAndreas Gohr    // trigger event here
417016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
41854e95700STom N Harris    return true;
4197bff22c0SAndreas Gohr}
4207bff22c0SAndreas Gohr
4217bff22c0SAndreas Gohr/**
4227bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
4237bff22c0SAndreas Gohr *
4247bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
4257bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
4267bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
4277bff22c0SAndreas Gohr *
4287bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
4291304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
4307bff22c0SAndreas Gohr *
4317bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
4327bff22c0SAndreas Gohr */
4337bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data) {
4347bff22c0SAndreas Gohr    foreach($data as $tag => $inst) {
4357bff22c0SAndreas Gohr        foreach($inst as $attr) {
4367bff22c0SAndreas Gohr            echo '<', $tag, ' ', buildAttributes($attr);
43726afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script') {
438e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
43909f791c4SDominik Eckelmann                    $attr['_data'] = "/*<![CDATA[*/".
440e226efe1SAndreas Gohr                        $attr['_data'].
44109f791c4SDominik Eckelmann                        "\n/*!]]>*/";
442e226efe1SAndreas Gohr
4431304d1dbSAndreas Gohr                echo '>', $attr['_data'], '</', $tag, '>';
4447bff22c0SAndreas Gohr            } else {
4457bff22c0SAndreas Gohr                echo '/>';
4467bff22c0SAndreas Gohr            }
4477bff22c0SAndreas Gohr            echo "\n";
4487bff22c0SAndreas Gohr        }
4497bff22c0SAndreas Gohr    }
4506b13307fSandi}
4516b13307fSandi
4526b13307fSandi/**
4536b13307fSandi * Print a link
4546b13307fSandi *
4555e163278SAndreas Gohr * Just builds a link.
4566b13307fSandi *
4576b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4586b13307fSandi */
4591af98a77SAnika Henkefunction tpl_link($url, $name, $more = '', $return = false) {
46001f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4611af98a77SAnika Henke    if($more) $out .= ' '.$more;
4621af98a77SAnika Henke    $out .= ">$name</a>";
4631af98a77SAnika Henke    if($return) return $out;
4641af98a77SAnika Henke    print $out;
46554e95700STom N Harris    return true;
4666b13307fSandi}
4676b13307fSandi
4686b13307fSandi/**
46955efc227SAndreas Gohr * Prints a link to a WikiPage
47055efc227SAndreas Gohr *
47155efc227SAndreas Gohr * Wrapper around html_wikilink
47255efc227SAndreas Gohr *
47355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
47455efc227SAndreas Gohr */
4750b17fdc6SAndreas Gohrfunction tpl_pagelink($id, $name = null) {
476d317fb5dSAnika Henke    print '<bdi>'.html_wikilink($id, $name).'</bdi>';
47754e95700STom N Harris    return true;
47855efc227SAndreas Gohr}
47955efc227SAndreas Gohr
48055efc227SAndreas Gohr/**
481a3ec5f4aSmatthiasgrimm * get the parent page
482a3ec5f4aSmatthiasgrimm *
483a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
484a3ec5f4aSmatthiasgrimm * returns false if none is available
485a3ec5f4aSmatthiasgrimm *
486377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
487a3ec5f4aSmatthiasgrimm */
488377f9e97SAndreas Gohrfunction tpl_getparent($id) {
489377f9e97SAndreas Gohr    $parent = getNS($id).':';
490377f9e97SAndreas Gohr    resolve_pageid('', $parent, $exists);
491a197105eSmatthiasgrimm    if($parent == $id) {
492a197105eSmatthiasgrimm        $pos    = strrpos(getNS($id), ':');
493a197105eSmatthiasgrimm        $parent = substr($parent, 0, $pos).':';
494a197105eSmatthiasgrimm        resolve_pageid('', $parent, $exists);
495377f9e97SAndreas Gohr        if($parent == $id) return false;
496a197105eSmatthiasgrimm    }
497377f9e97SAndreas Gohr    return $parent;
498a3ec5f4aSmatthiasgrimm}
499a3ec5f4aSmatthiasgrimm
500a3ec5f4aSmatthiasgrimm/**
5016b13307fSandi * Print one of the buttons
5026b13307fSandi *
503a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
504a453d131SAdrian Lang * @see    tpl_get_action
5056b13307fSandi */
5061af98a77SAnika Henkefunction tpl_button($type, $return = false) {
507a453d131SAdrian Lang    $data = tpl_get_action($type);
508a453d131SAdrian Lang    if($data === false) {
509a453d131SAdrian Lang        return false;
510a453d131SAdrian Lang    } elseif(!is_array($data)) {
511a453d131SAdrian Lang        $out = sprintf($data, 'button');
512409d7af7SAndreas Gohr    } else {
513ac7a515fSAndreas Gohr        /**
514ac7a515fSAndreas Gohr         * @var string $accesskey
515ac7a515fSAndreas Gohr         * @var string $id
516ac7a515fSAndreas Gohr         * @var string $method
517ac7a515fSAndreas Gohr         * @var array  $params
518ac7a515fSAndreas Gohr         */
519a453d131SAdrian Lang        extract($data);
520a453d131SAdrian Lang        if($id === '#dokuwiki__top') {
521a453d131SAdrian Lang            $out = html_topbtn();
522409d7af7SAndreas Gohr        } else {
523a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
524409d7af7SAndreas Gohr        }
525409d7af7SAndreas Gohr    }
5261af98a77SAnika Henke    if($return) return $out;
527a453d131SAdrian Lang    echo $out;
528a453d131SAdrian Lang    return true;
5296b13307fSandi}
5306b13307fSandi
5316b13307fSandi/**
532ed630903Sandi * Like the action buttons but links
533ed630903Sandi *
534a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
535a453d131SAdrian Lang * @see    tpl_get_action
536a453d131SAdrian Lang */
537a453d131SAdrian Langfunction tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
538a453d131SAdrian Lang    global $lang;
539a453d131SAdrian Lang    $data = tpl_get_action($type);
540a453d131SAdrian Lang    if($data === false) {
541a453d131SAdrian Lang        return false;
542a453d131SAdrian Lang    } elseif(!is_array($data)) {
543a453d131SAdrian Lang        $out = sprintf($data, 'link');
544a453d131SAdrian Lang    } else {
545ac7a515fSAndreas Gohr        /**
546ac7a515fSAndreas Gohr         * @var string $accesskey
547ac7a515fSAndreas Gohr         * @var string $id
548ac7a515fSAndreas Gohr         * @var string $method
549b1af9014SChristopher Smith         * @var bool   $nofollow
550ac7a515fSAndreas Gohr         * @var array  $params
551*becfa414SGerrit Uitslag         * @var string $replacement
552ac7a515fSAndreas Gohr         */
553a453d131SAdrian Lang        extract($data);
554a453d131SAdrian Lang        if(strpos($id, '#') === 0) {
555a453d131SAdrian Lang            $linktarget = $id;
556a453d131SAdrian Lang        } else {
557a453d131SAdrian Lang            $linktarget = wl($id, $params);
558a453d131SAdrian Lang        }
559a453d131SAdrian Lang        $caption = $lang['btn_'.$type];
560*becfa414SGerrit Uitslag        if(strpos($caption, '%s')){
561*becfa414SGerrit Uitslag            $caption = sprintf($caption, $replacement);
562*becfa414SGerrit Uitslag        }
563c7e90e3fSAnika Henke        $akey    = $addTitle = '';
564c7e90e3fSAnika Henke        if($accesskey) {
565c7e90e3fSAnika Henke            $akey     = 'accesskey="'.$accesskey.'" ';
566c7e90e3fSAnika Henke            $addTitle = ' ['.strtoupper($accesskey).']';
567c7e90e3fSAnika Henke        }
568b1af9014SChristopher Smith        $rel = $nofollow ? 'rel="nofollow" ' : '';
569ac7a515fSAndreas Gohr        $out = tpl_link(
570ac7a515fSAndreas Gohr            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
571a453d131SAdrian Lang            'class="action '.$type.'" '.
572b1af9014SChristopher Smith                $akey.$rel.
573ac7a515fSAndreas Gohr                'title="'.hsc($caption).$addTitle.'"', 1
574ac7a515fSAndreas Gohr        );
575a453d131SAdrian Lang    }
576a453d131SAdrian Lang    if($return) return $out;
577a453d131SAdrian Lang    echo $out;
578a453d131SAdrian Lang    return true;
579a453d131SAdrian Lang}
580a453d131SAdrian Lang
581a453d131SAdrian Lang/**
582a453d131SAdrian Lang * Check the actions and get data for buttons and links
583ed630903Sandi *
584a453d131SAdrian Lang * Available actions are
585a453d131SAdrian Lang *
586a453d131SAdrian Lang *  edit        - edit/create/show/draft
587ed630903Sandi *  history     - old revisions
588ed630903Sandi *  recent      - recent changes
589a453d131SAdrian Lang *  login       - login/logout - if ACL enabled
590a453d131SAdrian Lang *  profile     - user profile (if logged in)
591ed630903Sandi *  index       - The index
592ed630903Sandi *  admin       - admin page - if enough rights
593a453d131SAdrian Lang *  top         - back to top
594a453d131SAdrian Lang *  back        - back to parent - if available
595bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
596a453d131SAdrian Lang *  subscribe/subscription- subscribe/unsubscribe
597ed630903Sandi *
598ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
599a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
600a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
601ac7a515fSAndreas Gohr * @param string $type
602ac7a515fSAndreas Gohr * @return array|bool|string
603ed630903Sandi */
604a453d131SAdrian Langfunction tpl_get_action($type) {
605ed630903Sandi    global $ID;
606ed630903Sandi    global $INFO;
607ed630903Sandi    global $REV;
608ed630903Sandi    global $ACT;
609b1af9014SChristopher Smith    global $conf;
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;
621*becfa414SGerrit Uitslag    $replacement = '';
622ed630903Sandi    switch($type) {
623ed630903Sandi        case 'edit':
6240b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
625ed630903Sandi            if($ACT == 'show' || $ACT == 'search') {
626a453d131SAdrian Lang                $method = 'post';
627ed630903Sandi                if($INFO['writable']) {
628a453d131SAdrian Lang                    $accesskey = 'e';
629b8a111f5SMichael Klier                    if(!empty($INFO['draft'])) {
6306709e843SAdrian Lang                        $type         = 'draft';
631a453d131SAdrian Lang                        $params['do'] = 'draft';
632b8a111f5SMichael Klier                    } else {
633a453d131SAdrian Lang                        $params['rev'] = $REV;
634a453d131SAdrian Lang                        if(!$INFO['exists']) {
6356709e843SAdrian Lang                            $type = 'create';
636ed630903Sandi                        }
637b8a111f5SMichael Klier                    }
638ed630903Sandi                } else {
639a453d131SAdrian Lang                    if(!actionOK('source')) return false; //pseudo action
640a453d131SAdrian Lang                    $params['rev'] = $REV;
6416709e843SAdrian Lang                    $type          = 'source';
642a453d131SAdrian Lang                    $accesskey     = 'v';
643ed630903Sandi                }
644ed630903Sandi            } else {
64584148531SMichael Hamann                $params    = array();
6466709e843SAdrian Lang                $type      = 'show';
647a453d131SAdrian Lang                $accesskey = 'v';
648ed630903Sandi            }
6491af98a77SAnika Henke            break;
650a453d131SAdrian Lang        case 'revisions':
6516709e843SAdrian Lang            $type      = 'revs';
652a453d131SAdrian Lang            $accesskey = 'o';
6531af98a77SAnika Henke            break;
654ed630903Sandi        case 'recent':
655a453d131SAdrian Lang            $accesskey = 'r';
6561af98a77SAnika Henke            break;
657ed630903Sandi        case 'index':
658a453d131SAdrian Lang            $accesskey = 'x';
659b1af9014SChristopher Smith            // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml)
660b1af9014SChristopher Smith            if ($conf['start'] == $ID && !$conf['sitemap']) {
661b1af9014SChristopher Smith                $nofollow = false;
662b1af9014SChristopher Smith            }
6631af98a77SAnika Henke            break;
664ed630903Sandi        case 'top':
665076f0d72SAnika Henke            $accesskey = 't';
66684148531SMichael Hamann            $params    = array();
667a453d131SAdrian Lang            $id        = '#dokuwiki__top';
6681af98a77SAnika Henke            break;
669a3ec5f4aSmatthiasgrimm        case 'back':
670a453d131SAdrian Lang            $parent = tpl_getparent($ID);
671a453d131SAdrian Lang            if(!$parent) {
672a453d131SAdrian Lang                return false;
673a3ec5f4aSmatthiasgrimm            }
674a453d131SAdrian Lang            $id        = $parent;
67584148531SMichael Hamann            $params    = array();
676a453d131SAdrian Lang            $accesskey = 'b';
6771af98a77SAnika Henke            break;
678*becfa414SGerrit Uitslag        case 'img_backto':
679*becfa414SGerrit Uitslag            $params = array();
680*becfa414SGerrit Uitslag            $accesskey = 'b';
681*becfa414SGerrit Uitslag            $replacement = $ID;
682*becfa414SGerrit Uitslag            break;
683ed630903Sandi        case 'login':
684a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
6852380e8a8SAdrian Lang            if(isset($_SERVER['REMOTE_USER'])) {
6863a48618aSAnika Henke                if(!actionOK('logout')) {
6872380e8a8SAdrian Lang                    return false;
6882380e8a8SAdrian Lang                }
689a453d131SAdrian Lang                $params['do'] = 'logout';
690a453d131SAdrian Lang                $type         = 'logout';
691bf413a4eSAnika Henke            }
692bf413a4eSAnika Henke            break;
693bf413a4eSAnika Henke        case 'register':
694443e135dSChristopher Smith            if(!empty($_SERVER['REMOTE_USER'])) {
695bf413a4eSAnika Henke                return false;
696bf413a4eSAnika Henke            }
697bf413a4eSAnika Henke            break;
698bf413a4eSAnika Henke        case 'resendpwd':
699443e135dSChristopher Smith            if(!empty($_SERVER['REMOTE_USER'])) {
700bf413a4eSAnika Henke                return false;
701ed630903Sandi            }
7021af98a77SAnika Henke            break;
703ed630903Sandi        case 'admin':
704a453d131SAdrian Lang            if(!$INFO['ismanager']) {
705a453d131SAdrian Lang                return false;
706c059e1a6SAndreas Gohr            }
7071af98a77SAnika Henke            break;
7081246e016SAndreas Gohr        case 'revert':
709a453d131SAdrian Lang            if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
710a453d131SAdrian Lang                return false;
7111246e016SAndreas Gohr            }
712a453d131SAdrian Lang            $params['rev']    = $REV;
713a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
7141246e016SAndreas Gohr            break;
7156709e843SAdrian Lang        case 'subscribe':
7163a48618aSAnika Henke            if(!$_SERVER['REMOTE_USER']) {
717a453d131SAdrian Lang                return false;
718b158d625SSteven Danz            }
7191af98a77SAnika Henke            break;
720f00151b4Schris        case 'backlink':
7211af98a77SAnika Henke            break;
7228b06d178Schris        case 'profile':
7233a48618aSAnika Henke            if(!isset($_SERVER['REMOTE_USER'])) {
724a453d131SAdrian Lang                return false;
7258b06d178Schris            }
7261af98a77SAnika Henke            break;
727b9eb2e61SKate Arzamastseva        case 'media':
728d08527abSAnika Henke            $params['ns'] = getNS($ID);
729b9eb2e61SKate Arzamastseva            break;
730*becfa414SGerrit Uitslag        case 'mediaManager':
731*becfa414SGerrit Uitslag            // View image in media manager
732*becfa414SGerrit Uitslag            global $IMG;
733*becfa414SGerrit Uitslag            $imgNS = getNS($IMG);
734*becfa414SGerrit Uitslag            $authNS = auth_quickaclcheck("$imgNS:*");
735*becfa414SGerrit Uitslag            if ($authNS < AUTH_UPLOAD) {
736*becfa414SGerrit Uitslag                return false;
737*becfa414SGerrit Uitslag            }
738*becfa414SGerrit Uitslag            $params = array(
739*becfa414SGerrit Uitslag                'ns' => $imgNS,
740*becfa414SGerrit Uitslag                'image' => $IMG,
741*becfa414SGerrit Uitslag                'do' => 'media'
742*becfa414SGerrit Uitslag            );
743*becfa414SGerrit Uitslag            //$type = 'media';
744*becfa414SGerrit Uitslag            break;
745ed630903Sandi        default:
746a453d131SAdrian Lang            return '[unknown %s type]';
7471af98a77SAnika Henke            break;
748ed630903Sandi    }
749*becfa414SGerrit Uitslag    return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement');
750ed630903Sandi}
751ed630903Sandi
752ed630903Sandi/**
75301f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
75401f17825SAnika Henke *
75501f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
756ac7a515fSAndreas Gohr * @param
757ac7a515fSAndreas Gohr * @param bool   $link link or form button?
758ac7a515fSAndreas Gohr * @param bool   $wrapper HTML element wrapper
759ac7a515fSAndreas Gohr * @param bool   $return return or print
760ac7a515fSAndreas Gohr * @param string $pre prefix for links
761ac7a515fSAndreas Gohr * @param string $suf suffix for links
762ac7a515fSAndreas Gohr * @param string $inner inner HTML for links
763ac7a515fSAndreas Gohr * @return bool|string
76401f17825SAnika Henke */
765ac7a515fSAndreas Gohrfunction tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
76601f17825SAnika Henke    $out = '';
767ac7a515fSAndreas Gohr    if($link) {
768ac7a515fSAndreas Gohr        $out .= tpl_actionlink($type, $pre, $suf, $inner, 1);
769ac7a515fSAndreas Gohr    } else {
770ac7a515fSAndreas Gohr        $out .= tpl_button($type, 1);
771ac7a515fSAndreas Gohr    }
77201f17825SAnika Henke    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
77301f17825SAnika Henke
77401f17825SAnika Henke    if($return) return $out;
77501f17825SAnika Henke    print $out;
77601f17825SAnika Henke    return $out ? true : false;
77701f17825SAnika Henke}
77801f17825SAnika Henke
77901f17825SAnika Henke/**
7806b13307fSandi * Print the search form
7816b13307fSandi *
78272645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
78372645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
78472645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
78572645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
78672645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
78772645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
78872645b75SAndreas Gohr *
7896b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
790ac7a515fSAndreas Gohr * @param bool $ajax
791ac7a515fSAndreas Gohr * @param bool $autocomplete
792ac7a515fSAndreas Gohr * @return bool
7936b13307fSandi */
79472645b75SAndreas Gohrfunction tpl_searchform($ajax = true, $autocomplete = true) {
7956b13307fSandi    global $lang;
796c1e3b7d9Smatthiasgrimm    global $ACT;
797ad4aaef7SAndreas Gohr    global $QUERY;
798c1e3b7d9Smatthiasgrimm
799670ff54eSchris    // don't print the search form if search action has been disabled
80064276bbcSarbrk1    if(!actionOK('search')) return false;
801670ff54eSchris
8029805efa0SAnika Henke    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get" role="search"><div class="no">';
8036b13307fSandi    print '<input type="hidden" name="do" value="search" />';
804c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
805ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
80672645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
80707493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
80811ea018fSAndreas Gohr    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
80924a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
8104beabca9SAnika Henke    print '</div></form>';
81154e95700STom N Harris    return true;
8126b13307fSandi}
8136b13307fSandi
8146b13307fSandi/**
8156b13307fSandi * Print the breadcrumbs trace
8166b13307fSandi *
8176b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
818ac7a515fSAndreas Gohr * @param string $sep Separator between entries
819ac7a515fSAndreas Gohr * @return bool
8206b13307fSandi */
821e260f93bSAnika Henkefunction tpl_breadcrumbs($sep = '•') {
8226b13307fSandi    global $lang;
8236b13307fSandi    global $conf;
8246b13307fSandi
8256b13307fSandi    //check if enabled
826359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
8276b13307fSandi
8286b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
829265e3787Sandi
8302979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
831265e3787Sandi
83240eb54bbSjan    //render crumbs, highlight the last one
8331b6f3a44SAndreas Gohr    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
83440eb54bbSjan    $last = count($crumbs);
83540eb54bbSjan    $i    = 0;
836a77f5846Sjan    foreach($crumbs as $id => $name) {
83740eb54bbSjan        $i++;
8382979a10bSKatriel Traum        echo $crumbs_sep;
83992795d04Sandi        if($i == $last) print '<span class="curid">';
840d317fb5dSAnika Henke        print '<bdi>';
841e26fd1eeSAndreas Gohr        tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"');
842d317fb5dSAnika Henke        print '</bdi>';
84392795d04Sandi        if($i == $last) print '</span>';
8446b13307fSandi    }
84554e95700STom N Harris    return true;
8466b13307fSandi}
8476b13307fSandi
8486b13307fSandi/**
8491734437eSandi * Hierarchical breadcrumbs
8501734437eSandi *
85131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8521734437eSandi * It only makes sense with a deep site structure.
8531734437eSandi *
8541734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8556bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
85631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
857f46c9e83SAnika Henke * @author <fredrik@averpil.com>
8586bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
859ac7a515fSAndreas Gohr * @param string $sep Separator between entries
860ac7a515fSAndreas Gohr * @return bool
8611734437eSandi */
862e260f93bSAnika Henkefunction tpl_youarehere($sep = ' » ') {
8631734437eSandi    global $conf;
8641734437eSandi    global $ID;
8651734437eSandi    global $lang;
8661734437eSandi
86731e187f8SSean Coates    // check if enabled
86854e95700STom N Harris    if(!$conf['youarehere']) return false;
8691734437eSandi
8701734437eSandi    $parts = explode(':', $ID);
871796bafb3SAndreas Gohr    $count = count($parts);
8721734437eSandi
8731b6f3a44SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
8741734437eSandi
8751734437eSandi    // always print the startpage
876fca4df27SAnika Henke    echo '<span class="home">';
877e013f48dSAnika Henke    tpl_pagelink(':'.$conf['start']);
878fca4df27SAnika Henke    echo '</span>';
879796bafb3SAndreas Gohr
880796bafb3SAndreas Gohr    // print intermediate namespace links
881796bafb3SAndreas Gohr    $part = '';
882796bafb3SAndreas Gohr    for($i = 0; $i < $count - 1; $i++) {
883796bafb3SAndreas Gohr        $part .= $parts[$i].':';
884796bafb3SAndreas Gohr        $page = $part;
885796bafb3SAndreas Gohr        if($page == $conf['start']) continue; // Skip startpage
886796bafb3SAndreas Gohr
887796bafb3SAndreas Gohr        // output
888796bafb3SAndreas Gohr        echo $sep;
889e013f48dSAnika Henke        tpl_pagelink($page);
89031e187f8SSean Coates    }
8911734437eSandi
892796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
893e013f48dSAnika Henke    resolve_pageid('', $page, $exists);
894ac7a515fSAndreas Gohr    if(isset($page) && $page == $part.$parts[$i]) return true;
895796bafb3SAndreas Gohr    $page = $part.$parts[$i];
896ac7a515fSAndreas Gohr    if($page == $conf['start']) return true;
897796bafb3SAndreas Gohr    echo $sep;
898e013f48dSAnika Henke    tpl_pagelink($page);
89954e95700STom N Harris    return true;
9001734437eSandi}
9011734437eSandi
9021734437eSandi/**
9036b13307fSandi * Print info if the user is logged in
904a2488c3cSMatthias Grimm * and show full name in that case
9056b13307fSandi *
9066b13307fSandi * Could be enhanced with a profile link in future?
9076b13307fSandi *
9086b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
909ac7a515fSAndreas Gohr * @return bool
9106b13307fSandi */
9116b13307fSandifunction tpl_userinfo() {
9126b13307fSandi    global $lang;
9133e63b73bSMichael Klier    global $INFO;
914c66972f2SAdrian Lang    if(isset($_SERVER['REMOTE_USER'])) {
915d317fb5dSAnika Henke        print $lang['loggedinas'].': <bdi>'.hsc($INFO['userinfo']['name']).'</bdi> (<bdi>'.hsc($_SERVER['REMOTE_USER']).'</bdi>)';
91654e95700STom N Harris        return true;
91754e95700STom N Harris    }
91854e95700STom N Harris    return false;
9196b13307fSandi}
9206b13307fSandi
9216b13307fSandi/**
9226b13307fSandi * Print some info about the current page
9236b13307fSandi *
9246b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
925ac7a515fSAndreas Gohr * @param bool $ret return content instead of printing it
926ac7a515fSAndreas Gohr * @return bool|string
9276b13307fSandi */
9284b0d3916SAndreas Gohrfunction tpl_pageinfo($ret = false) {
9296b13307fSandi    global $conf;
9306b13307fSandi    global $lang;
9316b13307fSandi    global $INFO;
932c6e92a3cSDavid Lorentsen    global $ID;
933c6e92a3cSDavid Lorentsen
934c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
935ac7a515fSAndreas Gohr    if(!auth_quickaclcheck($ID)) {
936ac7a515fSAndreas Gohr        return false;
937ac7a515fSAndreas Gohr    }
9386b13307fSandi
9396b13307fSandi    // prepare date and path
9406b13307fSandi    $fn = $INFO['filepath'];
9416b13307fSandi    if(!$conf['fullpath']) {
942613bca54SAndreas Gohr        if($INFO['rev']) {
94350fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['olddir']).'/', '', $fn);
9446b13307fSandi        } else {
94550fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['datadir']).'/', '', $fn);
9466b13307fSandi        }
9476b13307fSandi    }
948bee6dc82Sandi    $fn   = utf8_decodeFN($fn);
949f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
9506b13307fSandi
951faecdfdfSAndreas Gohr    // print it
952faecdfdfSAndreas Gohr    if($INFO['exists']) {
9534b0d3916SAndreas Gohr        $out = '';
954d317fb5dSAnika Henke        $out .= '<bdi>'.$fn.'</bdi>';
955e260f93bSAnika Henke        $out .= ' · ';
9564b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
9574b0d3916SAndreas Gohr        $out .= ': ';
9584b0d3916SAndreas Gohr        $out .= $date;
9596b13307fSandi        if($INFO['editor']) {
9604b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
961d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
9625aa52fafSBen Coburn        } else {
9634b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
9646b13307fSandi        }
9656b13307fSandi        if($INFO['locked']) {
966e260f93bSAnika Henke            $out .= ' · ';
9674b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
9684b0d3916SAndreas Gohr            $out .= ': ';
969d317fb5dSAnika Henke            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
9706b13307fSandi        }
9714b0d3916SAndreas Gohr        if($ret) {
9724b0d3916SAndreas Gohr            return $out;
9734b0d3916SAndreas Gohr        } else {
9744b0d3916SAndreas Gohr            echo $out;
97554e95700STom N Harris            return true;
9766b13307fSandi        }
9774b0d3916SAndreas Gohr    }
97854e95700STom N Harris    return false;
9796b13307fSandi}
9806b13307fSandi
981820fa24bSandi/**
982a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
98387c434ceSAndreas Gohr *
98487c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
985a6598f23SBen Coburn * the given ID is used.
98687c434ceSAndreas Gohr *
98787c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
988ac7a515fSAndreas Gohr * @param string $id page id
989ac7a515fSAndreas Gohr * @param bool   $ret return content instead of printing
990ac7a515fSAndreas Gohr * @return bool|string
99187c434ceSAndreas Gohr */
992a6598f23SBen Coburnfunction tpl_pagetitle($id = null, $ret = false) {
99387c434ceSAndreas Gohr    if(is_null($id)) {
99487c434ceSAndreas Gohr        global $ID;
99587c434ceSAndreas Gohr        $id = $ID;
99687c434ceSAndreas Gohr    }
99787c434ceSAndreas Gohr
99887c434ceSAndreas Gohr    $name = $id;
999fe9ec250SChris Smith    if(useHeading('navigation')) {
100087c434ceSAndreas Gohr        $title = p_get_first_heading($id);
100187c434ceSAndreas Gohr        if($title) $name = $title;
100287c434ceSAndreas Gohr    }
1003a6598f23SBen Coburn
1004a6598f23SBen Coburn    if($ret) {
1005a6598f23SBen Coburn        return hsc($name);
1006a6598f23SBen Coburn    } else {
100787c434ceSAndreas Gohr        print hsc($name);
100854e95700STom N Harris        return true;
100987c434ceSAndreas Gohr    }
1010a6598f23SBen Coburn}
1011340756e4Sandi
101255efc227SAndreas Gohr/**
101355efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
101455efc227SAndreas Gohr *
101555efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
101655efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
101755efc227SAndreas Gohr *
101855efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
101955efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
102055efc227SAndreas Gohr * to the names of the latter one)
102155efc227SAndreas Gohr *
10223df72098SAndreas Gohr * Only allowed in: detail.php
102355efc227SAndreas Gohr *
102455efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1025ac7a515fSAndreas Gohr * @param array  $tags tags to try
1026ac7a515fSAndreas Gohr * @param string $alt alternative output if no data was found
1027ac7a515fSAndreas Gohr * @param null   $src the image src, uses global $SRC if not given
1028ac7a515fSAndreas Gohr * @return string
102955efc227SAndreas Gohr */
10303df72098SAndreas Gohrfunction tpl_img_getTag($tags, $alt = '', $src = null) {
103155efc227SAndreas Gohr    // Init Exif Reader
103255efc227SAndreas Gohr    global $SRC;
10333df72098SAndreas Gohr
10343df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
10353df72098SAndreas Gohr
103655efc227SAndreas Gohr    static $meta = null;
10373df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
103855efc227SAndreas Gohr    if($meta === false) return $alt;
103955efc227SAndreas Gohr    $info = $meta->getField($tags);
104055efc227SAndreas Gohr    if($info == false) return $alt;
104155efc227SAndreas Gohr    return $info;
104255efc227SAndreas Gohr}
104355efc227SAndreas Gohr
104455efc227SAndreas Gohr/**
1045*becfa414SGerrit Uitslag * Returns a description list of the metatags of the current image
1046*becfa414SGerrit Uitslag *
1047*becfa414SGerrit Uitslag * @return string html of description list
1048*becfa414SGerrit Uitslag */
1049*becfa414SGerrit Uitslagfunction tpl_img_meta() {
1050*becfa414SGerrit Uitslag    global $lang;
1051*becfa414SGerrit Uitslag
1052*becfa414SGerrit Uitslag    $tags = tpl_get_img_meta();
1053*becfa414SGerrit Uitslag
1054*becfa414SGerrit Uitslag    echo '<dl>';
1055*becfa414SGerrit Uitslag    foreach($tags as $tag) {
1056*becfa414SGerrit Uitslag        $label = $lang[$tag['langkey']];
1057*becfa414SGerrit Uitslag        if(!$label) $label = $tag['langkey'];
1058*becfa414SGerrit Uitslag
1059*becfa414SGerrit Uitslag        echo '<dt>'.$label.':</dt><dd>';
1060*becfa414SGerrit Uitslag        if ($tag['type'] == 'date') {
1061*becfa414SGerrit Uitslag            echo dformat($tag['value']);
1062*becfa414SGerrit Uitslag        } else {
1063*becfa414SGerrit Uitslag            echo hsc($tag['value']);
1064*becfa414SGerrit Uitslag        }
1065*becfa414SGerrit Uitslag        echo '</dd>';
1066*becfa414SGerrit Uitslag    }
1067*becfa414SGerrit Uitslag    echo '</dl>';
1068*becfa414SGerrit Uitslag}
1069*becfa414SGerrit Uitslag
1070*becfa414SGerrit Uitslag/**
1071*becfa414SGerrit Uitslag * Returns metadata as configured in mediameta config file, ready for creating html
1072*becfa414SGerrit Uitslag *
1073*becfa414SGerrit Uitslag * @return array with arrays containing the entries:
1074*becfa414SGerrit Uitslag *   - string langkey  key to lookup in the $lang var, if not found printed as is
1075*becfa414SGerrit Uitslag *   - string type     type of value
1076*becfa414SGerrit Uitslag *   - string value    tag value (unescaped)
1077*becfa414SGerrit Uitslag */
1078*becfa414SGerrit Uitslagfunction tpl_get_img_meta() {
1079*becfa414SGerrit Uitslag
1080*becfa414SGerrit Uitslag    $config_files = getConfigFiles('mediameta');
1081*becfa414SGerrit Uitslag    foreach ($config_files as $config_file) {
1082*becfa414SGerrit Uitslag        if(@file_exists($config_file)) {
1083*becfa414SGerrit Uitslag            include($config_file);
1084*becfa414SGerrit Uitslag        }
1085*becfa414SGerrit Uitslag    }
1086*becfa414SGerrit Uitslag    /** @var array $fields the included array with metadata */
1087*becfa414SGerrit Uitslag
1088*becfa414SGerrit Uitslag    $tags = array();
1089*becfa414SGerrit Uitslag    foreach($fields as $tag){
1090*becfa414SGerrit Uitslag        $t = array();
1091*becfa414SGerrit Uitslag        if (!empty($tag[0])) {
1092*becfa414SGerrit Uitslag            $t = array($tag[0]);
1093*becfa414SGerrit Uitslag        }
1094*becfa414SGerrit Uitslag        if(is_array($tag[3])) {
1095*becfa414SGerrit Uitslag            $t = array_merge($t,$tag[3]);
1096*becfa414SGerrit Uitslag        }
1097*becfa414SGerrit Uitslag        $value = tpl_img_getTag($t);
1098*becfa414SGerrit Uitslag        if ($value) {
1099*becfa414SGerrit Uitslag            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
1100*becfa414SGerrit Uitslag        }
1101*becfa414SGerrit Uitslag    }
1102*becfa414SGerrit Uitslag    return $tags;
1103*becfa414SGerrit Uitslag}
1104*becfa414SGerrit Uitslag
1105*becfa414SGerrit Uitslag/**
110655efc227SAndreas Gohr * Prints the image with a link to the full sized version
110755efc227SAndreas Gohr *
110855efc227SAndreas Gohr * Only allowed in: detail.php
1109a02d2933SAndreas Gohr *
1110ac7a515fSAndreas Gohr * @triggers TPL_IMG_DISPLAY
1111a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
1112a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
1113a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
1114a02d2933SAndreas Gohr * @param $params array  - additional image attributes
1115ac7a515fSAndreas Gohr * @return mixed Result of TPL_IMG_DISPLAY
111655efc227SAndreas Gohr */
1117a02d2933SAndreas Gohrfunction tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
111855efc227SAndreas Gohr    global $IMG;
1119ac7a515fSAndreas Gohr    global $INPUT;
112055efc227SAndreas Gohr    $w = tpl_img_getTag('File.Width');
112155efc227SAndreas Gohr    $h = tpl_img_getTag('File.Height');
112255efc227SAndreas Gohr
112355efc227SAndreas Gohr    //resize to given max values
112423a34783SAndreas Gohr    $ratio = 1;
112523a34783SAndreas Gohr    if($w >= $h) {
1126f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth) {
112755efc227SAndreas Gohr            $ratio = $maxwidth / $w;
1128f8925855Sjoe.lapp        } elseif($maxheight && $h > $maxheight) {
112955efc227SAndreas Gohr            $ratio = $maxheight / $h;
113055efc227SAndreas Gohr        }
113155efc227SAndreas Gohr    } else {
1132f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight) {
113355efc227SAndreas Gohr            $ratio = $maxheight / $h;
1134f8925855Sjoe.lapp        } elseif($maxwidth && $w > $maxwidth) {
113555efc227SAndreas Gohr            $ratio = $maxwidth / $w;
113655efc227SAndreas Gohr        }
113755efc227SAndreas Gohr    }
113855efc227SAndreas Gohr    if($ratio) {
113955efc227SAndreas Gohr        $w = floor($ratio * $w);
114055efc227SAndreas Gohr        $h = floor($ratio * $h);
114155efc227SAndreas Gohr    }
114255efc227SAndreas Gohr
11436de3759aSAndreas Gohr    //prepare URLs
1144ac7a515fSAndreas Gohr    $url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&');
1145ac7a515fSAndreas Gohr    $src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&');
114655efc227SAndreas Gohr
11472684e50aSAndreas Gohr    //prepare attributes
114855efc227SAndreas Gohr    $alt = tpl_img_getTag('Simple.Title');
1149a02d2933SAndreas Gohr    if(is_null($params)) {
11502684e50aSAndreas Gohr        $p = array();
1151a02d2933SAndreas Gohr    } else {
1152a02d2933SAndreas Gohr        $p = $params;
1153a02d2933SAndreas Gohr    }
11542684e50aSAndreas Gohr    if($w) $p['width'] = $w;
11552684e50aSAndreas Gohr    if($h) $p['height'] = $h;
11562684e50aSAndreas Gohr    $p['class'] = 'img_detail';
11572684e50aSAndreas Gohr    if($alt) {
11582684e50aSAndreas Gohr        $p['alt']   = $alt;
11592684e50aSAndreas Gohr        $p['title'] = $alt;
11602684e50aSAndreas Gohr    } else {
11612684e50aSAndreas Gohr        $p['alt'] = '';
11622684e50aSAndreas Gohr    }
1163a02d2933SAndreas Gohr    $p['src'] = $src;
116455efc227SAndreas Gohr
1165a02d2933SAndreas Gohr    $data = array('url'=> ($link ? $url : null), 'params'=> $p);
1166a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
1167a02d2933SAndreas Gohr}
1168a02d2933SAndreas Gohr
1169a02d2933SAndreas Gohr/**
1170a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
1171ac7a515fSAndreas Gohr *
1172ac7a515fSAndreas Gohr * @param array $data
1173ac7a515fSAndreas Gohr * @return bool
1174a02d2933SAndreas Gohr */
1175ac7a515fSAndreas Gohrfunction _tpl_img_action($data) {
117659f3611bSAnika Henke    global $lang;
1177a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
1178a02d2933SAndreas Gohr
117959f3611bSAnika Henke    if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
1180a02d2933SAndreas Gohr    print '<img '.$p.'/>';
1181a02d2933SAndreas Gohr    if($data['url']) print '</a>';
118254e95700STom N Harris    return true;
118355efc227SAndreas Gohr}
118455efc227SAndreas Gohr
11857367b368SAndreas Gohr/**
1186881f2ee2SAndreas Haerter * This function inserts a small gif which in reality is the indexer function.
11877367b368SAndreas Gohr *
11887367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11897367b368SAndreas Gohr * template
1190ac7a515fSAndreas Gohr *
1191ac7a515fSAndreas Gohr * @return bool
11927367b368SAndreas Gohr */
11937367b368SAndreas Gohrfunction tpl_indexerWebBug() {
11947367b368SAndreas Gohr    global $ID;
11951dad36f5SAndreas Gohr
11967367b368SAndreas Gohr    $p           = array();
1197b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1198e68c51baSAndreas Gohr        '&'.time();
1199881f2ee2SAndreas Haerter    $p['width']  = 2; //no more 1x1 px image because we live in times of ad blockers...
12007367b368SAndreas Gohr    $p['height'] = 1;
12017367b368SAndreas Gohr    $p['alt']    = '';
12027367b368SAndreas Gohr    $att         = buildAttributes($p);
12037367b368SAndreas Gohr    print "<img $att />";
120454e95700STom N Harris    return true;
12057367b368SAndreas Gohr}
12067367b368SAndreas Gohr
120778d4e784SEsther Brunner/**
120878d4e784SEsther Brunner * tpl_getConf($id)
120978d4e784SEsther Brunner *
121078d4e784SEsther Brunner * use this function to access template configuration variables
1211ac7a515fSAndreas Gohr *
121217448fb8SChristopher Smith * @param string $id      name of the value to access
121317448fb8SChristopher Smith * @param mixed  $notset  what to return if the setting is not available
121417448fb8SChristopher Smith * @return mixed
121578d4e784SEsther Brunner */
121617448fb8SChristopher Smithfunction tpl_getConf($id, $notset=false) {
121778d4e784SEsther Brunner    global $conf;
121817566ac6SAdrian Lang    static $tpl_configloaded = false;
121978d4e784SEsther Brunner
122078d4e784SEsther Brunner    $tpl = $conf['template'];
122178d4e784SEsther Brunner
122278d4e784SEsther Brunner    if(!$tpl_configloaded) {
122378d4e784SEsther Brunner        $tconf = tpl_loadConfig();
122478d4e784SEsther Brunner        if($tconf !== false) {
122578d4e784SEsther Brunner            foreach($tconf as $key => $value) {
122678d4e784SEsther Brunner                if(isset($conf['tpl'][$tpl][$key])) continue;
122778d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
122878d4e784SEsther Brunner            }
122978d4e784SEsther Brunner            $tpl_configloaded = true;
123078d4e784SEsther Brunner        }
123178d4e784SEsther Brunner    }
123278d4e784SEsther Brunner
123317448fb8SChristopher Smith    if(isset($conf['tpl'][$tpl][$id])){
123478d4e784SEsther Brunner        return $conf['tpl'][$tpl][$id];
123578d4e784SEsther Brunner    }
123678d4e784SEsther Brunner
123717448fb8SChristopher Smith    return $notset;
123817448fb8SChristopher Smith}
123917448fb8SChristopher Smith
124078d4e784SEsther Brunner/**
124178d4e784SEsther Brunner * tpl_loadConfig()
1242ac7a515fSAndreas Gohr *
124378d4e784SEsther Brunner * reads all template configuration variables
124478d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
1245ac7a515fSAndreas Gohr *
1246ac7a515fSAndreas Gohr * @return array
124778d4e784SEsther Brunner */
124878d4e784SEsther Brunnerfunction tpl_loadConfig() {
124978d4e784SEsther Brunner
1250c4766956SAndreas Gohr    $file = tpl_incdir().'/conf/default.php';
125178d4e784SEsther Brunner    $conf = array();
125278d4e784SEsther Brunner
125378d4e784SEsther Brunner    if(!@file_exists($file)) return false;
125478d4e784SEsther Brunner
125578d4e784SEsther Brunner    // load default config file
125678d4e784SEsther Brunner    include($file);
125778d4e784SEsther Brunner
125878d4e784SEsther Brunner    return $conf;
125978d4e784SEsther Brunner}
126078d4e784SEsther Brunner
126117566ac6SAdrian Lang// language methods
126217566ac6SAdrian Lang/**
126317566ac6SAdrian Lang * tpl_getLang($id)
126417566ac6SAdrian Lang *
126517566ac6SAdrian Lang * use this function to access template language variables
126617566ac6SAdrian Lang */
126717566ac6SAdrian Langfunction tpl_getLang($id) {
126817566ac6SAdrian Lang    static $lang = array();
126917566ac6SAdrian Lang
127017566ac6SAdrian Lang    if(count($lang) === 0) {
1271c4766956SAndreas Gohr        $path = tpl_incdir().'lang/';
127217566ac6SAdrian Lang
127317566ac6SAdrian Lang        $lang = array();
127417566ac6SAdrian Lang
127517566ac6SAdrian Lang        global $conf; // definitely don't invoke "global $lang"
127617566ac6SAdrian Lang        // don't include once
127717566ac6SAdrian Lang        @include($path.'en/lang.php');
127817566ac6SAdrian Lang        if($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
127917566ac6SAdrian Lang    }
128017566ac6SAdrian Lang
128117566ac6SAdrian Lang    return $lang[$id];
128217566ac6SAdrian Lang}
128317566ac6SAdrian Lang
12843df72098SAndreas Gohr/**
1285c5c17fdaSKlap-in * Retrieve a language dependent file and pass to xhtml renderer for display
1286e8ec13b9SKlap-in * template equivalent of p_locale_xhtml()
1287e8ec13b9SKlap-in *
1288e8ec13b9SKlap-in * @param   string $id id of language dependent wiki page
1289e8ec13b9SKlap-in * @return  string     parsed contents of the wiki page in xhtml format
1290e8ec13b9SKlap-in */
1291e8ec13b9SKlap-infunction tpl_locale_xhtml($id) {
1292c5c17fdaSKlap-in    return p_cached_output(tpl_localeFN($id));
1293e8ec13b9SKlap-in}
1294e8ec13b9SKlap-in
1295e8ec13b9SKlap-in/**
1296c5c17fdaSKlap-in * Prepends appropriate path for a language dependent filename
1297e8ec13b9SKlap-in */
1298c5c17fdaSKlap-infunction tpl_localeFN($id) {
1299e8ec13b9SKlap-in    $path = tpl_incdir().'lang/';
1300e8ec13b9SKlap-in    global $conf;
1301e8ec13b9SKlap-in    $file = DOKU_CONF.'/template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
1302e8ec13b9SKlap-in    if (!@file_exists($file)){
1303e8ec13b9SKlap-in        $file = $path.$conf['lang'].'/'.$id.'.txt';
1304e8ec13b9SKlap-in        if(!@file_exists($file)){
1305e8ec13b9SKlap-in            //fall back to english
1306e8ec13b9SKlap-in            $file = $path.'en/'.$id.'.txt';
1307e8ec13b9SKlap-in        }
1308e8ec13b9SKlap-in    }
1309e8ec13b9SKlap-in    return $file;
1310e8ec13b9SKlap-in}
1311e8ec13b9SKlap-in
1312e8ec13b9SKlap-in/**
13133df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
13143df72098SAndreas Gohr *
13153df72098SAndreas Gohr * Depending on the user's actions this may be a list of
13163df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
13173df72098SAndreas Gohr * a message of referencing pages
13183df72098SAndreas Gohr *
13193df72098SAndreas Gohr * Only allowed in mediamanager.php
13203df72098SAndreas Gohr *
1321c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1322c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
13233df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
13243df72098SAndreas Gohr */
132500e3e394SChristopher Smithfunction tpl_mediaContent($fromajax = false, $sort='natural') {
13263df72098SAndreas Gohr    global $IMG;
13273df72098SAndreas Gohr    global $AUTH;
13283df72098SAndreas Gohr    global $INUSE;
13293df72098SAndreas Gohr    global $NS;
13303df72098SAndreas Gohr    global $JUMPTO;
1331ac7a515fSAndreas Gohr    global $INPUT;
13323df72098SAndreas Gohr
1333ac7a515fSAndreas Gohr    $do = $INPUT->extract('do')->str('do');
1334c182313eSAndreas Gohr    if(in_array($do, array('save', 'cancel'))) $do = '';
1335c182313eSAndreas Gohr
1336c182313eSAndreas Gohr    if(!$do) {
1337ac7a515fSAndreas Gohr        if($INPUT->bool('edit')) {
1338c182313eSAndreas Gohr            $do = 'metaform';
1339c182313eSAndreas Gohr        } elseif(is_array($INUSE)) {
1340c182313eSAndreas Gohr            $do = 'filesinuse';
1341c182313eSAndreas Gohr        } else {
1342c182313eSAndreas Gohr            $do = 'filelist';
1343c182313eSAndreas Gohr        }
1344c182313eSAndreas Gohr    }
1345c182313eSAndreas Gohr
1346c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1347c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1348c182313eSAndreas Gohr    $data = array('do' => $do);
1349c182313eSAndreas Gohr    $evt  = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1350c182313eSAndreas Gohr    if($evt->advise_before()) {
1351c182313eSAndreas Gohr        $do = $data['do'];
135230fd72fbSKate Arzamastseva        if($do == 'filesinuse') {
1353c182313eSAndreas Gohr            media_filesinuse($INUSE, $IMG);
1354c182313eSAndreas Gohr        } elseif($do == 'filelist') {
135500e3e394SChristopher Smith            media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
1356c9f56829SAndreas Gohr        } elseif($do == 'searchlist') {
1357ac7a515fSAndreas Gohr            media_searchlist($INPUT->str('q'), $NS, $AUTH);
1358c182313eSAndreas Gohr        } else {
1359c182313eSAndreas Gohr            msg('Unknown action '.hsc($do), -1);
1360c182313eSAndreas Gohr        }
1361c182313eSAndreas Gohr    }
1362c182313eSAndreas Gohr    $evt->advise_after();
1363c182313eSAndreas Gohr    unset($evt);
1364c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1365c182313eSAndreas Gohr
13663df72098SAndreas Gohr}
13673df72098SAndreas Gohr
13683df72098SAndreas Gohr/**
1369d9162c6cSKate Arzamastseva * Prints the central column in full-screen media manager
1370d9162c6cSKate Arzamastseva * Depending on the opened tab this may be a list of
1371d9162c6cSKate Arzamastseva * files in a namespace, upload form or search form
1372d9162c6cSKate Arzamastseva *
1373d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1374d9162c6cSKate Arzamastseva */
1375035e07f1SKate Arzamastsevafunction tpl_mediaFileList() {
1376d9162c6cSKate Arzamastseva    global $AUTH;
1377d9162c6cSKate Arzamastseva    global $NS;
1378d9162c6cSKate Arzamastseva    global $JUMPTO;
137995b451bcSAdrian Lang    global $lang;
1380ac7a515fSAndreas Gohr    global $INPUT;
1381d9162c6cSKate Arzamastseva
1382ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_files');
1383e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
1384ac7a515fSAndreas Gohr    if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
1385d9162c6cSKate Arzamastseva
138694add303SAnika Henke    echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
138795b451bcSAdrian Lang
1388ed69a2aeSKate Arzamastseva    media_tabs_files($opened_tab);
138923846a98SKate Arzamastseva
139094add303SAnika Henke    echo '<div class="panelHeader">'.NL;
139195b451bcSAdrian Lang    echo '<h3>';
1392026d14a9SAnika Henke    $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
1393c98f205eSAdrian Lang    printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
139494add303SAnika Henke    echo '</h3>'.NL;
139595b451bcSAdrian Lang    if($opened_tab === 'search' || $opened_tab === 'files') {
139695b451bcSAdrian Lang        media_tab_files_options();
139723846a98SKate Arzamastseva    }
139894add303SAnika Henke    echo '</div>'.NL;
1399d9162c6cSKate Arzamastseva
140094add303SAnika Henke    echo '<div class="panelContent">'.NL;
140195b451bcSAdrian Lang    if($opened_tab == 'files') {
140295b451bcSAdrian Lang        media_tab_files($NS, $AUTH, $JUMPTO);
140395b451bcSAdrian Lang    } elseif($opened_tab == 'upload') {
140495b451bcSAdrian Lang        media_tab_upload($NS, $AUTH, $JUMPTO);
140595b451bcSAdrian Lang    } elseif($opened_tab == 'search') {
140695b451bcSAdrian Lang        media_tab_search($NS, $AUTH);
140795b451bcSAdrian Lang    }
140894add303SAnika Henke    echo '</div>'.NL;
1409d9162c6cSKate Arzamastseva}
1410d9162c6cSKate Arzamastseva
1411d9162c6cSKate Arzamastseva/**
1412d9162c6cSKate Arzamastseva * Prints the third column in full-screen media manager
1413d9162c6cSKate Arzamastseva * Depending on the opened tab this may be details of the
1414d9162c6cSKate Arzamastseva * selected file, the meta editing dialog or
1415d9162c6cSKate Arzamastseva * list of file revisions
1416d9162c6cSKate Arzamastseva *
1417d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1418d9162c6cSKate Arzamastseva */
1419035e07f1SKate Arzamastsevafunction tpl_mediaFileDetails($image, $rev) {
1420ac7a515fSAndreas Gohr    global $AUTH, $NS, $conf, $DEL, $lang, $INPUT;
1421d9162c6cSKate Arzamastseva
142292cac9a9SKate Arzamastseva    $removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1423ac7a515fSAndreas Gohr    if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
14246dd095f5SKate Arzamastseva    if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1425ac7a515fSAndreas Gohr    if(isset($NS) && getNS($image) != $NS) return;
1426ac7a515fSAndreas Gohr    $do = $INPUT->str('mediado');
14271eeeced2SKate Arzamastseva
1428ac7a515fSAndreas Gohr    $opened_tab = $INPUT->str('tab_details');
1429e5d185e1SKate Arzamastseva
1430e5d185e1SKate Arzamastseva    $tab_array = array('view');
1431ac7a515fSAndreas Gohr    list(, $mime) = mimetype($image);
1432e5d185e1SKate Arzamastseva    if($mime == 'image/jpeg') {
1433e5d185e1SKate Arzamastseva        $tab_array[] = 'edit';
1434e5d185e1SKate Arzamastseva    }
1435e5d185e1SKate Arzamastseva    if($conf['mediarevisions']) {
1436e5d185e1SKate Arzamastseva        $tab_array[] = 'history';
1437e5d185e1SKate Arzamastseva    }
1438e5d185e1SKate Arzamastseva
1439e5d185e1SKate Arzamastseva    if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
1440ac7a515fSAndreas Gohr    if($INPUT->bool('edit')) $opened_tab = 'edit';
144123846a98SKate Arzamastseva    if($do == 'restore') $opened_tab = 'view';
1442d9162c6cSKate Arzamastseva
1443ed69a2aeSKate Arzamastseva    media_tabs_details($image, $opened_tab);
144423846a98SKate Arzamastseva
144559f3611bSAnika Henke    echo '<div class="panelHeader"><h3>';
1446ac7a515fSAndreas Gohr    list($ext) = mimetype($image, false);
144795b451bcSAdrian Lang    $class    = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
144895b451bcSAdrian Lang    $class    = 'select mediafile mf_'.$class;
144900c2d4a9SAnika Henke    $tabTitle = '<strong><a href="'.ml($image).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>';
145008317413SAdrian Lang    if($opened_tab === 'view' && $rev) {
145108317413SAdrian Lang        printf($lang['media_viewold'], $tabTitle, dformat($rev));
145208317413SAdrian Lang    } else {
1453026d14a9SAnika Henke        printf($lang['media_'.$opened_tab], $tabTitle);
145408317413SAdrian Lang    }
1455b8a84c03SAndreas Gohr
145694add303SAnika Henke    echo '</h3></div>'.NL;
145795b451bcSAdrian Lang
145894add303SAnika Henke    echo '<div class="panelContent">'.NL;
145995b451bcSAdrian Lang
146023846a98SKate Arzamastseva    if($opened_tab == 'view') {
146123846a98SKate Arzamastseva        media_tab_view($image, $NS, $AUTH, $rev);
146223846a98SKate Arzamastseva
146392cac9a9SKate Arzamastseva    } elseif($opened_tab == 'edit' && !$removed) {
146423846a98SKate Arzamastseva        media_tab_edit($image, $NS, $AUTH);
146523846a98SKate Arzamastseva
1466e5d185e1SKate Arzamastseva    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
146710799f9cSKate Arzamastseva        media_tab_history($image, $NS, $AUTH);
146823846a98SKate Arzamastseva    }
146995b451bcSAdrian Lang
147094add303SAnika Henke    echo '</div>'.NL;
1471d9162c6cSKate Arzamastseva}
1472d9162c6cSKate Arzamastseva
1473d9162c6cSKate Arzamastseva/**
14743df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
14753df72098SAndreas Gohr *
14763df72098SAndreas Gohr * Only allowed in mediamanager.php
14773df72098SAndreas Gohr *
14783df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
14793df72098SAndreas Gohr */
1480fa8e5c77SKate Arzamastsevafunction tpl_mediaTree() {
14813df72098SAndreas Gohr    global $NS;
148223846a98SKate Arzamastseva    ptln('<div id="media__tree">');
14833df72098SAndreas Gohr    media_nstree($NS);
14843df72098SAndreas Gohr    ptln('</div>');
14853df72098SAndreas Gohr}
14863df72098SAndreas Gohr
1487a00de5b5SAndreas Gohr/**
1488a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1489a00de5b5SAndreas Gohr *
1490a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1491a00de5b5SAndreas Gohr *
1492a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1493a00de5b5SAndreas Gohr */
1494a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty = '', $button = '&gt;') {
1495a00de5b5SAndreas Gohr    global $ID;
1496a00de5b5SAndreas Gohr    global $REV;
1497a00de5b5SAndreas Gohr    global $lang;
1498a00de5b5SAndreas Gohr
1499e63eccffSAndreas Gohr    echo '<form action="'.script().'" method="get" accept-charset="utf-8">';
15003b9a3b55SAnika Henke    echo '<div class="no">';
1501a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1502a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1503443e135dSChristopher Smith    if (!empty($_SERVER['REMOTE_USER'])) {
1504a00de5b5SAndreas Gohr        echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
150561efcda1SChristopher Smith    }
1506a00de5b5SAndreas Gohr
15075f17c394SAnika Henke    echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">';
1508a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1509a00de5b5SAndreas Gohr
151061917024SAnika Henke    echo '<optgroup label="'.$lang['page_tools'].'">';
1511396c218fSAndreas Gohr    $act = tpl_get_action('edit');
1512396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1513a00de5b5SAndreas Gohr
1514396c218fSAndreas Gohr    $act = tpl_get_action('revert');
1515396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1516396c218fSAndreas Gohr
15173b9a3b55SAnika Henke    $act = tpl_get_action('revisions');
15183b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
15193b9a3b55SAnika Henke
1520396c218fSAndreas Gohr    $act = tpl_get_action('backlink');
1521396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
15223b9a3b55SAnika Henke
15233b9a3b55SAnika Henke    $act = tpl_get_action('subscribe');
15243b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1525a00de5b5SAndreas Gohr    echo '</optgroup>';
1526a00de5b5SAndreas Gohr
152761917024SAnika Henke    echo '<optgroup label="'.$lang['site_tools'].'">';
1528396c218fSAndreas Gohr    $act = tpl_get_action('recent');
1529396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1530396c218fSAndreas Gohr
15313b9a3b55SAnika Henke    $act = tpl_get_action('media');
15323b9a3b55SAnika Henke    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
15333b9a3b55SAnika Henke
1534396c218fSAndreas Gohr    $act = tpl_get_action('index');
1535396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1536a00de5b5SAndreas Gohr    echo '</optgroup>';
1537a00de5b5SAndreas Gohr
153861917024SAnika Henke    echo '<optgroup label="'.$lang['user_tools'].'">';
1539396c218fSAndreas Gohr    $act = tpl_get_action('login');
1540396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1541a00de5b5SAndreas Gohr
15423b9a3b55SAnika Henke    $act = tpl_get_action('register');
1543396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1544a00de5b5SAndreas Gohr
15453b9a3b55SAnika Henke    $act = tpl_get_action('profile');
1546396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1547a00de5b5SAndreas Gohr
1548396c218fSAndreas Gohr    $act = tpl_get_action('admin');
1549396c218fSAndreas Gohr    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1550a00de5b5SAndreas Gohr    echo '</optgroup>';
1551a00de5b5SAndreas Gohr
1552a00de5b5SAndreas Gohr    echo '</select>';
1553f22c1964SAndreas Gohr    echo '<input type="submit" value="'.$button.'" />';
15543b9a3b55SAnika Henke    echo '</div>';
1555a00de5b5SAndreas Gohr    echo '</form>';
1556a00de5b5SAndreas Gohr}
1557a00de5b5SAndreas Gohr
1558066fee30SAndreas Gohr/**
1559066fee30SAndreas Gohr * Print a informational line about the used license
1560066fee30SAndreas Gohr *
1561066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1562ac7a515fSAndreas Gohr * @param  string $img     print image? (|button|badge)
1563ac7a515fSAndreas Gohr * @param  bool   $imgonly skip the textual description?
1564ac7a515fSAndreas Gohr * @param  bool   $return  when true don't print, but return HTML
1565ac7a515fSAndreas Gohr * @param  bool   $wrap    wrap in div with class="license"?
1566ac7a515fSAndreas Gohr * @return string
1567066fee30SAndreas Gohr */
156880083a41SAndreas Gohrfunction tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
1569066fee30SAndreas Gohr    global $license;
1570066fee30SAndreas Gohr    global $conf;
1571066fee30SAndreas Gohr    global $lang;
1572066fee30SAndreas Gohr    if(!$conf['license']) return '';
1573066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1574066fee30SAndreas Gohr    $lic    = $license[$conf['license']];
157553e15c8bSAnika Henke    $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
1576066fee30SAndreas Gohr
157780083a41SAndreas Gohr    $out = '';
157880083a41SAndreas Gohr    if($wrap) $out .= '<div class="license">';
1579066fee30SAndreas Gohr    if($img) {
1580066fee30SAndreas Gohr        $src = license_img($img);
1581066fee30SAndreas Gohr        if($src) {
158253e15c8bSAnika Henke            $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
158353e15c8bSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
158453e15c8bSAnika Henke            if(!$imgonly) $out .= ' ';
1585066fee30SAndreas Gohr        }
1586066fee30SAndreas Gohr    }
15874cefd216SMichael Klier    if(!$imgonly) {
158853e15c8bSAnika Henke        $out .= $lang['license'].' ';
1589d317fb5dSAnika Henke        $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
1590d317fb5dSAnika Henke        $out .= '>'.$lic['name'].'</a></bdi>';
15914cefd216SMichael Klier    }
159280083a41SAndreas Gohr    if($wrap) $out .= '</div>';
1593066fee30SAndreas Gohr
1594066fee30SAndreas Gohr    if($return) return $out;
1595066fee30SAndreas Gohr    echo $out;
1596ac7a515fSAndreas Gohr    return '';
1597066fee30SAndreas Gohr}
1598066fee30SAndreas Gohr
1599a81910eeSAndreas Gohr/**
1600835dfcaeSAnika Henke * Includes the rendered HTML of a given page
1601a81910eeSAndreas Gohr *
1602a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1603a81910eeSAndreas Gohr * template
1604a81910eeSAndreas Gohr */
1605835dfcaeSAnika Henkefunction tpl_include_page($pageid, $print = true, $propagate = false) {
1606c786a1b6SAnika Henke    if (!$pageid) return false;
1607835dfcaeSAnika Henke    if ($propagate) $pageid = page_findnearest($pageid);
1608835dfcaeSAnika Henke
1609c786a1b6SAnika Henke    global $TOC;
16109a2e250aSAndreas Gohr    $oldtoc = $TOC;
1611a81910eeSAndreas Gohr    $html   = p_wiki_xhtml($pageid, '', false);
16129a2e250aSAndreas Gohr    $TOC    = $oldtoc;
1613a81910eeSAndreas Gohr
1614a81910eeSAndreas Gohr    if(!$print) return $html;
1615a81910eeSAndreas Gohr    echo $html;
1616e66d3e6dSAndreas Gohr    return $html;
1617e66d3e6dSAndreas Gohr}
1618e66d3e6dSAndreas Gohr
1619e66d3e6dSAndreas Gohr/**
16205b75cd1fSAdrian Lang * Display the subscribe form
16215b75cd1fSAdrian Lang *
16225b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
16235b75cd1fSAdrian Lang */
16245b75cd1fSAdrian Langfunction tpl_subscribe() {
16255b75cd1fSAdrian Lang    global $INFO;
16265b75cd1fSAdrian Lang    global $ID;
16275b75cd1fSAdrian Lang    global $lang;
16286b8f02cfSAdrian Lang    global $conf;
162940c347dbSAdrian Lang    $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
16305b75cd1fSAdrian Lang
16315b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
16325b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
163315741132SAndreas Gohr    echo '<div class="level2">';
16345b75cd1fSAdrian Lang    if($INFO['subscribed'] === false) {
16355b75cd1fSAdrian Lang        echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
16365b75cd1fSAdrian Lang    } else {
16375b75cd1fSAdrian Lang        echo '<ul>';
16385b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1639056c2049SAndreas Gohr            echo '<li><div class="li">';
16405b75cd1fSAdrian Lang            if($sub['target'] !== $ID) {
1641056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
16425b75cd1fSAdrian Lang            } else {
1643056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
16445b75cd1fSAdrian Lang            }
164540c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
164615741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1647056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
164815741132SAndreas Gohr
1649ac7a515fSAndreas Gohr            echo '<a href="'.wl(
1650ac7a515fSAndreas Gohr                $ID,
1651ac7a515fSAndreas Gohr                array(
1652ac7a515fSAndreas Gohr                     'do'        => 'subscribe',
165366d2bed9SAdrian Lang                     'sub_target'=> $sub['target'],
165466d2bed9SAdrian Lang                     'sub_style' => $sub['style'],
165566d2bed9SAdrian Lang                     'sub_action'=> 'unsubscribe',
1656ac7a515fSAndreas Gohr                     'sectok'    => getSecurityToken()
1657ac7a515fSAndreas Gohr                )
1658ac7a515fSAndreas Gohr            ).
165966d2bed9SAdrian Lang                '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
166066d2bed9SAdrian Lang                '</a></div></li>';
16615b75cd1fSAdrian Lang        }
16625b75cd1fSAdrian Lang        echo '</ul>';
16635b75cd1fSAdrian Lang    }
166415741132SAndreas Gohr    echo '</div>';
16655b75cd1fSAdrian Lang
166615741132SAndreas Gohr    // Add new subscription form
16675b75cd1fSAdrian Lang    echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
166815741132SAndreas Gohr    echo '<div class="level2">';
16695b75cd1fSAdrian Lang    $ns      = getNS($ID).':';
167015741132SAndreas Gohr    $targets = array(
167115741132SAndreas Gohr        $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
167215741132SAndreas Gohr        $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
167315741132SAndreas Gohr    );
167415741132SAndreas Gohr    $styles  = array(
167515741132SAndreas Gohr        'every'  => $lang['subscr_style_every'],
16766b8f02cfSAdrian Lang        'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
16776b8f02cfSAdrian Lang        'list'   => sprintf($lang['subscr_style_list'], $stime_days),
167815741132SAndreas Gohr    );
167915741132SAndreas Gohr
1680056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1681056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1682056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1683056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1684056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1685056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1686056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1687056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1688056c2049SAndreas Gohr    $form->endFieldset();
16895b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
16905b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
169115741132SAndreas Gohr    echo '</div>';
16925b75cd1fSAdrian Lang}
16935b75cd1fSAdrian Lang
1694d059ba9bSAndreas Gohr/**
1695d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1696d059ba9bSAndreas Gohr *
1697d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1698d059ba9bSAndreas Gohr *
1699d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1700d059ba9bSAndreas Gohr */
1701d059ba9bSAndreas Gohrfunction tpl_flush() {
1702d059ba9bSAndreas Gohr    ob_flush();
1703d059ba9bSAndreas Gohr    flush();
1704d059ba9bSAndreas Gohr}
1705d059ba9bSAndreas Gohr
1706afca7e7eSAnika Henke/**
1707378325f9SAndreas Gohr * Tries to find a ressource file in the given locations.
1708afca7e7eSAnika Henke *
1709378325f9SAndreas Gohr * If a given location starts with a colon it is assumed to be a media
1710378325f9SAndreas Gohr * file, otherwise it is assumed to be relative to the current template
1711378325f9SAndreas Gohr *
1712378325f9SAndreas Gohr * @param  array $search       locations to look at
1713378325f9SAndreas Gohr * @param  bool  $abs           if to use absolute URL
1714ac7a515fSAndreas Gohr * @param  array &$imginfo   filled with getimagesize()
1715ac7a515fSAndreas Gohr * @return string
1716378325f9SAndreas Gohr * @author Andreas  Gohr <andi@splitbrain.org>
1717afca7e7eSAnika Henke */
1718378325f9SAndreas Gohrfunction tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1719ac7a515fSAndreas Gohr    $img     = '';
1720ac7a515fSAndreas Gohr    $file    = '';
1721ac7a515fSAndreas Gohr    $ismedia = false;
1722378325f9SAndreas Gohr    // loop through candidates until a match was found:
1723378325f9SAndreas Gohr    foreach($search as $img) {
1724378325f9SAndreas Gohr        if(substr($img, 0, 1) == ':') {
1725378325f9SAndreas Gohr            $file    = mediaFN($img);
1726378325f9SAndreas Gohr            $ismedia = true;
1727378325f9SAndreas Gohr        } else {
1728c4766956SAndreas Gohr            $file    = tpl_incdir().$img;
1729378325f9SAndreas Gohr            $ismedia = false;
17301f13e33dSAnika Henke        }
17310f747863Slupo49
1732378325f9SAndreas Gohr        if(file_exists($file)) break;
1733872a6d29SAnika Henke    }
1734378325f9SAndreas Gohr
1735378325f9SAndreas Gohr    // fetch image data if requested
1736378325f9SAndreas Gohr    if(!is_null($imginfo)) {
1737378325f9SAndreas Gohr        $imginfo = getimagesize($file);
1738378325f9SAndreas Gohr    }
1739378325f9SAndreas Gohr
1740378325f9SAndreas Gohr    // build URL
1741378325f9SAndreas Gohr    if($ismedia) {
1742378325f9SAndreas Gohr        $url = ml($img, '', true, '', $abs);
1743378325f9SAndreas Gohr    } else {
1744c4766956SAndreas Gohr        $url = tpl_basedir().$img;
1745378325f9SAndreas Gohr        if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
1746378325f9SAndreas Gohr    }
1747378325f9SAndreas Gohr
1748378325f9SAndreas Gohr    return $url;
1749a7e5f74cSlupo49}
17501f13e33dSAnika Henke
1751872a6d29SAnika Henke/**
1752e5d4768dSAndreas Gohr * PHP include a file
1753e5d4768dSAndreas Gohr *
1754e5d4768dSAndreas Gohr * either from the conf directory if it exists, otherwise use
1755e5d4768dSAndreas Gohr * file in the template's root directory.
1756e5d4768dSAndreas Gohr *
1757e5d4768dSAndreas Gohr * The function honours config cascade settings and looks for the given
1758e5d4768dSAndreas Gohr * file next to the ´main´ config files, in the order protected, local,
1759e5d4768dSAndreas Gohr * default.
1760e5d4768dSAndreas Gohr *
1761e5d4768dSAndreas Gohr * Note: no escaping or sanity checking is done here. Never pass user input
1762e5d4768dSAndreas Gohr * to this function!
1763e5d4768dSAndreas Gohr *
1764e5d4768dSAndreas Gohr * @author Anika Henke <anika@selfthinker.org>
1765e5d4768dSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1766e5d4768dSAndreas Gohr */
1767e5d4768dSAndreas Gohrfunction tpl_includeFile($file) {
1768e5d4768dSAndreas Gohr    global $config_cascade;
1769e5d4768dSAndreas Gohr    foreach(array('protected', 'local', 'default') as $config_group) {
1770e5d4768dSAndreas Gohr        if(empty($config_cascade['main'][$config_group])) continue;
1771e5d4768dSAndreas Gohr        foreach($config_cascade['main'][$config_group] as $conf_file) {
1772e5d4768dSAndreas Gohr            $dir = dirname($conf_file);
1773e5d4768dSAndreas Gohr            if(file_exists("$dir/$file")) {
1774f3a1225fSAnika Henke                include("$dir/$file");
1775e5d4768dSAndreas Gohr                return;
1776e5d4768dSAndreas Gohr            }
1777e5d4768dSAndreas Gohr        }
1778e5d4768dSAndreas Gohr    }
1779e5d4768dSAndreas Gohr
1780e5d4768dSAndreas Gohr    // still here? try the template dir
1781e5d4768dSAndreas Gohr    $file = tpl_incdir().$file;
1782e5d4768dSAndreas Gohr    if(file_exists($file)) {
1783f3a1225fSAnika Henke        include($file);
1784e5d4768dSAndreas Gohr    }
1785e5d4768dSAndreas Gohr}
1786e5d4768dSAndreas Gohr
1787e5d4768dSAndreas Gohr/**
1788872a6d29SAnika Henke * Returns <link> tag for various icon types (favicon|mobile|generic)
1789872a6d29SAnika Henke *
1790872a6d29SAnika Henke * @author Anika Henke <anika@selfthinker.org>
1791ac7a515fSAndreas Gohr * @param  array $types - list of icon types to display (favicon|mobile|generic)
1792ac7a515fSAndreas Gohr * @return string
1793872a6d29SAnika Henke */
1794872a6d29SAnika Henkefunction tpl_favicon($types = array('favicon')) {
1795872a6d29SAnika Henke
1796872a6d29SAnika Henke    $return = '';
1797872a6d29SAnika Henke
1798872a6d29SAnika Henke    foreach($types as $type) {
1799872a6d29SAnika Henke        switch($type) {
1800872a6d29SAnika Henke            case 'favicon':
1801378325f9SAndreas Gohr                $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
1802378325f9SAndreas Gohr                $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1803872a6d29SAnika Henke                break;
1804872a6d29SAnika Henke            case 'mobile':
1805cab75975SAnika Henke                $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.png');
1806378325f9SAndreas Gohr                $return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
1807872a6d29SAnika Henke                break;
1808872a6d29SAnika Henke            case 'generic':
1809872a6d29SAnika Henke                // ideal world solution, which doesn't work in any browser yet
1810378325f9SAndreas Gohr                $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
1811378325f9SAndreas Gohr                $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
1812872a6d29SAnika Henke                break;
1813872a6d29SAnika Henke        }
1814872a6d29SAnika Henke    }
1815872a6d29SAnika Henke
1816872a6d29SAnika Henke    return $return;
1817afca7e7eSAnika Henke}
1818afca7e7eSAnika Henke
1819d9162c6cSKate Arzamastseva/**
1820d9162c6cSKate Arzamastseva * Prints full-screen media manager
1821d9162c6cSKate Arzamastseva *
1822d9162c6cSKate Arzamastseva * @author Kate Arzamastseva <pshns@ukr.net>
1823d9162c6cSKate Arzamastseva */
1824d9162c6cSKate Arzamastsevafunction tpl_media() {
1825ac7a515fSAndreas Gohr    global $NS, $IMG, $JUMPTO, $REV, $lang, $fullscreen, $INPUT;
182688a71175SKate Arzamastseva    $fullscreen = true;
182795b451bcSAdrian Lang    require_once DOKU_INC.'lib/exe/mediamanager.php';
1828d9162c6cSKate Arzamastseva
1829ac7a515fSAndreas Gohr    $rev   = '';
1830ac7a515fSAndreas Gohr    $image = cleanID($INPUT->str('image'));
183198f03b57SKate Arzamastseva    if(isset($IMG)) $image = $IMG;
183298f03b57SKate Arzamastseva    if(isset($JUMPTO)) $image = $JUMPTO;
18339c1bd4bcSKate Arzamastseva    if(isset($REV) && !$JUMPTO) $rev = $REV;
183498f03b57SKate Arzamastseva
183594add303SAnika Henke    echo '<div id="mediamanager__page">'.NL;
1836bc314c58SAnika Henke    echo '<h1>'.$lang['btn_media'].'</h1>'.NL;
1837d9162c6cSKate Arzamastseva    html_msgarea();
183894add303SAnika Henke
183994add303SAnika Henke    echo '<div class="panel namespaces">'.NL;
184094add303SAnika Henke    echo '<h2>'.$lang['namespaces'].'</h2>'.NL;
184195b451bcSAdrian Lang    echo '<div class="panelHeader">';
1842ba340a70SAnika Henke    echo $lang['media_namespaces'];
184394add303SAnika Henke    echo '</div>'.NL;
184495b451bcSAdrian Lang
184594add303SAnika Henke    echo '<div class="panelContent" id="media__tree">'.NL;
184695b451bcSAdrian Lang    media_nstree($NS);
184794add303SAnika Henke    echo '</div>'.NL;
184894add303SAnika Henke    echo '</div>'.NL;
1849fa8e5c77SKate Arzamastseva
185094add303SAnika Henke    echo '<div class="panel filelist">'.NL;
1851035e07f1SKate Arzamastseva    tpl_mediaFileList();
185294add303SAnika Henke    echo '</div>'.NL;
1853fa8e5c77SKate Arzamastseva
185494add303SAnika Henke    echo '<div class="panel file">'.NL;
185594add303SAnika Henke    echo '<h2 class="a11y">'.$lang['media_file'].'</h2>'.NL;
1856035e07f1SKate Arzamastseva    tpl_mediaFileDetails($image, $rev);
185794add303SAnika Henke    echo '</div>'.NL;
1858ba340a70SAnika Henke
185994add303SAnika Henke    echo '</div>'.NL;
1860d9162c6cSKate Arzamastseva}
1861afca7e7eSAnika Henke
1862c71db656SAnika Henke/**
1863c71db656SAnika Henke * Return useful layout classes
1864c71db656SAnika Henke *
1865c71db656SAnika Henke * @author Anika Henke <anika@selfthinker.org>
1866c71db656SAnika Henke */
1867c71db656SAnika Henkefunction tpl_classes() {
1868c71db656SAnika Henke    global $ACT, $conf, $ID, $INFO;
1869c71db656SAnika Henke    $classes = array(
1870c71db656SAnika Henke        'dokuwiki',
1871c71db656SAnika Henke        'mode_'.$ACT,
1872c71db656SAnika Henke        'tpl_'.$conf['template'],
1873443e135dSChristopher Smith        !empty($_SERVER['REMOTE_USER']) ? 'loggedIn' : '',
187439f00629SAnika Henke        $INFO['exists'] ? '' : 'notFound',
1875c71db656SAnika Henke        ($ID == $conf['start']) ? 'home' : '',
1876c71db656SAnika Henke    );
1877c71db656SAnika Henke    return join(' ', $classes);
1878c71db656SAnika Henke}
1879c71db656SAnika Henke
1880e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1881a00de5b5SAndreas Gohr
1882