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