adaniel Thu Mar 29 21:32:21 2001 EDT
Modified files:
/php4/pear/HTML Common.php
Log:
added a few methods to manipulate attributes
Index: php4/pear/HTML/Common.php
diff -u php4/pear/HTML/Common.php:1.7 php4/pear/HTML/Common.php:1.8
--- php4/pear/HTML/Common.php:1.7 Sat Mar 24 13:08:59 2001
+++ php4/pear/HTML/Common.php Thu Mar 29 21:32:21 2001
@@ -16,13 +16,13 @@
// | Authors: Adam Daniel <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: Common.php,v 1.7 2001/03/24 21:08:59 adaniel Exp $
+// $Id: Common.php,v 1.8 2001/03/30 05:32:21 adaniel Exp $
/**
* Base class for all HTML classes
*
* @author Adam Daniel <[EMAIL PROTECTED]>
- * @version 1.4
+ * @version 1.5
* @since PHP 4.0.3pl1
* @abstract
*/
@@ -45,7 +45,7 @@
/**
* HTML comment on the object
* @var string
- * @since 1.4
+ * @since 1.5
* @access private
*/
var $_comment = "";
@@ -136,6 +136,31 @@
} // end func _parseAttributes
/**
+ * Returns the array key for the given non-name-value pair attribute
+ *
+ * @param string $attr Attribute
+ * @param array $attributes Array of attribute
+ * @since 1.0
+ * @access public
+ * @return void
+ * @throws
+ */
+ function _getAttrKey($attr, $attributes)
+ {
+ if (is_array($attributes)) {
+ $keys = array_keys($attributes);
+ for ($counter=0; $counter < count($keys); $counter++) {
+ $key = $keys[$counter];
+ $value = $attributes[$key];
+ if (strtoupper($value) == strtoupper($attr) && is_int($key)) {
+ return $key;
+ break;
+ }
+ }
+ }
+ } //end func _getAttrKey
+
+ /**
* Updates the attributes in $attr1 with the values in $attr2 without changing
the other existing attributes
* @param array $attr1 Original attributes array
* @param array $attr2 New attributes array
@@ -151,15 +176,7 @@
if (!is_int($key)) {
$attr1[$key] = $value;
} else {
- $key = null;
- if (is_array($attr1)) {
- while (list($currKey, $currValue) = each($attr1)) {
- if ($currValue == $value) {
- $key = $currKey;
- break;
- }
- }
- }
+ $key = $this->_getAttrKey($value, $attr1);
if (isset($key)) {
$attr1[$key] = $value;
} else {
@@ -172,6 +189,48 @@
}
}
} // end func _updateAtrrArray
+
+ /**
+ * Removes the given attribute from the given array
+ *
+ * @param string $attr Attribute name
+ * @param array $attributes Attribute array
+ * @since 1.4
+ * @access public
+ * @return void
+ * @throws
+ */
+ function _removeAttr($attr, &$attributes)
+ {
+ if (in_array(strtolower($attr), array_keys($attributes))) {
+ unset($attributes[$attr]);
+ } else {
+ unset($attributes[$this->_getAttrKey($attr, $attributes)]);
+ }
+ } //end func _removeAttr
+
+ /**
+ * Returns the value of the given attribute
+ *
+ * @param string $attr Attribute name
+ * @since 1.5
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getAttribute($attr)
+ {
+ if (is_array($this->_attributes)) {
+ while (list($key, $value) = each($this->_attributes)) {
+ if (is_int($key) && strtoupper($value) == strtoupper($attr)) {
+ return true;
+ } elseif (strtolower($key) == strtolower($attr)){
+ return $value;
+ }
+ }
+ }
+ return false;
+ } //end func getAttribute
/**
* Sets the HTML attributes
@@ -195,6 +254,20 @@
} // end func updateAttributes
/**
+ * Removes an attribute from
+ *
+ * @param string $attr Attribute name
+ * @since 1.4
+ * @access public
+ * @return void
+ * @throws
+ */
+ function removeAttribute($attr)
+ {
+ $this->_removeAttr($atttr, $this->_attributes);
+ } //end func removeAttribute
+
+ /**
* Sets the tab offset
* @param int $offset
* @access public
@@ -205,6 +278,19 @@
} // end func setTabOffset
/**
+ * Returns the tabOffset
+ *
+ * @since 1.5
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getTabOffset()
+ {
+ return $this->_tabOffset;
+ } //end func getTabOffset
+
+ /**
* Sets the HTML comment to be displayed at the beginning of the HTML string
*
* @param string
@@ -217,6 +303,19 @@
{
$this->_comment = $comment;
} // end func setHtmlComment
+
+ /**
+ * Returns the HTML comment
+ *
+ * @since 1.5
+ * @access public
+ * @return void
+ * @throws
+ */
+ function getComment()
+ {
+ return $this->_comment;
+ } //end func getComment
/**
* Abstract method. Must be extended to return the objects HTML
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]