From: hickert Date: Mon, 14 Nov 2005 10:20:40 +0000 (+0000) Subject: Added xmlParse class X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=95ae404d6f3660ac0e5513a3fd0b5d2678702117;p=gosa.git Added xmlParse class git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1935 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_xmlParse.inc b/include/class_xmlParse.inc new file mode 100644 index 000000000..42bfc3c69 --- /dev/null +++ b/include/class_xmlParse.inc @@ -0,0 +1,146 @@ +parser = xml_parser_create(); + xml_set_object($this->parser, $this); + xml_set_element_handler($this->parser, "tag_open", "tag_close"); + } + + function parseMenu($file) + { + if (!($fp = @fopen($file, "r"))) { + print_red(sprintf(_("could not open XML input '%s'."),$file)); + $this->data = array(); + return(false); + } + + $data = fread($fp, filesize($file)); + + $t = split("\n",$data); + $s = preg_replace("//","",$data.""); + $data = $t[0]."\n".$s; + + fclose($fp); + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 1); + xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 0); + xml_parse_into_struct($this->parser, $data, $vals, $index); + + $params = array(); + $level = array(); + + $this->data = array(); + $i = 0 ; + $current =""; + $dir = ""; + foreach($vals as $ele){ + if($ele['tag'] =="INPUT") continue; + if($ele['tag'] =="INCLUDE") continue; + if($ele['type'] == "open"){ + $tag = $ele['tag'].$i; + + if($ele['tag'] != "MENU"){ + $i++; + $this->currentPos ++ ; + $this->depth[$this->currentPos] = $tag; + } + $current = &$this->data; + foreach($this->depth as $name){ + $current = &$current[$name]; + } + }elseif($ele['type']=="close"){ + unset($this->depth[($this->currentPos)]); + $this->currentPos --; + if($ele['tag'] == "MENU") + $dir =""; + } + if($ele['tag'] == "CATEGORY"){ + $current[$dir]['name'] = $ele['value']; + } + if(isset($current['type'])){ + unset($current['type']); + } + if($ele['tag'] == "DIRECTORY"){ + $dir .= preg_replace("/\.directory/","",$ele['value'])."/"; +// $path= $ele['value']; +// $current[$dir]['path'] = $path; + } + if($ele['tag'] == "CATEGORY"){ + $current[$dir] = $ele['value']; + } + $curback = $current; + } + } + + + function parse($filename) + { + if(!file_exists($filename)){ + return(false); + }else{ + $fh= fopen($filename, "r"); + $xmldata= fread($fh, 100000); + fclose($fh); + if(!xml_parse($this->parser, chop($xmldata))){ + print(sprintf(_("XML error in %s : %s at line %d"),$filename, + xml_error_string(xml_get_error_code($this->parser)), + xml_get_current_line_number($this->parser))); + } + } + return(true); + } + + function tag_open($parser, $tag, $attrs) + { + $this->currentPos ++ ; + $this->depth[$this->currentPos] = $tag; + + $current = &$this->data; + foreach($this->depth as $name){ + $current = &$current[$name]; + } + $current = $attrs; + } + + function tag_close($parser, $tag) + { + unset($this->depth[($this->currentPos)]); + $this->currentPos --; + } + + function GetData() + { + return ($this->data); + } + +} +?>