diff options
author | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
---|---|---|
committer | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
commit | 269b942a2bf7b022795e591d9b0ad04526ee7e09 (patch) | |
tree | f465bb5a700d4cc5d72ca6e55e251640a46b869b | |
parent | a25530f6594c7ba45b3faa9537fda9f807069759 (diff) |
added ability to "extend" helpers
* modified Loader to check for prefixed helpers in application/helpers folder
* surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent.
-rw-r--r-- | system/helpers/array_helper.php | 27 | ||||
-rw-r--r-- | system/helpers/cookie_helper.php | 86 | ||||
-rw-r--r-- | system/helpers/date_helper.php | 598 | ||||
-rw-r--r-- | system/helpers/directory_helper.php | 34 | ||||
-rw-r--r-- | system/helpers/download_helper.php | 94 | ||||
-rw-r--r-- | system/helpers/email_helper.php | 14 | ||||
-rw-r--r-- | system/helpers/file_helper.php | 138 | ||||
-rw-r--r-- | system/helpers/form_helper.php | 402 | ||||
-rw-r--r-- | system/helpers/html_helper.php | 140 | ||||
-rw-r--r-- | system/helpers/inflector_helper.php | 133 | ||||
-rw-r--r-- | system/helpers/security_helper.php | 66 | ||||
-rw-r--r-- | system/helpers/smiley_helper.php | 120 | ||||
-rw-r--r-- | system/helpers/string_helper.php | 165 | ||||
-rw-r--r-- | system/helpers/text_helper.php | 431 | ||||
-rw-r--r-- | system/helpers/typography_helper.php | 46 | ||||
-rw-r--r-- | system/helpers/url_helper.php | 482 | ||||
-rw-r--r-- | system/helpers/xml_helper.php | 32 | ||||
-rw-r--r-- | system/libraries/Loader.php | 17 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 | ||||
-rw-r--r-- | user_guide/general/helpers.html | 45 |
20 files changed, 1700 insertions, 1371 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 85d03794c..236e3904e 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -39,14 +39,17 @@ * @param mixed
* @return mixed depends on what the array contains
*/
-function element($item, $array, $default = FALSE)
+if (! function_exists('element'))
{
- if ( ! isset($array[$item]) OR $array[$item] == "")
+ function element($item, $array, $default = FALSE)
{
- return $default;
- }
+ if ( ! isset($array[$item]) OR $array[$item] == "")
+ {
+ return $default;
+ }
- return $array[$item];
+ return $array[$item];
+ }
}
// ------------------------------------------------------------------------
@@ -58,14 +61,16 @@ function element($item, $array, $default = FALSE) * @param array
* @return mixed depends on what the array contains
*/
-function random_element($array)
+if (! function_exists('random_element'))
{
- if ( ! is_array($array))
+ function random_element($array)
{
- return $array;
- }
- return $array[array_rand($array)];
+ if ( ! is_array($array))
+ {
+ return $array;
+ }
+ return $array[array_rand($array)];
+ }
}
-
?>
\ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 2a4a963dd..102057f8c 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -42,52 +42,55 @@ * @param string the cookie prefix
* @return void
*/
-function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '')
+if (! function_exists('set_cookie'))
{
- if (is_array($name))
- {
- foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
- {
- if (isset($name[$item]))
+ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '')
+ {
+ if (is_array($name))
+ {
+ foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
{
- $$item = $name[$item];
+ if (isset($name[$item]))
+ {
+ $$item = $name[$item];
+ }
}
}
- }
- // Set the config file options
- $CI =& get_instance();
+ // 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 ($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)
+ if ( ! is_numeric($expire))
{
- $expire = time() + $expire;
+ $expire = time() - 86500;
}
else
{
- $expire = 0;
+ if ($expire > 0)
+ {
+ $expire = time() + $expire;
+ }
+ else
+ {
+ $expire = 0;
+ }
}
- }
- setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
+ setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
+ }
}
// --------------------------------------------------------------------
@@ -100,10 +103,13 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = * @param bool
* @return mixed
*/
-function get_cookie($index = '', $xss_clean = FALSE)
+if (! function_exists('get_cookie'))
{
- $CI =& get_instance();
- return $CI->input->cookie($index, $xss_clean);
+ function get_cookie($index = '', $xss_clean = FALSE)
+ {
+ $CI =& get_instance();
+ return $CI->input->cookie($index, $xss_clean);
+ }
}
// --------------------------------------------------------------------
@@ -117,10 +123,12 @@ function get_cookie($index = '', $xss_clean = FALSE) * @param string the cookie prefix
* @return void
*/
-function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
+if (! function_exists('delete_cookie'))
{
- set_cookie($name, '', '', $domain, $path, $prefix);
+ function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
+ {
+ set_cookie($name, '', '', $domain, $path, $prefix);
+ }
}
-
?>
\ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 9f4c66b4e..24e0b1794 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -35,26 +35,29 @@ * @access public
* @return integer
*/
-function now()
+if (! function_exists('now'))
{
- $CI =& get_instance();
-
- if (strtolower($CI->config->item('time_reference')) == 'gmt')
+ function now()
{
- $now = time();
- $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
+ $CI =& get_instance();
- if (strlen($system_time) < 10)
+ if (strtolower($CI->config->item('time_reference')) == 'gmt')
{
- $system_time = time();
- log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.');
- }
+ $now = time();
+ $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
- return $system_time;
- }
- else
- {
- return time();
+ 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
+ {
+ return time();
+ }
}
}
@@ -77,16 +80,19 @@ function now() * @param integer
* @return integer
*/
-function mdate($datestr = '', $time = '')
+if (! function_exists('mdate'))
{
- if ($datestr == '')
- return '';
+ function mdate($datestr = '', $time = '')
+ {
+ if ($datestr == '')
+ return '';
- if ($time == '')
- $time = now();
+ if ($time == '')
+ $time = now();
- $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr));
- return date($datestr, $time);
+ $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr));
+ return date($datestr, $time);
+ }
}
// ------------------------------------------------------------------------
@@ -101,28 +107,30 @@ function mdate($datestr = '', $time = '') * @param integer Unix timestamp
* @return string
*/
-function standard_date($fmt = 'DATE_RFC822', $time = '')
+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_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',
- 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O',
- 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O',
- 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q'
- );
-
- if ( ! isset($formats[$fmt]))
+ function standard_date($fmt = 'DATE_RFC822', $time = '')
{
- return FALSE;
- }
+ $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_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',
+ 'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O',
+ 'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O',
+ 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q'
+ );
+
+ if ( ! isset($formats[$fmt]))
+ {
+ return FALSE;
+ }
- return mdate($formats[$fmt], $time);
+ return mdate($formats[$fmt], $time);
+ }
}
-
// ------------------------------------------------------------------------
@@ -137,105 +145,108 @@ function standard_date($fmt = 'DATE_RFC822', $time = '') * @param integer Unix timestamp
* @return integer
*/
-function timespan($seconds = 1, $time = '')
+if (! function_exists('timespan'))
{
- $CI =& get_instance();
- $CI->lang->load('date');
-
- if ( ! is_numeric($seconds))
+ function timespan($seconds = 1, $time = '')
{
- $seconds = 1;
- }
+ $CI =& get_instance();
+ $CI->lang->load('date');
+
+ if ( ! is_numeric($seconds))
+ {
+ $seconds = 1;
+ }
- if ( ! is_numeric($time))
- {
- $time = time();
- }
+ if ( ! is_numeric($time))
+ {
+ $time = time();
+ }
- if ($time <= $seconds)
- {
- $seconds = 1;
- }
- else
- {
- $seconds = $time - $seconds;
- }
+ if ($time <= $seconds)
+ {
+ $seconds = 1;
+ }
+ else
+ {
+ $seconds = $time - $seconds;
+ }
- $str = '';
- $years = floor($seconds / 31536000);
-
- if ($years > 0)
- {
- $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', ';
- }
+ $str = '';
+ $years = floor($seconds / 31536000);
- $seconds -= $years * 31536000;
- $months = floor($seconds / 2628000);
-
- if ($years > 0 OR $months > 0)
- {
- if ($months > 0)
+ if ($years > 0)
{
- $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', ';
+ $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', ';
}
- $seconds -= $months * 2628000;
- }
-
- $weeks = floor($seconds / 604800);
+ $seconds -= $years * 31536000;
+ $months = floor($seconds / 2628000);
- if ($years > 0 OR $months > 0 OR $weeks > 0)
- {
- if ($weeks > 0)
- {
- $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', ';
+ 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;
- }
+ $seconds -= $weeks * 604800;
+ }
- $days = floor($seconds / 86400);
+ $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')).', ';
- }
+ 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;
- }
+ $seconds -= $days * 86400;
+ }
- $hours = floor($seconds / 3600);
+ $hours = floor($seconds / 3600);
- if ($days > 0 OR $hours > 0)
- {
- if ($hours > 0)
+ if ($days > 0 OR $hours > 0)
{
- $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', ';
- }
+ if ($hours > 0)
+ {
+ $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', ';
+ }
- $seconds -= $hours * 3600;
- }
+ $seconds -= $hours * 3600;
+ }
- $minutes = floor($seconds / 60);
+ $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')).', ';
- }
+ 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;
- }
+ $seconds -= $minutes * 60;
+ }
- if ($str == '')
- {
- $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', ';
- }
+ if ($str == '')
+ {
+ $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', ';
+ }
- return substr(trim($str), 0, -1);
+ return substr(trim($str), 0, -1);
+ }
}
// ------------------------------------------------------------------------
@@ -251,28 +262,31 @@ function timespan($seconds = 1, $time = '') * @param integer a numeric year
* @return integer
*/
-function days_in_month($month = 0, $year = '')
+if (! function_exists('days_in_month'))
{
- if ($month < 1 OR $month > 12)
+ function days_in_month($month = 0, $year = '')
{
- return 0;
- }
+ if ($month < 1 OR $month > 12)
+ {
+ return 0;
+ }
- if ( ! is_numeric($year) OR strlen($year) != 4)
- {
- $year = date('Y');
- }
+ 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))
+ if ($month == 2)
{
- return 29;
+ if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0))
+ {
+ return 29;
+ }
}
- }
- $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
- return $days_in_month[$month - 1];
+ $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+ return $days_in_month[$month - 1];
+ }
}
// ------------------------------------------------------------------------
@@ -284,12 +298,15 @@ function days_in_month($month = 0, $year = '') * @param integer Unix timestamp
* @return integer
*/
-function local_to_gmt($time = '')
+if (! function_exists('local_to_gmt'))
{
- if ($time == '')
- $time = time();
+ 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));
+ return mktime( gmdate("H", $time), gmdate("i", $time), gmdate("s", $time), gmdate("m", $time), gmdate("d", $time), gmdate("Y", $time));
+ }
}
// ------------------------------------------------------------------------
@@ -307,21 +324,24 @@ function local_to_gmt($time = '') * @param bool whether DST is active
* @return integer
*/
-function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
-{
- if ($time == '')
- {
- return now();
- }
+if (! function_exists('gmt_to_local'))
+{
+ function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE)
+ {
+ if ($time == '')
+ {
+ return now();
+ }
- $time += timezones($timezone) * 3600;
+ $time += timezones($timezone) * 3600;
- if ($dst == TRUE)
- {
- $time += 3600;
- }
+ if ($dst == TRUE)
+ {
+ $time += 3600;
+ }
- return $time;
+ return $time;
+ }
}
// ------------------------------------------------------------------------
@@ -333,25 +353,28 @@ function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) * @param integer Unix timestamp
* @return integer
*/
-function mysql_to_unix($time = '')
+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),
- substr($time, 10, 2),
- substr($time, 12, 2),
- substr($time, 4, 2),
- substr($time, 6, 2),
- substr($time, 0, 4)
- );
+ function mysql_to_unix($time = '')
+ {
+ // 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),
+ substr($time, 10, 2),
+ substr($time, 12, 2),
+ substr($time, 4, 2),
+ substr($time, 6, 2),
+ substr($time, 0, 4)
+ );
+ }
}
// ------------------------------------------------------------------------
@@ -367,30 +390,33 @@ function mysql_to_unix($time = '') * @param string format: us or euro
* @return string
*/
-function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
+if (! function_exists('unix_to_human'))
{
- $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' ';
-
- if ($fmt == 'us')
+ function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us')
{
- $r .= date('h', $time).':'.date('i', $time);
- }
- else
- {
- $r .= date('H', $time).':'.date('i', $time);
- }
+ $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' ';
+
+ if ($fmt == 'us')
+ {
+ $r .= date('h', $time).':'.date('i', $time);
+ }
+ else
+ {
+ $r .= date('H', $time).':'.date('i', $time);
+ }
- if ($seconds)
- {
- $r .= ':'.date('s', $time);
- }
+ if ($seconds)
+ {
+ $r .= ':'.date('s', $time);
+ }
- if ($fmt == 'us')
- {
- $r .= ' '.date('A', $time);
- }
+ if ($fmt == 'us')
+ {
+ $r .= ' '.date('A', $time);
+ }
- return $r;
+ return $r;
+ }
}
// ------------------------------------------------------------------------
@@ -404,59 +430,62 @@ function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') * @param string format: us or euro
* @return integer
*/
-function human_to_unix($datestr = '')
+if (! function_exists('human_to_unix'))
{
- if ($datestr == '')
+ function human_to_unix($datestr = '')
{
- return FALSE;
- }
+ if ($datestr == '')
+ {
+ return FALSE;
+ }
- $datestr = trim($datestr);
- $datestr = preg_replace("/\040+/", "\040", $datestr);
+ $datestr = trim($datestr);
+ $datestr = preg_replace("/\040+/", "\040", $datestr);
- if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr))
- {
- return FALSE;
- }
+ if ( ! ereg("^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\040[0-9]{1,2}:[0-9]{1,2}.*$", $datestr))
+ {
+ return FALSE;
+ }
- $split = preg_split("/\040/", $datestr);
+ $split = preg_split("/\040/", $datestr);
- $ex = explode("-", $split['0']);
+ $ex = explode("-", $split['0']);
- $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0'];
- $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
- $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
+ $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0'];
+ $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
+ $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
- $ex = explode(":", $split['1']);
+ $ex = explode(":", $split['1']);
- $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0'];
- $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
+ $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0'];
+ $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1'];
- if (isset($ex['2']) AND ereg("[0-9]{1,2}", $ex['2']))
- {
- $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
- }
- else
- {
- // Unless specified, seconds get set to zero.
- $sec = '00';
- }
+ if (isset($ex['2']) AND ereg("[0-9]{1,2}", $ex['2']))
+ {
+ $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2'];
+ }
+ else
+ {
+ // Unless specified, seconds get set to zero.
+ $sec = '00';
+ }
- if (isset($split['2']))
- {
- $ampm = strtolower($split['2']);
+ 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) == 'p' AND $hour < 12)
+ $hour = $hour + 12;
- if (substr($ampm, 0, 1) == 'a' AND $hour == 12)
- $hour = '00';
+ if (substr($ampm, 0, 1) == 'a' AND $hour == 12)
+ $hour = '00';
- if (strlen($hour) == 1)
- $hour = '0'.$hour;
- }
+ if (strlen($hour) == 1)
+ $hour = '0'.$hour;
+ }
- return mktime($hour, $min, $sec, $month, $day, $year);
+ return mktime($hour, $min, $sec, $month, $day, $year);
+ }
}
// ------------------------------------------------------------------------
@@ -472,32 +501,35 @@ function human_to_unix($datestr = '') * @param string menu name
* @return string
*/
-function timezone_menu($default = 'UTC', $class = "", $name = 'timezones')
+if (! function_exists('timezone_menu'))
{
- $CI =& get_instance();
- $CI->lang->load('date');
+ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones')
+ {
+ $CI =& get_instance();
+ $CI->lang->load('date');
- if ($default == 'GMT')
- $default = 'UTC';
+ if ($default == 'GMT')
+ $default = 'UTC';
- $menu = '<select name="'.$name.'"';
+ $menu = '<select name="'.$name.'"';
- if ($class != '')
- {
- $menu .= ' class="'.$class.'"';
- }
+ if ($class != '')
+ {
+ $menu .= ' class="'.$class.'"';
+ }
- $menu .= ">\n";
+ $menu .= ">\n";
- foreach (timezones() as $key => $val)
- {
- $selected = ($default == $key) ? " selected='selected'" : '';
- $menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n";
- }
+ foreach (timezones() as $key => $val)
+ {
+ $selected = ($default == $key) ? " selected='selected'" : '';
+ $menu .= "<option value='{$key}'{$selected}>".$CI->lang->line($key)."</option>\n";
+ }
- $menu .= "</select>";
+ $menu .= "</select>";
- return $menu;
+ return $menu;
+ }
}
// ------------------------------------------------------------------------
@@ -512,54 +544,56 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') * @param string timezone
* @return string
*/
-function timezones($tz = '')
+if (! function_exists('timezones'))
{
- // Note: Don't change the order of these even though
- // some items appear to be in the wrong order
+ function timezones($tz = '')
+ {
+ // Note: Don't change the order of these even though
+ // some items appear to be in the wrong order
- $zones = array(
- 'UM12' => -12,
- 'UM11' => -11,
- 'UM10' => -10,
- 'UM9' => -9,
- 'UM8' => -8,
- 'UM7' => -7,
- 'UM6' => -6,
- 'UM5' => -5,
- 'UM4' => -4,
- 'UM25' => -2.5,
- 'UM3' => -3,
- 'UM2' => -2,
- 'UM1' => -1,
- 'UTC' => 0,
- 'UP1' => +1,
- 'UP2' => +2,
- 'UP3' => +3,
- 'UP25' => +2.5,
- 'UP4' => +4,
- 'UP35' => +3.5,
- 'UP5' => +5,
- 'UP45' => +4.5,
- 'UP6' => +6,
- 'UP7' => +7,
- 'UP8' => +8,
- 'UP9' => +9,
- 'UP85' => +8.5,
- 'UP10' => +10,
- 'UP11' => +11,
- 'UP12' => +12
- );
+ $zones = array(
+ 'UM12' => -12,
+ 'UM11' => -11,
+ 'UM10' => -10,
+ 'UM9' => -9,
+ 'UM8' => -8,
+ 'UM7' => -7,
+ 'UM6' => -6,
+ 'UM5' => -5,
+ 'UM4' => -4,
+ 'UM25' => -2.5,
+ 'UM3' => -3,
+ 'UM2' => -2,
+ 'UM1' => -1,
+ 'UTC' => 0,
+ 'UP1' => +1,
+ 'UP2' => +2,
+ 'UP3' => +3,
+ 'UP25' => +2.5,
+ 'UP4' => +4,
+ 'UP35' => +3.5,
+ 'UP5' => +5,
+ 'UP45' => +4.5,
+ 'UP6' => +6,
+ 'UP7' => +7,
+ 'UP8' => +8,
+ 'UP9' => +9,
+ 'UP85' => +8.5,
+ 'UP10' => +10,
+ 'UP11' => +11,
+ 'UP12' => +12
+ );
- if ($tz == '')
- {
- return $zones;
- }
+ if ($tz == '')
+ {
+ return $zones;
+ }
- if ($tz == 'GMT')
- $tz = 'UTC';
+ if ($tz == 'GMT')
+ $tz = 'UTC';
- return ( ! isset($zones[$tz])) ? 0 : $zones[$tz];
+ return ( ! isset($zones[$tz])) ? 0 : $zones[$tz];
+ }
}
-
?>
\ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 4a499de5c..5a23944cb 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -39,29 +39,31 @@ * @param bool whether to limit the result to the top level only
* @return array
*/
-function directory_map($source_dir, $top_level_only = FALSE)
-{
- if ($fp = @opendir($source_dir))
- {
- $filedata = array();
- while (FALSE !== ($file = readdir($fp)))
+if (! function_exists('directory_map'))
+{
+ function directory_map($source_dir, $top_level_only = FALSE)
+ {
+ if ($fp = @opendir($source_dir))
{
- if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
+ $filedata = array();
+ while (FALSE !== ($file = readdir($fp)))
{
- $temp_array = array();
+ if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE)
+ {
+ $temp_array = array();
- $temp_array = directory_map($source_dir.$file."/");
+ $temp_array = directory_map($source_dir.$file."/");
- $filedata[$file] = $temp_array;
- }
- elseif (substr($file, 0, 1) != ".")
- {
- $filedata[] = $file;
+ $filedata[$file] = $temp_array;
+ }
+ elseif (substr($file, 0, 1) != ".")
+ {
+ $filedata[] = $file;
+ }
}
+ return $filedata;
}
- return $filedata;
}
}
-
?>
\ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index e8bc2f7f6..2d0e737c9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -37,60 +37,62 @@ * @param mixed the data to be downloaded
* @return void
*/
-function force_download($filename = '', $data = '')
+if (! function_exists('force_download'))
{
- if ($filename == '' OR $data == '')
+ function force_download($filename = '', $data = '')
{
- return FALSE;
- }
+ if ($filename == '' OR $data == '')
+ {
+ return FALSE;
+ }
- // Try to determine if the filename includes a file extension.
- // We need it in order to set the MIME type
- if (FALSE === strpos($filename, '.'))
- {
- return FALSE;
- }
+ // Try to determine if the filename includes a file extension.
+ // We need it in order to set the MIME type
+ if (FALSE === strpos($filename, '.'))
+ {
+ return FALSE;
+ }
- // Grab the file extension
- $x = explode('.', $filename);
- $extension = end($x);
+ // Grab the file extension
+ $x = explode('.', $filename);
+ $extension = end($x);
- // Load the mime types
- @include(APPPATH.'config/mimes'.EXT);
+ // Load the mime types
+ @include(APPPATH.'config/mimes'.EXT);
- // Set a default mime if we can't find it
- if ( ! isset($mimes[$extension]))
- {
- $mime = 'application/octet-stream';
- }
- else
- {
- $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
- }
+ // Set a default mime if we can't find it
+ if ( ! isset($mimes[$extension]))
+ {
+ $mime = 'application/octet-stream';
+ }
+ else
+ {
+ $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
+ }
- // Generate the server headers
- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
- {
- header('Content-Type: "'.$mime.'"');
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header("Content-Transfer-Encoding: binary");
- header('Pragma: public');
- header("Content-Length: ".strlen($data));
- }
- else
- {
- header('Content-Type: "'.$mime.'"');
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
- header('Pragma: no-cache');
- header("Content-Length: ".strlen($data));
- }
+ // Generate the server headers
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
+ {
+ header('Content-Type: "'.$mime.'"');
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header("Content-Transfer-Encoding: binary");
+ header('Pragma: public');
+ header("Content-Length: ".strlen($data));
+ }
+ else
+ {
+ header('Content-Type: "'.$mime.'"');
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ header("Content-Length: ".strlen($data));
+ }
- echo $data;
+ echo $data;
+ }
}
-
?>
\ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index b44fae554..e677afd28 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -33,9 +33,12 @@ * @access public
* @return bool
*/
-function valid_email($address)
+if (! function_exists('valid_email'))
{
- return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
+ function valid_email($address)
+ {
+ return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
+ }
}
// ------------------------------------------------------------------------
@@ -46,9 +49,12 @@ function valid_email($address) * @access public
* @return bool
*/
-function send_email($recipient, $subject = 'Test email', $message = 'Hello World')
+if (! function_exists('send_email'))
{
- return mail($recipient, $subject, $message);
+ function send_email($recipient, $subject = 'Test email', $message = 'Hello World')
+ {
+ return mail($recipient, $subject, $message);
+ }
}
?>
\ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 868561b5a..bbf340930 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -36,35 +36,38 @@ * @param string path to file
* @return string
*/
-function read_file($file)
+if (! function_exists('read_file'))
{
- if ( ! file_exists($file))
+ function read_file($file)
{
- return FALSE;
- }
+ if ( ! file_exists($file))
+ {
+ return FALSE;
+ }
- if (function_exists('file_get_contents'))
- {
- return file_get_contents($file);
- }
+ if (function_exists('file_get_contents'))
+ {
+ return file_get_contents($file);
+ }
- if ( ! $fp = @fopen($file, 'rb'))
- {
- return FALSE;
- }
+ if ( ! $fp = @fopen($file, 'rb'))
+ {
+ return FALSE;
+ }
- flock($fp, LOCK_SH);
+ flock($fp, LOCK_SH);
- $data = '';
- if (filesize($file) > 0)
- {
- $data =& fread($fp, filesize($file));
- }
+ $data = '';
+ if (filesize($file) > 0)
+ {
+ $data =& fread($fp, filesize($file));
+ }
- flock($fp, LOCK_UN);
- fclose($fp);
+ flock($fp, LOCK_UN);
+ fclose($fp);
- return $data;
+ return $data;
+ }
}
// ------------------------------------------------------------------------
@@ -80,19 +83,22 @@ function read_file($file) * @param string file data
* @return bool
*/
-function write_file($path, $data, $mode = 'wb')
+if (! function_exists('write_file'))
{
- if ( ! $fp = @fopen($path, $mode))
+ function write_file($path, $data, $mode = 'wb')
{
- return FALSE;
- }
+ if ( ! $fp = @fopen($path, $mode))
+ {
+ return FALSE;
+ }
- flock($fp, LOCK_EX);
- fwrite($fp, $data);
- flock($fp, LOCK_UN);
- fclose($fp);
+ flock($fp, LOCK_EX);
+ fwrite($fp, $data);
+ flock($fp, LOCK_UN);
+ fclose($fp);
- return TRUE;
+ return TRUE;
+ }
}
// ------------------------------------------------------------------------
@@ -110,34 +116,37 @@ function write_file($path, $data, $mode = 'wb') * @param bool whether to delete any directories found in the path
* @return bool
*/
-function delete_files($path, $del_dir = FALSE, $level = 0)
-{
- // Trim the trailing slash
- $path = preg_replace("|^(.+?)/*$|", "\\1", $path);
+if (! function_exists('delete_files'))
+{
+ function delete_files($path, $del_dir = FALSE, $level = 0)
+ {
+ // Trim the trailing slash
+ $path = preg_replace("|^(.+?)/*$|", "\\1", $path);
- if ( ! $current_dir = @opendir($path))
- return;
+ if ( ! $current_dir = @opendir($path))
+ return;
- while(FALSE !== ($filename = @readdir($current_dir)))
- {
- if ($filename != "." and $filename != "..")
+ while(FALSE !== ($filename = @readdir($current_dir)))
{
- if (is_dir($path.'/'.$filename))
- {
- $level++;
- delete_files($path.'/'.$filename, $del_dir, $level);
- }
- else
+ if ($filename != "." and $filename != "..")
{
- unlink($path.'/'.$filename);
+ if (is_dir($path.'/'.$filename))
+ {
+ $level++;
+ delete_files($path.'/'.$filename, $del_dir, $level);
+ }
+ else
+ {
+ unlink($path.'/'.$filename);
+ }
}
}
- }
- @closedir($current_dir);
+ @closedir($current_dir);
- if ($del_dir == TRUE AND $level > 0)
- {
- @rmdir($path);
+ if ($del_dir == TRUE AND $level > 0)
+ {
+ @rmdir($path);
+ }
}
}
@@ -154,25 +163,28 @@ function delete_files($path, $del_dir = FALSE, $level = 0) * @param bool whether to include the path as part of the filename
* @return array
*/
-function get_filenames($source_dir, $include_path = FALSE)
+if (! function_exists('get_filenames'))
{
- $_filedata = array();
-
- if ($fp = @opendir($source_dir))
+ function get_filenames($source_dir, $include_path = FALSE)
{
- while (FALSE !== ($file = readdir($fp)))
+ $_filedata = array();
+
+ if ($fp = @opendir($source_dir))
{
- if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.')
- {
- get_filenames($source_dir.$file."/", $include_path);
- }
- elseif (substr($file, 0, 1) != ".")
+ while (FALSE !== ($file = readdir($fp)))
{
+ if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.')
+ {
+ get_filenames($source_dir.$file."/", $include_path);
+ }
+ elseif (substr($file, 0, 1) != ".")
+ {
- $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
+ $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
+ }
}
+ return $_filedata;
}
- return $_filedata;
}
}
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a2bc2002e..7c3b16ff1 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -38,35 +38,38 @@ * @param array a key/value pair hidden data
* @return string
*/
-function form_open($action = '', $attributes = array(), $hidden = array())
+if (! function_exists('form_open'))
{
- $CI =& get_instance();
+ function form_open($action = '', $attributes = array(), $hidden = array())
+ {
+ $CI =& get_instance();
- $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action;
+ $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action;
- $form = '<form action="'.$action.'"';
+ $form = '<form action="'.$action.'"';
- if ( ! isset($attributes['method']))
- {
- $form .= ' method="post"';
- }
+ if ( ! isset($attributes['method']))
+ {
+ $form .= ' method="post"';
+ }
- if (is_array($attributes) AND count($attributes) > 0)
- {
- foreach ($attributes as $key => $val)
+ if (is_array($attributes) AND count($attributes) > 0)
{
- $form .= ' '.$key.'="'.$val.'"';
+ foreach ($attributes as $key => $val)
+ {
+ $form .= ' '.$key.'="'.$val.'"';
+ }
}
- }
- $form .= '>';
+ $form .= '>';
- if (is_array($hidden) AND count($hidden > 0))
- {
- $form .= form_hidden($hidden);
- }
+ if (is_array($hidden) AND count($hidden > 0))
+ {
+ $form .= form_hidden($hidden);
+ }
- return $form;
+ return $form;
+ }
}
// ------------------------------------------------------------------------
@@ -82,10 +85,13 @@ function form_open($action = '', $attributes = array(), $hidden = array()) * @param array a key/value pair hidden data
* @return string
*/
-function form_open_multipart($action, $attributes = array(), $hidden = array())
+if (! function_exists('form_open_multipart'))
{
- $attributes['enctype'] = 'multipart/form-data';
- return form_open($action, $attributes, $hidden);
+ function form_open_multipart($action, $attributes = array(), $hidden = array())
+ {
+ $attributes['enctype'] = 'multipart/form-data';
+ return form_open($action, $attributes, $hidden);
+ }
}
// ------------------------------------------------------------------------
@@ -101,20 +107,23 @@ function form_open_multipart($action, $attributes = array(), $hidden = array()) * @param string
* @return string
*/
-function form_hidden($name, $value = '')
+if (! function_exists('form_hidden'))
{
- if ( ! is_array($name))
+ function form_hidden($name, $value = '')
{
- return '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />';
- }
+ if ( ! is_array($name))
+ {
+ return '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />';
+ }
- $form = '';
- foreach ($name as $name => $value)
- {
- $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />';
- }
+ $form = '';
+ foreach ($name as $name => $value)
+ {
+ $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />';
+ }
- return $form;
+ return $form;
+ }
}
// ------------------------------------------------------------------------
@@ -128,11 +137,14 @@ function form_hidden($name, $value = '') * @param string
* @return string
*/
-function form_input($data = '', $value = '', $extra = '')
+if (! function_exists('form_input'))
{
- $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50');
+ function form_input($data = '', $value = '', $extra = '')
+ {
+ $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50');
- return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ }
}
// ------------------------------------------------------------------------
@@ -148,15 +160,18 @@ function form_input($data = '', $value = '', $extra = '') * @param string
* @return string
*/
-function form_password($data = '', $value = '', $extra = '')
+if (! function_exists('form_password'))
{
- if ( ! is_array($data))
+ function form_password($data = '', $value = '', $extra = '')
{
- $data = array('name' => $data);
- }
+ if ( ! is_array($data))
+ {
+ $data = array('name' => $data);
+ }
- $data['type'] = 'password';
- return form_input($data, $value, $extra);
+ $data['type'] = 'password';
+ return form_input($data, $value, $extra);
+ }
}
// ------------------------------------------------------------------------
@@ -172,15 +187,18 @@ function form_password($data = '', $value = '', $extra = '') * @param string
* @return string
*/
-function form_upload($data = '', $value = '', $extra = '')
+if (! function_exists('form_upload'))
{
- if ( ! is_array($data))
+ function form_upload($data = '', $value = '', $extra = '')
{
- $data = array('name' => $data);
- }
+ if ( ! is_array($data))
+ {
+ $data = array('name' => $data);
+ }
- $data['type'] = 'file';
- return form_input($data, $value, $extra);
+ $data['type'] = 'file';
+ return form_input($data, $value, $extra);
+ }
}
// ------------------------------------------------------------------------
@@ -194,21 +212,24 @@ function form_upload($data = '', $value = '', $extra = '') * @param string
* @return string
*/
-function form_textarea($data = '', $value = '', $extra = '')
+if (! function_exists('form_textarea'))
{
- $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12');
-
- if ( ! is_array($data) OR ! isset($data['value']))
- {
- $val = $value;
- }
- else
+ function form_textarea($data = '', $value = '', $extra = '')
{
- $val = $data['value'];
- unset($data['value']); // textareas don't use the value attribute
- }
+ $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12');
+
+ if ( ! is_array($data) OR ! isset($data['value']))
+ {
+ $val = $value;
+ }
+ else
+ {
+ $val = $data['value'];
+ unset($data['value']); // textareas don't use the value attribute
+ }
- return "<textarea ".parse_form_attributes($data, $defaults).$extra.">".$val."</textarea>\n";
+ return "<textarea ".parse_form_attributes($data, $defaults).$extra.">".$val."</textarea>\n";
+ }
}
// ------------------------------------------------------------------------
@@ -223,32 +244,35 @@ function form_textarea($data = '', $value = '', $extra = '') * @param string
* @return string
*/
-function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
+if (! function_exists('form_dropdown'))
{
- if ( ! is_array($selected))
+ function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
{
- $selected = array($selected);
- }
+ if ( ! is_array($selected))
+ {
+ $selected = array($selected);
+ }
- if ($extra != '') $extra = ' '.$extra;
+ if ($extra != '') $extra = ' '.$extra;
- $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
+ $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
- $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
+ $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
- foreach ($options as $key => $val)
- {
- $key = (string) $key;
- $val = (string) $val;
+ foreach ($options as $key => $val)
+ {
+ $key = (string) $key;
+ $val = (string) $val;
- $sel = (in_array($key, $selected))?' selected="selected"':'';
+ $sel = (in_array($key, $selected))?' selected="selected"':'';
- $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
- }
+ $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
+ }
- $form .= '</select>';
+ $form .= '</select>';
- return $form;
+ return $form;
+ }
}
// ------------------------------------------------------------------------
@@ -263,30 +287,33 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext * @param string
* @return string
*/
-function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '')
+if (! function_exists('form_checkbox'))
{
- $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
-
- if (is_array($data) AND array_key_exists('checked', $data))
+ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '')
{
- $checked = $data['checked'];
-
- if ($checked == FALSE)
- {
- unset($data['checked']);
- }
- else
+ $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
+
+ if (is_array($data) AND array_key_exists('checked', $data))
{
- $data['checked'] = 'checked';
+ $checked = $data['checked'];
+
+ if ($checked == FALSE)
+ {
+ unset($data['checked']);
+ }
+ else
+ {
+ $data['checked'] = 'checked';
+ }
}
- }
- if ($checked == TRUE)
- $defaults['checked'] = 'checked';
- else
- unset($defaults['checked']);
+ if ($checked == TRUE)
+ $defaults['checked'] = 'checked';
+ else
+ unset($defaults['checked']);
- return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ }
}
// ------------------------------------------------------------------------
@@ -301,15 +328,18 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') * @param string
* @return string
*/
-function form_radio($data = '', $value = '', $checked = TRUE, $extra = '')
+if (! function_exists('form_radio'))
{
- if ( ! is_array($data))
- {
- $data = array('name' => $data);
- }
+ function form_radio($data = '', $value = '', $checked = TRUE, $extra = '')
+ {
+ if ( ! is_array($data))
+ {
+ $data = array('name' => $data);
+ }
- $data['type'] = 'radio';
- return form_checkbox($data, $value, $checked, $extra);
+ $data['type'] = 'radio';
+ return form_checkbox($data, $value, $checked, $extra);
+ }
}
// ------------------------------------------------------------------------
@@ -322,12 +352,15 @@ function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') * @param string
* @param string
* @return string
- */
-function form_submit($data = '', $value = '', $extra = '')
-{
- $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
+ */
+if (! function_exists('form_submit'))
+{
+ function form_submit($data = '', $value = '', $extra = '')
+ {
+ $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
- return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ }
}
// ------------------------------------------------------------------------
@@ -341,11 +374,14 @@ function form_submit($data = '', $value = '', $extra = '') * @param string
* @return string
*/
-function form_reset($data = '', $value = '', $extra = '')
+if (! function_exists('form_reset'))
{
- $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
+ function form_reset($data = '', $value = '', $extra = '')
+ {
+ $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
- return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
+ }
}
// ------------------------------------------------------------------------
@@ -359,27 +395,30 @@ function form_reset($data = '', $value = '', $extra = '') * @param string Additional attributes
* @return string
*/
-function form_label($label_text = '', $id = '', $attributes = array())
+if (! function_exists('form_label'))
{
+ function form_label($label_text = '', $id = '', $attributes = array())
+ {
- $label = '<label';
+ $label = '<label';
- if ($id != '')
- {
- $label .= " for=\"$id\"";
- }
+ if ($id != '')
+ {
+ $label .= " for=\"$id\"";
+ }
- if (is_array($attributes) AND count($attributes) > 0)
- {
- foreach ($attributes as $key => $val)
+ if (is_array($attributes) AND count($attributes) > 0)
{
- $label .= ' '.$key.'="'.$val.'"';
+ foreach ($attributes as $key => $val)
+ {
+ $label .= ' '.$key.'="'.$val.'"';
+ }
}
- }
- $label .= ">$label_text</label>";
+ $label .= ">$label_text</label>";
- return $label;
+ return $label;
+ }
}
// ------------------------------------------------------------------------
@@ -394,29 +433,32 @@ function form_label($label_text = '', $id = '', $attributes = array()) * @param string Additional attributes
* @return string
*/
-function form_fieldset($legend_text = '', $attributes = array())
+if (! function_exists('form_fieldset'))
{
+ function form_fieldset($legend_text = '', $attributes = array())
+ {
- $fieldset = "<fieldset";
+ $fieldset = "<fieldset";
- if (is_array($attributes) AND count($attributes) > 0)
- {
- foreach ($attributes as $key => $val)
+ if (is_array($attributes) AND count($attributes) > 0)
{
- $fieldset .= ' '.$key.'="'.$val.'"';
+ foreach ($attributes as $key => $val)
+ {
+ $fieldset .= ' '.$key.'="'.$val.'"';
+ }
}
- }
- $fieldset .= ">\n";
+ $fieldset .= ">\n";
- if ($legend_text != '')
- {
- $fieldset .= "<legend>$legend_text</legend>\n";
- }
+ if ($legend_text != '')
+ {
+ $fieldset .= "<legend>$legend_text</legend>\n";
+ }
- return $fieldset;
+ return $fieldset;
+ }
}
// ------------------------------------------------------------------------
@@ -428,9 +470,12 @@ function form_fieldset($legend_text = '', $attributes = array()) * @param string
* @return string
*/
-function form_fieldset_close($extra = '')
+if (! function_exists('form_fieldset_close'))
{
- return "</fieldset>\n".$extra;
+ function form_fieldset_close($extra = '')
+ {
+ return "</fieldset>\n".$extra;
+ }
}
// ------------------------------------------------------------------------
@@ -442,9 +487,12 @@ function form_fieldset_close($extra = '') * @param string
* @return string
*/
-function form_close($extra = '')
+if (! function_exists('form_close'))
{
- return "</form>\n".$extra;
+ function form_close($extra = '')
+ {
+ return "</form>\n".$extra;
+ }
}
// ------------------------------------------------------------------------
@@ -458,30 +506,33 @@ function form_close($extra = '') * @param string
* @return string
*/
-function form_prep($str = '')
+if (! function_exists('form_prep'))
{
- if ($str === '')
+ function form_prep($str = '')
{
- return '';
- }
+ if ($str === '')
+ {
+ return '';
+ }
- $temp = '__TEMP_AMPERSANDS__';
+ $temp = '__TEMP_AMPERSANDS__';
- // Replace entities to temporary markers so that
- // htmlspecialchars won't mess them up
- $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
- $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
+ // Replace entities to temporary markers so that
+ // htmlspecialchars won't mess them up
+ $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
+ $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
- $str = htmlspecialchars($str);
+ $str = htmlspecialchars($str);
- // In case htmlspecialchars misses these.
- $str = str_replace(array("'", '"'), array("'", """), $str);
+ // In case htmlspecialchars misses these.
+ $str = str_replace(array("'", '"'), array("'", """), $str);
- // Decode the temp markers back to entities
- $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
- $str = preg_replace("/$temp(\w+);/","&\\1;",$str);
+ // Decode the temp markers back to entities
+ $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
+ $str = preg_replace("/$temp(\w+);/","&\\1;",$str);
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -496,37 +547,40 @@ function form_prep($str = '') * @param array
* @return string
*/
-function parse_form_attributes($attributes, $default)
+if (! function_exists('parse_form_attributes'))
{
- if (is_array($attributes))
+ function parse_form_attributes($attributes, $default)
{
- foreach ($default as $key => $val)
+ if (is_array($attributes))
{
- if (isset($attributes[$key]))
+ foreach ($default as $key => $val)
{
- $default[$key] = $attributes[$key];
- unset($attributes[$key]);
+ if (isset($attributes[$key]))
+ {
+ $default[$key] = $attributes[$key];
+ unset($attributes[$key]);
+ }
}
- }
- if (count($attributes) > 0)
- {
- $default = array_merge($default, $attributes);
+ if (count($attributes) > 0)
+ {
+ $default = array_merge($default, $attributes);
+ }
}
- }
- $att = '';
- foreach ($default as $key => $val)
- {
- if ($key == 'value')
+ $att = '';
+ foreach ($default as $key => $val)
{
- $val = form_prep($val);
- }
+ if ($key == 'value')
+ {
+ $val = form_prep($val);
+ }
- $att .= $key . '="' . $val . '" ';
- }
+ $att .= $key . '="' . $val . '" ';
+ }
- return $att;
+ return $att;
+ }
}
?>
\ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index a11d23e15..56e25316c 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -38,9 +38,12 @@ * @param integer
* @return string
*/
-function heading($data = '', $h = '1')
+if (! function_exists('heading'))
{
- return "<h".$h.">".$data."</h".$h.">";
+ function heading($data = '', $h = '1')
+ {
+ return "<h".$h.">".$data."</h".$h.">";
+ }
}
// ------------------------------------------------------------------------
@@ -55,9 +58,12 @@ function heading($data = '', $h = '1') * @param mixed
* @return string
*/
-function ul($list, $attributes = '')
+if (! function_exists('ul'))
{
- return _list('ul', $list, $attributes);
+ function ul($list, $attributes = '')
+ {
+ return _list('ul', $list, $attributes);
+ }
}
// ------------------------------------------------------------------------
@@ -72,9 +78,12 @@ function ul($list, $attributes = '') * @param mixed
* @return string
*/
-function ol($list, $attributes = '')
+if (! function_exists('ol'))
{
- return _list('ol', $list, $attributes);
+ function ol($list, $attributes = '')
+ {
+ return _list('ol', $list, $attributes);
+ }
}
// ------------------------------------------------------------------------
@@ -91,63 +100,66 @@ function ol($list, $attributes = '') * @param intiger
* @return string
*/
-function _list($type = 'ul', $list, $attributes = '', $depth = 0)
+if (! function_exists('_list'))
{
- // If an array wasn't submitted there's nothing to do...
- if ( ! is_array($list))
+ function _list($type = 'ul', $list, $attributes = '', $depth = 0)
{
- return $list;
- }
+ // If an array wasn't submitted there's nothing to do...
+ if ( ! is_array($list))
+ {
+ return $list;
+ }
- // Set the indentation based on the depth
- $out = str_repeat(" ", $depth);
+ // Set the indentation based on the depth
+ $out = str_repeat(" ", $depth);
- // Were any attributes submitted? If so generate a string
- if (is_array($attributes))
- {
- $atts = '';
- foreach ($attributes as $key => $val)
+ // Were any attributes submitted? If so generate a string
+ if (is_array($attributes))
{
- $atts .= ' ' . $key . '="' . $val . '"';
+ $atts = '';
+ foreach ($attributes as $key => $val)
+ {
+ $atts .= ' ' . $key . '="' . $val . '"';
+ }
+ $attributes = $atts;
}
- $attributes = $atts;
- }
- // Write the opening list tag
- $out .= "<".$type.$attributes.">\n";
+ // Write the opening list tag
+ $out .= "<".$type.$attributes.">\n";
- // Cycle through the list elements. If an array is
- // encountered we will recursively call _list()
+ // Cycle through the list elements. If an array is
+ // encountered we will recursively call _list()
- static $_last_list_item = '';
- foreach ($list as $key => $val)
- {
- $_last_list_item = $key;
+ static $_last_list_item = '';
+ foreach ($list as $key => $val)
+ {
+ $_last_list_item = $key;
- $out .= str_repeat(" ", $depth + 2);
- $out .= "<li>";
-
- if ( ! is_array($val))
- {
- $out .= $val;
- }
- else
- {
- $out .= $_last_list_item."\n";
- $out .= _list($type, $val, '', $depth + 4);
$out .= str_repeat(" ", $depth + 2);
+ $out .= "<li>";
+
+ if ( ! is_array($val))
+ {
+ $out .= $val;
+ }
+ else
+ {
+ $out .= $_last_list_item."\n";
+ $out .= _list($type, $val, '', $depth + 4);
+ $out .= str_repeat(" ", $depth + 2);
+ }
+
+ $out .= "</li>\n";
}
- $out .= "</li>\n";
- }
-
- // Set the indentation for the closing tag
- $out .= str_repeat(" ", $depth);
+ // Set the indentation for the closing tag
+ $out .= str_repeat(" ", $depth);
- // Write the closing list tag
- $out .= "</".$type.">\n";
+ // Write the closing list tag
+ $out .= "</".$type.">\n";
- return $out;
+ return $out;
+ }
}
// ------------------------------------------------------------------------
@@ -159,9 +171,12 @@ function _list($type = 'ul', $list, $attributes = '', $depth = 0) * @param integer
* @return string
*/
-function br($num = 1)
+if (! function_exists('br'))
{
- return str_repeat("<br />", $num);
+ function br($num = 1)
+ {
+ return str_repeat("<br />", $num);
+ }
}
// ------------------------------------------------------------------------
@@ -173,9 +188,12 @@ function br($num = 1) * @param integer
* @return string
*/
-function nbs($num = 1)
+if (! function_exists('nbs'))
{
- return str_repeat(" ", $num);
+ function nbs($num = 1)
+ {
+ return str_repeat(" ", $num);
+ }
}
// ------------------------------------------------------------------------
@@ -187,18 +205,18 @@ function nbs($num = 1) * @param array
* @return string
*/
-function meta($meta = array(), $newline = "\n")
+if (! function_exists('meta'))
{
- $str = '';
- foreach ($meta as $key => $val)
+ function meta($meta = array(), $newline = "\n")
{
- $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
- }
+ $str = '';
+ foreach ($meta as $key => $val)
+ {
+ $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
+ }
- return $str;
+ return $str;
+ }
}
-
-
-
?>
\ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index b1864cb0b..bf70a6799 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -36,34 +36,36 @@ * @access public
* @param string
* @return str
- */
-function singular($str)
-{
- $str = strtolower(trim($str));
- $end = substr($str, -3);
+ */
+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';
- }
- elseif ($end == 'ses')
- {
- $str = substr($str, 0, strlen($str)-2);
- }
- else
- {
- $end = substr($str, -1);
+ if ($end == 'ies')
+ {
+ $str = substr($str, 0, strlen($str)-3).'y';
+ }
+ elseif ($end == 'ses')
+ {
+ $str = substr($str, 0, strlen($str)-2);
+ }
+ else
+ {
+ $end = substr($str, -1);
- if ($end == 's')
- {
- $str = substr($str, 0, strlen($str)-1);
- }
- }
+ if ($end == 's')
+ {
+ $str = substr($str, 0, strlen($str)-1);
+ }
+ }
- return $str;
+ return $str;
+ }
}
-
// --------------------------------------------------------------------
/**
@@ -75,32 +77,34 @@ function singular($str) * @param string
* @param bool
* @return str
- */
-function plural($str, $force = FALSE)
-{
- $str = strtolower(trim($str));
- $end = substr($str, -1);
-
- if ($end == 'y')
- {
- $str = substr($str, 0, strlen($str)-1).'ies';
- }
- elseif ($end == 's')
- {
- if ($force == TRUE)
- {
- $str .= 'es';
- }
- }
- else
- {
- $str .= 's';
- }
-
- return $str;
+ */
+if (! function_exists('plural'))
+{
+ function plural($str, $force = FALSE)
+ {
+ $str = strtolower(trim($str));
+ $end = substr($str, -1);
+
+ if ($end == 'y')
+ {
+ $str = substr($str, 0, strlen($str)-1).'ies';
+ }
+ elseif ($end == 's')
+ {
+ if ($force == TRUE)
+ {
+ $str .= 'es';
+ }
+ }
+ else
+ {
+ $str .= 's';
+ }
+
+ return $str;
+ }
}
-
// --------------------------------------------------------------------
/**
@@ -111,12 +115,15 @@ function plural($str, $force = FALSE) * @access public
* @param string
* @return str
- */
-function camelize($str)
-{
- $str = 'x'.strtolower(trim($str));
- $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
- return substr(str_replace(' ', '', $str), 1);
+ */
+if (! function_exists('camelize'))
+{
+ function camelize($str)
+ {
+ $str = 'x'.strtolower(trim($str));
+ $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
+ return substr(str_replace(' ', '', $str), 1);
+ }
}
// --------------------------------------------------------------------
@@ -129,10 +136,13 @@ function camelize($str) * @access public
* @param string
* @return str
- */
-function underscore($str)
+ */
+if (! function_exists('underscore'))
{
- return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
+ function underscore($str)
+ {
+ return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
+ }
}
// --------------------------------------------------------------------
@@ -145,10 +155,13 @@ function underscore($str) * @access public
* @param string
* @return str
- */
-function humanize($str)
-{
- return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
+ */
+if (! function_exists('humanize'))
+{
+ function humanize($str)
+ {
+ return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
+ }
}
?>
\ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 97c9a6ba6..7552fd89c 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -35,10 +35,13 @@ * @param string the character set of your data
* @return string
*/
-function xss_clean($str, $charset = 'ISO-8859-1')
+if (! function_exists('xss_clean'))
{
- $CI =& get_instance();
- return $CI->input->xss_clean($str, $charset);
+ function xss_clean($str, $charset = 'ISO-8859-1')
+ {
+ $CI =& get_instance();
+ return $CI->input->xss_clean($str, $charset);
+ }
}
// --------------------------------------------------------------------
@@ -49,32 +52,35 @@ function xss_clean($str, $charset = 'ISO-8859-1') * @access public
* @param string
* @return string
- */
-function dohash($str, $type = 'sha1')
-{
- if ($type == 'sha1')
+ */
+if (! function_exists('dohash'))
+{
+ function dohash($str, $type = 'sha1')
{
- if ( ! function_exists('sha1'))
+ if ($type == 'sha1')
{
- if ( ! function_exists('mhash'))
- {
- require_once(BASEPATH.'libraries/Sha1'.EXT);
- $SH = new CI_SHA;
- return $SH->generate($str);
+ if ( ! function_exists('sha1'))
+ {
+ if ( ! function_exists('mhash'))
+ {
+ require_once(BASEPATH.'libraries/Sha1'.EXT);
+ $SH = new CI_SHA;
+ return $SH->generate($str);
+ }
+ else
+ {
+ return bin2hex(mhash(MHASH_SHA1, $str));
+ }
}
else
{
- return bin2hex(mhash(MHASH_SHA1, $str));
- }
+ return sha1($str);
+ }
}
else
{
- return sha1($str);
- }
- }
- else
- {
- return md5($str);
+ return md5($str);
+ }
}
}
@@ -87,12 +93,15 @@ function dohash($str, $type = 'sha1') * @param string
* @return string
*/
-function strip_image_tags($str)
+if (! function_exists('strip_image_tags'))
{
- $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str);
- $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str);
+ 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;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -104,9 +113,12 @@ function strip_image_tags($str) * @param string
* @return string
*/
-function encode_php_tags($str)
+if (! function_exists('encode_php_tags'))
{
- return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('<?php', '<?PHP', '<?', '?>'), $str);
+ function encode_php_tags($str)
+ {
+ return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('<?php', '<?PHP', '<?', '?>'), $str);
+ }
}
?>
\ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index d61ea7828..f4149478c 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -37,9 +37,11 @@ * @param string field name
* @return string
*/
-function js_insert_smiley($form_name = '', $form_field = '')
+if (! function_exists('js_insert_smiley'))
{
-return <<<EOF
+ function js_insert_smiley($form_name = '', $form_field = '')
+ {
+ return <<<EOF
<script type="text/javascript">
function insert_smiley(smiley)
{
@@ -47,8 +49,8 @@ return <<<EOF }
</script>
EOF;
-}
-
+ }
+}
// ------------------------------------------------------------------------
/**
@@ -61,37 +63,40 @@ EOF; * @param string the URL to the folder containing the smiley images
* @return array
*/
-function get_clickable_smileys($image_url = '', $smileys = NULL)
+if (! function_exists('get_clickable_smileys'))
{
- if ( ! is_array($smileys))
+ function get_clickable_smileys($image_url = '', $smileys = NULL)
{
- if (FALSE === ($smileys = _get_smiley_array()))
+ if ( ! is_array($smileys))
{
- return $str;
- }
- }
+ if (FALSE === ($smileys = _get_smiley_array()))
+ {
+ return $str;
+ }
+ }
- // Add a trailing slash to the file path if needed
- $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
+ // Add a trailing slash to the file path if needed
+ $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
- $used = array();
- foreach ($smileys as $key => $val)
- {
- // Keep duplicates from being used, which can happen if the
- // mapping array contains multiple identical replacements. For example:
- // :-) and :) might be replaced with the same image so both smileys
- // will be in the array.
- if (isset($used[$smileys[$key][0]]))
+ $used = array();
+ foreach ($smileys as $key => $val)
{
- continue;
- }
+ // Keep duplicates from being used, which can happen if the
+ // mapping array contains multiple identical replacements. For example:
+ // :-) and :) might be replaced with the same image so both smileys
+ // will be in the array.
+ if (isset($used[$smileys[$key][0]]))
+ {
+ continue;
+ }
- $link[] = "<a href=\"javascript:void(0);\" onClick=\"insert_smiley('".$key."')\"><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."')\"><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;
- }
+ $used[$smileys[$key][0]] = TRUE;
+ }
- return $link;
+ return $link;
+ }
}
// ------------------------------------------------------------------------
@@ -106,30 +111,33 @@ function get_clickable_smileys($image_url = '', $smileys = NULL) * @param string the URL to the folder containing the smiley images
* @return string
*/
-function parse_smileys($str = '', $image_url = '', $smileys = NULL)
+if (! function_exists('parse_smileys'))
{
- if ($image_url == '')
+ function parse_smileys($str = '', $image_url = '', $smileys = NULL)
{
- return $str;
- }
-
- if ( ! is_array($smileys))
- {
- if (FALSE === ($smileys = _get_smiley_array()))
+ if ($image_url == '')
{
return $str;
- }
- }
+ }
+
+ if ( ! is_array($smileys))
+ {
+ if (FALSE === ($smileys = _get_smiley_array()))
+ {
+ return $str;
+ }
+ }
- // Add a trailing slash to the file path if needed
- $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
+ // Add a trailing slash to the file path if needed
+ $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url);
- foreach ($smileys as $key => $val)
- {
- $str = str_replace($key, "<img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" />", $str);
- }
+ foreach ($smileys as $key => $val)
+ {
+ $str = str_replace($key, "<img src=\"".$image_url.$smileys[$key][0]."\" width=\"".$smileys[$key][1]."\" height=\"".$smileys[$key][2]."\" alt=\"".$smileys[$key][3]."\" style=\"border:0;\" />", $str);
+ }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -142,24 +150,24 @@ function parse_smileys($str = '', $image_url = '', $smileys = NULL) * @access private
* @return mixed
*/
-function _get_smiley_array()
+if (! function_exists('_get_smiley_array'))
{
- if ( ! file_exists(APPPATH.'config/smileys'.EXT))
+ function _get_smiley_array()
{
- return FALSE;
- }
+ if ( ! file_exists(APPPATH.'config/smileys'.EXT))
+ {
+ return FALSE;
+ }
- include(APPPATH.'config/smileys'.EXT);
+ include(APPPATH.'config/smileys'.EXT);
- if ( ! isset($smileys) OR ! is_array($smileys))
- {
- return FALSE;
- }
+ if ( ! isset($smileys) OR ! is_array($smileys))
+ {
+ return FALSE;
+ }
- return $smileys;
+ return $smileys;
+ }
}
-
-
-
?>
\ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 42bcd57ad..f68f44ac1 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -42,10 +42,13 @@ * @param string
* @return string
*/
-function trim_slashes($str)
+if (! function_exists('trim_slashes'))
{
- return trim($str, '/');
-}
+ function trim_slashes($str)
+ {
+ return trim($str, '/');
+ }
+}
// ------------------------------------------------------------------------
@@ -58,21 +61,24 @@ function trim_slashes($str) * @param mixed string or array
* @return mixed string or array
*/
- function strip_slashes($str)
- {
- if (is_array($str))
- {
- foreach ($str as $key => $val)
+if (! function_exists('strip_slashes'))
+{
+ function strip_slashes($str)
+ {
+ if (is_array($str))
+ {
+ foreach ($str as $key => $val)
+ {
+ $str[$key] = strip_slashes($val);
+ }
+ }
+ else
{
- $str[$key] = strip_slashes($val);
+ $str = stripslashes($str);
}
- }
- else
- {
- $str = stripslashes($str);
- }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -86,9 +92,12 @@ function trim_slashes($str) * @param string
* @return string
*/
-function strip_quotes($str)
+if (! function_exists('strip_quotes'))
{
- return str_replace(array('"', "'"), '', $str);
+ function strip_quotes($str)
+ {
+ return str_replace(array('"', "'"), '', $str);
+ }
}
// ------------------------------------------------------------------------
@@ -102,9 +111,12 @@ function strip_quotes($str) * @param string
* @return string
*/
-function quotes_to_entities($str)
-{
- return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
+if (! function_exists('quotes_to_entities'))
+{
+ function quotes_to_entities($str)
+ {
+ return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
+ }
}
// ------------------------------------------------------------------------
@@ -124,9 +136,12 @@ function quotes_to_entities($str) * @param string
* @return string
*/
-function reduce_double_slashes($str)
+if (! function_exists('reduce_double_slashes'))
{
- return preg_replace("#([^:])//+#", "\\1/", $str);
+ function reduce_double_slashes($str)
+ {
+ return preg_replace("#([^:])//+#", "\\1/", $str);
+ }
}
// ------------------------------------------------------------------------
@@ -148,16 +163,19 @@ function reduce_double_slashes($str) * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
* @return string
*/
-function reduce_multiples($str, $character = ',', $trim = FALSE)
+if (! function_exists('reduce_multiples'))
{
- $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
-
- if ($trim === TRUE)
+ function reduce_multiples($str, $character = ',', $trim = FALSE)
{
- $str = trim($str, $character);
- }
+ $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
+
+ if ($trim === TRUE)
+ {
+ $str = trim($str, $character);
+ }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -171,36 +189,40 @@ function reduce_multiples($str, $character = ',', $trim = FALSE) * @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' :
+ */
+if (! function_exists('random_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;
+ 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;
+ }
}
}
+
// ------------------------------------------------------------------------
/**
@@ -211,18 +233,21 @@ function random_string($type = 'alnum', $len = 8) * @access public
* @param string (as many parameters as needed)
* @return string
- */
-function alternator()
+ */
+if (! function_exists('alternator'))
{
- static $i;
-
- if (func_num_args() == 0)
+ function alternator()
{
- $i = 0;
- return '';
+ static $i;
+
+ if (func_num_args() == 0)
+ {
+ $i = 0;
+ return '';
+ }
+ $args = func_get_args();
+ return $args[($i++ % count($args))];
}
- $args = func_get_args();
- return $args[($i++ % count($args))];
}
// ------------------------------------------------------------------------
@@ -235,10 +260,12 @@ function alternator() * @param integer number of repeats
* @return string
*/
-function repeater($data, $num = 1)
+if (! function_exists('repeater'))
{
- return (($num > 0) ? str_repeat($data, $num) : '');
-}
-
+ 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 20bf32335..30cec3148 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -38,27 +38,30 @@ * @param string the end character. Usually an ellipsis
* @return string
*/
-function word_limiter($str, $n = 100, $end_char = '…')
+if (! function_exists('word_limiter'))
{
- if (strlen($str) < $n)
+ function word_limiter($str, $n = 100, $end_char = '…')
{
- return $str;
- }
+ if (strlen($str) < $n)
+ {
+ return $str;
+ }
- $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)));
+ $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str)));
- if (count($words) <= $n)
- {
- return $str;
- }
+ if (count($words) <= $n)
+ {
+ return $str;
+ }
- $str = '';
- for ($i = 0; $i < $n; $i++)
- {
- $str .= $words[$i].' ';
- }
+ $str = '';
+ for ($i = 0; $i < $n; $i++)
+ {
+ $str .= $words[$i].' ';
+ }
- return trim($str).$end_char;
+ return trim($str).$end_char;
+ }
}
// ------------------------------------------------------------------------
@@ -75,28 +78,31 @@ function word_limiter($str, $n = 100, $end_char = '…') * @param string the end character. Usually an ellipsis
* @return string
*/
-function character_limiter($str, $n = 500, $end_char = '…')
+if (! function_exists('character_limiter'))
{
- if (strlen($str) < $n)
+ function character_limiter($str, $n = 500, $end_char = '…')
{
- return $str;
- }
+ if (strlen($str) < $n)
+ {
+ return $str;
+ }
- $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));
+ $str = preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str));
- if (strlen($str) <= $n)
- {
- return $str;
- }
+ if (strlen($str) <= $n)
+ {
+ return $str;
+ }
- $out = "";
- foreach (explode(' ', trim($str)) as $val)
- {
- $out .= $val.' ';
- if (strlen($out) >= $n)
+ $out = "";
+ foreach (explode(' ', trim($str)) as $val)
{
- return trim($out).$end_char;
- }
+ $out .= $val.' ';
+ if (strlen($out) >= $n)
+ {
+ return trim($out).$end_char;
+ }
+ }
}
}
@@ -111,41 +117,44 @@ function character_limiter($str, $n = 500, $end_char = '…') * @param string
* @return string
*/
-function ascii_to_entities($str)
+if (! function_exists('ascii_to_entities'))
{
- $count = 1;
- $out = '';
- $temp = array();
-
- for ($i = 0, $s = strlen($str); $i < $s; $i++)
- {
- $ordinal = ord($str[$i]);
+ function ascii_to_entities($str)
+ {
+ $count = 1;
+ $out = '';
+ $temp = array();
- if ($ordinal < 128)
- {
- $out .= $str[$i];
- }
- else
+ for ($i = 0, $s = strlen($str); $i < $s; $i++)
{
- if (count($temp) == 0)
+ $ordinal = ord($str[$i]);
+
+ if ($ordinal < 128)
{
- $count = ($ordinal < 224) ? 2 : 3;
+ $out .= $str[$i];
}
+ else
+ {
+ if (count($temp) == 0)
+ {
+ $count = ($ordinal < 224) ? 2 : 3;
+ }
- $temp[] = $ordinal;
+ $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);
+ 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();
+ $out .= '&#'.$number.';';
+ $count = 1;
+ $temp = array();
+ }
}
}
- }
- return $out;
+ return $out;
+ }
}
// ------------------------------------------------------------------------
@@ -160,45 +169,48 @@ function ascii_to_entities($str) * @param bool
* @return string
*/
-function entities_to_ascii($str, $all = TRUE)
+if (! function_exists('entities_to_ascii'))
{
- if (preg_match_all('/\&#(\d+)\;/', $str, $matches))
- {
- for ($i = 0, $s = count($matches['0']); $i < $s; $i++)
- {
- $digits = $matches['1'][$i];
+ 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 = '';
+ $out = '';
- if ($digits < 128)
- {
- $out .= chr($digits);
+ 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));
- }
+ }
+ 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);
+ $str = str_replace($matches['0'][$i], $out, $str);
+ }
}
- }
- if ($all)
- {
- $str = str_replace(array("&", "<", ">", """, "'", "-"),
- array("&","<",">","\"", "'", "-"),
- $str);
- }
+ if ($all)
+ {
+ $str = str_replace(array("&", "<", ">", """, "'", "-"),
+ array("&","<",">","\"", "'", "-"),
+ $str);
+ }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -216,27 +228,30 @@ function entities_to_ascii($str, $all = TRUE) * @param string the optional replacement value
* @return string
*/
-function word_censor($str, $censored, $replacement = '')
+if (! function_exists('word_censor'))
{
- if ( ! is_array($censored))
- {
- return $str;
- }
-
- $str = ' '.$str.' ';
- foreach ($censored as $badword)
+ function word_censor($str, $censored, $replacement = '')
{
- if ($replacement != '')
+ if ( ! is_array($censored))
{
- $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str);
+ return $str;
}
- else
+
+ $str = ' '.$str.' ';
+ foreach ($censored as $badword)
{
- $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str);
+ 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);
+ return trim($str);
+ }
}
// ------------------------------------------------------------------------
@@ -250,45 +265,48 @@ function word_censor($str, $censored, $replacement = '') * @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);
+if (! function_exists('highlight_code'))
+{
+ function highlight_code($str)
+ {
+ // The highlight string function encodes and highlights
+ // brackets so we need them to start raw
+ $str = str_replace(array('<', '>'), array('<', '>'), $str);
- // Replace any existing PHP tags to temporary markers so they don't accidentally
- // break the string out of PHP, and thus, thwart the highlighting.
+ // 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>'),
- array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
+ $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. 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
+ // 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 ?>';
+ $str = '<?php tempstart'."\n".$str.'tempend ?>';
- // All the magic happens here, baby!
- $str = highlight_string($str, TRUE);
+ // 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);
- }
+ // 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("#tempend.+#is", "</span>\n</code>", $str);
+ // Remove our artificially added PHP
+ $str = preg_replace("#\<code\>.+?tempstart\<br />(?:\</span\>)?#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', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
- array('<?', '?>', '<%', '%>', '\\', '</script>'), $str);
+ // Replace our markers back to PHP tags.
+ $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'),
+ array('<?', '?>', '<%', '%>', '\\', '</script>'), $str);
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -305,19 +323,22 @@ function highlight_code($str) * @param string the closing tag to end the phrase with
* @return string
*/
-function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
+if (! function_exists('highlight_phrase'))
{
- if ($str == '')
+ function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
{
- return '';
- }
+ if ($str == '')
+ {
+ return '';
+ }
- if ($phrase != '')
- {
- return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
- }
+ if ($phrase != '')
+ {
+ return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str);
+ }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -334,89 +355,91 @@ function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '< * @param integer the number of characters to wrap at
* @return string
*/
-function word_wrap($str, $charlim = '76')
+if (! function_exists('word_wrap'))
{
- // Se the character limit
- if ( ! is_numeric($charlim))
- $charlim = 76;
+ function word_wrap($str, $charlim = '76')
+ {
+ // Se the character limit
+ if ( ! is_numeric($charlim))
+ $charlim = 76;
- // Reduce multiple spaces
- $str = preg_replace("| +|", " ", $str);
+ // Reduce multiple spaces
+ $str = preg_replace("| +|", " ", $str);
- // Standardize newlines
- $str = preg_replace("/\r\n|\r/", "\n", $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++)
+ // 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))
{
- $unwrap[] = $matches['1'][$i];
- $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
+ 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);
+ // 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)
+ // Split the string into individual lines of text and cycle through them
+ $output = "";
+ foreach (explode("\n", $str) as $line)
{
- $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))
+ // Is the line within the allowed character count?
+ // If so we'll join it to the output and continue
+ if (strlen($line) <= $charlim)
{
- break;
+ $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);
- }
+ // 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;
- }
+ // 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";
- }
+ $output .= "\n";
+ }
- // Put our markers back
- if (count($unwrap) > 0)
- {
- foreach ($unwrap as $key => $val)
- {
- $output = str_replace("{{unwrapped".$key."}}", $val, $output);
+ // 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);
+ // Remove the unwrap tags
+ $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
- return $output;
+ return $output;
+ }
}
-
?>
\ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 4a746c6e4..4d9a1bb6b 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -34,28 +34,31 @@ * @param string
* @return string
*/
-function nl2br_except_pre($str)
+if (! function_exists('nl2br_except_pre'))
{
- $ex = explode("pre>",$str);
- $ct = count($ex);
-
- $newstr = "";
- for ($i = 0; $i < $ct; $i++)
+ function nl2br_except_pre($str)
{
- if (($i % 2) == 0)
- {
- $newstr .= nl2br($ex[$i]);
- }
- else
+ $ex = explode("pre>",$str);
+ $ct = count($ex);
+
+ $newstr = "";
+ for ($i = 0; $i < $ct; $i++)
{
- $newstr .= $ex[$i];
- }
+ if (($i % 2) == 0)
+ {
+ $newstr .= nl2br($ex[$i]);
+ }
+ else
+ {
+ $newstr .= $ex[$i];
+ }
- if ($ct - 1 != $i)
- $newstr .= "pre>";
- }
+ if ($ct - 1 != $i)
+ $newstr .= "pre>";
+ }
- return $newstr;
+ return $newstr;
+ }
}
// ------------------------------------------------------------------------
@@ -68,10 +71,13 @@ function nl2br_except_pre($str) * @param string
* @return string
*/
-function auto_typography($str)
+if (! function_exists('auto_typography'))
{
- $TYPE = new Auto_typography();
- return $TYPE->convert($str);
+ function auto_typography($str)
+ {
+ $TYPE = new Auto_typography();
+ return $TYPE->convert($str);
+ }
}
// ------------------------------------------------------------------------
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 9969af044..ad71caa45 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -37,10 +37,13 @@ * @param string
* @return string
*/
-function site_url($uri = '')
+if (! function_exists('site_url'))
{
- $CI =& get_instance();
- return $CI->config->site_url($uri);
+ function site_url($uri = '')
+ {
+ $CI =& get_instance();
+ return $CI->config->site_url($uri);
+ }
}
// ------------------------------------------------------------------------
@@ -53,10 +56,13 @@ function site_url($uri = '') * @access public
* @return string
*/
-function base_url()
+if (! function_exists('base_url'))
{
- $CI =& get_instance();
- return $CI->config->slash_item('base_url');
+ function base_url()
+ {
+ $CI =& get_instance();
+ return $CI->config->slash_item('base_url');
+ }
}
// ------------------------------------------------------------------------
@@ -69,10 +75,13 @@ function base_url() * @access public
* @return string
*/
-function index_page()
+if (! function_exists('index_page'))
{
- $CI =& get_instance();
- return $CI->config->item('index_page');
+ function index_page()
+ {
+ $CI =& get_instance();
+ return $CI->config->item('index_page');
+ }
}
// ------------------------------------------------------------------------
@@ -88,34 +97,37 @@ function index_page() * @param mixed any attributes
* @return string
*/
-function anchor($uri = '', $title = '', $attributes = '')
+if (! function_exists('anchor'))
{
- $title = (string) $title;
-
- if ( ! is_array($uri))
- {
- $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri;
- }
- else
+ function anchor($uri = '', $title = '', $attributes = '')
{
- $site_url = site_url($uri);
- }
+ $title = (string) $title;
- if ($title == '')
- {
- $title = $site_url;
- }
+ if ( ! is_array($uri))
+ {
+ $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri;
+ }
+ else
+ {
+ $site_url = site_url($uri);
+ }
+
+ if ($title == '')
+ {
+ $title = $site_url;
+ }
- if ($attributes == '')
- {
- $attributes = ' title="'.$title.'"';
- }
- else
- {
- $attributes = _parse_attributes($attributes);
- }
+ if ($attributes == '')
+ {
+ $attributes = ' title="'.$title.'"';
+ }
+ else
+ {
+ $attributes = _parse_attributes($attributes);
+ }
- return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
+ return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
+ }
}
// ------------------------------------------------------------------------
@@ -132,33 +144,36 @@ function anchor($uri = '', $title = '', $attributes = '') * @param mixed any attributes
* @return string
*/
-function anchor_popup($uri = '', $title = '', $attributes = FALSE)
-{
- $title = (string) $title;
+if (! function_exists('anchor_popup'))
+{
+ function anchor_popup($uri = '', $title = '', $attributes = FALSE)
+ {
+ $title = (string) $title;
- $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri;
+ $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri;
- if ($title == '')
- {
- $title = $site_url;
- }
+ if ($title == '')
+ {
+ $title = $site_url;
+ }
- if ($attributes === FALSE)
- {
- return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
- }
+ if ($attributes === FALSE)
+ {
+ return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
+ }
- if ( ! is_array($attributes))
- {
- $attributes = array();
- }
+ if ( ! is_array($attributes))
+ {
+ $attributes = array();
+ }
- foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
- {
- $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
- }
+ foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
+ {
+ $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
+ }
- return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\">".$title."</a>";
+ return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\">".$title."</a>";
+ }
}
// ------------------------------------------------------------------------
@@ -172,18 +187,21 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) * @param mixed any attributes
* @return string
*/
-function mailto($email, $title = '', $attributes = '')
+if (! function_exists('mailto'))
{
- $title = (string) $title;
-
- if ($title == "")
+ function mailto($email, $title = '', $attributes = '')
{
- $title = $email;
- }
+ $title = (string) $title;
- $attributes = _parse_attributes($attributes);
+ if ($title == "")
+ {
+ $title = $email;
+ }
- return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
+ $attributes = _parse_attributes($attributes);
+
+ return '<a href="mailto:'.$email.'"'.$attributes.'>'.$title.'</a>';
+ }
}
// ------------------------------------------------------------------------
@@ -199,100 +217,103 @@ function mailto($email, $title = '', $attributes = '') * @param mixed any attributes
* @return string
*/
-function safe_mailto($email, $title = '', $attributes = '')
+if (! function_exists('safe_mailto'))
{
- $title = (string) $title;
-
- if ($title == "")
+ function safe_mailto($email, $title = '', $attributes = '')
{
- $title = $email;
- }
+ $title = (string) $title;
+
+ if ($title == "")
+ {
+ $title = $email;
+ }
- for ($i = 0; $i < 16; $i++)
- {
- $x[] = substr('<a href="mailto:', $i, 1);
- }
+ for ($i = 0; $i < 16; $i++)
+ {
+ $x[] = substr('<a href="mailto:', $i, 1);
+ }
- for ($i = 0; $i < strlen($email); $i++)
- {
- $x[] = "|".ord(substr($email, $i, 1));
- }
+ for ($i = 0; $i < strlen($email); $i++)
+ {
+ $x[] = "|".ord(substr($email, $i, 1));
+ }
- $x[] = '"';
+ $x[] = '"';
- if ($attributes != '')
- {
- if (is_array($attributes))
+ if ($attributes != '')
{
- foreach ($attributes as $key => $val)
+ if (is_array($attributes))
{
- $x[] = ' '.$key.'="';
- for ($i = 0; $i < strlen($val); $i++)
+ foreach ($attributes as $key => $val)
{
- $x[] = "|".ord(substr($val, $i, 1));
+ $x[] = ' '.$key.'="';
+ for ($i = 0; $i < strlen($val); $i++)
+ {
+ $x[] = "|".ord(substr($val, $i, 1));
+ }
+ $x[] = '"';
}
- $x[] = '"';
}
- }
- else
- {
- for ($i = 0; $i < strlen($attributes); $i++)
- {
- $x[] = substr($attributes, $i, 1);
+ else
+ {
+ for ($i = 0; $i < strlen($attributes); $i++)
+ {
+ $x[] = substr($attributes, $i, 1);
+ }
}
- }
- }
-
- $x[] = '>';
+ }
- $temp = array();
- for ($i = 0; $i < strlen($title); $i++)
- {
- $ordinal = ord($title[$i]);
+ $x[] = '>';
- if ($ordinal < 128)
+ $temp = array();
+ for ($i = 0; $i < strlen($title); $i++)
{
- $x[] = "|".$ordinal;
- }
- else
- {
- if (count($temp) == 0)
+ $ordinal = ord($title[$i]);
+
+ if ($ordinal < 128)
{
- $count = ($ordinal < 224) ? 2 : 3;
+ $x[] = "|".$ordinal;
}
-
- $temp[] = $ordinal;
- if (count($temp) == $count)
+ else
{
- $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
- $x[] = "|".$number;
- $count = 1;
- $temp = array();
+ 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);
+ $x[] = "|".$number;
+ $count = 1;
+ $temp = array();
+ }
}
}
- }
- $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
+ $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>';
- $x = array_reverse($x);
- ob_start();
+ $x = array_reverse($x);
+ ob_start();
-?><script type="text/javascript">
-//<![CDATA[
-var l=new Array();
-<?php
-$i = 0;
-foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
+ ?><script type="text/javascript">
+ //<![CDATA[
+ var l=new Array();
+ <?php
+ $i = 0;
+ foreach ($x as $val){ ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php } ?>
-for (var i = l.length-1; i >= 0; i=i-1){
-if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
-else document.write(unescape(l[i]));}
-//]]>
-</script><?php
+ for (var i = l.length-1; i >= 0; i=i-1){
+ if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";");
+ else document.write(unescape(l[i]));}
+ //]]>
+ </script><?php
- $buffer = ob_get_contents();
- ob_end_clean();
- return $buffer;
+ $buffer = ob_get_contents();
+ ob_end_clean();
+ return $buffer;
+ }
}
// ------------------------------------------------------------------------
@@ -311,55 +332,58 @@ else document.write(unescape(l[i]));} * @param bool whether to create pop-up links
* @return string
*/
-function auto_link($str, $type = 'both', $popup = FALSE)
+if (! function_exists('auto_link'))
{
- if ($type != 'email')
- {
- if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
- {
- $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
-
- for ($i = 0; $i < sizeof($matches['0']); $i++)
+ function auto_link($str, $type = 'both', $popup = FALSE)
+ {
+ if ($type != 'email')
+ {
+ if (preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches))
{
- $period = '';
- if (preg_match("|\.$|", $matches['6'][$i]))
+ $pop = ($popup == TRUE) ? " target=\"_blank\" " : "";
+
+ for ($i = 0; $i < sizeof($matches['0']); $i++)
{
- $period = '.';
- $matches['6'][$i] = substr($matches['6'][$i], 0, -1);
- }
+ $period = '';
+ if (preg_match("|\.$|", $matches['6'][$i]))
+ {
+ $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].'://'.
- $matches['5'][$i].
- $matches['6'][$i].'"'.$pop.'>http'.
- $matches['4'][$i].'://'.
- $matches['5'][$i].
- $matches['6'][$i].'</a>'.
- $period, $str);
+ $str = str_replace($matches['0'][$i],
+ $matches['1'][$i].'<a href="http'.
+ $matches['4'][$i].'://'.
+ $matches['5'][$i].
+ $matches['6'][$i].'"'.$pop.'>http'.
+ $matches['4'][$i].'://'.
+ $matches['5'][$i].
+ $matches['6'][$i].'</a>'.
+ $period, $str);
+ }
}
}
- }
- if ($type != 'url')
- {
- if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
- {
- for ($i = 0; $i < sizeof($matches['0']); $i++)
+ if ($type != 'url')
+ {
+ if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches))
{
- $period = '';
- if (preg_match("|\.$|", $matches['3'][$i]))
+ for ($i = 0; $i < sizeof($matches['0']); $i++)
{
- $period = '.';
- $matches['3'][$i] = substr($matches['3'][$i], 0, -1);
- }
+ $period = '';
+ if (preg_match("|\.$|", $matches['3'][$i]))
+ {
+ $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);
- }
+ $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
+ }
+ }
}
+ return $str;
}
- return $str;
}
// ------------------------------------------------------------------------
@@ -373,19 +397,22 @@ function auto_link($str, $type = 'both', $popup = FALSE) * @param string the URL
* @return string
*/
-function prep_url($str = '')
+if (! function_exists('prep_url'))
{
- if ($str == 'http://' OR $str == '')
+ function prep_url($str = '')
{
- return '';
- }
+ if ($str == 'http://' OR $str == '')
+ {
+ return '';
+ }
- if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
- {
- $str = 'http://'.$str;
- }
+ if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
+ {
+ $str = 'http://'.$str;
+ }
- return $str;
+ return $str;
+ }
}
// ------------------------------------------------------------------------
@@ -402,36 +429,39 @@ function prep_url($str = '') * @param string the separator: dash, or underscore
* @return string
*/
-function url_title($str, $separator = 'dash')
+if (! function_exists('url_title'))
{
- if ($separator == 'dash')
- {
- $search = '_';
- $replace = '-';
- }
- else
+ function url_title($str, $separator = 'dash')
{
- $search = '-';
- $replace = '_';
- }
+ if ($separator == 'dash')
+ {
+ $search = '_';
+ $replace = '-';
+ }
+ else
+ {
+ $search = '-';
+ $replace = '_';
+ }
- $trans = array(
- $search => $replace,
- "\s+" => $replace,
- "[^a-z0-9".$replace."]" => '',
- $replace."+" => $replace,
- $replace."$" => '',
- "^".$replace => ''
- );
+ $trans = array(
+ $search => $replace,
+ "\s+" => $replace,
+ "[^a-z0-9".$replace."]" => '',
+ $replace."+" => $replace,
+ $replace."$" => '',
+ "^".$replace => ''
+ );
- $str = strip_tags(strtolower($str));
+ $str = strip_tags(strtolower($str));
- foreach ($trans as $key => $val)
- {
- $str = preg_replace("#".$key."#", $val, $str);
- }
+ foreach ($trans as $key => $val)
+ {
+ $str = preg_replace("#".$key."#", $val, $str);
+ }
- return trim(stripslashes($str));
+ return trim(stripslashes($str));
+ }
}
// ------------------------------------------------------------------------
@@ -446,16 +476,19 @@ function url_title($str, $separator = 'dash') * @param string the method: location or redirect
* @return string
*/
-function redirect($uri = '', $method = 'location')
+if (! function_exists('redirect'))
{
- switch($method)
+ function redirect($uri = '', $method = 'location')
{
- case 'refresh' : header("Refresh:0;url=".site_url($uri));
- break;
- default : header("Location: ".site_url($uri));
- break;
+ switch($method)
+ {
+ case 'refresh' : header("Refresh:0;url=".site_url($uri));
+ break;
+ default : header("Location: ".site_url($uri));
+ break;
+ }
+ exit;
}
- exit;
}
// ------------------------------------------------------------------------
@@ -470,32 +503,35 @@ function redirect($uri = '', $method = 'location') * @param bool
* @return string
*/
-function _parse_attributes($attributes, $javascript = FALSE)
+if (! function_exists('_parse_attributes'))
{
- if (is_string($attributes))
+ function _parse_attributes($attributes, $javascript = FALSE)
{
- return ($attributes != '') ? ' '.$attributes : '';
- }
+ if (is_string($attributes))
+ {
+ return ($attributes != '') ? ' '.$attributes : '';
+ }
- $att = '';
- foreach ($attributes as $key => $val)
- {
- if ($javascript == TRUE)
+ $att = '';
+ foreach ($attributes as $key => $val)
{
- $att .= $key . '=' . $val . ',';
+ if ($javascript == TRUE)
+ {
+ $att .= $key . '=' . $val . ',';
+ }
+ else
+ {
+ $att .= ' ' . $key . '="' . $val . '"';
+ }
}
- else
+
+ if ($javascript == TRUE AND $att != '')
{
- $att .= ' ' . $key . '="' . $val . '"';
+ $att = substr($att, 0, -1);
}
- }
- if ($javascript == TRUE AND $att != '')
- {
- $att = substr($att, 0, -1);
+ return $att;
}
-
- return $att;
}
?>
\ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 1a2c7379c..5aa6de9ec 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -34,25 +34,27 @@ * @param string
* @return string
*/
-function xml_convert($str)
+if (! function_exists('xml_convert'))
{
- $temp = '__TEMP_AMPERSANDS__';
-
- // 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);
+ function xml_convert($str)
+ {
+ $temp = '__TEMP_AMPERSANDS__';
+
+ // 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);
- $str = str_replace(array("&","<",">","\"", "'", "-"),
- array("&", "<", ">", """, "'", "-"),
- $str);
+ $str = str_replace(array("&","<",">","\"", "'", "-"),
+ array("&", "<", ">", """, "'", "-"),
+ $str);
- // Decode the temp markers back to entities
- $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
- $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
+ // Decode the temp markers back to entities
+ $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
+ $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
- return $str;
+ return $str;
+ }
}
-
?>
\ No newline at end of file diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 320a43a00..a59d6e38e 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -366,8 +366,23 @@ class CI_Loader { {
continue;
}
+
+ $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT;
- if (file_exists(APPPATH.'helpers/'.$helper.EXT))
+ // Is this a helper extension request?
+ if (file_exists($ext_helper))
+ {
+ $base_helper = BASEPATH.'helpers/'.$helper.EXT;
+
+ if ( ! file_exists($base_helper))
+ {
+ show_error('Unable to load the requested file: helpers/'.$helper.EXT);
+ }
+
+ include_once($ext_helper);
+ include_once($base_helper);
+ }
+ elseif (file_exists(APPPATH.'helpers/'.$helper.EXT))
{
include_once(APPPATH.'helpers/'.$helper.EXT);
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index d8a67405e..d029f3222 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -129,6 +129,7 @@ Change Log <li>Helpers & Plugins
<ul>
+ <li>Added ability to <a href="./general/helpers.html">"extend" Helpers</a>.</li>
<li>Added an <a href="./helpers/email_helper.html">email helper</a> into core helpers.</li>
<li>Added <kbd>strip_quotes()</kbd> function to <a href="./helpers/string_helper.html">string helper</a>.</li>
<li>Added <kbd>reduce_multiples()</kbd> function to <a href="./helpers/string_helper.html">string helper</a>.</li>
diff --git a/user_guide/general/helpers.html b/user_guide/general/helpers.html index 0b83884b5..38ce76815 100644 --- a/user_guide/general/helpers.html +++ b/user_guide/general/helpers.html @@ -116,6 +116,51 @@ This is done by opening the <var>application/config/autoload.php</var> file and <p>Where "Click Here" is the name of the link, and "blog/comments" is the URI to the controller/function you wish to link to.</p>
+<h2>"Extending" Helpers</h2>
+
+<p>To "extend" Helpers, create a file in your <dfn>application/helpers/</dfn> folder with an identical name to the existing Helper, but prefixed with <kbd>MY_</kbd> (this item is configurable. See below.).</p>
+
+<p>If all you need to do is add some functionality to an existing helper - perhaps add a function or two, or change how a particular
+ helper function operates - then it's overkill to replace the entire helper with your version. In this case it's better to simply
+ "extend" the Helper. The term "extend" is used loosely since Helper functions are procedural and discrete and cannot be extended
+ in the traditional programmatic sense. Under the hood, this gives you the ability to add to the functions a Helper provides,
+ or to modify how the native Helper functions operate.</p>
+
+<p>For example, to extend the native <kbd>Array Helper</kbd> you'll create a file named <dfn>application/helpers/</dfn><kbd>MY_array_helper.php</kbd>, and add or override functions:</p>
+
+<code>
+// any_in_array() is not in the Array Helper, so it defines a new function<br />
+function any_in_array($needle, $haystack)<br />
+{<br />
+ $needle = (is_array($needle)) ? $needle : array($needle);<br />
+ <br />
+ foreach ($needle as $item)<br />
+ {<br />
+ if (in_array($item, $haystack))<br />
+ {<br />
+ return TRUE;<br />
+ }<br />
+ }<br />
+ <br />
+ return FALSE;<br />
+}<br />
+<br />
+// random_element() is included in Array Helper, so it overrides the native function<br />
+function random_element($array)<br />
+{<br />
+ shuffle($array);<br />
+ return array_pop();<br />
+}<br />
+</code>
+
+<h3>Setting Your Own Prefix</h3>
+
+<p>The filename prefix for "extending" Helpers is the same used to extend libraries and Core classes. To set your own prefix, open your <dfn>application/config/config.php</dfn> file and look for this item:</p>
+
+<code>$config['subclass_prefix'] = 'MY_';</code>
+
+<p>Please note that all native CodeIgniter libraries are prefixed with <kbd>CI_</kbd> so DO NOT use that as your prefix.</p>
+
<h2>Now What?</h2>
|