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