From b0dd10f8171945e0c1f3527dd1e9d18b043e01a7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Aug 2006 17:25:49 +0000 Subject: Initial Import --- system/helpers/array_helper.php | 47 ++++ system/helpers/cookie_helper.php | 77 +++++ system/helpers/date_helper.php | 530 +++++++++++++++++++++++++++++++++++ system/helpers/directory_helper.php | 69 +++++ system/helpers/file_helper.php | 139 +++++++++ system/helpers/form_helper.php | 382 +++++++++++++++++++++++++ system/helpers/html_helper.php | 76 +++++ system/helpers/index.html | 15 + system/helpers/security_helper.php | 112 ++++++++ system/helpers/string_helper.php | 154 ++++++++++ system/helpers/text_helper.php | 386 +++++++++++++++++++++++++ system/helpers/typography_helper.php | 490 ++++++++++++++++++++++++++++++++ system/helpers/url_helper.php | 487 ++++++++++++++++++++++++++++++++ system/helpers/xml_helper.php | 55 ++++ 14 files changed, 3019 insertions(+) create mode 100644 system/helpers/array_helper.php create mode 100644 system/helpers/cookie_helper.php create mode 100644 system/helpers/date_helper.php create mode 100644 system/helpers/directory_helper.php create mode 100644 system/helpers/file_helper.php create mode 100644 system/helpers/form_helper.php create mode 100644 system/helpers/html_helper.php create mode 100644 system/helpers/index.html create mode 100644 system/helpers/security_helper.php create mode 100644 system/helpers/string_helper.php create mode 100644 system/helpers/text_helper.php create mode 100644 system/helpers/typography_helper.php create mode 100644 system/helpers/url_helper.php create mode 100644 system/helpers/xml_helper.php (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php new file mode 100644 index 000000000..cccde1fc4 --- /dev/null +++ b/system/helpers/array_helper.php @@ -0,0 +1,47 @@ + \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php new file mode 100644 index 000000000..24e243ddd --- /dev/null +++ b/system/helpers/cookie_helper.php @@ -0,0 +1,77 @@ + 0) + { + $expire = time() + $expire; + } + else + { + $expire = 0; + } + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, 0); +} + +?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php new file mode 100644 index 000000000..2a3d50859 --- /dev/null +++ b/system/helpers/date_helper.php @@ -0,0 +1,530 @@ +config->item('time_reference')) == 'gmt') + { + $now = time(); + $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + + if (strlen($system_time) < 10) + { + $system_time = time(); + log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); + } + + return $system_time; + } + else + { + return time(); + } +} + +// ------------------------------------------------------------------------ + +/** + * Convert MySQL Style Datecodes + * + * This function is identical to PHPs date() function, + * except that it allows date codes to be formatted using + * the MySQL style, where each code letter is preceded + * with a percent sign: %Y %m %d etc... + * + * The benefit of doing dates this way is that you don't + * have to worry about escaping your text letters that + * match the date codes. + * + * @access public + * @param string + * @param integer + * @return integer + */ +function mdate($datestr = '', $time = '') +{ + if ($datestr == '') + return ''; + + if ($time == '') + $time = now(); + + $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); + return date($datestr, $time); +} + +// ------------------------------------------------------------------------ + +/** + * Convert MySQL Style Datecodes + * + * Returns a span of seconds in this format: + * 10 days 14 hours 36 minutes 47 seconds + * + * @access public + * @param integer a number of seconds + * @param integer Unix timestamp + * @return integer + */ +function timespan($seconds = 1, $time = '') +{ + $obj =& get_instance(); + $obj->lang->load('date'); + + if ( ! is_numeric($seconds)) + { + $seconds = 1; + } + + if ( ! is_numeric($time)) + { + $time = time(); + } + + if ($time <= $seconds) + { + $seconds = 1; + } + else + { + $seconds = $time - $seconds; + } + + $str = ''; + $years = floor($seconds / 31536000); + + if ($years > 0) + { + $str .= $years.' '.$obj->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; + } + + $seconds -= $years * 31536000; + $months = floor($seconds / 2628000); + + if ($years > 0 OR $months > 0) + { + if ($months > 0) + { + $str .= $months.' '.$obj->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.' '.$obj->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; + } + + $seconds -= $weeks * 604800; + } + + $days = floor($seconds / 86400); + + if ($months > 0 OR $weeks > 0 OR $days > 0) + { + if ($days > 0) + { + $str .= $days.' '.$obj->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; + } + + $seconds -= $days * 86400; + } + + $hours = floor($seconds / 3600); + + if ($days > 0 OR $hours > 0) + { + if ($hours > 0) + { + $str .= $hours.' '.$obj->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; + } + + $seconds -= $hours * 3600; + } + + $minutes = floor($seconds / 60); + + if ($days > 0 OR $hours > 0 OR $minutes > 0) + { + if ($minutes > 0) + { + $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minutes')).', '; + } + + $seconds -= $minutes * 60; + } + + if ($str == '') + { + $str .= $seconds.' '.$obj->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; + } + + return substr(trim($str), 0, -1); +} + +// ------------------------------------------------------------------------ + +/** + * Number of days in a month + * + * Takes a month/year as input and returns the number of days + * for the given month/year. Takes leap years into consideration. + * + * @access public + * @param integer a numeric month + * @param integer a numeric year + * @return integer + */ +function days_in_month($month = 0, $year = '') +{ + if ($month < 1 OR $month > 12) + { + return 0; + } + + if ( ! ctype_digit($year) OR strlen($year) != 4) + { + $year = date('Y'); + } + + if ($month == 2) + { + 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]; +} + +// ------------------------------------------------------------------------ + +/** + * Converts a local Unix timestamp to GMT + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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)); +} + +// ------------------------------------------------------------------------ + +/** + * Converts GMT time to a localized value + * + * Takes a Unix timestamp (in GMT) as input, and returns + * at the local value based on the timezone and DST setting + * submitted + * + * @access public + * @param integer Unix timestamp + * @param string timezone + * @param bool whether DST is active + * @return integer + */ +function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) +{ + if ($time == '') + { + return now(); + } + + $time += timezones($timezone) * 3600; + + if ($dst == TRUE) + { + $time += 3600; + } + + return $time; +} + +// ------------------------------------------------------------------------ + +/** + * Converts a MySQL Timestamp to Unix + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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) + ); +} + +// ------------------------------------------------------------------------ + +/** + * Unix to "Human" + * + * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM + * + * @access public + * @param integer Unix timestamp + * @param bool whether to show seconds + * @param string format: us or euro + * @return string + */ +function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') +{ + $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; + + if ($fmt == 'us') + { + $r .= date('h', $time).':'.date('i', $time); + } + else + { + $r .= date('H', $time).':'.date('i', $time); + } + + if ($seconds) + { + $r .= ':'.date('s', $time); + } + + if ($fmt == 'us') + { + $r .= ' '.date('A', $time); + } + + return $r; +} + +// ------------------------------------------------------------------------ + +/** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @access public + * @param string format: us or euro + * @return integer + */ +function human_to_unix($datestr = '') +{ + if ($datestr == '') + { + return FALSE; + } + + $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; + } + + $split = preg_split("/\040/", $datestr); + + $ex = explode("-", $split['0']); + + $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; + $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; + + $ex = explode(":", $split['1']); + + $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; + $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + + 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 (substr($ampm, 0, 1) == 'p' AND $hour < 12) + $hour = $hour + 12; + + if (substr($ampm, 0, 1) == 'a' AND $hour == 12) + $hour = '00'; + + if (strlen($hour) == 1) + $hour = '0'.$hour; + } + + return mktime($hour, $min, $sec, $month, $day, $year); +} + +// ------------------------------------------------------------------------ + +/** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @access public + * @param string timezone + * @param string classname + * @param string menu name + * @return string + */ +function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') +{ + $obj =& get_instance(); + $obj->lang->load('date'); + + if ($default == 'GMT') + $default = 'UTC'; + + $menu = '"; + + return $menu; +} + +// ------------------------------------------------------------------------ + +/** + * Timezones + * + * Returns an array of timezones. This is a helper function + * for varios other ones in this library + * + * @access public + * @param string timezone + * @return string + */ +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 + ); + + if ($tz == '') + { + return $zones; + } + + if ($tz == 'GMT') + $tz = 'UTC'; + + 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 new file mode 100644 index 000000000..69eb13d11 --- /dev/null +++ b/system/helpers/directory_helper.php @@ -0,0 +1,69 @@ + \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php new file mode 100644 index 000000000..93bddb029 --- /dev/null +++ b/system/helpers/file_helper.php @@ -0,0 +1,139 @@ + 0) + { + $data = fread($fp, filesize($file)); + } + + flock($fp, LOCK_UN); + fclose($fp); + + return $data; +} + +// ------------------------------------------------------------------------ + +/** + * Write File + * + * Writes data to the file specified in the path. + * Creats a new file if non-existant. + * + * @access public + * @param string path to file + * @param string file data + * @return bool + */ +function write_file($path, $data) +{ + if ( ! $fp = @fopen($path, 'wb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + + return TRUE; +} + +// ------------------------------------------------------------------------ + +/** + * Delete Files + * + * Deletes all files contained in the supplied directory path. + * Files must be writable or owned by the system in order to be deleted. + * If the second parameter is set to TRUE, any direcotries contained + * within the supplied base directory will be nuked as well. + * + * @access public + * @param string path to file + * @param bool whether to delete any directories found in the path + * @return bool + */ +function delete_files($path, $del_dir = FALSE) +{ + // Trim the trailing slahs + $path = preg_replace("|^(.+?)/*$|", "\\1", $path); + + if ( ! $current_dir = @opendir($path)) + return; + + while(FALSE !== ($filename = @readdir($current_dir))) + { + if ($filename != "." and $filename != "..") + { + if (is_dir($path.'/'.$filename)) + { + delete_files($path.'/'.$filename, $del_dir); + } + else + { + unlink($path.'/'.$filename); + } + } + } + @closedir($current_dir); + + if ($del_dir == TRUE) + { + @rmdir($path); + } +} + + +?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php new file mode 100644 index 000000000..f82ad01a0 --- /dev/null +++ b/system/helpers/form_helper.php @@ -0,0 +1,382 @@ +config->site_url($action).'"'; + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @access public + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); +} + +// ------------------------------------------------------------------------ + +/** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or an associative + * array with multiple values. + * + * @access public + * @param mixed + * @param string + * @return string + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Dropdown Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (isset($data['checked'])) + { + $checked = $data['checked']; + + if ($checked == FALSE) + unset($data['checked']); + } + + if ($checked == TRUE) + $defaults['checked'] = ' checked="checked"'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +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); +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +function form_prep($str = '') +{ + if ($str == '') + { + return ''; + } + + return str_replace(array("'", '"'), array("'", """), htmlspecialchars($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @parm array + * @return string + */ +function parse_form_attributes($attributes, $default) +{ + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + foreach ($default as $key => $val) + { + if ($key == 'value') + { + $val = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + +?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php new file mode 100644 index 000000000..1c97dda53 --- /dev/null +++ b/system/helpers/html_helper.php @@ -0,0 +1,76 @@ +".$data.""; +} + +// ------------------------------------------------------------------------ + +/** + * Generates HTML BR tags based on number supplied + * + * @access public + * @param integer + * @return string + */ +function br($num = 1) +{ + return str_repeat("
", $num); +} + +// ------------------------------------------------------------------------ + +/** + * Generates non-breaking space entities based on number supplied + * + * @access public + * @param integer + * @return string + */ +function nbs($num = 1) +{ + return str_repeat(" ", $num); +} + + + +?> \ No newline at end of file diff --git a/system/helpers/index.html b/system/helpers/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/helpers/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php new file mode 100644 index 000000000..918e4ae90 --- /dev/null +++ b/system/helpers/security_helper.php @@ -0,0 +1,112 @@ +input->xss_clean($str, $charset); +} + +// -------------------------------------------------------------------- + +/** + * Hash encode a string + * + * @access public + * @param string + * @return string + */ +function hash($str, $type = 'sha1') +{ + if ($type == 'sha1') + { + if ( ! function_exists('sha1')) + { + if ( ! function_exists('mhash')) + { + require_once(BASEPATH.'libraries/Sha1'.EXT); + $SH = new CI_SHA; + return $SH->generate($str); + } + else + { + return bin2hex(mhash(MHASH_SHA1, $str)); + } + } + else + { + return sha1($str); + } + } + else + { + return md5($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Strip Image Tags + * + * @access public + * @parm string + * @return string + */ +function strip_image_tags($str) +{ + $str = preg_replace("##", "\\1", $str); + $str = preg_replace("##", "\\1", $str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Convert PHP tags to entities + * + * @access public + * @parm string + * @return string + */ +function encode_php_tags($str) +{ + return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); +} + +?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php new file mode 100644 index 000000000..d5a3591f9 --- /dev/null +++ b/system/helpers/string_helper.php @@ -0,0 +1,154 @@ + \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php new file mode 100644 index 000000000..15b5573bf --- /dev/null +++ b/system/helpers/text_helper.php @@ -0,0 +1,386 @@ += $n) + { + return trim($out).$end_char; + } + } +} + +// ------------------------------------------------------------------------ + +/** + * High ASCII to Entities + * + * Converts High ascii text and MS Word special characters to character entities + * + * @access public + * @param string + * @return string + */ +function ascii_to_entities($str) +{ + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { + $out .= $str[$i]; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; +} + +// ------------------------------------------------------------------------ + +/** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @access public + * @param string + * @param bool + * @return string + */ +function entities_to_ascii($str, $all = TRUE) +{ + if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) + { + for ($i = 0, $s = count($matches['0']); $i < $s; $i++) + { + $digits = $matches['1'][$i]; + + $out = ''; + + if ($digits < 128) + { + $out .= chr($digits); + + } + elseif ($digits < 2048) + { + $out .= chr(192 + (($digits - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + else + { + $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); + $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + + $str = str_replace($matches['0'][$i], $out, $str); + } + } + + if ($all) + { + $str = str_replace(array("&", "<", ">", """, "'", "-"), + array("&","<",">","\"", "'", "-"), + $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Word Censoring Function + * + * Supply a string and an array of disallowed words and any + * matched words will be converted to #### or to the replacement + * word you've submitted. + * + * @access public + * @param string the text string + * @param string the array of censoered words + * @param string the optional replacement value + * @return string + */ +function word_censor($str, $censored, $replacement = '') +{ + if ( ! is_array($censored)) + { + return $str; + } + + $str = ' '.$str.' '; + foreach ($censored as $badword) + { + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } + } + + return trim($str); +} + +// ------------------------------------------------------------------------ + +/** + * Code Highlighter + * + * Colorizes code strings + * + * @access public + * @param string the text string + * @return string + */ +function highlight_code($str) +{ + // The highlight string function encodes and highlights + // brackets so we need them to start raw + $str = str_replace(array('<', '>'), array('<', '>'), $str); + + // Replace any existing PHP tags to temporary markers so they don't accidentally + // break the string out of PHP, and thus, thwart the highlighting. + + $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); + + // The highlight_string function requires that the text be surrounded + // by PHP tags. Since we don't know if A) the submitted text has PHP tags, + // or B) whether the PHP tags enclose the entire string, we will add our + // own PHP tags around the string along with some markers to make replacement easier later + + $str = ''; // '), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } + + // Remove our artificially added PHP + $str = preg_replace("#\.+?//tempstart\
\#is", "\n", $str); + $str = preg_replace("#\.+?//tempstart\
#is", "\n", $str); + $str = preg_replace("#//tempend.+#is", "
\n", $str); + + // Replace our markers back to PHP tags. + $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') +{ + if ($str == '') + { + return ''; + } + + if ($phrase != '') + { + return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * + * @access public + * @param string the text string + * @param integer the number of characters to wrap at + * @return string + */ +function word_wrap($str, $chars = '76') +{ + if ( ! ctype_digit($chars)) + $chars = 76; + + $str = preg_replace("/(\r\n|\r|\n)/", "\n", $str); + $lines = split("\n", $str); + + $output = ""; + while (list(, $thisline) = each($lines)) + { + if (strlen($thisline) > $chars) + { + $line = ""; + $words = split(" ", $thisline); + while(list(, $thisword) = each($words)) + { + while((strlen($thisword)) > $chars) + { + $cur_pos = 0; + for($i=0; $i < $chars - 1; $i++) + { + $output .= $thisword[$i]; + $cur_pos++; + } + + $output .= "\n"; + $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos)); + } + + if ((strlen($line) + strlen($thisword)) > $chars) + { + $output .= $line."\n"; + $line = $thisword." "; + } + else + { + $line .= $thisword." "; + } + } + + $output .= $line."\n"; + } + else + { + $output .= $thisline."\n"; + } + } + + return $output; +} + +?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php new file mode 100644 index 000000000..6a5495239 --- /dev/null +++ b/system/helpers/typography_helper.php @@ -0,0 +1,490 @@ +",$str); + $ct = count($ex); + + $newstr = ""; + for ($i = 0; $i < $ct; $i++) + { + if (($i % 2) == 0) + { + $newstr .= nl2br($ex[$i]); + } + else + { + $newstr .= $ex[$i]; + } + + if ($ct - 1 != $i) + $newstr .= "pre>"; + } + + return $newstr; +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Wrapper Function + * + * + * @access public + * @parm string + * @return string + */ +function auto_typography($str) +{ + $TYPE = new Auto_typography(); + return $TYPE->convert($str); +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Class + * + * + * @access private + * @category Helpers + * @author Rick Ellis + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/helpers/ + */ +class Auto_typography { + + // Block level elements that should not be wrapped inside

tags + var $block_elements = 'div|blockquote|pre|code|h\d|script|ol|un'; + + // Elements that should not have

and
tags within them. + var $skip_elements = 'pre|ol|ul'; + + // Tags we want the parser to completely ignore when splitting the string. + var $ignore_elements = 'a|b|i|em|strong|span|img|li'; + + + /** + * Main Processing Function + * + */ + function convert($str) + { + if ($str == '') + { + return ''; + } + + $str = ' '.$str.' '; + + // Standardize Newlines to make matching easier + $str = preg_replace("/(\r\n|\r)/", "\n", $str); + + /* + * Reduce line breaks + * + * If there are more than two consecutive line + * breaks we'll compress them down to a maximum + * of two since there's no benefit to more. + * + */ + $str = preg_replace("/\n\n+/", "\n\n", $str); + + /* + * Convert quotes within tags to tempoarary marker + * + * We don't want quotes converted within + * tags so we'll temporarily convert them to + * {{{DQ}}} and {{{SQ}}} + * + */ + if (preg_match_all("#\<.+?>#si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['0'][$i], + str_replace(array("'",'"'), array('{{{SQ}}}', '{{{DQ}}}'), $matches['0'][$i]), + $str); + } + } + + /* + * Convert "ignore" tags to tempoarary marker + * + * The parser splits out the string at every tag + * it encounters. Certain inline tags, like image + * tags, links, span tags, etc. will be adversely + * affected if they are split out so we'll convert + * the opening < temporarily to: {{{tag}}} + * + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{{{tag}}}\\1\\2", $str); + + /* + * Split the string at every tag + * + * This creates an array with this prototype: + * + * [array] + * { + * [0] = + * [1] = Content contained between the tags + * [2] = + * Etc... + * } + * + */ + $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); + + /* + * Build our finalized string + * + * We'll cycle through the array, skipping tags, + * and processing the contained text + * + */ + $str = ''; + $process = TRUE; + foreach ($chunks as $chunk) + { + /* + * Are we dealing with a tag? + * + * If so, we'll skip the processing for this cycle. + * Well also set the "process" flag which allows us + * to skip

 tags and a few other things.
+			 *
+			 */			
+			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match)) 
+			{
+				if (preg_match("#".$this->skip_elements."#", $match['2']))
+				{
+					$process =  ($match['1'] == '/') ? TRUE : FALSE;		
+				}
+		
+				$str .= $chunk;
+				continue;
+			}
+		
+			if ($process == FALSE)
+			{
+				$str .= $chunk;
+				continue;
+			}
+			
+			//  Convert Newlines into 

and
tags + $str .= $this->format_newlines($chunk); + } + + // Convert Quotes and other characters + $str = $this->format_characters($str); + + // We'll swap our temporary markers back and do some clean up. + $str = preg_replace('#(

\n*

)#', '', $str); + $str = preg_replace('#()

#', "\\1", $str); + + $str = str_replace( + array('

', '

', '{{{tag}}}', '{{{DQ}}}', '{{{SQ}}}'), + array('

', '

', '<', '"', "'"), + $str + ); + + return trim($str); + } + + // -------------------------------------------------------------------- + + /** + * Format Characters + * + * This function mainly converts double and single quotes + * to entities, but since these are directional, it does + * it based on some rules. It also converts em-dashes + * and a couple other things. + */ + function format_characters($str) + { + $table = array( + ' "' => " “", + '" ' => "” ", + " '" => " ‘", + "' " => "’ ", + + '>"' => ">“", + '"<' => "”<", + ">'" => ">‘", + "'<" => "’<", + + "\"." => "”.", + "\"," => "”,", + "\";" => "”;", + "\":" => "”:", + "\"!" => "”!", + "\"?" => "”?", + + ". " => ".  ", + "? " => "?  ", + "! " => "!  ", + ": " => ":  ", + ); + + // These deal with quotes within quotes, like: "'hi here'" + $start = 0; + $space = array("\n", "\t", " "); + + while(TRUE) + { + $current = strpos(substr($str, $start), "\"'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( ! in_array($one_after, $space) && $one_after != "<") + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."“‘".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space) && (in_array($one_after, $space) OR $one_after == '<')) + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."”’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'\""); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( in_array($one_before, $space) && ! in_array($one_after, $space) && $one_after != "<") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."‘“".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space) && $one_before != ">") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."’”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Are there quotes within a word, as in: ("something") + if (preg_match_all("/(.)\"(\S+?)\"(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], + $str); + } + } + } + + if (preg_match_all("/(.)\'(\S+?)\'(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], + $str); + } + } + } + + // How about one apostrophe, as in Rick's + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Em-dashes + $start = 0; + while(TRUE) + { + $current = strpos(substr($str, $start), "--"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + $two_before = substr($str, $start+$current-2, 1); + $two_after = substr($str, $start+$current+3, 1); + + if (( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + OR + ( ! in_array($two_before, $space) && ! in_array($two_after, $space) && $one_before == ' ' && $one_after == ' ') + ) + { + $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, + $two_before.trim($one_before)."—".trim($one_after).$two_after, + $str); + } + + $start = $start+$current+2; + } + + // Ellipsis + $str = preg_replace("#(\w)\.\.\.(\s|
|

)#", "\\1…\\2", $str); + $str = preg_replace("#(\s|
|

)\.\.\.(\w)#", "\\1…\\2", $str); + + // Run the translation array we defined above + $str = str_replace(array_keys($table), array_values($table), $str); + + // If there are any stray double quotes we'll catch them here + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), '"'); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space)) + { + $str = str_replace( $one_before.'"'.$one_after, + $one_before."“".$one_after, + $str); + } + elseif( ! in_array($one_before, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."‘".$one_after, + $str); + } + elseif( ! in_array($one_before, $space)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Format Newlines + * + * Converts newline characters into either

tags or
+ * + */ + function format_newlines($str) + { + if ($str == '') + { + return $str; + } + + if (strpos($str, "\n") === FALSE) + { + return '

'.$str.'

'; + } + + $str = str_replace("\n\n", "

\n\n

", $str); + $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
\\2\\3", $str); + + return '

'.$str.'

'; + } +} + + +?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php new file mode 100644 index 000000000..d2d2a5985 --- /dev/null +++ b/system/helpers/url_helper.php @@ -0,0 +1,487 @@ +config->site_url($uri); +} + +// ------------------------------------------------------------------------ + +/** + * Base URL + * + * Returns the "base_url" item from your config file + * + * @access public + * @return string + */ +function base_url() +{ + $obj =& get_instance(); + return $obj->config->item('base_url', 1); +} + +// ------------------------------------------------------------------------ + +/** + * Index page + * + * Returns the "index_page" from your config file + * + * @access public + * @return string + */ +function index_page() +{ + $obj =& get_instance(); + return $obj->config->item('index_page'); +} + +// ------------------------------------------------------------------------ + +/** + * Anchor Link + * + * Creates an anchor based on the local URL. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +function anchor($uri = '', $title = '', $attributes = '') +{ + $site_url = site_url($uri); + + if ($title == '') + { + $title = $site_url; + } + + if ($attributes == '') + { + $attributes = ' title="'.$title.'"'; + } + else + { + if (is_array($attributes)) + { + $attributes = parse_url_attributes($attributes); + } + } + + return ''.$title.''; +} + +// ------------------------------------------------------------------------ + +/** + * Anchor Link - Pop-up version + * + * Creates an anchor based on the local URL. The link + * opens a new window based on the attributes specified. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +function anchor_popup($uri = '', $title = '', $attributes = FALSE) +{ + $site_url = site_url($uri); + + if ($title == '') + { + $title = $site_url; + } + + if ($attributes === FALSE) + { + return "".$title.""; + } + + 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]; + } + + return "".$title.""; +} + +// ------------------------------------------------------------------------ + +/** + * Mailto Link + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +function mailto($email, $title = '', $attributes = '') +{ + if ($title == "") + { + $title = $email; + } + + if (is_array($attributes)) + { + $attributes = parse_url_attributes($attributes); + } + + return ''.$title.''; +} + +// ------------------------------------------------------------------------ + +/** + * Encoded Mailto Link + * + * Create a spam-protected mailto link written in Javascript + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +function safe_mailto($email, $title = '', $attributes = '') +{ + if ($title == "") + { + $title = $email; + } + + for ($i = 0; $i < 16; $i++) + { + $x[] = substr(' $val) + { + $x[] = ' '.$key.'="'; + for ($i = 0; $i < strlen($val); $i++) + { + $x[] = "|".ord(substr($val, $i, 1)); + } + $x[] = '"'; + } + } + 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]); + + if ($ordinal < 128) + { + $x[] = "|".$ordinal; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + $x[] = "|".$number; + $count = 1; + $temp = array(); + } + } + } + + $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; + + $x = array_reverse($x); + ob_start(); + +?>http'. + $matches['4'][$i].'://'. + $matches['5'][$i]. + $matches['6'][$i].''. + $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++) + { + $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); + } + + } + } + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Prep URL + * + * Simply adds the http:// part if missing + * + * @access public + * @param string the URL + * @return string + */ +function prep_url($str = '') +{ + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with either a dash + * or an underscore as the word separator. + * + * @access public + * @param string the string + * @param string the separator: dash, or underscore + * @return string + */ +function url_title($str, $separator = 'dash') +{ + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } + + $trans = array( + $search => $replace, + "\s+" => $replace, + "[^a-z0-9".$replace."]" => '', + $replace."+" => $replace, + $replace."$" => '', + "^".$replace => '' + ); + + $str = strip_tags(strtolower($str)); + + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#", $val, $str); + } + + return trim(stripslashes($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Header Redirect + * + * Header redirect in two flavors + * + * @access public + * @param string the URL + * @param string the method: location or redirect + * @return string + */ +function redirect($uri = '', $method = 'location') +{ + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("location:".site_url($uri)); + break; + } + exit; +} + +// ------------------------------------------------------------------------ + +/** + * Parse out the attributes + * + * Some of the functions use this + * + * @access private + * @param array + * @param bool + * @return string + */ +function parse_url_attributes($attributes, $javascript = FALSE) +{ + $att = ''; + foreach ($attributes as $key => $val) + { + if ($javascript == TRUE) + { + $att .= $key . '=' . $val . ','; + } + else + { + $att .= ' ' . $key . '="' . $val . '"'; + } + } + + if ($javascript == TRUE) + { + $att = substr($att, 0, -1); + } + + return $att; +} + +?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php new file mode 100644 index 000000000..ee3fc289b --- /dev/null +++ b/system/helpers/xml_helper.php @@ -0,0 +1,55 @@ +","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b071bb5a92aade551345a495fb13f5678f3978d0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 19:28:37 +0000 Subject: --- system/helpers/form_helper.php | 2 +- system/helpers/url_helper.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index f82ad01a0..d4e45a0af 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -326,7 +326,7 @@ function form_close($extra = '') */ function form_prep($str = '') { - if ($str == '') + if ($str === '') { return ''; } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d2d2a5985..03d6c3b2c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -90,7 +90,7 @@ function index_page() */ function anchor($uri = '', $title = '', $attributes = '') { - $site_url = site_url($uri); + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') { @@ -128,7 +128,7 @@ function anchor($uri = '', $title = '', $attributes = '') */ function anchor_popup($uri = '', $title = '', $attributes = FALSE) { - $site_url = site_url($uri); + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') { -- cgit v1.2.3-24-g4f1b From 141808ad31d4eefad4c6c3dbaf8306fac2342668 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 01:52:51 +0000 Subject: --- system/helpers/form_helper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d4e45a0af..069101063 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -38,11 +38,16 @@ * @param array a key/value pair hidden data * @return string */ -function form_open($action, $attributes = array(), $hidden = array()) +function form_open($action = '', $attributes = array(), $hidden = array()) { $obj =& get_instance(); - $form = '
config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } if (is_array($attributes) AND count($attributes) > 0) { -- cgit v1.2.3-24-g4f1b From 57b3d39cb79bb3b8d193e0e345a62e3396e519f2 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:28:31 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 069101063..eb97913f1 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -247,7 +247,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - if (isset($data['checked'])) + if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; @@ -256,7 +256,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') } if ($checked == TRUE) - $defaults['checked'] = ' checked="checked"'; + $defaults['checked'] = 'checked'; else unset($defaults['checked']); -- cgit v1.2.3-24-g4f1b From eb6db84333c40ed8d15dec5014564120ee0c60e6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 02:39:45 +0000 Subject: --- system/helpers/date_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 2a3d50859..c8205bb7d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -189,7 +189,7 @@ function timespan($seconds = 1, $time = '') { if ($minutes > 0) { - $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minutes')).', '; + $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } $seconds -= $minutes * 60; -- cgit v1.2.3-24-g4f1b From 2ed76d5ac89ec7869dcb64c050360fb2f99e9326 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 2 Sep 2006 17:34:52 +0000 Subject: --- system/helpers/file_helper.php | 4 ++-- system/helpers/url_helper.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 93bddb029..32c0b2cdc 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -75,9 +75,9 @@ function read_file($file) * @param string file data * @return bool */ -function write_file($path, $data) +function write_file($path, $data, $mode = 'wb') { - if ( ! $fp = @fopen($path, 'wb')) + if ( ! $fp = @fopen($path, $mode)) { return FALSE; } diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 03d6c3b2c..09169e32e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -56,7 +56,7 @@ function site_url($uri = '') function base_url() { $obj =& get_instance(); - return $obj->config->item('base_url', 1); + return $obj->config->slash_item('base_url'); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 1cf89aab5fff8c8068cbf0ed18038b6e4fd4f605 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 3 Sep 2006 18:24:39 +0000 Subject: --- system/helpers/date_helper.php | 2 +- system/helpers/text_helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index c8205bb7d..ab3a31867 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -223,7 +223,7 @@ function days_in_month($month = 0, $year = '') return 0; } - if ( ! ctype_digit($year) OR strlen($year) != 4) + if ( ! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 15b5573bf..e4f816eb1 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -333,7 +333,7 @@ function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '< */ function word_wrap($str, $chars = '76') { - if ( ! ctype_digit($chars)) + if ( ! is_numeric($chars)) $chars = 76; $str = preg_replace("/(\r\n|\r|\n)/", "\n", $str); -- cgit v1.2.3-24-g4f1b From 73e582fbd7d7f6cdcf7f18b31b4b96ecb7c4141f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 01:36:34 +0000 Subject: --- system/helpers/security_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 918e4ae90..f14ba72a0 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -50,7 +50,7 @@ function xss_clean($str, $charset = 'ISO-8859-1') * @param string * @return string */ -function hash($str, $type = 'sha1') +function dohash($str, $type = 'sha1') { if ($type == 'sha1') { -- cgit v1.2.3-24-g4f1b From 4d07c1528873d70efcb6fbf305a8ab930a9bc758 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 Sep 2006 02:14:53 +0000 Subject: --- system/helpers/url_helper.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 09169e32e..6e2f7f452 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -90,7 +90,14 @@ function index_page() */ function anchor($uri = '', $title = '', $attributes = '') { - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + if ( ! is_array($uri)) + { + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + } + else + { + $site_url = site_url($uri); + } if ($title == '') { -- cgit v1.2.3-24-g4f1b From 402ddf4859c4e0691aa3eed7d57ad6d1b0a21a9b Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 18:57:05 +0000 Subject: --- system/helpers/array_helper.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index cccde1fc4..de0faeeff 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -27,6 +27,30 @@ // ------------------------------------------------------------------------ +/** + * Element + * + * Lets you determine whether an array index is set and whether it has a value. + * If the element is empty it returns FALSE (or whater you specify as the default value.) + * + * @access public + * @param string + * @param array + * @param mixed + * @return mixed depends on what the array contains + */ +function element($item, $array, $default = FALSE) +{ + if ( ! isset($array[$item]) OR $array[$item] == "") + { + return $default; + } + + return $array[$item]; +} + +// ------------------------------------------------------------------------ + /** * Random Element - Takes an array as input and returns a random element * -- cgit v1.2.3-24-g4f1b From 5b179b55d389282e5097451e6b6a707baee0522c Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 20 Sep 2006 23:44:53 +0000 Subject: --- system/helpers/inflector_helper.php | 140 ++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 system/helpers/inflector_helper.php (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php new file mode 100644 index 000000000..3bded708e --- /dev/null +++ b/system/helpers/inflector_helper.php @@ -0,0 +1,140 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bc042dd0692a6b4b89f11f88e6e3763162ce8048 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 02:46:59 +0000 Subject: --- system/helpers/text_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index e4f816eb1..e2da32746 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -266,7 +266,7 @@ function highlight_code($str) // 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 = ''; // '; // All the magic happens here, baby! $str = highlight_string($str, TRUE); -- cgit v1.2.3-24-g4f1b From 885b0343036695ad673fc24ba7682fc155c54036 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 05:36:15 +0000 Subject: --- system/helpers/cookie_helper.php | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 24e243ddd..fc5920f25 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -55,6 +55,22 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = } } + // Set the config file options + $obj =& get_instance(); + + if ($prefix == '' AND $obj->config->item('cookie_prefix') != '') + { + $obj->config->item('cookie_prefix'); + } + if ($domain == '' AND $obj->config->item('cookie_domain') != '') + { + $obj->config->item('cookie_domain'); + } + if ($prefix == '/' AND $obj->config->item('cookie_path') != '/') + { + $obj->config->item('cookie_path'); + } + if ( ! is_numeric($expire)) { $expire = time() - 86500; @@ -73,5 +89,38 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = setcookie($prefix.$name, $value, $expire, $path, $domain, 0); } + +// -------------------------------------------------------------------- + +/** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @param bool + * @return mixed + */ +function get_cookie($index = '', $xss_clean = FALSE) +{ + $obj =& get_instance(); + return $obj->input->cookie($index, $xss_clean); +} + +// -------------------------------------------------------------------- + +/** + * Delete a COOKIE + * + * @param mixed + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @return void + */ +function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') +{ + set_cookie($name, '', '', $domain, $path, $prefix); +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 592cdcbc58963f0cf811aea59db9907943460770 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 22 Sep 2006 18:45:42 +0000 Subject: --- system/helpers/inflector_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 3bded708e..3d8d3e0ca 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -31,7 +31,7 @@ /** * Singular * - * Takes a plural word and makes it singular + * Takes a singular word and makes it plural * * @access public * @param string @@ -64,7 +64,7 @@ function singular($str) /** * Plural * - * Takes a singular word and makes it plural + * Takes a plural word and makes it singular * * @access public * @param string -- cgit v1.2.3-24-g4f1b From ee54c112bfb488f833fa032758b817e1bb2c1d7d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 17:13:38 +0000 Subject: --- system/helpers/typography_helper.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 6a5495239..65924f911 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -275,13 +275,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+2, 1); - if ( ! in_array($one_after, $space) && $one_after != "<") + if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") { $str = str_replace( $one_before."\"'".$one_after, $one_before."“‘".$one_after, $str); } - elseif ( ! in_array($one_before, $space) && (in_array($one_after, $space) OR $one_after == '<')) + elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) { $str = str_replace( $one_before."\"'".$one_after, $one_before."”’".$one_after, @@ -302,13 +302,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+2, 1); - if ( in_array($one_before, $space) && ! in_array($one_after, $space) && $one_after != "<") + if ( in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE) && $one_after != "<") { $str = str_replace( $one_before."'\"".$one_after, $one_before."‘“".$one_after, $str); } - elseif ( ! in_array($one_before, $space) && $one_before != ">") + elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") { $str = str_replace( $one_before."'\"".$one_after, $one_before."’”".$one_after, @@ -323,7 +323,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], @@ -336,7 +336,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space) && ! in_array($matches['3'][$i], $space)) + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], @@ -357,7 +357,7 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, @@ -380,9 +380,9 @@ class Auto_typography { $two_before = substr($str, $start+$current-2, 1); $two_after = substr($str, $start+$current+3, 1); - if (( ! in_array($one_before, $space) && ! in_array($one_after, $space)) + if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) OR - ( ! in_array($two_before, $space) && ! in_array($two_after, $space) && $one_before == ' ' && $one_after == ' ') + ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') ) { $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, @@ -413,13 +413,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space)) + if ( ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before.'"'.$one_after, $one_before."“".$one_after, $str); } - elseif( ! in_array($one_before, $space)) + elseif( ! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."”".$one_after, @@ -440,13 +440,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space)) + if ( ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."‘".$one_after, $str); } - elseif( ! in_array($one_before, $space)) + elseif( ! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, -- cgit v1.2.3-24-g4f1b From 78ce3cc370efc9d63b3d473deb37c92f40002d3d Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 02:58:03 +0000 Subject: --- system/helpers/file_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 32c0b2cdc..4c7eaa54e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -42,6 +42,11 @@ function read_file($file) { return FALSE; } + + if (function_exists('file_get_contents')) + { + return file_get_contents($file); + } if ( ! $fp = @fopen($file, 'rb')) { @@ -53,7 +58,7 @@ function read_file($file) $data = ''; if (filesize($file) > 0) { - $data = fread($fp, filesize($file)); + $data =& fread($fp, filesize($file)); } flock($fp, LOCK_UN); -- cgit v1.2.3-24-g4f1b From e8f6eb62a0600daf5b192746e1eed3e81516bc92 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 06:46:16 +0000 Subject: --- system/helpers/date_helper.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index ab3a31867..987658c2e 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -92,7 +92,43 @@ function mdate($datestr = '', $time = '') // ------------------------------------------------------------------------ /** - * Convert MySQL Style Datecodes + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * @access public + * @param string the chosen format + * @param integer Unix timestamp + * @return string + */ +function standard_date($fmt = 'DATE_RFC822', $time = '') +{ + $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_RFC2822' => '%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); +} + + +// ------------------------------------------------------------------------ + +/** + * Timespan * * Returns a span of seconds in this format: * 10 days 14 hours 36 minutes 47 seconds -- cgit v1.2.3-24-g4f1b From b8afd045b9ed165bdae0d18b3e6f7483a4566e1c Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 06:46:29 +0000 Subject: --- system/helpers/download_helper.php | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 system/helpers/download_helper.php (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php new file mode 100644 index 000000000..8d9fee478 --- /dev/null +++ b/system/helpers/download_helper.php @@ -0,0 +1,96 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 02855e0a5ca144b8b01be2a49cb2780cf5abf653 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:46:15 +0000 Subject: --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 4c7eaa54e..c0f525688 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -112,7 +112,7 @@ function write_file($path, $data, $mode = 'wb') */ function delete_files($path, $del_dir = FALSE) { - // Trim the trailing slahs + // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); if ( ! $current_dir = @opendir($path)) -- cgit v1.2.3-24-g4f1b From 078fb91f6b58233066d96a3ff0b4cde19d8e4db2 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:50:05 +0000 Subject: --- system/helpers/user_agent_helper.php | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 system/helpers/user_agent_helper.php (limited to 'system/helpers') diff --git a/system/helpers/user_agent_helper.php b/system/helpers/user_agent_helper.php new file mode 100644 index 000000000..3c6085e77 --- /dev/null +++ b/system/helpers/user_agent_helper.php @@ -0,0 +1,89 @@ + 'Windows Longhorn', + 'windows nt 5.2' => 'Windows 2003', + 'windows nt 5.0' => 'Windows 2000', + 'windows nt 5.1' => 'Windows XP', + 'windows nt 4.0' => 'Windows NT 4.0', + 'winnt4.0' => 'Windows NT 4.0', + 'winnt 4.0' => 'Windows NT', + 'winnt' => 'Windows NT', + 'windows 98' => 'Windows 98', + 'win98' => 'Windows 98', + 'windows 95' => 'Windows 95', + 'win95' => 'Windows 95', + 'windows' => 'Unknown Windows OS', + 'mac os x' => 'Mac OS X', + 'freebsd' => 'FreeBSD', + 'ppc' => 'Macintosh', + 'sunos' => 'Sun Solaris', + 'linux' => 'Linux', + 'debian' => 'Debian', + 'beos' => 'BeOS', + 'apachebench' => 'ApacheBench', + 'aix' => 'AIX', + 'irix' => 'Irix', + 'osf' => 'DEC OSF', + 'hp-ux' => 'HP-UX', + 'netbsd' => 'NetBSD', + 'bsdi' => 'BSDi', + 'openbsd' => 'OpenBSD', + 'gnu' => 'GNU/Linux', + 'unix' => 'Unknown Unix OS' + ); + + + foreach ($os as $key => $val) + { + if (preg_match("|$key|i", $_SERVER['HTTP_USER_AGENT'])) + { + return $val; + } + } + + return 'Unknown OS'; +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 75198f97ba9df6e5696ac295820d9d73a4e4f441 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:16:53 +0000 Subject: --- system/helpers/cookie_helper.php | 18 +++++++++--------- system/helpers/date_helper.php | 28 ++++++++++++++-------------- system/helpers/form_helper.php | 4 ++-- system/helpers/security_helper.php | 4 ++-- system/helpers/url_helper.php | 12 ++++++------ 5 files changed, 33 insertions(+), 33 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index fc5920f25..8985fae2e 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -56,19 +56,19 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = } // Set the config file options - $obj =& get_instance(); + $CI =& get_instance(); - if ($prefix == '' AND $obj->config->item('cookie_prefix') != '') + if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') { - $obj->config->item('cookie_prefix'); + $CI->config->item('cookie_prefix'); } - if ($domain == '' AND $obj->config->item('cookie_domain') != '') + if ($domain == '' AND $CI->config->item('cookie_domain') != '') { - $obj->config->item('cookie_domain'); + $CI->config->item('cookie_domain'); } - if ($prefix == '/' AND $obj->config->item('cookie_path') != '/') + if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') { - $obj->config->item('cookie_path'); + $CI->config->item('cookie_path'); } if ( ! is_numeric($expire)) @@ -102,8 +102,8 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = */ function get_cookie($index = '', $xss_clean = FALSE) { - $obj =& get_instance(); - return $obj->input->cookie($index, $xss_clean); + $CI =& get_instance(); + return $CI->input->cookie($index, $xss_clean); } // -------------------------------------------------------------------- diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 987658c2e..03519e686 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -37,9 +37,9 @@ */ function now() { - $obj =& get_instance(); + $CI =& get_instance(); - if (strtolower($obj->config->item('time_reference')) == 'gmt') + if (strtolower($CI->config->item('time_reference')) == 'gmt') { $now = time(); $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); @@ -140,8 +140,8 @@ function standard_date($fmt = 'DATE_RFC822', $time = '') */ function timespan($seconds = 1, $time = '') { - $obj =& get_instance(); - $obj->lang->load('date'); + $CI =& get_instance(); + $CI->lang->load('date'); if ( ! is_numeric($seconds)) { @@ -167,7 +167,7 @@ function timespan($seconds = 1, $time = '') if ($years > 0) { - $str .= $years.' '.$obj->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; + $str .= $years.' '.$CI->lang->line((($years > 1) ? 'date_years' : 'date_year')).', '; } $seconds -= $years * 31536000; @@ -177,7 +177,7 @@ function timespan($seconds = 1, $time = '') { if ($months > 0) { - $str .= $months.' '.$obj->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; + $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; } $seconds -= $months * 2628000; @@ -189,7 +189,7 @@ function timespan($seconds = 1, $time = '') { if ($weeks > 0) { - $str .= $weeks.' '.$obj->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; + $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; } $seconds -= $weeks * 604800; @@ -201,7 +201,7 @@ function timespan($seconds = 1, $time = '') { if ($days > 0) { - $str .= $days.' '.$obj->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; + $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; } $seconds -= $days * 86400; @@ -213,7 +213,7 @@ function timespan($seconds = 1, $time = '') { if ($hours > 0) { - $str .= $hours.' '.$obj->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; + $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; } $seconds -= $hours * 3600; @@ -225,7 +225,7 @@ function timespan($seconds = 1, $time = '') { if ($minutes > 0) { - $str .= $minutes.' '.$obj->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; + $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; } $seconds -= $minutes * 60; @@ -233,7 +233,7 @@ function timespan($seconds = 1, $time = '') if ($str == '') { - $str .= $seconds.' '.$obj->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; + $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; } return substr(trim($str), 0, -1); @@ -475,8 +475,8 @@ function human_to_unix($datestr = '') */ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { - $obj =& get_instance(); - $obj->lang->load('date'); + $CI =& get_instance(); + $CI->lang->load('date'); if ($default == 'GMT') $default = 'UTC'; @@ -493,7 +493,7 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') foreach (timezones() as $key => $val) { $selected = ($default == $key) ? " selected='selected'" : ''; - $menu .= "\n"; + $menu .= "\n"; } $menu .= ""; diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index eb97913f1..3fd361041 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,9 +40,9 @@ */ function form_open($action = '', $attributes = array(), $hidden = array()) { - $obj =& get_instance(); + $CI =& get_instance(); - $form = 'config->site_url($action).'"'; if ( ! isset($attributes['method'])) { diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index f14ba72a0..347cab427 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -37,8 +37,8 @@ */ function xss_clean($str, $charset = 'ISO-8859-1') { - $obj =& get_instance(); - return $obj->input->xss_clean($str, $charset); + $CI =& get_instance(); + return $CI->input->xss_clean($str, $charset); } // -------------------------------------------------------------------- diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 6e2f7f452..2f93bcfbf 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -39,8 +39,8 @@ */ function site_url($uri = '') { - $obj =& get_instance(); - return $obj->config->site_url($uri); + $CI =& get_instance(); + return $CI->config->site_url($uri); } // ------------------------------------------------------------------------ @@ -55,8 +55,8 @@ function site_url($uri = '') */ function base_url() { - $obj =& get_instance(); - return $obj->config->slash_item('base_url'); + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); } // ------------------------------------------------------------------------ @@ -71,8 +71,8 @@ function base_url() */ function index_page() { - $obj =& get_instance(); - return $obj->config->item('index_page'); + $CI =& get_instance(); + return $CI->config->item('index_page'); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From d54078fff55f74ee4fd320b27f8129b48bdcd3fa Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:38:16 +0000 Subject: --- system/helpers/typography_helper.php | 72 +++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 65924f911..84ca0ed6f 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -129,7 +129,7 @@ class Auto_typography { * * We don't want quotes converted within * tags so we'll temporarily convert them to - * {{{DQ}}} and {{{SQ}}} + * {@DQ} and {@SQ} * */ if (preg_match_all("#\<.+?>#si", $str, $matches)) @@ -137,11 +137,24 @@ class Auto_typography { for ($i = 0; $i < count($matches['0']); $i++) { $str = str_replace($matches['0'][$i], - str_replace(array("'",'"'), array('{{{SQ}}}', '{{{DQ}}}'), $matches['0'][$i]), + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), $str); } } - + + + /* + * Add closing/opening paragraph tags before/after "block" elements + * + * Since block elements (like ,
, etc.) do not get
+		 * wrapped in paragraph tags we will add a closing 

tag just before + * each block element starts and an opening

tag right after the block element + * ends. Later on we'll do some further clean up. + * + */ + $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

\\1\\2\\3", $str); + $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

", $str); + /* * Convert "ignore" tags to tempoarary marker * @@ -149,10 +162,10 @@ class Auto_typography { * it encounters. Certain inline tags, like image * tags, links, span tags, etc. will be adversely * affected if they are split out so we'll convert - * the opening < temporarily to: {{{tag}}} + * the opening < temporarily to: {@TAG} * - */ - $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{{{tag}}}\\1\\2", $str); + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); /* * Split the string at every tag @@ -188,7 +201,7 @@ class Auto_typography { * Well also set the "process" flag which allows us * to skip

 tags and a few other things.
 			 *
-			 */			
+			 */
 			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match)) 
 			{
 				if (preg_match("#".$this->skip_elements."#", $match['2']))
@@ -210,20 +223,51 @@ class Auto_typography {
 			$str .= $this->format_newlines($chunk);
 		}
 
+
+		/*
+		 * Clean up paragraph tags before/after "block" elements
+		 *
+		 * Earlier we added 

tags before/after block level elements. + * Then, we added paragraph tags around double line breaks. This + * potentially created incorrectly formatted paragraphs so we'll + * clean it up here. + * + */ + $str = preg_replace("#

({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); + $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

#", "\\1\\2\\3", $str); + // Convert Quotes and other characters $str = $this->format_characters($str); - - // We'll swap our temporary markers back and do some clean up. + + // Final clean up $str = preg_replace('#(

\n*

)#', '', $str); $str = preg_replace('#()

#', "\\1", $str); - + $str = str_replace( - array('

', '

', '{{{tag}}}', '{{{DQ}}}', '{{{SQ}}}'), - array('

', '

', '<', '"', "'"), + array( + '

', + '

', + '

', + '

', + '{@TAG}', + '{@DQ}', + '{@SQ}', + '

' + ), + array( + '

', + '

', + '

', + '

', + '<', + '"', + "'", + '' + ), $str - ); + ); - return trim($str); + return $str; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f4c010098af532d9eb843743ef6bb8ed05689765 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:53:22 +0000 Subject: --- system/helpers/typography_helper.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 84ca0ed6f..ba6804873 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -223,7 +223,9 @@ class Auto_typography { $str .= $this->format_newlines($chunk); } - + // FINAL CLEAN UP + // IMPORTANT: DO NOT ALTER THE ORDER OF THE ITEMS BELOW! + /* * Clean up paragraph tags before/after "block" elements * @@ -239,10 +241,14 @@ class Auto_typography { // Convert Quotes and other characters $str = $this->format_characters($str); - // Final clean up + // Fix an artifact that happens during the paragraph replacement $str = preg_replace('#(

\n*

)#', '', $str); + + // If the user submitted their own paragraph tags with class data + // in them we will retain them instead of using our tags. $str = preg_replace('#()

#', "\\1", $str); + // Final clean up $str = str_replace( array( '

', -- cgit v1.2.3-24-g4f1b From 9fcc28a29299fbbc242f87bf1b1e61fda6543886 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 17:49:47 +0000 Subject: --- system/helpers/file_helper.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index c0f525688..635ef1ba0 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -110,7 +110,7 @@ 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) +function delete_files($path, $del_dir = FALSE, $level = 0) { // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); @@ -124,7 +124,8 @@ function delete_files($path, $del_dir = FALSE) { if (is_dir($path.'/'.$filename)) { - delete_files($path.'/'.$filename, $del_dir); + $level++; + delete_files($path.'/'.$filename, $del_dir, $level); } else { @@ -134,7 +135,7 @@ function delete_files($path, $del_dir = FALSE) } @closedir($current_dir); - if ($del_dir == TRUE) + if ($del_dir == TRUE AND $level > 0) { @rmdir($path); } -- cgit v1.2.3-24-g4f1b From e7e1dcd452a15abaaa01c03cd1ade564e3a59453 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 18:04:01 +0000 Subject: --- system/helpers/array_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index de0faeeff..8adbd8548 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -31,7 +31,7 @@ * Element * * Lets you determine whether an array index is set and whether it has a value. - * If the element is empty it returns FALSE (or whater you specify as the default value.) + * If the element is empty it returns FALSE (or whatever you specify as the default value.) * * @access public * @param string diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 69eb13d11..4b7a383b2 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -28,7 +28,7 @@ // ------------------------------------------------------------------------ /** - * Create a Direcotry Map + * Create a Directory Map * * Reads the specified directory and builds an array * representation of it. Sub-folders contained with the -- cgit v1.2.3-24-g4f1b From fafe28bec4f414e48f63e01ed9105ae5c2c99802 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:08:17 +0000 Subject: --- system/helpers/date_helper.php | 2 +- system/helpers/file_helper.php | 4 +- system/helpers/form_helper.php | 4 +- system/helpers/security_helper.php | 8 ++-- system/helpers/typography_helper.php | 6 +-- system/helpers/user_agent_helper.php | 89 ------------------------------------ 6 files changed, 12 insertions(+), 101 deletions(-) delete mode 100644 system/helpers/user_agent_helper.php (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 03519e686..911862423 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -507,7 +507,7 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') * Timezones * * Returns an array of timezones. This is a helper function - * for varios other ones in this library + * for various other ones in this library * * @access public * @param string timezone diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 635ef1ba0..7a04324e4 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -73,7 +73,7 @@ function read_file($file) * Write File * * Writes data to the file specified in the path. - * Creats a new file if non-existant. + * Creates a new file if non-existent. * * @access public * @param string path to file @@ -102,7 +102,7 @@ function write_file($path, $data, $mode = 'wb') * * Deletes all files contained in the supplied directory path. * Files must be writable or owned by the system in order to be deleted. - * If the second parameter is set to TRUE, any direcotries contained + * If the second parameter is set to TRUE, any directories contained * within the supplied base directory will be nuked as well. * * @access public diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 3fd361041..e12d89319 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -204,7 +204,7 @@ function form_textarea($data = '', $value = '', $extra = '') // ------------------------------------------------------------------------ /** - * Dropdown Menu + * Drop-down Menu * * @access public * @param string @@ -348,7 +348,7 @@ function form_prep($str = '') * * @access private * @param array - * @parm array + * @param array * @return string */ function parse_form_attributes($attributes, $default) diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 347cab427..34386ffea 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -31,8 +31,8 @@ * XSS Filtering * * @access public - * @parm string - * @parm string the character set of your data + * @param string + * @param string the character set of your data * @return string */ function xss_clean($str, $charset = 'ISO-8859-1') @@ -84,7 +84,7 @@ function dohash($str, $type = 'sha1') * Strip Image Tags * * @access public - * @parm string + * @param string * @return string */ function strip_image_tags($str) @@ -101,7 +101,7 @@ function strip_image_tags($str) * Convert PHP tags to entities * * @access public - * @parm string + * @param string * @return string */ function encode_php_tags($str) diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index ba6804873..fe9e3bb92 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -65,7 +65,7 @@ function nl2br_except_pre($str) * * * @access public - * @parm string + * @param string * @return string */ function auto_typography($str) @@ -125,7 +125,7 @@ class Auto_typography { $str = preg_replace("/\n\n+/", "\n\n", $str); /* - * Convert quotes within tags to tempoarary marker + * Convert quotes within tags to temporary marker * * We don't want quotes converted within * tags so we'll temporarily convert them to @@ -156,7 +156,7 @@ class Auto_typography { $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

", $str); /* - * Convert "ignore" tags to tempoarary marker + * Convert "ignore" tags to temporary marker * * The parser splits out the string at every tag * it encounters. Certain inline tags, like image diff --git a/system/helpers/user_agent_helper.php b/system/helpers/user_agent_helper.php deleted file mode 100644 index 3c6085e77..000000000 --- a/system/helpers/user_agent_helper.php +++ /dev/null @@ -1,89 +0,0 @@ - 'Windows Longhorn', - 'windows nt 5.2' => 'Windows 2003', - 'windows nt 5.0' => 'Windows 2000', - 'windows nt 5.1' => 'Windows XP', - 'windows nt 4.0' => 'Windows NT 4.0', - 'winnt4.0' => 'Windows NT 4.0', - 'winnt 4.0' => 'Windows NT', - 'winnt' => 'Windows NT', - 'windows 98' => 'Windows 98', - 'win98' => 'Windows 98', - 'windows 95' => 'Windows 95', - 'win95' => 'Windows 95', - 'windows' => 'Unknown Windows OS', - 'mac os x' => 'Mac OS X', - 'freebsd' => 'FreeBSD', - 'ppc' => 'Macintosh', - 'sunos' => 'Sun Solaris', - 'linux' => 'Linux', - 'debian' => 'Debian', - 'beos' => 'BeOS', - 'apachebench' => 'ApacheBench', - 'aix' => 'AIX', - 'irix' => 'Irix', - 'osf' => 'DEC OSF', - 'hp-ux' => 'HP-UX', - 'netbsd' => 'NetBSD', - 'bsdi' => 'BSDi', - 'openbsd' => 'OpenBSD', - 'gnu' => 'GNU/Linux', - 'unix' => 'Unknown Unix OS' - ); - - - foreach ($os as $key => $val) - { - if (preg_match("|$key|i", $_SERVER['HTTP_USER_AGENT'])) - { - return $val; - } - } - - return 'Unknown OS'; -} - - -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- system/helpers/array_helper.php | 4 +-- system/helpers/cookie_helper.php | 10 +++--- system/helpers/date_helper.php | 32 ++++++++--------- system/helpers/directory_helper.php | 20 +++++------ system/helpers/download_helper.php | 8 ++--- system/helpers/file_helper.php | 14 ++++---- system/helpers/form_helper.php | 10 +++--- system/helpers/html_helper.php | 4 +-- system/helpers/inflector_helper.php | 4 +-- system/helpers/security_helper.php | 8 ++--- system/helpers/string_helper.php | 20 +++++------ system/helpers/text_helper.php | 68 ++++++++++++++++++------------------ system/helpers/typography_helper.php | 32 ++++++++--------- system/helpers/url_helper.php | 38 ++++++++++---------- system/helpers/xml_helper.php | 6 ++-- 15 files changed, 139 insertions(+), 139 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 8adbd8548..491c61577 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 8985fae2e..b117816e2 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Code Igniter Cookie Helpers - * + * * @package CodeIgniter * @subpackage Helpers * @category Helpers @@ -30,7 +30,7 @@ /** * Set cookie * - * Accepts six parameter, or you can submit an associative + * Accepts six parameter, or you can submit an associative * array in the first parameter containing all the values. * * @access public @@ -43,7 +43,7 @@ * @return void */ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') -{ +{ if (is_array($name)) { foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 911862423..b8df03edb 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -39,10 +39,10 @@ function now() { $CI =& get_instance(); - if (strtolower($CI->config->item('time_reference')) == 'gmt') + if (strtolower($CI->config->item('time_reference')) == 'gmt') { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + $now = time(); + $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); if (strlen($system_time) < 10) { @@ -130,7 +130,7 @@ function standard_date($fmt = 'DATE_RFC822', $time = '') /** * Timespan * - * Returns a span of seconds in this format: + * Returns a span of seconds in this format: * 10 days 14 hours 36 minutes 47 seconds * * @access public @@ -244,7 +244,7 @@ function timespan($seconds = 1, $time = '') /** * Number of days in a month * - * Takes a month/year as input and returns the number of days + * Takes a month/year as input and returns the number of days * for the given month/year. Takes leap years into consideration. * * @access public @@ -265,7 +265,7 @@ function days_in_month($month = 0, $year = '') } if ($month == 2) - { + { if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) { return 29; @@ -290,7 +290,7 @@ 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)); } // ------------------------------------------------------------------------ @@ -335,7 +335,7 @@ function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) * @return integer */ 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 @@ -345,7 +345,7 @@ function mysql_to_unix($time = '') $time = str_replace(' ', '', $time); // YYYYMMDDHHMMSS - return mktime( + return mktime( substr($time, 8, 2), substr($time, 10, 2), substr($time, 12, 2), @@ -422,13 +422,13 @@ function human_to_unix($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']; - $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']; @@ -515,10 +515,10 @@ function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') */ function timezones($tz = '') { - // Note: Don't change the order of these even though + // Note: Don't change the order of these even though // some items appear to be in the wrong order - $zones = array( + $zones = array( 'UM12' => -12, 'UM11' => -11, 'UM10' => -10, @@ -548,7 +548,7 @@ function timezones($tz = '') 'UP85' => +8.5, 'UP10' => +10, 'UP11' => +11, - 'UP12' => +12 + 'UP12' => +12 ); if ($tz == '') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 4b7a383b2..e6ed47fd8 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -45,14 +45,14 @@ function directory_map($source_dir, $top_level_only = FALSE) $filedata = array(); if ($fp = @opendir($source_dir)) - { + { while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) - { + 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; } @@ -60,9 +60,9 @@ function directory_map($source_dir, $top_level_only = FALSE) { $filedata[] = $file; } - } - return $filedata; - } + } + return $filedata; + } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 8d9fee478..dbedd8722 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -78,8 +78,8 @@ function force_download($filename = '', $data = '') header("Content-Transfer-Encoding: binary"); header('Pragma: public'); header("Content-Length: ".strlen($data)); - } - else + } + else { header('Content-Type: "'.$mime.'"'); header('Content-Disposition: attachment; filename="'.$filename.'"'); diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 7a04324e4..c9c21380d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -56,13 +56,13 @@ function read_file($file) flock($fp, LOCK_SH); $data = ''; - if (filesize($file) > 0) + if (filesize($file) > 0) { - $data =& fread($fp, filesize($file)); + $data =& fread($fp, filesize($file)); } flock($fp, LOCK_UN); - fclose($fp); + fclose($fp); return $data; } @@ -72,7 +72,7 @@ function read_file($file) /** * Write File * - * Writes data to the file specified in the path. + * Writes data to the file specified in the path. * Creates a new file if non-existent. * * @access public @@ -119,7 +119,7 @@ function delete_files($path, $del_dir = FALSE, $level = 0) return; while(FALSE !== ($filename = @readdir($current_dir))) - { + { if ($filename != "." and $filename != "..") { if (is_dir($path.'/'.$filename)) diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e12d89319..6d10a9862 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -53,7 +53,7 @@ function form_open($action = '', $attributes = array(), $hidden = array()) { foreach ($attributes as $key => $val) { - $form .= ' '.$key.'="'.$val.'"'; + $form .= ' '.$key.'="'.$val.'"'; } } @@ -100,7 +100,7 @@ function form_open_multipart($action, $attributes = array(), $hidden = array()) * @return string */ function form_hidden($name, $value = '') -{ +{ if ( ! is_array($name)) { return ''; @@ -251,7 +251,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $checked = $data['checked']; - if ($checked == FALSE) + if ($checked == FALSE) unset($data['checked']); } diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 1c97dda53..5ba1df990 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 3d8d3e0ca..666ec40b8 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 34386ffea..06228468f 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -60,7 +60,7 @@ function dohash($str, $type = 'sha1') { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; - return $SH->generate($str); + return $SH->generate($str); } else { @@ -88,7 +88,7 @@ function dohash($str, $type = 'sha1') * @return string */ function strip_image_tags($str) -{ +{ $str = preg_replace("##", "\\1", $str); $str = preg_replace("##", "\\1", $str); diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index d5a3591f9..ba704df9e 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -67,7 +67,7 @@ function trim_slashes($str) */ function reduce_double_slashes($str) { - return preg_replace("#([^:])//+#", "\\1/", $str); + return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ @@ -101,15 +101,15 @@ function random_string($type = 'alnum', $len = 8) } $str = ''; - for ($i=0; $i < $len; $i++) - { - $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); + for ($i=0; $i < $len; $i++) + { + $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } - return $str; + return $str; break; - case 'unique' : return md5(uniqid(mt_rand())); - break; - } + case 'unique' : return md5(uniqid(mt_rand())); + break; + } } // ------------------------------------------------------------------------ diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index e2da32746..fbc63a9b4 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -35,12 +35,12 @@ * @access public * @param string * @param integer - * @param string the end character. Usually an ellipsis + * @param string the end character. Usually an ellipsis * @return string */ function word_limiter($str, $n = 100, $end_char = '…') { - if (strlen($str) < $n) + if (strlen($str) < $n) { return $str; } @@ -53,12 +53,12 @@ function word_limiter($str, $n = 100, $end_char = '…') } $str = ''; - for ($i = 0; $i < $n; $i++) + for ($i = 0; $i < $n; $i++) { $str .= $words[$i].' '; } - return trim($str).$end_char; + return trim($str).$end_char; } // ------------------------------------------------------------------------ @@ -72,12 +72,12 @@ function word_limiter($str, $n = 100, $end_char = '…') * @access public * @param string * @param integer - * @param string the end character. Usually an ellipsis + * @param string the end character. Usually an ellipsis * @return string */ function character_limiter($str, $n = 500, $end_char = '…') { - if (strlen($str) < $n) + if (strlen($str) < $n) { return $str; } @@ -95,7 +95,7 @@ function character_limiter($str, $n = 500, $end_char = '…') $out .= $val.' '; if (strlen($out) >= $n) { - return trim($out).$end_char; + return trim($out).$end_char; } } } @@ -116,14 +116,14 @@ function ascii_to_entities($str) $count = 1; $out = ''; $temp = array(); - + for ($i = 0, $s = strlen($str); $i < $s; $i++) { $ordinal = ord($str[$i]); - + if ($ordinal < 128) { - $out .= $str[$i]; + $out .= $str[$i]; } else { @@ -131,9 +131,9 @@ function ascii_to_entities($str) { $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); @@ -141,10 +141,10 @@ function ascii_to_entities($str) $out .= '&#'.$number.';'; $count = 1; $temp = array(); - } - } + } + } } - + return $out; } @@ -169,35 +169,35 @@ function entities_to_ascii($str, $all = TRUE) $digits = $matches['1'][$i]; $out = ''; - + if ($digits < 128) { $out .= chr($digits); - - } + + } elseif ($digits < 2048) { $out .= chr(192 + (($digits - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); - } + } else { $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } - + $str = str_replace($matches['0'][$i], $out, $str); } } - + if ($all) { $str = str_replace(array("&", "<", ">", """, "'", "-"), array("&","<",">","\"", "'", "-"), $str); } - + return $str; } @@ -252,8 +252,8 @@ function word_censor($str, $censored, $replacement = '') */ function highlight_code($str) { - // The highlight string function encodes and highlights - // brackets so we need them to start raw + // 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 @@ -340,15 +340,15 @@ function word_wrap($str, $chars = '76') $lines = split("\n", $str); $output = ""; - while (list(, $thisline) = each($lines)) + while (list(, $thisline) = each($lines)) { if (strlen($thisline) > $chars) { $line = ""; $words = split(" ", $thisline); - while(list(, $thisword) = each($words)) + while(list(, $thisword) = each($words)) { - while((strlen($thisword)) > $chars) + while((strlen($thisword)) > $chars) { $cur_pos = 0; for($i=0; $i < $chars - 1; $i++) @@ -361,20 +361,20 @@ function word_wrap($str, $chars = '76') $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos)); } - if ((strlen($line) + strlen($thisword)) > $chars) + if ((strlen($line) + strlen($thisword)) > $chars) { $output .= $line."\n"; $line = $thisword." "; - } - else + } + else { $line .= $thisword." "; } } $output .= $line."\n"; - } - else + } + else { $output .= $thisline."\n"; } diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index fe9e3bb92..1681fa37c 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -46,12 +46,12 @@ function nl2br_except_pre($str) { $newstr .= nl2br($ex[$i]); } - else + else { $newstr .= $ex[$i]; } - if ($ct - 1 != $i) + if ($ct - 1 != $i) $newstr .= "pre>"; } @@ -62,7 +62,7 @@ function nl2br_except_pre($str) /** * Auto Typography Wrapper Function - * + * * * @access public * @param string @@ -78,7 +78,7 @@ function auto_typography($str) /** * Auto Typography Class - * + * * * @access private * @category Helpers @@ -117,7 +117,7 @@ class Auto_typography { /* * Reduce line breaks * - * If there are more than two consecutive line + * If there are more than two consecutive line * breaks we'll compress them down to a maximum * of two since there's no benefit to more. * @@ -127,8 +127,8 @@ class Auto_typography { /* * Convert quotes within tags to temporary marker * - * We don't want quotes converted within - * tags so we'll temporarily convert them to + * We don't want quotes converted within + * tags so we'll temporarily convert them to * {@DQ} and {@SQ} * */ @@ -136,7 +136,7 @@ class Auto_typography { { for ($i = 0; $i < count($matches['0']); $i++) { - $str = str_replace($matches['0'][$i], + $str = str_replace($matches['0'][$i], str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), $str); } @@ -159,7 +159,7 @@ class Auto_typography { * Convert "ignore" tags to temporary marker * * The parser splits out the string at every tag - * it encounters. Certain inline tags, like image + * it encounters. Certain inline tags, like image * tags, links, span tags, etc. will be adversely * affected if they are split out so we'll convert * the opening < temporarily to: {@TAG} @@ -202,7 +202,7 @@ class Auto_typography { * to skip

 tags and a few other things.
 			 *
 			 */
-			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match)) 
+			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
 			{
 				if (preg_match("#".$this->skip_elements."#", $match['2']))
 				{
@@ -244,7 +244,7 @@ class Auto_typography {
 		// Fix an artifact that happens during the paragraph replacement
 		$str = preg_replace('#(

\n*

)#', '', $str); - // If the user submitted their own paragraph tags with class data + // If the user submitted their own paragraph tags with class data // in them we will retain them instead of using our tags. $str = preg_replace('#()

#', "\\1", $str); @@ -444,8 +444,8 @@ class Auto_typography { } // Ellipsis - $str = preg_replace("#(\w)\.\.\.(\s|
|

)#", "\\1…\\2", $str); - $str = preg_replace("#(\s|
|

)\.\.\.(\w)#", "\\1…\\2", $str); + $str = preg_replace("#(\w)\.\.\.(\s|
|

)#", "\\1…\\2", $str); + $str = preg_replace("#(\s|
|

)\.\.\.(\w)#", "\\1…\\2", $str); // Run the translation array we defined above $str = str_replace(array_keys($table), array_values($table), $str); @@ -536,5 +536,5 @@ class Auto_typography { } } - + ?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 2f93bcfbf..cd628c6ae 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -30,7 +30,7 @@ /** * Site URL * - * Create a local URL based on your basepath. Segments can be passed via the + * Create a local URL based on your basepath. Segments can be passed via the * first parameter either as a string or an array. * * @access public @@ -38,7 +38,7 @@ * @return string */ function site_url($uri = '') -{ +{ $CI =& get_instance(); return $CI->config->site_url($uri); } @@ -54,7 +54,7 @@ function site_url($uri = '') * @return string */ function base_url() -{ +{ $CI =& get_instance(); return $CI->config->slash_item('base_url'); } @@ -70,7 +70,7 @@ function base_url() * @return string */ function index_page() -{ +{ $CI =& get_instance(); return $CI->config->item('index_page'); } @@ -173,7 +173,7 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) */ function mailto($email, $title = '', $attributes = '') { - if ($title == "") + if ($title == "") { $title = $email; } @@ -201,7 +201,7 @@ function mailto($email, $title = '', $attributes = '') */ function safe_mailto($email, $title = '', $attributes = '') { - if ($title == "") + if ($title == "") { $title = $email; } @@ -216,7 +216,7 @@ function safe_mailto($email, $title = '', $attributes = '') $x[] = "|".ord(substr($email, $i, 1)); } - $x[] = '"'; + $x[] = '"'; if ($attributes != '') { @@ -250,7 +250,7 @@ function safe_mailto($email, $title = '', $attributes = '') if ($ordinal < 128) { - $x[] = "|".$ordinal; + $x[] = "|".$ordinal; } else { @@ -266,7 +266,7 @@ function safe_mailto($email, $title = '', $attributes = '') $x[] = "|".$number; $count = 1; $temp = array(); - } + } } } @@ -282,15 +282,15 @@ var l=new Array(); $i = 0; foreach ($x as $val){ ?>l[]=''; -for (var i = l.length-1; i >= 0; i=i-1){ -if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";"); +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]));} //]]> $val) { $str = preg_replace("#".$key."#", $val, $str); - } + } return trim(stripslashes($str)); } @@ -445,12 +445,12 @@ function url_title($str, $separator = 'dash') * @return string */ function redirect($uri = '', $method = 'location') -{ +{ switch($method) { case 'refresh' : header("Refresh:0;url=".site_url($uri)); break; - default : header("location:".site_url($uri)); + default : header("location:".site_url($uri)); break; } exit; diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index ee3fc289b..4cc91f4ef 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -49,7 +49,7 @@ function xml_convert($str) $str = preg_replace("/$temp(\w+);/","&\\1;", $str); return $str; -} +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c1e23ce329575d2777dc1c87b87c4b1171c4e18b Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 20:49:27 +0000 Subject: --- system/helpers/directory_helper.php | 6 ++---- system/helpers/file_helper.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index e6ed47fd8..ad868519d 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -40,12 +40,10 @@ * @return array */ function directory_map($source_dir, $top_level_only = FALSE) -{ - if ( ! isset($filedata)) - $filedata = array(); - +{ if ($fp = @opendir($source_dir)) { + $filedata = array(); while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index c9c21380d..4da62ade6 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -141,5 +141,39 @@ function delete_files($path, $del_dir = FALSE, $level = 0) } } +// ------------------------------------------------------------------------ + +/** + * Get Filenames + * + * Reads the specified directory and builds an array containing the filenames. + * Any sub-folders contained within the specified path are read as well. + * + * @access public + * @param string path to source + * @param bool whether to include the path as part of the filename + * @return array + */ +function get_filenames($source_dir, $include_path = FALSE) +{ + static $_filedata = array(); + + if ($fp = @opendir($source_dir)) + { + 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; + } + } + return $_filedata; + } +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7acd581d9441fb8ada4c46c58f4ec30a01507506 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:37:22 +0000 Subject: --- system/helpers/form_helper.php | 18 +++++++++++++++++- system/helpers/xml_helper.php | 9 ++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 6d10a9862..7d594d72c 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -335,8 +335,24 @@ function form_prep($str = '') { return ''; } + + $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); + + $str = htmlspecialchars($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); - return str_replace(array("'", '"'), array("'", """), htmlspecialchars($str)); + return $str; } // ------------------------------------------------------------------------ diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 4cc91f4ef..856722b32 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -36,15 +36,18 @@ */ function xml_convert($str) { - $temp = '__TEMP_AMPERSANDS'; - + $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); - + + // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); $str = preg_replace("/$temp(\w+);/","&\\1;", $str); -- cgit v1.2.3-24-g4f1b From 86c60398852a299aa4a485c7e9e3c1d45e8c2184 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 02:50:53 +0000 Subject: --- system/helpers/text_helper.php | 105 +++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 35 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index fbc63a9b4..1b9178129 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -325,62 +325,97 @@ function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '< * Word Wrap * * Wraps text at the specified character. Maintains the integrity of words. + * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor + * will URLs. * * @access public * @param string the text string * @param integer the number of characters to wrap at * @return string */ -function word_wrap($str, $chars = '76') -{ - if ( ! is_numeric($chars)) - $chars = 76; +function word_wrap($str, $charlim = '76') +{ + // Se the character limit + if ( ! is_numeric($charlim)) + $charlim = 76; + + // Reduce multiple spaces + $str = preg_replace("| +|", " ", $str); - $str = preg_replace("/(\r\n|\r|\n)/", "\n", $str); - $lines = split("\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++) + { + $unwrap[] = $matches['1'][$i]; + $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); + } + } + + // Use PHP's native function to do the initial wordwrap. + // We set the cut flag to FALSE so that any individual words that are + // too long get left alone. In the next step we'll deal with them. + $str = wordwrap($str, $charlim, "\n", FALSE); + + // Split the string into individual lines of text and cycle through them $output = ""; - while (list(, $thisline) = each($lines)) + foreach (explode("\n", $str) as $line) { - if (strlen($thisline) > $chars) + // Is the line within the allowed character count? + // If so we'll join it to the output and continue + if (strlen($line) <= $charlim) + { + $output .= $line.$this->newline; + continue; + } + + $temp = ''; + while((strlen($line)) > $charlim) { - $line = ""; - $words = split(" ", $thisline); - while(list(, $thisword) = each($words)) + // If the over-length word is a URL we won't wrap it + if (preg_match("!\[url.+\]|://|wwww.!", $line)) { - while((strlen($thisword)) > $chars) - { - $cur_pos = 0; - for($i=0; $i < $chars - 1; $i++) - { - $output .= $thisword[$i]; - $cur_pos++; - } - - $output .= "\n"; - $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos)); - } - - if ((strlen($line) + strlen($thisword)) > $chars) - { - $output .= $line."\n"; - $line = $thisword." "; - } - else - { - $line .= $thisword." "; - } + break; } - $output .= $line."\n"; + // 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.$this->newline.$line; } else { - $output .= $thisline."\n"; + $output .= $line; + } + + $output .= $this->newline; + } + + // Put our markers back + if (count($unwrap) > 0) + { + foreach ($unwrap as $key => $val) + { + $output = str_replace("{{unwrapped".$key."}}", $val, $output); } } + // Remove the unwrap tags + $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); + return $output; } + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7e5999d0b3d5a0742acd5aa57f43bdbae6da6fa Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 05:21:35 +0000 Subject: --- system/helpers/smiley_helper.php | 154 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 system/helpers/smiley_helper.php (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php new file mode 100644 index 000000000..05ffb29b2 --- /dev/null +++ b/system/helpers/smiley_helper.php @@ -0,0 +1,154 @@ + + function insert_smiley(smiley) + { + document.{$form_name}.{$form_field}.value += " " + smiley; + } + +EOF; +} + +// ------------------------------------------------------------------------ + +/** + * Get Clickable Smileys + * + * Returns an array of image tag links that can be clicked to be inserted + * into a form field. + * + * @access public + * @param string the URL to the folder containing the smiley images + * @return array + */ +function get_clickable_smileys($image_url = '') +{ + if (FALSE === ($smileys = _get_smiley_array())) + { + return array(); + } + + // 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']])) + { + continue; + } + + $link[] = "\"".$smileys[$key]['3']."\""; + + $used[$smileys[$key]['0']] = TRUE; + } + + return $link; +} + +// ------------------------------------------------------------------------ + +/** + * Parse Smileys + * + * Takes a string as input and swaps any contained smileys for the actual image + * + * @access public + * @param string the text to be parsed + * @param string the URL to the folder containing the smiley images + * @return string + */ +function parse_smileys($str, $image_url) +{ + 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); + + foreach ($smileys as $key => $val) + { + $str = str_replace($key, "\"".$smileys[$key]['3']."\"", $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @access private + * @return mixed + */ +function _get_smiley_array() +{ + if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + { + return FALSE; + } + + include_once(APPPATH.'config/smileys'.EXT); + + if ( ! isset($smileys) OR ! is_array($smileys)) + { + return FALSE; + } + + return $smileys; +} + + + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bd56abb1e531d1122a0719b2108ed38e2d8c7327 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 18:00:37 +0000 Subject: --- system/helpers/smiley_helper.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 05ffb29b2..0f426d609 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -22,7 +22,7 @@ * @subpackage Helpers * @category Helpers * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/helpers/download_helper.html + * @link http://www.codeigniter.com/user_guide/helpers/smiley_helper.html */ // ------------------------------------------------------------------------ @@ -61,12 +61,15 @@ EOF; * @param string the URL to the folder containing the smiley images * @return array */ -function get_clickable_smileys($image_url = '') +function get_clickable_smileys($image_url = '', $smileys = NULL) { - if (FALSE === ($smileys = _get_smiley_array())) + if ( ! is_array($smileys)) { - return array(); - } + 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); @@ -78,14 +81,14 @@ function get_clickable_smileys($image_url = '') // 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']])) + if (isset($used[$smileys[$key][0]])) { continue; } - $link[] = "\"".$smileys[$key]['3']."\""; + $link[] = "\"".$smileys[$key][3]."\""; - $used[$smileys[$key]['0']] = TRUE; + $used[$smileys[$key][0]] = TRUE; } return $link; @@ -103,19 +106,27 @@ function get_clickable_smileys($image_url = '') * @param string the URL to the folder containing the smiley images * @return string */ -function parse_smileys($str, $image_url) +function parse_smileys($str = '', $image_url = '', $smileys = NULL) { - 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); foreach ($smileys as $key => $val) { - $str = str_replace($key, "\"".$smileys[$key]['3']."\"", $str); + $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); } return $str; -- cgit v1.2.3-24-g4f1b From 5ed8bf334fa9714db3cb71cd3ec3bfcb6f5e4c98 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 29 Oct 2006 17:44:54 +0000 Subject: --- system/helpers/list_helper.php | 132 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 system/helpers/list_helper.php (limited to 'system/helpers') diff --git a/system/helpers/list_helper.php b/system/helpers/list_helper.php new file mode 100644 index 000000000..587a0aa93 --- /dev/null +++ b/system/helpers/list_helper.php @@ -0,0 +1,132 @@ +\n"; + + foreach ($list as $item) + { + if (is_array($item)) + { + $out .= _list($type, $item, '', $depth+4); + } + else + { + $out .= str_repeat(" ", $depth + 2); + + $out .= "
  • ".$item."
  • \n"; + } + } + + $out .= str_repeat(" ", $depth); + + $out .= "\n"; + + return $out; +} + +// ------------------------------------------------------------------------ + +/** + * Generates the attribute string + * + * @access private + * @param mixed + * @return string + */ +function _set_attributes($attributes) +{ + if (is_string($attributes)) + { + return $attributes; + } + + $atts = ''; + foreach ($attributes as $key => $val) + { + $atts .= ' ' . $key . '="' . $val . '"'; + } + + return $atts; +} +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 27e4e6ec42954ed38084774b94f52519e56cc1d4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 29 Oct 2006 20:19:02 +0000 Subject: --- system/helpers/html_helper.php | 107 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 5ba1df990..e32abfbf2 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -42,6 +42,113 @@ function heading($data = '', $h = '1') { return "".$data.""; } + +// ------------------------------------------------------------------------ + +/** + * Unordered List + * + * Generates an HTML unordered list from an single or multi-dimensional array. + * + * @access public + * @param array + * @param mixed + * @return string + */ +function ul($list, $attributes = '') +{ + return _list('ul', $list, $attributes); +} + +// ------------------------------------------------------------------------ + +/** + * Ordered List + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @access public + * @param array + * @param mixed + * @return string + */ +function ol($list, $attributes = '') +{ + return _list('ol', $list, $attributes); +} + +// ------------------------------------------------------------------------ + +/** + * Generates the list + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @access private + * @param string + * @param mixed + * @param mixed + * @param intiger + * @return string + */ +function _list($type = 'ul', $list, $attributes = '', $depth = 0) +{ + // 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); + + // Were any attributes submitted? If so generate a string + if (is_array($attributes)) + { + $atts = ''; + foreach ($attributes as $key => $val) + { + $atts .= ' ' . $key . '="' . $val . '"'; + } + $attributes = $atts; + } + + // Write the opening list tag + $out .= "<".$type.$attributes.">\n"; + + // 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; + + $out .= str_repeat(" ", $depth + 2); + $out .= "
  • "; + + if ( ! is_array($val)) + { + $out .= $val; + } + else + { + $out .= $_last_list_item."\n"; + $out .= _list($type, $val, '', $depth + 4); + $out .= str_repeat(" ", $depth + 2); + } + + $out .= "
  • \n"; + } + + // Set the indentation for the closing tag + $out .= str_repeat(" ", $depth); + + // Write the closing list tag + $out .= "\n"; + + return $out; +} // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 2898b0f28b4a044829fa9a6df8c258049dc5f585 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 29 Oct 2006 20:23:20 +0000 Subject: --- system/helpers/list_helper.php | 132 ----------------------------------------- 1 file changed, 132 deletions(-) delete mode 100644 system/helpers/list_helper.php (limited to 'system/helpers') diff --git a/system/helpers/list_helper.php b/system/helpers/list_helper.php deleted file mode 100644 index 587a0aa93..000000000 --- a/system/helpers/list_helper.php +++ /dev/null @@ -1,132 +0,0 @@ -\n"; - - foreach ($list as $item) - { - if (is_array($item)) - { - $out .= _list($type, $item, '', $depth+4); - } - else - { - $out .= str_repeat(" ", $depth + 2); - - $out .= "
  • ".$item."
  • \n"; - } - } - - $out .= str_repeat(" ", $depth); - - $out .= "\n"; - - return $out; -} - -// ------------------------------------------------------------------------ - -/** - * Generates the attribute string - * - * @access private - * @param mixed - * @return string - */ -function _set_attributes($attributes) -{ - if (is_string($attributes)) - { - return $attributes; - } - - $atts = ''; - foreach ($attributes as $key => $val) - { - $atts .= ' ' . $key . '="' . $val . '"'; - } - - return $atts; -} -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f3a6204bb0f4538d6a77d9c85c56545be73ecd64 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 29 Oct 2006 20:24:11 +0000 Subject: --- system/helpers/smiley_helper.php | 2 +- system/helpers/url_helper.php | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 0f426d609..a07337246 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -149,7 +149,7 @@ function _get_smiley_array() return FALSE; } - include_once(APPPATH.'config/smileys'.EXT); + include(APPPATH.'config/smileys'.EXT); if ( ! isset($smileys) OR ! is_array($smileys)) { diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index cd628c6ae..9010a06a3 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -110,10 +110,7 @@ function anchor($uri = '', $title = '', $attributes = '') } else { - if (is_array($attributes)) - { - $attributes = parse_url_attributes($attributes); - } + $attributes = _parse_attributes($attributes); } return ''.$title.''; @@ -157,7 +154,7 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key]; } - return "".$title.""; + return "".$title.""; } // ------------------------------------------------------------------------ @@ -178,10 +175,7 @@ function mailto($email, $title = '', $attributes = '') $title = $email; } - if (is_array($attributes)) - { - $attributes = parse_url_attributes($attributes); - } + $attributes = _parse_attributes($attributes); return ''.$title.''; } @@ -468,8 +462,13 @@ function redirect($uri = '', $method = 'location') * @param bool * @return string */ -function parse_url_attributes($attributes, $javascript = FALSE) +function _parse_attributes($attributes, $javascript = FALSE) { + if (is_string($attributes)) + { + return ($attributes != '') ? ' '.$attributes : ''; + } + $att = ''; foreach ($attributes as $key => $val) { @@ -483,7 +482,7 @@ function parse_url_attributes($attributes, $javascript = FALSE) } } - if ($javascript == TRUE) + if ($javascript == TRUE AND $att != '') { $att = substr($att, 0, -1); } -- cgit v1.2.3-24-g4f1b From 7c807cba83ab368d027a28f4b84ee6a301430e80 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 18:13:24 +0000 Subject: --- system/helpers/text_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 1b9178129..655d6e531 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -370,7 +370,7 @@ function word_wrap($str, $charlim = '76') // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { - $output .= $line.$this->newline; + $output .= $line."\n"; continue; } @@ -399,7 +399,7 @@ function word_wrap($str, $charlim = '76') $output .= $line; } - $output .= $this->newline; + $output .= "\n"; } // Put our markers back -- cgit v1.2.3-24-g4f1b From 40d299e8221ba5d641e07c18ef19f4ac13ff9b85 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 4 Nov 2006 05:07:59 +0000 Subject: --- system/helpers/html_helper.php | 21 +++++++++++++++++++++ system/helpers/url_helper.php | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index e32abfbf2..90a776386 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -178,6 +178,27 @@ function nbs($num = 1) return str_repeat(" ", $num); } +// ------------------------------------------------------------------------ + +/** + * Generates meta tags from an array of key/values + * + * @access public + * @param array + * @return string + */ +function meta($meta = array(), $newline = "\n") +{ + $str = ''; + foreach ($meta as $key => $val) + { + $str .= ''.$newline; + } + + return $str; +} + + ?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 9010a06a3..3ca597460 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -442,9 +442,9 @@ function redirect($uri = '', $method = 'location') { switch($method) { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); + case 'refresh' : header("Refresh:0;url=".site_url($uri)); break; - default : header("location:".site_url($uri)); + default : header("location:".site_url($uri)); break; } exit; -- cgit v1.2.3-24-g4f1b From 17f4d73ff388dbcb4d9fbd4f79a0f9150ddc8c7e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:23:13 +0000 Subject: unset the value attribute in textarea --- system/helpers/form_helper.php | 806 +++++++++++++++++++++-------------------- 1 file changed, 404 insertions(+), 402 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7d594d72c..8186d4ccd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,403 +1,405 @@ -config->site_url($action).'"'; - - if ( ! isset($attributes['method'])) - { - $form .= ' method="post"'; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } - - $form .= '>'; - - if (is_array($hidden) AND count($hidden > 0)) - { - $form .= form_hidden($hidden); - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @access public - * @param string the URI segments of the form destination - * @param array a key/value pair of attributes - * @param array a key/value pair hidden data - * @return string - */ -function form_open_multipart($action, $attributes = array(), $hidden = array()) -{ - $attributes['enctype'] = 'multipart/form-data'; - return form_open($action, $attributes, $hidden); -} - -// ------------------------------------------------------------------------ - -/** - * Hidden Input Field - * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. - * - * @access public - * @param mixed - * @param string - * @return string - */ -function form_hidden($name, $value = '') -{ - if ( ! is_array($name)) - { - return ''; - } - - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_input($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_password($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'password'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_upload($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_textarea($data = '', $value = '', $extra = '') -{ - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') -{ - if ($extra != '') $extra = ' '.$extra; - - $form = ''; - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') -{ - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) - { - $checked = $data['checked']; - - if ($checked == FALSE) - unset($data['checked']); - } - - if ($checked == TRUE) - $defaults['checked'] = 'checked'; - else - unset($defaults['checked']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Radio Button - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -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); -} - -// ------------------------------------------------------------------------ - -/** - * Submit Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ -function form_close($extra = '') -{ - return "\n".$extra; -} - -// ------------------------------------------------------------------------ - -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @access public - * @param string - * @return string - */ -function form_prep($str = '') -{ - if ($str === '') - { - return ''; - } - - $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); - - $str = htmlspecialchars($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); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @access private - * @param array - * @param array - * @return string - */ -function parse_form_attributes($attributes, $default) -{ - if (is_array($attributes)) - { - foreach ($default as $key => $val) - { - if (isset($attributes[$key])) - { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); - } - } - - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); - } - } - - $att = ''; - foreach ($default as $key => $val) - { - if ($key == 'value') - { - $val = form_prep($val); - } - - $att .= $key . '="' . $val . '" '; - } - - return $att; -} - +config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @access public + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); +} + +// ------------------------------------------------------------------------ + +/** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or an associative + * array with multiple values. + * + * @access public + * @param mixed + * @param string + * @return string + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); + + unset ($data['value']); // textareas don't use the value attribute + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Drop-down Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + unset($data['checked']); + } + + if ($checked == TRUE) + $defaults['checked'] = 'checked'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +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); +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +function form_prep($str = '') +{ + if ($str === '') + { + return ''; + } + + $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); + + $str = htmlspecialchars($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); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @param array + * @return string + */ +function parse_form_attributes($attributes, $default) +{ + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + foreach ($default as $key => $val) + { + if ($key == 'value') + { + $val = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From dbbe40862c895296a9e3d9e184ff2da3788800d4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 13 Feb 2007 23:46:23 +0000 Subject: changed Content-Disposition: from "inline" to "attachment" for MSIE in force_download() --- system/helpers/download_helper.php | 190 ++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 95 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index dbedd8722..34cc152cc 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -1,96 +1,96 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c4ac15f47a73a2db99406d901d53803b87f255bb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 17:22:31 +0000 Subject: fixed a a value bug introduced when clearing value from textarea --- system/helpers/form_helper.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 8186d4ccd..a166198fb 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -196,9 +196,15 @@ function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); - - unset ($data['value']); // textareas don't use the value attribute + 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 "\n"; } -- cgit v1.2.3-24-g4f1b From 5811bf1da422839d8dd6cfc7e6bac65649fceacd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 20 Feb 2007 01:26:08 +0000 Subject: added a space to redirect Location to conform to w3c http spec --- system/helpers/url_helper.php | 984 +++++++++++++++++++++--------------------- 1 file changed, 492 insertions(+), 492 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 3ca597460..baac0e5d8 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,493 +1,493 @@ -config->site_url($uri); -} - -// ------------------------------------------------------------------------ - -/** - * Base URL - * - * Returns the "base_url" item from your config file - * - * @access public - * @return string - */ -function base_url() -{ - $CI =& get_instance(); - return $CI->config->slash_item('base_url'); -} - -// ------------------------------------------------------------------------ - -/** - * Index page - * - * Returns the "index_page" from your config file - * - * @access public - * @return string - */ -function index_page() -{ - $CI =& get_instance(); - return $CI->config->item('index_page'); -} - -// ------------------------------------------------------------------------ - -/** - * Anchor Link - * - * Creates an anchor based on the local URL. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ -function anchor($uri = '', $title = '', $attributes = '') -{ - 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); - } - - return ''.$title.''; -} - -// ------------------------------------------------------------------------ - -/** - * Anchor Link - Pop-up version - * - * Creates an anchor based on the local URL. The link - * opens a new window based on the attributes specified. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ -function anchor_popup($uri = '', $title = '', $attributes = FALSE) -{ - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; - - if ($title == '') - { - $title = $site_url; - } - - if ($attributes === FALSE) - { - return "".$title.""; - } - - 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]; - } - - return "".$title.""; -} - -// ------------------------------------------------------------------------ - -/** - * Mailto Link - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ -function mailto($email, $title = '', $attributes = '') -{ - if ($title == "") - { - $title = $email; - } - - $attributes = _parse_attributes($attributes); - - return ''.$title.''; -} - -// ------------------------------------------------------------------------ - -/** - * Encoded Mailto Link - * - * Create a spam-protected mailto link written in Javascript - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ -function safe_mailto($email, $title = '', $attributes = '') -{ - if ($title == "") - { - $title = $email; - } - - for ($i = 0; $i < 16; $i++) - { - $x[] = substr(' $val) - { - $x[] = ' '.$key.'="'; - for ($i = 0; $i < strlen($val); $i++) - { - $x[] = "|".ord(substr($val, $i, 1)); - } - $x[] = '"'; - } - } - 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]); - - if ($ordinal < 128) - { - $x[] = "|".$ordinal; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - $x[] = "|".$number; - $count = 1; - $temp = array(); - } - } - } - - $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; - - $x = array_reverse($x); - ob_start(); - -?>http'. - $matches['4'][$i].'://'. - $matches['5'][$i]. - $matches['6'][$i].''. - $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++) - { - $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); - } - - } - } - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Prep URL - * - * Simply adds the http:// part if missing - * - * @access public - * @param string the URL - * @return string - */ -function prep_url($str = '') -{ - if ($str == 'http://' OR $str == '') - { - return ''; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Create URL Title - * - * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. - * - * @access public - * @param string the string - * @param string the separator: dash, or underscore - * @return string - */ -function url_title($str, $separator = 'dash') -{ - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else - { - $search = '-'; - $replace = '_'; - } - - $trans = array( - $search => $replace, - "\s+" => $replace, - "[^a-z0-9".$replace."]" => '', - $replace."+" => $replace, - $replace."$" => '', - "^".$replace => '' - ); - - $str = strip_tags(strtolower($str)); - - foreach ($trans as $key => $val) - { - $str = preg_replace("#".$key."#", $val, $str); - } - - return trim(stripslashes($str)); -} - -// ------------------------------------------------------------------------ - -/** - * Header Redirect - * - * Header redirect in two flavors - * - * @access public - * @param string the URL - * @param string the method: location or redirect - * @return string - */ -function redirect($uri = '', $method = 'location') -{ - switch($method) - { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); - break; - default : header("location:".site_url($uri)); - break; - } - exit; -} - -// ------------------------------------------------------------------------ - -/** - * Parse out the attributes - * - * Some of the functions use this - * - * @access private - * @param array - * @param bool - * @return string - */ -function _parse_attributes($attributes, $javascript = FALSE) -{ - if (is_string($attributes)) - { - return ($attributes != '') ? ' '.$attributes : ''; - } - - $att = ''; - foreach ($attributes as $key => $val) - { - if ($javascript == TRUE) - { - $att .= $key . '=' . $val . ','; - } - else - { - $att .= ' ' . $key . '="' . $val . '"'; - } - } - - if ($javascript == TRUE AND $att != '') - { - $att = substr($att, 0, -1); - } - - return $att; -} - +config->site_url($uri); +} + +// ------------------------------------------------------------------------ + +/** + * Base URL + * + * Returns the "base_url" item from your config file + * + * @access public + * @return string + */ +function base_url() +{ + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); +} + +// ------------------------------------------------------------------------ + +/** + * Index page + * + * Returns the "index_page" from your config file + * + * @access public + * @return string + */ +function index_page() +{ + $CI =& get_instance(); + return $CI->config->item('index_page'); +} + +// ------------------------------------------------------------------------ + +/** + * Anchor Link + * + * Creates an anchor based on the local URL. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +function anchor($uri = '', $title = '', $attributes = '') +{ + 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); + } + + return ''.$title.''; +} + +// ------------------------------------------------------------------------ + +/** + * Anchor Link - Pop-up version + * + * Creates an anchor based on the local URL. The link + * opens a new window based on the attributes specified. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +function anchor_popup($uri = '', $title = '', $attributes = FALSE) +{ + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + + if ($title == '') + { + $title = $site_url; + } + + if ($attributes === FALSE) + { + return "".$title.""; + } + + 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]; + } + + return "".$title.""; +} + +// ------------------------------------------------------------------------ + +/** + * Mailto Link + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +function mailto($email, $title = '', $attributes = '') +{ + if ($title == "") + { + $title = $email; + } + + $attributes = _parse_attributes($attributes); + + return ''.$title.''; +} + +// ------------------------------------------------------------------------ + +/** + * Encoded Mailto Link + * + * Create a spam-protected mailto link written in Javascript + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +function safe_mailto($email, $title = '', $attributes = '') +{ + if ($title == "") + { + $title = $email; + } + + for ($i = 0; $i < 16; $i++) + { + $x[] = substr(' $val) + { + $x[] = ' '.$key.'="'; + for ($i = 0; $i < strlen($val); $i++) + { + $x[] = "|".ord(substr($val, $i, 1)); + } + $x[] = '"'; + } + } + 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]); + + if ($ordinal < 128) + { + $x[] = "|".$ordinal; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + $x[] = "|".$number; + $count = 1; + $temp = array(); + } + } + } + + $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; + + $x = array_reverse($x); + ob_start(); + +?>http'. + $matches['4'][$i].'://'. + $matches['5'][$i]. + $matches['6'][$i].''. + $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++) + { + $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); + } + + } + } + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Prep URL + * + * Simply adds the http:// part if missing + * + * @access public + * @param string the URL + * @return string + */ +function prep_url($str = '') +{ + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with either a dash + * or an underscore as the word separator. + * + * @access public + * @param string the string + * @param string the separator: dash, or underscore + * @return string + */ +function url_title($str, $separator = 'dash') +{ + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } + + $trans = array( + $search => $replace, + "\s+" => $replace, + "[^a-z0-9".$replace."]" => '', + $replace."+" => $replace, + $replace."$" => '', + "^".$replace => '' + ); + + $str = strip_tags(strtolower($str)); + + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#", $val, $str); + } + + return trim(stripslashes($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Header Redirect + * + * Header redirect in two flavors + * + * @access public + * @param string the URL + * @param string the method: location or redirect + * @return string + */ +function redirect($uri = '', $method = 'location') +{ + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("Location: ".site_url($uri)); + break; + } + exit; +} + +// ------------------------------------------------------------------------ + +/** + * Parse out the attributes + * + * Some of the functions use this + * + * @access private + * @param array + * @param bool + * @return string + */ +function _parse_attributes($attributes, $javascript = FALSE) +{ + if (is_string($attributes)) + { + return ($attributes != '') ? ' '.$attributes : ''; + } + + $att = ''; + foreach ($attributes as $key => $val) + { + if ($javascript == TRUE) + { + $att .= $key . '=' . $val . ','; + } + else + { + $att .= ' ' . $key . '="' . $val . '"'; + } + } + + if ($javascript == TRUE AND $att != '') + { + $att = substr($att, 0, -1); + } + + return $att; +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8389487656f0f8c027b0cfe38014b7035be10888 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 13 Mar 2007 20:51:52 +0000 Subject: removed duplicate 'DATE_RFC822' --- system/helpers/date_helper.php | 1129 ++++++++++++++++++++-------------------- 1 file changed, 564 insertions(+), 565 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index b8df03edb..504a962ce 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,566 +1,565 @@ -config->item('time_reference')) == 'gmt') - { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - - if (strlen($system_time) < 10) - { - $system_time = time(); - log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); - } - - return $system_time; - } - else - { - return time(); - } -} - -// ------------------------------------------------------------------------ - -/** - * Convert MySQL Style Datecodes - * - * This function is identical to PHPs date() function, - * except that it allows date codes to be formatted using - * the MySQL style, where each code letter is preceded - * with a percent sign: %Y %m %d etc... - * - * The benefit of doing dates this way is that you don't - * have to worry about escaping your text letters that - * match the date codes. - * - * @access public - * @param string - * @param integer - * @return integer - */ -function mdate($datestr = '', $time = '') -{ - if ($datestr == '') - return ''; - - if ($time == '') - $time = now(); - - $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); - return date($datestr, $time); -} - -// ------------------------------------------------------------------------ - -/** - * Standard Date - * - * Returns a date formatted according to the submitted standard. - * - * @access public - * @param string the chosen format - * @param integer Unix timestamp - * @return string - */ -function standard_date($fmt = 'DATE_RFC822', $time = '') -{ - $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_RFC2822' => '%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); -} - - -// ------------------------------------------------------------------------ - -/** - * Timespan - * - * Returns a span of seconds in this format: - * 10 days 14 hours 36 minutes 47 seconds - * - * @access public - * @param integer a number of seconds - * @param integer Unix timestamp - * @return integer - */ -function timespan($seconds = 1, $time = '') -{ - $CI =& get_instance(); - $CI->lang->load('date'); - - if ( ! is_numeric($seconds)) - { - $seconds = 1; - } - - if ( ! is_numeric($time)) - { - $time = time(); - } - - 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')).', '; - } - - $seconds -= $years * 31536000; - $months = floor($seconds / 2628000); - - if ($years > 0 OR $months > 0) - { - if ($months > 0) - { - $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; - } - - $seconds -= $months * 2628000; - } - - $weeks = floor($seconds / 604800); - - if ($years > 0 OR $months > 0 OR $weeks > 0) - { - if ($weeks > 0) - { - $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; - } - - $seconds -= $weeks * 604800; - } - - $days = floor($seconds / 86400); - - if ($months > 0 OR $weeks > 0 OR $days > 0) - { - if ($days > 0) - { - $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; - } - - $seconds -= $days * 86400; - } - - $hours = floor($seconds / 3600); - - if ($days > 0 OR $hours > 0) - { - if ($hours > 0) - { - $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; - } - - $seconds -= $hours * 3600; - } - - $minutes = floor($seconds / 60); - - if ($days > 0 OR $hours > 0 OR $minutes > 0) - { - if ($minutes > 0) - { - $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; - } - - $seconds -= $minutes * 60; - } - - if ($str == '') - { - $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; - } - - return substr(trim($str), 0, -1); -} - -// ------------------------------------------------------------------------ - -/** - * Number of days in a month - * - * Takes a month/year as input and returns the number of days - * for the given month/year. Takes leap years into consideration. - * - * @access public - * @param integer a numeric month - * @param integer a numeric year - * @return integer - */ -function days_in_month($month = 0, $year = '') -{ - if ($month < 1 OR $month > 12) - { - return 0; - } - - if ( ! is_numeric($year) OR strlen($year) != 4) - { - $year = date('Y'); - } - - if ($month == 2) - { - if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) - { - return 29; - } - } - - $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - return $days_in_month[$month - 1]; -} - -// ------------------------------------------------------------------------ - -/** - * Converts a local Unix timestamp to GMT - * - * @access public - * @param integer Unix timestamp - * @return integer - */ -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)); -} - -// ------------------------------------------------------------------------ - -/** - * Converts GMT time to a localized value - * - * Takes a Unix timestamp (in GMT) as input, and returns - * at the local value based on the timezone and DST setting - * submitted - * - * @access public - * @param integer Unix timestamp - * @param string timezone - * @param bool whether DST is active - * @return integer - */ -function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) -{ - if ($time == '') - { - return now(); - } - - $time += timezones($timezone) * 3600; - - if ($dst == TRUE) - { - $time += 3600; - } - - return $time; -} - -// ------------------------------------------------------------------------ - -/** - * Converts a MySQL Timestamp to Unix - * - * @access public - * @param integer Unix timestamp - * @return integer - */ -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) - ); -} - -// ------------------------------------------------------------------------ - -/** - * Unix to "Human" - * - * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM - * - * @access public - * @param integer Unix timestamp - * @param bool whether to show seconds - * @param string format: us or euro - * @return string - */ -function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') -{ - $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; - - if ($fmt == 'us') - { - $r .= date('h', $time).':'.date('i', $time); - } - else - { - $r .= date('H', $time).':'.date('i', $time); - } - - if ($seconds) - { - $r .= ':'.date('s', $time); - } - - if ($fmt == 'us') - { - $r .= ' '.date('A', $time); - } - - return $r; -} - -// ------------------------------------------------------------------------ - -/** - * Convert "human" date to GMT - * - * Reverses the above process - * - * @access public - * @param string format: us or euro - * @return integer - */ -function human_to_unix($datestr = '') -{ - if ($datestr == '') - { - return FALSE; - } - - $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; - } - - $split = preg_split("/\040/", $datestr); - - $ex = explode("-", $split['0']); - - $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; - $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; - - $ex = explode(":", $split['1']); - - $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; - $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; - - 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 (substr($ampm, 0, 1) == 'p' AND $hour < 12) - $hour = $hour + 12; - - if (substr($ampm, 0, 1) == 'a' AND $hour == 12) - $hour = '00'; - - if (strlen($hour) == 1) - $hour = '0'.$hour; - } - - return mktime($hour, $min, $sec, $month, $day, $year); -} - -// ------------------------------------------------------------------------ - -/** - * Timezone Menu - * - * Generates a drop-down menu of timezones. - * - * @access public - * @param string timezone - * @param string classname - * @param string menu name - * @return string - */ -function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') -{ - $CI =& get_instance(); - $CI->lang->load('date'); - - if ($default == 'GMT') - $default = 'UTC'; - - $menu = '"; - - return $menu; -} - -// ------------------------------------------------------------------------ - -/** - * Timezones - * - * Returns an array of timezones. This is a helper function - * for various other ones in this library - * - * @access public - * @param string timezone - * @return string - */ -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 - ); - - if ($tz == '') - { - return $zones; - } - - if ($tz == 'GMT') - $tz = 'UTC'; - - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; -} - - +config->item('time_reference')) == 'gmt') + { + $now = time(); + $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); + + if (strlen($system_time) < 10) + { + $system_time = time(); + log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); + } + + return $system_time; + } + else + { + return time(); + } +} + +// ------------------------------------------------------------------------ + +/** + * Convert MySQL Style Datecodes + * + * This function is identical to PHPs date() function, + * except that it allows date codes to be formatted using + * the MySQL style, where each code letter is preceded + * with a percent sign: %Y %m %d etc... + * + * The benefit of doing dates this way is that you don't + * have to worry about escaping your text letters that + * match the date codes. + * + * @access public + * @param string + * @param integer + * @return integer + */ +function mdate($datestr = '', $time = '') +{ + if ($datestr == '') + return ''; + + if ($time == '') + $time = now(); + + $datestr = str_replace('%\\', '', preg_replace("/([a-z]+?){1}/i", "\\\\\\1", $datestr)); + return date($datestr, $time); +} + +// ------------------------------------------------------------------------ + +/** + * Standard Date + * + * Returns a date formatted according to the submitted standard. + * + * @access public + * @param string the chosen format + * @param integer Unix timestamp + * @return string + */ +function standard_date($fmt = 'DATE_RFC822', $time = '') +{ + $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); +} + + +// ------------------------------------------------------------------------ + +/** + * Timespan + * + * Returns a span of seconds in this format: + * 10 days 14 hours 36 minutes 47 seconds + * + * @access public + * @param integer a number of seconds + * @param integer Unix timestamp + * @return integer + */ +function timespan($seconds = 1, $time = '') +{ + $CI =& get_instance(); + $CI->lang->load('date'); + + if ( ! is_numeric($seconds)) + { + $seconds = 1; + } + + if ( ! is_numeric($time)) + { + $time = time(); + } + + 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')).', '; + } + + $seconds -= $years * 31536000; + $months = floor($seconds / 2628000); + + if ($years > 0 OR $months > 0) + { + if ($months > 0) + { + $str .= $months.' '.$CI->lang->line((($months > 1) ? 'date_months' : 'date_month')).', '; + } + + $seconds -= $months * 2628000; + } + + $weeks = floor($seconds / 604800); + + if ($years > 0 OR $months > 0 OR $weeks > 0) + { + if ($weeks > 0) + { + $str .= $weeks.' '.$CI->lang->line((($weeks > 1) ? 'date_weeks' : 'date_week')).', '; + } + + $seconds -= $weeks * 604800; + } + + $days = floor($seconds / 86400); + + if ($months > 0 OR $weeks > 0 OR $days > 0) + { + if ($days > 0) + { + $str .= $days.' '.$CI->lang->line((($days > 1) ? 'date_days' : 'date_day')).', '; + } + + $seconds -= $days * 86400; + } + + $hours = floor($seconds / 3600); + + if ($days > 0 OR $hours > 0) + { + if ($hours > 0) + { + $str .= $hours.' '.$CI->lang->line((($hours > 1) ? 'date_hours' : 'date_hour')).', '; + } + + $seconds -= $hours * 3600; + } + + $minutes = floor($seconds / 60); + + if ($days > 0 OR $hours > 0 OR $minutes > 0) + { + if ($minutes > 0) + { + $str .= $minutes.' '.$CI->lang->line((($minutes > 1) ? 'date_minutes' : 'date_minute')).', '; + } + + $seconds -= $minutes * 60; + } + + if ($str == '') + { + $str .= $seconds.' '.$CI->lang->line((($seconds > 1) ? 'date_seconds' : 'date_second')).', '; + } + + return substr(trim($str), 0, -1); +} + +// ------------------------------------------------------------------------ + +/** + * Number of days in a month + * + * Takes a month/year as input and returns the number of days + * for the given month/year. Takes leap years into consideration. + * + * @access public + * @param integer a numeric month + * @param integer a numeric year + * @return integer + */ +function days_in_month($month = 0, $year = '') +{ + if ($month < 1 OR $month > 12) + { + return 0; + } + + if ( ! is_numeric($year) OR strlen($year) != 4) + { + $year = date('Y'); + } + + if ($month == 2) + { + if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0)) + { + return 29; + } + } + + $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + return $days_in_month[$month - 1]; +} + +// ------------------------------------------------------------------------ + +/** + * Converts a local Unix timestamp to GMT + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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)); +} + +// ------------------------------------------------------------------------ + +/** + * Converts GMT time to a localized value + * + * Takes a Unix timestamp (in GMT) as input, and returns + * at the local value based on the timezone and DST setting + * submitted + * + * @access public + * @param integer Unix timestamp + * @param string timezone + * @param bool whether DST is active + * @return integer + */ +function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) +{ + if ($time == '') + { + return now(); + } + + $time += timezones($timezone) * 3600; + + if ($dst == TRUE) + { + $time += 3600; + } + + return $time; +} + +// ------------------------------------------------------------------------ + +/** + * Converts a MySQL Timestamp to Unix + * + * @access public + * @param integer Unix timestamp + * @return integer + */ +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) + ); +} + +// ------------------------------------------------------------------------ + +/** + * Unix to "Human" + * + * Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM + * + * @access public + * @param integer Unix timestamp + * @param bool whether to show seconds + * @param string format: us or euro + * @return string + */ +function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') +{ + $r = date('Y', $time).'-'.date('m', $time).'-'.date('d', $time).' '; + + if ($fmt == 'us') + { + $r .= date('h', $time).':'.date('i', $time); + } + else + { + $r .= date('H', $time).':'.date('i', $time); + } + + if ($seconds) + { + $r .= ':'.date('s', $time); + } + + if ($fmt == 'us') + { + $r .= ' '.date('A', $time); + } + + return $r; +} + +// ------------------------------------------------------------------------ + +/** + * Convert "human" date to GMT + * + * Reverses the above process + * + * @access public + * @param string format: us or euro + * @return integer + */ +function human_to_unix($datestr = '') +{ + if ($datestr == '') + { + return FALSE; + } + + $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; + } + + $split = preg_split("/\040/", $datestr); + + $ex = explode("-", $split['0']); + + $year = (strlen($ex['0']) == 2) ? '20'.$ex['0'] : $ex['0']; + $month = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + $day = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; + + $ex = explode(":", $split['1']); + + $hour = (strlen($ex['0']) == 1) ? '0'.$ex['0'] : $ex['0']; + $min = (strlen($ex['1']) == 1) ? '0'.$ex['1'] : $ex['1']; + + 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 (substr($ampm, 0, 1) == 'p' AND $hour < 12) + $hour = $hour + 12; + + if (substr($ampm, 0, 1) == 'a' AND $hour == 12) + $hour = '00'; + + if (strlen($hour) == 1) + $hour = '0'.$hour; + } + + return mktime($hour, $min, $sec, $month, $day, $year); +} + +// ------------------------------------------------------------------------ + +/** + * Timezone Menu + * + * Generates a drop-down menu of timezones. + * + * @access public + * @param string timezone + * @param string classname + * @param string menu name + * @return string + */ +function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') +{ + $CI =& get_instance(); + $CI->lang->load('date'); + + if ($default == 'GMT') + $default = 'UTC'; + + $menu = '"; + + return $menu; +} + +// ------------------------------------------------------------------------ + +/** + * Timezones + * + * Returns an array of timezones. This is a helper function + * for various other ones in this library + * + * @access public + * @param string timezone + * @return string + */ +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 + ); + + if ($tz == '') + { + return $zones; + } + + if ($tz == 'GMT') + $tz = 'UTC'; + + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 72b58ca3afbf507d0b6fcedcecae01cc876ddd1f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 7 Apr 2007 20:58:23 +0000 Subject: repeater won't return any results if it is set to repeat 0 times. --- system/helpers/string_helper.php | 306 +++++++++++++++++++-------------------- 1 file changed, 153 insertions(+), 153 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index ba704df9e..c0a8854dc 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,154 +1,154 @@ - 0) ? str_repeat($data, $num) : ''); +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d2df9bc7cc9d4b3e53818470c5d0977c9a36677c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:41:17 +0000 Subject: update pMachine to EllisLab update copyright year update Code Igniter to CodeIgniter --- system/helpers/array_helper.php | 140 ++--- system/helpers/cookie_helper.php | 250 ++++---- system/helpers/date_helper.php | 6 +- system/helpers/directory_helper.php | 132 ++--- system/helpers/download_helper.php | 6 +- system/helpers/file_helper.php | 356 +++++------ system/helpers/form_helper.php | 6 +- system/helpers/html_helper.php | 406 ++++++------- system/helpers/inflector_helper.php | 278 ++++----- system/helpers/security_helper.php | 222 +++---- system/helpers/smiley_helper.php | 328 +++++------ system/helpers/string_helper.php | 6 +- system/helpers/text_helper.php | 840 +++++++++++++------------- system/helpers/typography_helper.php | 1078 +++++++++++++++++----------------- system/helpers/url_helper.php | 6 +- system/helpers/xml_helper.php | 114 ++-- 16 files changed, 2087 insertions(+), 2087 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 491c61577..674ef3bec 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,71 +1,71 @@ - \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index b117816e2..9dc5df9b1 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -1,126 +1,126 @@ -config->item('cookie_prefix') != '') - { - $CI->config->item('cookie_prefix'); - } - if ($domain == '' AND $CI->config->item('cookie_domain') != '') - { - $CI->config->item('cookie_domain'); - } - if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') - { - $CI->config->item('cookie_path'); - } - - if ( ! is_numeric($expire)) - { - $expire = time() - 86500; - } - else - { - if ($expire > 0) - { - $expire = time() + $expire; - } - else - { - $expire = 0; - } - } - - setcookie($prefix.$name, $value, $expire, $path, $domain, 0); -} - -// -------------------------------------------------------------------- - -/** - * Fetch an item from the COOKIE array - * - * @access public - * @param string - * @param bool - * @return mixed - */ -function get_cookie($index = '', $xss_clean = FALSE) -{ - $CI =& get_instance(); - return $CI->input->cookie($index, $xss_clean); -} - -// -------------------------------------------------------------------- - -/** - * Delete a COOKIE - * - * @param mixed - * @param string the cookie domain. Usually: .yourdomain.com - * @param string the cookie path - * @param string the cookie prefix - * @return void - */ -function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') -{ - set_cookie($name, '', '', $domain, $path, $prefix); -} - - +config->item('cookie_prefix') != '') + { + $CI->config->item('cookie_prefix'); + } + if ($domain == '' AND $CI->config->item('cookie_domain') != '') + { + $CI->config->item('cookie_domain'); + } + if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') + { + $CI->config->item('cookie_path'); + } + + if ( ! is_numeric($expire)) + { + $expire = time() - 86500; + } + else + { + if ($expire > 0) + { + $expire = time() + $expire; + } + else + { + $expire = 0; + } + } + + setcookie($prefix.$name, $value, $expire, $path, $domain, 0); +} + +// -------------------------------------------------------------------- + +/** + * Fetch an item from the COOKIE array + * + * @access public + * @param string + * @param bool + * @return mixed + */ +function get_cookie($index = '', $xss_clean = FALSE) +{ + $CI =& get_instance(); + return $CI->input->cookie($index, $xss_clean); +} + +// -------------------------------------------------------------------- + +/** + * Delete a COOKIE + * + * @param mixed + * @param string the cookie domain. Usually: .yourdomain.com + * @param string the cookie path + * @param string the cookie prefix + * @return void + */ +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 504a962ce..c67e3da2d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,12 +1,12 @@ \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 34cc152cc..c9d81f692 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -1,12 +1,12 @@ 0) - { - $data =& fread($fp, filesize($file)); - } - - flock($fp, LOCK_UN); - fclose($fp); - - return $data; -} - -// ------------------------------------------------------------------------ - -/** - * Write File - * - * Writes data to the file specified in the path. - * Creates a new file if non-existent. - * - * @access public - * @param string path to file - * @param string file data - * @return bool - */ -function write_file($path, $data, $mode = 'wb') -{ - if ( ! $fp = @fopen($path, $mode)) - { - return FALSE; - } - - flock($fp, LOCK_EX); - fwrite($fp, $data); - flock($fp, LOCK_UN); - fclose($fp); - - return TRUE; -} - -// ------------------------------------------------------------------------ - -/** - * Delete Files - * - * Deletes all files contained in the supplied directory path. - * Files must be writable or owned by the system in order to be deleted. - * If the second parameter is set to TRUE, any directories contained - * within the supplied base directory will be nuked as well. - * - * @access public - * @param string path to file - * @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 ( ! $current_dir = @opendir($path)) - return; - - while(FALSE !== ($filename = @readdir($current_dir))) - { - if ($filename != "." and $filename != "..") - { - if (is_dir($path.'/'.$filename)) - { - $level++; - delete_files($path.'/'.$filename, $del_dir, $level); - } - else - { - unlink($path.'/'.$filename); - } - } - } - @closedir($current_dir); - - if ($del_dir == TRUE AND $level > 0) - { - @rmdir($path); - } -} - -// ------------------------------------------------------------------------ - -/** - * Get Filenames - * - * Reads the specified directory and builds an array containing the filenames. - * Any sub-folders contained within the specified path are read as well. - * - * @access public - * @param string path to source - * @param bool whether to include the path as part of the filename - * @return array - */ -function get_filenames($source_dir, $include_path = FALSE) -{ - static $_filedata = array(); - - if ($fp = @opendir($source_dir)) - { - 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; - } - } - return $_filedata; - } -} - + 0) + { + $data =& fread($fp, filesize($file)); + } + + flock($fp, LOCK_UN); + fclose($fp); + + return $data; +} + +// ------------------------------------------------------------------------ + +/** + * Write File + * + * Writes data to the file specified in the path. + * Creates a new file if non-existent. + * + * @access public + * @param string path to file + * @param string file data + * @return bool + */ +function write_file($path, $data, $mode = 'wb') +{ + if ( ! $fp = @fopen($path, $mode)) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $data); + flock($fp, LOCK_UN); + fclose($fp); + + return TRUE; +} + +// ------------------------------------------------------------------------ + +/** + * Delete Files + * + * Deletes all files contained in the supplied directory path. + * Files must be writable or owned by the system in order to be deleted. + * If the second parameter is set to TRUE, any directories contained + * within the supplied base directory will be nuked as well. + * + * @access public + * @param string path to file + * @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 ( ! $current_dir = @opendir($path)) + return; + + while(FALSE !== ($filename = @readdir($current_dir))) + { + if ($filename != "." and $filename != "..") + { + if (is_dir($path.'/'.$filename)) + { + $level++; + delete_files($path.'/'.$filename, $del_dir, $level); + } + else + { + unlink($path.'/'.$filename); + } + } + } + @closedir($current_dir); + + if ($del_dir == TRUE AND $level > 0) + { + @rmdir($path); + } +} + +// ------------------------------------------------------------------------ + +/** + * Get Filenames + * + * Reads the specified directory and builds an array containing the filenames. + * Any sub-folders contained within the specified path are read as well. + * + * @access public + * @param string path to source + * @param bool whether to include the path as part of the filename + * @return array + */ +function get_filenames($source_dir, $include_path = FALSE) +{ + static $_filedata = array(); + + if ($fp = @opendir($source_dir)) + { + 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; + } + } + return $_filedata; + } +} + ?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a166198fb..adbddd5ad 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,12 +1,12 @@ ".$data.""; -} - -// ------------------------------------------------------------------------ - -/** - * Unordered List - * - * Generates an HTML unordered list from an single or multi-dimensional array. - * - * @access public - * @param array - * @param mixed - * @return string - */ -function ul($list, $attributes = '') -{ - return _list('ul', $list, $attributes); -} - -// ------------------------------------------------------------------------ - -/** - * Ordered List - * - * Generates an HTML ordered list from an single or multi-dimensional array. - * - * @access public - * @param array - * @param mixed - * @return string - */ -function ol($list, $attributes = '') -{ - return _list('ol', $list, $attributes); -} - -// ------------------------------------------------------------------------ - -/** - * Generates the list - * - * Generates an HTML ordered list from an single or multi-dimensional array. - * - * @access private - * @param string - * @param mixed - * @param mixed - * @param intiger - * @return string - */ -function _list($type = 'ul', $list, $attributes = '', $depth = 0) -{ - // 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); - - // Were any attributes submitted? If so generate a string - if (is_array($attributes)) - { - $atts = ''; - foreach ($attributes as $key => $val) - { - $atts .= ' ' . $key . '="' . $val . '"'; - } - $attributes = $atts; - } - - // Write the opening list tag - $out .= "<".$type.$attributes.">\n"; - - // 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; - - $out .= str_repeat(" ", $depth + 2); - $out .= "
  • "; - - if ( ! is_array($val)) - { - $out .= $val; - } - else - { - $out .= $_last_list_item."\n"; - $out .= _list($type, $val, '', $depth + 4); - $out .= str_repeat(" ", $depth + 2); - } - - $out .= "
  • \n"; - } - - // Set the indentation for the closing tag - $out .= str_repeat(" ", $depth); - - // Write the closing list tag - $out .= "\n"; - - return $out; -} - -// ------------------------------------------------------------------------ - -/** - * Generates HTML BR tags based on number supplied - * - * @access public - * @param integer - * @return string - */ -function br($num = 1) -{ - return str_repeat("
    ", $num); -} - -// ------------------------------------------------------------------------ - -/** - * Generates non-breaking space entities based on number supplied - * - * @access public - * @param integer - * @return string - */ -function nbs($num = 1) -{ - return str_repeat(" ", $num); -} - -// ------------------------------------------------------------------------ - -/** - * Generates meta tags from an array of key/values - * - * @access public - * @param array - * @return string - */ -function meta($meta = array(), $newline = "\n") -{ - $str = ''; - foreach ($meta as $key => $val) - { - $str .= ''.$newline; - } - - return $str; -} - - - - +".$data.""; +} + +// ------------------------------------------------------------------------ + +/** + * Unordered List + * + * Generates an HTML unordered list from an single or multi-dimensional array. + * + * @access public + * @param array + * @param mixed + * @return string + */ +function ul($list, $attributes = '') +{ + return _list('ul', $list, $attributes); +} + +// ------------------------------------------------------------------------ + +/** + * Ordered List + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @access public + * @param array + * @param mixed + * @return string + */ +function ol($list, $attributes = '') +{ + return _list('ol', $list, $attributes); +} + +// ------------------------------------------------------------------------ + +/** + * Generates the list + * + * Generates an HTML ordered list from an single or multi-dimensional array. + * + * @access private + * @param string + * @param mixed + * @param mixed + * @param intiger + * @return string + */ +function _list($type = 'ul', $list, $attributes = '', $depth = 0) +{ + // 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); + + // Were any attributes submitted? If so generate a string + if (is_array($attributes)) + { + $atts = ''; + foreach ($attributes as $key => $val) + { + $atts .= ' ' . $key . '="' . $val . '"'; + } + $attributes = $atts; + } + + // Write the opening list tag + $out .= "<".$type.$attributes.">\n"; + + // 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; + + $out .= str_repeat(" ", $depth + 2); + $out .= "
  • "; + + if ( ! is_array($val)) + { + $out .= $val; + } + else + { + $out .= $_last_list_item."\n"; + $out .= _list($type, $val, '', $depth + 4); + $out .= str_repeat(" ", $depth + 2); + } + + $out .= "
  • \n"; + } + + // Set the indentation for the closing tag + $out .= str_repeat(" ", $depth); + + // Write the closing list tag + $out .= "\n"; + + return $out; +} + +// ------------------------------------------------------------------------ + +/** + * Generates HTML BR tags based on number supplied + * + * @access public + * @param integer + * @return string + */ +function br($num = 1) +{ + return str_repeat("
    ", $num); +} + +// ------------------------------------------------------------------------ + +/** + * Generates non-breaking space entities based on number supplied + * + * @access public + * @param integer + * @return string + */ +function nbs($num = 1) +{ + return str_repeat(" ", $num); +} + +// ------------------------------------------------------------------------ + +/** + * Generates meta tags from an array of key/values + * + * @access public + * @param array + * @return string + */ +function meta($meta = array(), $newline = "\n") +{ + $str = ''; + foreach ($meta as $key => $val) + { + $str .= ''.$newline; + } + + return $str; +} + + + + ?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 666ec40b8..fbe851f3b 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,140 +1,140 @@ - \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 06228468f..eec04015d 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -1,112 +1,112 @@ -input->xss_clean($str, $charset); -} - -// -------------------------------------------------------------------- - -/** - * Hash encode a string - * - * @access public - * @param string - * @return string - */ -function dohash($str, $type = 'sha1') -{ - if ($type == 'sha1') - { - if ( ! function_exists('sha1')) - { - if ( ! function_exists('mhash')) - { - require_once(BASEPATH.'libraries/Sha1'.EXT); - $SH = new CI_SHA; - return $SH->generate($str); - } - else - { - return bin2hex(mhash(MHASH_SHA1, $str)); - } - } - else - { - return sha1($str); - } - } - else - { - return md5($str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Strip Image Tags - * - * @access public - * @param string - * @return string - */ -function strip_image_tags($str) -{ - $str = preg_replace("##", "\\1", $str); - $str = preg_replace("##", "\\1", $str); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Convert PHP tags to entities - * - * @access public - * @param string - * @return string - */ -function encode_php_tags($str) -{ - return str_replace(array(''), array('<?php', '<?PHP', '<?', '?>'), $str); -} - +input->xss_clean($str, $charset); +} + +// -------------------------------------------------------------------- + +/** + * Hash encode a string + * + * @access public + * @param string + * @return string + */ +function dohash($str, $type = 'sha1') +{ + if ($type == 'sha1') + { + if ( ! function_exists('sha1')) + { + if ( ! function_exists('mhash')) + { + require_once(BASEPATH.'libraries/Sha1'.EXT); + $SH = new CI_SHA; + return $SH->generate($str); + } + else + { + return bin2hex(mhash(MHASH_SHA1, $str)); + } + } + else + { + return sha1($str); + } + } + else + { + return md5($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Strip Image Tags + * + * @access public + * @param string + * @return string + */ +function strip_image_tags($str) +{ + $str = preg_replace("##", "\\1", $str); + $str = preg_replace("##", "\\1", $str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Convert PHP tags to entities + * + * @access public + * @param string + * @return string + */ +function encode_php_tags($str) +{ + return str_replace(array(''), 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 a07337246..9f16d3132 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -1,165 +1,165 @@ - - function insert_smiley(smiley) - { - document.{$form_name}.{$form_field}.value += " " + smiley; - } - -EOF; -} - -// ------------------------------------------------------------------------ - -/** - * Get Clickable Smileys - * - * Returns an array of image tag links that can be clicked to be inserted - * into a form field. - * - * @access public - * @param string the URL to the folder containing the smiley images - * @return array - */ -function get_clickable_smileys($image_url = '', $smileys = NULL) -{ - 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); - - $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]])) - { - continue; - } - - $link[] = "\"".$smileys[$key][3]."\""; - - $used[$smileys[$key][0]] = TRUE; - } - - return $link; -} - -// ------------------------------------------------------------------------ - -/** - * Parse Smileys - * - * Takes a string as input and swaps any contained smileys for the actual image - * - * @access public - * @param string the text to be parsed - * @param string the URL to the folder containing the smiley images - * @return string - */ -function parse_smileys($str = '', $image_url = '', $smileys = NULL) -{ - 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); - - foreach ($smileys as $key => $val) - { - $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Get Smiley Array - * - * Fetches the config/smiley.php file - * - * @access private - * @return mixed - */ -function _get_smiley_array() -{ - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) - { - return FALSE; - } - - include(APPPATH.'config/smileys'.EXT); - - if ( ! isset($smileys) OR ! is_array($smileys)) - { - return FALSE; - } - - return $smileys; -} - - - - + + function insert_smiley(smiley) + { + document.{$form_name}.{$form_field}.value += " " + smiley; + } + +EOF; +} + +// ------------------------------------------------------------------------ + +/** + * Get Clickable Smileys + * + * Returns an array of image tag links that can be clicked to be inserted + * into a form field. + * + * @access public + * @param string the URL to the folder containing the smiley images + * @return array + */ +function get_clickable_smileys($image_url = '', $smileys = NULL) +{ + 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); + + $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]])) + { + continue; + } + + $link[] = "\"".$smileys[$key][3]."\""; + + $used[$smileys[$key][0]] = TRUE; + } + + return $link; +} + +// ------------------------------------------------------------------------ + +/** + * Parse Smileys + * + * Takes a string as input and swaps any contained smileys for the actual image + * + * @access public + * @param string the text to be parsed + * @param string the URL to the folder containing the smiley images + * @return string + */ +function parse_smileys($str = '', $image_url = '', $smileys = NULL) +{ + 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); + + foreach ($smileys as $key => $val) + { + $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @access private + * @return mixed + */ +function _get_smiley_array() +{ + if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + { + return FALSE; + } + + include(APPPATH.'config/smileys'.EXT); + + if ( ! isset($smileys) OR ! is_array($smileys)) + { + return FALSE; + } + + return $smileys; +} + + + + ?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index c0a8854dc..04c3a592a 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,12 +1,12 @@ = $n) - { - return trim($out).$end_char; - } - } -} - -// ------------------------------------------------------------------------ - -/** - * High ASCII to Entities - * - * Converts High ascii text and MS Word special characters to character entities - * - * @access public - * @param string - * @return string - */ -function ascii_to_entities($str) -{ - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; -} - -// ------------------------------------------------------------------------ - -/** - * Entities to ASCII - * - * Converts character entities back to ASCII - * - * @access public - * @param string - * @param bool - * @return string - */ -function entities_to_ascii($str, $all = TRUE) -{ - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; - - $out = ''; - - if ($digits < 128) - { - $out .= chr($digits); - - } - elseif ($digits < 2048) - { - $out .= chr(192 + (($digits - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - else - { - $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); - $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - - $str = str_replace($matches['0'][$i], $out, $str); - } - } - - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Word Censoring Function - * - * Supply a string and an array of disallowed words and any - * matched words will be converted to #### or to the replacement - * word you've submitted. - * - * @access public - * @param string the text string - * @param string the array of censoered words - * @param string the optional replacement value - * @return string - */ -function word_censor($str, $censored, $replacement = '') -{ - if ( ! is_array($censored)) - { - return $str; - } - - $str = ' '.$str.' '; - foreach ($censored as $badword) - { - if ($replacement != '') - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); - } - else - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); - } - } - - return trim($str); -} - -// ------------------------------------------------------------------------ - -/** - * Code Highlighter - * - * Colorizes code strings - * - * @access public - * @param string the text string - * @return string - */ -function highlight_code($str) -{ - // The highlight string function encodes and highlights - // brackets so we need them to start raw - $str = str_replace(array('<', '>'), array('<', '>'), $str); - - // Replace any existing PHP tags to temporary markers so they don't accidentally - // break the string out of PHP, and thus, thwart the highlighting. - - $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); - - // The highlight_string function requires that the text be surrounded - // by PHP tags. Since we don't know if A) the submitted text has PHP tags, - // or B) whether the PHP tags enclose the entire string, we will add our - // own PHP tags around the string along with some markers to make replacement easier later - - $str = ''; - - // 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(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } - - // Remove our artificially added PHP - $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); - $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); - $str = preg_replace("#//tempend.+#is", "
    \n", $str); - - // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '
    ') -{ - if ($str == '') - { - return ''; - } - - if ($phrase != '') - { - return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Word Wrap - * - * Wraps text at the specified character. Maintains the integrity of words. - * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor - * will URLs. - * - * @access public - * @param string the text string - * @param integer the number of characters to wrap at - * @return string - */ -function word_wrap($str, $charlim = '76') -{ - // Se the character limit - if ( ! is_numeric($charlim)) - $charlim = 76; - - // Reduce multiple spaces - $str = preg_replace("| +|", " ", $str); - - // Standardize newlines - $str = preg_replace("/\r\n|\r/", "\n", $str); - - // If the current word is surrounded by {unwrap} tags we'll - // strip the entire chunk and replace it with a marker. - $unwrap = array(); - if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $unwrap[] = $matches['1'][$i]; - $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); - } - } - - // Use PHP's native function to do the initial wordwrap. - // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. - $str = wordwrap($str, $charlim, "\n", FALSE); - - // Split the string into individual lines of text and cycle through them - $output = ""; - foreach (explode("\n", $str) as $line) - { - // Is the line within the allowed character count? - // If so we'll join it to the output and continue - if (strlen($line) <= $charlim) - { - $output .= $line."\n"; - continue; - } - - $temp = ''; - while((strlen($line)) > $charlim) - { - // If the over-length word is a URL we won't wrap it - if (preg_match("!\[url.+\]|://|wwww.!", $line)) - { - break; - } - - // Trim the word down - $temp .= substr($line, 0, $charlim-1); - $line = substr($line, $charlim-1); - } - - // If $temp contains data it means we had to split up an over-length - // word into smaller chunks so we'll add it back to our current line - if ($temp != '') - { - $output .= $temp.$this->newline.$line; - } - else - { - $output .= $line; - } - - $output .= "\n"; - } - - // Put our markers back - if (count($unwrap) > 0) - { - foreach ($unwrap as $key => $val) - { - $output = str_replace("{{unwrapped".$key."}}", $val, $output); - } - } - - // Remove the unwrap tags - $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - - return $output; -} - - += $n) + { + return trim($out).$end_char; + } + } +} + +// ------------------------------------------------------------------------ + +/** + * High ASCII to Entities + * + * Converts High ascii text and MS Word special characters to character entities + * + * @access public + * @param string + * @return string + */ +function ascii_to_entities($str) +{ + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { + $out .= $str[$i]; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; +} + +// ------------------------------------------------------------------------ + +/** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @access public + * @param string + * @param bool + * @return string + */ +function entities_to_ascii($str, $all = TRUE) +{ + if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) + { + for ($i = 0, $s = count($matches['0']); $i < $s; $i++) + { + $digits = $matches['1'][$i]; + + $out = ''; + + if ($digits < 128) + { + $out .= chr($digits); + + } + elseif ($digits < 2048) + { + $out .= chr(192 + (($digits - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + else + { + $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); + $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + + $str = str_replace($matches['0'][$i], $out, $str); + } + } + + if ($all) + { + $str = str_replace(array("&", "<", ">", """, "'", "-"), + array("&","<",">","\"", "'", "-"), + $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Word Censoring Function + * + * Supply a string and an array of disallowed words and any + * matched words will be converted to #### or to the replacement + * word you've submitted. + * + * @access public + * @param string the text string + * @param string the array of censoered words + * @param string the optional replacement value + * @return string + */ +function word_censor($str, $censored, $replacement = '') +{ + if ( ! is_array($censored)) + { + return $str; + } + + $str = ' '.$str.' '; + foreach ($censored as $badword) + { + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } + } + + return trim($str); +} + +// ------------------------------------------------------------------------ + +/** + * Code Highlighter + * + * Colorizes code strings + * + * @access public + * @param string the text string + * @return string + */ +function highlight_code($str) +{ + // The highlight string function encodes and highlights + // brackets so we need them to start raw + $str = str_replace(array('<', '>'), array('<', '>'), $str); + + // Replace any existing PHP tags to temporary markers so they don't accidentally + // break the string out of PHP, and thus, thwart the highlighting. + + $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); + + // The highlight_string function requires that the text be surrounded + // by PHP tags. Since we don't know if A) the submitted text has PHP tags, + // or B) whether the PHP tags enclose the entire string, we will add our + // own PHP tags around the string along with some markers to make replacement easier later + + $str = ''; + + // 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(''), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } + + // Remove our artificially added PHP + $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); + $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); + $str = preg_replace("#//tempend.+#is", "
    \n", $str); + + // Replace our markers back to PHP tags. + $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '
    ') +{ + if ($str == '') + { + return ''; + } + + if ($phrase != '') + { + return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); + } + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor + * will URLs. + * + * @access public + * @param string the text string + * @param integer the number of characters to wrap at + * @return string + */ +function word_wrap($str, $charlim = '76') +{ + // Se the character limit + if ( ! is_numeric($charlim)) + $charlim = 76; + + // Reduce multiple spaces + $str = preg_replace("| +|", " ", $str); + + // Standardize newlines + $str = preg_replace("/\r\n|\r/", "\n", $str); + + // If the current word is surrounded by {unwrap} tags we'll + // strip the entire chunk and replace it with a marker. + $unwrap = array(); + if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $unwrap[] = $matches['1'][$i]; + $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); + } + } + + // Use PHP's native function to do the initial wordwrap. + // We set the cut flag to FALSE so that any individual words that are + // too long get left alone. In the next step we'll deal with them. + $str = wordwrap($str, $charlim, "\n", FALSE); + + // Split the string into individual lines of text and cycle through them + $output = ""; + foreach (explode("\n", $str) as $line) + { + // Is the line within the allowed character count? + // If so we'll join it to the output and continue + if (strlen($line) <= $charlim) + { + $output .= $line."\n"; + continue; + } + + $temp = ''; + while((strlen($line)) > $charlim) + { + // If the over-length word is a URL we won't wrap it + if (preg_match("!\[url.+\]|://|wwww.!", $line)) + { + break; + } + + // Trim the word down + $temp .= substr($line, 0, $charlim-1); + $line = substr($line, $charlim-1); + } + + // If $temp contains data it means we had to split up an over-length + // word into smaller chunks so we'll add it back to our current line + if ($temp != '') + { + $output .= $temp.$this->newline.$line; + } + else + { + $output .= $line; + } + + $output .= "\n"; + } + + // Put our markers back + if (count($unwrap) > 0) + { + foreach ($unwrap as $key => $val) + { + $output = str_replace("{{unwrapped".$key."}}", $val, $output); + } + } + + // Remove the unwrap tags + $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); + + return $output; +} + + ?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 1681fa37c..131358c6a 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,540 +1,540 @@ -",$str); - $ct = count($ex); - - $newstr = ""; - for ($i = 0; $i < $ct; $i++) - { - if (($i % 2) == 0) - { - $newstr .= nl2br($ex[$i]); - } - else - { - $newstr .= $ex[$i]; - } - - if ($ct - 1 != $i) - $newstr .= "pre>"; - } - - return $newstr; -} - -// ------------------------------------------------------------------------ - -/** - * Auto Typography Wrapper Function - * - * - * @access public - * @param string - * @return string - */ -function auto_typography($str) -{ - $TYPE = new Auto_typography(); - return $TYPE->convert($str); -} - -// ------------------------------------------------------------------------ - -/** - * Auto Typography Class - * - * - * @access private - * @category Helpers - * @author Rick Ellis - * @author Paul Burdick - * @link http://www.codeigniter.com/user_guide/helpers/ - */ -class Auto_typography { - - // Block level elements that should not be wrapped inside

    tags - var $block_elements = 'div|blockquote|pre|code|h\d|script|ol|un'; - - // Elements that should not have

    and
    tags within them. - var $skip_elements = 'pre|ol|ul'; - - // Tags we want the parser to completely ignore when splitting the string. - var $ignore_elements = 'a|b|i|em|strong|span|img|li'; - - - /** - * Main Processing Function - * - */ - function convert($str) - { - if ($str == '') - { - return ''; - } - - $str = ' '.$str.' '; - - // Standardize Newlines to make matching easier - $str = preg_replace("/(\r\n|\r)/", "\n", $str); - - /* - * Reduce line breaks - * - * If there are more than two consecutive line - * breaks we'll compress them down to a maximum - * of two since there's no benefit to more. - * - */ - $str = preg_replace("/\n\n+/", "\n\n", $str); - - /* - * Convert quotes within tags to temporary marker - * - * We don't want quotes converted within - * tags so we'll temporarily convert them to - * {@DQ} and {@SQ} - * - */ - if (preg_match_all("#\<.+?>#si", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $str = str_replace($matches['0'][$i], - str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), - $str); - } - } - - - /* - * Add closing/opening paragraph tags before/after "block" elements - * - * Since block elements (like ,

    , etc.) do not get
    -		 * wrapped in paragraph tags we will add a closing 

    tag just before - * each block element starts and an opening

    tag right after the block element - * ends. Later on we'll do some further clean up. - * - */ - $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

    \\1\\2\\3", $str); - $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

    ", $str); - - /* - * Convert "ignore" tags to temporary marker - * - * The parser splits out the string at every tag - * it encounters. Certain inline tags, like image - * tags, links, span tags, etc. will be adversely - * affected if they are split out so we'll convert - * the opening < temporarily to: {@TAG} - * - */ - $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); - - /* - * Split the string at every tag - * - * This creates an array with this prototype: - * - * [array] - * { - * [0] = - * [1] = Content contained between the tags - * [2] = - * Etc... - * } - * - */ - $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); - - /* - * Build our finalized string - * - * We'll cycle through the array, skipping tags, - * and processing the contained text - * - */ - $str = ''; - $process = TRUE; - foreach ($chunks as $chunk) - { - /* - * Are we dealing with a tag? - * - * If so, we'll skip the processing for this cycle. - * Well also set the "process" flag which allows us - * to skip

     tags and a few other things.
    -			 *
    -			 */
    -			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
    -			{
    -				if (preg_match("#".$this->skip_elements."#", $match['2']))
    -				{
    -					$process =  ($match['1'] == '/') ? TRUE : FALSE;		
    -				}
    -		
    -				$str .= $chunk;
    -				continue;
    -			}
    -		
    -			if ($process == FALSE)
    -			{
    -				$str .= $chunk;
    -				continue;
    -			}
    -			
    -			//  Convert Newlines into 

    and
    tags - $str .= $this->format_newlines($chunk); - } - - // FINAL CLEAN UP - // IMPORTANT: DO NOT ALTER THE ORDER OF THE ITEMS BELOW! - - /* - * Clean up paragraph tags before/after "block" elements - * - * Earlier we added

    tags before/after block level elements. - * Then, we added paragraph tags around double line breaks. This - * potentially created incorrectly formatted paragraphs so we'll - * clean it up here. - * - */ - $str = preg_replace("#

    ({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); - $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

    #", "\\1\\2\\3", $str); - - // Convert Quotes and other characters - $str = $this->format_characters($str); - - // Fix an artifact that happens during the paragraph replacement - $str = preg_replace('#(

    \n*

    )#', '', $str); - - // If the user submitted their own paragraph tags with class data - // in them we will retain them instead of using our tags. - $str = preg_replace('#()

    #', "\\1", $str); - - // Final clean up - $str = str_replace( - array( - '

    ', - '

    ', - '

    ', - '

    ', - '{@TAG}', - '{@DQ}', - '{@SQ}', - '

    ' - ), - array( - '

    ', - '

    ', - '

    ', - '

    ', - '<', - '"', - "'", - '' - ), - $str - ); - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Format Characters - * - * This function mainly converts double and single quotes - * to entities, but since these are directional, it does - * it based on some rules. It also converts em-dashes - * and a couple other things. - */ - function format_characters($str) - { - $table = array( - ' "' => " “", - '" ' => "” ", - " '" => " ‘", - "' " => "’ ", - - '>"' => ">“", - '"<' => "”<", - ">'" => ">‘", - "'<" => "’<", - - "\"." => "”.", - "\"," => "”,", - "\";" => "”;", - "\":" => "”:", - "\"!" => "”!", - "\"?" => "”?", - - ". " => ".  ", - "? " => "?  ", - "! " => "!  ", - ": " => ":  ", - ); - - // These deal with quotes within quotes, like: "'hi here'" - $start = 0; - $space = array("\n", "\t", " "); - - while(TRUE) - { - $current = strpos(substr($str, $start), "\"'"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+2, 1); - - if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") - { - $str = str_replace( $one_before."\"'".$one_after, - $one_before."“‘".$one_after, - $str); - } - elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) - { - $str = str_replace( $one_before."\"'".$one_after, - $one_before."”’".$one_after, - $str); - } - - $start = $start+$current+2; - } - - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), "'\""); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+2, 1); - - if ( in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE) && $one_after != "<") - { - $str = str_replace( $one_before."'\"".$one_after, - $one_before."‘“".$one_after, - $str); - } - elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") - { - $str = str_replace( $one_before."'\"".$one_after, - $one_before."’”".$one_after, - $str); - } - - $start = $start+$current+2; - } - - // Are there quotes within a word, as in: ("something") - if (preg_match_all("/(.)\"(\S+?)\"(.)/", $str, $matches)) - { - for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) - { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) - { - $str = str_replace( $matches['0'][$i], - $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], - $str); - } - } - } - - if (preg_match_all("/(.)\'(\S+?)\'(.)/", $str, $matches)) - { - for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) - { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) - { - $str = str_replace( $matches['0'][$i], - $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], - $str); - } - } - } - - // How about one apostrophe, as in Rick's - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), "'"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+1, 1); - - if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."’".$one_after, - $str); - } - - $start = $start+$current+2; - } - - // Em-dashes - $start = 0; - while(TRUE) - { - $current = strpos(substr($str, $start), "--"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+2, 1); - $two_before = substr($str, $start+$current-2, 1); - $two_after = substr($str, $start+$current+3, 1); - - if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) - OR - ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') - ) - { - $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, - $two_before.trim($one_before)."—".trim($one_after).$two_after, - $str); - } - - $start = $start+$current+2; - } - - // Ellipsis - $str = preg_replace("#(\w)\.\.\.(\s|
    |

    )#", "\\1…\\2", $str); - $str = preg_replace("#(\s|
    |

    )\.\.\.(\w)#", "\\1…\\2", $str); - - // Run the translation array we defined above - $str = str_replace(array_keys($table), array_values($table), $str); - - // If there are any stray double quotes we'll catch them here - - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), '"'); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+1, 1); - - if ( ! in_array($one_after, $space, TRUE)) - { - $str = str_replace( $one_before.'"'.$one_after, - $one_before."“".$one_after, - $str); - } - elseif( ! in_array($one_before, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."”".$one_after, - $str); - } - - $start = $start+$current+2; - } - - $start = 0; - - while(TRUE) - { - $current = strpos(substr($str, $start), "'"); - - if ($current === FALSE) break; - - $one_before = substr($str, $start+$current-1, 1); - $one_after = substr($str, $start+$current+1, 1); - - if ( ! in_array($one_after, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."‘".$one_after, - $str); - } - elseif( ! in_array($one_before, $space, TRUE)) - { - $str = str_replace( $one_before."'".$one_after, - $one_before."’".$one_after, - $str); - } - - $start = $start+$current+2; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Format Newlines - * - * Converts newline characters into either

    tags or
    - * - */ - function format_newlines($str) - { - if ($str == '') - { - return $str; - } - - if (strpos($str, "\n") === FALSE) - { - return '

    '.$str.'

    '; - } - - $str = str_replace("\n\n", "

    \n\n

    ", $str); - $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); - - return '

    '.$str.'

    '; - } -} - - +",$str); + $ct = count($ex); + + $newstr = ""; + for ($i = 0; $i < $ct; $i++) + { + if (($i % 2) == 0) + { + $newstr .= nl2br($ex[$i]); + } + else + { + $newstr .= $ex[$i]; + } + + if ($ct - 1 != $i) + $newstr .= "pre>"; + } + + return $newstr; +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Wrapper Function + * + * + * @access public + * @param string + * @return string + */ +function auto_typography($str) +{ + $TYPE = new Auto_typography(); + return $TYPE->convert($str); +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Class + * + * + * @access private + * @category Helpers + * @author Rick Ellis + * @author Paul Burdick + * @link http://www.codeigniter.com/user_guide/helpers/ + */ +class Auto_typography { + + // Block level elements that should not be wrapped inside

    tags + var $block_elements = 'div|blockquote|pre|code|h\d|script|ol|un'; + + // Elements that should not have

    and
    tags within them. + var $skip_elements = 'pre|ol|ul'; + + // Tags we want the parser to completely ignore when splitting the string. + var $ignore_elements = 'a|b|i|em|strong|span|img|li'; + + + /** + * Main Processing Function + * + */ + function convert($str) + { + if ($str == '') + { + return ''; + } + + $str = ' '.$str.' '; + + // Standardize Newlines to make matching easier + $str = preg_replace("/(\r\n|\r)/", "\n", $str); + + /* + * Reduce line breaks + * + * If there are more than two consecutive line + * breaks we'll compress them down to a maximum + * of two since there's no benefit to more. + * + */ + $str = preg_replace("/\n\n+/", "\n\n", $str); + + /* + * Convert quotes within tags to temporary marker + * + * We don't want quotes converted within + * tags so we'll temporarily convert them to + * {@DQ} and {@SQ} + * + */ + if (preg_match_all("#\<.+?>#si", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $str = str_replace($matches['0'][$i], + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), + $str); + } + } + + + /* + * Add closing/opening paragraph tags before/after "block" elements + * + * Since block elements (like ,

    , etc.) do not get
    +		 * wrapped in paragraph tags we will add a closing 

    tag just before + * each block element starts and an opening

    tag right after the block element + * ends. Later on we'll do some further clean up. + * + */ + $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

    \\1\\2\\3", $str); + $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

    ", $str); + + /* + * Convert "ignore" tags to temporary marker + * + * The parser splits out the string at every tag + * it encounters. Certain inline tags, like image + * tags, links, span tags, etc. will be adversely + * affected if they are split out so we'll convert + * the opening < temporarily to: {@TAG} + * + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); + + /* + * Split the string at every tag + * + * This creates an array with this prototype: + * + * [array] + * { + * [0] = + * [1] = Content contained between the tags + * [2] = + * Etc... + * } + * + */ + $chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); + + /* + * Build our finalized string + * + * We'll cycle through the array, skipping tags, + * and processing the contained text + * + */ + $str = ''; + $process = TRUE; + foreach ($chunks as $chunk) + { + /* + * Are we dealing with a tag? + * + * If so, we'll skip the processing for this cycle. + * Well also set the "process" flag which allows us + * to skip

     tags and a few other things.
    +			 *
    +			 */
    +			if (preg_match("#<(/*)(".$this->block_elements.").*?\>#", $chunk, $match))
    +			{
    +				if (preg_match("#".$this->skip_elements."#", $match['2']))
    +				{
    +					$process =  ($match['1'] == '/') ? TRUE : FALSE;		
    +				}
    +		
    +				$str .= $chunk;
    +				continue;
    +			}
    +		
    +			if ($process == FALSE)
    +			{
    +				$str .= $chunk;
    +				continue;
    +			}
    +			
    +			//  Convert Newlines into 

    and
    tags + $str .= $this->format_newlines($chunk); + } + + // FINAL CLEAN UP + // IMPORTANT: DO NOT ALTER THE ORDER OF THE ITEMS BELOW! + + /* + * Clean up paragraph tags before/after "block" elements + * + * Earlier we added

    tags before/after block level elements. + * Then, we added paragraph tags around double line breaks. This + * potentially created incorrectly formatted paragraphs so we'll + * clean it up here. + * + */ + $str = preg_replace("#

    ({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); + $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

    #", "\\1\\2\\3", $str); + + // Convert Quotes and other characters + $str = $this->format_characters($str); + + // Fix an artifact that happens during the paragraph replacement + $str = preg_replace('#(

    \n*

    )#', '', $str); + + // If the user submitted their own paragraph tags with class data + // in them we will retain them instead of using our tags. + $str = preg_replace('#()

    #', "\\1", $str); + + // Final clean up + $str = str_replace( + array( + '

    ', + '

    ', + '

    ', + '

    ', + '{@TAG}', + '{@DQ}', + '{@SQ}', + '

    ' + ), + array( + '

    ', + '

    ', + '

    ', + '

    ', + '<', + '"', + "'", + '' + ), + $str + ); + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Format Characters + * + * This function mainly converts double and single quotes + * to entities, but since these are directional, it does + * it based on some rules. It also converts em-dashes + * and a couple other things. + */ + function format_characters($str) + { + $table = array( + ' "' => " “", + '" ' => "” ", + " '" => " ‘", + "' " => "’ ", + + '>"' => ">“", + '"<' => "”<", + ">'" => ">‘", + "'<" => "’<", + + "\"." => "”.", + "\"," => "”,", + "\";" => "”;", + "\":" => "”:", + "\"!" => "”!", + "\"?" => "”?", + + ". " => ".  ", + "? " => "?  ", + "! " => "!  ", + ": " => ":  ", + ); + + // These deal with quotes within quotes, like: "'hi here'" + $start = 0; + $space = array("\n", "\t", " "); + + while(TRUE) + { + $current = strpos(substr($str, $start), "\"'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."“‘".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) + { + $str = str_replace( $one_before."\"'".$one_after, + $one_before."”’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'\""); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + + if ( in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE) && $one_after != "<") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."‘“".$one_after, + $str); + } + elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") + { + $str = str_replace( $one_before."'\"".$one_after, + $one_before."’”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Are there quotes within a word, as in: ("something") + if (preg_match_all("/(.)\"(\S+?)\"(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], + $str); + } + } + } + + if (preg_match_all("/(.)\'(\S+?)\'(.)/", $str, $matches)) + { + for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) + { + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + { + $str = str_replace( $matches['0'][$i], + $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], + $str); + } + } + } + + // How about one apostrophe, as in Rick's + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + // Em-dashes + $start = 0; + while(TRUE) + { + $current = strpos(substr($str, $start), "--"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+2, 1); + $two_before = substr($str, $start+$current-2, 1); + $two_after = substr($str, $start+$current+3, 1); + + if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + OR + ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') + ) + { + $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, + $two_before.trim($one_before)."—".trim($one_after).$two_after, + $str); + } + + $start = $start+$current+2; + } + + // Ellipsis + $str = preg_replace("#(\w)\.\.\.(\s|
    |

    )#", "\\1…\\2", $str); + $str = preg_replace("#(\s|
    |

    )\.\.\.(\w)#", "\\1…\\2", $str); + + // Run the translation array we defined above + $str = str_replace(array_keys($table), array_values($table), $str); + + // If there are any stray double quotes we'll catch them here + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), '"'); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space, TRUE)) + { + $str = str_replace( $one_before.'"'.$one_after, + $one_before."“".$one_after, + $str); + } + elseif( ! in_array($one_before, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."”".$one_after, + $str); + } + + $start = $start+$current+2; + } + + $start = 0; + + while(TRUE) + { + $current = strpos(substr($str, $start), "'"); + + if ($current === FALSE) break; + + $one_before = substr($str, $start+$current-1, 1); + $one_after = substr($str, $start+$current+1, 1); + + if ( ! in_array($one_after, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."‘".$one_after, + $str); + } + elseif( ! in_array($one_before, $space, TRUE)) + { + $str = str_replace( $one_before."'".$one_after, + $one_before."’".$one_after, + $str); + } + + $start = $start+$current+2; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Format Newlines + * + * Converts newline characters into either

    tags or
    + * + */ + function format_newlines($str) + { + if ($str == '') + { + return $str; + } + + if (strpos($str, "\n") === FALSE) + { + return '

    '.$str.'

    '; + } + + $str = str_replace("\n\n", "

    \n\n

    ", $str); + $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
    \\2\\3", $str); + + return '

    '.$str.'

    '; + } +} + + ?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index baac0e5d8..c05bc2088 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,12 +1,12 @@ ","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; -} - - +","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cea5dbe08c909c5efa54bbaa56980b2288bbd296 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 27 Apr 2007 03:33:21 +0000 Subject: fixed checked = 1 to be checked = checked in array created checkboxes --- system/helpers/form_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index adbddd5ad..531ab66c0 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -260,7 +260,13 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') $checked = $data['checked']; if ($checked == FALSE) + { unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } } if ($checked == TRUE) -- cgit v1.2.3-24-g4f1b From 2c25fd0fb075090257e69440c94ef6fddd6f02f2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 2 May 2007 11:39:23 +0000 Subject: return preg_replace("|^/*(.+?)/*$|", "\\1", $str); to return trim($str, '/'); --- system/helpers/string_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 04c3a592a..011be2333 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -44,8 +44,8 @@ */ function trim_slashes($str) { - return preg_replace("|^/*(.+?)/*$|", "\\1", $str); -} + return trim($str, '/'); +} // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From f5a519822db2201b98f822ad4f8659bad2ce9bcd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 11 Jul 2007 19:35:09 +0000 Subject: inflector helper changes to account for words ending in "s" --- system/helpers/inflector_helper.php | 78 ++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 32 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index fbe851f3b..28ecf5201 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -39,26 +39,31 @@ */ function singular($str) { - $str = strtolower(trim($str)); - $end = substr($str, -3); - - if ($end == 'ies') - { - $str = substr($str, 0, strlen($str)-3).'y'; - } - else - { - $end = substr($str, -1); - - if ($end == 's') - { - $str = substr($str, 0, strlen($str)-1); - } - } - - return $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 == 's') + { + $str = substr($str, 0, strlen($str)-1); + } + } + + return $str; } + // -------------------------------------------------------------------- /** @@ -68,25 +73,34 @@ function singular($str) * * @access public * @param string + * @param bool * @return str */ -function plural($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') - { - $str .= 's'; - } - - return $str; + $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; } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 1f2fd2d5db0ff9e91388cec079a9ff58392ab654 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 21:59:12 +0000 Subject: adding type casting of $title argument in URL helper functions to a string. A numeric 0 sent to these functions would evaluate if ($title == '') as TRUE, and type casting seems the more appropriate fix than simply using $title === '', since we're expecting and treating $title as a string. --- system/helpers/url_helper.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index c05bc2088..01cd3458d 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -90,6 +90,8 @@ function index_page() */ function anchor($uri = '', $title = '', $attributes = '') { + $title = (string) $title; + if ( ! is_array($uri)) { $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; @@ -132,6 +134,8 @@ function anchor($uri = '', $title = '', $attributes = '') */ function anchor_popup($uri = '', $title = '', $attributes = FALSE) { + $title = (string) $title; + $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; if ($title == '') @@ -170,6 +174,8 @@ function anchor_popup($uri = '', $title = '', $attributes = FALSE) */ function mailto($email, $title = '', $attributes = '') { + $title = (string) $title; + if ($title == "") { $title = $email; @@ -195,6 +201,8 @@ function mailto($email, $title = '', $attributes = '') */ function safe_mailto($email, $title = '', $attributes = '') { + $title = (string) $title; + if ($title == "") { $title = $email; -- cgit v1.2.3-24-g4f1b From eea2bdaaffcbee1a9efb56e60ae5712e30873f87 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 22:09:45 +0000 Subject: fixed the plural() and singular() function comments --- system/helpers/inflector_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 28ecf5201..49143913c 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -31,7 +31,7 @@ /** * Singular * - * Takes a singular word and makes it plural + * Takes a plural word and makes it singular * * @access public * @param string @@ -69,7 +69,7 @@ function singular($str) /** * Plural * - * Takes a plural word and makes it singular + * Takes a singular word and makes it plural * * @access public * @param string -- cgit v1.2.3-24-g4f1b From c80593c537117b11e2f75287fc9a18e0d0d2bf5a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 23:40:14 +0000 Subject: type cast $key => $val pair in $options array as strings for friendlier handling of setting options as 'selected' --- system/helpers/form_helper.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 531ab66c0..263dc0f19 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -229,6 +229,9 @@ function form_dropdown($name = '', $options = array(), $selected = '', $extra = foreach ($options as $key => $val) { + $key = (string) $key; + $val = (string) $val; + $sel = ($selected != $key) ? '' : ' selected="selected"'; $form .= '\n"; -- cgit v1.2.3-24-g4f1b From 7aa1809e775bddfa08e17d8424a3532fcf06d6ae Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 19 Jul 2007 00:13:13 +0000 Subject: --- system/helpers/cookie_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 9dc5df9b1..4fb30bd5b 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -60,15 +60,15 @@ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') { - $CI->config->item('cookie_prefix'); + $prefix = $CI->config->item('cookie_prefix'); } if ($domain == '' AND $CI->config->item('cookie_domain') != '') { - $CI->config->item('cookie_domain'); + $domain = $CI->config->item('cookie_domain'); } - if ($prefix == '/' AND $CI->config->item('cookie_path') != '/') + if ($path == '/' AND $CI->config->item('cookie_path') != '/') { - $CI->config->item('cookie_path'); + $path = $CI->config->item('cookie_path'); } if ( ! is_numeric($expire)) -- cgit v1.2.3-24-g4f1b From 6838f00a708f53f834fb8a98af560177db1d1454 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Oct 2007 19:29:59 +0000 Subject: Fixed a typo in the docblock comments that had CodeIgniter spelled CodeIgnitor. --- system/helpers/array_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- system/helpers/download_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/form_helper.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/inflector_helper.php | 2 +- system/helpers/security_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 2 +- system/helpers/xml_helper.php | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 674ef3bec..9c4447198 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 4fb30bd5b..663ef1c5d 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index c67e3da2d..b80f5f7d7 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 71f3778a1..425613669 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index c9d81f692..257233481 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 89801c0bf..18798fdf4 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 263dc0f19..17022a3b3 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 152d18b76..48d680f29 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 49143913c..4202bd12c 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index eec04015d..a8afd7dbd 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 9f16d3132..86654a761 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 011be2333..8ef715953 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 3c7270b9b..d315db0ff 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 131358c6a..355f02cf9 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 01cd3458d..b75ae6b11 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 398b07e3f..e041bf9b6 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource -- cgit v1.2.3-24-g4f1b From 1a274a0c5971086ed1690094790ad12858a73fd4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 30 Nov 2007 01:34:12 +0000 Subject: Fixed a bug in word_wrap() of the Text Helper that incorrectly referenced an object. --- system/helpers/text_helper.php | 422 +---------------------------------------- 1 file changed, 1 insertion(+), 421 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index d315db0ff..fb50ba9d7 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1,421 +1 @@ -= $n) - { - return trim($out).$end_char; - } - } -} - -// ------------------------------------------------------------------------ - -/** - * High ASCII to Entities - * - * Converts High ascii text and MS Word special characters to character entities - * - * @access public - * @param string - * @return string - */ -function ascii_to_entities($str) -{ - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; -} - -// ------------------------------------------------------------------------ - -/** - * Entities to ASCII - * - * Converts character entities back to ASCII - * - * @access public - * @param string - * @param bool - * @return string - */ -function entities_to_ascii($str, $all = TRUE) -{ - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; - - $out = ''; - - if ($digits < 128) - { - $out .= chr($digits); - - } - elseif ($digits < 2048) - { - $out .= chr(192 + (($digits - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - else - { - $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); - $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - - $str = str_replace($matches['0'][$i], $out, $str); - } - } - - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Word Censoring Function - * - * Supply a string and an array of disallowed words and any - * matched words will be converted to #### or to the replacement - * word you've submitted. - * - * @access public - * @param string the text string - * @param string the array of censoered words - * @param string the optional replacement value - * @return string - */ -function word_censor($str, $censored, $replacement = '') -{ - if ( ! is_array($censored)) - { - return $str; - } - - $str = ' '.$str.' '; - foreach ($censored as $badword) - { - if ($replacement != '') - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); - } - else - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); - } - } - - return trim($str); -} - -// ------------------------------------------------------------------------ - -/** - * Code Highlighter - * - * Colorizes code strings - * - * @access public - * @param string the text string - * @return string - */ -function highlight_code($str) -{ - // The highlight string function encodes and highlights - // brackets so we need them to start raw - $str = str_replace(array('<', '>'), array('<', '>'), $str); - - // Replace any existing PHP tags to temporary markers so they don't accidentally - // break the string out of PHP, and thus, thwart the highlighting. - - $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); - - // The highlight_string function requires that the text be surrounded - // by PHP tags. Since we don't know if A) the submitted text has PHP tags, - // or B) whether the PHP tags enclose the entire string, we will add our - // own PHP tags around the string along with some markers to make replacement easier later - - $str = ''; - - // 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(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } - - // Remove our artificially added PHP - $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); - $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); - $str = preg_replace("#//tempend.+#is", "
    \n", $str); - - // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') -{ - if ($str == '') - { - return ''; - } - - if ($phrase != '') - { - return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); - } - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Word Wrap - * - * Wraps text at the specified character. Maintains the integrity of words. - * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor - * will URLs. - * - * @access public - * @param string the text string - * @param integer the number of characters to wrap at - * @return string - */ -function word_wrap($str, $charlim = '76') -{ - // Se the character limit - if ( ! is_numeric($charlim)) - $charlim = 76; - - // Reduce multiple spaces - $str = preg_replace("| +|", " ", $str); - - // Standardize newlines - $str = preg_replace("/\r\n|\r/", "\n", $str); - - // If the current word is surrounded by {unwrap} tags we'll - // strip the entire chunk and replace it with a marker. - $unwrap = array(); - if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $unwrap[] = $matches['1'][$i]; - $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); - } - } - - // Use PHP's native function to do the initial wordwrap. - // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. - $str = wordwrap($str, $charlim, "\n", FALSE); - - // Split the string into individual lines of text and cycle through them - $output = ""; - foreach (explode("\n", $str) as $line) - { - // Is the line within the allowed character count? - // If so we'll join it to the output and continue - if (strlen($line) <= $charlim) - { - $output .= $line."\n"; - continue; - } - - $temp = ''; - while((strlen($line)) > $charlim) - { - // If the over-length word is a URL we won't wrap it - if (preg_match("!\[url.+\]|://|wwww.!", $line)) - { - break; - } - - // Trim the word down - $temp .= substr($line, 0, $charlim-1); - $line = substr($line, $charlim-1); - } - - // If $temp contains data it means we had to split up an over-length - // word into smaller chunks so we'll add it back to our current line - if ($temp != '') - { - $output .= $temp.$this->newline.$line; - } - else - { - $output .= $line; - } - - $output .= "\n"; - } - - // Put our markers back - if (count($unwrap) > 0) - { - foreach ($unwrap as $key => $val) - { - $output = str_replace("{{unwrapped".$key."}}", $val, $output); - } - } - - // Remove the unwrap tags - $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - - return $output; -} - - -?> \ No newline at end of file += $n) { return trim($out).$end_char; } } } // ------------------------------------------------------------------------ /** * High ASCII to Entities * * Converts High ascii text and MS Word special characters to character entities * * @access public * @param string * @return string */ function ascii_to_entities($str) { $count = 1; $out = ''; $temp = array(); for ($i = 0, $s = strlen($str); $i < $s; $i++) { $ordinal = ord($str[$i]); if ($ordinal < 128) { $out .= $str[$i]; } else { if (count($temp) == 0) { $count = ($ordinal < 224) ? 2 : 3; } $temp[] = $ordinal; if (count($temp) == $count) { $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); $out .= '&#'.$number.';'; $count = 1; $temp = array(); } } } return $out; } // ------------------------------------------------------------------------ /** * Entities to ASCII * * Converts character entities back to ASCII * * @access public * @param string * @param bool * @return string */ function entities_to_ascii($str, $all = TRUE) { if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) { for ($i = 0, $s = count($matches['0']); $i < $s; $i++) { $digits = $matches['1'][$i]; $out = ''; if ($digits < 128) { $out .= chr($digits); } elseif ($digits < 2048) { $out .= chr(192 + (($digits - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } else { $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } $str = str_replace($matches['0'][$i], $out, $str); } } if ($all) { $str = str_replace(array("&", "<", ">", """, "'", "-"), array("&","<",">","\"", "'", "-"), $str); } return $str; } // ------------------------------------------------------------------------ /** * Word Censoring Function * * Supply a string and an array of disallowed words and any * matched words will be converted to #### or to the replacement * word you've submitted. * * @access public * @param string the text string * @param string the array of censoered words * @param string the optional replacement value * @return string */ function word_censor($str, $censored, $replacement = '') { if ( ! is_array($censored)) { return $str; } $str = ' '.$str.' '; foreach ($censored as $badword) { if ($replacement != '') { $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); } else { $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); } } return trim($str); } // ------------------------------------------------------------------------ /** * Code Highlighter * * Colorizes code strings * * @access public * @param string the text string * @return string */ function highlight_code($str) { // The highlight string function encodes and highlights // brackets so we need them to start raw $str = str_replace(array('<', '>'), array('<', '>'), $str); // Replace any existing PHP tags to temporary markers so they don't accidentally // break the string out of PHP, and thus, thwart the highlighting. $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); // The highlight_string function requires that the text be surrounded // by PHP tags. Since we don't know if A) the submitted text has PHP tags, // or B) whether the PHP tags enclose the entire string, we will add our // own PHP tags around the string along with some markers to make replacement easier later $str = ''; // 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(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } // Remove our artificially added PHP $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); $str = preg_replace("#//tempend.+#is", "
    \n", $str); // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') { if ($str == '') { return ''; } if ($phrase != '') { return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); } return $str; } // ------------------------------------------------------------------------ /** * Word Wrap * * Wraps text at the specified character. Maintains the integrity of words. * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * * @access public * @param string the text string * @param integer the number of characters to wrap at * @return string */ function word_wrap($str, $charlim = '76') { // Se the character limit if ( ! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); // Standardize newlines $str = preg_replace("/\r\n|\r/", "\n", $str); // If the current word is surrounded by {unwrap} tags we'll // strip the entire chunk and replace it with a marker. $unwrap = array(); if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { $unwrap[] = $matches['1'][$i]; $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); } } // Use PHP's native function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them $output = ""; foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { $output .= $line."\n"; continue; } $temp = ''; while((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) { break; } // Trim the word down $temp .= substr($line, 0, $charlim-1); $line = substr($line, $charlim-1); } // If $temp contains data it means we had to split up an over-length // word into smaller chunks so we'll add it back to our current line if ($temp != '') { $output .= $temp . "\n" . $line; } else { $output .= $line; } $output .= "\n"; } // Put our markers back if (count($unwrap) > 0) { foreach ($unwrap as $key => $val) { $output = str_replace("{{unwrapped".$key."}}", $val, $output); } } // Remove the unwrap tags $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); return $output; } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d34c95b0554e8d43f3d3c96cc84a754e8f1e2372 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 6 Dec 2007 13:54:54 +0000 Subject: added strip_quotes(), quotes_to_entities(), reduce_multiples() to string helper --- system/helpers/string_helper.php | 155 +-------------------------------------- 1 file changed, 1 insertion(+), 154 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 8ef715953..879ae2f8f 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,154 +1 @@ - 0) ? str_repeat($data, $num) : ''); -} - - -?> \ No newline at end of file + $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\""), array("'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace("#".$character."+#", $character, $str); if ($trim == TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3755fc67fe28ae88061a13e5b78bb91fe836fcb1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 9 Dec 2007 18:22:51 +0000 Subject: fix up of regular expression in reduce multiples --- system/helpers/string_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 879ae2f8f..1ca25e331 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1 +1 @@ - $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\""), array("'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace("#".$character."+#", $character, $str); if ($trim == TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file + $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\""), array("'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $preg_chars = preg_quote($character, '#') . preg_quote($character, '#'); $str = preg_replace("#$preg_chars+#", $character, $str); if ($trim == TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 375d9bac3453e309900b475cb4a1efb836f97440 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 9 Dec 2007 18:25:55 +0000 Subject: quotes to entities now takes escaped and non-escaped quotes --- system/helpers/string_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 1ca25e331..470bce2eb 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1 +1 @@ - $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\""), array("'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $preg_chars = preg_quote($character, '#') . preg_quote($character, '#'); $str = preg_replace("#$preg_chars+#", $character, $str); if ($trim == TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file + $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $preg_chars = preg_quote($character, '#') . preg_quote($character, '#'); $str = preg_replace("#$preg_chars+#", $character, $str); if ($trim == TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From fc2f834bf9b134994ef1214e06153f74f8772630 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 11 Dec 2007 13:44:20 +0000 Subject: Fixed a bug in highlight_pharse() that caused an error with slashes. --- system/helpers/text_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index fb50ba9d7..b75cd8f78 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1 +1 @@ -= $n) { return trim($out).$end_char; } } } // ------------------------------------------------------------------------ /** * High ASCII to Entities * * Converts High ascii text and MS Word special characters to character entities * * @access public * @param string * @return string */ function ascii_to_entities($str) { $count = 1; $out = ''; $temp = array(); for ($i = 0, $s = strlen($str); $i < $s; $i++) { $ordinal = ord($str[$i]); if ($ordinal < 128) { $out .= $str[$i]; } else { if (count($temp) == 0) { $count = ($ordinal < 224) ? 2 : 3; } $temp[] = $ordinal; if (count($temp) == $count) { $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); $out .= '&#'.$number.';'; $count = 1; $temp = array(); } } } return $out; } // ------------------------------------------------------------------------ /** * Entities to ASCII * * Converts character entities back to ASCII * * @access public * @param string * @param bool * @return string */ function entities_to_ascii($str, $all = TRUE) { if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) { for ($i = 0, $s = count($matches['0']); $i < $s; $i++) { $digits = $matches['1'][$i]; $out = ''; if ($digits < 128) { $out .= chr($digits); } elseif ($digits < 2048) { $out .= chr(192 + (($digits - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } else { $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } $str = str_replace($matches['0'][$i], $out, $str); } } if ($all) { $str = str_replace(array("&", "<", ">", """, "'", "-"), array("&","<",">","\"", "'", "-"), $str); } return $str; } // ------------------------------------------------------------------------ /** * Word Censoring Function * * Supply a string and an array of disallowed words and any * matched words will be converted to #### or to the replacement * word you've submitted. * * @access public * @param string the text string * @param string the array of censoered words * @param string the optional replacement value * @return string */ function word_censor($str, $censored, $replacement = '') { if ( ! is_array($censored)) { return $str; } $str = ' '.$str.' '; foreach ($censored as $badword) { if ($replacement != '') { $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); } else { $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); } } return trim($str); } // ------------------------------------------------------------------------ /** * Code Highlighter * * Colorizes code strings * * @access public * @param string the text string * @return string */ function highlight_code($str) { // The highlight string function encodes and highlights // brackets so we need them to start raw $str = str_replace(array('<', '>'), array('<', '>'), $str); // Replace any existing PHP tags to temporary markers so they don't accidentally // break the string out of PHP, and thus, thwart the highlighting. $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); // The highlight_string function requires that the text be surrounded // by PHP tags. Since we don't know if A) the submitted text has PHP tags, // or B) whether the PHP tags enclose the entire string, we will add our // own PHP tags around the string along with some markers to make replacement easier later $str = ''; // 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(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } // Remove our artificially added PHP $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); $str = preg_replace("#//tempend.+#is", "
    \n", $str); // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') { if ($str == '') { return ''; } if ($phrase != '') { return preg_replace('/('.preg_quote($phrase).')/i', $tag_open."\\1".$tag_close, $str); } return $str; } // ------------------------------------------------------------------------ /** * Word Wrap * * Wraps text at the specified character. Maintains the integrity of words. * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * * @access public * @param string the text string * @param integer the number of characters to wrap at * @return string */ function word_wrap($str, $charlim = '76') { // Se the character limit if ( ! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); // Standardize newlines $str = preg_replace("/\r\n|\r/", "\n", $str); // If the current word is surrounded by {unwrap} tags we'll // strip the entire chunk and replace it with a marker. $unwrap = array(); if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { $unwrap[] = $matches['1'][$i]; $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); } } // Use PHP's native function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them $output = ""; foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { $output .= $line."\n"; continue; } $temp = ''; while((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) { break; } // Trim the word down $temp .= substr($line, 0, $charlim-1); $line = substr($line, $charlim-1); } // If $temp contains data it means we had to split up an over-length // word into smaller chunks so we'll add it back to our current line if ($temp != '') { $output .= $temp . "\n" . $line; } else { $output .= $line; } $output .= "\n"; } // Put our markers back if (count($unwrap) > 0) { foreach ($unwrap as $key => $val) { $output = str_replace("{{unwrapped".$key."}}", $val, $output); } } // Remove the unwrap tags $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); return $output; } ?> \ No newline at end of file += $n) { return trim($out).$end_char; } } } // ------------------------------------------------------------------------ /** * High ASCII to Entities * * Converts High ascii text and MS Word special characters to character entities * * @access public * @param string * @return string */ function ascii_to_entities($str) { $count = 1; $out = ''; $temp = array(); for ($i = 0, $s = strlen($str); $i < $s; $i++) { $ordinal = ord($str[$i]); if ($ordinal < 128) { $out .= $str[$i]; } else { if (count($temp) == 0) { $count = ($ordinal < 224) ? 2 : 3; } $temp[] = $ordinal; if (count($temp) == $count) { $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); $out .= '&#'.$number.';'; $count = 1; $temp = array(); } } } return $out; } // ------------------------------------------------------------------------ /** * Entities to ASCII * * Converts character entities back to ASCII * * @access public * @param string * @param bool * @return string */ function entities_to_ascii($str, $all = TRUE) { if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) { for ($i = 0, $s = count($matches['0']); $i < $s; $i++) { $digits = $matches['1'][$i]; $out = ''; if ($digits < 128) { $out .= chr($digits); } elseif ($digits < 2048) { $out .= chr(192 + (($digits - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } else { $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); $out .= chr(128 + ($digits % 64)); } $str = str_replace($matches['0'][$i], $out, $str); } } if ($all) { $str = str_replace(array("&", "<", ">", """, "'", "-"), array("&","<",">","\"", "'", "-"), $str); } return $str; } // ------------------------------------------------------------------------ /** * Word Censoring Function * * Supply a string and an array of disallowed words and any * matched words will be converted to #### or to the replacement * word you've submitted. * * @access public * @param string the text string * @param string the array of censoered words * @param string the optional replacement value * @return string */ function word_censor($str, $censored, $replacement = '') { if ( ! is_array($censored)) { return $str; } $str = ' '.$str.' '; foreach ($censored as $badword) { if ($replacement != '') { $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/i", $replacement, $str); } else { $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword)).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); } } return trim($str); } // ------------------------------------------------------------------------ /** * Code Highlighter * * Colorizes code strings * * @access public * @param string the text string * @return string */ function highlight_code($str) { // The highlight string function encodes and highlights // brackets so we need them to start raw $str = str_replace(array('<', '>'), array('<', '>'), $str); // Replace any existing PHP tags to temporary markers so they don't accidentally // break the string out of PHP, and thus, thwart the highlighting. $str = str_replace(array('<?php', '?>', '\\'), array('phptagopen', 'phptagclose', 'backslashtmp'), $str); // The highlight_string function requires that the text be surrounded // by PHP tags. Since we don't know if A) the submitted text has PHP tags, // or B) whether the PHP tags enclose the entire string, we will add our // own PHP tags around the string along with some markers to make replacement easier later $str = ''; // 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(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); } // Remove our artificially added PHP $str = preg_replace("#\.+?//tempstart\
    \#is", "\n", $str); $str = preg_replace("#\.+?//tempstart\
    #is", "\n", $str); $str = preg_replace("#//tempend.+#is", "
    \n", $str); // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'backslashtmp'), array('<?php', '?>', '\\'), $str); //', $tag_close = '') { if ($str == '') { return ''; } if ($phrase != '') { return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); } return $str; } // ------------------------------------------------------------------------ /** * Word Wrap * * Wraps text at the specified character. Maintains the integrity of words. * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * * @access public * @param string the text string * @param integer the number of characters to wrap at * @return string */ function word_wrap($str, $charlim = '76') { // Se the character limit if ( ! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); // Standardize newlines $str = preg_replace("/\r\n|\r/", "\n", $str); // If the current word is surrounded by {unwrap} tags we'll // strip the entire chunk and replace it with a marker. $unwrap = array(); if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { $unwrap[] = $matches['1'][$i]; $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); } } // Use PHP's native function to do the initial wordwrap. // We set the cut flag to FALSE so that any individual words that are // too long get left alone. In the next step we'll deal with them. $str = wordwrap($str, $charlim, "\n", FALSE); // Split the string into individual lines of text and cycle through them $output = ""; foreach (explode("\n", $str) as $line) { // Is the line within the allowed character count? // If so we'll join it to the output and continue if (strlen($line) <= $charlim) { $output .= $line."\n"; continue; } $temp = ''; while((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) { break; } // Trim the word down $temp .= substr($line, 0, $charlim-1); $line = substr($line, $charlim-1); } // If $temp contains data it means we had to split up an over-length // word into smaller chunks so we'll add it back to our current line if ($temp != '') { $output .= $temp . "\n" . $line; } else { $output .= $line; } $output .= "\n"; } // Put our markers back if (count($unwrap) > 0) { foreach ($unwrap as $key => $val) { $output = str_replace("{{unwrapped".$key."}}", $val, $output); } } // Remove the unwrap tags $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); return $output; } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 49c676be3a786f2699392a9061b228fdf76078ca Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 11 Dec 2007 16:53:36 +0000 Subject: optimized reduce_multiples and strengthened type checking --- system/helpers/string_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 470bce2eb..765e1648f 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1 +1 @@ - $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $preg_chars = preg_quote($character, '#') . preg_quote($character, '#'); $str = preg_replace("#$preg_chars+#", $character, $str); if ($trim == TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file + $val) { $str[$key] = strip_slashes($val); } } else { $str = stripslashes($str); } return $str; } // ------------------------------------------------------------------------ /** * Strip Quotes * * Removes single and double quotes from a string * * @access public * @param string * @return string */ function strip_quotes($str) { return str_replace(array('"', "'"), '', $str); } // ------------------------------------------------------------------------ /** * Quotes to Entities * * Converts single and double quotes to entities * * @access public * @param string * @return string */ function quotes_to_entities($str) { return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); } // ------------------------------------------------------------------------ /** * Reduce Double Slashes * * Converts double slashes in a string to a single slash, * except those found in http:// * * http://www.some-site.com//index.php * * becomes: * * http://www.some-site.com/index.php * * @access public * @param string * @return string */ function reduce_double_slashes($str) { return preg_replace("#([^:])//+#", "\\1/", $str); } // ------------------------------------------------------------------------ /** * Reduce Multiples * * Reduces multiple instances of a particular character. Example: * * Fred, Bill,, Joe, Jimmy * * becomes: * * Fred, Bill, Joe, Jimmy * * @access public * @param string * @param string the character you wish to reduce * @param bool TRUE/FALSE - whether to trim the character from the beginning/end * @return string */ function reduce_multiples($str, $character = ',', $trim = FALSE) { $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); if ($trim === TRUE) { $str = trim($str, $character); } return $str; } // ------------------------------------------------------------------------ /** * Create a Random String * * Useful for generating passwords or hashes. * * @access public * @param string type of random string. Options: alunum, numeric, nozero, unique * @param integer number of characters * @return string */ function random_string($type = 'alnum', $len = 8) { switch($type) { case 'alnum' : case 'numeric' : case 'nozero' : switch ($type) { case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; break; case 'nozero' : $pool = '123456789'; break; } $str = ''; for ($i=0; $i < $len; $i++) { $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); } return $str; break; case 'unique' : return md5(uniqid(mt_rand())); break; } } // ------------------------------------------------------------------------ /** * Alternator * * Allows strings to be alternated. See docs... * * @access public * @param string (as many parameters as needed) * @return string */ function alternator() { static $i; if (func_num_args() == 0) { $i = 0; return ''; } $args = func_get_args(); return $args[($i++ % count($args))]; } // ------------------------------------------------------------------------ /** * Repeater function * * @access public * @param string * @param integer number of repeats * @return string */ function repeater($data, $num = 1) { return (($num > 0) ? str_repeat($data, $num) : ''); } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c3d8e6a78ea47e9133ed426fef4b0e4650e64d3d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Dec 2007 13:50:46 +0000 Subject: Added form_reset() function to form helper. --- system/helpers/form_helper.php | 421 +---------------------------------------- 1 file changed, 1 insertion(+), 420 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 17022a3b3..a23d4c6d2 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,420 +1 @@ -config->site_url($action).'"'; - - if ( ! isset($attributes['method'])) - { - $form .= ' method="post"'; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } - - $form .= '>'; - - if (is_array($hidden) AND count($hidden > 0)) - { - $form .= form_hidden($hidden); - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @access public - * @param string the URI segments of the form destination - * @param array a key/value pair of attributes - * @param array a key/value pair hidden data - * @return string - */ -function form_open_multipart($action, $attributes = array(), $hidden = array()) -{ - $attributes['enctype'] = 'multipart/form-data'; - return form_open($action, $attributes, $hidden); -} - -// ------------------------------------------------------------------------ - -/** - * Hidden Input Field - * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. - * - * @access public - * @param mixed - * @param string - * @return string - */ -function form_hidden($name, $value = '') -{ - if ( ! is_array($name)) - { - return ''; - } - - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_input($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_password($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'password'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_upload($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_textarea($data = '', $value = '', $extra = '') -{ - $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 "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') -{ - if ($extra != '') $extra = ' '.$extra; - - $form = ''; - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') -{ - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) - { - $checked = $data['checked']; - - if ($checked == FALSE) - { - unset($data['checked']); - } - else - { - $data['checked'] = 'checked'; - } - } - - if ($checked == TRUE) - $defaults['checked'] = 'checked'; - else - unset($defaults['checked']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Radio Button - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -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); -} - -// ------------------------------------------------------------------------ - -/** - * Submit Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ -function form_close($extra = '') -{ - return "\n".$extra; -} - -// ------------------------------------------------------------------------ - -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @access public - * @param string - * @return string - */ -function form_prep($str = '') -{ - if ($str === '') - { - return ''; - } - - $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); - - $str = htmlspecialchars($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); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @access private - * @param array - * @param array - * @return string - */ -function parse_form_attributes($attributes, $default) -{ - if (is_array($attributes)) - { - foreach ($default as $key => $val) - { - if (isset($attributes[$key])) - { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); - } - } - - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); - } - } - - $att = ''; - foreach ($default as $key => $val) - { - if ($key == 'value') - { - $val = form_prep($val); - } - - $att .= $key . '="' . $val . '" '; - } - - return $att; -} - -?> \ No newline at end of file +config->site_url($action).'"'; if ( ! isset($attributes['method'])) { $form .= ' method="post"'; } if (is_array($attributes) AND count($attributes) > 0) { foreach ($attributes as $key => $val) { $form .= ' '.$key.'="'.$val.'"'; } } $form .= '>'; if (is_array($hidden) AND count($hidden > 0)) { $form .= form_hidden($hidden); } return $form; } // ------------------------------------------------------------------------ /** * Form Declaration - Multipart type * * Creates the opening portion of the form, but with "multipart/form-data". * * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string */ function form_open_multipart($action, $attributes = array(), $hidden = array()) { $attributes['enctype'] = 'multipart/form-data'; return form_open($action, $attributes, $hidden); } // ------------------------------------------------------------------------ /** * Hidden Input Field * * Generates hidden fields. You can pass a simple key/value string or an associative * array with multiple values. * * @access public * @param mixed * @param string * @return string */ function form_hidden($name, $value = '') { if ( ! is_array($name)) { return ''; } $form = ''; foreach ($name as $name => $value) { $form .= ''; } return $form; } // ------------------------------------------------------------------------ /** * Text Input Field * * @access public * @param mixed * @param string * @param string * @return string */ function form_input($data = '', $value = '', $extra = '') { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } // ------------------------------------------------------------------------ /** * Password Field * * Identical to the input function but adds the "password" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_password($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'password'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Upload Field * * Identical to the input function but adds the "file" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_upload($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'file'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Textarea field * * @access public * @param mixed * @param string * @param string * @return string */ function form_textarea($data = '', $value = '', $extra = '') { $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 "\n"; } // ------------------------------------------------------------------------ /** * Drop-down Menu * * @access public * @param string * @param array * @param string * @param string * @return string */ function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') { if ($extra != '') $extra = ' '.$extra; $form = ''; return $form; } // ------------------------------------------------------------------------ /** * Checkbox Field * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; if ($checked == FALSE) { unset($data['checked']); } else { $data['checked'] = 'checked'; } } if ($checked == TRUE) $defaults['checked'] = 'checked'; else unset($defaults['checked']); return "\n"; } // ------------------------------------------------------------------------ /** * Radio Button * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ 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); } // ------------------------------------------------------------------------ /** * Submit Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Reset Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Form Close Tag * * @access public * @param string * @return string */ function form_close($extra = '') { return "\n".$extra; } // ------------------------------------------------------------------------ /** * Form Prep * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * * @access public * @param string * @return string */ function form_prep($str = '') { if ($str === '') { return ''; } $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); $str = htmlspecialchars($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); return $str; } // ------------------------------------------------------------------------ /** * Parse the form attributes * * Helper function used by some of the form helpers * * @access private * @param array * @param array * @return string */ function parse_form_attributes($attributes, $default) { if (is_array($attributes)) { foreach ($default as $key => $val) { if (isset($attributes[$key])) { $default[$key] = $attributes[$key]; unset($attributes[$key]); } } if (count($attributes) > 0) { $default = array_merge($default, $attributes); } } $att = ''; foreach ($default as $key => $val) { if ($key == 'value') { $val = form_prep($val); } $att .= $key . '="' . $val . '" '; } return $att; } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a0fa90b1bbb61d47bcc9bc95d983e66dfc8732dd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 1 Jan 2008 15:59:47 +0000 Subject: Fixed a bug in get_filenames() in the File Helper where the array wasn't cleared after each call. --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 18798fdf4..d07d35f97 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -156,7 +156,7 @@ function delete_files($path, $del_dir = FALSE, $level = 0) */ function get_filenames($source_dir, $include_path = FALSE) { - static $_filedata = array(); + $_filedata = array(); if ($fp = @opendir($source_dir)) { -- cgit v1.2.3-24-g4f1b From f3e8a3508a4c9bfc203ce861a73e989dc4771f49 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 4 Jan 2008 14:30:38 +0000 Subject: Added form_fieldset(), form_fieldset_close(), and form_label() to form helper. --- system/helpers/form_helper.php | 524 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 523 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a23d4c6d2..e591eb74c 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1 +1,523 @@ -config->site_url($action).'"'; if ( ! isset($attributes['method'])) { $form .= ' method="post"'; } if (is_array($attributes) AND count($attributes) > 0) { foreach ($attributes as $key => $val) { $form .= ' '.$key.'="'.$val.'"'; } } $form .= '>'; if (is_array($hidden) AND count($hidden > 0)) { $form .= form_hidden($hidden); } return $form; } // ------------------------------------------------------------------------ /** * Form Declaration - Multipart type * * Creates the opening portion of the form, but with "multipart/form-data". * * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string */ function form_open_multipart($action, $attributes = array(), $hidden = array()) { $attributes['enctype'] = 'multipart/form-data'; return form_open($action, $attributes, $hidden); } // ------------------------------------------------------------------------ /** * Hidden Input Field * * Generates hidden fields. You can pass a simple key/value string or an associative * array with multiple values. * * @access public * @param mixed * @param string * @return string */ function form_hidden($name, $value = '') { if ( ! is_array($name)) { return ''; } $form = ''; foreach ($name as $name => $value) { $form .= ''; } return $form; } // ------------------------------------------------------------------------ /** * Text Input Field * * @access public * @param mixed * @param string * @param string * @return string */ function form_input($data = '', $value = '', $extra = '') { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } // ------------------------------------------------------------------------ /** * Password Field * * Identical to the input function but adds the "password" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_password($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'password'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Upload Field * * Identical to the input function but adds the "file" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_upload($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'file'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Textarea field * * @access public * @param mixed * @param string * @param string * @return string */ function form_textarea($data = '', $value = '', $extra = '') { $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 "\n"; } // ------------------------------------------------------------------------ /** * Drop-down Menu * * @access public * @param string * @param array * @param string * @param string * @return string */ function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') { if ($extra != '') $extra = ' '.$extra; $form = ''; return $form; } // ------------------------------------------------------------------------ /** * Checkbox Field * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; if ($checked == FALSE) { unset($data['checked']); } else { $data['checked'] = 'checked'; } } if ($checked == TRUE) $defaults['checked'] = 'checked'; else unset($defaults['checked']); return "\n"; } // ------------------------------------------------------------------------ /** * Radio Button * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ 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); } // ------------------------------------------------------------------------ /** * Submit Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Reset Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Form Close Tag * * @access public * @param string * @return string */ function form_close($extra = '') { return "\n".$extra; } // ------------------------------------------------------------------------ /** * Form Prep * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * * @access public * @param string * @return string */ function form_prep($str = '') { if ($str === '') { return ''; } $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); $str = htmlspecialchars($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); return $str; } // ------------------------------------------------------------------------ /** * Parse the form attributes * * Helper function used by some of the form helpers * * @access private * @param array * @param array * @return string */ function parse_form_attributes($attributes, $default) { if (is_array($attributes)) { foreach ($default as $key => $val) { if (isset($attributes[$key])) { $default[$key] = $attributes[$key]; unset($attributes[$key]); } } if (count($attributes) > 0) { $default = array_merge($default, $attributes); } } $att = ''; foreach ($default as $key => $val) { if ($key == 'value') { $val = form_prep($val); } $att .= $key . '="' . $val . '" '; } return $att; } ?> \ No newline at end of file +config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @access public + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); +} + +// ------------------------------------------------------------------------ + +/** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or an associative + * array with multiple values. + * + * @access public + * @param mixed + * @param string + * @return string + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $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 "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Drop-down Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } + } + + if ($checked == TRUE) + $defaults['checked'] = 'checked'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +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); +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Reset Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_reset($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Label Tag + * + * @access public + * @param string The text to appear onscreen + * @param string The id the label applies to + * @param string Additional attributes + * @return string + */ +function form_label($label_text = '', $id = '', $attributes = array()) +{ + + $label = ' 0) + { + foreach ($attributes as $key => $val) + { + $label .= ' '.$key.'="'.$val.'"'; + } + } + + $label .= ">$label_text"; + + return $label; +} + +// ------------------------------------------------------------------------ +/** + * Fieldset Tag + * + * Used to produce
    text. To close fieldset + * use form_fieldset_close() + * + * @access public + * @param string The legend text + * @param string Additional attributes + * @return string + */ +function form_fieldset($legend_text = '', $attributes = array()) +{ + + $fieldset = " 0) + { + foreach ($attributes as $key => $val) + { + $fieldset .= ' '.$key.'="'.$val.'"'; + } + } + + $fieldset .= ">\n"; + + if ($legend_text != '') + { + $fieldset .= "$legend_text\n"; + } + + + + return $fieldset; +} + +// ------------------------------------------------------------------------ + +/** + * Fieldset Close Tag + * + * @access public + * @param string + * @return string + */ +function form_fieldset_close($extra = '') +{ + return "
    \n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +function form_prep($str = '') +{ + if ($str === '') + { + return ''; + } + + $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); + + $str = htmlspecialchars($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); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @param array + * @return string + */ +function parse_form_attributes($attributes, $default) +{ + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + foreach ($default as $key => $val) + { + if ($key == 'value') + { + $val = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4021b51750afb7e39dc0e5ea6e839c7da4e069ab Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 4 Jan 2008 22:26:12 +0000 Subject: added the ability to have multiple selected items in form_dropdown() --- system/helpers/form_helper.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e591eb74c..a67ea050d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -221,18 +221,24 @@ function form_textarea($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { + if ( ! is_array($selected)) + { + $selected = array($selected); + } + if ($extra != '') $extra = ' '.$extra; - - $form = '\n"; foreach ($options as $key => $val) { $key = (string) $key; $val = (string) $val; - $sel = ($selected != $key) ? '' : ' selected="selected"'; + $sel = (in_array($key, $selected))?' selected="selected"':''; $form .= '\n"; } -- cgit v1.2.3-24-g4f1b From e4e603b1083242fd08fc84e2cb29e998dddaee0c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 9 Jan 2008 14:18:14 +0000 Subject: fix for is_really_writable --- system/helpers/file_helper.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index d07d35f97..83ef6a066 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -176,4 +176,39 @@ function get_filenames($source_dir, $include_path = FALSE) } } +// -------------------------------------------------------------------- + +/** + * Tests for file writability + * + * is_writable() returns TRUE on Windows servers + * when you really can't write to the file + * as the OS reports to PHP as FALSE only if the + * read-only attribute is marked. Ugh? + * + * @access private + * @return void + */ +function is_really_writable($file) +{ + if (is_dir($file)) + { + $file = rtrim($file, '/').'/'.md5(rand(1,100)); + + if (($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + @chmod($file, 0777); + @unlink($file); + } + elseif (($fp = @fopen($file, 'ab')) === FALSE) + { + return FALSE; + } + + fclose($fp); + return TRUE; +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 56e5722f2861f0e4c2bd0c9bb4e9d5065dd0a5b0 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 9 Jan 2008 19:43:40 +0000 Subject: bugfix --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a67ea050d..1d2cb8604 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -229,7 +229,7 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext } if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected > 1))?' multiple="multiple"':''; + $multiple = (count($selected) > 1)?' multiple="multiple"':''; $form = '\n"; -- cgit v1.2.3-24-g4f1b From 76708b780c558c0d5db1efd8e11787269e0507e3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 15 Jan 2008 23:58:19 +0000 Subject: bug(re)fix: I am so smart. s - m - r - t --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3bc9d81..9f3509d51 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -231,7 +231,7 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext } if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected > 1))?' multiple="multiple"':''; + $multiple = (count($selected) > 1))?' multiple="multiple"':''; $form = '\n"; -- cgit v1.2.3-24-g4f1b From 8b25191aededd91dd4ab942fd0c776f073433db2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 17 Jan 2008 00:34:37 +0000 Subject: Fixed bug #2810 with nested tags improperly having paragraph tags placed around them. --- system/helpers/typography_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 355f02cf9..aa751db8b 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -152,8 +152,8 @@ class Auto_typography { * ends. Later on we'll do some further clean up. * */ - $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

    \\1\\2\\3", $str); - $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

    ", $str); + $str = preg_replace("#(<)(".$this->block_elements.")(.*?>)#", "

    \\1\\2\\3", $str); + $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

    ", $str); /* * Convert "ignore" tags to temporary marker -- cgit v1.2.3-24-g4f1b From f8f05703f61689b4d0b432f12e36a27f15778458 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 14:39:23 +0000 Subject: added check for "multiple" attribute in form_dropdown() (bug# 3261) --- system/helpers/form_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c3a3ccb5b..a727f4715 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -231,7 +231,8 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext } if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected) > 1) ? ' multiple="multiple"' : ''; + + $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; $form = ' $val) - { - $selected = ($default == $key) ? " selected='selected'" : ''; - $menu .= "\n"; - } + foreach (timezones() as $key => $val) + { + $selected = ($default == $key) ? " selected='selected'" : ''; + $menu .= "\n"; + } - $menu .= ""; + $menu .= ""; - 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 = '

    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 ''; - } + if ( ! is_array($name)) + { + return ''; + } - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } - 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 "\n"; + return "\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 "\n"; + return "\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 = '\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 .= '\n"; - } + $form .= '\n"; + } - $form .= ''; + $form .= ''; - 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 "\n"; + return "\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 "\n"; + return "\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 "\n"; + return "\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 = ' 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_text"; - 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 = " 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_text\n"; - } + if ($legend_text != '') + { + $fieldset .= "$legend_text\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 "\n".$extra; + function form_fieldset_close($extra = '') + { + return "\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 "\n".$extra; + function form_close($extra = '') + { + return "\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 "".$data.""; + function heading($data = '', $h = '1') + { + return "".$data.""; + } } // ------------------------------------------------------------------------ @@ -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 .= "
  • "; - - if ( ! is_array($val)) - { - $out .= $val; - } - else - { - $out .= $_last_list_item."\n"; - $out .= _list($type, $val, '', $depth + 4); $out .= str_repeat(" ", $depth + 2); + $out .= "
  • "; + + if ( ! is_array($val)) + { + $out .= $val; + } + else + { + $out .= $_last_list_item."\n"; + $out .= _list($type, $val, '', $depth + 4); + $out .= str_repeat(" ", $depth + 2); + } + + $out .= "
  • \n"; } - $out .= "\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 .= "\n"; + // Write the closing list tag + $out .= "\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("
    ", $num); + function br($num = 1) + { + return str_repeat("
    ", $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 .= ''.$newline; - } + $str = ''; + foreach ($meta as $key => $val) + { + $str .= ''.$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("##", "\\1", $str); - $str = preg_replace("##", "\\1", $str); + function strip_image_tags($str) + { + $str = preg_replace("##", "\\1", $str); + $str = preg_replace("##", "\\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(''), array('<?php', '<?PHP', '<?', '?>'), $str); + function encode_php_tags($str) + { + return str_replace(array(''), 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 << function insert_smiley(smiley) { @@ -47,8 +49,8 @@ return << 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[] = "\"".$smileys[$key][3]."\""; + $link[] = "\"".$smileys[$key][3]."\""; - $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, "\"".$smileys[$key][3]."\"", $str); - } + foreach ($smileys as $key => $val) + { + $str = str_replace($key, "\"".$smileys[$key][3]."\"", $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('', '<%', '%>', '\\', ''), - array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); + $str = str_replace(array('', '<%', '%>', '\\', ''), + array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); - // The highlight_string function requires that the text be surrounded - // by PHP tags. 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 = ''; + $str = ''; - // 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(''), array(''), $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(''), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } - // Remove our artificially added PHP - $str = preg_replace("#\.+?tempstart\
    (?:\)?#is", "\n", $str); - $str = preg_replace("#tempend.+#is", "
    \n", $str); + // Remove our artificially added PHP + $str = preg_replace("#\.+?tempstart\
    (?:\)?#is", "\n", $str); + $str = preg_replace("#tempend.+#is", "
    \n", $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 = '', $tag_close = '') +if (! function_exists('highlight_phrase')) { - if ($str == '') + function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') { - 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 = '', $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 ''.$title.''; + return ''.$title.''; + } } // ------------------------------------------------------------------------ @@ -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 "".$title.""; - } + if ($attributes === FALSE) + { + return "".$title.""; + } - 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 "".$title.""; + return "".$title.""; + } } // ------------------------------------------------------------------------ @@ -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 ''.$title.''; + $attributes = _parse_attributes($attributes); + + return ''.$title.''; + } } // ------------------------------------------------------------------------ @@ -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(' $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(); -?>= 0; i=i-1){ + if (l[i].substring(0, 1) == '|') document.write("&#"+unescape(l[i].substring(1))+";"); + else document.write(unescape(l[i]));} + //]]> + http'. - $matches['4'][$i].'://'. - $matches['5'][$i]. - $matches['6'][$i].''. - $period, $str); + $str = str_replace($matches['0'][$i], + $matches['1'][$i].'http'. + $matches['4'][$i].'://'. + $matches['5'][$i]. + $matches['6'][$i].''. + $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 -- cgit v1.2.3-24-g4f1b From 0975bcc8d56392af3d07f1e2af941b727d6dc389 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 17:21:27 +0000 Subject: Fixed a bug (#3328) where the smiley helper might return an undefined variable. --- system/helpers/smiley_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index f4149478c..25962eb54 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -71,7 +71,7 @@ if (! function_exists('get_clickable_smileys')) { if (FALSE === ($smileys = _get_smiley_array())) { - return $str; + return $smileys; } } -- cgit v1.2.3-24-g4f1b From 1c8dd3ad67bfa8da796bc0ebbfdf72be8d5bafb1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 20:20:00 +0000 Subject: fixed bug #3314 where the top level path would be deleted along with files in delete_files() --- system/helpers/file_helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index bbf340930..ef07de76c 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -122,7 +122,7 @@ if (! function_exists('delete_files')) { // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); - + if ( ! $current_dir = @opendir($path)) return; @@ -132,8 +132,7 @@ if (! function_exists('delete_files')) { if (is_dir($path.'/'.$filename)) { - $level++; - delete_files($path.'/'.$filename, $del_dir, $level); + delete_files($path.'/'.$filename, $del_dir, $level + 1); } else { -- cgit v1.2.3-24-g4f1b From 2d87b4d2fa7d2fd01876eaa8cf1f727d863d3e6c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 15:19:53 +0000 Subject: Fixed a bug (#1872) where word_limiter() was not retaining whitespace. --- system/helpers/text_helper.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 30cec3148..21ab77830 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -40,27 +40,21 @@ */ if (! function_exists('word_limiter')) { - function word_limiter($str, $n = 100, $end_char = '…') + function word_limiter($str, $limit = 100, $end_char = '…') { - if (strlen($str) < $n) + if (trim($str) == '') { return $str; } - $words = explode(' ', preg_replace("/\s+/", ' ', preg_replace("/(\r\n|\r|\n)/", " ", $str))); - - if (count($words) <= $n) - { - return $str; - } + preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $matches); - $str = ''; - for ($i = 0; $i < $n; $i++) + if (strlen($str) == strlen($matches[0])) { - $str .= $words[$i].' '; + $end_char = ''; } - - return trim($str).$end_char; + + return rtrim($matches[0]).$end_char; } } -- cgit v1.2.3-24-g4f1b From 432e97322ad518468235649ad25974eef3f3d39f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 16:13:57 +0000 Subject: Added link() to the HTML helper. --- system/helpers/html_helper.php | 130 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 56e25316c..d887be6ce 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -182,17 +182,122 @@ if (! function_exists('br')) // ------------------------------------------------------------------------ /** - * Generates non-breaking space entities based on number supplied + * Image + * + * Generates an image tag * * @access public * @param integer * @return string */ -if (! function_exists('nbs')) +if (! function_exists('image')) { - function nbs($num = 1) + function image($src = '', $alt = '', $index_page = FALSE) { - return str_repeat(" ", $num); + $CI =& get_instance(); + + $css = ''; + + foreach ($stylesheets as $stylesheet) + { + if (strpos($stylesheet, '://') !== FALSE) + { + $href = ' href="'.$stylesheet.'"'; + } + elseif ($index_page === TRUE) + { + $href = ' href="'.$CI->config->site_url($stylesheet).'"'; + } + else + { + $href = ' href="'.$CI->config->slash_item('base_url').$stylesheet.'"'; + } + + $media = ($media !== '') ? ' media="'.$media.'"' : ''; + + $css .= 'link type="text/css" rel="stylesheet"'.$href.$media.' />'."\n"; + } + + return $css; + } +} + +// ------------------------------------------------------------------------ + +/** + * Link + * + * Generates link to a CSS file + * + * @access public + * @param mixed stylesheet name(s) + * @param string media type + * @param boolean should index_page be added to the css path + * @return string + */ +if (! function_exists('link')) +{ + function link($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) + { + $CI =& get_instance(); + + $link = 'link '; + + if (is_array($href)) + { + foreach ($href as $k=>$v) + { + if ($k == 'href' AND strpos($k, '://') === FALSE) + { + if ($index_page === TRUE) + { + $link .= ' href="'.$CI->config->site_url($v).'" '; + } + else + { + $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" '; + } + } + else + { + $link .= "$k=\"$v\" "; + } + } + + $link .= "/>\n"; + } + else + { + if ( strpos($href, '://') !== FALSE) + { + $link .= ' href="'.$href.'" '; + } + elseif ($index_page === TRUE) + { + $link .= ' href="'.$CI->config->site_url($href).'" '; + } + else + { + $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" '; + } + + $link .= 'rel="'.$rel.'" type="'.$type.'" '; + + if ($media != '') + { + $link .= 'media="'.$media.'" '; + } + + if ($title != '') + { + $link .= 'title="'.$title.'" '; + } + + $link .= '/>'."\n"; + } + + + return $link; } } @@ -219,4 +324,21 @@ if (! function_exists('meta')) } } +// ------------------------------------------------------------------------ + +/** + * Generates non-breaking space entities based on number supplied + * + * @access public + * @param integer + * @return string + */ +if (! function_exists('nbs')) +{ + function nbs($num = 1) + { + return str_repeat(" ", $num); + } +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 165da619b64c6ade34366b99ef87758ef547dbdb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 16:36:00 +0000 Subject: added stylesheet() to html helper --- system/helpers/html_helper.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index d887be6ce..660d867bd 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -230,8 +230,11 @@ if (! function_exists('image')) * Generates link to a CSS file * * @access public - * @param mixed stylesheet name(s) - * @param string media type + * @param mixed stylesheet hrefs or an array + * @param string rel + * @param string type + * @param string title + * @param string media * @param boolean should index_page be added to the css path * @return string */ @@ -303,6 +306,25 @@ if (! function_exists('link')) // ------------------------------------------------------------------------ +/** + * Stylesheet + * + * Generates a to a CSS + * + * @access public + * @param array + * @return string + */ +if (! function_exists('stylesheet')) +{ + function stylesheet($href = '', $rel = 'stylesheet', $title = '', $media = 'screen') + { + return link($href, $rel, 'text/css', $title, $media); + } +} + +// ------------------------------------------------------------------------ + /** * Generates meta tags from an array of key/values * -- cgit v1.2.3-24-g4f1b From 0684897f89f8363dc431e8ade0535bce521a7af2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 16:55:30 +0000 Subject: remove stylesheet() so as not to overly pollute function names, rename link() to link_tag() to avoid PHP collision. --- system/helpers/html_helper.php | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 660d867bd..f88bc0723 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -238,9 +238,9 @@ if (! function_exists('image')) * @param boolean should index_page be added to the css path * @return string */ -if (! function_exists('link')) +if (! function_exists('link_tag')) { - function link($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) + function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) { $CI =& get_instance(); @@ -306,25 +306,6 @@ if (! function_exists('link')) // ------------------------------------------------------------------------ -/** - * Stylesheet - * - * Generates a to a CSS - * - * @access public - * @param array - * @return string - */ -if (! function_exists('stylesheet')) -{ - function stylesheet($href = '', $rel = 'stylesheet', $title = '', $media = 'screen') - { - return link($href, $rel, 'text/css', $title, $media); - } -} - -// ------------------------------------------------------------------------ - /** * Generates meta tags from an array of key/values * -- cgit v1.2.3-24-g4f1b From f653a2fe2f82130ff9d8db6a4913b4823dd81424 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 20:16:01 +0000 Subject: added img() to HTML helper --- system/helpers/html_helper.php | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index f88bc0723..0c884502f 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -184,41 +184,48 @@ if (! function_exists('br')) /** * Image * - * Generates an image tag + * Generates an element * * @access public - * @param integer + * @param mixed * @return string */ -if (! function_exists('image')) +if (! function_exists('img')) { - function image($src = '', $alt = '', $index_page = FALSE) + function img($src = '', $index_page = FALSE) { - $CI =& get_instance(); - - $css = ''; + if ( ! is_array($src) ) + { + $src = array('src' => $src); + } + + $img = '$v) { - if (strpos($stylesheet, '://') !== FALSE) - { - $href = ' href="'.$stylesheet.'"'; - } - elseif ($index_page === TRUE) + + if ($k == 'src' AND strpos($v, '://') === FALSE) { - $href = ' href="'.$CI->config->site_url($stylesheet).'"'; + $CI =& get_instance(); + + if ($index_page === TRUE) + { + $img .= ' src="'.$CI->config->site_url($v).'" '; + } + else + { + $img .= ' src="'.$CI->config->slash_item('base_url').$v.'" '; + } } else { - $href = ' href="'.$CI->config->slash_item('base_url').$stylesheet.'"'; + $img .= " $k=\"$v\" "; } - - $media = ($media !== '') ? ' media="'.$media.'"' : ''; - - $css .= 'link type="text/css" rel="stylesheet"'.$href.$media.' />'."\n"; } - - return $css; + + $img .= '/>'; + + return $img; } } @@ -244,7 +251,7 @@ if (! function_exists('link_tag')) { $CI =& get_instance(); - $link = 'link '; + $link = ' Date: Mon, 11 Feb 2008 12:46:24 +0000 Subject: added Path Helper --- system/helpers/path_helper.php | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 system/helpers/path_helper.php (limited to 'system/helpers') diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php new file mode 100644 index 000000000..30d26d6ee --- /dev/null +++ b/system/helpers/path_helper.php @@ -0,0 +1,70 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From fd971781c4f4d1b436cc7b9efd2e409b7b400b88 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 20 Feb 2008 18:39:18 +0000 Subject: modified get_filenames() to return FALSE if the directory cannot be read --- system/helpers/file_helper.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index ef07de76c..0005c2a24 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -184,6 +184,10 @@ if (! function_exists('get_filenames')) } return $_filedata; } + else + { + return $FALSE; + } } } -- cgit v1.2.3-24-g4f1b From bca400fbd1cccf817bc16c725da2ffe82757b4c7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Feb 2008 22:19:55 +0000 Subject: fix $FALSE to FALSE --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0005c2a24..096d225d7 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -186,7 +186,7 @@ if (! function_exists('get_filenames')) } else { - return $FALSE; + return FALSE; } } } -- cgit v1.2.3-24-g4f1b From 2c6dda41c8207ffa704934a1fbde65769ce86992 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 26 Feb 2008 23:18:27 +0000 Subject: fixed recursion in get_filenames() (bug #3523) --- system/helpers/file_helper.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 096d225d7..1b37af2fd 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -164,17 +164,22 @@ if (! function_exists('delete_files')) */ if (! function_exists('get_filenames')) { - function get_filenames($source_dir, $include_path = FALSE) + function get_filenames($source_dir, $include_path = FALSE, $recursion = FALSE) { - $_filedata = array(); - + static $_filedata = array(); + + if ($recursion === FALSE) + { + $_filedata = array(); + } + if ($fp = @opendir($source_dir)) { while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') { - get_filenames($source_dir.$file."/", $include_path); + get_filenames($source_dir.$file."/", $include_path, TRUE); } elseif (substr($file, 0, 1) != ".") { -- cgit v1.2.3-24-g4f1b From 37fb01baec92a3e7898380923712e0c48b21107a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 6 Mar 2008 13:01:47 +0000 Subject: Modified img() in the HTML Helper to remove an unneeded space. Modified anchor() in the URL helper to convert entities in the title attribute. --- system/helpers/html_helper.php | 2 +- system/helpers/url_helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 0c884502f..4684d8ea8 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -199,7 +199,7 @@ if (! function_exists('img')) $src = array('src' => $src); } - $img = '$v) { diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index ad71caa45..bd94b390c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -119,7 +119,7 @@ if (! function_exists('anchor')) if ($attributes == '') { - $attributes = ' title="'.$title.'"'; + $attributes = ' title="'.htmlentities($title).'"'; } else { -- cgit v1.2.3-24-g4f1b From 707d0e0f1e0ea922fbe38d8b43f1fb4e2ea001e5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Mar 2008 11:50:00 +0000 Subject: added form_button to form helper --- system/helpers/form_helper.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3b16ff1..db41cb5cd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -386,6 +386,33 @@ if (! function_exists('form_reset')) // ------------------------------------------------------------------------ +/** + * Form Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if (! function_exists('form_button')) +{ + function form_button($data = '', $content = '', $extra = '') + { + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + + if ( is_array($data) AND isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return "\n"; + } +} + +// ------------------------------------------------------------------------ + /** * Form Label Tag * -- cgit v1.2.3-24-g4f1b From 560efb353a1395f51a170f32b974c2afb897a712 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 27 Mar 2008 16:07:00 +0000 Subject: Fixed bug #4350 in get_filenames() when the $source_dir does not include a trailing slash --- system/helpers/file_helper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 1b37af2fd..7eb93dab2 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -160,19 +160,23 @@ if (! function_exists('delete_files')) * @access public * @param string path to source * @param bool whether to include the path as part of the filename + * @param bool internal variable to determine recursion status - do not use in calls * @return array */ if (! function_exists('get_filenames')) { - function get_filenames($source_dir, $include_path = FALSE, $recursion = FALSE) + function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); - if ($recursion === FALSE) + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) { $_filedata = array(); + $source_dir = realpath($source_dir).'/'; } + if ($fp = @opendir($source_dir)) { while (FALSE !== ($file = readdir($fp))) -- cgit v1.2.3-24-g4f1b From f00992d66cab3efa8cbec8cc8623c4ea830cc5e3 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 28 Mar 2008 14:13:14 +0000 Subject: moved the $_recursion conditional in get_filenames() to fix a bug where a bad submitted path would result in the system using / as the source directory. --- system/helpers/file_helper.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 7eb93dab2..e1a4ff31a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -168,17 +168,16 @@ if (! function_exists('get_filenames')) function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { static $_filedata = array(); - - // reset the array and make sure $source_dir has a trailing slash on the initial call - if ($_recursion === FALSE) - { - $_filedata = array(); - $source_dir = realpath($source_dir).'/'; - } - - + if ($fp = @opendir($source_dir)) { + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) + { + $_filedata = array(); + $source_dir = realpath($source_dir).'/'; + } + while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') -- cgit v1.2.3-24-g4f1b From 2ec3a5e12f2095ae2cc341760a9c44acf353743e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 30 Mar 2008 17:51:11 +0000 Subject: Fixed a bug in link_tag() of the URL helper where a key was passed instead of a value. --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4684d8ea8..3e15b4442 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -257,7 +257,7 @@ if (! function_exists('link_tag')) { foreach ($href as $k=>$v) { - if ($k == 'href' AND strpos($k, '://') === FALSE) + if ($k == 'href' AND strpos($v, '://') === FALSE) { if ($index_page === TRUE) { -- cgit v1.2.3-24-g4f1b From ac7c81e3cd8891d7a8103c121911f7192b5027af Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 1 Apr 2008 13:59:49 +0000 Subject: Modified get_filenames() to use DIRECTORY_SEPARATOR constant instead of '/' for better cross-platform compatibility --- system/helpers/file_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index e1a4ff31a..04c5747bf 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -175,14 +175,14 @@ if (! function_exists('get_filenames')) if ($_recursion === FALSE) { $_filedata = array(); - $source_dir = realpath($source_dir).'/'; + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') { - get_filenames($source_dir.$file."/", $include_path, TRUE); + get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } elseif (substr($file, 0, 1) != ".") { -- cgit v1.2.3-24-g4f1b From 3a555ef16dfe811815af83fdeccfebd6c04b99b2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 17 Apr 2008 22:03:00 +0000 Subject: The Download helper now exits within force-download(). --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 2d0e737c9..5e47fc5c9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -91,7 +91,7 @@ if (! function_exists('force_download')) header("Content-Length: ".strlen($data)); } - echo $data; + exit($data); } } -- cgit v1.2.3-24-g4f1b From 05f830c7105ef3cd4a8388bffe7cf73c35236105 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Apr 2008 13:35:20 +0000 Subject: Added the ability to include an optional HTTP Response Code in the redirect() function of the URL Helper. --- system/helpers/url_helper.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index bd94b390c..1ff26082c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -470,6 +470,8 @@ if (! function_exists('url_title')) * Header Redirect * * Header redirect in two flavors + * For very fine grained control over headers, you could use the Output + * Library's set_header() function. * * @access public * @param string the URL @@ -478,13 +480,13 @@ if (! function_exists('url_title')) */ if (! function_exists('redirect')) { - function redirect($uri = '', $method = 'location') + function redirect($uri = '', $method = 'location', $http_response_code = 302) { switch($method) { case 'refresh' : header("Refresh:0;url=".site_url($uri)); break; - default : header("Location: ".site_url($uri)); + default : header("Location: ".site_url($uri), TRUE, $http_response_code); break; } exit; -- cgit v1.2.3-24-g4f1b From a9911fc06160f9d4538475e2bf9ee45c9ff8f746 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 May 2008 01:48:51 +0000 Subject: another change to the download helper for compatibility --- system/helpers/download_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 5e47fc5c9..ee3d78f25 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -91,7 +91,8 @@ if (! function_exists('force_download')) header("Content-Length: ".strlen($data)); } - exit($data); + echo $data; + exit; // exit($data); // didn't work on some browsers } } -- cgit v1.2.3-24-g4f1b From c0c5c97ffbfac81837e1913c77da7462c096ae87 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 1 May 2008 01:56:51 +0000 Subject: revert... Derek's an idiot --- system/helpers/download_helper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index ee3d78f25..5e47fc5c9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -91,8 +91,7 @@ if (! function_exists('force_download')) header("Content-Length: ".strlen($data)); } - echo $data; - exit; // exit($data); // didn't work on some browsers + exit($data); } } -- cgit v1.2.3-24-g4f1b From 7327499064ae165468c7440f8571c3e570b58a0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:39:18 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/helpers/array_helper.php | 4 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 12 +-- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 181 +++++++++++++++++++++++++++++++++-- system/helpers/form_helper.php | 26 ++--- system/helpers/html_helper.php | 6 +- system/helpers/path_helper.php | 2 +- system/helpers/security_helper.php | 4 +- system/helpers/smiley_helper.php | 8 +- system/helpers/text_helper.php | 4 +- system/helpers/typography_helper.php | 24 ++--- system/helpers/url_helper.php | 10 +- 14 files changed, 227 insertions(+), 60 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 236e3904e..8ae44826a 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -43,7 +43,7 @@ if (! function_exists('element')) { function element($item, $array, $default = FALSE) { - if ( ! isset($array[$item]) OR $array[$item] == "") + if (! isset($array[$item]) OR $array[$item] == "") { return $default; } @@ -65,7 +65,7 @@ if (! function_exists('random_element')) { function random_element($array) { - if ( ! is_array($array)) + if (! is_array($array)) { return $array; } diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 102057f8c..75c769e9c 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -73,7 +73,7 @@ if (! function_exists('set_cookie')) $path = $CI->config->item('cookie_path'); } - if ( ! is_numeric($expire)) + if (! is_numeric($expire)) { $expire = time() - 86500; } diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 24e0b1794..004cfb122 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -123,7 +123,7 @@ if (! function_exists('standard_date')) 'DATE_W3C' => '%Y-%m-%dT%H:%i:%s%Q' ); - if ( ! isset($formats[$fmt])) + if (! isset($formats[$fmt])) { return FALSE; } @@ -152,12 +152,12 @@ if (! function_exists('timespan')) $CI =& get_instance(); $CI->lang->load('date'); - if ( ! is_numeric($seconds)) + if (! is_numeric($seconds)) { $seconds = 1; } - if ( ! is_numeric($time)) + if (! is_numeric($time)) { $time = time(); } @@ -271,7 +271,7 @@ if (! function_exists('days_in_month')) return 0; } - if ( ! is_numeric($year) OR strlen($year) != 4) + if (! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } @@ -442,7 +442,7 @@ if (! function_exists('human_to_unix')) $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)) + 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; } @@ -592,7 +592,7 @@ if (! function_exists('timezones')) if ($tz == 'GMT') $tz = 'UTC'; - return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; + return (! isset($zones[$tz])) ? 0 : $zones[$tz]; } } diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 5e47fc5c9..284c6c96e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -61,7 +61,7 @@ if (! function_exists('force_download')) @include(APPPATH.'config/mimes'.EXT); // Set a default mime if we can't find it - if ( ! isset($mimes[$extension])) + if (! isset($mimes[$extension])) { $mime = 'application/octet-stream'; } diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index e677afd28..307f3b588 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -37,7 +37,7 @@ if (! function_exists('valid_email')) { function valid_email($address) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; } } diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 04c5747bf..1eb8348e9 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -40,7 +40,7 @@ if (! function_exists('read_file')) { function read_file($file) { - if ( ! file_exists($file)) + if (! file_exists($file)) { return FALSE; } @@ -50,7 +50,7 @@ if (! function_exists('read_file')) return file_get_contents($file); } - if ( ! $fp = @fopen($file, 'rb')) + if (! $fp = @fopen($file, 'rb')) { return FALSE; } @@ -87,7 +87,7 @@ if (! function_exists('write_file')) { function write_file($path, $data, $mode = 'wb') { - if ( ! $fp = @fopen($path, $mode)) + if (! $fp = @fopen($path, $mode)) { return FALSE; } @@ -123,7 +123,7 @@ if (! function_exists('delete_files')) // Trim the trailing slash $path = preg_replace("|^(.+?)/*$|", "\\1", $path); - if ( ! $current_dir = @opendir($path)) + if (! $current_dir = @opendir($path)) return; while(FALSE !== ($filename = @readdir($current_dir))) @@ -167,7 +167,7 @@ if (! function_exists('get_filenames')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { - static $_filedata = array(); + $_filedata = array(); if ($fp = @opendir($source_dir)) { @@ -180,11 +180,11 @@ if (! function_exists('get_filenames')) while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.') + if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) { get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); } - elseif (substr($file, 0, 1) != ".") + elseif (strncmp($file, '.', 1) !== 0) { $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file; @@ -201,4 +201,171 @@ if (! function_exists('get_filenames')) // -------------------------------------------------------------------- +/** + * Get Directory File Information + * + * Reads the specified directory and builds an array containing the filenames, + * filesize, dates, and permissions + * + * Any sub-folders contained within the specified path are read as well. + * + * @access public + * @param string path to source + * @param bool whether to include the path as part of the filename + * @param bool internal variable to determine recursion status - do not use in calls + * @return array + */ +if (! function_exists('get_dir_file_info')) +{ + function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE) + { + $_filedata = array(); + $relative_path = $source_dir; + + if ($fp = @opendir($source_dir)) + { + // reset the array and make sure $source_dir has a trailing slash on the initial call + if ($_recursion === FALSE) + { + $_filedata = array(); + $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + } + + while (FALSE !== ($file = readdir($fp))) + { + if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) + { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); + } + elseif (strncmp($file, '.', 1) !== 0) + { + $_filedata[$file] = get_file_info($source_dir.$file); + $_filedata[$file]['relative_path'] = $relative_path; + } + } + return $_filedata; + } + else + { + return FALSE; + } + } +} + +// -------------------------------------------------------------------- + +/** +* Get File Info +* +* Given a file and path, returns the name, path, size, date modified +* Second parameter allows you to explicitly declare what information you want returned +* Options are: name, server_path, size, date, readable, writable, executable, fileperms +* Returns FALSE if the file cannot be found. +* +* @access public +* @param string path to file +* @param mixed array or comma separated string of information returned +* @return array +*/ +if (! function_exists('get_file_info')) +{ + function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date')) + { + + if (! file_exists($file)) + { + return FALSE; + } + + if (is_string($returned_values)) + { + $returned_values = explode(',', $returned_values); + } + + foreach ($returned_values as $key) + { + switch ($key) + { + case 'name': + $fileinfo['name'] = substr(strrchr($file, '/'), 1); + break; + case 'server_path': + $fileinfo['server_path'] = $file; + break; + case 'size': + $fileinfo['size'] = filesize($file); + break; + case 'date': + $fileinfo['date'] = filectime($file); + break; + case 'readable': + $fileinfo['readable'] = is_readable($file); + break; + case 'writable': + // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms() + $fileinfo['writable'] = is_writable($file); + break; + case 'executable': + $fileinfo['executable'] = is_executable($file); + break; + case 'fileperms': + $fileinfo['fileperms'] = fileperms($file); + break; + } + } + + return $fileinfo; + } +} + +// -------------------------------------------------------------------- + +/** + * Get Mime by Extension + * + * Translates a file extension into a mime type based on config/mimes.php. + * Returns FALSE if it can't determine the type, or open the mime config file + * + * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience + * It should NOT be trusted, and should certainly NOT be used for security + * + * @access public + * @param string path to file + * @return mixed + */ +if (! function_exists('get_mime_by_extension')) +{ + function get_mime_by_extension($file) + { + $extension = substr(strrchr($file, '.'), 1); + + global $mimes; + + if (! is_array($mimes)) + { + if (! require_once(APPPATH.'config/mimes.php')) + { + return FALSE; + } + } + + if (array_key_exists($extension, $mimes)) + { + if (is_array($mimes[$extension])) + { + // Multiple mime types, just give the first one + return current($mimes[$extension]); + } + else + { + return $mimes[$extension]; + } + } + else + { + return FALSE; + } + } +} + ?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index db41cb5cd..10858339e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -48,7 +48,7 @@ if (! function_exists('form_open')) $form = '
    '; } @@ -141,7 +141,7 @@ if (! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } @@ -164,7 +164,7 @@ if (! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -191,7 +191,7 @@ if (! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -216,9 +216,9 @@ if (! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if (! is_array($data) OR ! isset($data['value'])) { $val = $value; } @@ -248,7 +248,7 @@ if (! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - if ( ! is_array($selected)) + if (! is_array($selected)) { $selected = array($selected); } @@ -291,7 +291,7 @@ if (! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { @@ -332,7 +332,7 @@ if (! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -357,7 +357,7 @@ if (! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'submit', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -378,7 +378,7 @@ if (! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'reset', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -399,7 +399,7 @@ if (! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'type' => 'submit'); if ( is_array($data) AND isset($data['content'])) { diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 3e15b4442..4e86465c1 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -105,7 +105,7 @@ if (! function_exists('_list')) function _list($type = 'ul', $list, $attributes = '', $depth = 0) { // If an array wasn't submitted there's nothing to do... - if ( ! is_array($list)) + if (! is_array($list)) { return $list; } @@ -138,7 +138,7 @@ if (! function_exists('_list')) $out .= str_repeat(" ", $depth + 2); $out .= "
  • "; - if ( ! is_array($val)) + if (! is_array($val)) { $out .= $val; } @@ -194,7 +194,7 @@ if (! function_exists('img')) { function img($src = '', $index_page = FALSE) { - if ( ! is_array($src) ) + if (! is_array($src) ) { $src = array('src' => $src); } diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 30d26d6ee..6abff06af 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -57,7 +57,7 @@ if (! function_exists('set_realpath')) // Make sure the path exists if ($check_existance == TRUE) { - if ( ! is_dir($path)) + if (! is_dir($path)) { show_error('Not a valid path: '.$path); } diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 7552fd89c..edb6ebb50 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -59,9 +59,9 @@ if (! function_exists('dohash')) { if ($type == 'sha1') { - if ( ! function_exists('sha1')) + if (! function_exists('sha1')) { - if ( ! function_exists('mhash')) + if (! function_exists('mhash')) { require_once(BASEPATH.'libraries/Sha1'.EXT); $SH = new CI_SHA; diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 25962eb54..81c6b9199 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -67,7 +67,7 @@ if (! function_exists('get_clickable_smileys')) { function get_clickable_smileys($image_url = '', $smileys = NULL) { - if ( ! is_array($smileys)) + if (! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) { @@ -120,7 +120,7 @@ if (! function_exists('parse_smileys')) return $str; } - if ( ! is_array($smileys)) + if (! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) { @@ -154,14 +154,14 @@ if (! function_exists('_get_smiley_array')) { function _get_smiley_array() { - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + if (! file_exists(APPPATH.'config/smileys'.EXT)) { return FALSE; } include(APPPATH.'config/smileys'.EXT); - if ( ! isset($smileys) OR ! is_array($smileys)) + if (! isset($smileys) OR ! is_array($smileys)) { return FALSE; } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 21ab77830..df3c89e6f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -226,7 +226,7 @@ if (! function_exists('word_censor')) { function word_censor($str, $censored, $replacement = '') { - if ( ! is_array($censored)) + if (! is_array($censored)) { return $str; } @@ -354,7 +354,7 @@ if (! function_exists('word_wrap')) function word_wrap($str, $charlim = '76') { // Se the character limit - if ( ! is_numeric($charlim)) + if (! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 4d9a1bb6b..88071604d 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -330,13 +330,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+2, 1); - if ( ! in_array($one_after, $space, TRUE) && $one_after != "<") + if (! in_array($one_after, $space, TRUE) && $one_after != "<") { $str = str_replace( $one_before."\"'".$one_after, $one_before."“‘".$one_after, $str); } - elseif ( ! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) + elseif (! in_array($one_before, $space, TRUE) && (in_array($one_after, $space, TRUE) OR $one_after == '<')) { $str = str_replace( $one_before."\"'".$one_after, $one_before."”’".$one_after, @@ -363,7 +363,7 @@ class Auto_typography { $one_before."‘“".$one_after, $str); } - elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") + elseif (! in_array($one_before, $space, TRUE) && $one_before != ">") { $str = str_replace( $one_before."'\"".$one_after, $one_before."’”".$one_after, @@ -378,7 +378,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + if (! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], @@ -391,7 +391,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + if (! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], @@ -412,7 +412,7 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + if (! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, @@ -435,9 +435,9 @@ class Auto_typography { $two_before = substr($str, $start+$current-2, 1); $two_after = substr($str, $start+$current+3, 1); - if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + if ((! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) OR - ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') + (! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') ) { $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, @@ -468,13 +468,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space, TRUE)) + if (! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before.'"'.$one_after, $one_before."“".$one_after, $str); } - elseif( ! in_array($one_before, $space, TRUE)) + elseif(! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."”".$one_after, @@ -495,13 +495,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if ( ! in_array($one_after, $space, TRUE)) + if (! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."‘".$one_after, $str); } - elseif( ! in_array($one_before, $space, TRUE)) + elseif(! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 1ff26082c..02c7f3379 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -103,9 +103,9 @@ if (! function_exists('anchor')) { $title = (string) $title; - if ( ! is_array($uri)) + if (! is_array($uri)) { - $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; + $site_url = (! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri; } else { @@ -150,7 +150,7 @@ if (! function_exists('anchor_popup')) { $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 == '') { @@ -162,14 +162,14 @@ if (! function_exists('anchor_popup')) return "".$title.""; } - if ( ! is_array($attributes)) + 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]; + $atts[$key] = (! isset($attributes[$key])) ? $val : $attributes[$key]; } return "".$title.""; -- cgit v1.2.3-24-g4f1b From 14031d152b76e7744d6f8a70964ecae77ca55179 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 18:29:43 +0000 Subject: implemented fopen mode constants --- system/helpers/file_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 1eb8348e9..2bcb98b4d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -50,7 +50,7 @@ if (! function_exists('read_file')) return file_get_contents($file); } - if (! $fp = @fopen($file, 'rb')) + if (! $fp = @fopen($file, FOPEN_READ_BOF)) { return FALSE; } @@ -85,7 +85,7 @@ if (! function_exists('read_file')) */ if (! function_exists('write_file')) { - function write_file($path, $data, $mode = 'wb') + function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_BOF) { if (! $fp = @fopen($path, $mode)) { @@ -167,7 +167,7 @@ if (! function_exists('get_filenames')) { function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE) { - $_filedata = array(); + static $_filedata = array(); if ($fp = @opendir($source_dir)) { -- cgit v1.2.3-24-g4f1b From 3be20e26b7d3c0f60bc60b314a85138100edab52 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 5 May 2008 20:07:09 +0000 Subject: tweak to the new fopen mode constant names --- system/helpers/file_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 2bcb98b4d..147a7fdf1 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -50,7 +50,7 @@ if (! function_exists('read_file')) return file_get_contents($file); } - if (! $fp = @fopen($file, FOPEN_READ_BOF)) + if (! $fp = @fopen($file, FOPEN_READ)) { return FALSE; } @@ -85,7 +85,7 @@ if (! function_exists('read_file')) */ if (! function_exists('write_file')) { - function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_BOF) + function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { if (! $fp = @fopen($path, $mode)) { -- cgit v1.2.3-24-g4f1b From de7320bb78f02baa3b7cad3983d5b6d3a9c74f34 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 13:51:02 +0000 Subject: Changed the radio() and checkbox() functions to default to not checked by default. --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 10858339e..c9a6897ae 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -289,7 +289,7 @@ if (! function_exists('form_dropdown')) */ if (! function_exists('form_checkbox')) { - function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') + function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); @@ -330,7 +330,7 @@ if (! function_exists('form_checkbox')) */ if (! function_exists('form_radio')) { - function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') + function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if (! is_array($data)) { -- cgit v1.2.3-24-g4f1b From 2798b5033815f9165ad10137c0866b5fdb59ea54 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 6 May 2008 14:12:18 +0000 Subject: fixed a bug where the dir resource was not closed in the directory helper, and made it more efficient http://codeigniter.com/bug_tracker/bug/4206/ --- system/helpers/directory_helper.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 5a23944cb..25c16c1fc 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -45,22 +45,31 @@ if (! function_exists('directory_map')) { if ($fp = @opendir($source_dir)) { + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; $filedata = array(); + while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && substr($file, 0, 1) != '.' AND $top_level_only == FALSE) + if (substr($file, 0, 1) == '.') + { + continue; + } + + if ($top_level_only == FALSE && @is_dir($source_dir.$file)) { $temp_array = array(); - $temp_array = directory_map($source_dir.$file."/"); + $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR); $filedata[$file] = $temp_array; } - elseif (substr($file, 0, 1) != ".") + else { $filedata[] = $file; } } + + closedir($fp); return $filedata; } } -- cgit v1.2.3-24-g4f1b From fd93d22814b090ef85f3079d31fffa66d23d95e8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 6 May 2008 15:18:50 +0000 Subject: Flipped user guide page titles for easier recognition in tabs: CodeIgniter User Guide : Page TItle to Page Title : CodeIgniter User Guide --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 147a7fdf1..21ed5ff97 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -22,7 +22,7 @@ * @subpackage Helpers * @category Helpers * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/helpers/file_helpers.html + * @link http://codeigniter.com/user_guide/helpers/file_helper.html */ // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 00618de8c4aca96edb09094a86242b2495ba124d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 6 May 2008 15:59:14 +0000 Subject: Added a Compatibility Helper --- system/helpers/compatibility_helper.php | 496 ++++++++++++++++++++++++++++++++ 1 file changed, 496 insertions(+) create mode 100644 system/helpers/compatibility_helper.php (limited to 'system/helpers') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php new file mode 100644 index 000000000..9cc282598 --- /dev/null +++ b/system/helpers/compatibility_helper.php @@ -0,0 +1,496 @@ + 0) // 8 = FILE_APPEND flag + { + $mode = FOPEN_WRITE_CREATE; + } + else + { + $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE; + } + + // Check if we're using the include path + if (($flags & 1) > 0) // 1 = FILE_USE_INCLUDE_PATH flag + { + $use_include_path = TRUE; + } + else + { + $use_include_path = FALSE; + } + + $fp = @fopen($filename, $mode, $use_include_path); + + if ($fp === FALSE) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to open stream', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + if (($flags & LOCK_EX) > 0) + { + if (! flock($fh, LOCK_EX)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + } + + // write it + if (($written = @fwrite($fp, $data)) === FALSE) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') failed to write to '.htmlentities($filename), $backtrace[0]['file'], $backtrace[0]['line']); + } + + // Close the handle + @fclose($fh); + + // Return length + return $written; + } +} + +// ------------------------------------------------------------------------ + +/** + * fputcsv() + * + * Format line as CSV and write to file pointer + * http://us.php.net/manual/en/function.fputcsv.php + * + * @access public + * @param resource file pointer + * @param array data to be written + * @param string delimiter + * @param string enclosure + * @return int length of written string + */ +if (! function_exists('fputcsv')) +{ + function fputcsv($handle, $fields, $delimiter = ',', $enclosure = '"') + { + // Checking for a handle resource + if (! is_resource($handle)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.gettype($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // OK, it is a resource, but is it a stream? + if (get_resource_type($handle) !== 'stream') + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.get_resource_type($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // Checking for an array of fields + if (! is_array($fields)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 2 to be array, '.gettype($fields).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // validate delimiter + if (strlen($delimiter) > 1) + { + $delimiter = substr($delimiter, 0, 1); + $backtrace = debug_backtrace(); + _exception_handler(E_NOTICE, 'fputcsv() delimiter must be one character long, "'.htmlentities($delimiter).'" used', $backtrace[0]['file'], $backtrace[0]['line']); + } + + // validate enclosure + if (strlen($enclosure) > 1) + { + $enclosure = substr($enclosure, 0, 1); + $backtrace = debug_backtrace(); + _exception_handler(E_NOTICE, 'fputcsv() enclosure must be one character long, "'.htmlentities($enclosure).'" used', $backtrace[0]['file'], $backtrace[0]['line']); + + } + + $out = ''; + + foreach ($fields as $cell) + { + $cell = str_replace($enclosure, $enclosure.$enclosure, $cell); + + if (strpos($cell, $delimiter) !== FALSE || strpos($cell, $enclosure) !== FALSE || strpos($cell, "\n") !== FALSE) + { + $out .= $enclosure.$cell.$enclosure.$delimiter; + } + else + { + $out .= $cell.$delimiter; + } + } + + $length = @fwrite($handle, substr($out, 0, -1)."\n"); + + return $length; + } +} + +// ------------------------------------------------------------------------ + +/** + * stripos() + * + * Find position of first occurrence of a case-insensitive string + * http://us.php.net/manual/en/function.stripos.php + * + * @access public + * @param string haystack + * @param string needle + * @param int offset + * @return int numeric position of the first occurrence of needle in the haystack + */ +if (! function_exists('stripos')) +{ + function stripos($haystack, $needle, $offset = NULL) + { + // Cast non string scalar values + if (is_scalar($haystack)) + { + settype($haystack, 'STRING'); + } + + if (! is_string($haystack)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'stripos() expects parameter 1 to be string, '.gettype($haystack).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + if (! is_scalar($needle)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'stripos() needle is not a string or an integer in '.$backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + if (is_float($offset)) + { + $offset = (int)$offset; + } + + if (! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'stripos() expects parameter 3 to be long, '.gettype($offset).' given', $backtrace[0]['file'], $backtrace[0]['line']); + return NULL; + } + + return strpos(strtolower($haystack), strtolower($needle), $offset); + } +} + +// ------------------------------------------------------------------------ + +/** + * str_ireplace() + * + * Find position of first occurrence of a case-insensitive string + * http://us.php.net/manual/en/function.str-ireplace.php + * (parameter 4, $count, is not supported as to do so in PHP 4 would make + * it a required parameter) + * + * @access public + * @param mixed search + * @param mixed replace + * @param mixed subject + * @return int numeric position of the first occurrence of needle in the haystack + */ +if (! function_exists('str_ireplace')) +{ + function str_ireplace($search, $replace, $subject) + { + // Nothing to do here + if ($search === NULL || $subject === NULL) + { + return $subject; + } + + // Crazy arguments + if (is_scalar($search) && is_array($replace)) + { + $backtrace = debug_backtrace(); + + if (is_object($replace)) + { + show_error('Object of class '.get_class($replace).' could not be converted to string in '.$backtrace[0]['file'].' on line '.$backtrace[0]['line']); + } + else + { + _exception_handler(E_USER_NOTICE, 'Array to string conversion in '.$backtrace[0]['file'], $backtrace[0]['line']); + } + } + + // Searching for an array + if (is_array($search)) + { + // Replacing with an array + if (is_array($replace)) + { + $search = array_values($search); + $replace = array_values($replace); + + if (count($search) >= count($replace)) + { + $replace = array_pad($replace, count($search), ''); + } + else + { + $replace = array_slice($replace, 0, count($search)); + } + } + else + { + // Replacing with a string all positions + $replace = array_fill(0, count($search), $replace); + } + } + else + { + //Searching for a string and replacing with a string. + $search = array((string)$search); + $replace = array((string)$replace); + } + + // Prepare the search array + foreach ($search as $search_key => $search_value) + { + $search[$search_key] = '/'.preg_quote($search_value, '/').'/i'; + } + + // Prepare the replace array (escape backreferences) + foreach ($replace as $k => $v) + { + $replace[$k] = str_replace(array(chr(92), '$'), array(chr(92).chr(92), '\$'), $v); + } + + // do the replacement + $result = preg_replace($search, $replace, (array)$subject); + + // Check if subject was initially a string and return it as a string + if (! is_array($subject)) + { + return current($result); + } + + // Otherwise, just return the array + return $result; + } +} + +// ------------------------------------------------------------------------ + +/** + * http_build_query() + * + * Generate URL-encoded query string + * http://us.php.net/manual/en/function.http-build-query.php + * + * @access public + * @param array form data + * @param string numeric prefix + * @param string argument separator + * @return string URL-encoded string + */ +if (! function_exists('http_build_query')) +{ + function http_build_query($formdata, $numeric_prefix = NULL, $separator = NULL) + { + // Check the data + if (! is_array($formdata) && ! is_object($formdata)) + { + $backtrace = debug_backtrace(); + _exception_handler(E_USER_WARNING, 'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given', $backtrace[0]['file'], $backtrace[0]['line']); + return FALSE; + } + + // Cast it as array + if (is_object($formdata)) + { + $formdata = get_object_vars($formdata); + } + + // If the array is empty, return NULL + if (empty($formdata)) + { + return NULL; + } + + // Argument separator + if ($separator === NULL) + { + $separator = ini_get('arg_separator.output'); + + if (strlen($separator) == 0) + { + $separator = '&'; + } + } + + // Start building the query + $tmp = array(); + + foreach ($formdata as $key => $val) + { + if ($val === NULL) + { + continue; + } + + if (is_integer($key) && $numeric_prefix != NULL) + { + $key = $numeric_prefix.$key; + } + + if (is_resource($val)) + { + return NULL; + } + + // hand it off to a recursive parser + $tmp[] = _http_build_query_helper($key, $val, $separator); + } + + return implode($separator, $tmp); + } + + + // Helper helper. Remind anyone of college? + // Required to handle recursion in nested arrays. + // + // You could shave fractions of fractions of a second by moving where + // the urlencoding takes place, but it's much less intuitive, and if + // your application has 10,000 form fields, well, you have other problems ;) + function _http_build_query_helper($key, $val, $separator = '&') + { + if (is_scalar($val)) + { + return urlencode($key).'='.urlencode($val); + } + else + { + // arrays please + if (is_object($val)) + { + $val = get_object_vars($val); + } + + foreach ($val as $k => $v) + { + $tmp[] = _http_build_query_helper($key.'['.$k.']', $v, $separator); + } + } + + return implode($separator, $tmp); + } +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d196d4e8593adc8324e4bfbbb959c89ecb3284dc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 03:20:03 +0000 Subject: fixed a typo with a variable in the compatibility helper --- system/helpers/compatibility_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 9cc282598..0d214648c 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -129,7 +129,7 @@ if (! function_exists('file_put_contents')) if (($flags & LOCK_EX) > 0) { - if (! flock($fh, LOCK_EX)) + if (! flock($fp, LOCK_EX)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']); @@ -145,7 +145,7 @@ if (! function_exists('file_put_contents')) } // Close the handle - @fclose($fh); + @fclose($fp); // Return length return $written; -- cgit v1.2.3-24-g4f1b From cd6f9cdbbcdd550e73beccb906fe7ee78714a3f1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 17:31:03 +0000 Subject: removed default title= attribute from anchor() in URL Helper --- system/helpers/url_helper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 02c7f3379..d702f6b87 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -117,11 +117,7 @@ if (! function_exists('anchor')) $title = $site_url; } - if ($attributes == '') - { - $attributes = ' title="'.htmlentities($title).'"'; - } - else + if ($attributes != '') { $attributes = _parse_attributes($attributes); } -- cgit v1.2.3-24-g4f1b From 94a2182c95cc95646ad582616d335bce62152c86 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 15:00:28 +0000 Subject: added symbolic_permissions() and octal_permissions() to the File helper --- system/helpers/file_helper.php | 88 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 21ed5ff97..bdde2d55d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -368,4 +368,92 @@ if (! function_exists('get_mime_by_extension')) } } +// -------------------------------------------------------------------- + +/** + * Symbolic Permissions + * + * Takes a numeric value representing a file's permissions and returns + * standard symbolic notation representing that value + * + * @access public + * @param int + * @return string + */ +if (! function_exists('symbolic_permissions')) +{ + function symbolic_permissions($perms) + { + if (($perms & 0xC000) == 0xC000) + { + $symbolic = 's'; // Socket + } + elseif (($perms & 0xA000) == 0xA000) + { + $symbolic = 'l'; // Symbolic Link + } + elseif (($perms & 0x8000) == 0x8000) + { + $symbolic = '-'; // Regular + } + elseif (($perms & 0x6000) == 0x6000) + { + $symbolic = 'b'; // Block special + } + elseif (($perms & 0x4000) == 0x4000) + { + $symbolic = 'd'; // Directory + } + elseif (($perms & 0x2000) == 0x2000) + { + $symbolic = 'c'; // Character special + } + elseif (($perms & 0x1000) == 0x1000) + { + $symbolic = 'p'; // FIFO pipe + } + else + { + $symbolic = 'u'; // Unknown + } + + // Owner + $symbolic .= (($perms & 0x0100) ? 'r' : '-'); + $symbolic .= (($perms & 0x0080) ? 'w' : '-'); + $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); + + // Group + $symbolic .= (($perms & 0x0020) ? 'r' : '-'); + $symbolic .= (($perms & 0x0010) ? 'w' : '-'); + $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); + + // World + $symbolic .= (($perms & 0x0004) ? 'r' : '-'); + $symbolic .= (($perms & 0x0002) ? 'w' : '-'); + $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); + + return $symbolic; + } +} + +// -------------------------------------------------------------------- + +/** + * Octal Permissions + * + * Takes a numeric value representing a file's permissions and returns + * a three character string representing the file's octal permissions + * + * @access public + * @param int + * @return string + */ +if (! function_exists('octal_permissions')) +{ + function octal_permissions($perms) + { + return substr(sprintf('%o', $perms), -3); + } +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5583e1aae64ff7e902136c4ba610d438dc2015d4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 15:48:20 +0000 Subject: removed closing PHP tag from all framework files --- system/helpers/array_helper.php | 1 - system/helpers/compatibility_helper.php | 1 - system/helpers/cookie_helper.php | 1 - system/helpers/date_helper.php | 1 - system/helpers/directory_helper.php | 1 - system/helpers/download_helper.php | 1 - system/helpers/email_helper.php | 1 - system/helpers/file_helper.php | 1 - system/helpers/form_helper.php | 1 - system/helpers/html_helper.php | 1 - system/helpers/inflector_helper.php | 1 - system/helpers/path_helper.php | 1 - system/helpers/security_helper.php | 1 - system/helpers/smiley_helper.php | 1 - system/helpers/string_helper.php | 1 - system/helpers/text_helper.php | 1 - system/helpers/typography_helper.php | 1 - system/helpers/url_helper.php | 1 - system/helpers/xml_helper.php | 1 - 19 files changed, 19 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 8ae44826a..0d9fc0b47 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,4 +73,3 @@ if (! function_exists('random_element')) } } -?> \ No newline at end of file diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 0d214648c..ee7e77058 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -493,4 +493,3 @@ if (! function_exists('http_build_query')) } } -?> \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 75c769e9c..0d21f11e4 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -131,4 +131,3 @@ if (! function_exists('delete_cookie')) } } -?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 004cfb122..447146860 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -596,4 +596,3 @@ if (! function_exists('timezones')) } } -?> \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 25c16c1fc..a3227c810 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -75,4 +75,3 @@ if (! function_exists('directory_map')) } } -?> \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 284c6c96e..39c2a2afc 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,4 +95,3 @@ if (! function_exists('force_download')) } } -?> \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 307f3b588..a1452cec9 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -57,4 +57,3 @@ if (! function_exists('send_email')) } } -?> \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index bdde2d55d..0c2ae5af6 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -456,4 +456,3 @@ if (! function_exists('octal_permissions')) } } -?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c9a6897ae..c91e5a5c7 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,4 +610,3 @@ if (! function_exists('parse_form_attributes')) } } -?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4e86465c1..f488a5d3d 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -351,4 +351,3 @@ if (! function_exists('nbs')) } } -?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index bf70a6799..a833c70b8 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -164,4 +164,3 @@ if (! function_exists('humanize')) } } -?> \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 6abff06af..8ff9f2425 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -67,4 +67,3 @@ if (! function_exists('set_realpath')) } } -?> \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index edb6ebb50..6e61aa71d 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -121,4 +121,3 @@ if (! function_exists('encode_php_tags')) } } -?> \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 81c6b9199..d65801834 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -170,4 +170,3 @@ if (! function_exists('_get_smiley_array')) } } -?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index f68f44ac1..cd2af0cef 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -268,4 +268,3 @@ if (! function_exists('repeater')) } } -?> \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index df3c89e6f..95c2c619b 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -436,4 +436,3 @@ if (! function_exists('word_wrap')) } } -?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 88071604d..82573844b 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -542,4 +542,3 @@ class Auto_typography { } -?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d702f6b87..1c6c5c552 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,4 +532,3 @@ if (! function_exists('_parse_attributes')) } } -?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 5aa6de9ec..a3d08f622 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -57,4 +57,3 @@ if (! function_exists('xml_convert')) } } -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7deac9f2f9e43cedb18202542e8a46061df046e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 16:27:41 +0000 Subject: Undoing change committed in r1115 --- system/helpers/array_helper.php | 1 + system/helpers/compatibility_helper.php | 1 + system/helpers/cookie_helper.php | 1 + system/helpers/date_helper.php | 1 + system/helpers/directory_helper.php | 1 + system/helpers/download_helper.php | 1 + system/helpers/email_helper.php | 1 + system/helpers/file_helper.php | 1 + system/helpers/form_helper.php | 1 + system/helpers/html_helper.php | 1 + system/helpers/inflector_helper.php | 1 + system/helpers/path_helper.php | 1 + system/helpers/security_helper.php | 1 + system/helpers/smiley_helper.php | 1 + system/helpers/string_helper.php | 1 + system/helpers/text_helper.php | 1 + system/helpers/typography_helper.php | 1 + system/helpers/url_helper.php | 1 + system/helpers/xml_helper.php | 1 + 19 files changed, 19 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 0d9fc0b47..8ae44826a 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,3 +73,4 @@ if (! function_exists('random_element')) } } +?> \ No newline at end of file diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index ee7e77058..0d214648c 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -493,3 +493,4 @@ if (! function_exists('http_build_query')) } } +?> \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 0d21f11e4..75c769e9c 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -131,3 +131,4 @@ if (! function_exists('delete_cookie')) } } +?> \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 447146860..004cfb122 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -596,3 +596,4 @@ if (! function_exists('timezones')) } } +?> \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index a3227c810..25c16c1fc 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -75,3 +75,4 @@ if (! function_exists('directory_map')) } } +?> \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 39c2a2afc..284c6c96e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,3 +95,4 @@ if (! function_exists('force_download')) } } +?> \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index a1452cec9..307f3b588 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -57,3 +57,4 @@ if (! function_exists('send_email')) } } +?> \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0c2ae5af6..bdde2d55d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -456,3 +456,4 @@ if (! function_exists('octal_permissions')) } } +?> \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c91e5a5c7..c9a6897ae 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,3 +610,4 @@ if (! function_exists('parse_form_attributes')) } } +?> \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index f488a5d3d..4e86465c1 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -351,3 +351,4 @@ if (! function_exists('nbs')) } } +?> \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index a833c70b8..bf70a6799 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -164,3 +164,4 @@ if (! function_exists('humanize')) } } +?> \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 8ff9f2425..6abff06af 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -67,3 +67,4 @@ if (! function_exists('set_realpath')) } } +?> \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 6e61aa71d..edb6ebb50 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -121,3 +121,4 @@ if (! function_exists('encode_php_tags')) } } +?> \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index d65801834..81c6b9199 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -170,3 +170,4 @@ if (! function_exists('_get_smiley_array')) } } +?> \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index cd2af0cef..f68f44ac1 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -268,3 +268,4 @@ if (! function_exists('repeater')) } } +?> \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 95c2c619b..df3c89e6f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -436,3 +436,4 @@ if (! function_exists('word_wrap')) } } +?> \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 82573844b..88071604d 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -542,3 +542,4 @@ class Auto_typography { } +?> \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 1c6c5c552..d702f6b87 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,3 +532,4 @@ if (! function_exists('_parse_attributes')) } } +?> \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index a3d08f622..5aa6de9ec 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -57,3 +57,4 @@ if (! function_exists('xml_convert')) } } +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a3ffbbb75ab9403941e4f810703313432b3993cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 18:18:29 +0000 Subject: Removed closing PHP tags, replaced with a comment block identifying the end of the file --- system/helpers/array_helper.php | 4 +++- system/helpers/compatibility_helper.php | 4 +++- system/helpers/cookie_helper.php | 4 +++- system/helpers/date_helper.php | 4 +++- system/helpers/directory_helper.php | 4 +++- system/helpers/download_helper.php | 4 +++- system/helpers/email_helper.php | 4 +++- system/helpers/file_helper.php | 6 ++++-- system/helpers/form_helper.php | 4 +++- system/helpers/html_helper.php | 4 +++- system/helpers/inflector_helper.php | 4 +++- system/helpers/path_helper.php | 4 +++- system/helpers/security_helper.php | 4 +++- system/helpers/smiley_helper.php | 4 +++- system/helpers/string_helper.php | 4 +++- system/helpers/text_helper.php | 4 +++- system/helpers/typography_helper.php | 4 +++- system/helpers/url_helper.php | 4 +++- system/helpers/xml_helper.php | 4 +++- 19 files changed, 58 insertions(+), 20 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 8ae44826a..837e41f14 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -73,4 +73,6 @@ if (! function_exists('random_element')) } } -?> \ No newline at end of file + +/* End of file array_helper.php */ +/* Location: ./system/helpers/array_helper.php */ \ No newline at end of file diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index 0d214648c..076f677fa 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -493,4 +493,6 @@ if (! function_exists('http_build_query')) } } -?> \ No newline at end of file + +/* End of file compatibility_helper.php */ +/* Location: ./system/helpers/compatibility_helper.php */ \ No newline at end of file diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 75c769e9c..7b8989e3b 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -131,4 +131,6 @@ if (! function_exists('delete_cookie')) } } -?> \ No newline at end of file + +/* End of file cookie_helper.php */ +/* Location: ./system/helpers/cookie_helper.php */ \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 004cfb122..c4f0e9a40 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -596,4 +596,6 @@ if (! function_exists('timezones')) } } -?> \ No newline at end of file + +/* End of file date_helper.php */ +/* Location: ./system/helpers/date_helper.php */ \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 25c16c1fc..7af4d1e38 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -75,4 +75,6 @@ if (! function_exists('directory_map')) } } -?> \ No newline at end of file + +/* End of file directory_helper.php */ +/* Location: ./system/helpers/directory_helper.php */ \ No newline at end of file diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 284c6c96e..2096fd849 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,4 +95,6 @@ if (! function_exists('force_download')) } } -?> \ No newline at end of file + +/* End of file download_helper.php */ +/* Location: ./system/helpers/download_helper.php */ \ No newline at end of file diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index 307f3b588..594a030fe 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -57,4 +57,6 @@ if (! function_exists('send_email')) } } -?> \ No newline at end of file + +/* End of file email_helper.php */ +/* Location: ./system/helpers/email_helper.php */ \ No newline at end of file diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index bdde2d55d..fac916f3d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -87,7 +87,7 @@ if (! function_exists('write_file')) { function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { - if (! $fp = @fopen($path, $mode)) + if (! $fp = fopen($path, $mode)) { return FALSE; } @@ -456,4 +456,6 @@ if (! function_exists('octal_permissions')) } } -?> \ No newline at end of file + +/* End of file file_helper.php */ +/* Location: ./system/helpers/file_helper.php */ \ No newline at end of file diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c9a6897ae..541ab844a 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,4 +610,6 @@ if (! function_exists('parse_form_attributes')) } } -?> \ No newline at end of file + +/* End of file form_helper.php */ +/* Location: ./system/helpers/form_helper.php */ \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4e86465c1..592c33a50 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -351,4 +351,6 @@ if (! function_exists('nbs')) } } -?> \ No newline at end of file + +/* End of file html_helper.php */ +/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index bf70a6799..b0b99be54 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -164,4 +164,6 @@ if (! function_exists('humanize')) } } -?> \ No newline at end of file + +/* End of file inflector_helper.php */ +/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 6abff06af..05bbd0027 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -67,4 +67,6 @@ if (! function_exists('set_realpath')) } } -?> \ No newline at end of file + +/* End of file path_helper.php */ +/* Location: ./system/helpers/path_helper.php */ \ No newline at end of file diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index edb6ebb50..0dc1429dd 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -121,4 +121,6 @@ if (! function_exists('encode_php_tags')) } } -?> \ No newline at end of file + +/* End of file security_helper.php */ +/* Location: ./system/helpers/security_helper.php */ \ No newline at end of file diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 81c6b9199..2162ddda0 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -170,4 +170,6 @@ if (! function_exists('_get_smiley_array')) } } -?> \ No newline at end of file + +/* End of file smiley_helper.php */ +/* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index f68f44ac1..b934723bf 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -268,4 +268,6 @@ if (! function_exists('repeater')) } } -?> \ No newline at end of file + +/* End of file string_helper.php */ +/* Location: ./system/helpers/string_helper.php */ \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index df3c89e6f..2d03699f3 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -436,4 +436,6 @@ if (! function_exists('word_wrap')) } } -?> \ No newline at end of file + +/* End of file text_helper.php */ +/* Location: ./system/helpers/text_helper.php */ \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 88071604d..78ade5cc3 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -542,4 +542,6 @@ class Auto_typography { } -?> \ No newline at end of file + +/* End of file typography_helper.php */ +/* Location: ./system/helpers/typography_helper.php */ \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index d702f6b87..32d2da80e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -532,4 +532,6 @@ if (! function_exists('_parse_attributes')) } } -?> \ No newline at end of file + +/* End of file url_helper.php */ +/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 5aa6de9ec..b91664433 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -57,4 +57,6 @@ if (! function_exists('xml_convert')) } } -?> \ No newline at end of file + +/* End of file xml_helper.php */ +/* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 15dcf49a0ea6895cbf009dc15277858cfdd422ef Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 21:37:04 +0000 Subject: removed an ereg from config added a qualifier to a str_replace for \t in Input changed substr to strncmp in Codeigniter.php and directory_map function added braces in an if statement of unit test Removed "scripts" from the auto-load search path. Scripts were deprecated in Version 1.4.1 (September 21, 2006). If you still need to use them for legacy reasons, they must now be manually loaded in each Controller. --- system/helpers/directory_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 7af4d1e38..d00bdf0aa 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -50,7 +50,7 @@ if (! function_exists('directory_map')) while (FALSE !== ($file = readdir($fp))) { - if (substr($file, 0, 1) == '.') + if (strncmp($file, '.', 1) == 0) { continue; } @@ -75,6 +75,6 @@ if (! function_exists('directory_map')) } } - -/* End of file directory_helper.php */ + +/* End of file directory_helper.php */ /* Location: ./system/helpers/directory_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0b59f270a432f8c7b6128981f0a39b4a2e2fbd34 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 04:22:33 +0000 Subject: Some sweeping syntax changes for consistency: (! foo) changed to ( ! foo) || changed to OR changed newline standardization code in various places from preg_replace to str_replace --- system/helpers/array_helper.php | 14 +++---- system/helpers/compatibility_helper.php | 38 +++++++++--------- system/helpers/cookie_helper.php | 14 +++---- system/helpers/date_helper.php | 42 ++++++++++---------- system/helpers/directory_helper.php | 4 +- system/helpers/download_helper.php | 10 ++--- system/helpers/email_helper.php | 12 +++--- system/helpers/file_helper.php | 38 +++++++++--------- system/helpers/form_helper.php | 70 ++++++++++++++++----------------- system/helpers/html_helper.php | 30 +++++++------- system/helpers/inflector_helper.php | 16 ++++---- system/helpers/path_helper.php | 10 ++--- system/helpers/security_helper.php | 18 ++++----- system/helpers/smiley_helper.php | 22 +++++------ system/helpers/string_helper.php | 24 +++++------ system/helpers/text_helper.php | 33 +++++++++------- system/helpers/typography_helper.php | 39 +++++++++--------- system/helpers/url_helper.php | 40 +++++++++---------- system/helpers/xml_helper.php | 8 ++-- 19 files changed, 244 insertions(+), 238 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 837e41f14..faa90373c 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,4 +1,4 @@ - 0) { - if (! flock($fp, LOCK_EX)) + if ( ! flock($fp, LOCK_EX)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'file_put_contents('.htmlentities($filename).') unable to acquire an exclusive lock on file', $backtrace[0]['file'], $backtrace[0]['line']); @@ -167,12 +167,12 @@ if (! function_exists('file_put_contents')) * @param string enclosure * @return int length of written string */ -if (! function_exists('fputcsv')) +if ( ! function_exists('fputcsv')) { function fputcsv($handle, $fields, $delimiter = ',', $enclosure = '"') { // Checking for a handle resource - if (! is_resource($handle)) + if ( ! is_resource($handle)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 1 to be stream resource, '.gettype($handle).' given', $backtrace[0]['file'], $backtrace[0]['line']); @@ -188,7 +188,7 @@ if (! function_exists('fputcsv')) } // Checking for an array of fields - if (! is_array($fields)) + if ( ! is_array($fields)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'fputcsv() expects parameter 2 to be array, '.gettype($fields).' given', $backtrace[0]['file'], $backtrace[0]['line']); @@ -218,7 +218,7 @@ if (! function_exists('fputcsv')) { $cell = str_replace($enclosure, $enclosure.$enclosure, $cell); - if (strpos($cell, $delimiter) !== FALSE || strpos($cell, $enclosure) !== FALSE || strpos($cell, "\n") !== FALSE) + if (strpos($cell, $delimiter) !== FALSE OR strpos($cell, $enclosure) !== FALSE OR strpos($cell, "\n") !== FALSE) { $out .= $enclosure.$cell.$enclosure.$delimiter; } @@ -248,7 +248,7 @@ if (! function_exists('fputcsv')) * @param int offset * @return int numeric position of the first occurrence of needle in the haystack */ -if (! function_exists('stripos')) +if ( ! function_exists('stripos')) { function stripos($haystack, $needle, $offset = NULL) { @@ -258,14 +258,14 @@ if (! function_exists('stripos')) settype($haystack, 'STRING'); } - if (! is_string($haystack)) + if ( ! is_string($haystack)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() expects parameter 1 to be string, '.gettype($haystack).' given', $backtrace[0]['file'], $backtrace[0]['line']); return FALSE; } - if (! is_scalar($needle)) + if ( ! is_scalar($needle)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() needle is not a string or an integer in '.$backtrace[0]['file'], $backtrace[0]['line']); @@ -277,7 +277,7 @@ if (! function_exists('stripos')) $offset = (int)$offset; } - if (! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) + if ( ! is_int($offset) && ! is_bool($offset) && ! is_null($offset)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'stripos() expects parameter 3 to be long, '.gettype($offset).' given', $backtrace[0]['file'], $backtrace[0]['line']); @@ -304,12 +304,12 @@ if (! function_exists('stripos')) * @param mixed subject * @return int numeric position of the first occurrence of needle in the haystack */ -if (! function_exists('str_ireplace')) +if ( ! function_exists('str_ireplace')) { function str_ireplace($search, $replace, $subject) { // Nothing to do here - if ($search === NULL || $subject === NULL) + if ($search === NULL OR $subject === NULL) { return $subject; } @@ -376,7 +376,7 @@ if (! function_exists('str_ireplace')) $result = preg_replace($search, $replace, (array)$subject); // Check if subject was initially a string and return it as a string - if (! is_array($subject)) + if ( ! is_array($subject)) { return current($result); } @@ -400,12 +400,12 @@ if (! function_exists('str_ireplace')) * @param string argument separator * @return string URL-encoded string */ -if (! function_exists('http_build_query')) +if ( ! function_exists('http_build_query')) { function http_build_query($formdata, $numeric_prefix = NULL, $separator = NULL) { // Check the data - if (! is_array($formdata) && ! is_object($formdata)) + if ( ! is_array($formdata) && ! is_object($formdata)) { $backtrace = debug_backtrace(); _exception_handler(E_USER_WARNING, 'http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given', $backtrace[0]['file'], $backtrace[0]['line']); diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 7b8989e3b..821622649 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -1,4 +1,4 @@ -config->item('cookie_path'); } - if (! is_numeric($expire)) + if ( ! is_numeric($expire)) { $expire = time() - 86500; } @@ -103,7 +103,7 @@ if (! function_exists('set_cookie')) * @param bool * @return mixed */ -if (! function_exists('get_cookie')) +if ( ! function_exists('get_cookie')) { function get_cookie($index = '', $xss_clean = FALSE) { @@ -123,7 +123,7 @@ if (! function_exists('get_cookie')) * @param string the cookie prefix * @return void */ -if (! function_exists('delete_cookie')) +if ( ! function_exists('delete_cookie')) { function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') { @@ -131,6 +131,6 @@ if (! function_exists('delete_cookie')) } } - -/* End of file cookie_helper.php */ + +/* End of file cookie_helper.php */ /* Location: ./system/helpers/cookie_helper.php */ \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index c4f0e9a40..095e460a9 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -1,4 +1,4 @@ - '%Y-%m-%dT%H:%i:%s%Q' ); - if (! isset($formats[$fmt])) + if ( ! isset($formats[$fmt])) { return FALSE; } @@ -145,19 +145,19 @@ if (! function_exists('standard_date')) * @param integer Unix timestamp * @return integer */ -if (! function_exists('timespan')) +if ( ! function_exists('timespan')) { function timespan($seconds = 1, $time = '') { $CI =& get_instance(); $CI->lang->load('date'); - if (! is_numeric($seconds)) + if ( ! is_numeric($seconds)) { $seconds = 1; } - if (! is_numeric($time)) + if ( ! is_numeric($time)) { $time = time(); } @@ -262,7 +262,7 @@ if (! function_exists('timespan')) * @param integer a numeric year * @return integer */ -if (! function_exists('days_in_month')) +if ( ! function_exists('days_in_month')) { function days_in_month($month = 0, $year = '') { @@ -271,7 +271,7 @@ if (! function_exists('days_in_month')) return 0; } - if (! is_numeric($year) OR strlen($year) != 4) + if ( ! is_numeric($year) OR strlen($year) != 4) { $year = date('Y'); } @@ -298,7 +298,7 @@ if (! function_exists('days_in_month')) * @param integer Unix timestamp * @return integer */ -if (! function_exists('local_to_gmt')) +if ( ! function_exists('local_to_gmt')) { function local_to_gmt($time = '') { @@ -324,7 +324,7 @@ if (! function_exists('local_to_gmt')) * @param bool whether DST is active * @return integer */ -if (! function_exists('gmt_to_local')) +if ( ! function_exists('gmt_to_local')) { function gmt_to_local($time = '', $timezone = 'UTC', $dst = FALSE) { @@ -353,7 +353,7 @@ if (! function_exists('gmt_to_local')) * @param integer Unix timestamp * @return integer */ -if (! function_exists('mysql_to_unix')) +if ( ! function_exists('mysql_to_unix')) { function mysql_to_unix($time = '') { @@ -390,7 +390,7 @@ if (! function_exists('mysql_to_unix')) * @param string format: us or euro * @return string */ -if (! function_exists('unix_to_human')) +if ( ! function_exists('unix_to_human')) { function unix_to_human($time = '', $seconds = FALSE, $fmt = 'us') { @@ -430,7 +430,7 @@ if (! function_exists('unix_to_human')) * @param string format: us or euro * @return integer */ -if (! function_exists('human_to_unix')) +if ( ! function_exists('human_to_unix')) { function human_to_unix($datestr = '') { @@ -442,7 +442,7 @@ if (! function_exists('human_to_unix')) $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)) + 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; } @@ -501,7 +501,7 @@ if (! function_exists('human_to_unix')) * @param string menu name * @return string */ -if (! function_exists('timezone_menu')) +if ( ! function_exists('timezone_menu')) { function timezone_menu($default = 'UTC', $class = "", $name = 'timezones') { @@ -544,7 +544,7 @@ if (! function_exists('timezone_menu')) * @param string timezone * @return string */ -if (! function_exists('timezones')) +if ( ! function_exists('timezones')) { function timezones($tz = '') { @@ -592,10 +592,10 @@ if (! function_exists('timezones')) if ($tz == 'GMT') $tz = 'UTC'; - return (! isset($zones[$tz])) ? 0 : $zones[$tz]; + return ( ! isset($zones[$tz])) ? 0 : $zones[$tz]; } } - -/* End of file date_helper.php */ + +/* End of file date_helper.php */ /* Location: ./system/helpers/date_helper.php */ \ No newline at end of file diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index d00bdf0aa..1bf694f0b 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -1,4 +1,4 @@ -'; } @@ -137,11 +137,11 @@ if (! function_exists('form_hidden')) * @param string * @return string */ -if (! function_exists('form_input')) +if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } @@ -160,11 +160,11 @@ if (! function_exists('form_input')) * @param string * @return string */ -if (! function_exists('form_password')) +if ( ! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') { - if (! is_array($data)) + if ( ! is_array($data)) { $data = array('name' => $data); } @@ -187,11 +187,11 @@ if (! function_exists('form_password')) * @param string * @return string */ -if (! function_exists('form_upload')) +if ( ! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') { - if (! is_array($data)) + if ( ! is_array($data)) { $data = array('name' => $data); } @@ -212,13 +212,13 @@ if (! function_exists('form_upload')) * @param string * @return string */ -if (! function_exists('form_textarea')) +if ( ! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if (! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } @@ -244,11 +244,11 @@ if (! function_exists('form_textarea')) * @param string * @return string */ -if (! function_exists('form_dropdown')) +if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - if (! is_array($selected)) + if ( ! is_array($selected)) { $selected = array($selected); } @@ -287,11 +287,11 @@ if (! function_exists('form_dropdown')) * @param string * @return string */ -if (! function_exists('form_checkbox')) +if ( ! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { - $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { @@ -328,11 +328,11 @@ if (! function_exists('form_checkbox')) * @param string * @return string */ -if (! function_exists('form_radio')) +if ( ! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { - if (! is_array($data)) + if ( ! is_array($data)) { $data = array('name' => $data); } @@ -353,11 +353,11 @@ if (! function_exists('form_radio')) * @param string * @return string */ -if (! function_exists('form_submit')) +if ( ! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'submit', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -374,11 +374,11 @@ if (! function_exists('form_submit')) * @param string * @return string */ -if (! function_exists('form_reset')) +if ( ! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'reset', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -395,11 +395,11 @@ if (! function_exists('form_reset')) * @param string * @return string */ -if (! function_exists('form_button')) +if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); if ( is_array($data) AND isset($data['content'])) { @@ -422,7 +422,7 @@ if (! function_exists('form_button')) * @param string Additional attributes * @return string */ -if (! function_exists('form_label')) +if ( ! function_exists('form_label')) { function form_label($label_text = '', $id = '', $attributes = array()) { @@ -460,7 +460,7 @@ if (! function_exists('form_label')) * @param string Additional attributes * @return string */ -if (! function_exists('form_fieldset')) +if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) { @@ -497,7 +497,7 @@ if (! function_exists('form_fieldset')) * @param string * @return string */ -if (! function_exists('form_fieldset_close')) +if ( ! function_exists('form_fieldset_close')) { function form_fieldset_close($extra = '') { @@ -514,7 +514,7 @@ if (! function_exists('form_fieldset_close')) * @param string * @return string */ -if (! function_exists('form_close')) +if ( ! function_exists('form_close')) { function form_close($extra = '') { @@ -533,7 +533,7 @@ if (! function_exists('form_close')) * @param string * @return string */ -if (! function_exists('form_prep')) +if ( ! function_exists('form_prep')) { function form_prep($str = '') { @@ -574,7 +574,7 @@ if (! function_exists('form_prep')) * @param array * @return string */ -if (! function_exists('parse_form_attributes')) +if ( ! function_exists('parse_form_attributes')) { function parse_form_attributes($attributes, $default) { @@ -610,6 +610,6 @@ if (! function_exists('parse_form_attributes')) } } - -/* End of file form_helper.php */ + +/* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ \ No newline at end of file diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 592c33a50..7a61055f7 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -1,4 +1,4 @@ -"; - if (! is_array($val)) + if ( ! is_array($val)) { $out .= $val; } @@ -171,7 +171,7 @@ if (! function_exists('_list')) * @param integer * @return string */ -if (! function_exists('br')) +if ( ! function_exists('br')) { function br($num = 1) { @@ -190,11 +190,11 @@ if (! function_exists('br')) * @param mixed * @return string */ -if (! function_exists('img')) +if ( ! function_exists('img')) { function img($src = '', $index_page = FALSE) { - if (! is_array($src) ) + if ( ! is_array($src) ) { $src = array('src' => $src); } @@ -245,7 +245,7 @@ if (! function_exists('img')) * @param boolean should index_page be added to the css path * @return string */ -if (! function_exists('link_tag')) +if ( ! function_exists('link_tag')) { function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) { @@ -320,7 +320,7 @@ if (! function_exists('link_tag')) * @param array * @return string */ -if (! function_exists('meta')) +if ( ! function_exists('meta')) { function meta($meta = array(), $newline = "\n") { @@ -343,7 +343,7 @@ if (! function_exists('meta')) * @param integer * @return string */ -if (! function_exists('nbs')) +if ( ! function_exists('nbs')) { function nbs($num = 1) { @@ -351,6 +351,6 @@ if (! function_exists('nbs')) } } - -/* End of file html_helper.php */ + +/* End of file html_helper.php */ /* Location: ./system/helpers/html_helper.php */ \ No newline at end of file diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index b0b99be54..49ba542a1 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -1,4 +1,4 @@ -', $tag_close = '') { @@ -349,19 +349,22 @@ if (! function_exists('highlight_phrase')) * @param integer the number of characters to wrap at * @return string */ -if (! function_exists('word_wrap')) +if ( ! function_exists('word_wrap')) { function word_wrap($str, $charlim = '76') { // Se the character limit - if (! is_numeric($charlim)) + if ( ! is_numeric($charlim)) $charlim = 76; // Reduce multiple spaces $str = preg_replace("| +|", " ", $str); // Standardize newlines - $str = preg_replace("/\r\n|\r/", "\n", $str); + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\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. @@ -436,6 +439,6 @@ if (! function_exists('word_wrap')) } } - -/* End of file text_helper.php */ + +/* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */ \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 78ade5cc3..cfb2b94f6 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,4 +1,4 @@ -") + elseif ( ! in_array($one_before, $space, TRUE) && $one_before != ">") { $str = str_replace( $one_before."'\"".$one_after, $one_before."’”".$one_after, @@ -378,7 +381,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if (! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."“".$matches['2'][$i]."”".$matches['3'][$i], @@ -391,7 +394,7 @@ class Auto_typography { { for ($i=0, $s=sizeof($matches['0']); $i < $s; ++$i) { - if (! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) + if ( ! in_array($matches['1'][$i], $space, TRUE) && ! in_array($matches['3'][$i], $space, TRUE)) { $str = str_replace( $matches['0'][$i], $matches['1'][$i]."‘".$matches['2'][$i]."’".$matches['3'][$i], @@ -412,7 +415,7 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if (! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + if ( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, @@ -435,9 +438,9 @@ class Auto_typography { $two_before = substr($str, $start+$current-2, 1); $two_after = substr($str, $start+$current+3, 1); - if ((! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) + if (( ! in_array($one_before, $space, TRUE) && ! in_array($one_after, $space, TRUE)) OR - (! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') + ( ! in_array($two_before, $space, TRUE) && ! in_array($two_after, $space, TRUE) && $one_before == ' ' && $one_after == ' ') ) { $str = str_replace( $two_before.$one_before."--".$one_after.$two_after, @@ -468,13 +471,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if (! in_array($one_after, $space, TRUE)) + if ( ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before.'"'.$one_after, $one_before."“".$one_after, $str); } - elseif(! in_array($one_before, $space, TRUE)) + elseif( ! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."”".$one_after, @@ -495,13 +498,13 @@ class Auto_typography { $one_before = substr($str, $start+$current-1, 1); $one_after = substr($str, $start+$current+1, 1); - if (! in_array($one_after, $space, TRUE)) + if ( ! in_array($one_after, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."‘".$one_after, $str); } - elseif(! in_array($one_before, $space, TRUE)) + elseif( ! in_array($one_before, $space, TRUE)) { $str = str_replace( $one_before."'".$one_after, $one_before."’".$one_after, @@ -542,6 +545,6 @@ class Auto_typography { } - -/* End of file typography_helper.php */ + +/* End of file typography_helper.php */ /* Location: ./system/helpers/typography_helper.php */ \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 32d2da80e..16dd3e021 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,4 +1,4 @@ -".$title.""; } - if (! is_array($attributes)) + 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]; + $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key]; } return "".$title.""; @@ -183,7 +183,7 @@ if (! function_exists('anchor_popup')) * @param mixed any attributes * @return string */ -if (! function_exists('mailto')) +if ( ! function_exists('mailto')) { function mailto($email, $title = '', $attributes = '') { @@ -213,7 +213,7 @@ if (! function_exists('mailto')) * @param mixed any attributes * @return string */ -if (! function_exists('safe_mailto')) +if ( ! function_exists('safe_mailto')) { function safe_mailto($email, $title = '', $attributes = '') { @@ -328,7 +328,7 @@ if (! function_exists('safe_mailto')) * @param bool whether to create pop-up links * @return string */ -if (! function_exists('auto_link')) +if ( ! function_exists('auto_link')) { function auto_link($str, $type = 'both', $popup = FALSE) { @@ -393,7 +393,7 @@ if (! function_exists('auto_link')) * @param string the URL * @return string */ -if (! function_exists('prep_url')) +if ( ! function_exists('prep_url')) { function prep_url($str = '') { @@ -425,7 +425,7 @@ if (! function_exists('prep_url')) * @param string the separator: dash, or underscore * @return string */ -if (! function_exists('url_title')) +if ( ! function_exists('url_title')) { function url_title($str, $separator = 'dash') { @@ -474,7 +474,7 @@ if (! function_exists('url_title')) * @param string the method: location or redirect * @return string */ -if (! function_exists('redirect')) +if ( ! function_exists('redirect')) { function redirect($uri = '', $method = 'location', $http_response_code = 302) { @@ -501,7 +501,7 @@ if (! function_exists('redirect')) * @param bool * @return string */ -if (! function_exists('_parse_attributes')) +if ( ! function_exists('_parse_attributes')) { function _parse_attributes($attributes, $javascript = FALSE) { @@ -532,6 +532,6 @@ if (! function_exists('_parse_attributes')) } } - -/* End of file url_helper.php */ + +/* End of file url_helper.php */ /* Location: ./system/helpers/url_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index b91664433..256d1e020 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,4 +1,4 @@ - Date: Wed, 28 May 2008 23:46:28 +0000 Subject: added error suppression to fopen() in write_file() --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0d33fe3f2..86c5c09db 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -87,7 +87,7 @@ if ( ! function_exists('write_file')) { function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE) { - if ( ! $fp = fopen($path, $mode)) + if ( ! $fp = @fopen($path, $mode)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 1e6ab99c692bb0337559d3303143838dff37d638 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 6 Jun 2008 11:37:34 +0000 Subject: Form helper refactored to allow form_open() and form_fieldset() to accept arrays or strings as arguments. --- system/helpers/form_helper.php | 70 ++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 19 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c6aa0d2b4..cc08f4fe4 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -48,18 +48,7 @@ if ( ! function_exists('form_open')) $form = ' 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } + $form .= _attributes_to_string($attributes, TRUE); $form .= '>'; @@ -467,13 +456,7 @@ if ( ! function_exists('form_fieldset')) $fieldset = " 0) - { - foreach ($attributes as $key => $val) - { - $fieldset .= ' '.$key.'="'.$val.'"'; - } - } + $fieldset .= _attributes_to_string($attributes, FALSE); $fieldset .= ">\n"; @@ -610,6 +593,55 @@ if ( ! function_exists('parse_form_attributes')) } } +// ------------------------------------------------------------------------ + +/** + * Attributes To String + * + * Helper function used by some of the form helpers + * + * @access private + * @param mixed + * @param bool + * @return string + */ +if ( ! function_exists('_attributes_to_string')) +{ + function _attributes_to_string($attributes, $formtag = FALSE) + { + if (is_string($attributes) AND strlen($attributes) > 0) + { + if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) + { + $attributes .= ' method="post"'; + } + + return ' '.$attributes; + } + + if (is_object($attributes) AND count($attributes) > 0) + { + $attributes = (array)$attributes; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + $atts = ''; + + if ( ! isset($attributes['method']) AND $formtag === TRUE) + { + $atts .= ' method="post"'; + } + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } + + return $atts; + } + } +} /* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f7623aab9c9d9c0d0dae5911857cf8ba8d7a462c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 6 Jun 2008 13:36:19 +0000 Subject: default to post method --- system/helpers/form_helper.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index cc08f4fe4..37afc2daf 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,7 +40,7 @@ */ if ( ! function_exists('form_open')) { - function form_open($action = '', $attributes = array(), $hidden = array()) + function form_open($action = '', $attributes = = 'method="post"', $hidden = array()) { $CI =& get_instance(); @@ -453,7 +453,6 @@ if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) { - $fieldset = " Date: Fri, 6 Jun 2008 13:41:53 +0000 Subject: goofed. Fixed up. --- system/helpers/form_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 37afc2daf..d250d76e8 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,10 +40,15 @@ */ if ( ! function_exists('form_open')) { - function form_open($action = '', $attributes = = 'method="post"', $hidden = array()) + function form_open($action = '', $attributes = '', $hidden = array()) { $CI =& get_instance(); + if ($attributes == '') + { + $attributes = 'method="post"'; + } + $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; $form = ' Date: Thu, 19 Jun 2008 07:46:22 +0000 Subject: removed maxlength and size as automatically added attributes in form helper --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d250d76e8..5b28d3de8 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -135,7 +135,7 @@ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } -- cgit v1.2.3-24-g4f1b From a935c3f0b0c733641c0b3b6cc8c2f4b2e3df71f2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 19 Jun 2008 17:42:55 +0000 Subject: added a Number helper --- system/helpers/number_helper.php | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 system/helpers/number_helper.php (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php new file mode 100644 index 000000000..f158b1cdc --- /dev/null +++ b/system/helpers/number_helper.php @@ -0,0 +1,68 @@ += 1000000000) + { + $num = round($num/107374182)/10; + $unit = 'GB'; + } + elseif ($num >= 1000000) + { + $num = round($num/104857)/10; + $unit = 'MB'; + } + elseif ($num >= 1000) + { + $num = round($num/102)/10; + $unit = 'KB'; + } + else + { + $unit = 'Bytes'; + } + + return number_format($num, 1).' '.$unit; + } +} + +/* End of file number_helper.php */ +/* Location: ./system/helpers/number_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0f109193689f22ff9b9764c299f3297d987ce78d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 19 Jun 2008 18:09:13 +0000 Subject: --- system/helpers/number_helper.php | 138 ++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 67 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index f158b1cdc..23ba3a1bb 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -1,68 +1,72 @@ -= 1000000000) - { - $num = round($num/107374182)/10; - $unit = 'GB'; - } - elseif ($num >= 1000000) - { - $num = round($num/104857)/10; - $unit = 'MB'; - } - elseif ($num >= 1000) - { - $num = round($num/102)/10; - $unit = 'KB'; - } - else - { - $unit = 'Bytes'; - } - - return number_format($num, 1).' '.$unit; - } -} - -/* End of file number_helper.php */ += 1000000000000) + { + $num = round($num/1099511627776)/10; + $unit = 'TB'; + } + elseif ($num >= 1000000000) + { + $num = round($num/107374182)/10; + $unit = 'GB'; + } + elseif ($num >= 1000000) + { + $num = round($num/104857)/10; + $unit = 'MB'; + } + elseif ($num >= 1000) + { + $num = round($num/102)/10; + $unit = 'KB'; + } + else + { + $unit = 'Bytes'; + } + + return number_format($num, 1).' '.$unit; + } +} + +/* End of file number_helper.php */ /* Location: ./system/helpers/number_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 85f66ea6d2291c77a937305457592e24c85425ae Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 26 Jun 2008 17:03:38 +0000 Subject: Number helper uses lang files Bytes use whole numbers (123.0 bytes is just silly) --- system/helpers/number_helper.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 23ba3a1bb..8c9e384eb 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -38,30 +38,33 @@ if ( ! function_exists('byte_format')) { function byte_format($num) { + $CI =& get_instance(); + $CI->lang->load('number'); if ($num >= 1000000000000) { $num = round($num/1099511627776)/10; - $unit = 'TB'; + $unit = $CI->lang->line('terabyte_abbr'); } elseif ($num >= 1000000000) { $num = round($num/107374182)/10; - $unit = 'GB'; + $unit = $CI->lang->line('gigabyte_abbr'); } elseif ($num >= 1000000) { $num = round($num/104857)/10; - $unit = 'MB'; + $unit = $CI->lang->line('megabyte_abbr'); } elseif ($num >= 1000) { $num = round($num/102)/10; - $unit = 'KB'; + $unit = $CI->lang->line('kilobyte_abbr'); } else { - $unit = 'Bytes'; + $unit = $CI->lang->line('bytes'); + return number_format($num).' '.$unit; } return number_format($num, 1).' '.$unit; -- cgit v1.2.3-24-g4f1b From fd7943aaac8f35956e30874291e211d2a3c48453 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 27 Jun 2008 07:44:45 +0000 Subject: Fixed a double opening <p> tag in the index pages of each system directory. --- system/helpers/index.html | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/index.html b/system/helpers/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/helpers/index.html +++ b/system/helpers/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

    Directory access is forbidden.

    +

    Directory access is forbidden.

    - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cc1be0f6fbf032896b5b1f6373cb247df648f6c8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Jun 2008 17:14:46 +0000 Subject: Moved the
    ", $str); + $str = preg_replace('/<\/span>/i', '', $str); + // Replace our markers back to PHP tags. $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); -- cgit v1.2.3-24-g4f1b From 337c74ab2af0dec69659f8c68c82b12c878c1b88 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 3 Oct 2008 19:09:53 +0000 Subject: tweak of temp tag and highlighting replacement to accommodate environments with different colors specified for highlight_string() --- system/helpers/text_helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 54ef1b580..9f13896ae 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -287,12 +287,11 @@ if ( ! function_exists('highlight_code')) { $str = str_replace(array(''), array(''), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - $str = str_replace('<?php ', '', $str); } - + // Remove our artificially added PHP, and the syntax highlighting that came with it - $str = str_replace('<?php ', '', $str); - $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n
    ", $str); + $str = preg_replace('/<\?php( | )/i', '', $str); + $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); $str = preg_replace('/<\/span>/i', '', $str); // Replace our markers back to PHP tags. -- cgit v1.2.3-24-g4f1b From dbc9e15c814ad2fc8a3fb10fbd1350d42b1f7f9c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 6 Oct 2008 14:41:47 +0000 Subject: Altered auto_link() in the URL helper so that email addresses with "+" included will be linked. --- system/helpers/url_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 121b36b97..acf889007 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -400,7 +400,7 @@ if ( ! function_exists('auto_link')) if ($type != 'url') { - if (preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) + 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++) { -- cgit v1.2.3-24-g4f1b From b4a6cf35fe8c637cec5be811f109f6f841456283 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 6 Oct 2008 18:39:36 +0000 Subject: Added some code to ignore empty folders when deleting directories --- system/helpers/file_helper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 58951823b..6378784f4 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -132,7 +132,11 @@ if ( ! function_exists('delete_files')) { if (is_dir($path.'/'.$filename)) { - delete_files($path.'/'.$filename, $del_dir, $level + 1); + // Ignore empty folders + if (substr($filename, 0, 1) != '.') + { + delete_files($path.'/'.$filename, $del_dir, $level + 1); + } } else { -- cgit v1.2.3-24-g4f1b From fd275707f6c1a5a63feb8708731d7c97683df765 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 10 Oct 2008 22:37:06 +0000 Subject: modifications to url_title() --- system/helpers/url_helper.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index acf889007..002090df1 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -479,19 +479,20 @@ if ( ! function_exists('url_title')) } $trans = array( - $search => $replace, - "\s+" => $replace, - "[^a-z0-9".$replace."]" => '', - $replace."+" => $replace, - $replace."$" => '', - "^".$replace => '' - ); + '&\#\d+?;' => '', + '&\S+?;' => '', + '\s+' => $replace, + '[^a-z0-9\-\._]' => '', + $replace.'+' => $replace, + $replace.'$' => $replace, + '^'.$replace => $replace + ); - $str = strip_tags(strtolower($str)); + $str = strip_tags($str); foreach ($trans as $key => $val) { - $str = preg_replace("#".$key."#", $val, $str); + $str = preg_replace("#".$key."#i", $val, $str); } return trim(stripslashes($str)); -- cgit v1.2.3-24-g4f1b From 42597a107d799fa86ebc706bf8cbac4f9471d08c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 15 Oct 2008 14:10:44 +0000 Subject: Added support for arbitrary attributes in anchor_popup() of the URL helper. --- system/helpers/url_helper.php | 112 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 53 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 002090df1..744295f4c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -36,7 +36,7 @@ * @access public * @param string * @return string - */ + */ if ( ! function_exists('site_url')) { function site_url($uri = '') @@ -55,7 +55,7 @@ if ( ! function_exists('site_url')) * * @access public * @return string - */ + */ if ( ! function_exists('base_url')) { function base_url() @@ -75,7 +75,7 @@ if ( ! function_exists('base_url')) * * @access public * @return string - */ + */ if ( ! function_exists('current_url')) { function current_url() @@ -89,11 +89,11 @@ if ( ! function_exists('current_url')) /** * URL String * - * Returns the URI segments. + * Returns the URI segments. * * @access public * @return string - */ + */ if ( ! function_exists('uri_string')) { function uri_string() @@ -112,7 +112,7 @@ if ( ! function_exists('uri_string')) * * @access public * @return string - */ + */ if ( ! function_exists('index_page')) { function index_page() @@ -121,7 +121,7 @@ if ( ! function_exists('index_page')) return $CI->config->item('index_page'); } } - + // ------------------------------------------------------------------------ /** @@ -134,13 +134,13 @@ if ( ! function_exists('index_page')) * @param string the link title * @param mixed any attributes * @return string - */ + */ if ( ! function_exists('anchor')) { function anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; - + if ( ! is_array($uri)) { $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; @@ -149,7 +149,7 @@ if ( ! function_exists('anchor')) { $site_url = site_url($uri); } - + if ($title == '') { $title = $site_url; @@ -163,7 +163,7 @@ if ( ! function_exists('anchor')) return ''.$title.''; } } - + // ------------------------------------------------------------------------ /** @@ -181,35 +181,41 @@ if ( ! function_exists('anchor')) 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; - + if ($title == '') { $title = $site_url; } - + if ($attributes === FALSE) { return "".$title.""; } - + 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]; + unset($attributes[$key]); + } + + if ($attributes != '') + { + $attributes = _parse_attributes($attributes); } - return "".$title.""; + return "".$title.""; } } - + // ------------------------------------------------------------------------ /** @@ -226,18 +232,18 @@ if ( ! function_exists('mailto')) function mailto($email, $title = '', $attributes = '') { $title = (string) $title; - + if ($title == "") { $title = $email; } - + $attributes = _parse_attributes($attributes); - + return ''.$title.''; } } - + // ------------------------------------------------------------------------ /** @@ -256,17 +262,17 @@ if ( ! function_exists('safe_mailto')) function safe_mailto($email, $title = '', $attributes = '') { $title = (string) $title; - + if ($title == "") { $title = $email; } - + for ($i = 0; $i < 16; $i++) { $x[] = substr(' -EOF; - } -} -// ------------------------------------------------------------------------ - -/** - * Get Clickable Smileys - * - * Returns an array of image tag links that can be clicked to be inserted - * into a form field. - * - * @access public - * @param string the URL to the folder containing the smiley images - * @return array - */ -if ( ! function_exists('get_clickable_smileys')) -{ - function get_clickable_smileys($image_url = '', $smileys = NULL) - { - if ( ! is_array($smileys)) - { - if (FALSE === ($smileys = _get_smiley_array())) - { - return $smileys; - } - } - - // 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]])) - { - continue; - } - - $link[] = "\"".$smileys[$key][3]."\""; - - $used[$smileys[$key][0]] = TRUE; - } - - return $link; - } -} - -// ------------------------------------------------------------------------ - -/** - * Parse Smileys - * - * Takes a string as input and swaps any contained smileys for the actual image - * - * @access public - * @param string the text to be parsed - * @param string the URL to the folder containing the smiley images - * @return string - */ -if ( ! function_exists('parse_smileys')) -{ - function parse_smileys($str = '', $image_url = '', $smileys = NULL) - { - 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); - - foreach ($smileys as $key => $val) - { - $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Get Smiley Array - * - * Fetches the config/smiley.php file - * - * @access private - * @return mixed - */ -if ( ! function_exists('_get_smiley_array')) -{ - function _get_smiley_array() - { - if ( ! file_exists(APPPATH.'config/smileys'.EXT)) - { - return FALSE; - } - - include(APPPATH.'config/smileys'.EXT); - - if ( ! isset($smileys) OR ! is_array($smileys)) - { - return FALSE; - } - - return $smileys; - } -} - - -/* End of file smiley_helper.php */ + + function insert_smiley(smiley) + { + document.{$form_name}.{$form_field}.value += " " + smiley; + } + +EOF; + } +} +// ------------------------------------------------------------------------ + +/** + * Get Clickable Smileys + * + * Returns an array of image tag links that can be clicked to be inserted + * into a form field. + * + * @access public + * @param string the URL to the folder containing the smiley images + * @return array + */ +if ( ! function_exists('get_clickable_smileys')) +{ + function get_clickable_smileys($image_url = '', $smileys = NULL) + { + if ( ! is_array($smileys)) + { + if (FALSE === ($smileys = _get_smiley_array())) + { + return $smileys; + } + } + + // 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]])) + { + continue; + } + + $link[] = "\"".$smileys[$key][3]."\""; + + $used[$smileys[$key][0]] = TRUE; + } + + return $link; + } +} + +// ------------------------------------------------------------------------ + +/** + * Parse Smileys + * + * Takes a string as input and swaps any contained smileys for the actual image + * + * @access public + * @param string the text to be parsed + * @param string the URL to the folder containing the smiley images + * @return string + */ +if ( ! function_exists('parse_smileys')) +{ + function parse_smileys($str = '', $image_url = '', $smileys = NULL) + { + 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); + + foreach ($smileys as $key => $val) + { + $str = str_replace($key, "\"".$smileys[$key][3]."\"", $str); + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Get Smiley Array + * + * Fetches the config/smiley.php file + * + * @access private + * @return mixed + */ +if ( ! function_exists('_get_smiley_array')) +{ + function _get_smiley_array() + { + if ( ! file_exists(APPPATH.'config/smileys'.EXT)) + { + return FALSE; + } + + include(APPPATH.'config/smileys'.EXT); + + if ( ! isset($smileys) OR ! is_array($smileys)) + { + return FALSE; + } + + return $smileys; + } +} + + +/* End of file smiley_helper.php */ /* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 4e376a88c..319002ea7 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -1,273 +1,273 @@ - $val) - { - $str[$key] = strip_slashes($val); - } - } - else - { - $str = stripslashes($str); - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Strip Quotes - * - * Removes single and double quotes from a string - * - * @access public - * @param string - * @return string - */ -if ( ! function_exists('strip_quotes')) -{ - function strip_quotes($str) - { - return str_replace(array('"', "'"), '', $str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Quotes to Entities - * - * Converts single and double quotes to entities - * - * @access public - * @param string - * @return string - */ -if ( ! function_exists('quotes_to_entities')) -{ - function quotes_to_entities($str) - { - return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); - } -} - -// ------------------------------------------------------------------------ -/** - * Reduce Double Slashes - * - * Converts double slashes in a string to a single slash, - * except those found in http:// - * - * http://www.some-site.com//index.php - * - * becomes: - * - * http://www.some-site.com/index.php - * - * @access public - * @param string - * @return string - */ -if ( ! function_exists('reduce_double_slashes')) -{ - function reduce_double_slashes($str) - { - return preg_replace("#([^:])//+#", "\\1/", $str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Reduce Multiples - * - * Reduces multiple instances of a particular character. Example: - * - * Fred, Bill,, Joe, Jimmy - * - * becomes: - * - * Fred, Bill, Joe, Jimmy - * - * @access public - * @param string - * @param string the character you wish to reduce - * @param bool TRUE/FALSE - whether to trim the character from the beginning/end - * @return string - */ -if ( ! function_exists('reduce_multiples')) -{ - function reduce_multiples($str, $character = ',', $trim = FALSE) - { - $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); - - if ($trim === TRUE) - { - $str = trim($str, $character); - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Create a Random String - * - * Useful for generating passwords or hashes. - * - * @access public - * @param string type of random string. Options: alunum, numeric, nozero, unique - * @param integer number of characters - * @return string - */ -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; - } - } -} - -// ------------------------------------------------------------------------ - -/** - * Alternator - * - * Allows strings to be alternated. See docs... - * - * @access public - * @param string (as many parameters as needed) - * @return string - */ -if ( ! function_exists('alternator')) -{ - function alternator() - { - static $i; - - if (func_num_args() == 0) - { - $i = 0; - return ''; - } - $args = func_get_args(); - return $args[($i++ % count($args))]; - } -} - -// ------------------------------------------------------------------------ - -/** - * Repeater function - * - * @access public - * @param string - * @param integer number of repeats - * @return string - */ -if ( ! function_exists('repeater')) -{ - function repeater($data, $num = 1) - { - return (($num > 0) ? str_repeat($data, $num) : ''); - } -} - - -/* End of file string_helper.php */ + $val) + { + $str[$key] = strip_slashes($val); + } + } + else + { + $str = stripslashes($str); + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Strip Quotes + * + * Removes single and double quotes from a string + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('strip_quotes')) +{ + function strip_quotes($str) + { + return str_replace(array('"', "'"), '', $str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Quotes to Entities + * + * Converts single and double quotes to entities + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('quotes_to_entities')) +{ + function quotes_to_entities($str) + { + return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str); + } +} + +// ------------------------------------------------------------------------ +/** + * Reduce Double Slashes + * + * Converts double slashes in a string to a single slash, + * except those found in http:// + * + * http://www.some-site.com//index.php + * + * becomes: + * + * http://www.some-site.com/index.php + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('reduce_double_slashes')) +{ + function reduce_double_slashes($str) + { + return preg_replace("#([^:])//+#", "\\1/", $str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Reduce Multiples + * + * Reduces multiple instances of a particular character. Example: + * + * Fred, Bill,, Joe, Jimmy + * + * becomes: + * + * Fred, Bill, Joe, Jimmy + * + * @access public + * @param string + * @param string the character you wish to reduce + * @param bool TRUE/FALSE - whether to trim the character from the beginning/end + * @return string + */ +if ( ! function_exists('reduce_multiples')) +{ + function reduce_multiples($str, $character = ',', $trim = FALSE) + { + $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str); + + if ($trim === TRUE) + { + $str = trim($str, $character); + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Create a Random String + * + * Useful for generating passwords or hashes. + * + * @access public + * @param string type of random string. Options: alunum, numeric, nozero, unique + * @param integer number of characters + * @return string + */ +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; + } + } +} + +// ------------------------------------------------------------------------ + +/** + * Alternator + * + * Allows strings to be alternated. See docs... + * + * @access public + * @param string (as many parameters as needed) + * @return string + */ +if ( ! function_exists('alternator')) +{ + function alternator() + { + static $i; + + if (func_num_args() == 0) + { + $i = 0; + return ''; + } + $args = func_get_args(); + return $args[($i++ % count($args))]; + } +} + +// ------------------------------------------------------------------------ + +/** + * Repeater function + * + * @access public + * @param string + * @param integer number of repeats + * @return string + */ +if ( ! function_exists('repeater')) +{ + function repeater($data, $num = 1) + { + return (($num > 0) ? str_repeat($data, $num) : ''); + } +} + + +/* End of file string_helper.php */ /* Location: ./system/helpers/string_helper.php */ \ No newline at end of file diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8a4460825..6e61f776a 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -1,443 +1,443 @@ -= $n) - { - return trim($out).$end_char; - } - } - } -} - -// ------------------------------------------------------------------------ - -/** - * High ASCII to Entities - * - * Converts High ascii text and MS Word special characters to character entities - * - * @access public - * @param string - * @return string - */ -if ( ! function_exists('ascii_to_entities')) -{ - function ascii_to_entities($str) - { - $count = 1; - $out = ''; - $temp = array(); - - for ($i = 0, $s = strlen($str); $i < $s; $i++) - { - $ordinal = ord($str[$i]); - - if ($ordinal < 128) - { - $out .= $str[$i]; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - - $out .= '&#'.$number.';'; - $count = 1; - $temp = array(); - } - } - } - - return $out; - } -} - -// ------------------------------------------------------------------------ - -/** - * Entities to ASCII - * - * Converts character entities back to ASCII - * - * @access public - * @param string - * @param bool - * @return string - */ -if ( ! function_exists('entities_to_ascii')) -{ - function entities_to_ascii($str, $all = TRUE) - { - if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) - { - for ($i = 0, $s = count($matches['0']); $i < $s; $i++) - { - $digits = $matches['1'][$i]; - - $out = ''; - - if ($digits < 128) - { - $out .= chr($digits); - - } - elseif ($digits < 2048) - { - $out .= chr(192 + (($digits - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - else - { - $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); - $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); - $out .= chr(128 + ($digits % 64)); - } - - $str = str_replace($matches['0'][$i], $out, $str); - } - } - - if ($all) - { - $str = str_replace(array("&", "<", ">", """, "'", "-"), - array("&","<",">","\"", "'", "-"), - $str); - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Word Censoring Function - * - * Supply a string and an array of disallowed words and any - * matched words will be converted to #### or to the replacement - * word you've submitted. - * - * @access public - * @param string the text string - * @param string the array of censoered words - * @param string the optional replacement value - * @return string - */ -if ( ! function_exists('word_censor')) -{ - function word_censor($str, $censored, $replacement = '') - { - if ( ! is_array($censored)) - { - return $str; - } - - $str = ' '.$str.' '; - foreach ($censored as $badword) - { - if ($replacement != '') - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/i", $replacement, $str); - } - else - { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); - } - } - - return trim($str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Code Highlighter - * - * Colorizes code strings - * - * @access public - * @param string the text string - * @return string - */ -if ( ! function_exists('highlight_code')) -{ - function highlight_code($str) - { - // The highlight string function encodes and highlights - // brackets so we need them to start raw - $str = str_replace(array('<', '>'), array('<', '>'), $str); - - // Replace any existing PHP tags to temporary markers so they don't accidentally - // break the string out of PHP, and thus, thwart the highlighting. - - $str = str_replace(array('', '<%', '%>', '\\', ''), - array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); - - // The highlight_string function requires that the text be surrounded - // by PHP tags, which we will remove later - $str = ''; // tags - // so we'll replace them with tags. - - if (abs(PHP_VERSION) < 5) - { - $str = str_replace(array(''), array(''), $str); - $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); - } - - // Remove our artificially added PHP, and the syntax highlighting that came with it - $str = preg_replace('/<\?php( | )/i', '', $str); - $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); - $str = preg_replace('/<\/span>/i', '', $str); - - // Replace our markers back to PHP tags. - $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), - array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Phrase Highlighter - * - * Highlights a phrase within a text string - * - * @access public - * @param string the text string - * @param string the phrase you'd like to highlight - * @param string the openging tag to precede the phrase with - * @param string the closing tag to end the phrase with - * @return string - */ -if ( ! function_exists('highlight_phrase')) -{ - function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') - { - if ($str == '') - { - return ''; - } - - if ($phrase != '') - { - return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Word Wrap - * - * Wraps text at the specified character. Maintains the integrity of words. - * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor - * will URLs. - * - * @access public - * @param string the text string - * @param integer the number of characters to wrap at - * @return string - */ -if ( ! function_exists('word_wrap')) -{ - function word_wrap($str, $charlim = '76') - { - // Se the character limit - if ( ! is_numeric($charlim)) - $charlim = 76; - - // Reduce multiple spaces - $str = preg_replace("| +|", " ", $str); - - // Standardize newlines - if (strpos($str, "\r") !== FALSE) - { - $str = str_replace(array("\r\n", "\r"), "\n", $str); - } - - // If the current word is surrounded by {unwrap} tags we'll - // strip the entire chunk and replace it with a marker. - $unwrap = array(); - if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) - { - for ($i = 0; $i < count($matches['0']); $i++) - { - $unwrap[] = $matches['1'][$i]; - $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); - } - } - - // Use PHP's native function to do the initial wordwrap. - // We set the cut flag to FALSE so that any individual words that are - // too long get left alone. In the next step we'll deal with them. - $str = wordwrap($str, $charlim, "\n", FALSE); - - // Split the string into individual lines of text and cycle through them - $output = ""; - foreach (explode("\n", $str) as $line) - { - // Is the line within the allowed character count? - // If so we'll join it to the output and continue - if (strlen($line) <= $charlim) - { - $output .= $line."\n"; - continue; - } - - $temp = ''; - while((strlen($line)) > $charlim) - { - // If the over-length word is a URL we won't wrap it - if (preg_match("!\[url.+\]|://|wwww.!", $line)) - { - break; - } - - // Trim the word down - $temp .= substr($line, 0, $charlim-1); - $line = substr($line, $charlim-1); - } - - // If $temp contains data it means we had to split up an over-length - // word into smaller chunks so we'll add it back to our current line - if ($temp != '') - { - $output .= $temp . "\n" . $line; - } - else - { - $output .= $line; - } - - $output .= "\n"; - } - - // Put our markers back - if (count($unwrap) > 0) - { - foreach ($unwrap as $key => $val) - { - $output = str_replace("{{unwrapped".$key."}}", $val, $output); - } - } - - // Remove the unwrap tags - $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); - - return $output; - } -} - - -/* End of file text_helper.php */ += $n) + { + return trim($out).$end_char; + } + } + } +} + +// ------------------------------------------------------------------------ + +/** + * High ASCII to Entities + * + * Converts High ascii text and MS Word special characters to character entities + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('ascii_to_entities')) +{ + function ascii_to_entities($str) + { + $count = 1; + $out = ''; + $temp = array(); + + for ($i = 0, $s = strlen($str); $i < $s; $i++) + { + $ordinal = ord($str[$i]); + + if ($ordinal < 128) + { + $out .= $str[$i]; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + + $out .= '&#'.$number.';'; + $count = 1; + $temp = array(); + } + } + } + + return $out; + } +} + +// ------------------------------------------------------------------------ + +/** + * Entities to ASCII + * + * Converts character entities back to ASCII + * + * @access public + * @param string + * @param bool + * @return string + */ +if ( ! function_exists('entities_to_ascii')) +{ + function entities_to_ascii($str, $all = TRUE) + { + if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) + { + for ($i = 0, $s = count($matches['0']); $i < $s; $i++) + { + $digits = $matches['1'][$i]; + + $out = ''; + + if ($digits < 128) + { + $out .= chr($digits); + + } + elseif ($digits < 2048) + { + $out .= chr(192 + (($digits - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + else + { + $out .= chr(224 + (($digits - ($digits % 4096)) / 4096)); + $out .= chr(128 + ((($digits % 4096) - ($digits % 64)) / 64)); + $out .= chr(128 + ($digits % 64)); + } + + $str = str_replace($matches['0'][$i], $out, $str); + } + } + + if ($all) + { + $str = str_replace(array("&", "<", ">", """, "'", "-"), + array("&","<",">","\"", "'", "-"), + $str); + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Word Censoring Function + * + * Supply a string and an array of disallowed words and any + * matched words will be converted to #### or to the replacement + * word you've submitted. + * + * @access public + * @param string the text string + * @param string the array of censoered words + * @param string the optional replacement value + * @return string + */ +if ( ! function_exists('word_censor')) +{ + function word_censor($str, $censored, $replacement = '') + { + if ( ! is_array($censored)) + { + return $str; + } + + $str = ' '.$str.' '; + foreach ($censored as $badword) + { + if ($replacement != '') + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/i", $replacement, $str); + } + else + { + $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + } + } + + return trim($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Code Highlighter + * + * Colorizes code strings + * + * @access public + * @param string the text string + * @return string + */ +if ( ! function_exists('highlight_code')) +{ + function highlight_code($str) + { + // The highlight string function encodes and highlights + // brackets so we need them to start raw + $str = str_replace(array('<', '>'), array('<', '>'), $str); + + // Replace any existing PHP tags to temporary markers so they don't accidentally + // break the string out of PHP, and thus, thwart the highlighting. + + $str = str_replace(array('', '<%', '%>', '\\', ''), + array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str); + + // The highlight_string function requires that the text be surrounded + // by PHP tags, which we will remove later + $str = ''; // tags + // so we'll replace them with tags. + + if (abs(PHP_VERSION) < 5) + { + $str = str_replace(array(''), array(''), $str); + $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str); + } + + // Remove our artificially added PHP, and the syntax highlighting that came with it + $str = preg_replace('/<\?php( | )/i', '', $str); + $str = preg_replace('/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', "$1\n\n", $str); + $str = preg_replace('/<\/span>/i', '', $str); + + // Replace our markers back to PHP tags. + $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), + array('<?', '?>', '<%', '%>', '\\', '</script>'), $str); + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Phrase Highlighter + * + * Highlights a phrase within a text string + * + * @access public + * @param string the text string + * @param string the phrase you'd like to highlight + * @param string the openging tag to precede the phrase with + * @param string the closing tag to end the phrase with + * @return string + */ +if ( ! function_exists('highlight_phrase')) +{ + function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '') + { + if ($str == '') + { + return ''; + } + + if ($phrase != '') + { + return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open."\\1".$tag_close, $str); + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor + * will URLs. + * + * @access public + * @param string the text string + * @param integer the number of characters to wrap at + * @return string + */ +if ( ! function_exists('word_wrap')) +{ + function word_wrap($str, $charlim = '76') + { + // Se the character limit + if ( ! is_numeric($charlim)) + $charlim = 76; + + // Reduce multiple spaces + $str = preg_replace("| +|", " ", $str); + + // Standardize newlines + if (strpos($str, "\r") !== FALSE) + { + $str = str_replace(array("\r\n", "\r"), "\n", $str); + } + + // If the current word is surrounded by {unwrap} tags we'll + // strip the entire chunk and replace it with a marker. + $unwrap = array(); + if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) + { + for ($i = 0; $i < count($matches['0']); $i++) + { + $unwrap[] = $matches['1'][$i]; + $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); + } + } + + // Use PHP's native function to do the initial wordwrap. + // We set the cut flag to FALSE so that any individual words that are + // too long get left alone. In the next step we'll deal with them. + $str = wordwrap($str, $charlim, "\n", FALSE); + + // Split the string into individual lines of text and cycle through them + $output = ""; + foreach (explode("\n", $str) as $line) + { + // Is the line within the allowed character count? + // If so we'll join it to the output and continue + if (strlen($line) <= $charlim) + { + $output .= $line."\n"; + continue; + } + + $temp = ''; + while((strlen($line)) > $charlim) + { + // If the over-length word is a URL we won't wrap it + if (preg_match("!\[url.+\]|://|wwww.!", $line)) + { + break; + } + + // Trim the word down + $temp .= substr($line, 0, $charlim-1); + $line = substr($line, $charlim-1); + } + + // If $temp contains data it means we had to split up an over-length + // word into smaller chunks so we'll add it back to our current line + if ($temp != '') + { + $output .= $temp . "\n" . $line; + } + else + { + $output .= $line; + } + + $output .= "\n"; + } + + // Put our markers back + if (count($unwrap) > 0) + { + foreach ($unwrap as $key => $val) + { + $output = str_replace("{{unwrapped".$key."}}", $val, $output); + } + } + + // Remove the unwrap tags + $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output); + + return $output; + } +} + + +/* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */ \ No newline at end of file diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index d3cc7f175..46fe6bf36 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -1,71 +1,71 @@ -load->library('typography'); - - return $CI->typography->nl2br_except_pre($str); - } -} - -// ------------------------------------------------------------------------ - -/** - * Auto Typography Wrapper Function - * - * - * @access public - * @param string - * @param bool whether to reduce multiple instances of double newlines to two - * @return string - */ -if ( ! function_exists('auto_typography')) -{ - function auto_typography($str, $reduce_linebreaks = FALSE) - { - $CI =& get_instance(); - $CI->load->library('typography'); - return $CI->typography->auto_typography($str, $reduce_linebreaks); - } -} - -/* End of file typography_helper.php */ +load->library('typography'); + + return $CI->typography->nl2br_except_pre($str); + } +} + +// ------------------------------------------------------------------------ + +/** + * Auto Typography Wrapper Function + * + * + * @access public + * @param string + * @param bool whether to reduce multiple instances of double newlines to two + * @return string + */ +if ( ! function_exists('auto_typography')) +{ + function auto_typography($str, $reduce_linebreaks = FALSE) + { + $CI =& get_instance(); + $CI->load->library('typography'); + return $CI->typography->auto_typography($str, $reduce_linebreaks); + } +} + +/* End of file typography_helper.php */ /* Location: ./system/helpers/typography_helper.php */ \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 744295f4c..fd13dc2d4 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -1,582 +1,582 @@ -config->site_url($uri); - } -} - -// ------------------------------------------------------------------------ - -/** - * Base URL - * - * Returns the "base_url" item from your config file - * - * @access public - * @return string - */ -if ( ! function_exists('base_url')) -{ - function base_url() - { - $CI =& get_instance(); - return $CI->config->slash_item('base_url'); - } -} - -// ------------------------------------------------------------------------ - -/** - * Current URL - * - * Returns the full URL (including segments) of the page where this - * function is placed - * - * @access public - * @return string - */ -if ( ! function_exists('current_url')) -{ - function current_url() - { - $CI =& get_instance(); - return $CI->config->site_url($CI->uri->uri_string()); - } -} - -// ------------------------------------------------------------------------ -/** - * URL String - * - * Returns the URI segments. - * - * @access public - * @return string - */ -if ( ! function_exists('uri_string')) -{ - function uri_string() - { - $CI =& get_instance(); - return $CI->uri->uri_string(); - } -} - -// ------------------------------------------------------------------------ - -/** - * Index page - * - * Returns the "index_page" from your config file - * - * @access public - * @return string - */ -if ( ! function_exists('index_page')) -{ - function index_page() - { - $CI =& get_instance(); - return $CI->config->item('index_page'); - } -} - -// ------------------------------------------------------------------------ - -/** - * Anchor Link - * - * Creates an anchor based on the local URL. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ -if ( ! function_exists('anchor')) -{ - function anchor($uri = '', $title = '', $attributes = '') - { - $title = (string) $title; - - 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 = _parse_attributes($attributes); - } - - return ''.$title.''; - } -} - -// ------------------------------------------------------------------------ - -/** - * Anchor Link - Pop-up version - * - * Creates an anchor based on the local URL. The link - * opens a new window based on the attributes specified. - * - * @access public - * @param string the URL - * @param string the link title - * @param mixed any attributes - * @return string - */ -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; - - if ($title == '') - { - $title = $site_url; - } - - if ($attributes === FALSE) - { - return "".$title.""; - } - - 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]; - unset($attributes[$key]); - } - - if ($attributes != '') - { - $attributes = _parse_attributes($attributes); - } - - return "".$title.""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Mailto Link - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ -if ( ! function_exists('mailto')) -{ - function mailto($email, $title = '', $attributes = '') - { - $title = (string) $title; - - if ($title == "") - { - $title = $email; - } - - $attributes = _parse_attributes($attributes); - - return ''.$title.''; - } -} - -// ------------------------------------------------------------------------ - -/** - * Encoded Mailto Link - * - * Create a spam-protected mailto link written in Javascript - * - * @access public - * @param string the email address - * @param string the link title - * @param mixed any attributes - * @return string - */ -if ( ! function_exists('safe_mailto')) -{ - function safe_mailto($email, $title = '', $attributes = '') - { - $title = (string) $title; - - if ($title == "") - { - $title = $email; - } - - for ($i = 0; $i < 16; $i++) - { - $x[] = substr(' $val) - { - $x[] = ' '.$key.'="'; - for ($i = 0; $i < strlen($val); $i++) - { - $x[] = "|".ord(substr($val, $i, 1)); - } - $x[] = '"'; - } - } - 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]); - - if ($ordinal < 128) - { - $x[] = "|".$ordinal; - } - else - { - if (count($temp) == 0) - { - $count = ($ordinal < 224) ? 2 : 3; - } - - $temp[] = $ordinal; - if (count($temp) == $count) - { - $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); - $x[] = "|".$number; - $count = 1; - $temp = array(); - } - } - } - - $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; - - $x = array_reverse($x); - ob_start(); - - ?>http'. - $matches['4'][$i].'://'. - $matches['5'][$i]. - $matches['6'][$i].''. - $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++) - { - $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); - } - } - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Prep URL - * - * Simply adds the http:// part if missing - * - * @access public - * @param string the URL - * @return string - */ -if ( ! function_exists('prep_url')) -{ - function prep_url($str = '') - { - if ($str == 'http://' OR $str == '') - { - return ''; - } - - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') - { - $str = 'http://'.$str; - } - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Create URL Title - * - * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. - * - * @access public - * @param string the string - * @param string the separator: dash, or underscore - * @return string - */ -if ( ! function_exists('url_title')) -{ - function url_title($str, $separator = 'dash') - { - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else - { - $search = '-'; - $replace = '_'; - } - - $trans = array( - '&\#\d+?;' => '', - '&\S+?;' => '', - '\s+' => $replace, - '[^a-z0-9\-\._]' => '', - $replace.'+' => $replace, - $replace.'$' => $replace, - '^'.$replace => $replace - ); - - $str = strip_tags($str); - - foreach ($trans as $key => $val) - { - $str = preg_replace("#".$key."#i", $val, $str); - } - - return trim(stripslashes($str)); - } -} - -// ------------------------------------------------------------------------ - -/** - * Header Redirect - * - * Header redirect in two flavors - * For very fine grained control over headers, you could use the Output - * Library's set_header() function. - * - * @access public - * @param string the URL - * @param string the method: location or redirect - * @return string - */ -if ( ! function_exists('redirect')) -{ - function redirect($uri = '', $method = 'location', $http_response_code = 302) - { - switch($method) - { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); - break; - default : header("Location: ".site_url($uri), TRUE, $http_response_code); - break; - } - exit; - } -} - -// ------------------------------------------------------------------------ - -/** - * Parse out the attributes - * - * Some of the functions use this - * - * @access private - * @param array - * @param bool - * @return string - */ -if ( ! function_exists('_parse_attributes')) -{ - function _parse_attributes($attributes, $javascript = FALSE) - { - if (is_string($attributes)) - { - return ($attributes != '') ? ' '.$attributes : ''; - } - - $att = ''; - foreach ($attributes as $key => $val) - { - if ($javascript == TRUE) - { - $att .= $key . '=' . $val . ','; - } - else - { - $att .= ' ' . $key . '="' . $val . '"'; - } - } - - if ($javascript == TRUE AND $att != '') - { - $att = substr($att, 0, -1); - } - - return $att; - } -} - - -/* End of file url_helper.php */ +config->site_url($uri); + } +} + +// ------------------------------------------------------------------------ + +/** + * Base URL + * + * Returns the "base_url" item from your config file + * + * @access public + * @return string + */ +if ( ! function_exists('base_url')) +{ + function base_url() + { + $CI =& get_instance(); + return $CI->config->slash_item('base_url'); + } +} + +// ------------------------------------------------------------------------ + +/** + * Current URL + * + * Returns the full URL (including segments) of the page where this + * function is placed + * + * @access public + * @return string + */ +if ( ! function_exists('current_url')) +{ + function current_url() + { + $CI =& get_instance(); + return $CI->config->site_url($CI->uri->uri_string()); + } +} + +// ------------------------------------------------------------------------ +/** + * URL String + * + * Returns the URI segments. + * + * @access public + * @return string + */ +if ( ! function_exists('uri_string')) +{ + function uri_string() + { + $CI =& get_instance(); + return $CI->uri->uri_string(); + } +} + +// ------------------------------------------------------------------------ + +/** + * Index page + * + * Returns the "index_page" from your config file + * + * @access public + * @return string + */ +if ( ! function_exists('index_page')) +{ + function index_page() + { + $CI =& get_instance(); + return $CI->config->item('index_page'); + } +} + +// ------------------------------------------------------------------------ + +/** + * Anchor Link + * + * Creates an anchor based on the local URL. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +if ( ! function_exists('anchor')) +{ + function anchor($uri = '', $title = '', $attributes = '') + { + $title = (string) $title; + + 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 = _parse_attributes($attributes); + } + + return ''.$title.''; + } +} + +// ------------------------------------------------------------------------ + +/** + * Anchor Link - Pop-up version + * + * Creates an anchor based on the local URL. The link + * opens a new window based on the attributes specified. + * + * @access public + * @param string the URL + * @param string the link title + * @param mixed any attributes + * @return string + */ +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; + + if ($title == '') + { + $title = $site_url; + } + + if ($attributes === FALSE) + { + return "".$title.""; + } + + 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]; + unset($attributes[$key]); + } + + if ($attributes != '') + { + $attributes = _parse_attributes($attributes); + } + + return "".$title.""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Mailto Link + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +if ( ! function_exists('mailto')) +{ + function mailto($email, $title = '', $attributes = '') + { + $title = (string) $title; + + if ($title == "") + { + $title = $email; + } + + $attributes = _parse_attributes($attributes); + + return ''.$title.''; + } +} + +// ------------------------------------------------------------------------ + +/** + * Encoded Mailto Link + * + * Create a spam-protected mailto link written in Javascript + * + * @access public + * @param string the email address + * @param string the link title + * @param mixed any attributes + * @return string + */ +if ( ! function_exists('safe_mailto')) +{ + function safe_mailto($email, $title = '', $attributes = '') + { + $title = (string) $title; + + if ($title == "") + { + $title = $email; + } + + for ($i = 0; $i < 16; $i++) + { + $x[] = substr(' $val) + { + $x[] = ' '.$key.'="'; + for ($i = 0; $i < strlen($val); $i++) + { + $x[] = "|".ord(substr($val, $i, 1)); + } + $x[] = '"'; + } + } + 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]); + + if ($ordinal < 128) + { + $x[] = "|".$ordinal; + } + else + { + if (count($temp) == 0) + { + $count = ($ordinal < 224) ? 2 : 3; + } + + $temp[] = $ordinal; + if (count($temp) == $count) + { + $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64); + $x[] = "|".$number; + $count = 1; + $temp = array(); + } + } + } + + $x[] = '<'; $x[] = '/'; $x[] = 'a'; $x[] = '>'; + + $x = array_reverse($x); + ob_start(); + + ?>http'. + $matches['4'][$i].'://'. + $matches['5'][$i]. + $matches['6'][$i].''. + $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++) + { + $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); + } + } + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Prep URL + * + * Simply adds the http:// part if missing + * + * @access public + * @param string the URL + * @return string + */ +if ( ! function_exists('prep_url')) +{ + function prep_url($str = '') + { + if ($str == 'http://' OR $str == '') + { + return ''; + } + + if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + { + $str = 'http://'.$str; + } + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Create URL Title + * + * Takes a "title" string as input and creates a + * human-friendly URL string with either a dash + * or an underscore as the word separator. + * + * @access public + * @param string the string + * @param string the separator: dash, or underscore + * @return string + */ +if ( ! function_exists('url_title')) +{ + function url_title($str, $separator = 'dash') + { + if ($separator == 'dash') + { + $search = '_'; + $replace = '-'; + } + else + { + $search = '-'; + $replace = '_'; + } + + $trans = array( + '&\#\d+?;' => '', + '&\S+?;' => '', + '\s+' => $replace, + '[^a-z0-9\-\._]' => '', + $replace.'+' => $replace, + $replace.'$' => $replace, + '^'.$replace => $replace + ); + + $str = strip_tags($str); + + foreach ($trans as $key => $val) + { + $str = preg_replace("#".$key."#i", $val, $str); + } + + return trim(stripslashes($str)); + } +} + +// ------------------------------------------------------------------------ + +/** + * Header Redirect + * + * Header redirect in two flavors + * For very fine grained control over headers, you could use the Output + * Library's set_header() function. + * + * @access public + * @param string the URL + * @param string the method: location or redirect + * @return string + */ +if ( ! function_exists('redirect')) +{ + function redirect($uri = '', $method = 'location', $http_response_code = 302) + { + switch($method) + { + case 'refresh' : header("Refresh:0;url=".site_url($uri)); + break; + default : header("Location: ".site_url($uri), TRUE, $http_response_code); + break; + } + exit; + } +} + +// ------------------------------------------------------------------------ + +/** + * Parse out the attributes + * + * Some of the functions use this + * + * @access private + * @param array + * @param bool + * @return string + */ +if ( ! function_exists('_parse_attributes')) +{ + function _parse_attributes($attributes, $javascript = FALSE) + { + if (is_string($attributes)) + { + return ($attributes != '') ? ' '.$attributes : ''; + } + + $att = ''; + foreach ($attributes as $key => $val) + { + if ($javascript == TRUE) + { + $att .= $key . '=' . $val . ','; + } + else + { + $att .= ' ' . $key . '="' . $val . '"'; + } + } + + if ($javascript == TRUE AND $att != '') + { + $att = substr($att, 0, -1); + } + + return $att; + } +} + + +/* End of file url_helper.php */ /* Location: ./system/helpers/url_helper.php */ \ No newline at end of file diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 83e2bb3a0..90cce3dda 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -1,62 +1,62 @@ -","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; - } -} - - -/* End of file xml_helper.php */ +","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; + } +} + + +/* End of file xml_helper.php */ /* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 40a2fc8ab781130761237a29455718d24cb23821 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 9 Dec 2008 19:41:25 +0000 Subject: added $lowercase parameter to url_title() to allow forced lowercase --- system/helpers/url_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index fd13dc2d4..9b449ea9e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -471,7 +471,7 @@ if ( ! function_exists('prep_url')) */ if ( ! function_exists('url_title')) { - function url_title($str, $separator = 'dash') + function url_title($str, $separator = 'dash', $lowercase = FALSE) { if ($separator == 'dash') { @@ -501,6 +501,11 @@ if ( ! function_exists('url_title')) $str = preg_replace("#".$key."#i", $val, $str); } + if ($lowercase === TRUE) + { + $str = strtolower($str); + } + return trim(stripslashes($str)); } } -- cgit v1.2.3-24-g4f1b From f1b721a3559e8eb95bc580a3f79c5c2e896c9932 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 21 Jan 2009 17:52:13 +0000 Subject: Fixed a bug affecting some locales where word censoring would not work on words beginning or ending with an accented character. --- system/helpers/text_helper.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 6e61f776a..e79a2419d 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -230,21 +230,28 @@ if ( ! function_exists('word_censor')) { return $str; } + + $str = ' '.$str.' '; + + // \w, \b and a few others do not match on a unicode character + // set for performance reasons. As a result words like über + // will not match on a word boundary. Instead, we'll assume that + // a bad word will be bookeneded by any of these characters. + $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; - $str = ' '.$str.' '; foreach ($censored as $badword) { if ($replacement != '') { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/i", $replacement, $str); + $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/i", "\\1{$replacement}\\3", $str); } else { - $str = preg_replace("/\b(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")\b/ie", "str_repeat('#', strlen('\\1'))", $str); + $str = preg_replace("/({$delim})(".str_replace('\*', '\w*?', preg_quote($badword, '/')).")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'", $str); } } - - return trim($str); + + return trim($str); } } -- cgit v1.2.3-24-g4f1b From 33559103ddf02648837c85ed72425ac06c06080c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 2 Feb 2009 18:50:38 +0000 Subject: replaced all sizeof() in favor of count() - aliases are teh sux0r --- system/helpers/url_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 9b449ea9e..6c3bc837a 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -382,7 +382,7 @@ if ( ! function_exists('auto_link')) { $pop = ($popup == TRUE) ? " target=\"_blank\" " : ""; - for ($i = 0; $i < sizeof($matches['0']); $i++) + for ($i = 0; $i < count($matches['0']); $i++) { $period = ''; if (preg_match("|\.$|", $matches['6'][$i])) @@ -408,7 +408,7 @@ if ( ! function_exists('auto_link')) { 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++) + for ($i = 0; $i < count($matches['0']); $i++) { $period = ''; if (preg_match("|\.$|", $matches['3'][$i])) -- cgit v1.2.3-24-g4f1b From 01d6b4f663588e80ca43deafc40090c910eb4b35 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 3 Feb 2009 14:51:00 +0000 Subject: Fixed a bug where the end character was being added when the character limit's limit intersected the last word of the string. http://expressionengine.com/forums/viewthread/103748/ --- system/helpers/text_helper.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index e79a2419d..fa1de8bc6 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -87,14 +87,16 @@ if ( ! function_exists('character_limiter')) { return $str; } - + $out = ""; foreach (explode(' ', trim($str)) as $val) { - $out .= $val.' '; + $out .= $val.' '; + if (strlen($out) >= $n) { - return trim($out).$end_char; + $out = trim($out); + return (strlen($out) == strlen($str)) ? $out : $out.$end_char; } } } @@ -236,7 +238,7 @@ if ( ! function_exists('word_censor')) // \w, \b and a few others do not match on a unicode character // set for performance reasons. As a result words like über // will not match on a word boundary. Instead, we'll assume that - // a bad word will be bookeneded by any of these characters. + // a bad word will be bookended by any of these characters. $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; foreach ($censored as $badword) -- cgit v1.2.3-24-g4f1b From 1978e12d4221fe7e61749a3206b086e5d4158f77 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 3 Feb 2009 14:54:43 +0000 Subject: tweak to ascii_to_entities() for low ascii entities --- system/helpers/text_helper.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index fa1de8bc6..ad051cd76 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -127,7 +127,17 @@ if ( ! function_exists('ascii_to_entities')) if ($ordinal < 128) { - $out .= $str[$i]; + /* + If the $temp array has a value but we have moved on, then it seems only + fair that we output that entity and restart $temp before continuing. -Paul + */ + if (count($temp) == 1) + { + $out .= '&#'.array_shift($temp).';'; + $count = 1; + } + + $out .= $str[$i]; } else { -- cgit v1.2.3-24-g4f1b From 78a5fc973844c64fe9ead260948b85efaf680da9 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 5 Feb 2009 16:34:35 +0000 Subject: Added the ability to have optgroups in form_dropdown() within the form helper. --- system/helpers/form_helper.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c002c6fc0..01d0ea76d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -268,11 +268,26 @@ if ( ! function_exists('form_dropdown')) foreach ($options as $key => $val) { $key = (string) $key; - $val = (string) $val; - $sel = (in_array($key, $selected))?' selected="selected"':''; + if (is_array($val)) + { + $form .= ''."\n"; + + foreach ($val as $optgroup_key => $optgroup_val) + { + $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; + + $form .= '\n"; + } - $form .= '\n"; + $form .= ''."\n"; + } + else + { + $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; + + $form .= '\n"; + } } $form .= ''; -- cgit v1.2.3-24-g4f1b From 86a840cc46ec3f0b8a83938e665a52e625b9f3c7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 5 Feb 2009 17:31:58 +0000 Subject: wrong var fix --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 01d0ea76d..8cae91a41 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -275,7 +275,7 @@ if ( ! function_exists('form_dropdown')) foreach ($val as $optgroup_key => $optgroup_val) { - $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; + $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; $form .= '\n"; } -- cgit v1.2.3-24-g4f1b From 904094a177488edeacbe8e184d788c286c3e3d9f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 10 Feb 2009 14:00:34 +0000 Subject: Changed the default "type" of form_button() to "button" from "submit" in the form helper. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 8cae91a41..4a62cdb5e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -424,7 +424,7 @@ if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button'); if ( is_array($data) AND isset($data['content'])) { -- cgit v1.2.3-24-g4f1b From a6aabaff9a396436d36b57df84eec77ee72e70ed Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 17:37:52 +0000 Subject: Fixed a bug in plural() with words that end in y http://codeigniter.com/bug_tracker/bug/6342/ --- system/helpers/inflector_helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 9393f11e4..39db5d4af 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -87,7 +87,9 @@ if ( ! function_exists('plural')) if ($end == 'y') { - $str = substr($str, 0, strlen($str)-1).'ies'; + // Y preceded by vowel => regular plural + $vowels = array('a', 'e', 'i', 'o', 'u'); + $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies'; } elseif ($end == 's') { -- cgit v1.2.3-24-g4f1b From f0bcb3c9c41ba4a7236908e2997eb56109ad9592 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 18:40:21 +0000 Subject: udpated xss_clean() in the security helper to pass $is_image instead of the deprecated $charset http://codeigniter.com/bug_tracker/bug/6706/ --- system/helpers/security_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 0e2ba788d..4dbbf728a 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -32,15 +32,15 @@ * * @access public * @param string - * @param string the character set of your data + * @param bool whether or not the content is an image file * @return string */ if ( ! function_exists('xss_clean')) { - function xss_clean($str, $charset = 'ISO-8859-1') + function xss_clean($str, $is_image = FALSE) { $CI =& get_instance(); - return $CI->input->xss_clean($str, $charset); + return $CI->input->xss_clean($str, $is_image); } } -- cgit v1.2.3-24-g4f1b From 534be03fdc52bdaeb48ffe89cb6aa042ad1890ad Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 18:47:47 +0000 Subject: changed redirect() to only force site_url() when the supplied URL doesn't start with an http protocol, allowing you to use the helper for external URLs. --- system/helpers/url_helper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 6c3bc837a..5be43300e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -528,11 +528,16 @@ if ( ! function_exists('redirect')) { function redirect($uri = '', $method = 'location', $http_response_code = 302) { + if ( ! preg_match('#^https?://#i', $uri)) + { + $uri = site_url($uri); + } + switch($method) { - case 'refresh' : header("Refresh:0;url=".site_url($uri)); + case 'refresh' : header("Refresh:0;url=".$uri); break; - default : header("Location: ".site_url($uri), TRUE, $http_response_code); + default : header("Location: ".$uri, TRUE, $http_response_code); break; } exit; -- cgit v1.2.3-24-g4f1b From 0b2145f96b6c05aefb51cccb643d203b83a0d761 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 18:56:01 +0000 Subject: Added trailing periods as characters to be removed in url_title() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed an extraneous Ã… character from the file that crept in from somewhere --- system/helpers/url_helper.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 5be43300e..958c16c4b 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -406,7 +406,7 @@ if ( ! function_exists('auto_link')) if ($type != 'url') { - if (preg_match_all("/([a-zA-Z0-9_\.\-\+Ã…]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) + if (preg_match_all("/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches)) { for ($i = 0; $i < count($matches['0']); $i++) { @@ -491,7 +491,8 @@ if ( ! function_exists('url_title')) '[^a-z0-9\-\._]' => '', $replace.'+' => $replace, $replace.'$' => $replace, - '^'.$replace => $replace + '^'.$replace => $replace, + '\.+$' => '' ); $str = strip_tags($str); -- cgit v1.2.3-24-g4f1b From 2c8dc585dd4134e71a7356f99b6a0dac12bf9d1a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 20:15:49 +0000 Subject: added global cookie prefix to get_cookie() unless the cookie exists as-requested --- system/helpers/cookie_helper.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index d906882ae..77f86e489 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -107,8 +107,14 @@ if ( ! function_exists('get_cookie')) { function get_cookie($index = '', $xss_clean = FALSE) { - $CI =& get_instance(); - return $CI->input->cookie($index, $xss_clean); + $prefix = ''; + + if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') + { + $prefix = config_item('cookie_prefix'); + } + + return $CI->input->cookie($prefix.$index, $xss_clean); } } -- cgit v1.2.3-24-g4f1b From a04cfa77a3b113e5a9d858466bc9ae9f674081fb Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 20:16:57 +0000 Subject: didn't mean to completely remove the CI superobject from get_cookie... --- system/helpers/cookie_helper.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 77f86e489..8d892a5d6 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -107,6 +107,8 @@ if ( ! function_exists('get_cookie')) { function get_cookie($index = '', $xss_clean = FALSE) { + $CI =& get_instance(); + $prefix = ''; if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') -- cgit v1.2.3-24-g4f1b From 63dc27f30ed9327060e7e423a99b67a2f19b8f36 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 21:59:20 +0000 Subject: declared $_filedata as static so it can work properly with recursion through subdirectories http://codeigniter.com/bug_tracker/bug/6592/ --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 8078d96fa..b0c554658 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -223,7 +223,7 @@ if ( ! function_exists('get_dir_file_info')) { function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE) { - $_filedata = array(); + static $_filedata = array(); $relative_path = $source_dir; if ($fp = @opendir($source_dir)) -- cgit v1.2.3-24-g4f1b From 28e5c8fc0ed79017a67b896613698e98fa7da8b3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 9 Mar 2009 22:36:48 +0000 Subject: Fixed a bug that was not setting the default checkbox/radio/pull-down value correctly --- system/helpers/form_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 4a62cdb5e..05616f707 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -644,7 +644,7 @@ if ( ! function_exists('set_select')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0) + if (count($_POST) === 0 AND $default == TRUE) { return ' selected="selected"'; } @@ -699,7 +699,7 @@ if ( ! function_exists('set_checkbox')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0) + if (count($_POST) === 0 AND $default == TRUE) { return ' checked="checked"'; } @@ -754,7 +754,7 @@ if ( ! function_exists('set_radio')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0) + if (count($_POST) === 0 AND $default == TRUE) { return ' checked="checked"'; } -- cgit v1.2.3-24-g4f1b From 1322ec54289f09f7e176924902d5642f269aec48 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Mar 2009 17:01:14 +0000 Subject: ereg eradication --- system/helpers/date_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index dbd7e0ecc..7f6073427 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -460,7 +460,7 @@ if ( ! function_exists('human_to_unix')) $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'])) + if (isset($ex['2']) && preg_match('/[0-9]{1,2}/', $ex['2'])) { $sec = (strlen($ex['2']) == 1) ? '0'.$ex['2'] : $ex['2']; } -- cgit v1.2.3-24-g4f1b From 57fe41072c9d97d3cba2cd5faef529ac94571bfb Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Thu, 26 Mar 2009 18:58:46 +0000 Subject: Modified form_hidden() to accept multi-dimensional arrays. --- system/helpers/form_helper.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 05616f707..0173340c5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -103,19 +103,35 @@ if ( ! function_exists('form_open_multipart')) */ if ( ! function_exists('form_hidden')) { - function form_hidden($name, $value = '') + function form_hidden($name, $value = '', $recursing = FALSE) { - if ( ! is_array($name)) + static $form; + + if ($recursing === FALSE) { - return ''; + $form = "\n"; } - $form = ''; + if (is_array($name)) + { + foreach ($name as $key => $val) + { + form_hidden($key, $val, TRUE); + } + return $form; + } - foreach ($name as $name => $value) + if ( ! is_array($value)) + { + $form .= ''."\n"; + } + else { - $form .= "\n"; - $form .= ''; + foreach ($value as $k => $v) + { + $k = (is_int($k)) ? '' : $k; + form_hidden($name.'['.$k.']', $v, TRUE); + } } return $form; @@ -264,7 +280,7 @@ if ( ! function_exists('form_dropdown')) $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; $form = '"; + return ""; } } -- cgit v1.2.3-24-g4f1b From 8c5299640fed112bb86e7a3930432bd084e86dad Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 10 Jul 2009 19:05:08 +0000 Subject: removed entity protection from form_prep() so as to preserve the user's input when called back into a form element --- system/helpers/form_helper.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index bdc87b86f..987ff18e2 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,22 +610,11 @@ if ( ! function_exists('form_prep')) return ''; } - $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); - $str = htmlspecialchars($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); - return $str; } } -- cgit v1.2.3-24-g4f1b From 94026d914090861da9c2826508a4597badb86af6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 15 Jul 2009 15:56:58 +0000 Subject: added return FALSE if directory_map() cannot read the directory --- system/helpers/directory_helper.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index b1c497686..a6fb7841e 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -72,6 +72,10 @@ if ( ! function_exists('directory_map')) closedir($fp); return $filedata; } + else + { + return FALSE; + } } } -- cgit v1.2.3-24-g4f1b From 01a9b107cab449d1ce24746612e9cf7074e6608d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 17 Jul 2009 18:30:36 +0000 Subject: modified Form Helper so that form_prep() keeps track of strings it's already processed, to prevent encoding and prep from occurring more than once --- system/helpers/form_helper.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 987ff18e2..4c229ae9f 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -123,7 +123,7 @@ if ( ! function_exists('form_hidden')) if ( ! is_array($value)) { - $form .= ''."\n"; + $form .= ''."\n"; } else { @@ -239,8 +239,9 @@ if ( ! function_exists('form_textarea')) $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - - return ""; + + $name = (is_array($data)) ? $data['name'] : $data; + return ""; } } @@ -264,7 +265,7 @@ if (! function_exists('form_multiselect')) { $extra .= ' multiple="multiple"'; } - + return form_dropdown($name, $options, $selected, $extra); } } @@ -592,8 +593,10 @@ if ( ! function_exists('form_close')) */ if ( ! function_exists('form_prep')) { - function form_prep($str = '') + function form_prep($str = '', $field_name = '') { + static $prepped_fields = array(); + // if the field name is an array we do this recursively if (is_array($str)) { @@ -610,11 +613,21 @@ if ( ! function_exists('form_prep')) return ''; } + if (isset($prepped_fields[$field_name])) + { + return $prepped_fields[$field_name]; + } + $str = htmlspecialchars($str); // In case htmlspecialchars misses these. $str = str_replace(array("'", '"'), array("'", """), $str); + if ($field_name != '') + { + $prepped_fields[$field_name] = $str; + } + return $str; } } @@ -643,10 +656,10 @@ if ( ! function_exists('set_value')) return $default; } - return form_prep($_POST[$field]); + return form_prep($_POST[$field], $field); } - return form_prep($OBJ->set_value($field, $default)); + return form_prep($OBJ->set_value($field, $default), $field); } } @@ -902,12 +915,12 @@ if ( ! function_exists('_parse_form_attributes')) } $att = ''; - + foreach ($default as $key => $val) { if ($key == 'value') { - $val = form_prep($val); + $val = form_prep($val, $default['name']); } $att .= $key . '="' . $val . '" '; -- cgit v1.2.3-24-g4f1b From 3eb9faceb9fedb0fa50a2b2d1fc4952c2652af70 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 17 Jul 2009 20:25:13 +0000 Subject: modification to form_prep() solution. A bandaid really, to return the $str if the field has already been prepped --- system/helpers/form_helper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 4c229ae9f..c5e977a40 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -613,9 +613,13 @@ if ( ! function_exists('form_prep')) return ''; } + // we've already prepped a field with this name + // @todo need to figure out a way to namespace this so + // that we know the *exact* field and not just one with + // the same name if (isset($prepped_fields[$field_name])) { - return $prepped_fields[$field_name]; + return $str; } $str = htmlspecialchars($str); -- cgit v1.2.3-24-g4f1b From de8f409e84c4b2c428cba3f2845f2658d3db9b90 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 29 Jul 2009 13:46:37 +0000 Subject: Updating the smiley helper to work with more than one field. Also changing insertion position to be at the cursor and using ids instead of form names. --- system/helpers/smiley_helper.php | 140 +++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 21 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index f9a2cf2b0..f085e53b1 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -28,29 +28,91 @@ // ------------------------------------------------------------------------ /** - * JS Insert Smiley + * Smiley Javascript * - * Generates the javascrip function needed to insert smileys into a form field + * Returns the javascript required for the smiley insertion. Optionally takes + * an array of aliases to loosely couple the smiley array to the view. * * @access public - * @param string form name - * @param string field name - * @return string + * @param mixed alias name or array of alias->field_id pairs + * @param string field_id if alias name was passed in + * @return array */ -if ( ! function_exists('js_insert_smiley')) +if ( ! function_exists('smiley_js')) { - function js_insert_smiley($form_name = '', $form_field = '') - { - return << - function insert_smiley(smiley) + function smiley_js($alias = '', $field_id = '') { - document.{$form_name}.{$form_field}.value += " " + smiley; - } - + static $do_setup = TRUE; + + $r = ''; + + if ($alias != '' && ! is_array($alias)) + { + $alias = array($alias => $field_id); + } + + if ($do_setup === TRUE) + { + $do_setup = FALSE; + + $m = array(); + + if (is_array($alias)) + { + foreach($alias as $name => $id) + { + $m[] = '"'.$name.'" : "'.$id.'"'; + } + } + + $m = '{'.implode(',', $m).'}'; + + $r .= << $id) + { + $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n"; + } + } + } + + return ''; } } + // ------------------------------------------------------------------------ /** @@ -65,8 +127,15 @@ EOF; */ if ( ! function_exists('get_clickable_smileys')) { - function get_clickable_smileys($image_url = '', $smileys = NULL) + function get_clickable_smileys($image_url, $alias = '', $smileys = NULL) { + // For backward compatibility with js_insert_smiley + + if (is_array($alias)) + { + $smileys = $alias; + } + if ( ! is_array($smileys)) { if (FALSE === ($smileys = _get_smiley_array())) @@ -76,8 +145,8 @@ if ( ! function_exists('get_clickable_smileys')) } // Add a trailing slash to the file path if needed - $image_url = preg_replace("/(.+?)\/*$/", "\\1/", $image_url); - + $image_url = rtrim($image_url, '/').'/'; + $used = array(); foreach ($smileys as $key => $val) { @@ -89,12 +158,12 @@ if ( ! function_exists('get_clickable_smileys')) { continue; } - - $link[] = "\"".$smileys[$key][3]."\""; - + + $link[] = "\"".$smileys[$key][3]."\""; + $used[$smileys[$key][0]] = TRUE; } - + return $link; } } @@ -170,6 +239,35 @@ if ( ! function_exists('_get_smiley_array')) } } +// ------------------------------------------------------------------------ + +/** + * JS Insert Smiley + * + * Generates the javascript function needed to insert smileys into a form field + * + * DEPRECATED as of version 1.7.2, use smiley_js instead + * + * @access public + * @param string form name + * @param string field name + * @return string + */ +if ( ! function_exists('js_insert_smiley')) +{ + function js_insert_smiley($form_name = '', $form_field = '') + { + return << + function insert_smiley(smiley) + { + document.{$form_name}.{$form_field}.value += " " + smiley; + } + +EOF; + } +} + /* End of file smiley_helper.php */ /* Location: ./system/helpers/smiley_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 928158bf3a308330ab6518ff0d149d4585d7f38f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 08:20:58 +0000 Subject: adding accept-charset to form_open() --- system/helpers/form_helper.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c5e977a40..2fd4807fc 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -44,9 +44,30 @@ if ( ! function_exists('form_open')) { $CI =& get_instance(); + $charset = strtolower($CI->config->item('charset')); + if ($attributes == '') { - $attributes = 'method="post"'; + $attributes = 'method="post" accept-charset="'.$charset.'"'; + } + else + { + if ( is_string($attributes) ) + { + if(strpos('accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.$charset.'"'; + } + } + else + { + $attributes = (array) $attributes; + + if(!in_array('accept-charset', $attributes)) + { + $attributes['accept-charset'] = $charset; + } + } } $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; -- cgit v1.2.3-24-g4f1b From f673a87ad9530a2982caef0bd5a53983d6b06a63 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 09:35:03 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 2fd4807fc..5917d1016 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -52,7 +52,7 @@ if ( ! function_exists('form_open')) } else { - if ( is_string($attributes) ) + if ( is_string($attributes)) { if(strpos('accept-charset=') === FALSE) { @@ -63,7 +63,7 @@ if ( ! function_exists('form_open')) { $attributes = (array) $attributes; - if(!in_array('accept-charset', $attributes)) + if ( ! in_array('accept-charset', $attributes)) { $attributes['accept-charset'] = $charset; } -- cgit v1.2.3-24-g4f1b From 76763bb6e18c15bf099564789bfa621a938313d8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 11:25:20 +0000 Subject: removed some trivial spaces from output --- system/helpers/html_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 427d1ce3f..ca933bd78 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -301,11 +301,11 @@ if ( ! function_exists('link_tag')) { if ($index_page === TRUE) { - $link .= ' href="'.$CI->config->site_url($v).'" '; + $link .= 'href="'.$CI->config->site_url($v).'" '; } else { - $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" '; + $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" '; } } else @@ -324,11 +324,11 @@ if ( ! function_exists('link_tag')) } elseif ($index_page === TRUE) { - $link .= ' href="'.$CI->config->site_url($href).'" '; + $link .= 'href="'.$CI->config->site_url($href).'" '; } else { - $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" '; + $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" '; } $link .= 'rel="'.$rel.'" type="'.$type.'" '; -- cgit v1.2.3-24-g4f1b From 292dcd83359db59a60564cf7ceb1890e5395ac36 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 11:26:32 +0000 Subject: removed some trivial spaces from output --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index ca933bd78..b55ec88ca 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -320,7 +320,7 @@ if ( ! function_exists('link_tag')) { if ( strpos($href, '://') !== FALSE) { - $link .= ' href="'.$href.'" '; + $link .= 'href="'.$href.'" '; } elseif ($index_page === TRUE) { -- cgit v1.2.3-24-g4f1b From 3241d73d55649893cea7c55d1d24b2981088b0d1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 17 Sep 2009 12:17:45 +0000 Subject: modified the way accept-charset is added --- system/helpers/form_helper.php | 54 +++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5917d1016..02e2edd3e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -44,30 +44,9 @@ if ( ! function_exists('form_open')) { $CI =& get_instance(); - $charset = strtolower($CI->config->item('charset')); - if ($attributes == '') { - $attributes = 'method="post" accept-charset="'.$charset.'"'; - } - else - { - if ( is_string($attributes)) - { - if(strpos('accept-charset=') === FALSE) - { - $attributes .= ' accept-charset="'.$charset.'"'; - } - } - else - { - $attributes = (array) $attributes; - - if ( ! in_array('accept-charset', $attributes)) - { - $attributes['accept-charset'] = $charset; - } - } + $attributes = 'method="post"'; } $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; @@ -87,6 +66,7 @@ if ( ! function_exists('form_open')) } } + // ------------------------------------------------------------------------ /** @@ -978,6 +958,11 @@ if ( ! function_exists('_attributes_to_string')) $attributes .= ' method="post"'; } + if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + return ' '.$attributes; } @@ -988,19 +973,24 @@ if ( ! function_exists('_attributes_to_string')) if (is_array($attributes) AND count($attributes) > 0) { - $atts = ''; + $atts = ''; - if ( ! isset($attributes['method']) AND $formtag === TRUE) - { - $atts .= ' method="post"'; - } + if ( ! isset($attributes['method']) AND $formtag === TRUE) + { + $atts .= ' method="post"'; + } - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } + if ( ! isset($attributes['accept-charset']) AND $formtag === TRUE) + { + $atts .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } - return $atts; + return $atts; } } } -- cgit v1.2.3-24-g4f1b From e339ef56f366024b4d094a8f7335d56cf683598b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 25 Sep 2009 03:23:21 +0000 Subject: Made get_mime_by_extension() case insensitive. --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0d7b5d5aa..cb3d60ee9 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -340,7 +340,7 @@ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { - $extension = substr(strrchr($file, '.'), 1); + $extension = strtolower(substr(strrchr($file, '.'), 1)); global $mimes; -- cgit v1.2.3-24-g4f1b From 8719a5c7fe75b84f49f584065e5ef4e4e2a0f16f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 8 Oct 2009 16:42:59 +0000 Subject: Deprecated the dohash() function in favour of do_hash() for naming consistency. --- system/helpers/security_helper.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 9cc70aaff..8fb53e718 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -46,6 +46,22 @@ if ( ! function_exists('xss_clean')) // -------------------------------------------------------------------- +/** + * Hash encode a string + * + * This is simply an alias for do_hash() + * dohash() is now deprecated + */ +if ( ! function_exists('dohash')) +{ + function dohash($str, $type = 'sha1') + { + return $this->do_hash($str, $type); + } +} + +// -------------------------------------------------------------------- + /** * Hash encode a string * @@ -53,9 +69,9 @@ if ( ! function_exists('xss_clean')) * @param string * @return string */ -if ( ! function_exists('dohash')) +if ( ! function_exists('do_hash')) { - function dohash($str, $type = 'sha1') + function do_hash($str, $type = 'sha1') { if ($type == 'sha1') { -- cgit v1.2.3-24-g4f1b From a3f47180e3885fca82599e90c95ce6e5c26072d6 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 4 Nov 2009 17:23:32 +0000 Subject: Modified inflector helper to properly pluralize words that end in 'ch' or 'sh' http://codeigniter.com/bug_tracker/bug/9384/ --- system/helpers/inflector_helper.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index e65968a9d..8db4f3d75 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -91,6 +91,17 @@ if ( ! function_exists('plural')) $vowels = array('a', 'e', 'i', 'o', 'u'); $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies'; } + elseif ($end == 'h') + { + if (substr($str, -2) == 'ch' || substr($str, -2) == 'sh') + { + $str .= 'es'; + } + else + { + $str .= 's'; + } + } elseif ($end == 's') { if ($force == TRUE) -- cgit v1.2.3-24-g4f1b From 986e17262a17aa2c2059bc3be25a18b43deb712e Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 9 Nov 2009 20:51:15 +0000 Subject: incorrect variable name in the smiley helper js --- system/helpers/smiley_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index f085e53b1..ab1f2c27e 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -93,7 +93,7 @@ if ( ! function_exists('smiley_js')) el.setSelectionRange(newStart, newStart); } else if (document.selection) { - document.selection.createRange().text = text; + document.selection.createRange().text = smiley; } } EOF; -- cgit v1.2.3-24-g4f1b From 788b00f7eaad969120079acedc82e8d60b0e2a46 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Nov 2009 18:00:20 +0000 Subject: non-backwards compatible change to get_dir_file_info() for performance reasons, as well as fixing recursive bug --- system/helpers/file_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index cb3d60ee9..41ec2648e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -220,7 +220,7 @@ if ( ! function_exists('get_filenames')) */ if ( ! function_exists('get_dir_file_info')) { - function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE) + function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) { static $_filedata = array(); $relative_path = $source_dir; @@ -234,18 +234,20 @@ if ( ! function_exists('get_dir_file_info')) $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } + // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) - { - get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) + if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); + } + elseif (strncmp($file, '.', 1) !== 0) + { $_filedata[$file] = get_file_info($source_dir.$file); $_filedata[$file]['relative_path'] = $relative_path; } } + return $_filedata; } else -- cgit v1.2.3-24-g4f1b From 42e74bc677f3f59d6c6a77d371b70c8365ce2e27 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 23 Dec 2009 16:44:07 +0000 Subject: tweaking the regex for reduce_double_slashes to correctly handle duplicates at the beginning of the string --- system/helpers/string_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 3f7f09a15..dbfa0c41a 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -140,7 +140,7 @@ if ( ! function_exists('reduce_double_slashes')) { function reduce_double_slashes($str) { - return preg_replace("#([^:])//+#", "\\1/", $str); + return preg_replace("#(^|[^:])//+#", "\\1/", $str); } } -- cgit v1.2.3-24-g4f1b From 7f3719faf120dc15f3d7b45e132ab3192f60ad62 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Jan 2010 13:35:37 +0000 Subject: updated copyrights --- system/helpers/array_helper.php | 2 +- system/helpers/compatibility_helper.php | 2 +- system/helpers/cookie_helper.php | 2 +- system/helpers/date_helper.php | 2 +- system/helpers/directory_helper.php | 2 +- system/helpers/download_helper.php | 2 +- system/helpers/email_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/form_helper.php | 2 +- system/helpers/html_helper.php | 2 +- system/helpers/inflector_helper.php | 2 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/path_helper.php | 2 +- system/helpers/security_helper.php | 2 +- system/helpers/smiley_helper.php | 2 +- system/helpers/string_helper.php | 2 +- system/helpers/text_helper.php | 2 +- system/helpers/typography_helper.php | 2 +- system/helpers/url_helper.php | 2 +- system/helpers/xml_helper.php | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index 39d0c88c6..b7289900f 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index c217f7f52..e7b21c660 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 7607ffb4a..40afadb57 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index fae9e66e4..0e9781666 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index a6fb7841e..791cf0d10 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a8f7b1a7f..638ebaa88 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/email_helper.php b/system/helpers/email_helper.php index df602b115..046562a91 100644 --- a/system/helpers/email_helper.php +++ b/system/helpers/email_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 41ec2648e..114b2927a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 02e2edd3e..c78b805e5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index b55ec88ca..d5bdd080c 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php index 8db4f3d75..c4c530bc5 100644 --- a/system/helpers/inflector_helper.php +++ b/system/helpers/inflector_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index e97a8c78b..442619c93 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index a041a60b7..cf683f2a1 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 502fae4b3..030b6bff1 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 8fb53e718..1f0a62906 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index ab1f2c27e..931f1308d 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index dbfa0c41a..67cbd0eb6 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 06910e411..1e672937b 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 2706d53b0..5621e6dd0 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 546552a69..90ea9207e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 2a4c808ce..712f6777e 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 98a447ac363d00d856c18f34ffbd4d14cad51eb3 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Thu, 7 Jan 2010 18:14:28 +0000 Subject: changing the second parameter in directory_map to an integer that controls recursion depth. A depth of 0 is fully recursive to maintain backward compatibility with the boolean values. --- system/helpers/directory_helper.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index 791cf0d10..7de6a3c51 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -36,32 +36,30 @@ * * @access public * @param string path to source - * @param bool whether to limit the result to the top level only + * @param int depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) * @return array */ if ( ! function_exists('directory_map')) { - function directory_map($source_dir, $top_level_only = FALSE, $hidden = FALSE) - { + function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) + { if ($fp = @opendir($source_dir)) { - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; - $filedata = array(); - + $filedata = array(); + $new_depth = $directory_depth - 1; + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + while (FALSE !== ($file = readdir($fp))) { - if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..')) + // Remove '.', '..', and hidden files [optional] + if ( ! trim($file, '.') OR ($hidden == FALSE && $file[0] == '.')) { continue; } - - if ($top_level_only == FALSE && @is_dir($source_dir.$file)) + + if (($directory_depth < 1 OR $new_depth > 0) && @is_dir($source_dir.$file)) { - $temp_array = array(); - - $temp_array = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, $hidden); - - $filedata[$file] = $temp_array; + $filedata[$file] = directory_map($source_dir.$file.DIRECTORY_SEPARATOR, $new_depth, $hidden); } else { @@ -72,10 +70,8 @@ if ( ! function_exists('directory_map')) closedir($fp); return $filedata; } - else - { - return FALSE; - } + + return FALSE; } } -- cgit v1.2.3-24-g4f1b From 3e9519e07af366f9bd7b48de34db689f573d37ea Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 15 Jan 2010 00:09:34 +0000 Subject: Update to file helper to return FALSE on failure. --- system/helpers/file_helper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 114b2927a..2be06ac4f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -124,7 +124,9 @@ if ( ! function_exists('delete_files')) $path = rtrim($path, DIRECTORY_SEPARATOR); if ( ! $current_dir = @opendir($path)) - return; + { + return TRUE; + } while(FALSE !== ($filename = @readdir($current_dir))) { @@ -148,8 +150,10 @@ if ( ! function_exists('delete_files')) if ($del_dir == TRUE AND $level > 0) { - @rmdir($path); + return @rmdir($path); } + + return TRUE; } } -- cgit v1.2.3-24-g4f1b From 33d4b6aac7f33d6cddfa5fb39c5701ecc9cfa80b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:23:00 +0000 Subject: adding the ability for form_open_multipart() to accept string attribute arguments --- system/helpers/form_helper.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c78b805e5..60d2631e9 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -84,7 +84,15 @@ if ( ! function_exists('form_open_multipart')) { function form_open_multipart($action, $attributes = array(), $hidden = array()) { - $attributes['enctype'] = 'multipart/form-data'; + if (is_string($attributes)) + { + $attributes .= ' enctype="multipart/form-data"'; + } + else + { + $attributes['enctype'] = 'multipart/form-data'; + } + return form_open($action, $attributes, $hidden); } } -- cgit v1.2.3-24-g4f1b From f063ed7a0d51fd2abd5dd716ab7f92a54e45cd11 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:48:25 +0000 Subject: making get_mime_by_extension case insensitive --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 2be06ac4f..9ea5018ae 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -346,7 +346,7 @@ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { - $extension = strtolower(substr(strrchr($file, '.'), 1)); + $extension = strtolower(substr(strrchr(strtolower($file), '.'), 1)); global $mimes; -- cgit v1.2.3-24-g4f1b From 9502311beeda23042370bb891f850eab3aadad96 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:51:21 +0000 Subject: change already made - revert --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 9ea5018ae..2be06ac4f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -346,7 +346,7 @@ if ( ! function_exists('get_mime_by_extension')) { function get_mime_by_extension($file) { - $extension = strtolower(substr(strrchr(strtolower($file), '.'), 1)); + $extension = strtolower(substr(strrchr($file, '.'), 1)); global $mimes; -- cgit v1.2.3-24-g4f1b From fcbb0266468db83d2d8d4006d80f77445fd6a0e2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 16:13:15 +0000 Subject: optional precision argument in byte_format() --- system/helpers/number_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index cf683f2a1..1fdd30326 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -36,29 +36,29 @@ */ if ( ! function_exists('byte_format')) { - function byte_format($num) + function byte_format($num, $precision = 1) { $CI =& get_instance(); $CI->lang->load('number'); if ($num >= 1000000000000) { - $num = round($num / 1099511627776, 1); + $num = round($num / 1099511627776, $precision); $unit = $CI->lang->line('terabyte_abbr'); } elseif ($num >= 1000000000) { - $num = round($num / 1073741824, 1); + $num = round($num / 1073741824, $precision); $unit = $CI->lang->line('gigabyte_abbr'); } elseif ($num >= 1000000) { - $num = round($num / 1048576, 1); + $num = round($num / 1048576, $precision); $unit = $CI->lang->line('megabyte_abbr'); } elseif ($num >= 1000) { - $num = round($num / 1024, 1); + $num = round($num / 1024, $precision); $unit = $CI->lang->line('kilobyte_abbr'); } else @@ -67,9 +67,11 @@ if ( ! function_exists('byte_format')) return number_format($num).' '.$unit; } - return number_format($num, 1).' '.$unit; + return number_format($num, $precision).' '.$unit; } } + + /* End of file number_helper.php */ /* Location: ./system/helpers/number_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 472dd21a7bc60147afff7bf100bbb6c9f339d0fc Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 23 Jan 2010 20:03:27 +0000 Subject: Added alpha, and sha1 string types to random_string() in the String Helper. --- system/helpers/string_helper.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 67cbd0eb6..4767f0b5f 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -186,22 +186,27 @@ if ( ! function_exists('reduce_multiples')) * Useful for generating passwords or hashes. * * @access public - * @param string type of random string. Options: alunum, numeric, nozero, unique + * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1 * @param integer number of characters * @return string - */ + */ if ( ! function_exists('random_string')) -{ +{ function random_string($type = 'alnum', $len = 8) { switch($type) { + case 'basic' : return mt_rand(); + break; case 'alnum' : case 'numeric' : case 'nozero' : + case 'alpha' : switch ($type) { + case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + break; case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'numeric' : $pool = '0123456789'; @@ -217,12 +222,22 @@ if ( ! function_exists('random_string')) } return $str; break; - case 'unique' : return md5(uniqid(mt_rand())); + case 'unique' : + case 'md5' : + + return md5(uniqid(mt_rand())); + break; + case 'encrypt' : + case 'sha1' : + + $CI =& get_instance(); + $CI->load->helper('security'); + + return do_hash(uniqid(mt_rand(), TRUE), 'sha1'); break; } } } - // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 22224b513bf5dcb3f34798f0a9568049966d7ee8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 23:06:53 -0600 Subject: modified cookie helper to use input class --- system/helpers/cookie_helper.php | 43 +--------------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/cookie_helper.php b/system/helpers/cookie_helper.php index 40afadb57..4be371efe 100644 --- a/system/helpers/cookie_helper.php +++ b/system/helpers/cookie_helper.php @@ -46,50 +46,9 @@ if ( ! function_exists('set_cookie')) { function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '') { - if (is_array($name)) - { - foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item) - { - if (isset($name[$item])) - { - $$item = $name[$item]; - } - } - } - // Set the config file options $CI =& get_instance(); - - if ($prefix == '' AND $CI->config->item('cookie_prefix') != '') - { - $prefix = $CI->config->item('cookie_prefix'); - } - if ($domain == '' AND $CI->config->item('cookie_domain') != '') - { - $domain = $CI->config->item('cookie_domain'); - } - if ($path == '/' AND $CI->config->item('cookie_path') != '/') - { - $path = $CI->config->item('cookie_path'); - } - - if ( ! is_numeric($expire)) - { - $expire = time() - 86500; - } - else - { - if ($expire > 0) - { - $expire = time() + $expire; - } - else - { - $expire = 0; - } - } - - setcookie($prefix.$name, $value, $expire, $path, $domain, 0); + $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix); } } -- cgit v1.2.3-24-g4f1b From 626d39f92bb9185ea85daafd6679529d054b85ab Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 23:14:56 -0600 Subject: code comments fix --- system/helpers/file_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 2be06ac4f..274c4ad37 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -125,7 +125,7 @@ if ( ! function_exists('delete_files')) if ( ! $current_dir = @opendir($path)) { - return TRUE; + return FALSE; } while(FALSE !== ($filename = @readdir($current_dir))) @@ -218,7 +218,7 @@ if ( ! function_exists('get_filenames')) * * @access public * @param string path to source - * @param bool whether to include the path as part of the filename + * @param bool Look only at the top level directory specified? * @param bool internal variable to determine recursion status - do not use in calls * @return array */ -- cgit v1.2.3-24-g4f1b From 36591099aa01107294f8b2794351b078b7575a25 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:05:51 -0600 Subject: little cleaner regex in human_to_unix() --- system/helpers/date_helper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 0e9781666..2c60f0302 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -288,7 +288,7 @@ if ( ! function_exists('days_in_month')) return $days_in_month[$month - 1]; } } - + // ------------------------------------------------------------------------ /** @@ -343,7 +343,7 @@ if ( ! function_exists('gmt_to_local')) return $time; } } - + // ------------------------------------------------------------------------ /** @@ -440,14 +440,14 @@ if ( ! function_exists('human_to_unix')) } $datestr = trim($datestr); - $datestr = preg_replace("/\040+/", "\040", $datestr); - + $datestr = preg_replace("/\040+/", ' ', $datestr); + if ( ! preg_match('/^[0-9]{2,4}\-[0-9]{1,2}\-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(?::[0-9]{1,2})?(?:\s[AP]M)?$/i', $datestr)) { return FALSE; } - - $split = preg_split("/\040/", $datestr); + + $split = explode(' ', $datestr); $ex = explode("-", $split['0']); -- cgit v1.2.3-24-g4f1b From 68788d5577d9f101220e3e6e8fba0829feb136de Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:11:31 -0600 Subject: bringing form helper in sync --- system/helpers/form_helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 60d2631e9..5feb3ce66 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -66,7 +66,6 @@ if ( ! function_exists('form_open')) } } - // ------------------------------------------------------------------------ /** @@ -266,7 +265,7 @@ if ( ! function_exists('form_textarea')) * @param string * @return type */ -if (! function_exists('form_multiselect')) +if ( ! function_exists('form_multiselect')) { function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') { @@ -320,7 +319,7 @@ if ( ! function_exists('form_dropdown')) { $key = (string) $key; - if (is_array($val)) + if (is_array($val) && ! empty($val)) { $form .= ''."\n"; @@ -638,7 +637,7 @@ if ( ! function_exists('form_prep')) if ($field_name != '') { - $prepped_fields[$field_name] = $str; + $prepped_fields[$field_name] = $field_name; } return $str; -- cgit v1.2.3-24-g4f1b From d4433348afe653a0472cbe4d023db883fd142d11 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:13:55 -0600 Subject: whitespace --- system/helpers/number_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/number_helper.php b/system/helpers/number_helper.php index 1fdd30326..f7979215c 100644 --- a/system/helpers/number_helper.php +++ b/system/helpers/number_helper.php @@ -72,6 +72,5 @@ if ( ! function_exists('byte_format')) } - /* End of file number_helper.php */ /* Location: ./system/helpers/number_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 11b1e51f8df7a1e47d002a14a76748f6f629f988 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:22:44 -0600 Subject: no in helpers, updated security lib to use Security class instead of Input --- system/helpers/security_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 1f0a62906..654cfd100 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -40,7 +40,7 @@ if ( ! function_exists('xss_clean')) function xss_clean($str, $is_image = FALSE) { $CI =& get_instance(); - return $CI->input->xss_clean($str, $is_image); + return $CI->security->xss_clean($str, $is_image); } } @@ -56,7 +56,7 @@ if ( ! function_exists('dohash')) { function dohash($str, $type = 'sha1') { - return $this->do_hash($str, $type); + return do_hash($str, $type); } } -- cgit v1.2.3-24-g4f1b From 48822fa77cd02a7974a56cf92d989aefbd98e9af Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:23:39 -0600 Subject: updating attributes to lowercase and added CDATA block around js --- system/helpers/smiley_helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 931f1308d..775cc1b99 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -68,7 +68,6 @@ if ( ! function_exists('smiley_js')) $m = '{'.implode(',', $m).'}'; $r .= <<'.$r.''; + return ''; } } @@ -159,7 +158,7 @@ if ( ! function_exists('get_clickable_smileys')) continue; } - $link[] = "\"".$smileys[$key][3]."\""; + $link[] = "\"".$smileys[$key][3]."\""; $used[$smileys[$key][0]] = TRUE; } -- cgit v1.2.3-24-g4f1b From 1e1419229ea85b9928f2b0f7d2bad1f5cefc3946 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:24:50 -0600 Subject: whitespace, code comments --- system/helpers/string_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php index 4767f0b5f..60f6ed171 100644 --- a/system/helpers/string_helper.php +++ b/system/helpers/string_helper.php @@ -30,7 +30,7 @@ /** * Trim Slashes * - * Removes any leading/traling slashes from a string: + * Removes any leading/trailing slashes from a string: * * /this/that/theother/ * @@ -46,10 +46,10 @@ if ( ! function_exists('trim_slashes')) { function trim_slashes($str) { - return trim($str, '/'); - } + return trim($str, '/'); + } } - + // ------------------------------------------------------------------------ /** @@ -120,6 +120,7 @@ if ( ! function_exists('quotes_to_entities')) } // ------------------------------------------------------------------------ + /** * Reduce Double Slashes * @@ -143,7 +144,7 @@ if ( ! function_exists('reduce_double_slashes')) return preg_replace("#(^|[^:])//+#", "\\1/", $str); } } - + // ------------------------------------------------------------------------ /** @@ -173,7 +174,7 @@ if ( ! function_exists('reduce_multiples')) { $str = trim($str, $character); } - + return $str; } } @@ -238,6 +239,7 @@ if ( ! function_exists('random_string')) } } } + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From daf9c01a2c25515eea87fb4f4c905f49c30d0214 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:29:30 -0600 Subject: added convert_accented_characters() function to Text Helper --- system/helpers/text_helper.php | 48 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 1e672937b..477260216 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -87,7 +87,7 @@ if ( ! function_exists('character_limiter')) { return $str; } - + $out = ""; foreach (explode(' ', trim($str)) as $val) { @@ -136,7 +136,7 @@ if ( ! function_exists('ascii_to_entities')) $out .= '&#'.array_shift($temp).';'; $count = 1; } - + $out .= $str[$i]; } else @@ -248,7 +248,7 @@ if ( ! function_exists('word_censor')) // \w, \b and a few others do not match on a unicode character // set for performance reasons. As a result words like über // will not match on a word boundary. Instead, we'll assume that - // a bad word will be bookended by any of these characters. + // a bad word will be bookeneded by any of these characters. $delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'; foreach ($censored as $badword) @@ -352,6 +352,44 @@ if ( ! function_exists('highlight_phrase')) return $str; } } + +// ------------------------------------------------------------------------ + +/** + * Convert Accented Foreign Characters to ASCII + * + * @access public + * @param string the text string + * @return string + */ +if ( ! function_exists('convert_accented_characters')) +{ + function convert_accented_characters($match) + { + if ( ! file_exists(APPPATH.'config/foreign_chars'.EXT)) + { + return $match; + } + + include APPPATH.'config/foreign_chars'.EXT; + + if ( ! isset($foreign_characters)) + { + return $match; + } + + $ord = ord($match['1']); + + if (isset($foreign_characters[$ord])) + { + return $foreign_characters[$ord]; + } + else + { + return $match['1']; + } + } +} // ------------------------------------------------------------------------ @@ -431,7 +469,7 @@ if ( ! function_exists('word_wrap')) // word into smaller chunks so we'll add it back to our current line if ($temp != '') { - $output .= $temp . "\n" . $line; + $output .= $temp."\n".$line; } else { @@ -456,7 +494,7 @@ if ( ! function_exists('word_wrap')) return $output; } } - + /* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2b7de06bd0e2184c9bffc971490f7f640c736a6a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:31:08 -0600 Subject: added entity_decode() to Typography helper, updated auto_typography() --- system/helpers/typography_helper.php | 59 ++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 5621e6dd0..712b57509 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -54,16 +54,71 @@ if ( ! function_exists('nl2br_except_pre')) * * @access public * @param string + * @param bool whether to allow javascript event handlers * @param bool whether to reduce multiple instances of double newlines to two * @return string */ if ( ! function_exists('auto_typography')) { - function auto_typography($str, $reduce_linebreaks = FALSE) + function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) { $CI =& get_instance(); $CI->load->library('typography'); - return $CI->typography->auto_typography($str, $reduce_linebreaks); + return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); + } +} + + +// -------------------------------------------------------------------- + +/** + * HTML Entities Decode + * + * This function is a replacement for html_entity_decode() + * + * In some versions of PHP the native function does not work + * when UTF-8 is the specified character set, so this gives us + * a work-around. More info here: + * http://bugs.php.net/bug.php?id=25670 + * + * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the + * character set, and the PHP developers said they were not back porting the + * fix to versions other than PHP 5.x. + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('entity_decode')) +{ + function entity_decode($str, $charset='UTF-8') + { + if (stristr($str, '&') === FALSE) return $str; + + // The reason we are not using html_entity_decode() by itself is because + // while it is not technically correct to leave out the semicolon + // at the end of an entity most browsers will still interpret the entity + // correctly. html_entity_decode() does not convert entities without + // semicolons, so we are left with our own little solution here. Bummer. + + if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) + { + $str = html_entity_decode($str, ENT_COMPAT, $charset); + $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); + return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); + } + + // Numeric Entities + $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); + $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); + + // Literal Entities - Slightly slow so we do another check + if (stristr($str, '&') === FALSE) + { + $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); + } + + return $str; } } -- cgit v1.2.3-24-g4f1b From 85b2bb7df5e5308b5283e24a3d83aadd1fa9d4de Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:32:03 -0600 Subject: improved xml_convert() of XML helper --- system/helpers/xml_helper.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 712f6777e..09b7aee49 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -36,25 +36,33 @@ */ if ( ! function_exists('xml_convert')) { - function xml_convert($str) + function xml_convert($str, $protect_all = FALSE) { $temp = '__TEMP_AMPERSANDS__'; // Replace entities to temporary markers so that - // ampersands won't get messed up + // ampersands won't get messed up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + if ($protect_all === TRUE) + { + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + } $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); + array("&", "<", ">", """, "'", "-"), + $str); // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - + + if ($protect_all === TRUE) + { + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + } + return $str; - } + } } -- cgit v1.2.3-24-g4f1b From 99111e3abe02e9a40795fa96f33ea08e492eadcd Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:39:08 -0600 Subject: added end of function marker --- system/helpers/xml_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/helpers') diff --git a/system/helpers/xml_helper.php b/system/helpers/xml_helper.php index 09b7aee49..56f5e0112 100644 --- a/system/helpers/xml_helper.php +++ b/system/helpers/xml_helper.php @@ -65,6 +65,7 @@ if ( ! function_exists('xml_convert')) } } +// ------------------------------------------------------------------------ /* End of file xml_helper.php */ /* Location: ./system/helpers/xml_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b41032d2df1e63566f1183533b388372538c46d0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:22:45 -0600 Subject: moved CAPTCHA plugin to a helper --- system/helpers/captcha_helper.php | 246 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 system/helpers/captcha_helper.php (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php new file mode 100644 index 000000000..a58789219 --- /dev/null +++ b/system/helpers/captcha_helper.php @@ -0,0 +1,246 @@ + '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); + + foreach ($defaults as $key => $val) + { + if ( ! is_array($data)) + { + if ( ! isset($$key) OR $$key == '') + { + $$key = $val; + } + } + else + { + $$key = ( ! isset($data[$key])) ? $val : $data[$key]; + } + } + + if ($img_path == '' OR $img_url == '') + { + return FALSE; + } + + if ( ! @is_dir($img_path)) + { + return FALSE; + } + + if ( ! is_writable($img_path)) + { + return FALSE; + } + + if ( ! extension_loaded('gd')) + { + return FALSE; + } + + // ----------------------------------- + // Remove old images + // ----------------------------------- + + list($usec, $sec) = explode(" ", microtime()); + $now = ((float)$usec + (float)$sec); + + $current_dir = @opendir($img_path); + + while($filename = @readdir($current_dir)) + { + if ($filename != "." and $filename != ".." and $filename != "index.html") + { + $name = str_replace(".jpg", "", $filename); + + if (($name + $expiration) < $now) + { + @unlink($img_path.$filename); + } + } + } + + @closedir($current_dir); + + // ----------------------------------- + // Do we have a "word" yet? + // ----------------------------------- + + if ($word == '') + { + $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + + $str = ''; + for ($i = 0; $i < 8; $i++) + { + $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1); + } + + $word = $str; + } + + // ----------------------------------- + // Determine angle and position + // ----------------------------------- + + $length = strlen($word); + $angle = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0; + $x_axis = rand(6, (360/$length)-16); + $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height); + + // ----------------------------------- + // Create image + // ----------------------------------- + + // PHP.net recommends imagecreatetruecolor(), but it isn't always available + if (function_exists('imagecreatetruecolor')) + { + $im = imagecreatetruecolor($img_width, $img_height); + } + else + { + $im = imagecreate($img_width, $img_height); + } + + // ----------------------------------- + // Assign colors + // ----------------------------------- + + $bg_color = imagecolorallocate ($im, 255, 255, 255); + $border_color = imagecolorallocate ($im, 153, 102, 102); + $text_color = imagecolorallocate ($im, 204, 153, 153); + $grid_color = imagecolorallocate($im, 255, 182, 182); + $shadow_color = imagecolorallocate($im, 255, 240, 240); + + // ----------------------------------- + // Create the rectangle + // ----------------------------------- + + ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color); + + // ----------------------------------- + // Create the spiral pattern + // ----------------------------------- + + $theta = 1; + $thetac = 7; + $radius = 16; + $circles = 20; + $points = 32; + + for ($i = 0; $i < ($circles * $points) - 1; $i++) + { + $theta = $theta + $thetac; + $rad = $radius * ($i / $points ); + $x = ($rad * cos($theta)) + $x_axis; + $y = ($rad * sin($theta)) + $y_axis; + $theta = $theta + $thetac; + $rad1 = $radius * (($i + 1) / $points); + $x1 = ($rad1 * cos($theta)) + $x_axis; + $y1 = ($rad1 * sin($theta )) + $y_axis; + imageline($im, $x, $y, $x1, $y1, $grid_color); + $theta = $theta - $thetac; + } + + // ----------------------------------- + // Write the text + // ----------------------------------- + + $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE; + + if ($use_font == FALSE) + { + $font_size = 5; + $x = rand(0, $img_width/($length/3)); + $y = 0; + } + else + { + $font_size = 16; + $x = rand(0, $img_width/($length/1.5)); + $y = $font_size+2; + } + + for ($i = 0; $i < strlen($word); $i++) + { + if ($use_font == FALSE) + { + $y = rand(0 , $img_height/2); + imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color); + $x += ($font_size*2); + } + else + { + $y = rand($img_height/2, $img_height-3); + imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1)); + $x += $font_size; + } + } + + + // ----------------------------------- + // Create the border + // ----------------------------------- + + imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color); + + // ----------------------------------- + // Generate the image + // ----------------------------------- + + $img_name = $now.'.jpg'; + + ImageJPEG($im, $img_path.$img_name); + + $img = "\""; + + ImageDestroy($im); + + return array('word' => $word, 'time' => $now, 'image' => $img); + } +} + +// ------------------------------------------------------------------------ + +/* End of file captcha_pi.php */ +/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1c73f4e9a1b8d33e7eeda622b9ae44b9b2f41251 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:27:41 -0600 Subject: fixed eof code comment --- system/helpers/captcha_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index a58789219..67db50947 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -242,5 +242,5 @@ if ( ! function_exists('create_captcha')) // ------------------------------------------------------------------------ -/* End of file captcha_pi.php */ -/* Location: ./system/plugins/captcha_pi.php */ \ No newline at end of file +/* End of file captcha_helper.php */ +/* Location: ./system/heleprs/captcha_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e659fbbffd63d019b1a3753a8e3b3dd74e1cb225 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:34:09 -0600 Subject: moving js cal plugin to a helper --- system/helpers/js_calendar_helper.php | 629 ++++++++++++++++++++++++++++++++++ 1 file changed, 629 insertions(+) create mode 100644 system/helpers/js_calendar_helper.php (limited to 'system/helpers') diff --git a/system/helpers/js_calendar_helper.php b/system/helpers/js_calendar_helper.php new file mode 100644 index 000000000..f722777b3 --- /dev/null +++ b/system/helpers/js_calendar_helper.php @@ -0,0 +1,629 @@ +load->plugin('js_calendar'); + +Once loaded you'll add the calendar script to the of your page like this: + + + +The above function will be passed the name of your form. + +Then to show the actual calendar you'll do this: + + +
    + +

    Today

    +
    + + +Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, +and the third tells the calendar whether to highlight the current day or not. + +Lastly, you'll need some CSS for your calendar: + +.calendar { + border: 1px #6975A3 solid; + background-color: transparent; +} +.calheading { + background-color: #7C8BC0; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; +} +.calnavleft { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + padding: 4px; + cursor: pointer; +} +.calnavright { + background-color: #7C8BC0; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + font-weight: bold; + color: #fff; + text-align: right; + padding: 4px; + cursor: pointer; +} +.caldayheading { + background-color: #000; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 10px; + text-align: center; + padding: 6px 2px 6px 2px; +} +.caldaycells{ + color: #000; + background-color: #D1D7E6; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #E0E5F1 solid; + cursor: pointer; +} +.caldaycellhover{ + color: #fff; + background-color: #B3BCD4; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + text-align: center; + padding: 4px; + border: 1px #B3BCD4 solid; + cursor: pointer; +} +.caldayselected{ + background-color: #737FAC; + color: #fff; + font-family: Lucida Grande, Verdana, Geneva, Sans-serif; + font-size: 11px; + font-weight: bold; + text-align: center; + border: 1px #566188 solid; + padding: 3px; + cursor: pointer; +} +.calblanktop { + background-color: #fff; + padding: 4px; +} +.calblankbot { + background-color: #fff; + padding: 4px; +} + + +*/ + +function js_calendar_script($form_name = 'entryform') +{ +$CI =& get_instance(); +$CI->load->language('calendar'); +ob_start(); +?> + + + var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); + document.write('.$field_id.'.write()); + '; +} + + +/* End of file js_calendar_pi.php */ +/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b6de7d13eb06d7736d255eaa0b60391a4d2b4bf5 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 11:34:34 -0600 Subject: REMOVING js calendar helper / plugin. No need with the prolific jQuery calendars --- system/helpers/js_calendar_helper.php | 629 ---------------------------------- 1 file changed, 629 deletions(-) delete mode 100644 system/helpers/js_calendar_helper.php (limited to 'system/helpers') diff --git a/system/helpers/js_calendar_helper.php b/system/helpers/js_calendar_helper.php deleted file mode 100644 index f722777b3..000000000 --- a/system/helpers/js_calendar_helper.php +++ /dev/null @@ -1,629 +0,0 @@ -load->plugin('js_calendar'); - -Once loaded you'll add the calendar script to the of your page like this: - - - -The above function will be passed the name of your form. - -Then to show the actual calendar you'll do this: - - -
    - -

    Today

    -
    - - -Note: The first parameter is the name of the field containing your date, the second parameter contains the "now" time, -and the third tells the calendar whether to highlight the current day or not. - -Lastly, you'll need some CSS for your calendar: - -.calendar { - border: 1px #6975A3 solid; - background-color: transparent; -} -.calheading { - background-color: #7C8BC0; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; -} -.calnavleft { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - padding: 4px; - cursor: pointer; -} -.calnavright { - background-color: #7C8BC0; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - font-weight: bold; - color: #fff; - text-align: right; - padding: 4px; - cursor: pointer; -} -.caldayheading { - background-color: #000; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 10px; - text-align: center; - padding: 6px 2px 6px 2px; -} -.caldaycells{ - color: #000; - background-color: #D1D7E6; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #E0E5F1 solid; - cursor: pointer; -} -.caldaycellhover{ - color: #fff; - background-color: #B3BCD4; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - text-align: center; - padding: 4px; - border: 1px #B3BCD4 solid; - cursor: pointer; -} -.caldayselected{ - background-color: #737FAC; - color: #fff; - font-family: Lucida Grande, Verdana, Geneva, Sans-serif; - font-size: 11px; - font-weight: bold; - text-align: center; - border: 1px #566188 solid; - padding: 3px; - cursor: pointer; -} -.calblanktop { - background-color: #fff; - padding: 4px; -} -.calblankbot { - background-color: #fff; - padding: 4px; -} - - -*/ - -function js_calendar_script($form_name = 'entryform') -{ -$CI =& get_instance(); -$CI->load->language('calendar'); -ob_start(); -?> - - - var '.$field_id.' = new calendar("'.$field_id.'", '.$time.', '.(($highlight == TRUE) ? 'true' : 'false').'); - document.write('.$field_id.'.write()); - '; -} - - -/* End of file js_calendar_pi.php */ -/* Location: ./system/plugins/js_calendar_pi.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From fc5c7e5e89d1ac8a84555b8d3971f14533abde03 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 11 Mar 2010 10:29:13 -0600 Subject: added @php4 tag to compat helper (thanks Phil) --- system/helpers/compatibility_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/helpers') diff --git a/system/helpers/compatibility_helper.php b/system/helpers/compatibility_helper.php index e7b21c660..4d7d466f5 100644 --- a/system/helpers/compatibility_helper.php +++ b/system/helpers/compatibility_helper.php @@ -25,6 +25,7 @@ * well with CodeIgniter, so those functions have been refactored. * We cheat a little and use CI's _exception_handler() to output our own PHP errors * so that the behavior fully mimicks the PHP 5 counterparts. -- Derek Jones + * @PHP4 * * @package CodeIgniter * @subpackage Helpers -- cgit v1.2.3-24-g4f1b From 4e8d66aeea7f03b75df5a387a54fce1889834ded Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 15 Mar 2010 12:23:27 -0400 Subject: code comment typo fix --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index d5bdd080c..4afa678a3 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -97,7 +97,7 @@ if ( ! function_exists('ol')) * @param string * @param mixed * @param mixed - * @param intiger + * @param integer * @return string */ if ( ! function_exists('_list')) -- cgit v1.2.3-24-g4f1b From 76b369e191f4432ceba51ba7d7993c4ea54579ae Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Fri, 19 Mar 2010 11:15:28 -0400 Subject: Changed a few strstr to strpos for consistency w performance guidelines and to mirror EE2. --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 638ebaa88..eac024fcb 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -71,7 +71,7 @@ if ( ! function_exists('force_download')) } // Generate the server headers - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) { header('Content-Type: "'.$mime.'"'); header('Content-Disposition: attachment; filename="'.$filename.'"'); -- cgit v1.2.3-24-g4f1b From 726c8eb63eac6f64408536dd39b7854dfa000251 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 12 Mar 2010 11:55:51 +0000 Subject: prep_url() will now not append http:// to string if a protocol is already used. That would really mess up itunes://, spotify://, telnet://, etc. --- system/helpers/url_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 90ea9207e..86caa278c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -446,7 +446,7 @@ if ( ! function_exists('prep_url')) return ''; } - if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') + if (!preg_match('/^[a-z]{3,6}:\/\//', $str)) { $str = 'http://'.$str; } -- cgit v1.2.3-24-g4f1b From d265871dfe205a905cd6c39e8ac4371f13848e58 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 22 Mar 2010 11:05:01 -0500 Subject: expanded philsturgeon's bugfix to parse_url() and updated docs and changelog --- system/helpers/url_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 86caa278c..7707d6854 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -431,7 +431,7 @@ if ( ! function_exists('auto_link')) /** * Prep URL * - * Simply adds the http:// part if missing + * Simply adds the http:// part if no scheme is included * * @access public * @param string the URL @@ -446,7 +446,7 @@ if ( ! function_exists('prep_url')) return ''; } - if (!preg_match('/^[a-z]{3,6}:\/\//', $str)) + if ( ! parse_url($str, PHP_URL_SCHEME)) { $str = 'http://'.$str; } -- cgit v1.2.3-24-g4f1b From a091147feb0331e758b74e7ea13f6ebcb645cd9b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 30 Mar 2010 10:33:09 -0500 Subject: moved entity_decode() to the Security library to handle an issue with HTML in input when the global XSS filter is enabled --- system/helpers/typography_helper.php | 38 +++--------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 712b57509..e45480e1a 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -76,15 +76,6 @@ if ( ! function_exists('auto_typography')) * * This function is a replacement for html_entity_decode() * - * In some versions of PHP the native function does not work - * when UTF-8 is the specified character set, so this gives us - * a work-around. More info here: - * http://bugs.php.net/bug.php?id=25670 - * - * NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the - * character set, and the PHP developers said they were not back porting the - * fix to versions other than PHP 5.x. - * * @access public * @param string * @return string @@ -93,32 +84,9 @@ if ( ! function_exists('entity_decode')) { function entity_decode($str, $charset='UTF-8') { - if (stristr($str, '&') === FALSE) return $str; - - // The reason we are not using html_entity_decode() by itself is because - // while it is not technically correct to leave out the semicolon - // at the end of an entity most browsers will still interpret the entity - // correctly. html_entity_decode() does not convert entities without - // semicolons, so we are left with our own little solution here. Bummer. - - if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>='))) - { - $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str); - return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str); - } - - // Numeric Entities - $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str); - $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str); - - // Literal Entities - Slightly slow so we do another check - if (stristr($str, '&') === FALSE) - { - $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); - } - - return $str; + $CI =& get_instance(); + $CI->load->library('security'); + return $CI->security->entity_decode($str, $charset); } } -- cgit v1.2.3-24-g4f1b From 73c19fc2e15bb542053bc347ee922ceb26114696 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Fri, 9 Apr 2010 11:18:26 -0400 Subject: Modified get_file_info in the file helper, changing filectime() to filemtime() for dates. --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 274c4ad37..448bf275f 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -305,7 +305,7 @@ if ( ! function_exists('get_file_info')) $fileinfo['size'] = filesize($file); break; case 'date': - $fileinfo['date'] = filectime($file); + $fileinfo['date'] = filemtime($file); break; case 'readable': $fileinfo['readable'] = is_readable($file); -- cgit v1.2.3-24-g4f1b From 60e78c75f9cb332dcd5a387bf4262c1566f32b8e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 20 Apr 2010 12:45:14 -0500 Subject: Modifying smiley_js() in the smiley helper to add optional third parameter to return only the javascript with no script tags. --- system/helpers/smiley_helper.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/smiley_helper.php b/system/helpers/smiley_helper.php index 775cc1b99..b9eb0a23e 100644 --- a/system/helpers/smiley_helper.php +++ b/system/helpers/smiley_helper.php @@ -40,7 +40,7 @@ */ if ( ! function_exists('smiley_js')) { - function smiley_js($alias = '', $field_id = '') + function smiley_js($alias = '', $field_id = '', $inline = TRUE) { static $do_setup = TRUE; @@ -108,7 +108,14 @@ EOF; } } - return ''; + if ($inline) + { + return ''; + } + else + { + return $r; + } } } -- cgit v1.2.3-24-g4f1b From a0905f33eabec71e411c837967750e15d6febf19 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 Jul 2010 08:11:33 -0400 Subject: img() will now generate an empty string as an alt attribute if one is not provided. --- system/helpers/html_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 4afa678a3..cd7b4ce6b 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -199,6 +199,12 @@ if ( ! function_exists('img')) $src = array('src' => $src); } + // If there is no alt attribute defined, set it to an empty string + if ( ! isset($src['alt'])) + { + $src['alt'] = ''; + } + $img = '$v) -- cgit v1.2.3-24-g4f1b From 958543a38c2c97b0ec4c10fc9faf4f0753143880 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 22 Jul 2010 14:10:26 -0400 Subject: Adding CSRF into config Adding CSRF token into form open() --- system/helpers/form_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5feb3ce66..632f94505 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -62,6 +62,12 @@ if ( ! function_exists('form_open')) $form .= form_hidden($hidden); } + // CSRF + if ($CI->config->item('csrf_protection') === TRUE) + { + $form .= form_hidden($CI->security->csrf_token_name, $CI->security->csrf_hash); + } + return $form; } } -- cgit v1.2.3-24-g4f1b From 4433f424d7a0dd7e5863ddd5393c13be377ed6ce Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 23 Jul 2010 08:47:34 -0400 Subject: adding sanitize_filename() into the security helper --- system/helpers/security_helper.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/security_helper.php b/system/helpers/security_helper.php index 654cfd100..63f0e9cdb 100644 --- a/system/helpers/security_helper.php +++ b/system/helpers/security_helper.php @@ -44,6 +44,24 @@ if ( ! function_exists('xss_clean')) } } +// ------------------------------------------------------------------------ + +/** + * Sanitize Filename + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('sanitize_filename')) +{ + function sanitize_filename($filename) + { + $CI =& get_instance(); + return $CI->security->sanitize_filename($filename); + } +} + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From cbe3247819be75c34231ea200874044735bd853b Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 5 Aug 2010 14:09:20 -0500 Subject: Adding an ellipsize function to the text helper, and associated documentation to the user guide. --- system/helpers/text_helper.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 477260216..b7ade7a8f 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -495,6 +495,48 @@ if ( ! function_exists('word_wrap')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('ellipsize')) +{ + /** + * Ellipsize String + * + * This function will strip tags from a string, split it at its max_length and ellipsize + * + * @param string string to ellipsize + * @param integer max length of string + * @param mixed int (1|0) or float, .5, .2, etc for position to split + * @param string ellipsis ; Default '...' + * @return string ellipsized string + */ + function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') + { + // Strip tags + $str = trim(strip_tags($str)); + + // Is the string long enough to ellipsize? + if (strlen($str) <= $max_length) + { + return $str; + } + + $beg = substr($str, 0, floor($max_length * $position)); + + $position = ($position > 1) ? 1 : $position; + + if ($position === 1) + { + $end = substr($str, 0, -($max_length - strlen($beg))); + } + else + { + $end = substr($str, -($max_length - strlen($beg))); + } + + return $beg.$ellipsis.$end; + } +} /* End of file text_helper.php */ /* Location: ./system/helpers/text_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0f6b7c1ce0f0122ba162dc579a34a73438d4955a Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 5 Aug 2010 14:11:14 -0500 Subject: moving code comment in text helper --- system/helpers/text_helper.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system/helpers') diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b7ade7a8f..b85e2aaef 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -497,19 +497,19 @@ if ( ! function_exists('word_wrap')) // ------------------------------------------------------------------------ +/** + * Ellipsize String + * + * This function will strip tags from a string, split it at its max_length and ellipsize + * + * @param string string to ellipsize + * @param integer max length of string + * @param mixed int (1|0) or float, .5, .2, etc for position to split + * @param string ellipsis ; Default '...' + * @return string ellipsized string + */ if ( ! function_exists('ellipsize')) { - /** - * Ellipsize String - * - * This function will strip tags from a string, split it at its max_length and ellipsize - * - * @param string string to ellipsize - * @param integer max length of string - * @param mixed int (1|0) or float, .5, .2, etc for position to split - * @param string ellipsis ; Default '...' - * @return string ellipsized string - */ function ellipsize($str, $max_length, $position = 1, $ellipsis = '…') { // Strip tags -- cgit v1.2.3-24-g4f1b From d2167a01ec5bd134a4138b50d76487caa72245c6 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Tue, 14 Sep 2010 15:05:42 -0400 Subject: Fixed a bug in the URL Helper where prep_url() could cause a PHP error on PHP versions < 5.1.2. --- system/helpers/url_helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/helpers') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 7707d6854..dad761145 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -446,7 +446,9 @@ if ( ! function_exists('prep_url')) return ''; } - if ( ! parse_url($str, PHP_URL_SCHEME)) + $url = parse_url($str); + + if ( ! $url OR ! isset($url['scheme'])) { $str = 'http://'.$str; } -- cgit v1.2.3-24-g4f1b From fd2ba8836d74ded06cfe14f728387698c0532148 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 18:45:42 -0500 Subject: Fix #96 html validation failure on csrf hidden input on form_open() in the form helper. Added