xref: /dokuwiki/inc/template.php (revision f8cc712e2ad522d0bd56b9ba3983cd42abf664ad)
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');
507ea0913cSchris}
517ea0913cSchris
527ea0913cSchrisfunction tpl_content_core(){
536b13307fSandi  global $ACT;
546b13307fSandi  global $TEXT;
556b13307fSandi  global $PRE;
566b13307fSandi  global $SUF;
576b13307fSandi  global $SUM;
586b13307fSandi  global $IDX;
596b13307fSandi
606b13307fSandi  switch($ACT){
616b13307fSandi    case 'show':
626b13307fSandi      html_show();
636b13307fSandi      break;
64ea67f144Sandi    case 'preview':
656b13307fSandi      html_edit($TEXT);
666b13307fSandi      html_show($TEXT);
676b13307fSandi      break;
68ee4c4a1bSAndreas Gohr    case 'recover':
69ee4c4a1bSAndreas Gohr      html_edit($TEXT);
70ee4c4a1bSAndreas Gohr      break;
716b13307fSandi    case 'edit':
726b13307fSandi      html_edit();
736b13307fSandi      break;
74ee4c4a1bSAndreas Gohr    case 'draft':
75ee4c4a1bSAndreas Gohr      html_draft();
76ee4c4a1bSAndreas Gohr      break;
776b13307fSandi    case 'wordblock':
786b13307fSandi      html_edit($TEXT,'wordblock');
796b13307fSandi      break;
806b13307fSandi    case 'search':
816b13307fSandi      html_search();
826b13307fSandi      break;
836b13307fSandi    case 'revisions':
8471726d78SBen Coburn      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
8571726d78SBen Coburn      html_revisions($first);
866b13307fSandi      break;
876b13307fSandi    case 'diff':
886b13307fSandi      html_diff();
896b13307fSandi      break;
906b13307fSandi    case 'recent':
915749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
92a39955b0Smatthiasgrimm      html_recent($first);
936b13307fSandi      break;
946b13307fSandi    case 'index':
956b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
966b13307fSandi      break;
976b13307fSandi    case 'backlink':
986b13307fSandi      html_backlinks();
996b13307fSandi      break;
1006b13307fSandi    case 'conflict':
1016b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1026b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
1036b13307fSandi      break;
1046b13307fSandi    case 'locked':
105ee20e7d1Sandi      html_locked();
1066b13307fSandi      break;
1076b13307fSandi    case 'login':
1086b13307fSandi      html_login();
1096b13307fSandi      break;
1106b13307fSandi    case 'register':
1116b13307fSandi      html_register();
1126b13307fSandi      break;
1138b06d178Schris    case 'resendpwd':
1148b06d178Schris      html_resendpwd();
1158b06d178Schris      break;
116820fa24bSandi    case 'denied':
1175e991bd8Sandi      print p_locale_xhtml('denied');
118820fa24bSandi      break;
1198b06d178Schris    case 'profile' :
1208b06d178Schris      html_updateprofile();
1218b06d178Schris      break;
122c19fe9c0Sandi    case 'admin':
123c19fe9c0Sandi      tpl_admin();
124c19fe9c0Sandi      break;
1256b13307fSandi    default:
12624bb549bSchris      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12724bb549bSchris      if ($evt->advise_before())
128ea67f144Sandi        msg("Failed to handle command: ".hsc($ACT),-1);
12924bb549bSchris      $evt->advise_after();
13024bb549bSchris      unset($evt);
1316b13307fSandi  }
1326b13307fSandi}
1336b13307fSandi
134c19fe9c0Sandi/**
135c19fe9c0Sandi * Handle the admin page contents
136c19fe9c0Sandi *
137c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
138c19fe9c0Sandi */
139c19fe9c0Sandifunction tpl_admin(){
140*f8cc712eSAndreas Gohr    global $INFO;
14111e2ce22Schris
14211e2ce22Schris    $plugin = NULL;
143bb4866bdSchris    if (!empty($_REQUEST['page'])) {
14411e2ce22Schris        $pluginlist = plugin_list('admin');
14511e2ce22Schris
14611e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
14711e2ce22Schris
14811e2ce22Schris          // attempt to load the plugin
14911e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
15011e2ce22Schris        }
15111e2ce22Schris    }
15211e2ce22Schris
153*f8cc712eSAndreas Gohr    if ($plugin !== NULL){
154*f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
155*f8cc712eSAndreas Gohr            msg('For admins only',-1);
15611e2ce22Schris            html_admin();
157*f8cc712eSAndreas Gohr        }else{
158*f8cc712eSAndreas Gohr            $plugin->html();
159*f8cc712eSAndreas Gohr        }
160*f8cc712eSAndreas Gohr    }else{
161*f8cc712eSAndreas Gohr        html_admin();
162*f8cc712eSAndreas Gohr    }
163c19fe9c0Sandi}
1646b13307fSandi
1656b13307fSandi/**
1666b13307fSandi * Print the correct HTML meta headers
1676b13307fSandi *
1686b13307fSandi * This has to go into the head section of your template.
1696b13307fSandi *
170016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
171f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
1726b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1736b13307fSandi */
174f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
1756b13307fSandi  global $ID;
176d98d4540SBen Coburn  global $REV;
1776b13307fSandi  global $INFO;
1786b13307fSandi  global $ACT;
1796b13307fSandi  global $lang;
180dc57ef04Sandi  global $conf;
1816b13307fSandi  $it=2;
1826b13307fSandi
1837bff22c0SAndreas Gohr  // prepare the head array
1847bff22c0SAndreas Gohr  $head = array();
1857bff22c0SAndreas Gohr
1867bff22c0SAndreas Gohr
1876b13307fSandi  // the usual stuff
1887bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
189da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
190da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
191f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
1927bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
193bb4866bdSchris                           'title'=>$lang['btn_index'] );
194f96fa415SAndreas Gohr
195f96fa415SAndreas Gohr  if($alt){
1967bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
1977bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
1987bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
1997bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2007bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
2017bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2027bff22c0SAndreas Gohr                             'href'=>exportlink($ID, 'xhtml', '', false, '&'));
2037bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2047bff22c0SAndreas Gohr                             'href'=>exportlink($ID, 'raw', '', false, '&'));
205f96fa415SAndreas Gohr  }
2066b13307fSandi
2076b13307fSandi  // setup robot tags apropriate for different modes
2084f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2096b13307fSandi    if($INFO['exists']){
2106b13307fSandi      //delay indexing:
2116b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2127bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2136b13307fSandi      }else{
2147bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2156b13307fSandi      }
2166b13307fSandi    }else{
2177bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
2186b13307fSandi    }
2197a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2207bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2216b13307fSandi  }else{
2227bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2236b13307fSandi  }
2246b13307fSandi
225831800b8SAndreas Gohr  // set metadata
226831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
227831800b8SAndreas Gohr    // date of modification
228831800b8SAndreas Gohr    if($REV){
2297bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
230831800b8SAndreas Gohr    }else{
2317bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
232831800b8SAndreas Gohr    }
233831800b8SAndreas Gohr
234831800b8SAndreas Gohr    // keywords (explicit or implicit)
235bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
2367bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
237831800b8SAndreas Gohr    }else{
2387bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
239831800b8SAndreas Gohr    }
240831800b8SAndreas Gohr  }
241831800b8SAndreas Gohr
24278a6aeb1SAndreas Gohr  // load stylesheets
2437bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
2447bff22c0SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php');
2457bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
246615960feSTom N Harris                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
247bad31ae9SAndreas Gohr
24878a6aeb1SAndreas Gohr  // load javascript
249041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
250bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
2513df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
2523df72098SAndreas Gohr    $js_edit  = 1;
2533df72098SAndreas Gohr    $js_write = 0;
2543df72098SAndreas Gohr  }
2553df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
2567bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
257c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
258aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
2597bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
260c591aabeSAndreas Gohr    }
2617bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
2627bff22c0SAndreas Gohr                               '_data'=> $script);
263c591aabeSAndreas Gohr  }
2647bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
2657bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
2667bff22c0SAndreas Gohr
2677bff22c0SAndreas Gohr  // trigger event here
268016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
2697bff22c0SAndreas Gohr}
2707bff22c0SAndreas Gohr
2717bff22c0SAndreas Gohr/**
2727bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
2737bff22c0SAndreas Gohr *
2747bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
2757bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
2767bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
2777bff22c0SAndreas Gohr *
2787bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
2791304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
2807bff22c0SAndreas Gohr *
2817bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
2827bff22c0SAndreas Gohr */
2837bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
2847bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
2857bff22c0SAndreas Gohr    foreach($inst as $attr){
2867bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
2877bff22c0SAndreas Gohr      if(isset($attr['_data'])){
288e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
289e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
290e226efe1SAndreas Gohr                             $attr['_data'].
291e226efe1SAndreas Gohr                             "\n//--><!]]>";
292e226efe1SAndreas Gohr
2931304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
2947bff22c0SAndreas Gohr      }else{
2957bff22c0SAndreas Gohr        echo '/>';
2967bff22c0SAndreas Gohr      }
2977bff22c0SAndreas Gohr      echo "\n";
2987bff22c0SAndreas Gohr    }
2997bff22c0SAndreas Gohr  }
3006b13307fSandi}
3016b13307fSandi
3026b13307fSandi/**
3036b13307fSandi * Print a link
3046b13307fSandi *
3055e163278SAndreas Gohr * Just builds a link.
3066b13307fSandi *
3076b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3086b13307fSandi */
3096b13307fSandifunction tpl_link($url,$name,$more=''){
3105e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3116b13307fSandi  if ($more) print ' '.$more;
3126b13307fSandi  print ">$name</a>";
3136b13307fSandi}
3146b13307fSandi
3156b13307fSandi/**
31655efc227SAndreas Gohr * Prints a link to a WikiPage
31755efc227SAndreas Gohr *
31855efc227SAndreas Gohr * Wrapper around html_wikilink
31955efc227SAndreas Gohr *
32055efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
32155efc227SAndreas Gohr */
32255efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
32355efc227SAndreas Gohr  print html_wikilink($id,$name);
32455efc227SAndreas Gohr}
32555efc227SAndreas Gohr
32655efc227SAndreas Gohr/**
327a3ec5f4aSmatthiasgrimm * get the parent page
328a3ec5f4aSmatthiasgrimm *
329a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
330a3ec5f4aSmatthiasgrimm * returns false if none is available
331a3ec5f4aSmatthiasgrimm *
332377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
333a3ec5f4aSmatthiasgrimm */
334377f9e97SAndreas Gohrfunction tpl_getparent($id){
335a3ec5f4aSmatthiasgrimm  global $conf;
336377f9e97SAndreas Gohr  $parent = getNS($id).':';
337377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
338a197105eSmatthiasgrimm  if($parent == $id) {
339a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
340a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
341a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
342377f9e97SAndreas Gohr    if($parent == $id) return false;
343a197105eSmatthiasgrimm  }
344377f9e97SAndreas Gohr  return $parent;
345a3ec5f4aSmatthiasgrimm}
346a3ec5f4aSmatthiasgrimm
347a3ec5f4aSmatthiasgrimm/**
3486b13307fSandi * Print one of the buttons
3496b13307fSandi *
3506b13307fSandi * Available Buttons are
3516b13307fSandi *
352ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
3536b13307fSandi *  history     - old revisions
3546b13307fSandi *  recent      - recent changes
3556b13307fSandi *  login       - login/logout button - if ACL enabled
356d449b912SDenis Simakov *  profile     - user profile button (if logged in)
3576b13307fSandi *  index       - The index
358c19fe9c0Sandi *  admin       - admin page - if enough rights
3596b13307fSandi *  top         - a back to top button
360a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
361d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
362d67ca2c0Smatthiasgrimm *                after references have been displayed
363bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
364d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
3656b13307fSandi *
3666b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
367a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
3686b13307fSandi */
3696b13307fSandifunction tpl_button($type){
370b158d625SSteven Danz  global $ACT;
3716b13307fSandi  global $ID;
372d98d4540SBen Coburn  global $REV;
373d67ca2c0Smatthiasgrimm  global $NS;
374c19fe9c0Sandi  global $INFO;
3756b13307fSandi  global $conf;
376cd52f92dSchris  global $auth;
3776b13307fSandi
37875e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
37975e487e9SAndreas Gohr  $ctype = $type;
38075e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
38175e487e9SAndreas Gohr  if(!actionOK($ctype)) return;
382409d7af7SAndreas Gohr
3836b13307fSandi  switch($type){
3846b13307fSandi    case 'edit':
385409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
386409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
387409d7af7SAndreas Gohr        if($INFO['writable']){
388bb4866bdSchris          if(!empty($INFO['draft'])){
389409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
390409d7af7SAndreas Gohr          }else{
391409d7af7SAndreas Gohr            if($INFO['exists']){
392409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
393409d7af7SAndreas Gohr            }else{
394409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
395409d7af7SAndreas Gohr            }
396409d7af7SAndreas Gohr          }
397409d7af7SAndreas Gohr        }else{
398409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
399409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
400409d7af7SAndreas Gohr        }
401409d7af7SAndreas Gohr      }else{
402409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
403409d7af7SAndreas Gohr      }
4046b13307fSandi      break;
4056b13307fSandi    case 'history':
4065bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
4076b13307fSandi      break;
4086b13307fSandi    case 'recent':
4095bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
4106b13307fSandi      break;
4116b13307fSandi    case 'index':
4125bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
4136b13307fSandi      break;
414a3ec5f4aSmatthiasgrimm    case 'back':
4156222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4166222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
417a3ec5f4aSmatthiasgrimm      }
418a3ec5f4aSmatthiasgrimm      break;
4196b13307fSandi    case 'top':
4206b13307fSandi      print html_topbtn();
4216b13307fSandi      break;
4226b13307fSandi    case 'login':
4236b13307fSandi      if($conf['useacl']){
4246b13307fSandi        if($_SERVER['REMOTE_USER']){
4256b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
4266b13307fSandi        }else{
4276b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
4286b13307fSandi        }
4296b13307fSandi      }
4306b13307fSandi      break;
431c19fe9c0Sandi    case 'admin':
432*f8cc712eSAndreas Gohr      if($INFO['ismanager'])
4335bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
434c19fe9c0Sandi      break;
435d67ca2c0Smatthiasgrimm    case 'backtomedia':
436d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
437d67ca2c0Smatthiasgrimm      break;
4381380fc45SAndreas Gohr    case 'subscription':
439f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
440b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
4411380fc45SAndreas Gohr          if($INFO['subscribed']){
4421380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
443b158d625SSteven Danz          } else {
4441380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
445b158d625SSteven Danz          }
446b158d625SSteven Danz        }
447b158d625SSteven Danz      }
448b158d625SSteven Danz      break;
449f00151b4Schris    case 'backlink':
450f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
451f00151b4Schris      break;
4528b06d178Schris    case 'profile':
45336223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
45436223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
4558b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
4568b06d178Schris      }
4578b06d178Schris      break;
458c19fe9c0Sandi    default:
459c19fe9c0Sandi      print '[unknown button type]';
4606b13307fSandi  }
4616b13307fSandi}
4626b13307fSandi
4636b13307fSandi/**
464ed630903Sandi * Like the action buttons but links
465ed630903Sandi *
466ed630903Sandi * Available links are
467ed630903Sandi *
468d449b912SDenis Simakov *  edit    - edit/create/show link
469ed630903Sandi *  history - old revisions
470ed630903Sandi *  recent  - recent changes
471d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
472d449b912SDenis Simakov *  profile - user profile link (if logged in)
473ed630903Sandi *  index   - The index
474ed630903Sandi *  admin   - admin page - if enough rights
475d449b912SDenis Simakov *  top     - a back to top link
476d449b912SDenis Simakov *  back    - a back to parent link - if available
477bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
478d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
479ed630903Sandi *
480ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
481a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
482ed630903Sandi * @see    tpl_button
483ed630903Sandi */
484ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
485ed630903Sandi  global $ID;
486ed630903Sandi  global $INFO;
487ed630903Sandi  global $REV;
488ed630903Sandi  global $ACT;
489ed630903Sandi  global $conf;
490ed630903Sandi  global $lang;
491cd52f92dSchris  global $auth;
492ed630903Sandi
49375e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
49475e487e9SAndreas Gohr  $ctype = $type;
49575e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
49675e487e9SAndreas Gohr  if(!actionOK($ctype)) return;
497409d7af7SAndreas Gohr
498ed630903Sandi  switch($type){
499ed630903Sandi    case 'edit':
500ed630903Sandi      #most complicated type - we need to decide on current action
501ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
502ed630903Sandi        if($INFO['writable']){
503b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
504b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
505b8a111f5SMichael Klier                       $pre.$lang['btn_draft'].$suf,
506b8a111f5SMichael Klier                       'class="action edit" acceskey="e" rel="nofollow"');
507b8a111f5SMichael Klier          } else {
508ed630903Sandi            if($INFO['exists']){
509ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
510ed630903Sandi                       $pre.$lang['btn_edit'].$suf,
511b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
512ed630903Sandi            }else{
513ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
514ed630903Sandi                       $pre.$lang['btn_create'].$suf,
515b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
516ed630903Sandi            }
517b8a111f5SMichael Klier          }
518ed630903Sandi        }else{
519409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
520ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
521ed630903Sandi                   $pre.$lang['btn_source'].$suf,
522b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
523ed630903Sandi        }
524ed630903Sandi      }else{
525ed630903Sandi          tpl_link(wl($ID,'do=show'),
526ed630903Sandi                   $pre.$lang['btn_show'].$suf,
527b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
528ed630903Sandi      }
529c059e1a6SAndreas Gohr      return true;
530ed630903Sandi    case 'history':
531b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
532c059e1a6SAndreas Gohr      return true;
533ed630903Sandi    case 'recent':
534b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
535c059e1a6SAndreas Gohr      return true;
536ed630903Sandi    case 'index':
537b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
538c059e1a6SAndreas Gohr      return true;
539ed630903Sandi    case 'top':
54021a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
541c059e1a6SAndreas Gohr      return true;
542a3ec5f4aSmatthiasgrimm    case 'back':
543f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
544f7569b7bSAndreas Gohr        tpl_link(wl($parent,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
545c059e1a6SAndreas Gohr        return true;
546a3ec5f4aSmatthiasgrimm      }
547c059e1a6SAndreas Gohr      return false;
548ed630903Sandi    case 'login':
549ed630903Sandi      if($conf['useacl']){
550ed630903Sandi        if($_SERVER['REMOTE_USER']){
551b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
552ed630903Sandi        }else{
553b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
554ed630903Sandi        }
555c059e1a6SAndreas Gohr        return true;
556ed630903Sandi      }
557c059e1a6SAndreas Gohr      return false;
558ed630903Sandi    case 'admin':
559*f8cc712eSAndreas Gohr      if($INFO['ismanager']){
560b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
561c059e1a6SAndreas Gohr        return true;
562c059e1a6SAndreas Gohr      }
563c059e1a6SAndreas Gohr      return false;
564f9eb5648Ssteven-danz   case 'subscribe':
565075f000fSChristopher Arndt   case 'subscription':
566f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
567b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
568075f000fSChristopher Arndt          if($INFO['subscribed']) {
569b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
570b158d625SSteven Danz          } else {
571b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
572b158d625SSteven Danz          }
573c059e1a6SAndreas Gohr          return true;
574b158d625SSteven Danz        }
575b158d625SSteven Danz      }
576c059e1a6SAndreas Gohr      return false;
577f00151b4Schris    case 'backlink':
578b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
579c059e1a6SAndreas Gohr      return true;
5808b06d178Schris    case 'profile':
58136223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
58236223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
5838b06d178Schris        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
584c059e1a6SAndreas Gohr        return true;
5858b06d178Schris      }
586c059e1a6SAndreas Gohr      return false;
587ed630903Sandi    default:
588ed630903Sandi      print '[unknown link type]';
589c059e1a6SAndreas Gohr      return true;
590ed630903Sandi  }
591ed630903Sandi}
592ed630903Sandi
593ed630903Sandi/**
5946b13307fSandi * Print the search form
5956b13307fSandi *
59672645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
59772645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
59872645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
59972645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
60072645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
60172645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
60272645b75SAndreas Gohr *
6036b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6046b13307fSandi */
60572645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6066b13307fSandi  global $lang;
607c1e3b7d9Smatthiasgrimm  global $ACT;
608c1e3b7d9Smatthiasgrimm
609670ff54eSchris  // don't print the search form if search action has been disabled
610670ff54eSchris  if (!actionOk('search')) return;
611670ff54eSchris
6121dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6136b13307fSandi  print '<input type="hidden" name="do" value="search" />';
614c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
615bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
61672645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
617818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
61811ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
61924a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6204beabca9SAnika Henke  print '</div></form>';
6216b13307fSandi}
6226b13307fSandi
6236b13307fSandi/**
6246b13307fSandi * Print the breadcrumbs trace
6256b13307fSandi *
6266b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6276b13307fSandi */
6286b13307fSandifunction tpl_breadcrumbs(){
6296b13307fSandi  global $lang;
6306b13307fSandi  global $conf;
6316b13307fSandi
6326b13307fSandi  //check if enabled
6336b13307fSandi  if(!$conf['breadcrumbs']) return;
6346b13307fSandi
6356b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
636265e3787Sandi
637265e3787Sandi  //reverse crumborder in right-to-left mode
638265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
639265e3787Sandi
64040eb54bbSjan  //render crumbs, highlight the last one
6416b13307fSandi  print $lang['breadcrumb'].':';
64240eb54bbSjan  $last = count($crumbs);
64340eb54bbSjan  $i = 0;
644a77f5846Sjan  foreach ($crumbs as $id => $name){
64540eb54bbSjan    $i++;
646265e3787Sandi    print ' <span class="bcsep">&raquo;</span> ';
64792795d04Sandi    if ($i == $last) print '<span class="curid">';
648e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
64992795d04Sandi    if ($i == $last) print '</span>';
6506b13307fSandi  }
6516b13307fSandi}
6526b13307fSandi
6536b13307fSandi/**
6541734437eSandi * Hierarchical breadcrumbs
6551734437eSandi *
65631e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
6571734437eSandi * It only makes sense with a deep site structure.
6581734437eSandi *
6591734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
6606bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
66131e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
6621734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
6636bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
6641734437eSandi */
665796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
6661734437eSandi  global $conf;
6671734437eSandi  global $ID;
6681734437eSandi  global $lang;
6691734437eSandi
67031e187f8SSean Coates  // check if enabled
67131e187f8SSean Coates  if(!$conf['youarehere']) return;
6721734437eSandi
6731734437eSandi  $parts = explode(':', $ID);
674796bafb3SAndreas Gohr  $count = count($parts);
6751734437eSandi
676796bafb3SAndreas Gohr  echo $lang['youarehere'].': ';
6771734437eSandi
6781734437eSandi  // always print the startpage
679796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
680796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
681e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
682796bafb3SAndreas Gohr
683796bafb3SAndreas Gohr  // print intermediate namespace links
684796bafb3SAndreas Gohr  $part = '';
685796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
686796bafb3SAndreas Gohr    $part .= $parts[$i].':';
687796bafb3SAndreas Gohr    $page = $part;
688796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
689796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
690796bafb3SAndreas Gohr
691796bafb3SAndreas Gohr    // output
692796bafb3SAndreas Gohr    echo $sep;
693796bafb3SAndreas Gohr    if($exists){
694796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
695796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
696e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
69731e187f8SSean Coates    }else{
698796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
69931e187f8SSean Coates    }
70031e187f8SSean Coates  }
7011734437eSandi
702796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
703d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
704796bafb3SAndreas Gohr  $page = $part.$parts[$i];
705796bafb3SAndreas Gohr  if($page == $conf['start']) return;
706796bafb3SAndreas Gohr  echo $sep;
707d8186216SBen Coburn  if(@file_exists(wikiFN($page))){
708796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
709796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
710e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
71131e187f8SSean Coates  }else{
712796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
7131734437eSandi  }
7141734437eSandi}
7151734437eSandi
7161734437eSandi/**
7176b13307fSandi * Print info if the user is logged in
718a2488c3cSMatthias Grimm * and show full name in that case
7196b13307fSandi *
7206b13307fSandi * Could be enhanced with a profile link in future?
7216b13307fSandi *
7226b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7236b13307fSandi */
7246b13307fSandifunction tpl_userinfo(){
7256b13307fSandi  global $lang;
726a2488c3cSMatthias Grimm  global $INFO;
7276b13307fSandi  if($_SERVER['REMOTE_USER'])
728a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
7296b13307fSandi}
7306b13307fSandi
7316b13307fSandi/**
7326b13307fSandi * Print some info about the current page
7336b13307fSandi *
7346b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7356b13307fSandi */
7366b13307fSandifunction tpl_pageinfo(){
7376b13307fSandi  global $conf;
7386b13307fSandi  global $lang;
7396b13307fSandi  global $INFO;
7406b13307fSandi  global $REV;
7416b13307fSandi
7426b13307fSandi  // prepare date and path
7436b13307fSandi  $fn = $INFO['filepath'];
7446b13307fSandi  if(!$conf['fullpath']){
7456b13307fSandi    if($REV){
7466b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
7476b13307fSandi    }else{
7486b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
7496b13307fSandi    }
7506b13307fSandi  }
751bee6dc82Sandi  $fn = utf8_decodeFN($fn);
7526b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
7536b13307fSandi
7546b13307fSandi  // print it
7556b13307fSandi  if($INFO['exists']){
7566b13307fSandi    print $fn;
7576b13307fSandi    print ' &middot; ';
7586b13307fSandi    print $lang['lastmod'];
7596b13307fSandi    print ': ';
7606b13307fSandi    print $date;
7616b13307fSandi    if($INFO['editor']){
7626b13307fSandi      print ' '.$lang['by'].' ';
7636b13307fSandi      print $INFO['editor'];
7646b13307fSandi    }
7656b13307fSandi    if($INFO['locked']){
7666b13307fSandi      print ' &middot; ';
7676b13307fSandi      print $lang['lockedby'];
7686b13307fSandi      print ': ';
7696b13307fSandi      print $INFO['locked'];
7706b13307fSandi    }
7716b13307fSandi  }
7726b13307fSandi}
7736b13307fSandi
774820fa24bSandi/**
775a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
77687c434ceSAndreas Gohr *
77787c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
778a6598f23SBen Coburn * the given ID is used.
77987c434ceSAndreas Gohr *
78087c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
78187c434ceSAndreas Gohr */
782a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
78387c434ceSAndreas Gohr  global $conf;
78487c434ceSAndreas Gohr  if(is_null($id)){
78587c434ceSAndreas Gohr    global $ID;
78687c434ceSAndreas Gohr    $id = $ID;
78787c434ceSAndreas Gohr  }
78887c434ceSAndreas Gohr
78987c434ceSAndreas Gohr  $name = $id;
79087c434ceSAndreas Gohr  if ($conf['useheading']) {
79187c434ceSAndreas Gohr    $title = p_get_first_heading($id);
79287c434ceSAndreas Gohr    if ($title) $name = $title;
79387c434ceSAndreas Gohr  }
794a6598f23SBen Coburn
795a6598f23SBen Coburn  if ($ret) {
796a6598f23SBen Coburn      return hsc($name);
797a6598f23SBen Coburn  } else {
79887c434ceSAndreas Gohr      print hsc($name);
79987c434ceSAndreas Gohr  }
800a6598f23SBen Coburn}
801340756e4Sandi
80255efc227SAndreas Gohr/**
80355efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
80455efc227SAndreas Gohr *
80555efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
80655efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
80755efc227SAndreas Gohr *
80855efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
80955efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
81055efc227SAndreas Gohr * to the names of the latter one)
81155efc227SAndreas Gohr *
8123df72098SAndreas Gohr * Only allowed in: detail.php
81355efc227SAndreas Gohr *
81455efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
81555efc227SAndreas Gohr */
8163df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
81755efc227SAndreas Gohr  // Init Exif Reader
81855efc227SAndreas Gohr  global $SRC;
8193df72098SAndreas Gohr
8203df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
8213df72098SAndreas Gohr
82255efc227SAndreas Gohr  static $meta = null;
8233df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
82455efc227SAndreas Gohr  if($meta === false) return $alt;
82555efc227SAndreas Gohr  $info = $meta->getField($tags);
82655efc227SAndreas Gohr  if($info == false) return $alt;
82755efc227SAndreas Gohr  return $info;
82855efc227SAndreas Gohr}
82955efc227SAndreas Gohr
83055efc227SAndreas Gohr/**
83155efc227SAndreas Gohr * Prints the image with a link to the full sized version
83255efc227SAndreas Gohr *
83355efc227SAndreas Gohr * Only allowed in: detail.php
83455efc227SAndreas Gohr */
835f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
83655efc227SAndreas Gohr  global $IMG;
83755efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
83855efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
83955efc227SAndreas Gohr
84055efc227SAndreas Gohr  //resize to given max values
84123a34783SAndreas Gohr  $ratio = 1;
84223a34783SAndreas Gohr  if($w >= $h){
843f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
84455efc227SAndreas Gohr      $ratio = $maxwidth/$w;
845f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
84655efc227SAndreas Gohr      $ratio = $maxheight/$h;
84755efc227SAndreas Gohr    }
84855efc227SAndreas Gohr  }else{
849f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
85055efc227SAndreas Gohr      $ratio = $maxheight/$h;
851f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
85255efc227SAndreas Gohr      $ratio = $maxwidth/$w;
85355efc227SAndreas Gohr    }
85455efc227SAndreas Gohr  }
85555efc227SAndreas Gohr  if($ratio){
85655efc227SAndreas Gohr    $w = floor($ratio*$w);
85755efc227SAndreas Gohr    $h = floor($ratio*$h);
85855efc227SAndreas Gohr  }
85955efc227SAndreas Gohr
8606de3759aSAndreas Gohr  //prepare URLs
8616de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
8626de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
86355efc227SAndreas Gohr
8642684e50aSAndreas Gohr  //prepare attributes
86555efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
8662684e50aSAndreas Gohr  $p = array();
8672684e50aSAndreas Gohr  if($w) $p['width']  = $w;
8682684e50aSAndreas Gohr  if($h) $p['height'] = $h;
8692684e50aSAndreas Gohr         $p['class']  = 'img_detail';
8702684e50aSAndreas Gohr  if($alt){
8712684e50aSAndreas Gohr    $p['alt']   = $alt;
8722684e50aSAndreas Gohr    $p['title'] = $alt;
8732684e50aSAndreas Gohr  }else{
8742684e50aSAndreas Gohr    $p['alt'] = '';
8752684e50aSAndreas Gohr  }
8762684e50aSAndreas Gohr  $p = buildAttributes($p);
87755efc227SAndreas Gohr
87855efc227SAndreas Gohr  print '<a href="'.$url.'">';
8796de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
88055efc227SAndreas Gohr  print '</a>';
88155efc227SAndreas Gohr}
88255efc227SAndreas Gohr
8837367b368SAndreas Gohr/**
8847367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
8857367b368SAndreas Gohr * is the inexer function.
8867367b368SAndreas Gohr *
8877367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
8887367b368SAndreas Gohr * template
8897367b368SAndreas Gohr */
8907367b368SAndreas Gohrfunction tpl_indexerWebBug(){
8917367b368SAndreas Gohr  global $ID;
8921dad36f5SAndreas Gohr  global $INFO;
8931dad36f5SAndreas Gohr  if(!$INFO['exists']) return;
8941dad36f5SAndreas Gohr
8950dc92c6fSAndreas Gohr  if(isHiddenPage($ID)) return; //no need to index hidden pages
8960dc92c6fSAndreas Gohr
8977367b368SAndreas Gohr  $p = array();
898b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
899e68c51baSAndreas Gohr                 '&'.time();
9007367b368SAndreas Gohr  $p['width']  = 1;
9017367b368SAndreas Gohr  $p['height'] = 1;
9027367b368SAndreas Gohr  $p['alt']    = '';
9037367b368SAndreas Gohr  $att = buildAttributes($p);
9047367b368SAndreas Gohr  print "<img $att />";
9057367b368SAndreas Gohr}
9067367b368SAndreas Gohr
90778d4e784SEsther Brunner// configuration methods
90878d4e784SEsther Brunner/**
90978d4e784SEsther Brunner * tpl_getConf($id)
91078d4e784SEsther Brunner *
91178d4e784SEsther Brunner * use this function to access template configuration variables
91278d4e784SEsther Brunner */
91378d4e784SEsther Brunnerfunction tpl_getConf($id){
91478d4e784SEsther Brunner  global $conf;
91578d4e784SEsther Brunner  global $tpl_configloaded;
91678d4e784SEsther Brunner
91778d4e784SEsther Brunner  $tpl = $conf['template'];
91878d4e784SEsther Brunner
91978d4e784SEsther Brunner  if (!$tpl_configloaded){
92078d4e784SEsther Brunner    $tconf = tpl_loadConfig();
92178d4e784SEsther Brunner    if ($tconf !== false){
92278d4e784SEsther Brunner      foreach ($tconf as $key => $value){
92378d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
92478d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
92578d4e784SEsther Brunner      }
92678d4e784SEsther Brunner      $tpl_configloaded = true;
92778d4e784SEsther Brunner    }
92878d4e784SEsther Brunner  }
92978d4e784SEsther Brunner
93078d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
93178d4e784SEsther Brunner}
93278d4e784SEsther Brunner
93378d4e784SEsther Brunner/**
93478d4e784SEsther Brunner * tpl_loadConfig()
93578d4e784SEsther Brunner * reads all template configuration variables
93678d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
93778d4e784SEsther Brunner */
93878d4e784SEsther Brunnerfunction tpl_loadConfig(){
93978d4e784SEsther Brunner
94078d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
94178d4e784SEsther Brunner  $conf = array();
94278d4e784SEsther Brunner
94378d4e784SEsther Brunner  if (!@file_exists($file)) return false;
94478d4e784SEsther Brunner
94578d4e784SEsther Brunner  // load default config file
94678d4e784SEsther Brunner  include($file);
94778d4e784SEsther Brunner
94878d4e784SEsther Brunner  return $conf;
94978d4e784SEsther Brunner}
95078d4e784SEsther Brunner
9513df72098SAndreas Gohr/**
9523df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
9533df72098SAndreas Gohr *
9543df72098SAndreas Gohr * Depending on the user's actions this may be a list of
9553df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
9563df72098SAndreas Gohr * a message of referencing pages
9573df72098SAndreas Gohr *
9583df72098SAndreas Gohr * Only allowed in mediamanager.php
9593df72098SAndreas Gohr *
9603df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
9613df72098SAndreas Gohr */
9623df72098SAndreas Gohrfunction tpl_mediaContent(){
9633df72098SAndreas Gohr  global $IMG;
9643df72098SAndreas Gohr  global $AUTH;
9653df72098SAndreas Gohr  global $INUSE;
9663df72098SAndreas Gohr  global $NS;
9673df72098SAndreas Gohr  global $JUMPTO;
9683df72098SAndreas Gohr
9693df72098SAndreas Gohr  ptln('<div id="media__content">');
9703df72098SAndreas Gohr  if($_REQUEST['edit']){
9713df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
9727b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
9733df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
9743df72098SAndreas Gohr  }else{
9753df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
9763df72098SAndreas Gohr  }
9773df72098SAndreas Gohr  ptln('</div>');
9783df72098SAndreas Gohr}
9793df72098SAndreas Gohr
9803df72098SAndreas Gohr/**
9813df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
9823df72098SAndreas Gohr *
9833df72098SAndreas Gohr * Only allowed in mediamanager.php
9843df72098SAndreas Gohr *
9853df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
9863df72098SAndreas Gohr */
9873df72098SAndreas Gohrfunction tpl_mediaTree(){
9883df72098SAndreas Gohr  global $NS;
9893df72098SAndreas Gohr
9903df72098SAndreas Gohr  ptln('<div id="media__tree">');
9913df72098SAndreas Gohr  media_nstree($NS);
9923df72098SAndreas Gohr  ptln('</div>');
9933df72098SAndreas Gohr}
9943df72098SAndreas Gohr
995340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
996