From 8310595f0e80f72ac790478b8a7dfc6470051639 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:18:15 +0200 Subject: Changed Date helper to return time() based on the timezone parameter. --- application/config/config.php | 16 +++++++--------- index.php | 2 ++ system/helpers/date_helper.php | 24 +++++++++--------------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 2628885f0..4d0e5080a 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -204,7 +204,7 @@ $config['directory_trigger'] = 'd'; // experimental not currently in use | 4 = All Messages | | You can also pass in a array with threshold levels to show individual error types -| +| | array(2) = Debug Messages, without Error Messages | | For a live site you'll usually only enable Errors (1) to be logged otherwise @@ -253,7 +253,7 @@ $config['cache_path'] = ''; | | If you use the Encryption class or the Session class you | MUST set an encryption key. See the user guide for info. -| +| | http://codeigniter.com/user_guide/libraries/encryption.html | http://codeigniter.com/user_guide/libraries/sessions.html | @@ -297,7 +297,7 @@ $config['sess_time_to_update'] = 300; | 'cookie_domain' = Set to .your-domain.com for site-wide cookies | 'cookie_path' = Typically will be a forward slash | 'cookie_secure' = Cookies will only be set if a secure HTTPS connection exists. -| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) +| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) | */ $config['cookie_prefix'] = ""; @@ -359,16 +359,14 @@ $config['compress_output'] = FALSE; /* |-------------------------------------------------------------------------- -| Master Time Reference +| Master Timezone |-------------------------------------------------------------------------- | -| Options are 'local' or 'gmt'. This pref tells the system whether to use -| your server's local time as the master 'now' reference, or convert it to -| GMT. See the 'date helper' page of the user guide for information -| regarding date handling. +| You can set any PHP supported timezones to be the master timezone when +| you call th now() function. | */ -$config['time_reference'] = 'local'; +$config['timezone'] = 'UTC'; /* diff --git a/index.php b/index.php index 5a1190112..28586093d 100644 --- a/index.php +++ b/index.php @@ -162,6 +162,8 @@ if (defined('ENVIRONMENT')) // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE // -------------------------------------------------------------------- +date_default_timezone_set('UTC'); + /* * --------------------------------------------------------------- * Resolve the system path for increased reliability diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index f1ba364f5..aecc7d90f 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -46,25 +46,19 @@ */ if ( ! function_exists('now')) { - function now() + function now($timezone = NULL) { - $CI =& get_instance(); + $CI =& get_instance(); - if (strtolower($CI->config->item('time_reference')) == 'gmt') - { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + if (is_null($timezone)) + $timezone = $CI->config->item('timezone'); - if (strlen($system_time) < 10) - { - $system_time = time(); - log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); - } + $timezone = new DateTimeZone($timezone); + $now = new DateTime('now', $timezone); + $offset = $timezone->getOffset($now); + $time = time() + $offset; - return $system_time; - } - - return time(); + return $time; } } -- cgit v1.2.3-24-g4f1b From 7bf0a4ff35efc758ef43b3a848e655285946b8b6 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:36:15 +0200 Subject: Added doccumentation for the new date helper. --- system/helpers/date_helper.php | 4 +++- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/helpers/date_helper.rst | 22 ++++++++++++++-------- user_guide_src/source/installation/upgrade_300.rst | 6 ++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index aecc7d90f..7ff7444e5 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -40,8 +40,10 @@ /** * Get "now" time * - * Returns time() or its GMT equivalent based on the config file preference + * Returns time() based on the timezone parameter or on the "timezone" + * setting * + * @param string * @return int */ if ( ! function_exists('now')) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index b4bf0cfaa..e5b6eea47 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -40,6 +40,7 @@ Release Date: Not Released - Helpers + - Date helper will now return now() based on the timezone you specify. - url_title() will now trim extra dashes from beginning and end. - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper `. - Changed humanize to include a second param for the separator. diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index b21d147bd..b8c3dd076 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -20,14 +20,20 @@ The following functions are available: now() ===== -Returns the current time as a Unix timestamp, referenced either to your -server's local time or GMT, based on the "time reference" setting in -your config file. If you do not intend to set your master time reference -to GMT (which you'll typically do if you run a site that lets each user -set their own timezone settings) there is no benefit to using this -function over PHP's time() function. - -.. php:method:: now() +Returns the current time as a Unix timestamp, based on the "timezone" parameter. +All PHP available timezones are supported. + +.. php:method:: now($timezone = NULL) + + :param string $timezone: The timezone you want to be returned + :returns: integer + +:: + + $tz = "Australia/Victoria"; + echo now($tz); + +If a timezone is not provided, it will return time() based on "timezone" setting. mdate() ======= diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 4c594ab17..b6f52080a 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -31,3 +31,9 @@ Step 3: Remove $autoload['core'] from your config/autoload.php Use of the `$autoload['core']` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed. Move any entries that you might have listed there to `$autoload['libraries']` instead. + +Step 4: Change your use of the Date heper's now() function +========================================================== + +Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>` +You must replace $config['time_reference'] with $config['timezone']. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 91a13199292d8b4495e6ecbcb6a5fea1294cd2da Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:50:32 +0200 Subject: Fixed typo. --- application/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/config.php b/application/config/config.php index 4d0e5080a..eb3ddddb0 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -363,7 +363,7 @@ $config['compress_output'] = FALSE; |-------------------------------------------------------------------------- | | You can set any PHP supported timezones to be the master timezone when -| you call th now() function. +| you call the now() function. | */ $config['timezone'] = 'UTC'; -- cgit v1.2.3-24-g4f1b From 16760bb0d812b951564bd1742af6e622490ca05c Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:51:52 +0200 Subject: Added braces as requested. --- system/helpers/date_helper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 7ff7444e5..14d973f65 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -53,7 +53,9 @@ if ( ! function_exists('now')) $CI =& get_instance(); if (is_null($timezone)) + { $timezone = $CI->config->item('timezone'); + } $timezone = new DateTimeZone($timezone); $now = new DateTime('now', $timezone); -- cgit v1.2.3-24-g4f1b From 0ed4f63f4268b0c98f549ffd711702fd45a761d0 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 22:07:44 +0200 Subject: Fixed a typo and added the route for the config file. --- user_guide_src/source/installation/upgrade_300.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index b6f52080a..5d6450ee6 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -32,8 +32,8 @@ Step 3: Remove $autoload['core'] from your config/autoload.php Use of the `$autoload['core']` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed. Move any entries that you might have listed there to `$autoload['libraries']` instead. -Step 4: Change your use of the Date heper's now() function +Step 4: Change your use of the Date helper's now() function ========================================================== Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>` -You must replace $config['time_reference'] with $config['timezone']. \ No newline at end of file +You must replace $config['time_reference'] with $config['timezone'] in your config.php file. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f5d1fd2ce8bfa049c8049184ac6d385d0f70fe29 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Fri, 8 Jun 2012 23:37:33 +0200 Subject: Updated the upgrade guide to specify which are the supported timezones. --- user_guide_src/source/installation/upgrade_300.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 503e5366c..e86ef67da 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -46,7 +46,8 @@ Step 5: Change your use of the Date helper's now() function =========================================================== Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>` -You must replace $config['time_reference'] with $config['timezone'] in your config.php file. +You must replace $config['time_reference'] with $config['timezone'] in your config.php file. You can select all +PHP supported timezones, listed here: `PHP's supported timezones `_. Step 6: Move your errors folder =============================== -- cgit v1.2.3-24-g4f1b From e15e3dde9dca15e2d65f098010d3fb7004cef5e7 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Sat, 9 Jun 2012 23:52:27 +0200 Subject: Fixed timezone change in index.php Now it does not ever change the local timezone, and it adds the option to get the 'local' time() --- index.php | 2 -- system/helpers/date_helper.php | 14 ++++++++++---- user_guide_src/source/helpers/date_helper.rst | 3 ++- user_guide_src/source/installation/upgrade_300.rst | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index 62fc2ab1b..3b00dd360 100644 --- a/index.php +++ b/index.php @@ -162,8 +162,6 @@ if (defined('ENVIRONMENT')) // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE // -------------------------------------------------------------------- -date_default_timezone_set('UTC'); - /* * --------------------------------------------------------------- * Resolve the system path for increased reliability diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 3b0c3289d..d5acec23f 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -57,10 +57,16 @@ if ( ! function_exists('now')) $timezone = $CI->config->item('timezone'); } - $timezone = new DateTimeZone($timezone); - $now = new DateTime('now', $timezone); - $offset = $timezone->getOffset($now); - $time = time() + $offset; + $time = time(); + if(strtolower($timezone) != 'local') + { + $local = new DateTime(NULL, new DateTimeZone(date_default_timezone_get())); + $now = new DateTime(NULL, new DateTimeZone($timezone)); + $lcl_offset = $local->getOffset(); + $tz_offset = $now->getOffset(); + $offset = $tz_offset - $lcl_offset; + $time = $time + $offset; + } return $time; } diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index b6c6ed4bb..33b39bd5b 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -21,7 +21,8 @@ now() ===== Returns the current time as a Unix timestamp, based on the "timezone" parameter. -All PHP available timezones are supported. +All PHP available timezones are supported. You can also use 'local' timezone, and +it will return time(). .. php:method:: now($timezone = NULL) diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index e86ef67da..c2c3899ee 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -47,7 +47,8 @@ Step 5: Change your use of the Date helper's now() function Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>` You must replace $config['time_reference'] with $config['timezone'] in your config.php file. You can select all -PHP supported timezones, listed here: `PHP's supported timezones `_. +PHP supported timezones, listed here: `Supported timezones `_. You can also +use 'local' if you want to get time(). Step 6: Move your errors folder =============================== -- cgit v1.2.3-24-g4f1b From a9617a35ce4af051d3ad1298c2c24453460754cc Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Sun, 10 Jun 2012 00:13:04 +0200 Subject: Changed the default timezone to local and explained in the config file. --- application/config/config.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index eb3ddddb0..12ef77c76 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -363,10 +363,11 @@ $config['compress_output'] = FALSE; |-------------------------------------------------------------------------- | | You can set any PHP supported timezones to be the master timezone when -| you call the now() function. +| you call the now() function. 'local' string can be used to get the local +| time. | */ -$config['timezone'] = 'UTC'; +$config['timezone'] = 'local'; /* -- cgit v1.2.3-24-g4f1b From c88daba688d309150a7dce43817ab76ec7834bda Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Mon, 11 Jun 2012 13:58:30 +0200 Subject: Optimized now() function. Thanks to @narfbg --- system/helpers/date_helper.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index d5acec23f..b818da9d8 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -50,25 +50,20 @@ if ( ! function_exists('now')) */ function now($timezone = NULL) { - $CI =& get_instance(); - - if (is_null($timezone)) + if (empty($timezone)) { - $timezone = $CI->config->item('timezone'); + $timezone = config_item('timezone'); } - $time = time(); - if(strtolower($timezone) != 'local') + if ($timezone === 'local' OR $timezone === date_default_timezone_get()) { - $local = new DateTime(NULL, new DateTimeZone(date_default_timezone_get())); - $now = new DateTime(NULL, new DateTimeZone($timezone)); - $lcl_offset = $local->getOffset(); - $tz_offset = $now->getOffset(); - $offset = $tz_offset - $lcl_offset; - $time = $time + $offset; + return time(); } - return $time; + $datetime = new DateTime('now', new DateTimeZone($timezone)); + sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); + + return mktime($hour, $minute, $second, $month, $day, $year); } } -- cgit v1.2.3-24-g4f1b From 6a56d50cc03ec74a905718e711b48253cc267f00 Mon Sep 17 00:00:00 2001 From: Kevin Wood-Friend Date: Tue, 12 Jun 2012 09:54:01 -0400 Subject: Modified Form Validation class's set_rules() so it can now handle an array of rules, instead of just a string --- system/libraries/Form_validation.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 77c968e7c..6cbe032c7 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -187,6 +187,12 @@ class CI_Form_validation { return $this; } + // Convert an array of rules to a string + if (is_array($rules)) + { + $rules = implode('|', $rules); + } + // No fields? Nothing to do... if ( ! is_string($field) OR ! is_string($rules) OR $field === '') { -- cgit v1.2.3-24-g4f1b From fe8f5e25c8127c0ff7ebb77dd5f9b982e9eb9270 Mon Sep 17 00:00:00 2001 From: Kevin Wood-Friend Date: Tue, 12 Jun 2012 09:56:00 -0400 Subject: Updated changelog for set_rules() accepting an array of rules, as well as a string. --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index ab3e01394..33b413163 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -147,6 +147,7 @@ Release Date: Not Released - _execute() now considers input data to be invalid if a specified rule is not found. - Removed method is_numeric() as it exists as a native PHP function and _execute() will find and use that (the 'is_numeric' rule itself is deprecated since 1.6.1). - Native PHP functions used as rules can now accept an additional parameter, other than the data itself. + - Updated set_rules() to accept an array of rules as well as a string. - Changed the :doc:`Session Library ` to select only one row when using database sessions. - Added all_flashdata() method to session class. Returns an associative array of only flashdata. - Allowed for setting table class defaults in a config file. -- cgit v1.2.3-24-g4f1b From feb14dac4e7a417a48344a5188a8ad8074871df4 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 12 Jun 2012 16:09:36 +0200 Subject: Changed the config parameter. The session's _get_time() function has also changed. --- application/config/config.php | 4 ++-- system/helpers/date_helper.php | 2 +- system/libraries/Session.php | 14 +++++++++++--- user_guide_src/source/helpers/date_helper.rst | 6 ++---- user_guide_src/source/installation/upgrade_300.rst | 5 ++--- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 12ef77c76..fd6a1aeb0 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -359,7 +359,7 @@ $config['compress_output'] = FALSE; /* |-------------------------------------------------------------------------- -| Master Timezone +| Master Time Reference |-------------------------------------------------------------------------- | | You can set any PHP supported timezones to be the master timezone when @@ -367,7 +367,7 @@ $config['compress_output'] = FALSE; | time. | */ -$config['timezone'] = 'local'; +$config['time_reference'] = 'local'; /* diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index b818da9d8..131508f69 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -52,7 +52,7 @@ if ( ! function_exists('now')) { if (empty($timezone)) { - $timezone = config_item('timezone'); + $timezone = config_item('time_reference'); } if ($timezone === 'local' OR $timezone === date_default_timezone_get()) diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 7beedd96b..9fdf744c3 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -786,9 +786,17 @@ class CI_Session { */ protected function _get_time() { - return (strtolower($this->time_reference) === 'gmt') - ? mktime(gmdate('H'), gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y')) - : time(); + $timezone = config_item('time_reference'); + + if ($timezone === 'local' OR $timezone === date_default_timezone_get()) + { + return time(); + } + + $datetime = new DateTime('now', new DateTimeZone($timezone)); + sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); + + return mktime($hour, $minute, $second, $month, $day, $year); } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index 33b39bd5b..7bbfd4f15 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -30,11 +30,9 @@ it will return time(). :returns: integer :: + echo now("Australia/Victoria"); - $tz = "Australia/Victoria"; - echo now($tz); - -If a timezone is not provided, it will return time() based on "timezone" setting. +If a timezone is not provided, it will return time() based on "time_reference" setting. mdate() ======= diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index c2c3899ee..debf9662c 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -45,9 +45,8 @@ need to rename the `$active_record` variable to `$query_builder`. Step 5: Change your use of the Date helper's now() function =========================================================== -Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>` -You must replace $config['time_reference'] with $config['timezone'] in your config.php file. You can select all -PHP supported timezones, listed here: `Supported timezones `_. You can also +Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>`. +You can now select all PHP supported timezones in the `time_reference` setting, listed here: `Supported timezones `_. You can also use 'local' if you want to get time(). Step 6: Move your errors folder -- cgit v1.2.3-24-g4f1b From f9311136d9f821b7b0b1f2fa7c933f51803d4f96 Mon Sep 17 00:00:00 2001 From: Kevin Wood-Friend Date: Tue, 12 Jun 2012 10:57:57 -0400 Subject: Updated Form Validation's documentation for set_rules() now accepting an array of rules --- user_guide_src/source/libraries/form_validation.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 3c0e6eda4..3bcad7ba6 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -304,6 +304,10 @@ Give it a try! Submit your form without the proper data and you'll see new error messages that correspond to your new rules. There are numerous rules available which you can read about in the validation reference. +.. note:: You can also pass an array of rules to set_rules(), instead of a string. Example:: + + $this->form_validation->set_rules('username', 'Username', array('required', 'min_length[5]')); + Prepping Data ============= @@ -935,7 +939,7 @@ $this->form_validation->set_rules(); :param string $field: The field name :param string $label: The field label - :param string $rules: The rules, seperated by a pipe "|" + :param mixed $rules: The rules, as a string with rules separated by a pipe "|", or an array or rules. :rtype: Object Permits you to set validation rules, as described in the tutorial -- cgit v1.2.3-24-g4f1b From 97827bc9ddad61f51ceb595e8b8b5441d4d991c2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 21:20:05 +0300 Subject: Fix issue #1460 --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 88a3b388f..63d3372cf 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,7 +596,7 @@ abstract class CI_DB_driver { */ public function compile_binds($sql, $binds) { - if (preg_match_all('/(>|<|=|!)\s*('.preg_quote($this->bind_marker).')/i', $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) + if (preg_match_all('/(>|<|=|!|BETWEEN\s|AND\s)\s*('.preg_quote($this->bind_marker).')/i', $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) { return $sql; } -- cgit v1.2.3-24-g4f1b From 29953ddc989e2ae26afedefd99e347f2d692d0ec Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 21:48:13 +0300 Subject: Additional improvements to compile_binds() --- system/database/DB_driver.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 63d3372cf..e0266b2b6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,7 +596,12 @@ abstract class CI_DB_driver { */ public function compile_binds($sql, $binds) { - if (preg_match_all('/(>|<|=|!|BETWEEN\s|AND\s)\s*('.preg_quote($this->bind_marker).')/i', $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) + if (empty($binds)) OR empty($this->bind_marker)) + { + return $sql; + } + elseif (preg_match_all('/(>|<|=|!|BETWEEN\s|AND\s)\s*('.preg_quote($this->bind_marker).')/i', + $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) { return $sql; } @@ -610,10 +615,9 @@ abstract class CI_DB_driver { $binds = array_values($binds); } - - for ($i = count($matches) - 1; $i >= 0; $i--) + for ($i = count($matches) - 1, $l = strlen($this->bind_marker); $i >= 0; $i--) { - $sql = substr_replace($sql, $this->escape($binds[$i]), $matches[$i][2][1], 1); + $sql = substr_replace($sql, $this->escape($binds[$i]), $matches[$i][2][1], $l); } return $sql; -- cgit v1.2.3-24-g4f1b From 63779194b6788edfa8899ed3c86c653d0933ce3b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 13 Jun 2012 10:04:49 +0300 Subject: Fix a syntax error --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e0266b2b6..e04463429 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,7 +596,7 @@ abstract class CI_DB_driver { */ public function compile_binds($sql, $binds) { - if (empty($binds)) OR empty($this->bind_marker)) + if (empty($binds) OR empty($this->bind_marker)) { return $sql; } -- cgit v1.2.3-24-g4f1b From 6984d153f68f1f89fa6800143498cc4914441d66 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 13 Jun 2012 10:10:17 +0300 Subject: Add a changelog entry --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 33b413163..e955209b1 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -265,6 +265,7 @@ Bug fixes for 3.0 - Fixed a bug in the File-based :doc:`Cache Library ` driver's get_metadata() method where a non-existent array key was accessed for the TTL value. - Fixed a bug (#1202) - :doc:`Encryption Library ` encode_from_legacy() didn't set back the encrypt mode on failure. - Fixed a bug (#145) - compile_binds() failed when the bind marker was present in a literal string within the query. +- Fixed a bug in protect_identifiers() where if passed along with the field names, operators got escaped as well. Version 2.1.1 ============= -- cgit v1.2.3-24-g4f1b From 9cf12d1de76c2696233a437e0cdc7266bb846ae6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 13 Jun 2012 10:19:59 +0300 Subject: Fix docs for Input library (issue #1465) --- user_guide_src/source/libraries/input.rst | 37 +++++++++---------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst index 7f995f050..8c6f7c849 100644 --- a/user_guide_src/source/libraries/input.rst +++ b/user_guide_src/source/libraries/input.rst @@ -42,14 +42,14 @@ this:: Please refer to the :doc:`Security class ` documentation for information on using XSS Filtering in your application. -Using POST, COOKIE, or SERVER Data -================================== +Using POST, GET, COOKIE, or SERVER Data +======================================= -CodeIgniter comes with three helper functions that let you fetch POST, +CodeIgniter comes with four helper methods that let you fetch POST, GET, COOKIE or SERVER items. The main advantage of using the provided functions rather than fetching an item directly ($_POST['something']) -is that the functions will check to see if the item is set and return -false (boolean) if not. This lets you conveniently use data without +is that the methods will check to see if the item is set and return +NULL if not. This lets you conveniently use data without having to test whether an item exists first. In other words, normally you might do something like this:: @@ -73,8 +73,8 @@ looking for:: $this->input->post('some_data'); -The function returns FALSE (boolean) if the item you are attempting to -retrieve does not exist. +The function returns NULL if the item you are attempting to retrieve +does not exist. The second optional parameter lets you run the data through the XSS filter. It's enabled by setting the second parameter to boolean TRUE; @@ -130,7 +130,9 @@ $this->input->cookie() This function is identical to the post function, only it fetches cookie data:: - $this->input->cookie('some_data', TRUE); + $this->input->cookie('some_cookie'); + $this->input->cookie('some_cookie, TRUE); // with XSS filter + $this->input->server() ====================== @@ -195,25 +197,6 @@ parameters:: $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); -$this->input->cookie() -====================== - -Lets you fetch a cookie. The first parameter will contain the name of -the cookie you are looking for (including any prefixes):: - - cookie('some_cookie'); - -The function returns NULL if the item you are attempting to -retrieve does not exist. - -The second optional parameter lets you run the data through the XSS -filter. It's enabled by setting the second parameter to boolean TRUE; - -:: - - cookie('some_cookie', TRUE); - - $this->input->ip_address() =========================== -- cgit v1.2.3-24-g4f1b From 22c3e73573d2828cec6183866b162359f873a949 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 13 Jun 2012 10:21:36 +0300 Subject: Another input library docs fix --- user_guide_src/source/libraries/input.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst index 8c6f7c849..c0b9c6589 100644 --- a/user_guide_src/source/libraries/input.rst +++ b/user_guide_src/source/libraries/input.rst @@ -59,9 +59,10 @@ With CodeIgniter's built in functions you can simply do this:: $something = $this->input->post('something'); -The three functions are: +The four methods are: - $this->input->post() +- $this->input->get() - $this->input->cookie() - $this->input->server() -- cgit v1.2.3-24-g4f1b From 10cbdf091b3cdbc72847dad28a1dce03a92119b6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 13 Jun 2012 13:32:30 +0300 Subject: Really fix compile_binds() --- system/database/DB_driver.php | 44 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e04463429..1fece5cf7 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,28 +596,54 @@ abstract class CI_DB_driver { */ public function compile_binds($sql, $binds) { - if (empty($binds) OR empty($this->bind_marker)) - { - return $sql; - } - elseif (preg_match_all('/(>|<|=|!|BETWEEN\s|AND\s)\s*('.preg_quote($this->bind_marker).')/i', - $sql, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE) !== count($binds)) + if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE) { return $sql; } elseif ( ! is_array($binds)) { - $binds = array($binds); + $binds = array($this->escape($binds)); + $bind_count = 1; } else { // Make sure we're using numeric keys $binds = array_values($binds); + $bind_count = count($binds); + + // Escape the bind values + for ($i = 0; $i < $bind_count; $i++) + { + $binds[$i] = $this->escape($binds[$i]); + } } - for ($i = count($matches) - 1, $l = strlen($this->bind_marker); $i >= 0; $i--) + // Make sure not to replace a chunk inside a string that happens to match the bind marker + if ($c = preg_match_all("/'[^']*'/i", $sql, $matches)) + { + $ml = strlen($this->bind_marker); + $c = preg_match_all('/'.preg_quote($this->bind_marker).'/i', + str_replace($matches[0], + str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), + $sql, $c), + $matches, PREG_OFFSET_CAPTURE); + + // Bind values' count must match the count of markers in the query + if ($bind_count !== $c) + { + return $sql; + } + + do + { + $c--; + $sql = substr_replace($sql, $binds[$c], $matches[0][$c][1], $ml); + } + while ($c !== 0); + } + elseif (substr_count($sql, $this->bind_marker) === count($binds)) { - $sql = substr_replace($sql, $this->escape($binds[$i]), $matches[$i][2][1], $l); + return str_replace($this->bind_marker, $binds, $sql, $bind_count); } return $sql; -- cgit v1.2.3-24-g4f1b From af915ce01e4e5424a7a4ea67e4e3018a40752a89 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 13 Jun 2012 19:03:06 +0300 Subject: Switch compile_binds() to use substr_replace() instead of str_replace() --- system/database/DB_driver.php | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1fece5cf7..d056bdb90 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -602,7 +602,7 @@ abstract class CI_DB_driver { } elseif ( ! is_array($binds)) { - $binds = array($this->escape($binds)); + $binds = array($binds); $bind_count = 1; } else @@ -610,18 +610,14 @@ abstract class CI_DB_driver { // Make sure we're using numeric keys $binds = array_values($binds); $bind_count = count($binds); - - // Escape the bind values - for ($i = 0; $i < $bind_count; $i++) - { - $binds[$i] = $this->escape($binds[$i]); - } } + // We'll need the marker length later + $ml = strlen($this->bind_marker); + // Make sure not to replace a chunk inside a string that happens to match the bind marker if ($c = preg_match_all("/'[^']*'/i", $sql, $matches)) { - $ml = strlen($this->bind_marker); $c = preg_match_all('/'.preg_quote($this->bind_marker).'/i', str_replace($matches[0], str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]), @@ -633,18 +629,18 @@ abstract class CI_DB_driver { { return $sql; } - - do - { - $c--; - $sql = substr_replace($sql, $binds[$c], $matches[0][$c][1], $ml); - } - while ($c !== 0); } - elseif (substr_count($sql, $this->bind_marker) === count($binds)) + elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker).'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count) + { + return $sql; + } + + do { - return str_replace($this->bind_marker, $binds, $sql, $bind_count); + $c--; + $sql = substr_replace($sql, $this->escape($binds[$c]), $matches[0][$c][1], $ml); } + while ($c !== 0); return $sql; } -- cgit v1.2.3-24-g4f1b From 7400965017f87c3aba18bf75ed7d732359fd577d Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Wed, 13 Jun 2012 22:57:50 +0200 Subject: Fixed some stuff in documentation. --- application/config/config.php | 7 ++++--- system/helpers/date_helper.php | 4 ++-- user_guide_src/source/helpers/date_helper.rst | 9 ++++++--- user_guide_src/source/installation/upgrade_300.rst | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index fd6a1aeb0..31ff2024d 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -362,9 +362,10 @@ $config['compress_output'] = FALSE; | Master Time Reference |-------------------------------------------------------------------------- | -| You can set any PHP supported timezones to be the master timezone when -| you call the now() function. 'local' string can be used to get the local -| time. +| Options are 'local' or any PHP supported timezone. This pref tells the +| system whether to use your server's local time as the master 'now' +| reference, or convert it to any PHP supported timezone. See the 'date +| helper' page of the user guide for information regarding date handling. | */ $config['time_reference'] = 'local'; diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 131508f69..a5c46e47b 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -42,8 +42,8 @@ if ( ! function_exists('now')) /** * Get "now" time * - * Returns time() based on the timezone parameter or on the "timezone" - * setting + * Returns time() based on the timezone parameter or on the + * "time_reference" setting * * @param string * @return int diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index 7bbfd4f15..1b7177fc2 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -20,9 +20,12 @@ The following functions are available: now() ===== -Returns the current time as a Unix timestamp, based on the "timezone" parameter. -All PHP available timezones are supported. You can also use 'local' timezone, and -it will return time(). +Returns the current time as a Unix timestamp, referenced either to your +server's local time or any PHP suported timezone, based on the "time reference" +setting in your config file. If you do not intend to set your master time reference +to any other PHP suported timezone (which you'll typically do if you run a site that +lets each user set their own timezone settings) there is no benefit to using this +function over PHP's time() function. .. php:method:: now($timezone = NULL) diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index debf9662c..d8a3d5bc1 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -46,8 +46,8 @@ Step 5: Change your use of the Date helper's now() function =========================================================== Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>`. -You can now select all PHP supported timezones in the `time_reference` setting, listed here: `Supported timezones `_. You can also -use 'local' if you want to get time(). +You can now select all PHP supported timezones in the `time_reference` setting, listed here: +`Supported timezones `_. You can also use 'local' if you want to get time(). Step 6: Move your errors folder =============================== -- 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 ++++++++++++-------- user_guide_src/source/changelog.rst | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) 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, '/')); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index e955209b1..039e8acf3 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -266,11 +266,12 @@ Bug fixes for 3.0 - Fixed a bug (#1202) - :doc:`Encryption Library ` encode_from_legacy() didn't set back the encrypt mode on failure. - Fixed a bug (#145) - compile_binds() failed when the bind marker was present in a literal string within the query. - Fixed a bug in protect_identifiers() where if passed along with the field names, operators got escaped as well. +- Fixed a bug (#10) - :doc:`URI Library ` internal method _detect_uri() failed with paths containing a colon. Version 2.1.1 ============= -Release Date: Not Released +Release Date: June 13, 2012 - General Changes - Fixed support for docx, xlsx files in mimes.php. @@ -295,7 +296,6 @@ Bug fixes for 2.1.1 - Fixed a bug (#726) - PDO put a 'dbname' argument in it's connection string regardless of the database platform in use, which made it impossible to use SQLite. - Fixed a bug - CI_DB_pdo_driver::num_rows() was not returning properly value with SELECT queries, cause it was relying on PDOStatement::rowCount(). - Fixed a bug (#1059) - CI_Image_lib::clear() was not correctly clearing all necessary object properties, namely width and height. -- Fixed a bud (#1387) - Active Record's ``from()`` method didn't escape table aliases. Version 2.1.0 ============= -- cgit v1.2.3-24-g4f1b From d163e0b219b8afacea3cd0d1d7c2ce5bb6f8a933 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 03:09:53 +0300 Subject: Polish changes from pull #1233 - Session class already has the time_reference setting - 'GMT' is a valid timezone, so nothing needs to be changed in order to work properly (upgrade notes) - Altered some description text --- application/config/config.php | 6 +++--- system/libraries/Session.php | 12 +++++------- user_guide_src/source/changelog.rst | 3 ++- user_guide_src/source/installation/upgrade_300.rst | 11 ++--------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 31ff2024d..7da889f81 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -362,9 +362,9 @@ $config['compress_output'] = FALSE; | Master Time Reference |-------------------------------------------------------------------------- | -| Options are 'local' or any PHP supported timezone. This pref tells the -| system whether to use your server's local time as the master 'now' -| reference, or convert it to any PHP supported timezone. See the 'date +| Options are 'local' or any PHP supported timezone. This preference tells +| the system whether to use your server's local time as the master 'now' +| reference, or convert it to the configured one timezone. See the 'date | helper' page of the user guide for information regarding date handling. | */ diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 9fdf744c3..72a942b8a 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -149,11 +149,11 @@ class CI_Session { public $flashdata_key = 'flash'; /** - * Function to use to get the current time + * Timezone to use for the current time * * @var string */ - public $time_reference = 'time'; + public $time_reference = 'local'; /** * Probablity level of garbage collection of old sessions @@ -203,7 +203,7 @@ class CI_Session { // manually via the $params array above or via the config file foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { - $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); + $this->$key = isset($params[$key]) ? $params[$key] : $this->CI->config->item($key); } if ($this->encryption_key === '') @@ -786,14 +786,12 @@ class CI_Session { */ protected function _get_time() { - $timezone = config_item('time_reference'); - - if ($timezone === 'local' OR $timezone === date_default_timezone_get()) + if ($this->time_reference === 'local' OR $this->time_reference === date_default_timezone_get()) { return time(); } - $datetime = new DateTime('now', new DateTimeZone($timezone)); + $datetime = new DateTime('now', new DateTimeZone($this->time_reference)); sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second); return mktime($hour, $minute, $second, $month, $day, $year); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 1f5bcb648..06bfba887 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -48,7 +48,7 @@ Release Date: Not Released - Helpers - - Date helper will now return now() based on the timezone you specify. + - :doc:`Date Helper ` function now() now works with all timezone strings supported by PHP. - ``create_captcha()`` accepts additional colors parameter, allowing for color customization. - ``url_title()`` will now trim extra dashes from beginning and end. - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper `. @@ -173,6 +173,7 @@ Release Date: Not Released - Added get_content_type() method to the :doc:`Output Library `. - Added get_mimes() function to system/core/Commons.php to return the config/mimes.php array. - Added a second argument to set_content_type() in the :doc:`Output Library ` that allows setting the document charset as well. + - $config['time_reference'] now supports all timezone strings supported by PHP. Bug fixes for 3.0 ------------------ diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index d8a3d5bc1..c70737cff 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -42,14 +42,7 @@ need to rename the `$active_record` variable to `$query_builder`. // $active_record = TRUE; $query_builder = TRUE; -Step 5: Change your use of the Date helper's now() function -=========================================================== - -Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>`. -You can now select all PHP supported timezones in the `time_reference` setting, listed here: -`Supported timezones `_. You can also use 'local' if you want to get time(). - -Step 6: Move your errors folder +Step 5: Move your errors folder =============================== -In version 3.0.0, the errors folder has been moved from "application/errors" to "application/views/errors". \ No newline at end of file +In version 3.0.0, the errors folder has been moved from _application/errors_ to _application/views/errors_. \ No newline at end of file -- 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(-) 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(-) 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 From 43cfd0c37ca241618f33eae87fec720a5bcf13d6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:18:26 +0300 Subject: Comment out _set_uri_string() test as it is no longer callable from outside the class --- tests/codeigniter/core/URI_test.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 0ba694b46..60ed1a4e9 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -9,6 +9,10 @@ class URI_test extends CI_TestCase { // -------------------------------------------------------------------- + /* As of the following commit, _set_uri_string() is a protected method: + + https://github.com/EllisLab/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2 + public function test_set_uri_string() { // Slashes get killed @@ -18,6 +22,7 @@ class URI_test extends CI_TestCase { $this->uri->_set_uri_string('nice/uri'); $this->assertEquals('nice/uri', $this->uri->uri_string); } + */ // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e1c8ee76f4756442094106320d9577c2c7595959 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:35:11 +0300 Subject: Alter now() tests --- tests/codeigniter/helpers/date_helper_test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4b747b864..bcb1477bc 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -13,6 +13,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_local() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -22,6 +24,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our test instance $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'local'); + $this->assertEquals(time(), now()); } @@ -29,6 +35,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_gmt() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -38,6 +46,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our stdClass $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'gmt'); + $t = time(); $this->assertEquals( mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), -- cgit v1.2.3-24-g4f1b From 0ddff314d619e5d24bdf07f3da33c779f5b6e2c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:18:07 +0300 Subject: test_now_gmt() -> test_now_utc() --- tests/codeigniter/helpers/date_helper_test.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index bcb1477bc..242935116 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -33,7 +33,7 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_now_gmt() + public function test_now_utc() { /* @@ -41,18 +41,17 @@ class Date_helper_test extends CI_TestCase { $config = $this->getMock('CI_Config'); $config->expects($this->any()) ->method('item') - ->will($this->returnValue('gmt')); + ->will($this->returnValue('UTC')); // Add the stub to our stdClass $this->ci_instance_var('config', $config); */ - $this->ci_set_config('time_reference', 'gmt'); + $this->ci_set_config('time_reference', 'UTC'); - $t = time(); $this->assertEquals( - mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), + gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), now() ); } -- cgit v1.2.3-24-g4f1b From 3ed533109309326a858c778dfea5cb9186f965b4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:21:07 +0300 Subject: Some optimizations to the date helper tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 242935116..1d397ac81 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -51,7 +51,7 @@ class Date_helper_test extends CI_TestCase { $this->ci_set_config('time_reference', 'UTC'); $this->assertEquals( - gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), + gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), now() ); } @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $this->assertEquals( - mktime( - gmdate('H', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), - gmdate('m', $this->time), gmdate('d', $this->time), gmdate('Y', $this->time) + gmmktime( + date('G', $this->time), date('i', $this->time), date('s', $this->time), + date('n', $this->time), date('j', $this->time), date('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From 3bbbd26ecb60966b07c597310ae241c432bce198 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:35:32 +0300 Subject: Some optimizations to the date helper --- system/helpers/date_helper.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index a5c46e47b..d5036f645 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -314,13 +314,13 @@ if ( ! function_exists('local_to_gmt')) $time = time(); } - return mktime( - gmdate('H', $time), - gmdate('i', $time), - gmdate('s', $time), - gmdate('m', $time), - gmdate('d', $time), - gmdate('Y', $time) + return gmmktime( + date('H', $time), + date('i', $time), + date('s', $time), + date('m', $time), + date('d', $time), + date('Y', $time) ); } } @@ -375,9 +375,7 @@ if ( ! function_exists('mysql_to_unix')) // since the formatting changed with MySQL 4.1 // YYYY-MM-DD HH:MM:SS - $time = str_replace('-', '', $time); - $time = str_replace(':', '', $time); - $time = str_replace(' ', '', $time); + $time = str_replace(array('-', ':', ' '), '', $time); // YYYYMMDDHHMMSS return mktime( -- cgit v1.2.3-24-g4f1b From 19c83f6ec6dd29b2ecbeba87801d275f4e247678 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 14:33:33 +0300 Subject: Add changelog entry for issue #1387 --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 06bfba887..7748f9b37 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -269,6 +269,7 @@ Bug fixes for 3.0 - Fixed a bug (#145) - compile_binds() failed when the bind marker was present in a literal string within the query. - Fixed a bug in protect_identifiers() where if passed along with the field names, operators got escaped as well. - Fixed a bug (#10) - :doc:`URI Library ` internal method _detect_uri() failed with paths containing a colon. +- Fixed a bug (#1387) - :doc:`Query Builder `'s from() method didn't escape table aliases. Version 2.1.1 ============= -- cgit v1.2.3-24-g4f1b