xref: /dokuwiki/inc/template.php (revision 54e95700e0c482e0db73d64cc5a10bc56841fc2c)
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');
50*54e95700STom N Harris
51*54e95700STom 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);
133*54e95700STom N Harris      return false;
1346b13307fSandi  }
135*54e95700STom 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    }
167*54e95700STom N Harris    return true;
168c19fe9c0Sandi}
1696b13307fSandi
1706b13307fSandi/**
1716b13307fSandi * Print the correct HTML meta headers
1726b13307fSandi *
1736b13307fSandi * This has to go into the head section of your template.
1746b13307fSandi *
175016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
176f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
1776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1786b13307fSandi */
179f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
1806b13307fSandi  global $ID;
181d98d4540SBen Coburn  global $REV;
1826b13307fSandi  global $INFO;
1836b13307fSandi  global $ACT;
1846b13307fSandi  global $lang;
185dc57ef04Sandi  global $conf;
1866b13307fSandi  $it=2;
1876b13307fSandi
1887bff22c0SAndreas Gohr  // prepare the head array
1897bff22c0SAndreas Gohr  $head = array();
1907bff22c0SAndreas Gohr
1917bff22c0SAndreas Gohr
1926b13307fSandi  // the usual stuff
1937bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
194da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
195da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
196f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
1977bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
198bb4866bdSchris                           'title'=>$lang['btn_index'] );
199f96fa415SAndreas Gohr
200f96fa415SAndreas Gohr  if($alt){
2017bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2027bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2037bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2047bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2057bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
2067bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2077bff22c0SAndreas Gohr                             'href'=>exportlink($ID, 'xhtml', '', false, '&'));
2087bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2097bff22c0SAndreas Gohr                             'href'=>exportlink($ID, 'raw', '', false, '&'));
210f96fa415SAndreas Gohr  }
2116b13307fSandi
2126b13307fSandi  // setup robot tags apropriate for different modes
2134f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2146b13307fSandi    if($INFO['exists']){
2156b13307fSandi      //delay indexing:
2166b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2177bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2186b13307fSandi      }else{
2197bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2206b13307fSandi      }
2216b13307fSandi    }else{
2227bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
2236b13307fSandi    }
2247a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2257bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2266b13307fSandi  }else{
2277bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2286b13307fSandi  }
2296b13307fSandi
230831800b8SAndreas Gohr  // set metadata
231831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
232831800b8SAndreas Gohr    // date of modification
233831800b8SAndreas Gohr    if($REV){
2347bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
235831800b8SAndreas Gohr    }else{
2367bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
237831800b8SAndreas Gohr    }
238831800b8SAndreas Gohr
239831800b8SAndreas Gohr    // keywords (explicit or implicit)
240bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
2417bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
242831800b8SAndreas Gohr    }else{
2437bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
244831800b8SAndreas Gohr    }
245831800b8SAndreas Gohr  }
246831800b8SAndreas Gohr
24778a6aeb1SAndreas Gohr  // load stylesheets
2487bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
2497bff22c0SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php');
2507bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
251615960feSTom N Harris                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
252bad31ae9SAndreas Gohr
25378a6aeb1SAndreas Gohr  // load javascript
254041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
255bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
2563df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
2573df72098SAndreas Gohr    $js_edit  = 1;
2583df72098SAndreas Gohr    $js_write = 0;
2593df72098SAndreas Gohr  }
2603df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
2617bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
262c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
263aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
2647bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
265c591aabeSAndreas Gohr    }
2667bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
2677bff22c0SAndreas Gohr                               '_data'=> $script);
268c591aabeSAndreas Gohr  }
2697bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
2707bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
2717bff22c0SAndreas Gohr
2727bff22c0SAndreas Gohr  // trigger event here
273016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
274*54e95700STom N Harris  return true;
2757bff22c0SAndreas Gohr}
2767bff22c0SAndreas Gohr
2777bff22c0SAndreas Gohr/**
2787bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
2797bff22c0SAndreas Gohr *
2807bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
2817bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
2827bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
2837bff22c0SAndreas Gohr *
2847bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
2851304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
2867bff22c0SAndreas Gohr *
2877bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
2887bff22c0SAndreas Gohr */
2897bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
2907bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
2917bff22c0SAndreas Gohr    foreach($inst as $attr){
2927bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
2937bff22c0SAndreas Gohr      if(isset($attr['_data'])){
294e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
295e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
296e226efe1SAndreas Gohr                             $attr['_data'].
297e226efe1SAndreas Gohr                             "\n//--><!]]>";
298e226efe1SAndreas Gohr
2991304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3007bff22c0SAndreas Gohr      }else{
3017bff22c0SAndreas Gohr        echo '/>';
3027bff22c0SAndreas Gohr      }
3037bff22c0SAndreas Gohr      echo "\n";
3047bff22c0SAndreas Gohr    }
3057bff22c0SAndreas Gohr  }
3066b13307fSandi}
3076b13307fSandi
3086b13307fSandi/**
3096b13307fSandi * Print a link
3106b13307fSandi *
3115e163278SAndreas Gohr * Just builds a link.
3126b13307fSandi *
3136b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3146b13307fSandi */
3156b13307fSandifunction tpl_link($url,$name,$more=''){
3165e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3176b13307fSandi  if ($more) print ' '.$more;
3186b13307fSandi  print ">$name</a>";
319*54e95700STom N Harris  return true;
3206b13307fSandi}
3216b13307fSandi
3226b13307fSandi/**
32355efc227SAndreas Gohr * Prints a link to a WikiPage
32455efc227SAndreas Gohr *
32555efc227SAndreas Gohr * Wrapper around html_wikilink
32655efc227SAndreas Gohr *
32755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
32855efc227SAndreas Gohr */
32955efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
33055efc227SAndreas Gohr  print html_wikilink($id,$name);
331*54e95700STom N Harris  return true;
33255efc227SAndreas Gohr}
33355efc227SAndreas Gohr
33455efc227SAndreas Gohr/**
335a3ec5f4aSmatthiasgrimm * get the parent page
336a3ec5f4aSmatthiasgrimm *
337a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
338a3ec5f4aSmatthiasgrimm * returns false if none is available
339a3ec5f4aSmatthiasgrimm *
340377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
341a3ec5f4aSmatthiasgrimm */
342377f9e97SAndreas Gohrfunction tpl_getparent($id){
343a3ec5f4aSmatthiasgrimm  global $conf;
344377f9e97SAndreas Gohr  $parent = getNS($id).':';
345377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
346a197105eSmatthiasgrimm  if($parent == $id) {
347a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
348a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
349a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
350377f9e97SAndreas Gohr    if($parent == $id) return false;
351a197105eSmatthiasgrimm  }
352377f9e97SAndreas Gohr  return $parent;
353a3ec5f4aSmatthiasgrimm}
354a3ec5f4aSmatthiasgrimm
355a3ec5f4aSmatthiasgrimm/**
3566b13307fSandi * Print one of the buttons
3576b13307fSandi *
3586b13307fSandi * Available Buttons are
3596b13307fSandi *
360ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
3616b13307fSandi *  history     - old revisions
3626b13307fSandi *  recent      - recent changes
3636b13307fSandi *  login       - login/logout button - if ACL enabled
364d449b912SDenis Simakov *  profile     - user profile button (if logged in)
3656b13307fSandi *  index       - The index
366c19fe9c0Sandi *  admin       - admin page - if enough rights
3676b13307fSandi *  top         - a back to top button
368a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
369d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
370d67ca2c0Smatthiasgrimm *                after references have been displayed
371bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
372d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
3736b13307fSandi *
3746b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
375a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
3766b13307fSandi */
3776b13307fSandifunction tpl_button($type){
378b158d625SSteven Danz  global $ACT;
3796b13307fSandi  global $ID;
380d98d4540SBen Coburn  global $REV;
381d67ca2c0Smatthiasgrimm  global $NS;
382c19fe9c0Sandi  global $INFO;
3836b13307fSandi  global $conf;
384cd52f92dSchris  global $auth;
3856b13307fSandi
38675e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
38775e487e9SAndreas Gohr  $ctype = $type;
38875e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
389*54e95700STom N Harris  if(!actionOK($ctype)) return false;
390409d7af7SAndreas Gohr
3916b13307fSandi  switch($type){
3926b13307fSandi    case 'edit':
393409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
394409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
395409d7af7SAndreas Gohr        if($INFO['writable']){
396bb4866bdSchris          if(!empty($INFO['draft'])){
397409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
398409d7af7SAndreas Gohr          }else{
399409d7af7SAndreas Gohr            if($INFO['exists']){
400409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
401409d7af7SAndreas Gohr            }else{
402409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
403409d7af7SAndreas Gohr            }
404409d7af7SAndreas Gohr          }
405409d7af7SAndreas Gohr        }else{
406409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
407409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
408409d7af7SAndreas Gohr        }
409409d7af7SAndreas Gohr      }else{
410409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
411409d7af7SAndreas Gohr      }
412*54e95700STom N Harris      return true;
4136b13307fSandi    case 'history':
4145bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
415*54e95700STom N Harris      return true;
4166b13307fSandi    case 'recent':
4175bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
418*54e95700STom N Harris      return true;
4196b13307fSandi    case 'index':
4205bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
421*54e95700STom N Harris      return true;
422a3ec5f4aSmatthiasgrimm    case 'back':
4236222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4246222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
425*54e95700STom N Harris        return true;
426a3ec5f4aSmatthiasgrimm      }
427*54e95700STom N Harris      return false;
4286b13307fSandi    case 'top':
4296b13307fSandi      print html_topbtn();
430*54e95700STom N Harris      return true;
4316b13307fSandi    case 'login':
4326b13307fSandi      if($conf['useacl']){
4336b13307fSandi        if($_SERVER['REMOTE_USER']){
4346b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
4356b13307fSandi        }else{
4366b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
4376b13307fSandi        }
438*54e95700STom N Harris        return true;
4396b13307fSandi      }
440*54e95700STom N Harris      return false;
441c19fe9c0Sandi    case 'admin':
442*54e95700STom N Harris      if($INFO['ismanager']){
4435bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
444*54e95700STom N Harris        return true;
445*54e95700STom N Harris      }
446*54e95700STom N Harris      return false;
447d67ca2c0Smatthiasgrimm    case 'backtomedia':
448d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
449*54e95700STom N Harris      return false;
4501380fc45SAndreas Gohr    case 'subscription':
451f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
452b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
4531380fc45SAndreas Gohr          if($INFO['subscribed']){
4541380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
455b158d625SSteven Danz          } else {
4561380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
457b158d625SSteven Danz          }
458*54e95700STom N Harris          return true;
459b158d625SSteven Danz        }
460b158d625SSteven Danz      }
461*54e95700STom N Harris      return false;
462f00151b4Schris    case 'backlink':
463f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
464*54e95700STom N Harris      return true;
4658b06d178Schris    case 'profile':
46636223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
46736223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
4688b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
469*54e95700STom N Harris        return true;
4708b06d178Schris      }
471*54e95700STom N Harris      return false;
472c19fe9c0Sandi    default:
473c19fe9c0Sandi      print '[unknown button type]';
474*54e95700STom N Harris      return true;
4756b13307fSandi  }
4766b13307fSandi}
4776b13307fSandi
4786b13307fSandi/**
479ed630903Sandi * Like the action buttons but links
480ed630903Sandi *
481ed630903Sandi * Available links are
482ed630903Sandi *
483d449b912SDenis Simakov *  edit    - edit/create/show link
484ed630903Sandi *  history - old revisions
485ed630903Sandi *  recent  - recent changes
486d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
487d449b912SDenis Simakov *  profile - user profile link (if logged in)
488ed630903Sandi *  index   - The index
489ed630903Sandi *  admin   - admin page - if enough rights
490d449b912SDenis Simakov *  top     - a back to top link
491d449b912SDenis Simakov *  back    - a back to parent link - if available
492bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
493d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
494ed630903Sandi *
495ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
496a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
497ed630903Sandi * @see    tpl_button
498ed630903Sandi */
499ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
500ed630903Sandi  global $ID;
501ed630903Sandi  global $INFO;
502ed630903Sandi  global $REV;
503ed630903Sandi  global $ACT;
504ed630903Sandi  global $conf;
505ed630903Sandi  global $lang;
506cd52f92dSchris  global $auth;
507ed630903Sandi
50875e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
50975e487e9SAndreas Gohr  $ctype = $type;
51075e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
511*54e95700STom N Harris  if(!actionOK($ctype)) return false;
512409d7af7SAndreas Gohr
513ed630903Sandi  switch($type){
514ed630903Sandi    case 'edit':
515ed630903Sandi      #most complicated type - we need to decide on current action
516ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
517ed630903Sandi        if($INFO['writable']){
518b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
519b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
520b8a111f5SMichael Klier                       $pre.$lang['btn_draft'].$suf,
521b8a111f5SMichael Klier                       'class="action edit" acceskey="e" rel="nofollow"');
522b8a111f5SMichael Klier          } else {
523ed630903Sandi            if($INFO['exists']){
524ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
525ed630903Sandi                       $pre.$lang['btn_edit'].$suf,
526b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
527ed630903Sandi            }else{
528ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
529ed630903Sandi                       $pre.$lang['btn_create'].$suf,
530b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
531ed630903Sandi            }
532b8a111f5SMichael Klier          }
533ed630903Sandi        }else{
534409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
535ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
536ed630903Sandi                   $pre.$lang['btn_source'].$suf,
537b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
538ed630903Sandi        }
539ed630903Sandi      }else{
540ed630903Sandi          tpl_link(wl($ID,'do=show'),
541ed630903Sandi                   $pre.$lang['btn_show'].$suf,
542b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
543ed630903Sandi      }
544c059e1a6SAndreas Gohr      return true;
545ed630903Sandi    case 'history':
546b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
547c059e1a6SAndreas Gohr      return true;
548ed630903Sandi    case 'recent':
549b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
550c059e1a6SAndreas Gohr      return true;
551ed630903Sandi    case 'index':
552b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
553c059e1a6SAndreas Gohr      return true;
554ed630903Sandi    case 'top':
55521a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
556c059e1a6SAndreas Gohr      return true;
557a3ec5f4aSmatthiasgrimm    case 'back':
558f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
559f7569b7bSAndreas Gohr        tpl_link(wl($parent,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
560c059e1a6SAndreas Gohr        return true;
561a3ec5f4aSmatthiasgrimm      }
562c059e1a6SAndreas Gohr      return false;
563ed630903Sandi    case 'login':
564ed630903Sandi      if($conf['useacl']){
565ed630903Sandi        if($_SERVER['REMOTE_USER']){
566b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
567ed630903Sandi        }else{
568b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
569ed630903Sandi        }
570c059e1a6SAndreas Gohr        return true;
571ed630903Sandi      }
572c059e1a6SAndreas Gohr      return false;
573ed630903Sandi    case 'admin':
574f8cc712eSAndreas Gohr      if($INFO['ismanager']){
575b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
576c059e1a6SAndreas Gohr        return true;
577c059e1a6SAndreas Gohr      }
578c059e1a6SAndreas Gohr      return false;
579f9eb5648Ssteven-danz   case 'subscribe':
580075f000fSChristopher Arndt   case 'subscription':
581f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
582b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
583075f000fSChristopher Arndt          if($INFO['subscribed']) {
584b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
585b158d625SSteven Danz          } else {
586b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
587b158d625SSteven Danz          }
588c059e1a6SAndreas Gohr          return true;
589b158d625SSteven Danz        }
590b158d625SSteven Danz      }
591c059e1a6SAndreas Gohr      return false;
592f00151b4Schris    case 'backlink':
593b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
594c059e1a6SAndreas Gohr      return true;
5958b06d178Schris    case 'profile':
59636223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
59736223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
5988b06d178Schris        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
599c059e1a6SAndreas Gohr        return true;
6008b06d178Schris      }
601c059e1a6SAndreas Gohr      return false;
602ed630903Sandi    default:
603ed630903Sandi      print '[unknown link type]';
604c059e1a6SAndreas Gohr      return true;
605ed630903Sandi  }
606ed630903Sandi}
607ed630903Sandi
608ed630903Sandi/**
6096b13307fSandi * Print the search form
6106b13307fSandi *
61172645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
61272645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
61372645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
61472645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
61572645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
61672645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
61772645b75SAndreas Gohr *
6186b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6196b13307fSandi */
62072645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6216b13307fSandi  global $lang;
622c1e3b7d9Smatthiasgrimm  global $ACT;
623c1e3b7d9Smatthiasgrimm
624670ff54eSchris  // don't print the search form if search action has been disabled
625*54e95700STom N Harris  if (!actionOk('search')) return false;
626670ff54eSchris
6271dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6286b13307fSandi  print '<input type="hidden" name="do" value="search" />';
629c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
630bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
63172645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
632818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
63311ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
63424a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6354beabca9SAnika Henke  print '</div></form>';
636*54e95700STom N Harris  return true;
6376b13307fSandi}
6386b13307fSandi
6396b13307fSandi/**
6406b13307fSandi * Print the breadcrumbs trace
6416b13307fSandi *
6426b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6436b13307fSandi */
644*54e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
6456b13307fSandi  global $lang;
6466b13307fSandi  global $conf;
6476b13307fSandi
6486b13307fSandi  //check if enabled
649*54e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
6506b13307fSandi
6516b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
652265e3787Sandi
653265e3787Sandi  //reverse crumborder in right-to-left mode
654265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
655265e3787Sandi
65640eb54bbSjan  //render crumbs, highlight the last one
6576b13307fSandi  print $lang['breadcrumb'].':';
65840eb54bbSjan  $last = count($crumbs);
65940eb54bbSjan  $i = 0;
660a77f5846Sjan  foreach ($crumbs as $id => $name){
66140eb54bbSjan    $i++;
662*54e95700STom N Harris    print ' <span class="bcsep">'.$sep.'</span> ';
66392795d04Sandi    if ($i == $last) print '<span class="curid">';
664e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
66592795d04Sandi    if ($i == $last) print '</span>';
6666b13307fSandi  }
667*54e95700STom N Harris  return true;
6686b13307fSandi}
6696b13307fSandi
6706b13307fSandi/**
6711734437eSandi * Hierarchical breadcrumbs
6721734437eSandi *
67331e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
6741734437eSandi * It only makes sense with a deep site structure.
6751734437eSandi *
6761734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
6776bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
67831e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
6791734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
6806bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
6811734437eSandi */
682796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
6831734437eSandi  global $conf;
6841734437eSandi  global $ID;
6851734437eSandi  global $lang;
6861734437eSandi
68731e187f8SSean Coates  // check if enabled
688*54e95700STom N Harris  if(!$conf['youarehere']) return false;
6891734437eSandi
6901734437eSandi  $parts = explode(':', $ID);
691796bafb3SAndreas Gohr  $count = count($parts);
6921734437eSandi
693796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
6941734437eSandi
6951734437eSandi  // always print the startpage
696796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
697796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
698e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
699796bafb3SAndreas Gohr
700796bafb3SAndreas Gohr  // print intermediate namespace links
701796bafb3SAndreas Gohr  $part = '';
702796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
703796bafb3SAndreas Gohr    $part .= $parts[$i].':';
704796bafb3SAndreas Gohr    $page = $part;
705796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
706796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
707796bafb3SAndreas Gohr
708796bafb3SAndreas Gohr    // output
709796bafb3SAndreas Gohr    echo $sep;
710796bafb3SAndreas Gohr    if($exists){
711796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
712796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
713e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
71431e187f8SSean Coates    }else{
715796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
71631e187f8SSean Coates    }
71731e187f8SSean Coates  }
7181734437eSandi
719796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
720d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
721796bafb3SAndreas Gohr  $page = $part.$parts[$i];
722796bafb3SAndreas Gohr  if($page == $conf['start']) return;
723796bafb3SAndreas Gohr  echo $sep;
724d8186216SBen Coburn  if(@file_exists(wikiFN($page))){
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"');
7301734437eSandi  }
731*54e95700STom N Harris  return true;
7321734437eSandi}
7331734437eSandi
7341734437eSandi/**
7356b13307fSandi * Print info if the user is logged in
736a2488c3cSMatthias Grimm * and show full name in that case
7376b13307fSandi *
7386b13307fSandi * Could be enhanced with a profile link in future?
7396b13307fSandi *
7406b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7416b13307fSandi */
7426b13307fSandifunction tpl_userinfo(){
7436b13307fSandi  global $lang;
744a2488c3cSMatthias Grimm  global $INFO;
745*54e95700STom N Harris  if($_SERVER['REMOTE_USER']){
746a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
747*54e95700STom N Harris    return true;
748*54e95700STom N Harris  }
749*54e95700STom N Harris  return false;
7506b13307fSandi}
7516b13307fSandi
7526b13307fSandi/**
7536b13307fSandi * Print some info about the current page
7546b13307fSandi *
7556b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7566b13307fSandi */
7576b13307fSandifunction tpl_pageinfo(){
7586b13307fSandi  global $conf;
7596b13307fSandi  global $lang;
7606b13307fSandi  global $INFO;
7616b13307fSandi  global $REV;
7626b13307fSandi
7636b13307fSandi  // prepare date and path
7646b13307fSandi  $fn = $INFO['filepath'];
7656b13307fSandi  if(!$conf['fullpath']){
7666b13307fSandi    if($REV){
7676b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
7686b13307fSandi    }else{
7696b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
7706b13307fSandi    }
7716b13307fSandi  }
772bee6dc82Sandi  $fn = utf8_decodeFN($fn);
7736b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
7746b13307fSandi
7756b13307fSandi  // print it
7766b13307fSandi  if($INFO['exists']){
7776b13307fSandi    print $fn;
7786b13307fSandi    print ' &middot; ';
7796b13307fSandi    print $lang['lastmod'];
7806b13307fSandi    print ': ';
7816b13307fSandi    print $date;
7826b13307fSandi    if($INFO['editor']){
7836b13307fSandi      print ' '.$lang['by'].' ';
7846b13307fSandi      print $INFO['editor'];
7855aa52fafSBen Coburn    }else{
7865aa52fafSBen Coburn      print ' ('.$lang['external_edit'].')';
7876b13307fSandi    }
7886b13307fSandi    if($INFO['locked']){
7896b13307fSandi      print ' &middot; ';
7906b13307fSandi      print $lang['lockedby'];
7916b13307fSandi      print ': ';
7926b13307fSandi      print $INFO['locked'];
7936b13307fSandi    }
794*54e95700STom N Harris    return true;
7956b13307fSandi  }
796*54e95700STom N Harris  return false;
7976b13307fSandi}
7986b13307fSandi
799820fa24bSandi/**
800a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
80187c434ceSAndreas Gohr *
80287c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
803a6598f23SBen Coburn * the given ID is used.
80487c434ceSAndreas Gohr *
80587c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
80687c434ceSAndreas Gohr */
807a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
80887c434ceSAndreas Gohr  global $conf;
80987c434ceSAndreas Gohr  if(is_null($id)){
81087c434ceSAndreas Gohr    global $ID;
81187c434ceSAndreas Gohr    $id = $ID;
81287c434ceSAndreas Gohr  }
81387c434ceSAndreas Gohr
81487c434ceSAndreas Gohr  $name = $id;
81587c434ceSAndreas Gohr  if ($conf['useheading']) {
81687c434ceSAndreas Gohr    $title = p_get_first_heading($id);
81787c434ceSAndreas Gohr    if ($title) $name = $title;
81887c434ceSAndreas Gohr  }
819a6598f23SBen Coburn
820a6598f23SBen Coburn  if ($ret) {
821a6598f23SBen Coburn      return hsc($name);
822a6598f23SBen Coburn  } else {
82387c434ceSAndreas Gohr      print hsc($name);
824*54e95700STom N Harris      return true;
82587c434ceSAndreas Gohr  }
826a6598f23SBen Coburn}
827340756e4Sandi
82855efc227SAndreas Gohr/**
82955efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
83055efc227SAndreas Gohr *
83155efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
83255efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
83355efc227SAndreas Gohr *
83455efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
83555efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
83655efc227SAndreas Gohr * to the names of the latter one)
83755efc227SAndreas Gohr *
8383df72098SAndreas Gohr * Only allowed in: detail.php
83955efc227SAndreas Gohr *
84055efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
84155efc227SAndreas Gohr */
8423df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
84355efc227SAndreas Gohr  // Init Exif Reader
84455efc227SAndreas Gohr  global $SRC;
8453df72098SAndreas Gohr
8463df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
8473df72098SAndreas Gohr
84855efc227SAndreas Gohr  static $meta = null;
8493df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
85055efc227SAndreas Gohr  if($meta === false) return $alt;
85155efc227SAndreas Gohr  $info = $meta->getField($tags);
85255efc227SAndreas Gohr  if($info == false) return $alt;
85355efc227SAndreas Gohr  return $info;
85455efc227SAndreas Gohr}
85555efc227SAndreas Gohr
85655efc227SAndreas Gohr/**
85755efc227SAndreas Gohr * Prints the image with a link to the full sized version
85855efc227SAndreas Gohr *
85955efc227SAndreas Gohr * Only allowed in: detail.php
86055efc227SAndreas Gohr */
861f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
86255efc227SAndreas Gohr  global $IMG;
86355efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
86455efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
86555efc227SAndreas Gohr
86655efc227SAndreas Gohr  //resize to given max values
86723a34783SAndreas Gohr  $ratio = 1;
86823a34783SAndreas Gohr  if($w >= $h){
869f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
87055efc227SAndreas Gohr      $ratio = $maxwidth/$w;
871f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
87255efc227SAndreas Gohr      $ratio = $maxheight/$h;
87355efc227SAndreas Gohr    }
87455efc227SAndreas Gohr  }else{
875f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
87655efc227SAndreas Gohr      $ratio = $maxheight/$h;
877f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
87855efc227SAndreas Gohr      $ratio = $maxwidth/$w;
87955efc227SAndreas Gohr    }
88055efc227SAndreas Gohr  }
88155efc227SAndreas Gohr  if($ratio){
88255efc227SAndreas Gohr    $w = floor($ratio*$w);
88355efc227SAndreas Gohr    $h = floor($ratio*$h);
88455efc227SAndreas Gohr  }
88555efc227SAndreas Gohr
8866de3759aSAndreas Gohr  //prepare URLs
8876de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
8886de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
88955efc227SAndreas Gohr
8902684e50aSAndreas Gohr  //prepare attributes
89155efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
8922684e50aSAndreas Gohr  $p = array();
8932684e50aSAndreas Gohr  if($w) $p['width']  = $w;
8942684e50aSAndreas Gohr  if($h) $p['height'] = $h;
8952684e50aSAndreas Gohr         $p['class']  = 'img_detail';
8962684e50aSAndreas Gohr  if($alt){
8972684e50aSAndreas Gohr    $p['alt']   = $alt;
8982684e50aSAndreas Gohr    $p['title'] = $alt;
8992684e50aSAndreas Gohr  }else{
9002684e50aSAndreas Gohr    $p['alt'] = '';
9012684e50aSAndreas Gohr  }
9022684e50aSAndreas Gohr  $p = buildAttributes($p);
90355efc227SAndreas Gohr
90455efc227SAndreas Gohr  print '<a href="'.$url.'">';
9056de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
90655efc227SAndreas Gohr  print '</a>';
907*54e95700STom N Harris  return true;
90855efc227SAndreas Gohr}
90955efc227SAndreas Gohr
9107367b368SAndreas Gohr/**
9117367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9127367b368SAndreas Gohr * is the inexer function.
9137367b368SAndreas Gohr *
9147367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9157367b368SAndreas Gohr * template
9167367b368SAndreas Gohr */
9177367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9187367b368SAndreas Gohr  global $ID;
9191dad36f5SAndreas Gohr  global $INFO;
920*54e95700STom N Harris  if(!$INFO['exists']) return false;
9211dad36f5SAndreas Gohr
922*54e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
9230dc92c6fSAndreas Gohr
9247367b368SAndreas Gohr  $p = array();
925b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
926e68c51baSAndreas Gohr                 '&'.time();
9277367b368SAndreas Gohr  $p['width']  = 1;
9287367b368SAndreas Gohr  $p['height'] = 1;
9297367b368SAndreas Gohr  $p['alt']    = '';
9307367b368SAndreas Gohr  $att = buildAttributes($p);
9317367b368SAndreas Gohr  print "<img $att />";
932*54e95700STom N Harris  return true;
9337367b368SAndreas Gohr}
9347367b368SAndreas Gohr
93578d4e784SEsther Brunner// configuration methods
93678d4e784SEsther Brunner/**
93778d4e784SEsther Brunner * tpl_getConf($id)
93878d4e784SEsther Brunner *
93978d4e784SEsther Brunner * use this function to access template configuration variables
94078d4e784SEsther Brunner */
94178d4e784SEsther Brunnerfunction tpl_getConf($id){
94278d4e784SEsther Brunner  global $conf;
94378d4e784SEsther Brunner  global $tpl_configloaded;
94478d4e784SEsther Brunner
94578d4e784SEsther Brunner  $tpl = $conf['template'];
94678d4e784SEsther Brunner
94778d4e784SEsther Brunner  if (!$tpl_configloaded){
94878d4e784SEsther Brunner    $tconf = tpl_loadConfig();
94978d4e784SEsther Brunner    if ($tconf !== false){
95078d4e784SEsther Brunner      foreach ($tconf as $key => $value){
95178d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
95278d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
95378d4e784SEsther Brunner      }
95478d4e784SEsther Brunner      $tpl_configloaded = true;
95578d4e784SEsther Brunner    }
95678d4e784SEsther Brunner  }
95778d4e784SEsther Brunner
95878d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
95978d4e784SEsther Brunner}
96078d4e784SEsther Brunner
96178d4e784SEsther Brunner/**
96278d4e784SEsther Brunner * tpl_loadConfig()
96378d4e784SEsther Brunner * reads all template configuration variables
96478d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
96578d4e784SEsther Brunner */
96678d4e784SEsther Brunnerfunction tpl_loadConfig(){
96778d4e784SEsther Brunner
96878d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
96978d4e784SEsther Brunner  $conf = array();
97078d4e784SEsther Brunner
97178d4e784SEsther Brunner  if (!@file_exists($file)) return false;
97278d4e784SEsther Brunner
97378d4e784SEsther Brunner  // load default config file
97478d4e784SEsther Brunner  include($file);
97578d4e784SEsther Brunner
97678d4e784SEsther Brunner  return $conf;
97778d4e784SEsther Brunner}
97878d4e784SEsther Brunner
9793df72098SAndreas Gohr/**
9803df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
9813df72098SAndreas Gohr *
9823df72098SAndreas Gohr * Depending on the user's actions this may be a list of
9833df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
9843df72098SAndreas Gohr * a message of referencing pages
9853df72098SAndreas Gohr *
9863df72098SAndreas Gohr * Only allowed in mediamanager.php
9873df72098SAndreas Gohr *
9883df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
9893df72098SAndreas Gohr */
9903df72098SAndreas Gohrfunction tpl_mediaContent(){
9913df72098SAndreas Gohr  global $IMG;
9923df72098SAndreas Gohr  global $AUTH;
9933df72098SAndreas Gohr  global $INUSE;
9943df72098SAndreas Gohr  global $NS;
9953df72098SAndreas Gohr  global $JUMPTO;
9963df72098SAndreas Gohr
9973df72098SAndreas Gohr  ptln('<div id="media__content">');
9983df72098SAndreas Gohr  if($_REQUEST['edit']){
9993df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
10007b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
10013df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
10023df72098SAndreas Gohr  }else{
10033df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
10043df72098SAndreas Gohr  }
10053df72098SAndreas Gohr  ptln('</div>');
10063df72098SAndreas Gohr}
10073df72098SAndreas Gohr
10083df72098SAndreas Gohr/**
10093df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
10103df72098SAndreas Gohr *
10113df72098SAndreas Gohr * Only allowed in mediamanager.php
10123df72098SAndreas Gohr *
10133df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10143df72098SAndreas Gohr */
10153df72098SAndreas Gohrfunction tpl_mediaTree(){
10163df72098SAndreas Gohr  global $NS;
10173df72098SAndreas Gohr
10183df72098SAndreas Gohr  ptln('<div id="media__tree">');
10193df72098SAndreas Gohr  media_nstree($NS);
10203df72098SAndreas Gohr  ptln('</div>');
10213df72098SAndreas Gohr}
10223df72098SAndreas Gohr
1023340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1024