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