xref: /dokuwiki/inc/template.php (revision 6e37f3d92cd20e04f37d47feb5fde819e056da5e)
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;
115820fa24bSandi    case 'denied':
1165e991bd8Sandi      print p_locale_xhtml('denied');
117820fa24bSandi			break;
118c19fe9c0Sandi    case 'admin':
119c19fe9c0Sandi      tpl_admin();
120c19fe9c0Sandi      break;
1216b13307fSandi    default:
122ea67f144Sandi			msg("Failed to handle command: ".hsc($ACT),-1);
1236b13307fSandi  }
1246b13307fSandi}
1256b13307fSandi
126c19fe9c0Sandi/**
127c19fe9c0Sandi * Handle the admin page contents
128c19fe9c0Sandi *
129c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
130c19fe9c0Sandi */
131c19fe9c0Sandifunction tpl_admin(){
13211e2ce22Schris
13311e2ce22Schris    $plugin = NULL;
13411e2ce22Schris    if ($_REQUEST['page']) {
13511e2ce22Schris        $pluginlist = plugin_list('admin');
13611e2ce22Schris
13711e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
13811e2ce22Schris
13911e2ce22Schris          // attempt to load the plugin
14011e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
14111e2ce22Schris        }
14211e2ce22Schris    }
14311e2ce22Schris
14411e2ce22Schris    if ($plugin !== NULL)
14511e2ce22Schris        $plugin->html();
14611e2ce22Schris    else
14711e2ce22Schris        html_admin();
14811e2ce22Schris/*
149c19fe9c0Sandi  switch($_REQUEST['page']){
150c19fe9c0Sandi        case 'acl':
151c19fe9c0Sandi            admin_acl_html();
152c19fe9c0Sandi            break;
15311e2ce22Schris        case 'plugin':
15411e2ce22Schris            require_once(DOKU_INC.'inc/admin_plugin.php');
15511e2ce22Schris            admin_plugin_html();
15611e2ce22Schris            break;
157c19fe9c0Sandi    default:
158c19fe9c0Sandi            html_admin();
159c19fe9c0Sandi    }
16011e2ce22Schris*/
161c19fe9c0Sandi}
1626b13307fSandi
1636b13307fSandi/**
1646b13307fSandi * Print the correct HTML meta headers
1656b13307fSandi *
1666b13307fSandi * This has to go into the head section of your template.
1676b13307fSandi *
1686b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1696b13307fSandi */
1706b13307fSandifunction tpl_metaheaders(){
1716b13307fSandi  global $ID;
1726b13307fSandi  global $INFO;
1736b13307fSandi  global $ACT;
1746b13307fSandi  global $lang;
175dc57ef04Sandi  global $conf;
1766b13307fSandi  $it=2;
1776b13307fSandi
1786b13307fSandi  // the usual stuff
1796b13307fSandi  ptln('<meta name="generator" content="DokuWiki '.getVersion().'" />',$it);
1806b13307fSandi  ptln('<link rel="start" href="'.DOKU_BASE.'" />',$it);
1816b13307fSandi  ptln('<link rel="contents" href="'.wl($ID,'do=index').'" title="'.$lang['index'].'" />',$it);
1826b13307fSandi  ptln('<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="'.DOKU_BASE.'feed.php" />',$it);
1836b13307fSandi  ptln('<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="'.DOKU_BASE.'feed.php?mode=list&amp;ns='.$INFO['namespace'].'" />',$it);
1846b13307fSandi  ptln('<link rel="alternate" type="text/html" title="Plain HTML" href="'.wl($ID,'do=export_html').'" />',$it);
1856b13307fSandi  ptln('<link rel="alternate" type="text/plain" title="Wiki Markup" href="'.wl($ID, 'do=export_raw').'" />',$it);
186f62ea8a1Sandi  ptln('<link rel="stylesheet" media="screen" type="text/css" href="'.DOKU_BASE.'lib/styles/style.css" />',$it);
1876b13307fSandi
1886b13307fSandi  // setup robot tags apropriate for different modes
1896b13307fSandi  if( ($ACT=='show' || $ACT=='export_html') && !$REV){
1906b13307fSandi    if($INFO['exists']){
1916b13307fSandi      ptln('<meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />',$it);
1926b13307fSandi      //delay indexing:
1936b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
1946b13307fSandi        ptln('<meta name="robots" content="index,follow" />',$it);
1956b13307fSandi      }else{
1966b13307fSandi        ptln('<meta name="robots" content="noindex,nofollow" />',$it);
1976b13307fSandi      }
1986b13307fSandi    }else{
1996b13307fSandi      ptln('<meta name="robots" content="noindex,follow" />',$it);
2006b13307fSandi    }
2016b13307fSandi  }else{
2026b13307fSandi    ptln('<meta name="robots" content="noindex,nofollow" />',$it);
2036b13307fSandi  }
2046b13307fSandi
2056b13307fSandi  // include some JavaScript language strings
206ea2eed85Sandi  ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it);
20708478e65SAndreas Gohr  ptln("  var alertText   = '".str_replace('\\\\n','\\n',addslashes($lang['qb_alert']))."'",$it);
20808478e65SAndreas Gohr  ptln("  var notSavedYet = '".str_replace('\\\\n','\\n',addslashes($lang['notsavedyet']))."'",$it);
2096b13307fSandi  ptln("  var DOKU_BASE   = '".DOKU_BASE."'",$it);
21020d062caSAndreas Gohr
2116b13307fSandi  ptln('</script>',$it);
2126b13307fSandi
2139a3ea4f8Sandi  // load the default JavaScript files
214ea2eed85Sandi  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
215f62ea8a1Sandi       DOKU_BASE.'lib/scripts/script.js"></script>',$it);
216ea2eed85Sandi  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
217f62ea8a1Sandi       DOKU_BASE.'lib/scripts/tw-sack.js"></script>',$it);
218ea2eed85Sandi  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
219f62ea8a1Sandi       DOKU_BASE.'lib/scripts/ajax.js"></script>',$it);
2206b13307fSandi
221d74aace9Schris
222d74aace9Schris  // dom tool tip library, for insitu footnotes
223d74aace9Schris  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
224d74aace9Schris       DOKU_BASE.'lib/scripts/domLib.js"></script>',$it);
225d74aace9Schris  ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
226d74aace9Schris       DOKU_BASE.'lib/scripts/domTT.js"></script>',$it);
227dc57ef04Sandi
2285e163278SAndreas Gohr
2295e163278SAndreas Gohr
2305e163278SAndreas Gohr  // editing functions
2315e163278SAndreas Gohr  if($ACT=='edit' || $ACT=='preview'){
23220d062caSAndreas Gohr    // add size control
23320d062caSAndreas Gohr    ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it);
23420d062caSAndreas Gohr    ptln("addEvent(window,'onload',function(){initSizeCtl('sizectl','wikitext')});",$it+2);
23520d062caSAndreas Gohr    ptln('</script>',$it);
23620d062caSAndreas Gohr
2375e163278SAndreas Gohr    if($INFO['writable']){
23820d062caSAndreas Gohr      // load toolbar functions
23920d062caSAndreas Gohr      ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
24020d062caSAndreas Gohr           DOKU_BASE.'lib/scripts/edit.js"></script>',$it);
24120d062caSAndreas Gohr
24220d062caSAndreas Gohr      // load spellchecker functions if wanted
24320d062caSAndreas Gohr      if($conf['spellchecker']){
24420d062caSAndreas Gohr        ptln('<script language="javascript" type="text/javascript" charset="utf-8" src="'.
24520d062caSAndreas Gohr             DOKU_BASE.'lib/scripts/spellcheck.js"></script>',$it+2);
24620d062caSAndreas Gohr      }
24720d062caSAndreas Gohr
24820d062caSAndreas Gohr      ptln('<script language="javascript" type="text/javascript" charset="utf-8">',$it);
24920d062caSAndreas Gohr
25020d062caSAndreas Gohr      // add toolbar
25120d062caSAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
25220d062caSAndreas Gohr      toolbar_JSdefines('toolbar');
25320d062caSAndreas Gohr      ptln("addEvent(window,'onload',function(){initToolbar('toolbar','wikitext',toolbar);});",$it+2);
25420d062caSAndreas Gohr
2555e163278SAndreas Gohr      // add pageleave check
2565e163278SAndreas Gohr      ptln("addEvent(window,'onload',function(){initChangeCheck('".
2575e163278SAndreas Gohr           str_replace('\\\\n','\\n',addslashes($lang['notsavedyet']))."');});",$it);
2585e163278SAndreas Gohr
2595e163278SAndreas Gohr      // add lock timer
2605e163278SAndreas Gohr      ptln("addEvent(window,'onload',function(){init_locktimer(".
2615e163278SAndreas Gohr           ($conf['locktime']-60).",'".
2625e163278SAndreas Gohr           str_replace('\\\\n','\\n',addslashes($lang['willexpire']))."');});",$it);
2635e163278SAndreas Gohr
26420d062caSAndreas Gohr      // add spellchecker
26520d062caSAndreas Gohr      if($conf['spellchecker']){
26620d062caSAndreas Gohr        //init here
2675e163278SAndreas Gohr        ptln("addEvent(window,'onload',function(){ ajax_spell.init('".
2685e163278SAndreas Gohr                                       $lang['spell_start']."','".
26920d062caSAndreas Gohr                                       $lang['spell_stop']."','".
27020d062caSAndreas Gohr                                       $lang['spell_wait']."','".
27120d062caSAndreas Gohr                                       $lang['spell_noerr']."','".
27220d062caSAndreas Gohr                                       $lang['spell_nosug']."','".
27320d062caSAndreas Gohr                                       $lang['spell_change']."'); });");
27420d062caSAndreas Gohr      }
27520d062caSAndreas Gohr      ptln('</script>',$it);
27620d062caSAndreas Gohr    }
2775e163278SAndreas Gohr  }
27820d062caSAndreas Gohr
2793600bd52SAndreas Gohr  // plugin stylesheets and Scripts
2803600bd52SAndreas Gohr  plugin_printCSSJS();
2816b13307fSandi}
2826b13307fSandi
2836b13307fSandi/**
2846b13307fSandi * Print a link
2856b13307fSandi *
2865e163278SAndreas Gohr * Just builds a link.
2876b13307fSandi *
2886b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2896b13307fSandi */
2906b13307fSandifunction tpl_link($url,$name,$more=''){
2915e163278SAndreas Gohr  print '<a href="'.$url.'" ';
2926b13307fSandi  if ($more) print ' '.$more;
2936b13307fSandi  print ">$name</a>";
2946b13307fSandi}
2956b13307fSandi
2966b13307fSandi/**
29755efc227SAndreas Gohr * Prints a link to a WikiPage
29855efc227SAndreas Gohr *
29955efc227SAndreas Gohr * Wrapper around html_wikilink
30055efc227SAndreas Gohr *
30155efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
30255efc227SAndreas Gohr */
30355efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
30455efc227SAndreas Gohr  print html_wikilink($id,$name);
30555efc227SAndreas Gohr}
30655efc227SAndreas Gohr
30755efc227SAndreas Gohr/**
308a3ec5f4aSmatthiasgrimm * get the parent page
309a3ec5f4aSmatthiasgrimm *
310a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
311a3ec5f4aSmatthiasgrimm * returns false if none is available
312a3ec5f4aSmatthiasgrimm *
313a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
314a3ec5f4aSmatthiasgrimm */
315a3ec5f4aSmatthiasgrimmfunction tpl_getparent($ID){
316a3ec5f4aSmatthiasgrimm  global $conf;
317a3ec5f4aSmatthiasgrimm
318a3ec5f4aSmatthiasgrimm  if ($ID != $conf['start']) {
319a3ec5f4aSmatthiasgrimm    $idparts = explode(':', $ID);
320a3ec5f4aSmatthiasgrimm    $pn = array_pop($idparts);    // get the page name
321a3ec5f4aSmatthiasgrimm
322a3ec5f4aSmatthiasgrimm    for ($n=0; $n < 2; $n++) {
323a3ec5f4aSmatthiasgrimm      if (count($idparts) == 0) {
324a3ec5f4aSmatthiasgrimm        $ID = $conf['start'];     // go to topmost page
325a3ec5f4aSmatthiasgrimm        break;
326a3ec5f4aSmatthiasgrimm      }else{
327a3ec5f4aSmatthiasgrimm        $ns = array_pop($idparts);     // get the last part of namespace
328a3ec5f4aSmatthiasgrimm        if ($pn != $ns) {                 // are we already home?
329a3ec5f4aSmatthiasgrimm          array_push($idparts, $ns, $ns); // no, then add a page with same name
330a3ec5f4aSmatthiasgrimm          $ID = implode (':', $idparts); // as the namespace and recombine $ID
331a3ec5f4aSmatthiasgrimm          break;
332a3ec5f4aSmatthiasgrimm        }
333a3ec5f4aSmatthiasgrimm      }
334a3ec5f4aSmatthiasgrimm    }
335a3ec5f4aSmatthiasgrimm
336a3ec5f4aSmatthiasgrimm    if (@file_exists(wikiFN($ID))) {
337a3ec5f4aSmatthiasgrimm      return $ID;
338a3ec5f4aSmatthiasgrimm    }
339a3ec5f4aSmatthiasgrimm  }
340a3ec5f4aSmatthiasgrimm  return false;
341a3ec5f4aSmatthiasgrimm}
342a3ec5f4aSmatthiasgrimm
343a3ec5f4aSmatthiasgrimm/**
3446b13307fSandi * Print one of the buttons
3456b13307fSandi *
3466b13307fSandi * Available Buttons are
3476b13307fSandi *
3486b13307fSandi *  edit        - edit/create/show button
3496b13307fSandi *  history     - old revisions
3506b13307fSandi *  recent      - recent changes
3516b13307fSandi *  login       - login/logout button - if ACL enabled
3526b13307fSandi *  index       - The index
353c19fe9c0Sandi *  admin       - admin page - if enough rights
3546b13307fSandi *  top         - a back to top button
355a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
356d67ca2c0Smatthiasgrimm *  backtomedia - returns to the mediafile upload dialog
357d67ca2c0Smatthiasgrimm *                after references have been displayed
358bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
3596b13307fSandi *
3606b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
361a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
3626b13307fSandi */
3636b13307fSandifunction tpl_button($type){
364b158d625SSteven Danz  global $ACT;
3656b13307fSandi  global $ID;
366d67ca2c0Smatthiasgrimm  global $NS;
367c19fe9c0Sandi  global $INFO;
3686b13307fSandi  global $conf;
3696b13307fSandi
3706b13307fSandi  switch($type){
3716b13307fSandi    case 'edit':
3726b13307fSandi      print html_editbutton();
3736b13307fSandi      break;
3746b13307fSandi    case 'history':
3755bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
3766b13307fSandi      break;
3776b13307fSandi    case 'recent':
3785bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
3796b13307fSandi      break;
3806b13307fSandi    case 'index':
3815bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
3826b13307fSandi      break;
383a3ec5f4aSmatthiasgrimm    case 'back':
3846222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
3856222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
386a3ec5f4aSmatthiasgrimm      }
387a3ec5f4aSmatthiasgrimm      break;
3886b13307fSandi    case 'top':
3896b13307fSandi      print html_topbtn();
3906b13307fSandi      break;
3916b13307fSandi    case 'login':
3926b13307fSandi      if($conf['useacl']){
3936b13307fSandi        if($_SERVER['REMOTE_USER']){
3946b13307fSandi          print html_btn('logout',$ID,'',array('do' => 'logout',));
3956b13307fSandi        }else{
3966b13307fSandi          print html_btn('login',$ID,'',array('do' => 'login'));
3976b13307fSandi        }
3986b13307fSandi      }
3996b13307fSandi      break;
400c19fe9c0Sandi    case 'admin':
401c19fe9c0Sandi      if($INFO['perm'] == AUTH_ADMIN)
4025bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
403c19fe9c0Sandi      break;
404d67ca2c0Smatthiasgrimm    case 'backtomedia':
405d67ca2c0Smatthiasgrimm      print html_backtomedia_button(array('ns' => $NS),'b');
406d67ca2c0Smatthiasgrimm      break;
4071380fc45SAndreas Gohr    case 'subscription':
408f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
409b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
4101380fc45SAndreas Gohr          if($INFO['subscribed']){
4111380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
412b158d625SSteven Danz          } else {
4131380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
414b158d625SSteven Danz          }
415b158d625SSteven Danz        }
416b158d625SSteven Danz      }
417b158d625SSteven Danz      break;
418f00151b4Schris    case 'backlink':
419f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
420f00151b4Schris      break;
421c19fe9c0Sandi    default:
422c19fe9c0Sandi      print '[unknown button type]';
4236b13307fSandi  }
4246b13307fSandi}
4256b13307fSandi
4266b13307fSandi/**
427ed630903Sandi * Like the action buttons but links
428ed630903Sandi *
429ed630903Sandi * Available links are
430ed630903Sandi *
431ed630903Sandi *  edit    - edit/create/show button
432ed630903Sandi *  history - old revisions
433ed630903Sandi *  recent  - recent changes
434ed630903Sandi *  login   - login/logout button - if ACL enabled
435ed630903Sandi *  index   - The index
436ed630903Sandi *  admin   - admin page - if enough rights
437ed630903Sandi *  top     - a back to top button
438a3ec5f4aSmatthiasgrimm *  back    - a back to parent button - if available
439bbd37938SAndreas Gohr * backlink - links to the list of backlinks
440ed630903Sandi *
441ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
442a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
443ed630903Sandi * @see    tpl_button
444ed630903Sandi */
445ed630903Sandifunction tpl_actionlink($type,$pre='',$suf=''){
446ed630903Sandi  global $ID;
447ed630903Sandi  global $INFO;
448ed630903Sandi  global $REV;
449ed630903Sandi  global $ACT;
450ed630903Sandi  global $conf;
451ed630903Sandi  global $lang;
452ed630903Sandi
453ed630903Sandi  switch($type){
454ed630903Sandi    case 'edit':
455ed630903Sandi      #most complicated type - we need to decide on current action
456ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
457ed630903Sandi        if($INFO['writable']){
458ed630903Sandi          if($INFO['exists']){
459ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
460ed630903Sandi                     $pre.$lang['btn_edit'].$suf,
461b7af031cSsu                     'class="action edit" accesskey="e" rel="nofollow"');
462ed630903Sandi          }else{
463ed630903Sandi            tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
464ed630903Sandi                     $pre.$lang['btn_create'].$suf,
465b7af031cSsu                     'class="action create" accesskey="e" rel="nofollow"');
466ed630903Sandi          }
467ed630903Sandi        }else{
468ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
469ed630903Sandi                   $pre.$lang['btn_source'].$suf,
470b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
471ed630903Sandi        }
472ed630903Sandi      }else{
473ed630903Sandi          tpl_link(wl($ID,'do=show'),
474ed630903Sandi                   $pre.$lang['btn_show'].$suf,
475b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
476ed630903Sandi      }
477ed630903Sandi      break;
478ed630903Sandi    case 'history':
479b7af031cSsu      tpl_link(wl($ID,'do=revisions'),$pre.$lang['btn_revs'].$suf,'class="action revisions" accesskey="o"');
480ed630903Sandi      break;
481ed630903Sandi    case 'recent':
482b7af031cSsu      tpl_link(wl($ID,'do=recent'),$pre.$lang['btn_recent'].$suf,'class="action recent" accesskey="r"');
483ed630903Sandi      break;
484ed630903Sandi    case 'index':
485b7af031cSsu      tpl_link(wl($ID,'do=index'),$pre.$lang['btn_index'].$suf,'class="action index" accesskey="x"');
486ed630903Sandi      break;
487ed630903Sandi    case 'top':
488b7af031cSsu      print '<a href="#top" class="action top" accesskey="x">'.$pre.$lang['btn_top'].$suf.'</a>';
489ed630903Sandi      break;
490a3ec5f4aSmatthiasgrimm    case 'back':
491a3ec5f4aSmatthiasgrimm      if ($ID = tpl_getparent($ID)) {
492b7af031cSsu        tpl_link(wl($ID,'do=show'),$pre.$lang['btn_back'].$suf,'class="action back" accesskey="b"');
493a3ec5f4aSmatthiasgrimm      }
494a3ec5f4aSmatthiasgrimm      break;
495ed630903Sandi    case 'login':
496ed630903Sandi      if($conf['useacl']){
497ed630903Sandi        if($_SERVER['REMOTE_USER']){
498b7af031cSsu          tpl_link(wl($ID,'do=logout'),$pre.$lang['btn_logout'].$suf,'class="action logout"');
499ed630903Sandi        }else{
500b7af031cSsu          tpl_link(wl($ID,'do=login'),$pre.$lang['btn_login'].$suf,'class="action logout"');
501ed630903Sandi        }
502ed630903Sandi      }
503ed630903Sandi      break;
504ed630903Sandi    case 'admin':
505ed630903Sandi      if($INFO['perm'] == AUTH_ADMIN)
506b7af031cSsu        tpl_link(wl($ID,'do=admin'),$pre.$lang['btn_admin'].$suf,'class="action admin"');
507ed630903Sandi      break;
508f9eb5648Ssteven-danz   case 'subscribe':
509075f000fSChristopher Arndt   case 'subscription':
510f9eb5648Ssteven-danz      if($conf['useacl'] && $ACT == 'show' && $conf['subscribers'] == 1){
511b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
512075f000fSChristopher Arndt          if($INFO['subscribed']) {
513b7af031cSsu            tpl_link(wl($ID,'do=unsubscribe'),$pre.$lang['btn_unsubscribe'].$suf,'class="action unsubscribe"');
514b158d625SSteven Danz          } else {
515b7af031cSsu            tpl_link(wl($ID,'do=subscribe'),$pre.$lang['btn_subscribe'].$suf,'class="action subscribe"');
516b158d625SSteven Danz          }
517b158d625SSteven Danz        }
518b158d625SSteven Danz      }
519b158d625SSteven Danz      break;
520f00151b4Schris	case 'backlink':
521b7af031cSsu	  tpl_link(wl($ID,'do=backlink'),$pre.$lang['btn_backlink'].$suf, 'class="action backlink"');
522f00151b4Schris	  break;
523ed630903Sandi    default:
524ed630903Sandi      print '[unknown link type]';
525ed630903Sandi  }
526ed630903Sandi}
527ed630903Sandi
528ed630903Sandi/**
5296b13307fSandi * Print the search form
5306b13307fSandi *
5316b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5326b13307fSandi */
5336b13307fSandifunction tpl_searchform(){
5346b13307fSandi  global $lang;
535c1e3b7d9Smatthiasgrimm  global $ACT;
536c1e3b7d9Smatthiasgrimm
5375e163278SAndreas Gohr  print '<form action="'.wl().'" accept-charset="utf-8" class="search" name="search">';
5386b13307fSandi  print '<input type="hidden" name="do" value="search" />';
539c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
540c1e3b7d9Smatthiasgrimm
541c1e3b7d9Smatthiasgrimm  if ($ACT == 'search')
542c1e3b7d9Smatthiasgrimm    print 'value="'.$_REQUEST['id'].'" '; /* keep search input as long as user stays on search page */
543c1e3b7d9Smatthiasgrimm
544c1e3b7d9Smatthiasgrimm  print 'id="qsearch_in" accesskey="f" name="id" class="edit" onkeyup="ajax_qsearch.call(\'qsearch_in\',\'qsearch_out\')" />';
5456b13307fSandi  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" />';
5469a3ea4f8Sandi  print '<div id="qsearch_out" class="ajax_qsearch" onclick="this.style.display=\'none\'"></div>';
5476b13307fSandi  print '</form>';
5486b13307fSandi}
5496b13307fSandi
5506b13307fSandi/**
5516b13307fSandi * Print the breadcrumbs trace
5526b13307fSandi *
5536b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
5546b13307fSandi */
5556b13307fSandifunction tpl_breadcrumbs(){
5566b13307fSandi  global $lang;
5576b13307fSandi  global $conf;
5586b13307fSandi
5596b13307fSandi  //check if enabled
5606b13307fSandi  if(!$conf['breadcrumbs']) return;
5616b13307fSandi
5626b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
563265e3787Sandi
564265e3787Sandi  //reverse crumborder in right-to-left mode
565265e3787Sandi  if($lang['direction'] == 'rtl') $crumbs = array_reverse($crumbs,true);
566265e3787Sandi
56740eb54bbSjan  //render crumbs, highlight the last one
5686b13307fSandi  print $lang['breadcrumb'].':';
56940eb54bbSjan  $last = count($crumbs);
57040eb54bbSjan  $i = 0;
571a77f5846Sjan  foreach ($crumbs as $id => $name){
57240eb54bbSjan    $i++;
573265e3787Sandi    print ' <span class="bcsep">&raquo;</span> ';
57492795d04Sandi    if ($i == $last) print '<span class="curid">';
575a77f5846Sjan    tpl_link(wl($id),$name,'class="breadcrumbs" title="'.$id.'"');
57692795d04Sandi    if ($i == $last) print '</span>';
5776b13307fSandi  }
5786b13307fSandi}
5796b13307fSandi
5806b13307fSandi/**
5811734437eSandi * Hierarchical breadcrumbs
5821734437eSandi *
5831734437eSandi * This code was suggested as replacement for the usual breadcrumbs
5841734437eSandi * trail in the Wiki and was modified by me.
5851734437eSandi * It only makes sense with a deep site structure.
5861734437eSandi *
5871734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
5886bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
5891734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
5906bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
5911734437eSandi */
5921734437eSandifunction tpl_youarehere(){
5931734437eSandi  global $conf;
5941734437eSandi  global $ID;
5951734437eSandi  global $lang;
5961734437eSandi
5971734437eSandi
5981734437eSandi  $parts     = explode(':', $ID);
5991734437eSandi
6006bd812dfSNigel McNie  // Perhaps a $lang['tree'] could be defined? "Trace" isn't too appropriate
6016bd812dfSNigel McNie  //print $lang['tree'].': ';
6021734437eSandi  print $lang['breadcrumb'].': ';
6031734437eSandi
6041734437eSandi  //always print the startpage
6051734437eSandi  if( $a_part[0] != $conf['start'] )
6061734437eSandi    tpl_link(wl($conf['start']),$conf['start'],'title="'.$conf['start'].'"');
6071734437eSandi
6081734437eSandi  $page = '';
6091734437eSandi  foreach ($parts as $part){
6106bd812dfSNigel McNie        // Skip startpage if already done
6116bd812dfSNigel McNie        if ($part == $conf['start']) continue;
6126bd812dfSNigel McNie
6131734437eSandi          print ' &raquo; ';
6141734437eSandi    $page .= $part;
6151734437eSandi
6161734437eSandi    if(file_exists(wikiFN($page))){
6171734437eSandi      tpl_link(wl($page),$part,'title="'.$page.'"');
6181734437eSandi    }else{
6196bd812dfSNigel McNie      // Print the link, but mark as not-existing, as for other non-existing links
6206bd812dfSNigel McNie      tpl_link(wl($page),$part,'title="'.$page.'" class="wikilink2"');
6216bd812dfSNigel McNie      //print $page;
6221734437eSandi    }
6231734437eSandi
6241734437eSandi    $page .= ':';
6251734437eSandi  }
6261734437eSandi}
6271734437eSandi
6281734437eSandi/**
6296b13307fSandi * Print info if the user is logged in
630a2488c3cSMatthias Grimm * and show full name in that case
6316b13307fSandi *
6326b13307fSandi * Could be enhanced with a profile link in future?
6336b13307fSandi *
6346b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6356b13307fSandi */
6366b13307fSandifunction tpl_userinfo(){
6376b13307fSandi  global $lang;
638a2488c3cSMatthias Grimm  global $INFO;
6396b13307fSandi  if($_SERVER['REMOTE_USER'])
640a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
6416b13307fSandi}
6426b13307fSandi
6436b13307fSandi/**
6446b13307fSandi * Print some info about the current page
6456b13307fSandi *
6466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6476b13307fSandi */
6486b13307fSandifunction tpl_pageinfo(){
6496b13307fSandi  global $conf;
6506b13307fSandi  global $lang;
6516b13307fSandi  global $INFO;
6526b13307fSandi  global $REV;
6536b13307fSandi
6546b13307fSandi  // prepare date and path
6556b13307fSandi  $fn = $INFO['filepath'];
6566b13307fSandi  if(!$conf['fullpath']){
6576b13307fSandi    if($REV){
6586b13307fSandi      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
6596b13307fSandi    }else{
6606b13307fSandi      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
6616b13307fSandi    }
6626b13307fSandi  }
663bee6dc82Sandi  $fn = utf8_decodeFN($fn);
6646b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
6656b13307fSandi
6666b13307fSandi  // print it
6676b13307fSandi  if($INFO['exists']){
6686b13307fSandi    print $fn;
6696b13307fSandi    print ' &middot; ';
6706b13307fSandi    print $lang['lastmod'];
6716b13307fSandi    print ': ';
6726b13307fSandi    print $date;
6736b13307fSandi    if($INFO['editor']){
6746b13307fSandi      print ' '.$lang['by'].' ';
6756b13307fSandi      print $INFO['editor'];
6766b13307fSandi    }
6776b13307fSandi    if($INFO['locked']){
6786b13307fSandi      print ' &middot; ';
6796b13307fSandi      print $lang['lockedby'];
6806b13307fSandi      print ': ';
6816b13307fSandi      print $INFO['locked'];
6826b13307fSandi    }
6836b13307fSandi  }
6846b13307fSandi}
6856b13307fSandi
686820fa24bSandi/**
687820fa24bSandi * Print a list of namespaces containing media files
688820fa24bSandi *
689820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
690820fa24bSandi */
691820fa24bSandifunction tpl_medianamespaces(){
692820fa24bSandi	global $conf;
693820fa24bSandi
694820fa24bSandi  $data = array();
695820fa24bSandi  search($data,$conf['mediadir'],'search_namespaces',array());
696820fa24bSandi  print html_buildlist($data,'idx',media_html_list_namespaces);
697820fa24bSandi}
698820fa24bSandi
699820fa24bSandi/**
700820fa24bSandi * Print a list of mediafiles in the current namespace
701820fa24bSandi *
702820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
703820fa24bSandi */
704820fa24bSandifunction tpl_mediafilelist(){
705820fa24bSandi  global $conf;
706820fa24bSandi  global $lang;
707820fa24bSandi  global $NS;
7088ef6b7caSandi  global $AUTH;
709820fa24bSandi  $dir = utf8_encodeFN(str_replace(':','/',$NS));
710820fa24bSandi
711820fa24bSandi  $data = array();
712820fa24bSandi  search($data,$conf['mediadir'],'search_media',array(),$dir);
713820fa24bSandi
714820fa24bSandi  if(!count($data)){
7154b15e09dSAndreas Gohr    ptln('<div class="nothing">'.$lang['nothingfound'].'</div>');
716820fa24bSandi    return;
717820fa24bSandi  }
718820fa24bSandi
719820fa24bSandi  ptln('<ul>',2);
720820fa24bSandi  foreach($data as $item){
721820fa24bSandi    ptln('<li>',4);
722*6e37f3d9SAndreas Gohr    ptln('<a href="javascript:mediaSelect(\':'.$item['id'].'\')">'.
723820fa24bSandi         utf8_decodeFN($item['file']).
724820fa24bSandi         '</a>',6);
7258ef6b7caSandi
7268ef6b7caSandi    //prepare deletion button
7278ef6b7caSandi    if($AUTH >= AUTH_DELETE){
7288ef6b7caSandi      $ask  = $lang['del_confirm'].'\\n';
7298ef6b7caSandi      $ask .= $item['id'];
7308ef6b7caSandi
731f62ea8a1Sandi      $del = '<a href="'.DOKU_BASE.'lib/exe/media.php?delete='.urlencode($item['id']).'" '.
7328ef6b7caSandi             'onclick="return confirm(\''.$ask.'\')" onkeypress="return confirm(\''.$ask.'\')">'.
733f62ea8a1Sandi             '<img src="'.DOKU_BASE.'lib/images/del.png" alt="'.$lang['btn_delete'].'" '.
7348ef6b7caSandi             'align="bottom" title="'.$lang['btn_delete'].'" /></a>';
7358ef6b7caSandi    }else{
7368ef6b7caSandi      $del = '';
7378ef6b7caSandi    }
7388ef6b7caSandi
739820fa24bSandi    if($item['isimg']){
74023a34783SAndreas Gohr      $w = $item['meta']->getField('File.Width');
74123a34783SAndreas Gohr      $h = $item['meta']->getField('File.Height');
742820fa24bSandi
7438ef6b7caSandi      ptln('('.$w.'&#215;'.$h.' '.filesize_h($item['size']).')',6);
7448ef6b7caSandi      ptln($del.'<br />',6);
745478cd997SAndreas Gohr      ptln('<div class="imagemeta">',6);
7469fcd3d1dSandi
74723a34783SAndreas Gohr      //build thumbnail
74823a34783SAndreas Gohr      print '<a href="javascript:mediaSelect(\''.$item['id'].'\')">';
74923a34783SAndreas Gohr
75023a34783SAndreas Gohr      if($w>120 || $h>120){
75123a34783SAndreas Gohr        $ratio = $item['meta']->getResizeRatio(120);
75223a34783SAndreas Gohr        $w = floor($w * $ratio);
75323a34783SAndreas Gohr        $h = floor($h * $ratio);
7549fcd3d1dSandi      }
75523a34783SAndreas Gohr
7566de3759aSAndreas Gohr      $src = ml($item['id'],array('w'=>$w,'h'=>$h));
75723a34783SAndreas Gohr
75823a34783SAndreas Gohr      $p = array();
75923a34783SAndreas Gohr      $p['width']  = $w;
76023a34783SAndreas Gohr      $p['height'] = $h;
76123a34783SAndreas Gohr      $p['alt']    = $item['id'];
76223a34783SAndreas Gohr      $p['class']  = 'thumb';
76323a34783SAndreas Gohr      $att = buildAttributes($p);
76423a34783SAndreas Gohr
76523a34783SAndreas Gohr      print '<img src="'.$src.'" '.$att.' />';
7669fcd3d1dSandi      print '</a>';
767820fa24bSandi
7686d861d12SAndreas Gohr      //read EXIF/IPTC data
76923a34783SAndreas Gohr      $t = $item['meta']->getField('IPTC.Headline');
7706d861d12SAndreas Gohr      if($t) print '<b>'.$t.'</b><br />';
7716d861d12SAndreas Gohr
77236df6fa3SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
77336df6fa3SAndreas Gohr                                         'EXIF.TIFFImageDescription',
77436df6fa3SAndreas Gohr                                         'EXIF.TIFFUserComment'));
7756d861d12SAndreas Gohr      if($t) print $t.'<br />';
7766d861d12SAndreas Gohr
77723a34783SAndreas Gohr      $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category'));
7786d861d12SAndreas Gohr      if($t) print '<i>'.$t.'</i><br />';
7796d861d12SAndreas Gohr
78036df6fa3SAndreas Gohr      //add edit button
78136df6fa3SAndreas Gohr      if($AUTH >= AUTH_UPLOAD && $item['meta']->getField('File.Mime') == 'image/jpeg'){
78236df6fa3SAndreas Gohr        print '<a href="'.DOKU_BASE.'lib/exe/media.php?edit='.urlencode($item['id']).'">';
78336df6fa3SAndreas Gohr        print '<img src="'.DOKU_BASE.'lib/images/edit.gif" alt="'.$lang['metaedit'].'" title="'.$lang['metaedit'].'" />';
78436df6fa3SAndreas Gohr        print '</a>';
78536df6fa3SAndreas Gohr      }
78636df6fa3SAndreas Gohr
7876d861d12SAndreas Gohr      ptln('</div>',6);
788820fa24bSandi    }else{
789820fa24bSandi      ptln ('('.filesize_h($item['size']).')',6);
7908ef6b7caSandi      ptln($del,6);
791820fa24bSandi    }
792820fa24bSandi    ptln('</li>',4);
793820fa24bSandi  }
794820fa24bSandi  ptln('</ul>',2);
795820fa24bSandi}
796820fa24bSandi
797820fa24bSandi/**
798d67ca2c0Smatthiasgrimm * show references to a media file
799d67ca2c0Smatthiasgrimm * References uses the same visual as search results and share
800d67ca2c0Smatthiasgrimm * their CSS tags except pagenames won't be links.
801d67ca2c0Smatthiasgrimm *
802d67ca2c0Smatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
803d67ca2c0Smatthiasgrimm */
804d67ca2c0Smatthiasgrimmfunction tpl_showreferences(&$data){
805d67ca2c0Smatthiasgrimm  global $lang;
806d67ca2c0Smatthiasgrimm
807d67ca2c0Smatthiasgrimm  $hidden=0; //count of hits without read permission
808d67ca2c0Smatthiasgrimm
809d67ca2c0Smatthiasgrimm  if(count($data)){
810d67ca2c0Smatthiasgrimm    usort($data,'sort_search_fulltext');
811d67ca2c0Smatthiasgrimm    foreach($data as $row){
812d67ca2c0Smatthiasgrimm      if(auth_quickaclcheck($row['id']) >= AUTH_READ){
813d67ca2c0Smatthiasgrimm        print '<div class="search_result">';
814d67ca2c0Smatthiasgrimm        print '<span class="mediaref_ref">'.$row['id'].'</span>';
815d67ca2c0Smatthiasgrimm        print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
816d67ca2c0Smatthiasgrimm        print '<div class="search_snippet">'.$row['snippet'].'</div>';
817d67ca2c0Smatthiasgrimm        print '</div>';
818d67ca2c0Smatthiasgrimm      }else
819d67ca2c0Smatthiasgrimm        $hidden++;
820d67ca2c0Smatthiasgrimm    }
821d67ca2c0Smatthiasgrimm    if ($hidden){
822d67ca2c0Smatthiasgrimm      print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
823d67ca2c0Smatthiasgrimm    }
824d67ca2c0Smatthiasgrimm  }
825d67ca2c0Smatthiasgrimm}
826d67ca2c0Smatthiasgrimm
827d67ca2c0Smatthiasgrimm/**
828820fa24bSandi * Print the media upload form if permissions are correct
829820fa24bSandi *
830820fa24bSandi * @author Andreas Gohr <andi@splitbrain.org>
831820fa24bSandi */
832820fa24bSandifunction tpl_mediauploadform(){
833820fa24bSandi  global $NS;
834820fa24bSandi  global $UPLOADOK;
8358ef6b7caSandi  global $AUTH;
836820fa24bSandi  global $lang;
837820fa24bSandi
838820fa24bSandi  if(!$UPLOADOK) return;
839820fa24bSandi
8408dd5e97bSandi  ptln('<form action="'.DOKU_BASE.'lib/exe/media.php" name="upload"'.
841820fa24bSandi       ' method="post" enctype="multipart/form-data">',2);
842820fa24bSandi  ptln($lang['txt_upload'].':<br />',4);
843820fa24bSandi  ptln('<input type="file" name="upload" class="edit" onchange="suggestWikiname();" />',4);
844820fa24bSandi  ptln('<input type="hidden" name="ns" value="'.hsc($NS).'" /><br />',4);
845820fa24bSandi  ptln($lang['txt_filename'].'<br />',4);
846820fa24bSandi  ptln('<input type="text" name="id" class="edit" />',4);
847820fa24bSandi  ptln('<input type="submit" class="button" value="'.$lang['btn_upload'].'" accesskey="s" />',4);
8488ef6b7caSandi  if($AUTH >= AUTH_DELETE){
849b6912aeaSAndreas Gohr    ptln('<label for="ow"><input type="checkbox" name="ow" value="1" id="ow">'.$lang['txt_overwrt'].'</label>',4);
8508ef6b7caSandi  }
851820fa24bSandi  ptln('</form>',2);
852820fa24bSandi}
853820fa24bSandi
85487c434ceSAndreas Gohr/**
85587c434ceSAndreas Gohr * Prints the name of the given page (current one if none given).
85687c434ceSAndreas Gohr *
85787c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
85887c434ceSAndreas Gohr * the given ID is printed.
85987c434ceSAndreas Gohr *
86087c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
86187c434ceSAndreas Gohr */
86287c434ceSAndreas Gohrfunction tpl_pagetitle($id=null){
86387c434ceSAndreas Gohr  global $conf;
86487c434ceSAndreas Gohr  if(is_null($id)){
86587c434ceSAndreas Gohr    global $ID;
86687c434ceSAndreas Gohr    $id = $ID;
86787c434ceSAndreas Gohr  }
86887c434ceSAndreas Gohr
86987c434ceSAndreas Gohr  $name = $id;
87087c434ceSAndreas Gohr  if ($conf['useheading']) {
87187c434ceSAndreas Gohr    $title = p_get_first_heading($id);
87287c434ceSAndreas Gohr    if ($title) $name = $title;
87387c434ceSAndreas Gohr  }
87487c434ceSAndreas Gohr  print hsc($name);
87587c434ceSAndreas Gohr}
876340756e4Sandi
87755efc227SAndreas Gohr/**
87855efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
87955efc227SAndreas Gohr *
88055efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
88155efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
88255efc227SAndreas Gohr *
88355efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
88455efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
88555efc227SAndreas Gohr * to the names of the latter one)
88655efc227SAndreas Gohr *
88736df6fa3SAndreas Gohr * Only allowed in: detail.php, mediaedit.php
88855efc227SAndreas Gohr *
88955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
89055efc227SAndreas Gohr */
89155efc227SAndreas Gohrfunction tpl_img_getTag($tags,$alt=''){
89255efc227SAndreas Gohr  // Init Exif Reader
89355efc227SAndreas Gohr  global $SRC;
89455efc227SAndreas Gohr  static $meta = null;
89555efc227SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($SRC);
89655efc227SAndreas Gohr  if($meta === false) return $alt;
89755efc227SAndreas Gohr  $info = $meta->getField($tags);
89855efc227SAndreas Gohr  if($info == false) return $alt;
89955efc227SAndreas Gohr  return $info;
90055efc227SAndreas Gohr}
90155efc227SAndreas Gohr
90255efc227SAndreas Gohr/**
90355efc227SAndreas Gohr * Prints the image with a link to the full sized version
90455efc227SAndreas Gohr *
90555efc227SAndreas Gohr * Only allowed in: detail.php
90655efc227SAndreas Gohr */
907f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
90855efc227SAndreas Gohr  global $IMG;
90955efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
91055efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
91155efc227SAndreas Gohr
91255efc227SAndreas Gohr  //resize to given max values
91323a34783SAndreas Gohr  $ratio = 1;
91423a34783SAndreas Gohr  if($w >= $h){
915f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
91655efc227SAndreas Gohr      $ratio = $maxwidth/$w;
917f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
91855efc227SAndreas Gohr      $ratio = $maxheight/$h;
91955efc227SAndreas Gohr    }
92055efc227SAndreas Gohr  }else{
921f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
92255efc227SAndreas Gohr      $ratio = $maxheight/$h;
923f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
92455efc227SAndreas Gohr      $ratio = $maxwidth/$w;
92555efc227SAndreas Gohr    }
92655efc227SAndreas Gohr  }
92755efc227SAndreas Gohr  if($ratio){
92855efc227SAndreas Gohr    $w = floor($ratio*$w);
92955efc227SAndreas Gohr    $h = floor($ratio*$h);
93055efc227SAndreas Gohr  }
93155efc227SAndreas Gohr
9326de3759aSAndreas Gohr  //prepare URLs
9336de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
9346de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
93555efc227SAndreas Gohr
9362684e50aSAndreas Gohr  //prepare attributes
93755efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
9382684e50aSAndreas Gohr  $p = array();
9392684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9402684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9412684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9422684e50aSAndreas Gohr  if($alt){
9432684e50aSAndreas Gohr    $p['alt']   = $alt;
9442684e50aSAndreas Gohr    $p['title'] = $alt;
9452684e50aSAndreas Gohr  }else{
9462684e50aSAndreas Gohr    $p['alt'] = '';
9472684e50aSAndreas Gohr  }
9482684e50aSAndreas Gohr  $p = buildAttributes($p);
94955efc227SAndreas Gohr
95055efc227SAndreas Gohr  print '<a href="'.$url.'">';
9516de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
95255efc227SAndreas Gohr  print '</a>';
95355efc227SAndreas Gohr}
95455efc227SAndreas Gohr
9557367b368SAndreas Gohr/**
9567367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
9577367b368SAndreas Gohr * is the inexer function.
9587367b368SAndreas Gohr *
9597367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9607367b368SAndreas Gohr * template
9617367b368SAndreas Gohr */
9627367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9637367b368SAndreas Gohr  global $ID;
9641dad36f5SAndreas Gohr  global $INFO;
9651dad36f5SAndreas Gohr  if(!$INFO['exists']) return;
9661dad36f5SAndreas Gohr
9677367b368SAndreas Gohr  $p = array();
968e68c51baSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.urlencode($ID).
969e68c51baSAndreas Gohr                 '&'.time();
9707367b368SAndreas Gohr  $p['width']  = 1;
9717367b368SAndreas Gohr  $p['height'] = 1;
9727367b368SAndreas Gohr  $p['alt']    = '';
9737367b368SAndreas Gohr  $att = buildAttributes($p);
9747367b368SAndreas Gohr  print "<img $att />";
9757367b368SAndreas Gohr}
9767367b368SAndreas Gohr
977340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 :
978