3 if (function_exists ("DebugBreak")) {
\r
5 $DBGSESSID = "1@clienthost:7869";
\r
11 echo getcwd(). "\n";
\r
15 $lang = $argv[1]; // the language
\r
16 $doc = $argv[2]; // the document name (xd-001 etc.)
\r
17 $encoding_in = $argv[3];
\r
18 $encoding_out = $argv[4];
\r
20 echo "input encoding = $encoding_in \n";
\r
22 if ($encoding_in != $encoding_out) {
\r
26 $fencoding = 'UTF-8'; // This is the standard encoding of our XML source files
\r
28 $dirlist = glob ("*.html"); // get the list of html files within the doc main directory
\r
30 $idlist = array (); // initiate the id list array
\r
31 $fidlist = array (); // make a id list for every file
\r
32 $bilist = array (); // make a book info list
\r
34 BuildIDList ($lang, $doc, $idlist, $bilist);// build the ID List for the use of comments in xdocman
\r
36 foreach ($dirlist as $key => $file) { // for every html file
\r
37 ParseXHTML ($file, $lang, $doc, $fidlist, $idlist);
\r
40 WriteBookInfoList ($fidlist, $bilist);
\r
42 var_dump ($fidlist);
\r
44 copy ("style.css", "tmp/style.css"); // copy the style file to the temporary directory
\r
46 /***** ParseXHTML () **********************************/
\r
47 /* Parse the XHTML files
\r
51 function ParseXHTML (&$file, $lang, $doc, &$fidlist, &$idlist) {
\r
53 $data = file_get_contents ($file); // get the xhtml-file content
\r
54 $parser = xml_parser_create ($fencoding);
\r
55 $imglist = array (); // initiate the image list array
\r
57 xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);
\r
58 // xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);
\r
60 xml_parse_into_struct ($parser, $data, $values, $tags); // parse the xhtml file
\r
61 xml_parser_free ($parser);
\r
63 MakePictureList ($values, $tags, $imglist, $lang, $doc); // build the list with the used images
\r
64 CopyImages ($imglist); // copy the used images into the temp folder
\r
65 ChangeLinks ($values, $tags, $lang, $doc); // changed the links, so we can use the files with xdocman
\r
66 MakeFileIDList ($file, $values, $tags, $fidlist, $idlist);
\r
69 echo "array: tags\n";
\r
71 echo "array: values\n";
\r
73 echo "array: imglist\n";
\r
74 var_dump ($imglist);
\r
76 echo "array:".$file." generate output\n";
\r
78 OutputXHTML ($file, $values, $tags, 0);
\r
81 /***** MakeFileIDList (...) **********************************/
\r
84 function MakeFileIDList ($file, &$values, &$tags, &$fidlist, &$idlist) {
\r
85 echo "file = $file\n";
\r
87 $fidlist[$file] = array ();
\r
89 foreach ($tags['a'] as $key => $val) {
\r
90 if (isset ($values[$val]['attributes'])) {
\r
91 foreach ($values[$val]['attributes'] as $tkey => $tval) {
\r
92 if ($tkey == 'id') {
\r
93 // $idList[$tval] = $tval;
\r
95 // echo "id = $tval \n";
\r
97 if (isset ($idlist[$tval])) {
\r
98 echo "setzen $file: $tval = $idlist[$tval] \n";
\r
99 $fidlist[$file][$tval]['title'] = $idlist[$tval]['title'];
\r
100 $fidlist[$file][$tval]['element'] = $idlist[$tval]['element'];
\r
108 /***** ChangeLinks (...) **********************************/
\r
110 * changes href in <a href="..."> if href is sort of chxxx.html or index.html or ixxx.html
\r
111 * to ?lang=en&doc=xd-999&file=chxxx.html
\r
113 function ChangeLinks (&$values, &$tags, $lang, $doc) {
\r
114 foreach ($tags['a'] as $key => $val) {
\r
115 if (($values[$val]['type'] == 'open') || ($values[$val]['type'] == 'complete')) {
\r
116 if (isset ($values[$val]['attributes']['href'])) {
\r
117 $olddest = $values[$val]['attributes']['href'];
\r
119 echo "string = " . $olddest;
\r
120 preg_match ("/([ch|index|ix|pr|co|ar]).*\.html.*/i", $olddest, $linkval);
\r
121 // preg_match ("/#.*/i", $olddest, $idval);
\r
124 if (isset ($linkval[0])) {
\r
125 // $newdest .= "manual.php?lang=$lang&doc=$doc&file=".$linkval[0];
\r
126 // echo " link = " . $linkval[0];
\r
128 preg_match ("/#.*/i", $olddest, $lidval);
\r
129 if (isset ($lidval[0])) {
\r
130 echo " id = ". $lidval[0];
\r
131 $newdest .= "manual.php?lang=$lang&doc=$doc&id=".str_replace ('#', "", $lidval[0])."&file=".$linkval[0];
\r
134 $newdest .= "manual.php?lang=$lang&doc=$doc&file=".$linkval[0];
\r
138 else if (isset ($idval[0])) {
\r
139 echo " id = ".$idval[0];
\r
141 $newdest = $olddest;
\r
145 $newdest = $olddest;
\r
149 $values[$val]['attributes']['href'] = $newdest;
\r
155 /***** CopyImages (...) **********************************/
\r
158 function CopyImages (&$imglist) {
\r
159 CreateDirectory ('tmp/img');
\r
160 CreateDirectory ('tmp/img/callouts');
\r
161 CreateDirectory ('tmp/img/nav');
\r
162 CreateDirectory ('tmp/img/admon');
\r
164 foreach ($imglist as $key => $img) {
\r
165 $path = explode ('/', $img);
\r
167 if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {
\r
168 $dest = "tmp/".$path[0].'/'.$path[3];
\r
171 $dest = "tmp/".$img;
\r
174 copy ($img, $dest);
\r
178 /***** MakePictureList (...) **********************************/
\r
181 function MakePictureList (&$values, &$tags, &$imglist, &$lang, &$doc) {
\r
182 //** scan every <a> tag for the onmouseover and onmouseout attribute
\r
183 foreach ($tags['a'] as $key => $val) {
\r
184 if (isset ($values[$val]['attributes'])) {
\r
185 foreach ($values[$val]['attributes'] as $tkey => $tval) {
\r
186 if (($tkey == 'onmouseover') || ($tkey == 'onmouseout')) {
\r
187 //** strip everthing before the '='
\r
188 $ta = explode ('=', $tval);
\r
189 $img = str_replace ("'", "", $ta[1]);
\r
191 if (!in_array ($img, $imglist)) {
\r
192 array_push ($imglist, $img);
\r
195 $values[$val]['attributes'][$tkey] = $ta[0]."='docs/".$lang."/".$doc."/".$img."'";
\r
201 //** scan every <img> tag for the src attribute
\r
202 foreach ($tags['img'] as $key => $val) {
\r
203 if (isset ($values[$val]['attributes'])) {
\r
204 foreach ($values[$val]['attributes'] as $tkey => $tval) {
\r
205 if ($tkey == 'src') {
\r
206 if (!in_array ($tval, $imglist)) {
\r
207 array_push ($imglist, $tval);
\r
210 //** now change the image path from img/en/xxxx/xxx.png to img/xxx.png
\r
211 $path = explode ('/', $tval);
\r
213 if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {
\r
214 $newpath = $path[0].'/'.$path[3];
\r
216 $img = "docs/".$lang."/".$doc."/".$newpath;
\r
218 $values[$val]['attributes'][$tkey] = $img;
\r
221 $values[$val]['attributes'][$tkey] = "docs/".$lang."/".$doc."/".$tval;
\r
229 /***** OutputXHTML (...) **********************************/
\r
232 function OutputXHTML (&$file, &$values, &$tags, $all) {
\r
235 global $encoding_in;
\r
236 global $encoding_out;
\r
237 $fp = fopen ("tmp/".$file, "w");
\r
238 $i = count ($values);
\r
240 //** get start and end
\r
247 $start = $tags['body'][0] + 1;
\r
248 $end = $tags['body'][1] - 1;
\r
252 $text = '<?xml version="1.0" encoding="'.$fencoding.'" standalone="no"?>'."\n";
\r
253 $text .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
\r
254 fwrite ($fp, $text);
\r
259 foreach ($values as $key => $tag) {
\r
260 if (($key < $start) || ($key > $end)) {
\r
267 if ($tag['type'] == 'open') {
\r
272 else if ($tag['type'] == 'close') {
\r
276 else if ($tag['type'] == 'cdata') {
\r
279 else { //** it's complete
\r
285 $text = htmlspecialchars ($tag['value']);
\r
288 $text .= $tag['tag'];
\r
290 if (isset ($tag['attributes'])) {
\r
291 foreach ($tag['attributes'] as $key => $att) {
\r
292 $text .= ' '.$key. '="' . $att . '"';
\r
296 if (isset ($tag['value'])) {
\r
298 $text .= ">".htmlspecialchars ($tag['value']);
\r
301 $text .= ">".htmlspecialchars ($tag['value'])."</" . $tag['tag'] . ">";
\r
305 if (($tag['tag'] == 'a') && ($tag['type'] == 'complete')) {
\r
315 $text = mb_convert_encoding ($text, 'HTML-ENTITIES', $encoding_in);
\r
318 fwrite ($fp, $text);
\r
323 /***** CreateDirectory (...) **********************************/
\r
325 function CreateDirectory ($dirname) {
\r
327 $dir = split ('[/|\\]', $dirname);
\r
329 for ($i = 0; $i < count ($dir); $i++) {
\r
330 $path .= $dir[$i]."/";
\r
332 if (!is_dir ($path)) {
\r
333 @mkdir ($path, 0777);
\r
334 @chmod ($path, 0777);
\r
338 if (is_dir ($dirname)) {
\r
345 /***** BuildIDList (...) **********************************/
\r
347 function BuildIDList ($lang, $doc, &$idlist, &$bilist) {
\r
349 $data = file_get_contents ($lang."_".$doc.".xml"); // get the xml-file content
\r
350 $parser = xml_parser_create ($fencoding);
\r
352 xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);
\r
353 xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);
\r
355 xml_parse_into_struct ($parser, $data, $values, $tags); // parse the xml file
\r
356 xml_parser_free ($parser);
\r
358 MakeIDList ($values, $tags, $idlist); // build the list with the used ids
\r
359 MakeBIList ($values, $tags, $bilist); // build the Book Info list
\r
361 echo "array: bilist\n";
\r
362 var_dump ($bilist);
\r
363 echo "array: tags\n";
\r
365 echo "array: values\n";
\r
366 var_dump ($values);
\r
370 /***** MakeIDList (...) **********************************/
\r
372 function MakeIDList (&$values, &$tags, &$idlist) {
\r
373 $taglist = array ("chapter", "sect1", "sect2", "sect3", "sect4", "figure");
\r
375 foreach ($taglist as $tlkey => $tag) { // for every tag with a possible id
\r
377 if (isset ($tags[$tag])) {
\r
378 foreach ($tags[$tag] as $key => $val) {
\r
379 if (isset ($values[$val]['attributes'])) {
\r
380 foreach ($values[$val]['attributes'] as $tkey => $tval) {
\r
381 if ($tkey == 'id') { // we have an id, so look for the title
\r
382 if ($values[$val + 1]['tag'] == 'title') { // if the next tag is a title
\r
383 // $idlist[$tval] = $values[$val + 1]['value'];
\r
384 $idlist[$tval]['title'] = $values[$val + 1]['value'];
\r
385 $idlist[$tval]['element'] = $tag; // the element
\r
395 /***** MakeBIList (...) **********************************/
\r
397 function MakeBIList (&$values, &$tags, &$bilist) {
\r
401 if (isset ($tags['book'])) {
\r
402 // $count = count ($tags['book']);
\r
403 $start = $tags['bookinfo'][0] + 1;
\r
404 $end = $tags['bookinfo'][1] - 1;
\r
407 else if (isset ($tags['article'])) {
\r
408 $start = $tags['articleinfo'][0] + 1;
\r
409 $end = $tags['articleinfo'][1] - 1;
\r
413 // get the status attribute from book or article
\r
415 if (isset ($values[0]['attributes']['status'])) {
\r
416 $status = explode ('_', $values[0]['attributes']['status']);
\r
418 if (($status[0] == 'progress') && (isset ($status[1]))) {
\r
419 $bilist['status'] = $status[1];
\r
422 $bilist['status'] = $status[0];
\r
426 // search for the title
\r
428 for ($index = $start; $index <= $end; $index++) {
\r
430 case 0: // search the title tag
\r
431 if ($values[$index]['tag'] == 'title') {
\r
432 if (isset ($values[$index]['value'])) {
\r
433 $bilist['title'] = $values[$index]['value'];
\r
436 if ($values[$index]['type'] == 'open') {
\r
437 $state = 1; // title is not complete, so append the other tags (i.e. from quote or emphasis)
\r
440 $state = 2; // title is complete
\r
445 case 1: // append the values of every tag until the closing title tag
\r
446 if ($values[$index]['tag'] == 'title') {
\r
447 if (isset ($values[$index]['value'])) {
\r
448 $bilist['title'] .= $values[$index]['value'];
\r
451 if ($values[$index]['type'] == 'close') {
\r
452 $state = 2; // title is complete
\r
456 if (isset ($values[$index]['value'])) {
\r
457 $bilist['title'] .= $values[$index]['value'];
\r
466 if ($state == 2) { // if we have the title leave the loop
\r
471 // search for the revnumber and revdate within the last revision within revhistory
\r
473 if (isset ($tags['revision'])) { // ok we have a revision
\r
474 $count = count ($tags['revision']);
\r
476 $start = $tags['revision'][$count - 2];
\r
477 $end = $tags['revision'][$count - 1];
\r
480 if (isset ($tags['revnumber'])) {
\r
481 $count = count ($tags['revnumber']);
\r
483 for ($index = 0; $index < $count; $index++) {
\r
484 $val_index = $tags['revnumber'][$index];
\r
486 if (($val_index > $start) && ($val_index < $end)) {
\r
487 $bilist['revnumber'] = $values[$val_index]['value'];
\r
492 if (isset ($tags['date'])) {
\r
493 $count = count ($tags['date']);
\r
495 for ($index = 0; $index < $count; $index++) {
\r
496 $val_index = $tags['date'][$index];
\r
498 if (($val_index > $start) && ($val_index < $end)) {
\r
499 $bilist['revdate'] = $values[$val_index]['value'];
\r
505 /***** WriteBookInfoList (...) **********************************/
\r
507 function WriteBookInfoList (&$fidlist, &$bilist) {
\r
510 global $encoding_in;
\r
512 $fp = fopen ("tmp/docinfo.xml", "w");
\r
515 $text = "<?xml version=\"1.0\" ?>" . "\n";
\r
516 fwrite ($fp, $text);
\r
518 $text = "<docinfo>\n";
\r
519 fwrite ($fp, $text);
\r
521 foreach ($bilist as $tag => $value) {
\r
522 $text = " <$tag>$value</$tag>\n";
\r
523 fwrite ($fp, $text);
\r
526 foreach ($fidlist as $filename => $file) {
\r
527 $text = " <file>\n <name>$filename</name>\n";
\r
528 fwrite ($fp, $text);
\r
530 foreach ($file as $id => $idvalue) {
\r
531 $text = " <entry>\n <id>".$id."</id>\n";
\r
532 fwrite ($fp, $text);
\r
534 $text = " <element>".$idvalue['element']."</element>\n";
\r
535 fwrite ($fp, $text);
\r
537 $text = " <text>".$idvalue['title']."</text>\n </entry>\n";
\r
540 $text = mb_convert_encoding ($text, 'HTML-ENTITIES', $encoding_in);
\r
543 fwrite ($fp, $text);
\r
546 $text = " </file>\n";
\r
547 fwrite ($fp, $text);
\r
550 $text = "</docinfo>";
\r
551 fwrite ($fp, $text);
\r
557 /******************************************************************************/
\r