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