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