"strong", "i" => "em"); var $allowedOpenTags = array("div", "p", "address", "strong", "em", "h4", "h5", "h6", "ul", "ol", "li"); var $allowedSingleTags = array("br", "img"); var $allowedOpenAttribTags = array("a", "img", "h3"); var $attributes = array( "a" => array("href", "title"), "img" => array("src", "alt"), "h3" => array("id")); var $allowedCloseTags = array("a", "div", "p", "address", "strong", "em", "h3", "h4", "h5", "h6", "ul", "ol", "li"); var $newLineTags = array("br", "div", "p", "address", "h3", "h4", "h5", "h6", "ul", "ol", "li"); function Parser() { $this->xmlParser = xml_parser_create(); xml_set_element_handler($this->xmlParser, array(&$this, "startElement"), array(&$this, "endElement")); xml_set_character_data_handler($this->xmlParser, array(&$this, "characterData")); $this->depth = array(); $this->deep = 0; foreach(array_merge($this->allowedOpenTags, $this->allowedOpenAttribTags) as $tag) { $this->depth[$tag] = 0; } } function startElement($parser, $name, $attrs) { global $temp; $tag = strtolower($name); if(array_key_exists($tag, $this->mappedTags)) $tag = $this->mappedTags[$tag]; if(in_array($tag, $this->allowedOpenTags)) { if($this->depth[$tag] == 0) $temp .= "<" . $tag . ">"; $this->depth[$tag]++; } elseif(in_array($tag, $this->allowedOpenAttribTags)) { if($this->depth[$tag] == 0) { $temp .= "<" . $tag; foreach($this->attributes[$tag] as $attrib) { if(isset($attrs[$attrib])) $temp .= " " . strtolower($attrib) . "=\"" . $attrs[$attrib] . "\""; if(isset($attrs[strtoupper($attrib)])) $temp .= " " . strtolower($attrib) . "=\"" . $attrs[strtoupper($attrib)] . "\""; } if($tag == "img") { $src = $attrs["SRC"]; if(strpos($src, "http") === false) $src = "http://" . $_SERVER['SERVER_NAME'] . $src; if(($gis = @getimagesize($src)) !== false) { list($width, $height, $type, $attr) = $gis; $temp .= " " . $attr; } } if(in_array($tag, $this->allowedSingleTags)) $temp .= " />"; else $temp .= ">"; } $this->depth[$tag]++; } elseif(in_array($tag, $this->allowedSingleTags)) { $temp .= "<" . $tag . " />"; } elseif($this->deep > 0) { $temp .= "<" . $tag; foreach($attrs as $key => $attrib) { @$temp .= " " . strtolower($key) . "="" . $attrib . """; } $temp .= ">"; } $this->deep++; } function endElement($parser, $name) { global $temp; $this->deep--; $tag = strtolower($name); if(array_key_exists($tag, $this->mappedTags)) $tag = $this->mappedTags[$tag]; if(in_array($tag, $this->allowedSingleTags)) { /* do nothing */ } elseif(in_array($tag, $this->allowedCloseTags)) { $this->depth[$tag]--; if($this->depth[$tag] == 0) $temp .= ""; } elseif($this->deep > 0) { $temp .= "</" . $tag . ">"; } if(in_array($tag, $this->newLineTags)) { $temp .= "\n"; } } function characterData($parser, $data) { global $temp; if(($this->deep == 1) && (trim($data) != "") && $this->pEnvelope) $temp .= "

" . $this->applySlashes(htmlspecialchars($data)) . "

"; else $temp .= $this->applySlashes(htmlspecialchars($data)); } var $trans = array("'" => "\'", "\r" => "", "\n" => " ", "\t" => " ", " " => " ", " " => " "); function applySlashes($str) { $newlength = strlen($str); do { $oldlength = $newlength; $str = stripslashes($str); $newlength = strlen($str); } while($oldlength != $newlength); return strtr($str, $this->trans); } function parse($string, $env = true) { global $temp; $tmp = $temp; $temp = ""; $this->pEnvelope = $env; if (!xml_parse($this->xmlParser, "" . $string . "", true)) { $temp = $string; $this->parsedText = $temp; return false; } $this->parsedText = $temp; $temp = $tmp; return true; } function free() { xml_parser_free($this->xmlParser); } function getText() { return $this->parsedText; } } ?>