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