xref: /dokuwiki/inc/template.php (revision ece9fa7a2e2237ae9c68cc8c39521de00ac91739)
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
9  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10  require_once(DOKU_CONF.'dokuwiki.php');
11
12/**
13 * Returns the path to the given template, uses
14 * default one if the custom version doesn't exist.
15 * Also enables gzip compression if configured.
16 *
17 * @author Andreas Gohr <andi@splitbrain.org>
18 */
19function template($tpl){
20  global $conf;
21
22  if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
23    return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
24
25  return DOKU_INC.'lib/tpl/default/'.$tpl;
26}
27
28/**
29 * Print the content
30 *
31 * This function is used for printing all the usual content
32 * (defined by the global $ACT var) by calling the appropriate
33 * outputfunction(s) from html.php
34 *
35 * Everything that doesn't use the main template file isn't
36 * handled by this function. ACL stuff is not done here either.
37 *
38 * @author Andreas Gohr <andi@splitbrain.org>
39 */
40function tpl_content() {
41  global $ACT;
42
43  ob_start();
44
45  trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
46
47  $html_output = ob_get_clean();
48
49  trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
50
51  return !empty($html_output);
52}
53
54function tpl_content_core(){
55  global $ACT;
56  global $TEXT;
57  global $PRE;
58  global $SUF;
59  global $SUM;
60  global $IDX;
61
62  switch($ACT){
63    case 'show':
64      html_show();
65      break;
66    case 'preview':
67      html_edit($TEXT);
68      html_show($TEXT);
69      break;
70    case 'recover':
71      html_edit($TEXT);
72      break;
73    case 'edit':
74      html_edit();
75      break;
76    case 'draft':
77      html_draft();
78      break;
79    case 'wordblock':
80      html_edit($TEXT,'wordblock');
81      break;
82    case 'search':
83      html_search();
84      break;
85    case 'revisions':
86      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
87      html_revisions($first);
88      break;
89    case 'diff':
90      html_diff();
91      break;
92    case 'recent':
93      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
94      html_recent($first);
95      break;
96    case 'index':
97      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
98      break;
99    case 'backlink':
100      html_backlinks();
101      break;
102    case 'conflict':
103      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
104      html_diff(con($PRE,$TEXT,$SUF),false);
105      break;
106    case 'locked':
107      html_locked();
108      break;
109    case 'login':
110      html_login();
111      break;
112    case 'register':
113      html_register();
114      break;
115    case 'resendpwd':
116      html_resendpwd();
117      break;
118    case 'denied':
119      print p_locale_xhtml('denied');
120      break;
121    case 'profile' :
122      html_updateprofile();
123      break;
124    case 'admin':
125      tpl_admin();
126      break;
127    default:
128      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
129      if ($evt->advise_before())
130        msg("Failed to handle command: ".hsc($ACT),-1);
131      $evt->advise_after();
132      unset($evt);
133      return false;
134  }
135  return true;
136}
137
138/**
139 * Handle the admin page contents
140 *
141 * @author Andreas Gohr <andi@splitbrain.org>
142 */
143function tpl_admin(){
144    global $INFO;
145
146    $plugin = NULL;
147    if (!empty($_REQUEST['page'])) {
148        $pluginlist = plugin_list('admin');
149
150        if (in_array($_REQUEST['page'], $pluginlist)) {
151
152          // attempt to load the plugin
153          $plugin =& plugin_load('admin',$_REQUEST['page']);
154        }
155    }
156
157    if ($plugin !== NULL){
158        if($plugin->forAdminOnly() && !$INFO['isadmin']){
159            msg('For admins only',-1);
160            html_admin();
161        }else{
162            $plugin->html();
163        }
164    }else{
165        html_admin();
166    }
167    return true;
168}
169
170/**
171 * Print the correct HTML meta headers
172 *
173 * This has to go into the head section of your template.
174 *
175 * @triggers TPL_METAHEADER_OUTPUT
176 * @param  boolean $alt Should feeds and alternative format links be added?
177 * @author Andreas Gohr <andi@splitbrain.org>
178 */
179function tpl_metaheaders($alt=true){
180  global $ID;
181  global $REV;
182  global $INFO;
183  global $ACT;
184  global $lang;
185  global $conf;
186  $it=2;
187
188  // prepare the head array
189  $head = array();
190
191
192  // the usual stuff
193  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
194  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
195                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
196  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
197  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
198                           'title'=>$lang['btn_index'] );
199
200  if($alt){
201    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
202                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
203    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
204                             'title'=>'Current Namespace',
205                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
206    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
207                             'href'=>exportlink($ID, 'xhtml', '', false, '&'));
208    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
209                             'href'=>exportlink($ID, 'raw', '', false, '&'));
210  }
211
212  // setup robot tags apropriate for different modes
213  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
214    if($INFO['exists']){
215      //delay indexing:
216      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
217        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
218      }else{
219        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
220      }
221    }else{
222      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
223    }
224  }elseif(defined('DOKU_MEDIADETAIL')){
225    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
226  }else{
227    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
228  }
229
230  // set metadata
231  if($ACT == 'show' || $ACT=='export_xhtml'){
232    // date of modification
233    if($REV){
234      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
235    }else{
236      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
237    }
238
239    // keywords (explicit or implicit)
240    if(!empty($INFO['meta']['subject'])){
241      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
242    }else{
243      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
244    }
245  }
246
247  // load stylesheets
248  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
249                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all');
250  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
251                          'href'=>DOKU_BASE.'lib/exe/css.php');
252  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
253                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
254
255  // load javascript
256  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
257  $js_write = ($INFO['writable']) ? 1 : 0;
258  if(defined('DOKU_MEDIAMANAGER')){
259    $js_edit  = 1;
260    $js_write = 0;
261  }
262  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
263    $script = "NS='".$INFO['namespace']."';";
264    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
265      require_once(DOKU_INC.'inc/toolbar.php');
266      $script .= "SIG='".toolbar_signature()."';";
267    }
268    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
269                               '_data'=> $script);
270  }
271  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
272                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
273
274  // trigger event here
275  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
276  return true;
277}
278
279/**
280 * prints the array build by tpl_metaheaders
281 *
282 * $data is an array of different header tags. Each tag can have multiple
283 * instances. Attributes are given as key value pairs. Values will be HTML
284 * encoded automatically so they should be provided as is in the $data array.
285 *
286 * For tags having a body attribute specify the the body data in the special
287 * attribute '_data'. This field will NOT BE ESCAPED automatically.
288 *
289 * @author Andreas Gohr <andi@splitbrain.org>
290 */
291function _tpl_metaheaders_action($data){
292  foreach($data as $tag => $inst){
293    foreach($inst as $attr){
294      echo '<',$tag,' ',buildAttributes($attr);
295      if(isset($attr['_data'])){
296          if($tag == 'script' && $attr['_data'])
297            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
298                             $attr['_data'].
299                             "\n//--><!]]>";
300
301          echo '>',$attr['_data'],'</',$tag,'>';
302      }else{
303        echo '/>';
304      }
305      echo "\n";
306    }
307  }
308}
309
310/**
311 * Print a link
312 *
313 * Just builds a link.
314 *
315 * @author Andreas Gohr <andi@splitbrain.org>
316 */
317function tpl_link($url,$name,$more=''){
318  print '<a href="'.$url.'" ';
319  if ($more) print ' '.$more;
320  print ">$name</a>";
321  return true;
322}
323
324/**
325 * Prints a link to a WikiPage
326 *
327 * Wrapper around html_wikilink
328 *
329 * @author Andreas Gohr <andi@splitbrain.org>
330 */
331function tpl_pagelink($id,$name=NULL){
332  print html_wikilink($id,$name);
333  return true;
334}
335
336/**
337 * get the parent page
338 *
339 * Tries to find out which page is parent.
340 * returns false if none is available
341 *
342 * @author Andreas Gohr <andi@splitbrain.org>
343 */
344function tpl_getparent($id){
345  global $conf;
346  $parent = getNS($id).':';
347  resolve_pageid('',$parent,$exists);
348  if($parent == $id) {
349    $pos = strrpos (getNS($id),':');
350    $parent = substr($parent,0,$pos).':';
351    resolve_pageid('',$parent,$exists);
352    if($parent == $id) return false;
353  }
354  return $parent;
355}
356
357/**
358 * Print one of the buttons
359 *
360 * Available Buttons are
361 *
362 *  edit        - edit/create/show/draft button
363 *  history     - old revisions
364 *  recent      - recent changes
365 *  login       - login/logout button - if ACL enabled
366 *  profile     - user profile button (if logged in)
367 *  index       - The index
368 *  admin       - admin page - if enough rights
369 *  top         - a back to top button
370 *  back        - a back to parent button - if available
371 *  backtomedia - returns to the mediafile upload dialog
372 *                after references have been displayed
373 *  backlink    - links to the list of backlinks
374 *  subscription- subscribe/unsubscribe button
375 *
376 * @author Andreas Gohr <andi@splitbrain.org>
377 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
378 */
379function tpl_button($type){
380  global $ACT;
381  global $ID;
382  global $REV;
383  global $NS;
384  global $INFO;
385  global $conf;
386  global $auth;
387
388  // check disabled actions and fix the badly named ones
389  $ctype = $type;
390  if($type == 'history') $ctype='revisions';
391  if(!actionOK($ctype)) return false;
392
393  switch($type){
394    case 'edit':
395      #most complicated type - we need to decide on current action
396      if($ACT == 'show' || $ACT == 'search'){
397        if($INFO['writable']){
398          if(!empty($INFO['draft'])){
399            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
400          }else{
401            if($INFO['exists']){
402              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
403            }else{
404              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
405            }
406          }
407        }else{
408          if(!actionOK('source')) return false; //pseudo action
409          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
410        }
411      }else{
412          echo html_btn('show',$ID,'v',array('do' => 'show'));
413      }
414      return true;
415    case 'history':
416      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
417      return true;
418    case 'recent':
419      print html_btn('recent','','r',array('do' => 'recent'));
420      return true;
421    case 'index':
422      print html_btn('index',$ID,'x',array('do' => 'index'));
423      return true;
424    case 'back':
425      if ($parent = tpl_getparent($ID)) {
426        print html_btn('back',$parent,'b',array('do' => 'show'));
427        return true;
428      }
429      return false;
430    case 'top':
431      print html_topbtn();
432      return true;
433    case 'login':
434      if($conf['useacl']){
435        if($_SERVER['REMOTE_USER']){
436          print html_btn('logout',$ID,'',array('do' => 'logout',));
437        }else{
438          print html_btn('login',$ID,'',array('do' => 'login'));
439        }
440        return true;
441      }
442      return false;
443    case 'admin':
444      if($INFO['ismanager']){
445        print html_btn('admin',$ID,'',array('do' => 'admin'));
446        return true;
447      }
448      return false;
449    case 'backtomedia':
450      print html_backtomedia_button(array('ns' => $NS),'b');
451      return false;
452    case 'subscription':
453      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
454        if($_SERVER['REMOTE_USER']){
455          if($INFO['subscribed']){
456            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
457          } else {
458            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
459          }
460          return true;
461        }
462      }
463      return false;
464    case 'backlink':
465      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
466      return true;
467    case 'profile':
468      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
469         $auth->canDo('Profile') && ($ACT!='profile')){
470        print html_btn('profile',$ID,'',array('do' => 'profile'));
471        return true;
472      }
473      return false;
474    default:
475      print '[unknown button type]';
476      return true;
477  }
478}
479
480/**
481 * Like the action buttons but links
482 *
483 * Available links are
484 *
485 *  edit    - edit/create/show link
486 *  history - old revisions
487 *  recent  - recent changes
488 *  login   - login/logout link - if ACL enabled
489 *  profile - user profile link (if logged in)
490 *  index   - The index
491 *  admin   - admin page - if enough rights
492 *  top     - a back to top link
493 *  back    - a back to parent link - if available
494 *  backlink - links to the list of backlinks
495 *  subscribe/subscription - subscribe/unsubscribe link
496 *
497 * @author Andreas Gohr <andi@splitbrain.org>
498 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
499 * @see    tpl_button
500 */
501function tpl_actionlink($type,$pre='',$suf=''){
502  global $ID;
503  global $INFO;
504  global $REV;
505  global $ACT;
506  global $conf;
507  global $lang;
508  global $auth;
509
510  // check disabled actions and fix the badly named ones
511  $ctype = $type;
512  if($type == 'history') $ctype='revisions';
513  if(!actionOK($ctype)) return false;
514
515  switch($type){
516    case 'edit':
517      #most complicated type - we need to decide on current action
518      if($ACT == 'show' || $ACT == 'search'){
519        if($INFO['writable']){
520          if(!empty($INFO['draft'])) {
521            tpl_link(wl($ID,'do=draft'),
522                       $pre.$lang['btn_draft'].$suf,
523                       'class="action edit" acceskey="e" rel="nofollow"');
524          } else {
525            if($INFO['exists']){
526              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
527                       $pre.$lang['btn_edit'].$suf,
528                       'class="action edit" accesskey="e" rel="nofollow"');
529            }else{
530              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
531                       $pre.$lang['btn_create'].$suf,
532                       'class="action create" accesskey="e" rel="nofollow"');
533            }
534          }
535        }else{
536          if(!actionOK('source')) return false; //pseudo action
537          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
538                   $pre.$lang['btn_source'].$suf,
539                   'class="action source" accesskey="v" rel="nofollow"');
540        }
541      }else{
542          tpl_link(wl($ID,'do=show'),
543                   $pre.$lang['btn_show'].$suf,
544                   'class="action show" accesskey="v" rel="nofollow"');
545      }
546      return true;
547    case 'history':
548      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
549      return true;
550    case 'recent':
551      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
552      return true;
553    case 'index':
554      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
555      return true;
556    case 'top':
557      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
558      return true;
559    case 'back':
560      if ($parent = tpl_getparent($ID)) {
561        tpl_link(wl($parent,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
562        return true;
563      }
564      return false;
565    case 'login':
566      if($conf['useacl']){
567        if($_SERVER['REMOTE_USER']){
568          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
569        }else{
570          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
571        }
572        return true;
573      }
574      return false;
575    case 'admin':
576      if($INFO['ismanager']){
577        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
578        return true;
579      }
580      return false;
581   case 'subscribe':
582   case 'subscription':
583      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
584        if($_SERVER['REMOTE_USER']){
585          if($INFO['subscribed']) {
586            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
587          } else {
588            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
589          }
590          return true;
591        }
592      }
593      return false;
594    case 'backlink':
595      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
596      return true;
597    case 'profile':
598      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
599         $auth->canDo('Profile') && ($ACT!='profile')){
600        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
601        return true;
602      }
603      return false;
604    default:
605      print '[unknown link type]';
606      return true;
607  }
608}
609
610/**
611 * Print the search form
612 *
613 * If the first parameter is given a div with the ID 'qsearch_out' will
614 * be added which instructs the ajax pagequicksearch to kick in and place
615 * its output into this div. The second parameter controls the propritary
616 * attribute autocomplete. If set to false this attribute will be set with an
617 * value of "off" to instruct the browser to disable it's own built in
618 * autocompletion feature (MSIE and Firefox)
619 *
620 * @author Andreas Gohr <andi@splitbrain.org>
621 */
622function tpl_searchform($ajax=true,$autocomplete=true){
623  global $lang;
624  global $ACT;
625
626  // don't print the search form if search action has been disabled
627  if (!actionOk('search')) return false;
628
629  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
630  print '<input type="hidden" name="do" value="search" />';
631  print '<input type="text" ';
632  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
633  if(!$autocomplete) print 'autocomplete="off" ';
634  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
635  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
636  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
637  print '</div></form>';
638  return true;
639}
640
641/**
642 * Print the breadcrumbs trace
643 *
644 * @author Andreas Gohr <andi@splitbrain.org>
645 */
646function tpl_breadcrumbs($sep='&raquo;'){
647  global $lang;
648  global $conf;
649
650  //check if enabled
651  if(!$conf['breadcrumbs']) return false;
652
653  $crumbs = breadcrumbs(); //setup crumb trace
654
655  //reverse crumborder in right-to-left mode
656  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
657
658  //render crumbs, highlight the last one
659  print $lang['breadcrumb'].':';
660  $last = count($crumbs);
661  $i = 0;
662  foreach ($crumbs as $id => $name){
663    $i++;
664    print ' <span class="bcsep">'.$sep.'</span> ';
665    if ($i == $last) print '<span class="curid">';
666    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
667    if ($i == $last) print '</span>';
668  }
669  return true;
670}
671
672/**
673 * Hierarchical breadcrumbs
674 *
675 * This code was suggested as replacement for the usual breadcrumbs.
676 * It only makes sense with a deep site structure.
677 *
678 * @author Andreas Gohr <andi@splitbrain.org>
679 * @author Nigel McNie <oracle.shinoda@gmail.com>
680 * @author Sean Coates <sean@caedmon.net>
681 * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
682 * @todo   May behave strangely in RTL languages
683 */
684function tpl_youarehere($sep=' &raquo; '){
685  global $conf;
686  global $ID;
687  global $lang;
688
689  // check if enabled
690  if(!$conf['youarehere']) return false;
691
692  $parts = explode(':', $ID);
693  $count = count($parts);
694
695  echo $lang['youarehere'].': ';
696
697  // always print the startpage
698  $title = p_get_first_heading($conf['start']);
699  if(!$title) $title = $conf['start'];
700  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
701
702  // print intermediate namespace links
703  $part = '';
704  for($i=0; $i<$count - 1; $i++){
705    $part .= $parts[$i].':';
706    $page = $part;
707    resolve_pageid('',$page,$exists);
708    if ($page == $conf['start']) continue; // Skip startpage
709
710    // output
711    echo $sep;
712    if($exists){
713      $title = p_get_first_heading($page);
714      if(!$title) $title = $parts[$i];
715      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
716    }else{
717      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
718    }
719  }
720
721  // print current page, skipping start page, skipping for namespace index
722  if(isset($page) && $page==$part.$parts[$i]) return;
723  $page = $part.$parts[$i];
724  if($page == $conf['start']) return;
725  echo $sep;
726  if(@file_exists(wikiFN($page))){
727    $title = p_get_first_heading($page);
728    if(!$title) $title = $parts[$i];
729    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
730  }else{
731    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
732  }
733  return true;
734}
735
736/**
737 * Print info if the user is logged in
738 * and show full name in that case
739 *
740 * Could be enhanced with a profile link in future?
741 *
742 * @author Andreas Gohr <andi@splitbrain.org>
743 */
744function tpl_userinfo(){
745  global $lang;
746  global $INFO;
747  if($_SERVER['REMOTE_USER']){
748    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
749    return true;
750  }
751  return false;
752}
753
754/**
755 * Print some info about the current page
756 *
757 * @author Andreas Gohr <andi@splitbrain.org>
758 */
759function tpl_pageinfo(){
760  global $conf;
761  global $lang;
762  global $INFO;
763  global $REV;
764
765  // prepare date and path
766  $fn = $INFO['filepath'];
767  if(!$conf['fullpath']){
768    if($REV){
769      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
770    }else{
771      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
772    }
773  }
774  $fn = utf8_decodeFN($fn);
775  $date = date($conf['dformat'],$INFO['lastmod']);
776
777  // print it
778  if($INFO['exists']){
779    print $fn;
780    print ' &middot; ';
781    print $lang['lastmod'];
782    print ': ';
783    print $date;
784    if($INFO['editor']){
785      print ' '.$lang['by'].' ';
786      print $INFO['editor'];
787    }else{
788      print ' ('.$lang['external_edit'].')';
789    }
790    if($INFO['locked']){
791      print ' &middot; ';
792      print $lang['lockedby'];
793      print ': ';
794      print $INFO['locked'];
795    }
796    return true;
797  }
798  return false;
799}
800
801/**
802 * Prints or returns the name of the given page (current one if none given).
803 *
804 * If useheading is enabled this will use the first headline else
805 * the given ID is used.
806 *
807 * @author Andreas Gohr <andi@splitbrain.org>
808 */
809function tpl_pagetitle($id=null, $ret=false){
810  global $conf;
811  if(is_null($id)){
812    global $ID;
813    $id = $ID;
814  }
815
816  $name = $id;
817  if ($conf['useheading']) {
818    $title = p_get_first_heading($id);
819    if ($title) $name = $title;
820  }
821
822  if ($ret) {
823      return hsc($name);
824  } else {
825      print hsc($name);
826      return true;
827  }
828}
829
830/**
831 * Returns the requested EXIF/IPTC tag from the current image
832 *
833 * If $tags is an array all given tags are tried until a
834 * value is found. If no value is found $alt is returned.
835 *
836 * Which texts are known is defined in the functions _exifTagNames
837 * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
838 * to the names of the latter one)
839 *
840 * Only allowed in: detail.php
841 *
842 * @author Andreas Gohr <andi@splitbrain.org>
843 */
844function tpl_img_getTag($tags,$alt='',$src=null){
845  // Init Exif Reader
846  global $SRC;
847
848  if(is_null($src)) $src = $SRC;
849
850  static $meta = null;
851  if(is_null($meta)) $meta = new JpegMeta($src);
852  if($meta === false) return $alt;
853  $info = $meta->getField($tags);
854  if($info == false) return $alt;
855  return $info;
856}
857
858/**
859 * Prints the image with a link to the full sized version
860 *
861 * Only allowed in: detail.php
862 */
863function tpl_img($maxwidth=0,$maxheight=0){
864  global $IMG;
865  $w = tpl_img_getTag('File.Width');
866  $h = tpl_img_getTag('File.Height');
867
868  //resize to given max values
869  $ratio = 1;
870  if($w >= $h){
871    if($maxwidth && $w >= $maxwidth){
872      $ratio = $maxwidth/$w;
873    }elseif($maxheight && $h > $maxheight){
874      $ratio = $maxheight/$h;
875    }
876  }else{
877    if($maxheight && $h >= $maxheight){
878      $ratio = $maxheight/$h;
879    }elseif($maxwidth && $w > $maxwidth){
880      $ratio = $maxwidth/$w;
881    }
882  }
883  if($ratio){
884    $w = floor($ratio*$w);
885    $h = floor($ratio*$h);
886  }
887
888  //prepare URLs
889  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
890  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
891
892  //prepare attributes
893  $alt=tpl_img_getTag('Simple.Title');
894  $p = array();
895  if($w) $p['width']  = $w;
896  if($h) $p['height'] = $h;
897         $p['class']  = 'img_detail';
898  if($alt){
899    $p['alt']   = $alt;
900    $p['title'] = $alt;
901  }else{
902    $p['alt'] = '';
903  }
904  $p = buildAttributes($p);
905
906  print '<a href="'.$url.'">';
907  print '<img src="'.$src.'" '.$p.'/>';
908  print '</a>';
909  return true;
910}
911
912/**
913 * This function inserts a 1x1 pixel gif which in reality
914 * is the inexer function.
915 *
916 * Should be called somewhere at the very end of the main.php
917 * template
918 */
919function tpl_indexerWebBug(){
920  global $ID;
921  global $INFO;
922  if(!$INFO['exists']) return false;
923
924  if(isHiddenPage($ID)) return false; //no need to index hidden pages
925
926  $p = array();
927  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
928                 '&'.time();
929  $p['width']  = 1;
930  $p['height'] = 1;
931  $p['alt']    = '';
932  $att = buildAttributes($p);
933  print "<img $att />";
934  return true;
935}
936
937// configuration methods
938/**
939 * tpl_getConf($id)
940 *
941 * use this function to access template configuration variables
942 */
943function tpl_getConf($id){
944  global $conf;
945  global $tpl_configloaded;
946
947  $tpl = $conf['template'];
948
949  if (!$tpl_configloaded){
950    $tconf = tpl_loadConfig();
951    if ($tconf !== false){
952      foreach ($tconf as $key => $value){
953        if (isset($conf['tpl'][$tpl][$key])) continue;
954        $conf['tpl'][$tpl][$key] = $value;
955      }
956      $tpl_configloaded = true;
957    }
958  }
959
960  return $conf['tpl'][$tpl][$id];
961}
962
963/**
964 * tpl_loadConfig()
965 * reads all template configuration variables
966 * this function is automatically called by tpl_getConf()
967 */
968function tpl_loadConfig(){
969
970  $file = DOKU_TPLINC.'/conf/default.php';
971  $conf = array();
972
973  if (!@file_exists($file)) return false;
974
975  // load default config file
976  include($file);
977
978  return $conf;
979}
980
981/**
982 * prints the "main content" in the mediamanger popup
983 *
984 * Depending on the user's actions this may be a list of
985 * files in a namespace, the meta editing dialog or
986 * a message of referencing pages
987 *
988 * Only allowed in mediamanager.php
989 *
990 * @author Andreas Gohr <andi@splitbrain.org>
991 */
992function tpl_mediaContent(){
993  global $IMG;
994  global $AUTH;
995  global $INUSE;
996  global $NS;
997  global $JUMPTO;
998
999  ptln('<div id="media__content">');
1000  if($_REQUEST['edit']){
1001    media_metaform($IMG,$AUTH);
1002  }elseif(is_array($INUSE)){
1003    media_filesinuse($INUSE,$IMG);
1004  }else{
1005    media_filelist($NS,$AUTH,$JUMPTO);
1006  }
1007  ptln('</div>');
1008}
1009
1010/**
1011 * prints the namespace tree in the mediamanger popup
1012 *
1013 * Only allowed in mediamanager.php
1014 *
1015 * @author Andreas Gohr <andi@splitbrain.org>
1016 */
1017function tpl_mediaTree(){
1018  global $NS;
1019
1020  ptln('<div id="media__tree">');
1021  media_nstree($NS);
1022  ptln('</div>');
1023}
1024
1025//Setup VIM: ex: et ts=2 enc=utf-8 :
1026