xref: /dokuwiki/inc/template.php (revision 6957b2ea013b27781cc1ccce8b94267006cb917d)
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');
5054e95700STom N Harris
5154e95700STom N Harris  return !empty($html_output);
527ea0913cSchris}
537ea0913cSchris
547ea0913cSchrisfunction tpl_content_core(){
556b13307fSandi  global $ACT;
566b13307fSandi  global $TEXT;
576b13307fSandi  global $PRE;
586b13307fSandi  global $SUF;
596b13307fSandi  global $SUM;
606b13307fSandi  global $IDX;
616b13307fSandi
626b13307fSandi  switch($ACT){
636b13307fSandi    case 'show':
646b13307fSandi      html_show();
656b13307fSandi      break;
66ea67f144Sandi    case 'preview':
676b13307fSandi      html_edit($TEXT);
686b13307fSandi      html_show($TEXT);
696b13307fSandi      break;
70ee4c4a1bSAndreas Gohr    case 'recover':
71ee4c4a1bSAndreas Gohr      html_edit($TEXT);
72ee4c4a1bSAndreas Gohr      break;
736b13307fSandi    case 'edit':
746b13307fSandi      html_edit();
756b13307fSandi      break;
76ee4c4a1bSAndreas Gohr    case 'draft':
77ee4c4a1bSAndreas Gohr      html_draft();
78ee4c4a1bSAndreas Gohr      break;
796b13307fSandi    case 'wordblock':
806b13307fSandi      html_edit($TEXT,'wordblock');
816b13307fSandi      break;
826b13307fSandi    case 'search':
836b13307fSandi      html_search();
846b13307fSandi      break;
856b13307fSandi    case 'revisions':
8671726d78SBen Coburn      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
8771726d78SBen Coburn      html_revisions($first);
886b13307fSandi      break;
896b13307fSandi    case 'diff':
906b13307fSandi      html_diff();
916b13307fSandi      break;
926b13307fSandi    case 'recent':
935749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
94a39955b0Smatthiasgrimm      html_recent($first);
956b13307fSandi      break;
966b13307fSandi    case 'index':
976b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
986b13307fSandi      break;
996b13307fSandi    case 'backlink':
1006b13307fSandi      html_backlinks();
1016b13307fSandi      break;
1026b13307fSandi    case 'conflict':
1036b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1046b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
1056b13307fSandi      break;
1066b13307fSandi    case 'locked':
107ee20e7d1Sandi      html_locked();
1086b13307fSandi      break;
1096b13307fSandi    case 'login':
1106b13307fSandi      html_login();
1116b13307fSandi      break;
1126b13307fSandi    case 'register':
1136b13307fSandi      html_register();
1146b13307fSandi      break;
1158b06d178Schris    case 'resendpwd':
1168b06d178Schris      html_resendpwd();
1178b06d178Schris      break;
118820fa24bSandi    case 'denied':
1195e991bd8Sandi      print p_locale_xhtml('denied');
120820fa24bSandi      break;
1218b06d178Schris    case 'profile' :
1228b06d178Schris      html_updateprofile();
1238b06d178Schris      break;
124c19fe9c0Sandi    case 'admin':
125c19fe9c0Sandi      tpl_admin();
126c19fe9c0Sandi      break;
1276b13307fSandi    default:
12824bb549bSchris      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12924bb549bSchris      if ($evt->advise_before())
130ea67f144Sandi        msg("Failed to handle command: ".hsc($ACT),-1);
13124bb549bSchris      $evt->advise_after();
13224bb549bSchris      unset($evt);
13354e95700STom N Harris      return false;
1346b13307fSandi  }
13554e95700STom N Harris  return true;
1366b13307fSandi}
1376b13307fSandi
138c19fe9c0Sandi/**
139c19fe9c0Sandi * Handle the admin page contents
140c19fe9c0Sandi *
141c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
142c19fe9c0Sandi */
143c19fe9c0Sandifunction tpl_admin(){
144f8cc712eSAndreas Gohr    global $INFO;
14511e2ce22Schris
14611e2ce22Schris    $plugin = NULL;
147bb4866bdSchris    if (!empty($_REQUEST['page'])) {
14811e2ce22Schris        $pluginlist = plugin_list('admin');
14911e2ce22Schris
15011e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
15111e2ce22Schris
15211e2ce22Schris          // attempt to load the plugin
15311e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
15411e2ce22Schris        }
15511e2ce22Schris    }
15611e2ce22Schris
157f8cc712eSAndreas Gohr    if ($plugin !== NULL){
158f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
159f8cc712eSAndreas Gohr            msg('For admins only',-1);
16011e2ce22Schris            html_admin();
161f8cc712eSAndreas Gohr        }else{
162f8cc712eSAndreas Gohr            $plugin->html();
163f8cc712eSAndreas Gohr        }
164f8cc712eSAndreas Gohr    }else{
165f8cc712eSAndreas Gohr        html_admin();
166f8cc712eSAndreas Gohr    }
16754e95700STom N Harris    return true;
168c19fe9c0Sandi}
1696b13307fSandi
1706b13307fSandi/**
1716b13307fSandi * Print the correct HTML meta headers
1726b13307fSandi *
1736b13307fSandi * This has to go into the head section of your template.
1746b13307fSandi *
175016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
176f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
1776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1786b13307fSandi */
179f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
1806b13307fSandi  global $ID;
181d98d4540SBen Coburn  global $REV;
1826b13307fSandi  global $INFO;
1836b13307fSandi  global $ACT;
1846b13307fSandi  global $lang;
185dc57ef04Sandi  global $conf;
1866b13307fSandi  $it=2;
1876b13307fSandi
1887bff22c0SAndreas Gohr  // prepare the head array
1897bff22c0SAndreas Gohr  $head = array();
1907bff22c0SAndreas Gohr
1917bff22c0SAndreas Gohr
1926b13307fSandi  // the usual stuff
1937bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
194da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
195da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
196f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
1977bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
198bb4866bdSchris                           'title'=>$lang['btn_index'] );
199f96fa415SAndreas Gohr
200f96fa415SAndreas Gohr  if($alt){
2017bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2027bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2037bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2047bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2057bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
206bae36d94SAndreas Gohr
207bae36d94SAndreas Gohr    if(actionOK('export_xhtml')){
2087bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2097bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'xhtml', '', false, '&'));
210bae36d94SAndreas Gohr    }
211bae36d94SAndreas Gohr
212bae36d94SAndreas Gohr    if(actionOK('export_raw')){
2137bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2147bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'raw', '', false, '&'));
215f96fa415SAndreas Gohr    }
216bae36d94SAndreas Gohr  }
2176b13307fSandi
2186b13307fSandi  // setup robot tags apropriate for different modes
2194f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2206b13307fSandi    if($INFO['exists']){
2216b13307fSandi      //delay indexing:
2226b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2237bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2246b13307fSandi      }else{
2257bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2266b13307fSandi      }
2276b13307fSandi    }else{
2287bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
2296b13307fSandi    }
2307a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2317bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2326b13307fSandi  }else{
2337bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2346b13307fSandi  }
2356b13307fSandi
236831800b8SAndreas Gohr  // set metadata
237831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
238831800b8SAndreas Gohr    // date of modification
239831800b8SAndreas Gohr    if($REV){
2407bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
241831800b8SAndreas Gohr    }else{
2427bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
243831800b8SAndreas Gohr    }
244831800b8SAndreas Gohr
245831800b8SAndreas Gohr    // keywords (explicit or implicit)
246bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
2477bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
248831800b8SAndreas Gohr    }else{
2497bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
250831800b8SAndreas Gohr    }
251831800b8SAndreas Gohr  }
252831800b8SAndreas Gohr
25378a6aeb1SAndreas Gohr  // load stylesheets
2547aaa4c46Smartin.tschofen  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
2557aaa4c46Smartin.tschofen                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all');
2567bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
2577bff22c0SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php');
2587bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
259615960feSTom N Harris                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
260bad31ae9SAndreas Gohr
26178a6aeb1SAndreas Gohr  // load javascript
262041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
263bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
2643df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
2653df72098SAndreas Gohr    $js_edit  = 1;
2663df72098SAndreas Gohr    $js_write = 0;
2673df72098SAndreas Gohr  }
2683df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
2697bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
270c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
271aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
2727bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
273c591aabeSAndreas Gohr    }
2747bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
2757bff22c0SAndreas Gohr                               '_data'=> $script);
276c591aabeSAndreas Gohr  }
2777bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
2787bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
2797bff22c0SAndreas Gohr
2807bff22c0SAndreas Gohr  // trigger event here
281016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
28254e95700STom N Harris  return true;
2837bff22c0SAndreas Gohr}
2847bff22c0SAndreas Gohr
2857bff22c0SAndreas Gohr/**
2867bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
2877bff22c0SAndreas Gohr *
2887bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
2897bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
2907bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
2917bff22c0SAndreas Gohr *
2927bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
2931304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
2947bff22c0SAndreas Gohr *
2957bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
2967bff22c0SAndreas Gohr */
2977bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
2987bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
2997bff22c0SAndreas Gohr    foreach($inst as $attr){
3007bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
3017bff22c0SAndreas Gohr      if(isset($attr['_data'])){
302e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
303e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
304e226efe1SAndreas Gohr                             $attr['_data'].
305e226efe1SAndreas Gohr                             "\n//--><!]]>";
306e226efe1SAndreas Gohr
3071304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3087bff22c0SAndreas Gohr      }else{
3097bff22c0SAndreas Gohr        echo '/>';
3107bff22c0SAndreas Gohr      }
3117bff22c0SAndreas Gohr      echo "\n";
3127bff22c0SAndreas Gohr    }
3137bff22c0SAndreas Gohr  }
3146b13307fSandi}
3156b13307fSandi
3166b13307fSandi/**
3176b13307fSandi * Print a link
3186b13307fSandi *
3195e163278SAndreas Gohr * Just builds a link.
3206b13307fSandi *
3216b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3226b13307fSandi */
3236b13307fSandifunction tpl_link($url,$name,$more=''){
3245e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3256b13307fSandi  if ($more) print ' '.$more;
3266b13307fSandi  print ">$name</a>";
32754e95700STom N Harris  return true;
3286b13307fSandi}
3296b13307fSandi
3306b13307fSandi/**
33155efc227SAndreas Gohr * Prints a link to a WikiPage
33255efc227SAndreas Gohr *
33355efc227SAndreas Gohr * Wrapper around html_wikilink
33455efc227SAndreas Gohr *
33555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
33655efc227SAndreas Gohr */
33755efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
33855efc227SAndreas Gohr  print html_wikilink($id,$name);
33954e95700STom N Harris  return true;
34055efc227SAndreas Gohr}
34155efc227SAndreas Gohr
34255efc227SAndreas Gohr/**
343a3ec5f4aSmatthiasgrimm * get the parent page
344a3ec5f4aSmatthiasgrimm *
345a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
346a3ec5f4aSmatthiasgrimm * returns false if none is available
347a3ec5f4aSmatthiasgrimm *
348377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
349a3ec5f4aSmatthiasgrimm */
350377f9e97SAndreas Gohrfunction tpl_getparent($id){
351a3ec5f4aSmatthiasgrimm  global $conf;
352377f9e97SAndreas Gohr  $parent = getNS($id).':';
353377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
354a197105eSmatthiasgrimm  if($parent == $id) {
355a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
356a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
357a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
358377f9e97SAndreas Gohr    if($parent == $id) return false;
359a197105eSmatthiasgrimm  }
360377f9e97SAndreas Gohr  return $parent;
361a3ec5f4aSmatthiasgrimm}
362a3ec5f4aSmatthiasgrimm
363a3ec5f4aSmatthiasgrimm/**
3646b13307fSandi * Print one of the buttons
3656b13307fSandi *
3666b13307fSandi * Available Buttons are
3676b13307fSandi *
368ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
3696b13307fSandi *  history     - old revisions
3706b13307fSandi *  recent      - recent changes
3716b13307fSandi *  login       - login/logout button - if ACL enabled
372d449b912SDenis Simakov *  profile     - user profile button (if logged in)
3736b13307fSandi *  index       - The index
374c19fe9c0Sandi *  admin       - admin page - if enough rights
3756b13307fSandi *  top         - a back to top button
376a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
377bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
378d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
3796b13307fSandi *
3806b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
381a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
3826b13307fSandi */
3836b13307fSandifunction tpl_button($type){
384b158d625SSteven Danz  global $ACT;
3856b13307fSandi  global $ID;
386d98d4540SBen Coburn  global $REV;
387d67ca2c0Smatthiasgrimm  global $NS;
388c19fe9c0Sandi  global $INFO;
3896b13307fSandi  global $conf;
390cd52f92dSchris  global $auth;
3916b13307fSandi
39275e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
39375e487e9SAndreas Gohr  $ctype = $type;
39475e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
39554e95700STom N Harris  if(!actionOK($ctype)) return false;
396409d7af7SAndreas Gohr
3976b13307fSandi  switch($type){
3986b13307fSandi    case 'edit':
399409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
400409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
401409d7af7SAndreas Gohr        if($INFO['writable']){
402bb4866bdSchris          if(!empty($INFO['draft'])){
403409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
404409d7af7SAndreas Gohr          }else{
405409d7af7SAndreas Gohr            if($INFO['exists']){
406409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
407409d7af7SAndreas Gohr            }else{
408409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
409409d7af7SAndreas Gohr            }
410409d7af7SAndreas Gohr          }
411409d7af7SAndreas Gohr        }else{
412409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
413409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
414409d7af7SAndreas Gohr        }
415409d7af7SAndreas Gohr      }else{
416409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
417409d7af7SAndreas Gohr      }
41854e95700STom N Harris      return true;
4196b13307fSandi    case 'history':
4205bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
42154e95700STom N Harris      return true;
4226b13307fSandi    case 'recent':
4235bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
42454e95700STom N Harris      return true;
4256b13307fSandi    case 'index':
4265bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
42754e95700STom N Harris      return true;
428a3ec5f4aSmatthiasgrimm    case 'back':
4296222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4306222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
43154e95700STom N Harris        return true;
432a3ec5f4aSmatthiasgrimm      }
43354e95700STom N Harris      return false;
4346b13307fSandi    case 'top':
4356b13307fSandi      print html_topbtn();
43654e95700STom N Harris      return true;
4376b13307fSandi    case 'login':
438*6957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
4396b13307fSandi        if($_SERVER['REMOTE_USER']){
4406b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
4416b13307fSandi        }else{
4426b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
4436b13307fSandi        }
44454e95700STom N Harris        return true;
4456b13307fSandi      }
44654e95700STom N Harris      return false;
447c19fe9c0Sandi    case 'admin':
44854e95700STom N Harris      if($INFO['ismanager']){
4495bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
45054e95700STom N Harris        return true;
45154e95700STom N Harris      }
45254e95700STom N Harris      return false;
4531380fc45SAndreas Gohr    case 'subscription':
454*6957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
455b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
4561380fc45SAndreas Gohr          if($INFO['subscribed']){
4571380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
458b158d625SSteven Danz          } else {
4591380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
460b158d625SSteven Danz          }
46154e95700STom N Harris          return true;
462b158d625SSteven Danz        }
463b158d625SSteven Danz      }
46454e95700STom N Harris      return false;
465f00151b4Schris    case 'backlink':
466f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
46754e95700STom N Harris      return true;
4688b06d178Schris    case 'profile':
469*6957b2eaSAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth &&
47036223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
4718b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
47254e95700STom N Harris        return true;
4738b06d178Schris      }
47454e95700STom N Harris      return false;
475c19fe9c0Sandi    default:
476c19fe9c0Sandi      print '[unknown button type]';
47754e95700STom N Harris      return true;
4786b13307fSandi  }
4796b13307fSandi}
4806b13307fSandi
4816b13307fSandi/**
482ed630903Sandi * Like the action buttons but links
483ed630903Sandi *
484ed630903Sandi * Available links are
485ed630903Sandi *
486d449b912SDenis Simakov *  edit    - edit/create/show link
487ed630903Sandi *  history - old revisions
488ed630903Sandi *  recent  - recent changes
489d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
490d449b912SDenis Simakov *  profile - user profile link (if logged in)
491ed630903Sandi *  index   - The index
492ed630903Sandi *  admin   - admin page - if enough rights
493d449b912SDenis Simakov *  top     - a back to top link
494d449b912SDenis Simakov *  back    - a back to parent link - if available
495bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
496d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
497ed630903Sandi *
498ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
499a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
500ed630903Sandi * @see    tpl_button
501ed630903Sandi */
502ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
503ed630903Sandi  global $ID;
504ed630903Sandi  global $INFO;
505ed630903Sandi  global $REV;
506ed630903Sandi  global $ACT;
507ed630903Sandi  global $conf;
508ed630903Sandi  global $lang;
509cd52f92dSchris  global $auth;
510ed630903Sandi
51175e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
51275e487e9SAndreas Gohr  $ctype = $type;
51375e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
51454e95700STom N Harris  if(!actionOK($ctype)) return false;
515409d7af7SAndreas Gohr
516ed630903Sandi  switch($type){
517ed630903Sandi    case 'edit':
518ed630903Sandi      #most complicated type - we need to decide on current action
519ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
520ed630903Sandi        if($INFO['writable']){
521b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
522b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
523b8a111f5SMichael Klier                       $pre.$lang['btn_draft'].$suf,
524b8a111f5SMichael Klier                       'class="action edit" acceskey="e" rel="nofollow"');
525b8a111f5SMichael Klier          } else {
526ed630903Sandi            if($INFO['exists']){
527ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
528ed630903Sandi                       $pre.$lang['btn_edit'].$suf,
529b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
530ed630903Sandi            }else{
531ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
532ed630903Sandi                       $pre.$lang['btn_create'].$suf,
533b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
534ed630903Sandi            }
535b8a111f5SMichael Klier          }
536ed630903Sandi        }else{
537409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
538ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
539ed630903Sandi                   $pre.$lang['btn_source'].$suf,
540b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
541ed630903Sandi        }
542ed630903Sandi      }else{
543ed630903Sandi          tpl_link(wl($ID,'do=show'),
544ed630903Sandi                   $pre.$lang['btn_show'].$suf,
545b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
546ed630903Sandi      }
547c059e1a6SAndreas Gohr      return true;
548ed630903Sandi    case 'history':
54941dfcdfcSAndreas Gohr      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o" rel="nofollow"');
550c059e1a6SAndreas Gohr      return true;
551ed630903Sandi    case 'recent':
5525e79da84SAnika Henke      tpl_link(wl('','do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r" rel="nofollow"');
553c059e1a6SAndreas Gohr      return true;
554ed630903Sandi    case 'index':
55541dfcdfcSAndreas Gohr      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x" rel="nofollow"');
556c059e1a6SAndreas Gohr      return true;
557ed630903Sandi    case 'top':
55821a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
559c059e1a6SAndreas Gohr      return true;
560a3ec5f4aSmatthiasgrimm    case 'back':
561f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
56241dfcdfcSAndreas Gohr        tpl_link(wl($parent,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b" rel="nofollow"');
563c059e1a6SAndreas Gohr        return true;
564a3ec5f4aSmatthiasgrimm      }
565c059e1a6SAndreas Gohr      return false;
566ed630903Sandi    case 'login':
567*6957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
568ed630903Sandi        if($_SERVER['REMOTE_USER']){
56941dfcdfcSAndreas Gohr          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout" rel="nofollow"');
570ed630903Sandi        }else{
57141dfcdfcSAndreas Gohr          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action login" rel="nofollow"');
572ed630903Sandi        }
573c059e1a6SAndreas Gohr        return true;
574ed630903Sandi      }
575c059e1a6SAndreas Gohr      return false;
576ed630903Sandi    case 'admin':
577f8cc712eSAndreas Gohr      if($INFO['ismanager']){
57841dfcdfcSAndreas Gohr        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin" rel="nofollow"');
579c059e1a6SAndreas Gohr        return true;
580c059e1a6SAndreas Gohr      }
581c059e1a6SAndreas Gohr      return false;
582f9eb5648Ssteven-danz   case 'subscribe':
583075f000fSChristopher Arndt   case 'subscription':
584*6957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
585b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
586075f000fSChristopher Arndt          if($INFO['subscribed']) {
58741dfcdfcSAndreas Gohr            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe" rel="nofollow"');
588b158d625SSteven Danz          } else {
58941dfcdfcSAndreas Gohr            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe" rel="nofollow"');
590b158d625SSteven Danz          }
591c059e1a6SAndreas Gohr          return true;
592b158d625SSteven Danz        }
593b158d625SSteven Danz      }
594c059e1a6SAndreas Gohr      return false;
595f00151b4Schris    case 'backlink':
59641dfcdfcSAndreas Gohr      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink" rel="nofollow"');
597c059e1a6SAndreas Gohr      return true;
5988b06d178Schris    case 'profile':
599*6957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
60036223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
60141dfcdfcSAndreas Gohr        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile" rel="nofollow"');
602c059e1a6SAndreas Gohr        return true;
6038b06d178Schris      }
604c059e1a6SAndreas Gohr      return false;
605ed630903Sandi    default:
606ed630903Sandi      print '[unknown link type]';
607c059e1a6SAndreas Gohr      return true;
608ed630903Sandi  }
609ed630903Sandi}
610ed630903Sandi
611ed630903Sandi/**
6126b13307fSandi * Print the search form
6136b13307fSandi *
61472645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
61572645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
61672645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
61772645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
61872645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
61972645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
62072645b75SAndreas Gohr *
6216b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6226b13307fSandi */
62372645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6246b13307fSandi  global $lang;
625c1e3b7d9Smatthiasgrimm  global $ACT;
626c1e3b7d9Smatthiasgrimm
627670ff54eSchris  // don't print the search form if search action has been disabled
62854e95700STom N Harris  if (!actionOk('search')) return false;
629670ff54eSchris
6301dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6316b13307fSandi  print '<input type="hidden" name="do" value="search" />';
632c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
633bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
63472645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
635818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
63611ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
63724a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6384beabca9SAnika Henke  print '</div></form>';
63954e95700STom N Harris  return true;
6406b13307fSandi}
6416b13307fSandi
6426b13307fSandi/**
6436b13307fSandi * Print the breadcrumbs trace
6446b13307fSandi *
6456b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6466b13307fSandi */
64754e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
6486b13307fSandi  global $lang;
6496b13307fSandi  global $conf;
6506b13307fSandi
6516b13307fSandi  //check if enabled
65254e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
6536b13307fSandi
6546b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
655265e3787Sandi
6562979a10bSKatriel Traum  //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
6572979a10bSKatriel Traum  if($lang['direction'] == 'rtl') {
6582979a10bSKatriel Traum    $crumbs = array_reverse($crumbs,true);
6592979a10bSKatriel Traum    $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
6602979a10bSKatriel Traum  } else {
6612979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
6622979a10bSKatriel Traum  }
663265e3787Sandi
66440eb54bbSjan  //render crumbs, highlight the last one
6656b13307fSandi  print $lang['breadcrumb'].':';
66640eb54bbSjan  $last = count($crumbs);
66740eb54bbSjan  $i = 0;
668a77f5846Sjan  foreach ($crumbs as $id => $name){
66940eb54bbSjan    $i++;
6702979a10bSKatriel Traum    echo $crumbs_sep;
67192795d04Sandi    if ($i == $last) print '<span class="curid">';
672e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
67392795d04Sandi    if ($i == $last) print '</span>';
6746b13307fSandi  }
67554e95700STom N Harris  return true;
6766b13307fSandi}
6776b13307fSandi
6786b13307fSandi/**
6791734437eSandi * Hierarchical breadcrumbs
6801734437eSandi *
68131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
6821734437eSandi * It only makes sense with a deep site structure.
6831734437eSandi *
6841734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
6856bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
68631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
6871734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
6886bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
6891734437eSandi */
690796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
6911734437eSandi  global $conf;
6921734437eSandi  global $ID;
6931734437eSandi  global $lang;
6941734437eSandi
69531e187f8SSean Coates  // check if enabled
69654e95700STom N Harris  if(!$conf['youarehere']) return false;
6971734437eSandi
6981734437eSandi  $parts = explode(':', $ID);
699796bafb3SAndreas Gohr  $count = count($parts);
7001734437eSandi
701796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
7021734437eSandi
7031734437eSandi  // always print the startpage
704796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
705796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
706e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
707796bafb3SAndreas Gohr
708796bafb3SAndreas Gohr  // print intermediate namespace links
709796bafb3SAndreas Gohr  $part = '';
710796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
711796bafb3SAndreas Gohr    $part .= $parts[$i].':';
712796bafb3SAndreas Gohr    $page = $part;
713796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
714796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
715796bafb3SAndreas Gohr
716796bafb3SAndreas Gohr    // output
717796bafb3SAndreas Gohr    echo $sep;
718796bafb3SAndreas Gohr    if($exists){
719796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
720796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
721e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
72231e187f8SSean Coates    }else{
723796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
72431e187f8SSean Coates    }
72531e187f8SSean Coates  }
7261734437eSandi
727796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
728d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
729796bafb3SAndreas Gohr  $page = $part.$parts[$i];
730796bafb3SAndreas Gohr  if($page == $conf['start']) return;
731796bafb3SAndreas Gohr  echo $sep;
732d8186216SBen Coburn  if(@file_exists(wikiFN($page))){
733796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
734796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
735e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
73631e187f8SSean Coates  }else{
737796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
7381734437eSandi  }
73954e95700STom N Harris  return true;
7401734437eSandi}
7411734437eSandi
7421734437eSandi/**
7436b13307fSandi * Print info if the user is logged in
744a2488c3cSMatthias Grimm * and show full name in that case
7456b13307fSandi *
7466b13307fSandi * Could be enhanced with a profile link in future?
7476b13307fSandi *
7486b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7496b13307fSandi */
7506b13307fSandifunction tpl_userinfo(){
7516b13307fSandi  global $lang;
752a2488c3cSMatthias Grimm  global $INFO;
75354e95700STom N Harris  if($_SERVER['REMOTE_USER']){
754a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
75554e95700STom N Harris    return true;
75654e95700STom N Harris  }
75754e95700STom N Harris  return false;
7586b13307fSandi}
7596b13307fSandi
7606b13307fSandi/**
7616b13307fSandi * Print some info about the current page
7626b13307fSandi *
7636b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7646b13307fSandi */
7656b13307fSandifunction tpl_pageinfo(){
7666b13307fSandi  global $conf;
7676b13307fSandi  global $lang;
7686b13307fSandi  global $INFO;
7696b13307fSandi  global $REV;
770c6e92a3cSDavid Lorentsen  global $ID;
771c6e92a3cSDavid Lorentsen
772c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
773c6e92a3cSDavid Lorentsen  if (!auth_quickaclcheck($ID)) { return; }
7746b13307fSandi
7756b13307fSandi  // prepare date and path
7766b13307fSandi  $fn = $INFO['filepath'];
7776b13307fSandi  if(!$conf['fullpath']){
7786b13307fSandi    if($REV){
7796b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
7806b13307fSandi    }else{
7816b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
7826b13307fSandi    }
7836b13307fSandi  }
784bee6dc82Sandi  $fn = utf8_decodeFN($fn);
7856b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
7866b13307fSandi
787faecdfdfSAndreas Gohr  // print it
788faecdfdfSAndreas Gohr  if($INFO['exists']){
7896b13307fSandi    print $fn;
7906b13307fSandi    print ' &middot; ';
7916b13307fSandi    print $lang['lastmod'];
7926b13307fSandi    print ': ';
7936b13307fSandi    print $date;
7946b13307fSandi    if($INFO['editor']){
7956b13307fSandi      print ' '.$lang['by'].' ';
7966b13307fSandi      print $INFO['editor'];
7975aa52fafSBen Coburn    }else{
7985aa52fafSBen Coburn      print ' ('.$lang['external_edit'].')';
7996b13307fSandi    }
8006b13307fSandi    if($INFO['locked']){
8016b13307fSandi      print ' &middot; ';
8026b13307fSandi      print $lang['lockedby'];
8036b13307fSandi      print ': ';
8046b13307fSandi      print $INFO['locked'];
8056b13307fSandi    }
80654e95700STom N Harris    return true;
8076b13307fSandi  }
80854e95700STom N Harris  return false;
8096b13307fSandi}
8106b13307fSandi
811820fa24bSandi/**
812a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
81387c434ceSAndreas Gohr *
81487c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
815a6598f23SBen Coburn * the given ID is used.
81687c434ceSAndreas Gohr *
81787c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
81887c434ceSAndreas Gohr */
819a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
82087c434ceSAndreas Gohr  global $conf;
82187c434ceSAndreas Gohr  if(is_null($id)){
82287c434ceSAndreas Gohr    global $ID;
82387c434ceSAndreas Gohr    $id = $ID;
82487c434ceSAndreas Gohr  }
82587c434ceSAndreas Gohr
82687c434ceSAndreas Gohr  $name = $id;
82787c434ceSAndreas Gohr  if ($conf['useheading']) {
82887c434ceSAndreas Gohr    $title = p_get_first_heading($id);
82987c434ceSAndreas Gohr    if ($title) $name = $title;
83087c434ceSAndreas Gohr  }
831a6598f23SBen Coburn
832a6598f23SBen Coburn  if ($ret) {
833a6598f23SBen Coburn      return hsc($name);
834a6598f23SBen Coburn  } else {
83587c434ceSAndreas Gohr      print hsc($name);
83654e95700STom N Harris      return true;
83787c434ceSAndreas Gohr  }
838a6598f23SBen Coburn}
839340756e4Sandi
84055efc227SAndreas Gohr/**
84155efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
84255efc227SAndreas Gohr *
84355efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
84455efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
84555efc227SAndreas Gohr *
84655efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
84755efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
84855efc227SAndreas Gohr * to the names of the latter one)
84955efc227SAndreas Gohr *
8503df72098SAndreas Gohr * Only allowed in: detail.php
85155efc227SAndreas Gohr *
85255efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
85355efc227SAndreas Gohr */
8543df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
85555efc227SAndreas Gohr  // Init Exif Reader
85655efc227SAndreas Gohr  global $SRC;
8573df72098SAndreas Gohr
8583df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
8593df72098SAndreas Gohr
86055efc227SAndreas Gohr  static $meta = null;
8613df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
86255efc227SAndreas Gohr  if($meta === false) return $alt;
86355efc227SAndreas Gohr  $info = $meta->getField($tags);
86455efc227SAndreas Gohr  if($info == false) return $alt;
86555efc227SAndreas Gohr  return $info;
86655efc227SAndreas Gohr}
86755efc227SAndreas Gohr
86855efc227SAndreas Gohr/**
86955efc227SAndreas Gohr * Prints the image with a link to the full sized version
87055efc227SAndreas Gohr *
87155efc227SAndreas Gohr * Only allowed in: detail.php
87255efc227SAndreas Gohr */
873f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
87455efc227SAndreas Gohr  global $IMG;
87555efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
87655efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
87755efc227SAndreas Gohr
87855efc227SAndreas Gohr  //resize to given max values
87923a34783SAndreas Gohr  $ratio = 1;
88023a34783SAndreas Gohr  if($w >= $h){
881f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
88255efc227SAndreas Gohr      $ratio = $maxwidth/$w;
883f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
88455efc227SAndreas Gohr      $ratio = $maxheight/$h;
88555efc227SAndreas Gohr    }
88655efc227SAndreas Gohr  }else{
887f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
88855efc227SAndreas Gohr      $ratio = $maxheight/$h;
889f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
89055efc227SAndreas Gohr      $ratio = $maxwidth/$w;
89155efc227SAndreas Gohr    }
89255efc227SAndreas Gohr  }
89355efc227SAndreas Gohr  if($ratio){
89455efc227SAndreas Gohr    $w = floor($ratio*$w);
89555efc227SAndreas Gohr    $h = floor($ratio*$h);
89655efc227SAndreas Gohr  }
89755efc227SAndreas Gohr
8986de3759aSAndreas Gohr  //prepare URLs
8996de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
9006de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
90155efc227SAndreas Gohr
9022684e50aSAndreas Gohr  //prepare attributes
90355efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
9042684e50aSAndreas Gohr  $p = array();
9052684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9062684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9072684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9082684e50aSAndreas Gohr  if($alt){
9092684e50aSAndreas Gohr    $p['alt']   = $alt;
9102684e50aSAndreas Gohr    $p['title'] = $alt;
9112684e50aSAndreas Gohr  }else{
9122684e50aSAndreas Gohr    $p['alt'] = '';
9132684e50aSAndreas Gohr  }
9142684e50aSAndreas Gohr  $p = buildAttributes($p);
91555efc227SAndreas Gohr
91655efc227SAndreas Gohr  print '<a href="'.$url.'">';
9176de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
91855efc227SAndreas Gohr  print '</a>';
91954e95700STom N Harris  return true;
92055efc227SAndreas Gohr}
92155efc227SAndreas Gohr
9227367b368SAndreas Gohr/**
9237367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9247367b368SAndreas Gohr * is the inexer function.
9257367b368SAndreas Gohr *
9267367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9277367b368SAndreas Gohr * template
9287367b368SAndreas Gohr */
9297367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9307367b368SAndreas Gohr  global $ID;
9311dad36f5SAndreas Gohr  global $INFO;
93254e95700STom N Harris  if(!$INFO['exists']) return false;
9331dad36f5SAndreas Gohr
93454e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
9350dc92c6fSAndreas Gohr
9367367b368SAndreas Gohr  $p = array();
937b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
938e68c51baSAndreas Gohr                 '&'.time();
9397367b368SAndreas Gohr  $p['width']  = 1;
9407367b368SAndreas Gohr  $p['height'] = 1;
9417367b368SAndreas Gohr  $p['alt']    = '';
9427367b368SAndreas Gohr  $att = buildAttributes($p);
9437367b368SAndreas Gohr  print "<img $att />";
94454e95700STom N Harris  return true;
9457367b368SAndreas Gohr}
9467367b368SAndreas Gohr
94778d4e784SEsther Brunner// configuration methods
94878d4e784SEsther Brunner/**
94978d4e784SEsther Brunner * tpl_getConf($id)
95078d4e784SEsther Brunner *
95178d4e784SEsther Brunner * use this function to access template configuration variables
95278d4e784SEsther Brunner */
95378d4e784SEsther Brunnerfunction tpl_getConf($id){
95478d4e784SEsther Brunner  global $conf;
95578d4e784SEsther Brunner  global $tpl_configloaded;
95678d4e784SEsther Brunner
95778d4e784SEsther Brunner  $tpl = $conf['template'];
95878d4e784SEsther Brunner
95978d4e784SEsther Brunner  if (!$tpl_configloaded){
96078d4e784SEsther Brunner    $tconf = tpl_loadConfig();
96178d4e784SEsther Brunner    if ($tconf !== false){
96278d4e784SEsther Brunner      foreach ($tconf as $key => $value){
96378d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
96478d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
96578d4e784SEsther Brunner      }
96678d4e784SEsther Brunner      $tpl_configloaded = true;
96778d4e784SEsther Brunner    }
96878d4e784SEsther Brunner  }
96978d4e784SEsther Brunner
97078d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
97178d4e784SEsther Brunner}
97278d4e784SEsther Brunner
97378d4e784SEsther Brunner/**
97478d4e784SEsther Brunner * tpl_loadConfig()
97578d4e784SEsther Brunner * reads all template configuration variables
97678d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
97778d4e784SEsther Brunner */
97878d4e784SEsther Brunnerfunction tpl_loadConfig(){
97978d4e784SEsther Brunner
98078d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
98178d4e784SEsther Brunner  $conf = array();
98278d4e784SEsther Brunner
98378d4e784SEsther Brunner  if (!@file_exists($file)) return false;
98478d4e784SEsther Brunner
98578d4e784SEsther Brunner  // load default config file
98678d4e784SEsther Brunner  include($file);
98778d4e784SEsther Brunner
98878d4e784SEsther Brunner  return $conf;
98978d4e784SEsther Brunner}
99078d4e784SEsther Brunner
9913df72098SAndreas Gohr/**
9923df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
9933df72098SAndreas Gohr *
9943df72098SAndreas Gohr * Depending on the user's actions this may be a list of
9953df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
9963df72098SAndreas Gohr * a message of referencing pages
9973df72098SAndreas Gohr *
9983df72098SAndreas Gohr * Only allowed in mediamanager.php
9993df72098SAndreas Gohr *
10003df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10013df72098SAndreas Gohr */
10023df72098SAndreas Gohrfunction tpl_mediaContent(){
10033df72098SAndreas Gohr  global $IMG;
10043df72098SAndreas Gohr  global $AUTH;
10053df72098SAndreas Gohr  global $INUSE;
10063df72098SAndreas Gohr  global $NS;
10073df72098SAndreas Gohr  global $JUMPTO;
10083df72098SAndreas Gohr
10093df72098SAndreas Gohr  ptln('<div id="media__content">');
10103df72098SAndreas Gohr  if($_REQUEST['edit']){
10113df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
10127b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
10133df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
10143df72098SAndreas Gohr  }else{
10153df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
10163df72098SAndreas Gohr  }
10173df72098SAndreas Gohr  ptln('</div>');
10183df72098SAndreas Gohr}
10193df72098SAndreas Gohr
10203df72098SAndreas Gohr/**
10213df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
10223df72098SAndreas Gohr *
10233df72098SAndreas Gohr * Only allowed in mediamanager.php
10243df72098SAndreas Gohr *
10253df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10263df72098SAndreas Gohr */
10273df72098SAndreas Gohrfunction tpl_mediaTree(){
10283df72098SAndreas Gohr  global $NS;
10293df72098SAndreas Gohr
10303df72098SAndreas Gohr  ptln('<div id="media__tree">');
10313df72098SAndreas Gohr  media_nstree($NS);
10323df72098SAndreas Gohr  ptln('</div>');
10333df72098SAndreas Gohr}
10343df72098SAndreas Gohr
1035340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1036