''
,'bln_endtag' => '1'
,'attributes' => array()
,'contents' => array()
);
function cls_htmlbase($in_props) {
while (list($key, $value) = each($this->defaults)) {
$this->props[$key] = $value;
}
while (list($key, $value) = each($in_props)) {
$this->props[$key] = $value;
}
// Get a copy of the attributes array. At this point, it
// is empty. But 'proper coding' requires us to copy it
// instead of using array() so that future changes won't
// be able to break this code.
$attributes = $this->props['attributes'];
// Reset the input properties array. it was used
// above to set class properties.
reset($in_props);
// Iterate over the input array, looking for
// valid attributes, when one is found save it
// into the copy of the attributes property.
while (list($key, $value) = each($in_props)) {
if ($this->validate_attribute_name($key)) {
$attributes[$key] = $value;
}
}
// Copy the attributes array back into the class
// property.
$this->props['attributes'] = $attributes;
}
function validate_attribute_name($name) {
$attributes = $this->valid_attributes;
if (is_array($attributes)) {
while (list($key, $value) = each($attributes)) {
if (preg_match("/^$value$/i", $name)) {
return(1);
}
}
}
return(0);
}
// Here is the uniquely named function.
// Only the name has changed, it's code
// remains the same.
function htmlbase_generate() {
$tag_name = $this->props['tag_name'];
$buffer = "<$tag_name";
// add attributes, if any, to the start tag.
$attributes = $this->props['attributes'];
while (list($key, $value) = each($attributes)) {
$buffer .= " $key=\"$value\"";
}
$buffer .= ">";
// add contained elements to buffer.
$contents = $this->props['contents'];
while (list($key, $value) = each($contents)) {
$buffer .= $value->generate();
}
if ($this->props['bln_endtag'] == '1') {
$buffer .= "$tag_name>";
}
return($buffer);
}
// This is the function that gets overridden
// by child classes. Its only job is to call
// the uniquely-named function.
function generate() {
return($this->htmlbase_generate());
}
function add($element) {
$contents = $this->props['contents'];
$contents[count($contents)] = $element;
$this->props['contents'] = $contents;
}
}
?>