diff options
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/array_helper.php | 48 | ||||
-rw-r--r-- | system/helpers/captcha_helper.php | 74 | ||||
-rw-r--r-- | system/helpers/compatibility_helper.php | 96 | ||||
-rw-r--r-- | system/helpers/cookie_helper.php | 8 | ||||
-rw-r--r-- | system/helpers/date_helper.php | 170 | ||||
-rw-r--r-- | system/helpers/directory_helper.php | 8 | ||||
-rw-r--r-- | system/helpers/download_helper.php | 10 | ||||
-rw-r--r-- | system/helpers/email_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/file_helper.php | 70 | ||||
-rw-r--r-- | system/helpers/form_helper.php | 36 | ||||
-rw-r--r-- | system/helpers/html_helper.php | 6 | ||||
-rw-r--r-- | system/helpers/inflector_helper.php | 44 | ||||
-rw-r--r-- | system/helpers/language_helper.php | 2 | ||||
-rw-r--r-- | system/helpers/number_helper.php | 12 | ||||
-rw-r--r-- | system/helpers/path_helper.php | 10 | ||||
-rw-r--r-- | system/helpers/security_helper.php | 24 | ||||
-rw-r--r-- | system/helpers/smiley_helper.php | 36 | ||||
-rw-r--r-- | system/helpers/string_helper.php | 62 | ||||
-rw-r--r-- | system/helpers/text_helper.php | 264 | ||||
-rw-r--r-- | system/helpers/typography_helper.php | 12 | ||||
-rw-r--r-- | system/helpers/url_helper.php | 24 | ||||
-rw-r--r-- | system/helpers/xml_helper.php | 18 |
22 files changed, 539 insertions, 499 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index b7289900f..447ee1aa4 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,9 +70,49 @@ if ( ! function_exists('random_element')) return $array; } return $array[array_rand($array)]; - } + } } +// -------------------------------------------------------------------- + +/** + * 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 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 = "<img src=\"$img_url$img_name\" width=\"$img_width\" height=\"$img_height\" style=\"border:0;\" alt=\" \" />"; - + 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 = '<select name="'.$name.'"'; - + if ($class != '') { $menu .= ' class="'.$class.'"'; } - + $menu .= ">\n"; - + foreach (timezones() as $key => $val) { $selected = ($default == $key) ? " selected='selected'" : ''; @@ -531,7 +531,7 @@ if ( ! function_exists('timezone_menu')) return $menu; } } - + // ------------------------------------------------------------------------ /** @@ -543,15 +543,15 @@ if ( ! function_exists('timezone_menu')) * @access public * @param string timezone * @return string - */ + */ if ( ! function_exists('timezones')) { function timezones($tz = '') { // Note: Don't change the order of these even though // some items appear to be in the wrong order - - $zones = array( + + $zones = array( 'UM12' => -12, 'UM11' => -11, 'UM10' => -10, @@ -593,15 +593,15 @@ if ( ! function_exists('timezones')) 'UP13' => +13, 'UP14' => +14 ); - + if ($tz == '') { return $zones; } - + if ($tz == 'GMT') $tz = 'UTC'; - + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; } } diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 7de6a3c51..574a5d8b0 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -38,7 +38,7 @@ * @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')) { function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) @@ -47,8 +47,8 @@ if ( ! function_exists('directory_map')) { $filedata = array(); $new_depth = $directory_depth - 1; - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] @@ -66,7 +66,7 @@ if ( ! function_exists('directory_map')) $filedata[] = $file; } } - + closedir($fp); return $filedata; } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index eac024fcb..4a17e519e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -36,7 +36,7 @@ * @param string filename * @param mixed the data to be downloaded * @return void - */ + */ if ( ! function_exists('force_download')) { function force_download($filename = '', $data = '') @@ -52,14 +52,14 @@ if ( ! function_exists('force_download')) { return FALSE; } - + // Grab the file extension $x = explode('.', $filename); $extension = end($x); // Load the mime types @include(APPPATH.'config/mimes'.EXT); - + // Set a default mime if we can't find it if ( ! isset($mimes[$extension])) { @@ -69,7 +69,7 @@ if ( ! function_exists('force_download')) { $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } - + // Generate the server headers if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { @@ -90,7 +90,7 @@ if ( ! function_exists('force_download')) header('Pragma: no-cache'); header("Content-Length: ".strlen($data)); } - + exit($data); } } diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 046562a91..7c8a610de 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -32,7 +32,7 @@ * * @access public * @return bool - */ + */ if ( ! function_exists('valid_email')) { function valid_email($address) @@ -48,7 +48,7 @@ if ( ! function_exists('valid_email')) * * @access public * @return bool - */ + */ if ( ! function_exists('send_email')) { function send_email($recipient, $subject = 'Test email', $message = 'Hello World') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 448bf275f..c1ac167a0 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -35,7 +35,7 @@ * @access public * @param string path to file * @return string - */ + */ if ( ! function_exists('read_file')) { function read_file($file) @@ -44,19 +44,19 @@ if ( ! function_exists('read_file')) { return FALSE; } - + if (function_exists('file_get_contents')) { - return file_get_contents($file); + return file_get_contents($file); } if ( ! $fp = @fopen($file, FOPEN_READ)) { return FALSE; } - + flock($fp, LOCK_SH); - + $data = ''; if (filesize($file) > 0) { @@ -69,7 +69,7 @@ if ( ! function_exists('read_file')) return $data; } } - + // ------------------------------------------------------------------------ /** @@ -82,7 +82,7 @@ if ( ! function_exists('read_file')) * @param string path to file * @param string file data * @return bool - */ + */ if ( ! function_exists('write_file')) { function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) @@ -91,16 +91,16 @@ if ( ! function_exists('write_file')) { return FALSE; } - + flock($fp, LOCK_EX); fwrite($fp, $data); flock($fp, LOCK_UN); - fclose($fp); + fclose($fp); return TRUE; } } - + // ------------------------------------------------------------------------ /** @@ -115,19 +115,19 @@ if ( ! function_exists('write_file')) * @param string path to file * @param bool whether to delete any directories found in the path * @return bool - */ + */ if ( ! function_exists('delete_files')) { function delete_files($path, $del_dir = FALSE, $level = 0) - { + { // Trim the trailing slash $path = rtrim($path, DIRECTORY_SEPARATOR); - + if ( ! $current_dir = @opendir($path)) { - return FALSE; + return FALSE; } - + while(FALSE !== ($filename = @readdir($current_dir))) { if ($filename != "." and $filename != "..") @@ -138,7 +138,7 @@ if ( ! function_exists('delete_files')) if (substr($filename, 0, 1) != '.') { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1); - } + } } else { @@ -147,12 +147,12 @@ if ( ! function_exists('delete_files')) } } @closedir($current_dir); - + if ($del_dir == TRUE AND $level > 0) { return @rmdir($path); } - + return TRUE; } } @@ -162,7 +162,7 @@ if ( ! function_exists('delete_files')) /** * Get Filenames * - * Reads the specified directory and builds an array containing the filenames. + * Reads the specified directory and builds an array containing the filenames. * Any sub-folders contained within the specified path are read as well. * * @access public @@ -170,13 +170,13 @@ if ( ! function_exists('delete_files')) * @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')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); - + if ($fp = @opendir($source_dir)) { // reset the array and make sure $source_dir has a trailing slash on the initial call @@ -185,12 +185,12 @@ if ( ! function_exists('get_filenames')) $_filedata = array(); $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } - + while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) { - get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); + get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } elseif (strncmp($file, '.', 1) !== 0) { @@ -211,7 +211,7 @@ if ( ! function_exists('get_filenames')) /** * Get Directory File Information * - * Reads the specified directory and builds an array containing the filenames, + * 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. @@ -221,7 +221,7 @@ if ( ! function_exists('get_filenames')) * @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')) { function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) @@ -243,10 +243,10 @@ if ( ! function_exists('get_dir_file_info')) { if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) { - get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) - { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); + } + elseif (strncmp($file, '.', 1) !== 0) + { $_filedata[$file] = get_file_info($source_dir.$file); $_filedata[$file]['relative_path'] = $relative_path; } @@ -332,7 +332,7 @@ if ( ! function_exists('get_file_info')) /** * Get Mime by Extension * - * Translates a file extension into a mime type based on config/mimes.php. + * 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 @@ -341,7 +341,7 @@ if ( ! function_exists('get_file_info')) * @access public * @param string path to file * @return mixed - */ + */ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) @@ -388,11 +388,11 @@ if ( ! function_exists('get_mime_by_extension')) * @access public * @param int * @return string - */ + */ if ( ! function_exists('symbolic_permissions')) { function symbolic_permissions($perms) - { + { if (($perms & 0xC000) == 0xC000) { $symbolic = 's'; // Socket @@ -441,7 +441,7 @@ if ( ! function_exists('symbolic_permissions')) $symbolic .= (($perms & 0x0002) ? 'w' : '-'); $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); - return $symbolic; + return $symbolic; } } @@ -456,7 +456,7 @@ if ( ! function_exists('symbolic_permissions')) * @access public * @param int * @return string - */ + */ if ( ! function_exists('octal_permissions')) { function octal_permissions($perms) diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 42355df42..e722a0758 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -37,7 +37,7 @@ * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string - */ + */ if ( ! function_exists('form_open')) { function form_open($action = '', $attributes = '', $hidden = array()) @@ -52,9 +52,9 @@ if ( ! function_exists('form_open')) $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; $form = '<form action="'.$action.'"'; - + $form .= _attributes_to_string($attributes, TRUE); - + $form .= '>'; // CSRF @@ -143,7 +143,7 @@ if ( ! function_exists('form_hidden')) { foreach ($value as $k => $v) { - $k = (is_int($k)) ? '' : $k; + $k = (is_int($k)) ? '' : $k; form_hidden($name.'['.$k.']', $v, TRUE); } } @@ -250,10 +250,10 @@ if ( ! function_exists('form_textarea')) } else { - $val = $data['value']; + $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - + $name = (is_array($data)) ? $data['name'] : $data; return "<textarea "._parse_form_attributes($data, $defaults).$extra.">".form_prep($val, $name)."</textarea>"; } @@ -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 .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$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("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str); $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\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 .= <<<EOF var smiley_map = {$m}; function insert_smiley(smiley, field_id) { var el = document.getElementById(field_id), newStart; - + if ( ! el && smiley_map[field_id]) { el = document.getElementById(smiley_map[field_id]); - + if ( ! el) return false; } - + el.focus(); smiley = " " + smiley; @@ -110,7 +110,7 @@ EOF; if ($inline) { - return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'; + return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>'; } 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[] = "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('".$key."', '".$alias."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>"; - + + $link[] = "<a href=\"javascript:void(0);\" onclick=\"insert_smiley('".$key."', '".$alias."')\"><img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" /></a>"; + $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('<?', '?>', '<%', '%>', '\\', '</script>'), + + $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), 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 = '<?php '.$str.' ?>'; // <? - // All the magic happens here, baby! + // All the magic happens here, baby! $str = highlight_string($str, TRUE); // Prior to PHP 5, the highligh function used icky <font> tags @@ -307,20 +307,20 @@ if ( ! function_exists('highlight_code')) $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $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('/<span style="color: #([A-Z0-9]+)"><\?php( | )/i', '<span style="color: #$1">', $str); $str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str); $str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/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 = '<strong>', $tag_close = '</strong>') @@ -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].'<a href="http'. $matches['4'][$i].'://'. @@ -416,7 +416,7 @@ if ( ! function_exists('auto_link')) $period = '.'; $matches['3'][$i] = substr($matches['3'][$i], 0, -1); } - + $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str); } } @@ -447,7 +447,7 @@ if ( ! function_exists('prep_url')) } $url = parse_url($str); - + if ( ! $url OR ! isset($url['scheme'])) { $str = 'http://'.$str; @@ -495,7 +495,7 @@ if ( ! function_exists('url_title')) $replace.'$' => $replace, '^'.$replace => $replace, '\.+$' => '' - ); + ); $str = strip_tags($str); @@ -508,7 +508,7 @@ if ( ! function_exists('url_title')) { $str = strtolower($str); } - + return trim(stripslashes($str)); } } @@ -535,7 +535,7 @@ if ( ! function_exists('redirect')) { $uri = site_url($uri); } - + switch($method) { case 'refresh' : header("Refresh:0;url=".$uri); diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 56f5e0112..dcfbbdf74 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -33,36 +33,36 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('xml_convert')) { function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; - // Replace entities to temporary markers so that - // ampersands won't get messed up + // Replace entities to temporary markers so that + // ampersands won't get messed up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - + if ($protect_all === TRUE) { $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); } - + $str = str_replace(array("&","<",">","\"", "'", "-"), 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; - } + } } // ------------------------------------------------------------------------ |