From 269b942a2bf7b022795e591d9b0ad04526ee7e09 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 21:00:20 +0000 Subject: added ability to "extend" helpers * modified Loader to check for prefixed helpers in application/helpers folder * surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent. --- system/helpers/html_helper.php | 140 +++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 61 deletions(-) (limited to 'system/helpers/html_helper.php') 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 -- cgit v1.2.3-24-g4f1b