. */ ?> xml = "" . $xmlString . ""; $this->xml = str_replace("\t", "", $this->xml); $this->xml = str_replace(" ", " ", $this->xml); $this->document = new DocumentParser($this->xml); $this->modules = $moduleList; $this->FindTags(); } public function GetParsedContent() { $this->ShiftTags(); $this->KillTags(); $remove = array("", ""); return str_replace($remove, "", $this->document->ToString()); } //PRIVATE FUNCTIONS private function FindTags() { $found = true; while($found) { $found = false; $foundItems = array(); foreach($this->modules as $val) { $tagList = &$this->document->GetElementsByTagName(strtolower($val)); if($tagList) { foreach($tagList as $key=>$tagVal) { $foundItems[] = $tagVal->GetTag(); } $this->ProcessTag($val, &$tagList); $found = true; } } } } private function ShiftTags() { if(is_array($this->shift)) { $this->shift = array_unique($this->shift); foreach($this->shift as $key=>$shiftval) { if(is_object($shiftval) && $shiftval->GetStatus() != 'shifted') { $parent = $shiftval->GetParent(); $parent->ReplaceChild($shiftval, $shiftval->GetChildren()); $this->shift[$key]->SetStatus("shifted"); } } } } private function KillTags() { if(is_array($this->kill)) { foreach($this->kill as $key=>$killval) { if(is_object($killval) && $killval->GetStatus() != 'killed') { $parent = $killval->GetParent(); $parent->ReplaceChild($killval, ''); $this->kill[$key]->SetStatus("killed"); } } } } private function &ProcessTag($tag, $tagList) { include_once(MODULES_FOLDER . $tag . '.module.php'); $className = "M" . $tag; foreach($tagList as $key=>$val) { $class = new $className(); $class->ReceiveNode($val); ob_start(); $class->Display(); $displayResult = ob_get_contents(); ob_end_clean(); $action = $class->ModuleAction(); foreach($action as $actkey=>$actval) { switch(strtolower($actkey)) { case 'replace': $placeholder = $this->document->GetElementsByTagName('placeholder'); foreach($placeholder as $plkey=>$plval) { if($plval->GetAttribute('name') == $actval) { //Nothing used replace yet. Code is untested! /*$plval->RemoveChildren(); $tempDoc = new DocumentParser("" . $displayResult . ""); $tempNodes = $tempDoc->GetNodes(); $plval->AppendChildren($tempNodes); $this->kill[] = $plval;*/ } } break; case 'append': //Add the value returned by Display() to the specified placeholder $placeholder = &$this->document->GetElementsByTagName('placeholder'); foreach($placeholder as $plkey=>$plval) { if($plval->GetAttribute('name') == $actval) { /* If the placeholder is the correct one, parse the return through * and then place the children into the active document, including * setting the parent. When the children have been added, mark * the original for deletion */ $tempDoc = new DocumentParser("" . $displayResult . ""); $tempNodes = $tempDoc->GetElementsByTagName('xml'); $tempChildren = $tempNodes[0]->GetChildren(); foreach($tempChildren as $child) { $child->SetParent($plval); } $plval->AppendChildren($tempChildren); $this->shift[] = $plval; } } $val->SetTag('kill'); $val->RemoveChildren(); break; case 'set': $tempDoc = new DocumentParser("" . $displayResult . ""); $tempNodes = $tempDoc->GetElementsByTagName('xml'); if(is_object($tempNodes[0])) { if($tempNodes[0]->HasChildren()) { $tempChildren = $tempNodes[0]->GetChildren(); foreach($tempChildren as $child) { $child->SetParent($val); } } } $val->SetTag('placeholder'); $val->RemoveChildren(); $val->AppendChildren($tempChildren); $this->shift[] = $val; break; default: die("Module Action ($actkey) Not Found ($tag)"); } } } } } ?>