/*newsboy : news system for the web written in php by justin grant (web: jusgrant.cjb.net or justin.host.za.net mail: [email protected])25 march v0.0.2 converted newsboy to a php class, allowing the layout to be easily modified. also added made the html that is genrated a little easier to read.24 march v0.0.1 just completed the intial version, very rough and basic.*/ class newsboy { var $xml_parser; var $xml_file; var $html; var $open_tag ; var $close_tag ; //class constructor function newsboy() { $this->xml_parser = ""; $this->xml_file = ""; $this->html = ""; $this->open_tag = array( //these are the default settings but they are quite easy to modify "newsboy" => "nn", "story" => " ", "date" => "", "slug" => " ", "text" => "", "pic" => "", "newline" => "" ); $this->close_tag = array( "newsboy" => " nnn", "story" => "", "date" => "", "slug" => " ", "text" => "n", "pic" => " " " ); } //class destructor (has to be invoked manually as php does not support destructors)
function destroy() { xml_parser_free($this->xml_parser); } //class members function concat($str) { $this->html .= $str; } function startelement($parser, $name, $attrs) { //global $open_tag; if ($format= $this->open_tag[$name]) { $this->html .= $format; } } function endelement($parser, $name) { global $close_tag; if ($format= $this->close_tag[$name]) { $this->html .= $format; } } function characterdata($parser, $data) { $this->html .= $data; } /* function pihandler($parser, $target, $data) { //switch (strtolower($target)){ // case "php": eval($data); // break; //} }*/ function parse() { $this->xml_parser = xml_parser_create(); xml_set_object($this->xml_parser, &$this); // use case-folding so we are sure to find the tag in $map_array xml_parser_set_option($this->xml_parser, xml_option_case_folding, true); xml_set_element_handler($this->xml_parser, "startelement", "endelement"); xml_set_character_data_handler($this->xml_parser, "characterdata");//xml_set_processing_instruction_handler($this->xml_parser, "pihandler"); if (!($fp = fopen($this->xml_file, "r"))) { die("could not open xml input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($this->xml_parser, $data, feof($fp))) { die(sprintf("xml error: %s at line %d", xml_error_string(xml_get_error_code($this->xml_parser)), xml_get_current_line_number($this->xml_parser))); } } }} ?>