diff options
author | Adrian Lang <lang@cosmocode.de> | 2009-11-04 11:01:15 +0100 |
---|---|---|
committer | Adrian Lang <lang@cosmocode.de> | 2009-11-04 11:01:15 +0100 |
commit | c66972f2cb89e65a8bbf8e39d42e8e479f7eb8dc (patch) | |
tree | 3d20030c333e987b42ff101ec339f2120f9f5883 /inc | |
parent | 1378fb56f6873b93fe002e8aed001e92857b5b5c (diff) | |
download | rpg-c66972f2cb89e65a8bbf8e39d42e8e479f7eb8dc.tar.gz rpg-c66972f2cb89e65a8bbf8e39d42e8e479f7eb8dc.tar.bz2 |
Emit less E_NOTICEs and E_STRICTs
Changes of behaviour are:
* Allow the user name, title & description \e2\80\9c0\e2\80\9d
* Default to Port 443 if using HTTPS
* Set $INFO['isadmin'] and $INFO['ismanager'] to \e2\80\9cfalse\e2\80\9d even if no user is
logged in
* Do not pass empty fragment field in the event data for event
ACTION_SHOW_REDIRECT
* Handle chunked encoding in HTTPClient
darcs-hash:20091104100115-e4919-5cf6397d4a457e3f98a8ca49fbdab03f2147721d.gz
Diffstat (limited to 'inc')
-rw-r--r-- | inc/HTTPClient.php | 21 | ||||
-rw-r--r-- | inc/actions.php | 17 | ||||
-rw-r--r-- | inc/auth.php | 15 | ||||
-rw-r--r-- | inc/cache.php | 2 | ||||
-rw-r--r-- | inc/changelog.php | 2 | ||||
-rw-r--r-- | inc/common.php | 22 | ||||
-rw-r--r-- | inc/html.php | 2 | ||||
-rw-r--r-- | inc/httputils.php | 2 | ||||
-rw-r--r-- | inc/indexer.php | 12 | ||||
-rw-r--r-- | inc/init.php | 27 | ||||
-rw-r--r-- | inc/parser/metadata.php | 8 | ||||
-rw-r--r-- | inc/template.php | 12 |
12 files changed, 81 insertions, 61 deletions
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 77b227e06..578d7e7cd 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -198,8 +198,8 @@ class HTTPClient { if(empty($path)) $path = '/'; if(!empty($uri['query'])) $path .= '?'.$uri['query']; $port = $uri['port']; - if($uri['user']) $this->user = $uri['user']; - if($uri['pass']) $this->pass = $uri['pass']; + if(isset($uri['user'])) $this->user = $uri['user']; + if(isset($uri['pass'])) $this->pass = $uri['pass']; // proxy setup if($this->proxy_host){ @@ -366,7 +366,7 @@ class HTTPClient { //read body (with chunked encoding if needed) $r_body = ''; - if(preg_match('/transfer\-(en)?coding:\s*chunked\r\n/i',$r_header)){ + if(preg_match('/transfer\-(en)?coding:\s*chunked\r\n/i',$r_headers)){ do { unset($chunk_size); do { @@ -416,7 +416,8 @@ class HTTPClient { else break; } - if($this->resp_headers['content-length'] && !$this->resp_headers['transfer-encoding'] && + if(isset($this->resp_headers['content-length']) && + !isset($this->resp_headers['transfer-encoding']) && $this->resp_headers['content-length'] == $r_size){ // we read the content-length, finish here break; @@ -429,7 +430,9 @@ class HTTPClient { fclose($socket); // decode gzip if needed - if($this->resp_headers['content-encoding'] == 'gzip' && strlen($r_body) > 10 && substr($r_body,0,3)=="\x1f\x8b\x08"){ + if(isset($this->resp_headers['content-encoding']) && + $this->resp_headers['content-encoding'] == 'gzip' && + strlen($r_body) > 10 && substr($r_body,0,3)=="\x1f\x8b\x08"){ $this->resp_body = @gzinflate(substr($r_body, 10)); }else{ $this->resp_body = $r_body; @@ -513,12 +516,12 @@ class HTTPClient { * @author Andreas Goetz <cpuidle@gmx.de> */ function _getCookies(){ + $headers = ''; foreach ($this->cookies as $key => $val){ - if ($headers) $headers .= '; '; - $headers .= $key.'='.$val; + $headers .= "$key=$val; "; } - - if ($headers) $headers = "Cookie: $headers".HTTP_NL; + $headers = substr($headers, 0, -2); + if ($headers !== '') $headers = "Cookie: $headers".HTTP_NL; return $headers; } diff --git a/inc/actions.php b/inc/actions.php index 4ade9aab2..27292e6f6 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -387,23 +387,22 @@ function act_redirect($id,$preact){ session_write_close(); } - //get section name when coming from section edit - if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ - $check = false; - $title = sectionID($match[0],$check); - } - $opts = array( 'id' => $id, - 'fragment' => $title, 'preact' => $preact ); + //get section name when coming from section edit + if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ + $check = false; //Byref + $opts['fragment'] = sectionID($match[0], $check); + } + trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); } function act_redirect_execute($opts){ $go = wl($opts['id'],'',true); - if($opts['fragment']) $go .= '#'.$opts['fragment']; + if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; //show it send_redirect($go); @@ -419,7 +418,7 @@ function act_auth($act){ global $INFO; //already logged in? - if($_SERVER['REMOTE_USER'] && $act=='login'){ + if(isset($_SERVER['REMOTE_USER']) && $act=='login'){ return 'show'; } diff --git a/inc/auth.php b/inc/auth.php index 0c0edef5f..7dd7eb557 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -74,7 +74,7 @@ if($conf['useacl']){ $_REQUEST['http_credentials'] = true; } - if($_REQUEST['authtok']){ + if(isset($_REQUEST['authtok'])){ // when an authentication token is given, trust the session auth_validateToken($_REQUEST['authtok']); }elseif(!is_null($auth) && $auth->canDo('external')){ @@ -336,7 +336,13 @@ function auth_ismanager($user=null,$groups=null,$adminonly=false){ global $USERINFO; if(!$conf['useacl']) return false; - if(is_null($user)) $user = $_SERVER['REMOTE_USER']; + if(is_null($user)) { + if (!isset($_SERVER['REMOTE_USER'])) { + return false; + } else { + $user = $_SERVER['REMOTE_USER']; + } + } if(is_null($groups)) $groups = (array) $USERINFO['grps']; $user = auth_nameencode($user); @@ -1019,7 +1025,7 @@ function auth_setCookie($user,$pass,$sticky) { // set cookie $cookie = base64_encode($user).'|'.((int) $sticky).'|'.base64_encode($pass); - if($sticky) $time = time()+60*60*24*365; //one year + $time = $sticky ? (time()+60*60*24*365) : 0; //one year if (version_compare(PHP_VERSION, '5.2.0', '>')) { setcookie(DOKU_COOKIE,$cookie,$time,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true); }else{ @@ -1039,6 +1045,9 @@ function auth_setCookie($user,$pass,$sticky) { * @returns array */ function auth_getCookie(){ + if (!isset($_COOKIE[DOKU_COOKIE])) { + return array(null, null, null); + } list($user,$sticky,$pass) = explode('|',$_COOKIE[DOKU_COOKIE],3); $sticky = (bool) $sticky; $pass = base64_decode($pass); diff --git a/inc/cache.php b/inc/cache.php index 900644d09..c01e17c3e 100644 --- a/inc/cache.php +++ b/inc/cache.php @@ -278,7 +278,7 @@ class cache_instructions extends cache_parser { parent::cache_parser($id, $file, 'i'); } - function retrieveCache() { + function retrieveCache($clean=true) { $contents = io_readFile($this->cache, false); return !empty($contents) ? unserialize($contents) : array(); } diff --git a/inc/changelog.php b/inc/changelog.php index debbc2834..bc2af2de3 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -382,7 +382,7 @@ function getRevisionInfo($id, $rev, $chunk_size=8192) { * * For efficiency, the log lines are parsed and cached for later * calls to getRevisionInfo. Large changelog files are read - * backwards in chunks untill the requested number of changelog + * backwards in chunks until the requested number of changelog * lines are recieved. * * @author Ben Coburn <btcoburn@silicodon.net> diff --git a/inc/common.php b/inc/common.php index a15cb5c62..40af3c9db 100644 --- a/inc/common.php +++ b/inc/common.php @@ -111,16 +111,16 @@ function pageinfo(){ $info['id'] = $ID; $info['rev'] = $REV; - if($_SERVER['REMOTE_USER']){ + // set info about manager/admin status. + $info['isadmin'] = false; + $info['ismanager'] = false; + if(isset($_SERVER['REMOTE_USER'])){ $info['userinfo'] = $USERINFO; $info['perm'] = auth_quickaclcheck($ID); $info['subscribed'] = is_subscribed($ID,$_SERVER['REMOTE_USER'],false); $info['subscribedns'] = is_subscribed($ID,$_SERVER['REMOTE_USER'],true); $info['client'] = $_SERVER['REMOTE_USER']; - // set info about manager/admin status - $info['isadmin'] = false; - $info['ismanager'] = false; if($info['perm'] == AUTH_ADMIN){ $info['isadmin'] = true; $info['ismanager'] = true; @@ -275,12 +275,9 @@ function breadcrumbs(){ global $ID; global $ACT; global $conf; - $crumbs = $_SESSION[DOKU_COOKIE]['bc']; //first visit? - if (!is_array($crumbs)){ - $crumbs = array(); - } + $crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array(); //we only save on show and existing wiki documents $file = wikiFN($ID); if($ACT != 'show' || !@file_exists($file)){ @@ -1130,11 +1127,14 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){ * @author Todd Augsburger <todd@rollerorgans.com> */ function getGoogleQuery(){ + if (!isset($_SERVER['HTTP_REFERER'])) { + return ''; + } $url = parse_url($_SERVER['HTTP_REFERER']); - if(!$url) return ''; $query = array(); parse_str($url['query'],$query); + $q = ''; if(isset($query['q'])) $q = $query['q']; // google, live/msn, aol, ask, altavista, alltheweb, gigablast elseif(isset($query['p'])) @@ -1144,7 +1144,7 @@ function getGoogleQuery(){ elseif(preg_match("#a9\.com#i",$url['host'])) // a9 $q = urldecode(ltrim($url['path'],'/')); - if(!$q) return ''; + if($q === '') return ''; $q = preg_split('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/',$q,-1,PREG_SPLIT_NO_EMPTY); return $q; } @@ -1403,7 +1403,7 @@ function preg_quote_cb($string){ /** * Shorten a given string by removing data from the middle * - * You can give the string in two parts, teh first part $keep + * You can give the string in two parts, the first part $keep * will never be shortened. The second part $short will be cut * in the middle to shorten but only if at least $min chars are * left to display it. Otherwise it will be left off. diff --git a/inc/html.php b/inc/html.php index bda9c88e4..0b53b4919 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1481,7 +1481,7 @@ function html_TOC($toc){ * Callback for html_buildlist */ function html_list_toc($item){ - if($item['hid']){ + if(isset($item['hid'])){ $link = '#'.$item['hid']; }else{ $link = $item['link']; diff --git a/inc/httputils.php b/inc/httputils.php index ed5d6dfd5..324a730b9 100644 --- a/inc/httputils.php +++ b/inc/httputils.php @@ -56,7 +56,7 @@ function http_conditionalRequest($timestamp){ header('HTTP/1.0 304 Not Modified'); // don't produce output, even if compression is on - ob_end_clean(); + @ob_end_clean(); exit; } diff --git a/inc/indexer.php b/inc/indexer.php index 1f2ff89e3..14af579bb 100644 --- a/inc/indexer.php +++ b/inc/indexer.php @@ -74,7 +74,7 @@ function idx_saveIndex($pre, $wlen, &$idx){ fwrite($fh,$line); } fclose($fh); - if($conf['fperm']) chmod($fn.'.tmp', $conf['fperm']); + if(isset($conf['fperm'])) chmod($fn.'.tmp', $conf['fperm']); io_rename($fn.'.tmp', $fn.'.idx'); return true; } @@ -574,12 +574,16 @@ function idx_lookup($words){ // merge found pages into final result array $final = array(); - foreach(array_keys($result) as $word){ + foreach($result as $word => $res){ $final[$word] = array(); - foreach($result[$word] as $wid){ + foreach($res as $wid){ $hits = &$docs[$wid]; foreach ($hits as $hitkey => $hitcnt) { - $final[$word][$hitkey] = $hitcnt + $final[$word][$hitkey]; + if (!isset($final[$word][$hitkey])) { + $final[$word][$hitkey] = $hitcnt; + } else { + $final[$word][$hitkey] += $hitcnt; + } } } } diff --git a/inc/init.php b/inc/init.php index 32a3d46a9..6fb9559ce 100644 --- a/inc/init.php +++ b/inc/init.php @@ -219,7 +219,7 @@ if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) { $_REQUEST = array_merge($_GET,$_POST); // we don't want a purge URL to be digged -if($_REQUEST['purge'] && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']); +if(isset($_REQUEST['purge']) && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']); // disable gzip if not available if($conf['compression'] == 'bz2' && !function_exists('bzopen')){ @@ -413,8 +413,8 @@ function getBaseURL($abs=null){ $dir = str_replace('\\','/',$dir); // bugfix for weird WIN behaviour $dir = preg_replace('#//+#','/',"/$dir/"); // ensure leading and trailing slashes - //handle script in lib/exe dir - $dir = preg_replace('!lib/exe/$!','',$dir); + //handle script in lib/exe dir + $dir = preg_replace('!lib/exe/$!','',$dir); //handle script in lib/plugins dir $dir = preg_replace('!lib/plugins/.*$!','',$dir); @@ -426,23 +426,27 @@ function getBaseURL($abs=null){ if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir; //split hostheader into host and port - list($host,$port) = explode(':',$_SERVER['HTTP_HOST']); - if(!$port) $port = $_SERVER['SERVER_PORT']; - if(!$port) $port = 80; - + $addr = explode(':',$_SERVER['HTTP_HOST']); + $host = $addr[0]; + $port = ''; + if (isset($addr[1])) { + $port = $addr[1]; + } elseif (isset($_SERVER['SERVER_PORT'])) { + $port = $_SERVER['SERVER_PORT']; + } if(!is_ssl()){ $proto = 'http://'; if ($port == '80') { - $port=''; + $port = ''; } }else{ $proto = 'https://'; if ($port == '443') { - $port=''; + $port = ''; } } - if($port) $port = ':'.$port; + if($port !== '') $port = ':'.$port; return $proto.$host.$port.$dir; } @@ -456,7 +460,8 @@ function getBaseURL($abs=null){ * @returns bool true when SSL is active */ function is_ssl(){ - if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ + if (!isset($_SERVER['HTTPS']) || + preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ return false; }else{ return true; diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 8aa00b4f5..c2afe8a7f 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -58,7 +58,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { // store internal info in metadata (notoc,nocache) $this->meta['internal'] = $this->info; - if (!$this->meta['description']['abstract']){ + if (!isset($this->meta['description']['abstract'])){ // cut off too long abstracts $this->doc = trim($this->doc); if (strlen($this->doc) > 500) @@ -91,7 +91,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } function header($text, $level, $pos) { - if (!$this->meta['title']) $this->meta['title'] = $text; + if (!isset($this->meta['title'])) $this->meta['title'] = $text; // add the header to the TOC $hid = $this->_headerToLink($text,'true'); @@ -227,7 +227,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { if ($this->capture) $this->doc .= $text; } - function file($text){ + function file($text, $lang = null, $file = null){ if ($this->capture){ $this->doc .= DOKU_LF.$text; if (strlen($this->doc) > 250) $this->capture = false; @@ -247,7 +247,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function code($text, $language = NULL){ + function code($text, $language = NULL, $file = null){ if ($this->capture){ $this->doc .= DOKU_LF.$text; if (strlen($this->doc) > 250) $this->capture = false; diff --git a/inc/template.php b/inc/template.php index f51e2acf9..3193e0013 100644 --- a/inc/template.php +++ b/inc/template.php @@ -80,7 +80,7 @@ function tpl_content_core(){ html_search(); break; case 'revisions': - $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; + $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; html_revisions($first); break; case 'diff': @@ -517,7 +517,7 @@ function tpl_button($type,$return=false){ break; case 'login': if($conf['useacl'] && $auth){ - if($_SERVER['REMOTE_USER']){ + if(isset($_SERVER['REMOTE_USER'])){ $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken())); }else{ $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken())); @@ -567,7 +567,7 @@ function tpl_button($type,$return=false){ $out .= html_btn('backlink',$ID,'',array('do' => 'backlink')); break; case 'profile': - if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $auth && + if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth && $auth->canDo('Profile') && ($ACT!='profile')){ $out .= html_btn('profile',$ID,'',array('do' => 'profile')); } @@ -927,7 +927,7 @@ function tpl_youarehere($sep=' » '){ function tpl_userinfo(){ global $lang; global $INFO; - if($_SERVER['REMOTE_USER']){ + if(isset($_SERVER['REMOTE_USER'])){ print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')'; return true; } @@ -1103,7 +1103,7 @@ function tpl_img($maxwidth=0,$maxheight=0){ /** * This function inserts a 1x1 pixel gif which in reality - * is the inexer function. + * is the indexer function. * * Should be called somewhere at the very end of the main.php * template @@ -1375,7 +1375,7 @@ function tpl_license($img='badge',$imgonly=false,$return=false){ if(!$imgonly) { $out .= $lang['license']; $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"'; - if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"'; + if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"'; $out .= '>'.$lic['name'].'</a>'; } $out .= '</div>'; |