xref: /dokuwiki/inc/template.php (revision 4bb1b5aebf56b2cf69230d1e557674419bc06eaa)
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;
184*4bb1b5aeSAndreas Gohr  global $QUERY;
1856b13307fSandi  global $lang;
186dc57ef04Sandi  global $conf;
1876b13307fSandi  $it=2;
1886b13307fSandi
1897bff22c0SAndreas Gohr  // prepare the head array
1907bff22c0SAndreas Gohr  $head = array();
1917bff22c0SAndreas Gohr
1927bff22c0SAndreas Gohr
1936b13307fSandi  // the usual stuff
1947bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
195da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
196da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
197f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
1987bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
199bb4866bdSchris                           'title'=>$lang['btn_index'] );
200f96fa415SAndreas Gohr
201f96fa415SAndreas Gohr  if($alt){
2027bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2037bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2047bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2057bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2067bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
207*4bb1b5aeSAndreas Gohr    if($ACT == 'search'){
208*4bb1b5aeSAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
209*4bb1b5aeSAndreas Gohr                               'title'=>'Search Result',
210*4bb1b5aeSAndreas Gohr                               'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
211*4bb1b5aeSAndreas Gohr    }
212bae36d94SAndreas Gohr
213bae36d94SAndreas Gohr    if(actionOK('export_xhtml')){
2147bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2157bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'xhtml', '', false, '&'));
216bae36d94SAndreas Gohr    }
217bae36d94SAndreas Gohr
218bae36d94SAndreas Gohr    if(actionOK('export_raw')){
2197bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2207bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'raw', '', false, '&'));
221f96fa415SAndreas Gohr    }
222bae36d94SAndreas Gohr  }
2236b13307fSandi
2246b13307fSandi  // setup robot tags apropriate for different modes
2254f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2266b13307fSandi    if($INFO['exists']){
2276b13307fSandi      //delay indexing:
2286b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2297bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2306b13307fSandi      }else{
2317bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2326b13307fSandi      }
2336b13307fSandi    }else{
2347bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
2356b13307fSandi    }
2367a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2377bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2386b13307fSandi  }else{
2397bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2406b13307fSandi  }
2416b13307fSandi
242831800b8SAndreas Gohr  // set metadata
243831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
244831800b8SAndreas Gohr    // date of modification
245831800b8SAndreas Gohr    if($REV){
2467bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
247831800b8SAndreas Gohr    }else{
2487bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
249831800b8SAndreas Gohr    }
250831800b8SAndreas Gohr
251831800b8SAndreas Gohr    // keywords (explicit or implicit)
252bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
2537bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
254831800b8SAndreas Gohr    }else{
2557bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
256831800b8SAndreas Gohr    }
257831800b8SAndreas Gohr  }
258831800b8SAndreas Gohr
25978a6aeb1SAndreas Gohr  // load stylesheets
2607aaa4c46Smartin.tschofen  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
2617aaa4c46Smartin.tschofen                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all');
2627bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
2637bff22c0SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php');
2647bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
265615960feSTom N Harris                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
266bad31ae9SAndreas Gohr
26778a6aeb1SAndreas Gohr  // load javascript
268041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
269bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
2703df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
2713df72098SAndreas Gohr    $js_edit  = 1;
2723df72098SAndreas Gohr    $js_write = 0;
2733df72098SAndreas Gohr  }
2743df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
2757bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
276c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
277aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
2787bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
279c591aabeSAndreas Gohr    }
2807bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
2817bff22c0SAndreas Gohr                               '_data'=> $script);
282c591aabeSAndreas Gohr  }
2837bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
2847bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
2857bff22c0SAndreas Gohr
2867bff22c0SAndreas Gohr  // trigger event here
287016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
28854e95700STom N Harris  return true;
2897bff22c0SAndreas Gohr}
2907bff22c0SAndreas Gohr
2917bff22c0SAndreas Gohr/**
2927bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
2937bff22c0SAndreas Gohr *
2947bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
2957bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
2967bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
2977bff22c0SAndreas Gohr *
2987bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
2991304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3007bff22c0SAndreas Gohr *
3017bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3027bff22c0SAndreas Gohr */
3037bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3047bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
3057bff22c0SAndreas Gohr    foreach($inst as $attr){
3067bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
3077bff22c0SAndreas Gohr      if(isset($attr['_data'])){
308e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
309e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
310e226efe1SAndreas Gohr                             $attr['_data'].
311e226efe1SAndreas Gohr                             "\n//--><!]]>";
312e226efe1SAndreas Gohr
3131304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3147bff22c0SAndreas Gohr      }else{
3157bff22c0SAndreas Gohr        echo '/>';
3167bff22c0SAndreas Gohr      }
3177bff22c0SAndreas Gohr      echo "\n";
3187bff22c0SAndreas Gohr    }
3197bff22c0SAndreas Gohr  }
3206b13307fSandi}
3216b13307fSandi
3226b13307fSandi/**
3236b13307fSandi * Print a link
3246b13307fSandi *
3255e163278SAndreas Gohr * Just builds a link.
3266b13307fSandi *
3276b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3286b13307fSandi */
3296b13307fSandifunction tpl_link($url,$name,$more=''){
3305e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3316b13307fSandi  if ($more) print ' '.$more;
3326b13307fSandi  print ">$name</a>";
33354e95700STom N Harris  return true;
3346b13307fSandi}
3356b13307fSandi
3366b13307fSandi/**
33755efc227SAndreas Gohr * Prints a link to a WikiPage
33855efc227SAndreas Gohr *
33955efc227SAndreas Gohr * Wrapper around html_wikilink
34055efc227SAndreas Gohr *
34155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
34255efc227SAndreas Gohr */
34355efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
34455efc227SAndreas Gohr  print html_wikilink($id,$name);
34554e95700STom N Harris  return true;
34655efc227SAndreas Gohr}
34755efc227SAndreas Gohr
34855efc227SAndreas Gohr/**
349a3ec5f4aSmatthiasgrimm * get the parent page
350a3ec5f4aSmatthiasgrimm *
351a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
352a3ec5f4aSmatthiasgrimm * returns false if none is available
353a3ec5f4aSmatthiasgrimm *
354377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
355a3ec5f4aSmatthiasgrimm */
356377f9e97SAndreas Gohrfunction tpl_getparent($id){
357a3ec5f4aSmatthiasgrimm  global $conf;
358377f9e97SAndreas Gohr  $parent = getNS($id).':';
359377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
360a197105eSmatthiasgrimm  if($parent == $id) {
361a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
362a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
363a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
364377f9e97SAndreas Gohr    if($parent == $id) return false;
365a197105eSmatthiasgrimm  }
366377f9e97SAndreas Gohr  return $parent;
367a3ec5f4aSmatthiasgrimm}
368a3ec5f4aSmatthiasgrimm
369a3ec5f4aSmatthiasgrimm/**
3706b13307fSandi * Print one of the buttons
3716b13307fSandi *
3726b13307fSandi * Available Buttons are
3736b13307fSandi *
374ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
3756b13307fSandi *  history     - old revisions
3766b13307fSandi *  recent      - recent changes
3776b13307fSandi *  login       - login/logout button - if ACL enabled
378d449b912SDenis Simakov *  profile     - user profile button (if logged in)
3796b13307fSandi *  index       - The index
380c19fe9c0Sandi *  admin       - admin page - if enough rights
3816b13307fSandi *  top         - a back to top button
382a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
383bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
384d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
3856b13307fSandi *
3866b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
387a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
3886b13307fSandi */
3896b13307fSandifunction tpl_button($type){
390b158d625SSteven Danz  global $ACT;
3916b13307fSandi  global $ID;
392d98d4540SBen Coburn  global $REV;
393d67ca2c0Smatthiasgrimm  global $NS;
394c19fe9c0Sandi  global $INFO;
3956b13307fSandi  global $conf;
396cd52f92dSchris  global $auth;
3976b13307fSandi
39875e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
39975e487e9SAndreas Gohr  $ctype = $type;
40075e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
40154e95700STom N Harris  if(!actionOK($ctype)) return false;
402409d7af7SAndreas Gohr
4036b13307fSandi  switch($type){
4046b13307fSandi    case 'edit':
405409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
406409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
407409d7af7SAndreas Gohr        if($INFO['writable']){
408bb4866bdSchris          if(!empty($INFO['draft'])){
409409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
410409d7af7SAndreas Gohr          }else{
411409d7af7SAndreas Gohr            if($INFO['exists']){
412409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
413409d7af7SAndreas Gohr            }else{
414409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
415409d7af7SAndreas Gohr            }
416409d7af7SAndreas Gohr          }
417409d7af7SAndreas Gohr        }else{
418409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
419409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
420409d7af7SAndreas Gohr        }
421409d7af7SAndreas Gohr      }else{
422409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
423409d7af7SAndreas Gohr      }
42454e95700STom N Harris      return true;
4256b13307fSandi    case 'history':
4265bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
42754e95700STom N Harris      return true;
4286b13307fSandi    case 'recent':
4295bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
43054e95700STom N Harris      return true;
4316b13307fSandi    case 'index':
4325bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
43354e95700STom N Harris      return true;
434a3ec5f4aSmatthiasgrimm    case 'back':
4356222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4366222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
43754e95700STom N Harris        return true;
438a3ec5f4aSmatthiasgrimm      }
43954e95700STom N Harris      return false;
4406b13307fSandi    case 'top':
4416b13307fSandi      print html_topbtn();
44254e95700STom N Harris      return true;
4436b13307fSandi    case 'login':
4446957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
4456b13307fSandi        if($_SERVER['REMOTE_USER']){
4466b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
4476b13307fSandi        }else{
4486b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
4496b13307fSandi        }
45054e95700STom N Harris        return true;
4516b13307fSandi      }
45254e95700STom N Harris      return false;
453c19fe9c0Sandi    case 'admin':
45454e95700STom N Harris      if($INFO['ismanager']){
4555bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
45654e95700STom N Harris        return true;
45754e95700STom N Harris      }
45854e95700STom N Harris      return false;
4591380fc45SAndreas Gohr    case 'subscription':
4606957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
461b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
4621380fc45SAndreas Gohr          if($INFO['subscribed']){
4631380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
464b158d625SSteven Danz          } else {
4651380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
466b158d625SSteven Danz          }
46754e95700STom N Harris          return true;
468b158d625SSteven Danz        }
469b158d625SSteven Danz      }
47054e95700STom N Harris      return false;
471f00151b4Schris    case 'backlink':
472f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
47354e95700STom N Harris      return true;
4748b06d178Schris    case 'profile':
4756957b2eaSAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth &&
47636223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
4778b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
47854e95700STom N Harris        return true;
4798b06d178Schris      }
48054e95700STom N Harris      return false;
481c19fe9c0Sandi    default:
482c19fe9c0Sandi      print '[unknown button type]';
48354e95700STom N Harris      return true;
4846b13307fSandi  }
4856b13307fSandi}
4866b13307fSandi
4876b13307fSandi/**
488ed630903Sandi * Like the action buttons but links
489ed630903Sandi *
490ed630903Sandi * Available links are
491ed630903Sandi *
492d449b912SDenis Simakov *  edit    - edit/create/show link
493ed630903Sandi *  history - old revisions
494ed630903Sandi *  recent  - recent changes
495d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
496d449b912SDenis Simakov *  profile - user profile link (if logged in)
497ed630903Sandi *  index   - The index
498ed630903Sandi *  admin   - admin page - if enough rights
499d449b912SDenis Simakov *  top     - a back to top link
500d449b912SDenis Simakov *  back    - a back to parent link - if available
501bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
502d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
503ed630903Sandi *
504ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
505a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
506ed630903Sandi * @see    tpl_button
507ed630903Sandi */
508ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
509ed630903Sandi  global $ID;
510ed630903Sandi  global $INFO;
511ed630903Sandi  global $REV;
512ed630903Sandi  global $ACT;
513ed630903Sandi  global $conf;
514ed630903Sandi  global $lang;
515cd52f92dSchris  global $auth;
516ed630903Sandi
51775e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
51875e487e9SAndreas Gohr  $ctype = $type;
51975e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
52054e95700STom N Harris  if(!actionOK($ctype)) return false;
521409d7af7SAndreas Gohr
522ed630903Sandi  switch($type){
523ed630903Sandi    case 'edit':
524ed630903Sandi      #most complicated type - we need to decide on current action
525ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
526ed630903Sandi        if($INFO['writable']){
527b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
528b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
529b8a111f5SMichael Klier                       $pre.$lang['btn_draft'].$suf,
530b8a111f5SMichael Klier                       'class="action edit" acceskey="e" rel="nofollow"');
531b8a111f5SMichael Klier          } else {
532ed630903Sandi            if($INFO['exists']){
533ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
534ed630903Sandi                       $pre.$lang['btn_edit'].$suf,
535b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
536ed630903Sandi            }else{
537ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
538ed630903Sandi                       $pre.$lang['btn_create'].$suf,
539b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
540ed630903Sandi            }
541b8a111f5SMichael Klier          }
542ed630903Sandi        }else{
543409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
544ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
545ed630903Sandi                   $pre.$lang['btn_source'].$suf,
546b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
547ed630903Sandi        }
548ed630903Sandi      }else{
549ed630903Sandi          tpl_link(wl($ID,'do=show'),
550ed630903Sandi                   $pre.$lang['btn_show'].$suf,
551b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
552ed630903Sandi      }
553c059e1a6SAndreas Gohr      return true;
554ed630903Sandi    case 'history':
55541dfcdfcSAndreas Gohr      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o" rel="nofollow"');
556c059e1a6SAndreas Gohr      return true;
557ed630903Sandi    case 'recent':
5585e79da84SAnika Henke      tpl_link(wl('','do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r" rel="nofollow"');
559c059e1a6SAndreas Gohr      return true;
560ed630903Sandi    case 'index':
56141dfcdfcSAndreas Gohr      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x" rel="nofollow"');
562c059e1a6SAndreas Gohr      return true;
563ed630903Sandi    case 'top':
56421a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
565c059e1a6SAndreas Gohr      return true;
566a3ec5f4aSmatthiasgrimm    case 'back':
567f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
56841dfcdfcSAndreas Gohr        tpl_link(wl($parent,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b" rel="nofollow"');
569c059e1a6SAndreas Gohr        return true;
570a3ec5f4aSmatthiasgrimm      }
571c059e1a6SAndreas Gohr      return false;
572ed630903Sandi    case 'login':
5736957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
574ed630903Sandi        if($_SERVER['REMOTE_USER']){
57541dfcdfcSAndreas Gohr          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout" rel="nofollow"');
576ed630903Sandi        }else{
57741dfcdfcSAndreas Gohr          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action login" rel="nofollow"');
578ed630903Sandi        }
579c059e1a6SAndreas Gohr        return true;
580ed630903Sandi      }
581c059e1a6SAndreas Gohr      return false;
582ed630903Sandi    case 'admin':
583f8cc712eSAndreas Gohr      if($INFO['ismanager']){
58441dfcdfcSAndreas Gohr        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin" rel="nofollow"');
585c059e1a6SAndreas Gohr        return true;
586c059e1a6SAndreas Gohr      }
587c059e1a6SAndreas Gohr      return false;
588f9eb5648Ssteven-danz   case 'subscribe':
589075f000fSChristopher Arndt   case 'subscription':
5906957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
591b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
592075f000fSChristopher Arndt          if($INFO['subscribed']) {
59341dfcdfcSAndreas Gohr            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe" rel="nofollow"');
594b158d625SSteven Danz          } else {
59541dfcdfcSAndreas Gohr            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe" rel="nofollow"');
596b158d625SSteven Danz          }
597c059e1a6SAndreas Gohr          return true;
598b158d625SSteven Danz        }
599b158d625SSteven Danz      }
600c059e1a6SAndreas Gohr      return false;
601f00151b4Schris    case 'backlink':
60241dfcdfcSAndreas Gohr      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink" rel="nofollow"');
603c059e1a6SAndreas Gohr      return true;
6048b06d178Schris    case 'profile':
6056957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
60636223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
60741dfcdfcSAndreas Gohr        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile" rel="nofollow"');
608c059e1a6SAndreas Gohr        return true;
6098b06d178Schris      }
610c059e1a6SAndreas Gohr      return false;
611ed630903Sandi    default:
612ed630903Sandi      print '[unknown link type]';
613c059e1a6SAndreas Gohr      return true;
614ed630903Sandi  }
615ed630903Sandi}
616ed630903Sandi
617ed630903Sandi/**
6186b13307fSandi * Print the search form
6196b13307fSandi *
62072645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
62172645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
62272645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
62372645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
62472645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
62572645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
62672645b75SAndreas Gohr *
6276b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6286b13307fSandi */
62972645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6306b13307fSandi  global $lang;
631c1e3b7d9Smatthiasgrimm  global $ACT;
632c1e3b7d9Smatthiasgrimm
633670ff54eSchris  // don't print the search form if search action has been disabled
63454e95700STom N Harris  if (!actionOk('search')) return false;
635670ff54eSchris
6361dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6376b13307fSandi  print '<input type="hidden" name="do" value="search" />';
638c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
639bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
64072645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
641818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
64211ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
64324a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6444beabca9SAnika Henke  print '</div></form>';
64554e95700STom N Harris  return true;
6466b13307fSandi}
6476b13307fSandi
6486b13307fSandi/**
6496b13307fSandi * Print the breadcrumbs trace
6506b13307fSandi *
6516b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6526b13307fSandi */
65354e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
6546b13307fSandi  global $lang;
6556b13307fSandi  global $conf;
6566b13307fSandi
6576b13307fSandi  //check if enabled
65854e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
6596b13307fSandi
6606b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
661265e3787Sandi
6622979a10bSKatriel Traum  //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
6632979a10bSKatriel Traum  if($lang['direction'] == 'rtl') {
6642979a10bSKatriel Traum    $crumbs = array_reverse($crumbs,true);
6652979a10bSKatriel Traum    $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
6662979a10bSKatriel Traum  } else {
6672979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
6682979a10bSKatriel Traum  }
669265e3787Sandi
67040eb54bbSjan  //render crumbs, highlight the last one
6716b13307fSandi  print $lang['breadcrumb'].':';
67240eb54bbSjan  $last = count($crumbs);
67340eb54bbSjan  $i = 0;
674a77f5846Sjan  foreach ($crumbs as $id => $name){
67540eb54bbSjan    $i++;
6762979a10bSKatriel Traum    echo $crumbs_sep;
67792795d04Sandi    if ($i == $last) print '<span class="curid">';
678e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
67992795d04Sandi    if ($i == $last) print '</span>';
6806b13307fSandi  }
68154e95700STom N Harris  return true;
6826b13307fSandi}
6836b13307fSandi
6846b13307fSandi/**
6851734437eSandi * Hierarchical breadcrumbs
6861734437eSandi *
68731e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
6881734437eSandi * It only makes sense with a deep site structure.
6891734437eSandi *
6901734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
6916bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
69231e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
6931734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
6946bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
6951734437eSandi */
696796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
6971734437eSandi  global $conf;
6981734437eSandi  global $ID;
6991734437eSandi  global $lang;
7001734437eSandi
70131e187f8SSean Coates  // check if enabled
70254e95700STom N Harris  if(!$conf['youarehere']) return false;
7031734437eSandi
7041734437eSandi  $parts = explode(':', $ID);
705796bafb3SAndreas Gohr  $count = count($parts);
7061734437eSandi
707796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
7081734437eSandi
7091734437eSandi  // always print the startpage
710796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
711796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
712e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
713796bafb3SAndreas Gohr
714796bafb3SAndreas Gohr  // print intermediate namespace links
715796bafb3SAndreas Gohr  $part = '';
716796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
717796bafb3SAndreas Gohr    $part .= $parts[$i].':';
718796bafb3SAndreas Gohr    $page = $part;
719796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
720796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
721796bafb3SAndreas Gohr
722796bafb3SAndreas Gohr    // output
723796bafb3SAndreas Gohr    echo $sep;
724796bafb3SAndreas Gohr    if($exists){
725796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
726796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
727e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
72831e187f8SSean Coates    }else{
729796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
73031e187f8SSean Coates    }
73131e187f8SSean Coates  }
7321734437eSandi
733796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
734d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
735796bafb3SAndreas Gohr  $page = $part.$parts[$i];
736796bafb3SAndreas Gohr  if($page == $conf['start']) return;
737796bafb3SAndreas Gohr  echo $sep;
738d8186216SBen Coburn  if(@file_exists(wikiFN($page))){
739796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
740796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
741e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
74231e187f8SSean Coates  }else{
743796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
7441734437eSandi  }
74554e95700STom N Harris  return true;
7461734437eSandi}
7471734437eSandi
7481734437eSandi/**
7496b13307fSandi * Print info if the user is logged in
750a2488c3cSMatthias Grimm * and show full name in that case
7516b13307fSandi *
7526b13307fSandi * Could be enhanced with a profile link in future?
7536b13307fSandi *
7546b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7556b13307fSandi */
7566b13307fSandifunction tpl_userinfo(){
7576b13307fSandi  global $lang;
758a2488c3cSMatthias Grimm  global $INFO;
75954e95700STom N Harris  if($_SERVER['REMOTE_USER']){
760a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
76154e95700STom N Harris    return true;
76254e95700STom N Harris  }
76354e95700STom N Harris  return false;
7646b13307fSandi}
7656b13307fSandi
7666b13307fSandi/**
7676b13307fSandi * Print some info about the current page
7686b13307fSandi *
7696b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7706b13307fSandi */
7716b13307fSandifunction tpl_pageinfo(){
7726b13307fSandi  global $conf;
7736b13307fSandi  global $lang;
7746b13307fSandi  global $INFO;
7756b13307fSandi  global $REV;
776c6e92a3cSDavid Lorentsen  global $ID;
777c6e92a3cSDavid Lorentsen
778c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
779c6e92a3cSDavid Lorentsen  if (!auth_quickaclcheck($ID)) { return; }
7806b13307fSandi
7816b13307fSandi  // prepare date and path
7826b13307fSandi  $fn = $INFO['filepath'];
7836b13307fSandi  if(!$conf['fullpath']){
7846b13307fSandi    if($REV){
7856b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
7866b13307fSandi    }else{
7876b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
7886b13307fSandi    }
7896b13307fSandi  }
790bee6dc82Sandi  $fn = utf8_decodeFN($fn);
7916b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
7926b13307fSandi
793faecdfdfSAndreas Gohr  // print it
794faecdfdfSAndreas Gohr  if($INFO['exists']){
7956b13307fSandi    print $fn;
7966b13307fSandi    print ' &middot; ';
7976b13307fSandi    print $lang['lastmod'];
7986b13307fSandi    print ': ';
7996b13307fSandi    print $date;
8006b13307fSandi    if($INFO['editor']){
8016b13307fSandi      print ' '.$lang['by'].' ';
8026b13307fSandi      print $INFO['editor'];
8035aa52fafSBen Coburn    }else{
8045aa52fafSBen Coburn      print ' ('.$lang['external_edit'].')';
8056b13307fSandi    }
8066b13307fSandi    if($INFO['locked']){
8076b13307fSandi      print ' &middot; ';
8086b13307fSandi      print $lang['lockedby'];
8096b13307fSandi      print ': ';
8106b13307fSandi      print $INFO['locked'];
8116b13307fSandi    }
81254e95700STom N Harris    return true;
8136b13307fSandi  }
81454e95700STom N Harris  return false;
8156b13307fSandi}
8166b13307fSandi
817820fa24bSandi/**
818a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
81987c434ceSAndreas Gohr *
82087c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
821a6598f23SBen Coburn * the given ID is used.
82287c434ceSAndreas Gohr *
82387c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
82487c434ceSAndreas Gohr */
825a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
82687c434ceSAndreas Gohr  global $conf;
82787c434ceSAndreas Gohr  if(is_null($id)){
82887c434ceSAndreas Gohr    global $ID;
82987c434ceSAndreas Gohr    $id = $ID;
83087c434ceSAndreas Gohr  }
83187c434ceSAndreas Gohr
83287c434ceSAndreas Gohr  $name = $id;
83387c434ceSAndreas Gohr  if ($conf['useheading']) {
83487c434ceSAndreas Gohr    $title = p_get_first_heading($id);
83587c434ceSAndreas Gohr    if ($title) $name = $title;
83687c434ceSAndreas Gohr  }
837a6598f23SBen Coburn
838a6598f23SBen Coburn  if ($ret) {
839a6598f23SBen Coburn      return hsc($name);
840a6598f23SBen Coburn  } else {
84187c434ceSAndreas Gohr      print hsc($name);
84254e95700STom N Harris      return true;
84387c434ceSAndreas Gohr  }
844a6598f23SBen Coburn}
845340756e4Sandi
84655efc227SAndreas Gohr/**
84755efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
84855efc227SAndreas Gohr *
84955efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
85055efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
85155efc227SAndreas Gohr *
85255efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
85355efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
85455efc227SAndreas Gohr * to the names of the latter one)
85555efc227SAndreas Gohr *
8563df72098SAndreas Gohr * Only allowed in: detail.php
85755efc227SAndreas Gohr *
85855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
85955efc227SAndreas Gohr */
8603df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
86155efc227SAndreas Gohr  // Init Exif Reader
86255efc227SAndreas Gohr  global $SRC;
8633df72098SAndreas Gohr
8643df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
8653df72098SAndreas Gohr
86655efc227SAndreas Gohr  static $meta = null;
8673df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
86855efc227SAndreas Gohr  if($meta === false) return $alt;
86955efc227SAndreas Gohr  $info = $meta->getField($tags);
87055efc227SAndreas Gohr  if($info == false) return $alt;
87155efc227SAndreas Gohr  return $info;
87255efc227SAndreas Gohr}
87355efc227SAndreas Gohr
87455efc227SAndreas Gohr/**
87555efc227SAndreas Gohr * Prints the image with a link to the full sized version
87655efc227SAndreas Gohr *
87755efc227SAndreas Gohr * Only allowed in: detail.php
87855efc227SAndreas Gohr */
879f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
88055efc227SAndreas Gohr  global $IMG;
88155efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
88255efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
88355efc227SAndreas Gohr
88455efc227SAndreas Gohr  //resize to given max values
88523a34783SAndreas Gohr  $ratio = 1;
88623a34783SAndreas Gohr  if($w >= $h){
887f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
88855efc227SAndreas Gohr      $ratio = $maxwidth/$w;
889f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
89055efc227SAndreas Gohr      $ratio = $maxheight/$h;
89155efc227SAndreas Gohr    }
89255efc227SAndreas Gohr  }else{
893f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
89455efc227SAndreas Gohr      $ratio = $maxheight/$h;
895f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
89655efc227SAndreas Gohr      $ratio = $maxwidth/$w;
89755efc227SAndreas Gohr    }
89855efc227SAndreas Gohr  }
89955efc227SAndreas Gohr  if($ratio){
90055efc227SAndreas Gohr    $w = floor($ratio*$w);
90155efc227SAndreas Gohr    $h = floor($ratio*$h);
90255efc227SAndreas Gohr  }
90355efc227SAndreas Gohr
9046de3759aSAndreas Gohr  //prepare URLs
9056de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
9066de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
90755efc227SAndreas Gohr
9082684e50aSAndreas Gohr  //prepare attributes
90955efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
9102684e50aSAndreas Gohr  $p = array();
9112684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9122684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9132684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9142684e50aSAndreas Gohr  if($alt){
9152684e50aSAndreas Gohr    $p['alt']   = $alt;
9162684e50aSAndreas Gohr    $p['title'] = $alt;
9172684e50aSAndreas Gohr  }else{
9182684e50aSAndreas Gohr    $p['alt'] = '';
9192684e50aSAndreas Gohr  }
9202684e50aSAndreas Gohr  $p = buildAttributes($p);
92155efc227SAndreas Gohr
92255efc227SAndreas Gohr  print '<a href="'.$url.'">';
9236de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
92455efc227SAndreas Gohr  print '</a>';
92554e95700STom N Harris  return true;
92655efc227SAndreas Gohr}
92755efc227SAndreas Gohr
9287367b368SAndreas Gohr/**
9297367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9307367b368SAndreas Gohr * is the inexer function.
9317367b368SAndreas Gohr *
9327367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9337367b368SAndreas Gohr * template
9347367b368SAndreas Gohr */
9357367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9367367b368SAndreas Gohr  global $ID;
9371dad36f5SAndreas Gohr  global $INFO;
93854e95700STom N Harris  if(!$INFO['exists']) return false;
9391dad36f5SAndreas Gohr
94054e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
9410dc92c6fSAndreas Gohr
9427367b368SAndreas Gohr  $p = array();
943b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
944e68c51baSAndreas Gohr                 '&'.time();
9457367b368SAndreas Gohr  $p['width']  = 1;
9467367b368SAndreas Gohr  $p['height'] = 1;
9477367b368SAndreas Gohr  $p['alt']    = '';
9487367b368SAndreas Gohr  $att = buildAttributes($p);
9497367b368SAndreas Gohr  print "<img $att />";
95054e95700STom N Harris  return true;
9517367b368SAndreas Gohr}
9527367b368SAndreas Gohr
95378d4e784SEsther Brunner// configuration methods
95478d4e784SEsther Brunner/**
95578d4e784SEsther Brunner * tpl_getConf($id)
95678d4e784SEsther Brunner *
95778d4e784SEsther Brunner * use this function to access template configuration variables
95878d4e784SEsther Brunner */
95978d4e784SEsther Brunnerfunction tpl_getConf($id){
96078d4e784SEsther Brunner  global $conf;
96178d4e784SEsther Brunner  global $tpl_configloaded;
96278d4e784SEsther Brunner
96378d4e784SEsther Brunner  $tpl = $conf['template'];
96478d4e784SEsther Brunner
96578d4e784SEsther Brunner  if (!$tpl_configloaded){
96678d4e784SEsther Brunner    $tconf = tpl_loadConfig();
96778d4e784SEsther Brunner    if ($tconf !== false){
96878d4e784SEsther Brunner      foreach ($tconf as $key => $value){
96978d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
97078d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
97178d4e784SEsther Brunner      }
97278d4e784SEsther Brunner      $tpl_configloaded = true;
97378d4e784SEsther Brunner    }
97478d4e784SEsther Brunner  }
97578d4e784SEsther Brunner
97678d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
97778d4e784SEsther Brunner}
97878d4e784SEsther Brunner
97978d4e784SEsther Brunner/**
98078d4e784SEsther Brunner * tpl_loadConfig()
98178d4e784SEsther Brunner * reads all template configuration variables
98278d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
98378d4e784SEsther Brunner */
98478d4e784SEsther Brunnerfunction tpl_loadConfig(){
98578d4e784SEsther Brunner
98678d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
98778d4e784SEsther Brunner  $conf = array();
98878d4e784SEsther Brunner
98978d4e784SEsther Brunner  if (!@file_exists($file)) return false;
99078d4e784SEsther Brunner
99178d4e784SEsther Brunner  // load default config file
99278d4e784SEsther Brunner  include($file);
99378d4e784SEsther Brunner
99478d4e784SEsther Brunner  return $conf;
99578d4e784SEsther Brunner}
99678d4e784SEsther Brunner
9973df72098SAndreas Gohr/**
9983df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
9993df72098SAndreas Gohr *
10003df72098SAndreas Gohr * Depending on the user's actions this may be a list of
10013df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
10023df72098SAndreas Gohr * a message of referencing pages
10033df72098SAndreas Gohr *
10043df72098SAndreas Gohr * Only allowed in mediamanager.php
10053df72098SAndreas Gohr *
10063df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10073df72098SAndreas Gohr */
10083df72098SAndreas Gohrfunction tpl_mediaContent(){
10093df72098SAndreas Gohr  global $IMG;
10103df72098SAndreas Gohr  global $AUTH;
10113df72098SAndreas Gohr  global $INUSE;
10123df72098SAndreas Gohr  global $NS;
10133df72098SAndreas Gohr  global $JUMPTO;
10143df72098SAndreas Gohr
10153df72098SAndreas Gohr  ptln('<div id="media__content">');
10163df72098SAndreas Gohr  if($_REQUEST['edit']){
10173df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
10187b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
10193df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
10203df72098SAndreas Gohr  }else{
10213df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
10223df72098SAndreas Gohr  }
10233df72098SAndreas Gohr  ptln('</div>');
10243df72098SAndreas Gohr}
10253df72098SAndreas Gohr
10263df72098SAndreas Gohr/**
10273df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
10283df72098SAndreas Gohr *
10293df72098SAndreas Gohr * Only allowed in mediamanager.php
10303df72098SAndreas Gohr *
10313df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10323df72098SAndreas Gohr */
10333df72098SAndreas Gohrfunction tpl_mediaTree(){
10343df72098SAndreas Gohr  global $NS;
10353df72098SAndreas Gohr
10363df72098SAndreas Gohr  ptln('<div id="media__tree">');
10373df72098SAndreas Gohr  media_nstree($NS);
10383df72098SAndreas Gohr  ptln('</div>');
10393df72098SAndreas Gohr}
10403df72098SAndreas Gohr
1041340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1042