From 6ef498b49946ba74d610b3805fb908b163a7f03a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 5 Jun 2012 22:01:58 +0300 Subject: Added get_mimes() function to system/core/Commons.php.The MIMEs array from config/mimes.php is used by multiple core classes, libraries and helpers and each of them has implemented an own way of getting it, which is not needed and is hard to maintain. This also fixes issue #1411 --- system/core/Common.php | 34 ++++++++++++++++++++++++++++++---- system/core/Output.php | 15 ++++----------- 2 files changed, 34 insertions(+), 15 deletions(-) (limited to 'system/core') diff --git a/system/core/Common.php b/system/core/Common.php index 8af7d6323..5e3b8262d 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -233,7 +233,7 @@ if ( ! function_exists('get_config')) $file_path = APPPATH.'config/config.php'; $found = FALSE; - if (file_exists($file_path)) + if (file_exists($file_path)) { $found = TRUE; require($file_path); @@ -242,9 +242,9 @@ if ( ! function_exists('get_config')) // Is the config file in the environment folder? if (defined(ENVIRONMENT) && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) { - require($file_path); - } - elseif ( ! $found) + require($file_path); + } + elseif ( ! $found) { set_status_header(503); exit('The configuration file does not exist.'); @@ -304,6 +304,32 @@ if ( ! function_exists('config_item')) // ------------------------------------------------------------------------ +if ( ! function_exists('get_mimes')) +{ + /** + * Returns the MIME types array from config/mimes.php + * + * @return array + */ + function &get_mimes() + { + static $_mimes = array(); + + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + { + $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); + } + elseif (is_file(APPPATH.'config/mimes.php')) + { + $_mimes = include(APPPATH.'config/mimes.php'); + } + + return $_mimes; + } +} + +// ------------------------------------------------------------------------ + if ( ! function_exists('show_error')) { /** diff --git a/system/core/Output.php b/system/core/Output.php index a9e77cc5f..09656711b 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -64,7 +64,7 @@ class CI_Output { * * @var array */ - public $mime_types = array(); + public $mimes = array(); /** * Determines wether profiler is enabled @@ -104,14 +104,7 @@ class CI_Output { $this->_zlib_oc = (bool) @ini_get('zlib.output_compression'); // Get mime types for later - if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) - { - $this->mime_types = include APPPATH.'config/'.ENVIRONMENT.'/mimes.php'; - } - else - { - $this->mime_types = include APPPATH.'config/mimes.php'; - } + $this->mimes =& get_mimes(); log_message('debug', 'Output Class Initialized'); } @@ -214,9 +207,9 @@ class CI_Output { $extension = ltrim($mime_type, '.'); // Is this extension supported? - if (isset($this->mime_types[$extension])) + if (isset($this->mimes[$extension])) { - $mime_type =& $this->mime_types[$extension]; + $mime_type =& $this->mimes[$extension]; if (is_array($mime_type)) { -- cgit v1.2.3-24-g4f1b From 24bd230337cc469941dbdb51e05351cc1b3fbe14 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 5 Jun 2012 22:29:12 +0300 Subject: Fix a magic_quotes-related bug and changed the default parameter value for is_php() --- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index b3e984d4d..50eae8fb1 100755 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -73,7 +73,7 @@ */ set_error_handler('_exception_handler'); - if ( ! is_php('5.3')) + if ( ! is_php('5.4')) { @set_magic_quotes_runtime(0); // Kill magic quotes } diff --git a/system/core/Common.php b/system/core/Common.php index 5e3b8262d..c08755c91 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -44,13 +44,13 @@ if ( ! function_exists('is_php')) /** * Determines if the current version of PHP is greater then the supplied value * - * Since there are a few places where we conditionally test for PHP > 5 + * Since there are a few places where we conditionally test for PHP > 5.3 * we'll set a static variable. * * @param string * @return bool TRUE if the current version is $version or higher */ - function is_php($version = '5.0.0') + function is_php($version = '5.3.0') { static $_is_php; $version = (string) $version; -- cgit v1.2.3-24-g4f1b From e6e6eff842ce4314b9ae7f1442579a1dba355e8d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 6 Jun 2012 00:24:57 +0300 Subject: Replace set_magic_quotes_runtime() with an ini_set() call --- system/core/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 50eae8fb1..8159b19f5 100755 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -75,7 +75,7 @@ if ( ! is_php('5.4')) { - @set_magic_quotes_runtime(0); // Kill magic quotes + @ini_set('magic_quotes_runtime', 0); // Kill magic quotes } /* -- cgit v1.2.3-24-g4f1b From c28b651b91367e86f1bd6ab7f0cd6c45e58811ab Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:26:04 +0200 Subject: Add support for ipv6 --- system/core/Input.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Input.php b/system/core/Input.php index 73f46ba6a..6a5a9d8f0 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -383,7 +383,27 @@ class CI_Input { */ public function valid_ip($ip) { - return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + if($this->ip_version($ip) === '4') + { + return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + } + else + { + return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); + } + } + + // -------------------------------------------------------------------- + + /** + * Return ip version + * + * @param string + * @return string + */ + public function ip_version($ip) + { + return strpos($ip, ":") === false ? '4' : '6'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0723617703dda3660597d9cdef59e7cdded1c497 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:39:02 +0200 Subject: follow styling guide --- system/core/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Input.php b/system/core/Input.php index 6a5a9d8f0..ac67aaf4f 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -383,7 +383,7 @@ class CI_Input { */ public function valid_ip($ip) { - if($this->ip_version($ip) === '4') + if ($this->ip_version($ip) === '4') { return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } -- cgit v1.2.3-24-g4f1b From 47b673324f06236264ca64f8c3155aab51762609 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 6 Jun 2012 15:58:05 +0300 Subject: Add a second parameter (charset) to CI_Output::set_content_type() + fix for issue #666 --- system/core/Output.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system/core') diff --git a/system/core/Output.php b/system/core/Output.php index 09656711b..0bf982289 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -200,7 +200,7 @@ class CI_Output { * @param string extension of the file we're outputting * @return void */ - public function set_content_type($mime_type) + public function set_content_type($mime_type, $charset = NULL) { if (strpos($mime_type, '/') === FALSE) { @@ -218,7 +218,13 @@ class CI_Output { } } - $header = 'Content-Type: '.$mime_type; + if (empty($charset)) + { + $charset = config_item('charset'); + } + + $header = 'Content-Type: '.$mime_type + .(empty($charset) ? NULL : '; charset='.strtolower($charset)); $this->headers[] = array($header, TRUE); return $this; -- cgit v1.2.3-24-g4f1b From 908f36a583384b0314d04c4cfe71992746e35daa Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:47:22 +0200 Subject: ip_version() now returns int instead of string --- system/core/Input.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core') diff --git a/system/core/Input.php b/system/core/Input.php index ac67aaf4f..36ff96d03 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -383,7 +383,7 @@ class CI_Input { */ public function valid_ip($ip) { - if ($this->ip_version($ip) === '4') + if ($this->ip_version($ip) === 4) { return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } @@ -399,11 +399,11 @@ class CI_Input { * Return ip version * * @param string - * @return string + * @return int */ public function ip_version($ip) { - return strpos($ip, ":") === false ? '4' : '6'; + return strpos($ip, ":") === false ? 4 : 6; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1eb9b127cfb3aef5d89b86a48e35b2f35cd17f81 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 17:57:40 +0200 Subject: styling guide false -> FALSE --- system/core/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Input.php b/system/core/Input.php index 36ff96d03..c1f2086c4 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -403,7 +403,7 @@ class CI_Input { */ public function ip_version($ip) { - return strpos($ip, ":") === false ? 4 : 6; + return strpos($ip, ":") === FALSE ? 4 : 6; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1ab6f6520ebfc016c49cfbe3a4d9d009be5da268 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 20:14:13 +0200 Subject: removed ip_version() --- system/core/Input.php | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'system/core') diff --git a/system/core/Input.php b/system/core/Input.php index c1f2086c4..b986c4973 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -383,27 +383,7 @@ class CI_Input { */ public function valid_ip($ip) { - if ($this->ip_version($ip) === 4) - { - return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); - } - else - { - return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); - } - } - - // -------------------------------------------------------------------- - - /** - * Return ip version - * - * @param string - * @return int - */ - public function ip_version($ip) - { - return strpos($ip, ":") === FALSE ? 4 : 6; + return (bool) filter_var($ip, FILTER_VALIDATE_IP); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c839d28f4230dce0c658338f267b821cc16490a2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 7 Jun 2012 14:35:27 +0300 Subject: Remove some unnecessary function_exists() checks and some minor improvements --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Output.php b/system/core/Output.php index 0bf982289..5588ffe8e 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -370,7 +370,7 @@ class CI_Output { if ($this->parse_exec_vars === TRUE) { - $memory = function_exists('memory_get_usage') ? round(memory_get_usage()/1024/1024, 2).'MB' : '0'; + $memory = round(memory_get_usage() / 1024 / 1024, 2).'MB'; $output = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $output); } -- cgit v1.2.3-24-g4f1b From 92aa67cf67292b20cfb8f18fc9e24b7408620355 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 23:37:17 +0300 Subject: Fix defined() usage in system/core/Common.php --- system/core/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Common.php b/system/core/Common.php index c08755c91..1708653e7 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -240,7 +240,7 @@ if ( ! function_exists('get_config')) } // Is the config file in the environment folder? - if (defined(ENVIRONMENT) && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) + if (defined('ENVIRONMENT') && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) { require($file_path); } -- cgit v1.2.3-24-g4f1b From 5a257187c4ca09ea61c19999bf061cec3f224cc2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 10 Jun 2012 06:18:14 +0300 Subject: Merge branch 2.1-stable into develop --- system/core/Input.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/core') diff --git a/system/core/Input.php b/system/core/Input.php index b986c4973..162e40c85 100755 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -376,14 +376,26 @@ class CI_Input { /** * Validate IP Address * - * Updated version suggested by Geert De Deckere - * * @param string + * @param string 'ipv4' or 'ipv6' * @return bool */ - public function valid_ip($ip) + public function valid_ip($ip, $which = '') { - return (bool) filter_var($ip, FILTER_VALIDATE_IP); + switch (strtolower($which)) + { + case 'ipv4': + $which = FILTER_FLAG_IPV4; + break; + case 'ipv6': + $which = FILTER_FLAG_IPV6; + break; + default: + $which = NULL; + break; + } + + return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0d2c06ea1d96ea3f35dd1e7856977a24cec43233 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 02:33:45 +0300 Subject: Change file permissions for system/core/*.php and system/database/DB.php so that they don't differ from the rest --- system/core/Benchmark.php | 0 system/core/CodeIgniter.php | 0 system/core/Config.php | 0 system/core/Exceptions.php | 0 system/core/Hooks.php | 0 system/core/Input.php | 0 system/core/Lang.php | 0 system/core/Model.php | 0 system/core/Output.php | 0 system/core/Router.php | 0 system/core/Security.php | 0 system/core/URI.php | 0 12 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 system/core/Benchmark.php mode change 100755 => 100644 system/core/CodeIgniter.php mode change 100755 => 100644 system/core/Config.php mode change 100755 => 100644 system/core/Exceptions.php mode change 100755 => 100644 system/core/Hooks.php mode change 100755 => 100644 system/core/Input.php mode change 100755 => 100644 system/core/Lang.php mode change 100755 => 100644 system/core/Model.php mode change 100755 => 100644 system/core/Output.php mode change 100755 => 100644 system/core/Router.php mode change 100755 => 100644 system/core/Security.php mode change 100755 => 100644 system/core/URI.php (limited to 'system/core') diff --git a/system/core/Benchmark.php b/system/core/Benchmark.php old mode 100755 new mode 100644 diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php old mode 100755 new mode 100644 diff --git a/system/core/Config.php b/system/core/Config.php old mode 100755 new mode 100644 diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php old mode 100755 new mode 100644 diff --git a/system/core/Hooks.php b/system/core/Hooks.php old mode 100755 new mode 100644 diff --git a/system/core/Input.php b/system/core/Input.php old mode 100755 new mode 100644 diff --git a/system/core/Lang.php b/system/core/Lang.php old mode 100755 new mode 100644 diff --git a/system/core/Model.php b/system/core/Model.php old mode 100755 new mode 100644 diff --git a/system/core/Output.php b/system/core/Output.php old mode 100755 new mode 100644 diff --git a/system/core/Router.php b/system/core/Router.php old mode 100755 new mode 100644 diff --git a/system/core/Security.php b/system/core/Security.php old mode 100755 new mode 100644 diff --git a/system/core/URI.php b/system/core/URI.php old mode 100755 new mode 100644 -- cgit v1.2.3-24-g4f1b From cce918033a99186cd76019d022571a8d9321d899 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 13:25:31 +0300 Subject: Fix APPPATH --- system/core/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/Loader.php b/system/core/Loader.php index 09e948714..94739c74a 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -668,7 +668,7 @@ class CI_Loader { * @param bool * @return void */ - public function add_package_path($path, $view_cascade=TRUE) + public function add_package_path($path, $view_cascade = TRUE) { $path = rtrim($path, '/').'/'; -- cgit v1.2.3-24-g4f1b From d461934184d95b0cfb2feec93f27b621ef72a5c2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 02:27:25 +0300 Subject: Fix issue #10 + URI class speed improvements --- system/core/URI.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'system/core') diff --git a/system/core/URI.php b/system/core/URI.php index a575bc36e..2e661ed4c 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -119,7 +119,7 @@ class CI_URI { } // No PATH_INFO?... What about QUERY_STRING? - $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); + $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') !== '') { $this->_set_uri_string($path); @@ -163,7 +163,7 @@ class CI_URI { * @param string * @return void */ - public function _set_uri_string($str) + protected function _set_uri_string($str) { // Filter out control characters $str = remove_invisible_characters($str, FALSE); @@ -177,8 +177,8 @@ class CI_URI { /** * Detects the URI * - * This function will detect the URI automatically and fix the query string - * if necessary. + * This function will detect the URI automatically + * and fix the query string if necessary. * * @return string */ @@ -189,7 +189,6 @@ class CI_URI { return ''; } - $uri = $_SERVER['REQUEST_URI']; if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); @@ -198,14 +197,19 @@ class CI_URI { { $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } + else + { + $uri = $_SERVER['REQUEST_URI']; + } // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct // URI is found, and also fixes the QUERY_STRING server var and $_GET array. - if (strncmp($uri, '?/', 2) === 0) + if (strpos($uri, '?/') === 0) { $uri = substr($uri, 2); } - $parts = preg_split('#\?#i', $uri, 2); + + $parts = explode('?', $uri, 2); $uri = $parts[0]; if (isset($parts[1])) { @@ -223,7 +227,7 @@ class CI_URI { return '/'; } - $uri = parse_url($uri, PHP_URL_PATH); + $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH); // Do some final cleaning of the URI and return it return str_replace(array('//', '../'), '/', trim($uri, '/')); -- cgit v1.2.3-24-g4f1b From a8262ba2fe0e11302b8d81e1afba71d4f96cd6d7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 03:16:44 +0300 Subject: Fix an issue from d461934184d95b0cfb2feec93f27b621ef72a5c2 --- system/core/URI.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core') diff --git a/system/core/URI.php b/system/core/URI.php index 2e661ed4c..ef1a12650 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -189,11 +189,11 @@ class CI_URI { return ''; } - if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) + if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) { - $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); + $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])); } - elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) + elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) { $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); } -- cgit v1.2.3-24-g4f1b From fb859791182edd2f46479cd69ea4615daebed655 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 03:32:19 +0300 Subject: And yet another missed line from the last one --- system/core/URI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core') diff --git a/system/core/URI.php b/system/core/URI.php index ef1a12650..a997525ee 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -195,7 +195,7 @@ class CI_URI { } elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) { - $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); + $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME']))); } else { -- cgit v1.2.3-24-g4f1b