Adding a common stringify_attributes function for dealing with attributes through out various helpers.

Signed-off-by: Eric Barnes <eric@ericlbarnes.com>
diff --git a/system/core/Common.php b/system/core/Common.php
index 06b1622..d4d01f8 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -598,5 +598,54 @@
 	}
 }
 
+// ------------------------------------------------------------------------
+
+if ( ! function_exists('_stringify_attributes'))
+{
+	/**
+	 * Attributes To String
+	 *
+	 * Helper function used to convert an array or object of
+	 * attributes to a string
+	 *
+	 * @param	mixed
+	 * @return	string
+	 */
+	function _stringify_attributes($attributes, $js = FALSE)
+	{
+		if (is_object($attributes) && count($attributes) > 0)
+		{
+			$attributes = (array) $attributes;
+		}
+
+		if (is_array($attributes))
+		{
+			$atts = '';
+			if (count($attributes) === 0)
+			{
+				return $atts;
+			}
+			foreach ($attributes as $key => $val)
+			{
+				if ($js)
+				{
+					$atts .= $key.'='.$val.',';
+				}
+				else
+				{
+					$atts .= ' '.$key.'="'.$val.'"';
+				}
+			}
+			return rtrim($atts, ',');
+		}
+		elseif (is_string($attributes) && strlen($attributes) > 0)
+		{
+			return ' '.$attributes;
+		}
+
+		return $attributes;
+	}
+}
+
 /* End of file Common.php */
 /* Location: ./system/core/Common.php */
\ No newline at end of file
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index a45b3d7..a792f09 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -575,22 +575,7 @@
 			$menu .= ' class="'.$class.'"';
 		}
 
-		// Generate a string from the attributes submitted, if any
-		if (is_array($attributes))
-		{
-			$atts = '';
-			foreach ($attributes as $key => $val)
-			{
-				$atts .= ' '.$key.'="'.$val.'"';
-			}
-			$attributes = $atts;
-		}
-		elseif (is_string($attributes) && strlen($attributes) > 0)
-		{
-			$attributes = ' '.$attributes;
-		}
-
-		$menu .= $attributes.">\n";
+		$menu .= _stringify_attributes($attributes).">\n";
 
 		foreach (timezones() as $key => $val)
 		{
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 96234bb..9843e80 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -51,7 +51,7 @@
 	 */
 	function heading($data = '', $h = '1', $attributes = '')
 	{
-		return '<h'.$h._html_attributes_to_string($attributes).'>'.$data.'</h'.$h.'>';
+		return '<h'.$h._stringify_attributes($attributes).'>'.$data.'</h'.$h.'>';
 	}
 }
 
@@ -120,7 +120,7 @@
 		$out = str_repeat(' ', $depth);
 
 		// Write the opening list tag
-		$out .= '<'.$type._html_attributes_to_string($attributes).">\n";
+		$out .= '<'.$type._stringify_attributes($attributes).">\n";
 
 		// Cycle through the list elements.  If an array is
 		// encountered we will recursively call _list()
@@ -215,7 +215,7 @@
 			}
 		}
 
-		return $img._html_attributes_to_string($attributes).'/>';
+		return $img._stringify_attributes($attributes).'/>';
 	}
 }
 
@@ -393,40 +393,5 @@
 	}
 }
 
-if ( ! function_exists('_html_attributes_to_string'))
-{
-	/**
-	 * Attributes To String
-	 *
-	 * Helper function used to convert array or object of attributes to a string
-	 *
-	 * @param	mixed
-	 * @param	bool
-	 * @return	string
-	 */
-	function _html_attributes_to_string($attributes)
-	{
-		if (is_object($attributes) && count($attributes) > 0)
-		{
-			$attributes = (array) $attributes;
-		}
-
-		if (is_array($attributes) && count($attributes) > 0)
-		{
-			$atts = '';
-			foreach ($attributes as $key => $val)
-			{
-				$atts .= ' '.$key.'="'.$val.'"';
-			}
-			return $atts;
-		}
-		elseif (is_string($attributes) && strlen($attributes) > 0)
-		{
-			return ' '.$attributes;
-		}
-
-		return $attributes;
-	}
-}
 /* End of file html_helper.php */
 /* Location: ./system/helpers/html_helper.php */
\ No newline at end of file
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 39e6343..57208c9 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -165,7 +165,7 @@
 
 		if ($attributes !== '')
 		{
-			$attributes = _parse_attributes($attributes);
+			$attributes = _stringify_attributes($attributes);
 		}
 
 		return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
@@ -221,10 +221,10 @@
 			unset($attributes[$key]);
 		}
 
-		$attributes = empty($attributes) ? '' : _parse_attributes($attributes);
+		$attributes = _stringify_attributes($attributes);
 
 		return '<a href="'.$site_url
-			.'" onclick="window.open(\''.$site_url."', '".$window_name."', '"._parse_attributes($atts, TRUE)."'); return false;\""
+			.'" onclick="window.open(\''.$site_url."', '".$window_name."', '"._stringify_attributes($atts, TRUE)."'); return false;\""
 			.$attributes.'>'.$title.'</a>';
 	}
 }
@@ -250,7 +250,7 @@
 			$title = $email;
 		}
 
-		return '<a href="mailto:'.$email.'"'._parse_attributes($attributes).'>'.$title.'</a>';
+		return '<a href="mailto:'.$email.'"'._stringify_attributes($attributes).'>'.$title.'</a>';
 	}
 }
 
@@ -560,47 +560,5 @@
 	}
 }
 
-// ------------------------------------------------------------------------
-
-if ( ! function_exists('_parse_attributes'))
-{
-	/**
-	 * Parse out the attributes
-	 *
-	 * Some of the functions use this
-	 *
-	 * @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 && $att !== '')
-		{
-			return substr($att, 0, -1);
-		}
-
-		return $att;
-	}
-}
-
 /* End of file url_helper.php */
 /* Location: ./system/helpers/url_helper.php */
\ No newline at end of file