3 if (function_exists ("DebugBreak")) {
\r
5 $DBGSESSID = "1@clienthost:7869";
\r
11 echo getcwd(). "\n";
\r
13 $doc = $argv[1]; // the document name (xd-001 etc.)
\r
15 $dirlist = glob ("*.html"); // get the list of html files within the doc main directory
\r
17 foreach ($dirlist as $key => $file) { // for every html file
\r
18 ParseXHTML ($file, $lang, $doc, $fidlist, $idlist);
\r
22 /***** ParseXHTML () **********************************/
\r
23 /* Parse the XHTML files
\r
27 function ParseXHTML (&$file, $lang, $doc, &$fidlist, &$idlist) {
\r
28 $data = file_get_contents ($file); // get the xhtml-file content
\r
29 $parser = xml_parser_create ($fencoding);
\r
30 $imglist = array (); // initiate the image list array
\r
32 xml_parser_set_option ($parser, XML_OPTION_CASE_FOLDING, 0);
\r
33 // xml_parser_set_option ($parser, XML_OPTION_SKIP_WHITE, 1);
\r
35 xml_parse_into_struct ($parser, $data, $values, $tags); // parse the xhtml file
\r
36 xml_parser_free ($parser);
\r
38 MakePictureList ($values, $tags, $imglist, $lang, $doc); // build the list with the used images
\r
39 CopyImages ($imglist); // copy the used images into the temp folder
\r
42 /***** CopyImages (...) **********************************/
\r
45 function CopyImages (&$imglist) {
\r
46 CreateDirectory ('tmp/img');
\r
47 CreateDirectory ('tmp/img/callouts');
\r
48 CreateDirectory ('tmp/img/nav');
\r
49 CreateDirectory ('tmp/img/admon');
\r
51 foreach ($imglist as $key => $img) {
\r
52 $path = explode ('/', $img);
\r
54 // The image path is something like: img/en/xxxx/xxx.png to img/xxx.png
\r
55 if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {
\r
56 $dest = "tmp/".$path[0].'/'.$path[1].'/'.$path[2].'/'.$path[3]; // build the destination path for the image
\r
57 CreateDirectory ('tmp/img/'.$path[1].'/'.$path[2]);
\r
60 $dest = "tmp/".$img;
\r
63 // echo "---copy:". $img. ":to:". $dest."\n";
\r
68 /***** MakePictureList (...) **********************************/
\r
71 function MakePictureList (&$values, &$tags, &$imglist, &$lang, &$doc) {
\r
72 // scan every <a> tag for the onmouseover and onmouseout attribute
\r
73 foreach ($tags['a'] as $key => $val) {
\r
74 if (isset ($values[$val]['attributes'])) {
\r
75 foreach ($values[$val]['attributes'] as $tkey => $tval) {
\r
76 if (($tkey == 'onmouseover') || ($tkey == 'onmouseout')) {
\r
77 $ta = explode ('=', $tval); // strip everthing before the '='
\r
78 $img = str_replace ("'", "", $ta[1]); // remove the '
\r
80 if (!in_array ($img, $imglist)) { // As long as this img yet isn't within the list
\r
81 array_push ($imglist, $img); // add this image to the list
\r
84 $values[$val]['attributes'][$tkey] = $ta[0]."='docs/".$lang."/".$doc."/".$img."'";
\r
90 // scan every <img> tag for the src attribute
\r
91 foreach ($tags['img'] as $key => $val) {
\r
92 if (isset ($values[$val]['attributes'])) {
\r
93 foreach ($values[$val]['attributes'] as $tkey => $tval) {
\r
94 if ($tkey == 'src') { // It it is the 'src' attribute
\r
95 if (!in_array ($tval, $imglist)) { // As long as this img yet isn't within the list
\r
96 array_push ($imglist, $tval); // add this image to the list
\r
99 // now change the image path from img/en/xxxx/xxx.png to img/xxx.png
\r
100 $path = explode ('/', $tval);
\r
102 if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {
\r
103 $newpath = $path[0].'/'.$path[3]; // path[0] = img; path[3] = xxx.png || xxx.jpg
\r
104 $img = "docs/".$lang."/".$doc."/".$newpath; // e.g. new path = docs/en/xn-001/img/xxx.png
\r
105 $values[$val]['attributes'][$tkey] = $img; // $img is the new link path to the image
\r
108 $values[$val]['attributes'][$tkey] = "docs/".$lang."/".$doc."/".$tval;
\r
116 /***** CreateDirectory (...) **********************************/
\r
118 function CreateDirectory ($dirname) {
\r
120 $dir = split ('[/|\\]', $dirname);
\r
122 for ($i = 0; $i < count ($dir); $i++) {
\r
123 $path .= $dir[$i]."/";
\r
125 if (!is_dir ($path)) {
\r
126 @mkdir ($path, 0777);
\r
127 @chmod ($path, 0777);
\r
131 if (is_dir ($dirname)) {
\r
138 /******************************************************************************/
\r