. */ ?> status = 'alive'; } /*========SET FUNCTIONS======*/ public function SetParent($nodeItem) { $this->parentNode = $nodeItem; } public function SetAttributes($array) { if(is_array($array)) { $this->attributes = $array; } } public function SetAttribute($name, $value) { $this->attributes[$name] = $value; } public function SetIdentifier($microtime) { $this->identifier = $microtime; } public function SetTag($name) { $this->name = $name; } public function SetContent($content) { $this->content = $content; } public function SetStatus($status) { $this->status = $status; } /*========END SET FUNCTIONS======*/ /*========GET FUNCTIONS======*/ public function GetAttributes() { if(is_array($this->attributes)) { return $this->attributes; } else { return false; } } public function GetAttribute($attributeName) { if(is_array($this->attributes) && $this->attributes[$attributeName] && !empty($this->attributes)) { return $this->attributes[$attributeName]; } else { return false; } } public function GetTag() { if($this->name) { return $this->name; } else return false; } public function GetChildren() { if(is_array($this->children)) { return $this->children; } else { return false; } } public function GetFirstChild() { if(is_array($this->children)) { return $this->children[0]; } else { return false; } } public function GetLastChild() { if(is_array($this->children)) { return $this->children[count($this->children) - 1]; } else { return false; } } public function GetContent() { if($this->content) { return $this->content; } else if(count($this->children) == 1 && $this->children[0]->GetTag() == 'text') { //If a node only contains one node and it has content, return $this->children[0]->GetContent(); } else { return false; } } public function GetParent() { if($this->parentNode) { return $this->parentNode; } } public function GetStatus() { return $this->status; } /*========END GET FUNCTIONS======*/ /*========BOOLEAN FUNCTIONS======*/ public function HasChildren() { if(is_array($this->children) && !empty($this->children)) { return true; } else { return false; } } public function HasAttributes() { if(is_array($this->attributes) && !empty($this->attributes)) { return true; } else { return false; } } public function HasAttribute($attribute) { if($this->HasAttributes() && isset($this->$attributes[$attribute])) { return true; } else { return false; } } public function HasContent() { if(strlen($this->GetContent()) > 0) { return true; } else { return false; } } /*======END BOOLEAN FUNCTIONS=======*/ /*========DESTRUCTIVE FUNCTIONS========*/ public function &Replace($array) { $this->attributes = $array->GetAttributes(); $this->name = $array->GetTag(); $this->children = $array->GetChildren(); $this->content = $array->GetContent(); } public function RemoveChildren() { $this->children = array(); } public function ReplaceChild($child, $nodes) { $found = false; $count = 0; $beforeChild = array(); $afterChild = array(); $newChildren = array(); if($this->children) { foreach($this->children as $key=>$val) { if($val == $child) { $found = true; } else if(!$found) { $beforeChild[] = $val; } else { $afterChild[] = $val; } } if($beforeChild && is_array($beforeChild)) { foreach($beforeChild as $key=>$val) { $newChildren[] = $val; } } if(is_array($nodes) && !empty($nodes)) { foreach($nodes as $key=>$val) { $newChildren[] = $val; } } else if($nodes && $nodes != '') { $newChildren[] = $nodes; } else if(is_null($nodes)){ //Why is it null? No fucking clue. } if(!empty($afterChild) && is_array($afterChild)) { foreach($afterChild as $key=>$val) { $newChildren[] = $val; } } $this->children = $newChildren; } else { if($nodes != '') { $this->AppendChildren($nodes); } } } /*========END DESTRUCTIVE FUNCTIONS========*/ /*========OTHER FUNCTIONS===========*/ public function ToString() { $string = ''; if($this->name && $this->name != 'text') { $string .= "<" . $this->name; if($this->attributes) { foreach($this->attributes as $key=>$val) { $string .= ' ' . $key . "=" . '"' . str_replace('"', "\"", $val) . '"'; } } if(!empty($this->children)) { $string .= ">"; foreach($this->children as $child) { $string .= $child->ToString(); } } else { $string .= " />"; } } else { $string .= $this->content; } if(!empty($this->children)&& $this->name != 'text') { $string .= "name . ">"; } return $string; } public function &AppendChildren($array) { $index = count($this->children); if($array) foreach($array as $key=>$val) { $this->children[$index] = $val; $index++; } else die($array); } /*========END OTHER FUNCTIONS==========*/ } ?>