diff options
author | Derek Allard <derek.allard@ellislab.com> | 2008-01-18 20:41:32 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2008-01-18 20:41:32 +0100 |
commit | 3d879d529107c0c9d3f1e6b894d9ed17b6e6c54f (patch) | |
tree | 4807d948cd652645031f75a14bc4b82840c99edd /system/helpers | |
parent | 4a9cb96df665485c1f5d0d98cd4723d4e2f45ce8 (diff) |
ExpressionEngine Dev Team in credit
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/array_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/cookie_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/date_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/directory_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/download_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/file_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/form_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/html_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/inflector_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/security_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/smiley_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/string_helper.php | 245 | ||||
-rw-r--r-- | system/helpers/text_helper.php | 422 | ||||
-rw-r--r-- | system/helpers/typography_helper.php | 7 | ||||
-rw-r--r-- | system/helpers/url_helper.php | 4 | ||||
-rw-r--r-- | system/helpers/xml_helper.php | 4 |
16 files changed, 694 insertions, 32 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 9c4447198..d559adf20 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/array_helper.html
*/
diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 663ef1c5d..c1469a9e9 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/cookie_helper.html
*/
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index b80f5f7d7..7213c3aa5 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/date_helper.html
*/
diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 425613669..273c8eeb5 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/directory_helper.html
*/
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 257233481..ece22d9a9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/download_helper.html
*/
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 83ef6a066..ebf30e947 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/file_helpers.html
*/
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a727f4715..5c1457066 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/form_helper.html
*/
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 48d680f29..07757c27f 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/html_helper.html
*/
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 4202bd12c..a72d0cef7 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/directory_helper.html
*/
diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index a8afd7dbd..44c6811d1 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/security_helper.html
*/
diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 86654a761..58ed20ef5 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/smiley_helper.html
*/
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 765e1648f..6f9491bb7 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1 +1,244 @@ -<?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 Rick Ellis
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter String Helpers
*
* @package CodeIgniter
* @subpackage Helpers
* @category Helpers
* @author Rick Ellis
* @link http://www.codeigniter.com/user_guide/helpers/string_helper.html
*/
// ------------------------------------------------------------------------
/**
* Trim Slashes
*
* Removes any leading/traling slashes from a string:
*
* /this/that/theother/
*
* becomes:
*
* this/that/theother
*
* @access public
* @param string
* @return string
*/
function trim_slashes($str)
{
return trim($str, '/');
}
// ------------------------------------------------------------------------
/**
* Strip Slashes
*
* Removes slashes contained in a string or in an array
*
* @access public
* @param mixed string or array
* @return mixed stering or array
*/
function strip_slashes($str)
{
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = strip_slashes($val);
}
}
else
{
$str = stripslashes($str);
}
return $str;
}
// ------------------------------------------------------------------------
/**
* Strip Quotes
*
* Removes single and double quotes from a string
*
* @access public
* @param string
* @return string
*/
function strip_quotes($str)
{
return str_replace(array('"', "'"), '', $str);
}
// ------------------------------------------------------------------------
/**
* Quotes to Entities
*
* Converts single and double quotes to entities
*
* @access public
* @param string
* @return string
*/
function quotes_to_entities($str)
{
return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
}
// ------------------------------------------------------------------------
/**
* Reduce Double Slashes
*
* Converts double slashes in a string to a single slash,
* except those found in http://
*
* http://www.some-site.com//index.php
*
* becomes:
*
* http://www.some-site.com/index.php
*
* @access public
* @param string
* @return string
*/
function reduce_double_slashes($str)
{
return preg_replace("#([^:])//+#", "\\1/", $str);
}
// ------------------------------------------------------------------------
/**
* Reduce Multiples
*
* Reduces multiple instances of a particular character. Example:
*
* Fred, Bill,, Joe, Jimmy
*
* becomes:
*
* Fred, Bill, Joe, Jimmy
*
* @access public
* @param string
* @param string the character you wish to reduce
* @param bool TRUE/FALSE - whether to trim the character from the beginning/end
* @return string
*/
function reduce_multiples($str, $character = ',', $trim = FALSE)
{
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
if ($trim === TRUE)
{
$str = trim($str, $character);
}
return $str;
}
// ------------------------------------------------------------------------
/**
* Create a Random String
*
* Useful for generating passwords or hashes.
*
* @access public
* @param string type of random string. Options: alunum, numeric, nozero, unique
* @param integer number of characters
* @return string
*/
function random_string($type = 'alnum', $len = 8)
{
switch($type)
{
case 'alnum' :
case 'numeric' :
case 'nozero' :
switch ($type)
{
case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'numeric' : $pool = '0123456789';
break;
case 'nozero' : $pool = '123456789';
break;
}
$str = '';
for ($i=0; $i < $len; $i++)
{
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
return $str;
break;
case 'unique' : return md5(uniqid(mt_rand()));
break;
}
}
// ------------------------------------------------------------------------
/**
* Alternator
*
* Allows strings to be alternated. See docs...
*
* @access public
* @param string (as many parameters as needed)
* @return string
*/
function alternator()
{
static $i;
if (func_num_args() == 0)
{
$i = 0;
return '';
}
$args = func_get_args();
return $args[($i++ % count($args))];
}
// ------------------------------------------------------------------------
/**
* Repeater function
*
* @access public
* @param string
* @param integer number of repeats
* @return string
*/
function repeater($data, $num = 1)
{
return (($num > 0) ? str_repeat($data, $num) : '');
}
?>
\ No newline at end of file +<?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) 2006, EllisLab, Inc.
+ * @license http://www.codeigniter.com/user_guide/license.html
+ * @link http://www.codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter String Helpers
+ *
+ * @package CodeIgniter
+ * @subpackage Helpers
+ * @category Helpers
+ * @author ExpressionEngine Dev Team
+ * @link http://www.codeigniter.com/user_guide/helpers/string_helper.html
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Trim Slashes
+ *
+ * Removes any leading/traling slashes from a string:
+ *
+ * /this/that/theother/
+ *
+ * becomes:
+ *
+ * this/that/theother
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+function trim_slashes($str)
+{
+ return trim($str, '/');
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Strip Slashes
+ *
+ * Removes slashes contained in a string or in an array
+ *
+ * @access public
+ * @param mixed string or array
+ * @return mixed stering or array
+ */
+ function strip_slashes($str)
+ {
+ if (is_array($str))
+ {
+ foreach ($str as $key => $val)
+ {
+ $str[$key] = strip_slashes($val);
+ }
+ }
+ else
+ {
+ $str = stripslashes($str);
+ }
+
+ return $str;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Strip Quotes
+ *
+ * Removes single and double quotes from a string
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+function strip_quotes($str)
+{
+ return str_replace(array('"', "'"), '', $str);
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Quotes to Entities
+ *
+ * Converts single and double quotes to entities
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+function quotes_to_entities($str)
+{
+ return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
+}
+
+// ------------------------------------------------------------------------
+/**
+ * Reduce Double Slashes
+ *
+ * Converts double slashes in a string to a single slash,
+ * except those found in http://
+ *
+ * http://www.some-site.com//index.php
+ *
+ * becomes:
+ *
+ * http://www.some-site.com/index.php
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+function reduce_double_slashes($str)
+{
+ return preg_replace("#([^:])//+#", "\\1/", $str);
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Reduce Multiples
+ *
+ * Reduces multiple instances of a particular character. Example:
+ *
+ * Fred, Bill,, Joe, Jimmy
+ *
+ * becomes:
+ *
+ * Fred, Bill, Joe, Jimmy
+ *
+ * @access public
+ * @param string
+ * @param string the character you wish to reduce
+ * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
+ * @return string
+ */
+function reduce_multiples($str, $character = ',', $trim = FALSE)
+{
+ $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
+
+ if ($trim === TRUE)
+ {
+ $str = trim($str, $character);
+ }
+
+ return $str;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Create a Random String
+ *
+ * Useful for generating passwords or hashes.
+ *
+ * @access public
+ * @param string type of random string. Options: alunum, numeric, nozero, unique
+ * @param integer number of characters
+ * @return string
+ */
+function random_string($type = 'alnum', $len = 8)
+{
+ switch($type)
+ {
+ case 'alnum' :
+ case 'numeric' :
+ case 'nozero' :
+
+ switch ($type)
+ {
+ case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
+ case 'numeric' : $pool = '0123456789';
+ break;
+ case 'nozero' : $pool = '123456789';
+ break;
+ }
+
+ $str = '';
+ for ($i=0; $i < $len; $i++)
+ {
+ $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
+ }
+ return $str;
+ break;
+ case 'unique' : return md5(uniqid(mt_rand()));
+ break;
+ }
+}
+// ------------------------------------------------------------------------
+
+/**
+ * Alternator
+ *
+ * Allows strings to be alternated. See docs...
+ *
+ * @access public
+ * @param string (as many parameters as needed)
+ * @return string
+ */
+function alternator()
+{
+ static $i;
+
+ if (func_num_args() == 0)
+ {
+ $i = 0;
+ return '';
+ }
+ $args = func_get_args();
+ return $args[($i++ % count($args))];
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Repeater function
+ *
+ * @access public
+ * @param string
+ * @param integer number of repeats
+ * @return string
+ */
+function repeater($data, $num = 1)
+{
+ return (($num > 0) ? str_repeat($data, $num) : '');
+}
+
+
+?>
\ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b75cd8f78..211ef1055 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1 +1,421 @@ -<?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 Rick Ellis
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter Text Helpers
*
* @package CodeIgniter
* @subpackage Helpers
* @category Helpers
* @author Rick Ellis
* @link http://www.codeigniter.com/user_guide/helpers/text_helper.html
*/
// ------------------------------------------------------------------------
/**
* Word Limiter
*
* Limits a string to X number of words.
*
* @access public
* @param string
* @param integer
* @param string the end character. Usually an ellipsis
* @return string
*/
function word_limiter($str, $n = 100, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}
$words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)));
if (count($words) <= $n)
{
return $str;
}
$str = '';
for ($i = 0; $i < $n; $i++)
{
$str .= $words[$i].' ';
}
return trim($str).$end_char;
}
// ------------------------------------------------------------------------
/**
* Character Limiter
*
* Limits the string based on the character count. Preserves complete words
* so the character count may not be exactly as specified.
*
* @access public
* @param string
* @param integer
* @param string the end character. Usually an ellipsis
* @return string
*/
function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n)
{
return $str;
}
$str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));
if (strlen($str) <= $n)
{
return $str;
}
$out = "";
foreach (explode(' ', trim($str)) as $val)
{
$out .= $val.' ';
if (strlen($out) >= $n)
{
return trim($out).$end_char;
}
}
}
// ------------------------------------------------------------------------
/**
* High ASCII to Entities
*
* Converts High ascii text and MS Word special characters to character entities
*
* @access public
* @param string
* @return string
*/
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)
{
$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;
}
// ------------------------------------------------------------------------
/**
* Entities to ASCII
*
* Converts character entities back to ASCII
*
* @access public
* @param string
* @param bool
* @return string
*/
function entities_to_ascii($str, $all = TRUE)
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
{
for ($i = 0, $s = count($matches['0']); $i < $s; $i++)
{
$digits = $matches['1'][$i];
$out = '';
if ($digits < 128)
{
$out .= chr($digits);
}
elseif ($digits < 2048)
{
$out .= chr(192 + (($digits - ($digits % 64)) / 64));
$out .= chr(128 + ($digits % 64));
}
else
{
$out .= chr(224 + (($digits - ($digits % 4096)) / 4096));
$out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64));
$out .= chr(128 + ($digits % 64));
}
$str = str_replace($matches['0'][$i], $out, $str);
}
}
if ($all)
{
$str = str_replace(array("&", "<", ">", """, "'", "-"),
array("&","<",">","\"", "'", "-"),
$str);
}
return $str;
}
// ------------------------------------------------------------------------
/**
* Word Censoring Function
*
* Supply a string and an array of disallowed words and any
* matched words will be converted to #### or to the replacement
* word you've submitted.
*
* @access public
* @param string the text string
* @param string the array of censoered words
* @param string the optional replacement value
* @return string
*/
function word_censor($str, $censored, $replacement = '')
{
if ( ! is_array($censored))
{
return $str;
}
$str = ' '.$str.' ';
foreach ($censored as $badword)
{
if ($replacement != '')
{
$str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str);
}
else
{
$str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str);
}
}
return trim($str);
}
// ------------------------------------------------------------------------
/**
* Code Highlighter
*
* Colorizes code strings
*
* @access public
* @param string the text string
* @return string
*/
function highlight_code($str)
{
// The highlight string function encodes and highlights
// brackets so we need them to start raw
$str = str_replace(array('<', '>'), array('<', '>'), $str);
// Replace any existing PHP tags to temporary markers so they don't accidentally
// break the string out of PHP, and thus, thwart the highlighting.
$str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str);
// The highlight_string function requires that the text be surrounded
// by PHP tags. Since we don't know if A) the submitted text has PHP tags,
// or B) whether the PHP tags enclose the entire string, we will add our
// own PHP tags around the string along with some markers to make replacement easier later
$str = '<?php //tempstart'."\n".$str.'//tempend ?>';
// All the magic happens here, baby!
$str = highlight_string($str, TRUE);
// Prior to PHP 5, the highlight function used icky font tags
// so we'll replace them with span tags.
if (abs(phpversion()) < 5)
{
$str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
$str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
}
// Remove our artificially added PHP
$str = preg_replace("#\<code\>.+?//tempstart\<br />\</span\>#is", "<code>\n", $str);
$str = preg_replace("#\<code\>.+?//tempstart\<br />#is", "<code>\n", $str);
$str = preg_replace("#//tempend.+#is", "</span>\n</code>", $str);
// Replace our markers back to PHP tags.
$str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //<?
return $str;
}
// ------------------------------------------------------------------------
/**
* Phrase Highlighter
*
* Highlights a phrase within a text string
*
* @access public
* @param string the text string
* @param string the phrase you'd like to highlight
* @param string the openging tag to precede the phrase with
* @param string the closing tag to end the phrase with
* @return string
*/
function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
{
if ($str == '')
{
return '';
}
if ($phrase != '')
{
return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
}
return $str;
}
// ------------------------------------------------------------------------
/**
* Word Wrap
*
* Wraps text at the specified character. Maintains the integrity of words.
* Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
* will URLs.
*
* @access public
* @param string the text string
* @param integer the number of characters to wrap at
* @return string
*/
function word_wrap($str, $charlim = '76')
{
// Se the character limit
if ( ! is_numeric($charlim))
$charlim = 76;
// Reduce multiple spaces
$str = preg_replace("| +|", " ", $str);
// Standardize newlines
$str = preg_replace("/\r\n|\r/", "\n", $str);
// 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];
$str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
}
}
// Use PHP's native function to do the initial wordwrap.
// We set the cut flag to FALSE so that any individual words that are
// too long get left alone. In the next step we'll deal with them.
$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)
{
// 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";
continue;
}
$temp = '';
while((strlen($line)) > $charlim)
{
// If the over-length word is a URL we won't wrap it
if (preg_match("!\[url.+\]|://|wwww.!", $line))
{
break;
}
// Trim the word down
$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
// word into smaller chunks so we'll add it back to our current line
if ($temp != '')
{
$output .= $temp . "\n" . $line;
}
else
{
$output .= $line;
}
$output .= "\n";
}
// Put our markers back
if (count($unwrap) > 0)
{
foreach ($unwrap as $key => $val)
{
$output = str_replace("{{unwrapped".$key."}}", $val, $output);
}
}
// Remove the unwrap tags
$output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
return $output;
}
?>
\ No newline at end of file +<?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) 2006, EllisLab, Inc.
+ * @license http://www.codeigniter.com/user_guide/license.html
+ * @link http://www.codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Text Helpers
+ *
+ * @package CodeIgniter
+ * @subpackage Helpers
+ * @category Helpers
+ * @author ExpressionEngine Dev Team
+ * @link http://www.codeigniter.com/user_guide/helpers/text_helper.html
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Word Limiter
+ *
+ * Limits a string to X number of words.
+ *
+ * @access public
+ * @param string
+ * @param integer
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
+function word_limiter($str, $n = 100, $end_char = '…')
+{
+ if (strlen($str) < $n)
+ {
+ return $str;
+ }
+
+ $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)));
+
+ if (count($words) <= $n)
+ {
+ return $str;
+ }
+
+ $str = '';
+ for ($i = 0; $i < $n; $i++)
+ {
+ $str .= $words[$i].' ';
+ }
+
+ return trim($str).$end_char;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Character Limiter
+ *
+ * Limits the string based on the character count. Preserves complete words
+ * so the character count may not be exactly as specified.
+ *
+ * @access public
+ * @param string
+ * @param integer
+ * @param string the end character. Usually an ellipsis
+ * @return string
+ */
+function character_limiter($str, $n = 500, $end_char = '…')
+{
+ if (strlen($str) < $n)
+ {
+ return $str;
+ }
+
+ $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));
+
+ if (strlen($str) <= $n)
+ {
+ return $str;
+ }
+
+ $out = "";
+ foreach (explode(' ', trim($str)) as $val)
+ {
+ $out .= $val.' ';
+ if (strlen($out) >= $n)
+ {
+ return trim($out).$end_char;
+ }
+ }
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * High ASCII to Entities
+ *
+ * Converts High ascii text and MS Word special characters to character entities
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+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)
+ {
+ $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;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Entities to ASCII
+ *
+ * Converts character entities back to ASCII
+ *
+ * @access public
+ * @param string
+ * @param bool
+ * @return string
+ */
+function entities_to_ascii($str, $all = TRUE)
+{
+ if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
+ {
+ for ($i = 0, $s = count($matches['0']); $i < $s; $i++)
+ {
+ $digits = $matches['1'][$i];
+
+ $out = '';
+
+ if ($digits < 128)
+ {
+ $out .= chr($digits);
+
+ }
+ elseif ($digits < 2048)
+ {
+ $out .= chr(192 + (($digits - ($digits % 64)) / 64));
+ $out .= chr(128 + ($digits % 64));
+ }
+ else
+ {
+ $out .= chr(224 + (($digits - ($digits % 4096)) / 4096));
+ $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64));
+ $out .= chr(128 + ($digits % 64));
+ }
+
+ $str = str_replace($matches['0'][$i], $out, $str);
+ }
+ }
+
+ if ($all)
+ {
+ $str = str_replace(array("&", "<", ">", """, "'", "-"),
+ array("&","<",">","\"", "'", "-"),
+ $str);
+ }
+
+ return $str;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Word Censoring Function
+ *
+ * Supply a string and an array of disallowed words and any
+ * matched words will be converted to #### or to the replacement
+ * word you've submitted.
+ *
+ * @access public
+ * @param string the text string
+ * @param string the array of censoered words
+ * @param string the optional replacement value
+ * @return string
+ */
+function word_censor($str, $censored, $replacement = '')
+{
+ if ( ! is_array($censored))
+ {
+ return $str;
+ }
+
+ $str = ' '.$str.' ';
+ foreach ($censored as $badword)
+ {
+ if ($replacement != '')
+ {
+ $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str);
+ }
+ else
+ {
+ $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str);
+ }
+ }
+
+ return trim($str);
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Code Highlighter
+ *
+ * Colorizes code strings
+ *
+ * @access public
+ * @param string the text string
+ * @return string
+ */
+function highlight_code($str)
+{
+ // The highlight string function encodes and highlights
+ // brackets so we need them to start raw
+ $str = str_replace(array('<', '>'), array('<', '>'), $str);
+
+ // Replace any existing PHP tags to temporary markers so they don't accidentally
+ // break the string out of PHP, and thus, thwart the highlighting.
+
+ $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str);
+
+ // The highlight_string function requires that the text be surrounded
+ // by PHP tags. Since we don't know if A) the submitted text has PHP tags,
+ // or B) whether the PHP tags enclose the entire string, we will add our
+ // own PHP tags around the string along with some markers to make replacement easier later
+
+ $str = '<?php //tempstart'."\n".$str.'//tempend ?>';
+
+ // All the magic happens here, baby!
+ $str = highlight_string($str, TRUE);
+
+ // Prior to PHP 5, the highlight function used icky font tags
+ // so we'll replace them with span tags.
+ if (abs(phpversion()) < 5)
+ {
+ $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
+ $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
+ }
+
+ // Remove our artificially added PHP
+ $str = preg_replace("#\<code\>.+?//tempstart\<br />\</span\>#is", "<code>\n", $str);
+ $str = preg_replace("#\<code\>.+?//tempstart\<br />#is", "<code>\n", $str);
+ $str = preg_replace("#//tempend.+#is", "</span>\n</code>", $str);
+
+ // Replace our markers back to PHP tags.
+ $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //<?
+
+ return $str;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Phrase Highlighter
+ *
+ * Highlights a phrase within a text string
+ *
+ * @access public
+ * @param string the text string
+ * @param string the phrase you'd like to highlight
+ * @param string the openging tag to precede the phrase with
+ * @param string the closing tag to end the phrase with
+ * @return string
+ */
+function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
+{
+ if ($str == '')
+ {
+ return '';
+ }
+
+ if ($phrase != '')
+ {
+ return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
+ }
+
+ return $str;
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Word Wrap
+ *
+ * Wraps text at the specified character. Maintains the integrity of words.
+ * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
+ * will URLs.
+ *
+ * @access public
+ * @param string the text string
+ * @param integer the number of characters to wrap at
+ * @return string
+ */
+function word_wrap($str, $charlim = '76')
+{
+ // Se the character limit
+ if ( ! is_numeric($charlim))
+ $charlim = 76;
+
+ // Reduce multiple spaces
+ $str = preg_replace("| +|", " ", $str);
+
+ // Standardize newlines
+ $str = preg_replace("/\r\n|\r/", "\n", $str);
+
+ // 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];
+ $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
+ }
+ }
+
+ // Use PHP's native function to do the initial wordwrap.
+ // We set the cut flag to FALSE so that any individual words that are
+ // too long get left alone. In the next step we'll deal with them.
+ $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)
+ {
+ // 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";
+ continue;
+ }
+
+ $temp = '';
+ while((strlen($line)) > $charlim)
+ {
+ // If the over-length word is a URL we won't wrap it
+ if (preg_match("!\[url.+\]|://|wwww.!", $line))
+ {
+ break;
+ }
+
+ // Trim the word down
+ $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
+ // word into smaller chunks so we'll add it back to our current line
+ if ($temp != '')
+ {
+ $output .= $temp . "\n" . $line;
+ }
+ else
+ {
+ $output .= $line;
+ }
+
+ $output .= "\n";
+ }
+
+ // Put our markers back
+ if (count($unwrap) > 0)
+ {
+ foreach ($unwrap as $key => $val)
+ {
+ $output = str_replace("{{unwrapped".$key."}}", $val, $output);
+ }
+ }
+
+ // Remove the unwrap tags
+ $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
+
+ return $output;
+}
+
+
+?>
\ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index aa751db8b..b57ec6c2c 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/typography_helper.html
*/
@@ -82,8 +82,7 @@ function auto_typography($str) *
* @access private
* @category Helpers
- * @author Rick Ellis
- * @author Paul Burdick
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/
*/
class Auto_typography {
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index b75ae6b11..39ef484c9 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/url_helper.html
*/
diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index e041bf9b6..8c39a7511 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://www.codeigniter.com/user_guide/license.html
* @link http://www.codeigniter.com
@@ -21,7 +21,7 @@ * @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author Rick Ellis
+ * @author ExpressionEngine Dev Team
* @link http://www.codeigniter.com/user_guide/helpers/xml_helper.html
*/
|