xref: /dokuwiki/inc/template.php (revision c6e92a3c4d55587151ee7d7aa52e889d2ed769b9)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki template functions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
96b13307fSandi  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10e7cb32dcSAndreas Gohr  require_once(DOKU_CONF.'dokuwiki.php');
116b13307fSandi
126b13307fSandi/**
135a892029SAndreas Gohr * Returns the path to the given template, uses
14524be65dSBen Coburn * default one if the custom version doesn't exist.
15524be65dSBen Coburn * Also enables gzip compression if configured.
165a892029SAndreas Gohr *
175a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
185a892029SAndreas Gohr */
195a892029SAndreas Gohrfunction template($tpl){
205a892029SAndreas Gohr  global $conf;
215a892029SAndreas Gohr
225a892029SAndreas Gohr  if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
235a892029SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
245a892029SAndreas Gohr
255a892029SAndreas Gohr  return DOKU_INC.'lib/tpl/default/'.$tpl;
265a892029SAndreas Gohr}
275a892029SAndreas Gohr
285a892029SAndreas Gohr/**
296b13307fSandi * Print the content
306b13307fSandi *
316b13307fSandi * This function is used for printing all the usual content
326b13307fSandi * (defined by the global $ACT var) by calling the appropriate
336b13307fSandi * outputfunction(s) from html.php
346b13307fSandi *
35ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
36ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
376b13307fSandi *
386b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
396b13307fSandi */
406b13307fSandifunction tpl_content() {
417ea0913cSchris  global $ACT;
427ea0913cSchris
437ea0913cSchris  ob_start();
447ea0913cSchris
45746855cfSBen Coburn  trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
467ea0913cSchris
477ea0913cSchris  $html_output = ob_get_clean();
487ea0913cSchris
49746855cfSBen Coburn  trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
5054e95700STom N Harris
5154e95700STom N Harris  return !empty($html_output);
527ea0913cSchris}
537ea0913cSchris
547ea0913cSchrisfunction tpl_content_core(){
556b13307fSandi  global $ACT;
566b13307fSandi  global $TEXT;
576b13307fSandi  global $PRE;
586b13307fSandi  global $SUF;
596b13307fSandi  global $SUM;
606b13307fSandi  global $IDX;
616b13307fSandi
626b13307fSandi  switch($ACT){
636b13307fSandi    case 'show':
646b13307fSandi      html_show();
656b13307fSandi      break;
66ea67f144Sandi    case 'preview':
676b13307fSandi      html_edit($TEXT);
686b13307fSandi      html_show($TEXT);
696b13307fSandi      break;
70ee4c4a1bSAndreas Gohr    case 'recover':
71ee4c4a1bSAndreas Gohr      html_edit($TEXT);
72ee4c4a1bSAndreas Gohr      break;
736b13307fSandi    case 'edit':
746b13307fSandi      html_edit();
756b13307fSandi      break;
76ee4c4a1bSAndreas Gohr    case 'draft':
77ee4c4a1bSAndreas Gohr      html_draft();
78ee4c4a1bSAndreas Gohr      break;
796b13307fSandi    case 'wordblock':
806b13307fSandi      html_edit($TEXT,'wordblock');
816b13307fSandi      break;
826b13307fSandi    case 'search':
836b13307fSandi      html_search();
846b13307fSandi      break;
856b13307fSandi    case 'revisions':
8671726d78SBen Coburn      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
8771726d78SBen Coburn      html_revisions($first);
886b13307fSandi      break;
896b13307fSandi    case 'diff':
906b13307fSandi      html_diff();
916b13307fSandi      break;
926b13307fSandi    case 'recent':
935749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
94a39955b0Smatthiasgrimm      html_recent($first);
956b13307fSandi      break;
966b13307fSandi    case 'index':
976b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
986b13307fSandi      break;
996b13307fSandi    case 'backlink':
1006b13307fSandi      html_backlinks();
1016b13307fSandi      break;
1026b13307fSandi    case 'conflict':
1036b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1046b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
1056b13307fSandi      break;
1066b13307fSandi    case 'locked':
107ee20e7d1Sandi      html_locked();
1086b13307fSandi      break;
1096b13307fSandi    case 'login':
1106b13307fSandi      html_login();
1116b13307fSandi      break;
1126b13307fSandi    case 'register':
1136b13307fSandi      html_register();
1146b13307fSandi      break;
1158b06d178Schris    case 'resendpwd':
1168b06d178Schris      html_resendpwd();
1178b06d178Schris      break;
118820fa24bSandi    case 'denied':
1195e991bd8Sandi      print p_locale_xhtml('denied');
120820fa24bSandi      break;
1218b06d178Schris    case 'profile' :
1228b06d178Schris      html_updateprofile();
1238b06d178Schris      break;
124c19fe9c0Sandi    case 'admin':
125c19fe9c0Sandi      tpl_admin();
126c19fe9c0Sandi      break;
1276b13307fSandi    default:
12824bb549bSchris      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12924bb549bSchris      if ($evt->advise_before())
130ea67f144Sandi        msg("Failed to handle command: ".hsc($ACT),-1);
13124bb549bSchris      $evt->advise_after();
13224bb549bSchris      unset($evt);
13354e95700STom N Harris      return false;
1346b13307fSandi  }
13554e95700STom N Harris  return true;
1366b13307fSandi}
1376b13307fSandi
138c19fe9c0Sandi/**
139c19fe9c0Sandi * Handle the admin page contents
140c19fe9c0Sandi *
141c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
142c19fe9c0Sandi */
143c19fe9c0Sandifunction tpl_admin(){
144f8cc712eSAndreas Gohr    global $INFO;
14511e2ce22Schris
14611e2ce22Schris    $plugin = NULL;
147bb4866bdSchris    if (!empty($_REQUEST['page'])) {
14811e2ce22Schris        $pluginlist = plugin_list('admin');
14911e2ce22Schris
15011e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
15111e2ce22Schris
15211e2ce22Schris          // attempt to load the plugin
15311e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
15411e2ce22Schris        }
15511e2ce22Schris    }
15611e2ce22Schris
157f8cc712eSAndreas Gohr    if ($plugin !== NULL){
158f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
159f8cc712eSAndreas Gohr            msg('For admins only',-1);
16011e2ce22Schris            html_admin();
161f8cc712eSAndreas Gohr        }else{
162f8cc712eSAndreas Gohr            $plugin->html();
163f8cc712eSAndreas Gohr        }
164f8cc712eSAndreas Gohr    }else{
165f8cc712eSAndreas Gohr        html_admin();
166f8cc712eSAndreas Gohr    }
16754e95700STom N Harris    return true;
168c19fe9c0Sandi}
1696b13307fSandi
1706b13307fSandi/**
1716b13307fSandi * Print the correct HTML meta headers
1726b13307fSandi *
1736b13307fSandi * This has to go into the head section of your template.
1746b13307fSandi *
175016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
176f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
1776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1786b13307fSandi */
179f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
1806b13307fSandi  global $ID;
181d98d4540SBen Coburn  global $REV;
1826b13307fSandi  global $INFO;
1836b13307fSandi  global $ACT;
1846b13307fSandi  global $lang;
185dc57ef04Sandi  global $conf;
1866b13307fSandi  $it=2;
1876b13307fSandi
1887bff22c0SAndreas Gohr  // prepare the head array
1897bff22c0SAndreas Gohr  $head = array();
1907bff22c0SAndreas Gohr
1917bff22c0SAndreas Gohr
1926b13307fSandi  // the usual stuff
1937bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
194da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
195da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
196f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
1977bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
198bb4866bdSchris                           'title'=>$lang['btn_index'] );
199f96fa415SAndreas Gohr
200f96fa415SAndreas Gohr  if($alt){
2017bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2027bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2037bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2047bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2057bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
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
2487aaa4c46Smartin.tschofen  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
2497aaa4c46Smartin.tschofen                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all');
2507bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
2517bff22c0SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php');
2527bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
253615960feSTom N Harris                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
254bad31ae9SAndreas Gohr
25578a6aeb1SAndreas Gohr  // load javascript
256041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
257bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
2583df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
2593df72098SAndreas Gohr    $js_edit  = 1;
2603df72098SAndreas Gohr    $js_write = 0;
2613df72098SAndreas Gohr  }
2623df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
2637bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
264c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
265aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
2667bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
267c591aabeSAndreas Gohr    }
2687bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
2697bff22c0SAndreas Gohr                               '_data'=> $script);
270c591aabeSAndreas Gohr  }
2717bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
2727bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
2737bff22c0SAndreas Gohr
2747bff22c0SAndreas Gohr  // trigger event here
275016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
27654e95700STom N Harris  return true;
2777bff22c0SAndreas Gohr}
2787bff22c0SAndreas Gohr
2797bff22c0SAndreas Gohr/**
2807bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
2817bff22c0SAndreas Gohr *
2827bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
2837bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
2847bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
2857bff22c0SAndreas Gohr *
2867bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
2871304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
2887bff22c0SAndreas Gohr *
2897bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
2907bff22c0SAndreas Gohr */
2917bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
2927bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
2937bff22c0SAndreas Gohr    foreach($inst as $attr){
2947bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
2957bff22c0SAndreas Gohr      if(isset($attr['_data'])){
296e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
297e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
298e226efe1SAndreas Gohr                             $attr['_data'].
299e226efe1SAndreas Gohr                             "\n//--><!]]>";
300e226efe1SAndreas Gohr
3011304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3027bff22c0SAndreas Gohr      }else{
3037bff22c0SAndreas Gohr        echo '/>';
3047bff22c0SAndreas Gohr      }
3057bff22c0SAndreas Gohr      echo "\n";
3067bff22c0SAndreas Gohr    }
3077bff22c0SAndreas Gohr  }
3086b13307fSandi}
3096b13307fSandi
3106b13307fSandi/**
3116b13307fSandi * Print a link
3126b13307fSandi *
3135e163278SAndreas Gohr * Just builds a link.
3146b13307fSandi *
3156b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3166b13307fSandi */
3176b13307fSandifunction tpl_link($url,$name,$more=''){
3185e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3196b13307fSandi  if ($more) print ' '.$more;
3206b13307fSandi  print ">$name</a>";
32154e95700STom N Harris  return true;
3226b13307fSandi}
3236b13307fSandi
3246b13307fSandi/**
32555efc227SAndreas Gohr * Prints a link to a WikiPage
32655efc227SAndreas Gohr *
32755efc227SAndreas Gohr * Wrapper around html_wikilink
32855efc227SAndreas Gohr *
32955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
33055efc227SAndreas Gohr */
33155efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
33255efc227SAndreas Gohr  print html_wikilink($id,$name);
33354e95700STom N Harris  return true;
33455efc227SAndreas Gohr}
33555efc227SAndreas Gohr
33655efc227SAndreas Gohr/**
337a3ec5f4aSmatthiasgrimm * get the parent page
338a3ec5f4aSmatthiasgrimm *
339a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
340a3ec5f4aSmatthiasgrimm * returns false if none is available
341a3ec5f4aSmatthiasgrimm *
342377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
343a3ec5f4aSmatthiasgrimm */
344377f9e97SAndreas Gohrfunction tpl_getparent($id){
345a3ec5f4aSmatthiasgrimm  global $conf;
346377f9e97SAndreas Gohr  $parent = getNS($id).':';
347377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
348a197105eSmatthiasgrimm  if($parent == $id) {
349a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
350a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
351a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
352377f9e97SAndreas Gohr    if($parent == $id) return false;
353a197105eSmatthiasgrimm  }
354377f9e97SAndreas Gohr  return $parent;
355a3ec5f4aSmatthiasgrimm}
356a3ec5f4aSmatthiasgrimm
357a3ec5f4aSmatthiasgrimm/**
3586b13307fSandi * Print one of the buttons
3596b13307fSandi *
3606b13307fSandi * Available Buttons are
3616b13307fSandi *
362ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
3636b13307fSandi *  history     - old revisions
3646b13307fSandi *  recent      - recent changes
3656b13307fSandi *  login       - login/logout button - if ACL enabled
366d449b912SDenis Simakov *  profile     - user profile button (if logged in)
3676b13307fSandi *  index       - The index
368c19fe9c0Sandi *  admin       - admin page - if enough rights
3696b13307fSandi *  top         - a back to top button
370a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
371d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
372d67ca2c0Smatthiasgrimm *                after references have been displayed
373bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
374d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
3756b13307fSandi *
3766b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
377a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
3786b13307fSandi */
3796b13307fSandifunction tpl_button($type){
380b158d625SSteven Danz  global $ACT;
3816b13307fSandi  global $ID;
382d98d4540SBen Coburn  global $REV;
383d67ca2c0Smatthiasgrimm  global $NS;
384c19fe9c0Sandi  global $INFO;
3856b13307fSandi  global $conf;
386cd52f92dSchris  global $auth;
3876b13307fSandi
38875e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
38975e487e9SAndreas Gohr  $ctype = $type;
39075e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
39154e95700STom N Harris  if(!actionOK($ctype)) return false;
392409d7af7SAndreas Gohr
3936b13307fSandi  switch($type){
3946b13307fSandi    case 'edit':
395409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
396409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
397409d7af7SAndreas Gohr        if($INFO['writable']){
398bb4866bdSchris          if(!empty($INFO['draft'])){
399409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
400409d7af7SAndreas Gohr          }else{
401409d7af7SAndreas Gohr            if($INFO['exists']){
402409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
403409d7af7SAndreas Gohr            }else{
404409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
405409d7af7SAndreas Gohr            }
406409d7af7SAndreas Gohr          }
407409d7af7SAndreas Gohr        }else{
408409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
409409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
410409d7af7SAndreas Gohr        }
411409d7af7SAndreas Gohr      }else{
412409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
413409d7af7SAndreas Gohr      }
41454e95700STom N Harris      return true;
4156b13307fSandi    case 'history':
4165bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
41754e95700STom N Harris      return true;
4186b13307fSandi    case 'recent':
4195bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
42054e95700STom N Harris      return true;
4216b13307fSandi    case 'index':
4225bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
42354e95700STom N Harris      return true;
424a3ec5f4aSmatthiasgrimm    case 'back':
4256222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4266222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
42754e95700STom N Harris        return true;
428a3ec5f4aSmatthiasgrimm      }
42954e95700STom N Harris      return false;
4306b13307fSandi    case 'top':
4316b13307fSandi      print html_topbtn();
43254e95700STom N Harris      return true;
4336b13307fSandi    case 'login':
4346b13307fSandi      if($conf['useacl']){
4356b13307fSandi        if($_SERVER['REMOTE_USER']){
4366b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
4376b13307fSandi        }else{
4386b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
4396b13307fSandi        }
44054e95700STom N Harris        return true;
4416b13307fSandi      }
44254e95700STom N Harris      return false;
443c19fe9c0Sandi    case 'admin':
44454e95700STom N Harris      if($INFO['ismanager']){
4455bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
44654e95700STom N Harris        return true;
44754e95700STom N Harris      }
44854e95700STom N Harris      return false;
449d67ca2c0Smatthiasgrimm    case 'backtomedia':
450d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
45154e95700STom N Harris      return false;
4521380fc45SAndreas Gohr    case 'subscription':
453f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
454b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
4551380fc45SAndreas Gohr          if($INFO['subscribed']){
4561380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
457b158d625SSteven Danz          } else {
4581380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
459b158d625SSteven Danz          }
46054e95700STom N Harris          return true;
461b158d625SSteven Danz        }
462b158d625SSteven Danz      }
46354e95700STom N Harris      return false;
464f00151b4Schris    case 'backlink':
465f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
46654e95700STom N Harris      return true;
4678b06d178Schris    case 'profile':
46836223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
46936223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
4708b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
47154e95700STom N Harris        return true;
4728b06d178Schris      }
47354e95700STom N Harris      return false;
474c19fe9c0Sandi    default:
475c19fe9c0Sandi      print '[unknown button type]';
47654e95700STom N Harris      return true;
4776b13307fSandi  }
4786b13307fSandi}
4796b13307fSandi
4806b13307fSandi/**
481ed630903Sandi * Like the action buttons but links
482ed630903Sandi *
483ed630903Sandi * Available links are
484ed630903Sandi *
485d449b912SDenis Simakov *  edit    - edit/create/show link
486ed630903Sandi *  history - old revisions
487ed630903Sandi *  recent  - recent changes
488d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
489d449b912SDenis Simakov *  profile - user profile link (if logged in)
490ed630903Sandi *  index   - The index
491ed630903Sandi *  admin   - admin page - if enough rights
492d449b912SDenis Simakov *  top     - a back to top link
493d449b912SDenis Simakov *  back    - a back to parent link - if available
494bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
495d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
496ed630903Sandi *
497ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
498a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
499ed630903Sandi * @see    tpl_button
500ed630903Sandi */
501ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
502ed630903Sandi  global $ID;
503ed630903Sandi  global $INFO;
504ed630903Sandi  global $REV;
505ed630903Sandi  global $ACT;
506ed630903Sandi  global $conf;
507ed630903Sandi  global $lang;
508cd52f92dSchris  global $auth;
509ed630903Sandi
51075e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
51175e487e9SAndreas Gohr  $ctype = $type;
51275e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
51354e95700STom N Harris  if(!actionOK($ctype)) return false;
514409d7af7SAndreas Gohr
515ed630903Sandi  switch($type){
516ed630903Sandi    case 'edit':
517ed630903Sandi      #most complicated type - we need to decide on current action
518ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
519ed630903Sandi        if($INFO['writable']){
520b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
521b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
522b8a111f5SMichael Klier                       $pre.$lang['btn_draft'].$suf,
523b8a111f5SMichael Klier                       'class="action edit" acceskey="e" rel="nofollow"');
524b8a111f5SMichael Klier          } else {
525ed630903Sandi            if($INFO['exists']){
526ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
527ed630903Sandi                       $pre.$lang['btn_edit'].$suf,
528b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
529ed630903Sandi            }else{
530ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
531ed630903Sandi                       $pre.$lang['btn_create'].$suf,
532b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
533ed630903Sandi            }
534b8a111f5SMichael Klier          }
535ed630903Sandi        }else{
536409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
537ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
538ed630903Sandi                   $pre.$lang['btn_source'].$suf,
539b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
540ed630903Sandi        }
541ed630903Sandi      }else{
542ed630903Sandi          tpl_link(wl($ID,'do=show'),
543ed630903Sandi                   $pre.$lang['btn_show'].$suf,
544b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
545ed630903Sandi      }
546c059e1a6SAndreas Gohr      return true;
547ed630903Sandi    case 'history':
548b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
549c059e1a6SAndreas Gohr      return true;
550ed630903Sandi    case 'recent':
551b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
552c059e1a6SAndreas Gohr      return true;
553ed630903Sandi    case 'index':
554b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
555c059e1a6SAndreas Gohr      return true;
556ed630903Sandi    case 'top':
55721a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
558c059e1a6SAndreas Gohr      return true;
559a3ec5f4aSmatthiasgrimm    case 'back':
560f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
561f7569b7bSAndreas Gohr        tpl_link(wl($parent,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
562c059e1a6SAndreas Gohr        return true;
563a3ec5f4aSmatthiasgrimm      }
564c059e1a6SAndreas Gohr      return false;
565ed630903Sandi    case 'login':
566ed630903Sandi      if($conf['useacl']){
567ed630903Sandi        if($_SERVER['REMOTE_USER']){
568b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
569ed630903Sandi        }else{
570b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
571ed630903Sandi        }
572c059e1a6SAndreas Gohr        return true;
573ed630903Sandi      }
574c059e1a6SAndreas Gohr      return false;
575ed630903Sandi    case 'admin':
576f8cc712eSAndreas Gohr      if($INFO['ismanager']){
577b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
578c059e1a6SAndreas Gohr        return true;
579c059e1a6SAndreas Gohr      }
580c059e1a6SAndreas Gohr      return false;
581f9eb5648Ssteven-danz   case 'subscribe':
582075f000fSChristopher Arndt   case 'subscription':
583f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
584b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
585075f000fSChristopher Arndt          if($INFO['subscribed']) {
586b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
587b158d625SSteven Danz          } else {
588b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
589b158d625SSteven Danz          }
590c059e1a6SAndreas Gohr          return true;
591b158d625SSteven Danz        }
592b158d625SSteven Danz      }
593c059e1a6SAndreas Gohr      return false;
594f00151b4Schris    case 'backlink':
595b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
596c059e1a6SAndreas Gohr      return true;
5978b06d178Schris    case 'profile':
59836223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
59936223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
6008b06d178Schris        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
601c059e1a6SAndreas Gohr        return true;
6028b06d178Schris      }
603c059e1a6SAndreas Gohr      return false;
604ed630903Sandi    default:
605ed630903Sandi      print '[unknown link type]';
606c059e1a6SAndreas Gohr      return true;
607ed630903Sandi  }
608ed630903Sandi}
609ed630903Sandi
610ed630903Sandi/**
6116b13307fSandi * Print the search form
6126b13307fSandi *
61372645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
61472645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
61572645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
61672645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
61772645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
61872645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
61972645b75SAndreas Gohr *
6206b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6216b13307fSandi */
62272645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6236b13307fSandi  global $lang;
624c1e3b7d9Smatthiasgrimm  global $ACT;
625c1e3b7d9Smatthiasgrimm
626670ff54eSchris  // don't print the search form if search action has been disabled
62754e95700STom N Harris  if (!actionOk('search')) return false;
628670ff54eSchris
6291dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6306b13307fSandi  print '<input type="hidden" name="do" value="search" />';
631c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
632bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
63372645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
634818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
63511ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
63624a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6374beabca9SAnika Henke  print '</div></form>';
63854e95700STom N Harris  return true;
6396b13307fSandi}
6406b13307fSandi
6416b13307fSandi/**
6426b13307fSandi * Print the breadcrumbs trace
6436b13307fSandi *
6446b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6456b13307fSandi */
64654e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
6476b13307fSandi  global $lang;
6486b13307fSandi  global $conf;
6496b13307fSandi
6506b13307fSandi  //check if enabled
65154e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
6526b13307fSandi
6536b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
654265e3787Sandi
655265e3787Sandi  //reverse crumborder in right-to-left mode
656265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
657265e3787Sandi
65840eb54bbSjan  //render crumbs, highlight the last one
6596b13307fSandi  print $lang['breadcrumb'].':';
66040eb54bbSjan  $last = count($crumbs);
66140eb54bbSjan  $i = 0;
662a77f5846Sjan  foreach ($crumbs as $id => $name){
66340eb54bbSjan    $i++;
66454e95700STom N Harris    print ' <span class="bcsep">'.$sep.'</span> ';
66592795d04Sandi    if ($i == $last) print '<span class="curid">';
666e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
66792795d04Sandi    if ($i == $last) print '</span>';
6686b13307fSandi  }
66954e95700STom N Harris  return true;
6706b13307fSandi}
6716b13307fSandi
6726b13307fSandi/**
6731734437eSandi * Hierarchical breadcrumbs
6741734437eSandi *
67531e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
6761734437eSandi * It only makes sense with a deep site structure.
6771734437eSandi *
6781734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
6796bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
68031e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
6811734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
6826bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
6831734437eSandi */
684796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
6851734437eSandi  global $conf;
6861734437eSandi  global $ID;
6871734437eSandi  global $lang;
6881734437eSandi
68931e187f8SSean Coates  // check if enabled
69054e95700STom N Harris  if(!$conf['youarehere']) return false;
6911734437eSandi
6921734437eSandi  $parts = explode(':', $ID);
693796bafb3SAndreas Gohr  $count = count($parts);
6941734437eSandi
695796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
6961734437eSandi
6971734437eSandi  // always print the startpage
698796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
699796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
700e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
701796bafb3SAndreas Gohr
702796bafb3SAndreas Gohr  // print intermediate namespace links
703796bafb3SAndreas Gohr  $part = '';
704796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
705796bafb3SAndreas Gohr    $part .= $parts[$i].':';
706796bafb3SAndreas Gohr    $page = $part;
707796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
708796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
709796bafb3SAndreas Gohr
710796bafb3SAndreas Gohr    // output
711796bafb3SAndreas Gohr    echo $sep;
712796bafb3SAndreas Gohr    if($exists){
713796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
714796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
715e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
71631e187f8SSean Coates    }else{
717796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
71831e187f8SSean Coates    }
71931e187f8SSean Coates  }
7201734437eSandi
721796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
722d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
723796bafb3SAndreas Gohr  $page = $part.$parts[$i];
724796bafb3SAndreas Gohr  if($page == $conf['start']) return;
725796bafb3SAndreas Gohr  echo $sep;
726d8186216SBen Coburn  if(@file_exists(wikiFN($page))){
727796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
728796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
729e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
73031e187f8SSean Coates  }else{
731796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
7321734437eSandi  }
73354e95700STom N Harris  return true;
7341734437eSandi}
7351734437eSandi
7361734437eSandi/**
7376b13307fSandi * Print info if the user is logged in
738a2488c3cSMatthias Grimm * and show full name in that case
7396b13307fSandi *
7406b13307fSandi * Could be enhanced with a profile link in future?
7416b13307fSandi *
7426b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7436b13307fSandi */
7446b13307fSandifunction tpl_userinfo(){
7456b13307fSandi  global $lang;
746a2488c3cSMatthias Grimm  global $INFO;
74754e95700STom N Harris  if($_SERVER['REMOTE_USER']){
748a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
74954e95700STom N Harris    return true;
75054e95700STom N Harris  }
75154e95700STom N Harris  return false;
7526b13307fSandi}
7536b13307fSandi
7546b13307fSandi/**
7556b13307fSandi * Print some info about the current page
7566b13307fSandi *
7576b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7586b13307fSandi */
7596b13307fSandifunction tpl_pageinfo(){
7606b13307fSandi  global $conf;
7616b13307fSandi  global $lang;
7626b13307fSandi  global $INFO;
7636b13307fSandi  global $REV;
764*c6e92a3cSDavid Lorentsen  global $ID;
765*c6e92a3cSDavid Lorentsen
766*c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
767*c6e92a3cSDavid Lorentsen  if (!auth_quickaclcheck($ID)) { return; }
7686b13307fSandi
7696b13307fSandi  // prepare date and path
7706b13307fSandi  $fn = $INFO['filepath'];
7716b13307fSandi  if(!$conf['fullpath']){
7726b13307fSandi    if($REV){
7736b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
7746b13307fSandi    }else{
7756b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
7766b13307fSandi    }
7776b13307fSandi  }
778bee6dc82Sandi  $fn = utf8_decodeFN($fn);
7796b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
7806b13307fSandi
7816b13307fSandi  // print it
7826b13307fSandi  if($INFO['exists']){
7836b13307fSandi    print $fn;
7846b13307fSandi    print ' &middot; ';
7856b13307fSandi    print $lang['lastmod'];
7866b13307fSandi    print ': ';
7876b13307fSandi    print $date;
7886b13307fSandi    if($INFO['editor']){
7896b13307fSandi      print ' '.$lang['by'].' ';
7906b13307fSandi      print $INFO['editor'];
7915aa52fafSBen Coburn    }else{
7925aa52fafSBen Coburn      print ' ('.$lang['external_edit'].')';
7936b13307fSandi    }
7946b13307fSandi    if($INFO['locked']){
7956b13307fSandi      print ' &middot; ';
7966b13307fSandi      print $lang['lockedby'];
7976b13307fSandi      print ': ';
7986b13307fSandi      print $INFO['locked'];
7996b13307fSandi    }
80054e95700STom N Harris    return true;
8016b13307fSandi  }
80254e95700STom N Harris  return false;
8036b13307fSandi}
8046b13307fSandi
805820fa24bSandi/**
806a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
80787c434ceSAndreas Gohr *
80887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
809a6598f23SBen Coburn * the given ID is used.
81087c434ceSAndreas Gohr *
81187c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
81287c434ceSAndreas Gohr */
813a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
81487c434ceSAndreas Gohr  global $conf;
81587c434ceSAndreas Gohr  if(is_null($id)){
81687c434ceSAndreas Gohr    global $ID;
81787c434ceSAndreas Gohr    $id = $ID;
81887c434ceSAndreas Gohr  }
81987c434ceSAndreas Gohr
82087c434ceSAndreas Gohr  $name = $id;
82187c434ceSAndreas Gohr  if ($conf['useheading']) {
82287c434ceSAndreas Gohr    $title = p_get_first_heading($id);
82387c434ceSAndreas Gohr    if ($title) $name = $title;
82487c434ceSAndreas Gohr  }
825a6598f23SBen Coburn
826a6598f23SBen Coburn  if ($ret) {
827a6598f23SBen Coburn      return hsc($name);
828a6598f23SBen Coburn  } else {
82987c434ceSAndreas Gohr      print hsc($name);
83054e95700STom N Harris      return true;
83187c434ceSAndreas Gohr  }
832a6598f23SBen Coburn}
833340756e4Sandi
83455efc227SAndreas Gohr/**
83555efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
83655efc227SAndreas Gohr *
83755efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
83855efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
83955efc227SAndreas Gohr *
84055efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
84155efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
84255efc227SAndreas Gohr * to the names of the latter one)
84355efc227SAndreas Gohr *
8443df72098SAndreas Gohr * Only allowed in: detail.php
84555efc227SAndreas Gohr *
84655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
84755efc227SAndreas Gohr */
8483df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
84955efc227SAndreas Gohr  // Init Exif Reader
85055efc227SAndreas Gohr  global $SRC;
8513df72098SAndreas Gohr
8523df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
8533df72098SAndreas Gohr
85455efc227SAndreas Gohr  static $meta = null;
8553df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
85655efc227SAndreas Gohr  if($meta === false) return $alt;
85755efc227SAndreas Gohr  $info = $meta->getField($tags);
85855efc227SAndreas Gohr  if($info == false) return $alt;
85955efc227SAndreas Gohr  return $info;
86055efc227SAndreas Gohr}
86155efc227SAndreas Gohr
86255efc227SAndreas Gohr/**
86355efc227SAndreas Gohr * Prints the image with a link to the full sized version
86455efc227SAndreas Gohr *
86555efc227SAndreas Gohr * Only allowed in: detail.php
86655efc227SAndreas Gohr */
867f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
86855efc227SAndreas Gohr  global $IMG;
86955efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
87055efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
87155efc227SAndreas Gohr
87255efc227SAndreas Gohr  //resize to given max values
87323a34783SAndreas Gohr  $ratio = 1;
87423a34783SAndreas Gohr  if($w >= $h){
875f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
87655efc227SAndreas Gohr      $ratio = $maxwidth/$w;
877f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
87855efc227SAndreas Gohr      $ratio = $maxheight/$h;
87955efc227SAndreas Gohr    }
88055efc227SAndreas Gohr  }else{
881f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
88255efc227SAndreas Gohr      $ratio = $maxheight/$h;
883f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
88455efc227SAndreas Gohr      $ratio = $maxwidth/$w;
88555efc227SAndreas Gohr    }
88655efc227SAndreas Gohr  }
88755efc227SAndreas Gohr  if($ratio){
88855efc227SAndreas Gohr    $w = floor($ratio*$w);
88955efc227SAndreas Gohr    $h = floor($ratio*$h);
89055efc227SAndreas Gohr  }
89155efc227SAndreas Gohr
8926de3759aSAndreas Gohr  //prepare URLs
8936de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
8946de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
89555efc227SAndreas Gohr
8962684e50aSAndreas Gohr  //prepare attributes
89755efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
8982684e50aSAndreas Gohr  $p = array();
8992684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9002684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9012684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9022684e50aSAndreas Gohr  if($alt){
9032684e50aSAndreas Gohr    $p['alt']   = $alt;
9042684e50aSAndreas Gohr    $p['title'] = $alt;
9052684e50aSAndreas Gohr  }else{
9062684e50aSAndreas Gohr    $p['alt'] = '';
9072684e50aSAndreas Gohr  }
9082684e50aSAndreas Gohr  $p = buildAttributes($p);
90955efc227SAndreas Gohr
91055efc227SAndreas Gohr  print '<a href="'.$url.'">';
9116de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
91255efc227SAndreas Gohr  print '</a>';
91354e95700STom N Harris  return true;
91455efc227SAndreas Gohr}
91555efc227SAndreas Gohr
9167367b368SAndreas Gohr/**
9177367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9187367b368SAndreas Gohr * is the inexer function.
9197367b368SAndreas Gohr *
9207367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9217367b368SAndreas Gohr * template
9227367b368SAndreas Gohr */
9237367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9247367b368SAndreas Gohr  global $ID;
9251dad36f5SAndreas Gohr  global $INFO;
92654e95700STom N Harris  if(!$INFO['exists']) return false;
9271dad36f5SAndreas Gohr
92854e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
9290dc92c6fSAndreas Gohr
9307367b368SAndreas Gohr  $p = array();
931b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
932e68c51baSAndreas Gohr                 '&'.time();
9337367b368SAndreas Gohr  $p['width']  = 1;
9347367b368SAndreas Gohr  $p['height'] = 1;
9357367b368SAndreas Gohr  $p['alt']    = '';
9367367b368SAndreas Gohr  $att = buildAttributes($p);
9377367b368SAndreas Gohr  print "<img $att />";
93854e95700STom N Harris  return true;
9397367b368SAndreas Gohr}
9407367b368SAndreas Gohr
94178d4e784SEsther Brunner// configuration methods
94278d4e784SEsther Brunner/**
94378d4e784SEsther Brunner * tpl_getConf($id)
94478d4e784SEsther Brunner *
94578d4e784SEsther Brunner * use this function to access template configuration variables
94678d4e784SEsther Brunner */
94778d4e784SEsther Brunnerfunction tpl_getConf($id){
94878d4e784SEsther Brunner  global $conf;
94978d4e784SEsther Brunner  global $tpl_configloaded;
95078d4e784SEsther Brunner
95178d4e784SEsther Brunner  $tpl = $conf['template'];
95278d4e784SEsther Brunner
95378d4e784SEsther Brunner  if (!$tpl_configloaded){
95478d4e784SEsther Brunner    $tconf = tpl_loadConfig();
95578d4e784SEsther Brunner    if ($tconf !== false){
95678d4e784SEsther Brunner      foreach ($tconf as $key => $value){
95778d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
95878d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
95978d4e784SEsther Brunner      }
96078d4e784SEsther Brunner      $tpl_configloaded = true;
96178d4e784SEsther Brunner    }
96278d4e784SEsther Brunner  }
96378d4e784SEsther Brunner
96478d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
96578d4e784SEsther Brunner}
96678d4e784SEsther Brunner
96778d4e784SEsther Brunner/**
96878d4e784SEsther Brunner * tpl_loadConfig()
96978d4e784SEsther Brunner * reads all template configuration variables
97078d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
97178d4e784SEsther Brunner */
97278d4e784SEsther Brunnerfunction tpl_loadConfig(){
97378d4e784SEsther Brunner
97478d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
97578d4e784SEsther Brunner  $conf = array();
97678d4e784SEsther Brunner
97778d4e784SEsther Brunner  if (!@file_exists($file)) return false;
97878d4e784SEsther Brunner
97978d4e784SEsther Brunner  // load default config file
98078d4e784SEsther Brunner  include($file);
98178d4e784SEsther Brunner
98278d4e784SEsther Brunner  return $conf;
98378d4e784SEsther Brunner}
98478d4e784SEsther Brunner
9853df72098SAndreas Gohr/**
9863df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
9873df72098SAndreas Gohr *
9883df72098SAndreas Gohr * Depending on the user's actions this may be a list of
9893df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
9903df72098SAndreas Gohr * a message of referencing pages
9913df72098SAndreas Gohr *
9923df72098SAndreas Gohr * Only allowed in mediamanager.php
9933df72098SAndreas Gohr *
9943df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
9953df72098SAndreas Gohr */
9963df72098SAndreas Gohrfunction tpl_mediaContent(){
9973df72098SAndreas Gohr  global $IMG;
9983df72098SAndreas Gohr  global $AUTH;
9993df72098SAndreas Gohr  global $INUSE;
10003df72098SAndreas Gohr  global $NS;
10013df72098SAndreas Gohr  global $JUMPTO;
10023df72098SAndreas Gohr
10033df72098SAndreas Gohr  ptln('<div id="media__content">');
10043df72098SAndreas Gohr  if($_REQUEST['edit']){
10053df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
10067b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
10073df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
10083df72098SAndreas Gohr  }else{
10093df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
10103df72098SAndreas Gohr  }
10113df72098SAndreas Gohr  ptln('</div>');
10123df72098SAndreas Gohr}
10133df72098SAndreas Gohr
10143df72098SAndreas Gohr/**
10153df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
10163df72098SAndreas Gohr *
10173df72098SAndreas Gohr * Only allowed in mediamanager.php
10183df72098SAndreas Gohr *
10193df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10203df72098SAndreas Gohr */
10213df72098SAndreas Gohrfunction tpl_mediaTree(){
10223df72098SAndreas Gohr  global $NS;
10233df72098SAndreas Gohr
10243df72098SAndreas Gohr  ptln('<div id="media__tree">');
10253df72098SAndreas Gohr  media_nstree($NS);
10263df72098SAndreas Gohr  ptln('</div>');
10273df72098SAndreas Gohr}
10283df72098SAndreas Gohr
1029340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
1030