From b312d2f18e24ad980e647884e1bae6c26ceb82d8 Mon Sep 17 00:00:00 2001 From: Mohammad Javad Naderi Date: Thu, 22 Aug 2013 13:23:15 +0430 Subject: character_limiter now works correct for UTF-8 strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strlen() doesn't return the actual length for unicode strings. For example strlen('سلام') returns 8, but length of سلام is 4. strlen(utf8_decode('سلام')) returns correct value 4. Reference: http://www.php.net/manual/de/function.strlen.php#45407 --- system/helpers/text_helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b2351db95..4ddf648cb 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -85,7 +85,7 @@ if ( ! function_exists('character_limiter')) */ function character_limiter($str, $n = 500, $end_char = '…') { - if (strlen($str) < $n) + if (strlen(utf8_decode($str)) < $n) { return $str; } @@ -93,7 +93,7 @@ if ( ! function_exists('character_limiter')) // a bit complicated, but faster than preg_replace with \s+ $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); - if (strlen($str) <= $n) + if (strlen(utf8_decode($str)) <= $n) { return $str; } @@ -103,10 +103,10 @@ if ( ! function_exists('character_limiter')) { $out .= $val.' '; - if (strlen($out) >= $n) + if (strlen(utf8_decode($out)) >= $n) { $out = trim($out); - return (strlen($out) === strlen($str)) ? $out : $out.$end_char; + return (strlen(utf8_decode($out)) === strlen(utf8_decode($str))) ? $out : $out.$end_char; } } } @@ -537,4 +537,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 9aebeaf6efa69a63c1518f1c7b0886e510909d29 Mon Sep 17 00:00:00 2001 From: Mohammad Javad Naderi Date: Thu, 22 Aug 2013 16:25:55 +0430 Subject: remove newline from end of file --- system/helpers/text_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 4ddf648cb..8dae3be4e 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -537,4 +537,4 @@ if ( ! function_exists('ellipsize')) } /* End of file text_helper.php */ -/* Location: ./system/helpers/text_helper.php */ +/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c6f5ed16c6a4a146deb40870781442d0936ac33a Mon Sep 17 00:00:00 2001 From: Mohammad Javad Naderi Date: Thu, 22 Aug 2013 18:33:50 +0430 Subject: count number of characters (with mb_strlen) instead of counting number of bytes with strlen --- system/helpers/text_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8dae3be4e..bfbdc2f00 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -85,7 +85,7 @@ if ( ! function_exists('character_limiter')) */ function character_limiter($str, $n = 500, $end_char = '…') { - if (strlen(utf8_decode($str)) < $n) + if (mb_strlen($str) < $n) { return $str; } @@ -93,7 +93,7 @@ if ( ! function_exists('character_limiter')) // a bit complicated, but faster than preg_replace with \s+ $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); - if (strlen(utf8_decode($str)) <= $n) + if (mb_strlen($str) <= $n) { return $str; } @@ -103,10 +103,10 @@ if ( ! function_exists('character_limiter')) { $out .= $val.' '; - if (strlen(utf8_decode($out)) >= $n) + if (mb_strlen($out) >= $n) { $out = trim($out); - return (strlen(utf8_decode($out)) === strlen(utf8_decode($str))) ? $out : $out.$end_char; + return (mb_strlen($out) === mb_strlen($str)) ? $out : $out.$end_char; } } } -- cgit v1.2.3-24-g4f1b From 8e7cc7a18086ad32c8e13525b643aadde054bf40 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Fri, 4 Oct 2013 02:45:28 +0300 Subject: parse $extra attributes in form_dropdown. --- system/helpers/form_helper.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 0cc5bd157..85f1f4e01 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -328,11 +328,8 @@ if ( ! function_exists('form_dropdown')) { $selected = array($_POST[$name]); } - - if ($extra != '') - { - $extra = ' '.$extra; - } + + $extra = _attributes_to_string($extra); $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; -- cgit v1.2.3-24-g4f1b From 3a3d5f6c2320a90436de241af41fe22df7344728 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 17 Oct 2013 22:22:16 +0200 Subject: Replace the last rand() with mt_rand() Better entropy, faster. Also fixed a few "it's" typos. --- system/helpers/captcha_helper.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 29911dc17..ea46f97b3 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -126,9 +126,9 @@ if ( ! function_exists('create_captcha')) // Determine angle and position // ----------------------------------- $length = strlen($word); - $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; - $x_axis = rand(6, (360/$length)-16); - $y_axis = ($angle >= 0) ? rand($img_height, $img_width) : rand(6, $img_height); + $angle = ($length >= 6) ? mt_rand(-($length-6), ($length-6)) : 0; + $x_axis = mt_rand(6, (360/$length)-16); + $y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height); // Create image // PHP.net recommends imagecreatetruecolor(), but it isn't always available @@ -183,13 +183,13 @@ if ( ! function_exists('create_captcha')) if ($use_font === FALSE) { $font_size = 5; - $x = rand(0, $img_width / ($length / 3)); + $x = mt_rand(0, $img_width / ($length / 3)); $y = 0; } else { $font_size = 16; - $x = rand(0, $img_width / ($length / 1.5)); + $x = mt_rand(0, $img_width / ($length / 1.5)); $y = $font_size + 2; } @@ -197,13 +197,13 @@ if ( ! function_exists('create_captcha')) { if ($use_font === FALSE) { - $y = rand(0 , $img_height / 2); + $y = mt_rand(0 , $img_height / 2); imagestring($im, $font_size, $x, $y, $word[$i], $colors['text']); $x += ($font_size * 2); } else { - $y = rand($img_height / 2, $img_height - 3); + $y = mt_rand($img_height / 2, $img_height - 3); imagettftext($im, $font_size, $angle, $x, $y, $colors['text'], $font_path, $word[$i]); $x += $font_size; } -- cgit v1.2.3-24-g4f1b From 7f5f8aaa01764f266b41791568863ec6bfda7e83 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 21 Oct 2013 14:37:40 +0300 Subject: Manually apply PR #2656 Fixes an 'Array to string conversion' notice in form_dropdown() --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 85f1f4e01..400a91faa 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -316,7 +316,7 @@ if ( ! function_exists('form_dropdown')) { isset($name['options']) OR $name['options'] = array(); isset($name['selected']) OR $name['selected'] = array(); - isset($name['extra']) OR $name['extra'] = array(); + isset($name['extra']) OR $name['extra'] = ''; return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); } @@ -328,7 +328,7 @@ if ( ! function_exists('form_dropdown')) { $selected = array($_POST[$name]); } - + $extra = _attributes_to_string($extra); $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; -- cgit v1.2.3-24-g4f1b From 72b4b3cbc71d2c266938b8878baba11c11c565ca Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 21 Oct 2013 14:44:57 +0300 Subject: Add 'filename' to the return elements for create_captcha() (PR #2602) --- system/helpers/captcha_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index ea46f97b3..24cd53568 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -215,12 +215,12 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Generate the image // ----------------------------------- - $img_name = $now.'.jpg'; - ImageJPEG($im, $img_path.$img_name); - $img = ' '; + $img_filename = $now.'.jpg'; + ImageJPEG($im, $img_path.$img_filename); + $img = ' '; ImageDestroy($im); - return array('word' => $word, 'time' => $now, 'image' => $img); + return array('word' => $word, 'time' => $now, 'image' => $img, 'filename' => $img_filename); } } -- cgit v1.2.3-24-g4f1b From a587a939ce0b8e7d1dfe0830ac83d881e151d6e0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 23 Oct 2013 19:57:46 +0300 Subject: Fix issue #2695 --- system/helpers/form_helper.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 400a91faa..a3d299b0d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -682,9 +682,20 @@ if ( ! function_exists('set_select')) { return ($default === TRUE) ? ' selected="selected"' : ''; } - elseif (is_array($input) && in_array($value, $input, TRUE)) + + $value = (string) $value; + if (is_array($input)) { - return ' selected="selected"'; + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($input as &$v) + { + if ($value === $v) + { + return ' selected="selected"'; + } + } + + return ''; } return ($input === $value) ? ' selected="selected"' : ''; @@ -718,9 +729,20 @@ if ( ! function_exists('set_checkbox')) { return ($default === TRUE) ? ' checked="checked"' : ''; } - elseif (is_array($input) && in_array($value, $input, TRUE)) + + $value = (string) $value; + if (is_array($input)) { - return ' checked="checked"'; + // Note: in_array('', array(0)) returns TRUE, do not use it + foreach ($input as &$v) + { + if ($value === $v) + { + return ' checked="checked"'; + } + } + + return ''; } return ($input === $value) ? ' checked="checked"' : ''; @@ -755,7 +777,7 @@ if ( ! function_exists('set_radio')) return ($default === TRUE) ? ' checked="checked"' : ''; } - return ($input === $value) ? ' checked="checked"' : ''; + return ($input === (string) $value) ? ' checked="checked"' : ''; } } -- cgit v1.2.3-24-g4f1b From 4c07fce7191ed5d9c393479406cce454a9c4a7cc Mon Sep 17 00:00:00 2001 From: vlakoff Date: Fri, 25 Oct 2013 01:20:32 +0200 Subject: Implement $protocol parameter in Config base_url() and site_url() methods Let's keep the implementation logic in one place. Improves 2023c3d05b042cf1322286d69557c2b8bf3bd8d5. --- system/helpers/url_helper.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index fbb4a1b24..b0f436840 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -52,14 +52,7 @@ if ( ! function_exists('site_url')) */ function site_url($uri = '', $protocol = NULL) { - $uri = get_instance()->config->site_url($uri); - - if (isset($protocol)) - { - return $protocol.substr($uri, strpos($uri, '://')); - } - - return $uri; + return get_instance()->config->site_url($uri, $protocol); } } @@ -80,14 +73,7 @@ if ( ! function_exists('base_url')) */ function base_url($uri = '', $protocol = NULL) { - $uri = get_instance()->config->base_url($uri); - - if (isset($protocol)) - { - return $protocol.substr($uri, strpos($uri, '://')); - } - - return $uri; + return get_instance()->config->base_url($uri, $protocol); } } -- cgit v1.2.3-24-g4f1b From 8f5420b5c59cb50dfb4834a3ab9a5bee5faadb1c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 10:34:23 +0200 Subject: Make CI_Input::set_cookie() and cookie helpers set_cookie(), get_cookie(), delete_cookie()'s first (name) parameter mandatory --- system/helpers/cookie_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index e5cf6b1d6..e465412cf 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -56,7 +56,7 @@ if ( ! function_exists('set_cookie')) * @param bool true makes the cookie accessible via http(s) only (no javascript) * @return void */ - function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE) + function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE) { // Set the config file options $CI =& get_instance(); @@ -75,7 +75,7 @@ if ( ! function_exists('get_cookie')) * @param bool * @return mixed */ - function get_cookie($index = '', $xss_clean = FALSE) + function get_cookie($index, $xss_clean = FALSE) { $CI =& get_instance(); $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix'); @@ -96,7 +96,7 @@ if ( ! function_exists('delete_cookie')) * @param string the cookie prefix * @return void */ - function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') + function delete_cookie($name, $domain = '', $path = '/', $prefix = '') { set_cookie($name, '', '', $domain, $path, $prefix); } -- cgit v1.2.3-24-g4f1b From ac023e10e7d9e4ad11783ff7e1154d2701a1ec18 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 16:13:03 +0200 Subject: Change Text helper default tag from to Supersedes PR #1497 --- system/helpers/text_helper.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b2351db95..c6d14784b 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -329,25 +329,17 @@ if ( ! function_exists('highlight_phrase')) * * Highlights a phrase within a text string * - * @param string the text string - * @param string the phrase you'd like to highlight - * @param string the openging tag to precede the phrase with - * @param string the closing tag to end the phrase with + * @param string $str the text string + * @param string $phrase the phrase you'd like to highlight + * @param string $tag_open the openging tag to precede the phrase with + * @param string $tag_close the closing tag to end the phrase with * @return string */ - function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') + function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') { - if ($str === '') - { - return ''; - } - - if ($phrase !== '') - { - return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open.'\\1'.$tag_close, $str); - } - - return $str; + return ($str !== '' && $phrase !== '') + ? preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open.'\\1'.$tag_close, $str) + : $str; } } -- cgit v1.2.3-24-g4f1b From 119d8a7547e155edaaa53682b9247cd7e80d8c9d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 15:27:53 +0200 Subject: Optimize get_instance() calls/assignments --- system/helpers/cookie_helper.php | 6 ++---- system/helpers/html_helper.php | 6 ++---- system/helpers/language_helper.php | 3 +-- system/helpers/security_helper.php | 9 +++------ system/helpers/url_helper.php | 9 +++------ 5 files changed, 11 insertions(+), 22 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index e465412cf..5cdcdd137 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -59,8 +59,7 @@ if ( ! function_exists('set_cookie')) function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE) { // Set the config file options - $CI =& get_instance(); - $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly); + get_instance()->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly); } } @@ -77,9 +76,8 @@ if ( ! function_exists('get_cookie')) */ function get_cookie($index, $xss_clean = FALSE) { - $CI =& get_instance(); $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix'); - return $CI->input->cookie($prefix.$index, $xss_clean); + return get_instance()->input->cookie($prefix.$index, $xss_clean); } } diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index ece39584b..988eee715 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -199,15 +199,13 @@ if ( ! function_exists('img')) { if ($k === 'src' && strpos($v, '://') === FALSE) { - $CI =& get_instance(); - if ($index_page === TRUE) { - $img .= ' src="'.$CI->config->site_url($v).'"'; + $img .= ' src="'.get_instance()->config->site_url($v).'"'; } else { - $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"'; + $img .= ' src="'.get_instance()->config->slash_item('base_url').$v.'"'; } } else diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 4d571a71c..d7aa8e638 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -52,8 +52,7 @@ if ( ! function_exists('lang')) */ function lang($line, $for = '', $attributes = array()) { - $CI =& get_instance(); - $line = $CI->lang->line($line); + $line = get_instance()->lang->line($line); if ($for !== '') { diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 4bb94a201..7a6df5420 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -49,8 +49,7 @@ if ( ! function_exists('xss_clean')) */ function xss_clean($str, $is_image = FALSE) { - $CI =& get_instance(); - return $CI->security->xss_clean($str, $is_image); + return get_instance()->security->xss_clean($str, $is_image); } } @@ -66,8 +65,7 @@ if ( ! function_exists('sanitize_filename')) */ function sanitize_filename($filename) { - $CI =& get_instance(); - return $CI->security->sanitize_filename($filename); + return get_instance()->security->sanitize_filename($filename); } } @@ -107,8 +105,7 @@ if ( ! function_exists('strip_image_tags')) */ function strip_image_tags($str) { - $CI =& get_instance(); - return $CI->security->strip_image_tags($str); + return get_instance()->security->strip_image_tags($str); } } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index b0f436840..2d9289791 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -91,8 +91,7 @@ if ( ! function_exists('current_url')) */ function current_url() { - $CI =& get_instance(); - return $CI->config->site_url($CI->uri->uri_string()); + return get_instance()->config->site_url($CI->uri->uri_string()); } } @@ -109,8 +108,7 @@ if ( ! function_exists('uri_string')) */ function uri_string() { - $CI =& get_instance(); - return $CI->uri->uri_string(); + return get_instance()->uri->uri_string(); } } @@ -127,8 +125,7 @@ if ( ! function_exists('index_page')) */ function index_page() { - $CI =& get_instance(); - return $CI->config->item('index_page'); + return get_instance()->config->item('index_page'); } } -- cgit v1.2.3-24-g4f1b From 80a16b1cd0d4716b5ea41497685a8fac02e34333 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 17:19:03 +0200 Subject: Fix #346 When ['global_xss_filtering'] was turned on, the , , & superglobals were automatically overwritten. This resulted in one of the following problems: - xss_clean() being called twice - Inability to retrieve the original (not filtered) value XSS filtering is now only applied on demand by the Input class, and the default value for the parameter in CI_Input methods is changed to NULL. Unless a boolean value is passed to them, whether XSS filtering is applied depends on the ['global_xss_filtering'] value. --- system/helpers/cookie_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 5cdcdd137..a79083a63 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -74,8 +74,9 @@ if ( ! function_exists('get_cookie')) * @param bool * @return mixed */ - function get_cookie($index, $xss_clean = FALSE) + function get_cookie($index, $xss_clean = NULL) { + is_bool($xss_clean) OR $xss_clean = (config_item('global_xss_filtering') === TRUE); $prefix = isset($_COOKIE[$index]) ? '' : config_item('cookie_prefix'); return get_instance()->input->cookie($prefix.$index, $xss_clean); } -- cgit v1.2.3-24-g4f1b From 4ea76cc2216b19bfae38dbbfe7104c21ee278d81 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 21:49:23 +0200 Subject: Fix 2 errors caused by recent commits --- system/helpers/url_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 2d9289791..f819b96e9 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -91,7 +91,8 @@ if ( ! function_exists('current_url')) */ function current_url() { - return get_instance()->config->site_url($CI->uri->uri_string()); + $CI =& get_instance(); + return $CI->config->site_url($CI->uri->uri_string()); } } -- cgit v1.2.3-24-g4f1b From 40235e6890650690afeaa451738bf7f8e586cfc3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 14:20:57 +0200 Subject: Fix #133 --- system/helpers/text_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index c6d14784b..bda844630 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -127,7 +127,7 @@ if ( ! function_exists('ascii_to_entities')) function ascii_to_entities($str) { $out = ''; - for ($i = 0, $s = strlen($str), $count = 1, $temp = array(); $i < $s; $i++) + for ($i = 0, $s = strlen($str) - 1, $count = 1, $temp = array(); $i <= $s; $i++) { $ordinal = ord($str[$i]); @@ -164,6 +164,11 @@ if ( ! function_exists('ascii_to_entities')) $count = 1; $temp = array(); } + // If this is the last iteration, just output whatever we have + elseif ($i === $s) + { + $out .= '&#'.implode(';', $temp).';'; + } } } -- cgit v1.2.3-24-g4f1b From a0a73c977ce25911f56948d89de817b3ca83adcb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 9 Jan 2014 19:21:26 +0200 Subject: Add HTTP response code 307 support in URL helper redirect() --- system/helpers/url_helper.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index f819b96e9..f9650cd04 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,11 +532,16 @@ if ( ! function_exists('redirect')) } elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) { - // Reference: http://en.wikipedia.org/wiki/Post/Redirect/Get - $code = (isset($_SERVER['REQUEST_METHOD'], $_SERVER['SERVER_PROTOCOL']) - && $_SERVER['REQUEST_METHOD'] === 'POST' - && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') - ? 303 : 302; + if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') + { + $code = ($_SERVER['REQUEST_METHOD'] !== 'GET') + ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get + : 307; + } + else + { + $code = 302; + } } switch ($method) -- cgit v1.2.3-24-g4f1b From d8b1ad31cf7ee205ddf3cf396b1d1bfa45af49fa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Jan 2014 17:42:52 +0200 Subject: Fix #2822: Incorrect usage of fwrite() We only used to check (and not always) if the return value of fwrite() is boolean FALSE, while it is possible that the otherwise returned bytecount is less than the length of data that we're trying to write. This allowed incomplete writes over network streams and possibly a few other edge cases. --- system/helpers/file_helper.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 4b45a62d0..0587740b1 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -79,11 +79,19 @@ if ( ! function_exists('write_file')) } flock($fp, LOCK_EX); - fwrite($fp, $data); + + for ($written = 0, $length = strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($fp, substr($data, $written))) === FALSE) + { + break; + } + } + flock($fp, LOCK_UN); fclose($fp); - return TRUE; + return is_int($result); } } -- cgit v1.2.3-24-g4f1b From 8fb31c929b9cca6154eb007ff553f4a96d31415e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 24 Jan 2014 11:49:24 +0200 Subject: [ci skip] AND -> && --- system/helpers/directory_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 81ffd1579..6f9251720 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -69,7 +69,7 @@ if ( ! function_exists('directory_map')) continue; } - @is_dir($source_dir.$file) AND $file .= DIRECTORY_SEPARATOR; + @is_dir($source_dir.$file) && $file .= DIRECTORY_SEPARATOR; if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { -- cgit v1.2.3-24-g4f1b From 88d16d7b97ebed83d6a1d1bda9c674546c9adc28 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Jan 2014 12:28:42 +0200 Subject: Fix #2845 --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 4fe6a0e88..9a6f684e4 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -120,7 +120,7 @@ if ( ! function_exists('force_download')) // Clean output buffer if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) { - ob_clean(); + @ob_clean(); } // Generate the server headers -- cgit v1.2.3-24-g4f1b From 03077f9ab1408d28b5b9783355d1629eda3ff5ae Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 7 Feb 2014 14:53:39 +0200 Subject: Use is_really_writable() in get_file_info() --- system/helpers/file_helper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0587740b1..ae3db5846 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -298,8 +298,7 @@ if ( ! function_exists('get_file_info')) $fileinfo['readable'] = is_readable($file); break; case 'writable': - // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms() - $fileinfo['writable'] = is_writable($file); + $fileinfo['writable'] = is_really_writable($file); break; case 'executable': $fileinfo['executable'] = is_executable($file); -- cgit v1.2.3-24-g4f1b From c697a3bfdfc301718058a09fd5692fbecee6920a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 7 Feb 2014 15:11:56 +0200 Subject: Use is_really_writable() in captcha helper --- system/helpers/captcha_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 24cd53568..b61b2d5cf 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -82,7 +82,7 @@ if ( ! function_exists('create_captcha')) } if ($img_path === '' OR $img_url === '' - OR ! @is_dir($img_path) OR ! is_writeable($img_path) + OR ! @is_dir($img_path) OR ! is_really_writable($img_path) OR ! extension_loaded('gd')) { return FALSE; -- cgit v1.2.3-24-g4f1b From 08dd57c567d37a0c94faa607f2fef331c9d1db0a Mon Sep 17 00:00:00 2001 From: Olanipekun Femi Date: Fri, 7 Feb 2014 08:16:48 -0800 Subject: Fixed Typo in String Helper function alnum spelled as alunum in random_string function documentation comment. --- system/helpers/string_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 12f818fda..777acba0b 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -188,7 +188,7 @@ if ( ! function_exists('random_string')) * * Useful for generating passwords or hashes. * - * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 + * @param string type of random string. basic, alpha, alnum, numeric, nozero, unique, md5, encrypt and sha1 * @param int number of characters * @return string */ @@ -294,4 +294,4 @@ if ( ! function_exists('repeater')) } /* End of file string_helper.php */ -/* Location: ./system/helpers/string_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/string_helper.php */ -- cgit v1.2.3-24-g4f1b From c7d82d8f3ca2531fbec82344c528d269dcffff08 Mon Sep 17 00:00:00 2001 From: iolufemi Date: Sun, 9 Feb 2014 22:39:22 +0100 Subject: Removed new line at the end of file locally. --- system/helpers/string_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 777acba0b..4be7f294b 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -294,4 +294,4 @@ if ( ! function_exists('repeater')) } /* End of file string_helper.php */ -/* Location: ./system/helpers/string_helper.php */ +/* Location: ./system/helpers/string_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- 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 7b62da68f..1cdbcdfcf 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 b61b2d5cf..13926774e 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 a79083a63..a08bec398 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 c3a8d3c9e..56e5c46aa 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 6f9251720..84ad35894 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 9a6f684e4..ffe5ff997 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 d2e6f5491..e93f35705 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 ae3db5846..575b87479 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 a3d299b0d..40852faf8 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 988eee715..604d1144a 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 a133cdddb..210d0fdfd 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 d7aa8e638..baea849b1 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 5ebdc946f..7d3bb2797 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 3f4f7e9fb..ae1f0bf33 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 7a6df5420..848cf4623 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 d9a693493..57debffa9 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 4be7f294b..a1daa1efe 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 bda844630..206ce5559 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 e4a8d3bc0..cd3827c8b 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 f9650cd04..a9790e5c4 100644 --- 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 84069a689..4c38b6988 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 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, 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 6ce4746474ddf050f7f4df61b7a22b7f5854d533 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Feb 2014 03:28:00 +0200 Subject: Update Text and Inflector helpers to utilize mbstring, if available Text: word_wrap(), ellipsize() Inflector: humanize(), underscore() (rel #2855) --- system/helpers/inflector_helper.php | 17 +++++++++-------- system/helpers/text_helper.php | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 210d0fdfd..b44594e2a 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -188,7 +188,7 @@ if ( ! function_exists('underscore')) */ function underscore($str) { - return preg_replace('/[\s]+/', '_', strtolower(trim($str))); + return preg_replace('/[\s]+/', '_', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str))); } } @@ -207,7 +207,7 @@ if ( ! function_exists('humanize')) */ function humanize($str, $separator = '_') { - return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str)))); + return ucwords(preg_replace('/['.$separator.']+/', ' ', trim(MB_ENABLED ? mb_strtolower($str) : strtolower($str)))); } } @@ -223,12 +223,13 @@ if ( ! function_exists('is_countable')) */ function is_countable($word) { - return ! in_array(strtolower($word), - array( - 'equipment', 'information', 'rice', 'money', - 'species', 'series', 'fish', 'meta' - ) - ); + return ! in_array( + strtolower($word), + array( + 'equipment', 'information', 'rice', 'money', + 'species', 'series', 'fish', 'meta' + ) + ); } } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 45e8ae760..76e1735b5 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -445,14 +445,14 @@ if ( ! function_exists('word_wrap')) { // Is the line within the allowed character count? // If so we'll join it to the output and continue - if (strlen($line) <= $charlim) + if (mb_strlen($line) <= $charlim) { $output .= $line."\n"; continue; } $temp = ''; - while ((strlen($line)) > $charlim) + while (mb_strlen($line) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match('!\[url.+\]|://|wwww.!', $line)) @@ -461,8 +461,8 @@ if ( ! function_exists('word_wrap')) } // Trim the word down - $temp .= substr($line, 0, $charlim - 1); - $line = substr($line, $charlim - 1); + $temp .= mb_substr($line, 0, $charlim - 1); + $line = mb_substr($line, $charlim - 1); } // If $temp contains data it means we had to split up an over-length @@ -512,21 +512,21 @@ if ( ! function_exists('ellipsize')) $str = trim(strip_tags($str)); // Is the string long enough to ellipsize? - if (strlen($str) <= $max_length) + if (mb_strlen($str) <= $max_length) { return $str; } - $beg = substr($str, 0, floor($max_length * $position)); + $beg = mb_substr($str, 0, floor($max_length * $position)); $position = ($position > 1) ? 1 : $position; if ($position === 1) { - $end = substr($str, 0, -($max_length - strlen($beg))); + $end = mb_substr($str, 0, -($max_length - mb_strlen($beg))); } else { - $end = substr($str, -($max_length - strlen($beg))); + $end = mb_substr($str, -($max_length - mb_strlen($beg))); } return $beg.$ellipsis.$end; -- cgit v1.2.3-24-g4f1b