Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop-image-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Feb 8, 2012
2 parents 69ff798 + 0209c70 commit 8d7fffc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
exit('Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}

Expand All @@ -233,6 +234,7 @@
{
if ( ! is_dir(APPPATH.'views/'))
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, '503');
exit('Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF);
}

Expand Down
3 changes: 3 additions & 0 deletions system/core/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
{
// Note: We use exit() rather then show_error() in order to avoid a
// self-referencing loop with the Excptions class
set_status_header(503);
exit('Unable to locate the specified class: '.$class.'.php');
}

Expand Down Expand Up @@ -243,6 +244,7 @@ function &get_config($replace = array())
// Fetch the config file
if ( ! file_exists($file_path))
{
set_status_header(503);
exit('The configuration file does not exist.');
}

Expand All @@ -251,6 +253,7 @@ function &get_config($replace = array())
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
set_status_header(503);
exit('Your config file does not appear to be formatted correctly.');
}

Expand Down
67 changes: 30 additions & 37 deletions system/core/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
* @filesource
*/

// ------------------------------------------------------------------------

/**
* Input Class
*
Expand Down Expand Up @@ -152,7 +150,7 @@ protected function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
public function get($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
if ($index === NULL AND ! empty($_GET))
if ($index === NULL && ! empty($_GET))
{
$get = array();

Expand All @@ -179,7 +177,7 @@ public function get($index = NULL, $xss_clean = FALSE)
public function post($index = NULL, $xss_clean = FALSE)
{
// Check if a field has been provided
if ($index === NULL AND ! empty($_POST))
if ($index === NULL && ! empty($_POST))
{
$post = array();

Expand All @@ -206,9 +204,9 @@ public function post($index = NULL, $xss_clean = FALSE)
*/
public function get_post($index = '', $xss_clean = FALSE)
{
return ( ! isset($_POST[$index]))
? $this->get($index, $xss_clean)
: $this->post($index, $xss_clean);
return isset($_POST[$index])
? $this->post($index, $xss_clean)
: $this->get($index, $xss_clean);
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -256,19 +254,19 @@ public function set_cookie($name = '', $value = '', $expire = '', $domain = '',
}
}

if ($prefix == '' AND config_item('cookie_prefix') != '')
if ($prefix == '' && config_item('cookie_prefix') != '')
{
$prefix = config_item('cookie_prefix');
}
if ($domain == '' AND config_item('cookie_domain') != '')
if ($domain == '' && config_item('cookie_domain') != '')
{
$domain = config_item('cookie_domain');
}
if ($path == '/' AND config_item('cookie_path') != '/')
if ($path == '/' && config_item('cookie_path') !== '/')
{
$path = config_item('cookie_path');
}
if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
if ($secure == FALSE && config_item('cookie_secure') != FALSE)
{
$secure = config_item('cookie_secure');
}
Expand Down Expand Up @@ -320,11 +318,11 @@ public function ip_address()

$this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
}
elseif ( ! $this->server('HTTP_CLIENT_IP') AND $this->server('REMOTE_ADDR'))
elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR'))
{
$this->ip_address = $_SERVER['REMOTE_ADDR'];
}
elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
elseif ($this->server('REMOTE_ADDR') && $this->server('HTTP_CLIENT_IP'))
{
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
}
Expand Down Expand Up @@ -414,7 +412,7 @@ public function user_agent()
return $this->user_agent;
}

return $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
return $this->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : FALSE;
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -469,19 +467,16 @@ protected function _sanitize_globals()
{
$_GET = array();
}
else
elseif (is_array($_GET) && count($_GET) > 0)
{
if (is_array($_GET) AND count($_GET) > 0)
foreach ($_GET as $key => $val)
{
foreach ($_GET as $key => $val)
{
$_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
$_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
}

// Clean $_POST Data
if (is_array($_POST) AND count($_POST) > 0)
if (is_array($_POST) && count($_POST) > 0)
{
foreach ($_POST as $key => $val)
{
Expand All @@ -490,7 +485,7 @@ protected function _sanitize_globals()
}

// Clean $_COOKIE Data
if (is_array($_COOKIE) AND count($_COOKIE) > 0)
if (is_array($_COOKIE) && count($_COOKIE) > 0)
{
// Also get rid of specially treated cookies that might be set by a server
// or silly application, that are of no use to a CI application anyway
Expand Down Expand Up @@ -568,7 +563,7 @@ protected function _clean_input_data($str)
}

// Standardize newlines if needed
if ($this->_standardize_newlines == TRUE AND strpos($str, "\r") !== FALSE)
if ($this->_standardize_newlines == TRUE && strpos($str, "\r") !== FALSE)
{
return str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
}
Expand All @@ -592,6 +587,7 @@ protected function _clean_input_keys($str)
{
if ( ! preg_match('/^[a-z0-9:_\/-]+$/i', $str))
{
set_status_header(503);
exit('Disallowed Key Characters.');
}

Expand Down Expand Up @@ -624,7 +620,7 @@ public function request_headers($xss_clean = FALSE)
}
else
{
$headers['Content-Type'] = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');
$headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE');

foreach ($_SERVER as $key => $val)
{
Expand Down Expand Up @@ -654,9 +650,9 @@ public function request_headers($xss_clean = FALSE)
*
* Returns the value of a single member of the headers class member
*
* @param string array key for $this->headers
* @param boolean XSS Clean or not
* @return mixed FALSE on failure, string on success
* @param string array key for $this->headers
* @param bool XSS Clean or not
* @return mixed FALSE on failure, string on success
*/
public function get_request_header($index, $xss_clean = FALSE)
{
Expand All @@ -670,12 +666,9 @@ public function get_request_header($index, $xss_clean = FALSE)
return FALSE;
}

if ($xss_clean === TRUE)
{
return $this->security->xss_clean($this->headers[$index]);
}

return $this->headers[$index];
return ($xss_clean === TRUE)
? $this->security->xss_clean($this->headers[$index])
: $this->headers[$index];
}

// --------------------------------------------------------------------
Expand All @@ -685,11 +678,11 @@ public function get_request_header($index, $xss_clean = FALSE)
*
* Test to see if a request contains the HTTP_X_REQUESTED_WITH header
*
* @return boolean
* @return bool
*/
public function is_ajax_request()
{
return ($this->server('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest');
return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}

// --------------------------------------------------------------------
Expand All @@ -699,11 +692,11 @@ public function is_ajax_request()
*
* Test to see if a request was made from the command line
*
* @return boolean
* @return bool
*/
public function is_cli_request()
{
return (php_sapi_name() === 'cli') or defined('STDIN');
return (php_sapi_name() === 'cli' OR defined('STDIN'));
}

}
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Bug fixes for 3.0
- Fixed a bug (#904) - ``CI_Loader::initialize()`` caused a PHP Fatal error to be triggered if error level E_STRICT is used.
- Fixed a hosting edge case where an empty $_SERVER['HTTPS'] variable would evaluate to 'on'
- Fixed a bug (#154) - ``CI_Session::sess_update()`` caused the session to be destroyed on pages where multiple AJAX requests were executed at once.
- Fixed a possible bug in ``CI_Input::is_ajax_request()`` where some clients might not send the X-Requested-With HTTP header value exactly as 'XmlHttpRequest'.

Version 2.1.0
=============
Expand Down

0 comments on commit 8d7fffc

Please sign in to comment.