xref: /dokuwiki/inc/template.php (revision f5c2808ff13d9b9dce9a6e2f2ea3989ef686c15c)
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
145a892029SAndreas Gohr * default one if the custom version doesn't exist
155a892029SAndreas Gohr *
165a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
175a892029SAndreas Gohr */
185a892029SAndreas Gohrfunction template($tpl){
195a892029SAndreas Gohr  global $conf;
205a892029SAndreas Gohr
215a892029SAndreas Gohr  if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
225a892029SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
235a892029SAndreas Gohr
245a892029SAndreas Gohr  return DOKU_INC.'lib/tpl/default/'.$tpl;
255a892029SAndreas Gohr}
265a892029SAndreas Gohr
275a892029SAndreas Gohr/**
286b13307fSandi * Print the content
296b13307fSandi *
306b13307fSandi * This function is used for printing all the usual content
316b13307fSandi * (defined by the global $ACT var) by calling the appropriate
326b13307fSandi * outputfunction(s) from html.php
336b13307fSandi *
34ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
35ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
366b13307fSandi *
376b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
386b13307fSandi */
396b13307fSandifunction tpl_content(){
406b13307fSandi  global $ACT;
416b13307fSandi  global $TEXT;
426b13307fSandi  global $PRE;
436b13307fSandi  global $SUF;
446b13307fSandi  global $SUM;
456b13307fSandi  global $IDX;
466b13307fSandi
476b13307fSandi  switch($ACT){
486b13307fSandi    case 'show':
496b13307fSandi      html_show();
506b13307fSandi      break;
51ea67f144Sandi    case 'preview':
526b13307fSandi      html_edit($TEXT);
536b13307fSandi      html_show($TEXT);
546b13307fSandi      break;
55ee4c4a1bSAndreas Gohr    case 'recover':
56ee4c4a1bSAndreas Gohr      html_edit($TEXT);
57ee4c4a1bSAndreas Gohr      break;
586b13307fSandi    case 'edit':
596b13307fSandi      html_edit();
606b13307fSandi      break;
61ee4c4a1bSAndreas Gohr    case 'draft':
62ee4c4a1bSAndreas Gohr      html_draft();
63ee4c4a1bSAndreas Gohr      break;
646b13307fSandi    case 'wordblock':
656b13307fSandi      html_edit($TEXT,'wordblock');
666b13307fSandi      break;
676b13307fSandi    case 'search':
686b13307fSandi      html_search();
696b13307fSandi      break;
706b13307fSandi    case 'revisions':
716b13307fSandi      html_revisions();
726b13307fSandi      break;
736b13307fSandi    case 'diff':
746b13307fSandi      html_diff();
756b13307fSandi      break;
766b13307fSandi    case 'recent':
775749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
78a39955b0Smatthiasgrimm      html_recent($first);
796b13307fSandi      break;
806b13307fSandi    case 'index':
816b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
826b13307fSandi      break;
836b13307fSandi    case 'backlink':
846b13307fSandi      html_backlinks();
856b13307fSandi      break;
866b13307fSandi    case 'conflict':
876b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
886b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
896b13307fSandi      break;
906b13307fSandi    case 'locked':
91ee20e7d1Sandi      html_locked();
926b13307fSandi      break;
936b13307fSandi    case 'login':
946b13307fSandi      html_login();
956b13307fSandi      break;
966b13307fSandi    case 'register':
976b13307fSandi      html_register();
986b13307fSandi      break;
998b06d178Schris    case 'resendpwd':
1008b06d178Schris      html_resendpwd();
1018b06d178Schris      break;
102820fa24bSandi    case 'denied':
1035e991bd8Sandi      print p_locale_xhtml('denied');
104820fa24bSandi      break;
1058b06d178Schris    case 'profile' :
1068b06d178Schris      html_updateprofile();
1078b06d178Schris      break;
108c19fe9c0Sandi    case 'admin':
109c19fe9c0Sandi      tpl_admin();
110c19fe9c0Sandi      break;
1116b13307fSandi    default:
112ea67f144Sandi            msg("Failed to handle command: ".hsc($ACT),-1);
1136b13307fSandi  }
1146b13307fSandi}
1156b13307fSandi
116c19fe9c0Sandi/**
117c19fe9c0Sandi * Handle the admin page contents
118c19fe9c0Sandi *
119c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
120c19fe9c0Sandi */
121c19fe9c0Sandifunction tpl_admin(){
12211e2ce22Schris
12311e2ce22Schris    $plugin = NULL;
12411e2ce22Schris    if ($_REQUEST['page']) {
12511e2ce22Schris        $pluginlist = plugin_list('admin');
12611e2ce22Schris
12711e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
12811e2ce22Schris
12911e2ce22Schris          // attempt to load the plugin
13011e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
13111e2ce22Schris        }
13211e2ce22Schris    }
13311e2ce22Schris
13411e2ce22Schris    if ($plugin !== NULL)
13511e2ce22Schris        $plugin->html();
13611e2ce22Schris    else
13711e2ce22Schris        html_admin();
138c19fe9c0Sandi}
1396b13307fSandi
1406b13307fSandi/**
1416b13307fSandi * Print the correct HTML meta headers
1426b13307fSandi *
1436b13307fSandi * This has to go into the head section of your template.
1446b13307fSandi *
145f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
1466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1476b13307fSandi */
148f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
1496b13307fSandi  global $ID;
1506b13307fSandi  global $INFO;
1516b13307fSandi  global $ACT;
1526b13307fSandi  global $lang;
153dc57ef04Sandi  global $conf;
1546b13307fSandi  $it=2;
1556b13307fSandi
1566b13307fSandi  // the usual stuff
1576b13307fSandi  ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it);
1586b13307fSandi  ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it);
1596b13307fSandi  ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it);
160f96fa415SAndreas Gohr
161f96fa415SAndreas Gohr  if($alt){
1626b13307fSandi    ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it);
1636b13307fSandi    ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&amp;ns='.$INFO['namespace'].'" />',$it);
164*f5c2808fSBen Coburn    ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.exportlink($ID, 'xhtml').'" />',$it);
165*f5c2808fSBen Coburn    ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.exportlink($ID, 'raw').'" />',$it);
166f96fa415SAndreas Gohr  }
1676b13307fSandi
1686b13307fSandi  // setup robot tags apropriate for different modes
1694f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
1706b13307fSandi    if($INFO['exists']){
1716b13307fSandi      ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it);
1726b13307fSandi      //delay indexing:
1736b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
1746b13307fSandi        ptln('<meta name="robots" content="index,follow" />',$it);
1756b13307fSandi      }else{
1766b13307fSandi        ptln('<meta name="robots" content="noindex,nofollow" />',$it);
1776b13307fSandi      }
1786b13307fSandi    }else{
1796b13307fSandi      ptln('<meta name="robots" content="noindex,follow" />',$it);
1806b13307fSandi    }
1816b13307fSandi  }else{
1826b13307fSandi    ptln('<meta name="robots" content="noindex,nofollow" />',$it);
1836b13307fSandi  }
1846b13307fSandi
18578a6aeb1SAndreas Gohr  // load stylesheets
18678a6aeb1SAndreas Gohr  ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php" />',$it);
18778a6aeb1SAndreas Gohr  ptln('<link rel="stylesheet" media="print" type="text/css" href="'.DOKU_BASE.'lib/exe/css.php?print=1" />',$it);
188bad31ae9SAndreas Gohr
18978a6aeb1SAndreas Gohr  // load javascript
190ee4c4a1bSAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover') ? 1 : 0;
191bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
192c591aabeSAndreas Gohr  if($js_edit && $js_write){
1934beabca9SAnika Henke    ptln('<script type="text/javascript" charset="utf-8">',$it);
194c591aabeSAndreas Gohr    ptln("NS='".$INFO['namespace']."';",$it+2);
195c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
196aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
197c591aabeSAndreas Gohr      ptln("SIG='".toolbar_signature()."';",$it+2);
198c591aabeSAndreas Gohr    }
199c591aabeSAndreas Gohr    ptln('</script>',$it);
200c591aabeSAndreas Gohr  }
2014beabca9SAnika Henke  ptln('<script type="text/javascript" charset="utf-8" src="'.
202c591aabeSAndreas Gohr       DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&amp;write='.$js_write.'"></script>',$it);
2036b13307fSandi}
2046b13307fSandi
2056b13307fSandi/**
2066b13307fSandi * Print a link
2076b13307fSandi *
2085e163278SAndreas Gohr * Just builds a link.
2096b13307fSandi *
2106b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2116b13307fSandi */
2126b13307fSandifunction tpl_link($url,$name,$more=''){
2135e163278SAndreas Gohr  print '<a href="'.$url.'" ';
2146b13307fSandi  if ($more) print ' '.$more;
2156b13307fSandi  print ">$name</a>";
2166b13307fSandi}
2176b13307fSandi
2186b13307fSandi/**
21955efc227SAndreas Gohr * Prints a link to a WikiPage
22055efc227SAndreas Gohr *
22155efc227SAndreas Gohr * Wrapper around html_wikilink
22255efc227SAndreas Gohr *
22355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
22455efc227SAndreas Gohr */
22555efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
22655efc227SAndreas Gohr  print html_wikilink($id,$name);
22755efc227SAndreas Gohr}
22855efc227SAndreas Gohr
22955efc227SAndreas Gohr/**
230a3ec5f4aSmatthiasgrimm * get the parent page
231a3ec5f4aSmatthiasgrimm *
232a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
233a3ec5f4aSmatthiasgrimm * returns false if none is available
234a3ec5f4aSmatthiasgrimm *
235a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
236a3ec5f4aSmatthiasgrimm */
237a3ec5f4aSmatthiasgrimmfunction tpl_getparent($ID){
238a3ec5f4aSmatthiasgrimm  global $conf;
239a3ec5f4aSmatthiasgrimm
240a3ec5f4aSmatthiasgrimm  if ($ID != $conf['start']) {
241a3ec5f4aSmatthiasgrimm    $idparts = explode(':', $ID);
242a3ec5f4aSmatthiasgrimm    $pn = array_pop($idparts);    // get the page name
243a3ec5f4aSmatthiasgrimm
244a3ec5f4aSmatthiasgrimm    for ($n=0; $n < 2; $n++) {
245a3ec5f4aSmatthiasgrimm      if (count($idparts) == 0) {
246a3ec5f4aSmatthiasgrimm        $ID = $conf['start'];     // go to topmost page
247a3ec5f4aSmatthiasgrimm        break;
248a3ec5f4aSmatthiasgrimm      }else{
249a3ec5f4aSmatthiasgrimm        $ns = array_pop($idparts);     // get the last part of namespace
250a3ec5f4aSmatthiasgrimm        if ($pn != $ns) {                 // are we already home?
251a3ec5f4aSmatthiasgrimm          array_push($idparts, $ns, $ns); // no, then add a page with same name
252a3ec5f4aSmatthiasgrimm          $ID = implode (':', $idparts); // as the namespace and recombine $ID
253a3ec5f4aSmatthiasgrimm          break;
254a3ec5f4aSmatthiasgrimm        }
255a3ec5f4aSmatthiasgrimm      }
256a3ec5f4aSmatthiasgrimm    }
257a3ec5f4aSmatthiasgrimm
258a3ec5f4aSmatthiasgrimm    if (@file_exists(wikiFN($ID))) {
259a3ec5f4aSmatthiasgrimm      return $ID;
260a3ec5f4aSmatthiasgrimm    }
261a3ec5f4aSmatthiasgrimm  }
262a3ec5f4aSmatthiasgrimm  return false;
263a3ec5f4aSmatthiasgrimm}
264a3ec5f4aSmatthiasgrimm
265a3ec5f4aSmatthiasgrimm/**
2666b13307fSandi * Print one of the buttons
2676b13307fSandi *
2686b13307fSandi * Available Buttons are
2696b13307fSandi *
270ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
2716b13307fSandi *  history     - old revisions
2726b13307fSandi *  recent      - recent changes
2736b13307fSandi *  login       - login/logout button - if ACL enabled
2746b13307fSandi *  index       - The index
275c19fe9c0Sandi *  admin       - admin page - if enough rights
2766b13307fSandi *  top         - a back to top button
277a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
278d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
279d67ca2c0Smatthiasgrimm *                after references have been displayed
280bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
2816b13307fSandi *
2826b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
283a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
2846b13307fSandi */
2856b13307fSandifunction tpl_button($type){
286b158d625SSteven Danz  global $ACT;
2876b13307fSandi  global $ID;
288d67ca2c0Smatthiasgrimm  global $NS;
289c19fe9c0Sandi  global $INFO;
2906b13307fSandi  global $conf;
291cd52f92dSchris  global $auth;
2926b13307fSandi
2936b13307fSandi  switch($type){
2946b13307fSandi    case 'edit':
2956b13307fSandi      print html_editbutton();
2966b13307fSandi      break;
2976b13307fSandi    case 'history':
2985bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
2996b13307fSandi      break;
3006b13307fSandi    case 'recent':
3015bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
3026b13307fSandi      break;
3036b13307fSandi    case 'index':
3045bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
3056b13307fSandi      break;
306a3ec5f4aSmatthiasgrimm    case 'back':
3076222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
3086222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
309a3ec5f4aSmatthiasgrimm      }
310a3ec5f4aSmatthiasgrimm      break;
3116b13307fSandi    case 'top':
3126b13307fSandi      print html_topbtn();
3136b13307fSandi      break;
3146b13307fSandi    case 'login':
3156b13307fSandi      if($conf['useacl']){
3166b13307fSandi        if($_SERVER['REMOTE_USER']){
3176b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
3186b13307fSandi        }else{
3196b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
3206b13307fSandi        }
3216b13307fSandi      }
3226b13307fSandi      break;
323c19fe9c0Sandi    case 'admin':
324c19fe9c0Sandi      if($INFO['perm'] == AUTH_ADMIN)
3255bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
326c19fe9c0Sandi      break;
327d67ca2c0Smatthiasgrimm    case 'backtomedia':
328d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
329d67ca2c0Smatthiasgrimm      break;
3301380fc45SAndreas Gohr    case 'subscription':
331f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
332b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
3331380fc45SAndreas Gohr          if($INFO['subscribed']){
3341380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
335b158d625SSteven Danz          } else {
3361380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
337b158d625SSteven Danz          }
338b158d625SSteven Danz        }
339b158d625SSteven Danz      }
340b158d625SSteven Danz      break;
341f00151b4Schris    case 'backlink':
342f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
343f00151b4Schris      break;
3448b06d178Schris    case 'profile':
34536223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
34636223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
3478b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
3488b06d178Schris      }
3498b06d178Schris      break;
350c19fe9c0Sandi    default:
351c19fe9c0Sandi      print '[unknown button type]';
3526b13307fSandi  }
3536b13307fSandi}
3546b13307fSandi
3556b13307fSandi/**
356ed630903Sandi * Like the action buttons but links
357ed630903Sandi *
358ed630903Sandi * Available links are
359ed630903Sandi *
360ed630903Sandi *  edit    - edit/create/show button
361ed630903Sandi *  history - old revisions
362ed630903Sandi *  recent  - recent changes
363ed630903Sandi *  login   - login/logout button - if ACL enabled
364ed630903Sandi *  index   - The index
365ed630903Sandi *  admin   - admin page - if enough rights
366ed630903Sandi *  top     - a back to top button
367a3ec5f4aSmatthiasgrimm *  back    - a back to parent button - if available
368bbd37938SAndreas Gohr * backlink - links to the list of backlinks
369ed630903Sandi *
370ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
371a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
372ed630903Sandi * @see    tpl_button
373ed630903Sandi */
374ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
375ed630903Sandi  global $ID;
376ed630903Sandi  global $INFO;
377ed630903Sandi  global $REV;
378ed630903Sandi  global $ACT;
379ed630903Sandi  global $conf;
380ed630903Sandi  global $lang;
381cd52f92dSchris  global $auth;
382ed630903Sandi
383ed630903Sandi  switch($type){
384ed630903Sandi    case 'edit':
385ed630903Sandi      #most complicated type - we need to decide on current action
386ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
387ed630903Sandi        if($INFO['writable']){
388ed630903Sandi          if($INFO['exists']){
389ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
390ed630903Sandi                     $pre.$lang['btn_edit'].$suf,
391b7af031cSsu                     'class="action edit" accesskey="e" rel="nofollow"');
392ed630903Sandi          }else{
393ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
394ed630903Sandi                     $pre.$lang['btn_create'].$suf,
395b7af031cSsu                     'class="action create" accesskey="e" rel="nofollow"');
396ed630903Sandi          }
397ed630903Sandi        }else{
398ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
399ed630903Sandi                   $pre.$lang['btn_source'].$suf,
400b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
401ed630903Sandi        }
402ed630903Sandi      }else{
403ed630903Sandi          tpl_link(wl($ID,'do=show'),
404ed630903Sandi                   $pre.$lang['btn_show'].$suf,
405b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
406ed630903Sandi      }
407ed630903Sandi      break;
408ed630903Sandi    case 'history':
409b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
410ed630903Sandi      break;
411ed630903Sandi    case 'recent':
412b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
413ed630903Sandi      break;
414ed630903Sandi    case 'index':
415b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
416ed630903Sandi      break;
417ed630903Sandi    case 'top':
41821a15207SAnika Henke      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
419ed630903Sandi      break;
420a3ec5f4aSmatthiasgrimm    case 'back':
421a3ec5f4aSmatthiasgrimm      if ($ID = tpl_getparent($ID)) {
422b7af031cSsu        tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
423a3ec5f4aSmatthiasgrimm      }
424a3ec5f4aSmatthiasgrimm      break;
425ed630903Sandi    case 'login':
426ed630903Sandi      if($conf['useacl']){
427ed630903Sandi        if($_SERVER['REMOTE_USER']){
428b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
429ed630903Sandi        }else{
430b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
431ed630903Sandi        }
432ed630903Sandi      }
433ed630903Sandi      break;
434ed630903Sandi    case 'admin':
435ed630903Sandi      if($INFO['perm'] == AUTH_ADMIN)
436b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
437ed630903Sandi      break;
438f9eb5648Ssteven-danz   case 'subscribe':
439075f000fSChristopher Arndt   case 'subscription':
440f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
441b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
442075f000fSChristopher Arndt          if($INFO['subscribed']) {
443b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
444b158d625SSteven Danz          } else {
445b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
446b158d625SSteven Danz          }
447b158d625SSteven Danz        }
448b158d625SSteven Danz      }
449b158d625SSteven Danz      break;
450f00151b4Schris    case 'backlink':
451b7af031cSsu      tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
452f00151b4Schris      break;
4538b06d178Schris    case 'profile':
45436223ba7SAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] &&
45536223ba7SAndreas Gohr         $auth->canDo('Profile') && ($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
4801dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
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" ';
48524a33b42SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" />';
4866b13307fSandi  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
48724a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
4884beabca9SAnika Henke  print '</div></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 *
52431e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
5251734437eSandi * It only makes sense with a deep site structure.
5261734437eSandi *
5271734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
5286bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
52931e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
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
53831e187f8SSean Coates  //check if enabled
53931e187f8SSean Coates  if(!$conf['youarehere']) return;
5401734437eSandi
5411734437eSandi  $parts     = explode(':', $ID);
5421734437eSandi
54331e187f8SSean Coates  print $lang['youarehere'].': ';
5441734437eSandi
5451734437eSandi  //always print the startpage
54631e187f8SSean Coates  if( $a_part[0] != $conf['start']){
54731e187f8SSean Coates    if($conf['useheading']){
54831e187f8SSean Coates      $pageName = p_get_first_heading($conf['start']);
54931e187f8SSean Coates    }else{
55031e187f8SSean Coates      $pageName = $conf['start'];
55131e187f8SSean Coates    }
55231e187f8SSean Coates    tpl_link(wl($conf['start']),$pageName,'title="'.$pageName.'"');
55331e187f8SSean Coates  }
5541734437eSandi
5551734437eSandi  $page = '';
5561734437eSandi  foreach ($parts as $part){
5576bd812dfSNigel McNie        // Skip startpage if already done
5586bd812dfSNigel McNie        if ($part == $conf['start']) continue;
5596bd812dfSNigel McNie
5601734437eSandi          print ' &raquo; ';
5611734437eSandi    $page .= $part;
5621734437eSandi
5631734437eSandi    if(file_exists(wikiFN($page))){
56431e187f8SSean Coates      if($conf['useheading']){
56531e187f8SSean Coates        $pageName = p_get_first_heading($page);
56631e187f8SSean Coates        $partName = $pageName;
56731e187f8SSean Coates      }else{
56831e187f8SSean Coates        $pageName = $page;
56931e187f8SSean Coates        $partName = $part;
57031e187f8SSean Coates      }
57131e187f8SSean Coates      tpl_link(wl($page),$partName,'title="'.$pageName.'"');
5721734437eSandi    }else{
5736bd812dfSNigel McNie      // Print the link, but mark as not-existing, as for other non-existing links
5746bd812dfSNigel McNie      tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"');
5756bd812dfSNigel McNie      //print $page;
5761734437eSandi    }
5771734437eSandi
5781734437eSandi    $page .= ':';
5791734437eSandi  }
5801734437eSandi}
5811734437eSandi
5821734437eSandi/**
5836b13307fSandi * Print info if the user is logged in
584a2488c3cSMatthias Grimm * and show full name in that case
5856b13307fSandi *
5866b13307fSandi * Could be enhanced with a profile link in future?
5876b13307fSandi *
5886b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5896b13307fSandi */
5906b13307fSandifunction tpl_userinfo(){
5916b13307fSandi  global $lang;
592a2488c3cSMatthias Grimm  global $INFO;
5936b13307fSandi  if($_SERVER['REMOTE_USER'])
594a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
5956b13307fSandi}
5966b13307fSandi
5976b13307fSandi/**
5986b13307fSandi * Print some info about the current page
5996b13307fSandi *
6006b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6016b13307fSandi */
6026b13307fSandifunction tpl_pageinfo(){
6036b13307fSandi  global $conf;
6046b13307fSandi  global $lang;
6056b13307fSandi  global $INFO;
6066b13307fSandi  global $REV;
6076b13307fSandi
6086b13307fSandi  // prepare date and path
6096b13307fSandi  $fn = $INFO['filepath'];
6106b13307fSandi  if(!$conf['fullpath']){
6116b13307fSandi    if($REV){
6126b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
6136b13307fSandi    }else{
6146b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
6156b13307fSandi    }
6166b13307fSandi  }
617bee6dc82Sandi  $fn = utf8_decodeFN($fn);
6186b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
6196b13307fSandi
6206b13307fSandi  // print it
6216b13307fSandi  if($INFO['exists']){
6226b13307fSandi    print $fn;
6236b13307fSandi    print ' &middot; ';
6246b13307fSandi    print $lang['lastmod'];
6256b13307fSandi    print ': ';
6266b13307fSandi    print $date;
6276b13307fSandi    if($INFO['editor']){
6286b13307fSandi      print ' '.$lang['by'].' ';
6296b13307fSandi      print $INFO['editor'];
6306b13307fSandi    }
6316b13307fSandi    if($INFO['locked']){
6326b13307fSandi      print ' &middot; ';
6336b13307fSandi      print $lang['lockedby'];
6346b13307fSandi      print ': ';
6356b13307fSandi      print $INFO['locked'];
6366b13307fSandi    }
6376b13307fSandi  }
6386b13307fSandi}
6396b13307fSandi
640820fa24bSandi/**
641820fa24bSandi * Print a list of namespaces containing media files
642820fa24bSandi *
643820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
644820fa24bSandi */
645820fa24bSandifunction tpl_medianamespaces(){
646820fa24bSandi    global $conf;
647820fa24bSandi
648820fa24bSandi  $data = array();
649820fa24bSandi  search($data,$conf['mediadir'],'search_namespaces',array());
650820fa24bSandi  print html_buildlist($data,'idx',media_html_list_namespaces);
651820fa24bSandi}
652820fa24bSandi
653820fa24bSandi/**
654820fa24bSandi * Print a list of mediafiles in the current namespace
655820fa24bSandi *
656820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
657820fa24bSandi */
658820fa24bSandifunction tpl_mediafilelist(){
659820fa24bSandi  global $conf;
660820fa24bSandi  global $lang;
661820fa24bSandi  global $NS;
6628ef6b7caSandi  global $AUTH;
663820fa24bSandi  $dir = utf8_encodeFN(str_replace(':','/',$NS));
664820fa24bSandi
665820fa24bSandi  $data = array();
666820fa24bSandi  search($data,$conf['mediadir'],'search_media',array(),$dir);
667820fa24bSandi
668820fa24bSandi  if(!count($data)){
6694b15e09dSAndreas Gohr    ptln('<div class="nothing">'.$lang['nothingfound'].'</div>');
670820fa24bSandi    return;
671820fa24bSandi  }
672820fa24bSandi
673820fa24bSandi  ptln('<ul>',2);
674820fa24bSandi  foreach($data as $item){
675806d77a0SAndreas Gohr    if(!$item['isimg']){
676806d77a0SAndreas Gohr      // add file icons
677806d77a0SAndreas Gohr      list($ext,$mime) = mimetype($item['file']);
678806d77a0SAndreas Gohr      $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
67943650a18SAndreas Gohr      $class = ' class="mediafile mf_'.$class.'"';
6801512f40dSAndreas Gohr    }else{
6811512f40dSAndreas Gohr      $class = '';
682806d77a0SAndreas Gohr    }
683806d77a0SAndreas Gohr
6840c6b58a8SAndreas Gohr    ptln('<li><div class="li">',4);
685806d77a0SAndreas Gohr    ptln('<a href="javascript:mediaSelect(\':'.$item['id'].'\')"'.$class.'>'.
686820fa24bSandi         utf8_decodeFN($item['file']).
687820fa24bSandi         '</a>',6);
6888ef6b7caSandi
6898ef6b7caSandi    //prepare deletion button
6908ef6b7caSandi    if($AUTH >= AUTH_DELETE){
6910699afe9SAndreas Gohr      $ask  = addslashes($lang['del_confirm']).'\\n';
6920699afe9SAndreas Gohr      $ask .= addslashes($item['id']);
6938ef6b7caSandi
694b6c6979fSAndreas Gohr      $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.rawurlencode($item['id']).'" '.
6958ef6b7caSandi             'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'.
696f62ea8a1Sandi             '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '.
6974beabca9SAnika Henke             'title="'.$lang['btn_delete'].'" /></a>';
6988ef6b7caSandi    }else{
6998ef6b7caSandi      $del = '';
7008ef6b7caSandi    }
7018ef6b7caSandi
702820fa24bSandi    if($item['isimg']){
70393c020acSAndreas Gohr      $w = (int) $item['meta']->getField('File.Width');
70493c020acSAndreas Gohr      $h = (int) $item['meta']->getField('File.Height');
705820fa24bSandi
7068ef6b7caSandi      ptln('('.$w.'&#215;'.$h.' '.filesize_h($item['size']).')',6);
7078ef6b7caSandi      ptln($del.'<br />',6);
708478cd997SAndreas Gohr      ptln('<div class="imagemeta">',6);
7099fcd3d1dSandi
71023a34783SAndreas Gohr      //build thumbnail
7110699afe9SAndreas Gohr      print '<a href="javascript:mediaSelect(\':'.$item['id'].'\')">';
71223a34783SAndreas Gohr
71323a34783SAndreas Gohr      if($w>120 || $h>120){
71423a34783SAndreas Gohr        $ratio = $item['meta']->getResizeRatio(120);
71523a34783SAndreas Gohr        $w = floor($w * $ratio);
71623a34783SAndreas Gohr        $h = floor($h * $ratio);
7179fcd3d1dSandi      }
71823a34783SAndreas Gohr
7196de3759aSAndreas Gohr      $src = ml($item['id'],array('w'=>$w,'h'=>$h));
72023a34783SAndreas Gohr
72123a34783SAndreas Gohr      $p = array();
72223a34783SAndreas Gohr      $p['width']  = $w;
72323a34783SAndreas Gohr      $p['height'] = $h;
72423a34783SAndreas Gohr      $p['alt']    = $item['id'];
72523a34783SAndreas Gohr      $p['class']  = 'thumb';
72623a34783SAndreas Gohr      $att = buildAttributes($p);
72723a34783SAndreas Gohr
72823a34783SAndreas Gohr      print '<img src="'.$src.'" '.$att.' />';
7299fcd3d1dSandi      print '</a>';
730820fa24bSandi
7316d861d12SAndreas Gohr      //read EXIF/IPTC data
73223a34783SAndreas Gohr      $t = $item['meta']->getField('IPTC.Headline');
73393c020acSAndreas Gohr      if($t) print '<strong>'.htmlspecialchars($t).'</strong><br />';
7346d861d12SAndreas Gohr
73536df6fa3SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
73636df6fa3SAndreas Gohr                                         'EXIF.TIFFImageDescription',
73736df6fa3SAndreas Gohr                                         'EXIF.TIFFUserComment'));
73893c020acSAndreas Gohr      if($t) print htmlspecialchars($t).'<br />';
7396d861d12SAndreas Gohr
74023a34783SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category'));
74193c020acSAndreas Gohr      if($t) print '<em>'.htmlspecialchars($t).'</em><br />';
7426d861d12SAndreas Gohr
74336df6fa3SAndreas Gohr      //add edit button
74436df6fa3SAndreas Gohr      if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){
745b6c6979fSAndreas Gohr        print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.rawurlencode($item['id']).'">';
74636df6fa3SAndreas Gohr        print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />';
74736df6fa3SAndreas Gohr        print '</a>';
74836df6fa3SAndreas Gohr      }
74936df6fa3SAndreas Gohr
7506d861d12SAndreas Gohr      ptln('</div>',6);
751820fa24bSandi    }else{
752820fa24bSandi      ptln ('('.filesize_h($item['size']).')',6);
7538ef6b7caSandi      ptln($del,6);
754820fa24bSandi    }
7550c6b58a8SAndreas Gohr    ptln('</div></li>',4);
756820fa24bSandi  }
757820fa24bSandi  ptln('</ul>',2);
758820fa24bSandi}
759820fa24bSandi
760820fa24bSandi/**
761d67ca2c0Smatthiasgrimm * show references to a media file
762d67ca2c0Smatthiasgrimm * References uses the same visual as search results and share
763d67ca2c0Smatthiasgrimm * their CSS tags except pagenames won't be links.
764d67ca2c0Smatthiasgrimm *
765d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
766d67ca2c0Smatthiasgrimm */
767d67ca2c0Smatthiasgrimmfunction tpl_showreferences(&$data){
768d67ca2c0Smatthiasgrimm  global $lang;
769d67ca2c0Smatthiasgrimm
770d67ca2c0Smatthiasgrimm  $hidden=0; //count of hits without read permission
771d67ca2c0Smatthiasgrimm
772d67ca2c0Smatthiasgrimm  if(count($data)){
773d67ca2c0Smatthiasgrimm    usort($data,'sort_search_fulltext');
774d67ca2c0Smatthiasgrimm    foreach($data as $row){
775d67ca2c0Smatthiasgrimm      if(auth_quickaclcheck($row['id']) >= AUTH_READ){
776d67ca2c0Smatthiasgrimm        print '<div class="search_result">';
777d67ca2c0Smatthiasgrimm        print '<span class="mediaref_ref">'.$row['id'].'</span>';
778d67ca2c0Smatthiasgrimm        print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
779d67ca2c0Smatthiasgrimm        print '<div class="search_snippet">'.$row['snippet'].'</div>';
780d67ca2c0Smatthiasgrimm        print '</div>';
781d67ca2c0Smatthiasgrimm      }else
782d67ca2c0Smatthiasgrimm        $hidden++;
783d67ca2c0Smatthiasgrimm    }
784d67ca2c0Smatthiasgrimm    if ($hidden){
785d67ca2c0Smatthiasgrimm      print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
786d67ca2c0Smatthiasgrimm    }
787d67ca2c0Smatthiasgrimm  }
788d67ca2c0Smatthiasgrimm}
789d67ca2c0Smatthiasgrimm
790d67ca2c0Smatthiasgrimm/**
791820fa24bSandi * Print the media upload form if permissions are correct
792820fa24bSandi *
793820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
794820fa24bSandi */
795820fa24bSandifunction tpl_mediauploadform(){
796820fa24bSandi  global $NS;
797820fa24bSandi  global $UPLOADOK;
7988ef6b7caSandi  global $AUTH;
799820fa24bSandi  global $lang;
800820fa24bSandi
801820fa24bSandi  if(!$UPLOADOK) return;
802820fa24bSandi
8031dd0c202SAnika Henke  ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" id="dw__upload"'.
804820fa24bSandi       ' method="post" enctype="multipart/form-data">',2);
805820fa24bSandi  ptln($lang['txt_upload'].':<br />',4);
806820fa24bSandi  ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4);
807820fa24bSandi  ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4);
808820fa24bSandi  ptln($lang['txt_filename'].'<br />',4);
809820fa24bSandi  ptln('<input type="text" name="id" class="edit" />',4);
810820fa24bSandi  ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4);
8118ef6b7caSandi  if($AUTH >= AUTH_DELETE){
81224a33b42SAndreas Gohr    ptln('<label for="dw__ow"><input type="checkbox" name="ow" value="1" id="dw__ow" />'.$lang['txt_overwrt'].'</label>',4);
8138ef6b7caSandi  }
814820fa24bSandi  ptln('</form>',2);
815820fa24bSandi}
816820fa24bSandi
81787c434ceSAndreas Gohr/**
81887c434ceSAndreas Gohr * Prints the name of the given page (current one if none given).
81987c434ceSAndreas Gohr *
82087c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
82187c434ceSAndreas Gohr * the given ID is printed.
82287c434ceSAndreas Gohr *
82387c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
82487c434ceSAndreas Gohr */
82587c434ceSAndreas Gohrfunction tpl_pagetitle($id=null){
82687c434ceSAndreas Gohr  global $conf;
82787c434ceSAndreas Gohr  if(is_null($id)){
82887c434ceSAndreas Gohr    global $ID;
82987c434ceSAndreas Gohr    $id = $ID;
83087c434ceSAndreas Gohr  }
83187c434ceSAndreas Gohr
83287c434ceSAndreas Gohr  $name = $id;
83387c434ceSAndreas Gohr  if ($conf['useheading']) {
83487c434ceSAndreas Gohr    $title = p_get_first_heading($id);
83587c434ceSAndreas Gohr    if ($title) $name = $title;
83687c434ceSAndreas Gohr  }
83787c434ceSAndreas Gohr  print hsc($name);
83887c434ceSAndreas Gohr}
839340756e4Sandi
84055efc227SAndreas Gohr/**
84155efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
84255efc227SAndreas Gohr *
84355efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
84455efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
84555efc227SAndreas Gohr *
84655efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
84755efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
84855efc227SAndreas Gohr * to the names of the latter one)
84955efc227SAndreas Gohr *
85036df6fa3SAndreas Gohr * Only allowed in: detail.php, mediaedit.php
85155efc227SAndreas Gohr *
85255efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
85355efc227SAndreas Gohr */
85455efc227SAndreas Gohrfunction tpl_img_getTag($tags,$alt=''){
85555efc227SAndreas Gohr  // Init Exif Reader
85655efc227SAndreas Gohr  global $SRC;
85755efc227SAndreas Gohr  static $meta = null;
85855efc227SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($SRC);
85955efc227SAndreas Gohr  if($meta === false) return $alt;
86055efc227SAndreas Gohr  $info = $meta->getField($tags);
86155efc227SAndreas Gohr  if($info == false) return $alt;
86255efc227SAndreas Gohr  return $info;
86355efc227SAndreas Gohr}
86455efc227SAndreas Gohr
86555efc227SAndreas Gohr/**
86655efc227SAndreas Gohr * Prints the image with a link to the full sized version
86755efc227SAndreas Gohr *
86855efc227SAndreas Gohr * Only allowed in: detail.php
86955efc227SAndreas Gohr */
870f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
87155efc227SAndreas Gohr  global $IMG;
87255efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
87355efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
87455efc227SAndreas Gohr
87555efc227SAndreas Gohr  //resize to given max values
87623a34783SAndreas Gohr  $ratio = 1;
87723a34783SAndreas Gohr  if($w >= $h){
878f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
87955efc227SAndreas Gohr      $ratio = $maxwidth/$w;
880f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
88155efc227SAndreas Gohr      $ratio = $maxheight/$h;
88255efc227SAndreas Gohr    }
88355efc227SAndreas Gohr  }else{
884f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
88555efc227SAndreas Gohr      $ratio = $maxheight/$h;
886f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
88755efc227SAndreas Gohr      $ratio = $maxwidth/$w;
88855efc227SAndreas Gohr    }
88955efc227SAndreas Gohr  }
89055efc227SAndreas Gohr  if($ratio){
89155efc227SAndreas Gohr    $w = floor($ratio*$w);
89255efc227SAndreas Gohr    $h = floor($ratio*$h);
89355efc227SAndreas Gohr  }
89455efc227SAndreas Gohr
8956de3759aSAndreas Gohr  //prepare URLs
8966de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
8976de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
89855efc227SAndreas Gohr
8992684e50aSAndreas Gohr  //prepare attributes
90055efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
9012684e50aSAndreas Gohr  $p = array();
9022684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9032684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9042684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9052684e50aSAndreas Gohr  if($alt){
9062684e50aSAndreas Gohr    $p['alt']   = $alt;
9072684e50aSAndreas Gohr    $p['title'] = $alt;
9082684e50aSAndreas Gohr  }else{
9092684e50aSAndreas Gohr    $p['alt'] = '';
9102684e50aSAndreas Gohr  }
9112684e50aSAndreas Gohr  $p = buildAttributes($p);
91255efc227SAndreas Gohr
91355efc227SAndreas Gohr  print '<a href="'.$url.'">';
9146de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
91555efc227SAndreas Gohr  print '</a>';
91655efc227SAndreas Gohr}
91755efc227SAndreas Gohr
9187367b368SAndreas Gohr/**
9197367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9207367b368SAndreas Gohr * is the inexer function.
9217367b368SAndreas Gohr *
9227367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9237367b368SAndreas Gohr * template
9247367b368SAndreas Gohr */
9257367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9267367b368SAndreas Gohr  global $ID;
9271dad36f5SAndreas Gohr  global $INFO;
9281dad36f5SAndreas Gohr  if(!$INFO['exists']) return;
9291dad36f5SAndreas Gohr
9300dc92c6fSAndreas Gohr  if(isHiddenPage($ID)) return; //no need to index hidden pages
9310dc92c6fSAndreas Gohr
9327367b368SAndreas Gohr  $p = array();
933b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
934e68c51baSAndreas Gohr                 '&'.time();
9357367b368SAndreas Gohr  $p['width']  = 1;
9367367b368SAndreas Gohr  $p['height'] = 1;
9377367b368SAndreas Gohr  $p['alt']    = '';
9387367b368SAndreas Gohr  $att = buildAttributes($p);
9397367b368SAndreas Gohr  print "<img $att />";
9407367b368SAndreas Gohr}
9417367b368SAndreas Gohr
94278d4e784SEsther Brunner// configuration methods
94378d4e784SEsther Brunner/**
94478d4e784SEsther Brunner * tpl_getConf($id)
94578d4e784SEsther Brunner *
94678d4e784SEsther Brunner * use this function to access template configuration variables
94778d4e784SEsther Brunner */
94878d4e784SEsther Brunnerfunction tpl_getConf($id){
94978d4e784SEsther Brunner  global $conf;
95078d4e784SEsther Brunner  global $tpl_configloaded;
95178d4e784SEsther Brunner
95278d4e784SEsther Brunner  $tpl = $conf['template'];
95378d4e784SEsther Brunner
95478d4e784SEsther Brunner  if (!$tpl_configloaded){
95578d4e784SEsther Brunner    $tconf = tpl_loadConfig();
95678d4e784SEsther Brunner    if ($tconf !== false){
95778d4e784SEsther Brunner      foreach ($tconf as $key => $value){
95878d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
95978d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
96078d4e784SEsther Brunner      }
96178d4e784SEsther Brunner      $tpl_configloaded = true;
96278d4e784SEsther Brunner    }
96378d4e784SEsther Brunner  }
96478d4e784SEsther Brunner
96578d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
96678d4e784SEsther Brunner}
96778d4e784SEsther Brunner
96878d4e784SEsther Brunner/**
96978d4e784SEsther Brunner * tpl_loadConfig()
97078d4e784SEsther Brunner * reads all template configuration variables
97178d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
97278d4e784SEsther Brunner */
97378d4e784SEsther Brunnerfunction tpl_loadConfig(){
97478d4e784SEsther Brunner
97578d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
97678d4e784SEsther Brunner  $conf = array();
97778d4e784SEsther Brunner
97878d4e784SEsther Brunner  if (!@file_exists($file)) return false;
97978d4e784SEsther Brunner
98078d4e784SEsther Brunner  // load default config file
98178d4e784SEsther Brunner  include($file);
98278d4e784SEsther Brunner
98378d4e784SEsther Brunner  return $conf;
98478d4e784SEsther Brunner}
98578d4e784SEsther Brunner
986340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
987