diff options
author | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
---|---|---|
committer | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
commit | 269b942a2bf7b022795e591d9b0ad04526ee7e09 (patch) | |
tree | f465bb5a700d4cc5d72ca6e55e251640a46b869b /system/helpers/html_helper.php | |
parent | a25530f6594c7ba45b3faa9537fda9f807069759 (diff) |
added ability to "extend" helpers
* modified Loader to check for prefixed helpers in application/helpers folder
* surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent.
Diffstat (limited to 'system/helpers/html_helper.php')
-rw-r--r-- | system/helpers/html_helper.php | 140 |
1 files changed, 79 insertions, 61 deletions
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index a11d23e15..56e25316c 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -38,9 +38,12 @@ * @param integer
* @return string
*/
-function heading($data = '', $h = '1')
+if (! function_exists('heading'))
{
- return "<h".$h.">".$data."</h".$h.">";
+ function heading($data = '', $h = '1')
+ {
+ return "<h".$h.">".$data."</h".$h.">";
+ }
}
// ------------------------------------------------------------------------
@@ -55,9 +58,12 @@ function heading($data = '', $h = '1') * @param mixed
* @return string
*/
-function ul($list, $attributes = '')
+if (! function_exists('ul'))
{
- return _list('ul', $list, $attributes);
+ function ul($list, $attributes = '')
+ {
+ return _list('ul', $list, $attributes);
+ }
}
// ------------------------------------------------------------------------
@@ -72,9 +78,12 @@ function ul($list, $attributes = '') * @param mixed
* @return string
*/
-function ol($list, $attributes = '')
+if (! function_exists('ol'))
{
- return _list('ol', $list, $attributes);
+ function ol($list, $attributes = '')
+ {
+ return _list('ol', $list, $attributes);
+ }
}
// ------------------------------------------------------------------------
@@ -91,63 +100,66 @@ function ol($list, $attributes = '') * @param intiger
* @return string
*/
-function _list($type = 'ul', $list, $attributes = '', $depth = 0)
+if (! function_exists('_list'))
{
- // If an array wasn't submitted there's nothing to do...
- if ( ! is_array($list))
+ function _list($type = 'ul', $list, $attributes = '', $depth = 0)
{
- return $list;
- }
+ // If an array wasn't submitted there's nothing to do...
+ if ( ! is_array($list))
+ {
+ return $list;
+ }
- // Set the indentation based on the depth
- $out = str_repeat(" ", $depth);
+ // Set the indentation based on the depth
+ $out = str_repeat(" ", $depth);
- // Were any attributes submitted? If so generate a string
- if (is_array($attributes))
- {
- $atts = '';
- foreach ($attributes as $key => $val)
+ // Were any attributes submitted? If so generate a string
+ if (is_array($attributes))
{
- $atts .= ' ' . $key . '="' . $val . '"';
+ $atts = '';
+ foreach ($attributes as $key => $val)
+ {
+ $atts .= ' ' . $key . '="' . $val . '"';
+ }
+ $attributes = $atts;
}
- $attributes = $atts;
- }
- // Write the opening list tag
- $out .= "<".$type.$attributes.">\n";
+ // Write the opening list tag
+ $out .= "<".$type.$attributes.">\n";
- // Cycle through the list elements. If an array is
- // encountered we will recursively call _list()
+ // Cycle through the list elements. If an array is
+ // encountered we will recursively call _list()
- static $_last_list_item = '';
- foreach ($list as $key => $val)
- {
- $_last_list_item = $key;
+ static $_last_list_item = '';
+ foreach ($list as $key => $val)
+ {
+ $_last_list_item = $key;
- $out .= str_repeat(" ", $depth + 2);
- $out .= "<li>";
-
- if ( ! is_array($val))
- {
- $out .= $val;
- }
- else
- {
- $out .= $_last_list_item."\n";
- $out .= _list($type, $val, '', $depth + 4);
$out .= str_repeat(" ", $depth + 2);
+ $out .= "<li>";
+
+ if ( ! is_array($val))
+ {
+ $out .= $val;
+ }
+ else
+ {
+ $out .= $_last_list_item."\n";
+ $out .= _list($type, $val, '', $depth + 4);
+ $out .= str_repeat(" ", $depth + 2);
+ }
+
+ $out .= "</li>\n";
}
- $out .= "</li>\n";
- }
-
- // Set the indentation for the closing tag
- $out .= str_repeat(" ", $depth);
+ // Set the indentation for the closing tag
+ $out .= str_repeat(" ", $depth);
- // Write the closing list tag
- $out .= "</".$type.">\n";
+ // Write the closing list tag
+ $out .= "</".$type.">\n";
- return $out;
+ return $out;
+ }
}
// ------------------------------------------------------------------------
@@ -159,9 +171,12 @@ function _list($type = 'ul', $list, $attributes = '', $depth = 0) * @param integer
* @return string
*/
-function br($num = 1)
+if (! function_exists('br'))
{
- return str_repeat("<br />", $num);
+ function br($num = 1)
+ {
+ return str_repeat("<br />", $num);
+ }
}
// ------------------------------------------------------------------------
@@ -173,9 +188,12 @@ function br($num = 1) * @param integer
* @return string
*/
-function nbs($num = 1)
+if (! function_exists('nbs'))
{
- return str_repeat(" ", $num);
+ function nbs($num = 1)
+ {
+ return str_repeat(" ", $num);
+ }
}
// ------------------------------------------------------------------------
@@ -187,18 +205,18 @@ function nbs($num = 1) * @param array
* @return string
*/
-function meta($meta = array(), $newline = "\n")
+if (! function_exists('meta'))
{
- $str = '';
- foreach ($meta as $key => $val)
+ function meta($meta = array(), $newline = "\n")
{
- $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
- }
+ $str = '';
+ foreach ($meta as $key => $val)
+ {
+ $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
+ }
- return $str;
+ return $str;
+ }
}
-
-
-
?>
\ No newline at end of file |