From 4921fed6c17a54efd4fac0bed4d058463bd9b601 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Jan 2012 01:28:07 +0200 Subject: Improve the smiley, string & text helpers --- system/helpers/smiley_helper.php | 97 ++++++++++++---------------- system/helpers/string_helper.php | 81 +++++++++--------------- system/helpers/text_helper.php | 133 +++++++++++++++++++-------------------- 3 files changed, 134 insertions(+), 177 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 700f4486c..bc265e552 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,13 +1,13 @@ - $id) { - foreach ($alias as $name => $id) - { - $m[] = '"'.$name.'" : "'.$id.'"'; - } + $m[] = '"'.$name.'" : "'.$id.'"'; } + } - $m = '{'.implode(',', $m).'}'; + $m = '{'.implode(',', $m).'}'; - $r .= <</*'; - } - else - { - return $r; - } + return ($inline) ? '' : $r; } } @@ -154,12 +145,9 @@ if ( ! function_exists('get_clickable_smileys')) $smileys = $alias; } - if ( ! is_array($smileys)) + if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())) { - if (FALSE === ($smileys = _get_smiley_array())) - { - return $smileys; - } + return $smileys; } // Add a trailing slash to the file path if needed @@ -178,7 +166,6 @@ if ( ! function_exists('get_clickable_smileys')) } $link[] = "\"".$smileys[$key][3]."\""; - $used[$smileys[$key][0]] = TRUE; } @@ -207,16 +194,13 @@ if ( ! function_exists('parse_smileys')) return $str; } - if ( ! is_array($smileys)) + if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())) { - if (FALSE === ($smileys = _get_smiley_array())) - { - return $str; - } + return $str; } // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); + $image_url = rtrim($image_url, '/').'/'; foreach ($smileys as $key => $val) { @@ -249,7 +233,7 @@ if ( ! function_exists('_get_smiley_array')) { include(APPPATH.'config/smileys.php'); } - + if (isset($smileys) AND is_array($smileys)) { return $smileys; @@ -288,6 +272,5 @@ EOF; } } - /* End of file smiley_helper.php */ -/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/smiley_helper.php */ diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 04d51c2f9..654f721b0 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,13 +1,13 @@ -load->helper('security'); - - return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); - break; + case 'basic': return mt_rand(); + case 'alnum': + case 'numeric': + case 'nozero': + case 'alpha': + switch ($type) + { + case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + break; + case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + break; + case 'numeric': $pool = '0123456789'; + break; + case 'nozero': $pool = '123456789'; + break; + } + return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len); + case 'unique': + case 'md5': return md5(uniqid(mt_rand())); + case 'encrypt': + case 'sha1': + $CI =& get_instance(); + $CI->load->helper('security'); + return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); } } } @@ -262,7 +245,6 @@ if ( ! function_exists('random_string')) function increment_string($str, $separator = '_', $first = 1) { preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); - return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; } @@ -311,6 +293,5 @@ 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 */ diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 842a31d75..562270f96 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1,13 +1,13 @@ -","\"", "'", "-"), - $str); + return str_replace(array('&', '<', '>', '"', ''', '-'), + array('&', '<', '>', '"', "'", '-'), + $str); } return $str; @@ -294,42 +294,38 @@ if ( ! function_exists('highlight_code')) { function highlight_code($str) { - // The highlight string function encodes and highlights - // brackets so we need them to start raw - $str = str_replace(array('<', '>'), array('<', '>'), $str); - - // Replace any existing PHP tags to temporary markers so they don't accidentally - // break the string out of PHP, and thus, thwart the highlighting. - - $str = str_replace(array('', '<%', '%>', '\\', ''), - array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); + /* The highlight string function encodes and highlights + * brackets so we need them to start raw. + * + * Also replace any existing PHP tags to temporary markers + * so they don't accidentally break the string out of PHP, + * and thus, thwart the highlighting. + */ + $str = str_replace(array('<', '>', '', '<%', '%>', '\\', ''), + array('<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + $str); // The highlight_string function requires that the text be surrounded // by PHP tags, which we will remove later - $str = ''; // tags - // so we'll replace them with tags. - - if (abs(PHP_VERSION) < 5) - { - $str = str_replace(array(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } + $str = highlight_string('', TRUE); // Remove our artificially added PHP, and the syntax highlighting that came with it - $str = preg_replace('/<\?php( | )/i', '', $str); - $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); - $str = preg_replace('/<\/span>/i', '', $str); + $str = preg_replace(array( + '/<\?php( | )/i', + '/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', + '/<\/span>/i' + ), + array( + '', + "$1\n\n", + '' + ), + $str); // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), - array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - - return $str; + return str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + array('<?', '?>', '<%', '%>', '\\', '</script>'), + $str); } } @@ -414,12 +410,14 @@ if ( ! function_exists('word_wrap')) { function word_wrap($str, $charlim = '76') { - // Se the character limit + // Set the character limit if ( ! is_numeric($charlim)) + { $charlim = 76; + } // Reduce multiple spaces - $str = preg_replace("| +|", " ", $str); + $str = preg_replace('| +|', ' ', $str); // Standardize newlines if (strpos($str, "\r") !== FALSE) @@ -430,22 +428,22 @@ if ( ! function_exists('word_wrap')) // If the current word is surrounded by {unwrap} tags we'll // strip the entire chunk and replace it with a marker. $unwrap = array(); - if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) + if (preg_match_all('|(\{unwrap\}.+?\{/unwrap\})|s', $str, $matches)) { - for ($i = 0; $i < count($matches['0']); $i++) + for ($i = 0, $c = count($matches[0]); $i < $c; $i++) { - $unwrap[] = $matches['1'][$i]; - $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); + $unwrap[] = $matches[1][$i]; + $str = str_replace($matches[1][$i], '{{unwrapped'.$i.'}}', $str); } } // Use PHP's native function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. + // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them - $output = ""; + $output = ''; foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? @@ -460,7 +458,7 @@ if ( ! function_exists('word_wrap')) while ((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it - if (preg_match("!\[url.+\]|://|wwww.!", $line)) + if (preg_match('!\[url.+\]|://|wwww.!', $line)) { break; } @@ -474,14 +472,12 @@ if ( ! function_exists('word_wrap')) // word into smaller chunks so we'll add it back to our current line if ($temp != '') { - $output .= $temp."\n".$line; + $output .= $temp."\n".$line."\n"; } else { - $output .= $line; + $output .= $line."\n"; } - - $output .= "\n"; } // Put our markers back @@ -489,14 +485,12 @@ if ( ! function_exists('word_wrap')) { foreach ($unwrap as $key => $val) { - $output = str_replace("{{unwrapped".$key."}}", $val, $output); + $output = str_replace('{{unwrapped'.$key.'}}', $val, $output); } } - // Remove the unwrap tags - $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - - return $output; + // Remove the unwrap tags and return + return str_replace(array('{unwrap}', '{/unwrap}'), '', $output); } } @@ -527,7 +521,6 @@ if ( ! function_exists('ellipsize')) } $beg = substr($str, 0, floor($max_length * $position)); - $position = ($position > 1) ? 1 : $position; if ($position === 1) @@ -544,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 fc443553248af8ac0c1cbb635fe9cbb70fdf7b82 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Jan 2012 02:14:55 +0200 Subject: Remove quotes around an integer value --- 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 562270f96..3a847f29b 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -408,7 +408,7 @@ if ( ! function_exists('convert_accented_characters')) */ if ( ! function_exists('word_wrap')) { - function word_wrap($str, $charlim = '76') + function word_wrap($str, $charlim = 76) { // Set the character limit if ( ! is_numeric($charlim)) -- cgit v1.2.3-24-g4f1b From cb324bd9268fc6b0c93fd22545bd989771d68b04 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 07:06:35 +0200 Subject: Some more misc. stuff --- system/helpers/smiley_helper.php | 2 -- system/helpers/string_helper.php | 17 +++++++++-------- system/helpers/text_helper.php | 8 +++----- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index bc265e552..03f3ee287 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Smiley Helpers * diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 654f721b0..fcdb0aa84 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter String Helpers * @@ -153,7 +151,7 @@ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) { - return preg_replace("#(^|[^:])//+#", "\\1/", $str); + return preg_replace('#(^|[^:])//+#', '\\1/', $str); } } @@ -181,7 +179,6 @@ if ( ! function_exists('reduce_multiples')) function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); - return ($trim === TRUE) ? trim($str, $character) : $str; } } @@ -211,13 +208,17 @@ if ( ! function_exists('random_string')) case 'alpha': switch ($type) { - case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + case 'alpha': + $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; - case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + case 'alnum': + $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; - case 'numeric': $pool = '0123456789'; + case 'numeric': + $pool = '0123456789'; break; - case 'nozero': $pool = '123456789'; + case 'nozero': + $pool = '123456789'; break; } return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len); diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 3a847f29b..cef32847d 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Text Helpers * @@ -93,7 +91,7 @@ if ( ! function_exists('character_limiter')) return $str; } - $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); + $str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { @@ -108,7 +106,7 @@ if ( ! function_exists('character_limiter')) if (strlen($out) >= $n) { $out = trim($out); - return (strlen($out) == strlen($str)) ? $out : $out.$end_char; + return (strlen($out) === strlen($str)) ? $out : $out.$end_char; } } } @@ -354,7 +352,7 @@ if ( ! function_exists('highlight_phrase')) if ($phrase != '') { - return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); + return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open.'\\1'.$tag_close, $str); } return $str; -- cgit v1.2.3-24-g4f1b From 2139ecdbe882dee32f60de5aec74ec2b8a509b7a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 11 Jan 2012 23:58:50 +0200 Subject: Added date_range() to the Date helper --- system/helpers/date_helper.php | 166 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 9e58d8630..4a0791a43 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -695,5 +695,169 @@ if ( ! function_exists('timezones')) } } +// ------------------------------------------------------------------------ + +/** + * Date range + * + * Returns a list of dates within a specified period. + * + * @access public + * @param int unix_start UNIX timestamp of period start date + * @param int unix_end|days UNIX timestamp of period end date + * or interval in days. + * @param mixed is_unix Specifies wether the second @param + * is a UNIX timestamp or day interval + * - TRUE or 'unix' for a timestamp + * - FALSE or 'days' for an interval + * @param string date_format Output date format, same as in date() + * @return array + */ +if ( ! function_exists('date_range')) +{ + function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d') + { + if ($unix_start == '' OR $mixed == '' OR $format == '') + { + return FALSE; + } + + $is_unix = ! ( ! $is_unix OR $is_unix === 'days'); + + // Validate input and try strtotime() on invalid timestamps/intervals, just in case + if ( ( ! preg_match('/^[0-9]+$/', $unix_start) && ($unix_start = @strtotime($unix_time)) === FALSE) + OR ( ! preg_match('/^[0-9]+$/', $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE)) + OR ($is_unix === TRUE && $mixed < $unix_start)) + { + return FALSE; + } + + if ($is_unix && ($unix_start == $mixed OR date($format, $unix_start) === date($format, $mixed))) + { + return array($start_date); + } + + $range = array(); + + if (is_php('5.2')) + { + /* NOTE: Even though the DateTime object has many useful features, it appears that + * it doesn't always handle properly timezones, when timestamps are passed + * directly to its constructor. Neither of the following gave proper results: + * + * new DateTime('') + * new DateTime('', '') + * + * --- available in PHP 5.3: + * + * DateTime::createFromFormat('', '') + * DateTime::createFromFormat('', '', 'setTimestamp($unix_start); + if ($is_unix) + { + $arg = new DateTime(); + $arg->setTimestamp($mixed); + } + else + { + $arg = (int) $mixed; + } + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); + $range = array(); + foreach ($period as $date) + { + $range[] = $date->format($format); + } + + /* If a period end date was passed to the DatePeriod constructor, it might not + * be in our results. Not sure if this is a bug or it's just possible because + * the end date might actually be less than 24 hours away from the previously + * generated DateTime object, but either way - we have to append it manually. + */ + if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) + { + $range[] = $arg->format($format); + } + + return $range; + } + + $from->setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); + $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); + if ($is_unix) + { + $arg = new DateTime(); + $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); + $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); + } + else + { + $arg = (int) $mixed; + } + $range[] = $from->format($format); + + if (is_int($arg)) // Day intervals + { + do + { + $from->modify('+1 day'); + $range[] = $from->format($format); + } + while (--$arg > 0); + } + else // end date UNIX timestamp + { + for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day')) + { + $range[] = $from->format($format); + } + + // Our loop only appended dates prior to our end date + $range[] = $arg->format($format); + } + + return $range; + } + + /* ---------------------------------------------------------------------------------- + * PHP Version is < 5.2. We have no other option, but to calculate manually ... + * + * NOTE: If we do something like this: + * + * $unix_timestamp + 86400 + * + * ... due to DST, there's a possibility of calculation errors and/or incorrect + * hours generated (if the specified format displays such data) due to DST. + */ + + $from = $to = array(); + sscanf(date('Y-n-j G:i:s', $unix_start), '%d-%d-%d %d:%d:%d', $from['y'], $from['mo'], $from['d'], $from['h'], $from['mi'], $from['s']); + + // If we don't have the end timestamp, let mktime() calculate it + $unix_end = ($is_unix) ? (int) $mixed : mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'] + $mixed, $from['y']); + + $end_check = date('Ymd', $unix_end); + while (date('Ymd', $unix_start = mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'], $from['y'])) !== $end_check) + { + $range[] = date($format, $unix_start); + $from['d']++; + } + + // Our loop only appended dates prior to our end date + $range[] = date($format, $unix_end); + + return $range; + } +} + /* End of file date_helper.php */ -/* Location: ./system/helpers/date_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/date_helper.php */ -- cgit v1.2.3-24-g4f1b From 4f553dfe20a3dcb2d384fe30210d85cf4f645de2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 15 Jan 2012 15:03:02 +0200 Subject: Remove a space :) --- system/helpers/date_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 4a0791a43..7bec8079d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -745,7 +745,7 @@ if ( ! function_exists('date_range')) * it doesn't always handle properly timezones, when timestamps are passed * directly to its constructor. Neither of the following gave proper results: * - * new DateTime('') + * new DateTime('') * new DateTime('', '') * * --- available in PHP 5.3: -- cgit v1.2.3-24-g4f1b From 0f2ec5bde259b67f66cc353692d71d8a47f71b01 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 16 Jan 2012 14:02:24 +0200 Subject: convert_accented_characters() to include foreign_chars.php only when needed --- system/helpers/text_helper.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index cef32847d..8e308b722 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -372,18 +372,23 @@ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($str) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); - } - elseif (is_file(APPPATH.'config/foreign_chars.php')) - { - include(APPPATH.'config/foreign_chars.php'); - } + global $foreign_characters; - if ( ! isset($foreign_characters)) + if ( ! isset($foreign_characters) OR ! is_array($foreign_characters)) { - return $str; + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); + } + elseif (is_file(APPPATH.'config/foreign_chars.php')) + { + include(APPPATH.'config/foreign_chars.php'); + } + + if ( ! isset($foreign_characters) OR ! is_array($foreign_chars)) + { + return $str; + } } return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str); -- cgit v1.2.3-24-g4f1b From 09375d71aa933ac6ba3665f7ccc6949840177ade Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 14:57:46 +0200 Subject: Some more cleaning --- system/helpers/smiley_helper.php | 39 ++++++++++++--------------------------- system/helpers/string_helper.php | 32 +++++++++++++++----------------- system/helpers/text_helper.php | 8 ++++---- 3 files changed, 31 insertions(+), 48 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 03f3ee287..d2b8936ae 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_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 @@ -40,7 +40,7 @@ /** * Smiley Javascript * - * Returns the javascript required for the smiley insertion. Optionally takes + * Returns the javascript required for the smiley insertion. Optionally takes * an array of aliases to loosely couple the smiley array to the view. * * @access public @@ -105,14 +105,11 @@ if ( ! function_exists('smiley_js')) } EOF; } - else + elseif (is_array($alias)) { - if (is_array($alias)) + foreach ($alias as $name => $id) { - foreach ($alias as $name => $id) - { - $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n"; - } + $r .= 'smiley_map["'.$name.'"] = "'.$id."\";\n"; } } @@ -137,13 +134,11 @@ if ( ! function_exists('get_clickable_smileys')) function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) { // For backward compatibility with js_insert_smiley - if (is_array($alias)) { $smileys = $alias; } - - if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())) + elseif (FALSE === ($smileys = _get_smiley_array())) { return $smileys; } @@ -155,7 +150,7 @@ if ( ! function_exists('get_clickable_smileys')) foreach ($smileys as $key => $val) { // Keep duplicates from being used, which can happen if the - // mapping array contains multiple identical replacements. For example: + // mapping array contains multiple identical replacements. For example: // :-) and :) might be replaced with the same image so both smileys // will be in the array. if (isset($used[$smileys[$key][0]])) @@ -163,7 +158,7 @@ if ( ! function_exists('get_clickable_smileys')) continue; } - $link[] = "\"".$smileys[$key][3]."\""; + $link[] = ''.$smileys[$key][3].''; $used[$smileys[$key][0]] = TRUE; } @@ -187,12 +182,7 @@ if ( ! function_exists('parse_smileys')) { function parse_smileys($str = '', $image_url = '', $smileys = NULL) { - if ($image_url == '') - { - return $str; - } - - if ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array())) + if ($image_url == '' OR ( ! is_array($smileys) && FALSE === ($smileys = _get_smiley_array()))) { return $str; } @@ -202,7 +192,7 @@ if ( ! function_exists('parse_smileys')) foreach ($smileys as $key => $val) { - $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); + $str = str_replace($key, ''.$smileys[$key][3].'', $str); } return $str; @@ -223,7 +213,7 @@ if ( ! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) + if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/smileys.php'); } @@ -232,12 +222,7 @@ if ( ! function_exists('_get_smiley_array')) include(APPPATH.'config/smileys.php'); } - if (isset($smileys) AND is_array($smileys)) - { - return $smileys; - } - - return FALSE; + return (isset($smileys) && is_array($smileys)) ? $smileys : FALSE; } } diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index fcdb0aa84..d0948800b 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_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 @@ -75,16 +75,14 @@ if ( ! function_exists('strip_slashes')) { function strip_slashes($str) { - if (is_array($str)) + if ( ! is_array($str)) { - foreach ($str as $key => $val) - { - $str[$key] = strip_slashes($val); - } + return stripslashes($str); } - else + + foreach ($str as $key => $val) { - return stripslashes($str); + $str[$key] = strip_slashes($val); } return $str; @@ -192,7 +190,7 @@ if ( ! function_exists('reduce_multiples')) * * @access public * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 - * @param integer number of characters + * @param int number of characters * @return string */ if ( ! function_exists('random_string')) @@ -238,10 +236,10 @@ if ( ! function_exists('random_string')) /** * Add's _1 to a string or increment the ending number to allow _2, _3, etc * - * @param string $str required - * @param string $separator What should the duplicate number be appended with - * @param string $first Which number should be used for the first dupe increment - * @return string + * @param string $str required + * @param string $separator What should the duplicate number be appended with + * @param string $first Which number should be used for the first dupe increment + * @return string */ function increment_string($str, $separator = '_', $first = 1) { @@ -254,10 +252,10 @@ function increment_string($str, $separator = '_', $first = 1) /** * Alternator * - * Allows strings to be alternated. See docs... + * Allows strings to be alternated. See docs... * * @access public - * @param string (as many parameters as needed) + * @param string (as many parameters as needed) * @return string */ if ( ! function_exists('alternator')) @@ -283,14 +281,14 @@ if ( ! function_exists('alternator')) * * @access public * @param string - * @param integer number of repeats + * @param int number of repeats * @return string */ if ( ! function_exists('repeater')) { function repeater($data, $num = 1) { - return (($num > 0) ? str_repeat($data, $num) : ''); + return ($num > 0) ? str_repeat($data, $num) : ''; } } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8e308b722..2d6da73ac 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_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 @@ -73,7 +73,7 @@ if ( ! function_exists('word_limiter')) /** * Character Limiter * - * Limits the string based on the character count. Preserves complete words + * Limits the string based on the character count. Preserves complete words * so the character count may not be exactly as specified. * * @access public @@ -376,7 +376,7 @@ if ( ! function_exists('convert_accented_characters')) if ( ! isset($foreign_characters) OR ! is_array($foreign_characters)) { - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php'); } @@ -400,7 +400,7 @@ if ( ! function_exists('convert_accented_characters')) /** * Word Wrap * - * Wraps text at the specified character. Maintains the integrity of words. + * Wraps text at the specified character. Maintains the integrity of words. * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * -- cgit v1.2.3-24-g4f1b From c5a1f93ef25c99df4035ef7182a6200b91afabab Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:29:02 +0200 Subject: Revert a space in the license agreement :) --- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index d2b8936ae..cb902114e 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_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/string_helper.php b/system/helpers/string_helper.php index d0948800b..0d1018f53 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_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/text_helper.php b/system/helpers/text_helper.php index 2d6da73ac..37b5d3178 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_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 8bbb38983b8052e32063244941315fe81199e024 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 21 Feb 2012 22:22:34 +0200 Subject: Removed a second/unnecessary variable initialization and fixed a comment --- system/helpers/date_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 7bec8079d..b186b2acb 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -771,8 +771,8 @@ if ( ! function_exists('date_range')) { $arg = (int) $mixed; } + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); - $range = array(); foreach ($period as $date) { $range[] = $date->format($format); @@ -836,7 +836,7 @@ if ( ! function_exists('date_range')) * $unix_timestamp + 86400 * * ... due to DST, there's a possibility of calculation errors and/or incorrect - * hours generated (if the specified format displays such data) due to DST. + * hours generated (if the specified format displays such data). */ $from = $to = array(); -- cgit v1.2.3-24-g4f1b From 30da39bb5d65c37203c12a42dfc50f7d231fb2d1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 10 Mar 2012 15:49:17 +0200 Subject: Remove PHP 5.1 dependancy check --- system/helpers/date_helper.php | 152 ++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 92 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index a655c1f21..cb15f6df6 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -739,121 +739,89 @@ if ( ! function_exists('date_range')) $range = array(); - if (is_php('5.2')) - { - /* NOTE: Even though the DateTime object has many useful features, it appears that - * it doesn't always handle properly timezones, when timestamps are passed - * directly to its constructor. Neither of the following gave proper results: - * - * new DateTime('') - * new DateTime('', '') - * - * --- available in PHP 5.3: - * - * DateTime::createFromFormat('', '') - * DateTime::createFromFormat('', '', 'setTimestamp($unix_start); - if ($is_unix) - { - $arg = new DateTime(); - $arg->setTimestamp($mixed); - } - else - { - $arg = (int) $mixed; - } - - $period = new DatePeriod($from, new DateInterval('P1D'), $arg); - foreach ($period as $date) - { - $range[] = $date->format($format); - } - - /* If a period end date was passed to the DatePeriod constructor, it might not - * be in our results. Not sure if this is a bug or it's just possible because - * the end date might actually be less than 24 hours away from the previously - * generated DateTime object, but either way - we have to append it manually. - */ - if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) - { - $range[] = $arg->format($format); - } - - return $range; - } + /* NOTE: Even though the DateTime object has many useful features, it appears that + * it doesn't always handle properly timezones, when timestamps are passed + * directly to its constructor. Neither of the following gave proper results: + * + * new DateTime('') + * new DateTime('', '') + * + * --- available in PHP 5.3: + * + * DateTime::createFromFormat('', '') + * DateTime::createFromFormat('', '', 'setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); - $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); + if (is_php('5.3')) + { + $from->setTimestamp($unix_start); if ($is_unix) { $arg = new DateTime(); - $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); - $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); + $arg->setTimestamp($mixed); } else { $arg = (int) $mixed; } - $range[] = $from->format($format); - if (is_int($arg)) // Day intervals + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); + foreach ($period as $date) { - do - { - $from->modify('+1 day'); - $range[] = $from->format($format); - } - while (--$arg > 0); + $range[] = $date->format($format); } - else // end date UNIX timestamp - { - for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day')) - { - $range[] = $from->format($format); - } - // Our loop only appended dates prior to our end date + /* If a period end date was passed to the DatePeriod constructor, it might not + * be in our results. Not sure if this is a bug or it's just possible because + * the end date might actually be less than 24 hours away from the previously + * generated DateTime object, but either way - we have to append it manually. + */ + if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) + { $range[] = $arg->format($format); } return $range; } - /* ---------------------------------------------------------------------------------- - * PHP Version is < 5.2. We have no other option, but to calculate manually ... - * - * NOTE: If we do something like this: - * - * $unix_timestamp + 86400 - * - * ... due to DST, there's a possibility of calculation errors and/or incorrect - * hours generated (if the specified format displays such data). - */ - - $from = $to = array(); - sscanf(date('Y-n-j G:i:s', $unix_start), '%d-%d-%d %d:%d:%d', $from['y'], $from['mo'], $from['d'], $from['h'], $from['mi'], $from['s']); - - // If we don't have the end timestamp, let mktime() calculate it - $unix_end = ($is_unix) ? (int) $mixed : mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'] + $mixed, $from['y']); + $from->setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); + $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); + if ($is_unix) + { + $arg = new DateTime(); + $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); + $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); + } + else + { + $arg = (int) $mixed; + } + $range[] = $from->format($format); - $end_check = date('Ymd', $unix_end); - while (date('Ymd', $unix_start = mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'], $from['y'])) !== $end_check) + if (is_int($arg)) // Day intervals { - $range[] = date($format, $unix_start); - $from['d']++; + do + { + $from->modify('+1 day'); + $range[] = $from->format($format); + } + while (--$arg > 0); } + else // end date UNIX timestamp + { + for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day')) + { + $range[] = $from->format($format); + } - // Our loop only appended dates prior to our end date - $range[] = date($format, $unix_end); + // Our loop only appended dates prior to our end date + $range[] = $arg->format($format); + } return $range; } -- cgit v1.2.3-24-g4f1b From 75124a53cf54f2a8c094756f9189be9159957f28 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 13 Mar 2012 12:47:58 +0200 Subject: Some comments altered --- system/helpers/smiley_helper.php | 5 ----- system/helpers/string_helper.php | 20 +++++++------------- system/helpers/text_helper.php | 29 ++++++++++------------------- 3 files changed, 17 insertions(+), 37 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 83fb863df..bc592f74f 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -43,7 +43,6 @@ * Returns the javascript required for the smiley insertion. Optionally takes * an array of aliases to loosely couple the smiley array to the view. * - * @access public * @param mixed alias name or array of alias->field_id pairs * @param string field_id if alias name was passed in * @return array @@ -125,7 +124,6 @@ EOF; * Returns an array of image tag links that can be clicked to be inserted * into a form field. * - * @access public * @param string the URL to the folder containing the smiley images * @return array */ @@ -173,7 +171,6 @@ if ( ! function_exists('get_clickable_smileys')) * * Takes a string as input and swaps any contained smileys for the actual image * - * @access public * @param string the text to be parsed * @param string the URL to the folder containing the smiley images * @return string @@ -206,7 +203,6 @@ if ( ! function_exists('parse_smileys')) * * Fetches the config/smiley.php file * - * @access private * @return mixed */ if ( ! function_exists('_get_smiley_array')) @@ -235,7 +231,6 @@ if ( ! function_exists('_get_smiley_array')) * * DEPRECATED as of version 1.7.2, use smiley_js instead * - * @access public * @param string form name * @param string field name * @return string diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 6573b9a5d..a53d1b88e 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -48,7 +48,6 @@ * * this/that/theother * - * @access public * @param string * @return string */ @@ -67,7 +66,6 @@ if ( ! function_exists('trim_slashes')) * * Removes slashes contained in a string or in an array * - * @access public * @param mixed string or array * @return mixed string or array */ @@ -96,7 +94,6 @@ if ( ! function_exists('strip_slashes')) * * Removes single and double quotes from a string * - * @access public * @param string * @return string */ @@ -115,7 +112,6 @@ if ( ! function_exists('strip_quotes')) * * Converts single and double quotes to entities * - * @access public * @param string * @return string */ @@ -141,7 +137,6 @@ if ( ! function_exists('quotes_to_entities')) * * http://www.some-site.com/index.php * - * @access public * @param string * @return string */ @@ -166,7 +161,6 @@ if ( ! function_exists('reduce_double_slashes')) * * Fred, Bill, Joe, Jimmy * - * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end @@ -188,7 +182,6 @@ if ( ! function_exists('reduce_multiples')) * * Useful for generating passwords or hashes. * - * @access public * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 * @param int number of characters * @return string @@ -219,7 +212,7 @@ if ( ! function_exists('random_string')) $pool = '123456789'; break; } - return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len); + return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len); case 'unique': case 'md5': return md5(uniqid(mt_rand())); case 'encrypt': @@ -241,10 +234,13 @@ if ( ! function_exists('random_string')) * @param string $first Which number should be used for the first dupe increment * @return string */ -function increment_string($str, $separator = '_', $first = 1) +if ( ! function_exists('increment_string')) { - preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); - return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + function increment_string($str, $separator = '_', $first = 1) + { + preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); + return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first; + } } // ------------------------------------------------------------------------ @@ -254,7 +250,6 @@ function increment_string($str, $separator = '_', $first = 1) * * Allows strings to be alternated. See docs... * - * @access public * @param string (as many parameters as needed) * @return string */ @@ -279,7 +274,6 @@ if ( ! function_exists('alternator')) /** * Repeater function * - * @access public * @param string * @param int number of repeats * @return string diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index bddb112b2..9a56159d9 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -42,9 +42,8 @@ * * Limits a string to X number of words. * - * @access public * @param string - * @param integer + * @param int * @param string the end character. Usually an ellipsis * @return string */ @@ -76,9 +75,8 @@ if ( ! function_exists('word_limiter')) * Limits the string based on the character count. Preserves complete words * so the character count may not be exactly as specified. * - * @access public * @param string - * @param integer + * @param int * @param string the end character. Usually an ellipsis * @return string */ @@ -119,7 +117,6 @@ if ( ! function_exists('character_limiter')) * * Converts High ascii text and MS Word special characters to character entities * - * @access public * @param string * @return string */ @@ -182,7 +179,6 @@ if ( ! function_exists('ascii_to_entities')) * * Converts character entities back to ASCII * - * @access public * @param string * @param bool * @return string @@ -238,7 +234,6 @@ if ( ! function_exists('entities_to_ascii')) * matched words will be converted to #### or to the replacement * word you've submitted. * - * @access public * @param string the text string * @param string the array of censoered words * @param string the optional replacement value @@ -284,7 +279,6 @@ if ( ! function_exists('word_censor')) * * Colorizes code strings * - * @access public * @param string the text string * @return string */ @@ -334,7 +328,6 @@ if ( ! function_exists('highlight_code')) * * Highlights a phrase within a text string * - * @access public * @param string the text string * @param string the phrase you'd like to highlight * @param string the openging tag to precede the phrase with @@ -364,7 +357,6 @@ if ( ! function_exists('highlight_phrase')) /** * Convert Accented Foreign Characters to ASCII * - * @access public * @param string the text string * @return string */ @@ -404,9 +396,8 @@ if ( ! function_exists('convert_accented_characters')) * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * - * @access public * @param string the text string - * @param integer the number of characters to wrap at + * @param int the number of characters to wrap at * @return string */ if ( ! function_exists('word_wrap')) @@ -467,8 +458,8 @@ if ( ! function_exists('word_wrap')) } // Trim the word down - $temp .= substr($line, 0, $charlim-1); - $line = substr($line, $charlim-1); + $temp .= substr($line, 0, $charlim - 1); + $line = substr($line, $charlim - 1); } // If $temp contains data it means we had to split up an over-length @@ -504,11 +495,11 @@ if ( ! function_exists('word_wrap')) * * This function will strip tags from a string, split it at its max_length and ellipsize * - * @param string string to ellipsize - * @param integer max length of string - * @param mixed int (1|0) or float, .5, .2, etc for position to split - * @param string ellipsis ; Default '...' - * @return string ellipsized string + * @param string string to ellipsize + * @param int max length of string + * @param mixed int (1|0) or float, .5, .2, etc for position to split + * @param string ellipsis ; Default '...' + * @return string ellipsized string */ if ( ! function_exists('ellipsize')) { -- cgit v1.2.3-24-g4f1b From ad97736d8249240cba802d33a24b7b11e02488cf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 13 Mar 2012 12:51:50 +0200 Subject: Remove access description comment --- system/helpers/date_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index cb15f6df6..ead0d1723 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -702,7 +702,6 @@ if ( ! function_exists('timezones')) * * Returns a list of dates within a specified period. * - * @access public * @param int unix_start UNIX timestamp of period start date * @param int unix_end|days UNIX timestamp of period end date * or interval in days. -- cgit v1.2.3-24-g4f1b From e79a3b134bb5268106d550934808dd9e404ca515 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 15:41:22 +0200 Subject: Remove EOF newlines --- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index bc592f74f..638100e9c 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -251,4 +251,4 @@ EOF; } /* End of file smiley_helper.php */ -/* Location: ./system/helpers/smiley_helper.php */ +/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index a53d1b88e..e570d5d01 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -287,4 +287,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 diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 9a56159d9..daf31c3d6 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -531,4 +531,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 8310595f0e80f72ac790478b8a7dfc6470051639 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:18:15 +0200 Subject: Changed Date helper to return time() based on the timezone parameter. --- system/helpers/date_helper.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index f1ba364f5..aecc7d90f 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -46,25 +46,19 @@ */ if ( ! function_exists('now')) { - function now() + function now($timezone = NULL) { - $CI =& get_instance(); + $CI =& get_instance(); - if (strtolower($CI->config->item('time_reference')) == 'gmt') - { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + if (is_null($timezone)) + $timezone = $CI->config->item('timezone'); - if (strlen($system_time) < 10) - { - $system_time = time(); - log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); - } + $timezone = new DateTimeZone($timezone); + $now = new DateTime('now', $timezone); + $offset = $timezone->getOffset($now); + $time = time() + $offset; - return $system_time; - } - - return time(); + return $time; } } -- cgit v1.2.3-24-g4f1b From 7bf0a4ff35efc758ef43b3a848e655285946b8b6 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:36:15 +0200 Subject: Added doccumentation for the new date helper. --- system/helpers/date_helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index aecc7d90f..7ff7444e5 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -40,8 +40,10 @@ /** * Get "now" time * - * Returns time() or its GMT equivalent based on the config file preference + * Returns time() based on the timezone parameter or on the "timezone" + * setting * + * @param string * @return int */ if ( ! function_exists('now')) -- cgit v1.2.3-24-g4f1b From 16760bb0d812b951564bd1742af6e622490ca05c Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Tue, 27 Mar 2012 18:51:52 +0200 Subject: Added braces as requested. --- system/helpers/date_helper.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 7ff7444e5..14d973f65 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -53,7 +53,9 @@ if ( ! function_exists('now')) $CI =& get_instance(); if (is_null($timezone)) + { $timezone = $CI->config->item('timezone'); + } $timezone = new DateTimeZone($timezone); $now = new DateTime('now', $timezone); -- cgit v1.2.3-24-g4f1b From d52e3b19eb03bcd38f89ccbf5aae68364f715343 Mon Sep 17 00:00:00 2001 From: Sam Li Date: Mon, 23 Apr 2012 23:04:35 +0800 Subject: Added fix for issue: https://github.com/EllisLab/CodeIgniter/issues/1277 --- system/helpers/download_helper.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 19192a147..18fe96223 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -100,6 +100,9 @@ if ( ! function_exists('force_download')) $x[count($x) - 1] = strtoupper($extension); $filename = implode('.', $x); } + + //Clean output buffer + ob_clean(); // Generate the server headers header('Content-Type: '.$mime); -- cgit v1.2.3-24-g4f1b From bbd9dd3df9d373fbac8560db926a9f70a5bde3b7 Mon Sep 17 00:00:00 2001 From: Sam Li Date: Mon, 23 Apr 2012 23:13:46 +0800 Subject: Tweak to comments to conform to style guide. --- 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 18fe96223..8b87f8179 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -101,7 +101,7 @@ if ( ! function_exists('force_download')) $filename = implode('.', $x); } - //Clean output buffer + // Clean output buffer ob_clean(); // Generate the server headers -- cgit v1.2.3-24-g4f1b From 14c350c77c232ab7a5cf68c30fdbab5cdac2d403 Mon Sep 17 00:00:00 2001 From: st2 Date: Wed, 25 Apr 2012 02:48:49 +0800 Subject: Update system/helpers/file_helper.php --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 3a373efd3..a5aabecd6 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -145,7 +145,7 @@ if ( ! function_exists('delete_files')) { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs); } - elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php))$/', $filename)) + elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @unlink($path.DIRECTORY_SEPARATOR.$filename); } -- cgit v1.2.3-24-g4f1b From 01b129a42b62fd08cd873f44ded026041b560420 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 11:36:50 -0400 Subject: Fix docblocks A-H --- system/helpers/array_helper.php | 56 ++-- system/helpers/captcha_helper.php | 18 +- system/helpers/cookie_helper.php | 64 ++--- system/helpers/date_helper.php | 244 ++++++++--------- system/helpers/directory_helper.php | 23 +- system/helpers/download_helper.php | 20 +- system/helpers/email_helper.php | 28 +- system/helpers/file_helper.php | 197 +++++++------- system/helpers/form_helper.php | 514 ++++++++++++++++++------------------ system/helpers/html_helper.php | 187 ++++++------- 10 files changed, 680 insertions(+), 671 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 6f56d9db9..6a7c8e3c7 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -37,19 +37,19 @@ // ------------------------------------------------------------------------ -/** - * Element - * - * Lets you determine whether an array index is set and whether it has a value. - * If the element is empty it returns FALSE (or whatever you specify as the default value.) - * - * @param string - * @param array - * @param mixed - * @return mixed depends on what the array contains - */ if ( ! function_exists('element')) { + /** + * Element + * + * Lets you determine whether an array index is set and whether it has a value. + * If the element is empty it returns FALSE (or whatever you specify as the default value.) + * + * @param string + * @param array + * @param mixed + * @return mixed depends on what the array contains + */ function element($item, $array, $default = FALSE) { return empty($array[$item]) ? $default : $array[$item]; @@ -58,14 +58,14 @@ if ( ! function_exists('element')) // ------------------------------------------------------------------------ -/** - * Random Element - Takes an array as input and returns a random element - * - * @param array - * @return mixed depends on what the array contains - */ if ( ! function_exists('random_element')) { + /** + * Random Element - Takes an array as input and returns a random element + * + * @param array + * @return mixed depends on what the array contains + */ function random_element($array) { return is_array($array) ? $array[array_rand($array)] : $array; @@ -74,19 +74,19 @@ if ( ! function_exists('random_element')) // -------------------------------------------------------------------- -/** - * Elements - * - * Returns only the array items specified. Will return a default value if - * it is not set. - * - * @param array - * @param array - * @param mixed - * @return mixed depends on what the array contains - */ if ( ! function_exists('elements')) { + /** + * Elements + * + * Returns only the array items specified. Will return a default value if + * it is not set. + * + * @param array + * @param array + * @param mixed + * @return mixed depends on what the array contains + */ function elements($items, $array, $default = FALSE) { $return = array(); diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index bdbc62097..b11670658 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -37,17 +37,17 @@ // ------------------------------------------------------------------------ -/** - * Create CAPTCHA - * - * @param array array of data for the CAPTCHA - * @param string path to create the image in - * @param string URL to the CAPTCHA image folder - * @param string server path to font - * @return string - */ if ( ! function_exists('create_captcha')) { + /** + * Create CAPTCHA + * + * @param array array of data for the CAPTCHA + * @param string path to create the image in + * @param string URL to the CAPTCHA image folder + * @param string server path to font + * @return string + */ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') { $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 06560e723..f396c76b0 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -37,24 +37,24 @@ // ------------------------------------------------------------------------ -/** - * Set cookie - * - * Accepts seven parameters, or you can submit an associative - * array in the first parameter containing all the values. - * - * @param mixed - * @param string the value of the cookie - * @param string the number of seconds until expiration - * @param string the cookie domain. Usually: .yourdomain.com - * @param string the cookie path - * @param string the cookie prefix - * @param bool true makes the cookie secure - * @param bool true makes the cookie accessible via http(s) only (no javascript) - * @return void - */ if ( ! function_exists('set_cookie')) { + /** + * Set cookie + * + * Accepts seven parameters, or you can submit an associative + * array in the first parameter containing all the values. + * + * @param mixed + * @param string the value of the cookie + * @param string the number of seconds until expiration + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @param bool true makes the cookie secure + * @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) { // Set the config file options @@ -65,15 +65,15 @@ if ( ! function_exists('set_cookie')) // -------------------------------------------------------------------- -/** - * Fetch an item from the COOKIE array - * - * @param string - * @param bool - * @return mixed - */ if ( ! function_exists('get_cookie')) { + /** + * Fetch an item from the COOKIE array + * + * @param string + * @param bool + * @return mixed + */ function get_cookie($index = '', $xss_clean = FALSE) { $CI =& get_instance(); @@ -84,17 +84,17 @@ if ( ! function_exists('get_cookie')) // -------------------------------------------------------------------- -/** - * Delete a COOKIE - * - * @param mixed - * @param string the cookie domain. Usually: .yourdomain.com - * @param string the cookie path - * @param string the cookie prefix - * @return void - */ if ( ! function_exists('delete_cookie')) { + /** + * Delete a COOKIE + * + * @param mixed + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @return void + */ function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') { set_cookie($name, '', '', $domain, $path, $prefix); diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index f1ba364f5..531d1d32f 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -37,15 +37,15 @@ // ------------------------------------------------------------------------ -/** - * Get "now" time - * - * Returns time() or its GMT equivalent based on the config file preference - * - * @return int - */ if ( ! function_exists('now')) { + /** + * Get "now" time + * + * Returns time() or its GMT equivalent based on the config file preference + * + * @return int + */ function now() { $CI =& get_instance(); @@ -70,24 +70,24 @@ if ( ! function_exists('now')) // ------------------------------------------------------------------------ -/** - * Convert MySQL Style Datecodes - * - * This function is identical to PHPs date() function, - * except that it allows date codes to be formatted using - * the MySQL style, where each code letter is preceded - * with a percent sign: %Y %m %d etc... - * - * The benefit of doing dates this way is that you don't - * have to worry about escaping your text letters that - * match the date codes. - * - * @param string - * @param int - * @return int - */ if ( ! function_exists('mdate')) { + /** + * Convert MySQL Style Datecodes + * + * This function is identical to PHPs date() function, + * except that it allows date codes to be formatted using + * the MySQL style, where each code letter is preceded + * with a percent sign: %Y %m %d etc... + * + * The benefit of doing dates this way is that you don't + * have to worry about escaping your text letters that + * match the date codes. + * + * @param string + * @param int + * @return int + */ function mdate($datestr = '', $time = '') { if ($datestr == '') @@ -109,17 +109,17 @@ if ( ! function_exists('mdate')) // ------------------------------------------------------------------------ -/** - * Standard Date - * - * Returns a date formatted according to the submitted standard. - * - * @param string the chosen format - * @param int Unix timestamp - * @return string - */ if ( ! function_exists('standard_date')) { + /** + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * @param string the chosen format + * @param int Unix timestamp + * @return string + */ function standard_date($fmt = 'DATE_RFC822', $time = '') { $formats = array( @@ -146,19 +146,19 @@ if ( ! function_exists('standard_date')) // ------------------------------------------------------------------------ -/** - * Timespan - * - * Returns a span of seconds in this format: - * 10 days 14 hours 36 minutes 47 seconds - * - * @param int a number of seconds - * @param int Unix timestamp - * @param int a number of display units - * @return string - */ if ( ! function_exists('timespan')) { + /** + * Timespan + * + * Returns a span of seconds in this format: + * 10 days 14 hours 36 minutes 47 seconds + * + * @param int a number of seconds + * @param int Unix timestamp + * @param int a number of display units + * @return string + */ function timespan($seconds = 1, $time = '', $units = 7) { $CI =& get_instance(); @@ -261,18 +261,18 @@ if ( ! function_exists('timespan')) // ------------------------------------------------------------------------ -/** - * Number of days in a month - * - * Takes a month/year as input and returns the number of days - * for the given month/year. Takes leap years into consideration. - * - * @param int a numeric month - * @param int a numeric year - * @return int - */ if ( ! function_exists('days_in_month')) { + /** + * Number of days in a month + * + * Takes a month/year as input and returns the number of days + * for the given month/year. Takes leap years into consideration. + * + * @param int a numeric month + * @param int a numeric year + * @return int + */ function days_in_month($month = 0, $year = '') { if ($month < 1 OR $month > 12) @@ -300,14 +300,14 @@ if ( ! function_exists('days_in_month')) // ------------------------------------------------------------------------ -/** - * Converts a local Unix timestamp to GMT - * - * @param int Unix timestamp - * @return int - */ if ( ! function_exists('local_to_gmt')) { + /** + * Converts a local Unix timestamp to GMT + * + * @param int Unix timestamp + * @return int + */ function local_to_gmt($time = '') { if ($time == '') @@ -328,20 +328,20 @@ if ( ! function_exists('local_to_gmt')) // ------------------------------------------------------------------------ -/** - * Converts GMT time to a localized value - * - * Takes a Unix timestamp (in GMT) as input, and returns - * at the local value based on the timezone and DST setting - * submitted - * - * @param int Unix timestamp - * @param string timezone - * @param bool whether DST is active - * @return int - */ if ( ! function_exists('gmt_to_local')) { + /** + * Converts GMT time to a localized value + * + * Takes a Unix timestamp (in GMT) as input, and returns + * at the local value based on the timezone and DST setting + * submitted + * + * @param int Unix timestamp + * @param string timezone + * @param bool whether DST is active + * @return int + */ function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) { if ($time == '') @@ -362,14 +362,14 @@ if ( ! function_exists('gmt_to_local')) // ------------------------------------------------------------------------ -/** - * Converts a MySQL Timestamp to Unix - * - * @param int Unix timestamp - * @return int - */ if ( ! function_exists('mysql_to_unix')) { + /** + * Converts a MySQL Timestamp to Unix + * + * @param int Unix timestamp + * @return int + */ function mysql_to_unix($time = '') { // We'll remove certain characters for backward compatibility @@ -394,18 +394,18 @@ if ( ! function_exists('mysql_to_unix')) // ------------------------------------------------------------------------ -/** - * Unix to "Human" - * - * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM - * - * @param int Unix timestamp - * @param bool whether to show seconds - * @param string format: us or euro - * @return string - */ if ( ! function_exists('unix_to_human')) { + /** + * Unix to "Human" + * + * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM + * + * @param int Unix timestamp + * @param bool whether to show seconds + * @param string format: us or euro + * @return string + */ function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; @@ -435,16 +435,16 @@ if ( ! function_exists('unix_to_human')) // ------------------------------------------------------------------------ -/** - * Convert "human" date to GMT - * - * Reverses the above process - * - * @param string format: us or euro - * @return int - */ if ( ! function_exists('human_to_unix')) { + /** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @param string format: us or euro + * @return int + */ function human_to_unix($datestr = '') { if ($datestr == '') @@ -509,16 +509,16 @@ if ( ! function_exists('human_to_unix')) // ------------------------------------------------------------------------ -/** - * Turns many "reasonably-date-like" strings into something - * that is actually useful. This only works for dates after unix epoch. - * - * @param string The terribly formatted date-like string - * @param string Date format to return (same as php date function) - * @return string - */ if ( ! function_exists('nice_date')) { + /** + * Turns many "reasonably-date-like" strings into something + * that is actually useful. This only works for dates after unix epoch. + * + * @param string The terribly formatted date-like string + * @param string Date format to return (same as php date function) + * @return string + */ function nice_date($bad_date = '', $format = FALSE) { if (empty($bad_date)) @@ -575,18 +575,18 @@ if ( ! function_exists('nice_date')) // ------------------------------------------------------------------------ -/** - * Timezone Menu - * - * Generates a drop-down menu of timezones. - * - * @param string timezone - * @param string classname - * @param string menu name - * @return string - */ if ( ! function_exists('timezone_menu')) { + /** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @param string timezone + * @param string classname + * @param string menu name + * @return string + */ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { $CI =& get_instance(); @@ -617,17 +617,17 @@ if ( ! function_exists('timezone_menu')) // ------------------------------------------------------------------------ -/** - * Timezones - * - * Returns an array of timezones. This is a helper function - * for various other ones in this library - * - * @param string timezone - * @return string - */ if ( ! function_exists('timezones')) { + /** + * Timezones + * + * Returns an array of timezones. This is a helper function + * for various other ones in this library + * + * @param string timezone + * @return string + */ function timezones($tz = '') { // Note: Don't change the order of these even though diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 4044ace11..bda8fe8bb 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -37,19 +37,20 @@ // ------------------------------------------------------------------------ -/** - * Create a Directory Map - * - * Reads the specified directory and builds an array - * representation of it. Sub-folders contained with the - * directory will be mapped as well. - * - * @param string path to source - * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) - * @return array - */ if ( ! function_exists('directory_map')) { + /** + * Create a Directory Map + * + * Reads the specified directory and builds an array + * representation of it. Sub-folders contained with the + * directory will be mapped as well. + * + * @param string path to source + * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) + * @param bool whether to show hidden files + * @return array + */ function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) { if ($fp = @opendir($source_dir)) diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 8b87f8179..97e6986b0 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -37,18 +37,18 @@ // ------------------------------------------------------------------------ -/** - * Force Download - * - * Generates headers that force a download to happen - * - * @param string filename - * @param mixed the data to be downloaded - * @param bool wether to try and send the actual file MIME type - * @return void - */ if ( ! function_exists('force_download')) { + /** + * Force Download + * + * Generates headers that force a download to happen + * + * @param string filename + * @param mixed the data to be downloaded + * @param bool wether to try and send the actual file MIME type + * @return void + */ function force_download($filename = '', $data = '', $set_mime = FALSE) { if ($filename == '' OR $data == '') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 497625c10..0516e938a 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -37,14 +37,14 @@ // ------------------------------------------------------------------------ -/** - * Validate email address - * - * @param string - * @return bool - */ if ( ! function_exists('valid_email')) { + /** + * Validate email address + * + * @param string + * @return bool + */ function valid_email($address) { return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address); @@ -53,16 +53,16 @@ if ( ! function_exists('valid_email')) // ------------------------------------------------------------------------ -/** - * Send an email - * - * @param string - * @param string - * @param string - * @return bool - */ if ( ! function_exists('send_email')) { + /** + * Send an email + * + * @param string + * @param string + * @param string + * @return bool + */ function send_email($recipient, $subject = 'Test email', $message = 'Hello World') { return mail($recipient, $subject, $message); diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index a5aabecd6..fb4503479 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -37,16 +37,16 @@ // ------------------------------------------------------------------------ -/** - * Read File - * - * Opens the file specfied in the path and returns it as a string. - * - * @param string path to file - * @return string - */ if ( ! function_exists('read_file')) { + /** + * Read File + * + * Opens the file specfied in the path and returns it as a string. + * + * @param string path to file + * @return string + */ function read_file($file) { if ( ! file_exists($file)) @@ -81,18 +81,19 @@ if ( ! function_exists('read_file')) // ------------------------------------------------------------------------ -/** - * Write File - * - * Writes data to the file specified in the path. - * Creates a new file if non-existent. - * - * @param string path to file - * @param string file data - * @return bool - */ if ( ! function_exists('write_file')) { + /** + * Write File + * + * Writes data to the file specified in the path. + * Creates a new file if non-existent. + * + * @param string path to file + * @param string file data + * @param int + * @return bool + */ function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { if ( ! $fp = @fopen($path, $mode)) @@ -111,22 +112,22 @@ if ( ! function_exists('write_file')) // ------------------------------------------------------------------------ -/** - * Delete Files - * - * Deletes all files contained in the supplied directory path. - * Files must be writable or owned by the system in order to be deleted. - * If the second parameter is set to TRUE, any directories contained - * within the supplied base directory will be nuked as well. - * - * @param string path to file - * @param bool whether to delete any directories found in the path - * @param int - * @param bool whether to skip deleting .htaccess and index page files - * @return bool - */ if ( ! function_exists('delete_files')) { + /** + * Delete Files + * + * Deletes all files contained in the supplied directory path. + * Files must be writable or owned by the system in order to be deleted. + * If the second parameter is set to TRUE, any directories contained + * within the supplied base directory will be nuked as well. + * + * @param string path to file + * @param bool whether to delete any directories found in the path + * @param int + * @param bool whether to skip deleting .htaccess and index page files + * @return bool + */ function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE) { // Trim the trailing slash @@ -164,19 +165,19 @@ if ( ! function_exists('delete_files')) // ------------------------------------------------------------------------ -/** - * Get Filenames - * - * Reads the specified directory and builds an array containing the filenames. - * Any sub-folders contained within the specified path are read as well. - * - * @param string path to source - * @param bool whether to include the path as part of the filename - * @param bool internal variable to determine recursion status - do not use in calls - * @return array - */ if ( ! function_exists('get_filenames')) { + /** + * Get Filenames + * + * Reads the specified directory and builds an array containing the filenames. + * Any sub-folders contained within the specified path are read as well. + * + * @param string path to source + * @param bool whether to include the path as part of the filename + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); @@ -212,21 +213,21 @@ if ( ! function_exists('get_filenames')) // -------------------------------------------------------------------- -/** - * Get Directory File Information - * - * Reads the specified directory and builds an array containing the filenames, - * filesize, dates, and permissions - * - * Any sub-folders contained within the specified path are read as well. - * - * @param string path to source - * @param bool Look only at the top level directory specified? - * @param bool internal variable to determine recursion status - do not use in calls - * @return array - */ if ( ! function_exists('get_dir_file_info')) { + /** + * Get Directory File Information + * + * Reads the specified directory and builds an array containing the filenames, + * filesize, dates, and permissions + * + * Any sub-folders contained within the specified path are read as well. + * + * @param string path to source + * @param bool Look only at the top level directory specified? + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) { static $_filedata = array(); @@ -265,20 +266,20 @@ if ( ! function_exists('get_dir_file_info')) // -------------------------------------------------------------------- -/** -* Get File Info -* -* Given a file and path, returns the name, path, size, date modified -* Second parameter allows you to explicitly declare what information you want returned -* Options are: name, server_path, size, date, readable, writable, executable, fileperms -* Returns FALSE if the file cannot be found. -* -* @param string path to file -* @param mixed array or comma separated string of information returned -* @return array -*/ if ( ! function_exists('get_file_info')) { + /** + * Get File Info + * + * Given a file and path, returns the name, path, size, date modified + * Second parameter allows you to explicitly declare what information you want returned + * Options are: name, server_path, size, date, readable, writable, executable, fileperms + * Returns FALSE if the file cannot be found. + * + * @param string path to file + * @param mixed array or comma separated string of information returned + * @return array + */ function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) { @@ -330,20 +331,20 @@ if ( ! function_exists('get_file_info')) // -------------------------------------------------------------------- -/** - * Get Mime by Extension - * - * Translates a file extension into a mime type based on config/mimes.php. - * Returns FALSE if it can't determine the type, or open the mime config file - * - * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience - * It should NOT be trusted, and should certainly NOT be used for security - * - * @param string path to file - * @return mixed - */ if ( ! function_exists('get_mime_by_extension')) { + /** + * Get Mime by Extension + * + * Translates a file extension into a mime type based on config/mimes.php. + * Returns FALSE if it can't determine the type, or open the mime config file + * + * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience + * It should NOT be trusted, and should certainly NOT be used for security + * + * @param string path to file + * @return mixed + */ function get_mime_by_extension($file) { $extension = strtolower(substr(strrchr($file, '.'), 1)); @@ -386,17 +387,17 @@ if ( ! function_exists('get_mime_by_extension')) // -------------------------------------------------------------------- -/** - * Symbolic Permissions - * - * Takes a numeric value representing a file's permissions and returns - * standard symbolic notation representing that value - * - * @param int - * @return string - */ if ( ! function_exists('symbolic_permissions')) { + /** + * Symbolic Permissions + * + * Takes a numeric value representing a file's permissions and returns + * standard symbolic notation representing that value + * + * @param int + * @return string + */ function symbolic_permissions($perms) { if (($perms & 0xC000) === 0xC000) @@ -453,17 +454,17 @@ if ( ! function_exists('symbolic_permissions')) // -------------------------------------------------------------------- -/** - * Octal Permissions - * - * Takes a numeric value representing a file's permissions and returns - * a three character string representing the file's octal permissions - * - * @param int - * @return string - */ if ( ! function_exists('octal_permissions')) { + /** + * Octal Permissions + * + * Takes a numeric value representing a file's permissions and returns + * a three character string representing the file's octal permissions + * + * @param int + * @return string + */ function octal_permissions($perms) { return substr(sprintf('%o', $perms), -3); diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e5b487608..b246d72f3 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -36,18 +36,18 @@ // ------------------------------------------------------------------------ -/** - * Form Declaration - * - * Creates the opening portion of the form. - * - * @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 - * @return string - */ if ( ! function_exists('form_open')) { + /** + * Form Declaration + * + * Creates the opening portion of the form. + * + * @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 + * @return string + */ function form_open($action = '', $attributes = '', $hidden = array()) { $CI =& get_instance(); @@ -85,18 +85,18 @@ if ( ! function_exists('form_open')) // ------------------------------------------------------------------------ -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @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 - * @return string - */ if ( ! function_exists('form_open_multipart')) { + /** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @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 + * @return string + */ function form_open_multipart($action = '', $attributes = array(), $hidden = array()) { if (is_string($attributes)) @@ -114,18 +114,19 @@ 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. - * - * @param mixed - * @param string - * @return string - */ if ( ! function_exists('form_hidden')) { + /** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or + * an associative array with multiple values. + * + * @param mixed + * @param string + * @param bool + * @return string + */ function form_hidden($name, $value = '', $recursing = FALSE) { static $form; @@ -163,16 +164,16 @@ if ( ! function_exists('form_hidden')) // ------------------------------------------------------------------------ -/** - * Text Input Field - * - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_input')) { + /** + * Text Input Field + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_input($data = '', $value = '', $extra = '') { $defaults = array('type' => 'text', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); @@ -183,18 +184,19 @@ if ( ! function_exists('form_input')) // ------------------------------------------------------------------------ -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @param mixed - * @param string - * @param string - * @return string - */ + if ( ! function_exists('form_password')) { + /** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_password($data = '', $value = '', $extra = '') { if ( ! is_array($data)) @@ -209,18 +211,18 @@ if ( ! function_exists('form_password')) // ------------------------------------------------------------------------ -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_upload')) { + /** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_upload($data = '', $value = '', $extra = '') { if ( ! is_array($data)) @@ -235,16 +237,16 @@ if ( ! function_exists('form_upload')) // ------------------------------------------------------------------------ -/** - * Textarea field - * - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_textarea')) { + /** + * Textarea field + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'cols' => '40', 'rows' => '10'); @@ -266,17 +268,17 @@ if ( ! function_exists('form_textarea')) // ------------------------------------------------------------------------ -/** - * Multi-select menu - * - * @param string - * @param array - * @param mixed - * @param string - * @return string - */ if ( ! function_exists('form_multiselect')) { + /** + * Multi-select menu + * + * @param string + * @param array + * @param mixed + * @param string + * @return string + */ function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') { if ( ! strpos($extra, 'multiple')) @@ -290,17 +292,17 @@ if ( ! function_exists('form_multiselect')) // -------------------------------------------------------------------- -/** - * Drop-down Menu - * - * @param string - * @param array - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_dropdown')) { + /** + * Drop-down Menu + * + * @param string + * @param array + * @param string + * @param string + * @return string + */ 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 @@ -358,17 +360,17 @@ if ( ! function_exists('form_dropdown')) // ------------------------------------------------------------------------ -/** - * Checkbox Field - * - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ if ( ! function_exists('form_checkbox')) { + /** + * Checkbox Field + * + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); @@ -402,17 +404,17 @@ if ( ! function_exists('form_checkbox')) // ------------------------------------------------------------------------ -/** - * Radio Button - * - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ if ( ! function_exists('form_radio')) { + /** + * Radio Button + * + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if ( ! is_array($data)) @@ -427,16 +429,16 @@ if ( ! function_exists('form_radio')) // ------------------------------------------------------------------------ -/** - * Submit Button - * - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_submit')) { + /** + * Submit Button + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); @@ -446,16 +448,16 @@ if ( ! function_exists('form_submit')) // ------------------------------------------------------------------------ -/** - * Reset Button - * - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_reset')) { + /** + * Reset Button + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); @@ -465,16 +467,16 @@ if ( ! function_exists('form_reset')) // ------------------------------------------------------------------------ -/** - * Form Button - * - * @param mixed - * @param string - * @param string - * @return string - */ if ( ! function_exists('form_button')) { + /** + * Form Button + * + * @param mixed + * @param string + * @param string + * @return string + */ function form_button($data = '', $content = '', $extra = '') { $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'type' => 'button'); @@ -490,16 +492,16 @@ if ( ! function_exists('form_button')) // ------------------------------------------------------------------------ -/** - * Form Label Tag - * - * @param string The text to appear onscreen - * @param string The id the label applies to - * @param string Additional attributes - * @return string - */ if ( ! function_exists('form_label')) { + /** + * Form Label Tag + * + * @param string The text to appear onscreen + * @param string The id the label applies to + * @param string Additional attributes + * @return string + */ function form_label($label_text = '', $id = '', $attributes = array()) { @@ -523,18 +525,19 @@ if ( ! function_exists('form_label')) } // ------------------------------------------------------------------------ -/** - * Fieldset Tag - * - * Used to produce
text. To close fieldset - * use form_fieldset_close() - * - * @param string The legend text - * @param string Additional attributes - * @return string - */ + if ( ! function_exists('form_fieldset')) { + /** + * Fieldset Tag + * + * Used to produce
text. To close fieldset + * use form_fieldset_close() + * + * @param string The legend text + * @param string Additional attributes + * @return string + */ function form_fieldset($legend_text = '', $attributes = array()) { $fieldset = '\n"; @@ -549,14 +552,14 @@ if ( ! function_exists('form_fieldset')) // ------------------------------------------------------------------------ -/** - * Fieldset Close Tag - * - * @param string - * @return string - */ if ( ! function_exists('form_fieldset_close')) { + /** + * Fieldset Close Tag + * + * @param string + * @return string + */ function form_fieldset_close($extra = '') { return '
'.$extra; @@ -565,14 +568,14 @@ if ( ! function_exists('form_fieldset_close')) // ------------------------------------------------------------------------ -/** - * Form Close Tag - * - * @param string - * @return string - */ if ( ! function_exists('form_close')) { + /** + * Form Close Tag + * + * @param string + * @return string + */ function form_close($extra = '') { return ''.$extra; @@ -581,16 +584,17 @@ if ( ! function_exists('form_close')) // ------------------------------------------------------------------------ -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @param string - * @return string - */ if ( ! function_exists('form_prep')) { + /** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @param string + * @param string + * @return string + */ function form_prep($str = '', $field_name = '') { static $prepped_fields = array(); @@ -631,18 +635,19 @@ 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 - * is active it retrieves the info from the validation class - * - * @param string - * @return mixed - */ if ( ! function_exists('set_value')) { + /** + * 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 + * is active it retrieves the info from the validation class + * + * @param string + * @param string + * @return mixed + */ function set_value($field = '', $default = '') { if (FALSE === ($OBJ =& _get_validation_object())) @@ -661,19 +666,19 @@ if ( ! function_exists('set_value')) // ------------------------------------------------------------------------ -/** - * Set Select - * - * Let's you set the selected value of a menu via data in the POST array. + * If Form Validation is active it retrieves the info from the validation class + * + * @param string + * @param string + * @param bool + * @return string + */ function set_select($field = '', $value = '', $default = FALSE) { $OBJ =& _get_validation_object(); @@ -712,19 +717,19 @@ if ( ! function_exists('set_select')) // ------------------------------------------------------------------------ -/** - * Set Checkbox - * - * Let's you set the selected value of a checkbox via the value in the POST array. - * If Form Validation is active it retrieves the info from the validation class - * - * @param string - * @param string - * @param bool - * @return string - */ if ( ! function_exists('set_checkbox')) { + /** + * Set Checkbox + * + * Let's you set the selected value of a checkbox via the value in the POST array. + * If Form Validation is active it retrieves the info from the validation class + * + * @param string + * @param string + * @param bool + * @return string + */ function set_checkbox($field = '', $value = '', $default = FALSE) { $OBJ =& _get_validation_object(); @@ -763,19 +768,19 @@ if ( ! function_exists('set_checkbox')) // ------------------------------------------------------------------------ -/** - * Set Radio - * - * Let's you set the selected value of a radio field via info in the POST array. - * If Form Validation is active it retrieves the info from the validation class - * - * @param string - * @param string - * @param bool - * @return string - */ if ( ! function_exists('set_radio')) { + /** + * Set Radio + * + * Let's you set the selected value of a radio field via info in the POST array. + * If Form Validation is active it retrieves the info from the validation class + * + * @param string + * @param string + * @param bool + * @return string + */ function set_radio($field = '', $value = '', $default = FALSE) { $OBJ =& _get_validation_object(); @@ -817,19 +822,20 @@ if ( ! function_exists('set_radio')) // ------------------------------------------------------------------------ -/** - * Form Error - * - * Returns the error for a specific form field. This is a helper for the - * form validation class. - * - * @param string - * @param string - * @param string - * @return string - */ + if ( ! function_exists('form_error')) { + /** + * Form Error + * + * Returns the error for a specific form field. This is a helper for the + * form validation class. + * + * @param string + * @param string + * @param string + * @return string + */ function form_error($field = '', $prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) @@ -843,18 +849,18 @@ if ( ! function_exists('form_error')) // ------------------------------------------------------------------------ -/** - * Validation Error String - * - * Returns all the errors associated with a form submission. This is a helper - * function for the form validation class. - * - * @param string - * @param string - * @return string - */ if ( ! function_exists('validation_errors')) { + /** + * Validation Error String + * + * Returns all the errors associated with a form submission. This is a helper + * function for the form validation class. + * + * @param string + * @param string + * @return string + */ function validation_errors($prefix = '', $suffix = '') { if (FALSE === ($OBJ =& _get_validation_object())) @@ -868,17 +874,17 @@ if ( ! function_exists('validation_errors')) // ------------------------------------------------------------------------ -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @param array - * @param array - * @return string - */ if ( ! function_exists('_parse_form_attributes')) { + /** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @param array + * @param array + * @return string + */ function _parse_form_attributes($attributes, $default) { if (is_array($attributes)) @@ -916,17 +922,17 @@ if ( ! function_exists('_parse_form_attributes')) // ------------------------------------------------------------------------ -/** - * Attributes To String - * - * Helper function used by some of the form helpers - * - * @param mixed - * @param bool - * @return string - */ if ( ! function_exists('_attributes_to_string')) { + /** + * Attributes To String + * + * Helper function used by some of the form helpers + * + * @param mixed + * @param bool + * @return string + */ function _attributes_to_string($attributes, $formtag = FALSE) { if (is_string($attributes) && strlen($attributes) > 0) @@ -975,16 +981,16 @@ if ( ! function_exists('_attributes_to_string')) // ------------------------------------------------------------------------ -/** - * Validation Object - * - * Determines what the form validation class was instantiated as, fetches - * the object and returns it. - * - * @return mixed - */ if ( ! function_exists('_get_validation_object')) { + /** + * Validation Object + * + * Determines what the form validation class was instantiated as, fetches + * the object and returns it. + * + * @return mixed + */ function &_get_validation_object() { $CI =& get_instance(); diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 0417bd253..124f58009 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -37,17 +37,18 @@ // ------------------------------------------------------------------------ -/** - * Heading - * - * Generates an HTML heading tag. - * - * @param string content - * @param int heading level - * @return string - */ if ( ! function_exists('heading')) { + /** + * Heading + * + * Generates an HTML heading tag. + * + * @param string content + * @param int heading level + * @param string + * @return string + */ function heading($data = '', $h = '1', $attributes = '') { return ''.$data.''; @@ -56,17 +57,17 @@ if ( ! function_exists('heading')) // ------------------------------------------------------------------------ -/** - * Unordered List - * - * Generates an HTML unordered list from an single or multi-dimensional array. - * - * @param array - * @param mixed - * @return string - */ if ( ! function_exists('ul')) { + /** + * Unordered List + * + * Generates an HTML unordered list from an single or multi-dimensional array. + * + * @param array + * @param mixed + * @return string + */ function ul($list, $attributes = '') { return _list('ul', $list, $attributes); @@ -75,17 +76,17 @@ if ( ! function_exists('ul')) // ------------------------------------------------------------------------ -/** - * Ordered List - * - * Generates an HTML ordered list from an single or multi-dimensional array. - * - * @param array - * @param mixed - * @return string - */ if ( ! function_exists('ol')) { + /** + * Ordered List + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @param array + * @param mixed + * @return string + */ function ol($list, $attributes = '') { return _list('ol', $list, $attributes); @@ -94,19 +95,19 @@ if ( ! function_exists('ol')) // ------------------------------------------------------------------------ -/** - * Generates the list - * - * Generates an HTML ordered list from an single or multi-dimensional array. - * - * @param string - * @param mixed - * @param mixed - * @param int - * @return string - */ if ( ! function_exists('_list')) { + /** + * Generates the list + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @param string + * @param mixed + * @param mixed + * @param int + * @return string + */ function _list($type = 'ul', $list, $attributes = '', $depth = 0) { // If an array wasn't submitted there's nothing to do... @@ -165,14 +166,14 @@ if ( ! function_exists('_list')) // ------------------------------------------------------------------------ -/** - * Generates HTML BR tags based on number supplied - * - * @param int - * @return string - */ if ( ! function_exists('br')) { + /** + * Generates HTML BR tags based on number supplied + * + * @param int + * @return string + */ function br($num = 1) { return str_repeat('
', $num); @@ -181,17 +182,17 @@ if ( ! function_exists('br')) // ------------------------------------------------------------------------ -/** - * Image - * - * Generates an element - * - * @param mixed - * @param bool - * @return string - */ if ( ! function_exists('img')) { + /** + * Image + * + * Generates an element + * + * @param mixed + * @param bool + * @return string + */ function img($src = '', $index_page = FALSE) { if ( ! is_array($src) ) @@ -234,20 +235,20 @@ if ( ! function_exists('img')) // ------------------------------------------------------------------------ -/** - * Doctype - * - * 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 - * doctypes config file. - * - * @param string type The doctype to be generated - * @return string - */ if ( ! function_exists('doctype')) { + /** + * Doctype + * + * 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 + * doctypes config file. + * + * @param string type The doctype to be generated + * @return string + */ function doctype($type = 'xhtml1-strict') { global $_doctypes; @@ -275,21 +276,21 @@ if ( ! function_exists('doctype')) // ------------------------------------------------------------------------ -/** - * Link - * - * Generates link to a CSS file - * - * @param mixed stylesheet hrefs or an array - * @param string rel - * @param string type - * @param string title - * @param string media - * @param bool should index_page be added to the css path - * @return string - */ if ( ! function_exists('link_tag')) { + /** + * Link + * + * Generates link to a CSS file + * + * @param mixed stylesheet hrefs or an array + * @param string rel + * @param string type + * @param string title + * @param string media + * @param bool should index_page be added to the css path + * @return string + */ function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) { $CI =& get_instance(); @@ -350,17 +351,17 @@ if ( ! function_exists('link_tag')) // ------------------------------------------------------------------------ -/** - * Generates meta tags from an array of key/values - * - * @param array - * @param string - * @param string - * @param string - * @return string - */ if ( ! function_exists('meta')) { + /** + * Generates meta tags from an array of key/values + * + * @param array + * @param string + * @param string + * @param string + * @return string + */ function meta($name = '', $content = '', $type = 'name', $newline = "\n") { // Since we allow the data to be passes as a string, a simple array @@ -392,14 +393,14 @@ if ( ! function_exists('meta')) // ------------------------------------------------------------------------ -/** - * Generates non-breaking space entities based on number supplied - * - * @param int - * @return string - */ if ( ! function_exists('nbs')) { + /** + * Generates non-breaking space entities based on number supplied + * + * @param int + * @return string + */ function nbs($num = 1) { return str_repeat(' ', $num); -- cgit v1.2.3-24-g4f1b From b75faa1a03a32330e412f0bd0332fb9fa389e914 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 12:03:32 -0400 Subject: Fix rest of the helpers --- system/helpers/inflector_helper.php | 98 ++++++------- system/helpers/language_helper.php | 18 +-- system/helpers/number_helper.php | 13 +- system/helpers/path_helper.php | 14 +- system/helpers/security_helper.php | 63 ++++---- system/helpers/smiley_helper.php | 103 ++++++-------- system/helpers/string_helper.php | 204 +++++++++++++------------- system/helpers/text_helper.php | 194 ++++++++++++------------- system/helpers/typography_helper.php | 47 +++--- system/helpers/url_helper.php | 268 ++++++++++++++++++----------------- system/helpers/xml_helper.php | 14 +- 11 files changed, 509 insertions(+), 527 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index feeaf57d7..72615671c 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -37,16 +37,16 @@ // -------------------------------------------------------------------- -/** - * Singular - * - * Takes a plural word and makes it singular - * - * @param string - * @return str - */ if ( ! function_exists('singular')) { + /** + * Singular + * + * Takes a plural word and makes it singular + * + * @param string + * @return str + */ function singular($str) { $result = strval($str); @@ -101,17 +101,17 @@ if ( ! function_exists('singular')) // -------------------------------------------------------------------- -/** - * Plural - * - * Takes a singular word and makes it plural - * - * @param string - * @param bool - * @return str - */ if ( ! function_exists('plural')) { + /** + * Plural + * + * Takes a singular word and makes it plural + * + * @param string + * @param bool + * @return str + */ function plural($str, $force = FALSE) { $result = strval($str); @@ -158,16 +158,16 @@ if ( ! function_exists('plural')) // -------------------------------------------------------------------- -/** - * Camelize - * - * Takes multiple words separated by spaces or underscores and camelizes them - * - * @param string - * @return str - */ if ( ! function_exists('camelize')) { + /** + * Camelize + * + * Takes multiple words separated by spaces or underscores and camelizes them + * + * @param string + * @return str + */ function camelize($str) { return strtolower($str[0]).substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1); @@ -176,16 +176,16 @@ if ( ! function_exists('camelize')) // -------------------------------------------------------------------- -/** - * Underscore - * - * Takes multiple words separated by spaces and underscores them - * - * @param string - * @return str - */ if ( ! function_exists('underscore')) { + /** + * Underscore + * + * Takes multiple words separated by spaces and underscores them + * + * @param string + * @return str + */ function underscore($str) { return preg_replace('/[\s]+/', '_', strtolower(trim($str))); @@ -194,31 +194,33 @@ if ( ! function_exists('underscore')) // -------------------------------------------------------------------- -/** - * Humanize - * - * Takes multiple words separated by the separator and changes them to spaces - * - * @param string $str - * @param string $separator - * @return str - */ if ( ! function_exists('humanize')) { + /** + * Humanize + * + * Takes multiple words separated by the separator and changes them to spaces + * + * @param string $str + * @param string $separator + * @return str + */ function humanize($str, $separator = '_') { return ucwords(preg_replace('/['.$separator.']+/', ' ', strtolower(trim($str)))); } } -/** - * Checks if the given word has a plural version. - * - * @param string the word to check - * @return bool if the word is countable - */ +// -------------------------------------------------------------------- + if ( ! function_exists('is_countable')) { + /** + * Checks if the given word has a plural version. + * + * @param string the word to check + * @return bool if the word is countable + */ function is_countable($word) { return ! in_array(strtolower(strval($word)), diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index b31c97107..34f030716 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -37,17 +37,17 @@ // ------------------------------------------------------------------------ -/** - * Lang - * - * Fetches a language variable and optionally outputs a form label - * - * @param string the language line - * @param string the id of the form element - * @return string - */ if ( ! function_exists('lang')) { + /** + * Lang + * + * Fetches a language variable and optionally outputs a form label + * + * @param string the language line + * @param string the id of the form element + * @return string + */ function lang($line, $id = '') { $CI =& get_instance(); diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 40da6e7bf..2a906ba1b 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -37,14 +37,15 @@ // ------------------------------------------------------------------------ -/** - * Formats a numbers as bytes, based on size, and adds the appropriate suffix - * - * @param mixed // will be cast as int - * @return string - */ if ( ! function_exists('byte_format')) { + /** + * Formats a numbers as bytes, based on size, and adds the appropriate suffix + * + * @param mixed // will be cast as int + * @param int + * @return string + */ function byte_format($num, $precision = 1) { $CI =& get_instance(); diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 6ee99072c..13410545c 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -37,15 +37,15 @@ // ------------------------------------------------------------------------ -/** - * Set Realpath - * - * @param string - * @param bool checks to see if the path exists - * @return string - */ if ( ! function_exists('set_realpath')) { + /** + * Set Realpath + * + * @param string + * @param bool checks to see if the path exists + * @return string + */ function set_realpath($path, $check_existance = FALSE) { // Security check to make sure the path is NOT a URL. No remote file inclusion! diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index d6f134c9f..6187a4a7a 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -37,15 +37,15 @@ // ------------------------------------------------------------------------ -/** - * XSS Filtering - * - * @param string - * @param bool whether or not the content is an image file - * @return string - */ if ( ! function_exists('xss_clean')) { + /** + * XSS Filtering + * + * @param string + * @param bool whether or not the content is an image file + * @return string + */ function xss_clean($str, $is_image = FALSE) { $CI =& get_instance(); @@ -55,14 +55,14 @@ if ( ! function_exists('xss_clean')) // ------------------------------------------------------------------------ -/** - * Sanitize Filename - * - * @param string - * @return string - */ if ( ! function_exists('sanitize_filename')) { + /** + * Sanitize Filename + * + * @param string + * @return string + */ function sanitize_filename($filename) { $CI =& get_instance(); @@ -72,14 +72,15 @@ if ( ! function_exists('sanitize_filename')) // -------------------------------------------------------------------- -/** - * Hash encode a string - * - * @param string - * @return string - */ if ( ! function_exists('do_hash')) { + /** + * Hash encode a string + * + * @param string + * @param string + * @return string + */ function do_hash($str, $type = 'sha1') { if ( ! in_array(strtolower($type), hash_algos())) @@ -93,14 +94,14 @@ if ( ! function_exists('do_hash')) // ------------------------------------------------------------------------ -/** - * Strip Image Tags - * - * @param string - * @return string - */ if ( ! function_exists('strip_image_tags')) { + /** + * Strip Image Tags + * + * @param string + * @return string + */ function strip_image_tags($str) { return preg_replace(array('##', '##'), '\\1', $str); @@ -109,14 +110,14 @@ if ( ! function_exists('strip_image_tags')) // ------------------------------------------------------------------------ -/** - * Convert PHP tags to entities - * - * @param string - * @return string - */ if ( ! function_exists('encode_php_tags')) { + /** + * Convert PHP tags to entities + * + * @param string + * @return string + */ function encode_php_tags($str) { return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 8dba74e73..6b4daf6d9 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -37,18 +37,19 @@ // ------------------------------------------------------------------------ -/** - * Smiley Javascript - * - * Returns the javascript required for the smiley insertion. Optionally takes - * an array of aliases to loosely couple the smiley array to the view. - * - * @param mixed alias name or array of alias->field_id pairs - * @param string field_id if alias name was passed in - * @return array - */ if ( ! function_exists('smiley_js')) { + /** + * Smiley Javascript + * + * Returns the javascript required for the smiley insertion. Optionally takes + * an array of aliases to loosely couple the smiley array to the view. + * + * @param mixed alias name or array of alias->field_id pairs + * @param string field_id if alias name was passed in + * @param bool + * @return array + */ function smiley_js($alias = '', $field_id = '', $inline = TRUE) { static $do_setup = TRUE; @@ -130,17 +131,20 @@ EOF; // ------------------------------------------------------------------------ -/** - * Get Clickable Smileys - * - * Returns an array of image tag links that can be clicked to be inserted - * into a form field. - * - * @param string the URL to the folder containing the smiley images - * @return array - */ + if ( ! function_exists('get_clickable_smileys')) { + /** + * Get Clickable Smileys + * + * Returns an array of image tag links that can be clicked to be inserted + * into a form field. + * + * @param string the URL to the folder containing the smiley images + * @param array + * @param array + * @return array + */ function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) { // For backward compatibility with js_insert_smiley @@ -184,17 +188,18 @@ if ( ! function_exists('get_clickable_smileys')) // ------------------------------------------------------------------------ -/** - * Parse Smileys - * - * Takes a string as input and swaps any contained smileys for the actual image - * - * @param string the text to be parsed - * @param string the URL to the folder containing the smiley images - * @return string - */ if ( ! function_exists('parse_smileys')) { + /** + * Parse Smileys + * + * Takes a string as input and swaps any contained smileys for the actual image + * + * @param string the text to be parsed + * @param string the URL to the folder containing the smiley images + * @param array + * @return string + */ function parse_smileys($str = '', $image_url = '', $smileys = NULL) { if ($image_url == '') @@ -224,15 +229,15 @@ if ( ! function_exists('parse_smileys')) // ------------------------------------------------------------------------ -/** - * Get Smiley Array - * - * Fetches the config/smiley.php file - * - * @return mixed - */ if ( ! function_exists('_get_smiley_array')) { + /** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @return mixed + */ function _get_smiley_array() { if (defined('ENVIRONMENT') && file_exists(APPPATH.'config/'.ENVIRONMENT.'/smileys.php')) @@ -253,33 +258,5 @@ if ( ! function_exists('_get_smiley_array')) } } -// ------------------------------------------------------------------------ - -/** - * JS Insert Smiley - * - * Generates the javascript function needed to insert smileys into a form field - * - * DEPRECATED as of version 1.7.2, use smiley_js instead - * - * @param string form name - * @param string field name - * @return string - */ -if ( ! function_exists('js_insert_smiley')) -{ - function js_insert_smiley($form_name = '', $form_field = '') - { - return << - function insert_smiley(smiley) - { - document.{$form_name}.{$form_field}.value += " " + smiley; - } - -EOF; - } -} - /* End of file smiley_helper.php */ /* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index aed35c157..b42799a8e 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -37,22 +37,22 @@ // ------------------------------------------------------------------------ -/** - * Trim Slashes - * - * Removes any leading/trailing slashes from a string: - * - * /this/that/theother/ - * - * becomes: - * - * this/that/theother - * - * @param string - * @return string - */ if ( ! function_exists('trim_slashes')) { + /** + * Trim Slashes + * + * Removes any leading/trailing slashes from a string: + * + * /this/that/theother/ + * + * becomes: + * + * this/that/theother + * + * @param string + * @return string + */ function trim_slashes($str) { return trim($str, '/'); @@ -61,16 +61,16 @@ if ( ! function_exists('trim_slashes')) // ------------------------------------------------------------------------ -/** - * Strip Slashes - * - * Removes slashes contained in a string or in an array - * - * @param mixed string or array - * @return mixed string or array - */ if ( ! function_exists('strip_slashes')) { + /** + * Strip Slashes + * + * Removes slashes contained in a string or in an array + * + * @param mixed string or array + * @return mixed string or array + */ function strip_slashes($str) { if (is_array($str)) @@ -91,16 +91,16 @@ if ( ! function_exists('strip_slashes')) // ------------------------------------------------------------------------ -/** - * Strip Quotes - * - * Removes single and double quotes from a string - * - * @param string - * @return string - */ if ( ! function_exists('strip_quotes')) { + /** + * Strip Quotes + * + * Removes single and double quotes from a string + * + * @param string + * @return string + */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); @@ -109,16 +109,16 @@ if ( ! function_exists('strip_quotes')) // ------------------------------------------------------------------------ -/** - * Quotes to Entities - * - * Converts single and double quotes to entities - * - * @param string - * @return string - */ if ( ! function_exists('quotes_to_entities')) { + /** + * Quotes to Entities + * + * Converts single and double quotes to entities + * + * @param string + * @return string + */ function quotes_to_entities($str) { return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); @@ -127,23 +127,23 @@ if ( ! function_exists('quotes_to_entities')) // ------------------------------------------------------------------------ -/** - * Reduce Double Slashes - * - * Converts double slashes in a string to a single slash, - * except those found in http:// - * - * http://www.some-site.com//index.php - * - * becomes: - * - * http://www.some-site.com/index.php - * - * @param string - * @return string - */ if ( ! function_exists('reduce_double_slashes')) { + /** + * Reduce Double Slashes + * + * Converts double slashes in a string to a single slash, + * except those found in http:// + * + * http://www.some-site.com//index.php + * + * becomes: + * + * http://www.some-site.com/index.php + * + * @param string + * @return string + */ function reduce_double_slashes($str) { return preg_replace('#(^|[^:])//+#', '\\1/', $str); @@ -152,24 +152,24 @@ if ( ! function_exists('reduce_double_slashes')) // ------------------------------------------------------------------------ -/** - * Reduce Multiples - * - * Reduces multiple instances of a particular character. Example: - * - * Fred, Bill,, Joe, Jimmy - * - * becomes: - * - * Fred, Bill, Joe, Jimmy - * - * @param string - * @param string the character you wish to reduce - * @param bool TRUE/FALSE - whether to trim the character from the beginning/end - * @return string - */ if ( ! function_exists('reduce_multiples')) { + /** + * Reduce Multiples + * + * Reduces multiple instances of a particular character. Example: + * + * Fred, Bill,, Joe, Jimmy + * + * becomes: + * + * Fred, Bill, Joe, Jimmy + * + * @param string + * @param string the character you wish to reduce + * @param bool TRUE/FALSE - whether to trim the character from the beginning/end + * @return string + */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); @@ -185,17 +185,17 @@ if ( ! function_exists('reduce_multiples')) // ------------------------------------------------------------------------ -/** - * Create a 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 int number of characters - * @return string - */ if ( ! function_exists('random_string')) { + /** + * Create a 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 int number of characters + * @return string + */ function random_string($type = 'alnum', $len = 8) { switch($type) @@ -242,16 +242,16 @@ if ( ! function_exists('random_string')) // ------------------------------------------------------------------------ -/** - * Add's _1 to a string or increment the ending number to allow _2, _3, etc - * - * @param string required - * @param string What should the duplicate number be appended with - * @param string Which number should be used for the first dupe increment - * @return string - */ if ( ! function_exists('increment_string')) { + /** + * Add's _1 to a string or increment the ending number to allow _2, _3, etc + * + * @param string required + * @param string What should the duplicate number be appended with + * @param string Which number should be used for the first dupe increment + * @return string + */ function increment_string($str, $separator = '_', $first = 1) { preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match); @@ -262,17 +262,17 @@ if ( ! function_exists('increment_string')) // ------------------------------------------------------------------------ -/** - * Alternator - * - * Allows strings to be alternated. See docs... - * - * @param string (as many parameters as needed) - * @return string - */ if ( ! function_exists('alternator')) { - function alternator() + /** + * Alternator + * + * Allows strings to be alternated. See docs... + * + * @param string (as many parameters as needed) + * @return string + */ + function alternator($args) { static $i; @@ -288,15 +288,15 @@ if ( ! function_exists('alternator')) // ------------------------------------------------------------------------ -/** - * Repeater function - * - * @param string - * @param int number of repeats - * @return string - */ if ( ! function_exists('repeater')) { + /** + * Repeater function + * + * @param string + * @param int number of repeats + * @return string + */ function repeater($data, $num = 1) { return ($num > 0) ? str_repeat($data, $num) : ''; diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index cc501c334..f53b06b93 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -37,18 +37,18 @@ // ------------------------------------------------------------------------ -/** - * Word Limiter - * - * Limits a string to X number of words. - * - * @param string - * @param int - * @param string the end character. Usually an ellipsis - * @return string - */ if ( ! function_exists('word_limiter')) { + /** + * Word Limiter + * + * Limits a string to X number of words. + * + * @param string + * @param int + * @param string the end character. Usually an ellipsis + * @return string + */ function word_limiter($str, $limit = 100, $end_char = '…') { if (trim($str) == '') @@ -69,19 +69,19 @@ if ( ! function_exists('word_limiter')) // ------------------------------------------------------------------------ -/** - * Character Limiter - * - * Limits the string based on the character count. Preserves complete words - * so the character count may not be exactly as specified. - * - * @param string - * @param int - * @param string the end character. Usually an ellipsis - * @return string - */ if ( ! function_exists('character_limiter')) { + /** + * Character Limiter + * + * Limits the string based on the character count. Preserves complete words + * so the character count may not be exactly as specified. + * + * @param string + * @param int + * @param string the end character. Usually an ellipsis + * @return string + */ function character_limiter($str, $n = 500, $end_char = '…') { if (strlen($str) < $n) @@ -112,16 +112,16 @@ if ( ! function_exists('character_limiter')) // ------------------------------------------------------------------------ -/** - * High ASCII to Entities - * - * Converts High ascii text and MS Word special characters to character entities - * - * @param string - * @return string - */ if ( ! function_exists('ascii_to_entities')) { + /** + * High ASCII to Entities + * + * Converts High ascii text and MS Word special characters to character entities + * + * @param string + * @return string + */ function ascii_to_entities($str) { $count = 1; @@ -172,17 +172,17 @@ if ( ! function_exists('ascii_to_entities')) // ------------------------------------------------------------------------ -/** - * Entities to ASCII - * - * Converts character entities back to ASCII - * - * @param string - * @param bool - * @return string - */ if ( ! function_exists('entities_to_ascii')) { + /** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @param string + * @param bool + * @return string + */ function entities_to_ascii($str, $all = TRUE) { if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) @@ -227,20 +227,20 @@ if ( ! function_exists('entities_to_ascii')) // ------------------------------------------------------------------------ -/** - * Word Censoring Function - * - * Supply a string and an array of disallowed words and any - * matched words will be converted to #### or to the replacement - * word you've submitted. - * - * @param string the text string - * @param string the array of censoered words - * @param string the optional replacement value - * @return string - */ if ( ! function_exists('word_censor')) { + /** + * Word Censoring Function + * + * Supply a string and an array of disallowed words and any + * matched words will be converted to #### or to the replacement + * word you've submitted. + * + * @param string the text string + * @param string the array of censoered words + * @param string the optional replacement value + * @return string + */ function word_censor($str, $censored, $replacement = '') { if ( ! is_array($censored)) @@ -274,16 +274,16 @@ if ( ! function_exists('word_censor')) // ------------------------------------------------------------------------ -/** - * Code Highlighter - * - * Colorizes code strings - * - * @param string the text string - * @return string - */ if ( ! function_exists('highlight_code')) { + /** + * Code Highlighter + * + * Colorizes code strings + * + * @param string the text string + * @return string + */ function highlight_code($str) { // The highlight string function encodes and highlights @@ -317,19 +317,19 @@ if ( ! function_exists('highlight_code')) // ------------------------------------------------------------------------ -/** - * Phrase Highlighter - * - * 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 - * @return string - */ if ( ! function_exists('highlight_phrase')) { + /** + * Phrase Highlighter + * + * 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 + * @return string + */ function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') { if ($str == '') @@ -348,14 +348,14 @@ if ( ! function_exists('highlight_phrase')) // ------------------------------------------------------------------------ -/** - * Convert Accented Foreign Characters to ASCII - * - * @param string the text string - * @return string - */ if ( ! function_exists('convert_accented_characters')) { + /** + * Convert Accented Foreign Characters to ASCII + * + * @param string the text string + * @return string + */ function convert_accented_characters($str) { if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/foreign_chars.php')) @@ -378,19 +378,19 @@ if ( ! function_exists('convert_accented_characters')) // ------------------------------------------------------------------------ -/** - * Word Wrap - * - * Wraps text at the specified character. Maintains the integrity of words. - * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor - * will URLs. - * - * @param string the text string - * @param int the number of characters to wrap at - * @return string - */ if ( ! function_exists('word_wrap')) { + /** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor + * will URLs. + * + * @param string the text string + * @param int the number of characters to wrap at + * @return string + */ function word_wrap($str, $charlim = '76') { // Se the character limit @@ -481,19 +481,19 @@ if ( ! function_exists('word_wrap')) // ------------------------------------------------------------------------ -/** - * Ellipsize String - * - * This function will strip tags from a string, split it at its max_length and ellipsize - * - * @param string string to ellipsize - * @param int max length of string - * @param mixed int (1|0) or float, .5, .2, etc for position to split - * @param string ellipsis ; Default '...' - * @return string ellipsized string - */ if ( ! function_exists('ellipsize')) { + /** + * Ellipsize String + * + * This function will strip tags from a string, split it at its max_length and ellipsize + * + * @param string string to ellipsize + * @param int max length of string + * @param mixed int (1|0) or float, .5, .2, etc for position to split + * @param string ellipsis ; Default '...' + * @return string ellipsized string + */ function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') { // Strip tags diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 7a3db5d6b..af9d16a89 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -37,14 +37,14 @@ // ------------------------------------------------------------------------ -/** - * Convert newlines to HTML line breaks except within PRE tags - * - * @param string - * @return string - */ if ( ! function_exists('nl2br_except_pre')) { + /** + * Convert newlines to HTML line breaks except within PRE tags + * + * @param string + * @return string + */ function nl2br_except_pre($str) { $CI =& get_instance(); @@ -55,16 +55,16 @@ if ( ! function_exists('nl2br_except_pre')) // ------------------------------------------------------------------------ -/** - * Auto Typography Wrapper Function - * - * @param string - * @param bool whether to allow javascript event handlers - * @param bool whether to reduce multiple instances of double newlines to two - * @return string - */ if ( ! function_exists('auto_typography')) { + /** + * Auto Typography Wrapper Function + * + * @param string + * @param bool whether to allow javascript event handlers + * @param bool whether to reduce multiple instances of double newlines to two + * @return string + */ function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) { $CI =& get_instance(); @@ -73,20 +73,19 @@ if ( ! function_exists('auto_typography')) } } - // -------------------------------------------------------------------- -/** - * HTML Entities Decode - * - * This function is a replacement for html_entity_decode() - * - * @param string - * @param string - * @return string - */ if ( ! function_exists('entity_decode')) { + /** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * @param string + * @param string + * @return string + */ function entity_decode($str, $charset = NULL) { global $SEC; diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 5576c2748..fa685645a 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -37,17 +37,17 @@ // ------------------------------------------------------------------------ -/** - * Site URL - * - * Create a local URL based on your basepath. Segments can be passed via the - * first parameter either as a string or an array. - * - * @param string - * @return string - */ if ( ! function_exists('site_url')) { + /** + * Site URL + * + * Create a local URL based on your basepath. Segments can be passed via the + * first parameter either as a string or an array. + * + * @param string + * @return string + */ function site_url($uri = '') { $CI =& get_instance(); @@ -57,18 +57,18 @@ if ( ! function_exists('site_url')) // ------------------------------------------------------------------------ -/** - * Base URL - * - * Create a local URL based on your basepath. - * Segments can be passed in as a string or an array, same as site_url - * or a URL to a file can be passed in, e.g. to an image file. - * - * @param string - * @return string - */ if ( ! function_exists('base_url')) { + /** + * Base URL + * + * Create a local URL based on your basepath. + * Segments can be passed in as a string or an array, same as site_url + * or a URL to a file can be passed in, e.g. to an image file. + * + * @param string + * @return string + */ function base_url($uri = '') { $CI =& get_instance(); @@ -78,16 +78,16 @@ if ( ! function_exists('base_url')) // ------------------------------------------------------------------------ -/** - * Current URL - * - * Returns the full URL (including segments) of the page where this - * function is placed - * - * @return string - */ if ( ! function_exists('current_url')) { + /** + * Current URL + * + * Returns the full URL (including segments) of the page where this + * function is placed + * + * @return string + */ function current_url() { $CI =& get_instance(); @@ -96,15 +96,16 @@ if ( ! function_exists('current_url')) } // ------------------------------------------------------------------------ -/** - * URL String - * - * Returns the URI segments. - * - * @return string - */ + if ( ! function_exists('uri_string')) { + /** + * URL String + * + * Returns the URI segments. + * + * @return string + */ function uri_string() { $CI =& get_instance(); @@ -114,15 +115,15 @@ if ( ! function_exists('uri_string')) // ------------------------------------------------------------------------ -/** - * Index page - * - * Returns the "index_page" from your config file - * - * @return string - */ if ( ! function_exists('index_page')) { + /** + * Index page + * + * Returns the "index_page" from your config file + * + * @return string + */ function index_page() { $CI =& get_instance(); @@ -132,18 +133,18 @@ if ( ! function_exists('index_page')) // ------------------------------------------------------------------------ -/** - * Anchor Link - * - * Creates an anchor based on the local URL. - * - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('anchor')) { + /** + * Anchor Link + * + * Creates an anchor based on the local URL. + * + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ function anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; @@ -173,19 +174,19 @@ if ( ! function_exists('anchor')) // ------------------------------------------------------------------------ -/** - * Anchor Link - Pop-up version - * - * Creates an anchor based on the local URL. The link - * opens a new window based on the attributes specified. - * - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('anchor_popup')) { + /** + * Anchor Link - Pop-up version + * + * Creates an anchor based on the local URL. The link + * opens a new window based on the attributes specified. + * + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ function anchor_popup($uri = '', $title = '', $attributes = FALSE) { $title = (string) $title; @@ -223,16 +224,16 @@ if ( ! function_exists('anchor_popup')) // ------------------------------------------------------------------------ -/** - * Mailto Link - * - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('mailto')) { + /** + * Mailto Link + * + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ function mailto($email, $title = '', $attributes = '') { $title = (string) $title; @@ -248,18 +249,18 @@ if ( ! function_exists('mailto')) // ------------------------------------------------------------------------ -/** - * Encoded Mailto Link - * - * Create a spam-protected mailto link written in Javascript - * - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ if ( ! function_exists('safe_mailto')) { + /** + * Encoded Mailto Link + * + * Create a spam-protected mailto link written in Javascript + * + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ function safe_mailto($email, $title = '', $attributes = '') { $title = (string) $title; @@ -357,21 +358,21 @@ if ( ! function_exists('safe_mailto')) // ------------------------------------------------------------------------ -/** - * Auto-linker - * - * Automatically links URL and Email addresses. - * Note: There's a bit of extra code here to deal with - * URLs or emails that end in a period. We'll strip these - * off and add them after the link. - * - * @param string the string - * @param string the type: email, url, or both - * @param bool whether to create pop-up links - * @return string - */ if ( ! function_exists('auto_link')) { + /** + * Auto-linker + * + * Automatically links URL and Email addresses. + * Note: There's a bit of extra code here to deal with + * URLs or emails that end in a period. We'll strip these + * off and add them after the link. + * + * @param string the string + * @param string the type: email, url, or both + * @param bool whether to create pop-up links + * @return string + */ function auto_link($str, $type = 'both', $popup = FALSE) { if ($type !== 'email' && preg_match_all('#(^|\s|\(|\b)((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i', $str, $matches)) @@ -423,16 +424,16 @@ if ( ! function_exists('auto_link')) // ------------------------------------------------------------------------ -/** - * Prep URL - * - * Simply adds the http:// part if no scheme is included - * - * @param string the URL - * @return string - */ if ( ! function_exists('prep_url')) { + /** + * Prep URL + * + * Simply adds the http:// part if no scheme is included + * + * @param string the URL + * @return string + */ function prep_url($str = '') { if ($str === 'http://' OR $str == '') @@ -453,20 +454,20 @@ if ( ! function_exists('prep_url')) // ------------------------------------------------------------------------ -/** - * Create URL Title - * - * Takes a "title" string as input and creates a - * human-friendly URL string with a "separator" string - * as the word separator. - * - * @param string the string - * @param string the separator - * @param bool - * @return string - */ if ( ! function_exists('url_title')) { + /** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with a "separator" string + * as the word separator. + * + * @param string the string + * @param string the separator + * @param bool + * @return string + */ function url_title($str, $separator = '-', $lowercase = FALSE) { if ($separator === 'dash') @@ -504,19 +505,20 @@ if ( ! function_exists('url_title')) // ------------------------------------------------------------------------ -/** - * Header Redirect - * - * Header redirect in two flavors - * For very fine grained control over headers, you could use the Output - * Library's set_header() function. - * - * @param string the URL - * @param string the method: location or refresh - * @return string - */ if ( ! function_exists('redirect')) { + /** + * Header Redirect + * + * Header redirect in two flavors + * For very fine grained control over headers, you could use the Output + * Library's set_header() function. + * + * @param string the URL + * @param string the method: location or refresh + * @param int + * @return string + */ function redirect($uri = '', $method = 'auto', $http_response_code = 302) { if ( ! preg_match('#^https?://#i', $uri)) @@ -545,17 +547,17 @@ if ( ! function_exists('redirect')) // ------------------------------------------------------------------------ -/** - * Parse out the attributes - * - * Some of the functions use this - * - * @param array - * @param bool - * @return string - */ if ( ! function_exists('_parse_attributes')) { + /** + * Parse out the attributes + * + * Some of the functions use this + * + * @param array + * @param bool + * @return string + */ function _parse_attributes($attributes, $javascript = FALSE) { if (is_string($attributes)) diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 67fd34b97..958c633dd 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -37,15 +37,15 @@ // ------------------------------------------------------------------------ -/** - * Convert Reserved XML characters to Entities - * - * @param string - * @param bool - * @return string - */ if ( ! function_exists('xml_convert')) { + /** + * Convert Reserved XML characters to Entities + * + * @param string + * @param bool + * @return string + */ function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; -- cgit v1.2.3-24-g4f1b From 963c96c5507ceb8b5c3de50d0ab959d21dcc8cd1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 2 May 2012 13:09:57 +0300 Subject: Fix a wrong variable name --- 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 daf31c3d6..c1c0eb947 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -377,7 +377,7 @@ if ( ! function_exists('convert_accented_characters')) include(APPPATH.'config/foreign_chars.php'); } - if ( ! isset($foreign_characters) OR ! is_array($foreign_chars)) + if ( ! isset($foreign_characters) OR ! is_array($foreign_characters)) { return $str; } -- cgit v1.2.3-24-g4f1b From 6986479050e7bf02cbafd9dbc82640a9e3865bb9 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 3 May 2012 14:05:00 -0400 Subject: Make valid_email helper function more accurate --- system/helpers/email_helper.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 0516e938a..c7b3abada 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -42,12 +42,40 @@ if ( ! function_exists('valid_email')) /** * Validate email address * + * Updated to be more accurate to RFC822 + * see: http://www.iamcal.com/publish/articles/php/parsing_email/ + * * @param string * @return bool */ - function valid_email($address) + function valid_email($email) { - return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $address); + $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; + + $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; + + $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'. + '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; + + $quoted_pair = '\\x5c[\\x00-\\x7f]'; + + $domain_literal = "\\x5b({$dtext}|{$quoted_pair})*\\x5d"; + + $quoted_string = "\\x22({$qtext}|{$quoted_pair})*\\x22"; + + $domain_ref = $atom; + + $sub_domain = "({$domain_ref}|{$domain_literal})"; + + $word = "({$atom}|{$quoted_string})"; + + $domain = "{$sub_domain}(\\x2e{$sub_domain})*"; + + $local_part = "{$word}(\\x2e{$word})*"; + + $addr_spec = "{$local_part}\\x40{$domain}"; + + return (bool) preg_match("!^{$addr_spec}$!", $email); } } -- cgit v1.2.3-24-g4f1b From 40dd9b5ffa1a9e0b1b885d4b592636dcc04af023 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 16 May 2012 15:41:05 -0400 Subject: Added filter_var for newer versions of php --- system/helpers/email_helper.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index c7b3abada..449aadfc2 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -50,6 +50,13 @@ if ( ! function_exists('valid_email')) */ function valid_email($email) { + // Use PHP's filters if they exist + if (function_exists('filter_var')) + { + return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); + } + + // Fallback based on RFC822 $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; -- cgit v1.2.3-24-g4f1b From 421d6abf1ad3a1cfb96f9aad326c72c9b6fa3a06 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 17 May 2012 07:46:25 -0400 Subject: Remove regex validation in favor of filter_var --- system/helpers/email_helper.php | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 449aadfc2..ea9f6105d 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -50,39 +50,7 @@ if ( ! function_exists('valid_email')) */ function valid_email($email) { - // Use PHP's filters if they exist - if (function_exists('filter_var')) - { - return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); - } - - // Fallback based on RFC822 - $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; - - $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; - - $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'. - '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; - - $quoted_pair = '\\x5c[\\x00-\\x7f]'; - - $domain_literal = "\\x5b({$dtext}|{$quoted_pair})*\\x5d"; - - $quoted_string = "\\x22({$qtext}|{$quoted_pair})*\\x22"; - - $domain_ref = $atom; - - $sub_domain = "({$domain_ref}|{$domain_literal})"; - - $word = "({$atom}|{$quoted_string})"; - - $domain = "{$sub_domain}(\\x2e{$sub_domain})*"; - - $local_part = "{$word}(\\x2e{$word})*"; - - $addr_spec = "{$local_part}\\x40{$domain}"; - - return (bool) preg_match("!^{$addr_spec}$!", $email); + return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); } } -- cgit v1.2.3-24-g4f1b From ae31eb5e75d914fc3ab622a7ac5c23eb1e6d9f9a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:54:15 +0300 Subject: Clean up the helpers --- system/helpers/date_helper.php | 65 ++++++++++++++++++------------------- system/helpers/download_helper.php | 2 +- system/helpers/form_helper.php | 1 - system/helpers/html_helper.php | 8 ++--- system/helpers/inflector_helper.php | 2 +- system/helpers/url_helper.php | 4 +-- 6 files changed, 39 insertions(+), 43 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 531d1d32f..5f0427f7d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -100,7 +100,7 @@ if ( ! function_exists('mdate')) $datestr = str_replace( '%\\', '', - preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr) + preg_replace('/([a-z]+?){1}/i', '\\\\\\1', $datestr) ); return date($datestr, $time); @@ -316,12 +316,12 @@ if ( ! function_exists('local_to_gmt')) } return mktime( - gmdate("H", $time), - gmdate("i", $time), - gmdate("s", $time), - gmdate("m", $time), - gmdate("d", $time), - gmdate("Y", $time) + gmdate('H', $time), + gmdate('i', $time), + gmdate('s', $time), + gmdate('m', $time), + gmdate('d', $time), + gmdate('Y', $time) ); } } @@ -452,8 +452,7 @@ if ( ! function_exists('human_to_unix')) return FALSE; } - $datestr = trim($datestr); - $datestr = preg_replace("/\040+/", ' ', $datestr); + $datestr = preg_replace('/\040+/', ' ', trim($datestr)); if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) { @@ -462,20 +461,20 @@ if ( ! function_exists('human_to_unix')) $split = explode(' ', $datestr); - $ex = explode("-", $split['0']); + $ex = explode('-', $split['0']); - $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; - $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; + $year = (strlen($ex[0]) === 2) ? '20'.$ex[0] : $ex[0]; + $month = (strlen($ex[1]) === 1) ? '0'.$ex[1] : $ex[1]; + $day = (strlen($ex[2]) === 1) ? '0'.$ex[2] : $ex[2]; - $ex = explode(":", $split['1']); + $ex = explode(':', $split['1']); - $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; - $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + $hour = (strlen($ex[0]) === 1) ? '0'.$ex[0] : $ex[0]; + $min = (strlen($ex[1]) === 1) ? '0'.$ex[1] : $ex[1]; - if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex['2'])) + if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex[2])) { - $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; + $sec = (strlen($ex[2]) === 1) ? '0'.$ex[2] : $ex[2]; } else { @@ -485,11 +484,11 @@ if ( ! function_exists('human_to_unix')) if (isset($split['2'])) { - $ampm = strtolower($split['2']); + $ampm = strtolower($split[2]); if (substr($ampm, 0, 1) === 'p' && $hour < 12) { - $hour = $hour + 12; + $hour += 12; } if (substr($ampm, 0, 1) === 'a' && $hour == 12) @@ -497,7 +496,7 @@ if ( ! function_exists('human_to_unix')) $hour = '00'; } - if (strlen($hour) == 1) + if (strlen($hour) === 1) { $hour = '0'.$hour; } @@ -529,7 +528,7 @@ if ( ! function_exists('nice_date')) // Date like: YYYYMM if (preg_match('/^\d{6}$/', $bad_date)) { - if (in_array(substr($bad_date, 0, 2),array('19', '20'))) + if (in_array(substr($bad_date, 0, 2), array('19', '20'))) { $year = substr($bad_date, 0, 4); $month = substr($bad_date, 4, 2); @@ -540,24 +539,24 @@ if ( ! function_exists('nice_date')) $year = substr($bad_date, 2, 4); } - return date($format, strtotime($year . '-' . $month . '-01')); + return date($format, strtotime($year.'-'.$month.'-01')); } // Date Like: YYYYMMDD - if (preg_match('/^\d{8}$/',$bad_date)) + if (preg_match('/^\d{8}$/', $bad_date)) { $month = substr($bad_date, 0, 2); $day = substr($bad_date, 2, 2); $year = substr($bad_date, 4, 4); - return date($format, strtotime($month . '/01/' . $year)); + return date($format, strtotime($month.'/01/'.$year)); } // Date Like: MM-DD-YYYY __or__ M-D-YYYY (or anything in between) - if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/',$bad_date)) + if (preg_match('/^\d{1,2}-\d{1,2}-\d{4}$/', $bad_date)) { list($m, $d, $y) = explode('-', $bad_date); - return date($format, strtotime("{$y}-{$m}-{$d}")); + return date($format, strtotime($y.'-'.$m.'-'.$d)); } // Any other kind of string, when converted into UNIX time, @@ -565,7 +564,7 @@ if ( ! function_exists('nice_date')) // return "Invalid Date". if (date('U', strtotime($bad_date)) == '0') { - return "Invalid Date"; + return 'Invalid Date'; } // It's probably a valid-ish date format already @@ -587,7 +586,7 @@ if ( ! function_exists('timezone_menu')) * @param string menu name * @return string */ - function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') + function timezone_menu($default = 'UTC', $class = '', $name = 'timezones') { $CI =& get_instance(); $CI->lang->load('date'); @@ -605,13 +604,11 @@ if ( ! function_exists('timezone_menu')) foreach (timezones() as $key => $val) { - $selected = ($default == $key) ? " selected='selected'" : ''; - $menu .= "\n"; + $selected = ($default == $key) ? ' selected="selected"' : ''; + $menu .= '\n"; } - $menu .= ""; - - return $menu; + return $menu.''; } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 97e6986b0..470b61ede 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -100,7 +100,7 @@ if ( ! function_exists('force_download')) $x[count($x) - 1] = strtoupper($extension); $filename = implode('.', $x); } - + // Clean output buffer ob_clean(); diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index b246d72f3..eca6c5f1e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -184,7 +184,6 @@ if ( ! function_exists('form_input')) // ------------------------------------------------------------------------ - if ( ! function_exists('form_password')) { /** diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 124f58009..92a6db477 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -379,10 +379,10 @@ if ( ! function_exists('meta')) $str = ''; foreach ($name as $meta) { - $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv'; - $name = ( ! isset($meta['name'])) ? '' : $meta['name']; - $content = ( ! isset($meta['content'])) ? '' : $meta['content']; - $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline']; + $type = ( ! isset($meta['type']) OR $meta['type'] === 'name') ? 'name' : 'http-equiv'; + $name = isset($meta['name']) ? $meta['name'] : ''; + $content = isset($meta['content']) ? $meta['content'] : ''; + $newline = isset($meta['newline']) ? $meta['newline'] : "\n"; $str .= ''.$newline; } diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index feeaf57d7..2a9466305 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -201,7 +201,7 @@ if ( ! function_exists('underscore')) * * @param string $str * @param string $separator - * @return str + * @return string */ if ( ! function_exists('humanize')) { diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 5576c2748..cf6df4ef5 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -198,7 +198,7 @@ if ( ! function_exists('anchor_popup')) if ($attributes === FALSE) { - return "".$title.''; + return '".$title.''; } if ( ! is_array($attributes)) @@ -217,7 +217,7 @@ if ( ! function_exists('anchor_popup')) $attributes = _parse_attributes($attributes); } - return "'.$title.''; + return ''.$title.''; } } -- cgit v1.2.3-24-g4f1b From d013c63462b4eaa2ac2f684b2ad498a9c4fb7dd5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 17 May 2012 08:15:47 -0400 Subject: tweak and changelog entry --- system/helpers/email_helper.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index ea9f6105d..628667d4d 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -42,15 +42,12 @@ if ( ! function_exists('valid_email')) /** * Validate email address * - * Updated to be more accurate to RFC822 - * see: http://www.iamcal.com/publish/articles/php/parsing_email/ - * * @param string * @return bool */ function valid_email($email) { - return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); + return filter_var($email, FILTER_VALIDATE_EMAIL); } } -- cgit v1.2.3-24-g4f1b From 16642c71403f4463dfe6e83c13a0e3120474cd1d Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 17 May 2012 08:20:16 -0400 Subject: Update inflector docblocks, add changelog entry --- system/helpers/inflector_helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 72615671c..647d840e4 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -45,7 +45,7 @@ if ( ! function_exists('singular')) * Takes a plural word and makes it singular * * @param string - * @return str + * @return string */ function singular($str) { @@ -110,7 +110,7 @@ if ( ! function_exists('plural')) * * @param string * @param bool - * @return str + * @return string */ function plural($str, $force = FALSE) { @@ -166,7 +166,7 @@ if ( ! function_exists('camelize')) * Takes multiple words separated by spaces or underscores and camelizes them * * @param string - * @return str + * @return string */ function camelize($str) { @@ -184,7 +184,7 @@ if ( ! function_exists('underscore')) * Takes multiple words separated by spaces and underscores them * * @param string - * @return str + * @return string */ function underscore($str) { @@ -203,7 +203,7 @@ if ( ! function_exists('humanize')) * * @param string $str * @param string $separator - * @return str + * @return string */ function humanize($str, $separator = '_') { -- cgit v1.2.3-24-g4f1b From f0eb2f133bf43be7ffa1bf71babf4ed28852e71b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 17 May 2012 08:32:11 -0400 Subject: Suggested changes --- system/helpers/number_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 2a906ba1b..e49f2f7a0 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -42,7 +42,7 @@ if ( ! function_exists('byte_format')) /** * Formats a numbers as bytes, based on size, and adds the appropriate suffix * - * @param mixed // will be cast as int + * @param mixed will be cast as int * @param int * @return string */ diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 4320dd392..5e6de08af 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -130,7 +130,7 @@ if ( ! function_exists('get_clickable_smileys')) * * @param string the URL to the folder containing the smiley images * @param array - * @param array + * @param array * @return array */ function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) -- cgit v1.2.3-24-g4f1b From 773ccc318f2769c9b7579630569b5d8ba47b114b Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:11:08 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/helpers --- system/helpers/captcha_helper.php | 6 +++--- system/helpers/date_helper.php | 38 ++++++++++++++++++------------------- system/helpers/directory_helper.php | 2 +- system/helpers/download_helper.php | 2 +- system/helpers/file_helper.php | 4 ++-- system/helpers/form_helper.php | 32 +++++++++++++++---------------- system/helpers/html_helper.php | 6 +++--- system/helpers/language_helper.php | 2 +- system/helpers/smiley_helper.php | 4 ++-- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 10 +++++----- system/helpers/url_helper.php | 24 +++++++++++------------ system/helpers/xml_helper.php | 4 ++-- 13 files changed, 68 insertions(+), 68 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index b11670658..4676b2a65 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -64,7 +64,7 @@ if ( ! function_exists('create_captcha')) } } - if ($img_path == '' OR $img_url == '' + if ($img_path === '' OR $img_url === '' OR ! @is_dir($img_path) OR ! is_writeable($img_path) OR ! extension_loaded('gd')) { @@ -93,7 +93,7 @@ if ( ! function_exists('create_captcha')) // Do we have a "word" yet? // ----------------------------------- - if ($word == '') + if ($word === '') { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $word = ''; @@ -156,7 +156,7 @@ if ( ! function_exists('create_captcha')) // Write the text // ----------------------------------- - $use_font = ($font_path != '' && file_exists($font_path) && function_exists('imagettftext')); + $use_font = ($font_path !== '' && file_exists($font_path) && function_exists('imagettftext')); if ($use_font === FALSE) { $font_size = 5; diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 5f0427f7d..0bda33378 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -50,7 +50,7 @@ if ( ! function_exists('now')) { $CI =& get_instance(); - if (strtolower($CI->config->item('time_reference')) == 'gmt') + if (strtolower($CI->config->item('time_reference')) === 'gmt') { $now = time(); $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); @@ -90,12 +90,12 @@ if ( ! function_exists('mdate')) */ function mdate($datestr = '', $time = '') { - if ($datestr == '') + if ($datestr === '') { return ''; } - $time = ($time == '') ? now() : $time; + $time = ($time === '') ? now() : $time; $datestr = str_replace( '%\\', @@ -280,14 +280,14 @@ if ( ! function_exists('days_in_month')) return 0; } - if ( ! is_numeric($year) OR strlen($year) != 4) + if ( ! is_numeric($year) OR strlen($year) !== 4) { $year = date('Y'); } - if ($month == 2) + if ($month === 2) { - if ($year % 400 == 0 OR ($year % 4 == 0 && $year % 100 != 0)) + if ($year % 400 === 0 OR ($year % 4 === 0 && $year % 100 !== 0)) { return 29; } @@ -310,7 +310,7 @@ if ( ! function_exists('local_to_gmt')) */ function local_to_gmt($time = '') { - if ($time == '') + if ($time === '') { $time = time(); } @@ -344,14 +344,14 @@ if ( ! function_exists('gmt_to_local')) */ function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) { - if ($time == '') + if ($time === '') { return now(); } $time += timezones($timezone) * 3600; - if ($dst == TRUE) + if ($dst === TRUE) { $time += 3600; } @@ -410,7 +410,7 @@ if ( ! function_exists('unix_to_human')) { $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; - if ($fmt == 'us') + if ($fmt === 'us') { $r .= date('h', $time).':'.date('i', $time); } @@ -424,7 +424,7 @@ if ( ! function_exists('unix_to_human')) $r .= ':'.date('s', $time); } - if ($fmt == 'us') + if ($fmt === 'us') { $r .= ' '.date('A', $time); } @@ -447,7 +447,7 @@ if ( ! function_exists('human_to_unix')) */ function human_to_unix($datestr = '') { - if ($datestr == '') + if ($datestr === '') { return FALSE; } @@ -491,7 +491,7 @@ if ( ! function_exists('human_to_unix')) $hour += 12; } - if (substr($ampm, 0, 1) === 'a' && $hour == 12) + if (substr($ampm, 0, 1) === 'a' && $hour === 12) { $hour = '00'; } @@ -562,7 +562,7 @@ if ( ! function_exists('nice_date')) // Any other kind of string, when converted into UNIX time, // produces "0 seconds after epoc..." is probably bad... // return "Invalid Date". - if (date('U', strtotime($bad_date)) == '0') + if (date('U', strtotime($bad_date)) === '0') { return 'Invalid Date'; } @@ -591,11 +591,11 @@ if ( ! function_exists('timezone_menu')) $CI =& get_instance(); $CI->lang->load('date'); - $default = ($default == 'GMT') ? 'UTC' : $default; + $default = ($default === 'GMT') ? 'UTC' : $default; $menu = '\n"; + $form .= '\n"; } else { @@ -263,7 +263,7 @@ if ( ! function_exists('form_textarea')) } $name = is_array($data) ? $data['name'] : $data; - return '\n"; + return '\n"; } } @@ -600,44 +600,15 @@ if ( ! function_exists('form_prep')) * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * - * @param string - * @param string + * @deprecated 3.0.0 This function has been broken for a long time + * and is now just an alias for html_escape(). It's + * second argument is ignored. + * @param string $str = '' + * @param string $field_name = '' * @return string */ function form_prep($str = '', $field_name = '') { - static $prepped_fields = array(); - - // if the field name is an array we do this recursively - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = form_prep($val); - } - - return $str; - } - - if ($str === '') - { - return ''; - } - - // we've already prepped a field with this name - // @todo need to figure out a way to namespace this so - // that we know the *exact* field and not just one with - // the same name - if (isset($prepped_fields[$field_name])) - { - return $str; - } - - if ($field_name !== '') - { - $prepped_fields[$field_name] = $field_name; - } - return html_escape($str); } } @@ -663,13 +634,13 @@ if ( ! function_exists('set_value')) { if ( ! isset($_POST[$field])) { - return $default; + return html_escape($default); } - return form_prep($_POST[$field], $field); + return html_escape($_POST[$field]); } - return form_prep($OBJ->set_value($field, $default), $field); + return html_escape($OBJ->set_value($field, $default)); } } @@ -919,7 +890,7 @@ if ( ! function_exists('_parse_form_attributes')) { if ($key === 'value') { - $val = form_prep($val, $default['name']); + $val = html_escape($val); } elseif ($key === 'name' && ! strlen($default['name'])) { -- cgit v1.2.3-24-g4f1b From 582ebcb3b7eebd12605804577710cf73f0362001 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 00:52:15 +0300 Subject: Fix #142 --- system/helpers/form_helper.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d81bb7c08..a09cb36dd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -298,10 +298,10 @@ if ( ! function_exists('form_dropdown')) /** * Drop-down Menu * - * @param string - * @param array - * @param string - * @param string + * @param mixed $name = '' + * @param mixed $options = array() + * @param mixed $selected = array() + * @param mixed $extra = array() * @return string */ function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') @@ -316,10 +316,7 @@ if ( ! function_exists('form_dropdown')) return form_dropdown($name['name'], $name['options'], $name['selected'], $name['extra']); } - if ( ! is_array($selected)) - { - $selected = array($selected); - } + is_array($selected) OR $selected = array($selected); // If no selected state was submitted we will attempt to set it automatically if (count($selected) === 0 && isset($_POST[$name])) @@ -352,14 +349,17 @@ if ( ! function_exists('form_dropdown')) foreach ($val as $optgroup_key => $optgroup_val) { $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; - $form .= '\n"; + $form .= '\n"; } $form .= "\n"; } else { - $form .= '\n"; + $form .= '\n"; } } -- cgit v1.2.3-24-g4f1b From 29d909d5d1a14efc2e316650946bf43ddf03f1fd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 01:05:09 +0300 Subject: [ci skip] Update docblocks for deprecated functions --- system/helpers/date_helper.php | 17 +++++++---------- system/helpers/file_helper.php | 10 ++++------ system/helpers/form_helper.php | 1 + system/helpers/security_helper.php | 10 ++++------ 4 files changed, 16 insertions(+), 22 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 51b2b76db..5d9251526 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -119,19 +119,16 @@ if ( ! function_exists('standard_date')) * * As of PHP 5.2, the DateTime extension provides constants that * serve for the exact same purpose and are used with date(). - * Due to that, this function is DEPRECATED and should be removed - * in CodeIgniter 3.1+. * - * Here are two examples of how you should replace it: + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 Use PHP's native date() instead. + * @link http://www.php.net/manual/en/class.datetime.php#datetime.constants.types * - * date(DATE_RFC822, now()); // default - * date(DATE_W3C, $time); // a different format and time + * @example date(DATE_RFC822, now()); // default + * @example date(DATE_W3C, $time); // a different format and time * - * Reference: http://www.php.net/manual/en/class.datetime.php#datetime.constants.types - * - * @deprecated - * @param string the chosen format - * @param int Unix timestamp + * @param string $fmt = 'DATE_RFC822' the chosen format + * @param int $time = NULL Unix timestamp * @return string */ function standard_date($fmt = 'DATE_RFC822', $time = NULL) diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 441345b05..8f23a3d54 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -44,12 +44,10 @@ if ( ! function_exists('read_file')) * * Opens the file specfied in the path and returns it as a string. * - * This function is DEPRECATED and should be removed in - * CodeIgniter 3.1+. Use file_get_contents() instead. - * - * @deprecated - * @param string path to file - * @return string + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents(). + * @param string $file Path to file + * @return string File contents */ function read_file($file) { diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a09cb36dd..622622c0e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -600,6 +600,7 @@ if ( ! function_exists('form_prep')) * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * + * @todo Remove in version 3.1+. * @deprecated 3.0.0 This function has been broken for a long time * and is now just an alias for html_escape(). It's * second argument is ignored. diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 5ecc960bc..8bbd06684 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -77,12 +77,10 @@ if ( ! function_exists('do_hash')) /** * Hash encode a string * - * This function is DEPRECATED and should be removed in - * CodeIgniter 3.1+. Use hash() instead. - * - * @deprecated - * @param string - * @param string + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 Use PHP's native hash() instead. + * @param string $str + * @param string $type = 'sha1' * @return string */ function do_hash($str, $type = 'sha1') -- cgit v1.2.3-24-g4f1b From 7d753464d13f3a3326a1679226127570cc0c498f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 03:37:40 +0300 Subject: [ci skip] Optimize ascii_to_entities() --- system/helpers/text_helper.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 016a36c57..89602fc28 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -118,18 +118,15 @@ if ( ! function_exists('ascii_to_entities')) /** * High ASCII to Entities * - * Converts High ascii text and MS Word special characters to character entities + * Converts high ASCII text and MS Word special characters to character entities * - * @param string + * @param string $str * @return string */ function ascii_to_entities($str) { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) + $out = ''; + for ($i = 0, $s = strlen($str), $count = 1, $temp = array(); $i < $s; $i++) { $ordinal = ord($str[$i]); -- cgit v1.2.3-24-g4f1b From 60826db46d3f9ceabcc280c494a975007423e64a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 14:45:23 +0300 Subject: Deprecate string helper repeater() (an alias for str_repeat()) --- system/helpers/string_helper.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 4eee2a262..c5c493452 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -276,8 +276,11 @@ if ( ! function_exists('repeater')) /** * Repeater function * - * @param string - * @param int number of repeats + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 This is just an alias for PHP's native str_repeat() + * + * @param string $data String to repeat + * @param int $num Number of repeats * @return string */ function repeater($data, $num = 1) -- cgit v1.2.3-24-g4f1b From 7c4d10660a0a47446474bf97e3cb65f80693f1ee Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 15:14:34 +0200 Subject: Fix issue #1953 (form values being escaped twice) Re-instaing an improved form_prep() function, reverting most of the changes from 74ffd17ab06327ca62ddfe28a186cae7ba6bd459. --- system/helpers/form_helper.php | 83 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 37 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 622622c0e..9c4c4dae6 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -124,9 +124,9 @@ if ( ! function_exists('form_hidden')) * Generates hidden fields. You can pass a simple key/value string or * an associative array with multiple values. * - * @param mixed - * @param string - * @param bool + * @param mixed $name Field name + * @param string $value Field value + * @param bool $recursing * @return string */ function form_hidden($name, $value = '', $recursing = FALSE) @@ -149,7 +149,7 @@ if ( ! function_exists('form_hidden')) if ( ! is_array($value)) { - $form .= '\n"; + $form .= '\n"; } else { @@ -243,9 +243,9 @@ if ( ! function_exists('form_textarea')) /** * Textarea field * - * @param mixed - * @param string - * @param string + * @param mixed $data + * @param string $value + * @param string $extra * @return string */ function form_textarea($data = '', $value = '', $extra = '') @@ -263,7 +263,7 @@ if ( ! function_exists('form_textarea')) } $name = is_array($data) ? $data['name'] : $data; - return '\n"; + return '\n"; } } @@ -298,10 +298,10 @@ if ( ! function_exists('form_dropdown')) /** * Drop-down Menu * - * @param mixed $name = '' - * @param mixed $options = array() - * @param mixed $selected = array() - * @param mixed $extra = array() + * @param mixed $name + * @param mixed $options + * @param mixed $selected + * @param mixed $extra * @return string */ function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') @@ -349,7 +349,7 @@ if ( ! function_exists('form_dropdown')) foreach ($val as $optgroup_key => $optgroup_val) { $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; - $form .= '\n"; } @@ -357,7 +357,7 @@ if ( ! function_exists('form_dropdown')) } else { - $form .= '\n"; } @@ -600,17 +600,28 @@ if ( ! function_exists('form_prep')) * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * - * @todo Remove in version 3.1+. - * @deprecated 3.0.0 This function has been broken for a long time - * and is now just an alias for html_escape(). It's - * second argument is ignored. - * @param string $str = '' - * @param string $field_name = '' - * @return string + * @param string|string[] $str Value to escape + * @param bool $is_textarea Whether we're escaping for a textarea element + * @return string|string[] Escaped values */ - function form_prep($str = '', $field_name = '') + function form_prep($str = '', $is_textarea = FALSE) { - return html_escape($str); + if (is_array($str)) + { + foreach (array_keys($str) as $key) + { + $str[$key] = form_prep($str[$key], $is_textarea); + } + + return $str; + } + + if ($is_textarea === TRUE) + { + return str_replace(array('<', '>'), array('<', '>'), stripslashes($str)); + } + + return str_replace(array("'", '"'), array(''', '"'), stripslashes($data)); } } @@ -625,23 +636,21 @@ if ( ! function_exists('set_value')) * re-populate an input field or textarea. If Form Validation * is active it retrieves the info from the validation class * - * @param string - * @param string - * @return mixed + * @param string $field Field name + * @param string $default Default value + * @param bool $is_textarea Whether the field is a textarea element + * @return string */ - function set_value($field = '', $default = '') + function set_value($field = '', $default = '', $is_textarea = FALSE) { if (FALSE === ($OBJ =& _get_validation_object())) { - if ( ! isset($_POST[$field])) - { - return html_escape($default); - } - - return html_escape($_POST[$field]); + return isset($_POST[$field]) + ? form_prep($_POST[$field], $is_textarea) + : form_prep($default, $is_textarea); } - return html_escape($OBJ->set_value($field, $default)); + return form_prep($OBJ->set_value($field, $default), $is_textarea); } } @@ -862,8 +871,8 @@ if ( ! function_exists('_parse_form_attributes')) * * Helper function used by some of the form helpers * - * @param array - * @param array + * @param array $attributes List of attributes + * @param array $default Default values * @return string */ function _parse_form_attributes($attributes, $default) @@ -891,7 +900,7 @@ if ( ! function_exists('_parse_form_attributes')) { if ($key === 'value') { - $val = html_escape($val); + $val = form_prep($val); } elseif ($key === 'name' && ! strlen($default['name'])) { -- cgit v1.2.3-24-g4f1b From 075f6fa31aab069aaa21a4d6f13e3ca850012d05 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 15:18:44 +0200 Subject: Fix an erroneous variable name --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 9c4c4dae6..2f451b402 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -621,7 +621,7 @@ if ( ! function_exists('form_prep')) return str_replace(array('<', '>'), array('<', '>'), stripslashes($str)); } - return str_replace(array("'", '"'), array(''', '"'), stripslashes($data)); + return str_replace(array("'", '"'), array(''', '"'), stripslashes($str)); } } -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/helpers/array_helper.php | 3 ++- system/helpers/captcha_helper.php | 3 ++- system/helpers/cookie_helper.php | 3 ++- system/helpers/date_helper.php | 3 ++- system/helpers/directory_helper.php | 3 ++- system/helpers/download_helper.php | 3 ++- system/helpers/email_helper.php | 3 ++- system/helpers/file_helper.php | 3 ++- system/helpers/form_helper.php | 4 +++- system/helpers/html_helper.php | 3 ++- system/helpers/inflector_helper.php | 3 ++- system/helpers/language_helper.php | 3 ++- system/helpers/number_helper.php | 3 ++- system/helpers/path_helper.php | 3 ++- system/helpers/security_helper.php | 3 ++- system/helpers/smiley_helper.php | 3 ++- system/helpers/string_helper.php | 3 ++- system/helpers/text_helper.php | 3 ++- system/helpers/typography_helper.php | 3 ++- system/helpers/url_helper.php | 3 ++- system/helpers/xml_helper.php | 3 ++- 21 files changed, 43 insertions(+), 21 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index ed2fe3c4a..0e66e4b77 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,4 +1,4 @@ - Date: Fri, 2 Nov 2012 23:33:45 +0200 Subject: Some micro-optimizations --- system/helpers/date_helper.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 5f05f0701..0fa400d7e 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -450,20 +450,13 @@ if ( ! function_exists('human_to_unix')) return FALSE; } - $split = explode(' ', $datestr); + sscanf($datestr, '%d-%d-%d %s %s', $year, $month, $day, $time, $ampm); + sscanf($time, '%d:%d:%d', $hour, $min, $sec); + isset($sec) OR $sec = 0; - list($year, $month, $day) = explode('-', $split[0]); - - $ex = explode(':', $split['1']); - - $hour = (int) $ex[0]; - $min = (int) $ex[1]; - $sec = ( ! empty($ex[2]) && preg_match('/[0-9]{1,2}/', $ex[2])) - ? (int) $ex[2] : 0; - - if (isset($split[2])) + if (isset($ampm)) { - $ampm = strtolower($split[2]); + $ampm = strtolower($ampm); if ($ampm[0] === 'p' && $hour < 12) { -- cgit v1.2.3-24-g4f1b From ba77f8ae39bdbf456159cb48f75aea7127f9cbcd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 15:40:48 +0200 Subject: Fix issue #1978 --- system/helpers/directory_helper.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 7223a2911..e90c92d79 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -47,9 +47,10 @@ if ( ! function_exists('directory_map')) * representation of it. Sub-folders contained with the * directory will be mapped as well. * - * @param string path to source - * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) - * @param bool whether to show hidden files + * @param string $source_dir Path to source + * @param int $directory_depth Depth of directories to traverse + * (0 = fully recursive, 1 = current dir, etc) + * @param bool $hidden Whether to show hidden files * @return array */ function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) @@ -70,7 +71,8 @@ if ( ! function_exists('directory_map')) if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { - $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); + $file .= DIRECTORY_SEPARATOR; + $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden); } else { -- cgit v1.2.3-24-g4f1b From e8b8904bdfd6f8320beb67fb6daa96ee14c3b917 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 15:50:17 +0200 Subject: directory_map() ... the final one --- system/helpers/directory_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index e90c92d79..49dcfc8a9 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -69,9 +69,10 @@ if ( ! function_exists('directory_map')) continue; } + @is_dir($source_dir.$file) AND $file .= DIRECTORY_SEPARATOR; + if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { - $file .= DIRECTORY_SEPARATOR; $filedata[$file] = directory_map($source_dir.$file, $new_depth, $hidden); } else -- cgit v1.2.3-24-g4f1b From 0898e2395df056f5df90a1dd2d5550f0eae4cd7c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 15:13:52 +0200 Subject: Deprecate the Email helper --- system/helpers/email_helper.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 6f5d17255..dfb166a5a 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -43,7 +43,8 @@ if ( ! function_exists('valid_email')) /** * Validate email address * - * @param string + * @deprecated 3.0.0 Use PHP's filter_var() instead + * @param string $email * @return bool */ function valid_email($email) @@ -59,12 +60,13 @@ if ( ! function_exists('send_email')) /** * Send an email * - * @param string - * @param string - * @param string + * @deprecated 3.0.0 Use PHP's mail() instead + * @param string $recipient + * @param string $subject + * @param string $message * @return bool */ - function send_email($recipient, $subject = 'Test email', $message = 'Hello World') + function send_email($recipient, $subject, $message) { return mail($recipient, $subject, $message); } -- cgit v1.2.3-24-g4f1b From f6d9a7cff222f868312a6d4ae4e4050616acb9a7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 17:27:57 +0200 Subject: Polish docs for the File and Form helpers --- system/helpers/file_helper.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 6383007ba..aebb6e47a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -66,12 +66,12 @@ if ( ! function_exists('write_file')) * Writes data to the file specified in the path. * Creates a new file if non-existent. * - * @param string path to file - * @param string file data - * @param int + * @param string $path File path + * @param string $data Data to write + * @param string $mode fopen() mode (default: 'wb') * @return bool */ - function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) + function write_file($path, $data, $mode = 'wb') { if ( ! $fp = @fopen($path, $mode)) { @@ -99,13 +99,13 @@ if ( ! function_exists('delete_files')) * If the second parameter is set to TRUE, any directories contained * within the supplied base directory will be nuked as well. * - * @param string path to file - * @param bool whether to delete any directories found in the path - * @param int - * @param bool whether to skip deleting .htaccess and index page files + * @param string $path File path + * @param bool $del_dir Whether to delete any directories found in the path + * @param bool $htdocs Whether to skip deleting .htaccess and index page files + * @param int $_level Current directory depth level (default: 0; internal use only) * @return bool */ - function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE) + function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0) { // Trim the trailing slash $path = rtrim($path, '/\\'); @@ -121,7 +121,7 @@ if ( ! function_exists('delete_files')) { if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.') { - delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs); + delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $htdocs, $_level + 1); } elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @@ -131,7 +131,7 @@ if ( ! function_exists('delete_files')) } @closedir($current_dir); - if ($del_dir === TRUE && $level > 0) + if ($del_dir === TRUE && $_level > 0) { return @rmdir($path); } @@ -319,12 +319,12 @@ if ( ! function_exists('get_mime_by_extension')) * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience * It should NOT be trusted, and should certainly NOT be used for security * - * @param string path to file - * @return mixed + * @param string $filename File name + * @return string */ - function get_mime_by_extension($file) + function get_mime_by_extension($filename) { - $extension = strtolower(substr(strrchr($file, '.'), 1)); + $extension = strtolower(substr(strrchr($filename, '.'), 1)); static $mimes; @@ -359,7 +359,7 @@ if ( ! function_exists('symbolic_permissions')) * Takes a numeric value representing a file's permissions and returns * standard symbolic notation representing that value * - * @param int + * @param int $perms Permissions * @return string */ function symbolic_permissions($perms) @@ -426,7 +426,7 @@ if ( ! function_exists('octal_permissions')) * Takes a numeric value representing a file's permissions and returns * a three character string representing the file's octal permissions * - * @param int + * @param int $perms Permissions * @return string */ function octal_permissions($perms) -- cgit v1.2.3-24-g4f1b From 53b8ef524529e6ca9f32ad49d36c5140df84feb0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 21:38:53 +0200 Subject: Polish docs for HTML, Inflector, Language, Number, Path, Security and Smiley helpers Also fixed a DB_cache bug introduced in previous commit and removed an unused parameter in a smiley helper --- system/helpers/html_helper.php | 6 +++--- system/helpers/inflector_helper.php | 21 ++++++++++----------- system/helpers/smiley_helper.php | 5 ++--- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 404392f06..fa49f7d75 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -157,12 +157,12 @@ if ( ! function_exists('br')) /** * Generates HTML BR tags based on number supplied * - * @param int + * @param int $count Number of times to repeat the tag * @return string */ - function br($num = 1) + function br($count = 1) { - return str_repeat('
', $num); + return str_repeat('
', $count); } } diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 6f1086a00..59cb296b2 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -45,7 +45,7 @@ if ( ! function_exists('singular')) * * Takes a plural word and makes it singular * - * @param string + * @param string $str Input string * @return string */ function singular($str) @@ -109,11 +109,10 @@ if ( ! function_exists('plural')) * * Takes a singular word and makes it plural * - * @param string - * @param bool + * @param string $str Input string * @return string */ - function plural($str, $force = FALSE) + function plural($str) { $result = strval($str); @@ -166,7 +165,7 @@ if ( ! function_exists('camelize')) * * Takes multiple words separated by spaces or underscores and camelizes them * - * @param string + * @param string $str Input string * @return string */ function camelize($str) @@ -184,7 +183,7 @@ if ( ! function_exists('underscore')) * * Takes multiple words separated by spaces and underscores them * - * @param string + * @param string $str Input string * @return string */ function underscore($str) @@ -202,8 +201,8 @@ if ( ! function_exists('humanize')) * * Takes multiple words separated by the separator and changes them to spaces * - * @param string $str - * @param string $separator + * @param string $str Input string + * @param string $separator Input separator * @return string */ function humanize($str, $separator = '_') @@ -219,12 +218,12 @@ if ( ! function_exists('is_countable')) /** * Checks if the given word has a plural version. * - * @param string the word to check - * @return bool if the word is countable + * @param string $word Word to check + * @return bool */ function is_countable($word) { - return ! in_array(strtolower(strval($word)), + return ! in_array(strtolower($word), array( 'equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'meta' diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 6ae8937ee..4b491758e 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -131,10 +131,9 @@ if ( ! function_exists('get_clickable_smileys')) * * @param string the URL to the folder containing the smiley images * @param array - * @param array * @return array */ - function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) + function get_clickable_smileys($image_url, $alias = '') { // For backward compatibility with js_insert_smiley if (is_array($alias)) @@ -143,7 +142,7 @@ if ( ! function_exists('get_clickable_smileys')) } elseif (FALSE === ($smileys = _get_smiley_array())) { - return $smileys; + return FALSE; } // Add a trailing slash to the file path if needed -- cgit v1.2.3-24-g4f1b From f7c39d6a123a73d90e4e9ebca2c66ed75731ab32 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 22:01:33 +0200 Subject: Deprecate String helper trim_slashes() trim(, '/') is even shorter ... --- system/helpers/string_helper.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index c895d5767..5177a7e59 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -51,6 +51,9 @@ if ( ! function_exists('trim_slashes')) * * this/that/theother * + * @todo Remove in version 3.1+. + * @deprecated 3.0.0 This is just an alias for PHP's native trim() + * * @param string * @return string */ -- cgit v1.2.3-24-g4f1b From 442682e488181a9e9139f02bb657e501eb78573d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 22:52:12 +0200 Subject: Polish docs for String, Text and Typography helpers --- 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 5177a7e59..9fc24559a 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -218,10 +218,10 @@ if ( ! function_exists('random_string')) break; } return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len); - case 'unique': + case 'unique': // todo: remove in 3.1+ case 'md5': return md5(uniqid(mt_rand())); - case 'encrypt': + case 'encrypt': // todo: remove in 3.1+ case 'sha1': return sha1(uniqid(mt_rand(), TRUE)); } -- cgit v1.2.3-24-g4f1b From 08f0f8b751c0e956e12fade9f6eea2bd581042ac Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Nov 2012 10:27:43 +0200 Subject: Polish docs for URL and XML helpers and deprecate obsolete options for String helper random_string() and URL helper url_title() --- system/helpers/url_helper.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 8e9cb7b03..0aa358a0b 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -474,9 +474,11 @@ if ( ! function_exists('url_title')) * human-friendly URL string with a "separator" string * as the word separator. * - * @param string the string - * @param string the separator - * @param bool + * @todo Remove old 'dash' and 'underscore' usage in 3.1+. + * @param string $str Input string + * @param string $separator Word separator + * (usually '-' or '_') + * @param bool $lowercase Wether to transform the output string to lowercase * @return string */ function url_title($str, $separator = '-', $lowercase = FALSE) @@ -525,10 +527,11 @@ if ( ! function_exists('redirect')) * For very fine grained control over headers, you could use the Output * Library's set_header() function. * - * @param string the URL - * @param string the method: location or refresh - * @param int - * @return string + * @param string $uri URL + * @param string $method Redirect method + * 'auto', 'location' or 'refresh' + * @param int $code HTTP Response status code + * @return void */ function redirect($uri = '', $method = 'auto', $code = NULL) { -- cgit v1.2.3-24-g4f1b From 7a7ad782b2f125622509a77c5a6f94ad4ae0f93c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Nov 2012 17:21:01 +0200 Subject: Some micro-optimizations --- system/helpers/date_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 0fa400d7e..7a0552b0b 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -677,8 +677,8 @@ if ( ! function_exists('date_range')) $is_unix = ! ( ! $is_unix OR $is_unix === 'days'); // Validate input and try strtotime() on invalid timestamps/intervals, just in case - if ( ( ! preg_match('/^[0-9]+$/', $unix_start) && ($unix_start = @strtotime($unix_time)) === FALSE) - OR ( ! preg_match('/^[0-9]+$/', $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE)) + if ( ( ! ctype_digit((string) $unix_start) && ($unix_start = @strtotime($unix_time)) === FALSE) + OR ( ! ctype_digit((string) $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE)) OR ($is_unix === TRUE && $mixed < $unix_start)) { return FALSE; -- cgit v1.2.3-24-g4f1b From 69779afa2882576d5e45f752dcee4107a07e27b0 Mon Sep 17 00:00:00 2001 From: webmasterar Date: Sat, 17 Nov 2012 01:06:41 +0000 Subject: Corrected phpdoc comment for mysql_to_unix() method --- system/helpers/date_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 7a0552b0b..d54e01968 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -360,8 +360,8 @@ if ( ! function_exists('mysql_to_unix')) /** * Converts a MySQL Timestamp to Unix * - * @param int Unix timestamp - * @return int + * @param int MySQL timestamp YYYY-MM-DD HH:MM:SS + * @return int Unix timstamp */ function mysql_to_unix($time = '') { -- cgit v1.2.3-24-g4f1b From 53fff911de3564c8688550452f138991730a704f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Nov 2012 16:57:23 +0200 Subject: Added support for stream-like downloads of existing files to force_download() Based on code/ideas from PR #365, #1254 --- system/helpers/download_helper.php | 41 +++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 8fe66e222..31652d53e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -56,6 +56,23 @@ if ( ! function_exists('force_download')) { return FALSE; } + elseif ($data === NULL) + { + if (@is_file($filename) && @file_exists($filename) && ($filesize = @filesize($filename)) !== FALSE) + { + $filepath = $filename; + $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename)); + $filename = end($filename); + } + else + { + return FALSE; + } + } + else + { + $filesize = strlen($data); + } // Set the default MIME type to send $mime = 'application/octet-stream'; @@ -95,8 +112,13 @@ if ( ! function_exists('force_download')) $filename = implode('.', $x); } + if ($data === NULL && ($fp = @fopen($filepath, 'rb')) === FALSE) + { + return FALSE; + } + // Clean output buffer - if (ob_get_level() !== 0) + if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) { ob_clean(); } @@ -106,7 +128,7 @@ if ( ! function_exists('force_download')) header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Expires: 0'); header('Content-Transfer-Encoding: binary'); - header('Content-Length: '.strlen($data)); + header('Content-Length: '.$filesize); // Internet Explorer-specific headers if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) @@ -116,7 +138,20 @@ if ( ! function_exists('force_download')) header('Pragma: no-cache'); - exit($data); + // If we have raw data - just dump it + if ($data !== NULL) + { + exit($data); + } + + // Flush 1MB chunks of data + while ( ! feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) + { + echo $data; + } + + fclose($fp); + exit; } } -- cgit v1.2.3-24-g4f1b From 3b407060439258c7ef9f30ac35b5f9f34101fd69 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Nov 2012 23:55:37 +0200 Subject: Language helper lang() to accept optional HTML attributes (an improved version of PR #1235) --- system/helpers/language_helper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 658be6de7..f931208e1 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -45,18 +45,19 @@ if ( ! function_exists('lang')) * * Fetches a language variable and optionally outputs a form label * - * @param string the language line - * @param string the id of the form element + * @param string $line The language line + * @param string $for The "for" value (id of the form element) + * @param array $attributes Any additional HTML attributes * @return string */ - function lang($line, $id = '') + function lang($line, $for = '', $attributes = array()) { $CI =& get_instance(); $line = $CI->lang->line($line); if ($id !== '') { - $line = ''; + $line = ''; } return $line; -- cgit v1.2.3-24-g4f1b From 719b60f7e84e7060b679a9359a487f5cbbb937bf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Nov 2012 00:05:06 +0200 Subject: Fix some erroneous variable names (sorry) --- system/helpers/language_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index f931208e1..6d24a9ca6 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -55,9 +55,9 @@ if ( ! function_exists('lang')) $CI =& get_instance(); $line = $CI->lang->line($line); - if ($id !== '') + if ($for !== '') { - $line = ''; + $line = ''; } return $line; -- cgit v1.2.3-24-g4f1b From 838a9d69a9139b6bcd6f8765fdd2d58b929e70ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Dec 2012 14:37:47 +0200 Subject: [ci skip] Cleaned some spaces --- system/helpers/form_helper.php | 1 - system/helpers/inflector_helper.php | 52 ++++++++++++++++++------------------- system/helpers/smiley_helper.php | 1 - system/helpers/text_helper.php | 2 +- system/helpers/url_helper.php | 2 +- 5 files changed, 28 insertions(+), 30 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e7bea92cc..c7e6d4933 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -814,7 +814,6 @@ if ( ! function_exists('set_radio')) // ------------------------------------------------------------------------ - if ( ! function_exists('form_error')) { /** diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 59cb296b2..68af820c5 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -58,33 +58,33 @@ if ( ! function_exists('singular')) } $singular_rules = array( - '/(matr)ices$/' => '\1ix', - '/(vert|ind)ices$/' => '\1ex', - '/^(ox)en/' => '\1', - '/(alias)es$/' => '\1', - '/([octop|vir])i$/' => '\1us', - '/(cris|ax|test)es$/' => '\1is', - '/(shoe)s$/' => '\1', - '/(o)es$/' => '\1', - '/(bus|campus)es$/' => '\1', - '/([m|l])ice$/' => '\1ouse', - '/(x|ch|ss|sh)es$/' => '\1', - '/(m)ovies$/' => '\1\2ovie', - '/(s)eries$/' => '\1\2eries', - '/([^aeiouy]|qu)ies$/' => '\1y', - '/([lr])ves$/' => '\1f', - '/(tive)s$/' => '\1', - '/(hive)s$/' => '\1', - '/([^f])ves$/' => '\1fe', - '/(^analy)ses$/' => '\1sis', + '/(matr)ices$/' => '\1ix', + '/(vert|ind)ices$/' => '\1ex', + '/^(ox)en/' => '\1', + '/(alias)es$/' => '\1', + '/([octop|vir])i$/' => '\1us', + '/(cris|ax|test)es$/' => '\1is', + '/(shoe)s$/' => '\1', + '/(o)es$/' => '\1', + '/(bus|campus)es$/' => '\1', + '/([m|l])ice$/' => '\1ouse', + '/(x|ch|ss|sh)es$/' => '\1', + '/(m)ovies$/' => '\1\2ovie', + '/(s)eries$/' => '\1\2eries', + '/([^aeiouy]|qu)ies$/' => '\1y', + '/([lr])ves$/' => '\1f', + '/(tive)s$/' => '\1', + '/(hive)s$/' => '\1', + '/([^f])ves$/' => '\1fe', + '/(^analy)ses$/' => '\1sis', '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/' => '\1\2sis', - '/([ti])a$/' => '\1um', - '/(p)eople$/' => '\1\2erson', - '/(m)en$/' => '\1an', - '/(s)tatuses$/' => '\1\2tatus', - '/(c)hildren$/' => '\1\2hild', - '/(n)ews$/' => '\1\2ews', - '/([^us])s$/' => '\1', + '/([ti])a$/' => '\1um', + '/(p)eople$/' => '\1\2erson', + '/(m)en$/' => '\1an', + '/(s)tatuses$/' => '\1\2tatus', + '/(c)hildren$/' => '\1\2hild', + '/(n)ews$/' => '\1\2ews', + '/([^us])s$/' => '\1' ); foreach ($singular_rules as $rule => $replacement) diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 4b491758e..7293999fe 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -120,7 +120,6 @@ EOF; // ------------------------------------------------------------------------ - if ( ! function_exists('get_clickable_smileys')) { /** diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index cce659231..705238704 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -139,7 +139,7 @@ if ( ! function_exists('ascii_to_entities')) */ if (count($temp) === 1) { - $out .= '&#'.array_shift($temp).';'; + $out .= '&#'.array_shift($temp).';'; $count = 1; } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 0aa358a0b..14c216afe 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -293,7 +293,7 @@ if ( ! function_exists('safe_mailto')) { foreach ($attributes as $key => $val) { - $x[] = ' '.$key.'="'; + $x[] = ' '.$key.'="'; for ($i = 0, $l = strlen($val); $i < $l; $i++) { $x[] = '|'.ord($val[$i]); -- cgit v1.2.3-24-g4f1b From 16800e4e356fa1aa3d92d368e6e495b97b64ad83 Mon Sep 17 00:00:00 2001 From: Aaron Adams Date: Fri, 7 Dec 2012 22:39:23 -0500 Subject: While most of CodeIgniter supports protocol-relative URLs, a few URL helpers do not. Most notably, redirect('//www.facebook.com/aaronadams') led my browser to https://aaronadams.ca/index.php/www.facebook.com/aaronadams. In this commit, I have fixed the header() helper, along with the anchor() and anchor_popup() helpers, to be compatible with protocol-relative URLs. Signed-off-by: Aaron Adams --- system/helpers/url_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 14c216afe..36ff0ff2c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -152,7 +152,7 @@ if ( ! function_exists('anchor')) if ( ! is_array($uri)) { - $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri); + $site_url = preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri); } else { @@ -191,7 +191,7 @@ if ( ! function_exists('anchor_popup')) function anchor_popup($uri = '', $title = '', $attributes = FALSE) { $title = (string) $title; - $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri); + $site_url = preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri); if ($title === '') { @@ -535,7 +535,7 @@ if ( ! function_exists('redirect')) */ function redirect($uri = '', $method = 'auto', $code = NULL) { - if ( ! preg_match('#^https?://#i', $uri)) + if ( ! preg_match('#^(\w+:)?//#i', $uri)) { $uri = site_url($uri); } -- cgit v1.2.3-24-g4f1b