From dd6719738936be31cdaa1758ca86d5eb14dcab3d Mon Sep 17 00:00:00 2001 From: Barry Mieny Date: Mon, 4 Oct 2010 16:33:58 +0200 Subject: Cleanup of stray spaces and tabs --- system/helpers/array_helper.php | 8 +- system/helpers/captcha_helper.php | 74 ++++----- system/helpers/compatibility_helper.php | 96 ++++++------ system/helpers/cookie_helper.php | 8 +- system/helpers/date_helper.php | 170 ++++++++++---------- system/helpers/directory_helper.php | 8 +- system/helpers/download_helper.php | 10 +- system/helpers/email_helper.php | 4 +- system/helpers/file_helper.php | 70 ++++----- system/helpers/form_helper.php | 36 ++--- system/helpers/html_helper.php | 6 +- system/helpers/inflector_helper.php | 44 +++--- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 12 +- system/helpers/path_helper.php | 10 +- system/helpers/security_helper.php | 24 +-- system/helpers/smiley_helper.php | 36 ++--- system/helpers/string_helper.php | 62 ++++---- system/helpers/text_helper.php | 264 ++++++++++++++++---------------- system/helpers/typography_helper.php | 12 +- system/helpers/url_helper.php | 24 +-- system/helpers/xml_helper.php | 18 +-- 22 files changed, 499 insertions(+), 499 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index b7289900f..bd30b7c16 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -38,7 +38,7 @@ * @param array * @param mixed * @return mixed depends on what the array contains - */ + */ if ( ! function_exists('element')) { function element($item, $array, $default = FALSE) @@ -49,7 +49,7 @@ if ( ! function_exists('element')) } return $array[$item]; - } + } } // ------------------------------------------------------------------------ @@ -60,7 +60,7 @@ if ( ! function_exists('element')) * @access public * @param array * @return mixed depends on what the array contains - */ + */ if ( ! function_exists('random_element')) { function random_element($array) @@ -70,7 +70,7 @@ if ( ! function_exists('random_element')) return $array; } return $array[array_rand($array)]; - } + } } diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 67db50947..3c80bb756 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -40,9 +40,9 @@ if ( ! function_exists('create_captcha')) { 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); - + { + $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); + foreach ($defaults as $key => $val) { if ( ! is_array($data)) @@ -53,11 +53,11 @@ if ( ! function_exists('create_captcha')) } } else - { + { $$key = ( ! isset($data[$key])) ? $val : $data[$key]; } } - + if ($img_path == '' OR $img_url == '') { return FALSE; @@ -67,45 +67,45 @@ if ( ! function_exists('create_captcha')) { return FALSE; } - + if ( ! is_writable($img_path)) { return FALSE; } - + if ( ! extension_loaded('gd')) { return FALSE; - } - + } + // ----------------------------------- - // Remove old images + // Remove old images // ----------------------------------- - + list($usec, $sec) = explode(" ", microtime()); $now = ((float)$usec + (float)$sec); - + $current_dir = @opendir($img_path); - + while($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { $name = str_replace(".jpg", "", $filename); - + if (($name + $expiration) < $now) { @unlink($img_path.$filename); } } } - + @closedir($current_dir); // ----------------------------------- // Do we have a "word" yet? // ----------------------------------- - + if ($word == '') { $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -115,23 +115,23 @@ if ( ! function_exists('create_captcha')) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } - + $word = $str; } - + // ----------------------------------- - // Determine angle and position + // Determine angle and position // ----------------------------------- - + $length = strlen($word); $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; - $x_axis = rand(6, (360/$length)-16); + $x_axis = rand(6, (360/$length)-16); $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height); - + // ----------------------------------- // Create image // ----------------------------------- - + // PHP.net recommends imagecreatetruecolor(), but it isn't always available if (function_exists('imagecreatetruecolor')) { @@ -141,11 +141,11 @@ if ( ! function_exists('create_captcha')) { $im = imagecreate($img_width, $img_height); } - + // ----------------------------------- // Assign colors // ----------------------------------- - + $bg_color = imagecolorallocate ($im, 255, 255, 255); $border_color = imagecolorallocate ($im, 153, 102, 102); $text_color = imagecolorallocate ($im, 204, 153, 153); @@ -155,13 +155,13 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Create the rectangle // ----------------------------------- - + ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); - + // ----------------------------------- // Create the spiral pattern // ----------------------------------- - + $theta = 1; $thetac = 7; $radius = 16; @@ -185,9 +185,9 @@ if ( ! function_exists('create_captcha')) // ----------------------------------- // Write the text // ----------------------------------- - + $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; - + if ($use_font == FALSE) { $font_size = 5; @@ -210,32 +210,32 @@ if ( ! function_exists('create_captcha')) $x += ($font_size*2); } else - { + { $y = rand($img_height/2, $img_height-3); imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); $x += $font_size; } } - + // ----------------------------------- // Create the border // ----------------------------------- - imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); + imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); // ----------------------------------- // Generate the image // ----------------------------------- - + $img_name = $now.'.jpg'; ImageJPEG($im, $img_path.$img_name); - + $img = "\""; - + ImageDestroy($im); - + return array('word' => $word, 'time' => $now, 'image' => $img); } } diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 4d7d466f5..912eae6e2 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -20,13 +20,13 @@ * * This helper contains some functions based on the PEAR PHP_Compat library * http://pear.php.net/package/PHP_Compat - * + * * The PEAR compat library is a little bloated and the code doesn't harmonize * well with CodeIgniter, so those functions have been refactored. * We cheat a little and use CI's _exception_handler() to output our own PHP errors * so that the behavior fully mimicks the PHP 5 counterparts. -- Derek Jones * @PHP4 - * + * * @package CodeIgniter * @subpackage Helpers * @category Helpers @@ -39,7 +39,7 @@ if ( ! defined('PHP_EOL')) { define('PHP_EOL', (DIRECTORY_SEPARATOR == '/') ? "\n" : "\r\n"); -} +} // ------------------------------------------------------------------------ @@ -83,16 +83,16 @@ if ( ! function_exists('file_put_contents')) } $text = ''; - + while ( ! feof($data)) { $text .= fread($data, 4096); } - + $data = $text; unset($text); } - + // strings only please! if (is_array($data)) { @@ -108,7 +108,7 @@ if ( ! function_exists('file_put_contents')) { $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE; } - + // Check if we're using the include path if (($flags & 1) > 0) // 1 = FILE_USE_INCLUDE_PATH flag { @@ -118,16 +118,16 @@ if ( ! function_exists('file_put_contents')) { $use_include_path = FALSE; } - + $fp = @fopen($filename, $mode, $use_include_path); - + if ($fp === FALSE) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to open stream', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + if (($flags & LOCK_EX) > 0) { if ( ! flock($fp, LOCK_EX)) @@ -137,17 +137,17 @@ if ( ! function_exists('file_put_contents')) return FALSE; } } - + // write it if (($written = @fwrite($fp, $data)) === FALSE) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to write to '.htmlentities($filename), $backtrace[0]['file'], $backtrace[0]['line']); } - + // Close the handle @fclose($fp); - + // Return length return $written; } @@ -179,7 +179,7 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.gettype($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // OK, it is a resource, but is it a stream? if (get_resource_type($handle) !== 'stream') { @@ -187,7 +187,7 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.get_resource_type($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // Checking for an array of fields if ( ! is_array($fields)) { @@ -195,7 +195,7 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 2 to be array, '.gettype($fields).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // validate delimiter if (strlen($delimiter) > 1) { @@ -203,7 +203,7 @@ if ( ! function_exists('fputcsv')) $backtrace = debug_backtrace(); _exception_handler(E_NOTICE, 'fputcsv() delimiter must be one character long, "'.htmlentities($delimiter).'" used', $backtrace[0]['file'], $backtrace[0]['line']); } - + // validate enclosure if (strlen($enclosure) > 1) { @@ -212,9 +212,9 @@ if ( ! function_exists('fputcsv')) _exception_handler(E_NOTICE, 'fputcsv() enclosure must be one character long, "'.htmlentities($enclosure).'" used', $backtrace[0]['file'], $backtrace[0]['line']); } - + $out = ''; - + foreach ($fields as $cell) { $cell = str_replace($enclosure, $enclosure.$enclosure, $cell); @@ -228,9 +228,9 @@ if ( ! function_exists('fputcsv')) $out .= $cell.$delimiter; } } - + $length = @fwrite($handle, substr($out, 0, -1)."\n"); - + return $length; } } @@ -258,33 +258,33 @@ if ( ! function_exists('stripos')) { settype($haystack, 'STRING'); } - + if ( ! is_string($haystack)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() expects parameter 1 to be string, '.gettype($haystack).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + if ( ! is_scalar($needle)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() needle is not a string or an integer in '.$backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + if (is_float($offset)) { $offset = (int)$offset; } - + if ( ! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() expects parameter 3 to be long, '.gettype($offset).' given', $backtrace[0]['file'], $backtrace[0]['line']); return NULL; } - + return strpos(strtolower($haystack), strtolower($needle), $offset); } } @@ -314,7 +314,7 @@ if ( ! function_exists('str_ireplace')) { return $subject; } - + // Crazy arguments if (is_scalar($search) && is_array($replace)) { @@ -329,7 +329,7 @@ if ( ! function_exists('str_ireplace')) _exception_handler(E_USER_NOTICE, 'Array to string conversion in '.$backtrace[0]['file'], $backtrace[0]['line']); } } - + // Searching for an array if (is_array($search)) { @@ -360,28 +360,28 @@ if ( ! function_exists('str_ireplace')) $search = array((string)$search); $replace = array((string)$replace); } - + // Prepare the search array foreach ($search as $search_key => $search_value) { $search[$search_key] = '/'.preg_quote($search_value, '/').'/i'; } - + // Prepare the replace array (escape backreferences) foreach ($replace as $k => $v) { $replace[$k] = str_replace(array(chr(92), '$'), array(chr(92).chr(92), '\$'), $v); } - + // do the replacement $result = preg_replace($search, $replace, (array)$subject); - + // Check if subject was initially a string and return it as a string if ( ! is_array($subject)) { return current($result); } - + // Otherwise, just return the array return $result; } @@ -412,19 +412,19 @@ if ( ! function_exists('http_build_query')) _exception_handler(E_USER_WARNING, 'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - + // Cast it as array if (is_object($formdata)) { $formdata = get_object_vars($formdata); } - + // If the array is empty, return NULL if (empty($formdata)) { return NULL; } - + // Argument separator if ($separator === NULL) { @@ -435,7 +435,7 @@ if ( ! function_exists('http_build_query')) $separator = '&'; } } - + // Start building the query $tmp = array(); @@ -445,36 +445,36 @@ if ( ! function_exists('http_build_query')) { continue; } - + if (is_integer($key) && $numeric_prefix != NULL) { $key = $numeric_prefix.$key; } - + if (is_resource($val)) { return NULL; } - + // hand it off to a recursive parser $tmp[] = _http_build_query_helper($key, $val, $separator); } - + return implode($separator, $tmp); } - - + + // Helper helper. Remind anyone of college? // Required to handle recursion in nested arrays. - // + // // You could shave fractions of fractions of a second by moving where // the urlencoding takes place, but it's much less intuitive, and if // your application has 10,000 form fields, well, you have other problems ;) function _http_build_query_helper($key, $val, $separator = '&') - { + { if (is_scalar($val)) { - return urlencode($key).'='.urlencode($val); + return urlencode($key).'='.urlencode($val); } else { @@ -483,13 +483,13 @@ if ( ! function_exists('http_build_query')) { $val = get_object_vars($val); } - + foreach ($val as $k => $v) { $tmp[] = _http_build_query_helper($key.'['.$k.']', $v, $separator); } } - + return implode($separator, $tmp); } } diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 4be371efe..2821fadb1 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -51,7 +51,7 @@ if ( ! function_exists('set_cookie')) $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix); } } - + // -------------------------------------------------------------------- /** @@ -67,14 +67,14 @@ if ( ! function_exists('get_cookie')) function get_cookie($index = '', $xss_clean = FALSE) { $CI =& get_instance(); - + $prefix = ''; - + if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') { $prefix = config_item('cookie_prefix'); } - + return $CI->input->cookie($prefix.$index, $xss_clean); } } diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 2c60f0302..e762be007 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -34,24 +34,24 @@ * * @access public * @return integer - */ + */ if ( ! function_exists('now')) { function now() { $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 (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.'); } - + return $system_time; } else @@ -60,7 +60,7 @@ if ( ! function_exists('now')) } } } - + // ------------------------------------------------------------------------ /** @@ -79,22 +79,22 @@ if ( ! function_exists('now')) * @param string * @param integer * @return integer - */ + */ if ( ! function_exists('mdate')) { function mdate($datestr = '', $time = '') { if ($datestr == '') return ''; - + if ($time == '') $time = now(); - + $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); return date($datestr, $time); } } - + // ------------------------------------------------------------------------ /** @@ -106,7 +106,7 @@ if ( ! function_exists('mdate')) * @param string the chosen format * @param integer Unix timestamp * @return string - */ + */ if ( ! function_exists('standard_date')) { function standard_date($fmt = 'DATE_RFC822', $time = '') @@ -127,11 +127,11 @@ if ( ! function_exists('standard_date')) { return FALSE; } - + return mdate($formats[$fmt], $time); } } - + // ------------------------------------------------------------------------ /** @@ -144,7 +144,7 @@ if ( ! function_exists('standard_date')) * @param integer a number of seconds * @param integer Unix timestamp * @return integer - */ + */ if ( ! function_exists('timespan')) { function timespan($seconds = 1, $time = '') @@ -156,12 +156,12 @@ if ( ! function_exists('timespan')) { $seconds = 1; } - + if ( ! is_numeric($time)) { $time = time(); } - + if ($time <= $seconds) { $seconds = 1; @@ -170,85 +170,85 @@ if ( ! function_exists('timespan')) { $seconds = $time - $seconds; } - + $str = ''; $years = floor($seconds / 31536000); - + if ($years > 0) - { + { $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; - } - + } + $seconds -= $years * 31536000; $months = floor($seconds / 2628000); - + if ($years > 0 OR $months > 0) { if ($months > 0) - { + { $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; - } - + } + $seconds -= $months * 2628000; } $weeks = floor($seconds / 604800); - + if ($years > 0 OR $months > 0 OR $weeks > 0) { if ($weeks > 0) - { + { $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; } - + $seconds -= $weeks * 604800; - } + } $days = floor($seconds / 86400); - + if ($months > 0 OR $weeks > 0 OR $days > 0) { if ($days > 0) - { + { $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; } - + $seconds -= $days * 86400; } - + $hours = floor($seconds / 3600); - + if ($days > 0 OR $hours > 0) { if ($hours > 0) { $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; } - + $seconds -= $hours * 3600; } - + $minutes = floor($seconds / 60); - + if ($days > 0 OR $hours > 0 OR $minutes > 0) { if ($minutes > 0) - { + { $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } - + $seconds -= $minutes * 60; } - + if ($str == '') { $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; } - + return substr(trim($str), 0, -1); } } - + // ------------------------------------------------------------------------ /** @@ -261,7 +261,7 @@ if ( ! function_exists('timespan')) * @param integer a numeric month * @param integer a numeric year * @return integer - */ + */ if ( ! function_exists('days_in_month')) { function days_in_month($month = 0, $year = '') @@ -270,12 +270,12 @@ if ( ! function_exists('days_in_month')) { return 0; } - + if ( ! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } - + if ($month == 2) { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) @@ -297,18 +297,18 @@ if ( ! function_exists('days_in_month')) * @access public * @param integer Unix timestamp * @return integer - */ + */ if ( ! function_exists('local_to_gmt')) { function local_to_gmt($time = '') { if ($time == '') $time = time(); - + return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time)); } } - + // ------------------------------------------------------------------------ /** @@ -323,23 +323,23 @@ if ( ! function_exists('local_to_gmt')) * @param string timezone * @param bool whether DST is active * @return integer - */ + */ if ( ! function_exists('gmt_to_local')) { function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) - { + { if ($time == '') { return now(); } - + $time += timezones($timezone) * 3600; if ($dst == TRUE) { $time += 3600; } - + return $time; } } @@ -352,7 +352,7 @@ if ( ! function_exists('gmt_to_local')) * @access public * @param integer Unix timestamp * @return integer - */ + */ if ( ! function_exists('mysql_to_unix')) { function mysql_to_unix($time = '') @@ -360,11 +360,11 @@ if ( ! function_exists('mysql_to_unix')) // We'll remove certain characters for backward compatibility // since the formatting changed with MySQL 4.1 // YYYY-MM-DD HH:MM:SS - + $time = str_replace('-', '', $time); $time = str_replace(':', '', $time); $time = str_replace(' ', '', $time); - + // YYYYMMDDHHMMSS return mktime( substr($time, 8, 2), @@ -376,7 +376,7 @@ if ( ! function_exists('mysql_to_unix')) ); } } - + // ------------------------------------------------------------------------ /** @@ -389,13 +389,13 @@ if ( ! function_exists('mysql_to_unix')) * @param bool whether to show seconds * @param string format: us or euro * @return string - */ + */ if ( ! function_exists('unix_to_human')) { function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; - + if ($fmt == 'us') { $r .= date('h', $time).':'.date('i', $time); @@ -404,21 +404,21 @@ if ( ! function_exists('unix_to_human')) { $r .= date('H', $time).':'.date('i', $time); } - + if ($seconds) { $r .= ':'.date('s', $time); } - + if ($fmt == 'us') { $r .= ' '.date('A', $time); } - + return $r; } } - + // ------------------------------------------------------------------------ /** @@ -429,7 +429,7 @@ if ( ! function_exists('unix_to_human')) * @access public * @param string format: us or euro * @return integer - */ + */ if ( ! function_exists('human_to_unix')) { function human_to_unix($datestr = '') @@ -438,25 +438,25 @@ if ( ! function_exists('human_to_unix')) { return FALSE; } - + $datestr = trim($datestr); $datestr = preg_replace("/\040+/", ' ', $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)) { return FALSE; } - + $split = explode(' ', $datestr); $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']; $ex = explode(":", $split['1']); - + $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; @@ -469,25 +469,25 @@ if ( ! function_exists('human_to_unix')) // Unless specified, seconds get set to zero. $sec = '00'; } - + if (isset($split['2'])) { $ampm = strtolower($split['2']); - + if (substr($ampm, 0, 1) == 'p' AND $hour < 12) $hour = $hour + 12; - + if (substr($ampm, 0, 1) == 'a' AND $hour == 12) $hour = '00'; - + if (strlen($hour) == 1) $hour = '0'.$hour; } - + return mktime($hour, $min, $sec, $month, $day, $year); } } - + // ------------------------------------------------------------------------ /** @@ -500,26 +500,26 @@ if ( ! function_exists('human_to_unix')) * @param string classname * @param string menu name * @return string - */ + */ if ( ! function_exists('timezone_menu')) { function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { $CI =& get_instance(); $CI->lang->load('date'); - + if ($default == 'GMT') $default = 'UTC'; $menu = '"; } @@ -279,7 +279,7 @@ if ( ! function_exists('form_multiselect')) { $extra .= ' multiple="multiple"'; } - + return form_dropdown($name, $options, $selected, $extra); } } @@ -414,7 +414,7 @@ if ( ! function_exists('form_radio')) function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if ( ! is_array($data)) - { + { $data = array('name' => $data); } @@ -435,7 +435,7 @@ if ( ! function_exists('form_radio')) * @return string */ if ( ! function_exists('form_submit')) -{ +{ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); @@ -512,7 +512,7 @@ if ( ! function_exists('form_label')) if ($id != '') { - $label .= " for=\"$id\""; + $label .= " for=\"$id\""; } if (is_array($attributes) AND count($attributes) > 0) @@ -610,7 +610,7 @@ if ( ! function_exists('form_prep')) 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)) { @@ -635,7 +635,7 @@ if ( ! function_exists('form_prep')) { return $str; } - + $str = htmlspecialchars($str); // In case htmlspecialchars misses these. @@ -645,7 +645,7 @@ if ( ! function_exists('form_prep')) { $prepped_fields[$field_name] = $field_name; } - + return $str; } } @@ -757,7 +757,7 @@ if ( ! function_exists('set_checkbox')) $OBJ =& _get_validation_object(); if ($OBJ === FALSE) - { + { if ( ! isset($_POST[$field])) { if (count($_POST) === 0 AND $default == TRUE) @@ -768,7 +768,7 @@ if ( ! function_exists('set_checkbox')) } $field = $_POST[$field]; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -823,7 +823,7 @@ if ( ! function_exists('set_radio')) } $field = $_POST[$field]; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -933,7 +933,7 @@ if ( ! function_exists('_parse_form_attributes')) } $att = ''; - + foreach ($default as $key => $val) { if ($key == 'value') @@ -978,7 +978,7 @@ if ( ! function_exists('_attributes_to_string')) return ' '.$attributes; } - + if (is_object($attributes) AND count($attributes) > 0) { $attributes = (array)$attributes; diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index cd7b4ce6b..1c8603dbc 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -388,9 +388,9 @@ 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']; + $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']; $str .= ''.$newline; diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index c4c530bc5..cd05c8d6d 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -36,14 +36,14 @@ * @access public * @param string * @return str - */ + */ if ( ! function_exists('singular')) -{ +{ function singular($str) { $str = strtolower(trim($str)); $end = substr($str, -3); - + if ($end == 'ies') { $str = substr($str, 0, strlen($str)-3).'y'; @@ -55,13 +55,13 @@ if ( ! function_exists('singular')) else { $end = substr($str, -1); - + if ($end == 's') { $str = substr($str, 0, strlen($str)-1); } } - + return $str; } } @@ -77,9 +77,9 @@ if ( ! function_exists('singular')) * @param string * @param bool * @return str - */ + */ if ( ! function_exists('plural')) -{ +{ function plural($str, $force = FALSE) { $str = strtolower(trim($str)); @@ -93,14 +93,14 @@ if ( ! function_exists('plural')) } elseif ($end == 'h') { - if (substr($str, -2) == 'ch' || substr($str, -2) == 'sh') - { - $str .= 'es'; - } - else - { - $str .= 's'; - } + if (substr($str, -2) == 'ch' || substr($str, -2) == 'sh') + { + $str .= 'es'; + } + else + { + $str .= 's'; + } } elseif ($end == 's') { @@ -128,11 +128,11 @@ if ( ! function_exists('plural')) * @access public * @param string * @return str - */ + */ if ( ! function_exists('camelize')) -{ +{ function camelize($str) - { + { $str = 'x'.strtolower(trim($str)); $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); return substr(str_replace(' ', '', $str), 1); @@ -149,7 +149,7 @@ if ( ! function_exists('camelize')) * @access public * @param string * @return str - */ + */ if ( ! function_exists('underscore')) { function underscore($str) @@ -168,15 +168,15 @@ if ( ! function_exists('underscore')) * @access public * @param string * @return str - */ + */ if ( ! function_exists('humanize')) -{ +{ function humanize($str) { return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str)))); } } - + /* End of file inflector_helper.php */ /* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 442619c93..c6bbe8636 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -36,7 +36,7 @@ * @param string the language line * @param string the id of the form element * @return string - */ + */ if ( ! function_exists('lang')) { function lang($line, $id = '') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index f7979215c..e4535f620 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -40,23 +40,23 @@ if ( ! function_exists('byte_format')) { $CI =& get_instance(); $CI->lang->load('number'); - - if ($num >= 1000000000000) + + if ($num >= 1000000000000) { $num = round($num / 1099511627776, $precision); $unit = $CI->lang->line('terabyte_abbr'); } - elseif ($num >= 1000000000) + elseif ($num >= 1000000000) { $num = round($num / 1073741824, $precision); $unit = $CI->lang->line('gigabyte_abbr'); } - elseif ($num >= 1000000) + elseif ($num >= 1000000) { $num = round($num / 1048576, $precision); $unit = $CI->lang->line('megabyte_abbr'); } - elseif ($num >= 1000) + elseif ($num >= 1000) { $num = round($num / 1024, $precision); $unit = $CI->lang->line('kilobyte_abbr'); @@ -68,7 +68,7 @@ if ( ! function_exists('byte_format')) } return number_format($num, $precision).' '.$unit; - } + } } diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 030b6bff1..556e8c9a2 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -34,7 +34,7 @@ * @param string * @param bool checks to see if the path exists * @return string - */ + */ if ( ! function_exists('set_realpath')) { function set_realpath($path, $check_existance = FALSE) @@ -44,16 +44,16 @@ if ( ! function_exists('set_realpath')) { show_error('The path you submitted must be a local server path, not a URL'); } - + // Resolve the path if (function_exists('realpath') AND @realpath($path) !== FALSE) { $path = realpath($path).'/'; } - + // Add a trailing slash $path = preg_replace("#([^/])/*$#", "\\1/", $path); - + // Make sure the path exists if ($check_existance == TRUE) { @@ -62,7 +62,7 @@ if ( ! function_exists('set_realpath')) show_error('Not a valid path: '.$path); } } - + return $path; } } diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 63f0e9cdb..08dd48a85 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -34,7 +34,7 @@ * @param string * @param bool whether or not the content is an image file * @return string - */ + */ if ( ! function_exists('xss_clean')) { function xss_clean($str, $is_image = FALSE) @@ -52,7 +52,7 @@ if ( ! function_exists('xss_clean')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('sanitize_filename')) { function sanitize_filename($filename) @@ -71,7 +71,7 @@ if ( ! function_exists('sanitize_filename')) * dohash() is now deprecated */ if ( ! function_exists('dohash')) -{ +{ function dohash($str, $type = 'sha1') { return do_hash($str, $type); @@ -86,9 +86,9 @@ if ( ! function_exists('dohash')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('do_hash')) -{ +{ function do_hash($str, $type = 'sha1') { if ($type == 'sha1') @@ -96,7 +96,7 @@ if ( ! function_exists('do_hash')) if ( ! function_exists('sha1')) { if ( ! function_exists('mhash')) - { + { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; return $SH->generate($str); @@ -109,7 +109,7 @@ if ( ! function_exists('do_hash')) else { return sha1($str); - } + } } else { @@ -117,7 +117,7 @@ if ( ! function_exists('do_hash')) } } } - + // ------------------------------------------------------------------------ /** @@ -126,18 +126,18 @@ if ( ! function_exists('do_hash')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('strip_image_tags')) { function strip_image_tags($str) { $str = preg_replace("##", "\\1", $str); $str = preg_replace("##", "\\1", $str); - + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -146,7 +146,7 @@ if ( ! function_exists('strip_image_tags')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('encode_php_tags')) { function encode_php_tags($str) diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index b9eb0a23e..3ebb61253 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -45,7 +45,7 @@ if ( ! function_exists('smiley_js')) static $do_setup = TRUE; $r = ''; - + if ($alias != '' && ! is_array($alias)) { $alias = array($alias => $field_id); @@ -54,9 +54,9 @@ if ( ! function_exists('smiley_js')) if ($do_setup === TRUE) { $do_setup = FALSE; - + $m = array(); - + if (is_array($alias)) { foreach($alias as $name => $id) @@ -64,22 +64,22 @@ if ( ! function_exists('smiley_js')) $m[] = '"'.$name.'" : "'.$id.'"'; } } - + $m = '{'.implode(',', $m).'}'; - + $r .= <</*'; + return ''; } else { @@ -124,8 +124,8 @@ EOF; /** * Get Clickable Smileys * - * Returns an array of image tag links that can be clicked to be inserted - * into a form field. + * 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 @@ -136,12 +136,12 @@ 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)) { if (FALSE === ($smileys = _get_smiley_array())) @@ -152,7 +152,7 @@ if ( ! function_exists('get_clickable_smileys')) // Add a trailing slash to the file path if needed $image_url = rtrim($image_url, '/').'/'; - + $used = array(); foreach ($smileys as $key => $val) { @@ -164,12 +164,12 @@ if ( ! function_exists('get_clickable_smileys')) { continue; } - - $link[] = "\"".$smileys[$key][3]."\""; - + + $link[] = "\"".$smileys[$key][3]."\""; + $used[$smileys[$key][0]] = TRUE; } - + return $link; } } diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 60f6ed171..544b3b42b 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -41,12 +41,12 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('trim_slashes')) { function trim_slashes($str) { - return trim($str, '/'); + return trim($str, '/'); } } @@ -60,13 +60,13 @@ if ( ! function_exists('trim_slashes')) * @access public * @param mixed string or array * @return mixed string or array - */ + */ if ( ! function_exists('strip_slashes')) { function strip_slashes($str) { if (is_array($str)) - { + { foreach ($str as $key => $val) { $str[$key] = strip_slashes($val); @@ -76,7 +76,7 @@ if ( ! function_exists('strip_slashes')) { $str = stripslashes($str); } - + return $str; } } @@ -91,7 +91,7 @@ if ( ! function_exists('strip_slashes')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('strip_quotes')) { function strip_quotes($str) @@ -110,11 +110,11 @@ if ( ! function_exists('strip_quotes')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('quotes_to_entities')) { function quotes_to_entities($str) - { + { return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); } } @@ -136,7 +136,7 @@ if ( ! function_exists('quotes_to_entities')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) @@ -163,7 +163,7 @@ if ( ! function_exists('reduce_double_slashes')) * @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')) { function reduce_multiples($str, $character = ',', $trim = FALSE) @@ -174,11 +174,11 @@ if ( ! function_exists('reduce_multiples')) { $str = trim($str, $character); } - + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -187,23 +187,23 @@ 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 string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 * @param integer number of characters * @return string - */ + */ if ( ! function_exists('random_string')) { function random_string($type = 'alnum', $len = 8) - { + { switch($type) { case 'basic' : return mt_rand(); - break; + break; case 'alnum' : case 'numeric' : case 'nozero' : case 'alpha' : - + switch ($type) { case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -222,20 +222,20 @@ if ( ! function_exists('random_string')) $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; - break; - case 'unique' : - case 'md5' : - + break; + case 'unique' : + case 'md5' : + return md5(uniqid(mt_rand())); - break; - case 'encrypt' : - case 'sha1' : - + break; + case 'encrypt' : + case 'sha1' : + $CI =& get_instance(); $CI->load->helper('security'); - + return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); - break; + break; } } } @@ -250,12 +250,12 @@ if ( ! function_exists('random_string')) * @access public * @param string (as many parameters as needed) * @return string - */ + */ if ( ! function_exists('alternator')) { function alternator() { - static $i; + static $i; if (func_num_args() == 0) { @@ -276,13 +276,13 @@ if ( ! function_exists('alternator')) * @param string * @param integer number of repeats * @return string - */ + */ if ( ! function_exists('repeater')) { 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 b85e2aaef..8bc1cd5e5 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -37,7 +37,7 @@ * @param integer * @param string the end character. Usually an ellipsis * @return string - */ + */ if ( ! function_exists('word_limiter')) { function word_limiter($str, $limit = 100, $end_char = '…') @@ -46,18 +46,18 @@ if ( ! function_exists('word_limiter')) { return $str; } - + preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); - + if (strlen($str) == strlen($matches[0])) { $end_char = ''; } - + return rtrim($matches[0]).$end_char; } } - + // ------------------------------------------------------------------------ /** @@ -71,7 +71,7 @@ if ( ! function_exists('word_limiter')) * @param integer * @param string the end character. Usually an ellipsis * @return string - */ + */ if ( ! function_exists('character_limiter')) { function character_limiter($str, $n = 500, $end_char = '…') @@ -80,28 +80,28 @@ if ( ! function_exists('character_limiter')) { return $str; } - + $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); if (strlen($str) <= $n) { return $str; } - + $out = ""; foreach (explode(' ', trim($str)) as $val) { $out .= $val.' '; - + if (strlen($out) >= $n) { $out = trim($out); return (strlen($out) == strlen($str)) ? $out : $out.$end_char; - } + } } } } - + // ------------------------------------------------------------------------ /** @@ -112,21 +112,21 @@ if ( ! function_exists('character_limiter')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('ascii_to_entities')) { function ascii_to_entities($str) { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { /* If the $temp array has a value but we have moved on, then it seems only fair that we output that entity and restart $temp before continuing. -Paul @@ -136,33 +136,33 @@ if ( ! function_exists('ascii_to_entities')) $out .= '&#'.array_shift($temp).';'; $count = 1; } - + $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; } } - + // ------------------------------------------------------------------------ /** @@ -174,51 +174,51 @@ if ( ! function_exists('ascii_to_entities')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('entities_to_ascii')) { function entities_to_ascii($str, $all = TRUE) { - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; - - $out = ''; - - if ($digits < 128) - { - $out .= chr($digits); - - } - elseif ($digits < 2048) - { - $out .= chr(192 + (($digits - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - else - { - $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); - $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - - $str = str_replace($matches['0'][$i], $out, $str); - } - } - - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } - - return $str; + if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) + { + for ($i = 0, $s = count($matches['0']); $i < $s; $i++) + { + $digits = $matches['1'][$i]; + + $out = ''; + + if ($digits < 128) + { + $out .= chr($digits); + + } + elseif ($digits < 2048) + { + $out .= chr(192 + (($digits - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + else + { + $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); + $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + + $str = str_replace($matches['0'][$i], $out, $str); + } + } + + if ($all) + { + $str = str_replace(array("&", "<", ">", """, "'", "-"), + array("&","<",">","\"", "'", "-"), + $str); + } + + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -233,7 +233,7 @@ if ( ! function_exists('entities_to_ascii')) * @param string the array of censoered words * @param string the optional replacement value * @return string - */ + */ if ( ! function_exists('word_censor')) { function word_censor($str, $censored, $replacement = '') @@ -242,8 +242,8 @@ if ( ! function_exists('word_censor')) { return $str; } - - $str = ' '.$str.' '; + + $str = ' '.$str.' '; // \w, \b and a few others do not match on a unicode character // set for performance reasons. As a result words like über @@ -263,10 +263,10 @@ if ( ! function_exists('word_censor')) } } - return trim($str); + return trim($str); } } - + // ------------------------------------------------------------------------ /** @@ -277,26 +277,26 @@ if ( ! function_exists('word_censor')) * @access public * @param string the text string * @return string - */ + */ 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('', '<%', '%>', '\\', ''), + + $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 @@ -307,20 +307,20 @@ if ( ! function_exists('highlight_code')) $str = str_replace(array(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } - + // Remove our artificially added PHP, and the syntax highlighting that came with it $str = preg_replace('/<\?php( | )/i', '', $str); $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); $str = preg_replace('/<\/span>/i', '', $str); - + // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - + return $str; } } - + // ------------------------------------------------------------------------ /** @@ -334,7 +334,7 @@ if ( ! function_exists('highlight_code')) * @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')) { function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') @@ -343,7 +343,7 @@ if ( ! function_exists('highlight_phrase')) { return ''; } - + if ($phrase != '') { return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); @@ -361,7 +361,7 @@ if ( ! function_exists('highlight_phrase')) * @access public * @param string the text string * @return string - */ + */ if ( ! function_exists('convert_accented_characters')) { function convert_accented_characters($match) @@ -370,16 +370,16 @@ if ( ! function_exists('convert_accented_characters')) { return $match; } - + include APPPATH.'config/foreign_chars'.EXT; - + if ( ! isset($foreign_characters)) { return $match; } - + $ord = ord($match['1']); - + if (isset($foreign_characters[$ord])) { return $foreign_characters[$ord]; @@ -390,7 +390,7 @@ if ( ! function_exists('convert_accented_characters')) } } } - + // ------------------------------------------------------------------------ /** @@ -404,7 +404,7 @@ if ( ! function_exists('convert_accented_characters')) * @param string the text string * @param integer the number of characters to wrap at * @return string - */ + */ if ( ! function_exists('word_wrap')) { function word_wrap($str, $charlim = '76') @@ -412,47 +412,47 @@ if ( ! function_exists('word_wrap')) // Se the character limit if ( ! is_numeric($charlim)) $charlim = 76; - + // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); - + // Standardize newlines if (strpos($str, "\r") !== FALSE) { - $str = str_replace(array("\r\n", "\r"), "\n", $str); + $str = str_replace(array("\r\n", "\r"), "\n", $str); } - - // If the current word is surrounded by {unwrap} tags we'll + + // 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)) { for ($i = 0; $i < count($matches['0']); $i++) { - $unwrap[] = $matches['1'][$i]; + $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 + + // 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. $str = wordwrap($str, $charlim, "\n", FALSE); - + // Split the string into individual lines of text and cycle through them $output = ""; - foreach (explode("\n", $str) as $line) + foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { - $output .= $line."\n"; + $output .= $line."\n"; continue; } - + $temp = ''; - while((strlen($line)) > $charlim) + while((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) @@ -464,12 +464,12 @@ if ( ! function_exists('word_wrap')) $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 + + // If $temp contains data it means we had to split up an over-length // word into smaller chunks so we'll add it back to our current line if ($temp != '') { - $output .= $temp."\n".$line; + $output .= $temp."\n".$line; } else { @@ -481,7 +481,7 @@ if ( ! function_exists('word_wrap')) // Put our markers back if (count($unwrap) > 0) - { + { foreach ($unwrap as $key => $val) { $output = str_replace("{{unwrapped".$key."}}", $val, $output); @@ -491,10 +491,10 @@ if ( ! function_exists('word_wrap')) // Remove the unwrap tags $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - return $output; + return $output; } } - + // ------------------------------------------------------------------------ /** @@ -502,10 +502,10 @@ 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 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 '...' + * @param string ellipsis ; Default '...' * @return string ellipsized string */ if ( ! function_exists('ellipsize')) @@ -534,7 +534,7 @@ if ( ! function_exists('ellipsize')) $end = substr($str, -($max_length - strlen($beg))); } - return $beg.$ellipsis.$end; + return $beg.$ellipsis.$end; } } diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index e45480e1a..1a71d1857 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -33,19 +33,19 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('nl2br_except_pre')) { function nl2br_except_pre($str) { $CI =& get_instance(); - + $CI->load->library('typography'); - + return $CI->typography->nl2br_except_pre($str); } } - + // ------------------------------------------------------------------------ /** @@ -62,7 +62,7 @@ if ( ! function_exists('auto_typography')) { function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) { - $CI =& get_instance(); + $CI =& get_instance(); $CI->load->library('typography'); return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); } @@ -84,7 +84,7 @@ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { - $CI =& get_instance(); + $CI =& get_instance(); $CI->load->library('security'); return $CI->security->entity_decode($str, $charset); } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index dad761145..e59efffec 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -70,7 +70,7 @@ if ( ! function_exists('base_url')) /** * Current URL * - * Returns the full URL (including segments) of the page where this + * Returns the full URL (including segments) of the page where this * function is placed * * @access public @@ -224,7 +224,7 @@ if ( ! function_exists('anchor_popup')) * @access public * @param string the email address * @param string the link title - * @param mixed any attributes + * @param mixed any attributes * @return string */ if ( ! function_exists('mailto')) @@ -254,7 +254,7 @@ if ( ! function_exists('mailto')) * @access public * @param string the email address * @param string the link title - * @param mixed any attributes + * @param mixed any attributes * @return string */ if ( ! function_exists('safe_mailto')) @@ -320,7 +320,7 @@ if ( ! function_exists('safe_mailto')) { $count = ($ordinal < 224) ? 2 : 3; } - + $temp[] = $ordinal; if (count($temp) == $count) { @@ -369,7 +369,7 @@ if ( ! function_exists('safe_mailto')) * @access public * @param string the string * @param string the type: email, url, or both - * @param bool whether to create pop-up links + * @param bool whether to create pop-up links * @return string */ if ( ! function_exists('auto_link')) @@ -381,7 +381,7 @@ if ( ! function_exists('auto_link')) if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)) { $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; - + for ($i = 0; $i < count($matches['0']); $i++) { $period = ''; @@ -390,7 +390,7 @@ if ( ! function_exists('auto_link')) $period = '.'; $matches['6'][$i] = substr($matches['6'][$i], 0, -1); } - + $str = str_replace($matches['0'][$i], $matches['1'][$i].'","\"", "'", "-"), array("&", "<", ">", """, "'", "-"), $str); - // Decode the temp markers back to entities + // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - + if ($protect_all === TRUE) { $str = preg_replace("/$temp(\w+);/","&\\1;", $str); } - + return $str; - } + } } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 3a082fd3d6cb2e72612d51b9d8e54e93effb93eb Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 7 Oct 2010 09:38:55 -0500 Subject: added elements() to the Array Helper to return elements from an array with specified keys only. Differs from array_intersect_assoc() in that a default value can be provided for keys that do not exist in the supplied array --- system/helpers/array_helper.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index bd30b7c16..447ee1aa4 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,6 +73,46 @@ if ( ! function_exists('random_element')) } } +// -------------------------------------------------------------------- + +/** + * Elements + * + * Returns only the array items specified. Will return a default value if + * it is not set. + * + * @access public + * @param array + * @param array + * @param mixed + * @return mixed depends on what the array contains + */ +if ( ! function_exists('elements')) +{ + function elements($items, $array, $default = FALSE) + { + $return = array(); + + if ( ! is_array($items)) + { + $items = array($items); + } + + foreach ($items as $item) + { + if (isset($array[$item])) + { + $return[$item] = $array[$item]; + } + else + { + $return[$item] = $default; + } + } + + return $return; + } +} /* End of file array_helper.php */ /* Location: ./system/helpers/array_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b