Fix leftovers from branch merging; remove more php closing tags; bump up requirements...
[plcapi.git] / doc / convert.php
1 <?php
2 /**
3  * Script used to convert docbook source to human readable docs
4  *
5  * @copyright (c) 2007-2014 G. Giunta
6  */
7
8 if ($_SERVER['argc'] < 4)
9     die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
10 else
11     echo "Starting xsl conversion process...\n";
12
13 $doc = $_SERVER['argv'][1];
14 $xss = $_SERVER['argv'][2];
15
16 if (!file_exists($doc))
17     die("KO: file $doc cannot be found\n");
18 if (!file_exists($xss))
19     die("KO: file $xss cannot be found\n");
20
21 // Load the XML source
22 $xml = new DOMDocument;
23 $xml->load($doc);
24 $xsl = new DOMDocument;
25 $xsl->load($xss);
26
27 // Configure the transformer
28 $proc = new XSLTProcessor;
29 if (version_compare(PHP_VERSION,'5.4',"<"))
30 {
31     if(defined('XSL_SECPREF_WRITE_FILE'))
32         ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
33 }
34 else
35 {
36     $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
37 }
38 $proc->importStyleSheet($xsl); // attach the xsl rules
39
40 //if ($_SERVER['argc'] >= 4)
41 //{
42     if (is_dir($_SERVER['argv'][3]))
43     {
44         if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3])))
45             echo "setting param base.dir KO\n";
46     }
47     else
48     {
49         //echo "{$_SERVER['argv'][3]} is not a dir\n";
50     }
51 //}
52
53 $out = $proc->transformToXML($xml);
54 if (!is_dir($_SERVER['argv'][3]))
55     file_put_contents($_SERVER['argv'][3], $out);
56
57 echo "OK\n";