Documentation is available at core.php
- <?
- class tree
- {
- var $children;
- function tree($children=array())
- {
- $this->children=$children;
- }
- function &add_child($child,$name="")
- {
- $slot=$name;
- if ($name=="") $slot=empty_slot($this->children);
- if ($child!="")
- {
- $this->children[$slot]=$child;
- return $this->children[$slot];
- }
- else return 0;
- }
- function remove_child($child)
- {
- $temp=array_intersect($this->children,array($child));
- $id=key($temp);
- unset($this->children[$id[0]]);
- }
- function set_child($id,$value)
- {
- $this->children[$id]=$value;
- }
- function &get_child($id)
- {
- return $this->children[$id];
- }
- function child_count()
- {
- return count($this->children);
- }
- function render()
- {
- $output="";
- foreach ($this->children as $child)
- {
- if (is_object($child)) $output.=$child->render();
- else $output.=$child;
- }
- return $output;
- }
- }
- class text extends tree
- {
- var $content;
- function text($content)
- {
- $this->tree();
- $this->content=&$this->add_child($content);
- }
- }
- class xml_comment extends tree
- {
- function render()
- {
- $output="";
- $output.="<!-- ";
- $output.=tree::render();
- $output.=" -->";
- return $output;
- }
- }
- class xml_element extends tree
- {
- var $attribs;
- var $tag;
- function xml_element($tag,$attribs=array())
- {
- $this->tree();
- $this->tag=$tag;
- $this->attribs=$attribs;
- }
- function set_attrib($name,$value)
- {
- $this->attribs[$name]=$value;
- }
- function add_attribs($attribs)
- {
- $this->attribs=array_merge($this->attribs,$attribs);
- }
- function render()
- {
- $output="";
- $tag=$this->tag;
- foreach($this->attribs as $name => $value)
- {
- $attr.=" $name=\"$value\"";
- }
- $temp=tree::render();
- if ($temp=="") $output="<$tag $attr/>\n";
- else $output="<$tag$attr>\n$temp\n</$tag>\n";
- return $output;
- }
- }
- class xml_m_content extends tree
- {
- function xml_m_content($tag)
- {
- $this->tag=$tag;
- $this->tree();
- }
- function add_content($content)
- {
- $t=&$this->add_child(new xml_element($this->tag));
- $t->add_child($content);
- }
- }
Documentation generated on Tue, 24 May 2005 03:57:41 -0400 by phpDocumentor 1.3.0RC3