From ac7a515f564d088e043bf190c9a4ced1d5c309db Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 9 Aug 2012 23:32:58 +0200 Subject: code cleanup in template.php * make use of $INPUT * clean up coding style * add phpdoc comments --- inc/template.php | 925 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 511 insertions(+), 414 deletions(-) diff --git a/inc/template.php b/inc/template.php index 7d09f7dd4..2dc58b36d 100644 --- a/inc/template.php +++ b/inc/template.php @@ -9,29 +9,33 @@ if(!defined('DOKU_INC')) die('meh.'); /** - * Returns the path to the given template, uses - * default one if the custom version doesn't exist. + * Access a template file + * + * Returns the path to the given file inside the current template, uses + * default template if the custom version doesn't exist. * * @author Andreas Gohr + * @param string $file + * @return string */ -function template($tpl){ +function template($file) { global $conf; - if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) - return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; + if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) + return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; - return DOKU_INC.'lib/tpl/default/'.$tpl; + return DOKU_INC.'lib/tpl/dokuwiki/'.$file; } - /** * Convenience function to access template dir from local FS * * This replaces the deprecated DOKU_TPLINC constant * * @author Andreas Gohr + * @return string */ -function tpl_incdir(){ +function tpl_incdir() { global $conf; return DOKU_INC.'lib/tpl/'.$conf['template'].'/'; } @@ -42,8 +46,9 @@ function tpl_incdir(){ * This replaces the deprecated DOKU_TPL constant * * @author Andreas Gohr + * @return string */ -function tpl_basedir(){ +function tpl_basedir() { global $conf; return DOKU_BASE.'lib/tpl/'.$conf['template'].'/'; } @@ -59,32 +64,43 @@ function tpl_basedir(){ * handled by this function. ACL stuff is not done here either. * * @author Andreas Gohr + * @triggers TPL_ACT_RENDER + * @triggers TPL_CONTENT_DISPLAY + * @param bool $prependTOC should the TOC be displayed here? + * @return bool true if any output */ -function tpl_content($prependTOC=true) { +function tpl_content($prependTOC = true) { global $ACT; global $INFO; $INFO['prependTOC'] = $prependTOC; ob_start(); - trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core'); + trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); $html_output = ob_get_clean(); - trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln'); + trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); return !empty($html_output); } -function tpl_content_core(){ +/** + * Default Action of TPL_ACT_RENDER + * + * @return bool + */ +function tpl_content_core() { global $ACT; global $TEXT; global $PRE; global $SUF; global $SUM; global $IDX; + global $INPUT; - switch($ACT){ + switch($ACT) { case 'show': html_show(); break; + /** @noinspection PhpMissingBreakStatementInspection */ case 'locked': html_locked(); case 'edit': @@ -102,20 +118,13 @@ function tpl_content_core(){ html_search(); break; case 'revisions': - $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; - html_revisions($first); + html_revisions($INPUT->int('first')); break; case 'diff': html_diff(); break; case 'recent': - if (is_array($_REQUEST['first'])) { - $_REQUEST['first'] = array_keys($_REQUEST['first']); - $_REQUEST['first'] = $_REQUEST['first'][0]; - } - $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; - $show_changes = $_REQUEST['show_changes']; - html_recent($first, $show_changes); + html_recent($INPUT->extract('first')->int('first'), $INPUT->str('show_changes')); break; case 'index': html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? @@ -124,8 +133,8 @@ function tpl_content_core(){ html_backlinks(); break; case 'conflict': - html_conflict(con($PRE,$TEXT,$SUF),$SUM); - html_diff(con($PRE,$TEXT,$SUF),false); + html_conflict(con($PRE, $TEXT, $SUF), $SUM); + html_diff(con($PRE, $TEXT, $SUF), false); break; case 'login': html_login(); @@ -152,9 +161,9 @@ function tpl_content_core(){ tpl_media(); break; default: - $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); - if ($evt->advise_before()) - msg("Failed to handle command: ".hsc($ACT),-1); + $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); + if($evt->advise_before()) + msg("Failed to handle command: ".hsc($ACT), -1); $evt->advise_after(); unset($evt); return false; @@ -169,43 +178,47 @@ function tpl_content_core(){ * a false argument * * @author Andreas Gohr + * @param bool $return Should the TOC be returned instead to be printed? + * @return string */ -function tpl_toc($return=false){ +function tpl_toc($return = false) { global $TOC; global $ACT; global $ID; global $REV; global $INFO; global $conf; + global $INPUT; $toc = array(); - if(is_array($TOC)){ + if(is_array($TOC)) { // if a TOC was prepared in global scope, always use it $toc = $TOC; - }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){ + } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { // get TOC from metadata, render if neccessary $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE); - if(isset($meta['internal']['toc'])){ + if(isset($meta['internal']['toc'])) { $tocok = $meta['internal']['toc']; - }else{ + } else { $tocok = true; } - $toc = $meta['description']['tableofcontents']; - if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){ + $toc = $meta['description']['tableofcontents']; + if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { $toc = array(); } - }elseif($ACT == 'admin'){ + } elseif($ACT == 'admin') { // try to load admin plugin TOC FIXME: duplicates code from tpl_admin $plugin = null; - if (!empty($_REQUEST['page'])) { + $class = $INPUT->str('page'); + if(!empty($class)) { $pluginlist = plugin_list('admin'); - if (in_array($_REQUEST['page'], $pluginlist)) { + if(in_array($class, $pluginlist)) { // attempt to load the plugin - $plugin =& plugin_load('admin',$_REQUEST['page']); + /** @var $plugin DokuWiki_Admin_Plugin */ + $plugin =& plugin_load('admin', $class); } } - if ( ($plugin !== null) && - (!$plugin->forAdminOnly() || $INFO['isadmin']) ){ + if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { $toc = $plugin->getTOC(); $TOC = $toc; // avoid later rebuild } @@ -215,6 +228,7 @@ function tpl_toc($return=false){ $html = html_TOC($toc); if($return) return $html; echo $html; + return ''; } /** @@ -222,26 +236,28 @@ function tpl_toc($return=false){ * * @author Andreas Gohr */ -function tpl_admin(){ +function tpl_admin() { global $INFO; global $TOC; + global $INPUT; $plugin = null; - if (!empty($_REQUEST['page'])) { + $class = $INPUT->str('page'); + if(!empty($class)) { $pluginlist = plugin_list('admin'); - if (in_array($_REQUEST['page'], $pluginlist)) { - + if(in_array($class, $pluginlist)) { // attempt to load the plugin - $plugin =& plugin_load('admin',$_REQUEST['page']); + /** @var $plugin DokuWiki_Admin_Plugin */ + $plugin =& plugin_load('admin', $class); } } - if ($plugin !== null){ + if($plugin !== null) { if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet if($INFO['prependTOC']) tpl_toc(); $plugin->html(); - }else{ + } else { html_admin(); } return true; @@ -252,11 +268,12 @@ function tpl_admin(){ * * This has to go into the head section of your template. * - * @triggers TPL_METAHEADER_OUTPUT - * @param boolean $alt Should feeds and alternative format links be added? * @author Andreas Gohr + * @triggers TPL_METAHEADER_OUTPUT + * @param bool $alt Should feeds and alternative format links be added? + * @return bool */ -function tpl_metaheaders($alt=true){ +function tpl_metaheaders($alt = true) { global $ID; global $REV; global $INFO; @@ -265,13 +282,12 @@ function tpl_metaheaders($alt=true){ global $QUERY; global $lang; global $conf; - $it=2; // prepare the head array $head = array(); // prepare seed for js and css - $tseed = 0; + $tseed = 0; $depends = getConfigFiles('main'); foreach($depends as $f) { $time = @filemtime($f); @@ -279,99 +295,119 @@ function tpl_metaheaders($alt=true){ } // the usual stuff - $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki'); - $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml', - 'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] ); - $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE ); - if(actionOK('index')){ - $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'), - 'title'=>$lang['btn_index'] ); + $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); + $head['link'][] = array( + 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', + 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] + ); + $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); + if(actionOK('index')) { + $head['link'][] = array( + 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), + 'title'=> $lang['btn_index'] + ); } - if($alt){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php'); - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Current Namespace', - 'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']); - if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){ - $head['link'][] = array( 'rel'=>'edit', - 'title'=>$lang['btn_edit'], - 'href'=> wl($ID,'do=edit',false,'&')); + if($alt) { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'application/rss+xml', + 'title'=> 'Recent Changes', 'href'=> DOKU_BASE.'feed.php' + ); + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'application/rss+xml', + 'title'=> 'Current Namespace', + 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] + ); + if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { + $head['link'][] = array( + 'rel' => 'edit', + 'title'=> $lang['btn_edit'], + 'href' => wl($ID, 'do=edit', false, '&') + ); } - if($ACT == 'search'){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Search Result', - 'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY); + if($ACT == 'search') { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'application/rss+xml', + 'title'=> 'Search Result', + 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY + ); } - if(actionOK('export_xhtml')){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML', - 'href'=>exportlink($ID, 'xhtml', '', false, '&')); + if(actionOK('export_xhtml')) { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> 'Plain HTML', + 'href'=> exportlink($ID, 'xhtml', '', false, '&') + ); } - if(actionOK('export_raw')){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup', - 'href'=>exportlink($ID, 'raw', '', false, '&')); + if(actionOK('export_raw')) { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> 'Wiki Markup', + 'href'=> exportlink($ID, 'raw', '', false, '&') + ); } } // setup robot tags apropriate for different modes - if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ - if($INFO['exists']){ + if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { + if($INFO['exists']) { //delay indexing: - if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); + if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); + } else { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); } - $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') ); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow'); + $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&')); + } else { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); } - }elseif(defined('DOKU_MEDIADETAIL')){ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); + } elseif(defined('DOKU_MEDIADETAIL')) { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); + } else { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); } // set metadata - if($ACT == 'show' || $ACT=='export_xhtml'){ + if($ACT == 'show' || $ACT == 'export_xhtml') { // date of modification - if($REV){ - $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV)); - }else{ - $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod'])); + if($REV) { + $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV)); + } else { + $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod'])); } // keywords (explicit or implicit) - if(!empty($INFO['meta']['subject'])){ - $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject'])); - }else{ - $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID)); + if(!empty($INFO['meta']['subject'])) { + $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); + } else { + $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); } } // load stylesheets - $head['link'][] = array('rel'=>'stylesheet', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed); + $head['link'][] = array( + 'rel' => 'stylesheet', 'type'=> 'text/css', + 'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed + ); // make $INFO and other vars available to JavaScripts - $json = new JSON(); + $json = new JSON(); $script = "var NS='".$INFO['namespace']."';"; - if($conf['useacl'] && $_SERVER['REMOTE_USER']){ + if($conf['useacl'] && $_SERVER['REMOTE_USER']) { $script .= "var SIG='".toolbar_signature()."';"; } $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; - $head['script'][] = array( 'type'=>'text/javascript', '_data'=> $script); + $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); // load external javascript - $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'', - 'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed); + $head['script'][] = array( + 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', + 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed + ); // trigger event here - trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); + trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); return true; } @@ -387,18 +423,18 @@ function tpl_metaheaders($alt=true){ * * @author Andreas Gohr */ -function _tpl_metaheaders_action($data){ - foreach($data as $tag => $inst){ - foreach($inst as $attr){ - echo '<',$tag,' ',buildAttributes($attr); - if(isset($attr['_data']) || $tag == 'script'){ +function _tpl_metaheaders_action($data) { + foreach($data as $tag => $inst) { + foreach($inst as $attr) { + echo '<', $tag, ' ', buildAttributes($attr); + if(isset($attr['_data']) || $tag == 'script') { if($tag == 'script' && $attr['_data']) $attr['_data'] = "/**/"; - echo '>',$attr['_data'],''; - }else{ + echo '>', $attr['_data'], ''; + } else { echo '/>'; } echo "\n"; @@ -413,11 +449,11 @@ function _tpl_metaheaders_action($data){ * * @author Andreas Gohr */ -function tpl_link($url,$name,$more='',$return=false){ +function tpl_link($url, $name, $more = '', $return = false) { $out = ' */ -function tpl_pagelink($id,$name=null){ - print html_wikilink($id,$name); +function tpl_pagelink($id, $name = null) { + print html_wikilink($id, $name); return true; } @@ -442,14 +478,13 @@ function tpl_pagelink($id,$name=null){ * * @author Andreas Gohr */ -function tpl_getparent($id){ - global $conf; +function tpl_getparent($id) { $parent = getNS($id).':'; - resolve_pageid('',$parent,$exists); + resolve_pageid('', $parent, $exists); if($parent == $id) { - $pos = strrpos (getNS($id),':'); - $parent = substr($parent,0,$pos).':'; - resolve_pageid('',$parent,$exists); + $pos = strrpos(getNS($id), ':'); + $parent = substr($parent, 0, $pos).':'; + resolve_pageid('', $parent, $exists); if($parent == $id) return false; } return $parent; @@ -461,21 +496,27 @@ function tpl_getparent($id){ * @author Adrian Lang * @see tpl_get_action */ -function tpl_button($type,$return=false){ +function tpl_button($type, $return = false) { $data = tpl_get_action($type); - if ($data === false) { + if($data === false) { return false; - } elseif (!is_array($data)) { + } elseif(!is_array($data)) { $out = sprintf($data, 'button'); } else { + /** + * @var string $accesskey + * @var string $id + * @var string $method + * @var array $params + */ extract($data); - if ($id === '#dokuwiki__top') { + if($id === '#dokuwiki__top') { $out = html_topbtn(); } else { $out = html_btn($type, $id, $accesskey, $params, $method); } } - if ($return) return $out; + if($return) return $out; echo $out; return true; } @@ -486,32 +527,40 @@ function tpl_button($type,$return=false){ * @author Adrian Lang * @see tpl_get_action */ -function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){ +function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { global $lang; $data = tpl_get_action($type); - if ($data === false) { + if($data === false) { return false; - } elseif (!is_array($data)) { + } elseif(!is_array($data)) { $out = sprintf($data, 'link'); } else { + /** + * @var string $accesskey + * @var string $id + * @var string $method + * @var array $params + */ extract($data); - if (strpos($id, '#') === 0) { + if(strpos($id, '#') === 0) { $linktarget = $id; } else { $linktarget = wl($id, $params); } - $caption = $lang['btn_' . $type]; - $akey = $addTitle = ''; - if($accesskey){ - $akey = 'accesskey="'.$accesskey.'" '; + $caption = $lang['btn_'.$type]; + $akey = $addTitle = ''; + if($accesskey) { + $akey = 'accesskey="'.$accesskey.'" '; $addTitle = ' ['.strtoupper($accesskey).']'; } - $out = tpl_link($linktarget, $pre.(($inner)?$inner:$caption).$suf, - 'class="action ' . $type . '" ' . - $akey . 'rel="nofollow" ' . - 'title="' . hsc($caption).$addTitle . '"', 1); + $out = tpl_link( + $linktarget, $pre.(($inner) ? $inner : $caption).$suf, + 'class="action '.$type.'" '. + $akey.'rel="nofollow" '. + 'title="'.hsc($caption).$addTitle.'"', 1 + ); } - if ($return) return $out; + if($return) return $out; echo $out; return true; } @@ -536,53 +585,53 @@ function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){ * @author Andreas Gohr * @author Matthias Grimm * @author Adrian Lang + * @param string $type + * @return array|bool|string */ function tpl_get_action($type) { global $ID; global $INFO; global $REV; global $ACT; - global $conf; - global $auth; // check disabled actions and fix the badly named ones - if($type == 'history') $type='revisions'; + if($type == 'history') $type = 'revisions'; if(!actionOK($type)) return false; $accesskey = null; $id = $ID; $method = 'get'; $params = array('do' => $type); - switch($type){ + switch($type) { case 'edit': // most complicated type - we need to decide on current action - if($ACT == 'show' || $ACT == 'search'){ + if($ACT == 'show' || $ACT == 'search') { $method = 'post'; - if($INFO['writable']){ + if($INFO['writable']) { $accesskey = 'e'; if(!empty($INFO['draft'])) { - $type = 'draft'; + $type = 'draft'; $params['do'] = 'draft'; } else { $params['rev'] = $REV; - if(!$INFO['exists']){ - $type = 'create'; + if(!$INFO['exists']) { + $type = 'create'; } } - }else{ + } else { if(!actionOK('source')) return false; //pseudo action $params['rev'] = $REV; - $type = 'source'; - $accesskey = 'v'; + $type = 'source'; + $accesskey = 'v'; } - }else{ - $params = array(); - $type = 'show'; + } else { + $params = array(); + $type = 'show'; $accesskey = 'v'; } break; case 'revisions': - $type = 'revs'; + $type = 'revs'; $accesskey = 'o'; break; case 'recent': @@ -593,40 +642,40 @@ function tpl_get_action($type) { break; case 'top': $accesskey = 't'; - $params = array(); - $id = '#dokuwiki__top'; + $params = array(); + $id = '#dokuwiki__top'; break; case 'back': $parent = tpl_getparent($ID); - if (!$parent) { + if(!$parent) { return false; } - $id = $parent; - $params = array(); + $id = $parent; + $params = array(); $accesskey = 'b'; break; case 'login': $params['sectok'] = getSecurityToken(); - if(isset($_SERVER['REMOTE_USER'])){ - if (!actionOK('logout')) { + if(isset($_SERVER['REMOTE_USER'])) { + if(!actionOK('logout')) { return false; } $params['do'] = 'logout'; - $type = 'logout'; + $type = 'logout'; } break; case 'register': - if($_SERVER['REMOTE_USER']){ + if($_SERVER['REMOTE_USER']) { return false; } break; case 'resendpwd': - if($_SERVER['REMOTE_USER']){ + if($_SERVER['REMOTE_USER']) { return false; } break; case 'admin': - if(!$INFO['ismanager']){ + if(!$INFO['ismanager']) { return false; } break; @@ -634,21 +683,22 @@ function tpl_get_action($type) { if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { return false; } - $params['rev'] = $REV; + $params['rev'] = $REV; $params['sectok'] = getSecurityToken(); break; + /** @noinspection PhpMissingBreakStatementInspection */ case 'subscription': - $type = 'subscribe'; + $type = 'subscribe'; $params['do'] = 'subscribe'; case 'subscribe': - if(!$_SERVER['REMOTE_USER']){ + if(!$_SERVER['REMOTE_USER']) { return false; } break; case 'backlink': break; case 'profile': - if(!isset($_SERVER['REMOTE_USER'])){ + if(!isset($_SERVER['REMOTE_USER'])) { return false; } break; @@ -665,14 +715,25 @@ function tpl_get_action($type) { * Wrapper around tpl_button() and tpl_actionlink() * * @author Anika Henke + * @param + * @param bool $link link or form button? + * @param bool $wrapper HTML element wrapper + * @param bool $return return or print + * @param string $pre prefix for links + * @param string $suf suffix for links + * @param string $inner inner HTML for links + * @return bool|string */ -function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') { +function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { $out = ''; - if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1); - else $out .= tpl_button($type,1); - if ($out && $wrapper) $out = "<$wrapper>$out"; + if($link) { + $out .= tpl_actionlink($type, $pre, $suf, $inner, 1); + } else { + $out .= tpl_button($type, 1); + } + if($out && $wrapper) $out = "<$wrapper>$out"; - if ($return) return $out; + if($return) return $out; print $out; return $out ? true : false; } @@ -688,14 +749,17 @@ function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$ * autocompletion feature (MSIE and Firefox) * * @author Andreas Gohr + * @param bool $ajax + * @param bool $autocomplete + * @return bool */ -function tpl_searchform($ajax=true,$autocomplete=true){ +function tpl_searchform($ajax = true, $autocomplete = true) { global $lang; global $ACT; global $QUERY; // don't print the search form if search action has been disabled - if (!actionOk('search')) return false; + if(!actionOk('search')) return false; print '