Fix: make convert.php script for doc generation compatible with php 5.3
authorgggeek <giunta.gaetano@gmail.com>
Sun, 2 Feb 2014 19:05:22 +0000 (20:05 +0100)
committergggeek <giunta.gaetano@gmail.com>
Sun, 2 Feb 2014 19:05:22 +0000 (20:05 +0100)
doc/convert.php

index c613445..8e7f7f0 100644 (file)
@@ -6,17 +6,17 @@
  */
 
 if ($_SERVER['argc'] < 4)
-  die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
+    die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
 else
-  echo "Starting xsl conversion process...\n";
+    echo "Starting xsl conversion process...\n";
 
 $doc = $_SERVER['argv'][1];
 $xss = $_SERVER['argv'][2];
 
 if (!file_exists($doc))
-  die("KO: file $doc cannot be found\n");
+    die("KO: file $doc cannot be found\n");
 if (!file_exists($xss))
-  die("KO: file $xss cannot be found\n");
+    die("KO: file $xss cannot be found\n");
 
 // Load the XML source
 $xml = new DOMDocument;
@@ -26,23 +26,32 @@ $xsl->load($xss);
 
 // Configure the transformer
 $proc = new XSLTProcessor;
+if (version_compare(PHP_VERSION,'5.4',"<"))
+{
+    if(defined('XSL_SECPREF_WRITE_FILE'))
+        ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
+}
+else
+{
+    $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
+}
 $proc->importStyleSheet($xsl); // attach the xsl rules
 
 //if ($_SERVER['argc'] >= 4)
 //{
-  if (is_dir($_SERVER['argv'][3]))
-  {
-
-    if (!$proc->setParameter('', 'base.dir', $_SERVER['argv'][3]))
-      echo "setting param base.dir KO\n";
-  }
-  else
-  {
-    //echo "{$_SERVER['argv'][3]} is not a dir\n";
-  }
+    if (is_dir($_SERVER['argv'][3]))
+    {
+        if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3])))
+            echo "setting param base.dir KO\n";
+    }
+    else
+    {
+        //echo "{$_SERVER['argv'][3]} is not a dir\n";
+    }
 //}
-  $out = $proc->transformToXML($xml);
-  if (!is_dir($_SERVER['argv'][3]))
+
+$out = $proc->transformToXML($xml);
+if (!is_dir($_SERVER['argv'][3]))
     file_put_contents($_SERVER['argv'][3], $out);
 
 echo "OK\n";