xref: /dokuwiki/inc/template.php (revision f03fd957525a714da1cde7e2957939046bd51bd5)
1<?php
2/**
3 * DokuWiki template functions
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9if(!defined('DOKU_INC')) die('meh.');
10
11/**
12 * Returns the path to the given template, uses
13 * default one if the custom version doesn't exist.
14 *
15 * @author Andreas Gohr <andi@splitbrain.org>
16 */
17function template($tpl){
18    global $conf;
19
20    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
21        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
22
23    return DOKU_INC.'lib/tpl/default/'.$tpl;
24}
25
26/**
27 * Print the content
28 *
29 * This function is used for printing all the usual content
30 * (defined by the global $ACT var) by calling the appropriate
31 * outputfunction(s) from html.php
32 *
33 * Everything that doesn't use the main template file isn't
34 * handled by this function. ACL stuff is not done here either.
35 *
36 * @author Andreas Gohr <andi@splitbrain.org>
37 */
38function tpl_content($prependTOC=true) {
39    global $ACT;
40    global $INFO;
41    $INFO['prependTOC'] = $prependTOC;
42
43    ob_start();
44    trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
45    $html_output = ob_get_clean();
46    trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
47
48    return !empty($html_output);
49}
50
51function tpl_content_core(){
52    global $ACT;
53    global $TEXT;
54    global $PRE;
55    global $SUF;
56    global $SUM;
57    global $IDX;
58
59    switch($ACT){
60        case 'show':
61            html_show();
62            break;
63        case 'locked':
64            html_locked();
65        case 'edit':
66        case 'recover':
67            html_edit();
68            break;
69        case 'preview':
70            html_edit();
71            html_show($TEXT);
72            break;
73        case 'draft':
74            html_draft();
75            break;
76        case 'search':
77            html_search();
78            break;
79        case 'revisions':
80            $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
81            html_revisions($first);
82            break;
83        case 'diff':
84            html_diff();
85            break;
86        case 'recent':
87            if (is_array($_REQUEST['first'])) {
88                $_REQUEST['first'] = array_keys($_REQUEST['first']);
89                $_REQUEST['first'] = $_REQUEST['first'][0];
90            }
91            $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
92            html_recent($first);
93            break;
94        case 'index':
95            html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
96                break;
97        case 'backlink':
98            html_backlinks();
99            break;
100        case 'conflict':
101            html_conflict(con($PRE,$TEXT,$SUF),$SUM);
102            html_diff(con($PRE,$TEXT,$SUF),false);
103            break;
104        case 'login':
105            html_login();
106            break;
107        case 'register':
108            html_register();
109            break;
110        case 'resendpwd':
111            html_resendpwd();
112            break;
113        case 'denied':
114            print p_locale_xhtml('denied');
115            break;
116        case 'profile' :
117            html_updateprofile();
118            break;
119        case 'admin':
120            tpl_admin();
121            break;
122        case 'subscribe':
123            tpl_subscribe();
124            break;
125        default:
126            $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
127            if ($evt->advise_before())
128                msg("Failed to handle command: ".hsc($ACT),-1);
129            $evt->advise_after();
130            unset($evt);
131            return false;
132    }
133    return true;
134}
135
136/**
137 * Places the TOC where the function is called
138 *
139 * If you use this you most probably want to call tpl_content with
140 * a false argument
141 *
142 * @author Andreas Gohr <andi@splitbrain.org>
143 */
144function tpl_toc($return=false){
145    global $TOC;
146    global $ACT;
147    global $ID;
148    global $REV;
149    global $INFO;
150    global $conf;
151    $toc = array();
152
153    if(is_array($TOC)){
154        // if a TOC was prepared in global scope, always use it
155        $toc = $TOC;
156    }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){
157        // get TOC from metadata, render if neccessary
158        $meta = p_get_metadata($ID, false, true);
159        if(isset($meta['internal']['toc'])){
160            $tocok = $meta['internal']['toc'];
161        }else{
162            $tocok = true;
163        }
164        $toc   = $meta['description']['tableofcontents'];
165        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){
166            $toc = array();
167        }
168    }elseif($ACT == 'admin'){
169        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
170        $plugin = null;
171        if (!empty($_REQUEST['page'])) {
172            $pluginlist = plugin_list('admin');
173            if (in_array($_REQUEST['page'], $pluginlist)) {
174                // attempt to load the plugin
175                $plugin =& plugin_load('admin',$_REQUEST['page']);
176            }
177        }
178        if ( ($plugin !== null) &&
179                (!$plugin->forAdminOnly() || $INFO['isadmin']) ){
180            $toc = $plugin->getTOC();
181            $TOC = $toc; // avoid later rebuild
182        }
183    }
184
185    trigger_event('TPL_TOC_RENDER', $toc, null, false);
186    $html = html_TOC($toc);
187    if($return) return $html;
188    echo $html;
189}
190
191/**
192 * Handle the admin page contents
193 *
194 * @author Andreas Gohr <andi@splitbrain.org>
195 */
196function tpl_admin(){
197    global $INFO;
198    global $TOC;
199
200    $plugin = null;
201    if (!empty($_REQUEST['page'])) {
202        $pluginlist = plugin_list('admin');
203
204        if (in_array($_REQUEST['page'], $pluginlist)) {
205
206            // attempt to load the plugin
207            $plugin =& plugin_load('admin',$_REQUEST['page']);
208        }
209    }
210
211    if ($plugin !== null){
212        if($plugin->forAdminOnly() && !$INFO['isadmin']){
213            msg('For admins only',-1);
214            html_admin();
215        }else{
216            if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
217            if($INFO['prependTOC']) tpl_toc();
218            $plugin->html();
219        }
220    }else{
221        html_admin();
222    }
223    return true;
224}
225
226/**
227 * Print the correct HTML meta headers
228 *
229 * This has to go into the head section of your template.
230 *
231 * @triggers TPL_METAHEADER_OUTPUT
232 * @param  boolean $alt Should feeds and alternative format links be added?
233 * @author Andreas Gohr <andi@splitbrain.org>
234 */
235function tpl_metaheaders($alt=true){
236    global $ID;
237    global $REV;
238    global $INFO;
239    global $JSINFO;
240    global $ACT;
241    global $QUERY;
242    global $lang;
243    global $conf;
244    $it=2;
245
246    // prepare the head array
247    $head = array();
248
249    // prepare seed for js and css
250    $tseed = 0;
251    $depends = getConfigFiles('main');
252    foreach($depends as $f) {
253        $time = @filemtime($f);
254        if($time > $tseed) $tseed = $time;
255    }
256
257    // the usual stuff
258    $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
259    $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
260            'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
261    $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
262    if(actionOK('index')){
263        $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
264                'title'=>$lang['btn_index'] );
265    }
266
267    if($alt){
268        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
269                'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
270        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
271                'title'=>'Current Namespace',
272                'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
273        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){
274            $head['link'][] = array( 'rel'=>'edit',
275                    'title'=>$lang['btn_edit'],
276                    'href'=> wl($ID,'do=edit',false,'&'));
277        }
278
279        if($ACT == 'search'){
280            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
281                    'title'=>'Search Result',
282                    'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
283        }
284
285        if(actionOK('export_xhtml')){
286            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
287                    'href'=>exportlink($ID, 'xhtml', '', false, '&'));
288        }
289
290        if(actionOK('export_raw')){
291            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
292                    'href'=>exportlink($ID, 'raw', '', false, '&'));
293        }
294    }
295
296    // setup robot tags apropriate for different modes
297    if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
298        if($INFO['exists']){
299            //delay indexing:
300            if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
301                $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
302            }else{
303                $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
304            }
305            $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') );
306        }else{
307            $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
308        }
309    }elseif(defined('DOKU_MEDIADETAIL')){
310        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
311    }else{
312        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
313    }
314
315    // set metadata
316    if($ACT == 'show' || $ACT=='export_xhtml'){
317        // date of modification
318        if($REV){
319            $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
320        }else{
321            $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
322        }
323
324        // keywords (explicit or implicit)
325        if(!empty($INFO['meta']['subject'])){
326            $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
327        }else{
328            $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
329        }
330    }
331
332    // load stylesheets
333    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
334            'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed);
335    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
336            'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template'].'&tseed='.$tseed);
337    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
338            'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template'].'&tseed='.$tseed);
339
340    // make $INFO and other vars available to JavaScripts
341    $json = new JSON();
342    $script = "var NS='".$INFO['namespace']."';";
343    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
344        $script .= "var SIG='".toolbar_signature()."';";
345    }
346    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
347    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
348            '_data'=> $script);
349
350    // load external javascript
351    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
352            'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed);
353
354    // trigger event here
355    trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
356    return true;
357}
358
359/**
360 * prints the array build by tpl_metaheaders
361 *
362 * $data is an array of different header tags. Each tag can have multiple
363 * instances. Attributes are given as key value pairs. Values will be HTML
364 * encoded automatically so they should be provided as is in the $data array.
365 *
366 * For tags having a body attribute specify the the body data in the special
367 * attribute '_data'. This field will NOT BE ESCAPED automatically.
368 *
369 * @author Andreas Gohr <andi@splitbrain.org>
370 */
371function _tpl_metaheaders_action($data){
372    foreach($data as $tag => $inst){
373        foreach($inst as $attr){
374            echo '<',$tag,' ',buildAttributes($attr);
375            if(isset($attr['_data']) || $tag == 'script'){
376                if($tag == 'script' && $attr['_data'])
377                    $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
378                        $attr['_data'].
379                        "\n//--><!]]>";
380
381                echo '>',$attr['_data'],'</',$tag,'>';
382            }else{
383                echo '/>';
384            }
385            echo "\n";
386        }
387    }
388}
389
390/**
391 * Print a link
392 *
393 * Just builds a link.
394 *
395 * @author Andreas Gohr <andi@splitbrain.org>
396 */
397function tpl_link($url,$name,$more='',$return=false){
398    $out = '<a href="'.$url.'" ';
399    if ($more) $out .= ' '.$more;
400    $out .= ">$name</a>";
401    if ($return) return $out;
402    print $out;
403    return true;
404}
405
406/**
407 * Prints a link to a WikiPage
408 *
409 * Wrapper around html_wikilink
410 *
411 * @author Andreas Gohr <andi@splitbrain.org>
412 */
413function tpl_pagelink($id,$name=null){
414    print html_wikilink($id,$name);
415    return true;
416}
417
418/**
419 * get the parent page
420 *
421 * Tries to find out which page is parent.
422 * returns false if none is available
423 *
424 * @author Andreas Gohr <andi@splitbrain.org>
425 */
426function tpl_getparent($id){
427    global $conf;
428    $parent = getNS($id).':';
429    resolve_pageid('',$parent,$exists);
430    if($parent == $id) {
431        $pos = strrpos (getNS($id),':');
432        $parent = substr($parent,0,$pos).':';
433        resolve_pageid('',$parent,$exists);
434        if($parent == $id) return false;
435    }
436    return $parent;
437}
438
439/**
440 * Print one of the buttons
441 *
442 * Available Buttons are
443 *
444 *  edit        - edit/create/show/draft button
445 *  history     - old revisions
446 *  recent      - recent changes
447 *  login       - login/logout button - if ACL enabled
448 *  profile     - user profile button (if logged in)
449 *  index       - The index
450 *  admin       - admin page - if enough rights
451 *  top         - a back to top button
452 *  back        - a back to parent button - if available
453 *  backlink    - links to the list of backlinks
454 *  subscription- subscribe/unsubscribe button
455 *
456 * @author Andreas Gohr <andi@splitbrain.org>
457 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
458 */
459function tpl_button($type,$return=false){
460    global $ACT;
461    global $ID;
462    global $REV;
463    global $NS;
464    global $INFO;
465    global $conf;
466    global $auth;
467
468    // check disabled actions and fix the badly named ones
469    $ctype = $type;
470    if($type == 'history') $ctype='revisions';
471    if(!actionOK($ctype)) return false;
472
473    $out = '';
474    switch($type){
475        case 'edit':
476            // most complicated type - we need to decide on current action
477            if($ACT == 'show' || $ACT == 'search'){
478                if($INFO['writable']){
479                    if(!empty($INFO['draft'])){
480                        $out .= html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
481                    }else{
482                        if($INFO['exists']){
483                            $out .= html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
484                        }else{
485                            $out .= html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
486                        }
487                    }
488                }else{
489                    if(!actionOK('source')) return false; //pseudo action
490                    $out .= html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
491                }
492            }else{
493                $out .= html_btn('show',$ID,'v',array('do' => 'show'));
494            }
495            break;
496        case 'history':
497            if(actionOK('revisions'))
498                $out .= html_btn('revs',$ID,'o',array('do' => 'revisions'));
499            break;
500        case 'recent':
501            if(actionOK('recent'))
502                $out .= html_btn('recent',$ID,'r',array('do' => 'recent'));
503            break;
504        case 'index':
505            if(actionOK('index'))
506                $out .= html_btn('index',$ID,'x',array('do' => 'index'));
507            break;
508        case 'back':
509            if ($parent = tpl_getparent($ID)) {
510                $out .= html_btn('back',$parent,'b',array('do' => 'show'));
511            }
512            break;
513        case 'top':
514            $out .= html_topbtn();
515            break;
516        case 'login':
517            if($conf['useacl'] && $auth){
518                if(isset($_SERVER['REMOTE_USER'])){
519                    $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken()));
520                }else{
521                    $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken()));
522                }
523            }
524            break;
525        case 'admin':
526            if($INFO['ismanager']){
527                $out .= html_btn('admin',$ID,'',array('do' => 'admin'));
528            }
529            break;
530        case 'revert':
531            if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
532                $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken()));
533            }
534            break;
535        case 'subscribe':
536            if ($conf['useacl'] && $auth && $ACT == 'show' &&
537                    $conf['subscribers'] && isset($_SERVER['REMOTE_USER']) &&
538                    actionOK('subscribe')) {
539                $out .= html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
540            }
541            break;
542        case 'backlink':
543            if(actionOK('backlink'))
544                $out .= html_btn('backlink',$ID,'',array('do' => 'backlink'));
545            break;
546        case 'profile':
547            if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth &&
548                    $auth->canDo('Profile') && ($ACT!='profile')){
549                $out .= html_btn('profile',$ID,'',array('do' => 'profile'));
550            }
551            break;
552        default:
553            $out .= '[unknown button type]';
554            break;
555    }
556    if ($return) return $out;
557    print $out;
558    return $out ? true : false;
559}
560
561/**
562 * Like the action buttons but links
563 *
564 * Available links are
565 *
566 *  edit    - edit/create/show link
567 *  history - old revisions
568 *  recent  - recent changes
569 *  login   - login/logout link - if ACL enabled
570 *  profile - user profile link (if logged in)
571 *  index   - The index
572 *  admin   - admin page - if enough rights
573 *  top     - a back to top link
574 *  back    - a back to parent link - if available
575 *  backlink - links to the list of backlinks
576 *  subscribe/subscription - subscribe/unsubscribe link
577 *
578 * @author Andreas Gohr <andi@splitbrain.org>
579 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
580 * @see    tpl_button
581 */
582function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
583    global $ID;
584    global $INFO;
585    global $REV;
586    global $ACT;
587    global $conf;
588    global $lang;
589    global $auth;
590
591    // check disabled actions and fix the badly named ones
592    $ctype = $type;
593    if($type == 'history') $ctype='revisions';
594    if(!actionOK($ctype)) return false;
595
596    $out = '';
597    switch($type){
598        case 'edit':
599            // most complicated type - we need to decide on current action
600            if($ACT == 'show' || $ACT == 'search'){
601                if($INFO['writable']){
602                    if(!empty($INFO['draft'])) {
603                        $out .= tpl_link(wl($ID,'do=draft'),
604                                $pre.(($inner)?$inner:$lang['btn_draft']).$suf,
605                                'class="action edit" accesskey="e" rel="nofollow"',1);
606                    } else {
607                        if($INFO['exists']){
608                            $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
609                                    $pre.(($inner)?$inner:$lang['btn_edit']).$suf,
610                                    'class="action edit" accesskey="e" rel="nofollow"',1);
611                        }else{
612                            $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
613                                    $pre.(($inner)?$inner:$lang['btn_create']).$suf,
614                                    'class="action create" accesskey="e" rel="nofollow"',1);
615                        }
616                    }
617                }else{
618                    if(actionOK('source')) //pseudo action
619                        $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
620                                $pre.(($inner)?$inner:$lang['btn_source']).$suf,
621                                'class="action source" accesskey="v" rel="nofollow"',1);
622                }
623            }else{
624                $out .= tpl_link(wl($ID,''),
625                        $pre.(($inner)?$inner:$lang['btn_show']).$suf,
626                        'class="action show" accesskey="v" rel="nofollow"',1);
627            }
628            break;
629        case 'history':
630            if(actionOK('revisions'))
631                $out .= tpl_link(wl($ID,'do=revisions'),
632                        $pre.(($inner)?$inner:$lang['btn_revs']).$suf,
633                        'class="action revisions" accesskey="o" rel="nofollow"',1);
634            break;
635        case 'recent':
636            if(actionOK('recent'))
637                $out .= tpl_link(wl($ID,'do=recent'),
638                        $pre.(($inner)?$inner:$lang['btn_recent']).$suf,
639                        'class="action recent" accesskey="r" rel="nofollow"',1);
640            break;
641        case 'index':
642            if(actionOK('index'))
643                $out .= tpl_link(wl($ID,'do=index'),
644                        $pre.(($inner)?$inner:$lang['btn_index']).$suf,
645                        'class="action index" accesskey="x" rel="nofollow"',1);
646            break;
647        case 'top':
648            $out .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'.
649                $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>';
650            break;
651        case 'back':
652            if ($parent = tpl_getparent($ID)) {
653                $out .= tpl_link(wl($parent,''),
654                        $pre.(($inner)?$inner:$lang['btn_back']).$suf,
655                        'class="action back" accesskey="b" rel="nofollow"',1);
656            }
657            break;
658        case 'login':
659            if($conf['useacl'] && $auth){
660                if($_SERVER['REMOTE_USER']){
661                    $out .= tpl_link(wl($ID,'do=logout&amp;sectok='.getSecurityToken()),
662                            $pre.(($inner)?$inner:$lang['btn_logout']).$suf,
663                            'class="action logout" rel="nofollow"',1);
664                }else{
665                    $out .= tpl_link(wl($ID,'do=login&amp;sectok='.getSecurityToken()),
666                            $pre.(($inner)?$inner:$lang['btn_login']).$suf,
667                            'class="action login" rel="nofollow"',1);
668                }
669            }
670            break;
671        case 'admin':
672            if($INFO['ismanager']){
673                $out .= tpl_link(wl($ID,'do=admin'),
674                        $pre.(($inner)?$inner:$lang['btn_admin']).$suf,
675                        'class="action admin" rel="nofollow"',1);
676            }
677            break;
678        case 'revert':
679            if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
680                $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())),
681                        $pre.(($inner)?$inner:$lang['btn_revert']).$suf,
682                        'class="action revert" rel="nofollow"',1);
683            }
684            break;
685        case 'subscribe':
686        case 'subscription':
687            if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']) {
688                if($_SERVER['REMOTE_USER']){
689                    if(actionOK('subscribe'))
690                        $out .= tpl_link(wl($ID,'do=subscribe'),
691                                $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf,
692                                'class="action subscribe" rel="nofollow"',1);
693                }
694            }
695            break;
696        case 'backlink':
697            if(actionOK('backlink'))
698                $out .= tpl_link(wl($ID,'do=backlink'),
699                        $pre.(($inner)?$inner:$lang['btn_backlink']).$suf,
700                        'class="action backlink" rel="nofollow"',1);
701            break;
702        case 'profile':
703            if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
704                    $auth->canDo('Profile') && ($ACT!='profile')){
705                $out .= tpl_link(wl($ID,'do=profile'),
706                        $pre.(($inner)?$inner:$lang['btn_profile']).$suf,
707                        'class="action profile" rel="nofollow"',1);
708            }
709            break;
710        default:
711            $out .= '[unknown link type]';
712            break;
713    }
714    if ($return) return $out;
715    print $out;
716    return $out ? true : false;
717}
718
719/**
720 * Wrapper around tpl_button() and tpl_actionlink()
721 *
722 * @author Anika Henke <anika@selfthinker.org>
723 */
724function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') {
725    $out = '';
726    if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1);
727    else $out .= tpl_button($type,1);
728    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
729
730    if ($return) return $out;
731    print $out;
732    return $out ? true : false;
733}
734
735/**
736 * Print the search form
737 *
738 * If the first parameter is given a div with the ID 'qsearch_out' will
739 * be added which instructs the ajax pagequicksearch to kick in and place
740 * its output into this div. The second parameter controls the propritary
741 * attribute autocomplete. If set to false this attribute will be set with an
742 * value of "off" to instruct the browser to disable it's own built in
743 * autocompletion feature (MSIE and Firefox)
744 *
745 * @author Andreas Gohr <andi@splitbrain.org>
746 */
747function tpl_searchform($ajax=true,$autocomplete=true){
748    global $lang;
749    global $ACT;
750    global $QUERY;
751
752    // don't print the search form if search action has been disabled
753    if (!actionOk('search')) return false;
754
755    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
756    print '<input type="hidden" name="do" value="search" />';
757    print '<input type="text" ';
758    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
759    if(!$autocomplete) print 'autocomplete="off" ';
760    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
761    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
762    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
763    print '</div></form>';
764    return true;
765}
766
767/**
768 * Print the breadcrumbs trace
769 *
770 * @author Andreas Gohr <andi@splitbrain.org>
771 */
772function tpl_breadcrumbs($sep='&raquo;'){
773    global $lang;
774    global $conf;
775
776    //check if enabled
777    if(!$conf['breadcrumbs']) return false;
778
779    $crumbs = breadcrumbs(); //setup crumb trace
780
781    //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
782    if($lang['direction'] == 'rtl') {
783        $crumbs = array_reverse($crumbs,true);
784        $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
785    } else {
786        $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
787    }
788
789    //render crumbs, highlight the last one
790    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
791    $last = count($crumbs);
792    $i = 0;
793    foreach ($crumbs as $id => $name){
794        $i++;
795        echo $crumbs_sep;
796        if ($i == $last) print '<span class="curid">';
797        tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
798        if ($i == $last) print '</span>';
799    }
800    return true;
801}
802
803/**
804 * Hierarchical breadcrumbs
805 *
806 * This code was suggested as replacement for the usual breadcrumbs.
807 * It only makes sense with a deep site structure.
808 *
809 * @author Andreas Gohr <andi@splitbrain.org>
810 * @author Nigel McNie <oracle.shinoda@gmail.com>
811 * @author Sean Coates <sean@caedmon.net>
812 * @author <fredrik@averpil.com>
813 * @todo   May behave strangely in RTL languages
814 */
815function tpl_youarehere($sep=' &raquo; '){
816    global $conf;
817    global $ID;
818    global $lang;
819
820    // check if enabled
821    if(!$conf['youarehere']) return false;
822
823    $parts = explode(':', $ID);
824    $count = count($parts);
825
826    if($GLOBALS['ACT'] == 'search')
827    {
828        $parts = array($conf['start']);
829        $count = 1;
830    }
831
832    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
833
834    // always print the startpage
835    $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start'];
836    if(!$title) $title = $conf['start'];
837    tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
838
839    // print intermediate namespace links
840    $part = '';
841    for($i=0; $i<$count - 1; $i++){
842        $part .= $parts[$i].':';
843        $page = $part;
844        resolve_pageid('',$page,$exists);
845        if ($page == $conf['start']) continue; // Skip startpage
846
847        // output
848        echo $sep;
849        if($exists){
850            $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
851            tpl_link(wl($page),hsc($title),'title="'.$page.'"');
852        }else{
853            tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
854        }
855    }
856
857    // print current page, skipping start page, skipping for namespace index
858    if(isset($page) && $page==$part.$parts[$i]) return;
859    $page = $part.$parts[$i];
860    if($page == $conf['start']) return;
861    echo $sep;
862    if(page_exists($page)){
863        $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
864        tpl_link(wl($page),hsc($title),'title="'.$page.'"');
865    }else{
866        tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
867    }
868    return true;
869}
870
871/**
872 * Print info if the user is logged in
873 * and show full name in that case
874 *
875 * Could be enhanced with a profile link in future?
876 *
877 * @author Andreas Gohr <andi@splitbrain.org>
878 */
879function tpl_userinfo(){
880    global $lang;
881    global $INFO;
882    if(isset($_SERVER['REMOTE_USER'])){
883        print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')';
884                return true;
885                }
886                return false;
887                }
888
889                /**
890                 * Print some info about the current page
891                 *
892                 * @author Andreas Gohr <andi@splitbrain.org>
893                 */
894                function tpl_pageinfo($ret=false){
895                global $conf;
896                global $lang;
897                global $INFO;
898                global $ID;
899
900                // return if we are not allowed to view the page
901                if (!auth_quickaclcheck($ID)) { return false; }
902
903                // prepare date and path
904                $fn = $INFO['filepath'];
905                if(!$conf['fullpath']){
906                    if($INFO['rev']){
907                        $fn = str_replace(fullpath($conf['olddir']).'/','',$fn);
908                    }else{
909                        $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
910                    }
911                }
912                $fn = utf8_decodeFN($fn);
913                $date = dformat($INFO['lastmod']);
914
915                // print it
916                if($INFO['exists']){
917                    $out = '';
918                    $out .= $fn;
919                    $out .= ' &middot; ';
920                    $out .= $lang['lastmod'];
921                    $out .= ': ';
922                    $out .= $date;
923                    if($INFO['editor']){
924                        $out .= ' '.$lang['by'].' ';
925                        $out .= editorinfo($INFO['editor']);
926                    }else{
927                        $out .= ' ('.$lang['external_edit'].')';
928                                }
929                                if($INFO['locked']){
930                                $out .= ' &middot; ';
931                                $out .= $lang['lockedby'];
932                                $out .= ': ';
933                                $out .= editorinfo($INFO['locked']);
934                                }
935                                if($ret){
936                                return $out;
937                                }else{
938                                echo $out;
939                                return true;
940                                }
941                                }
942                                return false;
943                                }
944
945                                /**
946                                 * Prints or returns the name of the given page (current one if none given).
947                                 *
948                                 * If useheading is enabled this will use the first headline else
949                                 * the given ID is used.
950                                 *
951                                 * @author Andreas Gohr <andi@splitbrain.org>
952                                 */
953function tpl_pagetitle($id=null, $ret=false){
954    global $conf;
955    if(is_null($id)){
956        global $ID;
957        $id = $ID;
958    }
959
960    $name = $id;
961    if (useHeading('navigation')) {
962        $title = p_get_first_heading($id);
963        if ($title) $name = $title;
964    }
965
966    if ($ret) {
967        return hsc($name);
968    } else {
969        print hsc($name);
970        return true;
971    }
972}
973
974/**
975 * Returns the requested EXIF/IPTC tag from the current image
976 *
977 * If $tags is an array all given tags are tried until a
978 * value is found. If no value is found $alt is returned.
979 *
980 * Which texts are known is defined in the functions _exifTagNames
981 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
982 * to the names of the latter one)
983 *
984 * Only allowed in: detail.php
985 *
986 * @author Andreas Gohr <andi@splitbrain.org>
987 */
988function tpl_img_getTag($tags,$alt='',$src=null){
989    // Init Exif Reader
990    global $SRC;
991
992    if(is_null($src)) $src = $SRC;
993
994    static $meta = null;
995    if(is_null($meta)) $meta = new JpegMeta($src);
996    if($meta === false) return $alt;
997    $info = $meta->getField($tags);
998    if($info == false) return $alt;
999    return $info;
1000}
1001
1002/**
1003 * Prints the image with a link to the full sized version
1004 *
1005 * Only allowed in: detail.php
1006 */
1007function tpl_img($maxwidth=0,$maxheight=0){
1008    global $IMG;
1009    $w = tpl_img_getTag('File.Width');
1010    $h = tpl_img_getTag('File.Height');
1011
1012    //resize to given max values
1013    $ratio = 1;
1014    if($w >= $h){
1015        if($maxwidth && $w >= $maxwidth){
1016            $ratio = $maxwidth/$w;
1017        }elseif($maxheight && $h > $maxheight){
1018            $ratio = $maxheight/$h;
1019        }
1020    }else{
1021        if($maxheight && $h >= $maxheight){
1022            $ratio = $maxheight/$h;
1023        }elseif($maxwidth && $w > $maxwidth){
1024            $ratio = $maxwidth/$w;
1025        }
1026    }
1027    if($ratio){
1028        $w = floor($ratio*$w);
1029        $h = floor($ratio*$h);
1030    }
1031
1032    //prepare URLs
1033    $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
1034    $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
1035
1036    //prepare attributes
1037    $alt=tpl_img_getTag('Simple.Title');
1038    $p = array();
1039    if($w) $p['width']  = $w;
1040    if($h) $p['height'] = $h;
1041    $p['class']  = 'img_detail';
1042    if($alt){
1043        $p['alt']   = $alt;
1044        $p['title'] = $alt;
1045    }else{
1046        $p['alt'] = '';
1047    }
1048    $p = buildAttributes($p);
1049
1050    print '<a href="'.$url.'">';
1051    print '<img src="'.$src.'" '.$p.'/>';
1052    print '</a>';
1053    return true;
1054}
1055
1056/**
1057 * This function inserts a 1x1 pixel gif which in reality
1058 * is the indexer function.
1059 *
1060 * Should be called somewhere at the very end of the main.php
1061 * template
1062 */
1063function tpl_indexerWebBug(){
1064    global $ID;
1065    global $INFO;
1066    if(!$INFO['exists']) return false;
1067
1068    if(isHiddenPage($ID)) return false; //no need to index hidden pages
1069
1070    $p = array();
1071    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1072        '&'.time();
1073    $p['width']  = 1;
1074    $p['height'] = 1;
1075    $p['alt']    = '';
1076    $att = buildAttributes($p);
1077    print "<img $att />";
1078    return true;
1079}
1080
1081// configuration methods
1082/**
1083 * tpl_getConf($id)
1084 *
1085 * use this function to access template configuration variables
1086 */
1087function tpl_getConf($id){
1088    global $conf;
1089    global $tpl_configloaded;
1090
1091    $tpl = $conf['template'];
1092
1093    if (!$tpl_configloaded){
1094        $tconf = tpl_loadConfig();
1095        if ($tconf !== false){
1096            foreach ($tconf as $key => $value){
1097                if (isset($conf['tpl'][$tpl][$key])) continue;
1098                $conf['tpl'][$tpl][$key] = $value;
1099            }
1100            $tpl_configloaded = true;
1101        }
1102    }
1103
1104    return $conf['tpl'][$tpl][$id];
1105}
1106
1107/**
1108 * tpl_loadConfig()
1109 * reads all template configuration variables
1110 * this function is automatically called by tpl_getConf()
1111 */
1112function tpl_loadConfig(){
1113
1114    $file = DOKU_TPLINC.'/conf/default.php';
1115    $conf = array();
1116
1117    if (!@file_exists($file)) return false;
1118
1119    // load default config file
1120    include($file);
1121
1122    return $conf;
1123}
1124
1125/**
1126 * prints the "main content" in the mediamanger popup
1127 *
1128 * Depending on the user's actions this may be a list of
1129 * files in a namespace, the meta editing dialog or
1130 * a message of referencing pages
1131 *
1132 * Only allowed in mediamanager.php
1133 *
1134 * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1135 * @param bool $fromajax - set true when calling this function via ajax
1136 * @author Andreas Gohr <andi@splitbrain.org>
1137 */
1138function tpl_mediaContent($fromajax=false){
1139    global $IMG;
1140    global $AUTH;
1141    global $INUSE;
1142    global $NS;
1143    global $JUMPTO;
1144
1145    if(is_array($_REQUEST['do'])){
1146        $do = array_shift(array_keys($_REQUEST['do']));
1147    }else{
1148        $do = $_REQUEST['do'];
1149    }
1150    if(in_array($do,array('save','cancel'))) $do = '';
1151
1152    if(!$do){
1153        if($_REQUEST['edit']){
1154            $do = 'metaform';
1155        }elseif(is_array($INUSE)){
1156            $do = 'filesinuse';
1157        }else{
1158            $do = 'filelist';
1159        }
1160    }
1161
1162    // output the content pane, wrapped in an event.
1163    if(!$fromajax) ptln('<div id="media__content">');
1164    $data = array( 'do' => $do);
1165    $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1166    if ($evt->advise_before()) {
1167        $do = $data['do'];
1168        if($do == 'metaform'){
1169            media_metaform($IMG,$AUTH);
1170        }elseif($do == 'filesinuse'){
1171            media_filesinuse($INUSE,$IMG);
1172        }elseif($do == 'filelist'){
1173            media_filelist($NS,$AUTH,$JUMPTO);
1174        }elseif($do == 'searchlist'){
1175            media_searchlist($_REQUEST['q'],$NS,$AUTH);
1176        }else{
1177            msg('Unknown action '.hsc($do),-1);
1178        }
1179    }
1180    $evt->advise_after();
1181    unset($evt);
1182    if(!$fromajax) ptln('</div>');
1183
1184}
1185
1186/**
1187 * prints the namespace tree in the mediamanger popup
1188 *
1189 * Only allowed in mediamanager.php
1190 *
1191 * @author Andreas Gohr <andi@splitbrain.org>
1192 */
1193function tpl_mediaTree(){
1194    global $NS;
1195
1196    ptln('<div id="media__tree">');
1197    media_nstree($NS);
1198    ptln('</div>');
1199}
1200
1201
1202/**
1203 * Print a dropdown menu with all DokuWiki actions
1204 *
1205 * Note: this will not use any pretty URLs
1206 *
1207 * @author Andreas Gohr <andi@splitbrain.org>
1208 */
1209function tpl_actiondropdown($empty='',$button='&gt;'){
1210    global $ID;
1211    global $INFO;
1212    global $REV;
1213    global $ACT;
1214    global $conf;
1215    global $lang;
1216    global $auth;
1217
1218    echo '<form method="post" accept-charset="utf-8">'; #FIXME action
1219        echo '<input type="hidden" name="id" value="'.$ID.'" />';
1220    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1221    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1222
1223    echo '<select name="do" id="action__selector" class="edit">';
1224    echo '<option value="">'.$empty.'</option>';
1225
1226    echo '<optgroup label=" &mdash; ">';
1227    // 'edit' - most complicated type, we need to decide on current action
1228    if($ACT == 'show' || $ACT == 'search'){
1229        if($INFO['writable']){
1230            if(!empty($INFO['draft'])) {
1231                echo '<option value="edit">'.$lang['btn_draft'].'</option>';
1232            } else {
1233                if($INFO['exists']){
1234                    echo '<option value="edit">'.$lang['btn_edit'].'</option>';
1235                }else{
1236                    echo '<option value="edit">'.$lang['btn_create'].'</option>';
1237                }
1238            }
1239        }else if(actionOK('source')) { //pseudo action
1240            echo '<option value="edit">'.$lang['btn_source'].'</option>';
1241        }
1242    }else{
1243        echo '<option value="show">'.$lang['btn_show'].'</option>';
1244    }
1245
1246    echo '<option value="revisions">'.$lang['btn_revs'].'</option>';
1247    if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
1248        echo '<option value="revert">'.$lang['btn_revert'].'</option>';
1249    }
1250    echo '<option value="backlink">'.$lang['btn_backlink'].'</option>';
1251    echo '</optgroup>';
1252
1253    echo '<optgroup label=" &mdash; ">';
1254    echo '<option value="recent">'.$lang['btn_recent'].'</option>';
1255    echo '<option value="index">'.$lang['btn_index'].'</option>';
1256    echo '</optgroup>';
1257
1258    echo '<optgroup label=" &mdash; ">';
1259    if($conf['useacl'] && $auth){
1260        if($_SERVER['REMOTE_USER']){
1261            echo '<option value="logout">'.$lang['btn_logout'].'</option>';
1262        }else{
1263            echo '<option value="login">'.$lang['btn_login'].'</option>';
1264        }
1265    }
1266
1267    if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
1268            $auth->canDo('Profile') && ($ACT!='profile')){
1269        echo '<option value="profile">'.$lang['btn_profile'].'</option>';
1270    }
1271
1272    if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']){
1273        if($_SERVER['REMOTE_USER']){
1274            echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>';
1275        }
1276    }
1277
1278    if($INFO['ismanager']){
1279        echo '<option value="admin">'.$lang['btn_admin'].'</option>';
1280    }
1281    echo '</optgroup>';
1282
1283    echo '</select>';
1284    echo '<input type="submit" value="'.$button.'" id="action__selectorbtn" />';
1285    echo '</form>';
1286}
1287
1288/**
1289 * Print a informational line about the used license
1290 *
1291 * @author Andreas Gohr <andi@splitbrain.org>
1292 * @param  string $img    - print image? (|button|badge)
1293 * @param  bool   $return - when true don't print, but return HTML
1294 */
1295function tpl_license($img='badge',$imgonly=false,$return=false){
1296    global $license;
1297    global $conf;
1298    global $lang;
1299    if(!$conf['license']) return '';
1300    if(!is_array($license[$conf['license']])) return '';
1301    $lic = $license[$conf['license']];
1302
1303    $out  = '<div class="license">';
1304    if($img){
1305        $src = license_img($img);
1306        if($src){
1307            $out .= '<a href="'.$lic['url'].'" rel="license"';
1308            if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1309            $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> ';
1310        }
1311    }
1312    if(!$imgonly) {
1313        $out .= $lang['license'];
1314        $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"';
1315        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1316        $out .= '>'.$lic['name'].'</a>';
1317    }
1318    $out .= '</div>';
1319
1320    if($return) return $out;
1321    echo $out;
1322}
1323
1324
1325/**
1326 * Includes the rendered XHTML of a given page
1327 *
1328 * This function is useful to populate sidebars or similar features in a
1329 * template
1330 */
1331function tpl_include_page($pageid,$print=true){
1332    global $ID;
1333    $oldid = $ID;
1334    $html = p_wiki_xhtml($pageid,'',false);
1335    $ID = $oldid;
1336
1337    if(!$print) return $html;
1338    echo $html;
1339}
1340
1341/**
1342 * Display the subscribe form
1343 *
1344 * @author Adrian Lang <lang@cosmocode.de>
1345 */
1346function tpl_subscribe() {
1347    global $INFO;
1348    global $ID;
1349    global $lang;
1350
1351    echo p_locale_xhtml('subscr_form');
1352    echo '<h2>' . $lang['subscr_m_current_header'] . '</h2>';
1353    echo '<div class="level2">';
1354    if ($INFO['subscribed'] === false) {
1355        echo '<p>' . $lang['subscr_m_not_subscribed'] . '</p>';
1356    } else {
1357        echo '<ul>';
1358        foreach($INFO['subscribed'] as $sub) {
1359            echo '<li><div class="li">';
1360            if ($sub['target'] !== $ID) {
1361                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
1362            } else {
1363                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
1364            }
1365            $sstl = $lang['subscr_style_'.$sub['style']];
1366            if(!$sstl) $sstl = hsc($sub['style']);
1367            echo ' ('.$sstl.') ';
1368
1369            echo '<a href="' . wl($ID,
1370                                  array('do'=>'subscribe',
1371                                        'sub_target'=>$sub['target'],
1372                                        'sub_style'=>$sub['style'],
1373                                        'sub_action'=>'unsubscribe',
1374                                        'sectok' => getSecurityToken())) .
1375                 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'] .
1376                 '</a></div></li>';
1377        }
1378        echo '</ul>';
1379    }
1380    echo '</div>';
1381
1382    // Add new subscription form
1383    echo '<h2>' . $lang['subscr_m_new_header'] . '</h2>';
1384    echo '<div class="level2">';
1385    $ns = getNS($ID).':';
1386    $targets = array(
1387            $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
1388            $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
1389            );
1390    $styles = array(
1391            'every'  => $lang['subscr_style_every'],
1392            'digest' => $lang['subscr_style_digest'],
1393            'list'   => $lang['subscr_style_list'],
1394            );
1395
1396    $form = new Doku_Form(array('id' => 'subscribe__form'));
1397    $form->startFieldset($lang['subscr_m_subscribe']);
1398    $form->addRadioSet('sub_target', $targets);
1399    $form->startFieldset($lang['subscr_m_receive']);
1400    $form->addRadioSet('sub_style', $styles);
1401    $form->addHidden('sub_action', 'subscribe');
1402    $form->addHidden('do', 'subscribe');
1403    $form->addHidden('id', $ID);
1404    $form->endFieldset();
1405    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
1406    html_form('SUBSCRIBE', $form);
1407    echo '</div>';
1408}
1409
1410/**
1411 * Tries to send already created content right to the browser
1412 *
1413 * Wraps around ob_flush() and flush()
1414 *
1415 * @author Andreas Gohr <andi@splitbrain.org>
1416 */
1417function tpl_flush(){
1418    ob_flush();
1419    flush();
1420}
1421
1422
1423//Setup VIM: ex: et ts=4 enc=utf-8 :
1424
1425