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