summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Barnes <eric@ericlbarnes.com>2012-07-29 06:18:07 +0200
committerEric Barnes <eric@ericlbarnes.com>2012-07-29 06:18:07 +0200
commit19204f96b8abc1322feb0f660240ed7abb69026b (patch)
tree7c47e4e125080ea4942c3eb61c9cde6b89b0ce46
parentacedd2b1a37b22cb04b01038f21876ddfe38b83a (diff)
Refactored _stringify_attributes function
Signed-off-by: Eric Barnes <eric@ericlbarnes.com>
-rw-r--r--system/core/Common.php46
1 files changed, 22 insertions, 24 deletions
diff --git a/system/core/Common.php b/system/core/Common.php
index d4d01f813..7c46c590a 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -603,47 +603,45 @@ if ( ! function_exists('html_escape'))
if ( ! function_exists('_stringify_attributes'))
{
/**
- * Attributes To String
+ * Stringify attributes for use in html tags.
*
- * Helper function used to convert an array or object of
+ * Helper function used to convert a string, array, or object of
* attributes to a string
*
- * @param mixed
+ * @param mixed string, array, object
+ * @param bool
* @return string
*/
function _stringify_attributes($attributes, $js = FALSE)
{
- if (is_object($attributes) && count($attributes) > 0)
+ if (is_string($attributes))
+ {
+ return strlen($attributes) > 0 ? ' '.$attributes : $attributes;
+ }
+
+ if (is_object($attributes))
{
$attributes = (array) $attributes;
}
- if (is_array($attributes))
+ if (count($attributes) === 0)
+ {
+ return;
+ }
+
+ $atts = '';
+ foreach ($attributes as $key => $val)
{
- $atts = '';
- if (count($attributes) === 0)
+ if ($js)
{
- return $atts;
+ $atts .= $key.'='.$val.',';
}
- foreach ($attributes as $key => $val)
+ else
{
- if ($js)
- {
- $atts .= $key.'='.$val.',';
- }
- else
- {
- $atts .= ' '.$key.'="'.$val.'"';
- }
+ $atts .= ' '.$key.'="'.$val.'"';
}
- return rtrim($atts, ',');
- }
- elseif (is_string($attributes) && strlen($attributes) > 0)
- {
- return ' '.$attributes;
}
-
- return $attributes;
+ return rtrim($atts, ',');
}
}