From f1b43d43385c81788dab9103a4f9be7e02432852 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jan 2012 14:41:50 +0200 Subject: Improve array, captcha & cookie helpers --- system/helpers/array_helper.php | 27 ++++---------- system/helpers/captcha_helper.php | 78 ++++++++++++++------------------------- system/helpers/cookie_helper.php | 17 +++------ 3 files changed, 39 insertions(+), 83 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index c46c4d103..881f57db3 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,13 +1,13 @@ - $val) { - if ( ! is_array($data)) + if ( ! is_array($data) && ( ! isset($$key) OR $$key == '')) { - if ( ! isset($$key) OR $$key == '') - { - $$key = $val; - } + $$key = $val; } else { @@ -70,22 +67,7 @@ if ( ! function_exists('create_captcha')) } } - if ($img_path == '' OR $img_url == '') - { - return FALSE; - } - - if ( ! @is_dir($img_path)) - { - return FALSE; - } - - if ( ! is_writable($img_path)) - { - return FALSE; - } - - if ( ! extension_loaded('gd')) + if ($img_path == '' OR $img_url == '' OR ! @is_dir($img_path) OR ! is_writeable($img_path) OR ! extension_loaded('gd')) { return FALSE; } @@ -94,21 +76,16 @@ if ( ! function_exists('create_captcha')) // Remove old images // ----------------------------------- - list($usec, $sec) = explode(" ", microtime()); + list($usec, $sec) = explode(' ', microtime()); $now = ((float)$usec + (float)$sec); $current_dir = @opendir($img_path); - while ($filename = @readdir($current_dir)) { - if ($filename != "." and $filename != ".." and $filename != "index.html") + if ($filename !== '.' && $filename !== '..' && $filename !== 'index.html' + && (str_replace('.jpg', '', $filename) + $expiration) < $now) { - $name = str_replace(".jpg", "", $filename); - - if (($name + $expiration) < $now) - { - @unlink($img_path.$filename); - } + @unlink($img_path.$filename); } } @@ -118,18 +95,17 @@ if ( ! function_exists('create_captcha')) // Do we have a "word" yet? // ----------------------------------- - if ($word == '') - { + if ($word == '') + { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $str = ''; - for ($i = 0; $i < 8; $i++) + $word = ''; + for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < 8; $i++) { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); + $word .= substr($pool, mt_rand(0, $mt_rand_max), 1); } - $word = $str; - } + } // ----------------------------------- // Determine angle and position @@ -138,7 +114,7 @@ if ( ! function_exists('create_captcha')) $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); + $y_axis = ($angle >= 0) ? rand($img_height, $img_width) : rand(6, $img_height); // ----------------------------------- // Create image @@ -180,18 +156,18 @@ if ( ! function_exists('create_captcha')) $circles = 20; $points = 32; - for ($i = 0; $i < ($circles * $points) - 1; $i++) + for ($i = 0, $cp = $circles * $points; $i < $cp - 1; $i++) { - $theta = $theta + $thetac; - $rad = $radius * ($i / $points ); + $theta += $thetac; + $rad = $radius * ($i / $points); $x = ($rad * cos($theta)) + $x_axis; $y = ($rad * sin($theta)) + $y_axis; - $theta = $theta + $thetac; + $theta += $thetac; $rad1 = $radius * (($i + 1) / $points); $x1 = ($rad1 * cos($theta)) + $x_axis; - $y1 = ($rad1 * sin($theta )) + $y_axis; + $y1 = ($rad1 * sin($theta)) + $y_axis; imageline($im, $x, $y, $x1, $y1, $grid_color); - $theta = $theta - $thetac; + $theta -= $thetac; } // ----------------------------------- @@ -213,18 +189,18 @@ if ( ! function_exists('create_captcha')) $y = $font_size+2; } - for ($i = 0; $i < strlen($word); $i++) + for ($i = 0; $i < $length; $i++) { if ($use_font == FALSE) { $y = rand(0 , $img_height/2); - imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color); + imagestring($im, $font_size, $x, $y, $word[$i], $text_color); $x += ($font_size*2); } else { $y = rand($img_height/2, $img_height-3); - imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); + imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, $word[$i]); $x += $font_size; } } @@ -255,4 +231,4 @@ if ( ! function_exists('create_captcha')) // ------------------------------------------------------------------------ /* End of file captcha_helper.php */ -/* Location: ./system/helpers/captcha_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/captcha_helper.php */ diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 7b439c47f..d6f836670 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -1,13 +1,13 @@ -input->cookie($prefix.$index, $xss_clean); } @@ -110,6 +104,5 @@ if ( ! function_exists('delete_cookie')) } } - /* End of file cookie_helper.php */ -/* Location: ./system/helpers/cookie_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/cookie_helper.php */ -- cgit v1.2.3-24-g4f1b From 4f2933d28370ad965059222553d8ace1dd2fe602 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 06:49:49 +0200 Subject: Some more misc. stuff --- system/helpers/array_helper.php | 2 -- system/helpers/captcha_helper.php | 37 +++++++------------------------------ 2 files changed, 7 insertions(+), 32 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 881f57db3..a454f936d 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Array Helpers * diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 40b6e5b23..89bff2366 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -67,7 +67,9 @@ if ( ! function_exists('create_captcha')) } } - if ($img_path == '' OR $img_url == '' OR ! @is_dir($img_path) OR ! is_writeable($img_path) OR ! extension_loaded('gd')) + if ($img_path == '' OR $img_url == '' + OR ! @is_dir($img_path) OR ! is_writeable($img_path) + OR ! extension_loaded('gd')) { return FALSE; } @@ -98,11 +100,10 @@ if ( ! function_exists('create_captcha')) if ($word == '') { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $word = ''; for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < 8; $i++) { - $word .= substr($pool, mt_rand(0, $mt_rand_max), 1); + $word .= $pool[mt_rand(0, $mt_rand_max)]; } } @@ -110,46 +111,32 @@ 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); - // ----------------------------------- // Create image - // ----------------------------------- - // PHP.net recommends imagecreatetruecolor(), but it isn't always available - if (function_exists('imagecreatetruecolor')) - { - $im = imagecreatetruecolor($img_width, $img_height); - } - else - { - $im = imagecreate($img_width, $img_height); - } + $im = function_exists('imagecreatetruecolor') + ? imagecreatetruecolor($img_width, $img_height) + : imagecreate($img_width, $img_height); // ----------------------------------- // Assign colors // ----------------------------------- - $bg_color = imagecolorallocate ($im, 255, 255, 255); $border_color = imagecolorallocate ($im, 153, 102, 102); $text_color = imagecolorallocate ($im, 204, 153, 153); $grid_color = imagecolorallocate($im, 255, 182, 182); $shadow_color = imagecolorallocate($im, 255, 240, 240); - // ----------------------------------- // Create the rectangle - // ----------------------------------- - ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); // ----------------------------------- // Create the spiral pattern // ----------------------------------- - $theta = 1; $thetac = 7; $radius = 16; @@ -173,7 +160,6 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Write the text // ----------------------------------- - $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; if ($use_font == FALSE) @@ -206,29 +192,20 @@ if ( ! function_exists('create_captcha')) } - // ----------------------------------- // Create the border - // ----------------------------------- - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); // ----------------------------------- // Generate the image // ----------------------------------- - $img_name = $now.'.jpg'; - ImageJPEG($im, $img_path.$img_name); - $img = "\""; - ImageDestroy($im); return array('word' => $word, 'time' => $now, 'image' => $img); } } -// ------------------------------------------------------------------------ - /* End of file captcha_helper.php */ /* Location: ./system/helpers/captcha_helper.php */ -- cgit v1.2.3-24-g4f1b From 63a21005ec657aa004b5ffc2b0965c1a201e4637 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 15:13:32 +0200 Subject: Some more cleaning --- system/helpers/array_helper.php | 13 ++++--------- system/helpers/captcha_helper.php | 8 ++++---- system/helpers/cookie_helper.php | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index a454f936d..82f0eb16c 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -53,12 +53,7 @@ if ( ! function_exists('element')) { function element($item, $array, $default = FALSE) { - if ( ! isset($array[$item]) OR $array[$item] == "") - { - return $default; - } - - return $array[$item]; + return ( ! isset($array[$item]) OR $array[$item] == '') ? $default : $array[$item]; } } @@ -75,7 +70,7 @@ if ( ! function_exists('random_element')) { function random_element($array) { - return (is_array($array)) ? $array[array_rand($array)] : $array; + return is_array($array) ? $array[array_rand($array)] : $array; } } @@ -105,7 +100,7 @@ if ( ! function_exists('elements')) foreach ($items as $item) { - $return[$item] = (isset($array[$item])) ? $array[$item] : $default; + $return[$item] = isset($array[$item]) ? $array[$item] : $default; } return $return; diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 89bff2366..0565457e2 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -170,7 +170,7 @@ if ( ! function_exists('create_captcha')) } else { - $font_size = 16; + $font_size = 16; $x = rand(0, $img_width/($length/1.5)); $y = $font_size+2; } @@ -192,7 +192,7 @@ if ( ! function_exists('create_captcha')) } - // Create the border + // Create the border imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); // ----------------------------------- @@ -200,7 +200,7 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- $img_name = $now.'.jpg'; ImageJPEG($im, $img_path.$img_name); - $img = "\""; + $img = ' '; ImageDestroy($im); return array('word' => $word, 'time' => $now, 'image' => $img); diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index d6f836670..52f489b39 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -91,7 +91,7 @@ if ( ! function_exists('get_cookie')) * Delete a COOKIE * * @param mixed - * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie domain. Usually: .yourdomain.com * @param string the cookie path * @param string the cookie prefix * @return void -- cgit v1.2.3-24-g4f1b From 5ad9e4ebba4ab8a8eb36952430d5a18978697360 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 20 Jan 2012 13:10:22 +0200 Subject: Replace AND with && --- system/helpers/captcha_helper.php | 4 +--- system/helpers/cookie_helper.php | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 0565457e2..3b62da929 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter CAPTCHA Helper * @@ -160,7 +158,7 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Write the text // ----------------------------------- - $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; + $use_font = ($font_path != '' && file_exists($font_path) && function_exists('imagettftext')); if ($use_font == FALSE) { diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 52f489b39..f32a1a5ae 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Cookie Helpers * -- cgit v1.2.3-24-g4f1b From 51a22815994cfd4522c78177e41f064ab8e53415 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:27:34 +0200 Subject: Revert a space in the license agreement :) --- system/helpers/array_helper.php | 2 +- system/helpers/captcha_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 82f0eb16c..45eaa4c10 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 3b62da929..c302a828b 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index f32a1a5ae..af2e1df80 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From 6b47711e85671fcfe1bd08ce80d23ca2e91e8e55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 13 Mar 2012 12:24:07 +0200 Subject: Remove access description line --- system/helpers/captcha_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 9ae959fbe..7dc5b3eec 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -40,7 +40,6 @@ /** * Create CAPTCHA * - * @access public * @param array array of data for the CAPTCHA * @param string path to create the image in * @param string URL to the CAPTCHA image folder -- cgit v1.2.3-24-g4f1b From e6f7d610b189e243ad48dcc3900a5c53cab2498d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 15:39:22 +0200 Subject: Remove EOF newlines --- system/helpers/array_helper.php | 2 +- system/helpers/captcha_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 464d1d112..6f56d9db9 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -103,4 +103,4 @@ if ( ! function_exists('elements')) } /* End of file array_helper.php */ -/* Location: ./system/helpers/array_helper.php */ +/* Location: ./system/helpers/array_helper.php */ \ No newline at end of file diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 7dc5b3eec..96e8c51a3 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -204,4 +204,4 @@ if ( ! function_exists('create_captcha')) } /* End of file captcha_helper.php */ -/* Location: ./system/helpers/captcha_helper.php */ +/* Location: ./system/helpers/captcha_helper.php */ \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index ec8aa3250..06560e723 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -102,4 +102,4 @@ if ( ! function_exists('delete_cookie')) } /* End of file cookie_helper.php */ -/* Location: ./system/helpers/cookie_helper.php */ +/* Location: ./system/helpers/cookie_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e684bdac2d6282e3b9a5c57e1006d5ed1664f647 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 13:47:29 +0300 Subject: Clear some spaces and fix some inconsistencies in the Zip library and system/helpers/ files --- system/helpers/captcha_helper.php | 4 +--- system/helpers/date_helper.php | 2 +- system/helpers/smiley_helper.php | 13 ++++++------- system/helpers/string_helper.php | 10 +++++----- system/helpers/text_helper.php | 8 ++++---- 5 files changed, 17 insertions(+), 20 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 578796573..5955e054a 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -1,4 +1,4 @@ - Date: Mon, 26 Mar 2012 20:53:47 +0300 Subject: Remove access description lines and cleanup the download, language, number, path & xml helpers --- system/helpers/download_helper.php | 3 +-- system/helpers/language_helper.php | 7 ++----- system/helpers/number_helper.php | 5 +---- system/helpers/path_helper.php | 3 +-- system/helpers/xml_helper.php | 14 ++++++-------- 5 files changed, 11 insertions(+), 21 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 96ff29dec..19192a147 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -42,7 +42,6 @@ * * Generates headers that force a download to happen * - * @access public * @param string filename * @param mixed the data to be downloaded * @param bool wether to try and send the actual file MIME type @@ -125,4 +124,4 @@ if ( ! function_exists('force_download')) } /* End of file download_helper.php */ -/* Location: ./system/helpers/download_helper.php */ +/* Location: ./system/helpers/download_helper.php */ \ No newline at end of file diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 1d66df59f..b31c97107 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Language Helpers * @@ -44,7 +42,6 @@ * * Fetches a language variable and optionally outputs a form label * - * @access public * @param string the language line * @param string the id of the form element * @return string @@ -58,7 +55,7 @@ if ( ! function_exists('lang')) if ($id != '') { - $line = '"; + $line = ''; } return $line; @@ -66,4 +63,4 @@ if ( ! function_exists('lang')) } /* End of file language_helper.php */ -/* Location: ./system/helpers/language_helper.php */ +/* Location: ./system/helpers/language_helper.php */ \ No newline at end of file diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index b6c823d8b..40da6e7bf 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Number Helpers * @@ -42,7 +40,6 @@ /** * Formats a numbers as bytes, based on size, and adds the appropriate suffix * - * @access public * @param mixed // will be cast as int * @return string */ @@ -84,4 +81,4 @@ if ( ! function_exists('byte_format')) } /* End of file number_helper.php */ -/* Location: ./system/helpers/number_helper.php */ +/* Location: ./system/helpers/number_helper.php */ \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index c31f0bdc5..6ee99072c 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -40,7 +40,6 @@ /** * Set Realpath * - * @access public * @param string * @param bool checks to see if the path exists * @return string @@ -71,4 +70,4 @@ if ( ! function_exists('set_realpath')) } /* End of file path_helper.php */ -/* Location: ./system/helpers/path_helper.php */ +/* Location: ./system/helpers/path_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index f3ff5764c..67fd34b97 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter XML Helpers * @@ -42,8 +40,8 @@ /** * Convert Reserved XML characters to Entities * - * @access public * @param string + * @param bool * @return string */ if ( ! function_exists('xml_convert')) @@ -54,11 +52,11 @@ if ( ! function_exists('xml_convert')) // Replace entities to temporary markers so that // ampersands won't get messed up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace('/&#(\d+);/', $temp.'\\1;', $str); if ($protect_all == TRUE) { - $str = preg_replace('/&(\w+);/', "$temp\\1;", $str); + $str = preg_replace('/&(\w+);/', $temp.'\\1;', $str); } $str = str_replace(array('&', '<', '>', '"', "'", '-'), @@ -66,11 +64,11 @@ if ( ! function_exists('xml_convert')) $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) { - return preg_replace("/$temp(\w+);/", '&\\1;', $str); + return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str); } return $str; @@ -78,4 +76,4 @@ if ( ! function_exists('xml_convert')) } /* End of file xml_helper.php */ -/* Location: ./system/helpers/xml_helper.php */ +/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2046b1a14f68495e6324edb26250916037bce9e1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 21:07:04 +0300 Subject: Remove access description lines and cleanup the html helper --- system/helpers/html_helper.php | 66 ++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 41 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index b8c4f36f6..0417bd253 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter HTML Helpers * @@ -42,12 +40,10 @@ /** * Heading * - * Generates an HTML heading tag. First param is the data. - * Second param is the size of the heading tag. + * Generates an HTML heading tag. * - * @access public - * @param string - * @param integer + * @param string content + * @param int heading level * @return string */ if ( ! function_exists('heading')) @@ -65,7 +61,6 @@ if ( ! function_exists('heading')) * * Generates an HTML unordered list from an single or multi-dimensional array. * - * @access public * @param array * @param mixed * @return string @@ -85,7 +80,6 @@ if ( ! function_exists('ul')) * * Generates an HTML ordered list from an single or multi-dimensional array. * - * @access public * @param array * @param mixed * @return string @@ -105,11 +99,10 @@ if ( ! function_exists('ol')) * * Generates an HTML ordered list from an single or multi-dimensional array. * - * @access private * @param string * @param mixed * @param mixed - * @param integer + * @param int * @return string */ if ( ! function_exists('_list')) @@ -131,13 +124,13 @@ if ( ! function_exists('_list')) $atts = ''; foreach ($attributes as $key => $val) { - $atts .= ' ' . $key . '="' . $val . '"'; + $atts .= ' '.$key.'="'.$val.'"'; } $attributes = $atts; } - elseif (is_string($attributes) AND strlen($attributes) > 0) + elseif (is_string($attributes) && strlen($attributes) > 0) { - $attributes = ' '. $attributes; + $attributes = ' '.$attributes; } // Write the opening list tag @@ -175,8 +168,7 @@ if ( ! function_exists('_list')) /** * Generates HTML BR tags based on number supplied * - * @access public - * @param integer + * @param int * @return string */ if ( ! function_exists('br')) @@ -194,8 +186,8 @@ if ( ! function_exists('br')) * * Generates an element * - * @access public * @param mixed + * @param bool * @return string */ if ( ! function_exists('img')) @@ -217,7 +209,7 @@ if ( ! function_exists('img')) foreach ($src as $k => $v) { - if ($k === 'src' AND strpos($v, '://') === FALSE) + if ($k === 'src' && strpos($v, '://') === FALSE) { $CI =& get_instance(); @@ -232,7 +224,7 @@ if ( ! function_exists('img')) } else { - $img .= " $k=\"$v\""; + $img .= ' '.$k.'="'.$v.'"'; } } @@ -248,10 +240,9 @@ if ( ! function_exists('img')) * Generates a page document type declaration * * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame, - * html4-strict, html4-trans, and html4-frame. Values are saved in the + * html4-strict, html4-trans, and html4-frame. Values are saved in the * doctypes config file. * - * @access public * @param string type The doctype to be generated * @return string */ @@ -263,7 +254,7 @@ if ( ! function_exists('doctype')) if ( ! is_array($_doctypes)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'); } @@ -278,7 +269,7 @@ if ( ! function_exists('doctype')) } } - return (isset($_doctypes[$type])) ? $_doctypes[$type] : FALSE; + return isset($_doctypes[$type]) ? $_doctypes[$type] : FALSE; } } @@ -289,13 +280,12 @@ if ( ! function_exists('doctype')) * * Generates link to a CSS file * - * @access public * @param mixed stylesheet hrefs or an array * @param string rel * @param string type * @param string title * @param string media - * @param boolean should index_page be added to the css path + * @param bool should index_page be added to the css path * @return string */ if ( ! function_exists('link_tag')) @@ -309,7 +299,7 @@ if ( ! function_exists('link_tag')) { foreach ($href as $k => $v) { - if ($k === 'href' AND strpos($v, '://') === FALSE) + if ($k === 'href' && strpos($v, '://') === FALSE) { if ($index_page === TRUE) { @@ -322,11 +312,9 @@ if ( ! function_exists('link_tag')) } else { - $link .= "$k=\"$v\" "; + $link .= $k.'="'.$v.'" '; } } - - $link .= '/>'; } else { @@ -354,11 +342,9 @@ if ( ! function_exists('link_tag')) { $link .= 'title="'.$title.'" '; } - - $link .= '/>'; } - return $link."\n"; + return $link."/>\n"; } } @@ -367,8 +353,10 @@ if ( ! function_exists('link_tag')) /** * Generates meta tags from an array of key/values * - * @access public * @param array + * @param string + * @param string + * @param string * @return string */ if ( ! function_exists('meta')) @@ -381,13 +369,10 @@ if ( ! function_exists('meta')) { $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); } - else + elseif (isset($name['name'])) { // Turn single array into multidimensional - if (isset($name['name'])) - { - $name = array($name); - } + $name = array($name); } $str = ''; @@ -410,8 +395,7 @@ if ( ! function_exists('meta')) /** * Generates non-breaking space entities based on number supplied * - * @access public - * @param integer + * @param int * @return string */ if ( ! function_exists('nbs')) @@ -423,4 +407,4 @@ if ( ! function_exists('nbs')) } /* End of file html_helper.php */ -/* Location: ./system/helpers/html_helper.php */ +/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 93a83c720e69d1d363896f6b685d2b7ef475ebbc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 21:24:02 +0300 Subject: Remove access description lines and cleanup the form helper --- system/helpers/form_helper.php | 161 ++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 105 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 37337d975..ada822860 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -24,8 +24,6 @@ * @since Version 1.0 */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Form Helpers * @@ -43,7 +41,6 @@ * * Creates the opening portion of the form. * - * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data @@ -71,15 +68,15 @@ 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->base_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 && ! (strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) { $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); } - if (is_array($hidden) AND count($hidden) > 0) + if (is_array($hidden) && count($hidden) > 0) { - $form .= sprintf("
%s
", form_hidden($hidden)); + $form .= sprintf('
%s
', form_hidden($hidden)); } return $form; @@ -93,7 +90,6 @@ if ( ! function_exists('form_open')) * * Creates the opening portion of the form, but with "multipart/form-data". * - * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data @@ -121,10 +117,9 @@ if ( ! function_exists('form_open_multipart')) /** * Hidden Input Field * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. + * Generates hidden fields. You can pass a simple key/value string or + * an associative array with multiple values. * - * @access public * @param mixed * @param string * @return string @@ -157,7 +152,7 @@ if ( ! function_exists('form_hidden')) { foreach ($value as $k => $v) { - $k = (is_int($k)) ? '' : $k; + $k = is_int($k) ? '' : $k; form_hidden($name.'['.$k.']', $v, TRUE); } } @@ -171,7 +166,6 @@ if ( ! function_exists('form_hidden')) /** * Text Input Field * - * @access public * @param mixed * @param string * @param string @@ -181,7 +175,7 @@ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'text', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); return '\n"; } @@ -194,7 +188,6 @@ if ( ! function_exists('form_input')) * * Identical to the input function but adds the "password" type * - * @access public * @param mixed * @param string * @param string @@ -221,7 +214,6 @@ if ( ! function_exists('form_password')) * * Identical to the input function but adds the "file" type * - * @access public * @param mixed * @param string * @param string @@ -246,7 +238,6 @@ if ( ! function_exists('form_upload')) /** * Textarea field * - * @access public * @param mixed * @param string * @param string @@ -256,7 +247,7 @@ if ( ! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '40', 'rows' => '10'); + $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'cols' => '40', 'rows' => '10'); if ( ! is_array($data) OR ! isset($data['value'])) { @@ -268,7 +259,7 @@ if ( ! function_exists('form_textarea')) unset($data['value']); // textareas don't use the value attribute } - $name = (is_array($data)) ? $data['name'] : $data; + $name = is_array($data) ? $data['name'] : $data; return '\n"; } } @@ -278,12 +269,11 @@ if ( ! function_exists('form_textarea')) /** * Multi-select menu * - * @access public * @param string * @param array * @param mixed * @param string - * @return type + * @return string */ if ( ! function_exists('form_multiselect')) { @@ -303,7 +293,6 @@ if ( ! function_exists('form_multiselect')) /** * Drop-down Menu * - * @access public * @param string * @param array * @param string @@ -314,28 +303,16 @@ if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - // If name is really an array then we'll call the function again using the array - if (is_array($name) && isset($name['name'])) - { - - if ( ! isset($name['options'])) - { - $name['options'] = array(); - } - - if ( ! isset($name['selected'])) - { - $name['selected'] = array(); - } - - if ( ! isset($name['extra'])) - { - $name['extra'] = ''; - } - - return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); - } - + // If name is really an array then we'll call the function again using the array + if (is_array($name) && isset($name['name'])) + { + isset($name['options']) OR $name['options'] = array(); + isset($name['selected']) OR $name['selected'] = array(); + isset($name['extra']) OR $name['extra'] = array(); + + return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); + } + if ( ! is_array($selected)) { $selected = array($selected); @@ -363,11 +340,11 @@ if ( ! function_exists('form_dropdown')) foreach ($val as $optgroup_key => $optgroup_val) { - $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; + $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; $form .= '\n"; } - $form .= ''."\n"; + $form .= "\n"; } else { @@ -375,9 +352,7 @@ if ( ! function_exists('form_dropdown')) } } - $form .= "\n"; - - return $form; + return $form."\n"; } } @@ -386,7 +361,6 @@ if ( ! function_exists('form_dropdown')) /** * Checkbox Field * - * @access public * @param mixed * @param string * @param bool @@ -397,9 +371,9 @@ if ( ! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); - if (is_array($data) AND array_key_exists('checked', $data)) + if (is_array($data) && array_key_exists('checked', $data)) { $checked = $data['checked']; @@ -431,7 +405,6 @@ if ( ! function_exists('form_checkbox')) /** * Radio Button * - * @access public * @param mixed * @param string * @param bool @@ -457,7 +430,6 @@ if ( ! function_exists('form_radio')) /** * Submit Button * - * @access public * @param mixed * @param string * @param string @@ -467,7 +439,7 @@ if ( ! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'submit', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); return '\n"; } } @@ -477,7 +449,6 @@ if ( ! function_exists('form_submit')) /** * Reset Button * - * @access public * @param mixed * @param string * @param string @@ -487,7 +458,7 @@ if ( ! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'reset', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); return '\n"; } } @@ -497,7 +468,6 @@ if ( ! function_exists('form_reset')) /** * Form Button * - * @access public * @param mixed * @param string * @param string @@ -507,8 +477,8 @@ 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'])) + $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'type' => 'button'); + if (is_array($data) && isset($data['content'])) { $content = $data['content']; unset($data['content']); // content is not an attribute @@ -523,7 +493,6 @@ if ( ! function_exists('form_button')) /** * Form Label Tag * - * @access public * @param string The text to appear onscreen * @param string The id the label applies to * @param string Additional attributes @@ -538,10 +507,10 @@ if ( ! function_exists('form_label')) if ($id != '') { - $label .= " for=\"$id\""; + $label .= ' for="'.$id.'"'; } - if (is_array($attributes) AND count($attributes) > 0) + if (is_array($attributes) && count($attributes) > 0) { foreach ($attributes as $key => $val) { @@ -549,7 +518,7 @@ if ( ! function_exists('form_label')) } } - return $label .= ">$label_text"; + return $label.'>'.$label_text.''; } } @@ -560,7 +529,6 @@ if ( ! function_exists('form_label')) * Used to produce
text. To close fieldset * use form_fieldset_close() * - * @access public * @param string The legend text * @param string Additional attributes * @return string @@ -572,7 +540,7 @@ if ( ! function_exists('form_fieldset')) $fieldset = '\n"; if ($legend_text != '') { - $fieldset .= "$legend_text\n"; + return $fieldset.''.$legend_text."\n"; } return $fieldset; @@ -584,7 +552,6 @@ if ( ! function_exists('form_fieldset')) /** * Fieldset Close Tag * - * @access public * @param string * @return string */ @@ -592,7 +559,7 @@ if ( ! function_exists('form_fieldset_close')) { function form_fieldset_close($extra = '') { - return "
".$extra; + return ''.$extra; } } @@ -601,7 +568,6 @@ if ( ! function_exists('form_fieldset_close')) /** * Form Close Tag * - * @access public * @param string * @return string */ @@ -609,7 +575,7 @@ if ( ! function_exists('form_close')) { function form_close($extra = '') { - return "
".$extra; + return ''.$extra; } } @@ -670,10 +636,9 @@ if ( ! function_exists('form_prep')) * Form Value * * Grabs a value from the POST array for the specified field so you can - * re-populate an input field or textarea. If Form Validation + * re-populate an input field or textarea. If Form Validation * is active it retrieves the info from the validation class * - * @access public * @param string * @return mixed */ @@ -703,7 +668,6 @@ if ( ! function_exists('set_value')) * Let's you set the selected value of a