xref: /dokuwiki/inc/template.php (revision 202ac28bb12b2bb376b138947c43e8b72eb78091)
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
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
106b13307fSandi
116b13307fSandi/**
125a892029SAndreas Gohr * Returns the path to the given template, uses
13524be65dSBen Coburn * default one if the custom version doesn't exist.
145a892029SAndreas Gohr *
155a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
165a892029SAndreas Gohr */
175a892029SAndreas Gohrfunction template($tpl){
185a892029SAndreas Gohr  global $conf;
195a892029SAndreas Gohr
205a892029SAndreas Gohr  if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
215a892029SAndreas Gohr    return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
225a892029SAndreas Gohr
235a892029SAndreas Gohr  return DOKU_INC.'lib/tpl/default/'.$tpl;
245a892029SAndreas Gohr}
255a892029SAndreas Gohr
265a892029SAndreas Gohr/**
276b13307fSandi * Print the content
286b13307fSandi *
296b13307fSandi * This function is used for printing all the usual content
306b13307fSandi * (defined by the global $ACT var) by calling the appropriate
316b13307fSandi * outputfunction(s) from html.php
326b13307fSandi *
33ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
34ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
356b13307fSandi *
366b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
376b13307fSandi */
38b8595a66SAndreas Gohrfunction tpl_content($prependTOC=true) {
397ea0913cSchris    global $ACT;
40b8595a66SAndreas Gohr    global $INFO;
41b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
427ea0913cSchris
437ea0913cSchris    ob_start();
44746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
457ea0913cSchris    $html_output = ob_get_clean();
46746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
4754e95700STom N Harris
4854e95700STom N Harris    return !empty($html_output);
497ea0913cSchris}
507ea0913cSchris
517ea0913cSchrisfunction tpl_content_core(){
526b13307fSandi  global $ACT;
536b13307fSandi  global $TEXT;
546b13307fSandi  global $PRE;
556b13307fSandi  global $SUF;
566b13307fSandi  global $SUM;
576b13307fSandi  global $IDX;
586b13307fSandi
596b13307fSandi  switch($ACT){
606b13307fSandi    case 'show':
616b13307fSandi      html_show();
626b13307fSandi      break;
63ea67f144Sandi    case 'preview':
646b13307fSandi      html_edit($TEXT);
656b13307fSandi      html_show($TEXT);
666b13307fSandi      break;
67ee4c4a1bSAndreas Gohr    case 'recover':
68ee4c4a1bSAndreas Gohr      html_edit($TEXT);
69ee4c4a1bSAndreas Gohr      break;
706b13307fSandi    case 'edit':
716b13307fSandi      html_edit();
726b13307fSandi      break;
73ee4c4a1bSAndreas Gohr    case 'draft':
74ee4c4a1bSAndreas Gohr      html_draft();
75ee4c4a1bSAndreas Gohr      break;
766b13307fSandi    case 'wordblock':
776b13307fSandi      html_edit($TEXT,'wordblock');
786b13307fSandi      break;
796b13307fSandi    case 'search':
806b13307fSandi      html_search();
816b13307fSandi      break;
826b13307fSandi    case 'revisions':
83c66972f2SAdrian Lang      $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
8471726d78SBen Coburn      html_revisions($first);
856b13307fSandi      break;
866b13307fSandi    case 'diff':
876b13307fSandi      html_diff();
886b13307fSandi      break;
896b13307fSandi    case 'recent':
90abdcc39fSmichael      if (is_array($_REQUEST['first'])) {
91abdcc39fSmichael        $_REQUEST['first'] = array_keys($_REQUEST['first']);
92abdcc39fSmichael        $_REQUEST['first'] = $_REQUEST['first'][0];
93abdcc39fSmichael      }
945749f1ceSmatthiasgrimm      $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
95a39955b0Smatthiasgrimm      html_recent($first);
966b13307fSandi      break;
976b13307fSandi    case 'index':
986b13307fSandi      html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
996b13307fSandi      break;
1006b13307fSandi    case 'backlink':
1016b13307fSandi      html_backlinks();
1026b13307fSandi      break;
1036b13307fSandi    case 'conflict':
1046b13307fSandi      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1056b13307fSandi      html_diff(con($PRE,$TEXT,$SUF),false);
1066b13307fSandi      break;
1076b13307fSandi    case 'locked':
108ee20e7d1Sandi      html_locked();
10927eb9321SAnika Henke      html_edit();
1106b13307fSandi      break;
1116b13307fSandi    case 'login':
1126b13307fSandi      html_login();
1136b13307fSandi      break;
1146b13307fSandi    case 'register':
1156b13307fSandi      html_register();
1166b13307fSandi      break;
1178b06d178Schris    case 'resendpwd':
1188b06d178Schris      html_resendpwd();
1198b06d178Schris      break;
120820fa24bSandi    case 'denied':
1215e991bd8Sandi      print p_locale_xhtml('denied');
122820fa24bSandi      break;
1238b06d178Schris    case 'profile' :
1248b06d178Schris      html_updateprofile();
1258b06d178Schris      break;
126c19fe9c0Sandi    case 'admin':
127c19fe9c0Sandi      tpl_admin();
128c19fe9c0Sandi      break;
1296b13307fSandi    default:
13024bb549bSchris      $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
13124bb549bSchris      if ($evt->advise_before())
132ea67f144Sandi        msg("Failed to handle command: ".hsc($ACT),-1);
13324bb549bSchris      $evt->advise_after();
13424bb549bSchris      unset($evt);
13554e95700STom N Harris      return false;
1366b13307fSandi  }
13754e95700STom N Harris  return true;
1386b13307fSandi}
1396b13307fSandi
140c19fe9c0Sandi/**
141b8595a66SAndreas Gohr * Places the TOC where the function is called
142b8595a66SAndreas Gohr *
143b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
144b8595a66SAndreas Gohr * a false argument
145b8595a66SAndreas Gohr *
146b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
147b8595a66SAndreas Gohr */
148b8595a66SAndreas Gohrfunction tpl_toc($return=false){
149b8595a66SAndreas Gohr    global $TOC;
150b8595a66SAndreas Gohr    global $ACT;
151b8595a66SAndreas Gohr    global $ID;
152b8595a66SAndreas Gohr    global $REV;
153b8595a66SAndreas Gohr    global $INFO;
154851f2e89SAnika Henke    global $conf;
155b8595a66SAndreas Gohr    $toc = array();
156b8595a66SAndreas Gohr
157b8595a66SAndreas Gohr    if(is_array($TOC)){
158b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
159b8595a66SAndreas Gohr        $toc = $TOC;
1603c86d7c9SAndreas Gohr    }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){
161b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
162b8595a66SAndreas Gohr        $meta = p_get_metadata($ID, false, true);
163b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])){
164b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
165b8595a66SAndreas Gohr        }else{
1662bb0d541Schris            $tocok = true;
167b8595a66SAndreas Gohr        }
168b8595a66SAndreas Gohr        $toc   = $meta['description']['tableofcontents'];
169851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){
170b8595a66SAndreas Gohr            $toc = array();
171b8595a66SAndreas Gohr        }
172b8595a66SAndreas Gohr    }elseif($ACT == 'admin'){
173b8595a66SAndreas Gohr        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
174b8595a66SAndreas Gohr        $plugin = null;
175b8595a66SAndreas Gohr        if (!empty($_REQUEST['page'])) {
176b8595a66SAndreas Gohr            $pluginlist = plugin_list('admin');
177b8595a66SAndreas Gohr            if (in_array($_REQUEST['page'], $pluginlist)) {
178b8595a66SAndreas Gohr                // attempt to load the plugin
179b8595a66SAndreas Gohr                $plugin =& plugin_load('admin',$_REQUEST['page']);
180b8595a66SAndreas Gohr            }
181b8595a66SAndreas Gohr        }
182b8595a66SAndreas Gohr        if ( ($plugin !== null) &&
183b8595a66SAndreas Gohr             (!$plugin->forAdminOnly() || $INFO['isadmin']) ){
184b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
185b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
186b8595a66SAndreas Gohr        }
187b8595a66SAndreas Gohr    }
188b8595a66SAndreas Gohr
1897dee3468SGina Haeussge    trigger_event('TPL_TOC_RENDER', $toc, NULL, false);
190b8595a66SAndreas Gohr    $html = html_TOC($toc);
191b8595a66SAndreas Gohr    if($return) return $html;
192b8595a66SAndreas Gohr    echo $html;
193b8595a66SAndreas Gohr}
194b8595a66SAndreas Gohr
195b8595a66SAndreas Gohr/**
196c19fe9c0Sandi * Handle the admin page contents
197c19fe9c0Sandi *
198c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
199c19fe9c0Sandi */
200c19fe9c0Sandifunction tpl_admin(){
201f8cc712eSAndreas Gohr    global $INFO;
202b8595a66SAndreas Gohr    global $TOC;
20311e2ce22Schris
204b8595a66SAndreas Gohr    $plugin = null;
205bb4866bdSchris    if (!empty($_REQUEST['page'])) {
20611e2ce22Schris        $pluginlist = plugin_list('admin');
20711e2ce22Schris
20811e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
20911e2ce22Schris
21011e2ce22Schris          // attempt to load the plugin
21111e2ce22Schris          $plugin =& plugin_load('admin',$_REQUEST['page']);
21211e2ce22Schris        }
21311e2ce22Schris    }
21411e2ce22Schris
215b8595a66SAndreas Gohr    if ($plugin !== null){
216f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
217f8cc712eSAndreas Gohr            msg('For admins only',-1);
21811e2ce22Schris            html_admin();
219f8cc712eSAndreas Gohr        }else{
220b8595a66SAndreas Gohr            if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
221b8595a66SAndreas Gohr            if($INFO['prependTOC']) tpl_toc();
222f8cc712eSAndreas Gohr            $plugin->html();
223f8cc712eSAndreas Gohr        }
224f8cc712eSAndreas Gohr    }else{
225f8cc712eSAndreas Gohr        html_admin();
226f8cc712eSAndreas Gohr    }
22754e95700STom N Harris    return true;
228c19fe9c0Sandi}
2296b13307fSandi
2306b13307fSandi/**
2316b13307fSandi * Print the correct HTML meta headers
2326b13307fSandi *
2336b13307fSandi * This has to go into the head section of your template.
2346b13307fSandi *
235016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
236f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
2376b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2386b13307fSandi */
239f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
2406b13307fSandi  global $ID;
241d98d4540SBen Coburn  global $REV;
2426b13307fSandi  global $INFO;
24372e0dc37SAndreas Gohr  global $JSINFO;
2446b13307fSandi  global $ACT;
2454bb1b5aeSAndreas Gohr  global $QUERY;
2466b13307fSandi  global $lang;
247dc57ef04Sandi  global $conf;
2486b13307fSandi  $it=2;
2496b13307fSandi
2507bff22c0SAndreas Gohr  // prepare the head array
2517bff22c0SAndreas Gohr  $head = array();
2527bff22c0SAndreas Gohr
253*202ac28bSMichael Klier  // prepare seed for js and css
254*202ac28bSMichael Klier  $tseed = 0;
255*202ac28bSMichael Klier  $depends = getConfigFiles('main');
256*202ac28bSMichael Klier  foreach($depends as $f) {
257*202ac28bSMichael Klier      $time = @filemtime($f);
258*202ac28bSMichael Klier      if($time > $tseed) $tseed = $time;
259*202ac28bSMichael Klier  }
2607bff22c0SAndreas Gohr
2616b13307fSandi  // the usual stuff
2627bff22c0SAndreas Gohr  $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
263da96af35SAndreas Gohr  $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
264da96af35SAndreas Gohr                           'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
265f4f47358SBen Coburn  $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
2667aedde2eSGina Haeussge  if(actionOK('index')){
2677bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
268bb4866bdSchris                           'title'=>$lang['btn_index'] );
2697aedde2eSGina Haeussge  }
270f96fa415SAndreas Gohr
271f96fa415SAndreas Gohr  if($alt){
2727bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2737bff22c0SAndreas Gohr                             'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2747bff22c0SAndreas Gohr    $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2757bff22c0SAndreas Gohr                             'title'=>'Current Namespace',
2767bff22c0SAndreas Gohr                             'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
277c35f3875SAndreas Gohr    if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){
278a2c734d5SAndreas Gohr        $head['link'][] = array( 'rel'=>'edit',
279715bdf1fSAndreas Gohr                                 'title'=>$lang['btn_edit'],
280c35f3875SAndreas Gohr                                 'href'=> wl($ID,'do=edit',false,'&'));
281c35f3875SAndreas Gohr    }
282c35f3875SAndreas Gohr
2834bb1b5aeSAndreas Gohr    if($ACT == 'search'){
2844bb1b5aeSAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2854bb1b5aeSAndreas Gohr                               'title'=>'Search Result',
2864bb1b5aeSAndreas Gohr                               'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
2874bb1b5aeSAndreas Gohr    }
288bae36d94SAndreas Gohr
289bae36d94SAndreas Gohr    if(actionOK('export_xhtml')){
2907bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2917bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'xhtml', '', false, '&'));
292bae36d94SAndreas Gohr    }
293bae36d94SAndreas Gohr
294bae36d94SAndreas Gohr    if(actionOK('export_raw')){
2957bff22c0SAndreas Gohr      $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2967bff22c0SAndreas Gohr                               'href'=>exportlink($ID, 'raw', '', false, '&'));
297f96fa415SAndreas Gohr    }
298bae36d94SAndreas Gohr  }
2996b13307fSandi
3006b13307fSandi  // setup robot tags apropriate for different modes
3014f2e0004STim Weber  if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
3026b13307fSandi    if($INFO['exists']){
3036b13307fSandi      //delay indexing:
3046b13307fSandi      if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
3057bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
3066b13307fSandi      }else{
3077bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3086b13307fSandi      }
30969db0cafSAndreas Gohr      $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') );
3106b13307fSandi    }else{
3117bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
3126b13307fSandi    }
3137a24876fSAndreas Gohr  }elseif(defined('DOKU_MEDIADETAIL')){
3147bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
3156b13307fSandi  }else{
3167bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3176b13307fSandi  }
3186b13307fSandi
319831800b8SAndreas Gohr  // set metadata
320831800b8SAndreas Gohr  if($ACT == 'show' || $ACT=='export_xhtml'){
321831800b8SAndreas Gohr    // date of modification
322831800b8SAndreas Gohr    if($REV){
3237bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
324831800b8SAndreas Gohr    }else{
3257bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
326831800b8SAndreas Gohr    }
327831800b8SAndreas Gohr
328831800b8SAndreas Gohr    // keywords (explicit or implicit)
329bb4866bdSchris    if(!empty($INFO['meta']['subject'])){
3307bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
331831800b8SAndreas Gohr    }else{
3327bff22c0SAndreas Gohr      $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
333831800b8SAndreas Gohr    }
334831800b8SAndreas Gohr  }
335831800b8SAndreas Gohr
33678a6aeb1SAndreas Gohr  // load stylesheets
3377aaa4c46Smartin.tschofen  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
338*202ac28bSMichael Klier                          'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template'].'&tseed='.$tseed);
3397bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
340*202ac28bSMichael Klier                          'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed);
3417bff22c0SAndreas Gohr  $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
342*202ac28bSMichael Klier                          'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template'].'&tseed='.$tseed);
343bad31ae9SAndreas Gohr
3448bbcb611SAndreas Gohr  // make $INFO and other vars available to JavaScripts
345463d4a65SAndreas Gohr  require_once(DOKU_INC.'inc/JSON.php');
346463d4a65SAndreas Gohr  $json = new JSON();
34772e0dc37SAndreas Gohr  $script = "var NS='".$INFO['namespace']."';";
348c591aabeSAndreas Gohr  if($conf['useacl'] && $_SERVER['REMOTE_USER']){
349aeaccbf9SAndreas Gohr      require_once(DOKU_INC.'inc/toolbar.php');
35072e0dc37SAndreas Gohr      $script .= "var SIG='".toolbar_signature()."';";
351c591aabeSAndreas Gohr  }
35272e0dc37SAndreas Gohr  $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
3537bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
3547bff22c0SAndreas Gohr                               '_data'=> $script);
3558bbcb611SAndreas Gohr
3568bbcb611SAndreas Gohr  // load external javascript
3577bff22c0SAndreas Gohr  $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
358*202ac28bSMichael Klier                             'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed);
3597bff22c0SAndreas Gohr
36083a482b6SAndreas Gohr
3617bff22c0SAndreas Gohr  // trigger event here
362016b6153SAndreas Gohr  trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
36354e95700STom N Harris  return true;
3647bff22c0SAndreas Gohr}
3657bff22c0SAndreas Gohr
3667bff22c0SAndreas Gohr/**
3677bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3687bff22c0SAndreas Gohr *
3697bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3707bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3717bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3727bff22c0SAndreas Gohr *
3737bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
3741304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3757bff22c0SAndreas Gohr *
3767bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3777bff22c0SAndreas Gohr */
3787bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3797bff22c0SAndreas Gohr  foreach($data as $tag => $inst){
3807bff22c0SAndreas Gohr    foreach($inst as $attr){
3817bff22c0SAndreas Gohr      echo '<',$tag,' ',buildAttributes($attr);
38226afa874SMikhail I. Izmestev      if(isset($attr['_data']) || $tag == 'script'){
383e226efe1SAndreas Gohr          if($tag == 'script' && $attr['_data'])
384e226efe1SAndreas Gohr            $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
385e226efe1SAndreas Gohr                             $attr['_data'].
386e226efe1SAndreas Gohr                             "\n//--><!]]>";
387e226efe1SAndreas Gohr
3881304d1dbSAndreas Gohr          echo '>',$attr['_data'],'</',$tag,'>';
3897bff22c0SAndreas Gohr      }else{
3907bff22c0SAndreas Gohr        echo '/>';
3917bff22c0SAndreas Gohr      }
3927bff22c0SAndreas Gohr      echo "\n";
3937bff22c0SAndreas Gohr    }
3947bff22c0SAndreas Gohr  }
3956b13307fSandi}
3966b13307fSandi
3976b13307fSandi/**
3986b13307fSandi * Print a link
3996b13307fSandi *
4005e163278SAndreas Gohr * Just builds a link.
4016b13307fSandi *
4026b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
4036b13307fSandi */
4041af98a77SAnika Henkefunction tpl_link($url,$name,$more='',$return=false){
40501f17825SAnika Henke  $out = '<a href="'.$url.'" ';
4061af98a77SAnika Henke  if ($more) $out .= ' '.$more;
4071af98a77SAnika Henke  $out .= ">$name</a>";
4081af98a77SAnika Henke  if ($return) return $out;
4091af98a77SAnika Henke  print $out;
41054e95700STom N Harris  return true;
4116b13307fSandi}
4126b13307fSandi
4136b13307fSandi/**
41455efc227SAndreas Gohr * Prints a link to a WikiPage
41555efc227SAndreas Gohr *
41655efc227SAndreas Gohr * Wrapper around html_wikilink
41755efc227SAndreas Gohr *
41855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
41955efc227SAndreas Gohr */
42055efc227SAndreas Gohrfunction tpl_pagelink($id,$name=NULL){
42155efc227SAndreas Gohr  print html_wikilink($id,$name);
42254e95700STom N Harris  return true;
42355efc227SAndreas Gohr}
42455efc227SAndreas Gohr
42555efc227SAndreas Gohr/**
426a3ec5f4aSmatthiasgrimm * get the parent page
427a3ec5f4aSmatthiasgrimm *
428a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
429a3ec5f4aSmatthiasgrimm * returns false if none is available
430a3ec5f4aSmatthiasgrimm *
431377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
432a3ec5f4aSmatthiasgrimm */
433377f9e97SAndreas Gohrfunction tpl_getparent($id){
434a3ec5f4aSmatthiasgrimm  global $conf;
435377f9e97SAndreas Gohr  $parent = getNS($id).':';
436377f9e97SAndreas Gohr  resolve_pageid('',$parent,$exists);
437a197105eSmatthiasgrimm  if($parent == $id) {
438a197105eSmatthiasgrimm    $pos = strrpos (getNS($id),':');
439a197105eSmatthiasgrimm    $parent = substr($parent,0,$pos).':';
440a197105eSmatthiasgrimm    resolve_pageid('',$parent,$exists);
441377f9e97SAndreas Gohr    if($parent == $id) return false;
442a197105eSmatthiasgrimm  }
443377f9e97SAndreas Gohr  return $parent;
444a3ec5f4aSmatthiasgrimm}
445a3ec5f4aSmatthiasgrimm
446a3ec5f4aSmatthiasgrimm/**
4476b13307fSandi * Print one of the buttons
4486b13307fSandi *
4496b13307fSandi * Available Buttons are
4506b13307fSandi *
451ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
4526b13307fSandi *  history     - old revisions
4536b13307fSandi *  recent      - recent changes
4546b13307fSandi *  login       - login/logout button - if ACL enabled
455d449b912SDenis Simakov *  profile     - user profile button (if logged in)
4566b13307fSandi *  index       - The index
457c19fe9c0Sandi *  admin       - admin page - if enough rights
4586b13307fSandi *  top         - a back to top button
459a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
460bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
461d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
4626b13307fSandi *
4636b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
464a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
4656b13307fSandi */
4661af98a77SAnika Henkefunction tpl_button($type,$return=false){
467b158d625SSteven Danz  global $ACT;
4686b13307fSandi  global $ID;
469d98d4540SBen Coburn  global $REV;
470d67ca2c0Smatthiasgrimm  global $NS;
471c19fe9c0Sandi  global $INFO;
4726b13307fSandi  global $conf;
473cd52f92dSchris  global $auth;
4746b13307fSandi
47575e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
47675e487e9SAndreas Gohr  $ctype = $type;
47775e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
47854e95700STom N Harris  if(!actionOK($ctype)) return false;
479409d7af7SAndreas Gohr
4801af98a77SAnika Henke  $out = '';
4816b13307fSandi  switch($type){
4826b13307fSandi    case 'edit':
483409d7af7SAndreas Gohr      #most complicated type - we need to decide on current action
484409d7af7SAndreas Gohr      if($ACT == 'show' || $ACT == 'search'){
485409d7af7SAndreas Gohr        if($INFO['writable']){
486bb4866bdSchris          if(!empty($INFO['draft'])){
4871af98a77SAnika Henke            $out .= html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
488409d7af7SAndreas Gohr          }else{
489409d7af7SAndreas Gohr            if($INFO['exists']){
4901af98a77SAnika Henke              $out .= html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
491409d7af7SAndreas Gohr            }else{
4921af98a77SAnika Henke              $out .= html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
493409d7af7SAndreas Gohr            }
494409d7af7SAndreas Gohr          }
495409d7af7SAndreas Gohr        }else{
496409d7af7SAndreas Gohr          if(!actionOK('source')) return false; //pseudo action
4971af98a77SAnika Henke          $out .= html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
498409d7af7SAndreas Gohr        }
499409d7af7SAndreas Gohr      }else{
5001af98a77SAnika Henke          $out .= html_btn('show',$ID,'v',array('do' => 'show'));
501409d7af7SAndreas Gohr      }
5021af98a77SAnika Henke      break;
5036b13307fSandi    case 'history':
5041af98a77SAnika Henke      if(actionOK('revisions'))
5051af98a77SAnika Henke        $out .= html_btn('revs',$ID,'o',array('do' => 'revisions'));
5061af98a77SAnika Henke      break;
5076b13307fSandi    case 'recent':
5081af98a77SAnika Henke      if(actionOK('recent'))
5091af98a77SAnika Henke        $out .= html_btn('recent',$ID,'r',array('do' => 'recent'));
5101af98a77SAnika Henke      break;
5116b13307fSandi    case 'index':
5121af98a77SAnika Henke      if(actionOK('index'))
5131af98a77SAnika Henke        $out .= html_btn('index',$ID,'x',array('do' => 'index'));
5141af98a77SAnika Henke      break;
515a3ec5f4aSmatthiasgrimm    case 'back':
5166222040cSmatthiasgrimm      if ($parent = tpl_getparent($ID)) {
5171af98a77SAnika Henke        $out .= html_btn('back',$parent,'b',array('do' => 'show'));
518a3ec5f4aSmatthiasgrimm      }
5191af98a77SAnika Henke      break;
5206b13307fSandi    case 'top':
5211af98a77SAnika Henke      $out .= html_topbtn();
5221af98a77SAnika Henke      break;
5236b13307fSandi    case 'login':
5246957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
525c66972f2SAdrian Lang        if(isset($_SERVER['REMOTE_USER'])){
5261af98a77SAnika Henke          $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken()));
5276b13307fSandi        }else{
5281af98a77SAnika Henke          $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken()));
5296b13307fSandi        }
5306b13307fSandi      }
5311af98a77SAnika Henke      break;
532c19fe9c0Sandi    case 'admin':
53354e95700STom N Harris      if($INFO['ismanager']){
5341af98a77SAnika Henke        $out .= html_btn('admin',$ID,'',array('do' => 'admin'));
53554e95700STom N Harris      }
5361af98a77SAnika Henke      break;
5371246e016SAndreas Gohr    case 'revert':
5381246e016SAndreas Gohr      if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
5391246e016SAndreas Gohr        $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken()));
5401246e016SAndreas Gohr      }
5411246e016SAndreas Gohr      break;
542582c5bfeSAndreas Gohr    case 'subscribe':
5431380fc45SAndreas Gohr    case 'subscription':
5446957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
545b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
5461380fc45SAndreas Gohr          if($INFO['subscribed']){
5471af98a77SAnika Henke            if(actionOK('unsubscribe'))
5481af98a77SAnika Henke              $out .= html_btn('unsubscribe',$ID,'',array('do' => 'unsubscribe',));
549b158d625SSteven Danz          } else {
5501af98a77SAnika Henke            if(actionOK('subscribe'))
5511af98a77SAnika Henke              $out .= html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
552582c5bfeSAndreas Gohr          }
553582c5bfeSAndreas Gohr        }
5541af98a77SAnika Henke      }
5551af98a77SAnika Henke      if($type == 'subscribe') break;
5561af98a77SAnika Henke      // else: fall through for backward compatibility
557582c5bfeSAndreas Gohr    case 'subscribens':
558582c5bfeSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
559582c5bfeSAndreas Gohr        if($_SERVER['REMOTE_USER']){
56052b0dd67SGuy Brand          if($INFO['subscribedns']){
5611af98a77SAnika Henke            if(actionOK('unsubscribens'))
5621af98a77SAnika Henke              $out .= html_btn('unsubscribens',$ID,'',array('do' => 'unsubscribens',));
56352b0dd67SGuy Brand          } else {
5641af98a77SAnika Henke            if(actionOK('subscribens'))
5651af98a77SAnika Henke              $out .= html_btn('subscribens',$ID,'',array('do' => 'subscribens',));
566b158d625SSteven Danz          }
567b158d625SSteven Danz        }
5681af98a77SAnika Henke      }
5691af98a77SAnika Henke      break;
570f00151b4Schris    case 'backlink':
5711af98a77SAnika Henke      if(actionOK('backlink'))
5721af98a77SAnika Henke        $out .= html_btn('backlink',$ID,'',array('do' => 'backlink'));
5734c30ec5fSAndreas Gohr      break;
5748b06d178Schris    case 'profile':
575c66972f2SAdrian Lang      if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth &&
57636223ba7SAndreas Gohr          $auth->canDo('Profile') && ($ACT!='profile')){
5771af98a77SAnika Henke        $out .= html_btn('profile',$ID,'',array('do' => 'profile'));
5788b06d178Schris      }
5791af98a77SAnika Henke      break;
580c19fe9c0Sandi    default:
5811af98a77SAnika Henke      $out .= '[unknown button type]';
5821af98a77SAnika Henke      break;
5836b13307fSandi  }
5841af98a77SAnika Henke  if ($return) return $out;
5851af98a77SAnika Henke  print $out;
5861af98a77SAnika Henke  return $out ? true : false;
5876b13307fSandi}
5886b13307fSandi
5896b13307fSandi/**
590ed630903Sandi * Like the action buttons but links
591ed630903Sandi *
592ed630903Sandi * Available links are
593ed630903Sandi *
594d449b912SDenis Simakov *  edit    - edit/create/show link
595ed630903Sandi *  history - old revisions
596ed630903Sandi *  recent  - recent changes
597d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
598d449b912SDenis Simakov *  profile - user profile link (if logged in)
599ed630903Sandi *  index   - The index
600ed630903Sandi *  admin   - admin page - if enough rights
601d449b912SDenis Simakov *  top     - a back to top link
602d449b912SDenis Simakov *  back    - a back to parent link - if available
603bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
604d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
605ed630903Sandi *
606ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
607a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
608ed630903Sandi * @see    tpl_button
609ed630903Sandi */
6101af98a77SAnika Henkefunction tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
611ed630903Sandi  global $ID;
612ed630903Sandi  global $INFO;
613ed630903Sandi  global $REV;
614ed630903Sandi  global $ACT;
615ed630903Sandi  global $conf;
616ed630903Sandi  global $lang;
617cd52f92dSchris  global $auth;
618ed630903Sandi
61975e487e9SAndreas Gohr  // check disabled actions and fix the badly named ones
62075e487e9SAndreas Gohr  $ctype = $type;
62175e487e9SAndreas Gohr  if($type == 'history') $ctype='revisions';
62254e95700STom N Harris  if(!actionOK($ctype)) return false;
623409d7af7SAndreas Gohr
6241af98a77SAnika Henke  $out = '';
625ed630903Sandi  switch($type){
626ed630903Sandi    case 'edit':
627ed630903Sandi      #most complicated type - we need to decide on current action
628ed630903Sandi      if($ACT == 'show' || $ACT == 'search'){
629ed630903Sandi        if($INFO['writable']){
630b8a111f5SMichael Klier          if(!empty($INFO['draft'])) {
6311af98a77SAnika Henke            $out .= tpl_link(wl($ID,'do=draft'),
632c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_draft']).$suf,
6331af98a77SAnika Henke                       'class="action edit" accesskey="e" rel="nofollow"',1);
634b8a111f5SMichael Klier          } else {
635ed630903Sandi            if($INFO['exists']){
6361af98a77SAnika Henke              $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
637c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_edit']).$suf,
6381af98a77SAnika Henke                       'class="action edit" accesskey="e" rel="nofollow"',1);
639ed630903Sandi            }else{
6401af98a77SAnika Henke              $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
641c97dfb07SAndreas Gohr                       $pre.(($inner)?$inner:$lang['btn_create']).$suf,
6421af98a77SAnika Henke                       'class="action create" accesskey="e" rel="nofollow"',1);
643ed630903Sandi            }
644b8a111f5SMichael Klier          }
645ed630903Sandi        }else{
6461af98a77SAnika Henke          if(actionOK('source')) //pseudo action
6471af98a77SAnika Henke            $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
648c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_source']).$suf,
6491af98a77SAnika Henke                   'class="action source" accesskey="v" rel="nofollow"',1);
650ed630903Sandi        }
651ed630903Sandi      }else{
6521af98a77SAnika Henke          $out .= tpl_link(wl($ID,'do=show'),
653c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_show']).$suf,
6541af98a77SAnika Henke                   'class="action show" accesskey="v" rel="nofollow"',1);
655ed630903Sandi      }
6561af98a77SAnika Henke      break;
657ed630903Sandi    case 'history':
6581af98a77SAnika Henke      if(actionOK('revisions'))
6591af98a77SAnika Henke        $out .= tpl_link(wl($ID,'do=revisions'),
660c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_revs']).$suf,
6611af98a77SAnika Henke               'class="action revisions" accesskey="o" rel="nofollow"',1);
6621af98a77SAnika Henke      break;
663ed630903Sandi    case 'recent':
6641af98a77SAnika Henke      if(actionOK('recent'))
6651af98a77SAnika Henke        $out .= tpl_link(wl($ID,'do=recent'),
666c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_recent']).$suf,
6671af98a77SAnika Henke              'class="action recent" accesskey="r" rel="nofollow"',1);
6681af98a77SAnika Henke      break;
669ed630903Sandi    case 'index':
6701af98a77SAnika Henke      if(actionOK('index'))
6711af98a77SAnika Henke        $out .= tpl_link(wl($ID,'do=index'),
672c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_index']).$suf,
6731af98a77SAnika Henke              'class="action index" accesskey="x" rel="nofollow"',1);
6741af98a77SAnika Henke      break;
675ed630903Sandi    case 'top':
6761af98a77SAnika Henke      $out .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'.
677c97dfb07SAndreas Gohr            $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>';
6781af98a77SAnika Henke      break;
679a3ec5f4aSmatthiasgrimm    case 'back':
680f7569b7bSAndreas Gohr      if ($parent = tpl_getparent($ID)) {
6811af98a77SAnika Henke        $out .= tpl_link(wl($parent,'do=show'),
682c97dfb07SAndreas Gohr        $pre.(($inner)?$inner:$lang['btn_back']).$suf,
6831af98a77SAnika Henke        'class="action back" accesskey="b" rel="nofollow"',1);
684a3ec5f4aSmatthiasgrimm      }
6851af98a77SAnika Henke      break;
686ed630903Sandi    case 'login':
6876957b2eaSAndreas Gohr      if($conf['useacl'] && $auth){
688ed630903Sandi        if($_SERVER['REMOTE_USER']){
6891af98a77SAnika Henke          $out .= tpl_link(wl($ID,'do=logout&amp;sectok='.getSecurityToken()),
690c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_logout']).$suf,
6911af98a77SAnika Henke                   'class="action logout" rel="nofollow"',1);
692ed630903Sandi        }else{
6931af98a77SAnika Henke          $out .= tpl_link(wl($ID,'do=login&amp;sectok='.getSecurityToken()),
694c97dfb07SAndreas Gohr                   $pre.(($inner)?$inner:$lang['btn_login']).$suf,
6951af98a77SAnika Henke                   'class="action login" rel="nofollow"',1);
696ed630903Sandi        }
697ed630903Sandi      }
6981af98a77SAnika Henke      break;
699ed630903Sandi    case 'admin':
700f8cc712eSAndreas Gohr      if($INFO['ismanager']){
7011af98a77SAnika Henke        $out .= tpl_link(wl($ID,'do=admin'),
702c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_admin']).$suf,
7031af98a77SAnika Henke                 'class="action admin" rel="nofollow"',1);
704c059e1a6SAndreas Gohr      }
7051af98a77SAnika Henke      break;
7061246e016SAndreas Gohr    case 'revert':
7071246e016SAndreas Gohr      if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
7081246e016SAndreas Gohr        $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())),
7091246e016SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_revert']).$suf,
7101246e016SAndreas Gohr                 'class="action revert" rel="nofollow"',1);
7111246e016SAndreas Gohr      }
7121246e016SAndreas Gohr      break;
713f9eb5648Ssteven-danz   case 'subscribe':
714075f000fSChristopher Arndt   case 'subscription':
7156957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
716b158d625SSteven Danz        if($_SERVER['REMOTE_USER']){
717075f000fSChristopher Arndt          if($INFO['subscribed']) {
7181af98a77SAnika Henke            if(actionOK('unsubscribe'))
7191af98a77SAnika Henke              $out .= tpl_link(wl($ID,'do=unsubscribe'),
720c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_unsubscribe']).$suf,
7211af98a77SAnika Henke                     'class="action unsubscribe" rel="nofollow"',1);
722b158d625SSteven Danz          } else {
7231af98a77SAnika Henke            if(actionOK('subscribe'))
7241af98a77SAnika Henke              $out .= tpl_link(wl($ID,'do=subscribe'),
725c97dfb07SAndreas Gohr                     $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf,
7261af98a77SAnika Henke                     'class="action subscribe" rel="nofollow"',1);
727b158d625SSteven Danz          }
728b158d625SSteven Danz        }
7291af98a77SAnika Henke      }
7301af98a77SAnika Henke      if($type == 'subscribe') break;
7311af98a77SAnika Henke      // else: fall through for backward compatibility
732280f11b7SMichael Klier    case 'subscribens':
733280f11b7SMichael Klier      if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
734280f11b7SMichael Klier        if($_SERVER['REMOTE_USER']){
735280f11b7SMichael Klier          if($INFO['subscribedns']) {
7361af98a77SAnika Henke            if(actionOK('unsubscribens'))
7371af98a77SAnika Henke              $out .= tpl_link(wl($ID,'do=unsubscribens'),
738280f11b7SMichael Klier                     $pre.(($inner)?$inner:$lang['btn_unsubscribens']).$suf,
7391af98a77SAnika Henke                     'class="action unsubscribens" rel="nofollow"',1);
740280f11b7SMichael Klier          } else {
7411af98a77SAnika Henke            if(actionOK('subscribens'))
7421af98a77SAnika Henke              $out .= tpl_link(wl($ID,'do=subscribens'),
743280f11b7SMichael Klier                     $pre.(($inner)?$inner:$lang['btn_subscribens']).$suf,
7441af98a77SAnika Henke                     'class="action subscribens" rel="nofollow"',1);
745280f11b7SMichael Klier          }
746280f11b7SMichael Klier        }
7471af98a77SAnika Henke      }
7481af98a77SAnika Henke      break;
749f00151b4Schris    case 'backlink':
7501af98a77SAnika Henke      if(actionOK('backlink'))
7511af98a77SAnika Henke        $out .= tpl_link(wl($ID,'do=backlink'),
752c97dfb07SAndreas Gohr               $pre.(($inner)?$inner:$lang['btn_backlink']).$suf,
7531af98a77SAnika Henke               'class="action backlink" rel="nofollow"',1);
7541af98a77SAnika Henke      break;
7558b06d178Schris    case 'profile':
7566957b2eaSAndreas Gohr      if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
75736223ba7SAndreas Gohr         $auth->canDo('Profile') && ($ACT!='profile')){
7581af98a77SAnika Henke        $out .= tpl_link(wl($ID,'do=profile'),
759c97dfb07SAndreas Gohr                 $pre.(($inner)?$inner:$lang['btn_profile']).$suf,
7601af98a77SAnika Henke                 'class="action profile" rel="nofollow"',1);
7618b06d178Schris      }
7621af98a77SAnika Henke      break;
763ed630903Sandi    default:
7641af98a77SAnika Henke      $out .= '[unknown link type]';
7651af98a77SAnika Henke      break;
766ed630903Sandi  }
7671af98a77SAnika Henke  if ($return) return $out;
7681af98a77SAnika Henke  print $out;
7691af98a77SAnika Henke  return $out ? true : false;
770ed630903Sandi}
771ed630903Sandi
772ed630903Sandi/**
77301f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
77401f17825SAnika Henke *
77501f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
77601f17825SAnika Henke */
77701f17825SAnika Henkefunction tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') {
77801f17825SAnika Henke    $out = '';
77901f17825SAnika Henke    if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1);
78001f17825SAnika Henke    else $out .= tpl_button($type,1);
78101f17825SAnika Henke    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
78201f17825SAnika Henke
78301f17825SAnika Henke    if ($return) return $out;
78401f17825SAnika Henke    print $out;
78501f17825SAnika Henke    return $out ? true : false;
78601f17825SAnika Henke}
78701f17825SAnika Henke
78801f17825SAnika Henke/**
7896b13307fSandi * Print the search form
7906b13307fSandi *
79172645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
79272645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
79372645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
79472645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
79572645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
79672645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
79772645b75SAndreas Gohr *
7986b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7996b13307fSandi */
80072645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
8016b13307fSandi  global $lang;
802c1e3b7d9Smatthiasgrimm  global $ACT;
803ad4aaef7SAndreas Gohr  global $QUERY;
804c1e3b7d9Smatthiasgrimm
805670ff54eSchris  // don't print the search form if search action has been disabled
80654e95700STom N Harris  if (!actionOk('search')) return false;
807670ff54eSchris
8081dd0c202SAnika Henke  print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
8096b13307fSandi  print '<input type="hidden" name="do" value="search" />';
810c1e3b7d9Smatthiasgrimm  print '<input type="text" ';
811ad4aaef7SAndreas Gohr  if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
81272645b75SAndreas Gohr  if(!$autocomplete) print 'autocomplete="off" ';
81307493d05SAnika Henke  print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
81411ea018fSAndreas Gohr  print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
81524a33b42SAndreas Gohr  if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
8164beabca9SAnika Henke  print '</div></form>';
81754e95700STom N Harris  return true;
8186b13307fSandi}
8196b13307fSandi
8206b13307fSandi/**
8216b13307fSandi * Print the breadcrumbs trace
8226b13307fSandi *
8236b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8246b13307fSandi */
82554e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
8266b13307fSandi  global $lang;
8276b13307fSandi  global $conf;
8286b13307fSandi
8296b13307fSandi  //check if enabled
83054e95700STom N Harris  if(!$conf['breadcrumbs']) return false;
8316b13307fSandi
8326b13307fSandi  $crumbs = breadcrumbs(); //setup crumb trace
833265e3787Sandi
8342979a10bSKatriel Traum  //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
8352979a10bSKatriel Traum  if($lang['direction'] == 'rtl') {
8362979a10bSKatriel Traum    $crumbs = array_reverse($crumbs,true);
8372979a10bSKatriel Traum    $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
8382979a10bSKatriel Traum  } else {
8392979a10bSKatriel Traum    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
8402979a10bSKatriel Traum  }
841265e3787Sandi
84240eb54bbSjan  //render crumbs, highlight the last one
8431b6f3a44SAndreas Gohr  print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
84440eb54bbSjan  $last = count($crumbs);
84540eb54bbSjan  $i = 0;
846a77f5846Sjan  foreach ($crumbs as $id => $name){
84740eb54bbSjan    $i++;
8482979a10bSKatriel Traum    echo $crumbs_sep;
84992795d04Sandi    if ($i == $last) print '<span class="curid">';
850e26fd1eeSAndreas Gohr    tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
85192795d04Sandi    if ($i == $last) print '</span>';
8526b13307fSandi  }
85354e95700STom N Harris  return true;
8546b13307fSandi}
8556b13307fSandi
8566b13307fSandi/**
8571734437eSandi * Hierarchical breadcrumbs
8581734437eSandi *
85931e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8601734437eSandi * It only makes sense with a deep site structure.
8611734437eSandi *
8621734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8636bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
86431e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
865f46c9e83SAnika Henke * @author <fredrik@averpil.com>
8666bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
8671734437eSandi */
868796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
8691734437eSandi  global $conf;
8701734437eSandi  global $ID;
8711734437eSandi  global $lang;
8721734437eSandi
87331e187f8SSean Coates  // check if enabled
87454e95700STom N Harris  if(!$conf['youarehere']) return false;
8751734437eSandi
8761734437eSandi  $parts = explode(':', $ID);
877796bafb3SAndreas Gohr  $count = count($parts);
8781734437eSandi
8793b437163SAlexey Torkhov  if($GLOBALS['ACT'] == 'search')
8803b437163SAlexey Torkhov  {
8813b437163SAlexey Torkhov    $parts = array($conf['start']);
8823b437163SAlexey Torkhov    $count = 1;
8833b437163SAlexey Torkhov  }
8843b437163SAlexey Torkhov
8851b6f3a44SAndreas Gohr  echo '<span class="bchead">'.$lang['youarehere'].': </span>';
8861734437eSandi
8871734437eSandi  // always print the startpage
888fe9ec250SChris Smith  $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start'];
889796bafb3SAndreas Gohr  if(!$title) $title = $conf['start'];
890e26fd1eeSAndreas Gohr  tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
891796bafb3SAndreas Gohr
892796bafb3SAndreas Gohr  // print intermediate namespace links
893796bafb3SAndreas Gohr  $part = '';
894796bafb3SAndreas Gohr  for($i=0; $i<$count - 1; $i++){
895796bafb3SAndreas Gohr    $part .= $parts[$i].':';
896796bafb3SAndreas Gohr    $page = $part;
897796bafb3SAndreas Gohr    resolve_pageid('',$page,$exists);
898796bafb3SAndreas Gohr    if ($page == $conf['start']) continue; // Skip startpage
899796bafb3SAndreas Gohr
900796bafb3SAndreas Gohr    // output
901796bafb3SAndreas Gohr    echo $sep;
902796bafb3SAndreas Gohr    if($exists){
903af03da1aSAndreas Gohr      $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
904e26fd1eeSAndreas Gohr      tpl_link(wl($page),hsc($title),'title="'.$page.'"');
90531e187f8SSean Coates    }else{
90678cbfcb6SAndreas Gohr      tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
90731e187f8SSean Coates    }
90831e187f8SSean Coates  }
9091734437eSandi
910796bafb3SAndreas Gohr  // print current page, skipping start page, skipping for namespace index
911d98d4540SBen Coburn  if(isset($page) && $page==$part.$parts[$i]) return;
912796bafb3SAndreas Gohr  $page = $part.$parts[$i];
913796bafb3SAndreas Gohr  if($page == $conf['start']) return;
914796bafb3SAndreas Gohr  echo $sep;
915103c256aSChris Smith  if(page_exists($page)){
916af03da1aSAndreas Gohr    $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
917e26fd1eeSAndreas Gohr    tpl_link(wl($page),hsc($title),'title="'.$page.'"');
91831e187f8SSean Coates  }else{
91978cbfcb6SAndreas Gohr    tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
9201734437eSandi  }
92154e95700STom N Harris  return true;
9221734437eSandi}
9231734437eSandi
9241734437eSandi/**
9256b13307fSandi * Print info if the user is logged in
926a2488c3cSMatthias Grimm * and show full name in that case
9276b13307fSandi *
9286b13307fSandi * Could be enhanced with a profile link in future?
9296b13307fSandi *
9306b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
9316b13307fSandi */
9326b13307fSandifunction tpl_userinfo(){
9336b13307fSandi  global $lang;
9343e63b73bSMichael Klier  global $INFO;
935c66972f2SAdrian Lang  if(isset($_SERVER['REMOTE_USER'])){
9363e63b73bSMichael Klier    print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')';
93754e95700STom N Harris    return true;
93854e95700STom N Harris  }
93954e95700STom N Harris  return false;
9406b13307fSandi}
9416b13307fSandi
9426b13307fSandi/**
9436b13307fSandi * Print some info about the current page
9446b13307fSandi *
9456b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
9466b13307fSandi */
9474b0d3916SAndreas Gohrfunction tpl_pageinfo($ret=false){
9486b13307fSandi  global $conf;
9496b13307fSandi  global $lang;
9506b13307fSandi  global $INFO;
951c6e92a3cSDavid Lorentsen  global $ID;
952c6e92a3cSDavid Lorentsen
953c6e92a3cSDavid Lorentsen  // return if we are not allowed to view the page
9544b0d3916SAndreas Gohr  if (!auth_quickaclcheck($ID)) { return false; }
9556b13307fSandi
9566b13307fSandi  // prepare date and path
9576b13307fSandi  $fn = $INFO['filepath'];
9586b13307fSandi  if(!$conf['fullpath']){
959613bca54SAndreas Gohr    if($INFO['rev']){
96050fbebceSGina Haeussge      $fn = str_replace(fullpath($conf['olddir']).'/','',$fn);
9616b13307fSandi    }else{
96250fbebceSGina Haeussge      $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
9636b13307fSandi    }
9646b13307fSandi  }
965bee6dc82Sandi  $fn = utf8_decodeFN($fn);
966f2263577SAndreas Gohr  $date = dformat($INFO['lastmod']);
9676b13307fSandi
968faecdfdfSAndreas Gohr  // print it
969faecdfdfSAndreas Gohr  if($INFO['exists']){
9704b0d3916SAndreas Gohr    $out = '';
9714b0d3916SAndreas Gohr    $out .= $fn;
9724b0d3916SAndreas Gohr    $out .= ' &middot; ';
9734b0d3916SAndreas Gohr    $out .= $lang['lastmod'];
9744b0d3916SAndreas Gohr    $out .= ': ';
9754b0d3916SAndreas Gohr    $out .= $date;
9766b13307fSandi    if($INFO['editor']){
9774b0d3916SAndreas Gohr      $out .= ' '.$lang['by'].' ';
978dc58b6f4SAndy Webber      $out .= editorinfo($INFO['editor']);
9795aa52fafSBen Coburn    }else{
9804b0d3916SAndreas Gohr      $out .= ' ('.$lang['external_edit'].')';
9816b13307fSandi    }
9826b13307fSandi    if($INFO['locked']){
9834b0d3916SAndreas Gohr      $out .= ' &middot; ';
9844b0d3916SAndreas Gohr      $out .= $lang['lockedby'];
9854b0d3916SAndreas Gohr      $out .= ': ';
986dc58b6f4SAndy Webber      $out .= editorinfo($INFO['locked']);
9876b13307fSandi    }
9884b0d3916SAndreas Gohr    if($ret){
9894b0d3916SAndreas Gohr        return $out;
9904b0d3916SAndreas Gohr    }else{
9914b0d3916SAndreas Gohr        echo $out;
99254e95700STom N Harris        return true;
9936b13307fSandi    }
9944b0d3916SAndreas Gohr  }
99554e95700STom N Harris  return false;
9966b13307fSandi}
9976b13307fSandi
998820fa24bSandi/**
999a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
100087c434ceSAndreas Gohr *
100187c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
1002a6598f23SBen Coburn * the given ID is used.
100387c434ceSAndreas Gohr *
100487c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
100587c434ceSAndreas Gohr */
1006a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
100787c434ceSAndreas Gohr  global $conf;
100887c434ceSAndreas Gohr  if(is_null($id)){
100987c434ceSAndreas Gohr    global $ID;
101087c434ceSAndreas Gohr    $id = $ID;
101187c434ceSAndreas Gohr  }
101287c434ceSAndreas Gohr
101387c434ceSAndreas Gohr  $name = $id;
1014fe9ec250SChris Smith  if (useHeading('navigation')) {
101587c434ceSAndreas Gohr    $title = p_get_first_heading($id);
101687c434ceSAndreas Gohr    if ($title) $name = $title;
101787c434ceSAndreas Gohr  }
1018a6598f23SBen Coburn
1019a6598f23SBen Coburn  if ($ret) {
1020a6598f23SBen Coburn      return hsc($name);
1021a6598f23SBen Coburn  } else {
102287c434ceSAndreas Gohr      print hsc($name);
102354e95700STom N Harris      return true;
102487c434ceSAndreas Gohr  }
1025a6598f23SBen Coburn}
1026340756e4Sandi
102755efc227SAndreas Gohr/**
102855efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
102955efc227SAndreas Gohr *
103055efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
103155efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
103255efc227SAndreas Gohr *
103355efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
103455efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
103555efc227SAndreas Gohr * to the names of the latter one)
103655efc227SAndreas Gohr *
10373df72098SAndreas Gohr * Only allowed in: detail.php
103855efc227SAndreas Gohr *
103955efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
104055efc227SAndreas Gohr */
10413df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
104255efc227SAndreas Gohr  // Init Exif Reader
104355efc227SAndreas Gohr  global $SRC;
10443df72098SAndreas Gohr
10453df72098SAndreas Gohr  if(is_null($src)) $src = $SRC;
10463df72098SAndreas Gohr
104755efc227SAndreas Gohr  static $meta = null;
10483df72098SAndreas Gohr  if(is_null($meta)) $meta = new JpegMeta($src);
104955efc227SAndreas Gohr  if($meta === false) return $alt;
105055efc227SAndreas Gohr  $info = $meta->getField($tags);
105155efc227SAndreas Gohr  if($info == false) return $alt;
105255efc227SAndreas Gohr  return $info;
105355efc227SAndreas Gohr}
105455efc227SAndreas Gohr
105555efc227SAndreas Gohr/**
105655efc227SAndreas Gohr * Prints the image with a link to the full sized version
105755efc227SAndreas Gohr *
105855efc227SAndreas Gohr * Only allowed in: detail.php
105955efc227SAndreas Gohr */
1060f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
106155efc227SAndreas Gohr  global $IMG;
106255efc227SAndreas Gohr  $w = tpl_img_getTag('File.Width');
106355efc227SAndreas Gohr  $h = tpl_img_getTag('File.Height');
106455efc227SAndreas Gohr
106555efc227SAndreas Gohr  //resize to given max values
106623a34783SAndreas Gohr  $ratio = 1;
106723a34783SAndreas Gohr  if($w >= $h){
1068f8925855Sjoe.lapp    if($maxwidth && $w >= $maxwidth){
106955efc227SAndreas Gohr      $ratio = $maxwidth/$w;
1070f8925855Sjoe.lapp    }elseif($maxheight && $h > $maxheight){
107155efc227SAndreas Gohr      $ratio = $maxheight/$h;
107255efc227SAndreas Gohr    }
107355efc227SAndreas Gohr  }else{
1074f8925855Sjoe.lapp    if($maxheight && $h >= $maxheight){
107555efc227SAndreas Gohr      $ratio = $maxheight/$h;
1076f8925855Sjoe.lapp    }elseif($maxwidth && $w > $maxwidth){
107755efc227SAndreas Gohr      $ratio = $maxwidth/$w;
107855efc227SAndreas Gohr    }
107955efc227SAndreas Gohr  }
108055efc227SAndreas Gohr  if($ratio){
108155efc227SAndreas Gohr    $w = floor($ratio*$w);
108255efc227SAndreas Gohr    $h = floor($ratio*$h);
108355efc227SAndreas Gohr  }
108455efc227SAndreas Gohr
10856de3759aSAndreas Gohr  //prepare URLs
10866de3759aSAndreas Gohr  $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
10876de3759aSAndreas Gohr  $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
108855efc227SAndreas Gohr
10892684e50aSAndreas Gohr  //prepare attributes
109055efc227SAndreas Gohr  $alt=tpl_img_getTag('Simple.Title');
10912684e50aSAndreas Gohr  $p = array();
10922684e50aSAndreas Gohr  if($w) $p['width']  = $w;
10932684e50aSAndreas Gohr  if($h) $p['height'] = $h;
10942684e50aSAndreas Gohr         $p['class']  = 'img_detail';
10952684e50aSAndreas Gohr  if($alt){
10962684e50aSAndreas Gohr    $p['alt']   = $alt;
10972684e50aSAndreas Gohr    $p['title'] = $alt;
10982684e50aSAndreas Gohr  }else{
10992684e50aSAndreas Gohr    $p['alt'] = '';
11002684e50aSAndreas Gohr  }
11012684e50aSAndreas Gohr  $p = buildAttributes($p);
110255efc227SAndreas Gohr
110355efc227SAndreas Gohr  print '<a href="'.$url.'">';
11046de3759aSAndreas Gohr  print '<img src="'.$src.'" '.$p.'/>';
110555efc227SAndreas Gohr  print '</a>';
110654e95700STom N Harris  return true;
110755efc227SAndreas Gohr}
110855efc227SAndreas Gohr
11097367b368SAndreas Gohr/**
11107367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
1111c66972f2SAdrian Lang * is the indexer function.
11127367b368SAndreas Gohr *
11137367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
11147367b368SAndreas Gohr * template
11157367b368SAndreas Gohr */
11167367b368SAndreas Gohrfunction tpl_indexerWebBug(){
11177367b368SAndreas Gohr  global $ID;
11181dad36f5SAndreas Gohr  global $INFO;
111954e95700STom N Harris  if(!$INFO['exists']) return false;
11201dad36f5SAndreas Gohr
112154e95700STom N Harris  if(isHiddenPage($ID)) return false; //no need to index hidden pages
11220dc92c6fSAndreas Gohr
11237367b368SAndreas Gohr  $p = array();
1124b6c6979fSAndreas Gohr  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1125e68c51baSAndreas Gohr                 '&'.time();
11267367b368SAndreas Gohr  $p['width']  = 1;
11277367b368SAndreas Gohr  $p['height'] = 1;
11287367b368SAndreas Gohr  $p['alt']    = '';
11297367b368SAndreas Gohr  $att = buildAttributes($p);
11307367b368SAndreas Gohr  print "<img $att />";
113154e95700STom N Harris  return true;
11327367b368SAndreas Gohr}
11337367b368SAndreas Gohr
113478d4e784SEsther Brunner// configuration methods
113578d4e784SEsther Brunner/**
113678d4e784SEsther Brunner * tpl_getConf($id)
113778d4e784SEsther Brunner *
113878d4e784SEsther Brunner * use this function to access template configuration variables
113978d4e784SEsther Brunner */
114078d4e784SEsther Brunnerfunction tpl_getConf($id){
114178d4e784SEsther Brunner  global $conf;
114278d4e784SEsther Brunner  global $tpl_configloaded;
114378d4e784SEsther Brunner
114478d4e784SEsther Brunner  $tpl = $conf['template'];
114578d4e784SEsther Brunner
114678d4e784SEsther Brunner  if (!$tpl_configloaded){
114778d4e784SEsther Brunner    $tconf = tpl_loadConfig();
114878d4e784SEsther Brunner    if ($tconf !== false){
114978d4e784SEsther Brunner      foreach ($tconf as $key => $value){
115078d4e784SEsther Brunner        if (isset($conf['tpl'][$tpl][$key])) continue;
115178d4e784SEsther Brunner        $conf['tpl'][$tpl][$key] = $value;
115278d4e784SEsther Brunner      }
115378d4e784SEsther Brunner      $tpl_configloaded = true;
115478d4e784SEsther Brunner    }
115578d4e784SEsther Brunner  }
115678d4e784SEsther Brunner
115778d4e784SEsther Brunner  return $conf['tpl'][$tpl][$id];
115878d4e784SEsther Brunner}
115978d4e784SEsther Brunner
116078d4e784SEsther Brunner/**
116178d4e784SEsther Brunner * tpl_loadConfig()
116278d4e784SEsther Brunner * reads all template configuration variables
116378d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
116478d4e784SEsther Brunner */
116578d4e784SEsther Brunnerfunction tpl_loadConfig(){
116678d4e784SEsther Brunner
116778d4e784SEsther Brunner  $file = DOKU_TPLINC.'/conf/default.php';
116878d4e784SEsther Brunner  $conf = array();
116978d4e784SEsther Brunner
117078d4e784SEsther Brunner  if (!@file_exists($file)) return false;
117178d4e784SEsther Brunner
117278d4e784SEsther Brunner  // load default config file
117378d4e784SEsther Brunner  include($file);
117478d4e784SEsther Brunner
117578d4e784SEsther Brunner  return $conf;
117678d4e784SEsther Brunner}
117778d4e784SEsther Brunner
11783df72098SAndreas Gohr/**
11793df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
11803df72098SAndreas Gohr *
11813df72098SAndreas Gohr * Depending on the user's actions this may be a list of
11823df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
11833df72098SAndreas Gohr * a message of referencing pages
11843df72098SAndreas Gohr *
11853df72098SAndreas Gohr * Only allowed in mediamanager.php
11863df72098SAndreas Gohr *
1187c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1188c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
11893df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11903df72098SAndreas Gohr */
1191c182313eSAndreas Gohrfunction tpl_mediaContent($fromajax=false){
11923df72098SAndreas Gohr  global $IMG;
11933df72098SAndreas Gohr  global $AUTH;
11943df72098SAndreas Gohr  global $INUSE;
11953df72098SAndreas Gohr  global $NS;
11963df72098SAndreas Gohr  global $JUMPTO;
11973df72098SAndreas Gohr
1198c9f56829SAndreas Gohr  if(is_array($_REQUEST['do'])){
1199c9f56829SAndreas Gohr    $do = array_shift(array_keys($_REQUEST['do']));
12003df72098SAndreas Gohr  }else{
1201c182313eSAndreas Gohr    $do = $_REQUEST['do'];
12023df72098SAndreas Gohr  }
1203c182313eSAndreas Gohr  if(in_array($do,array('save','cancel'))) $do = '';
1204c182313eSAndreas Gohr
1205c182313eSAndreas Gohr  if(!$do){
1206c182313eSAndreas Gohr      if($_REQUEST['edit']){
1207c182313eSAndreas Gohr        $do = 'metaform';
1208c182313eSAndreas Gohr      }elseif(is_array($INUSE)){
1209c182313eSAndreas Gohr        $do = 'filesinuse';
1210c182313eSAndreas Gohr      }else{
1211c182313eSAndreas Gohr        $do = 'filelist';
1212c182313eSAndreas Gohr      }
1213c182313eSAndreas Gohr  }
1214c182313eSAndreas Gohr
1215c182313eSAndreas Gohr  // output the content pane, wrapped in an event.
1216c182313eSAndreas Gohr  if(!$fromajax) ptln('<div id="media__content">');
1217c182313eSAndreas Gohr  $data = array( 'do' => $do);
1218c182313eSAndreas Gohr  $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1219c182313eSAndreas Gohr  if ($evt->advise_before()) {
1220c182313eSAndreas Gohr    $do = $data['do'];
1221c182313eSAndreas Gohr    if($do == 'metaform'){
1222c182313eSAndreas Gohr      media_metaform($IMG,$AUTH);
1223c182313eSAndreas Gohr    }elseif($do == 'filesinuse'){
1224c182313eSAndreas Gohr      media_filesinuse($INUSE,$IMG);
1225c182313eSAndreas Gohr    }elseif($do == 'filelist'){
1226c182313eSAndreas Gohr      media_filelist($NS,$AUTH,$JUMPTO);
1227c9f56829SAndreas Gohr    }elseif($do == 'searchlist'){
1228c9f56829SAndreas Gohr      media_searchlist($_REQUEST['q'],$NS,$AUTH);
1229c182313eSAndreas Gohr    }else{
1230c182313eSAndreas Gohr      msg('Unknown action '.hsc($do),-1);
1231c182313eSAndreas Gohr    }
1232c182313eSAndreas Gohr  }
1233c182313eSAndreas Gohr  $evt->advise_after();
1234c182313eSAndreas Gohr  unset($evt);
1235c182313eSAndreas Gohr  if(!$fromajax) ptln('</div>');
1236c182313eSAndreas Gohr
12373df72098SAndreas Gohr}
12383df72098SAndreas Gohr
12393df72098SAndreas Gohr/**
12403df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
12413df72098SAndreas Gohr *
12423df72098SAndreas Gohr * Only allowed in mediamanager.php
12433df72098SAndreas Gohr *
12443df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
12453df72098SAndreas Gohr */
12463df72098SAndreas Gohrfunction tpl_mediaTree(){
12473df72098SAndreas Gohr  global $NS;
12483df72098SAndreas Gohr
12493df72098SAndreas Gohr  ptln('<div id="media__tree">');
12503df72098SAndreas Gohr  media_nstree($NS);
12513df72098SAndreas Gohr  ptln('</div>');
12523df72098SAndreas Gohr}
12533df72098SAndreas Gohr
1254a00de5b5SAndreas Gohr
1255a00de5b5SAndreas Gohr/**
1256a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1257a00de5b5SAndreas Gohr *
1258a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1259a00de5b5SAndreas Gohr *
1260a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1261a00de5b5SAndreas Gohr */
1262a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty='',$button='&gt;'){
1263a00de5b5SAndreas Gohr    global $ID;
1264a00de5b5SAndreas Gohr    global $INFO;
1265a00de5b5SAndreas Gohr    global $REV;
1266a00de5b5SAndreas Gohr    global $ACT;
1267a00de5b5SAndreas Gohr    global $conf;
1268a00de5b5SAndreas Gohr    global $lang;
1269a00de5b5SAndreas Gohr    global $auth;
1270a00de5b5SAndreas Gohr
1271a00de5b5SAndreas Gohr
1272a00de5b5SAndreas Gohr    echo '<form method="post" accept-charset="utf-8">'; #FIXME action
1273a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1274a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1275a00de5b5SAndreas Gohr    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1276a00de5b5SAndreas Gohr
1277a00de5b5SAndreas Gohr    echo '<select name="do" id="action__selector" class="edit">';
1278a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1279a00de5b5SAndreas Gohr
1280a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1281a00de5b5SAndreas Gohr        // 'edit' - most complicated type, we need to decide on current action
1282a00de5b5SAndreas Gohr        if($ACT == 'show' || $ACT == 'search'){
1283a00de5b5SAndreas Gohr            if($INFO['writable']){
1284a00de5b5SAndreas Gohr                if(!empty($INFO['draft'])) {
1285a00de5b5SAndreas Gohr                    echo '<option value="edit">'.$lang['btn_draft'].'</option>';
1286a00de5b5SAndreas Gohr                } else {
1287a00de5b5SAndreas Gohr                    if($INFO['exists']){
1288a00de5b5SAndreas Gohr                        echo '<option value="edit">'.$lang['btn_edit'].'</option>';
1289a00de5b5SAndreas Gohr                    }else{
1290a00de5b5SAndreas Gohr                        echo '<option value="edit">'.$lang['btn_create'].'</option>';
1291a00de5b5SAndreas Gohr                    }
1292a00de5b5SAndreas Gohr                }
1293a00de5b5SAndreas Gohr            }else if(actionOK('source')) { //pseudo action
1294a00de5b5SAndreas Gohr                echo '<option value="edit">'.$lang['btn_source'].'</option>';
1295a00de5b5SAndreas Gohr            }
1296a00de5b5SAndreas Gohr        }else{
1297a00de5b5SAndreas Gohr            echo '<option value="show">'.$lang['btn_show'].'</option>';
1298a00de5b5SAndreas Gohr        }
1299a00de5b5SAndreas Gohr
1300a00de5b5SAndreas Gohr        echo '<option value="revisions">'.$lang['btn_revs'].'</option>';
13011246e016SAndreas Gohr        if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
13021246e016SAndreas Gohr            echo '<option value="revert">'.$lang['btn_revert'].'</option>';
13031246e016SAndreas Gohr        }
1304a00de5b5SAndreas Gohr        echo '<option value="backlink">'.$lang['btn_backlink'].'</option>';
1305a00de5b5SAndreas Gohr    echo '</optgroup>';
1306a00de5b5SAndreas Gohr
1307a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1308a00de5b5SAndreas Gohr        echo '<option value="recent">'.$lang['btn_recent'].'</option>';
1309a00de5b5SAndreas Gohr        echo '<option value="index">'.$lang['btn_index'].'</option>';
1310a00de5b5SAndreas Gohr    echo '</optgroup>';
1311a00de5b5SAndreas Gohr
1312a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1313a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth){
1314a00de5b5SAndreas Gohr            if($_SERVER['REMOTE_USER']){
1315a00de5b5SAndreas Gohr                echo '<option value="logout">'.$lang['btn_logout'].'</option>';
1316a00de5b5SAndreas Gohr            }else{
1317a00de5b5SAndreas Gohr                echo '<option value="login">'.$lang['btn_login'].'</option>';
1318a00de5b5SAndreas Gohr            }
1319a00de5b5SAndreas Gohr        }
1320a00de5b5SAndreas Gohr
1321a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
1322a00de5b5SAndreas Gohr             $auth->canDo('Profile') && ($ACT!='profile')){
1323a00de5b5SAndreas Gohr            echo '<option value="profile">'.$lang['btn_profile'].'</option>';
1324a00de5b5SAndreas Gohr        }
1325a00de5b5SAndreas Gohr
1326a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
1327a00de5b5SAndreas Gohr            if($_SERVER['REMOTE_USER']){
1328a00de5b5SAndreas Gohr                if($INFO['subscribed']) {
1329a00de5b5SAndreas Gohr                    echo '<option value="unsubscribe">'.$lang['btn_unsubscribe'].'</option>';
1330a00de5b5SAndreas Gohr                } else {
1331a00de5b5SAndreas Gohr                    echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>';
1332a00de5b5SAndreas Gohr                }
1333a00de5b5SAndreas Gohr            }
1334a00de5b5SAndreas Gohr        }
1335a00de5b5SAndreas Gohr
1336a00de5b5SAndreas Gohr        if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
1337a00de5b5SAndreas Gohr            if($_SERVER['REMOTE_USER']){
1338a00de5b5SAndreas Gohr                if($INFO['subscribedns']) {
1339a00de5b5SAndreas Gohr                    echo '<option value="unsubscribens">'.$lang['btn_unsubscribens'].'</option>';
1340a00de5b5SAndreas Gohr                } else {
1341a00de5b5SAndreas Gohr                    echo '<option value="subscribens">'.$lang['btn_subscribens'].'</option>';
1342a00de5b5SAndreas Gohr                }
1343a00de5b5SAndreas Gohr            }
1344a00de5b5SAndreas Gohr        }
1345a00de5b5SAndreas Gohr
1346a00de5b5SAndreas Gohr        if($INFO['ismanager']){
1347a00de5b5SAndreas Gohr            echo '<option value="admin">'.$lang['btn_admin'].'</option>';
1348a00de5b5SAndreas Gohr        }
1349a00de5b5SAndreas Gohr    echo '</optgroup>';
1350a00de5b5SAndreas Gohr
1351a00de5b5SAndreas Gohr    echo '</select>';
1352a00de5b5SAndreas Gohr    echo '<input type="submit" value="'.$button.'" id="action__selectorbtn" />';
1353a00de5b5SAndreas Gohr    echo '</form>';
1354a00de5b5SAndreas Gohr}
1355a00de5b5SAndreas Gohr
1356066fee30SAndreas Gohr/**
1357066fee30SAndreas Gohr * Print a informational line about the used license
1358066fee30SAndreas Gohr *
1359066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1360066fee30SAndreas Gohr * @param  string $img    - print image? (|button|badge)
1361066fee30SAndreas Gohr * @param  bool   $return - when true don't print, but return HTML
1362066fee30SAndreas Gohr */
13634cefd216SMichael Klierfunction tpl_license($img='badge',$imgonly=false,$return=false){
1364066fee30SAndreas Gohr    global $license;
1365066fee30SAndreas Gohr    global $conf;
1366066fee30SAndreas Gohr    global $lang;
1367066fee30SAndreas Gohr    if(!$conf['license']) return '';
1368066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1369066fee30SAndreas Gohr    $lic = $license[$conf['license']];
1370066fee30SAndreas Gohr
13714cefd216SMichael Klier    $out  = '<div class="license">';
1372066fee30SAndreas Gohr    if($img){
1373066fee30SAndreas Gohr        $src = license_img($img);
1374066fee30SAndreas Gohr        if($src){
1375066fee30SAndreas Gohr            $out .= '<a href="'.$lic['url'].'" rel="license"';
1376066fee30SAndreas Gohr            if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1377a57c7cafSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> ';
1378066fee30SAndreas Gohr        }
1379066fee30SAndreas Gohr    }
13804cefd216SMichael Klier    if(!$imgonly) {
1381066fee30SAndreas Gohr        $out .= $lang['license'];
1382066fee30SAndreas Gohr        $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"';
1383c66972f2SAdrian Lang        if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1384066fee30SAndreas Gohr        $out .= '>'.$lic['name'].'</a>';
13854cefd216SMichael Klier    }
1386c2a66484SKazutaka Miyasaka    $out .= '</div>';
1387066fee30SAndreas Gohr
1388066fee30SAndreas Gohr    if($return) return $out;
1389066fee30SAndreas Gohr    echo $out;
1390066fee30SAndreas Gohr}
1391066fee30SAndreas Gohr
1392a81910eeSAndreas Gohr
1393a81910eeSAndreas Gohr/**
1394a81910eeSAndreas Gohr * Includes the rendered XHTML of a given page
1395a81910eeSAndreas Gohr *
1396a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1397a81910eeSAndreas Gohr * template
1398a81910eeSAndreas Gohr */
1399a81910eeSAndreas Gohrfunction tpl_include_page($pageid,$print=true){
1400a81910eeSAndreas Gohr    global $ID;
1401a81910eeSAndreas Gohr    $oldid = $ID;
1402a81910eeSAndreas Gohr    $html = p_wiki_xhtml($pageid,'',false);
1403a81910eeSAndreas Gohr    $ID = $oldid;
1404a81910eeSAndreas Gohr
1405a81910eeSAndreas Gohr    if(!$print) return $html;
1406a81910eeSAndreas Gohr    echo $html;
1407a81910eeSAndreas Gohr}
1408a81910eeSAndreas Gohr
1409b8595a66SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
1410a00de5b5SAndreas Gohr
1411