--- /dev/null
+<?php\r
+\r
+ if (function_exists ("DebugBreak")) {\r
+ global $DBGSESSID;\r
+ $DBGSESSID = "1@clienthost:7869";\r
+ DebugBreak ();\r
+ }\r
+\r
+ var_dump ($argv);\r
+\r
+ echo getcwd(). "\n";\r
+\r
+ $recode_it = false;\r
+\r
+ $lang = $argv[1]; // the language\r
+ $doc = $argv[2]; // the document name (xd-001 etc.)\r
+ $encoding_in = $argv[3];\r
+ $encoding_out = $argv[4];\r
+\r
+ echo "input encoding = $encoding_in \n";\r
+\r
+ if ($encoding_in != $encoding_out) {\r
+ $recode_it = true;\r
+ }\r
+\r
+ $fencoding = 'UTF-8'; // This is the standard encoding of our XML source files\r
+\r
+ $dirlist = glob ("*.html"); // get the list of html files within the doc main directory\r
+\r
+ $idlist = array (); // initiate the id list array\r
+ $fidlist = array (); // make a id list for every file\r
+ $bilist = array (); // make a book info list\r
+\r
+ BuildIDList ($lang, $doc, $idlist, $bilist);// build the ID List for the use of comments in xdocman\r
+\r
+ foreach ($dirlist as $key => $file) { // for every html file\r
+ ParseXHTML ($file, $lang, $doc, $fidlist, $idlist);\r
+ }\r
+\r
+ WriteBookInfoList ($fidlist, $bilist);\r
+/*\r
+ var_dump ($fidlist);\r
+*/\r
+ copy ("style.css", "tmp/style.css"); // copy the style file to the temporary directory\r
+\r
+/***** ParseXHTML () **********************************/\r
+/* Parse the XHTML files\r
+ *\r
+ */\r
+\r
+ function ParseXHTML (&$file, $lang, $doc, &$fidlist, &$idlist) {\r
+ global $fencoding;\r
+ $data = file_get_contents ($file); // get the xhtml-file content\r
+ $parser = xml_parser_create ($fencoding);\r
+ $imglist = array (); // initiate the image list array\r
+\r
+ xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);\r
+ // xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);\r
+\r
+ xml_parse_into_struct ($parser, $data, $values, $tags); // parse the xhtml file\r
+ xml_parser_free ($parser);\r
+\r
+ MakePictureList ($values, $tags, $imglist, $lang, $doc); // build the list with the used images\r
+ CopyImages ($imglist); // copy the used images into the temp folder\r
+ ChangeLinks ($values, $tags, $lang, $doc); // changed the links, so we can use the files with xdocman\r
+ MakeFileIDList ($file, $values, $tags, $fidlist, $idlist);\r
+\r
+/*\r
+ echo "array: tags\n";\r
+ var_dump ($tags);\r
+ echo "array: values\n";\r
+ var_dump ($values);\r
+ echo "array: imglist\n";\r
+ var_dump ($imglist);\r
+\r
+ echo "array:".$file." generate output\n";\r
+*/\r
+ OutputXHTML ($file, $values, $tags, 0);\r
+ }\r
+\r
+/***** MakeFileIDList (...) **********************************/\r
+/*\r
+ */\r
+ function MakeFileIDList ($file, &$values, &$tags, &$fidlist, &$idlist) {\r
+ echo "file = $file\n";\r
+\r
+ $fidlist[$file] = array ();\r
+\r
+ foreach ($tags['a'] as $key => $val) {\r
+ if (isset ($values[$val]['attributes'])) {\r
+ foreach ($values[$val]['attributes'] as $tkey => $tval) {\r
+ if ($tkey == 'id') {\r
+ // $idList[$tval] = $tval;\r
+\r
+ // echo "id = $tval \n";\r
+\r
+ if (isset ($idlist[$tval])) {\r
+ echo "setzen $file: $tval = $idlist[$tval] \n";\r
+ $fidlist[$file][$tval]['title'] = $idlist[$tval]['title'];\r
+ $fidlist[$file][$tval]['element'] = $idlist[$tval]['element'];\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+/***** ChangeLinks (...) **********************************/\r
+/*\r
+ * changes href in <a href="..."> if href is sort of chxxx.html or index.html or ixxx.html\r
+ * to ?lang=en&doc=xd-999&file=chxxx.html\r
+ */\r
+ function ChangeLinks (&$values, &$tags, $lang, $doc) {\r
+ foreach ($tags['a'] as $key => $val) {\r
+ if (($values[$val]['type'] == 'open') || ($values[$val]['type'] == 'complete')) {\r
+ if (isset ($values[$val]['attributes']['href'])) {\r
+ $olddest = $values[$val]['attributes']['href'];\r
+\r
+ echo "string = " . $olddest;\r
+ preg_match ("/([ch|index|ix|pr|co|ar]).*\.html.*/i", $olddest, $linkval);\r
+ // preg_match ("/#.*/i", $olddest, $idval);\r
+\r
+ $newdest = "";\r
+ if (isset ($linkval[0])) {\r
+ // $newdest .= "manual.php?lang=$lang&doc=$doc&file=".$linkval[0];\r
+ // echo " link = " . $linkval[0];\r
+\r
+ preg_match ("/#.*/i", $olddest, $lidval);\r
+ if (isset ($lidval[0])) {\r
+ echo " id = ". $lidval[0];\r
+ $newdest .= "manual.php?lang=$lang&doc=$doc&id=".str_replace ('#', "", $lidval[0])."&file=".$linkval[0];\r
+ }\r
+ else {\r
+ $newdest .= "manual.php?lang=$lang&doc=$doc&file=".$linkval[0];\r
+ }\r
+ }\r
+/*\r
+ else if (isset ($idval[0])) {\r
+ echo " id = ".$idval[0];\r
+\r
+ $newdest = $olddest;\r
+ }\r
+*/\r
+ else {\r
+ $newdest = $olddest;\r
+ }\r
+\r
+ echo "\n";\r
+ $values[$val]['attributes']['href'] = $newdest;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+/***** CopyImages (...) **********************************/\r
+/*\r
+ */\r
+ function CopyImages (&$imglist) {\r
+ CreateDirectory ('tmp/img');\r
+ CreateDirectory ('tmp/img/callouts');\r
+ CreateDirectory ('tmp/img/nav');\r
+ CreateDirectory ('tmp/img/admon');\r
+\r
+ foreach ($imglist as $key => $img) {\r
+ $path = explode ('/', $img);\r
+\r
+ if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {\r
+ $dest = "tmp/".$path[0].'/'.$path[3];\r
+ }\r
+ else {\r
+ $dest = "tmp/".$img;\r
+ }\r
+\r
+ copy ($img, $dest);\r
+ }\r
+ }\r
+\r
+/***** MakePictureList (...) **********************************/\r
+/*\r
+ */\r
+ function MakePictureList (&$values, &$tags, &$imglist, &$lang, &$doc) {\r
+ //** scan every <a> tag for the onmouseover and onmouseout attribute\r
+ foreach ($tags['a'] as $key => $val) {\r
+ if (isset ($values[$val]['attributes'])) {\r
+ foreach ($values[$val]['attributes'] as $tkey => $tval) {\r
+ if (($tkey == 'onmouseover') || ($tkey == 'onmouseout')) {\r
+ //** strip everthing before the '='\r
+ $ta = explode ('=', $tval);\r
+ $img = str_replace ("'", "", $ta[1]);\r
+\r
+ if (!in_array ($img, $imglist)) {\r
+ array_push ($imglist, $img);\r
+ }\r
+\r
+ $values[$val]['attributes'][$tkey] = $ta[0]."='docs/".$lang."/".$doc."/".$img."'";\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ //** scan every <img> tag for the src attribute\r
+ foreach ($tags['img'] as $key => $val) {\r
+ if (isset ($values[$val]['attributes'])) {\r
+ foreach ($values[$val]['attributes'] as $tkey => $tval) {\r
+ if ($tkey == 'src') {\r
+ if (!in_array ($tval, $imglist)) {\r
+ array_push ($imglist, $tval);\r
+ }\r
+\r
+ //** now change the image path from img/en/xxxx/xxx.png to img/xxx.png\r
+ $path = explode ('/', $tval);\r
+\r
+ if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {\r
+ $newpath = $path[0].'/'.$path[3];\r
+\r
+ $img = "docs/".$lang."/".$doc."/".$newpath;\r
+\r
+ $values[$val]['attributes'][$tkey] = $img;\r
+ }\r
+ else {\r
+ $values[$val]['attributes'][$tkey] = "docs/".$lang."/".$doc."/".$tval;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+/***** OutputXHTML (...) **********************************/\r
+/*\r
+ */\r
+ function OutputXHTML (&$file, &$values, &$tags, $all) {\r
+ global $fencoding;\r
+ global $recode_it;\r
+ global $encoding_in;\r
+ global $encoding_out;\r
+ $fp = fopen ("tmp/".$file, "w");\r
+ $i = count ($values);\r
+\r
+ //** get start and end\r
+\r
+ if ($all) {\r
+ $start = 0;\r
+ $end = $i;\r
+ }\r
+ else {\r
+ $start = $tags['body'][0] + 1;\r
+ $end = $tags['body'][1] - 1;\r
+ }\r
+\r
+ if ($all) {\r
+ $text = '<?xml version="1.0" encoding="'.$fencoding.'" standalone="no"?>'."\n";\r
+ $text .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";\r
+ fwrite ($fp, $text);\r
+ }\r
+\r
+\r
+ if ($fp) {\r
+ foreach ($values as $key => $tag) {\r
+ if (($key < $start) || ($key > $end)) {\r
+ continue;\r
+ }\r
+\r
+ $cdata = 0;\r
+ $open = 0;\r
+\r
+ if ($tag['type'] == 'open') {\r
+ $text = "<";\r
+ $close = "\n>";\r
+ $open = 1;\r
+ }\r
+ else if ($tag['type'] == 'close') {\r
+ $text = "</";\r
+ $close = "\n>";\r
+ }\r
+ else if ($tag['type'] == 'cdata') {\r
+ $cdata = 1;\r
+ }\r
+ else { //** it's complete\r
+ $text = "<";\r
+ $close = " /\n>";\r
+ }\r
+\r
+ if ($cdata) {\r
+ $text = htmlspecialchars ($tag['value']);\r
+ }\r
+ else {\r
+ $text .= $tag['tag'];\r
+\r
+ if (isset ($tag['attributes'])) {\r
+ foreach ($tag['attributes'] as $key => $att) {\r
+ $text .= ' '.$key. '="' . $att . '"';\r
+ }\r
+ }\r
+\r
+ if (isset ($tag['value'])) {\r
+ if ($open) {\r
+ $text .= ">".htmlspecialchars ($tag['value']);\r
+ }\r
+ else {\r
+ $text .= ">".htmlspecialchars ($tag['value'])."</" . $tag['tag'] . ">";\r
+ }\r
+ }\r
+ else {\r
+ if (($tag['tag'] == 'a') && ($tag['type'] == 'complete')) {\r
+ $text .= "></a>";\r
+ }\r
+ else {\r
+ $text .= $close;\r
+ }\r
+ }\r
+ }\r
+\r
+ if ($recode_it) {\r
+ $text = mb_convert_encoding ($text, 'HTML-ENTITIES', $encoding_in);\r
+ }\r
+\r
+ fwrite ($fp, $text);\r
+ }\r
+ }\r
+ }\r
+\r
+/***** CreateDirectory (...) **********************************/\r
+\r
+ function CreateDirectory ($dirname) {\r
+ $path = "";\r
+ $dir = split ('[/|\\]', $dirname);\r
+\r
+ for ($i = 0; $i < count ($dir); $i++) {\r
+ $path .= $dir[$i]."/";\r
+\r
+ if (!is_dir ($path)) {\r
+ @mkdir ($path, 0777);\r
+ @chmod ($path, 0777);\r
+ }\r
+ }\r
+\r
+ if (is_dir ($dirname)) {\r
+ return 1;\r
+ }\r
+\r
+ return 0;\r
+ }\r
+\r
+/***** BuildIDList (...) **********************************/\r
+\r
+ function BuildIDList ($lang, $doc, &$idlist, &$bilist) {\r
+ global $fencoding;\r
+ $data = file_get_contents ($lang."_".$doc.".xml"); // get the xml-file content\r
+ $parser = xml_parser_create ($fencoding);\r
+\r
+ xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);\r
+ xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);\r
+\r
+ xml_parse_into_struct ($parser, $data, $values, $tags); // parse the xml file\r
+ xml_parser_free ($parser);\r
+\r
+ MakeIDList ($values, $tags, $idlist); // build the list with the used ids\r
+ MakeBIList ($values, $tags, $bilist); // build the Book Info list\r
+\r
+ echo "array: bilist\n";\r
+ var_dump ($bilist);\r
+ echo "array: tags\n";\r
+ var_dump ($tags);\r
+ echo "array: values\n";\r
+ var_dump ($values);\r
+\r
+ }\r
+\r
+/***** MakeIDList (...) **********************************/\r
+\r
+ function MakeIDList (&$values, &$tags, &$idlist) {\r
+ $taglist = array ("chapter", "sect1", "sect2", "sect3", "sect4", "figure");\r
+\r
+ foreach ($taglist as $tlkey => $tag) { // for every tag with a possible id\r
+\r
+ if (isset ($tags[$tag])) {\r
+ foreach ($tags[$tag] as $key => $val) {\r
+ if (isset ($values[$val]['attributes'])) {\r
+ foreach ($values[$val]['attributes'] as $tkey => $tval) {\r
+ if ($tkey == 'id') { // we have an id, so look for the title\r
+ if ($values[$val + 1]['tag'] == 'title') { // if the next tag is a title\r
+ // $idlist[$tval] = $values[$val + 1]['value'];\r
+ $idlist[$tval]['title'] = $values[$val + 1]['value'];\r
+ $idlist[$tval]['element'] = $tag; // the element\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+/***** MakeBIList (...) **********************************/\r
+\r
+ function MakeBIList (&$values, &$tags, &$bilist) {\r
+ $start = 0;\r
+ $end = 0;\r
+\r
+ if (isset ($tags['book'])) {\r
+ // $count = count ($tags['book']);\r
+ $start = $tags['bookinfo'][0] + 1;\r
+ $end = $tags['bookinfo'][1] - 1;\r
+ $state = 0;\r
+ }\r
+ else if (isset ($tags['article'])) {\r
+ $start = $tags['articleinfo'][0] + 1;\r
+ $end = $tags['articleinfo'][1] - 1;\r
+ $state = 0;\r
+ }\r
+\r
+ // get the status attribute from book or article\r
+\r
+ if (isset ($values[0]['attributes']['status'])) {\r
+ $status = explode ('_', $values[0]['attributes']['status']);\r
+\r
+ if (($status[0] == 'progress') && (isset ($status[1]))) {\r
+ $bilist['status'] = $status[1];\r
+ }\r
+ else {\r
+ $bilist['status'] = $status[0];\r
+ }\r
+ }\r
+\r
+ // search for the title\r
+\r
+ for ($index = $start; $index <= $end; $index++) {\r
+ switch ($state) {\r
+ case 0: // search the title tag\r
+ if ($values[$index]['tag'] == 'title') {\r
+ if (isset ($values[$index]['value'])) {\r
+ $bilist['title'] = $values[$index]['value'];\r
+ }\r
+\r
+ if ($values[$index]['type'] == 'open') {\r
+ $state = 1; // title is not complete, so append the other tags (i.e. from quote or emphasis)\r
+ }\r
+ else {\r
+ $state = 2; // title is complete\r
+ }\r
+ }\r
+ break;\r
+\r
+ case 1: // append the values of every tag until the closing title tag\r
+ if ($values[$index]['tag'] == 'title') {\r
+ if (isset ($values[$index]['value'])) {\r
+ $bilist['title'] .= $values[$index]['value'];\r
+ }\r
+\r
+ if ($values[$index]['type'] == 'close') {\r
+ $state = 2; // title is complete\r
+ }\r
+ }\r
+ else {\r
+ if (isset ($values[$index]['value'])) {\r
+ $bilist['title'] .= $values[$index]['value'];\r
+ }\r
+ }\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+\r
+ if ($state == 2) { // if we have the title leave the loop\r
+ break;\r
+ }\r
+ }\r
+\r
+ // search for the revnumber and revdate within the last revision within revhistory\r
+\r
+ if (isset ($tags['revision'])) { // ok we have a revision\r
+ $count = count ($tags['revision']);\r
+\r
+ $start = $tags['revision'][$count - 2];\r
+ $end = $tags['revision'][$count - 1];\r
+ }\r
+\r
+ if (isset ($tags['revnumber'])) {\r
+ $count = count ($tags['revnumber']);\r
+\r
+ for ($index = 0; $index < $count; $index++) {\r
+ $val_index = $tags['revnumber'][$index];\r
+\r
+ if (($val_index > $start) && ($val_index < $end)) {\r
+ $bilist['revnumber'] = $values[$val_index]['value'];\r
+ }\r
+ }\r
+ }\r
+\r
+ if (isset ($tags['date'])) {\r
+ $count = count ($tags['date']);\r
+\r
+ for ($index = 0; $index < $count; $index++) {\r
+ $val_index = $tags['date'][$index];\r
+\r
+ if (($val_index > $start) && ($val_index < $end)) {\r
+ $bilist['revdate'] = $values[$val_index]['value'];\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+/***** WriteBookInfoList (...) **********************************/\r
+\r
+ function WriteBookInfoList (&$fidlist, &$bilist) {\r
+ global $fencoding;\r
+ global $recode_it;\r
+ global $encoding_in;\r
+\r
+ $fp = fopen ("tmp/docinfo.xml", "w");\r
+\r
+ if ($fp) {\r
+ $text = "<?xml version=\"1.0\" ?>" . "\n";\r
+ fwrite ($fp, $text);\r
+\r
+ $text = "<docinfo>\n";\r
+ fwrite ($fp, $text);\r
+\r
+ foreach ($bilist as $tag => $value) {\r
+ $text = " <$tag>$value</$tag>\n";\r
+ fwrite ($fp, $text);\r
+ }\r
+\r
+ foreach ($fidlist as $filename => $file) {\r
+ $text = " <file>\n <name>$filename</name>\n";\r
+ fwrite ($fp, $text);\r
+\r
+ foreach ($file as $id => $idvalue) {\r
+ $text = " <entry>\n <id>".$id."</id>\n";\r
+ fwrite ($fp, $text);\r
+\r
+ $text = " <element>".$idvalue['element']."</element>\n";\r
+ fwrite ($fp, $text);\r
+\r
+ $text = " <text>".$idvalue['title']."</text>\n </entry>\n";\r
+\r
+ if ($recode_it) {\r
+ $text = mb_convert_encoding ($text, 'HTML-ENTITIES', $encoding_in);\r
+ }\r
+\r
+ fwrite ($fp, $text);\r
+ }\r
+\r
+ $text = " </file>\n";\r
+ fwrite ($fp, $text);\r
+ }\r
+\r
+ $text = "</docinfo>";\r
+ fwrite ($fp, $text);\r
+\r
+ fclose ($fp);\r
+ }\r
+ }\r
+\r
+/******************************************************************************/\r
+\r
+?>\r