Add pakefile as replacement for makefile
[plcapi.git] / doc / convert.php
1 <?php
2 /**
3  * Script used to convert docbook source to human readable docs.
4  *
5  * @copyright (c) 2007-2015 G. Giunta
6  */
7 if ($_SERVER['argc'] < 4) {
8     die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
9 } else {
10     echo "Starting xsl conversion process...\n";
11 }
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 }
19 if (!file_exists($xss)) {
20     die("KO: file $xss cannot be found\n");
21 }
22
23 // Load the XML source
24 $xml = new DOMDocument();
25 $xml->load($doc);
26 $xsl = new DOMDocument();
27 $xsl->load($xss);
28
29 // Configure the transformer
30 $proc = new XSLTProcessor();
31 if (version_compare(PHP_VERSION, '5.4', "<")) {
32     if (defined('XSL_SECPREF_WRITE_FILE')) {
33         ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
34     }
35 } else {
36     // the php online docs only mention setSecurityPrefs, but somehow some installs have setSecurityPreferences...
37     if (method_exists('XSLTProcessor', 'setSecurityPrefs')) {
38         $proc->setSecurityPrefs(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
39     } else {
40         $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
41     }
42 }
43 $proc->importStyleSheet($xsl); // attach the xsl rules
44
45 //if ($_SERVER['argc'] >= 4)
46 //{
47 if (is_dir($_SERVER['argv'][3])) {
48     if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3]))) {
49         echo "setting param base.dir KO\n";
50     }
51 } else {
52     //echo "{$_SERVER['argv'][3]} is not a dir\n";
53 }
54 //}
55
56 $out = $proc->transformToXML($xml);
57 if (!is_dir($_SERVER['argv'][3])) {
58     file_put_contents($_SERVER['argv'][3], $out);
59 }
60
61 echo "OK\n";