Initial import of the Guide contributed to the project byRobert Kraske. Was originall...
[phpeclipse.git] / net.sourceforge.phpeclipse.help / docbook-src / guide / parseimages.php
diff --git a/net.sourceforge.phpeclipse.help/docbook-src/guide/parseimages.php b/net.sourceforge.phpeclipse.help/docbook-src/guide/parseimages.php
new file mode 100644 (file)
index 0000000..3313a90
--- /dev/null
@@ -0,0 +1,140 @@
+<?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
+  $doc          = $argv[1];                     // the document name (xd-001 etc.)\r
+\r
+  $dirlist   = glob ("*.html");                 // get the list of html files within the doc main directory\r
+\r
+  foreach ($dirlist as $key => $file) {       // for every html file\r
+    ParseXHTML ($file, $lang, $doc, $fidlist, $idlist);\r
+  }\r
+\r
+\r
+/***** ParseXHTML ()                         **********************************/\r
+/* Parse the XHTML files\r
+ *\r
+ */\r
+\r
+  function ParseXHTML (&$file, $lang, $doc, &$fidlist, &$idlist) {\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
+  }\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
+      // The image path is something like: img/en/xxxx/xxx.png to img/xxx.png\r
+      if (($path[1] != 'callouts') && ($path[1] != 'nav') && ($path[1] != 'admon')) {\r
+        $dest = "tmp/".$path[0].'/'.$path[1].'/'.$path[2].'/'.$path[3];        // build the destination path for the image\r
+        CreateDirectory ('tmp/img/'.$path[1].'/'.$path[2]);\r
+      }\r
+      else {\r
+        $dest = "tmp/".$img;\r
+      }\r
+\r
+      // echo "---copy:". $img. ":to:". $dest."\n";\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
+            $ta  = explode ('=', $tval);                       // strip everthing before the '='\r
+            $img = str_replace ("'", "", $ta[1]);              // remove the '\r
+\r
+            if (!in_array ($img, $imglist)) {                  // As long as this img yet isn't within the list\r
+              array_push ($imglist, $img);                     //  add this image to the list\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') {                                // It it is the 'src' attribute\r
+            if (!in_array ($tval, $imglist)) {                 // As long as this img yet isn't within the list\r
+              array_push ($imglist, $tval);                    //  add this image to the list\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];                  // path[0] = img; path[3] = xxx.png || xxx.jpg\r
+              $img = "docs/".$lang."/".$doc."/".$newpath;        // e.g. new path = docs/en/xn-001/img/xxx.png\r
+              $values[$val]['attributes'][$tkey] = $img;         // $img is the new link path to the image\r
+            }\r
+            else {\r
+              $values[$val]['attributes'][$tkey] = "docs/".$lang."/".$doc."/".$tval;\r
+            }\r
+          }\r
+        }\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
+/******************************************************************************/\r
+\r
+?>\r