fields = array(); $this->xml = ""; $this->data = ""; $this->symbols = array(); $this->substitutes = array(); $this->has_symbols = false; } function startHandler($xp,$element,$attribs) { $element = strtolower($element); if($this->data != "") { $this->xml .= $this->data; $this->data = ""; } $this->xml .= "<$element"; foreach($attribs as $key=>$value) { $key = strtolower($key); $this->xml .= " $key='$value'"; } $this->xml .= ">"; if($element == "resultset") { $this->xml .= "\n"; foreach($this->params as $key=>$value) { $this->xml .= "<$key>$value\n"; } } } function endHandler($xp,$element) { $element = strtolower($element); if(in_array($element,$this->fields) && $this->has_symbols) { $temp = $this->substitute($this->data); $this->data = $temp; } $this->xml .= $this->data."\n"; $this->data = ""; } function cDataHandler($xp,$data) { $data = trim($data); if($data != "") { //$data = ereg_replace("&","&",$data); //$data = ereg_replace("<","<",$data); //$data = ereg_replace(">",">",$data); $data = utf8_encode($data); $this->data .= $data; } } function get_fields($fields_file) { $fields = array(); if(file_exists($fields_file)) { $in = fopen($fields_file,"r"); while($line = fgets($in)) { $field = trim($line); $fields[] = $field; } } return $fields; } function make_symbols_table($symbols_file) { $this->symbols = array(); if(file_exists($symbols_file)) { $in = fopen($symbols_file,"r"); while($line = fgets($in)) { $vals = explode(" = ",$line); $substitute = trim($vals[1]); if($substitute == "''") { $substitute = ""; } $this->symbols[] = $vals[0]; $this->substitutes[] = $substitute; } } if(count($this->symbols) != 0) $this->has_symbols = true; else $this->has_symbols = false; } function substitute($string) { $string = str_replace($this->symbols,$this->substitutes,$string); return $string; } function process_xml($xml, $params, $fields_file, $symbols_file) { $this->fields = $this->get_fields($fields_file); $this->params = $params; $this->parser = xml_parser_create(); xml_set_object($this->parser,$this); xml_set_element_handler($this->parser,"startHandler","endHandler"); xml_set_character_data_handler($this->parser,"cDataHandler"); $this->make_symbols_table($symbols_file); xml_parse($this->parser,$xml); return $this->xml; } } $macron_symbol = $form_vars["macron_symbol"]; if($macron_symbol == "macron") { $fields_file = "../nahuatl/macron_fields.txt"; $symbols_file = "../nahuatl/macrons.txt"; } else { $fields_file = ""; $symbols_file = ""; } $template_type = $form_vars["template_type"]; if(array_key_exists("username",$_SESSION)) { $username = $_SESSION["username"]; if($username != "") { $params["username"] = $username; } } if(array_key_exists("admin",$_SESSION)) { $admin = $_SESSION["admin"]; $link = $query_object->get_link(); $params["admin"] = $admin; $params["link"] = $link; } $params["template_type"] = $template_type; $stylesheet = $query_object->get_stylesheet(); $npp = new nahuatl_post_processor(); $xml = $query_object->get_xml(); $xml = $npp->process_xml($xml,$params,$fields_file,$symbols_file); $xml = ""."".$xml; header("Content-Type: application/xml"); echo $xml; ?>