From 1bdc9c8903eb2db33fdb8174d61e15100dfbbca8 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 10 Apr 2011 10:39:31 +0200 Subject: update to CI 2.0.2 Signed-off-by: Florian Pritz --- system/helpers/array_helper.php | 1 + system/helpers/captcha_helper.php | 2 +- system/helpers/cookie_helper.php | 4 ++-- system/helpers/download_helper.php | 9 ++++++++- system/helpers/file_helper.php | 13 +++++++++++-- system/helpers/form_helper.php | 11 +++++++++-- system/helpers/html_helper.php | 11 ++++++++++- system/helpers/inflector_helper.php | 28 +++++++++++++++------------- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/security_helper.php | 34 +--------------------------------- system/helpers/smiley_helper.php | 22 ++++++++++++---------- system/helpers/text_helper.php | 12 +++++++----- system/helpers/typography_helper.php | 5 ++--- 14 files changed, 81 insertions(+), 75 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 6b2415df2..075a31fdf 100755 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -69,6 +69,7 @@ if ( ! function_exists('random_element')) { return $array; } + return $array[array_rand($array)]; } } diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index c0e3798f4..19ec0c778 100755 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -87,7 +87,7 @@ if ( ! function_exists('create_captcha')) $current_dir = @opendir($img_path); - while($filename = @readdir($current_dir)) + while ($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 7701d503f..7cee02827 100755 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -44,11 +44,11 @@ */ if ( ! function_exists('set_cookie')) { - function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') + function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE) { // Set the config file options $CI =& get_instance(); - $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix); + $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 6cecd0d11..f8073d238 100755 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -58,7 +58,14 @@ if ( ! function_exists('force_download')) $extension = end($x); // Load the mime types - @include(APPPATH.'config/mimes'.EXT); + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + { + include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); + } + elseif (is_file(APPPATH.'config/mimes'.EXT)) + { + include(APPPATH.'config/mimes'.EXT); + } // 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 334eef87c..44344947e 100755 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -128,7 +128,7 @@ if ( ! function_exists('delete_files')) return FALSE; } - while(FALSE !== ($filename = @readdir($current_dir))) + while (FALSE !== ($filename = @readdir($current_dir))) { if ($filename != "." and $filename != "..") { @@ -352,7 +352,16 @@ if ( ! function_exists('get_mime_by_extension')) if ( ! is_array($mimes)) { - if ( ! require_once(APPPATH.'config/mimes.php')) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT)) + { + include(APPPATH.'config/'.ENVIRONMENT.'/mimes'.EXT); + } + elseif (is_file(APPPATH.'config/mimes'.EXT)) + { + include(APPPATH.'config/mimes'.EXT); + } + + if ( ! is_array($mimes)) { return FALSE; } diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 758056b50..acd75c239 100755 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -49,7 +49,14 @@ if ( ! function_exists('form_open')) $attributes = 'method="post"'; } - $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; + // If an action is not a full URL then turn it into one + if ($action && strpos($action, '://') === FALSE) + { + $action = $CI->config->site_url($action); + } + + // If no action is provided then set to the current url + $action OR $action = $CI->config->site_url($CI->uri->uri_string()); $form = '
config->item('csrf_protection') === TRUE) { - $hidden[$CI->security->csrf_token_name] = $CI->security->csrf_hash; + $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } if (is_array($hidden) AND count($hidden) > 0) diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 68c6f5908..c6103ab6f 100755 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -258,7 +258,16 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if ( ! require_once(APPPATH.'config/doctypes.php')) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT)) + { + include(APPPATH.'config/'.ENVIRONMENT.'/doctypes'.EXT); + } + elseif (is_file(APPPATH.'config/doctypes'.EXT)) + { + include(APPPATH.'config/doctypes'.EXT); + } + + if ( ! is_array($_doctypes)) { return FALSE; } diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 4cd7486b4..c7c113b8a 100755 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -41,20 +41,22 @@ if ( ! function_exists('singular')) { function singular($str) { - $str = strtolower(trim($str)); + $str = trim($str); $end = substr($str, -3); - - if ($end == 'ies') + + $str = preg_replace('/(.*)?([s|c]h)es/i','$1$2',$str); + + if (strtolower($end) == 'ies') { - $str = substr($str, 0, strlen($str)-3).'y'; + $str = substr($str, 0, strlen($str)-3).(preg_match('/[a-z]/',$end) ? 'y' : 'Y'); } - elseif ($end == 'ses') + elseif (strtolower($end) == 'ses') { $str = substr($str, 0, strlen($str)-2); } else { - $end = substr($str, -1); + $end = strtolower(substr($str, -1)); if ($end == 's') { @@ -81,19 +83,19 @@ if ( ! function_exists('singular')) if ( ! function_exists('plural')) { function plural($str, $force = FALSE) - { - $str = strtolower(trim($str)); + { + $str = trim($str); $end = substr($str, -1); - if ($end == 'y') + if (preg_match('/y/i',$end)) { // Y preceded by vowel => regular plural - $vowels = array('a', 'e', 'i', 'o', 'u'); + $vowels = array('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'); $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies'; } - elseif ($end == 'h') + elseif (preg_match('/h/i',$end)) { - if (substr($str, -2) == 'ch' OR substr($str, -2) == 'sh') + if(preg_match('/^[c|s]h$/i',substr($str, -2))) { $str .= 'es'; } @@ -102,7 +104,7 @@ if ( ! function_exists('plural')) $str .= 's'; } } - elseif ($end == 's') + elseif (preg_match('/s/i',$end)) { if ($force == TRUE) { diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 68c1a1fc6..ac0d69da1 100755 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -1,4 +1,4 @@ -generate($str); - } - else - { - return bin2hex(mhash(MHASH_SHA1, $str)); - } - } - else - { - return sha1($str); - } + return sha1($str); } else { diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 80a8d79ad..a2d1031b3 100755 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -59,7 +59,7 @@ if ( ! function_exists('smiley_js')) if (is_array($alias)) { - foreach($alias as $name => $id) + foreach ($alias as $name => $id) { $m[] = '"'.$name.'" : "'.$id.'"'; } @@ -101,7 +101,7 @@ EOF; { if (is_array($alias)) { - foreach($alias as $name => $id) + foreach ($alias as $name => $id) { $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n"; } @@ -229,19 +229,21 @@ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT)) { - return FALSE; + include(APPPATH.'config/'.ENVIRONMENT.'/smileys'.EXT); } - - include(APPPATH.'config/smileys'.EXT); - - if ( ! isset($smileys) OR ! is_array($smileys)) + elseif (file_exists(APPPATH.'config/smileys'.EXT)) + { + include(APPPATH.'config/smileys'.EXT); + } + + if (isset($smileys) AND is_array($smileys)) { - return FALSE; + return $smileys; } - return $smileys; + return FALSE; } } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 47e6ccc93..cca093976 100755 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -366,12 +366,14 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - if ( ! file_exists(APPPATH.'config/foreign_chars'.EXT)) + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT)) { - return $str; + include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars'.EXT); + } + elseif (is_file(APPPATH.'config/foreign_chars'.EXT)) + { + include(APPPATH.'config/foreign_chars'.EXT); } - - include APPPATH.'config/foreign_chars'.EXT; if ( ! isset($foreign_characters)) { @@ -443,7 +445,7 @@ if ( ! function_exists('word_wrap')) } $temp = ''; - while((strlen($line)) > $charlim) + while ((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 302bf45c5..19b4eec03 100755 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -84,9 +84,8 @@ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { - $CI =& get_instance(); - $CI->load->library('security'); - return $CI->security->entity_decode($str, $charset); + global $SEC; + return $SEC->entity_decode($str, $charset); } } -- cgit v1.2.3-24-g4f1b