xref: /dokuwiki/inc/template.php (revision 71726d7801bdcbf41dfdc79d244f09a0988529c0)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki template functions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
96b13307fSandi  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10e7cb32dcSAndreas Gohr  require_once(DOKU_CONF.'dokuwiki.php');
116b13307fSandi
126b13307fSandi/**
135a892029SAndreas Gohr * Returns the path to the given template, uses
14524be65dSBen Coburn * default one if the custom version doesn't exist.
15524be65dSBen Coburn * Also enables gzip compression if configured.
165a892029SAndreas Gohr *
175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
185a892029SAndreas Gohr */
195a892029SAndreas Gohrfunction template($tpl){
205a892029SAndreas Gohr  global $conf;
215a892029SAndreas Gohr
225a892029SAndreas Gohr  if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
235a892029SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
245a892029SAndreas Gohr
255a892029SAndreas Gohr  return DOKU_INC.'lib/tpl/default/'.$tpl;
265a892029SAndreas Gohr}
275a892029SAndreas Gohr
285a892029SAndreas Gohr/**
296b13307fSandi * Print the content
306b13307fSandi *
316b13307fSandi * This function is used for printing all the usual content
326b13307fSandi * (defined by the global $ACT var) by calling the appropriate
336b13307fSandi * outputfunction(s) from html.php
346b13307fSandi *
35ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
36ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
376b13307fSandi *
386b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
396b13307fSandi */
406b13307fSandifunction tpl_content() {
417ea0913cSchris  global $ACT;
427ea0913cSchris
437ea0913cSchris  ob_start();
447ea0913cSchris
45746855cfSBen Coburn  trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
467ea0913cSchris
477ea0913cSchris  $html_output = ob_get_clean();
487ea0913cSchris
49746855cfSBen Coburn  trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
507ea0913cSchris}
517ea0913cSchris
527ea0913cSchrisfunction tpl_content_core(){
536b13307fSandi  global $ACT;
546b13307fSandi  global $TEXT;
556b13307fSandi  global $PRE;
566b13307fSandi  global $SUF;
576b13307fSandi  global $SUM;
586b13307fSandi  global $IDX;
596b13307fSandi
606b13307fSandi  switch($ACT){
616b13307fSandi    case 'show':
626b13307fSandi      html_show();
636b13307fSandi      break;
64ea67f144Sandi    case 'preview':
656b13307fSandi      html_edit($TEXT);
666b13307fSandi      html_show($TEXT);
676b13307fSandi      break;
68ee4c4a1bSAndreas Gohr    case 'recover':
69ee4c4a1bSAndreas Gohr      html_edit($TEXT);
70ee4c4a1bSAndreas Gohr      break;
716b13307fSandi    case 'edit':
726b13307fSandi      html_edit();
736b13307fSandi      break;
74ee4c4a1bSAndreas Gohr    case 'draft':
75ee4c4a1bSAndreas Gohr      html_draft();
76ee4c4a1bSAndreas Gohr      break;
776b13307fSandi    case 'wordblock':
786b13307fSandi      html_edit($TEXT,'wordblock');
796b13307fSandi      break;
806b13307fSandi    case 'search':
816b13307fSandi      html_search();
826b13307fSandi      break;
836b13307fSandi    case 'revisions':
84*71726d78SBen Coburn      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
85*71726d78SBen Coburn      html_revisions($first);
866b13307fSandi      break;
876b13307fSandi    case 'diff':
886b13307fSandi      html_diff();
896b13307fSandi      break;
906b13307fSandi    case 'recent':
915749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
92a39955b0Smatthiasgrimm      html_recent($first);
936b13307fSandi      break;
946b13307fSandi    case 'index':
956b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
966b13307fSandi      break;
976b13307fSandi    case 'backlink':
986b13307fSandi      html_backlinks();
996b13307fSandi      break;
1006b13307fSandi    case 'conflict':
1016b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1026b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
1036b13307fSandi      break;
1046b13307fSandi    case 'locked':
105ee20e7d1Sandi      html_locked();
1066b13307fSandi      break;
1076b13307fSandi    case 'login':
1086b13307fSandi      html_login();
1096b13307fSandi      break;
1106b13307fSandi    case 'register':
1116b13307fSandi      html_register();
1126b13307fSandi      break;
1138b06d178Schris    case 'resendpwd':
1148b06d178Schris      html_resendpwd();
1158b06d178Schris      break;
116820fa24bSandi    case 'denied':
1175e991bd8Sandi      print p_locale_xhtml('denied');
118820fa24bSandi      break;
1198b06d178Schris    case 'profile' :
1208b06d178Schris      html_updateprofile();
1218b06d178Schris      break;
122c19fe9c0Sandi    case 'admin':
123c19fe9c0Sandi      tpl_admin();
124c19fe9c0Sandi      break;
1256b13307fSandi    default:
12624bb549bSchris      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12724bb549bSchris      if ($evt->advise_before())
128ea67f144Sandi        msg("Failed to handle command: ".hsc($ACT),-1);
12924bb549bSchris      $evt->advise_after();
13024bb549bSchris      unset($evt);
1316b13307fSandi  }
1326b13307fSandi}
1336b13307fSandi
134c19fe9c0Sandi/**
135c19fe9c0Sandi * Handle the admin page contents
136c19fe9c0Sandi *
137c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
138c19fe9c0Sandi */
139c19fe9c0Sandifunction tpl_admin(){
14011e2ce22Schris
14111e2ce22Schris    $plugin = NULL;
14211e2ce22Schris    if ($_REQUEST['page']) {
14311e2ce22Schris        $pluginlist = plugin_list('admin');
14411e2ce22Schris
14511e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
14611e2ce22Schris
14711e2ce22Schris          // attempt to load the plugin
14811e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
14911e2ce22Schris        }
15011e2ce22Schris    }
15111e2ce22Schris
15211e2ce22Schris    if ($plugin !== NULL)
15311e2ce22Schris        $plugin->html();
15411e2ce22Schris    else
15511e2ce22Schris        html_admin();
156c19fe9c0Sandi}
1576b13307fSandi
1586b13307fSandi/**
1596b13307fSandi * Print the correct HTML meta headers
1606b13307fSandi *
1616b13307fSandi * This has to go into the head section of your template.
1626b13307fSandi *
163f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
1646b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1656b13307fSandi */
166f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
1676b13307fSandi  global $ID;
168d98d4540SBen Coburn  global $REV;
1696b13307fSandi  global $INFO;
1706b13307fSandi  global $ACT;
1716b13307fSandi  global $lang;
172dc57ef04Sandi  global $conf;
1736b13307fSandi  $it=2;
1746b13307fSandi
1756b13307fSandi  // the usual stuff
1766b13307fSandi  ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it);
1776b13307fSandi  ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it);
1786b13307fSandi  ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it);
179f96fa415SAndreas Gohr
180f96fa415SAndreas Gohr  if($alt){
1816b13307fSandi    ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it);
1826b13307fSandi    ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&amp;ns='.$INFO['namespace'].'" />',$it);
183f5c2808fSBen Coburn    ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.exportlink($ID, 'xhtml').'" />',$it);
184f5c2808fSBen Coburn    ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.exportlink($ID, 'raw').'" />',$it);
185f96fa415SAndreas Gohr  }
1866b13307fSandi
1876b13307fSandi  // setup robot tags apropriate for different modes
1884f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
1896b13307fSandi    if($INFO['exists']){
1906b13307fSandi      ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it);
1916b13307fSandi      //delay indexing:
1926b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
1936b13307fSandi        ptln('<meta name="robots" content="index,follow" />',$it);
1946b13307fSandi      }else{
1956b13307fSandi        ptln('<meta name="robots" content="noindex,nofollow" />',$it);
1966b13307fSandi      }
1976b13307fSandi    }else{
1986b13307fSandi      ptln('<meta name="robots" content="noindex,follow" />',$it);
1996b13307fSandi    }
2007a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2017a24876fSAndreas Gohr    ptln('<meta name="robots" content="index,follow" />',$it);
2026b13307fSandi  }else{
2036b13307fSandi    ptln('<meta name="robots" content="noindex,nofollow" />',$it);
2046b13307fSandi  }
2056b13307fSandi
20678a6aeb1SAndreas Gohr  // load stylesheets
20778a6aeb1SAndreas Gohr  ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php" />',$it);
20878a6aeb1SAndreas Gohr  ptln('<link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php?print=1" />',$it);
209bad31ae9SAndreas Gohr
21078a6aeb1SAndreas Gohr  // load javascript
211ee4c4a1bSAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover') ? 1 : 0;
212bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
2133df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
2143df72098SAndreas Gohr    $js_edit  = 1;
2153df72098SAndreas Gohr    $js_write = 0;
2163df72098SAndreas Gohr  }
2173df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
2184beabca9SAnika Henke    ptln('<script type="text/javascript" charset="utf-8">',$it);
219c591aabeSAndreas Gohr    ptln("NS='".$INFO['namespace']."';",$it+2);
220c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
221aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
222c591aabeSAndreas Gohr      ptln("SIG='".toolbar_signature()."';",$it+2);
223c591aabeSAndreas Gohr    }
224c591aabeSAndreas Gohr    ptln('</script>',$it);
225c591aabeSAndreas Gohr  }
2264beabca9SAnika Henke  ptln('<script type="text/javascript" charset="utf-8" src="'.
227c591aabeSAndreas Gohr       DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&amp;write='.$js_write.'"></script>',$it);
2286b13307fSandi}
2296b13307fSandi
2306b13307fSandi/**
2316b13307fSandi * Print a link
2326b13307fSandi *
2335e163278SAndreas Gohr * Just builds a link.
2346b13307fSandi *
2356b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2366b13307fSandi */
2376b13307fSandifunction tpl_link($url,$name,$more=''){
2385e163278SAndreas Gohr  print '<a href="'.$url.'" ';
2396b13307fSandi  if ($more) print ' '.$more;
2406b13307fSandi  print ">$name</a>";
2416b13307fSandi}
2426b13307fSandi
2436b13307fSandi/**
24455efc227SAndreas Gohr * Prints a link to a WikiPage
24555efc227SAndreas Gohr *
24655efc227SAndreas Gohr * Wrapper around html_wikilink
24755efc227SAndreas Gohr *
24855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
24955efc227SAndreas Gohr */
25055efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
25155efc227SAndreas Gohr  print html_wikilink($id,$name);
25255efc227SAndreas Gohr}
25355efc227SAndreas Gohr
25455efc227SAndreas Gohr/**
255a3ec5f4aSmatthiasgrimm * get the parent page
256a3ec5f4aSmatthiasgrimm *
257a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
258a3ec5f4aSmatthiasgrimm * returns false if none is available
259a3ec5f4aSmatthiasgrimm *
260377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
261a3ec5f4aSmatthiasgrimm */
262377f9e97SAndreas Gohrfunction tpl_getparent($id){
263a3ec5f4aSmatthiasgrimm  global $conf;
264377f9e97SAndreas Gohr  $parent = getNS($id).':';
265377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
266a197105eSmatthiasgrimm  if($parent == $id) {
267a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
268a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
269a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
270377f9e97SAndreas Gohr    if($parent == $id) return false;
271a197105eSmatthiasgrimm  }
272377f9e97SAndreas Gohr  return $parent;
273a3ec5f4aSmatthiasgrimm}
274a3ec5f4aSmatthiasgrimm
275a3ec5f4aSmatthiasgrimm/**
2766b13307fSandi * Print one of the buttons
2776b13307fSandi *
2786b13307fSandi * Available Buttons are
2796b13307fSandi *
280ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
2816b13307fSandi *  history     - old revisions
2826b13307fSandi *  recent      - recent changes
2836b13307fSandi *  login       - login/logout button - if ACL enabled
2846b13307fSandi *  index       - The index
285c19fe9c0Sandi *  admin       - admin page - if enough rights
2866b13307fSandi *  top         - a back to top button
287a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
288d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
289d67ca2c0Smatthiasgrimm *                after references have been displayed
290bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
2916b13307fSandi *
2926b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
293a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
2946b13307fSandi */
2956b13307fSandifunction tpl_button($type){
296b158d625SSteven Danz  global $ACT;
2976b13307fSandi  global $ID;
298d98d4540SBen Coburn  global $REV;
299d67ca2c0Smatthiasgrimm  global $NS;
300c19fe9c0Sandi  global $INFO;
3016b13307fSandi  global $conf;
302cd52f92dSchris  global $auth;
3036b13307fSandi
30475e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
30575e487e9SAndreas Gohr  $ctype = $type;
30675e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
30775e487e9SAndreas Gohr  if(!actionOK($ctype)) return;
308409d7af7SAndreas Gohr
3096b13307fSandi  switch($type){
3106b13307fSandi    case 'edit':
311409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
312409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
313409d7af7SAndreas Gohr        if($INFO['writable']){
314409d7af7SAndreas Gohr          if($INFO['draft']){
315409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
316409d7af7SAndreas Gohr          }else{
317409d7af7SAndreas Gohr            if($INFO['exists']){
318409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
319409d7af7SAndreas Gohr            }else{
320409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
321409d7af7SAndreas Gohr            }
322409d7af7SAndreas Gohr          }
323409d7af7SAndreas Gohr        }else{
324409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
325409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
326409d7af7SAndreas Gohr        }
327409d7af7SAndreas Gohr      }else{
328409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
329409d7af7SAndreas Gohr      }
3306b13307fSandi      break;
3316b13307fSandi    case 'history':
3325bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
3336b13307fSandi      break;
3346b13307fSandi    case 'recent':
3355bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
3366b13307fSandi      break;
3376b13307fSandi    case 'index':
3385bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
3396b13307fSandi      break;
340a3ec5f4aSmatthiasgrimm    case 'back':
3416222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
3426222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
343a3ec5f4aSmatthiasgrimm      }
344a3ec5f4aSmatthiasgrimm      break;
3456b13307fSandi    case 'top':
3466b13307fSandi      print html_topbtn();
3476b13307fSandi      break;
3486b13307fSandi    case 'login':
3496b13307fSandi      if($conf['useacl']){
3506b13307fSandi        if($_SERVER['REMOTE_USER']){
3516b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
3526b13307fSandi        }else{
3536b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
3546b13307fSandi        }
3556b13307fSandi      }
3566b13307fSandi      break;
357c19fe9c0Sandi    case 'admin':
358c19fe9c0Sandi      if($INFO['perm'] == AUTH_ADMIN)
3595bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
360c19fe9c0Sandi      break;
361d67ca2c0Smatthiasgrimm    case 'backtomedia':
362d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
363d67ca2c0Smatthiasgrimm      break;
3641380fc45SAndreas Gohr    case 'subscription':
365f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
366b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
3671380fc45SAndreas Gohr          if($INFO['subscribed']){
3681380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
369b158d625SSteven Danz          } else {
3701380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
371b158d625SSteven Danz          }
372b158d625SSteven Danz        }
373b158d625SSteven Danz      }
374b158d625SSteven Danz      break;
375f00151b4Schris    case 'backlink':
376f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
377f00151b4Schris      break;
3788b06d178Schris    case 'profile':
37936223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
38036223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
3818b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
3828b06d178Schris      }
3838b06d178Schris      break;
384c19fe9c0Sandi    default:
385c19fe9c0Sandi      print '[unknown button type]';
3866b13307fSandi  }
3876b13307fSandi}
3886b13307fSandi
3896b13307fSandi/**
390ed630903Sandi * Like the action buttons but links
391ed630903Sandi *
392ed630903Sandi * Available links are
393ed630903Sandi *
394ed630903Sandi *  edit    - edit/create/show button
395ed630903Sandi *  history - old revisions
396ed630903Sandi *  recent  - recent changes
397ed630903Sandi *  login   - login/logout button - if ACL enabled
398ed630903Sandi *  index   - The index
399ed630903Sandi *  admin   - admin page - if enough rights
400ed630903Sandi *  top     - a back to top button
401a3ec5f4aSmatthiasgrimm *  back    - a back to parent button - if available
402bbd37938SAndreas Gohr * backlink - links to the list of backlinks
403ed630903Sandi *
404ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
405a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
406ed630903Sandi * @see    tpl_button
407ed630903Sandi */
408ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
409ed630903Sandi  global $ID;
410ed630903Sandi  global $INFO;
411ed630903Sandi  global $REV;
412ed630903Sandi  global $ACT;
413ed630903Sandi  global $conf;
414ed630903Sandi  global $lang;
415cd52f92dSchris  global $auth;
416ed630903Sandi
41775e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
41875e487e9SAndreas Gohr  $ctype = $type;
41975e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
42075e487e9SAndreas Gohr  if(!actionOK($ctype)) return;
421409d7af7SAndreas Gohr
422ed630903Sandi  switch($type){
423ed630903Sandi    case 'edit':
424ed630903Sandi      #most complicated type - we need to decide on current action
425ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
426ed630903Sandi        if($INFO['writable']){
427ed630903Sandi          if($INFO['exists']){
428ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
429ed630903Sandi                     $pre.$lang['btn_edit'].$suf,
430b7af031cSsu                     'class="action edit" accesskey="e" rel="nofollow"');
431ed630903Sandi          }else{
432ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
433ed630903Sandi                     $pre.$lang['btn_create'].$suf,
434b7af031cSsu                     'class="action create" accesskey="e" rel="nofollow"');
435ed630903Sandi          }
436ed630903Sandi        }else{
437409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
438ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
439ed630903Sandi                   $pre.$lang['btn_source'].$suf,
440b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
441ed630903Sandi        }
442ed630903Sandi      }else{
443ed630903Sandi          tpl_link(wl($ID,'do=show'),
444ed630903Sandi                   $pre.$lang['btn_show'].$suf,
445b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
446ed630903Sandi      }
447c059e1a6SAndreas Gohr      return true;
448ed630903Sandi    case 'history':
449b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
450c059e1a6SAndreas Gohr      return true;
451ed630903Sandi    case 'recent':
452b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
453c059e1a6SAndreas Gohr      return true;
454ed630903Sandi    case 'index':
455b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
456c059e1a6SAndreas Gohr      return true;
457ed630903Sandi    case 'top':
45821a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
459c059e1a6SAndreas Gohr      return true;
460a3ec5f4aSmatthiasgrimm    case 'back':
461a3ec5f4aSmatthiasgrimm      if ($ID = tpl_getparent($ID)) {
462b7af031cSsu        tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
463c059e1a6SAndreas Gohr        return true;
464a3ec5f4aSmatthiasgrimm      }
465c059e1a6SAndreas Gohr      return false;
466ed630903Sandi    case 'login':
467ed630903Sandi      if($conf['useacl']){
468ed630903Sandi        if($_SERVER['REMOTE_USER']){
469b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
470ed630903Sandi        }else{
471b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
472ed630903Sandi        }
473c059e1a6SAndreas Gohr        return true;
474ed630903Sandi      }
475c059e1a6SAndreas Gohr      return false;
476ed630903Sandi    case 'admin':
477c059e1a6SAndreas Gohr      if($INFO['perm'] == AUTH_ADMIN){
478b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
479c059e1a6SAndreas Gohr        return true;
480c059e1a6SAndreas Gohr      }
481c059e1a6SAndreas Gohr      return false;
482f9eb5648Ssteven-danz   case 'subscribe':
483075f000fSChristopher Arndt   case 'subscription':
484f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
485b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
486075f000fSChristopher Arndt          if($INFO['subscribed']) {
487b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
488b158d625SSteven Danz          } else {
489b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
490b158d625SSteven Danz          }
491c059e1a6SAndreas Gohr          return true;
492b158d625SSteven Danz        }
493b158d625SSteven Danz      }
494c059e1a6SAndreas Gohr      return false;
495f00151b4Schris    case 'backlink':
496b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
497c059e1a6SAndreas Gohr      return true;
4988b06d178Schris    case 'profile':
49936223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
50036223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
5018b06d178Schris        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
502c059e1a6SAndreas Gohr        return true;
5038b06d178Schris      }
504c059e1a6SAndreas Gohr      return false;
505ed630903Sandi    default:
506ed630903Sandi      print '[unknown link type]';
507c059e1a6SAndreas Gohr      return true;
508ed630903Sandi  }
509ed630903Sandi}
510ed630903Sandi
511ed630903Sandi/**
5126b13307fSandi * Print the search form
5136b13307fSandi *
51472645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
51572645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
51672645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
51772645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
51872645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
51972645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
52072645b75SAndreas Gohr *
5216b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5226b13307fSandi */
52372645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
5246b13307fSandi  global $lang;
525c1e3b7d9Smatthiasgrimm  global $ACT;
526c1e3b7d9Smatthiasgrimm
5271dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
5286b13307fSandi  print '<input type="hidden" name="do" value="search" />';
529c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
530bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
53172645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
532818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
53311ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
53424a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
5354beabca9SAnika Henke  print '</div></form>';
5366b13307fSandi}
5376b13307fSandi
5386b13307fSandi/**
5396b13307fSandi * Print the breadcrumbs trace
5406b13307fSandi *
5416b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5426b13307fSandi */
5436b13307fSandifunction tpl_breadcrumbs(){
5446b13307fSandi  global $lang;
5456b13307fSandi  global $conf;
5466b13307fSandi
5476b13307fSandi  //check if enabled
5486b13307fSandi  if(!$conf['breadcrumbs']) return;
5496b13307fSandi
5506b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
551265e3787Sandi
552265e3787Sandi  //reverse crumborder in right-to-left mode
553265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
554265e3787Sandi
55540eb54bbSjan  //render crumbs, highlight the last one
5566b13307fSandi  print $lang['breadcrumb'].':';
55740eb54bbSjan  $last = count($crumbs);
55840eb54bbSjan  $i = 0;
559a77f5846Sjan  foreach ($crumbs as $id => $name){
56040eb54bbSjan    $i++;
561265e3787Sandi    print ' <span class="bcsep">&raquo;</span> ';
56292795d04Sandi    if ($i == $last) print '<span class="curid">';
563a77f5846Sjan    tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"');
56492795d04Sandi    if ($i == $last) print '</span>';
5656b13307fSandi  }
5666b13307fSandi}
5676b13307fSandi
5686b13307fSandi/**
5691734437eSandi * Hierarchical breadcrumbs
5701734437eSandi *
57131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
5721734437eSandi * It only makes sense with a deep site structure.
5731734437eSandi *
5741734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
5756bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
57631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
5771734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
5786bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
5791734437eSandi */
580796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
5811734437eSandi  global $conf;
5821734437eSandi  global $ID;
5831734437eSandi  global $lang;
5841734437eSandi
58531e187f8SSean Coates  // check if enabled
58631e187f8SSean Coates  if(!$conf['youarehere']) return;
5871734437eSandi
5881734437eSandi  $parts = explode(':', $ID);
589796bafb3SAndreas Gohr  $count = count($parts);
5901734437eSandi
591796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
5921734437eSandi
5931734437eSandi  // always print the startpage
594796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
595796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
596796bafb3SAndreas Gohr  tpl_link(wl($conf['start']),$title,'title="'.$conf['start'].'"');
597796bafb3SAndreas Gohr
598796bafb3SAndreas Gohr  // print intermediate namespace links
599796bafb3SAndreas Gohr  $part = '';
600796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
601796bafb3SAndreas Gohr    $part .= $parts[$i].':';
602796bafb3SAndreas Gohr    $page = $part;
603796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
604796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
605796bafb3SAndreas Gohr
606796bafb3SAndreas Gohr    // output
607796bafb3SAndreas Gohr    echo $sep;
608796bafb3SAndreas Gohr    if($exists){
609796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
610796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
611796bafb3SAndreas Gohr      tpl_link(wl($page),$title,'title="'.$page.'"');
61231e187f8SSean Coates    }else{
613796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
61431e187f8SSean Coates    }
61531e187f8SSean Coates  }
6161734437eSandi
617796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
618d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
619796bafb3SAndreas Gohr  $page = $part.$parts[$i];
620796bafb3SAndreas Gohr  if($page == $conf['start']) return;
621796bafb3SAndreas Gohr  echo $sep;
6221734437eSandi  if(file_exists(wikiFN($page))){
623796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
624796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
625796bafb3SAndreas Gohr    tpl_link(wl($page),$title,'title="'.$page.'"');
62631e187f8SSean Coates  }else{
627796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
6281734437eSandi  }
6291734437eSandi}
6301734437eSandi
6311734437eSandi/**
6326b13307fSandi * Print info if the user is logged in
633a2488c3cSMatthias Grimm * and show full name in that case
6346b13307fSandi *
6356b13307fSandi * Could be enhanced with a profile link in future?
6366b13307fSandi *
6376b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6386b13307fSandi */
6396b13307fSandifunction tpl_userinfo(){
6406b13307fSandi  global $lang;
641a2488c3cSMatthias Grimm  global $INFO;
6426b13307fSandi  if($_SERVER['REMOTE_USER'])
643a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
6446b13307fSandi}
6456b13307fSandi
6466b13307fSandi/**
6476b13307fSandi * Print some info about the current page
6486b13307fSandi *
6496b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6506b13307fSandi */
6516b13307fSandifunction tpl_pageinfo(){
6526b13307fSandi  global $conf;
6536b13307fSandi  global $lang;
6546b13307fSandi  global $INFO;
6556b13307fSandi  global $REV;
6566b13307fSandi
6576b13307fSandi  // prepare date and path
6586b13307fSandi  $fn = $INFO['filepath'];
6596b13307fSandi  if(!$conf['fullpath']){
6606b13307fSandi    if($REV){
6616b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
6626b13307fSandi    }else{
6636b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
6646b13307fSandi    }
6656b13307fSandi  }
666bee6dc82Sandi  $fn = utf8_decodeFN($fn);
6676b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
6686b13307fSandi
6696b13307fSandi  // print it
6706b13307fSandi  if($INFO['exists']){
6716b13307fSandi    print $fn;
6726b13307fSandi    print ' &middot; ';
6736b13307fSandi    print $lang['lastmod'];
6746b13307fSandi    print ': ';
6756b13307fSandi    print $date;
6766b13307fSandi    if($INFO['editor']){
6776b13307fSandi      print ' '.$lang['by'].' ';
6786b13307fSandi      print $INFO['editor'];
6796b13307fSandi    }
6806b13307fSandi    if($INFO['locked']){
6816b13307fSandi      print ' &middot; ';
6826b13307fSandi      print $lang['lockedby'];
6836b13307fSandi      print ': ';
6846b13307fSandi      print $INFO['locked'];
6856b13307fSandi    }
6866b13307fSandi  }
6876b13307fSandi}
6886b13307fSandi
689820fa24bSandi/**
690a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
69187c434ceSAndreas Gohr *
69287c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
693a6598f23SBen Coburn * the given ID is used.
69487c434ceSAndreas Gohr *
69587c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
69687c434ceSAndreas Gohr */
697a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
69887c434ceSAndreas Gohr  global $conf;
69987c434ceSAndreas Gohr  if(is_null($id)){
70087c434ceSAndreas Gohr    global $ID;
70187c434ceSAndreas Gohr    $id = $ID;
70287c434ceSAndreas Gohr  }
70387c434ceSAndreas Gohr
70487c434ceSAndreas Gohr  $name = $id;
70587c434ceSAndreas Gohr  if ($conf['useheading']) {
70687c434ceSAndreas Gohr    $title = p_get_first_heading($id);
70787c434ceSAndreas Gohr    if ($title) $name = $title;
70887c434ceSAndreas Gohr  }
709a6598f23SBen Coburn
710a6598f23SBen Coburn  if ($ret) {
711a6598f23SBen Coburn      return hsc($name);
712a6598f23SBen Coburn  } else {
71387c434ceSAndreas Gohr      print hsc($name);
71487c434ceSAndreas Gohr  }
715a6598f23SBen Coburn}
716340756e4Sandi
71755efc227SAndreas Gohr/**
71855efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
71955efc227SAndreas Gohr *
72055efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
72155efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
72255efc227SAndreas Gohr *
72355efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
72455efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
72555efc227SAndreas Gohr * to the names of the latter one)
72655efc227SAndreas Gohr *
7273df72098SAndreas Gohr * Only allowed in: detail.php
72855efc227SAndreas Gohr *
72955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
73055efc227SAndreas Gohr */
7313df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
73255efc227SAndreas Gohr  // Init Exif Reader
73355efc227SAndreas Gohr  global $SRC;
7343df72098SAndreas Gohr
7353df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
7363df72098SAndreas Gohr
73755efc227SAndreas Gohr  static $meta = null;
7383df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
73955efc227SAndreas Gohr  if($meta === false) return $alt;
74055efc227SAndreas Gohr  $info = $meta->getField($tags);
74155efc227SAndreas Gohr  if($info == false) return $alt;
74255efc227SAndreas Gohr  return $info;
74355efc227SAndreas Gohr}
74455efc227SAndreas Gohr
74555efc227SAndreas Gohr/**
74655efc227SAndreas Gohr * Prints the image with a link to the full sized version
74755efc227SAndreas Gohr *
74855efc227SAndreas Gohr * Only allowed in: detail.php
74955efc227SAndreas Gohr */
750f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
75155efc227SAndreas Gohr  global $IMG;
75255efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
75355efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
75455efc227SAndreas Gohr
75555efc227SAndreas Gohr  //resize to given max values
75623a34783SAndreas Gohr  $ratio = 1;
75723a34783SAndreas Gohr  if($w >= $h){
758f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
75955efc227SAndreas Gohr      $ratio = $maxwidth/$w;
760f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
76155efc227SAndreas Gohr      $ratio = $maxheight/$h;
76255efc227SAndreas Gohr    }
76355efc227SAndreas Gohr  }else{
764f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
76555efc227SAndreas Gohr      $ratio = $maxheight/$h;
766f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
76755efc227SAndreas Gohr      $ratio = $maxwidth/$w;
76855efc227SAndreas Gohr    }
76955efc227SAndreas Gohr  }
77055efc227SAndreas Gohr  if($ratio){
77155efc227SAndreas Gohr    $w = floor($ratio*$w);
77255efc227SAndreas Gohr    $h = floor($ratio*$h);
77355efc227SAndreas Gohr  }
77455efc227SAndreas Gohr
7756de3759aSAndreas Gohr  //prepare URLs
7766de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
7776de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
77855efc227SAndreas Gohr
7792684e50aSAndreas Gohr  //prepare attributes
78055efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
7812684e50aSAndreas Gohr  $p = array();
7822684e50aSAndreas Gohr  if($w) $p['width']  = $w;
7832684e50aSAndreas Gohr  if($h) $p['height'] = $h;
7842684e50aSAndreas Gohr         $p['class']  = 'img_detail';
7852684e50aSAndreas Gohr  if($alt){
7862684e50aSAndreas Gohr    $p['alt']   = $alt;
7872684e50aSAndreas Gohr    $p['title'] = $alt;
7882684e50aSAndreas Gohr  }else{
7892684e50aSAndreas Gohr    $p['alt'] = '';
7902684e50aSAndreas Gohr  }
7912684e50aSAndreas Gohr  $p = buildAttributes($p);
79255efc227SAndreas Gohr
79355efc227SAndreas Gohr  print '<a href="'.$url.'">';
7946de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
79555efc227SAndreas Gohr  print '</a>';
79655efc227SAndreas Gohr}
79755efc227SAndreas Gohr
7987367b368SAndreas Gohr/**
7997367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
8007367b368SAndreas Gohr * is the inexer function.
8017367b368SAndreas Gohr *
8027367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
8037367b368SAndreas Gohr * template
8047367b368SAndreas Gohr */
8057367b368SAndreas Gohrfunction tpl_indexerWebBug(){
8067367b368SAndreas Gohr  global $ID;
8071dad36f5SAndreas Gohr  global $INFO;
8081dad36f5SAndreas Gohr  if(!$INFO['exists']) return;
8091dad36f5SAndreas Gohr
8100dc92c6fSAndreas Gohr  if(isHiddenPage($ID)) return; //no need to index hidden pages
8110dc92c6fSAndreas Gohr
8127367b368SAndreas Gohr  $p = array();
813b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
814e68c51baSAndreas Gohr                 '&'.time();
8157367b368SAndreas Gohr  $p['width']  = 1;
8167367b368SAndreas Gohr  $p['height'] = 1;
8177367b368SAndreas Gohr  $p['alt']    = '';
8187367b368SAndreas Gohr  $att = buildAttributes($p);
8197367b368SAndreas Gohr  print "<img $att />";
8207367b368SAndreas Gohr}
8217367b368SAndreas Gohr
82278d4e784SEsther Brunner// configuration methods
82378d4e784SEsther Brunner/**
82478d4e784SEsther Brunner * tpl_getConf($id)
82578d4e784SEsther Brunner *
82678d4e784SEsther Brunner * use this function to access template configuration variables
82778d4e784SEsther Brunner */
82878d4e784SEsther Brunnerfunction tpl_getConf($id){
82978d4e784SEsther Brunner  global $conf;
83078d4e784SEsther Brunner  global $tpl_configloaded;
83178d4e784SEsther Brunner
83278d4e784SEsther Brunner  $tpl = $conf['template'];
83378d4e784SEsther Brunner
83478d4e784SEsther Brunner  if (!$tpl_configloaded){
83578d4e784SEsther Brunner    $tconf = tpl_loadConfig();
83678d4e784SEsther Brunner    if ($tconf !== false){
83778d4e784SEsther Brunner      foreach ($tconf as $key => $value){
83878d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
83978d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
84078d4e784SEsther Brunner      }
84178d4e784SEsther Brunner      $tpl_configloaded = true;
84278d4e784SEsther Brunner    }
84378d4e784SEsther Brunner  }
84478d4e784SEsther Brunner
84578d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
84678d4e784SEsther Brunner}
84778d4e784SEsther Brunner
84878d4e784SEsther Brunner/**
84978d4e784SEsther Brunner * tpl_loadConfig()
85078d4e784SEsther Brunner * reads all template configuration variables
85178d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
85278d4e784SEsther Brunner */
85378d4e784SEsther Brunnerfunction tpl_loadConfig(){
85478d4e784SEsther Brunner
85578d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
85678d4e784SEsther Brunner  $conf = array();
85778d4e784SEsther Brunner
85878d4e784SEsther Brunner  if (!@file_exists($file)) return false;
85978d4e784SEsther Brunner
86078d4e784SEsther Brunner  // load default config file
86178d4e784SEsther Brunner  include($file);
86278d4e784SEsther Brunner
86378d4e784SEsther Brunner  return $conf;
86478d4e784SEsther Brunner}
86578d4e784SEsther Brunner
8663df72098SAndreas Gohr/**
8673df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
8683df72098SAndreas Gohr *
8693df72098SAndreas Gohr * Depending on the user's actions this may be a list of
8703df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
8713df72098SAndreas Gohr * a message of referencing pages
8723df72098SAndreas Gohr *
8733df72098SAndreas Gohr * Only allowed in mediamanager.php
8743df72098SAndreas Gohr *
8753df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
8763df72098SAndreas Gohr */
8773df72098SAndreas Gohrfunction tpl_mediaContent(){
8783df72098SAndreas Gohr  global $IMG;
8793df72098SAndreas Gohr  global $AUTH;
8803df72098SAndreas Gohr  global $INUSE;
8813df72098SAndreas Gohr  global $NS;
8823df72098SAndreas Gohr  global $JUMPTO;
8833df72098SAndreas Gohr
8843df72098SAndreas Gohr  ptln('<div id="media__content">');
8853df72098SAndreas Gohr  if($_REQUEST['edit']){
8863df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
8877b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
8883df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
8893df72098SAndreas Gohr  }else{
8903df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
8913df72098SAndreas Gohr  }
8923df72098SAndreas Gohr  ptln('</div>');
8933df72098SAndreas Gohr}
8943df72098SAndreas Gohr
8953df72098SAndreas Gohr/**
8963df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
8973df72098SAndreas Gohr *
8983df72098SAndreas Gohr * Only allowed in mediamanager.php
8993df72098SAndreas Gohr *
9003df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
9013df72098SAndreas Gohr */
9023df72098SAndreas Gohrfunction tpl_mediaTree(){
9033df72098SAndreas Gohr  global $NS;
9043df72098SAndreas Gohr
9053df72098SAndreas Gohr  ptln('<div id="media__tree">');
9063df72098SAndreas Gohr  media_nstree($NS);
9073df72098SAndreas Gohr  ptln('</div>');
9083df72098SAndreas Gohr}
9093df72098SAndreas Gohr
910340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
911