[evolvis-commits] r17727: there's a lot more to chang to use html_e*() functions, this is a start

mirabilos at evolvis.org mirabilos at evolvis.org
Fri Nov 25 17:37:46 CET 2011


Author: mirabilos
Date: 2011-11-25 17:37:46 +0100 (Fri, 25 Nov 2011)
New Revision: 17727

Modified:
   trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php
Log:
there's a lot more to chang to use html_e*() functions, this is a start

just as an example

also ignore only false values and empty array values in $attrs,
not empty-string values (like <img alt="" /> uses)


Modified: trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php	2011-11-25 16:20:34 UTC (rev 17726)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php	2011-11-25 16:37:46 UTC (rev 17727)
@@ -87,7 +87,12 @@
  * @param		int		The width of the image
  */
 function html_blankimage($height,$width) {
-	return '<img src="/images/blank.png" width="' . $width . '" height="' . $height . '" alt="" />';
+	return html_e('img', array(
+		'src' => '/images/blank.png',
+		'width' => $width,
+		'height' => $height,
+		'alt' => "",
+	    ));
 }
 
 /**
@@ -99,22 +104,16 @@
  * @param		array	Any <img> tag parameters (i.e. 'border', 'alt', etc...)
  */
 function html_abs_image($url, $width, $height, $args) {
-	$return = ('<img src="' . $url . '"');
-	reset($args);
-	while(list($k,$v) = each($args)) {
-		$return .= ' '.$k.'="'.$v.'"';
+	$args['src'] = $url;
+	// Add image dimensions (if given)
+	if ($width) {
+		$args['width'] = $width;
 	}
-
-	if (!isset($args['alt'])) {
-		$return .= ' alt=""';
+	if ($height) {
+		$args['height'] = $height;
 	}
 
-	// Add image dimensions (if given)
-	$return .= $width ?" width=\"" . $width . "\"": '';
-	$return .= $height? " height=\"" . $height . "\"": '';
-
-	$return .= (' />');
-	return $return;
+	return html_e('img', $args);
 }
 
 /**
@@ -631,9 +630,12 @@
  *	@return html code for checkbox control
  */
 function html_build_checkbox($name, $value, $checked) {
-	return '<input type="checkbox" name="'.$name.'"'
-		.' value="'.$value.'"'
-		.($checked ? 'checked="checked"' : '').'>';
+	return html_e('input', array(
+		'type' => 'checkbox',
+		'name' => $name,
+		'value' => $value,
+		'checked' => ($checked ? 'checked' : false),
+	    ));
 }
 
 
@@ -892,17 +894,19 @@
  *			element name
  * @param	array	$attrs
  *		(optional) associative array of element attributes
- *			empty values are ignored; arrays space-imploded
+ *			values: arrays are space-imploded;
+ *			    false values and empty arrays ignored
  * @return	string
  *		XHTML string suitable for echo'ing
  */
 function html_eo($name, $attrs=array()) {
 	$rv = '<' . $name;
 	foreach ($attrs as $key => $value) {
-		if (!$value) {
+		if (is_array($value)) {
+			$value = count($value) ? implode(" ", $value) : false;
+		}
+		if ($value === false) {
 			continue;
-		} else if (is_array($value)) {
-			$value = implode(" ", $value);
 		}
 		$rv .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
 	}
@@ -917,7 +921,8 @@
  *			element name
  * @param	array	$attrs
  *		(optional) associative array of element attributes
- *			empty values are ignored; arrays space-imploded
+ *			values: arrays are space-imploded;
+ *			    false values and empty arrays ignored
  * @param	string	$content
  *		(optional) XHTML to be placed inside
  * @param	bool	$shortform
@@ -929,10 +934,11 @@
 function html_e($name, $attrs=array(), $content="", $shortform=true) {
 	$rv = '<' . $name;
 	foreach ($attrs as $key => $value) {
-		if (!$value) {
+		if (is_array($value)) {
+			$value = count($value) ? implode(" ", $value) : false;
+		}
+		if ($value === false) {
 			continue;
-		} else if (is_array($value)) {
-			$value = implode(" ", $value);
 		}
 		$rv .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
 	}
@@ -968,6 +974,8 @@
  *			element name
  * @param	array	$attrs
  *		(optional) associative array of element attributes
+ *			values: arrays are space-imploded;
+ *			    false values and empty arrays ignored
  * @return	string
  *		XHTML string suitable for echo'ing
  */



More information about the evolvis-commits mailing list