xref: /dokuwiki/inc/template.php (revision c97dfb07cefa8287f778773c12a19108c079cb6b)
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;
1844bb1b5aeSAndreas 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']);
2074bb1b5aeSAndreas Gohr    if($ACT == 'search'){
2084bb1b5aeSAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2094bb1b5aeSAndreas Gohr                               'title'=>'Search Result',
2104bb1b5aeSAndreas Gohr                               'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
2114bb1b5aeSAndreas 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 */
508*c97dfb07SAndreas Gohrfunction tpl_actionlink($type,$pre='',$suf='',$inner=''){
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'),
529*c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$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),
534*c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_edit']).$suf,
535b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
536ed630903Sandi            }else{
537ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
538*c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$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),
545*c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_source']).$suf,
546b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
547ed630903Sandi        }
548ed630903Sandi      }else{
549ed630903Sandi          tpl_link(wl($ID,'do=show'),
550*c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_show']).$suf,
551b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
552ed630903Sandi      }
553c059e1a6SAndreas Gohr      return true;
554ed630903Sandi    case 'history':
555*c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=revisions'),
556*c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_revs']).$suf,
557*c97dfb07SAndreas Gohr               'class="action revisions" accesskey="o" rel="nofollow"');
558c059e1a6SAndreas Gohr      return true;
559ed630903Sandi    case 'recent':
560*c97dfb07SAndreas Gohr      tpl_link(wl('','do=recent'),
561*c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_recent']).$suf,
562*c97dfb07SAndreas Gohr              'class="action recent" accesskey="r" rel="nofollow"');
563c059e1a6SAndreas Gohr      return true;
564ed630903Sandi    case 'index':
565*c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=index'),
566*c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_index']).$suf,
567*c97dfb07SAndreas Gohr              'class="action index" accesskey="x" rel="nofollow"');
568c059e1a6SAndreas Gohr      return true;
569ed630903Sandi    case 'top':
570*c97dfb07SAndreas Gohr      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.
571*c97dfb07SAndreas Gohr            $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>';
572c059e1a6SAndreas Gohr      return true;
573a3ec5f4aSmatthiasgrimm    case 'back':
574f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
575*c97dfb07SAndreas Gohr        tpl_link(wl($parent,'do=show'),
576*c97dfb07SAndreas Gohr        $pre.(($inner)?$inner:$lang['btn_back']).$suf,
577*c97dfb07SAndreas Gohr        'class="action back" accesskey="b" rel="nofollow"');
578c059e1a6SAndreas Gohr        return true;
579a3ec5f4aSmatthiasgrimm      }
580c059e1a6SAndreas Gohr      return false;
581ed630903Sandi    case 'login':
5826957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
583ed630903Sandi        if($_SERVER['REMOTE_USER']){
584*c97dfb07SAndreas Gohr          tpl_link(wl($ID,'do=logout'),
585*c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_logout']).$suf,
586*c97dfb07SAndreas Gohr                   'class="action logout" rel="nofollow"');
587ed630903Sandi        }else{
588*c97dfb07SAndreas Gohr          tpl_link(wl($ID,'do=login'),
589*c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_login']).$suf,
590*c97dfb07SAndreas Gohr                   'class="action login" rel="nofollow"');
591ed630903Sandi        }
592c059e1a6SAndreas Gohr        return true;
593ed630903Sandi      }
594c059e1a6SAndreas Gohr      return false;
595ed630903Sandi    case 'admin':
596f8cc712eSAndreas Gohr      if($INFO['ismanager']){
597*c97dfb07SAndreas Gohr        tpl_link(wl($ID,'do=admin'),
598*c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_admin']).$suf,
599*c97dfb07SAndreas Gohr                 'class="action admin" rel="nofollow"');
600c059e1a6SAndreas Gohr        return true;
601c059e1a6SAndreas Gohr      }
602c059e1a6SAndreas Gohr      return false;
603f9eb5648Ssteven-danz   case 'subscribe':
604075f000fSChristopher Arndt   case 'subscription':
6056957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
606b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
607075f000fSChristopher Arndt          if($INFO['subscribed']) {
608*c97dfb07SAndreas Gohr            tpl_link(wl($ID,'do=unsubscribe'),
609*c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_unsubscribe']).$suf,
610*c97dfb07SAndreas Gohr                     'class="action unsubscribe" rel="nofollow"');
611b158d625SSteven Danz          } else {
612*c97dfb07SAndreas Gohr            tpl_link(wl($ID,'do=subscribe'),
613*c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf,
614*c97dfb07SAndreas Gohr                     'class="action subscribe" rel="nofollow"');
615b158d625SSteven Danz          }
616c059e1a6SAndreas Gohr          return true;
617b158d625SSteven Danz        }
618b158d625SSteven Danz      }
619c059e1a6SAndreas Gohr      return false;
620f00151b4Schris    case 'backlink':
621*c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=backlink'),
622*c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_backlink']).$suf,
623*c97dfb07SAndreas Gohr               'class="action backlink" rel="nofollow"');
624c059e1a6SAndreas Gohr      return true;
6258b06d178Schris    case 'profile':
6266957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
62736223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
628*c97dfb07SAndreas Gohr        tpl_link(wl($ID,'do=profile'),
629*c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_profile']).$suf,
630*c97dfb07SAndreas Gohr                 'class="action profile" rel="nofollow"');
631c059e1a6SAndreas Gohr        return true;
6328b06d178Schris      }
633c059e1a6SAndreas Gohr      return false;
634ed630903Sandi    default:
635ed630903Sandi      print '[unknown link type]';
636c059e1a6SAndreas Gohr      return true;
637ed630903Sandi  }
638ed630903Sandi}
639ed630903Sandi
640ed630903Sandi/**
6416b13307fSandi * Print the search form
6426b13307fSandi *
64372645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
64472645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
64572645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
64672645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
64772645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
64872645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
64972645b75SAndreas Gohr *
6506b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6516b13307fSandi */
65272645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6536b13307fSandi  global $lang;
654c1e3b7d9Smatthiasgrimm  global $ACT;
655c1e3b7d9Smatthiasgrimm
656670ff54eSchris  // don't print the search form if search action has been disabled
65754e95700STom N Harris  if (!actionOk('search')) return false;
658670ff54eSchris
6591dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6606b13307fSandi  print '<input type="hidden" name="do" value="search" />';
661c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
662bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
66372645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
664818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
66511ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
66624a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6674beabca9SAnika Henke  print '</div></form>';
66854e95700STom N Harris  return true;
6696b13307fSandi}
6706b13307fSandi
6716b13307fSandi/**
6726b13307fSandi * Print the breadcrumbs trace
6736b13307fSandi *
6746b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6756b13307fSandi */
67654e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
6776b13307fSandi  global $lang;
6786b13307fSandi  global $conf;
6796b13307fSandi
6806b13307fSandi  //check if enabled
68154e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
6826b13307fSandi
6836b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
684265e3787Sandi
6852979a10bSKatriel Traum  //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
6862979a10bSKatriel Traum  if($lang['direction'] == 'rtl') {
6872979a10bSKatriel Traum    $crumbs = array_reverse($crumbs,true);
6882979a10bSKatriel Traum    $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
6892979a10bSKatriel Traum  } else {
6902979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
6912979a10bSKatriel Traum  }
692265e3787Sandi
69340eb54bbSjan  //render crumbs, highlight the last one
6946b13307fSandi  print $lang['breadcrumb'].':';
69540eb54bbSjan  $last = count($crumbs);
69640eb54bbSjan  $i = 0;
697a77f5846Sjan  foreach ($crumbs as $id => $name){
69840eb54bbSjan    $i++;
6992979a10bSKatriel Traum    echo $crumbs_sep;
70092795d04Sandi    if ($i == $last) print '<span class="curid">';
701e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
70292795d04Sandi    if ($i == $last) print '</span>';
7036b13307fSandi  }
70454e95700STom N Harris  return true;
7056b13307fSandi}
7066b13307fSandi
7076b13307fSandi/**
7081734437eSandi * Hierarchical breadcrumbs
7091734437eSandi *
71031e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7111734437eSandi * It only makes sense with a deep site structure.
7121734437eSandi *
7131734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7146bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
71531e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
7161734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
7176bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
7181734437eSandi */
719796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
7201734437eSandi  global $conf;
7211734437eSandi  global $ID;
7221734437eSandi  global $lang;
7231734437eSandi
72431e187f8SSean Coates  // check if enabled
72554e95700STom N Harris  if(!$conf['youarehere']) return false;
7261734437eSandi
7271734437eSandi  $parts = explode(':', $ID);
728796bafb3SAndreas Gohr  $count = count($parts);
7291734437eSandi
730796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
7311734437eSandi
7321734437eSandi  // always print the startpage
733796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
734796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
735e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
736796bafb3SAndreas Gohr
737796bafb3SAndreas Gohr  // print intermediate namespace links
738796bafb3SAndreas Gohr  $part = '';
739796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
740796bafb3SAndreas Gohr    $part .= $parts[$i].':';
741796bafb3SAndreas Gohr    $page = $part;
742796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
743796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
744796bafb3SAndreas Gohr
745796bafb3SAndreas Gohr    // output
746796bafb3SAndreas Gohr    echo $sep;
747796bafb3SAndreas Gohr    if($exists){
748796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
749796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
750e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
75131e187f8SSean Coates    }else{
752796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
75331e187f8SSean Coates    }
75431e187f8SSean Coates  }
7551734437eSandi
756796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
757d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
758796bafb3SAndreas Gohr  $page = $part.$parts[$i];
759796bafb3SAndreas Gohr  if($page == $conf['start']) return;
760796bafb3SAndreas Gohr  echo $sep;
761d8186216SBen Coburn  if(@file_exists(wikiFN($page))){
762796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
763796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
764e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
76531e187f8SSean Coates  }else{
766796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
7671734437eSandi  }
76854e95700STom N Harris  return true;
7691734437eSandi}
7701734437eSandi
7711734437eSandi/**
7726b13307fSandi * Print info if the user is logged in
773a2488c3cSMatthias Grimm * and show full name in that case
7746b13307fSandi *
7756b13307fSandi * Could be enhanced with a profile link in future?
7766b13307fSandi *
7776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7786b13307fSandi */
7796b13307fSandifunction tpl_userinfo(){
7806b13307fSandi  global $lang;
781a2488c3cSMatthias Grimm  global $INFO;
78254e95700STom N Harris  if($_SERVER['REMOTE_USER']){
783a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
78454e95700STom N Harris    return true;
78554e95700STom N Harris  }
78654e95700STom N Harris  return false;
7876b13307fSandi}
7886b13307fSandi
7896b13307fSandi/**
7906b13307fSandi * Print some info about the current page
7916b13307fSandi *
7926b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7936b13307fSandi */
7946b13307fSandifunction tpl_pageinfo(){
7956b13307fSandi  global $conf;
7966b13307fSandi  global $lang;
7976b13307fSandi  global $INFO;
7986b13307fSandi  global $REV;
799c6e92a3cSDavid Lorentsen  global $ID;
800c6e92a3cSDavid Lorentsen
801c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
802c6e92a3cSDavid Lorentsen  if (!auth_quickaclcheck($ID)) { return; }
8036b13307fSandi
8046b13307fSandi  // prepare date and path
8056b13307fSandi  $fn = $INFO['filepath'];
8066b13307fSandi  if(!$conf['fullpath']){
8076b13307fSandi    if($REV){
8086b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
8096b13307fSandi    }else{
8106b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
8116b13307fSandi    }
8126b13307fSandi  }
813bee6dc82Sandi  $fn = utf8_decodeFN($fn);
8146b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
8156b13307fSandi
816faecdfdfSAndreas Gohr  // print it
817faecdfdfSAndreas Gohr  if($INFO['exists']){
8186b13307fSandi    print $fn;
8196b13307fSandi    print ' &middot; ';
8206b13307fSandi    print $lang['lastmod'];
8216b13307fSandi    print ': ';
8226b13307fSandi    print $date;
8236b13307fSandi    if($INFO['editor']){
8246b13307fSandi      print ' '.$lang['by'].' ';
8256b13307fSandi      print $INFO['editor'];
8265aa52fafSBen Coburn    }else{
8275aa52fafSBen Coburn      print ' ('.$lang['external_edit'].')';
8286b13307fSandi    }
8296b13307fSandi    if($INFO['locked']){
8306b13307fSandi      print ' &middot; ';
8316b13307fSandi      print $lang['lockedby'];
8326b13307fSandi      print ': ';
8336b13307fSandi      print $INFO['locked'];
8346b13307fSandi    }
83554e95700STom N Harris    return true;
8366b13307fSandi  }
83754e95700STom N Harris  return false;
8386b13307fSandi}
8396b13307fSandi
840820fa24bSandi/**
841a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
84287c434ceSAndreas Gohr *
84387c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
844a6598f23SBen Coburn * the given ID is used.
84587c434ceSAndreas Gohr *
84687c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
84787c434ceSAndreas Gohr */
848a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
84987c434ceSAndreas Gohr  global $conf;
85087c434ceSAndreas Gohr  if(is_null($id)){
85187c434ceSAndreas Gohr    global $ID;
85287c434ceSAndreas Gohr    $id = $ID;
85387c434ceSAndreas Gohr  }
85487c434ceSAndreas Gohr
85587c434ceSAndreas Gohr  $name = $id;
85687c434ceSAndreas Gohr  if ($conf['useheading']) {
85787c434ceSAndreas Gohr    $title = p_get_first_heading($id);
85887c434ceSAndreas Gohr    if ($title) $name = $title;
85987c434ceSAndreas Gohr  }
860a6598f23SBen Coburn
861a6598f23SBen Coburn  if ($ret) {
862a6598f23SBen Coburn      return hsc($name);
863a6598f23SBen Coburn  } else {
86487c434ceSAndreas Gohr      print hsc($name);
86554e95700STom N Harris      return true;
86687c434ceSAndreas Gohr  }
867a6598f23SBen Coburn}
868340756e4Sandi
86955efc227SAndreas Gohr/**
87055efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
87155efc227SAndreas Gohr *
87255efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
87355efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
87455efc227SAndreas Gohr *
87555efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
87655efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
87755efc227SAndreas Gohr * to the names of the latter one)
87855efc227SAndreas Gohr *
8793df72098SAndreas Gohr * Only allowed in: detail.php
88055efc227SAndreas Gohr *
88155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
88255efc227SAndreas Gohr */
8833df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
88455efc227SAndreas Gohr  // Init Exif Reader
88555efc227SAndreas Gohr  global $SRC;
8863df72098SAndreas Gohr
8873df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
8883df72098SAndreas Gohr
88955efc227SAndreas Gohr  static $meta = null;
8903df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
89155efc227SAndreas Gohr  if($meta === false) return $alt;
89255efc227SAndreas Gohr  $info = $meta->getField($tags);
89355efc227SAndreas Gohr  if($info == false) return $alt;
89455efc227SAndreas Gohr  return $info;
89555efc227SAndreas Gohr}
89655efc227SAndreas Gohr
89755efc227SAndreas Gohr/**
89855efc227SAndreas Gohr * Prints the image with a link to the full sized version
89955efc227SAndreas Gohr *
90055efc227SAndreas Gohr * Only allowed in: detail.php
90155efc227SAndreas Gohr */
902f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
90355efc227SAndreas Gohr  global $IMG;
90455efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
90555efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
90655efc227SAndreas Gohr
90755efc227SAndreas Gohr  //resize to given max values
90823a34783SAndreas Gohr  $ratio = 1;
90923a34783SAndreas Gohr  if($w >= $h){
910f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
91155efc227SAndreas Gohr      $ratio = $maxwidth/$w;
912f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
91355efc227SAndreas Gohr      $ratio = $maxheight/$h;
91455efc227SAndreas Gohr    }
91555efc227SAndreas Gohr  }else{
916f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
91755efc227SAndreas Gohr      $ratio = $maxheight/$h;
918f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
91955efc227SAndreas Gohr      $ratio = $maxwidth/$w;
92055efc227SAndreas Gohr    }
92155efc227SAndreas Gohr  }
92255efc227SAndreas Gohr  if($ratio){
92355efc227SAndreas Gohr    $w = floor($ratio*$w);
92455efc227SAndreas Gohr    $h = floor($ratio*$h);
92555efc227SAndreas Gohr  }
92655efc227SAndreas Gohr
9276de3759aSAndreas Gohr  //prepare URLs
9286de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
9296de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
93055efc227SAndreas Gohr
9312684e50aSAndreas Gohr  //prepare attributes
93255efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
9332684e50aSAndreas Gohr  $p = array();
9342684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9352684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9362684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9372684e50aSAndreas Gohr  if($alt){
9382684e50aSAndreas Gohr    $p['alt']   = $alt;
9392684e50aSAndreas Gohr    $p['title'] = $alt;
9402684e50aSAndreas Gohr  }else{
9412684e50aSAndreas Gohr    $p['alt'] = '';
9422684e50aSAndreas Gohr  }
9432684e50aSAndreas Gohr  $p = buildAttributes($p);
94455efc227SAndreas Gohr
94555efc227SAndreas Gohr  print '<a href="'.$url.'">';
9466de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
94755efc227SAndreas Gohr  print '</a>';
94854e95700STom N Harris  return true;
94955efc227SAndreas Gohr}
95055efc227SAndreas Gohr
9517367b368SAndreas Gohr/**
9527367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9537367b368SAndreas Gohr * is the inexer function.
9547367b368SAndreas Gohr *
9557367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9567367b368SAndreas Gohr * template
9577367b368SAndreas Gohr */
9587367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9597367b368SAndreas Gohr  global $ID;
9601dad36f5SAndreas Gohr  global $INFO;
96154e95700STom N Harris  if(!$INFO['exists']) return false;
9621dad36f5SAndreas Gohr
96354e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
9640dc92c6fSAndreas Gohr
9657367b368SAndreas Gohr  $p = array();
966b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
967e68c51baSAndreas Gohr                 '&'.time();
9687367b368SAndreas Gohr  $p['width']  = 1;
9697367b368SAndreas Gohr  $p['height'] = 1;
9707367b368SAndreas Gohr  $p['alt']    = '';
9717367b368SAndreas Gohr  $att = buildAttributes($p);
9727367b368SAndreas Gohr  print "<img $att />";
97354e95700STom N Harris  return true;
9747367b368SAndreas Gohr}
9757367b368SAndreas Gohr
97678d4e784SEsther Brunner// configuration methods
97778d4e784SEsther Brunner/**
97878d4e784SEsther Brunner * tpl_getConf($id)
97978d4e784SEsther Brunner *
98078d4e784SEsther Brunner * use this function to access template configuration variables
98178d4e784SEsther Brunner */
98278d4e784SEsther Brunnerfunction tpl_getConf($id){
98378d4e784SEsther Brunner  global $conf;
98478d4e784SEsther Brunner  global $tpl_configloaded;
98578d4e784SEsther Brunner
98678d4e784SEsther Brunner  $tpl = $conf['template'];
98778d4e784SEsther Brunner
98878d4e784SEsther Brunner  if (!$tpl_configloaded){
98978d4e784SEsther Brunner    $tconf = tpl_loadConfig();
99078d4e784SEsther Brunner    if ($tconf !== false){
99178d4e784SEsther Brunner      foreach ($tconf as $key => $value){
99278d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
99378d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
99478d4e784SEsther Brunner      }
99578d4e784SEsther Brunner      $tpl_configloaded = true;
99678d4e784SEsther Brunner    }
99778d4e784SEsther Brunner  }
99878d4e784SEsther Brunner
99978d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
100078d4e784SEsther Brunner}
100178d4e784SEsther Brunner
100278d4e784SEsther Brunner/**
100378d4e784SEsther Brunner * tpl_loadConfig()
100478d4e784SEsther Brunner * reads all template configuration variables
100578d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
100678d4e784SEsther Brunner */
100778d4e784SEsther Brunnerfunction tpl_loadConfig(){
100878d4e784SEsther Brunner
100978d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
101078d4e784SEsther Brunner  $conf = array();
101178d4e784SEsther Brunner
101278d4e784SEsther Brunner  if (!@file_exists($file)) return false;
101378d4e784SEsther Brunner
101478d4e784SEsther Brunner  // load default config file
101578d4e784SEsther Brunner  include($file);
101678d4e784SEsther Brunner
101778d4e784SEsther Brunner  return $conf;
101878d4e784SEsther Brunner}
101978d4e784SEsther Brunner
10203df72098SAndreas Gohr/**
10213df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
10223df72098SAndreas Gohr *
10233df72098SAndreas Gohr * Depending on the user's actions this may be a list of
10243df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
10253df72098SAndreas Gohr * a message of referencing pages
10263df72098SAndreas Gohr *
10273df72098SAndreas Gohr * Only allowed in mediamanager.php
10283df72098SAndreas Gohr *
10293df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10303df72098SAndreas Gohr */
10313df72098SAndreas Gohrfunction tpl_mediaContent(){
10323df72098SAndreas Gohr  global $IMG;
10333df72098SAndreas Gohr  global $AUTH;
10343df72098SAndreas Gohr  global $INUSE;
10353df72098SAndreas Gohr  global $NS;
10363df72098SAndreas Gohr  global $JUMPTO;
10373df72098SAndreas Gohr
10383df72098SAndreas Gohr  ptln('<div id="media__content">');
10393df72098SAndreas Gohr  if($_REQUEST['edit']){
10403df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
10417b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
10423df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
10433df72098SAndreas Gohr  }else{
10443df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
10453df72098SAndreas Gohr  }
10463df72098SAndreas Gohr  ptln('</div>');
10473df72098SAndreas Gohr}
10483df72098SAndreas Gohr
10493df72098SAndreas Gohr/**
10503df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
10513df72098SAndreas Gohr *
10523df72098SAndreas Gohr * Only allowed in mediamanager.php
10533df72098SAndreas Gohr *
10543df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10553df72098SAndreas Gohr */
10563df72098SAndreas Gohrfunction tpl_mediaTree(){
10573df72098SAndreas Gohr  global $NS;
10583df72098SAndreas Gohr
10593df72098SAndreas Gohr  ptln('<div id="media__tree">');
10603df72098SAndreas Gohr  media_nstree($NS);
10613df72098SAndreas Gohr  ptln('</div>');
10623df72098SAndreas Gohr}
10633df72098SAndreas Gohr
1064340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1065