xref: /dokuwiki/inc/template.php (revision 0dc92c6f78995331021c3b8c6a889913cf3f7de3)
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/**
136b13307fSandi * Wrapper around htmlspecialchars()
146b13307fSandi *
156b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
166b13307fSandi * @see    htmlspecialchars()
176b13307fSandi */
186b13307fSandifunction hsc($string){
196b13307fSandi  return htmlspecialchars($string);
206b13307fSandi}
216b13307fSandi
226b13307fSandi/**
236b13307fSandi * print a newline terminated string
246b13307fSandi *
256b13307fSandi * You can give an indention as optional parameter
266b13307fSandi *
276b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
286b13307fSandi */
296b13307fSandifunction ptln($string,$intend=0){
306b13307fSandi  for($i=0; $i<$intend; $i++) print ' ';
316b13307fSandi  print"$string\n";
326b13307fSandi}
336b13307fSandi
346b13307fSandi/**
355a892029SAndreas Gohr * Returns the path to the given template, uses
365a892029SAndreas Gohr * default one if the custom version doesn't exist
375a892029SAndreas Gohr *
385a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
395a892029SAndreas Gohr */
405a892029SAndreas Gohrfunction template($tpl){
415a892029SAndreas Gohr  global $conf;
425a892029SAndreas Gohr
435a892029SAndreas Gohr  if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
445a892029SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
455a892029SAndreas Gohr
465a892029SAndreas Gohr  return DOKU_INC.'lib/tpl/default/'.$tpl;
475a892029SAndreas Gohr}
485a892029SAndreas Gohr
495a892029SAndreas Gohr/**
506b13307fSandi * Print the content
516b13307fSandi *
526b13307fSandi * This function is used for printing all the usual content
536b13307fSandi * (defined by the global $ACT var) by calling the appropriate
546b13307fSandi * outputfunction(s) from html.php
556b13307fSandi *
566b13307fSandi * Everything that doesn't use the default template isn't
576b13307fSandi * handled by this function. ACL stuff is not done either.
586b13307fSandi *
596b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
606b13307fSandi */
616b13307fSandifunction tpl_content(){
626b13307fSandi  global $ACT;
636b13307fSandi  global $TEXT;
646b13307fSandi  global $PRE;
656b13307fSandi  global $SUF;
666b13307fSandi  global $SUM;
676b13307fSandi  global $IDX;
686b13307fSandi
696b13307fSandi  switch($ACT){
706b13307fSandi    case 'show':
716b13307fSandi      html_show();
726b13307fSandi      break;
73ea67f144Sandi    case 'preview':
746b13307fSandi      html_edit($TEXT);
756b13307fSandi      html_show($TEXT);
766b13307fSandi      break;
776b13307fSandi    case 'edit':
786b13307fSandi      html_edit();
796b13307fSandi      break;
806b13307fSandi    case 'wordblock':
816b13307fSandi      html_edit($TEXT,'wordblock');
826b13307fSandi      break;
836b13307fSandi    case 'search':
846b13307fSandi      html_search();
856b13307fSandi      break;
866b13307fSandi    case 'revisions':
876b13307fSandi      html_revisions();
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:
128ea67f144Sandi            msg("Failed to handle command: ".hsc($ACT),-1);
1296b13307fSandi  }
1306b13307fSandi}
1316b13307fSandi
132c19fe9c0Sandi/**
133c19fe9c0Sandi * Handle the admin page contents
134c19fe9c0Sandi *
135c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
136c19fe9c0Sandi */
137c19fe9c0Sandifunction tpl_admin(){
13811e2ce22Schris
13911e2ce22Schris    $plugin = NULL;
14011e2ce22Schris    if ($_REQUEST['page']) {
14111e2ce22Schris        $pluginlist = plugin_list('admin');
14211e2ce22Schris
14311e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
14411e2ce22Schris
14511e2ce22Schris          // attempt to load the plugin
14611e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
14711e2ce22Schris        }
14811e2ce22Schris    }
14911e2ce22Schris
15011e2ce22Schris    if ($plugin !== NULL)
15111e2ce22Schris        $plugin->html();
15211e2ce22Schris    else
15311e2ce22Schris        html_admin();
154c19fe9c0Sandi}
1556b13307fSandi
1566b13307fSandi/**
1576b13307fSandi * Print the correct HTML meta headers
1586b13307fSandi *
1596b13307fSandi * This has to go into the head section of your template.
1606b13307fSandi *
1616b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1626b13307fSandi */
1636b13307fSandifunction tpl_metaheaders(){
1646b13307fSandi  global $ID;
1656b13307fSandi  global $INFO;
1666b13307fSandi  global $ACT;
1676b13307fSandi  global $lang;
168dc57ef04Sandi  global $conf;
1696b13307fSandi  $it=2;
1706b13307fSandi
1716b13307fSandi  // the usual stuff
1726b13307fSandi  ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it);
1736b13307fSandi  ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it);
1746b13307fSandi  ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it);
1756b13307fSandi  ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it);
1766b13307fSandi  ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&amp;ns='.$INFO['namespace'].'" />',$it);
1776b13307fSandi  ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it);
1786b13307fSandi  ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it);
1796b13307fSandi
1806b13307fSandi  // setup robot tags apropriate for different modes
1816b13307fSandi  if( ($ACT=='show' || $ACT=='export_html') && !$REV){
1826b13307fSandi    if($INFO['exists']){
1836b13307fSandi      ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it);
1846b13307fSandi      //delay indexing:
1856b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
1866b13307fSandi        ptln('<meta name="robots" content="index,follow" />',$it);
1876b13307fSandi      }else{
1886b13307fSandi        ptln('<meta name="robots" content="noindex,nofollow" />',$it);
1896b13307fSandi      }
1906b13307fSandi    }else{
1916b13307fSandi      ptln('<meta name="robots" content="noindex,follow" />',$it);
1926b13307fSandi    }
1936b13307fSandi  }else{
1946b13307fSandi    ptln('<meta name="robots" content="noindex,nofollow" />',$it);
1956b13307fSandi  }
1966b13307fSandi
19778a6aeb1SAndreas Gohr  // load stylesheets
19878a6aeb1SAndreas Gohr  ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php" />',$it);
19978a6aeb1SAndreas Gohr  ptln('<link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php?print=1" />',$it);
200bad31ae9SAndreas Gohr
20178a6aeb1SAndreas Gohr  // load javascript
202bad31ae9SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview') ? 1 : 0;
203bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
20478a6aeb1SAndreas Gohr  $js_sig   = ($conf['useacl'] && $_SERVER['REMOTE_USER']) ? 1 : 0;
205bad31ae9SAndreas Gohr  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
20678a6aeb1SAndreas Gohr       DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&amp;write='.$js_write.'&amp;sig='.$js_sig.'"></script>',$it);
2076b13307fSandi}
2086b13307fSandi
2096b13307fSandi/**
2106b13307fSandi * Print a link
2116b13307fSandi *
2125e163278SAndreas Gohr * Just builds a link.
2136b13307fSandi *
2146b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2156b13307fSandi */
2166b13307fSandifunction tpl_link($url,$name,$more=''){
2175e163278SAndreas Gohr  print '<a href="'.$url.'" ';
2186b13307fSandi  if ($more) print ' '.$more;
2196b13307fSandi  print ">$name</a>";
2206b13307fSandi}
2216b13307fSandi
2226b13307fSandi/**
22355efc227SAndreas Gohr * Prints a link to a WikiPage
22455efc227SAndreas Gohr *
22555efc227SAndreas Gohr * Wrapper around html_wikilink
22655efc227SAndreas Gohr *
22755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
22855efc227SAndreas Gohr */
22955efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
23055efc227SAndreas Gohr  print html_wikilink($id,$name);
23155efc227SAndreas Gohr}
23255efc227SAndreas Gohr
23355efc227SAndreas Gohr/**
234a3ec5f4aSmatthiasgrimm * get the parent page
235a3ec5f4aSmatthiasgrimm *
236a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
237a3ec5f4aSmatthiasgrimm * returns false if none is available
238a3ec5f4aSmatthiasgrimm *
239a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
240a3ec5f4aSmatthiasgrimm */
241a3ec5f4aSmatthiasgrimmfunction tpl_getparent($ID){
242a3ec5f4aSmatthiasgrimm  global $conf;
243a3ec5f4aSmatthiasgrimm
244a3ec5f4aSmatthiasgrimm  if ($ID != $conf['start']) {
245a3ec5f4aSmatthiasgrimm    $idparts = explode(':', $ID);
246a3ec5f4aSmatthiasgrimm    $pn = array_pop($idparts);    // get the page name
247a3ec5f4aSmatthiasgrimm
248a3ec5f4aSmatthiasgrimm    for ($n=0; $n < 2; $n++) {
249a3ec5f4aSmatthiasgrimm      if (count($idparts) == 0) {
250a3ec5f4aSmatthiasgrimm        $ID = $conf['start'];     // go to topmost page
251a3ec5f4aSmatthiasgrimm        break;
252a3ec5f4aSmatthiasgrimm      }else{
253a3ec5f4aSmatthiasgrimm        $ns = array_pop($idparts);     // get the last part of namespace
254a3ec5f4aSmatthiasgrimm        if ($pn != $ns) {                 // are we already home?
255a3ec5f4aSmatthiasgrimm          array_push($idparts, $ns, $ns); // no, then add a page with same name
256a3ec5f4aSmatthiasgrimm          $ID = implode (':', $idparts); // as the namespace and recombine $ID
257a3ec5f4aSmatthiasgrimm          break;
258a3ec5f4aSmatthiasgrimm        }
259a3ec5f4aSmatthiasgrimm      }
260a3ec5f4aSmatthiasgrimm    }
261a3ec5f4aSmatthiasgrimm
262a3ec5f4aSmatthiasgrimm    if (@file_exists(wikiFN($ID))) {
263a3ec5f4aSmatthiasgrimm      return $ID;
264a3ec5f4aSmatthiasgrimm    }
265a3ec5f4aSmatthiasgrimm  }
266a3ec5f4aSmatthiasgrimm  return false;
267a3ec5f4aSmatthiasgrimm}
268a3ec5f4aSmatthiasgrimm
269a3ec5f4aSmatthiasgrimm/**
2706b13307fSandi * Print one of the buttons
2716b13307fSandi *
2726b13307fSandi * Available Buttons are
2736b13307fSandi *
2746b13307fSandi *  edit        - edit/create/show button
2756b13307fSandi *  history     - old revisions
2766b13307fSandi *  recent      - recent changes
2776b13307fSandi *  login       - login/logout button - if ACL enabled
2786b13307fSandi *  index       - The index
279c19fe9c0Sandi *  admin       - admin page - if enough rights
2806b13307fSandi *  top         - a back to top button
281a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
282d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
283d67ca2c0Smatthiasgrimm *                after references have been displayed
284bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
2856b13307fSandi *
2866b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
287a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
2886b13307fSandi */
2896b13307fSandifunction tpl_button($type){
290b158d625SSteven Danz  global $ACT;
2916b13307fSandi  global $ID;
292d67ca2c0Smatthiasgrimm  global $NS;
293c19fe9c0Sandi  global $INFO;
2946b13307fSandi  global $conf;
2956b13307fSandi
2966b13307fSandi  switch($type){
2976b13307fSandi    case 'edit':
2986b13307fSandi      print html_editbutton();
2996b13307fSandi      break;
3006b13307fSandi    case 'history':
3015bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
3026b13307fSandi      break;
3036b13307fSandi    case 'recent':
3045bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
3056b13307fSandi      break;
3066b13307fSandi    case 'index':
3075bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
3086b13307fSandi      break;
309a3ec5f4aSmatthiasgrimm    case 'back':
3106222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
3116222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
312a3ec5f4aSmatthiasgrimm      }
313a3ec5f4aSmatthiasgrimm      break;
3146b13307fSandi    case 'top':
3156b13307fSandi      print html_topbtn();
3166b13307fSandi      break;
3176b13307fSandi    case 'login':
3186b13307fSandi      if($conf['useacl']){
3196b13307fSandi        if($_SERVER['REMOTE_USER']){
3206b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
3216b13307fSandi        }else{
3226b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
3236b13307fSandi        }
3246b13307fSandi      }
3256b13307fSandi      break;
326c19fe9c0Sandi    case 'admin':
327c19fe9c0Sandi      if($INFO['perm'] == AUTH_ADMIN)
3285bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
329c19fe9c0Sandi      break;
330d67ca2c0Smatthiasgrimm    case 'backtomedia':
331d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
332d67ca2c0Smatthiasgrimm      break;
3331380fc45SAndreas Gohr    case 'subscription':
334f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
335b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
3361380fc45SAndreas Gohr          if($INFO['subscribed']){
3371380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
338b158d625SSteven Danz          } else {
3391380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
340b158d625SSteven Danz          }
341b158d625SSteven Danz        }
342b158d625SSteven Danz      }
343b158d625SSteven Danz      break;
344f00151b4Schris    case 'backlink':
345f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
346f00151b4Schris      break;
3478b06d178Schris    case 'profile':
3488b06d178Schris      if(($_SERVER['REMOTE_USER']) && auth_canDo('modifyUser') && ($ACT!='profile')){
3498b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
3508b06d178Schris      }
3518b06d178Schris      break;
352c19fe9c0Sandi    default:
353c19fe9c0Sandi      print '[unknown button type]';
3546b13307fSandi  }
3556b13307fSandi}
3566b13307fSandi
3576b13307fSandi/**
358ed630903Sandi * Like the action buttons but links
359ed630903Sandi *
360ed630903Sandi * Available links are
361ed630903Sandi *
362ed630903Sandi *  edit    - edit/create/show button
363ed630903Sandi *  history - old revisions
364ed630903Sandi *  recent  - recent changes
365ed630903Sandi *  login   - login/logout button - if ACL enabled
366ed630903Sandi *  index   - The index
367ed630903Sandi *  admin   - admin page - if enough rights
368ed630903Sandi *  top     - a back to top button
369a3ec5f4aSmatthiasgrimm *  back    - a back to parent button - if available
370bbd37938SAndreas Gohr * backlink - links to the list of backlinks
371ed630903Sandi *
372ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
373a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
374ed630903Sandi * @see    tpl_button
375ed630903Sandi */
376ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
377ed630903Sandi  global $ID;
378ed630903Sandi  global $INFO;
379ed630903Sandi  global $REV;
380ed630903Sandi  global $ACT;
381ed630903Sandi  global $conf;
382ed630903Sandi  global $lang;
383ed630903Sandi
384ed630903Sandi  switch($type){
385ed630903Sandi    case 'edit':
386ed630903Sandi      #most complicated type - we need to decide on current action
387ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
388ed630903Sandi        if($INFO['writable']){
389ed630903Sandi          if($INFO['exists']){
390ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
391ed630903Sandi                     $pre.$lang['btn_edit'].$suf,
392b7af031cSsu                     'class="action edit" accesskey="e" rel="nofollow"');
393ed630903Sandi          }else{
394ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
395ed630903Sandi                     $pre.$lang['btn_create'].$suf,
396b7af031cSsu                     'class="action create" accesskey="e" rel="nofollow"');
397ed630903Sandi          }
398ed630903Sandi        }else{
399ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
400ed630903Sandi                   $pre.$lang['btn_source'].$suf,
401b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
402ed630903Sandi        }
403ed630903Sandi      }else{
404ed630903Sandi          tpl_link(wl($ID,'do=show'),
405ed630903Sandi                   $pre.$lang['btn_show'].$suf,
406b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
407ed630903Sandi      }
408ed630903Sandi      break;
409ed630903Sandi    case 'history':
410b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
411ed630903Sandi      break;
412ed630903Sandi    case 'recent':
413b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
414ed630903Sandi      break;
415ed630903Sandi    case 'index':
416b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
417ed630903Sandi      break;
418ed630903Sandi    case 'top':
419b7af031cSsu      print '<a href="#top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
420ed630903Sandi      break;
421a3ec5f4aSmatthiasgrimm    case 'back':
422a3ec5f4aSmatthiasgrimm      if ($ID = tpl_getparent($ID)) {
423b7af031cSsu        tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
424a3ec5f4aSmatthiasgrimm      }
425a3ec5f4aSmatthiasgrimm      break;
426ed630903Sandi    case 'login':
427ed630903Sandi      if($conf['useacl']){
428ed630903Sandi        if($_SERVER['REMOTE_USER']){
429b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
430ed630903Sandi        }else{
431b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
432ed630903Sandi        }
433ed630903Sandi      }
434ed630903Sandi      break;
435ed630903Sandi    case 'admin':
436ed630903Sandi      if($INFO['perm'] == AUTH_ADMIN)
437b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
438ed630903Sandi      break;
439f9eb5648Ssteven-danz   case 'subscribe':
440075f000fSChristopher Arndt   case 'subscription':
441f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
442b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
443075f000fSChristopher Arndt          if($INFO['subscribed']) {
444b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
445b158d625SSteven Danz          } else {
446b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
447b158d625SSteven Danz          }
448b158d625SSteven Danz        }
449b158d625SSteven Danz      }
450b158d625SSteven Danz      break;
451f00151b4Schris    case 'backlink':
452b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
453f00151b4Schris      break;
4548b06d178Schris    case 'profile':
4558b06d178Schris      if(($_SERVER['REMOTE_USER']) && auth_canDo('modifyUser') && ($ACT!='profile')){
4568b06d178Schris        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
4578b06d178Schris      }
4588b06d178Schris      break;
459ed630903Sandi    default:
460ed630903Sandi      print '[unknown link type]';
461ed630903Sandi  }
462ed630903Sandi}
463ed630903Sandi
464ed630903Sandi/**
4656b13307fSandi * Print the search form
4666b13307fSandi *
46772645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
46872645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
46972645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
47072645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
47172645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
47272645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
47372645b75SAndreas Gohr *
4746b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4756b13307fSandi */
47672645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
4776b13307fSandi  global $lang;
478c1e3b7d9Smatthiasgrimm  global $ACT;
479c1e3b7d9Smatthiasgrimm
4805e163278SAndreas Gohr  print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search">';
4816b13307fSandi  print '<input type="hidden" name="do" value="search" />';
482c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
483bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
48472645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
485bad31ae9SAndreas Gohr  print 'id="qsearch_in" accesskey="f" name="id" class="edit" />';
4866b13307fSandi  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
48772645b75SAndreas Gohr  if($ajax) print '<div id="qsearch_out" class="ajax_qsearch JSpopup"></div>';
4886b13307fSandi  print '</form>';
4896b13307fSandi}
4906b13307fSandi
4916b13307fSandi/**
4926b13307fSandi * Print the breadcrumbs trace
4936b13307fSandi *
4946b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4956b13307fSandi */
4966b13307fSandifunction tpl_breadcrumbs(){
4976b13307fSandi  global $lang;
4986b13307fSandi  global $conf;
4996b13307fSandi
5006b13307fSandi  //check if enabled
5016b13307fSandi  if(!$conf['breadcrumbs']) return;
5026b13307fSandi
5036b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
504265e3787Sandi
505265e3787Sandi  //reverse crumborder in right-to-left mode
506265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
507265e3787Sandi
50840eb54bbSjan  //render crumbs, highlight the last one
5096b13307fSandi  print $lang['breadcrumb'].':';
51040eb54bbSjan  $last = count($crumbs);
51140eb54bbSjan  $i = 0;
512a77f5846Sjan  foreach ($crumbs as $id => $name){
51340eb54bbSjan    $i++;
514265e3787Sandi    print ' <span class="bcsep">&raquo;</span> ';
51592795d04Sandi    if ($i == $last) print '<span class="curid">';
516a77f5846Sjan    tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"');
51792795d04Sandi    if ($i == $last) print '</span>';
5186b13307fSandi  }
5196b13307fSandi}
5206b13307fSandi
5216b13307fSandi/**
5221734437eSandi * Hierarchical breadcrumbs
5231734437eSandi *
5241734437eSandi * This code was suggested as replacement for the usual breadcrumbs
5251734437eSandi * trail in the Wiki and was modified by me.
5261734437eSandi * It only makes sense with a deep site structure.
5271734437eSandi *
5281734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
5296bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
5301734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
5316bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
5321734437eSandi */
5331734437eSandifunction tpl_youarehere(){
5341734437eSandi  global $conf;
5351734437eSandi  global $ID;
5361734437eSandi  global $lang;
5371734437eSandi
5381734437eSandi
5391734437eSandi  $parts     = explode(':', $ID);
5401734437eSandi
5416bd812dfSNigel McNie  // Perhaps a $lang['tree'] could be defined? "Trace" isn't too appropriate
5426bd812dfSNigel McNie  //print $lang['tree'].': ';
5431734437eSandi  print $lang['breadcrumb'].': ';
5441734437eSandi
5451734437eSandi  //always print the startpage
5461734437eSandi  if( $a_part[0] != $conf['start'] )
5471734437eSandi    tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"');
5481734437eSandi
5491734437eSandi  $page = '';
5501734437eSandi  foreach ($parts as $part){
5516bd812dfSNigel McNie        // Skip startpage if already done
5526bd812dfSNigel McNie        if ($part == $conf['start']) continue;
5536bd812dfSNigel McNie
5541734437eSandi          print ' &raquo; ';
5551734437eSandi    $page .= $part;
5561734437eSandi
5571734437eSandi    if(file_exists(wikiFN($page))){
5581734437eSandi      tpl_link(wl($page),$part,'title="'.$page.'"');
5591734437eSandi    }else{
5606bd812dfSNigel McNie      // Print the link, but mark as not-existing, as for other non-existing links
5616bd812dfSNigel McNie      tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"');
5626bd812dfSNigel McNie      //print $page;
5631734437eSandi    }
5641734437eSandi
5651734437eSandi    $page .= ':';
5661734437eSandi  }
5671734437eSandi}
5681734437eSandi
5691734437eSandi/**
5706b13307fSandi * Print info if the user is logged in
571a2488c3cSMatthias Grimm * and show full name in that case
5726b13307fSandi *
5736b13307fSandi * Could be enhanced with a profile link in future?
5746b13307fSandi *
5756b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5766b13307fSandi */
5776b13307fSandifunction tpl_userinfo(){
5786b13307fSandi  global $lang;
579a2488c3cSMatthias Grimm  global $INFO;
5806b13307fSandi  if($_SERVER['REMOTE_USER'])
581a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
5826b13307fSandi}
5836b13307fSandi
5846b13307fSandi/**
5856b13307fSandi * Print some info about the current page
5866b13307fSandi *
5876b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5886b13307fSandi */
5896b13307fSandifunction tpl_pageinfo(){
5906b13307fSandi  global $conf;
5916b13307fSandi  global $lang;
5926b13307fSandi  global $INFO;
5936b13307fSandi  global $REV;
5946b13307fSandi
5956b13307fSandi  // prepare date and path
5966b13307fSandi  $fn = $INFO['filepath'];
5976b13307fSandi  if(!$conf['fullpath']){
5986b13307fSandi    if($REV){
5996b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
6006b13307fSandi    }else{
6016b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
6026b13307fSandi    }
6036b13307fSandi  }
604bee6dc82Sandi  $fn = utf8_decodeFN($fn);
6056b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
6066b13307fSandi
6076b13307fSandi  // print it
6086b13307fSandi  if($INFO['exists']){
6096b13307fSandi    print $fn;
6106b13307fSandi    print ' &middot; ';
6116b13307fSandi    print $lang['lastmod'];
6126b13307fSandi    print ': ';
6136b13307fSandi    print $date;
6146b13307fSandi    if($INFO['editor']){
6156b13307fSandi      print ' '.$lang['by'].' ';
6166b13307fSandi      print $INFO['editor'];
6176b13307fSandi    }
6186b13307fSandi    if($INFO['locked']){
6196b13307fSandi      print ' &middot; ';
6206b13307fSandi      print $lang['lockedby'];
6216b13307fSandi      print ': ';
6226b13307fSandi      print $INFO['locked'];
6236b13307fSandi    }
6246b13307fSandi  }
6256b13307fSandi}
6266b13307fSandi
627820fa24bSandi/**
628820fa24bSandi * Print a list of namespaces containing media files
629820fa24bSandi *
630820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
631820fa24bSandi */
632820fa24bSandifunction tpl_medianamespaces(){
633820fa24bSandi    global $conf;
634820fa24bSandi
635820fa24bSandi  $data = array();
636820fa24bSandi  search($data,$conf['mediadir'],'search_namespaces',array());
637820fa24bSandi  print html_buildlist($data,'idx',media_html_list_namespaces);
638820fa24bSandi}
639820fa24bSandi
640820fa24bSandi/**
641820fa24bSandi * Print a list of mediafiles in the current namespace
642820fa24bSandi *
643820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
644820fa24bSandi */
645820fa24bSandifunction tpl_mediafilelist(){
646820fa24bSandi  global $conf;
647820fa24bSandi  global $lang;
648820fa24bSandi  global $NS;
6498ef6b7caSandi  global $AUTH;
650820fa24bSandi  $dir = utf8_encodeFN(str_replace(':','/',$NS));
651820fa24bSandi
652820fa24bSandi  $data = array();
653820fa24bSandi  search($data,$conf['mediadir'],'search_media',array(),$dir);
654820fa24bSandi
655820fa24bSandi  if(!count($data)){
6564b15e09dSAndreas Gohr    ptln('<div class="nothing">'.$lang['nothingfound'].'</div>');
657820fa24bSandi    return;
658820fa24bSandi  }
659820fa24bSandi
660820fa24bSandi  ptln('<ul>',2);
661820fa24bSandi  foreach($data as $item){
662820fa24bSandi    ptln('<li>',4);
6636e37f3d9SAndreas Gohr    ptln('<a href="javascript:mediaSelect(\':'.$item['id'].'\')">'.
664820fa24bSandi         utf8_decodeFN($item['file']).
665820fa24bSandi         '</a>',6);
6668ef6b7caSandi
6678ef6b7caSandi    //prepare deletion button
6688ef6b7caSandi    if($AUTH >= AUTH_DELETE){
6698ef6b7caSandi      $ask  = $lang['del_confirm'].'\\n';
6708ef6b7caSandi      $ask .= $item['id'];
6718ef6b7caSandi
672f62ea8a1Sandi      $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '.
6738ef6b7caSandi             'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'.
674f62ea8a1Sandi             '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '.
6758ef6b7caSandi             'align="bottom" title="'.$lang['btn_delete'].'" /></a>';
6768ef6b7caSandi    }else{
6778ef6b7caSandi      $del = '';
6788ef6b7caSandi    }
6798ef6b7caSandi
680820fa24bSandi    if($item['isimg']){
68123a34783SAndreas Gohr      $w = $item['meta']->getField('File.Width');
68223a34783SAndreas Gohr      $h = $item['meta']->getField('File.Height');
683820fa24bSandi
6848ef6b7caSandi      ptln('('.$w.'&#215;'.$h.' '.filesize_h($item['size']).')',6);
6858ef6b7caSandi      ptln($del.'<br />',6);
686478cd997SAndreas Gohr      ptln('<div class="imagemeta">',6);
6879fcd3d1dSandi
68823a34783SAndreas Gohr      //build thumbnail
68923a34783SAndreas Gohr      print '<a href="javascript:mediaSelect(\''.$item['id'].'\')">';
69023a34783SAndreas Gohr
69123a34783SAndreas Gohr      if($w>120 || $h>120){
69223a34783SAndreas Gohr        $ratio = $item['meta']->getResizeRatio(120);
69323a34783SAndreas Gohr        $w = floor($w * $ratio);
69423a34783SAndreas Gohr        $h = floor($h * $ratio);
6959fcd3d1dSandi      }
69623a34783SAndreas Gohr
6976de3759aSAndreas Gohr      $src = ml($item['id'],array('w'=>$w,'h'=>$h));
69823a34783SAndreas Gohr
69923a34783SAndreas Gohr      $p = array();
70023a34783SAndreas Gohr      $p['width']  = $w;
70123a34783SAndreas Gohr      $p['height'] = $h;
70223a34783SAndreas Gohr      $p['alt']    = $item['id'];
70323a34783SAndreas Gohr      $p['class']  = 'thumb';
70423a34783SAndreas Gohr      $att = buildAttributes($p);
70523a34783SAndreas Gohr
70623a34783SAndreas Gohr      print '<img src="'.$src.'" '.$att.' />';
7079fcd3d1dSandi      print '</a>';
708820fa24bSandi
7096d861d12SAndreas Gohr      //read EXIF/IPTC data
71023a34783SAndreas Gohr      $t = $item['meta']->getField('IPTC.Headline');
7116d861d12SAndreas Gohr      if($t) print '<b>'.$t.'</b><br />';
7126d861d12SAndreas Gohr
71336df6fa3SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
71436df6fa3SAndreas Gohr                                         'EXIF.TIFFImageDescription',
71536df6fa3SAndreas Gohr                                         'EXIF.TIFFUserComment'));
7166d861d12SAndreas Gohr      if($t) print $t.'<br />';
7176d861d12SAndreas Gohr
71823a34783SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category'));
7196d861d12SAndreas Gohr      if($t) print '<i>'.$t.'</i><br />';
7206d861d12SAndreas Gohr
72136df6fa3SAndreas Gohr      //add edit button
72236df6fa3SAndreas Gohr      if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){
72336df6fa3SAndreas Gohr        print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.urlencode($item['id']).'">';
72436df6fa3SAndreas Gohr        print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />';
72536df6fa3SAndreas Gohr        print '</a>';
72636df6fa3SAndreas Gohr      }
72736df6fa3SAndreas Gohr
7286d861d12SAndreas Gohr      ptln('</div>',6);
729820fa24bSandi    }else{
730820fa24bSandi      ptln ('('.filesize_h($item['size']).')',6);
7318ef6b7caSandi      ptln($del,6);
732820fa24bSandi    }
733820fa24bSandi    ptln('</li>',4);
734820fa24bSandi  }
735820fa24bSandi  ptln('</ul>',2);
736820fa24bSandi}
737820fa24bSandi
738820fa24bSandi/**
739d67ca2c0Smatthiasgrimm * show references to a media file
740d67ca2c0Smatthiasgrimm * References uses the same visual as search results and share
741d67ca2c0Smatthiasgrimm * their CSS tags except pagenames won't be links.
742d67ca2c0Smatthiasgrimm *
743d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
744d67ca2c0Smatthiasgrimm */
745d67ca2c0Smatthiasgrimmfunction tpl_showreferences(&$data){
746d67ca2c0Smatthiasgrimm  global $lang;
747d67ca2c0Smatthiasgrimm
748d67ca2c0Smatthiasgrimm  $hidden=0; //count of hits without read permission
749d67ca2c0Smatthiasgrimm
750d67ca2c0Smatthiasgrimm  if(count($data)){
751d67ca2c0Smatthiasgrimm    usort($data,'sort_search_fulltext');
752d67ca2c0Smatthiasgrimm    foreach($data as $row){
753d67ca2c0Smatthiasgrimm      if(auth_quickaclcheck($row['id']) >= AUTH_READ){
754d67ca2c0Smatthiasgrimm        print '<div class="search_result">';
755d67ca2c0Smatthiasgrimm        print '<span class="mediaref_ref">'.$row['id'].'</span>';
756d67ca2c0Smatthiasgrimm        print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
757d67ca2c0Smatthiasgrimm        print '<div class="search_snippet">'.$row['snippet'].'</div>';
758d67ca2c0Smatthiasgrimm        print '</div>';
759d67ca2c0Smatthiasgrimm      }else
760d67ca2c0Smatthiasgrimm        $hidden++;
761d67ca2c0Smatthiasgrimm    }
762d67ca2c0Smatthiasgrimm    if ($hidden){
763d67ca2c0Smatthiasgrimm      print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
764d67ca2c0Smatthiasgrimm    }
765d67ca2c0Smatthiasgrimm  }
766d67ca2c0Smatthiasgrimm}
767d67ca2c0Smatthiasgrimm
768d67ca2c0Smatthiasgrimm/**
769820fa24bSandi * Print the media upload form if permissions are correct
770820fa24bSandi *
771820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
772820fa24bSandi */
773820fa24bSandifunction tpl_mediauploadform(){
774820fa24bSandi  global $NS;
775820fa24bSandi  global $UPLOADOK;
7768ef6b7caSandi  global $AUTH;
777820fa24bSandi  global $lang;
778820fa24bSandi
779820fa24bSandi  if(!$UPLOADOK) return;
780820fa24bSandi
7818dd5e97bSandi  ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" name="upload"'.
782820fa24bSandi       ' method="post" enctype="multipart/form-data">',2);
783820fa24bSandi  ptln($lang['txt_upload'].':<br />',4);
784820fa24bSandi  ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4);
785820fa24bSandi  ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4);
786820fa24bSandi  ptln($lang['txt_filename'].'<br />',4);
787820fa24bSandi  ptln('<input type="text" name="id" class="edit" />',4);
788820fa24bSandi  ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4);
7898ef6b7caSandi  if($AUTH >= AUTH_DELETE){
790b6912aeaSAndreas Gohr    ptln('<label for="ow"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4);
7918ef6b7caSandi  }
792820fa24bSandi  ptln('</form>',2);
793820fa24bSandi}
794820fa24bSandi
79587c434ceSAndreas Gohr/**
79687c434ceSAndreas Gohr * Prints the name of the given page (current one if none given).
79787c434ceSAndreas Gohr *
79887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
79987c434ceSAndreas Gohr * the given ID is printed.
80087c434ceSAndreas Gohr *
80187c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
80287c434ceSAndreas Gohr */
80387c434ceSAndreas Gohrfunction tpl_pagetitle($id=null){
80487c434ceSAndreas Gohr  global $conf;
80587c434ceSAndreas Gohr  if(is_null($id)){
80687c434ceSAndreas Gohr    global $ID;
80787c434ceSAndreas Gohr    $id = $ID;
80887c434ceSAndreas Gohr  }
80987c434ceSAndreas Gohr
81087c434ceSAndreas Gohr  $name = $id;
81187c434ceSAndreas Gohr  if ($conf['useheading']) {
81287c434ceSAndreas Gohr    $title = p_get_first_heading($id);
81387c434ceSAndreas Gohr    if ($title) $name = $title;
81487c434ceSAndreas Gohr  }
81587c434ceSAndreas Gohr  print hsc($name);
81687c434ceSAndreas Gohr}
817340756e4Sandi
81855efc227SAndreas Gohr/**
81955efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
82055efc227SAndreas Gohr *
82155efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
82255efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
82355efc227SAndreas Gohr *
82455efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
82555efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
82655efc227SAndreas Gohr * to the names of the latter one)
82755efc227SAndreas Gohr *
82836df6fa3SAndreas Gohr * Only allowed in: detail.php, mediaedit.php
82955efc227SAndreas Gohr *
83055efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
83155efc227SAndreas Gohr */
83255efc227SAndreas Gohrfunction tpl_img_getTag($tags,$alt=''){
83355efc227SAndreas Gohr  // Init Exif Reader
83455efc227SAndreas Gohr  global $SRC;
83555efc227SAndreas Gohr  static $meta = null;
83655efc227SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($SRC);
83755efc227SAndreas Gohr  if($meta === false) return $alt;
83855efc227SAndreas Gohr  $info = $meta->getField($tags);
83955efc227SAndreas Gohr  if($info == false) return $alt;
84055efc227SAndreas Gohr  return $info;
84155efc227SAndreas Gohr}
84255efc227SAndreas Gohr
84355efc227SAndreas Gohr/**
84455efc227SAndreas Gohr * Prints the image with a link to the full sized version
84555efc227SAndreas Gohr *
84655efc227SAndreas Gohr * Only allowed in: detail.php
84755efc227SAndreas Gohr */
848f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
84955efc227SAndreas Gohr  global $IMG;
85055efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
85155efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
85255efc227SAndreas Gohr
85355efc227SAndreas Gohr  //resize to given max values
85423a34783SAndreas Gohr  $ratio = 1;
85523a34783SAndreas Gohr  if($w >= $h){
856f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
85755efc227SAndreas Gohr      $ratio = $maxwidth/$w;
858f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
85955efc227SAndreas Gohr      $ratio = $maxheight/$h;
86055efc227SAndreas Gohr    }
86155efc227SAndreas Gohr  }else{
862f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
86355efc227SAndreas Gohr      $ratio = $maxheight/$h;
864f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
86555efc227SAndreas Gohr      $ratio = $maxwidth/$w;
86655efc227SAndreas Gohr    }
86755efc227SAndreas Gohr  }
86855efc227SAndreas Gohr  if($ratio){
86955efc227SAndreas Gohr    $w = floor($ratio*$w);
87055efc227SAndreas Gohr    $h = floor($ratio*$h);
87155efc227SAndreas Gohr  }
87255efc227SAndreas Gohr
8736de3759aSAndreas Gohr  //prepare URLs
8746de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
8756de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
87655efc227SAndreas Gohr
8772684e50aSAndreas Gohr  //prepare attributes
87855efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
8792684e50aSAndreas Gohr  $p = array();
8802684e50aSAndreas Gohr  if($w) $p['width']  = $w;
8812684e50aSAndreas Gohr  if($h) $p['height'] = $h;
8822684e50aSAndreas Gohr         $p['class']  = 'img_detail';
8832684e50aSAndreas Gohr  if($alt){
8842684e50aSAndreas Gohr    $p['alt']   = $alt;
8852684e50aSAndreas Gohr    $p['title'] = $alt;
8862684e50aSAndreas Gohr  }else{
8872684e50aSAndreas Gohr    $p['alt'] = '';
8882684e50aSAndreas Gohr  }
8892684e50aSAndreas Gohr  $p = buildAttributes($p);
89055efc227SAndreas Gohr
89155efc227SAndreas Gohr  print '<a href="'.$url.'">';
8926de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
89355efc227SAndreas Gohr  print '</a>';
89455efc227SAndreas Gohr}
89555efc227SAndreas Gohr
8967367b368SAndreas Gohr/**
8977367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
8987367b368SAndreas Gohr * is the inexer function.
8997367b368SAndreas Gohr *
9007367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9017367b368SAndreas Gohr * template
9027367b368SAndreas Gohr */
9037367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9047367b368SAndreas Gohr  global $ID;
9051dad36f5SAndreas Gohr  global $INFO;
9061dad36f5SAndreas Gohr  if(!$INFO['exists']) return;
9071dad36f5SAndreas Gohr
908*0dc92c6fSAndreas Gohr  if(isHiddenPage($ID)) return; //no need to index hidden pages
909*0dc92c6fSAndreas Gohr
9107367b368SAndreas Gohr  $p = array();
911e68c51baSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.urlencode($ID).
912e68c51baSAndreas Gohr                 '&'.time();
9137367b368SAndreas Gohr  $p['width']  = 1;
9147367b368SAndreas Gohr  $p['height'] = 1;
9157367b368SAndreas Gohr  $p['alt']    = '';
9167367b368SAndreas Gohr  $att = buildAttributes($p);
9177367b368SAndreas Gohr  print "<img $att />";
9187367b368SAndreas Gohr}
9197367b368SAndreas Gohr
920340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
921