collapse_dups = $collapse_dups; $this->index_numeric = $index_numeric; $this->data = ''; if ($data_source_type == 'raw') $this->data = $data_source; elseif ($data_source_type == 'stream') { while (!feof($data_source)) $this->data .= fread($data_source, 1000); // try filename, then if that fails... } elseif (file_exists($data_source)) $this->data = implode('', file($data_source)); // try url else { $fp = fopen($data_source,'r'); while (!feof($fp)) $this->data .= fread($fp, 1000); fclose($fp); } } // Parse the XML file into a verbose, flat array struct. // Then, coerce that into a simple nested array. function getTree() { $parser = xml_parser_create('ISO-8859-1'); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $this->data, $vals, $index); xml_parser_free($parser); $i = -1; return $this->getchildren($vals, $i); } // internal function: build a node of the tree function buildtag($thisvals, $vals, &$i, $type) { if (isset($thisvals['attributes'])) $tag['ATTRIBUTES'] = $thisvals['attributes']; // complete tag, just return it for storage in array if ($type === 'complete') @$tag['VALUE'] = $thisvals['value']; // open tag, recurse else { if(!is_array($tag)) $tag['VALUE'] = $thisvals['value']; $tag = array_merge($tag, $this->getchildren($vals, $i)); } return $tag; } // internal function: build an nested array representing children function getchildren($vals, &$i) { $children = array(); // Contains node data // Node has CDATA before it's children if ($i > -1 && isset($vals[$i]['value'])) $children['VALUE'] = $vals[$i]['value']; // Loop through children, until hit close tag or run out of tags while (++$i < count($vals)) { $type = $vals[$i]['type']; // 'cdata': Node has CDATA after one of it's children // (Add to cdata found before in this case) if ($type === 'cdata') $children['VALUE'] .= $vals[$i]['value']; // 'complete': At end of current branch // 'open': Node has children, recurse elseif ($type === 'complete' || $type === 'open') { $tag = $this->buildtag($vals[$i], $vals, $i, $type); if ($this->index_numeric) { $tag['TAG'] = $vals[$i]['tag']; $children[] = $tag; } else $children[$vals[$i]['tag']][] = $tag; } // 'close: End of node, return collected data // Do not increment $i or nodes disappear! elseif ($type === 'close') break; } if ($this->collapse_dups) foreach($children as $key => $value) if (is_array($value) && (count($value) == 1)) $children[$key] = $value[0]; return $children; } } ?> $v){ $this->XML .= $this->setNode($k, $v); } } function setNode($k, $v){ if(is_array($v) && array_key_exists(0,$v)){ foreach($v as $k1 => $v1){ $xml .= $this->setNode($k, $v1); } } else { $xml = ""; $xml .= "<".$k; $xml .= $this->getAttributes($v); $xml .= ">"; $xml .= $this->getChildren($v); $xml .= ""; } return $xml; } function getAttributes($v){ $xml = ""; if(is_array($v) && array_key_exists('ATTRIBUTES',$v)){ foreach($v['ATTRIBUTES'] as $k1 => $v1){ $xml .= ' '.$k1.'="'.$v1.'"'; } } return $xml; } function getChildren($v){ $xml = ""; if(is_array($v)){ foreach($v as $k1 => $v1){ if($k1 != "ATTRIBUTES" && $k1 != "VALUE"){ $xml .= $this->setNode($k1, $v1); } else if ($k1 == "VALUE"){ $xml .= $v1; } } } else { $xml .= $v; } return $xml; } function getXML(){ return $this->XML; } } ?> ","<","","",""); $healthy = array(">","<","©","™","®"); $variable = str_replace($not_healthy,$healthy,$variable); } else if($isnt_html == "Store") { $variable = str_replace("'","''",$variable); } return $variable; } function sanatizeentry($value, $is_html = false){ if(!$is_html){ $noaccept = array ("<",">","\r","\n","[\]r","[\]n","%0A","x0A","%0D","%20","x20","content-type:","charset=","mime-version:","multipart/mixed","bcc:","to:","from:","bc:","cc:","reply-to:"); $replace = array(" "," ","","","","","","","","","","content","character set","version","mixed","carbon copy","to","from","carbon copy","carbon copy","reply to"); } else { $noaccept = array ("\r","\n","[\]r","[\]n","%0A","x0A","%0D","%20","x20","content-type:","charset=","mime-version:","multipart/mixed","bcc:","to:","from:","bc:","cc:","reply-to:"); $replace = array("","","","","","","","","","content","character set","version","mixed","carbon copy","to","from","carbon copy","carbon copy","reply to"); } foreach($noaccept as $k => $v){ do{ $temp = strtolower($value); $pos = strpos($temp,$v); if($pos !== false){ $value = substr($value,0,$pos).$replace[$k].substr($value,($pos+strlen($noaccept[$k]))); } } while ($pos !== false); } return $value; } ?>