cache_dir."help/php"; if (!file_exists($this->cache_dir."help")) mkdir($this->cache_dir."help",0755); if (!file_exists($this->cache_dir."help/phpgtk")) mkdir($this->cache_dir."help/phpgtk",0755); if (!file_exists($this->cache_dir."help/phpgtk/{$this->lang}")) mkdir($this->cache_dir."help/phpgtk/{$this->lang}",0755); if (!file_exists($this->cache_dir."help/phpgtk/{$this->lang}/userguide")) mkdir($this->cache_dir."help/phpgtk/{$this->lang}/userguide",0755); if (!file_exists($this->cache_dir."help/phpgtk/{$this->lang}/userguide/chapters")) mkdir($this->cache_dir."help/phpgtk/{$this->lang}/userguide/chapters",0755); $outdir = $this->cache_dir . "help/phpgtk"; $urlprefix = "http://cvs.php.net/co.php/php-gtk-doc/"; $urls = array( $urlprefix. "manual.xml.in?p=1" => "manual.xml", $urlprefix. "global.ent?p=1" => "global.ent", $urlprefix. "{$this->lang}/language-defs.ent?p=1" => "{$this->lang}/language-defs.ent", $urlprefix. "{$this->lang}/reference.xml?p=1" => "{$this->lang}/reference.xml", $urlprefix. "{$this->lang}/userguide/chapters/install.xml?p=1" => "{$this->lang}/userguide/chapters/install.xml", $urlprefix. "{$this->lang}/userguide/chapters/intro.xml?p=1" => "{$this->lang}/userguide/chapters/intro.xml", $urlprefix. "{$this->lang}/userguide/chapters/widgets.xml?p=1" => "{$this->lang}/userguide/chapters/widgets.xml", $urlprefix. "{$this->lang}/userguide/chapters/signals.xml?p=1" => "{$this->lang}/userguide/chapters/signals.xml" ); $this->snoopy = new Snoopy; foreach ($urls as $url=>$file) { if (!$this->get_file($url,$outdir."/".$file)) return; } // by now it should have downloaded all the files! $manual_parser = new parser_XML; $manual_parser->data = implode('',file($outdir."/manual.xml")); //$manual_parser->debug=1; $manual_parser->html_parse(); // load the referece file as well! $manual_parser->data = implode('',file($outdir."/{$this->lang}/reference.xml")); //$manual_parser->debug=1; $manual_parser->html_parse(); // look for entities.. // of type /* bookinfo => en/bookinfo.xml preface chapter.* => en/chapter/????.xml faq.* features.* functions.* language.* pear.* appendices.* */ // this is a real hack! $sections = array( "chapters.intro" => "$outdir/{$this->lang}/userguide/chapters/intro.xml", "chapters.widgets" => "$outdir/{$this->lang}/userguide/chapters/widgets.xml", "chapters.signals" => "$outdir/{$this->lang}/userguide/chapters/signals.xml", "chapters.install" => "$outdir/{$this->lang}/userguide/chapters/install.xml" ); $fetchtypes = array( "bookinfo" => "S", "preface" => "S", "userguide" => "M", "tutorials" => "userguide/tuts/", "chapters" => "userguide/chapters/", "gtk" => "reference/", "gdk" => "reference/", "scn" => "reference/", "glade" => "reference/", "sqp" => "reference/", "reference" => "S", "licence" => "userguide/appendix/", "credits" => "S" ); echo "STAGE 2 parser : GOT ". count($manual_parser->htmltree) . "elements\n"; for($i=0;$ihtmltree);$i++) { // if ($i>10) break; if (!$manual_parser->htmltree[$i]->children) continue; for ($j=0;$jhtmltree[$i]->children);$j++) { if (!is_array($manual_parser->htmltree[$i]->children[$j])) continue; if ($manual_parser->htmltree[$i]->children[$j][0] !="ENTITY") continue; $ent = $manual_parser->htmltree[$i]->children[$j][1]; echo "GOT ENT $ent"; if (strpos($ent,".")) { $entinfo = explode(".", $ent ); if (!$fetchtypes[$entinfo[0]]) continue; if (strpos($fetchtypes[$entinfo[0]],"/" ) ) $entinfo[0] = $fetchtypes[$entinfo[0]] . $entinfo[0]; $thisdir = $outdir."/{$this->lang}/".$entinfo[0]; $sections[$ent] = $thisdir."/".$entinfo[1].".xml"; echo "\n$thisdir\n"; if (!file_exists(dirname($thisdir))) mkdir(dirname($thisdir),0755); if (!file_exists($thisdir)) mkdir($thisdir,0755); //$entname = str_replace("-","_", $entinfo[1]); $entname = $entinfo[1]; $this->get_file($urlprefix.$this->lang."/".$entinfo[0]."/".$entname .".xml?p=1", $thisdir."/".$entinfo[1].".xml"); } else { if (!$fetchtypes[$ent]) continue; $sections[$ent] = $outdir."/{$this->lang}/".$ent.".xml"; $this->get_file($urlprefix.$this->lang."/".$ent.".xml?p=1", $outdir."/{$this->lang}/".$ent.".xml"); } } } // now I should be able to build the manual ?? :) // sections is based on part's within the manual part. // first load up all the entity definitions.. unset($manual_parser); $this->manual_parser = new parser_XML; // preload all the ents! $preload_ents = array( $outdir . "/global.ent", "$outdir/{$this->lang}/language-defs.ent", ); foreach($preload_ents as $file) { echo "PRELOAD $file\n"; $this->manual_parser->data = implode('',file($file)); $this->manual_parser->html_parse(); } $this->manual_parser->data = implode('',file($outdir."/manual.xml")); $this->manual_parser->basedir=$outdir; $this->manual_parser->langdir=$this->lang; // load up entities! foreach($sections as $ent=>$filename) { echo "LOADING $ent from $filename\n"; $this->manual_parser->entities[$ent] = implode('',file($filename)); } // should add the entitiy files now!!! echo "INITIATING SECOND PARSE on "; //$this->manual_parser->debug=1; $this->manual_parser->html_parse(); //WOW that actually works!! // now generate some usefull information from it!!! // the manual index tree: // can be geerated by: /* book part (top level) chapter sect1 sect2 */ } function update_display($line) { global $dialogs; if (!trim($line)) return; echo "FETCHING : $line\n"; } function get_file($url,$local) { $this->update_display(basename($local)); if (file_exists($local)) return 1; //echo "$url => $local\n"; $this->snoopy->fetch($url); if (! $this->snoopy->results) return 0; $fh= fopen($local,"w"); fwrite($fh, $this->snoopy->results); fclose($fh); return 1; } }