@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @copyright (c) 2007-2014 G. Giunta |
6 | 6 | */ |
7 | 7 | |
8 | -if ($_SERVER['argc'] < 4) |
|
8 | +if ($_SERVER['argc']<4) |
|
9 | 9 | die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n"); |
10 | 10 | else |
11 | 11 | echo "Starting xsl conversion process...\n"; |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | |
27 | 27 | // Configure the transformer |
28 | 28 | $proc = new XSLTProcessor; |
29 | -if (version_compare(PHP_VERSION,'5.4',"<")) |
|
29 | +if (version_compare(PHP_VERSION, '5.4', "<")) |
|
30 | 30 | { |
31 | - if(defined('XSL_SECPREF_WRITE_FILE')) |
|
31 | + if (defined('XSL_SECPREF_WRITE_FILE')) |
|
32 | 32 | ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE); |
33 | 33 | } |
34 | 34 | else |
@@ -5,18 +5,21 @@ discard block |
||
5 | 5 | * @copyright (c) 2007-2014 G. Giunta |
6 | 6 | */ |
7 | 7 | |
8 | -if ($_SERVER['argc'] < 4) |
|
8 | +if ($_SERVER['argc'] < 4) { |
|
9 | 9 | die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n"); |
10 | -else |
|
10 | +} else { |
|
11 | 11 | echo "Starting xsl conversion process...\n"; |
12 | +} |
|
12 | 13 | |
13 | 14 | $doc = $_SERVER['argv'][1]; |
14 | 15 | $xss = $_SERVER['argv'][2]; |
15 | 16 | |
16 | -if (!file_exists($doc)) |
|
17 | +if (!file_exists($doc)) { |
|
17 | 18 | die("KO: file $doc cannot be found\n"); |
18 | -if (!file_exists($xss)) |
|
19 | +} |
|
20 | +if (!file_exists($xss)) { |
|
19 | 21 | die("KO: file $xss cannot be found\n"); |
22 | +} |
|
20 | 23 | |
21 | 24 | // Load the XML source |
22 | 25 | $xml = new DOMDocument; |
@@ -28,10 +31,10 @@ discard block |
||
28 | 31 | $proc = new XSLTProcessor; |
29 | 32 | if (version_compare(PHP_VERSION,'5.4',"<")) |
30 | 33 | { |
31 | - if(defined('XSL_SECPREF_WRITE_FILE')) |
|
32 | - ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE); |
|
33 | -} |
|
34 | -else |
|
34 | + if(defined('XSL_SECPREF_WRITE_FILE')) { |
|
35 | + ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE); |
|
36 | + } |
|
37 | + } else |
|
35 | 38 | { |
36 | 39 | $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE); |
37 | 40 | } |
@@ -41,18 +44,19 @@ discard block |
||
41 | 44 | //{ |
42 | 45 | if (is_dir($_SERVER['argv'][3])) |
43 | 46 | { |
44 | - if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3]))) |
|
45 | - echo "setting param base.dir KO\n"; |
|
46 | - } |
|
47 | - else |
|
47 | + if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3]))) { |
|
48 | + echo "setting param base.dir KO\n"; |
|
49 | + } |
|
50 | + } else |
|
48 | 51 | { |
49 | 52 | //echo "{$_SERVER['argv'][3]} is not a dir\n"; |
50 | 53 | } |
51 | 54 | //} |
52 | 55 | |
53 | 56 | $out = $proc->transformToXML($xml); |
54 | -if (!is_dir($_SERVER['argv'][3])) |
|
57 | +if (!is_dir($_SERVER['argv'][3])) { |
|
55 | 58 | file_put_contents($_SERVER['argv'][3], $out); |
59 | +} |
|
56 | 60 | |
57 | 61 | echo "OK\n"; |
58 | 62 | ?> |
59 | 63 | \ No newline at end of file |
@@ -8,29 +8,29 @@ discard block |
||
8 | 8 | |
9 | 9 | function highlight($file) |
10 | 10 | { |
11 | - $starttag = '<pre class="programlisting">'; |
|
12 | - $endtag = '</pre>'; |
|
11 | + $starttag = '<pre class="programlisting">'; |
|
12 | + $endtag = '</pre>'; |
|
13 | 13 | |
14 | - $content = file_get_contents($file); |
|
15 | - $last = 0; |
|
16 | - $out = ''; |
|
17 | - while(($start = strpos($content, $starttag, $last)) !== false) |
|
18 | - { |
|
14 | + $content = file_get_contents($file); |
|
15 | + $last = 0; |
|
16 | + $out = ''; |
|
17 | + while(($start = strpos($content, $starttag, $last)) !== false) |
|
18 | + { |
|
19 | 19 | $end = strpos($content, $endtag, $start); |
20 | - $code = substr($content, $start+strlen($starttag), $end-$start-strlen($starttag)); |
|
21 | - if ($code[strlen($code)-1] == "\n") { |
|
22 | - $code = substr($code, 0, -1); |
|
23 | - } |
|
20 | + $code = substr($content, $start+strlen($starttag), $end-$start-strlen($starttag)); |
|
21 | + if ($code[strlen($code)-1] == "\n") { |
|
22 | + $code = substr($code, 0, -1); |
|
23 | + } |
|
24 | 24 | //var_dump($code); |
25 | - $code = str_replace(array('>', '<'), array('>', '<'), $code); |
|
25 | + $code = str_replace(array('>', '<'), array('>', '<'), $code); |
|
26 | 26 | $code = highlight_string('<?php '.$code, true); |
27 | 27 | $code = str_replace('<span style="color: #0000BB"><?php <br />', '<span style="color: #0000BB">', $code); |
28 | 28 | //echo($code); |
29 | 29 | $out = $out . substr($content, $last, $start+strlen($starttag)-$last) . $code . $endtag; |
30 | 30 | $last = $end+strlen($endtag); |
31 | - } |
|
32 | - $out .= substr($content, $last, strlen($content)); |
|
33 | - return $out; |
|
31 | + } |
|
32 | + $out .= substr($content, $last, strlen($content)); |
|
33 | + return $out; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $dir = $argv[1]; |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | $files = scandir($dir); |
39 | 39 | foreach($files as $file) |
40 | 40 | { |
41 | - if (substr($file, -5, 5) == '.html') |
|
42 | - { |
|
43 | - $out = highlight($dir.'/'.$file); |
|
44 | - file_put_contents($dir.'/'.$file, $out); |
|
45 | - } |
|
41 | + if (substr($file, -5, 5) == '.html') |
|
42 | + { |
|
43 | + $out = highlight($dir.'/'.$file); |
|
44 | + file_put_contents($dir.'/'.$file, $out); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | ?> |
49 | 49 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $content = file_get_contents($file); |
15 | 15 | $last = 0; |
16 | 16 | $out = ''; |
17 | - while(($start = strpos($content, $starttag, $last)) !== false) |
|
17 | + while (($start = strpos($content, $starttag, $last)) !== false) |
|
18 | 18 | { |
19 | 19 | $end = strpos($content, $endtag, $start); |
20 | 20 | $code = substr($content, $start+strlen($starttag), $end-$start-strlen($starttag)); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $code = highlight_string('<?php '.$code, true); |
27 | 27 | $code = str_replace('<span style="color: #0000BB"><?php <br />', '<span style="color: #0000BB">', $code); |
28 | 28 | //echo($code); |
29 | - $out = $out . substr($content, $last, $start+strlen($starttag)-$last) . $code . $endtag; |
|
29 | + $out = $out.substr($content, $last, $start+strlen($starttag)-$last).$code.$endtag; |
|
30 | 30 | $last = $end+strlen($endtag); |
31 | 31 | } |
32 | 32 | $out .= substr($content, $last, strlen($content)); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $dir = $argv[1]; |
37 | 37 | |
38 | 38 | $files = scandir($dir); |
39 | -foreach($files as $file) |
|
39 | +foreach ($files as $file) |
|
40 | 40 | { |
41 | 41 | if (substr($file, -5, 5) == '.html') |
42 | 42 | { |