xref: /dokuwiki/inc/template.php (revision 806d77a088c76f38c4ae300876006d8328005338)
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;
204c591aabeSAndreas Gohr  if($js_edit && $js_write){
205c591aabeSAndreas Gohr    ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it);
206c591aabeSAndreas Gohr    ptln("NS='".$INFO['namespace']."';",$it+2);
207c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
208c591aabeSAndreas Gohr      require_once('inc/toolbar.php');
209c591aabeSAndreas Gohr      ptln("SIG='".toolbar_signature()."';",$it+2);
210c591aabeSAndreas Gohr    }
211c591aabeSAndreas Gohr    ptln('</script>',$it);
212c591aabeSAndreas Gohr  }
213bad31ae9SAndreas Gohr  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
214c591aabeSAndreas Gohr       DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&amp;write='.$js_write.'"></script>',$it);
2156b13307fSandi}
2166b13307fSandi
2176b13307fSandi/**
2186b13307fSandi * Print a link
2196b13307fSandi *
2205e163278SAndreas Gohr * Just builds a link.
2216b13307fSandi *
2226b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2236b13307fSandi */
2246b13307fSandifunction tpl_link($url,$name,$more=''){
2255e163278SAndreas Gohr  print '<a href="'.$url.'" ';
2266b13307fSandi  if ($more) print ' '.$more;
2276b13307fSandi  print ">$name</a>";
2286b13307fSandi}
2296b13307fSandi
2306b13307fSandi/**
23155efc227SAndreas Gohr * Prints a link to a WikiPage
23255efc227SAndreas Gohr *
23355efc227SAndreas Gohr * Wrapper around html_wikilink
23455efc227SAndreas Gohr *
23555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
23655efc227SAndreas Gohr */
23755efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
23855efc227SAndreas Gohr  print html_wikilink($id,$name);
23955efc227SAndreas Gohr}
24055efc227SAndreas Gohr
24155efc227SAndreas Gohr/**
242a3ec5f4aSmatthiasgrimm * get the parent page
243a3ec5f4aSmatthiasgrimm *
244a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
245a3ec5f4aSmatthiasgrimm * returns false if none is available
246a3ec5f4aSmatthiasgrimm *
247a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
248a3ec5f4aSmatthiasgrimm */
249a3ec5f4aSmatthiasgrimmfunction tpl_getparent($ID){
250a3ec5f4aSmatthiasgrimm  global $conf;
251a3ec5f4aSmatthiasgrimm
252a3ec5f4aSmatthiasgrimm  if ($ID != $conf['start']) {
253a3ec5f4aSmatthiasgrimm    $idparts = explode(':', $ID);
254a3ec5f4aSmatthiasgrimm    $pn = array_pop($idparts);    // get the page name
255a3ec5f4aSmatthiasgrimm
256a3ec5f4aSmatthiasgrimm    for ($n=0; $n < 2; $n++) {
257a3ec5f4aSmatthiasgrimm      if (count($idparts) == 0) {
258a3ec5f4aSmatthiasgrimm        $ID = $conf['start'];     // go to topmost page
259a3ec5f4aSmatthiasgrimm        break;
260a3ec5f4aSmatthiasgrimm      }else{
261a3ec5f4aSmatthiasgrimm        $ns = array_pop($idparts);     // get the last part of namespace
262a3ec5f4aSmatthiasgrimm        if ($pn != $ns) {                 // are we already home?
263a3ec5f4aSmatthiasgrimm          array_push($idparts, $ns, $ns); // no, then add a page with same name
264a3ec5f4aSmatthiasgrimm          $ID = implode (':', $idparts); // as the namespace and recombine $ID
265a3ec5f4aSmatthiasgrimm          break;
266a3ec5f4aSmatthiasgrimm        }
267a3ec5f4aSmatthiasgrimm      }
268a3ec5f4aSmatthiasgrimm    }
269a3ec5f4aSmatthiasgrimm
270a3ec5f4aSmatthiasgrimm    if (@file_exists(wikiFN($ID))) {
271a3ec5f4aSmatthiasgrimm      return $ID;
272a3ec5f4aSmatthiasgrimm    }
273a3ec5f4aSmatthiasgrimm  }
274a3ec5f4aSmatthiasgrimm  return false;
275a3ec5f4aSmatthiasgrimm}
276a3ec5f4aSmatthiasgrimm
277a3ec5f4aSmatthiasgrimm/**
2786b13307fSandi * Print one of the buttons
2796b13307fSandi *
2806b13307fSandi * Available Buttons are
2816b13307fSandi *
2826b13307fSandi *  edit        - edit/create/show button
2836b13307fSandi *  history     - old revisions
2846b13307fSandi *  recent      - recent changes
2856b13307fSandi *  login       - login/logout button - if ACL enabled
2866b13307fSandi *  index       - The index
287c19fe9c0Sandi *  admin       - admin page - if enough rights
2886b13307fSandi *  top         - a back to top button
289a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
290d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
291d67ca2c0Smatthiasgrimm *                after references have been displayed
292bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
2936b13307fSandi *
2946b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
295a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
2966b13307fSandi */
2976b13307fSandifunction tpl_button($type){
298b158d625SSteven Danz  global $ACT;
2996b13307fSandi  global $ID;
300d67ca2c0Smatthiasgrimm  global $NS;
301c19fe9c0Sandi  global $INFO;
3026b13307fSandi  global $conf;
3036b13307fSandi
3046b13307fSandi  switch($type){
3056b13307fSandi    case 'edit':
3066b13307fSandi      print html_editbutton();
3076b13307fSandi      break;
3086b13307fSandi    case 'history':
3095bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
3106b13307fSandi      break;
3116b13307fSandi    case 'recent':
3125bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
3136b13307fSandi      break;
3146b13307fSandi    case 'index':
3155bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
3166b13307fSandi      break;
317a3ec5f4aSmatthiasgrimm    case 'back':
3186222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
3196222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
320a3ec5f4aSmatthiasgrimm      }
321a3ec5f4aSmatthiasgrimm      break;
3226b13307fSandi    case 'top':
3236b13307fSandi      print html_topbtn();
3246b13307fSandi      break;
3256b13307fSandi    case 'login':
3266b13307fSandi      if($conf['useacl']){
3276b13307fSandi        if($_SERVER['REMOTE_USER']){
3286b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
3296b13307fSandi        }else{
3306b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
3316b13307fSandi        }
3326b13307fSandi      }
3336b13307fSandi      break;
334c19fe9c0Sandi    case 'admin':
335c19fe9c0Sandi      if($INFO['perm'] == AUTH_ADMIN)
3365bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
337c19fe9c0Sandi      break;
338d67ca2c0Smatthiasgrimm    case 'backtomedia':
339d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
340d67ca2c0Smatthiasgrimm      break;
3411380fc45SAndreas Gohr    case 'subscription':
342f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
343b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
3441380fc45SAndreas Gohr          if($INFO['subscribed']){
3451380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
346b158d625SSteven Danz          } else {
3471380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
348b158d625SSteven Danz          }
349b158d625SSteven Danz        }
350b158d625SSteven Danz      }
351b158d625SSteven Danz      break;
352f00151b4Schris    case 'backlink':
353f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
354f00151b4Schris      break;
3558b06d178Schris    case 'profile':
3568b06d178Schris      if(($_SERVER['REMOTE_USER']) && auth_canDo('modifyUser') && ($ACT!='profile')){
3578b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
3588b06d178Schris      }
3598b06d178Schris      break;
360c19fe9c0Sandi    default:
361c19fe9c0Sandi      print '[unknown button type]';
3626b13307fSandi  }
3636b13307fSandi}
3646b13307fSandi
3656b13307fSandi/**
366ed630903Sandi * Like the action buttons but links
367ed630903Sandi *
368ed630903Sandi * Available links are
369ed630903Sandi *
370ed630903Sandi *  edit    - edit/create/show button
371ed630903Sandi *  history - old revisions
372ed630903Sandi *  recent  - recent changes
373ed630903Sandi *  login   - login/logout button - if ACL enabled
374ed630903Sandi *  index   - The index
375ed630903Sandi *  admin   - admin page - if enough rights
376ed630903Sandi *  top     - a back to top button
377a3ec5f4aSmatthiasgrimm *  back    - a back to parent button - if available
378bbd37938SAndreas Gohr * backlink - links to the list of backlinks
379ed630903Sandi *
380ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
381a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
382ed630903Sandi * @see    tpl_button
383ed630903Sandi */
384ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
385ed630903Sandi  global $ID;
386ed630903Sandi  global $INFO;
387ed630903Sandi  global $REV;
388ed630903Sandi  global $ACT;
389ed630903Sandi  global $conf;
390ed630903Sandi  global $lang;
391ed630903Sandi
392ed630903Sandi  switch($type){
393ed630903Sandi    case 'edit':
394ed630903Sandi      #most complicated type - we need to decide on current action
395ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
396ed630903Sandi        if($INFO['writable']){
397ed630903Sandi          if($INFO['exists']){
398ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
399ed630903Sandi                     $pre.$lang['btn_edit'].$suf,
400b7af031cSsu                     'class="action edit" accesskey="e" rel="nofollow"');
401ed630903Sandi          }else{
402ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
403ed630903Sandi                     $pre.$lang['btn_create'].$suf,
404b7af031cSsu                     'class="action create" accesskey="e" rel="nofollow"');
405ed630903Sandi          }
406ed630903Sandi        }else{
407ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
408ed630903Sandi                   $pre.$lang['btn_source'].$suf,
409b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
410ed630903Sandi        }
411ed630903Sandi      }else{
412ed630903Sandi          tpl_link(wl($ID,'do=show'),
413ed630903Sandi                   $pre.$lang['btn_show'].$suf,
414b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
415ed630903Sandi      }
416ed630903Sandi      break;
417ed630903Sandi    case 'history':
418b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
419ed630903Sandi      break;
420ed630903Sandi    case 'recent':
421b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
422ed630903Sandi      break;
423ed630903Sandi    case 'index':
424b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
425ed630903Sandi      break;
426ed630903Sandi    case 'top':
427b7af031cSsu      print '<a href="#top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
428ed630903Sandi      break;
429a3ec5f4aSmatthiasgrimm    case 'back':
430a3ec5f4aSmatthiasgrimm      if ($ID = tpl_getparent($ID)) {
431b7af031cSsu        tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
432a3ec5f4aSmatthiasgrimm      }
433a3ec5f4aSmatthiasgrimm      break;
434ed630903Sandi    case 'login':
435ed630903Sandi      if($conf['useacl']){
436ed630903Sandi        if($_SERVER['REMOTE_USER']){
437b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
438ed630903Sandi        }else{
439b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
440ed630903Sandi        }
441ed630903Sandi      }
442ed630903Sandi      break;
443ed630903Sandi    case 'admin':
444ed630903Sandi      if($INFO['perm'] == AUTH_ADMIN)
445b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
446ed630903Sandi      break;
447f9eb5648Ssteven-danz   case 'subscribe':
448075f000fSChristopher Arndt   case 'subscription':
449f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
450b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
451075f000fSChristopher Arndt          if($INFO['subscribed']) {
452b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
453b158d625SSteven Danz          } else {
454b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
455b158d625SSteven Danz          }
456b158d625SSteven Danz        }
457b158d625SSteven Danz      }
458b158d625SSteven Danz      break;
459f00151b4Schris    case 'backlink':
460b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
461f00151b4Schris      break;
4628b06d178Schris    case 'profile':
4638b06d178Schris      if(($_SERVER['REMOTE_USER']) && auth_canDo('modifyUser') && ($ACT!='profile')){
4648b06d178Schris        tpl_link(wl($ID,'do=profile'),$pre.$lang['btn_profile'].$suf, 'class="action profile"');
4658b06d178Schris      }
4668b06d178Schris      break;
467ed630903Sandi    default:
468ed630903Sandi      print '[unknown link type]';
469ed630903Sandi  }
470ed630903Sandi}
471ed630903Sandi
472ed630903Sandi/**
4736b13307fSandi * Print the search form
4746b13307fSandi *
47572645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
47672645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
47772645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
47872645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
47972645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
48072645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
48172645b75SAndreas Gohr *
4826b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4836b13307fSandi */
48472645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
4856b13307fSandi  global $lang;
486c1e3b7d9Smatthiasgrimm  global $ACT;
487c1e3b7d9Smatthiasgrimm
4885e163278SAndreas Gohr  print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search">';
4896b13307fSandi  print '<input type="hidden" name="do" value="search" />';
490c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
491bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
49272645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
493bad31ae9SAndreas Gohr  print 'id="qsearch_in" accesskey="f" name="id" class="edit" />';
4946b13307fSandi  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
49572645b75SAndreas Gohr  if($ajax) print '<div id="qsearch_out" class="ajax_qsearch JSpopup"></div>';
4966b13307fSandi  print '</form>';
4976b13307fSandi}
4986b13307fSandi
4996b13307fSandi/**
5006b13307fSandi * Print the breadcrumbs trace
5016b13307fSandi *
5026b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5036b13307fSandi */
5046b13307fSandifunction tpl_breadcrumbs(){
5056b13307fSandi  global $lang;
5066b13307fSandi  global $conf;
5076b13307fSandi
5086b13307fSandi  //check if enabled
5096b13307fSandi  if(!$conf['breadcrumbs']) return;
5106b13307fSandi
5116b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
512265e3787Sandi
513265e3787Sandi  //reverse crumborder in right-to-left mode
514265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
515265e3787Sandi
51640eb54bbSjan  //render crumbs, highlight the last one
5176b13307fSandi  print $lang['breadcrumb'].':';
51840eb54bbSjan  $last = count($crumbs);
51940eb54bbSjan  $i = 0;
520a77f5846Sjan  foreach ($crumbs as $id => $name){
52140eb54bbSjan    $i++;
522265e3787Sandi    print ' <span class="bcsep">&raquo;</span> ';
52392795d04Sandi    if ($i == $last) print '<span class="curid">';
524a77f5846Sjan    tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"');
52592795d04Sandi    if ($i == $last) print '</span>';
5266b13307fSandi  }
5276b13307fSandi}
5286b13307fSandi
5296b13307fSandi/**
5301734437eSandi * Hierarchical breadcrumbs
5311734437eSandi *
5321734437eSandi * This code was suggested as replacement for the usual breadcrumbs
5331734437eSandi * trail in the Wiki and was modified by me.
5341734437eSandi * It only makes sense with a deep site structure.
5351734437eSandi *
5361734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
5376bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
5381734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
5396bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
5401734437eSandi */
5411734437eSandifunction tpl_youarehere(){
5421734437eSandi  global $conf;
5431734437eSandi  global $ID;
5441734437eSandi  global $lang;
5451734437eSandi
5461734437eSandi
5471734437eSandi  $parts     = explode(':', $ID);
5481734437eSandi
5496bd812dfSNigel McNie  // Perhaps a $lang['tree'] could be defined? "Trace" isn't too appropriate
5506bd812dfSNigel McNie  //print $lang['tree'].': ';
5511734437eSandi  print $lang['breadcrumb'].': ';
5521734437eSandi
5531734437eSandi  //always print the startpage
5541734437eSandi  if( $a_part[0] != $conf['start'] )
5551734437eSandi    tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"');
5561734437eSandi
5571734437eSandi  $page = '';
5581734437eSandi  foreach ($parts as $part){
5596bd812dfSNigel McNie        // Skip startpage if already done
5606bd812dfSNigel McNie        if ($part == $conf['start']) continue;
5616bd812dfSNigel McNie
5621734437eSandi          print ' &raquo; ';
5631734437eSandi    $page .= $part;
5641734437eSandi
5651734437eSandi    if(file_exists(wikiFN($page))){
5661734437eSandi      tpl_link(wl($page),$part,'title="'.$page.'"');
5671734437eSandi    }else{
5686bd812dfSNigel McNie      // Print the link, but mark as not-existing, as for other non-existing links
5696bd812dfSNigel McNie      tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"');
5706bd812dfSNigel McNie      //print $page;
5711734437eSandi    }
5721734437eSandi
5731734437eSandi    $page .= ':';
5741734437eSandi  }
5751734437eSandi}
5761734437eSandi
5771734437eSandi/**
5786b13307fSandi * Print info if the user is logged in
579a2488c3cSMatthias Grimm * and show full name in that case
5806b13307fSandi *
5816b13307fSandi * Could be enhanced with a profile link in future?
5826b13307fSandi *
5836b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5846b13307fSandi */
5856b13307fSandifunction tpl_userinfo(){
5866b13307fSandi  global $lang;
587a2488c3cSMatthias Grimm  global $INFO;
5886b13307fSandi  if($_SERVER['REMOTE_USER'])
589a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
5906b13307fSandi}
5916b13307fSandi
5926b13307fSandi/**
5936b13307fSandi * Print some info about the current page
5946b13307fSandi *
5956b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5966b13307fSandi */
5976b13307fSandifunction tpl_pageinfo(){
5986b13307fSandi  global $conf;
5996b13307fSandi  global $lang;
6006b13307fSandi  global $INFO;
6016b13307fSandi  global $REV;
6026b13307fSandi
6036b13307fSandi  // prepare date and path
6046b13307fSandi  $fn = $INFO['filepath'];
6056b13307fSandi  if(!$conf['fullpath']){
6066b13307fSandi    if($REV){
6076b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
6086b13307fSandi    }else{
6096b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
6106b13307fSandi    }
6116b13307fSandi  }
612bee6dc82Sandi  $fn = utf8_decodeFN($fn);
6136b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
6146b13307fSandi
6156b13307fSandi  // print it
6166b13307fSandi  if($INFO['exists']){
6176b13307fSandi    print $fn;
6186b13307fSandi    print ' &middot; ';
6196b13307fSandi    print $lang['lastmod'];
6206b13307fSandi    print ': ';
6216b13307fSandi    print $date;
6226b13307fSandi    if($INFO['editor']){
6236b13307fSandi      print ' '.$lang['by'].' ';
6246b13307fSandi      print $INFO['editor'];
6256b13307fSandi    }
6266b13307fSandi    if($INFO['locked']){
6276b13307fSandi      print ' &middot; ';
6286b13307fSandi      print $lang['lockedby'];
6296b13307fSandi      print ': ';
6306b13307fSandi      print $INFO['locked'];
6316b13307fSandi    }
6326b13307fSandi  }
6336b13307fSandi}
6346b13307fSandi
635820fa24bSandi/**
636820fa24bSandi * Print a list of namespaces containing media files
637820fa24bSandi *
638820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
639820fa24bSandi */
640820fa24bSandifunction tpl_medianamespaces(){
641820fa24bSandi    global $conf;
642820fa24bSandi
643820fa24bSandi  $data = array();
644820fa24bSandi  search($data,$conf['mediadir'],'search_namespaces',array());
645820fa24bSandi  print html_buildlist($data,'idx',media_html_list_namespaces);
646820fa24bSandi}
647820fa24bSandi
648820fa24bSandi/**
649820fa24bSandi * Print a list of mediafiles in the current namespace
650820fa24bSandi *
651820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
652820fa24bSandi */
653820fa24bSandifunction tpl_mediafilelist(){
654820fa24bSandi  global $conf;
655820fa24bSandi  global $lang;
656820fa24bSandi  global $NS;
6578ef6b7caSandi  global $AUTH;
658820fa24bSandi  $dir = utf8_encodeFN(str_replace(':','/',$NS));
659820fa24bSandi
660820fa24bSandi  $data = array();
661820fa24bSandi  search($data,$conf['mediadir'],'search_media',array(),$dir);
662820fa24bSandi
663820fa24bSandi  if(!count($data)){
6644b15e09dSAndreas Gohr    ptln('<div class="nothing">'.$lang['nothingfound'].'</div>');
665820fa24bSandi    return;
666820fa24bSandi  }
667820fa24bSandi
668820fa24bSandi  ptln('<ul>',2);
669820fa24bSandi  foreach($data as $item){
670*806d77a0SAndreas Gohr    if(!$item['isimg']){
671*806d77a0SAndreas Gohr      // add file icons
672*806d77a0SAndreas Gohr      list($ext,$mime) = mimetype($item['file']);
673*806d77a0SAndreas Gohr      $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
674*806d77a0SAndreas Gohr      $class .= ' class="mediafile mf_'.$class.'"';
675*806d77a0SAndreas Gohr    }
676*806d77a0SAndreas Gohr
677820fa24bSandi    ptln('<li>',4);
678*806d77a0SAndreas Gohr    ptln('<a href="javascript:mediaSelect(\':'.$item['id'].'\')"'.$class.'>'.
679820fa24bSandi         utf8_decodeFN($item['file']).
680820fa24bSandi         '</a>',6);
6818ef6b7caSandi
6828ef6b7caSandi    //prepare deletion button
6838ef6b7caSandi    if($AUTH >= AUTH_DELETE){
6848ef6b7caSandi      $ask  = $lang['del_confirm'].'\\n';
6858ef6b7caSandi      $ask .= $item['id'];
6868ef6b7caSandi
687f62ea8a1Sandi      $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '.
6888ef6b7caSandi             'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'.
689f62ea8a1Sandi             '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '.
6908ef6b7caSandi             'align="bottom" title="'.$lang['btn_delete'].'" /></a>';
6918ef6b7caSandi    }else{
6928ef6b7caSandi      $del = '';
6938ef6b7caSandi    }
6948ef6b7caSandi
695820fa24bSandi    if($item['isimg']){
69623a34783SAndreas Gohr      $w = $item['meta']->getField('File.Width');
69723a34783SAndreas Gohr      $h = $item['meta']->getField('File.Height');
698820fa24bSandi
6998ef6b7caSandi      ptln('('.$w.'&#215;'.$h.' '.filesize_h($item['size']).')',6);
7008ef6b7caSandi      ptln($del.'<br />',6);
701478cd997SAndreas Gohr      ptln('<div class="imagemeta">',6);
7029fcd3d1dSandi
70323a34783SAndreas Gohr      //build thumbnail
70423a34783SAndreas Gohr      print '<a href="javascript:mediaSelect(\''.$item['id'].'\')">';
70523a34783SAndreas Gohr
70623a34783SAndreas Gohr      if($w>120 || $h>120){
70723a34783SAndreas Gohr        $ratio = $item['meta']->getResizeRatio(120);
70823a34783SAndreas Gohr        $w = floor($w * $ratio);
70923a34783SAndreas Gohr        $h = floor($h * $ratio);
7109fcd3d1dSandi      }
71123a34783SAndreas Gohr
7126de3759aSAndreas Gohr      $src = ml($item['id'],array('w'=>$w,'h'=>$h));
71323a34783SAndreas Gohr
71423a34783SAndreas Gohr      $p = array();
71523a34783SAndreas Gohr      $p['width']  = $w;
71623a34783SAndreas Gohr      $p['height'] = $h;
71723a34783SAndreas Gohr      $p['alt']    = $item['id'];
71823a34783SAndreas Gohr      $p['class']  = 'thumb';
71923a34783SAndreas Gohr      $att = buildAttributes($p);
72023a34783SAndreas Gohr
72123a34783SAndreas Gohr      print '<img src="'.$src.'" '.$att.' />';
7229fcd3d1dSandi      print '</a>';
723820fa24bSandi
7246d861d12SAndreas Gohr      //read EXIF/IPTC data
72523a34783SAndreas Gohr      $t = $item['meta']->getField('IPTC.Headline');
7266d861d12SAndreas Gohr      if($t) print '<b>'.$t.'</b><br />';
7276d861d12SAndreas Gohr
72836df6fa3SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
72936df6fa3SAndreas Gohr                                         'EXIF.TIFFImageDescription',
73036df6fa3SAndreas Gohr                                         'EXIF.TIFFUserComment'));
7316d861d12SAndreas Gohr      if($t) print $t.'<br />';
7326d861d12SAndreas Gohr
73323a34783SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category'));
7346d861d12SAndreas Gohr      if($t) print '<i>'.$t.'</i><br />';
7356d861d12SAndreas Gohr
73636df6fa3SAndreas Gohr      //add edit button
73736df6fa3SAndreas Gohr      if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){
73836df6fa3SAndreas Gohr        print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.urlencode($item['id']).'">';
73936df6fa3SAndreas Gohr        print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />';
74036df6fa3SAndreas Gohr        print '</a>';
74136df6fa3SAndreas Gohr      }
74236df6fa3SAndreas Gohr
7436d861d12SAndreas Gohr      ptln('</div>',6);
744820fa24bSandi    }else{
745820fa24bSandi      ptln ('('.filesize_h($item['size']).')',6);
7468ef6b7caSandi      ptln($del,6);
747820fa24bSandi    }
748820fa24bSandi    ptln('</li>',4);
749820fa24bSandi  }
750820fa24bSandi  ptln('</ul>',2);
751820fa24bSandi}
752820fa24bSandi
753820fa24bSandi/**
754d67ca2c0Smatthiasgrimm * show references to a media file
755d67ca2c0Smatthiasgrimm * References uses the same visual as search results and share
756d67ca2c0Smatthiasgrimm * their CSS tags except pagenames won't be links.
757d67ca2c0Smatthiasgrimm *
758d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
759d67ca2c0Smatthiasgrimm */
760d67ca2c0Smatthiasgrimmfunction tpl_showreferences(&$data){
761d67ca2c0Smatthiasgrimm  global $lang;
762d67ca2c0Smatthiasgrimm
763d67ca2c0Smatthiasgrimm  $hidden=0; //count of hits without read permission
764d67ca2c0Smatthiasgrimm
765d67ca2c0Smatthiasgrimm  if(count($data)){
766d67ca2c0Smatthiasgrimm    usort($data,'sort_search_fulltext');
767d67ca2c0Smatthiasgrimm    foreach($data as $row){
768d67ca2c0Smatthiasgrimm      if(auth_quickaclcheck($row['id']) >= AUTH_READ){
769d67ca2c0Smatthiasgrimm        print '<div class="search_result">';
770d67ca2c0Smatthiasgrimm        print '<span class="mediaref_ref">'.$row['id'].'</span>';
771d67ca2c0Smatthiasgrimm        print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
772d67ca2c0Smatthiasgrimm        print '<div class="search_snippet">'.$row['snippet'].'</div>';
773d67ca2c0Smatthiasgrimm        print '</div>';
774d67ca2c0Smatthiasgrimm      }else
775d67ca2c0Smatthiasgrimm        $hidden++;
776d67ca2c0Smatthiasgrimm    }
777d67ca2c0Smatthiasgrimm    if ($hidden){
778d67ca2c0Smatthiasgrimm      print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
779d67ca2c0Smatthiasgrimm    }
780d67ca2c0Smatthiasgrimm  }
781d67ca2c0Smatthiasgrimm}
782d67ca2c0Smatthiasgrimm
783d67ca2c0Smatthiasgrimm/**
784820fa24bSandi * Print the media upload form if permissions are correct
785820fa24bSandi *
786820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
787820fa24bSandi */
788820fa24bSandifunction tpl_mediauploadform(){
789820fa24bSandi  global $NS;
790820fa24bSandi  global $UPLOADOK;
7918ef6b7caSandi  global $AUTH;
792820fa24bSandi  global $lang;
793820fa24bSandi
794820fa24bSandi  if(!$UPLOADOK) return;
795820fa24bSandi
7968dd5e97bSandi  ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" name="upload"'.
797820fa24bSandi       ' method="post" enctype="multipart/form-data">',2);
798820fa24bSandi  ptln($lang['txt_upload'].':<br />',4);
799820fa24bSandi  ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4);
800820fa24bSandi  ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4);
801820fa24bSandi  ptln($lang['txt_filename'].'<br />',4);
802820fa24bSandi  ptln('<input type="text" name="id" class="edit" />',4);
803820fa24bSandi  ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4);
8048ef6b7caSandi  if($AUTH >= AUTH_DELETE){
805b6912aeaSAndreas Gohr    ptln('<label for="ow"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4);
8068ef6b7caSandi  }
807820fa24bSandi  ptln('</form>',2);
808820fa24bSandi}
809820fa24bSandi
81087c434ceSAndreas Gohr/**
81187c434ceSAndreas Gohr * Prints the name of the given page (current one if none given).
81287c434ceSAndreas Gohr *
81387c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
81487c434ceSAndreas Gohr * the given ID is printed.
81587c434ceSAndreas Gohr *
81687c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
81787c434ceSAndreas Gohr */
81887c434ceSAndreas Gohrfunction tpl_pagetitle($id=null){
81987c434ceSAndreas Gohr  global $conf;
82087c434ceSAndreas Gohr  if(is_null($id)){
82187c434ceSAndreas Gohr    global $ID;
82287c434ceSAndreas Gohr    $id = $ID;
82387c434ceSAndreas Gohr  }
82487c434ceSAndreas Gohr
82587c434ceSAndreas Gohr  $name = $id;
82687c434ceSAndreas Gohr  if ($conf['useheading']) {
82787c434ceSAndreas Gohr    $title = p_get_first_heading($id);
82887c434ceSAndreas Gohr    if ($title) $name = $title;
82987c434ceSAndreas Gohr  }
83087c434ceSAndreas Gohr  print hsc($name);
83187c434ceSAndreas Gohr}
832340756e4Sandi
83355efc227SAndreas Gohr/**
83455efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
83555efc227SAndreas Gohr *
83655efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
83755efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
83855efc227SAndreas Gohr *
83955efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
84055efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
84155efc227SAndreas Gohr * to the names of the latter one)
84255efc227SAndreas Gohr *
84336df6fa3SAndreas Gohr * Only allowed in: detail.php, mediaedit.php
84455efc227SAndreas Gohr *
84555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
84655efc227SAndreas Gohr */
84755efc227SAndreas Gohrfunction tpl_img_getTag($tags,$alt=''){
84855efc227SAndreas Gohr  // Init Exif Reader
84955efc227SAndreas Gohr  global $SRC;
85055efc227SAndreas Gohr  static $meta = null;
85155efc227SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($SRC);
85255efc227SAndreas Gohr  if($meta === false) return $alt;
85355efc227SAndreas Gohr  $info = $meta->getField($tags);
85455efc227SAndreas Gohr  if($info == false) return $alt;
85555efc227SAndreas Gohr  return $info;
85655efc227SAndreas Gohr}
85755efc227SAndreas Gohr
85855efc227SAndreas Gohr/**
85955efc227SAndreas Gohr * Prints the image with a link to the full sized version
86055efc227SAndreas Gohr *
86155efc227SAndreas Gohr * Only allowed in: detail.php
86255efc227SAndreas Gohr */
863f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
86455efc227SAndreas Gohr  global $IMG;
86555efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
86655efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
86755efc227SAndreas Gohr
86855efc227SAndreas Gohr  //resize to given max values
86923a34783SAndreas Gohr  $ratio = 1;
87023a34783SAndreas Gohr  if($w >= $h){
871f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
87255efc227SAndreas Gohr      $ratio = $maxwidth/$w;
873f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
87455efc227SAndreas Gohr      $ratio = $maxheight/$h;
87555efc227SAndreas Gohr    }
87655efc227SAndreas Gohr  }else{
877f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
87855efc227SAndreas Gohr      $ratio = $maxheight/$h;
879f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
88055efc227SAndreas Gohr      $ratio = $maxwidth/$w;
88155efc227SAndreas Gohr    }
88255efc227SAndreas Gohr  }
88355efc227SAndreas Gohr  if($ratio){
88455efc227SAndreas Gohr    $w = floor($ratio*$w);
88555efc227SAndreas Gohr    $h = floor($ratio*$h);
88655efc227SAndreas Gohr  }
88755efc227SAndreas Gohr
8886de3759aSAndreas Gohr  //prepare URLs
8896de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
8906de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
89155efc227SAndreas Gohr
8922684e50aSAndreas Gohr  //prepare attributes
89355efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
8942684e50aSAndreas Gohr  $p = array();
8952684e50aSAndreas Gohr  if($w) $p['width']  = $w;
8962684e50aSAndreas Gohr  if($h) $p['height'] = $h;
8972684e50aSAndreas Gohr         $p['class']  = 'img_detail';
8982684e50aSAndreas Gohr  if($alt){
8992684e50aSAndreas Gohr    $p['alt']   = $alt;
9002684e50aSAndreas Gohr    $p['title'] = $alt;
9012684e50aSAndreas Gohr  }else{
9022684e50aSAndreas Gohr    $p['alt'] = '';
9032684e50aSAndreas Gohr  }
9042684e50aSAndreas Gohr  $p = buildAttributes($p);
90555efc227SAndreas Gohr
90655efc227SAndreas Gohr  print '<a href="'.$url.'">';
9076de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
90855efc227SAndreas Gohr  print '</a>';
90955efc227SAndreas Gohr}
91055efc227SAndreas Gohr
9117367b368SAndreas Gohr/**
9127367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9137367b368SAndreas Gohr * is the inexer function.
9147367b368SAndreas Gohr *
9157367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9167367b368SAndreas Gohr * template
9177367b368SAndreas Gohr */
9187367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9197367b368SAndreas Gohr  global $ID;
9201dad36f5SAndreas Gohr  global $INFO;
9211dad36f5SAndreas Gohr  if(!$INFO['exists']) return;
9221dad36f5SAndreas Gohr
9230dc92c6fSAndreas Gohr  if(isHiddenPage($ID)) return; //no need to index hidden pages
9240dc92c6fSAndreas Gohr
9257367b368SAndreas Gohr  $p = array();
926e68c51baSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.urlencode($ID).
927e68c51baSAndreas Gohr                 '&'.time();
9287367b368SAndreas Gohr  $p['width']  = 1;
9297367b368SAndreas Gohr  $p['height'] = 1;
9307367b368SAndreas Gohr  $p['alt']    = '';
9317367b368SAndreas Gohr  $att = buildAttributes($p);
9327367b368SAndreas Gohr  print "<img $att />";
9337367b368SAndreas Gohr}
9347367b368SAndreas Gohr
935340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
936