xref: /dokuwiki/inc/template.php (revision dc58b6f4952c9a966ba23101144f00d378746a17)
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;
1553c86d7c9SAndreas Gohr    }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){
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
1847dee3468SGina Haeussge    trigger_event('TPL_TOC_RENDER', $toc, NULL, false);
185b8595a66SAndreas Gohr    $html = html_TOC($toc);
186b8595a66SAndreas Gohr    if($return) return $html;
187b8595a66SAndreas Gohr    echo $html;
188b8595a66SAndreas Gohr}
189b8595a66SAndreas Gohr
190b8595a66SAndreas Gohr/**
191c19fe9c0Sandi * Handle the admin page contents
192c19fe9c0Sandi *
193c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
194c19fe9c0Sandi */
195c19fe9c0Sandifunction tpl_admin(){
196f8cc712eSAndreas Gohr    global $INFO;
197b8595a66SAndreas Gohr    global $TOC;
19811e2ce22Schris
199b8595a66SAndreas Gohr    $plugin = null;
200bb4866bdSchris    if (!empty($_REQUEST['page'])) {
20111e2ce22Schris        $pluginlist = plugin_list('admin');
20211e2ce22Schris
20311e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
20411e2ce22Schris
20511e2ce22Schris          // attempt to load the plugin
20611e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
20711e2ce22Schris        }
20811e2ce22Schris    }
20911e2ce22Schris
210b8595a66SAndreas Gohr    if ($plugin !== null){
211f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
212f8cc712eSAndreas Gohr            msg('For admins only',-1);
21311e2ce22Schris            html_admin();
214f8cc712eSAndreas Gohr        }else{
215b8595a66SAndreas Gohr            if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
216b8595a66SAndreas Gohr            if($INFO['prependTOC']) tpl_toc();
217f8cc712eSAndreas Gohr            $plugin->html();
218f8cc712eSAndreas Gohr        }
219f8cc712eSAndreas Gohr    }else{
220f8cc712eSAndreas Gohr        html_admin();
221f8cc712eSAndreas Gohr    }
22254e95700STom N Harris    return true;
223c19fe9c0Sandi}
2246b13307fSandi
2256b13307fSandi/**
2266b13307fSandi * Print the correct HTML meta headers
2276b13307fSandi *
2286b13307fSandi * This has to go into the head section of your template.
2296b13307fSandi *
230016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
231f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
2326b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2336b13307fSandi */
234f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
2356b13307fSandi  global $ID;
236d98d4540SBen Coburn  global $REV;
2376b13307fSandi  global $INFO;
2386b13307fSandi  global $ACT;
2394bb1b5aeSAndreas Gohr  global $QUERY;
2406b13307fSandi  global $lang;
241dc57ef04Sandi  global $conf;
2426b13307fSandi  $it=2;
2436b13307fSandi
2447bff22c0SAndreas Gohr  // prepare the head array
2457bff22c0SAndreas Gohr  $head = array();
2467bff22c0SAndreas Gohr
2477bff22c0SAndreas Gohr
2486b13307fSandi  // the usual stuff
2497bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
250da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
251da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
252f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
2537bff22c0SAndreas Gohr  $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
254bb4866bdSchris                           'title'=>$lang['btn_index'] );
255f96fa415SAndreas Gohr
256f96fa415SAndreas Gohr  if($alt){
2577bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2587bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2597bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2607bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2617bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
262c35f3875SAndreas Gohr    if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){
263c35f3875SAndreas Gohr        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/wiki',
264715bdf1fSAndreas Gohr                                 'title'=>$lang['btn_edit'],
265c35f3875SAndreas Gohr                                 'href'=> wl($ID,'do=edit',false,'&'));
266c35f3875SAndreas Gohr    }
267c35f3875SAndreas Gohr
2684bb1b5aeSAndreas Gohr    if($ACT == 'search'){
2694bb1b5aeSAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2704bb1b5aeSAndreas Gohr                               'title'=>'Search Result',
2714bb1b5aeSAndreas Gohr                               'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
2724bb1b5aeSAndreas Gohr    }
273bae36d94SAndreas Gohr
274bae36d94SAndreas Gohr    if(actionOK('export_xhtml')){
2757bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2767bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'xhtml', '', false, '&'));
277bae36d94SAndreas Gohr    }
278bae36d94SAndreas Gohr
279bae36d94SAndreas Gohr    if(actionOK('export_raw')){
2807bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2817bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'raw', '', false, '&'));
282f96fa415SAndreas Gohr    }
283bae36d94SAndreas Gohr  }
2846b13307fSandi
2856b13307fSandi  // setup robot tags apropriate for different modes
2864f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2876b13307fSandi    if($INFO['exists']){
2886b13307fSandi      //delay indexing:
2896b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2907bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2916b13307fSandi      }else{
2927bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
2936b13307fSandi      }
2946b13307fSandi    }else{
2957bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
2966b13307fSandi    }
2977a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
2987bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2996b13307fSandi  }else{
3007bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3016b13307fSandi  }
3026b13307fSandi
303831800b8SAndreas Gohr  // set metadata
304831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
305831800b8SAndreas Gohr    // date of modification
306831800b8SAndreas Gohr    if($REV){
3077bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
308831800b8SAndreas Gohr    }else{
3097bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
310831800b8SAndreas Gohr    }
311831800b8SAndreas Gohr
312831800b8SAndreas Gohr    // keywords (explicit or implicit)
313bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
3147bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
315831800b8SAndreas Gohr    }else{
3167bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
317831800b8SAndreas Gohr    }
318831800b8SAndreas Gohr  }
319831800b8SAndreas Gohr
32078a6aeb1SAndreas Gohr  // load stylesheets
3217aaa4c46Smartin.tschofen  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
322124af657SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template']);
3237bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
324124af657SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template']);
3257bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
326124af657SAndreas Gohr                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template']);
327bad31ae9SAndreas Gohr
32878a6aeb1SAndreas Gohr  // load javascript
329041d1964SAndreas Gohr  $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
330bad31ae9SAndreas Gohr  $js_write = ($INFO['writable']) ? 1 : 0;
3313df72098SAndreas Gohr  if(defined('DOKU_MEDIAMANAGER')){
3323df72098SAndreas Gohr    $js_edit  = 1;
3333df72098SAndreas Gohr    $js_write = 0;
3343df72098SAndreas Gohr  }
3353df72098SAndreas Gohr  if(($js_edit && $js_write) || defined('DOKU_MEDIAMANAGER')){
3367bff22c0SAndreas Gohr    $script = "NS='".$INFO['namespace']."';";
337c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
338aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
3397bff22c0SAndreas Gohr      $script .= "SIG='".toolbar_signature()."';";
340c591aabeSAndreas Gohr    }
3417bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
3427bff22c0SAndreas Gohr                               '_data'=> $script);
343c591aabeSAndreas Gohr  }
3447bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
3457bff22c0SAndreas Gohr                             'src'=>DOKU_BASE.'lib/exe/js.php?edit='.$js_edit.'&write='.$js_write);
3467bff22c0SAndreas Gohr
3477bff22c0SAndreas Gohr  // trigger event here
348016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
34954e95700STom N Harris  return true;
3507bff22c0SAndreas Gohr}
3517bff22c0SAndreas Gohr
3527bff22c0SAndreas Gohr/**
3537bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3547bff22c0SAndreas Gohr *
3557bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3567bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3577bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3587bff22c0SAndreas Gohr *
3597bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
3601304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3617bff22c0SAndreas Gohr *
3627bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3637bff22c0SAndreas Gohr */
3647bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3657bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
3667bff22c0SAndreas Gohr    foreach($inst as $attr){
3677bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
3687bff22c0SAndreas Gohr      if(isset($attr['_data'])){
369e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
370e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
371e226efe1SAndreas Gohr                             $attr['_data'].
372e226efe1SAndreas Gohr                             "\n//--><!]]>";
373e226efe1SAndreas Gohr
3741304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3757bff22c0SAndreas Gohr      }else{
3767bff22c0SAndreas Gohr        echo '/>';
3777bff22c0SAndreas Gohr      }
3787bff22c0SAndreas Gohr      echo "\n";
3797bff22c0SAndreas Gohr    }
3807bff22c0SAndreas Gohr  }
3816b13307fSandi}
3826b13307fSandi
3836b13307fSandi/**
3846b13307fSandi * Print a link
3856b13307fSandi *
3865e163278SAndreas Gohr * Just builds a link.
3876b13307fSandi *
3886b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3896b13307fSandi */
3906b13307fSandifunction tpl_link($url,$name,$more=''){
3915e163278SAndreas Gohr  print '<a href="'.$url.'" ';
3926b13307fSandi  if ($more) print ' '.$more;
3936b13307fSandi  print ">$name</a>";
39454e95700STom N Harris  return true;
3956b13307fSandi}
3966b13307fSandi
3976b13307fSandi/**
39855efc227SAndreas Gohr * Prints a link to a WikiPage
39955efc227SAndreas Gohr *
40055efc227SAndreas Gohr * Wrapper around html_wikilink
40155efc227SAndreas Gohr *
40255efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
40355efc227SAndreas Gohr */
40455efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
40555efc227SAndreas Gohr  print html_wikilink($id,$name);
40654e95700STom N Harris  return true;
40755efc227SAndreas Gohr}
40855efc227SAndreas Gohr
40955efc227SAndreas Gohr/**
410a3ec5f4aSmatthiasgrimm * get the parent page
411a3ec5f4aSmatthiasgrimm *
412a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
413a3ec5f4aSmatthiasgrimm * returns false if none is available
414a3ec5f4aSmatthiasgrimm *
415377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
416a3ec5f4aSmatthiasgrimm */
417377f9e97SAndreas Gohrfunction tpl_getparent($id){
418a3ec5f4aSmatthiasgrimm  global $conf;
419377f9e97SAndreas Gohr  $parent = getNS($id).':';
420377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
421a197105eSmatthiasgrimm  if($parent == $id) {
422a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
423a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
424a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
425377f9e97SAndreas Gohr    if($parent == $id) return false;
426a197105eSmatthiasgrimm  }
427377f9e97SAndreas Gohr  return $parent;
428a3ec5f4aSmatthiasgrimm}
429a3ec5f4aSmatthiasgrimm
430a3ec5f4aSmatthiasgrimm/**
4316b13307fSandi * Print one of the buttons
4326b13307fSandi *
4336b13307fSandi * Available Buttons are
4346b13307fSandi *
435ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
4366b13307fSandi *  history     - old revisions
4376b13307fSandi *  recent      - recent changes
4386b13307fSandi *  login       - login/logout button - if ACL enabled
439d449b912SDenis Simakov *  profile     - user profile button (if logged in)
4406b13307fSandi *  index       - The index
441c19fe9c0Sandi *  admin       - admin page - if enough rights
4426b13307fSandi *  top         - a back to top button
443a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
444bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
445d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
4466b13307fSandi *
4476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
448a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
4496b13307fSandi */
4506b13307fSandifunction tpl_button($type){
451b158d625SSteven Danz  global $ACT;
4526b13307fSandi  global $ID;
453d98d4540SBen Coburn  global $REV;
454d67ca2c0Smatthiasgrimm  global $NS;
455c19fe9c0Sandi  global $INFO;
4566b13307fSandi  global $conf;
457cd52f92dSchris  global $auth;
4586b13307fSandi
45975e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
46075e487e9SAndreas Gohr  $ctype = $type;
46175e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
46254e95700STom N Harris  if(!actionOK($ctype)) return false;
463409d7af7SAndreas Gohr
4646b13307fSandi  switch($type){
4656b13307fSandi    case 'edit':
466409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
467409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
468409d7af7SAndreas Gohr        if($INFO['writable']){
469bb4866bdSchris          if(!empty($INFO['draft'])){
470409d7af7SAndreas Gohr            echo html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
471409d7af7SAndreas Gohr          }else{
472409d7af7SAndreas Gohr            if($INFO['exists']){
473409d7af7SAndreas Gohr              echo html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
474409d7af7SAndreas Gohr            }else{
475409d7af7SAndreas Gohr              echo html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
476409d7af7SAndreas Gohr            }
477409d7af7SAndreas Gohr          }
478409d7af7SAndreas Gohr        }else{
479409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
480409d7af7SAndreas Gohr          echo html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
481409d7af7SAndreas Gohr        }
482409d7af7SAndreas Gohr      }else{
483409d7af7SAndreas Gohr          echo html_btn('show',$ID,'v',array('do' => 'show'));
484409d7af7SAndreas Gohr      }
48554e95700STom N Harris      return true;
4866b13307fSandi    case 'history':
4875bc81eb9SAnders Betnér      print html_btn('revs',$ID,'o',array('do' => 'revisions'));
48854e95700STom N Harris      return true;
4896b13307fSandi    case 'recent':
4905bc81eb9SAnders Betnér      print html_btn('recent','','r',array('do' => 'recent'));
49154e95700STom N Harris      return true;
4926b13307fSandi    case 'index':
4935bc81eb9SAnders Betnér      print html_btn('index',$ID,'x',array('do' => 'index'));
49454e95700STom N Harris      return true;
495a3ec5f4aSmatthiasgrimm    case 'back':
4966222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
4976222040cSmatthiasgrimm        print html_btn('back',$parent,'b',array('do' => 'show'));
49854e95700STom N Harris        return true;
499a3ec5f4aSmatthiasgrimm      }
50054e95700STom N Harris      return false;
5016b13307fSandi    case 'top':
5026b13307fSandi      print html_topbtn();
50354e95700STom N Harris      return true;
5046b13307fSandi    case 'login':
5056957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
5066b13307fSandi        if($_SERVER['REMOTE_USER']){
507cc670e1bSMichael Klier          print html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken()));
5086b13307fSandi        }else{
509cc670e1bSMichael Klier          print html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken()));
5106b13307fSandi        }
51154e95700STom N Harris        return true;
5126b13307fSandi      }
51354e95700STom N Harris      return false;
514c19fe9c0Sandi    case 'admin':
51554e95700STom N Harris      if($INFO['ismanager']){
5165bc81eb9SAnders Betnér        print html_btn('admin',$ID,'',array('do' => 'admin'));
51754e95700STom N Harris        return true;
51854e95700STom N Harris      }
51954e95700STom N Harris      return false;
520582c5bfeSAndreas Gohr    case 'subscribe':
5211380fc45SAndreas Gohr    case 'subscription':
5226957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
523b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
5241380fc45SAndreas Gohr          if($INFO['subscribed']){
5251380fc45SAndreas Gohr            print html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
526b158d625SSteven Danz          } else {
5271380fc45SAndreas Gohr            print html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
528b158d625SSteven Danz          }
529582c5bfeSAndreas Gohr          if($type == 'subscribe') return true;
530582c5bfeSAndreas Gohr        }
531582c5bfeSAndreas Gohr      }
532582c5bfeSAndreas Gohr      if($type == 'subscribe') return false;
533582c5bfeSAndreas Gohr      // fall through for backward compatibility
534582c5bfeSAndreas Gohr    case 'subscribens':
535582c5bfeSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
536582c5bfeSAndreas Gohr        if($_SERVER['REMOTE_USER']){
53752b0dd67SGuy Brand          if($INFO['subscribedns']){
53852b0dd67SGuy Brand            print html_btn('unsubscribens',$ID,'',array('do' => 'unsubscribens',));
53952b0dd67SGuy Brand          } else {
54052b0dd67SGuy Brand            print html_btn('subscribens',$ID,'',array('do' => 'subscribens',));
54152b0dd67SGuy Brand          }
54254e95700STom N Harris          return true;
543b158d625SSteven Danz        }
544b158d625SSteven Danz      }
54554e95700STom N Harris      return false;
546f00151b4Schris    case 'backlink':
547f00151b4Schris      print html_btn('backlink',$ID,'',array('do' => 'backlink'));
54854e95700STom N Harris      return true;
5498b06d178Schris    case 'profile':
5506957b2eaSAndreas Gohr      if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth &&
55136223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
5528b06d178Schris        print html_btn('profile',$ID,'',array('do' => 'profile'));
55354e95700STom N Harris        return true;
5548b06d178Schris      }
55554e95700STom N Harris      return false;
556c19fe9c0Sandi    default:
557c19fe9c0Sandi      print '[unknown button type]';
55854e95700STom N Harris      return true;
5596b13307fSandi  }
5606b13307fSandi}
5616b13307fSandi
5626b13307fSandi/**
563ed630903Sandi * Like the action buttons but links
564ed630903Sandi *
565ed630903Sandi * Available links are
566ed630903Sandi *
567d449b912SDenis Simakov *  edit    - edit/create/show link
568ed630903Sandi *  history - old revisions
569ed630903Sandi *  recent  - recent changes
570d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
571d449b912SDenis Simakov *  profile - user profile link (if logged in)
572ed630903Sandi *  index   - The index
573ed630903Sandi *  admin   - admin page - if enough rights
574d449b912SDenis Simakov *  top     - a back to top link
575d449b912SDenis Simakov *  back    - a back to parent link - if available
576bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
577d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
578ed630903Sandi *
579ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
580a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
581ed630903Sandi * @see    tpl_button
582ed630903Sandi */
583c97dfb07SAndreas Gohrfunction tpl_actionlink($type,$pre='',$suf='',$inner=''){
584ed630903Sandi  global $ID;
585ed630903Sandi  global $INFO;
586ed630903Sandi  global $REV;
587ed630903Sandi  global $ACT;
588ed630903Sandi  global $conf;
589ed630903Sandi  global $lang;
590cd52f92dSchris  global $auth;
591ed630903Sandi
59275e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
59375e487e9SAndreas Gohr  $ctype = $type;
59475e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
59554e95700STom N Harris  if(!actionOK($ctype)) return false;
596409d7af7SAndreas Gohr
597ed630903Sandi  switch($type){
598ed630903Sandi    case 'edit':
599ed630903Sandi      #most complicated type - we need to decide on current action
600ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
601ed630903Sandi        if($INFO['writable']){
602b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
603b8a111f5SMichael Klier            tpl_link(wl($ID,'do=draft'),
604c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_draft']).$suf,
605f6547e5dSAndreas Gohr                       'class="action edit" accesskey="e" rel="nofollow"');
606b8a111f5SMichael Klier          } else {
607ed630903Sandi            if($INFO['exists']){
608ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
609c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_edit']).$suf,
610b7af031cSsu                       'class="action edit" accesskey="e" rel="nofollow"');
611ed630903Sandi            }else{
612ed630903Sandi              tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
613c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_create']).$suf,
614b7af031cSsu                       'class="action create" accesskey="e" rel="nofollow"');
615ed630903Sandi            }
616b8a111f5SMichael Klier          }
617ed630903Sandi        }else{
618409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
619ed630903Sandi          tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
620c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_source']).$suf,
621b7af031cSsu                   'class="action source" accesskey="v" rel="nofollow"');
622ed630903Sandi        }
623ed630903Sandi      }else{
624ed630903Sandi          tpl_link(wl($ID,'do=show'),
625c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_show']).$suf,
626b7af031cSsu                   'class="action show" accesskey="v" rel="nofollow"');
627ed630903Sandi      }
628c059e1a6SAndreas Gohr      return true;
629ed630903Sandi    case 'history':
630c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=revisions'),
631c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_revs']).$suf,
632c97dfb07SAndreas Gohr               'class="action revisions" accesskey="o" rel="nofollow"');
633c059e1a6SAndreas Gohr      return true;
634ed630903Sandi    case 'recent':
635c97dfb07SAndreas Gohr      tpl_link(wl('','do=recent'),
636c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_recent']).$suf,
637c97dfb07SAndreas Gohr              'class="action recent" accesskey="r" rel="nofollow"');
638c059e1a6SAndreas Gohr      return true;
639ed630903Sandi    case 'index':
640c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=index'),
641c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_index']).$suf,
642c97dfb07SAndreas Gohr              'class="action index" accesskey="x" rel="nofollow"');
643c059e1a6SAndreas Gohr      return true;
644ed630903Sandi    case 'top':
645c97dfb07SAndreas Gohr      print '<a href="#dokuwiki__top" class="action top" accesskey="x">'.
646c97dfb07SAndreas Gohr            $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>';
647c059e1a6SAndreas Gohr      return true;
648a3ec5f4aSmatthiasgrimm    case 'back':
649f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
650c97dfb07SAndreas Gohr        tpl_link(wl($parent,'do=show'),
651c97dfb07SAndreas Gohr        $pre.(($inner)?$inner:$lang['btn_back']).$suf,
652c97dfb07SAndreas Gohr        'class="action back" accesskey="b" rel="nofollow"');
653c059e1a6SAndreas Gohr        return true;
654a3ec5f4aSmatthiasgrimm      }
655c059e1a6SAndreas Gohr      return false;
656ed630903Sandi    case 'login':
6576957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
658ed630903Sandi        if($_SERVER['REMOTE_USER']){
659cc670e1bSMichael Klier          tpl_link(wl($ID,'do=logout&amp;sectok='.getSecurityToken()),
660c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_logout']).$suf,
661c97dfb07SAndreas Gohr                   'class="action logout" rel="nofollow"');
662ed630903Sandi        }else{
663cc670e1bSMichael Klier          tpl_link(wl($ID,'do=login&amp;sectok='.getSecurityToken()),
664c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_login']).$suf,
665c97dfb07SAndreas Gohr                   'class="action login" rel="nofollow"');
666ed630903Sandi        }
667c059e1a6SAndreas Gohr        return true;
668ed630903Sandi      }
669c059e1a6SAndreas Gohr      return false;
670ed630903Sandi    case 'admin':
671f8cc712eSAndreas Gohr      if($INFO['ismanager']){
672c97dfb07SAndreas Gohr        tpl_link(wl($ID,'do=admin'),
673c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_admin']).$suf,
674c97dfb07SAndreas Gohr                 'class="action admin" rel="nofollow"');
675c059e1a6SAndreas Gohr        return true;
676c059e1a6SAndreas Gohr      }
677c059e1a6SAndreas Gohr      return false;
678f9eb5648Ssteven-danz   case 'subscribe':
679075f000fSChristopher Arndt   case 'subscription':
6806957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
681b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
682075f000fSChristopher Arndt          if($INFO['subscribed']) {
683c97dfb07SAndreas Gohr            tpl_link(wl($ID,'do=unsubscribe'),
684c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_unsubscribe']).$suf,
685c97dfb07SAndreas Gohr                     'class="action unsubscribe" rel="nofollow"');
686b158d625SSteven Danz          } else {
687c97dfb07SAndreas Gohr            tpl_link(wl($ID,'do=subscribe'),
688c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf,
689c97dfb07SAndreas Gohr                     'class="action subscribe" rel="nofollow"');
690b158d625SSteven Danz          }
691c059e1a6SAndreas Gohr          return true;
692b158d625SSteven Danz        }
693b158d625SSteven Danz      }
694c059e1a6SAndreas Gohr      return false;
695280f11b7SMichael Klier    case 'subscribens':
696280f11b7SMichael Klier      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
697280f11b7SMichael Klier        if($_SERVER['REMOTE_USER']){
698280f11b7SMichael Klier          if($INFO['subscribedns']) {
699280f11b7SMichael Klier            tpl_link(wl($ID,'do=unsubscribens'),
700280f11b7SMichael Klier                     $pre.(($inner)?$inner:$lang['btn_unsubscribens']).$suf,
701280f11b7SMichael Klier                     'class="action unsubscribens" rel="nofollow"');
702280f11b7SMichael Klier          } else {
703280f11b7SMichael Klier            tpl_link(wl($ID,'do=subscribens'),
704280f11b7SMichael Klier                     $pre.(($inner)?$inner:$lang['btn_subscribens']).$suf,
705280f11b7SMichael Klier                     'class="action subscribens" rel="nofollow"');
706280f11b7SMichael Klier          }
707280f11b7SMichael Klier          return true;
708280f11b7SMichael Klier        }
709280f11b7SMichael Klier      }
710280f11b7SMichael Klier      return false;
711f00151b4Schris    case 'backlink':
712c97dfb07SAndreas Gohr      tpl_link(wl($ID,'do=backlink'),
713c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_backlink']).$suf,
714c97dfb07SAndreas Gohr               'class="action backlink" rel="nofollow"');
715c059e1a6SAndreas Gohr      return true;
7168b06d178Schris    case 'profile':
7176957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
71836223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
719c97dfb07SAndreas Gohr        tpl_link(wl($ID,'do=profile'),
720c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_profile']).$suf,
721c97dfb07SAndreas Gohr                 'class="action profile" rel="nofollow"');
722c059e1a6SAndreas Gohr        return true;
7238b06d178Schris      }
724c059e1a6SAndreas Gohr      return false;
725ed630903Sandi    default:
726ed630903Sandi      print '[unknown link type]';
727c059e1a6SAndreas Gohr      return true;
728ed630903Sandi  }
729ed630903Sandi}
730ed630903Sandi
731ed630903Sandi/**
7326b13307fSandi * Print the search form
7336b13307fSandi *
73472645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
73572645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
73672645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
73772645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
73872645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
73972645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
74072645b75SAndreas Gohr *
7416b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7426b13307fSandi */
74372645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
7446b13307fSandi  global $lang;
745c1e3b7d9Smatthiasgrimm  global $ACT;
746c1e3b7d9Smatthiasgrimm
747670ff54eSchris  // don't print the search form if search action has been disabled
74854e95700STom N Harris  if (!actionOk('search')) return false;
749670ff54eSchris
7501dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
7516b13307fSandi  print '<input type="hidden" name="do" value="search" />';
752c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
753bad31ae9SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';
75472645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
755818d04d3SAndreas Gohr  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[ALT+F]" />';
75611ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
75724a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
7584beabca9SAnika Henke  print '</div></form>';
75954e95700STom N Harris  return true;
7606b13307fSandi}
7616b13307fSandi
7626b13307fSandi/**
7636b13307fSandi * Print the breadcrumbs trace
7646b13307fSandi *
7656b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7666b13307fSandi */
76754e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
7686b13307fSandi  global $lang;
7696b13307fSandi  global $conf;
7706b13307fSandi
7716b13307fSandi  //check if enabled
77254e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
7736b13307fSandi
7746b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
775265e3787Sandi
7762979a10bSKatriel Traum  //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
7772979a10bSKatriel Traum  if($lang['direction'] == 'rtl') {
7782979a10bSKatriel Traum    $crumbs = array_reverse($crumbs,true);
7792979a10bSKatriel Traum    $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
7802979a10bSKatriel Traum  } else {
7812979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
7822979a10bSKatriel Traum  }
783265e3787Sandi
78440eb54bbSjan  //render crumbs, highlight the last one
7851b6f3a44SAndreas Gohr  print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
78640eb54bbSjan  $last = count($crumbs);
78740eb54bbSjan  $i = 0;
788a77f5846Sjan  foreach ($crumbs as $id => $name){
78940eb54bbSjan    $i++;
7902979a10bSKatriel Traum    echo $crumbs_sep;
79192795d04Sandi    if ($i == $last) print '<span class="curid">';
792e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
79392795d04Sandi    if ($i == $last) print '</span>';
7946b13307fSandi  }
79554e95700STom N Harris  return true;
7966b13307fSandi}
7976b13307fSandi
7986b13307fSandi/**
7991734437eSandi * Hierarchical breadcrumbs
8001734437eSandi *
80131e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8021734437eSandi * It only makes sense with a deep site structure.
8031734437eSandi *
8041734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8056bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
80631e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
807f46c9e83SAnika Henke * @author <fredrik@averpil.com>
8086bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
8091734437eSandi */
810796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
8111734437eSandi  global $conf;
8121734437eSandi  global $ID;
8131734437eSandi  global $lang;
8141734437eSandi
81531e187f8SSean Coates  // check if enabled
81654e95700STom N Harris  if(!$conf['youarehere']) return false;
8171734437eSandi
8181734437eSandi  $parts = explode(':', $ID);
819796bafb3SAndreas Gohr  $count = count($parts);
8201734437eSandi
8211b6f3a44SAndreas Gohr  echo '<span class="bchead">'.$lang['youarehere'].': </span>';
8221734437eSandi
8231734437eSandi  // always print the startpage
824796bafb3SAndreas Gohr  $title = p_get_first_heading($conf['start']);
825796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
826e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
827796bafb3SAndreas Gohr
828796bafb3SAndreas Gohr  // print intermediate namespace links
829796bafb3SAndreas Gohr  $part = '';
830796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
831796bafb3SAndreas Gohr    $part .= $parts[$i].':';
832796bafb3SAndreas Gohr    $page = $part;
833796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
834796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
835796bafb3SAndreas Gohr
836796bafb3SAndreas Gohr    // output
837796bafb3SAndreas Gohr    echo $sep;
838796bafb3SAndreas Gohr    if($exists){
839796bafb3SAndreas Gohr      $title = p_get_first_heading($page);
840796bafb3SAndreas Gohr      if(!$title) $title = $parts[$i];
841e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
84231e187f8SSean Coates    }else{
84378cbfcb6SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
84431e187f8SSean Coates    }
84531e187f8SSean Coates  }
8461734437eSandi
847796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
848d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
849796bafb3SAndreas Gohr  $page = $part.$parts[$i];
850796bafb3SAndreas Gohr  if($page == $conf['start']) return;
851796bafb3SAndreas Gohr  echo $sep;
852103c256aSChris Smith  if(page_exists($page)){
853796bafb3SAndreas Gohr    $title = p_get_first_heading($page);
854796bafb3SAndreas Gohr    if(!$title) $title = $parts[$i];
855e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
85631e187f8SSean Coates  }else{
85778cbfcb6SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
8581734437eSandi  }
85954e95700STom N Harris  return true;
8601734437eSandi}
8611734437eSandi
8621734437eSandi/**
8636b13307fSandi * Print info if the user is logged in
864a2488c3cSMatthias Grimm * and show full name in that case
8656b13307fSandi *
8666b13307fSandi * Could be enhanced with a profile link in future?
8676b13307fSandi *
8686b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8696b13307fSandi */
8706b13307fSandifunction tpl_userinfo(){
8716b13307fSandi  global $lang;
87254e95700STom N Harris  if($_SERVER['REMOTE_USER']){
873*dc58b6f4SAndy Webber    print $lang['loggedinas'].': '.editorinfo($_SERVER['REMOTE_USER']);
87454e95700STom N Harris    return true;
87554e95700STom N Harris  }
87654e95700STom N Harris  return false;
8776b13307fSandi}
8786b13307fSandi
8796b13307fSandi/**
8806b13307fSandi * Print some info about the current page
8816b13307fSandi *
8826b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8836b13307fSandi */
8844b0d3916SAndreas Gohrfunction tpl_pageinfo($ret=false){
8856b13307fSandi  global $conf;
8866b13307fSandi  global $lang;
8876b13307fSandi  global $INFO;
8886b13307fSandi  global $REV;
889c6e92a3cSDavid Lorentsen  global $ID;
890c6e92a3cSDavid Lorentsen
891c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
8924b0d3916SAndreas Gohr  if (!auth_quickaclcheck($ID)) { return false; }
8936b13307fSandi
8946b13307fSandi  // prepare date and path
8956b13307fSandi  $fn = $INFO['filepath'];
8966b13307fSandi  if(!$conf['fullpath']){
8976b13307fSandi    if($REV){
89850fbebceSGina Haeussge      $fn = str_replace(fullpath($conf['olddir']).'/','',$fn);
8996b13307fSandi    }else{
90050fbebceSGina Haeussge      $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
9016b13307fSandi    }
9026b13307fSandi  }
903bee6dc82Sandi  $fn = utf8_decodeFN($fn);
904e656dcd4SAndreas Gohr  $date = strftime($conf['dformat'],$INFO['lastmod']);
9056b13307fSandi
906faecdfdfSAndreas Gohr  // print it
907faecdfdfSAndreas Gohr  if($INFO['exists']){
9084b0d3916SAndreas Gohr    $out = '';
9094b0d3916SAndreas Gohr    $out .= $fn;
9104b0d3916SAndreas Gohr    $out .= ' &middot; ';
9114b0d3916SAndreas Gohr    $out .= $lang['lastmod'];
9124b0d3916SAndreas Gohr    $out .= ': ';
9134b0d3916SAndreas Gohr    $out .= $date;
9146b13307fSandi    if($INFO['editor']){
9154b0d3916SAndreas Gohr      $out .= ' '.$lang['by'].' ';
916*dc58b6f4SAndy Webber      $out .= editorinfo($INFO['editor']);
9175aa52fafSBen Coburn    }else{
9184b0d3916SAndreas Gohr      $out .= ' ('.$lang['external_edit'].')';
9196b13307fSandi    }
9206b13307fSandi    if($INFO['locked']){
9214b0d3916SAndreas Gohr      $out .= ' &middot; ';
9224b0d3916SAndreas Gohr      $out .= $lang['lockedby'];
9234b0d3916SAndreas Gohr      $out .= ': ';
924*dc58b6f4SAndy Webber      $out .= editorinfo($INFO['locked']);
9256b13307fSandi    }
9264b0d3916SAndreas Gohr    if($ret){
9274b0d3916SAndreas Gohr        return $out;
9284b0d3916SAndreas Gohr    }else{
9294b0d3916SAndreas Gohr        echo $out;
93054e95700STom N Harris        return true;
9316b13307fSandi    }
9324b0d3916SAndreas Gohr  }
93354e95700STom N Harris  return false;
9346b13307fSandi}
9356b13307fSandi
936820fa24bSandi/**
937a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
93887c434ceSAndreas Gohr *
93987c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
940a6598f23SBen Coburn * the given ID is used.
94187c434ceSAndreas Gohr *
94287c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
94387c434ceSAndreas Gohr */
944a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
94587c434ceSAndreas Gohr  global $conf;
94687c434ceSAndreas Gohr  if(is_null($id)){
94787c434ceSAndreas Gohr    global $ID;
94887c434ceSAndreas Gohr    $id = $ID;
94987c434ceSAndreas Gohr  }
95087c434ceSAndreas Gohr
95187c434ceSAndreas Gohr  $name = $id;
95287c434ceSAndreas Gohr  if ($conf['useheading']) {
95387c434ceSAndreas Gohr    $title = p_get_first_heading($id);
95487c434ceSAndreas Gohr    if ($title) $name = $title;
95587c434ceSAndreas Gohr  }
956a6598f23SBen Coburn
957a6598f23SBen Coburn  if ($ret) {
958a6598f23SBen Coburn      return hsc($name);
959a6598f23SBen Coburn  } else {
96087c434ceSAndreas Gohr      print hsc($name);
96154e95700STom N Harris      return true;
96287c434ceSAndreas Gohr  }
963a6598f23SBen Coburn}
964340756e4Sandi
96555efc227SAndreas Gohr/**
96655efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
96755efc227SAndreas Gohr *
96855efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
96955efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
97055efc227SAndreas Gohr *
97155efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
97255efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
97355efc227SAndreas Gohr * to the names of the latter one)
97455efc227SAndreas Gohr *
9753df72098SAndreas Gohr * Only allowed in: detail.php
97655efc227SAndreas Gohr *
97755efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
97855efc227SAndreas Gohr */
9793df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
98055efc227SAndreas Gohr  // Init Exif Reader
98155efc227SAndreas Gohr  global $SRC;
9823df72098SAndreas Gohr
9833df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
9843df72098SAndreas Gohr
98555efc227SAndreas Gohr  static $meta = null;
9863df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
98755efc227SAndreas Gohr  if($meta === false) return $alt;
98855efc227SAndreas Gohr  $info = $meta->getField($tags);
98955efc227SAndreas Gohr  if($info == false) return $alt;
99055efc227SAndreas Gohr  return $info;
99155efc227SAndreas Gohr}
99255efc227SAndreas Gohr
99355efc227SAndreas Gohr/**
99455efc227SAndreas Gohr * Prints the image with a link to the full sized version
99555efc227SAndreas Gohr *
99655efc227SAndreas Gohr * Only allowed in: detail.php
99755efc227SAndreas Gohr */
998f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
99955efc227SAndreas Gohr  global $IMG;
100055efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
100155efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
100255efc227SAndreas Gohr
100355efc227SAndreas Gohr  //resize to given max values
100423a34783SAndreas Gohr  $ratio = 1;
100523a34783SAndreas Gohr  if($w >= $h){
1006f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
100755efc227SAndreas Gohr      $ratio = $maxwidth/$w;
1008f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
100955efc227SAndreas Gohr      $ratio = $maxheight/$h;
101055efc227SAndreas Gohr    }
101155efc227SAndreas Gohr  }else{
1012f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
101355efc227SAndreas Gohr      $ratio = $maxheight/$h;
1014f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
101555efc227SAndreas Gohr      $ratio = $maxwidth/$w;
101655efc227SAndreas Gohr    }
101755efc227SAndreas Gohr  }
101855efc227SAndreas Gohr  if($ratio){
101955efc227SAndreas Gohr    $w = floor($ratio*$w);
102055efc227SAndreas Gohr    $h = floor($ratio*$h);
102155efc227SAndreas Gohr  }
102255efc227SAndreas Gohr
10236de3759aSAndreas Gohr  //prepare URLs
10246de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
10256de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
102655efc227SAndreas Gohr
10272684e50aSAndreas Gohr  //prepare attributes
102855efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
10292684e50aSAndreas Gohr  $p = array();
10302684e50aSAndreas Gohr  if($w) $p['width']  = $w;
10312684e50aSAndreas Gohr  if($h) $p['height'] = $h;
10322684e50aSAndreas Gohr         $p['class']  = 'img_detail';
10332684e50aSAndreas Gohr  if($alt){
10342684e50aSAndreas Gohr    $p['alt']   = $alt;
10352684e50aSAndreas Gohr    $p['title'] = $alt;
10362684e50aSAndreas Gohr  }else{
10372684e50aSAndreas Gohr    $p['alt'] = '';
10382684e50aSAndreas Gohr  }
10392684e50aSAndreas Gohr  $p = buildAttributes($p);
104055efc227SAndreas Gohr
104155efc227SAndreas Gohr  print '<a href="'.$url.'">';
10426de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
104355efc227SAndreas Gohr  print '</a>';
104454e95700STom N Harris  return true;
104555efc227SAndreas Gohr}
104655efc227SAndreas Gohr
10477367b368SAndreas Gohr/**
10487367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
10497367b368SAndreas Gohr * is the inexer function.
10507367b368SAndreas Gohr *
10517367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
10527367b368SAndreas Gohr * template
10537367b368SAndreas Gohr */
10547367b368SAndreas Gohrfunction tpl_indexerWebBug(){
10557367b368SAndreas Gohr  global $ID;
10561dad36f5SAndreas Gohr  global $INFO;
105754e95700STom N Harris  if(!$INFO['exists']) return false;
10581dad36f5SAndreas Gohr
105954e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
10600dc92c6fSAndreas Gohr
10617367b368SAndreas Gohr  $p = array();
1062b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1063e68c51baSAndreas Gohr                 '&'.time();
10647367b368SAndreas Gohr  $p['width']  = 1;
10657367b368SAndreas Gohr  $p['height'] = 1;
10667367b368SAndreas Gohr  $p['alt']    = '';
10677367b368SAndreas Gohr  $att = buildAttributes($p);
10687367b368SAndreas Gohr  print "<img $att />";
106954e95700STom N Harris  return true;
10707367b368SAndreas Gohr}
10717367b368SAndreas Gohr
107278d4e784SEsther Brunner// configuration methods
107378d4e784SEsther Brunner/**
107478d4e784SEsther Brunner * tpl_getConf($id)
107578d4e784SEsther Brunner *
107678d4e784SEsther Brunner * use this function to access template configuration variables
107778d4e784SEsther Brunner */
107878d4e784SEsther Brunnerfunction tpl_getConf($id){
107978d4e784SEsther Brunner  global $conf;
108078d4e784SEsther Brunner  global $tpl_configloaded;
108178d4e784SEsther Brunner
108278d4e784SEsther Brunner  $tpl = $conf['template'];
108378d4e784SEsther Brunner
108478d4e784SEsther Brunner  if (!$tpl_configloaded){
108578d4e784SEsther Brunner    $tconf = tpl_loadConfig();
108678d4e784SEsther Brunner    if ($tconf !== false){
108778d4e784SEsther Brunner      foreach ($tconf as $key => $value){
108878d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
108978d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
109078d4e784SEsther Brunner      }
109178d4e784SEsther Brunner      $tpl_configloaded = true;
109278d4e784SEsther Brunner    }
109378d4e784SEsther Brunner  }
109478d4e784SEsther Brunner
109578d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
109678d4e784SEsther Brunner}
109778d4e784SEsther Brunner
109878d4e784SEsther Brunner/**
109978d4e784SEsther Brunner * tpl_loadConfig()
110078d4e784SEsther Brunner * reads all template configuration variables
110178d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
110278d4e784SEsther Brunner */
110378d4e784SEsther Brunnerfunction tpl_loadConfig(){
110478d4e784SEsther Brunner
110578d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
110678d4e784SEsther Brunner  $conf = array();
110778d4e784SEsther Brunner
110878d4e784SEsther Brunner  if (!@file_exists($file)) return false;
110978d4e784SEsther Brunner
111078d4e784SEsther Brunner  // load default config file
111178d4e784SEsther Brunner  include($file);
111278d4e784SEsther Brunner
111378d4e784SEsther Brunner  return $conf;
111478d4e784SEsther Brunner}
111578d4e784SEsther Brunner
11163df72098SAndreas Gohr/**
11173df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
11183df72098SAndreas Gohr *
11193df72098SAndreas Gohr * Depending on the user's actions this may be a list of
11203df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
11213df72098SAndreas Gohr * a message of referencing pages
11223df72098SAndreas Gohr *
11233df72098SAndreas Gohr * Only allowed in mediamanager.php
11243df72098SAndreas Gohr *
11253df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11263df72098SAndreas Gohr */
11273df72098SAndreas Gohrfunction tpl_mediaContent(){
11283df72098SAndreas Gohr  global $IMG;
11293df72098SAndreas Gohr  global $AUTH;
11303df72098SAndreas Gohr  global $INUSE;
11313df72098SAndreas Gohr  global $NS;
11323df72098SAndreas Gohr  global $JUMPTO;
11333df72098SAndreas Gohr
11343df72098SAndreas Gohr  ptln('<div id="media__content">');
11353df72098SAndreas Gohr  if($_REQUEST['edit']){
11363df72098SAndreas Gohr    media_metaform($IMG,$AUTH);
11377b877f51SAndreas Gohr  }elseif(is_array($INUSE)){
11383df72098SAndreas Gohr    media_filesinuse($INUSE,$IMG);
11393df72098SAndreas Gohr  }else{
11403df72098SAndreas Gohr    media_filelist($NS,$AUTH,$JUMPTO);
11413df72098SAndreas Gohr  }
11423df72098SAndreas Gohr  ptln('</div>');
11433df72098SAndreas Gohr}
11443df72098SAndreas Gohr
11453df72098SAndreas Gohr/**
11463df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
11473df72098SAndreas Gohr *
11483df72098SAndreas Gohr * Only allowed in mediamanager.php
11493df72098SAndreas Gohr *
11503df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11513df72098SAndreas Gohr */
11523df72098SAndreas Gohrfunction tpl_mediaTree(){
11533df72098SAndreas Gohr  global $NS;
11543df72098SAndreas Gohr
11553df72098SAndreas Gohr  ptln('<div id="media__tree">');
11563df72098SAndreas Gohr  media_nstree($NS);
11573df72098SAndreas Gohr  ptln('</div>');
11583df72098SAndreas Gohr}
11593df72098SAndreas Gohr
1160a00de5b5SAndreas Gohr
1161a00de5b5SAndreas Gohr/**
1162a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1163a00de5b5SAndreas Gohr *
1164a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1165a00de5b5SAndreas Gohr *
1166a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1167a00de5b5SAndreas Gohr */
1168a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty='',$button='&gt;'){
1169a00de5b5SAndreas Gohr    global $ID;
1170a00de5b5SAndreas Gohr    global $INFO;
1171a00de5b5SAndreas Gohr    global $REV;
1172a00de5b5SAndreas Gohr    global $ACT;
1173a00de5b5SAndreas Gohr    global $conf;
1174a00de5b5SAndreas Gohr    global $lang;
1175a00de5b5SAndreas Gohr    global $auth;
1176a00de5b5SAndreas Gohr
1177a00de5b5SAndreas Gohr
1178a00de5b5SAndreas Gohr    echo '<form method="post" accept-charset="utf-8">'; #FIXME action
1179a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1180a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1181a00de5b5SAndreas Gohr    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1182a00de5b5SAndreas Gohr
1183a00de5b5SAndreas Gohr    echo '<select name="do" id="action__selector" class="edit">';
1184a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1185a00de5b5SAndreas Gohr
1186a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1187a00de5b5SAndreas Gohr        // 'edit' - most complicated type, we need to decide on current action
1188a00de5b5SAndreas Gohr        if($ACT == 'show' || $ACT == 'search'){
1189a00de5b5SAndreas Gohr            if($INFO['writable']){
1190a00de5b5SAndreas Gohr                if(!empty($INFO['draft'])) {
1191a00de5b5SAndreas Gohr                    echo '<option value="edit">'.$lang['btn_draft'].'</option>';
1192a00de5b5SAndreas Gohr                } else {
1193a00de5b5SAndreas Gohr                    if($INFO['exists']){
1194a00de5b5SAndreas Gohr                        echo '<option value="edit">'.$lang['btn_edit'].'</option>';
1195a00de5b5SAndreas Gohr                    }else{
1196a00de5b5SAndreas Gohr                        echo '<option value="edit">'.$lang['btn_create'].'</option>';
1197a00de5b5SAndreas Gohr                    }
1198a00de5b5SAndreas Gohr                }
1199a00de5b5SAndreas Gohr            }else if(actionOK('source')) { //pseudo action
1200a00de5b5SAndreas Gohr                echo '<option value="edit">'.$lang['btn_source'].'</option>';
1201a00de5b5SAndreas Gohr            }
1202a00de5b5SAndreas Gohr        }else{
1203a00de5b5SAndreas Gohr            echo '<option value="show">'.$lang['btn_show'].'</option>';
1204a00de5b5SAndreas Gohr        }
1205a00de5b5SAndreas Gohr
1206a00de5b5SAndreas Gohr        echo '<option value="revisions">'.$lang['btn_revs'].'</option>';
1207a00de5b5SAndreas Gohr        echo '<option value="backlink">'.$lang['btn_backlink'].'</option>';
1208a00de5b5SAndreas Gohr    echo '</optgroup>';
1209a00de5b5SAndreas Gohr
1210a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1211a00de5b5SAndreas Gohr        echo '<option value="recent">'.$lang['btn_recent'].'</option>';
1212a00de5b5SAndreas Gohr        echo '<option value="index">'.$lang['btn_index'].'</option>';
1213a00de5b5SAndreas Gohr    echo '</optgroup>';
1214a00de5b5SAndreas Gohr
1215a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1216a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth){
1217a00de5b5SAndreas Gohr            if($_SERVER['REMOTE_USER']){
1218a00de5b5SAndreas Gohr                echo '<option value="logout">'.$lang['btn_logout'].'</option>';
1219a00de5b5SAndreas Gohr            }else{
1220a00de5b5SAndreas Gohr                echo '<option value="login">'.$lang['btn_login'].'</option>';
1221a00de5b5SAndreas Gohr            }
1222a00de5b5SAndreas Gohr        }
1223a00de5b5SAndreas Gohr
1224a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
1225a00de5b5SAndreas Gohr             $auth->canDo('Profile') && ($ACT!='profile')){
1226a00de5b5SAndreas Gohr            echo '<option value="profile">'.$lang['btn_profile'].'</option>';
1227a00de5b5SAndreas Gohr        }
1228a00de5b5SAndreas Gohr
1229a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
1230a00de5b5SAndreas Gohr            if($_SERVER['REMOTE_USER']){
1231a00de5b5SAndreas Gohr                if($INFO['subscribed']) {
1232a00de5b5SAndreas Gohr                    echo '<option value="unsubscribe">'.$lang['btn_unsubscribe'].'</option>';
1233a00de5b5SAndreas Gohr                } else {
1234a00de5b5SAndreas Gohr                    echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>';
1235a00de5b5SAndreas Gohr                }
1236a00de5b5SAndreas Gohr            }
1237a00de5b5SAndreas Gohr        }
1238a00de5b5SAndreas Gohr
1239a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
1240a00de5b5SAndreas Gohr            if($_SERVER['REMOTE_USER']){
1241a00de5b5SAndreas Gohr                if($INFO['subscribedns']) {
1242a00de5b5SAndreas Gohr                    echo '<option value="unsubscribens">'.$lang['btn_unsubscribens'].'</option>';
1243a00de5b5SAndreas Gohr                } else {
1244a00de5b5SAndreas Gohr                    echo '<option value="subscribens">'.$lang['btn_subscribens'].'</option>';
1245a00de5b5SAndreas Gohr                }
1246a00de5b5SAndreas Gohr            }
1247a00de5b5SAndreas Gohr        }
1248a00de5b5SAndreas Gohr
1249a00de5b5SAndreas Gohr        if($INFO['ismanager']){
1250a00de5b5SAndreas Gohr            echo '<option value="admin">'.$lang['btn_admin'].'</option>';
1251a00de5b5SAndreas Gohr        }
1252a00de5b5SAndreas Gohr    echo '</optgroup>';
1253a00de5b5SAndreas Gohr
1254a00de5b5SAndreas Gohr    echo '</select>';
1255a00de5b5SAndreas Gohr    echo '<input type="submit" value="'.$button.'" id="action__selectorbtn" />';
1256a00de5b5SAndreas Gohr    echo '</form>';
1257a00de5b5SAndreas Gohr}
1258a00de5b5SAndreas Gohr
1259b8595a66SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
1260a00de5b5SAndreas Gohr
1261