summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:51:06 +0100
committerFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:58:52 +0100
commitce2b69675075444c9e40b72bcdd42ab7edbbe633 (patch)
tree2932f13b0db14fe53dc0622d888318db638a017f /system/helpers
parentb6b8a6587c399bfd89e13e92ce04ee8486688e6e (diff)
update to CI 2.0
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
Diffstat (limited to 'system/helpers')
-rwxr-xr-x[-rw-r--r--]system/helpers/array_helper.php52
-rwxr-xr-xsystem/helpers/captcha_helper.php246
-rw-r--r--system/helpers/compatibility_helper.php498
-rwxr-xr-x[-rw-r--r--]system/helpers/cookie_helper.php55
-rwxr-xr-x[-rw-r--r--]system/helpers/date_helper.php180
-rwxr-xr-x[-rw-r--r--]system/helpers/directory_helper.php40
-rwxr-xr-x[-rw-r--r--]system/helpers/download_helper.php16
-rwxr-xr-x[-rw-r--r--]system/helpers/email_helper.php8
-rwxr-xr-x[-rw-r--r--]system/helpers/file_helper.php84
-rwxr-xr-x[-rw-r--r--]system/helpers/form_helper.php94
-rwxr-xr-x[-rw-r--r--]system/helpers/html_helper.php34
-rwxr-xr-x[-rw-r--r--]system/helpers/index.html0
-rwxr-xr-x[-rw-r--r--]system/helpers/inflector_helper.php43
-rwxr-xr-x[-rw-r--r--]system/helpers/language_helper.php6
-rwxr-xr-x[-rw-r--r--]system/helpers/number_helper.php29
-rwxr-xr-x[-rw-r--r--]system/helpers/path_helper.php14
-rwxr-xr-x[-rw-r--r--]system/helpers/security_helper.php64
-rwxr-xr-x[-rw-r--r--]system/helpers/smiley_helper.php52
-rwxr-xr-x[-rw-r--r--]system/helpers/string_helper.php73
-rwxr-xr-x[-rw-r--r--]system/helpers/text_helper.php319
-rwxr-xr-x[-rw-r--r--]system/helpers/typography_helper.php41
-rwxr-xr-x[-rw-r--r--]system/helpers/url_helper.php32
-rwxr-xr-x[-rw-r--r--]system/helpers/xml_helper.php33
23 files changed, 983 insertions, 1030 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index b7289900f..6b2415df2 100644..100755
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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
new file mode 100755
index 000000000..c0e3798f4
--- /dev/null
+++ b/system/helpers/captcha_helper.php
@@ -0,0 +1,246 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.1.6 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter CAPTCHA Helper
+ *
+ * @package CodeIgniter
+ * @subpackage Helpers
+ * @category Helpers
+ * @author ExpressionEngine Dev Team
+ * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Create CAPTCHA
+ *
+ * @access public
+ * @param array array of data for the CAPTCHA
+ * @param string path to create the image in
+ * @param string URL to the CAPTCHA image folder
+ * @param string server path to font
+ * @return string
+ */
+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);
+
+ foreach ($defaults as $key => $val)
+ {
+ if ( ! is_array($data))
+ {
+ if ( ! isset($$key) OR $$key == '')
+ {
+ $$key = $val;
+ }
+ }
+ else
+ {
+ $$key = ( ! isset($data[$key])) ? $val : $data[$key];
+ }
+ }
+
+ if ($img_path == '' OR $img_url == '')
+ {
+ return FALSE;
+ }
+
+ if ( ! @is_dir($img_path))
+ {
+ return FALSE;
+ }
+
+ if ( ! is_writable($img_path))
+ {
+ return FALSE;
+ }
+
+ if ( ! extension_loaded('gd'))
+ {
+ return FALSE;
+ }
+
+ // -----------------------------------
+ // 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';
+
+ $str = '';
+ for ($i = 0; $i < 8; $i++)
+ {
+ $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
+ }
+
+ $word = $str;
+ }
+
+ // -----------------------------------
+ // Determine angle and position
+ // -----------------------------------
+
+ $length = strlen($word);
+ $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0;
+ $x_axis = rand(6, (360/$length)-16);
+ $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height);
+
+ // -----------------------------------
+ // Create image
+ // -----------------------------------
+
+ // PHP.net recommends imagecreatetruecolor(), but it isn't always available
+ if (function_exists('imagecreatetruecolor'))
+ {
+ $im = imagecreatetruecolor($img_width, $img_height);
+ }
+ else
+ {
+ $im = imagecreate($img_width, $img_height);
+ }
+
+ // -----------------------------------
+ // Assign colors
+ // -----------------------------------
+
+ $bg_color = imagecolorallocate ($im, 255, 255, 255);
+ $border_color = imagecolorallocate ($im, 153, 102, 102);
+ $text_color = imagecolorallocate ($im, 204, 153, 153);
+ $grid_color = imagecolorallocate($im, 255, 182, 182);
+ $shadow_color = imagecolorallocate($im, 255, 240, 240);
+
+ // -----------------------------------
+ // Create the rectangle
+ // -----------------------------------
+
+ ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
+
+ // -----------------------------------
+ // Create the spiral pattern
+ // -----------------------------------
+
+ $theta = 1;
+ $thetac = 7;
+ $radius = 16;
+ $circles = 20;
+ $points = 32;
+
+ for ($i = 0; $i < ($circles * $points) - 1; $i++)
+ {
+ $theta = $theta + $thetac;
+ $rad = $radius * ($i / $points );
+ $x = ($rad * cos($theta)) + $x_axis;
+ $y = ($rad * sin($theta)) + $y_axis;
+ $theta = $theta + $thetac;
+ $rad1 = $radius * (($i + 1) / $points);
+ $x1 = ($rad1 * cos($theta)) + $x_axis;
+ $y1 = ($rad1 * sin($theta )) + $y_axis;
+ imageline($im, $x, $y, $x1, $y1, $grid_color);
+ $theta = $theta - $thetac;
+ }
+
+ // -----------------------------------
+ // 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;
+ $x = rand(0, $img_width/($length/3));
+ $y = 0;
+ }
+ else
+ {
+ $font_size = 16;
+ $x = rand(0, $img_width/($length/1.5));
+ $y = $font_size+2;
+ }
+
+ for ($i = 0; $i < strlen($word); $i++)
+ {
+ if ($use_font == FALSE)
+ {
+ $y = rand(0 , $img_height/2);
+ imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color);
+ $x += ($font_size*2);
+ }
+ else
+ {
+ $y = rand($img_height/2, $img_height-3);
+ imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1));
+ $x += $font_size;
+ }
+ }
+
+
+ // -----------------------------------
+ // Create the border
+ // -----------------------------------
+
+ imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);
+
+ // -----------------------------------
+ // Generate the image
+ // -----------------------------------
+
+ $img_name = $now.'.jpg';
+
+ ImageJPEG($im, $img_path.$img_name);
+
+ $img = "<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);
+ }
+}
+
+// ------------------------------------------------------------------------
+
+/* End of file captcha_helper.php */
+/* Location: ./system/heleprs/captcha_helper.php */ \ No newline at end of file
diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php
deleted file mode 100644
index e7b21c660..000000000
--- a/system/helpers/compatibility_helper.php
+++ /dev/null
@@ -1,498 +0,0 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
-/**
- * CodeIgniter
- *
- * An open source application development framework for PHP 4.3.2 or newer
- *
- * @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
- * @filesource
- */
-
-// ------------------------------------------------------------------------
-
-/**
- * CodeIgniter Compatibility Helpers
- *
- * 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
- *
- * @package CodeIgniter
- * @subpackage Helpers
- * @category Helpers
- * @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/helpers/compatibility_helper.html
- */
-
-// ------------------------------------------------------------------------
-
-if ( ! defined('PHP_EOL'))
-{
- define('PHP_EOL', (DIRECTORY_SEPARATOR == '/') ? "\n" : "\r\n");
-}
-
-// ------------------------------------------------------------------------
-
-/**
- * file_put_contents()
- *
- * Writes a string to a file
- * http://us.php.net/manual/en/function.file_put_contents.php
- * argument 4, $context, not supported
- *
- * @access public
- * @param string file name
- * @param mixed data to be written
- * @param int flags
- * @return int length of written string
- */
-if ( ! function_exists('file_put_contents'))
-{
- function file_put_contents($filename, $data, $flags = NULL)
- {
- if (is_scalar($data))
- {
- settype($data, 'STRING');
- }
-
- if ( ! is_string($data) && ! is_array($data) && ! is_resource($data))
- {
- $backtrace = debug_backtrace();
- _exception_handler(E_USER_WARNING, 'file_put_contents(): the 2nd parameter should be either a string or an array', $backtrace[0]['file'], $backtrace[0]['line']);
- return FALSE;
- }
-
- // read stream if given a stream resource
- if (is_resource($data))
- {
- if (get_resource_type($data) !== 'stream')
- {
- $backtrace = debug_backtrace();
- _exception_handler(E_USER_WARNING, 'file_put_contents(): supplied resource is not a valid stream resource', $backtrace[0]['file'], $backtrace[0]['line']);
- return FALSE;
- }
-
- $text = '';
-
- while ( ! feof($data))
- {
- $text .= fread($data, 4096);
- }
-
- $data = $text;
- unset($text);
- }
-
- // strings only please!
- if (is_array($data))
- {
- $data = implode('', $data);
- }
-
- // Set the appropriate mode
- if (($flags & 8) > 0) // 8 = FILE_APPEND flag
- {
- $mode = FOPEN_WRITE_CREATE;
- }
- else
- {
- $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE;
- }
-
- // Check if we're using the include path
- if (($flags & 1) > 0) // 1 = FILE_USE_INCLUDE_PATH flag
- {
- $use_include_path = TRUE;
- }
- else
- {
- $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))
- {
- $backtrace = debug_backtrace();
- _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']);
- 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;
- }
-}
-
-// ------------------------------------------------------------------------
-
-/**
- * fputcsv()
- *
- * Format line as CSV and write to file pointer
- * http://us.php.net/manual/en/function.fputcsv.php
- *
- * @access public
- * @param resource file pointer
- * @param array data to be written
- * @param string delimiter
- * @param string enclosure
- * @return int length of written string
- */
-if ( ! function_exists('fputcsv'))
-{
- function fputcsv($handle, $fields, $delimiter = ',', $enclosure = '"')
- {
- // Checking for a handle resource
- if ( ! is_resource($handle))
- {
- $backtrace = debug_backtrace();
- _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')
- {
- $backtrace = debug_backtrace();
- _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))
- {
- $backtrace = debug_backtrace();
- _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)
- {
- $delimiter = substr($delimiter, 0, 1);
- $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)
- {
- $enclosure = substr($enclosure, 0, 1);
- $backtrace = debug_backtrace();
- _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);
-
- if (strpos($cell, $delimiter) !== FALSE OR strpos($cell, $enclosure) !== FALSE OR strpos($cell, "\n") !== FALSE)
- {
- $out .= $enclosure.$cell.$enclosure.$delimiter;
- }
- else
- {
- $out .= $cell.$delimiter;
- }
- }
-
- $length = @fwrite($handle, substr($out, 0, -1)."\n");
-
- return $length;
- }
-}
-
-// ------------------------------------------------------------------------
-
-/**
- * stripos()
- *
- * Find position of first occurrence of a case-insensitive string
- * http://us.php.net/manual/en/function.stripos.php
- *
- * @access public
- * @param string haystack
- * @param string needle
- * @param int offset
- * @return int numeric position of the first occurrence of needle in the haystack
- */
-if ( ! function_exists('stripos'))
-{
- function stripos($haystack, $needle, $offset = NULL)
- {
- // Cast non string scalar values
- if (is_scalar($haystack))
- {
- 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);
- }
-}
-
-// ------------------------------------------------------------------------
-
-/**
- * str_ireplace()
- *
- * Find position of first occurrence of a case-insensitive string
- * http://us.php.net/manual/en/function.str-ireplace.php
- * (parameter 4, $count, is not supported as to do so in PHP 4 would make
- * it a required parameter)
- *
- * @access public
- * @param mixed search
- * @param mixed replace
- * @param mixed subject
- * @return int numeric position of the first occurrence of needle in the haystack
- */
-if ( ! function_exists('str_ireplace'))
-{
- function str_ireplace($search, $replace, $subject)
- {
- // Nothing to do here
- if ($search === NULL OR $subject === NULL)
- {
- return $subject;
- }
-
- // Crazy arguments
- if (is_scalar($search) && is_array($replace))
- {
- $backtrace = debug_backtrace();
-
- if (is_object($replace))
- {
- show_error('Object of class '.get_class($replace).' could not be converted to string in '.$backtrace[0]['file'].' on line '.$backtrace[0]['line']);
- }
- else
- {
- _exception_handler(E_USER_NOTICE, 'Array to string conversion in '.$backtrace[0]['file'], $backtrace[0]['line']);
- }
- }
-
- // Searching for an array
- if (is_array($search))
- {
- // Replacing with an array
- if (is_array($replace))
- {
- $search = array_values($search);
- $replace = array_values($replace);
-
- if (count($search) >= count($replace))
- {
- $replace = array_pad($replace, count($search), '');
- }
- else
- {
- $replace = array_slice($replace, 0, count($search));
- }
- }
- else
- {
- // Replacing with a string all positions
- $replace = array_fill(0, count($search), $replace);
- }
- }
- else
- {
- //Searching for a string and replacing with a string.
- $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;
- }
-}
-
-// ------------------------------------------------------------------------
-
-/**
- * http_build_query()
- *
- * Generate URL-encoded query string
- * http://us.php.net/manual/en/function.http-build-query.php
- *
- * @access public
- * @param array form data
- * @param string numeric prefix
- * @param string argument separator
- * @return string URL-encoded string
- */
-if ( ! function_exists('http_build_query'))
-{
- function http_build_query($formdata, $numeric_prefix = NULL, $separator = NULL)
- {
- // Check the data
- if ( ! is_array($formdata) && ! is_object($formdata))
- {
- $backtrace = debug_backtrace();
- _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)
- {
- $separator = ini_get('arg_separator.output');
-
- if (strlen($separator) == 0)
- {
- $separator = '&';
- }
- }
-
- // Start building the query
- $tmp = array();
-
- foreach ($formdata as $key => $val)
- {
- if ($val === NULL)
- {
- 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);
- }
- else
- {
- // arrays please
- if (is_object($val))
- {
- $val = get_object_vars($val);
- }
-
- foreach ($val as $k => $v)
- {
- $tmp[] = _http_build_query_helper($key.'['.$k.']', $v, $separator);
- }
- }
-
- return implode($separator, $tmp);
- }
-}
-
-
-/* End of file compatibility_helper.php */
-/* Location: ./system/helpers/compatibility_helper.php */ \ No newline at end of file
diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php
index 40afadb57..7701d503f 100644..100755
--- a/system/helpers/cookie_helper.php
+++ b/system/helpers/cookie_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -46,53 +46,12 @@ if ( ! function_exists('set_cookie'))
{
function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '')
{
- if (is_array($name))
- {
- foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
- {
- if (isset($name[$item]))
- {
- $$item = $name[$item];
- }
- }
- }
-
// Set the config file options
$CI =& get_instance();
-
- if ($prefix == '' AND $CI->config->item('cookie_prefix') != '')
- {
- $prefix = $CI->config->item('cookie_prefix');
- }
- if ($domain == '' AND $CI->config->item('cookie_domain') != '')
- {
- $domain = $CI->config->item('cookie_domain');
- }
- if ($path == '/' AND $CI->config->item('cookie_path') != '/')
- {
- $path = $CI->config->item('cookie_path');
- }
-
- if ( ! is_numeric($expire))
- {
- $expire = time() - 86500;
- }
- else
- {
- if ($expire > 0)
- {
- $expire = time() + $expire;
- }
- else
- {
- $expire = 0;
- }
- }
-
- setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
+ $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix);
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -108,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 0e9781666..553e8d7ee 100644..100755
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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 = '')
@@ -114,7 +114,7 @@ if ( ! function_exists('standard_date'))
$formats = array(
'DATE_ATOM' => '%Y-%m-%dT%H:%i:%s%Q',
'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC',
- 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%O',
+ 'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q',
'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O',
'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC',
'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O',
@@ -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))
@@ -288,7 +288,7 @@ if ( ! function_exists('days_in_month'))
return $days_in_month[$month - 1];
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -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,27 +323,27 @@ 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+/", "\040", $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 = preg_split("/\040/", $datestr);
+ $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 791cf0d10..38347fa62 100644..100755
--- a/system/helpers/directory_helper.php
+++ b/system/helpers/directory_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -36,46 +36,42 @@
*
* @access public
* @param string path to source
- * @param bool whether to limit the result to the top level only
+ * @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, $top_level_only = FALSE, $hidden = FALSE)
- {
+ function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE)
+ {
if ($fp = @opendir($source_dir))
{
- $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
- $filedata = array();
-
+ $filedata = array();
+ $new_depth = $directory_depth - 1;
+ $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
+
while (FALSE !== ($file = readdir($fp)))
{
- if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..'))
+ // Remove '.', '..', and hidden files [optional]
+ if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.'))
{
continue;
}
-
- if ($top_level_only == FALSE && @is_dir($source_dir.$file))
+
+ if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file))
{
- $temp_array = array();
-
- $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden);
-
- $filedata[$file] = $temp_array;
+ $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden);
}
else
{
$filedata[] = $file;
}
}
-
+
closedir($fp);
return $filedata;
}
- else
- {
- return FALSE;
- }
+
+ return FALSE;
}
}
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 638ebaa88..6cecd0d11 100644..100755
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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,9 +69,9 @@ if ( ! function_exists('force_download'))
{
$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
}
-
+
// Generate the server headers
- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
+ if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE)
{
header('Content-Type: "'.$mime.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');
@@ -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..651aef439 100644..100755
--- a/system/helpers/email_helper.php
+++ b/system/helpers/email_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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 fea54a1f6..334eef87c 100644..100755
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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,17 +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;
-
+ {
+ return FALSE;
+ }
+
while(FALSE !== ($filename = @readdir($current_dir)))
{
if ($filename != "." and $filename != "..")
@@ -136,7 +138,7 @@ if ( ! function_exists('delete_files'))
if (substr($filename, 0, 1) != '.')
{
delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1);
- }
+ }
}
else
{
@@ -145,11 +147,13 @@ if ( ! function_exists('delete_files'))
}
}
@closedir($current_dir);
-
+
if ($del_dir == TRUE AND $level > 0)
{
- @rmdir($path);
+ return @rmdir($path);
}
+
+ return TRUE;
}
}
@@ -158,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
@@ -166,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
@@ -181,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)
{
@@ -207,20 +211,20 @@ 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.
*
* @access public
* @param string path to source
- * @param bool whether to include the path as part of the filename
+ * @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, $include_path = FALSE, $_recursion = FALSE)
+ function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE)
{
static $_filedata = array();
$relative_path = $source_dir;
@@ -234,11 +238,12 @@ if ( ! function_exists('get_dir_file_info'))
$source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
}
+ // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast
while (FALSE !== ($file = readdir($fp)))
{
- if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
+ 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, $include_path, TRUE);
+ get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
}
elseif (strncmp($file, '.', 1) !== 0)
{
@@ -246,6 +251,7 @@ if ( ! function_exists('get_dir_file_info'))
$_filedata[$file]['relative_path'] = $relative_path;
}
}
+
return $_filedata;
}
else
@@ -299,7 +305,7 @@ if ( ! function_exists('get_file_info'))
$fileinfo['size'] = filesize($file);
break;
case 'date':
- $fileinfo['date'] = filectime($file);
+ $fileinfo['date'] = filemtime($file);
break;
case 'readable':
$fileinfo['readable'] = is_readable($file);
@@ -326,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
@@ -335,12 +341,12 @@ 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)
{
- $extension = substr(strrchr($file, '.'), 1);
+ $extension = strtolower(substr(strrchr($file, '.'), 1));
global $mimes;
@@ -382,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
@@ -435,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;
}
}
@@ -450,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 31b36efd0..758056b50 100644..100755
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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,14 +52,20 @@ 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
+ if ($CI->config->item('csrf_protection') === TRUE)
+ {
+ $hidden[$CI->security->csrf_token_name] = $CI->security->csrf_hash;
+ }
+
if (is_array($hidden) AND count($hidden) > 0)
{
- $form .= form_hidden($hidden);
+ $form .= sprintf("\n<div class=\"hidden\">%s</div>", form_hidden($hidden));
}
return $form;
@@ -83,7 +89,15 @@ if ( ! function_exists('form_open_multipart'))
{
function form_open_multipart($action, $attributes = array(), $hidden = array())
{
- $attributes['enctype'] = 'multipart/form-data';
+ if (is_string($attributes))
+ {
+ $attributes .= ' enctype="multipart/form-data"';
+ }
+ else
+ {
+ $attributes['enctype'] = 'multipart/form-data';
+ }
+
return form_open($action, $attributes, $hidden);
}
}
@@ -129,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);
}
}
@@ -236,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>";
}
@@ -257,7 +271,7 @@ if ( ! function_exists('form_textarea'))
* @param string
* @return type
*/
-if (! function_exists('form_multiselect'))
+if ( ! function_exists('form_multiselect'))
{
function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '')
{
@@ -265,7 +279,7 @@ if (! function_exists('form_multiselect'))
{
$extra .= ' multiple="multiple"';
}
-
+
return form_dropdown($name, $options, $selected, $extra);
}
}
@@ -311,7 +325,7 @@ if ( ! function_exists('form_dropdown'))
{
$key = (string) $key;
- if (is_array($val))
+ if (is_array($val) && ! empty($val))
{
$form .= '<optgroup label="'.$key.'">'."\n";
@@ -400,7 +414,7 @@ if ( ! function_exists('form_radio'))
function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
{
if ( ! is_array($data))
- {
+ {
$data = array('name' => $data);
}
@@ -421,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);
@@ -498,7 +512,7 @@ if ( ! function_exists('form_label'))
if ($id != '')
{
- $label .= " for=\"$id\"";
+ $label .= " for=\"$id\"";
}
if (is_array($attributes) AND count($attributes) > 0)
@@ -596,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))
{
@@ -621,7 +635,7 @@ if ( ! function_exists('form_prep'))
{
return $str;
}
-
+
$str = htmlspecialchars($str);
// In case htmlspecialchars misses these.
@@ -629,9 +643,9 @@ if ( ! function_exists('form_prep'))
if ($field_name != '')
{
- $prepped_fields[$field_name] = $str;
+ $prepped_fields[$field_name] = $field_name;
}
-
+
return $str;
}
}
@@ -743,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)
@@ -754,7 +768,7 @@ if ( ! function_exists('set_checkbox'))
}
$field = $_POST[$field];
-
+
if (is_array($field))
{
if ( ! in_array($value, $field))
@@ -809,7 +823,7 @@ if ( ! function_exists('set_radio'))
}
$field = $_POST[$field];
-
+
if (is_array($field))
{
if ( ! in_array($value, $field))
@@ -919,7 +933,7 @@ if ( ! function_exists('_parse_form_attributes'))
}
$att = '';
-
+
foreach ($default as $key => $val)
{
if ($key == 'value')
@@ -957,9 +971,14 @@ if ( ! function_exists('_attributes_to_string'))
$attributes .= ' method="post"';
}
+ if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE)
+ {
+ $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"';
+ }
+
return ' '.$attributes;
}
-
+
if (is_object($attributes) AND count($attributes) > 0)
{
$attributes = (array)$attributes;
@@ -967,19 +986,24 @@ if ( ! function_exists('_attributes_to_string'))
if (is_array($attributes) AND count($attributes) > 0)
{
- $atts = '';
+ $atts = '';
- if ( ! isset($attributes['method']) AND $formtag === TRUE)
- {
- $atts .= ' method="post"';
- }
+ if ( ! isset($attributes['method']) AND $formtag === TRUE)
+ {
+ $atts .= ' method="post"';
+ }
- foreach ($attributes as $key => $val)
- {
- $atts .= ' '.$key.'="'.$val.'"';
- }
+ if ( ! isset($attributes['accept-charset']) AND $formtag === TRUE)
+ {
+ $atts .= ' accept-charset="'.strtolower(config_item('charset')).'"';
+ }
+
+ foreach ($attributes as $key => $val)
+ {
+ $atts .= ' '.$key.'="'.$val.'"';
+ }
- return $atts;
+ return $atts;
}
}
}
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index c18a68778..68c6f5908 100644..100755
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -97,7 +97,7 @@ if ( ! function_exists('ol'))
* @param string
* @param mixed
* @param mixed
- * @param intiger
+ * @param integer
* @return string
*/
if ( ! function_exists('_list'))
@@ -199,6 +199,12 @@ if ( ! function_exists('img'))
$src = array('src' => $src);
}
+ // If there is no alt attribute defined, set it to an empty string
+ if ( ! isset($src['alt']))
+ {
+ $src['alt'] = '';
+ }
+
$img = '<img';
foreach ($src as $k=>$v)
@@ -210,16 +216,16 @@ if ( ! function_exists('img'))
if ($index_page === TRUE)
{
- $img .= ' src="'.$CI->config->site_url($v).'" ';
+ $img .= ' src="'.$CI->config->site_url($v).'"';
}
else
{
- $img .= ' src="'.$CI->config->slash_item('base_url').$v.'" ';
+ $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"';
}
}
else
{
- $img .= " $k=\"$v\" ";
+ $img .= " $k=\"$v\"";
}
}
@@ -301,11 +307,11 @@ if ( ! function_exists('link_tag'))
{
if ($index_page === TRUE)
{
- $link .= ' href="'.$CI->config->site_url($v).'" ';
+ $link .= 'href="'.$CI->config->site_url($v).'" ';
}
else
{
- $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" ';
+ $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" ';
}
}
else
@@ -320,15 +326,15 @@ if ( ! function_exists('link_tag'))
{
if ( strpos($href, '://') !== FALSE)
{
- $link .= ' href="'.$href.'" ';
+ $link .= 'href="'.$href.'" ';
}
elseif ($index_page === TRUE)
{
- $link .= ' href="'.$CI->config->site_url($href).'" ';
+ $link .= 'href="'.$CI->config->site_url($href).'" ';
}
else
{
- $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" ';
+ $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" ';
}
$link .= 'rel="'.$rel.'" type="'.$type.'" ';
@@ -382,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/index.html b/system/helpers/index.html
index c942a79ce..c942a79ce 100644..100755
--- a/system/helpers/index.html
+++ b/system/helpers/index.html
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index ffa99cc26..4cd7486b4 100644..100755
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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));
@@ -91,6 +91,17 @@ if ( ! function_exists('plural'))
$vowels = array('a', 'e', 'i', 'o', 'u');
$str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
}
+ elseif ($end == 'h')
+ {
+ if (substr($str, -2) == 'ch' OR substr($str, -2) == 'sh')
+ {
+ $str .= 'es';
+ }
+ else
+ {
+ $str .= 's';
+ }
+ }
elseif ($end == 's')
{
if ($force == TRUE)
@@ -117,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);
@@ -138,7 +149,7 @@ if ( ! function_exists('camelize'))
* @access public
* @param string
* @return str
- */
+ */
if ( ! function_exists('underscore'))
{
function underscore($str)
@@ -157,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..68c1a1fc6 100644..100755
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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 cf683f2a1..a2caea5e3 100644..100755
--- a/system/helpers/number_helper.php
+++ b/system/helpers/number_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -36,29 +36,29 @@
*/
if ( ! function_exists('byte_format'))
{
- function byte_format($num)
+ function byte_format($num, $precision = 1)
{
$CI =& get_instance();
$CI->lang->load('number');
-
- if ($num >= 1000000000000)
+
+ if ($num >= 1000000000000)
{
- $num = round($num / 1099511627776, 1);
+ $num = round($num / 1099511627776, $precision);
$unit = $CI->lang->line('terabyte_abbr');
}
- elseif ($num >= 1000000000)
+ elseif ($num >= 1000000000)
{
- $num = round($num / 1073741824, 1);
+ $num = round($num / 1073741824, $precision);
$unit = $CI->lang->line('gigabyte_abbr');
}
- elseif ($num >= 1000000)
+ elseif ($num >= 1000000)
{
- $num = round($num / 1048576, 1);
+ $num = round($num / 1048576, $precision);
$unit = $CI->lang->line('megabyte_abbr');
}
- elseif ($num >= 1000)
+ elseif ($num >= 1000)
{
- $num = round($num / 1024, 1);
+ $num = round($num / 1024, $precision);
$unit = $CI->lang->line('kilobyte_abbr');
}
else
@@ -67,9 +67,10 @@ if ( ! function_exists('byte_format'))
return number_format($num).' '.$unit;
}
- return number_format($num, 1).' '.$unit;
- }
+ return number_format($num, $precision).' '.$unit;
+ }
}
+
/* End of file number_helper.php */
/* Location: ./system/helpers/number_helper.php */ \ No newline at end of file
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index 030b6bff1..ffcf46842 100644..100755
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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 1fc47b34b..61ebf46f9 100644..100755
--- a/system/helpers/security_helper.php
+++ b/system/helpers/security_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -34,35 +34,69 @@
* @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)
{
$CI =& get_instance();
- return $CI->input->xss_clean($str, $is_image);
+ return $CI->security->xss_clean($str, $is_image);
}
}
-// --------------------------------------------------------------------
+// ------------------------------------------------------------------------
/**
- * Hash encode a string
+ * Sanitize Filename
*
* @access public
* @param string
* @return string
- */
+ */
+if ( ! function_exists('sanitize_filename'))
+{
+ function sanitize_filename($filename)
+ {
+ $CI =& get_instance();
+ return $CI->security->sanitize_filename($filename);
+ }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Hash encode a string
+ *
+ * This is simply an alias for do_hash()
+ * dohash() is now deprecated
+ */
if ( ! function_exists('dohash'))
-{
+{
function dohash($str, $type = 'sha1')
{
+ return do_hash($str, $type);
+ }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Hash encode a string
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+if ( ! function_exists('do_hash'))
+{
+ function do_hash($str, $type = 'sha1')
+ {
if ($type == 'sha1')
{
if ( ! function_exists('sha1'))
{
if ( ! function_exists('mhash'))
- {
+ {
require_once(BASEPATH.'libraries/Sha1'.EXT);
$SH = new CI_SHA;
return $SH->generate($str);
@@ -75,7 +109,7 @@ if ( ! function_exists('dohash'))
else
{
return sha1($str);
- }
+ }
}
else
{
@@ -83,7 +117,7 @@ if ( ! function_exists('dohash'))
}
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -92,18 +126,18 @@ if ( ! function_exists('dohash'))
* @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;
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -112,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 3a31be36e..80a8d79ad 100644..100755
--- a/system/helpers/smiley_helper.php
+++ b/system/helpers/smiley_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -40,12 +40,12 @@
*/
if ( ! function_exists('smiley_js'))
{
- function smiley_js($alias = '', $field_id = '')
+ function smiley_js($alias = '', $field_id = '', $inline = TRUE)
{
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,23 +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;
@@ -93,7 +92,7 @@ if ( ! function_exists('smiley_js'))
el.setSelectionRange(newStart, newStart);
}
else if (document.selection) {
- document.selection.createRange().text = text;
+ document.selection.createRange().text = smiley;
}
}
EOF;
@@ -109,7 +108,14 @@ EOF;
}
}
- return '<script type="text/javascript" charset="utf-8">'.$r.'</script>';
+ if ($inline)
+ {
+ return '<script type="text/javascript" charset="utf-8">/*<![CDATA[ */'.$r.'// ]]></script>';
+ }
+ else
+ {
+ return $r;
+ }
}
}
@@ -118,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
@@ -130,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()))
@@ -146,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)
{
@@ -158,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 c0409dc5a..7765bba31 100644..100755
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -30,7 +30,7 @@
/**
* Trim Slashes
*
- * Removes any leading/traling slashes from a string:
+ * Removes any leading/trailing slashes from a string:
*
* /this/that/theother/
*
@@ -41,15 +41,15 @@
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('trim_slashes'))
{
function trim_slashes($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,16 +110,17 @@ 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("&#39;","&quot;","&#39;","&quot;"), $str);
}
}
// ------------------------------------------------------------------------
+
/**
* Reduce Double Slashes
*
@@ -135,15 +136,15 @@ if ( ! function_exists('quotes_to_entities'))
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('reduce_double_slashes'))
{
function reduce_double_slashes($str)
{
- return preg_replace("#([^:])//+#", "\\1/", $str);
+ return preg_replace("#(^|[^:])//+#", "\\1/", $str);
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -162,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)
@@ -177,7 +178,7 @@ if ( ! function_exists('reduce_multiples'))
return $str;
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -186,22 +187,27 @@ if ( ! function_exists('reduce_multiples'))
* Useful for generating passwords or hashes.
*
* @access public
- * @param string type of random string. Options: alunum, numeric, nozero, unique
+ * @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;
case 'alnum' :
case 'numeric' :
case 'nozero' :
-
+ case 'alpha' :
+
switch ($type)
{
+ case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'numeric' : $pool = '0123456789';
@@ -216,9 +222,20 @@ if ( ! function_exists('random_string'))
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
return $str;
- break;
- case 'unique' : return md5(uniqid(mt_rand()));
- break;
+ break;
+ case 'unique' :
+ case 'md5' :
+
+ return md5(uniqid(mt_rand()));
+ break;
+ case 'encrypt' :
+ case 'sha1' :
+
+ $CI =& get_instance();
+ $CI->load->helper('security');
+
+ return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
+ break;
}
}
}
@@ -233,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)
{
@@ -259,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 1e672937b..47e6ccc93 100644..100755
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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 = '&#8230;')
@@ -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 = '&#8230;')
@@ -80,7 +80,7 @@ if ( ! function_exists('character_limiter'))
{
return $str;
}
-
+
$str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
if (strlen($str) <= $n)
@@ -92,16 +92,16 @@ if ( ! function_exists('character_limiter'))
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
@@ -138,31 +138,31 @@ if ( ! function_exists('ascii_to_entities'))
}
$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("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
- 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("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
+ 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,13 +242,13 @@ 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
// will not match on a word boundary. Instead, we'll assume that
- // a bad word will be bookended by any of these characters.
+ // a bad word will be bookeneded by any of these characters.
$delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
foreach ($censored as $badword)
@@ -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('&lt;', '&gt;'), 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]+)">&lt;\?php(&nbsp;| )/i', '<span style="color: #$1">', $str);
$str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/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('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $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);
@@ -352,7 +352,36 @@ if ( ! function_exists('highlight_phrase'))
return $str;
}
}
-
+
+// ------------------------------------------------------------------------
+
+/**
+ * Convert Accented Foreign Characters to ASCII
+ *
+ * @access public
+ * @param string the text string
+ * @return string
+ */
+if ( ! function_exists('convert_accented_characters'))
+{
+ function convert_accented_characters($str)
+ {
+ if ( ! file_exists(APPPATH.'config/foreign_chars'.EXT))
+ {
+ return $str;
+ }
+
+ include APPPATH.'config/foreign_chars'.EXT;
+
+ if ( ! isset($foreign_characters))
+ {
+ return $str;
+ }
+
+ return preg_replace(array_keys($foreign_characters), array_values($foreign_characters), $str);
+ }
+}
+
// ------------------------------------------------------------------------
/**
@@ -366,7 +395,7 @@ if ( ! function_exists('highlight_phrase'))
* @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')
@@ -374,47 +403,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))
@@ -426,12 +455,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
{
@@ -443,7 +472,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);
@@ -453,10 +482,52 @@ if ( ! function_exists('word_wrap'))
// Remove the unwrap tags
$output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
- return $output;
+ return $output;
}
}
+// ------------------------------------------------------------------------
+
+/**
+ * Ellipsize String
+ *
+ * This function will strip tags from a string, split it at its max_length and ellipsize
+ *
+ * @param string string to ellipsize
+ * @param integer max length of string
+ * @param mixed int (1|0) or float, .5, .2, etc for position to split
+ * @param string ellipsis ; Default '...'
+ * @return string ellipsized string
+ */
+if ( ! function_exists('ellipsize'))
+{
+ function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
+ {
+ // Strip tags
+ $str = trim(strip_tags($str));
+
+ // Is the string long enough to ellipsize?
+ if (strlen($str) <= $max_length)
+ {
+ return $str;
+ }
+
+ $beg = substr($str, 0, floor($max_length * $position));
+
+ $position = ($position > 1) ? 1 : $position;
+
+ if ($position === 1)
+ {
+ $end = substr($str, 0, -($max_length - strlen($beg)));
+ }
+ else
+ {
+ $end = substr($str, -($max_length - strlen($beg)));
+ }
+
+ return $beg.$ellipsis.$end;
+ }
+}
/* End of file text_helper.php */
/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file
diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php
index 5621e6dd0..302bf45c5 100644..100755
--- a/system/helpers/typography_helper.php
+++ b/system/helpers/typography_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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);
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -54,16 +54,39 @@ if ( ! function_exists('nl2br_except_pre'))
*
* @access public
* @param string
+ * @param bool whether to allow javascript event handlers
* @param bool whether to reduce multiple instances of double newlines to two
* @return string
*/
if ( ! function_exists('auto_typography'))
{
- function auto_typography($str, $reduce_linebreaks = FALSE)
+ 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, $reduce_linebreaks);
+ return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks);
+ }
+}
+
+
+// --------------------------------------------------------------------
+
+/**
+ * HTML Entities Decode
+ *
+ * This function is a replacement for html_entity_decode()
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+if ( ! function_exists('entity_decode'))
+{
+ function entity_decode($str, $charset='UTF-8')
+ {
+ $CI =& get_instance();
+ $CI->load->library('security');
+ return $CI->security->entity_decode($str, $charset);
}
}
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 90ea9207e..d0516cee6 100644..100755
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -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);
}
}
@@ -431,7 +431,7 @@ if ( ! function_exists('auto_link'))
/**
* Prep URL
*
- * Simply adds the http:// part if missing
+ * Simply adds the http:// part if no scheme is included
*
* @access public
* @param string the URL
@@ -446,7 +446,9 @@ if ( ! function_exists('prep_url'))
return '';
}
- if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
+ $url = parse_url($str);
+
+ if ( ! $url OR ! isset($url['scheme']))
{
$str = 'http://'.$str;
}
@@ -493,7 +495,7 @@ if ( ! function_exists('url_title'))
$replace.'$' => $replace,
'^'.$replace => $replace,
'\.+$' => ''
- );
+ );
$str = strip_tags($str);
@@ -506,7 +508,7 @@ if ( ! function_exists('url_title'))
{
$str = strtolower($str);
}
-
+
return trim(stripslashes($str));
}
}
@@ -533,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 712f6777e..cdd81ad70 100644..100755
--- a/system/helpers/xml_helper.php
+++ b/system/helpers/xml_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -33,30 +33,39 @@
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('xml_convert'))
{
- function xml_convert($str)
+ function xml_convert($str, $protect_all = FALSE)
{
$temp = '__TEMP_AMPERSANDS__';
- // Replace entities to temporary markers so that
+ // Replace entities to temporary markers so that
// ampersands won't get messed up
$str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
- $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
-
+
+ if ($protect_all === TRUE)
+ {
+ $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
+ }
+
$str = str_replace(array("&","<",">","\"", "'", "-"),
- array("&amp;", "&lt;", "&gt;", "&quot;", "&#39;", "&#45;"),
- $str);
+ array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
+ $str);
- // Decode the temp markers back to entities
+ // Decode the temp markers back to entities
$str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
- $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
-
+
+ if ($protect_all === TRUE)
+ {
+ $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
+ }
+
return $str;
}
}
+// ------------------------------------------------------------------------
/* End of file xml_helper.php */
/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file