From 9a05d2b0d838bb000a89ab9ea78a307b557768e7 Mon Sep 17 00:00:00 2001 From: John Nicely Date: Thu, 24 Nov 2011 10:50:39 -0800 Subject: Changed form_open() to compare $action against base_url() Checking for strpos($action, $CI->config->site_url()) === FALSE causes CSRF token to not be added in form_open() output. When site_url()'s first parameter ($uri) is empty, site_url's return value is the base URL plus the $CI->config->item('index_page') value. form_open() and CodeIgniter's URI routing do not require index.php to be in the URL, so any call to form_open() in which the $action parameter does not have index.php will always return false for the strpos() call. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d9305c00b..8733ae053 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -65,7 +65,7 @@ if ( ! function_exists('form_open')) $form .= '>'; // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites - if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"'))) + if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) { $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } -- cgit v1.2.3-24-g4f1b From 5c1aa631c5f5ec2f6b75ba1158178418e50ba11a Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 25 Dec 2011 01:24:29 -0600 Subject: Abstracting the loading of files in the config directory depending on environments. --- system/helpers/download_helper.php | 9 +-------- system/helpers/file_helper.php | 9 +-------- system/helpers/html_helper.php | 9 +-------- system/helpers/smiley_helper.php | 9 +-------- system/helpers/text_helper.php | 9 +-------- 5 files changed, 5 insertions(+), 40 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 5f5d1aaf7..3173c9840 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,14 +70,7 @@ if ( ! function_exists('force_download')) $extension = end($x); // Load the mime types - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); - } - elseif (is_file(APPPATH.'config/mimes.php')) - { - include(APPPATH.'config/mimes.php'); - } + load_environ_config('mimes'); // Set a default mime if we can't find it if ( ! isset($mimes[$extension])) diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 5b5085381..b4edcdea4 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -364,14 +364,7 @@ if ( ! function_exists('get_mime_by_extension')) if ( ! is_array($mimes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); - } - elseif (is_file(APPPATH.'config/mimes.php')) - { - include(APPPATH.'config/mimes.php'); - } + load_environ_config('mimes'); if ( ! is_array($mimes)) { diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index b6bb402a8..fa805f14f 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -275,14 +275,7 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); - } - elseif (is_file(APPPATH.'config/doctypes.php')) - { - include(APPPATH.'config/doctypes.php'); - } + load_environ_config('doctypes'); if ( ! is_array($_doctypes)) { diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 38e2965fc..e04d5d611 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -241,14 +241,7 @@ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); - } - elseif (file_exists(APPPATH.'config/smileys.php')) - { - include(APPPATH.'config/smileys.php'); - } + load_environ_config('smileys'); if (isset($smileys) AND is_array($smileys)) { diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 38b46e248..7a4a68995 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -378,14 +378,7 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); - } - elseif (is_file(APPPATH.'config/foreign_chars.php')) - { - include(APPPATH.'config/foreign_chars.php'); - } + load_environ_config('foreign_chars'); if ( ! isset($foreign_characters)) { -- cgit v1.2.3-24-g4f1b From d96f88277c1e9a4c069c2e2ee3d779385549f31a Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 27 Dec 2011 16:23:47 -0600 Subject: Revert "Abstracting the loading of files in the config directory depending on environments." This reverts commit 5c1aa631c5f5ec2f6b75ba1158178418e50ba11a. --- system/helpers/download_helper.php | 9 ++++++++- system/helpers/file_helper.php | 9 ++++++++- system/helpers/html_helper.php | 9 ++++++++- system/helpers/smiley_helper.php | 9 ++++++++- system/helpers/text_helper.php | 9 ++++++++- 5 files changed, 40 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 3173c9840..5f5d1aaf7 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,7 +70,14 @@ if ( ! function_exists('force_download')) $extension = end($x); // Load the mime types - load_environ_config('mimes'); + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); + } + elseif (is_file(APPPATH.'config/mimes.php')) + { + include(APPPATH.'config/mimes.php'); + } // Set a default mime if we can't find it if ( ! isset($mimes[$extension])) diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index b4edcdea4..5b5085381 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -364,7 +364,14 @@ if ( ! function_exists('get_mime_by_extension')) if ( ! is_array($mimes)) { - load_environ_config('mimes'); + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); + } + elseif (is_file(APPPATH.'config/mimes.php')) + { + include(APPPATH.'config/mimes.php'); + } if ( ! is_array($mimes)) { diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index fa805f14f..b6bb402a8 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -275,7 +275,14 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - load_environ_config('doctypes'); + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); + } + elseif (is_file(APPPATH.'config/doctypes.php')) + { + include(APPPATH.'config/doctypes.php'); + } if ( ! is_array($_doctypes)) { diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index e04d5d611..38e2965fc 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -241,7 +241,14 @@ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - load_environ_config('smileys'); + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); + } + elseif (file_exists(APPPATH.'config/smileys.php')) + { + include(APPPATH.'config/smileys.php'); + } if (isset($smileys) AND is_array($smileys)) { diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 7a4a68995..38b46e248 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -378,7 +378,14 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - load_environ_config('foreign_chars'); + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); + } + elseif (is_file(APPPATH.'config/foreign_chars.php')) + { + include(APPPATH.'config/foreign_chars.php'); + } if ( ! isset($foreign_characters)) { -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/helpers/array_helper.php | 2 +- system/helpers/captcha_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/form_helper.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/inflector_helper.php | 2 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/path_helper.php | 2 +- system/helpers/security_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 2 +- system/helpers/xml_helper.php | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 6b8695c11..c46c4d103 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 0fed81996..668b034d4 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index a4c1e4966..7b439c47f 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 49dbdbeb3..9e58d8630 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index cb37446f8..be65b388d 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 5f5d1aaf7..4a1a79cc3 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 22099e58a..e6a9003e2 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 5b5085381..cc9dea22a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 347e8be90..3a7f8fe3e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index b6bb402a8..2a603a607 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 7c5082192..f093dd921 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index b5217c903..ed17bfa4c 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 71cdabb60..71d39df1f 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index bca9dcb25..da2b8d307 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index ad4e29a87..d64bd12e1 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 38e2965fc..700f4486c 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 6691681e0..04d51c2f9 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 38b46e248..842a31d75 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index b1cedcd9d..f81c46210 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 5d9afe457..c630ebea8 100755 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 0cf8f13dc..b38dab479 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 8bf6bb654da32626e9c3a4e40f9ca7ea464a9e19 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jan 2012 16:11:04 +0200 Subject: Improve email, file & form helpers --- system/helpers/email_helper.php | 11 +++--- system/helpers/file_helper.php | 72 ++++++++++++++++++--------------------- system/helpers/form_helper.php | 74 ++++++++++++++--------------------------- 3 files changed, 62 insertions(+), 95 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index e6a9003e2..f184031a9 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -1,13 +1,13 @@ -config->site_url($CI->uri->uri_string()); - $form = '
\n"; - $form .= '>'; - - // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites - if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"'))) + // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites + if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"'))) { $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } @@ -156,7 +152,7 @@ if ( ! function_exists('form_hidden')) if ( ! is_array($value)) { - $form .= ''."\n"; + $form .= '\n"; } else { @@ -188,7 +184,7 @@ if ( ! function_exists('form_input')) { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return '\n"; } } @@ -274,7 +270,7 @@ if ( ! function_exists('form_textarea')) } $name = (is_array($data)) ? $data['name'] : $data; - return ""; + return '\n"; } } @@ -325,13 +321,9 @@ if ( ! function_exists('form_dropdown')) } // If no selected state was submitted we will attempt to set it automatically - if (count($selected) === 0) + if (count($selected) === 0 && isset($_POST[$name])) { - // If the form name appears in the $_POST array we have a winner! - if (isset($_POST[$name])) - { - $selected = array($_POST[$name]); - } + $selected = array($_POST[$name]); } if ($extra != '') $extra = ' '.$extra; @@ -346,12 +338,11 @@ if ( ! function_exists('form_dropdown')) if (is_array($val) && ! empty($val)) { - $form .= ''."\n"; + $form .= '\n"; foreach ($val as $optgroup_key => $optgroup_val) { $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; - $form .= '\n"; } @@ -359,13 +350,11 @@ if ( ! function_exists('form_dropdown')) } else { - $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; - - $form .= '\n"; + $form .= '\n"; } } - $form .= ''; + $form .= "\n"; return $form; } @@ -412,7 +401,7 @@ if ( ! function_exists('form_checkbox')) unset($defaults['checked']); } - return ""; + return '\n"; } } @@ -458,8 +447,7 @@ if ( ! function_exists('form_submit')) function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; + return '\n"; } } @@ -479,8 +467,7 @@ if ( ! function_exists('form_reset')) function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; + return '\n"; } } @@ -500,14 +487,13 @@ if ( ! function_exists('form_button')) function form_button($data = '', $content = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button'); - if ( is_array($data) AND isset($data['content'])) { $content = $data['content']; unset($data['content']); // content is not an attribute } - return ""; + return '\n"; } } @@ -542,9 +528,7 @@ if ( ! function_exists('form_label')) } } - $label .= ">$label_text"; - - return $label; + return $label .= ">$label_text"; } } @@ -564,12 +548,7 @@ if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) { - $fieldset = "\n"; if ($legend_text != '') { $fieldset .= "$legend_text\n"; @@ -654,15 +633,13 @@ if ( ! function_exists('form_prep')) { return $str; } - - $str = html_escape($str); if ($field_name != '') { $prepped_fields[$field_name] = $field_name; } - return $str; + return html_escape($str); } } @@ -992,7 +969,7 @@ if ( ! function_exists('_attributes_to_string')) $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; } - return ' '.$attributes; + return ' '.$attributes; } if (is_object($attributes) AND count($attributes) > 0) @@ -1043,21 +1020,20 @@ if ( ! function_exists('_get_validation_object')) // We set this as a variable since we're returning by reference. $return = FALSE; - + if (FALSE !== ($object = $CI->load->is_loaded('form_validation'))) { if ( ! isset($CI->$object) OR ! is_object($CI->$object)) { return $return; } - + return $CI->$object; } - + return $return; } } - /* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ -- cgit v1.2.3-24-g4f1b From 1e6b72cca80354619cf7ddceb2b5f23d37b972e9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jan 2012 19:09:22 +0200 Subject: Improve html, inflector & language helpers --- system/helpers/html_helper.php | 70 +++++++++++++------------------------ system/helpers/inflector_helper.php | 30 +++------------- system/helpers/language_helper.php | 9 +++-- 3 files changed, 33 insertions(+), 76 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 2a603a607..72970d9ca 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -1,13 +1,13 @@ -".$data.""; + return ''.$data.''; } } @@ -124,7 +123,7 @@ if ( ! function_exists('_list')) } // Set the indentation based on the depth - $out = str_repeat(" ", $depth); + $out = str_repeat(' ', $depth); // Were any attributes submitted? If so generate a string if (is_array($attributes)) @@ -142,7 +141,7 @@ if ( ! function_exists('_list')) } // Write the opening list tag - $out .= "<".$type.$attributes.">\n"; + $out .= '<'.$type.$attributes.">\n"; // Cycle through the list elements. If an array is // encountered we will recursively call _list() @@ -152,8 +151,7 @@ if ( ! function_exists('_list')) { $_last_list_item = $key; - $out .= str_repeat(" ", $depth + 2); - $out .= "
  • "; + $out .= str_repeat(' ', $depth + 2).'
  • '; if ( ! is_array($val)) { @@ -161,21 +159,14 @@ if ( ! function_exists('_list')) } else { - $out .= $_last_list_item."\n"; - $out .= _list($type, $val, '', $depth + 4); - $out .= str_repeat(" ", $depth + 2); + $out .= $_last_list_item."\n"._list($type, $val, '', $depth + 4).str_repeat(' ', $depth + 2); } $out .= "
  • \n"; } - // Set the indentation for the closing tag - $out .= str_repeat(" ", $depth); - - // Write the closing list tag - $out .= "\n"; - - return $out; + // Set the indentation for the closing tag and apply it + return $out.str_repeat(' ', $depth).'\n"; } } @@ -192,7 +183,7 @@ if ( ! function_exists('br')) { function br($num = 1) { - return str_repeat("
    ", $num); + return str_repeat('
    ', $num); } } @@ -224,10 +215,9 @@ if ( ! function_exists('img')) $img = '$v) + foreach ($src as $k => $v) { - - if ($k == 'src' AND strpos($v, '://') === FALSE) + if ($k === 'src' AND strpos($v, '://') === FALSE) { $CI =& get_instance(); @@ -246,9 +236,7 @@ if ( ! function_exists('img')) } } - $img .= '/>'; - - return $img; + return $img.'/>'; } } @@ -290,14 +278,7 @@ if ( ! function_exists('doctype')) } } - if (isset($_doctypes[$type])) - { - return $_doctypes[$type]; - } - else - { - return FALSE; - } + return (isset($_doctypes[$type])) ? $_doctypes[$type] : FALSE; } } @@ -322,14 +303,13 @@ if ( ! function_exists('link_tag')) function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) { $CI =& get_instance(); - $link = '$v) + foreach ($href as $k => $v) { - if ($k == 'href' AND strpos($v, '://') === FALSE) + if ($k === 'href' AND strpos($v, '://') === FALSE) { if ($index_page === TRUE) { @@ -346,11 +326,11 @@ if ( ! function_exists('link_tag')) } } - $link .= "/>"; + $link .= '/>'; } else { - if ( strpos($href, '://') !== FALSE) + if (strpos($href, '://') !== FALSE) { $link .= 'href="'.$href.'" '; } @@ -365,21 +345,20 @@ if ( ! function_exists('link_tag')) $link .= 'rel="'.$rel.'" type="'.$type.'" '; - if ($media != '') + if ($media != '') { $link .= 'media="'.$media.'" '; } - if ($title != '') + if ($title != '') { $link .= 'title="'.$title.'" '; } $link .= '/>'; } - $link .= "\n"; - return $link; + return $link."\n"; } } @@ -439,10 +418,9 @@ if ( ! function_exists('nbs')) { function nbs($num = 1) { - return str_repeat(" ", $num); + return str_repeat(' ', $num); } } - /* End of file html_helper.php */ -/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/html_helper.php */ diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index f093dd921..0bd1e112f 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,4 +1,4 @@ - '\1', ); - foreach ($singular_rules as $rule => $replacement) - { - if (preg_match($rule, $result)) - { - $result = preg_replace($rule, $replacement, $result); - break; - } - } - - return $result; + return preg_replace(array_keys($singular_values), $singular_values, $result); } } @@ -138,16 +129,7 @@ if ( ! function_exists('plural')) '/$/' => 's', ); - foreach ($plural_rules as $rule => $replacement) - { - if (preg_match($rule, $result)) - { - $result = preg_replace($rule, $replacement, $result); - break; - } - } - - return $result; + return preg_replace(array_keys($plural_rules), $plural_rules, $result); } } @@ -166,9 +148,7 @@ if ( ! function_exists('camelize')) { function camelize($str) { - $str = 'x'.strtolower(trim($str)); - $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); - return substr(str_replace(' ', '', $str), 1); + return substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1); } } @@ -212,4 +192,4 @@ if ( ! function_exists('humanize')) } /* End of file inflector_helper.php */ -/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/inflector_helper.php */ diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index ed17bfa4c..a83580a97 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -1,13 +1,13 @@ - Date: Fri, 6 Jan 2012 19:19:37 +0200 Subject: Improve number, path & security helpers --- system/helpers/number_helper.php | 9 ++++----- system/helpers/path_helper.php | 20 ++++++++------------ system/helpers/security_helper.php | 23 ++++++----------------- 3 files changed, 18 insertions(+), 34 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 71d39df1f..331b468c6 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -1,13 +1,13 @@ -#", "\\1", $str); - $str = preg_replace("##", "\\1", $str); - - return $str; + return preg_replace(array("##", "##"), "\\1", $str); } } @@ -135,6 +125,5 @@ if ( ! function_exists('encode_php_tags')) } } - /* End of file security_helper.php */ -/* Location: ./system/helpers/security_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/security_helper.php */ -- cgit v1.2.3-24-g4f1b From debcc3676083eca34f89d00e6197e9892f77c0e2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Jan 2012 02:05:29 +0200 Subject: Improve typography, url & xml helpers --- system/helpers/typography_helper.php | 10 +-- system/helpers/url_helper.php | 130 ++++++++++++++++------------------- system/helpers/xml_helper.php | 26 ++++--- 3 files changed, 78 insertions(+), 88 deletions(-) mode change 100755 => 100644 system/helpers/url_helper.php (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index f81c46210..c49348e6a 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,13 +1,13 @@ -'.$title.''; + return ''.$title.''; } } @@ -278,19 +275,16 @@ if ( ! function_exists('safe_mailto')) { $title = (string) $title; - if ($title == "") + if ($title == '') { $title = $email; } - for ($i = 0; $i < 16; $i++) - { - $x[] = substr(' $val) { $x[] = ' '.$key.'="'; - for ($i = 0; $i < strlen($val); $i++) + for ($i = 0, $l = strlen($val); $i < $l; $i++) { - $x[] = "|".ord(substr($val, $i, 1)); + $x[] = '|'.ord($val[$i]); } $x[] = '"'; } } else { - for ($i = 0; $i < strlen($attributes); $i++) + for ($i = 0, $l = strlen($attributes); $i < $l; $i++) { - $x[] = substr($attributes, $i, 1); + $x[] = $attributes[$i]; } } } @@ -321,26 +315,28 @@ if ( ! function_exists('safe_mailto')) $x[] = '>'; $temp = array(); - for ($i = 0; $i < strlen($title); $i++) + for ($i = 0, $l = strlen($title); $i < $l; $i++) { $ordinal = ord($title[$i]); if ($ordinal < 128) { - $x[] = "|".$ordinal; + $x[] = '|'.$ordinal; } else { - if (count($temp) == 0) + if (count($temp) === 0) { $count = ($ordinal < 224) ? 2 : 3; } $temp[] = $ordinal; - if (count($temp) == $count) + if (count($temp) === $count) { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - $x[] = "|".$number; + $number = ($count === 3) + ? (($temp[0] % 16) * 4096) + (($temp[1] % 64) * 64) + ($temp[2] % 64) + : (($temp[0] % 32) * 64) + ($temp[1] % 64); + $x[] = '|'.$number; $count = 1; $temp = array(); } @@ -356,8 +352,7 @@ if ( ! function_exists('safe_mailto')) //l[]=''; + for ($i = 0, $c = count($x); $i < $c; $i++) { ?>l[]=''; for (var i = l.length-1; i >= 0; i=i-1){ if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";"); @@ -391,49 +386,46 @@ if ( ! function_exists('auto_link')) { function auto_link($str, $type = 'both', $popup = FALSE) { - if ($type != 'email') + if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches)) { - if (preg_match_all("#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)) - { - $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; + $pop = ($popup) ? ' target="_blank" ' : ''; - for ($i = 0; $i < count($matches['0']); $i++) + for ($i = 0, $c = count($matches[0]); $i < $c; $i++) + { + if (preg_match('|\.$|', $matches[6][$i])) + { + $period = '.'; + $matches[6][$i] = substr($matches[6][$i], 0, -1); + } + else { $period = ''; - if (preg_match("|\.$|", $matches['6'][$i])) - { - $period = '.'; - $matches['6'][$i] = substr($matches['6'][$i], 0, -1); - } - - $str = str_replace($matches['0'][$i], - $matches['1'][$i].'http'. - $matches['4'][$i].'://'. - $matches['5'][$i]. - $matches['6'][$i].''. - $period, $str); } + + $str = str_replace($matches[0][$i], + $matches[1][$i].'http' + .$matches[4][$i].'://'.$matches[5][$i] + .$matches[6][$i].''.$period, + $str); } } - if ($type != 'url') + if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i', $str, $matches)) { - if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) + for ($i = 0, $c = count($matches); $i < $c; $i++) { - for ($i = 0; $i < count($matches['0']); $i++) + if (preg_match('|\.$|', $matches[3][$i])) + { + $period = '.'; + $matches[3][$i] = substr($matches[3][$i], 0, -1); + } + else { $period = ''; - if (preg_match("|\.$|", $matches['3'][$i])) - { - $period = '.'; - $matches['3'][$i] = substr($matches['3'][$i], 0, -1); - } - - $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); } + + $str = str_replace($matches[0][$i], safe_mailto($matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]).$period, $str); } } @@ -456,7 +448,7 @@ if ( ! function_exists('prep_url')) { function prep_url($str = '') { - if ($str == 'http://' OR $str == '') + if ($str === 'http://' OR $str == '') { return ''; } @@ -465,7 +457,7 @@ if ( ! function_exists('prep_url')) if ( ! $url OR ! isset($url['scheme'])) { - $str = 'http://'.$str; + return 'http://'.$str; } return $str; @@ -490,7 +482,7 @@ if ( ! function_exists('url_title')) { function url_title($str, $separator = 'dash', $lowercase = FALSE) { - if ($separator == 'dash') + if ($separator === 'dash') { $search = '_'; $replace = '-'; @@ -513,10 +505,9 @@ if ( ! function_exists('url_title')) ); $str = strip_tags($str); - foreach ($trans as $key => $val) { - $str = preg_replace("#".$key."#i", $val, $str); + $str = preg_replace('#'.$key.'#i', $val, $str); } if ($lowercase === TRUE) @@ -552,16 +543,18 @@ if ( ! function_exists('redirect')) } // IIS environment likely? Use 'refresh' for better compatibility - if (DIRECTORY_SEPARATOR != '/' && $method == 'auto') + if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto') { $method = 'refresh'; } switch($method) { - case 'refresh' : header("Refresh:0;url=".$uri); + case 'refresh': + header('Refresh:0;url='.$uri); break; - default : header("Location: ".$uri, TRUE, $http_response_code); + default: + header('Location: '.$uri, TRUE, $http_response_code); break; } exit; @@ -604,13 +597,12 @@ if ( ! function_exists('_parse_attributes')) if ($javascript == TRUE AND $att != '') { - $att = substr($att, 0, -1); + return substr($att, 0, -1); } return $att; } } - /* End of file url_helper.php */ -/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/url_helper.php */ diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index b38dab479..5242193ac 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,13 +1,13 @@ -","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); + $str = str_replace(array('&', '<', '>', '"', "'", '-'), + array('&', '<', '>', '"', ''', '-'), + $str); // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace('/$temp(\d+);/', '&#\\1;', $str); - if ($protect_all === TRUE) + if ($protect_all == TRUE) { - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + return preg_replace("/$temp(\w+);/", '&\\1;', $str); } return $str; } } -// ------------------------------------------------------------------------ - /* End of file xml_helper.php */ -/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/xml_helper.php */ -- cgit v1.2.3-24-g4f1b From 3b8ad8f6c300b4cec6901e5053495f93e104d267 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 10 Jan 2012 18:09:07 +0200 Subject: Fix a bug in the File helper --- system/helpers/file_helper.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 9b39b8c20..2d4b10e37 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -196,16 +196,16 @@ if ( ! function_exists('get_filenames')) while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) + if (@is_dir($source_dir.$file) && $file[0] !== '.') { get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } - elseif (strncmp($file, '.', 1) !== 0) + elseif ($file[0] !== '.') { $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; } } - closedir($source_dir); + closedir($fp); return $_filedata; } @@ -249,17 +249,17 @@ if ( ! function_exists('get_dir_file_info')) // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) + if (@is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE) { get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); } - elseif (strncmp($file, '.', 1) !== 0) + elseif ($file[0] !== '.') { $_filedata[$file] = get_file_info($source_dir.$file); $_filedata[$file]['relative_path'] = $relative_path; } } - closedir($source_dir); + closedir($fp); return $_filedata; } @@ -359,7 +359,7 @@ if ( ! function_exists('get_mime_by_extension')) if ( ! is_array($mimes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); } -- cgit v1.2.3-24-g4f1b From c357f5ecb0794fc59802ab7a9779453ee2b003c7 Mon Sep 17 00:00:00 2001 From: Wilbur Suero Date: Tue, 17 Jan 2012 00:17:35 -0400 Subject: Fixed error in inflector_helper.php in the singular function. The function was excepting $singluar_rules and got $singular_values. --- system/helpers/inflector_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 0bd1e112f..2069a1927 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -85,7 +85,7 @@ if ( ! function_exists('singular')) '/([^u])s$/' => '\1', ); - return preg_replace(array_keys($singular_values), $singular_values, $result); + return preg_replace(array_keys($singular_rules), $singular_rules, $result); } } -- cgit v1.2.3-24-g4f1b From 0e4d2b652ec4b0027b188a7aa84a9862b968f780 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Mon, 23 Jan 2012 18:19:20 -0600 Subject: Fix bug #195 Fixes bug #195 regarding non-existent user agent strings when using force_download() helper. --- system/helpers/download_helper.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 4a1a79cc3..aea948d81 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -88,26 +88,20 @@ if ( ! function_exists('force_download')) { $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } - + // Generate the server headers - if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) + header('Content-Type: "'.$mime.'"'); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header('Expires: 0'); + header("Content-Transfer-Encoding: binary"); + header("Content-Length: ".strlen($data)); + header('Pragma: no-cache'); + + // Internet Explorer-specific headers. + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { - header('Content-Type: "'.$mime.'"'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); header('Pragma: public'); - header("Content-Length: ".strlen($data)); - } - else - { - header('Content-Type: "'.$mime.'"'); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - header("Content-Length: ".strlen($data)); } exit($data); -- cgit v1.2.3-24-g4f1b From b38c5dd95644ed73166df34084041cee0efd7d23 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 29 Feb 2012 14:07:45 +0200 Subject: Add an optional set_mime parameter to force_download() --- system/helpers/download_helper.php | 80 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 39 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index aea948d81..34380cc88 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -1,13 +1,13 @@ - Date: Wed, 29 Feb 2012 12:12:49 +0000 Subject: Improved plural() and singular(). Avoids double-pluralization using "uncountable words" and better logic. --- system/helpers/inflector_helper.php | 152 +++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 56 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 2069a1927..02c425b8a 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -34,7 +34,7 @@ * @subpackage Helpers * @category Helpers * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/helpers/directory_helper.html + * @link http://codeigniter.com/user_guide/helpers/inflector_helper.html */ @@ -45,7 +45,6 @@ * * Takes a plural word and makes it singular * - * @access public * @param string * @return str */ @@ -55,37 +54,51 @@ if ( ! function_exists('singular')) { $result = strval($str); + if ( ! is_countable($result)) + { + return $result; + } + $singular_rules = array( - '/(matr)ices$/' => '\1ix', - '/(vert|ind)ices$/' => '\1ex', - '/^(ox)en/' => '\1', - '/(alias)es$/' => '\1', - '/([octop|vir])i$/' => '\1us', - '/(cris|ax|test)es$/' => '\1is', - '/(shoe)s$/' => '\1', - '/(o)es$/' => '\1', - '/(bus|campus)es$/' => '\1', - '/([m|l])ice$/' => '\1ouse', - '/(x|ch|ss|sh)es$/' => '\1', - '/(m)ovies$/' => '\1\2ovie', - '/(s)eries$/' => '\1\2eries', - '/([^aeiouy]|qu)ies$/' => '\1y', - '/([lr])ves$/' => '\1f', - '/(tive)s$/' => '\1', - '/(hive)s$/' => '\1', - '/([^f])ves$/' => '\1fe', - '/(^analy)ses$/' => '\1sis', + '/(matr)ices$/' => '\1ix', + '/(vert|ind)ices$/' => '\1ex', + '/^(ox)en/' => '\1', + '/(alias)es$/' => '\1', + '/([octop|vir])i$/' => '\1us', + '/(cris|ax|test)es$/' => '\1is', + '/(shoe)s$/' => '\1', + '/(o)es$/' => '\1', + '/(bus|campus)es$/' => '\1', + '/([m|l])ice$/' => '\1ouse', + '/(x|ch|ss|sh)es$/' => '\1', + '/(m)ovies$/' => '\1\2ovie', + '/(s)eries$/' => '\1\2eries', + '/([^aeiouy]|qu)ies$/' => '\1y', + '/([lr])ves$/' => '\1f', + '/(tive)s$/' => '\1', + '/(hive)s$/' => '\1', + '/([^f])ves$/' => '\1fe', + '/(^analy)ses$/' => '\1sis', '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis', - '/([ti])a$/' => '\1um', - '/(p)eople$/' => '\1\2erson', - '/(m)en$/' => '\1an', - '/(s)tatuses$/' => '\1\2tatus', - '/(c)hildren$/' => '\1\2hild', - '/(n)ews$/' => '\1\2ews', - '/([^u])s$/' => '\1', + '/([ti])a$/' => '\1um', + '/(p)eople$/' => '\1\2erson', + '/(m)en$/' => '\1an', + '/(s)tatuses$/' => '\1\2tatus', + '/(c)hildren$/' => '\1\2hild', + '/(n)ews$/' => '\1\2ews', + '/([^us])s$/' => '\1', ); - return preg_replace(array_keys($singular_rules), $singular_rules, $result); + foreach ($singular_rules as $rule => $replacement) + { + if (preg_match($rule, $result)) + { + $result = preg_replace($rule, $replacement, $result); + break; + } + } + + return $result; } } @@ -96,7 +109,6 @@ if ( ! function_exists('singular')) * * Takes a singular word and makes it plural * - * @access public * @param string * @param bool * @return str @@ -104,32 +116,46 @@ if ( ! function_exists('singular')) if ( ! function_exists('plural')) { function plural($str, $force = FALSE) - { + { $result = strval($str); + if ( ! is_countable($result)) + { + return $result; + } + $plural_rules = array( - '/^(ox)$/' => '\1\2en', // ox - '/([m|l])ouse$/' => '\1ice', // mouse, louse - '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index - '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address - '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency - '/(hive)$/' => '\1s', // archive, hive - '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife - '/sis$/' => 'ses', // basis, diagnosis - '/([ti])um$/' => '\1a', // datum, medium - '/(p)erson$/' => '\1eople', // person, salesperson - '/(m)an$/' => '\1en', // man, woman, spokesman - '/(c)hild$/' => '\1hildren', // child - '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato - '/(bu|campu)s$/' => '\1\2ses', // bus, campus - '/(alias|status|virus)/' => '\1es', // alias - '/(octop)us$/' => '\1i', // octopus - '/(ax|cris|test)is$/' => '\1es', // axis, crisis - '/s$/' => 's', // no change (compatibility) - '/$/' => 's', + '/^(ox)$/' => '\1\2en', // ox + '/([m|l])ouse$/' => '\1ice', // mouse, louse + '/(matr|vert|ind)ix|ex$/' => '\1ices', // matrix, vertex, index + '/(x|ch|ss|sh)$/' => '\1es', // search, switch, fix, box, process, address + '/([^aeiouy]|qu)y$/' => '\1ies', // query, ability, agency + '/(hive)$/' => '\1s', // archive, hive + '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', // half, safe, wife + '/sis$/' => 'ses', // basis, diagnosis + '/([ti])um$/' => '\1a', // datum, medium + '/(p)erson$/' => '\1eople', // person, salesperson + '/(m)an$/' => '\1en', // man, woman, spokesman + '/(c)hild$/' => '\1hildren', // child + '/(buffal|tomat)o$/' => '\1\2oes', // buffalo, tomato + '/(bu|campu)s$/' => '\1\2ses', // bus, campus + '/(alias|status|virus)$/' => '\1es', // alias + '/(octop)us$/' => '\1i', // octopus + '/(ax|cris|test)is$/' => '\1es', // axis, crisis + '/s$/' => 's', // no change (compatibility) + '/$/' => 's', ); - - return preg_replace(array_keys($plural_rules), $plural_rules, $result); + + foreach ($plural_rules as $rule => $replacement) + { + if (preg_match($rule, $result)) + { + $result = preg_replace($rule, $replacement, $result); + break; + } + } + + return $result; } } @@ -140,7 +166,6 @@ if ( ! function_exists('plural')) * * Takes multiple words separated by spaces or underscores and camelizes them * - * @access public * @param string * @return str */ @@ -159,7 +184,6 @@ if ( ! function_exists('camelize')) * * Takes multiple words separated by spaces and underscores them * - * @access public * @param string * @return str */ @@ -178,7 +202,6 @@ if ( ! function_exists('underscore')) * * Takes multiple words separated by the separator and changes them to spaces * - * @access public * @param string $str * @param string $separator * @return str @@ -191,5 +214,22 @@ if ( ! function_exists('humanize')) } } +/** + * Checks if the given word has a plural version. + * + * @param string the word to check + * @return bool if the word is countable + */ +if ( ! function_exists('is_countable')) +{ + function is_countable($word) + { + return ! (in_array(strtolower(strval($word)), array( + 'equipment', 'information', 'rice', 'money', + 'species', 'series', 'fish', 'meta' + ))); + } +} + /* End of file inflector_helper.php */ -/* Location: ./system/helpers/inflector_helper.php */ +/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From db0c06247949a4def38bcb0c0cf1239312140a81 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 29 Feb 2012 19:02:46 +0200 Subject: Change end() usage due to E_STRICT messages --- system/helpers/download_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 34380cc88..a8c59c2c0 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,7 +70,8 @@ if ( ! function_exists('force_download')) return FALSE; } - $extension = end(explode('.', $filename)); + $extension = explode('.', $filename); + $extension = end($extension); // Load the mime types if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) -- cgit v1.2.3-24-g4f1b From 8edf87dbb0dcbe61e8cbaa6229c70a46bee6dbd4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 20:20:03 +0200 Subject: Remove a PHP_VERSION < 5 check (no longer needed) --- system/helpers/text_helper.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 842a31d75..6e9ea570f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -300,9 +300,9 @@ if ( ! function_exists('highlight_code')) // Replace any existing PHP tags to temporary markers so they don't accidentally // break the string out of PHP, and thus, thwart the highlighting. - $str = str_replace(array('', '<%', '%>', '\\', ''), - array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); + array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + $str); // The highlight_string function requires that the text be surrounded // by PHP tags, which we will remove later @@ -311,25 +311,15 @@ if ( ! function_exists('highlight_code')) // All the magic happens here, baby! $str = highlight_string($str, TRUE); - // Prior to PHP 5, the highligh function used icky tags - // so we'll replace them with tags. - - if (abs(PHP_VERSION) < 5) - { - $str = str_replace(array(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } - // Remove our artificially added PHP, and the syntax highlighting that came with it $str = preg_replace('/<\?php( | )/i', '', $str); $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); $str = preg_replace('/<\/span>/i', '', $str); // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), - array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - - return $str; + return str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + array('<?', '?>', '<%', '%>', '\\', '</script>'), + $str); } } @@ -544,4 +534,4 @@ if ( ! function_exists('ellipsize')) } /* End of file text_helper.php */ -/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/text_helper.php */ -- cgit v1.2.3-24-g4f1b From 3edd88eee84886fc6ba3e1fc25beda3c424370bc Mon Sep 17 00:00:00 2001 From: tubalmartin Date: Sat, 3 Mar 2012 22:10:34 +0100 Subject: An even better url_title helper. Tests: http://codepad.org/tuJgvkyN Changelog entry added for 2.1.1 --- system/helpers/url_helper.php | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 9f4b85248..cdb6dae9c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -478,27 +478,14 @@ if ( ! function_exists('url_title')) { function url_title($str, $separator = 'dash', $lowercase = FALSE) { - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else - { - $search = '-'; - $replace = '_'; - } + $replace = $separator == 'dash' ? '-' : '_'; $trans = array( - '&\#\d+?;' => '', - '&\S+?;' => '', - '\s+' => $replace, - '[^a-z0-9\-\._]' => '', - $replace.'+' => $replace, - $replace.'$' => $replace, - '^'.$replace => $replace, - '\.+$' => '' - ); + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $replace, + $replace.'+' => $replace + ); $str = strip_tags($str); @@ -512,7 +499,7 @@ if ( ! function_exists('url_title')) $str = strtolower($str); } - return trim(stripslashes($str)); + return trim($str, $replace); } } -- cgit v1.2.3-24-g4f1b From f8f04ce990a46f1967cd58def4929c476f4595a5 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sun, 4 Mar 2012 14:21:12 +0000 Subject: Fixed conflicts. --- system/helpers/form_helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index bed2cb297..6efef2324 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -22,7 +22,6 @@ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 - * @filesource */ // ------------------------------------------------------------------------ @@ -72,8 +71,8 @@ if ( ! function_exists('form_open')) $form = '\n"; - // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites - if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"'))) + // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites + if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) { $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } -- cgit v1.2.3-24-g4f1b From 1a6971030718e2e92e6fc80750f7a14faf035257 Mon Sep 17 00:00:00 2001 From: tubalmartin Date: Sun, 4 Mar 2012 16:01:11 +0100 Subject: Allow developers to use any string as a separator, not just dashes or underscores. Backwards compatible when using 'dash' or 'underscore' as string separator. Tests: http://codepad.org/DWcxVH5r --- system/helpers/url_helper.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index cdb6dae9c..f1e8c6ac6 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -466,25 +466,34 @@ if ( ! function_exists('prep_url')) * Create URL Title * * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. + * human-friendly URL string with a "separator" string + * as the word separator. * * @access public * @param string the string - * @param string the separator: dash, or underscore + * @param string the separator * @return string */ if ( ! function_exists('url_title')) { - function url_title($str, $separator = 'dash', $lowercase = FALSE) + function url_title($str, $separator = '-', $lowercase = FALSE) { - $replace = $separator == 'dash' ? '-' : '_'; + if ($separator == 'dash') + { + $separator = '-'; + } + else if ($separator == 'underscore') + { + $separator = '_'; + } + + $q_separator = preg_quote($separator); $trans = array( - '&.+?;' => '', - '[^a-z0-9 _-]' => '', - '\s+' => $replace, - $replace.'+' => $replace + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $separator, + '('.$q_separator.')+' => $separator ); $str = strip_tags($str); @@ -499,7 +508,7 @@ if ( ! function_exists('url_title')) $str = strtolower($str); } - return trim($str, $replace); + return trim($str, $separator); } } -- cgit v1.2.3-24-g4f1b