xref: /dokuwiki/inc/template.php (revision 103c256a6f9161bec0a89e70eb600c84bcb51e50)
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
900976812SAndreas Gohr  if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
10e7cb32dcSAndreas Gohr  require_once(DOKU_CONF.'dokuwiki.php');
116b13307fSandi
126b13307fSandi/**
135a892029SAndreas Gohr * Returns the path to the given template, uses
14524be65dSBen Coburn * default one if the custom version doesn't exist.
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 */
39b8595a66SAndreas Gohrfunction tpl_content($prependTOC=true) {
407ea0913cSchris    global $ACT;
41b8595a66SAndreas Gohr    global $INFO;
42b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
437ea0913cSchris
447ea0913cSchris    ob_start();
45746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
467ea0913cSchris    $html_output = ob_get_clean();
47746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
4854e95700STom N Harris
4954e95700STom N Harris    return !empty($html_output);
507ea0913cSchris}
517ea0913cSchris
527ea0913cSchrisfunction tpl_content_core(){
536b13307fSandi  global $ACT;
546b13307fSandi  global $TEXT;
556b13307fSandi  global $PRE;
566b13307fSandi  global $SUF;
576b13307fSandi  global $SUM;
586b13307fSandi  global $IDX;
596b13307fSandi
606b13307fSandi  switch($ACT){
616b13307fSandi    case 'show':
626b13307fSandi      html_show();
636b13307fSandi      break;
64ea67f144Sandi    case 'preview':
656b13307fSandi      html_edit($TEXT);
666b13307fSandi      html_show($TEXT);
676b13307fSandi      break;
68ee4c4a1bSAndreas Gohr    case 'recover':
69ee4c4a1bSAndreas Gohr      html_edit($TEXT);
70ee4c4a1bSAndreas Gohr      break;
716b13307fSandi    case 'edit':
726b13307fSandi      html_edit();
736b13307fSandi      break;
74ee4c4a1bSAndreas Gohr    case 'draft':
75ee4c4a1bSAndreas Gohr      html_draft();
76ee4c4a1bSAndreas Gohr      break;
776b13307fSandi    case 'wordblock':
786b13307fSandi      html_edit($TEXT,'wordblock');
796b13307fSandi      break;
806b13307fSandi    case 'search':
816b13307fSandi      html_search();
826b13307fSandi      break;
836b13307fSandi    case 'revisions':
8471726d78SBen Coburn      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
8571726d78SBen Coburn      html_revisions($first);
866b13307fSandi      break;
876b13307fSandi    case 'diff':
886b13307fSandi      html_diff();
896b13307fSandi      break;
906b13307fSandi    case 'recent':
915749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
92a39955b0Smatthiasgrimm      html_recent($first);
936b13307fSandi      break;
946b13307fSandi    case 'index':
956b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
966b13307fSandi      break;
976b13307fSandi    case 'backlink':
986b13307fSandi      html_backlinks();
996b13307fSandi      break;
1006b13307fSandi    case 'conflict':
1016b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1026b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
1036b13307fSandi      break;
1046b13307fSandi    case 'locked':
105ee20e7d1Sandi      html_locked();
1066b13307fSandi      break;
1076b13307fSandi    case 'login':
1086b13307fSandi      html_login();
1096b13307fSandi      break;
1106b13307fSandi    case 'register':
1116b13307fSandi      html_register();
1126b13307fSandi      break;
1138b06d178Schris    case 'resendpwd':
1148b06d178Schris      html_resendpwd();
1158b06d178Schris      break;
116820fa24bSandi    case 'denied':
1175e991bd8Sandi      print p_locale_xhtml('denied');
118820fa24bSandi      break;
1198b06d178Schris    case 'profile' :
1208b06d178Schris      html_updateprofile();
1218b06d178Schris      break;
122c19fe9c0Sandi    case 'admin':
123c19fe9c0Sandi      tpl_admin();
124c19fe9c0Sandi      break;
1256b13307fSandi    default:
12624bb549bSchris      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12724bb549bSchris      if ($evt->advise_before())
128ea67f144Sandi        msg("Failed to handle command: ".hsc($ACT),-1);
12924bb549bSchris      $evt->advise_after();
13024bb549bSchris      unset($evt);
13154e95700STom N Harris      return false;
1326b13307fSandi  }
13354e95700STom N Harris  return true;
1346b13307fSandi}
1356b13307fSandi
136c19fe9c0Sandi/**
137b8595a66SAndreas Gohr * Places the TOC where the function is called
138b8595a66SAndreas Gohr *
139b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
140b8595a66SAndreas Gohr * a false argument
141b8595a66SAndreas Gohr *
142b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
143b8595a66SAndreas Gohr */
144b8595a66SAndreas Gohrfunction tpl_toc($return=false){
145b8595a66SAndreas Gohr    global $TOC;
146b8595a66SAndreas Gohr    global $ACT;
147b8595a66SAndreas Gohr    global $ID;
148b8595a66SAndreas Gohr    global $REV;
149b8595a66SAndreas Gohr    global $INFO;
150b8595a66SAndreas Gohr    $toc = array();
151b8595a66SAndreas Gohr
152b8595a66SAndreas Gohr    if(is_array($TOC)){
153b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
154b8595a66SAndreas Gohr        $toc = $TOC;
155b8595a66SAndreas Gohr    }elseif($ACT == 'show' && !$REV){
156b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
157b8595a66SAndreas Gohr        $meta = p_get_metadata($ID, false, true);
158b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])){
159b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
160b8595a66SAndreas Gohr        }else{
1612bb0d541Schris            $tocok = true;
162b8595a66SAndreas Gohr        }
163b8595a66SAndreas Gohr        $toc   = $meta['description']['tableofcontents'];
164b8595a66SAndreas Gohr        if(!$tocok || !is_array($toc) || count($toc) < 3){
165b8595a66SAndreas Gohr            $toc = array();
166b8595a66SAndreas Gohr        }
167b8595a66SAndreas Gohr    }elseif($ACT == 'admin'){
168b8595a66SAndreas Gohr        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
169b8595a66SAndreas Gohr        $plugin = null;
170b8595a66SAndreas Gohr        if (!empty($_REQUEST['page'])) {
171b8595a66SAndreas Gohr            $pluginlist = plugin_list('admin');
172b8595a66SAndreas Gohr            if (in_array($_REQUEST['page'], $pluginlist)) {
173b8595a66SAndreas Gohr                // attempt to load the plugin
174b8595a66SAndreas Gohr                $plugin =& plugin_load('admin',$_REQUEST['page']);
175b8595a66SAndreas Gohr            }
176b8595a66SAndreas Gohr        }
177b8595a66SAndreas Gohr        if ( ($plugin !== null) &&
178b8595a66SAndreas Gohr             (!$plugin->forAdminOnly() || $INFO['isadmin']) ){
179b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
180b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
181b8595a66SAndreas Gohr        }
182b8595a66SAndreas Gohr    }
183b8595a66SAndreas Gohr
184b8595a66SAndreas Gohr    $html = html_TOC($toc);
185b8595a66SAndreas Gohr    if($return) return $html;
186b8595a66SAndreas Gohr    echo $html;
187b8595a66SAndreas Gohr}
188b8595a66SAndreas Gohr
189b8595a66SAndreas Gohr/**
190c19fe9c0Sandi * Handle the admin page contents
191c19fe9c0Sandi *
192c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
193c19fe9c0Sandi */
194c19fe9c0Sandifunction tpl_admin(){
195f8cc712eSAndreas Gohr    global $INFO;
196b8595a66SAndreas Gohr    global $TOC;
19711e2ce22Schris
198b8595a66SAndreas Gohr    $plugin = null;
199bb4866bdSchris    if (!empty($_REQUEST['page'])) {
20011e2ce22Schris        $pluginlist = plugin_list('admin');
20111e2ce22Schris
20211e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
20311e2ce22Schris
20411e2ce22Schris          // attempt to load the plugin
20511e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
20611e2ce22Schris        }
20711e2ce22Schris    }
20811e2ce22Schris
209b8595a66SAndreas Gohr    if ($plugin !== null){
210f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
211f8cc712eSAndreas Gohr            msg('For admins only',-1);
21211e2ce22Schris            html_admin();
213f8cc712eSAndreas Gohr        }else{
214b8595a66SAndreas Gohr            if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
215b8595a66SAndreas Gohr            if($INFO['prependTOC']) tpl_toc();
216f8cc712eSAndreas Gohr            $plugin->html();
217f8cc712eSAndreas Gohr        }
218f8cc712eSAndreas Gohr    }else{
219f8cc712eSAndreas Gohr        html_admin();
220f8cc712eSAndreas Gohr    }
22154e95700STom N Harris    return true;
222c19fe9c0Sandi}
2236b13307fSandi
2246b13307fSandi/**
2256b13307fSandi * Print the correct HTML meta headers
2266b13307fSandi *
2276b13307fSandi * This has to go into the head section of your template.
2286b13307fSandi *
229016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
230f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
2316b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2326b13307fSandi */
233f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
2346b13307fSandi  global $ID;
235d98d4540SBen Coburn  global $REV;
2366b13307fSandi  global $INFO;
2376b13307fSandi  global $ACT;
2384bb1b5aeSAndreas Gohr  global $QUERY;
2396b13307fSandi  global $lang;
240dc57ef04Sandi  global $conf;
2416b13307fSandi  $it=2;
2426b13307fSandi
2437bff22c0SAndreas Gohr  // prepare the head array
2447bff22c0SAndreas Gohr  $head = array();
2457bff22c0SAndreas Gohr
2467bff22c0SAndreas Gohr
2476b13307fSandi  // the usual stuff
2487bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
249da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
250da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
251f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
2527bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
253bb4866bdSchris                           'title'=>$lang['btn_index'] );
254f96fa415SAndreas Gohr
255f96fa415SAndreas Gohr  if($alt){
2567bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2577bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2587bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2597bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2607bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
2614bb1b5aeSAndreas Gohr    if($ACT == 'search'){
2624bb1b5aeSAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2634bb1b5aeSAndreas Gohr                               'title'=>'Search Result',
2644bb1b5aeSAndreas Gohr                               'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
2654bb1b5aeSAndreas Gohr    }
266bae36d94SAndreas Gohr
267bae36d94SAndreas Gohr    if(actionOK('export_xhtml')){
2687bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2697bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'xhtml', '', false, '&'));
270bae36d94SAndreas Gohr    }
271bae36d94SAndreas Gohr
272bae36d94SAndreas Gohr    if(actionOK('export_raw')){
2737bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2747bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'raw', '', false, '&'));
275f96fa415SAndreas Gohr    }
276bae36d94SAndreas Gohr  }
2776b13307fSandi
2786b13307fSandi  // setup robot tags apropriate for different modes
2794f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2806b13307fSandi    if($INFO['exists']){
2816b13307fSandi      //delay indexing:
2826b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2837bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2846b13307fSandi      }else{
2857bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2866b13307fSandi      }
2876b13307fSandi    }else{
2887bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
2896b13307fSandi    }
2907a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2917bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2926b13307fSandi  }else{
2937bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2946b13307fSandi  }
2956b13307fSandi
296831800b8SAndreas Gohr  // set metadata
297831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
298831800b8SAndreas Gohr    // date of modification
299831800b8SAndreas Gohr    if($REV){
3007bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
301831800b8SAndreas Gohr    }else{
3027bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
303831800b8SAndreas Gohr    }
304831800b8SAndreas Gohr
305831800b8SAndreas Gohr    // keywords (explicit or implicit)
306bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
3077bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
308831800b8SAndreas Gohr    }else{
3097bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
310831800b8SAndreas Gohr    }
311831800b8SAndreas Gohr  }
312831800b8SAndreas Gohr
31378a6aeb1SAndreas Gohr  // load stylesheets
3147aaa4c46Smartin.tschofen  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
3157aaa4c46Smartin.tschofen                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all');
3167bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
3177bff22c0SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php');
3187bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
319615960feSTom N Harris                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print');
320bad31ae9SAndreas Gohr
32178a6aeb1SAndreas Gohr  // load javascript
322041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
323bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
3243df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
3253df72098SAndreas Gohr    $js_edit  = 1;
3263df72098SAndreas Gohr    $js_write = 0;
3273df72098SAndreas Gohr  }
3283df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
3297bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
330c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
331aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
3327bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
333c591aabeSAndreas Gohr    }
3347bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
3357bff22c0SAndreas Gohr                               '_data'=> $script);
336c591aabeSAndreas Gohr  }
3377bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
3387bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
3397bff22c0SAndreas Gohr
3407bff22c0SAndreas Gohr  // trigger event here
341016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
34254e95700STom N Harris  return true;
3437bff22c0SAndreas Gohr}
3447bff22c0SAndreas Gohr
3457bff22c0SAndreas Gohr/**
3467bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3477bff22c0SAndreas Gohr *
3487bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3497bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3507bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3517bff22c0SAndreas Gohr *
3527bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
3531304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3547bff22c0SAndreas Gohr *
3557bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3567bff22c0SAndreas Gohr */
3577bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3587bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
3597bff22c0SAndreas Gohr    foreach($inst as $attr){
3607bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
3617bff22c0SAndreas Gohr      if(isset($attr['_data'])){
362e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
363e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
364e226efe1SAndreas Gohr                             $attr['_data'].
365e226efe1SAndreas Gohr                             "\n//--><!]]>";
366e226efe1SAndreas Gohr
3671304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3687bff22c0SAndreas Gohr      }else{
3697bff22c0SAndreas Gohr        echo '/>';
3707bff22c0SAndreas Gohr      }
3717bff22c0SAndreas Gohr      echo "\n";
3727bff22c0SAndreas Gohr    }
3737bff22c0SAndreas Gohr  }
3746b13307fSandi}
3756b13307fSandi
3766b13307fSandi/**
3776b13307fSandi * Print a link
3786b13307fSandi *
3795e163278SAndreas Gohr * Just builds a link.
3806b13307fSandi *
3816b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3826b13307fSandi */
3836b13307fSandifunction tpl_link($url,$name,$more=''){
3845e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3856b13307fSandi  if ($more) print ' '.$more;
3866b13307fSandi  print ">$name</a>";
38754e95700STom N Harris  return true;
3886b13307fSandi}
3896b13307fSandi
3906b13307fSandi/**
39155efc227SAndreas Gohr * Prints a link to a WikiPage
39255efc227SAndreas Gohr *
39355efc227SAndreas Gohr * Wrapper around html_wikilink
39455efc227SAndreas Gohr *
39555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
39655efc227SAndreas Gohr */
39755efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
39855efc227SAndreas Gohr  print html_wikilink($id,$name);
39954e95700STom N Harris  return true;
40055efc227SAndreas Gohr}
40155efc227SAndreas Gohr
40255efc227SAndreas Gohr/**
403a3ec5f4aSmatthiasgrimm * get the parent page
404a3ec5f4aSmatthiasgrimm *
405a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
406a3ec5f4aSmatthiasgrimm * returns false if none is available
407a3ec5f4aSmatthiasgrimm *
408377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
409a3ec5f4aSmatthiasgrimm */
410377f9e97SAndreas Gohrfunction tpl_getparent($id){
411a3ec5f4aSmatthiasgrimm  global $conf;
412377f9e97SAndreas Gohr  $parent = getNS($id).':';
413377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
414a197105eSmatthiasgrimm  if($parent == $id) {
415a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
416a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
417a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
418377f9e97SAndreas Gohr    if($parent == $id) return false;
419a197105eSmatthiasgrimm  }
420377f9e97SAndreas Gohr  return $parent;
421a3ec5f4aSmatthiasgrimm}
422a3ec5f4aSmatthiasgrimm
423a3ec5f4aSmatthiasgrimm/**
4246b13307fSandi * Print one of the buttons
4256b13307fSandi *
4266b13307fSandi * Available Buttons are
4276b13307fSandi *
428ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
4296b13307fSandi *  history     - old revisions
4306b13307fSandi *  recent      - recent changes
4316b13307fSandi *  login       - login/logout button - if ACL enabled
432d449b912SDenis Simakov *  profile     - user profile button (if logged in)
4336b13307fSandi *  index       - The index
434c19fe9c0Sandi *  admin       - admin page - if enough rights
4356b13307fSandi *  top         - a back to top button
436a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
437bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
438d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
4396b13307fSandi *
4406b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
441a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
4426b13307fSandi */
4436b13307fSandifunction tpl_button($type){
444b158d625SSteven Danz  global $ACT;
4456b13307fSandi  global $ID;
446d98d4540SBen Coburn  global $REV;
447d67ca2c0Smatthiasgrimm  global $NS;
448c19fe9c0Sandi  global $INFO;
4496b13307fSandi  global $conf;
450cd52f92dSchris  global $auth;
4516b13307fSandi
45275e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
45375e487e9SAndreas Gohr  $ctype = $type;
45475e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
45554e95700STom N Harris  if(!actionOK($ctype)) return false;
456409d7af7SAndreas Gohr
4576b13307fSandi  switch($type){
4586b13307fSandi    case 'edit':
459409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
460409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
461409d7af7SAndreas Gohr        if($INFO['writable']){
462bb4866bdSchris          if(!empty($INFO['draft'])){
463409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
464409d7af7SAndreas Gohr          }else{
465409d7af7SAndreas Gohr            if($INFO['exists']){
466409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
467409d7af7SAndreas Gohr            }else{
468409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
469409d7af7SAndreas Gohr            }
470409d7af7SAndreas Gohr          }
471409d7af7SAndreas Gohr        }else{
472409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
473409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
474409d7af7SAndreas Gohr        }
475409d7af7SAndreas Gohr      }else{
476409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
477409d7af7SAndreas Gohr      }
47854e95700STom N Harris      return true;
4796b13307fSandi    case 'history':
4805bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
48154e95700STom N Harris      return true;
4826b13307fSandi    case 'recent':
4835bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
48454e95700STom N Harris      return true;
4856b13307fSandi    case 'index':
4865bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
48754e95700STom N Harris      return true;
488a3ec5f4aSmatthiasgrimm    case 'back':
4896222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4906222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
49154e95700STom N Harris        return true;
492a3ec5f4aSmatthiasgrimm      }
49354e95700STom N Harris      return false;
4946b13307fSandi    case 'top':
4956b13307fSandi      print html_topbtn();
49654e95700STom N Harris      return true;
4976b13307fSandi    case 'login':
4986957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
4996b13307fSandi        if($_SERVER['REMOTE_USER']){
500cc670e1bSMichael Klier          print html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken()));
5016b13307fSandi        }else{
502cc670e1bSMichael Klier          print html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken()));
5036b13307fSandi        }
50454e95700STom N Harris        return true;
5056b13307fSandi      }
50654e95700STom N Harris      return false;
507c19fe9c0Sandi    case 'admin':
50854e95700STom N Harris      if($INFO['ismanager']){
5095bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
51054e95700STom N Harris        return true;
51154e95700STom N Harris      }
51254e95700STom N Harris      return false;
5131380fc45SAndreas Gohr    case 'subscription':
5146957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
515b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
5161380fc45SAndreas Gohr          if($INFO['subscribed']){
5171380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
518b158d625SSteven Danz          } else {
5191380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
520b158d625SSteven Danz          }
52154e95700STom N Harris          return true;
522b158d625SSteven Danz        }
523b158d625SSteven Danz      }
52454e95700STom N Harris      return false;
525f00151b4Schris    case 'backlink':
526f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
52754e95700STom N Harris      return true;
5288b06d178Schris    case 'profile':
5296957b2eaSAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth &&
53036223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
5318b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
53254e95700STom N Harris        return true;
5338b06d178Schris      }
53454e95700STom N Harris      return false;
535c19fe9c0Sandi    default:
536c19fe9c0Sandi      print '[unknown button type]';
53754e95700STom N Harris      return true;
5386b13307fSandi  }
5396b13307fSandi}
5406b13307fSandi
5416b13307fSandi/**
542ed630903Sandi * Like the action buttons but links
543ed630903Sandi *
544ed630903Sandi * Available links are
545ed630903Sandi *
546d449b912SDenis Simakov *  edit    - edit/create/show link
547ed630903Sandi *  history - old revisions
548ed630903Sandi *  recent  - recent changes
549d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
550d449b912SDenis Simakov *  profile - user profile link (if logged in)
551ed630903Sandi *  index   - The index
552ed630903Sandi *  admin   - admin page - if enough rights
553d449b912SDenis Simakov *  top     - a back to top link
554d449b912SDenis Simakov *  back    - a back to parent link - if available
555bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
556d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
557ed630903Sandi *
558ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
559a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
560ed630903Sandi * @see    tpl_button
561ed630903Sandi */
562c97dfb07SAndreas Gohrfunction tpl_actionlink($type,$pre='',$suf='',$inner=''){
563ed630903Sandi  global $ID;
564ed630903Sandi  global $INFO;
565ed630903Sandi  global $REV;
566ed630903Sandi  global $ACT;
567ed630903Sandi  global $conf;
568ed630903Sandi  global $lang;
569cd52f92dSchris  global $auth;
570ed630903Sandi
57175e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
57275e487e9SAndreas Gohr  $ctype = $type;
57375e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
57454e95700STom N Harris  if(!actionOK($ctype)) return false;
575409d7af7SAndreas Gohr
576ed630903Sandi  switch($type){
577ed630903Sandi    case 'edit':
578ed630903Sandi      #most complicated type - we need to decide on current action
579ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
580ed630903Sandi        if($INFO['writable']){
581b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
582b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
583c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_draft']).$suf,
584f6547e5dSAndreas Gohr                       'class="action edit" accesskey="e" rel="nofollow"');
585b8a111f5SMichael Klier          } else {
586ed630903Sandi            if($INFO['exists']){
587ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
588c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_edit']).$suf,
589b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
590ed630903Sandi            }else{
591ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
592c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_create']).$suf,
593b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
594ed630903Sandi            }
595b8a111f5SMichael Klier          }
596ed630903Sandi        }else{
597409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
598ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
599c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_source']).$suf,
600b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
601ed630903Sandi        }
602ed630903Sandi      }else{
603ed630903Sandi          tpl_link(wl($ID,'do=show'),
604c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_show']).$suf,
605b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
606ed630903Sandi      }
607c059e1a6SAndreas Gohr      return true;
608ed630903Sandi    case 'history':
609c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=revisions'),
610c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_revs']).$suf,
611c97dfb07SAndreas Gohr               'class="action revisions" accesskey="o" rel="nofollow"');
612c059e1a6SAndreas Gohr      return true;
613ed630903Sandi    case 'recent':
614c97dfb07SAndreas Gohr      tpl_link(wl('','do=recent'),
615c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_recent']).$suf,
616c97dfb07SAndreas Gohr              'class="action recent" accesskey="r" rel="nofollow"');
617c059e1a6SAndreas Gohr      return true;
618ed630903Sandi    case 'index':
619c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=index'),
620c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_index']).$suf,
621c97dfb07SAndreas Gohr              'class="action index" accesskey="x" rel="nofollow"');
622c059e1a6SAndreas Gohr      return true;
623ed630903Sandi    case 'top':
624c97dfb07SAndreas Gohr      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.
625c97dfb07SAndreas Gohr            $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>';
626c059e1a6SAndreas Gohr      return true;
627a3ec5f4aSmatthiasgrimm    case 'back':
628f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
629c97dfb07SAndreas Gohr        tpl_link(wl($parent,'do=show'),
630c97dfb07SAndreas Gohr        $pre.(($inner)?$inner:$lang['btn_back']).$suf,
631c97dfb07SAndreas Gohr        'class="action back" accesskey="b" rel="nofollow"');
632c059e1a6SAndreas Gohr        return true;
633a3ec5f4aSmatthiasgrimm      }
634c059e1a6SAndreas Gohr      return false;
635ed630903Sandi    case 'login':
6366957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
637ed630903Sandi        if($_SERVER['REMOTE_USER']){
638cc670e1bSMichael Klier          tpl_link(wl($ID,'do=logout&amp;sectok='.getSecurityToken()),
639c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_logout']).$suf,
640c97dfb07SAndreas Gohr                   'class="action logout" rel="nofollow"');
641ed630903Sandi        }else{
642cc670e1bSMichael Klier          tpl_link(wl($ID,'do=login&amp;sectok='.getSecurityToken()),
643c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_login']).$suf,
644c97dfb07SAndreas Gohr                   'class="action login" rel="nofollow"');
645ed630903Sandi        }
646c059e1a6SAndreas Gohr        return true;
647ed630903Sandi      }
648c059e1a6SAndreas Gohr      return false;
649ed630903Sandi    case 'admin':
650f8cc712eSAndreas Gohr      if($INFO['ismanager']){
651c97dfb07SAndreas Gohr        tpl_link(wl($ID,'do=admin'),
652c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_admin']).$suf,
653c97dfb07SAndreas Gohr                 'class="action admin" rel="nofollow"');
654c059e1a6SAndreas Gohr        return true;
655c059e1a6SAndreas Gohr      }
656c059e1a6SAndreas Gohr      return false;
657f9eb5648Ssteven-danz   case 'subscribe':
658075f000fSChristopher Arndt   case 'subscription':
6596957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
660b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
661075f000fSChristopher Arndt          if($INFO['subscribed']) {
662c97dfb07SAndreas Gohr            tpl_link(wl($ID,'do=unsubscribe'),
663c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_unsubscribe']).$suf,
664c97dfb07SAndreas Gohr                     'class="action unsubscribe" rel="nofollow"');
665b158d625SSteven Danz          } else {
666c97dfb07SAndreas Gohr            tpl_link(wl($ID,'do=subscribe'),
667c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf,
668c97dfb07SAndreas Gohr                     'class="action subscribe" rel="nofollow"');
669b158d625SSteven Danz          }
670c059e1a6SAndreas Gohr          return true;
671b158d625SSteven Danz        }
672b158d625SSteven Danz      }
673c059e1a6SAndreas Gohr      return false;
674f00151b4Schris    case 'backlink':
675c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=backlink'),
676c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_backlink']).$suf,
677c97dfb07SAndreas Gohr               'class="action backlink" rel="nofollow"');
678c059e1a6SAndreas Gohr      return true;
6798b06d178Schris    case 'profile':
6806957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
68136223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
682c97dfb07SAndreas Gohr        tpl_link(wl($ID,'do=profile'),
683c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_profile']).$suf,
684c97dfb07SAndreas Gohr                 'class="action profile" rel="nofollow"');
685c059e1a6SAndreas Gohr        return true;
6868b06d178Schris      }
687c059e1a6SAndreas Gohr      return false;
688ed630903Sandi    default:
689ed630903Sandi      print '[unknown link type]';
690c059e1a6SAndreas Gohr      return true;
691ed630903Sandi  }
692ed630903Sandi}
693ed630903Sandi
694ed630903Sandi/**
6956b13307fSandi * Print the search form
6966b13307fSandi *
69772645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
69872645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
69972645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
70072645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
70172645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
70272645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
70372645b75SAndreas Gohr *
7046b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7056b13307fSandi */
70672645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
7076b13307fSandi  global $lang;
708c1e3b7d9Smatthiasgrimm  global $ACT;
709c1e3b7d9Smatthiasgrimm
710670ff54eSchris  // don't print the search form if search action has been disabled
71154e95700STom N Harris  if (!actionOk('search')) return false;
712670ff54eSchris
7131dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
7146b13307fSandi  print '<input type="hidden" name="do" value="search" />';
715c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
716bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
71772645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
718818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
71911ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
72024a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
7214beabca9SAnika Henke  print '</div></form>';
72254e95700STom N Harris  return true;
7236b13307fSandi}
7246b13307fSandi
7256b13307fSandi/**
7266b13307fSandi * Print the breadcrumbs trace
7276b13307fSandi *
7286b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7296b13307fSandi */
73054e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
7316b13307fSandi  global $lang;
7326b13307fSandi  global $conf;
7336b13307fSandi
7346b13307fSandi  //check if enabled
73554e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
7366b13307fSandi
7376b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
738265e3787Sandi
7392979a10bSKatriel Traum  //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
7402979a10bSKatriel Traum  if($lang['direction'] == 'rtl') {
7412979a10bSKatriel Traum    $crumbs = array_reverse($crumbs,true);
7422979a10bSKatriel Traum    $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
7432979a10bSKatriel Traum  } else {
7442979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
7452979a10bSKatriel Traum  }
746265e3787Sandi
74740eb54bbSjan  //render crumbs, highlight the last one
7481b6f3a44SAndreas Gohr  print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
74940eb54bbSjan  $last = count($crumbs);
75040eb54bbSjan  $i = 0;
751a77f5846Sjan  foreach ($crumbs as $id => $name){
75240eb54bbSjan    $i++;
7532979a10bSKatriel Traum    echo $crumbs_sep;
75492795d04Sandi    if ($i == $last) print '<span class="curid">';
755e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
75692795d04Sandi    if ($i == $last) print '</span>';
7576b13307fSandi  }
75854e95700STom N Harris  return true;
7596b13307fSandi}
7606b13307fSandi
7616b13307fSandi/**
7621734437eSandi * Hierarchical breadcrumbs
7631734437eSandi *
76431e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7651734437eSandi * It only makes sense with a deep site structure.
7661734437eSandi *
7671734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7686bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
76931e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
7701734437eSandi * @link   http://wiki.splitbrain.org/wiki:tipsandtricks:hierarchicalbreadcrumbs
7716bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
7721734437eSandi */
773796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
7741734437eSandi  global $conf;
7751734437eSandi  global $ID;
7761734437eSandi  global $lang;
7771734437eSandi
77831e187f8SSean Coates  // check if enabled
77954e95700STom N Harris  if(!$conf['youarehere']) return false;
7801734437eSandi
7811734437eSandi  $parts = explode(':', $ID);
782796bafb3SAndreas Gohr  $count = count($parts);
7831734437eSandi
7841b6f3a44SAndreas Gohr  echo '<span class="bchead">'.$lang['youarehere'].': </span>';
7851734437eSandi
7861734437eSandi  // always print the startpage
787796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
788796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
789e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
790796bafb3SAndreas Gohr
791796bafb3SAndreas Gohr  // print intermediate namespace links
792796bafb3SAndreas Gohr  $part = '';
793796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
794796bafb3SAndreas Gohr    $part .= $parts[$i].':';
795796bafb3SAndreas Gohr    $page = $part;
796796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
797796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
798796bafb3SAndreas Gohr
799796bafb3SAndreas Gohr    // output
800796bafb3SAndreas Gohr    echo $sep;
801796bafb3SAndreas Gohr    if($exists){
802796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
803796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
804e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
80531e187f8SSean Coates    }else{
806796bafb3SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
80731e187f8SSean Coates    }
80831e187f8SSean Coates  }
8091734437eSandi
810796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
811d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
812796bafb3SAndreas Gohr  $page = $part.$parts[$i];
813796bafb3SAndreas Gohr  if($page == $conf['start']) return;
814796bafb3SAndreas Gohr  echo $sep;
815*103c256aSChris Smith  if(page_exists($page)){
816796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
817796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
818e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
81931e187f8SSean Coates  }else{
820796bafb3SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2"');
8211734437eSandi  }
82254e95700STom N Harris  return true;
8231734437eSandi}
8241734437eSandi
8251734437eSandi/**
8266b13307fSandi * Print info if the user is logged in
827a2488c3cSMatthias Grimm * and show full name in that case
8286b13307fSandi *
8296b13307fSandi * Could be enhanced with a profile link in future?
8306b13307fSandi *
8316b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8326b13307fSandi */
8336b13307fSandifunction tpl_userinfo(){
8346b13307fSandi  global $lang;
835a2488c3cSMatthias Grimm  global $INFO;
83654e95700STom N Harris  if($_SERVER['REMOTE_USER']){
837a2488c3cSMatthias Grimm    print $lang['loggedinas'].': '.$INFO['userinfo']['name'];
83854e95700STom N Harris    return true;
83954e95700STom N Harris  }
84054e95700STom N Harris  return false;
8416b13307fSandi}
8426b13307fSandi
8436b13307fSandi/**
8446b13307fSandi * Print some info about the current page
8456b13307fSandi *
8466b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8476b13307fSandi */
8486b13307fSandifunction tpl_pageinfo(){
8496b13307fSandi  global $conf;
8506b13307fSandi  global $lang;
8516b13307fSandi  global $INFO;
8526b13307fSandi  global $REV;
853c6e92a3cSDavid Lorentsen  global $ID;
854c6e92a3cSDavid Lorentsen
855c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
856c6e92a3cSDavid Lorentsen  if (!auth_quickaclcheck($ID)) { return; }
8576b13307fSandi
8586b13307fSandi  // prepare date and path
8596b13307fSandi  $fn = $INFO['filepath'];
8606b13307fSandi  if(!$conf['fullpath']){
8616b13307fSandi    if($REV){
86200976812SAndreas Gohr      $fn = str_replace(fullpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
8636b13307fSandi    }else{
86400976812SAndreas Gohr      $fn = str_replace(fullpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
8656b13307fSandi    }
8666b13307fSandi  }
867bee6dc82Sandi  $fn = utf8_decodeFN($fn);
8686b13307fSandi  $date = date($conf['dformat'],$INFO['lastmod']);
8696b13307fSandi
870faecdfdfSAndreas Gohr  // print it
871faecdfdfSAndreas Gohr  if($INFO['exists']){
8726b13307fSandi    print $fn;
8736b13307fSandi    print ' &middot; ';
8746b13307fSandi    print $lang['lastmod'];
8756b13307fSandi    print ': ';
8766b13307fSandi    print $date;
8776b13307fSandi    if($INFO['editor']){
8786b13307fSandi      print ' '.$lang['by'].' ';
8796b13307fSandi      print $INFO['editor'];
8805aa52fafSBen Coburn    }else{
8815aa52fafSBen Coburn      print ' ('.$lang['external_edit'].')';
8826b13307fSandi    }
8836b13307fSandi    if($INFO['locked']){
8846b13307fSandi      print ' &middot; ';
8856b13307fSandi      print $lang['lockedby'];
8866b13307fSandi      print ': ';
8876b13307fSandi      print $INFO['locked'];
8886b13307fSandi    }
88954e95700STom N Harris    return true;
8906b13307fSandi  }
89154e95700STom N Harris  return false;
8926b13307fSandi}
8936b13307fSandi
894820fa24bSandi/**
895a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
89687c434ceSAndreas Gohr *
89787c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
898a6598f23SBen Coburn * the given ID is used.
89987c434ceSAndreas Gohr *
90087c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
90187c434ceSAndreas Gohr */
902a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
90387c434ceSAndreas Gohr  global $conf;
90487c434ceSAndreas Gohr  if(is_null($id)){
90587c434ceSAndreas Gohr    global $ID;
90687c434ceSAndreas Gohr    $id = $ID;
90787c434ceSAndreas Gohr  }
90887c434ceSAndreas Gohr
90987c434ceSAndreas Gohr  $name = $id;
91087c434ceSAndreas Gohr  if ($conf['useheading']) {
91187c434ceSAndreas Gohr    $title = p_get_first_heading($id);
91287c434ceSAndreas Gohr    if ($title) $name = $title;
91387c434ceSAndreas Gohr  }
914a6598f23SBen Coburn
915a6598f23SBen Coburn  if ($ret) {
916a6598f23SBen Coburn      return hsc($name);
917a6598f23SBen Coburn  } else {
91887c434ceSAndreas Gohr      print hsc($name);
91954e95700STom N Harris      return true;
92087c434ceSAndreas Gohr  }
921a6598f23SBen Coburn}
922340756e4Sandi
92355efc227SAndreas Gohr/**
92455efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
92555efc227SAndreas Gohr *
92655efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
92755efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
92855efc227SAndreas Gohr *
92955efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
93055efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
93155efc227SAndreas Gohr * to the names of the latter one)
93255efc227SAndreas Gohr *
9333df72098SAndreas Gohr * Only allowed in: detail.php
93455efc227SAndreas Gohr *
93555efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
93655efc227SAndreas Gohr */
9373df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
93855efc227SAndreas Gohr  // Init Exif Reader
93955efc227SAndreas Gohr  global $SRC;
9403df72098SAndreas Gohr
9413df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
9423df72098SAndreas Gohr
94355efc227SAndreas Gohr  static $meta = null;
9443df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
94555efc227SAndreas Gohr  if($meta === false) return $alt;
94655efc227SAndreas Gohr  $info = $meta->getField($tags);
94755efc227SAndreas Gohr  if($info == false) return $alt;
94855efc227SAndreas Gohr  return $info;
94955efc227SAndreas Gohr}
95055efc227SAndreas Gohr
95155efc227SAndreas Gohr/**
95255efc227SAndreas Gohr * Prints the image with a link to the full sized version
95355efc227SAndreas Gohr *
95455efc227SAndreas Gohr * Only allowed in: detail.php
95555efc227SAndreas Gohr */
956f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
95755efc227SAndreas Gohr  global $IMG;
95855efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
95955efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
96055efc227SAndreas Gohr
96155efc227SAndreas Gohr  //resize to given max values
96223a34783SAndreas Gohr  $ratio = 1;
96323a34783SAndreas Gohr  if($w >= $h){
964f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
96555efc227SAndreas Gohr      $ratio = $maxwidth/$w;
966f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
96755efc227SAndreas Gohr      $ratio = $maxheight/$h;
96855efc227SAndreas Gohr    }
96955efc227SAndreas Gohr  }else{
970f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
97155efc227SAndreas Gohr      $ratio = $maxheight/$h;
972f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
97355efc227SAndreas Gohr      $ratio = $maxwidth/$w;
97455efc227SAndreas Gohr    }
97555efc227SAndreas Gohr  }
97655efc227SAndreas Gohr  if($ratio){
97755efc227SAndreas Gohr    $w = floor($ratio*$w);
97855efc227SAndreas Gohr    $h = floor($ratio*$h);
97955efc227SAndreas Gohr  }
98055efc227SAndreas Gohr
9816de3759aSAndreas Gohr  //prepare URLs
9826de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
9836de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
98455efc227SAndreas Gohr
9852684e50aSAndreas Gohr  //prepare attributes
98655efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
9872684e50aSAndreas Gohr  $p = array();
9882684e50aSAndreas Gohr  if($w) $p['width']  = $w;
9892684e50aSAndreas Gohr  if($h) $p['height'] = $h;
9902684e50aSAndreas Gohr         $p['class']  = 'img_detail';
9912684e50aSAndreas Gohr  if($alt){
9922684e50aSAndreas Gohr    $p['alt']   = $alt;
9932684e50aSAndreas Gohr    $p['title'] = $alt;
9942684e50aSAndreas Gohr  }else{
9952684e50aSAndreas Gohr    $p['alt'] = '';
9962684e50aSAndreas Gohr  }
9972684e50aSAndreas Gohr  $p = buildAttributes($p);
99855efc227SAndreas Gohr
99955efc227SAndreas Gohr  print '<a href="'.$url.'">';
10006de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
100155efc227SAndreas Gohr  print '</a>';
100254e95700STom N Harris  return true;
100355efc227SAndreas Gohr}
100455efc227SAndreas Gohr
10057367b368SAndreas Gohr/**
10067367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
10077367b368SAndreas Gohr * is the inexer function.
10087367b368SAndreas Gohr *
10097367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
10107367b368SAndreas Gohr * template
10117367b368SAndreas Gohr */
10127367b368SAndreas Gohrfunction tpl_indexerWebBug(){
10137367b368SAndreas Gohr  global $ID;
10141dad36f5SAndreas Gohr  global $INFO;
101554e95700STom N Harris  if(!$INFO['exists']) return false;
10161dad36f5SAndreas Gohr
101754e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
10180dc92c6fSAndreas Gohr
10197367b368SAndreas Gohr  $p = array();
1020b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1021e68c51baSAndreas Gohr                 '&'.time();
10227367b368SAndreas Gohr  $p['width']  = 1;
10237367b368SAndreas Gohr  $p['height'] = 1;
10247367b368SAndreas Gohr  $p['alt']    = '';
10257367b368SAndreas Gohr  $att = buildAttributes($p);
10267367b368SAndreas Gohr  print "<img $att />";
102754e95700STom N Harris  return true;
10287367b368SAndreas Gohr}
10297367b368SAndreas Gohr
103078d4e784SEsther Brunner// configuration methods
103178d4e784SEsther Brunner/**
103278d4e784SEsther Brunner * tpl_getConf($id)
103378d4e784SEsther Brunner *
103478d4e784SEsther Brunner * use this function to access template configuration variables
103578d4e784SEsther Brunner */
103678d4e784SEsther Brunnerfunction tpl_getConf($id){
103778d4e784SEsther Brunner  global $conf;
103878d4e784SEsther Brunner  global $tpl_configloaded;
103978d4e784SEsther Brunner
104078d4e784SEsther Brunner  $tpl = $conf['template'];
104178d4e784SEsther Brunner
104278d4e784SEsther Brunner  if (!$tpl_configloaded){
104378d4e784SEsther Brunner    $tconf = tpl_loadConfig();
104478d4e784SEsther Brunner    if ($tconf !== false){
104578d4e784SEsther Brunner      foreach ($tconf as $key => $value){
104678d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
104778d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
104878d4e784SEsther Brunner      }
104978d4e784SEsther Brunner      $tpl_configloaded = true;
105078d4e784SEsther Brunner    }
105178d4e784SEsther Brunner  }
105278d4e784SEsther Brunner
105378d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
105478d4e784SEsther Brunner}
105578d4e784SEsther Brunner
105678d4e784SEsther Brunner/**
105778d4e784SEsther Brunner * tpl_loadConfig()
105878d4e784SEsther Brunner * reads all template configuration variables
105978d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
106078d4e784SEsther Brunner */
106178d4e784SEsther Brunnerfunction tpl_loadConfig(){
106278d4e784SEsther Brunner
106378d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
106478d4e784SEsther Brunner  $conf = array();
106578d4e784SEsther Brunner
106678d4e784SEsther Brunner  if (!@file_exists($file)) return false;
106778d4e784SEsther Brunner
106878d4e784SEsther Brunner  // load default config file
106978d4e784SEsther Brunner  include($file);
107078d4e784SEsther Brunner
107178d4e784SEsther Brunner  return $conf;
107278d4e784SEsther Brunner}
107378d4e784SEsther Brunner
10743df72098SAndreas Gohr/**
10753df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
10763df72098SAndreas Gohr *
10773df72098SAndreas Gohr * Depending on the user's actions this may be a list of
10783df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
10793df72098SAndreas Gohr * a message of referencing pages
10803df72098SAndreas Gohr *
10813df72098SAndreas Gohr * Only allowed in mediamanager.php
10823df72098SAndreas Gohr *
10833df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10843df72098SAndreas Gohr */
10853df72098SAndreas Gohrfunction tpl_mediaContent(){
10863df72098SAndreas Gohr  global $IMG;
10873df72098SAndreas Gohr  global $AUTH;
10883df72098SAndreas Gohr  global $INUSE;
10893df72098SAndreas Gohr  global $NS;
10903df72098SAndreas Gohr  global $JUMPTO;
10913df72098SAndreas Gohr
10923df72098SAndreas Gohr  ptln('<div id="media__content">');
10933df72098SAndreas Gohr  if($_REQUEST['edit']){
10943df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
10957b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
10963df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
10973df72098SAndreas Gohr  }else{
10983df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
10993df72098SAndreas Gohr  }
11003df72098SAndreas Gohr  ptln('</div>');
11013df72098SAndreas Gohr}
11023df72098SAndreas Gohr
11033df72098SAndreas Gohr/**
11043df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
11053df72098SAndreas Gohr *
11063df72098SAndreas Gohr * Only allowed in mediamanager.php
11073df72098SAndreas Gohr *
11083df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11093df72098SAndreas Gohr */
11103df72098SAndreas Gohrfunction tpl_mediaTree(){
11113df72098SAndreas Gohr  global $NS;
11123df72098SAndreas Gohr
11133df72098SAndreas Gohr  ptln('<div id="media__tree">');
11143df72098SAndreas Gohr  media_nstree($NS);
11153df72098SAndreas Gohr  ptln('</div>');
11163df72098SAndreas Gohr}
11173df72098SAndreas Gohr
1118b8595a66SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
1119