+ foreach (self::$tools as $name => $binary) {
+ if (isset($cliOpts[$name])) {
+ self::$tools[$name] = $cliOpts[$name];
+ }
+ }
+
+ foreach (self::$options as $name => $value) {
+ if (isset($cliOpts[$name])) {
+ self::$options[$name] = $cliOpts[$name];
+ }
+ }
+
+ //pake_echo('---'.self::$libVersion.'---');
+ }
+
+ public static function tool($name)
+ {
+ return self::$tools[$name];
+ }
+
+ public static function option($name)
+ {
+ return self::$options[$name];
+ }
+
+ /**
+ * @param string $inFile
+ * @param string $xssFile
+ * @param string $outFileOrDir
+ * @throws \Exception
+ */
+ public static function applyXslt($inFile, $xssFile, $outFileOrDir)
+ {
+
+ if (!file_exists($inFile)) {
+ throw new \Exception("File $inFile cannot be found");
+ }
+ if (!file_exists($xssFile)) {
+ throw new \Exception("File $xssFile cannot be found");
+ }
+
+ // Load the XML source
+ $xml = new \DOMDocument();
+ $xml->load($inFile);
+ $xsl = new \DOMDocument();
+ $xsl->load($xssFile);
+
+ // Configure the transformer
+ $processor = 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 {
+ // the php online docs only mention setSecurityPrefs, but somehow some installs have setSecurityPreferences...
+ if (method_exists('XSLTProcessor', 'setSecurityPrefs')) {
+ $processor->setSecurityPrefs(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
+ } else {
+ $processor->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
+ }
+ }
+ $processor->importStyleSheet($xsl); // attach the xsl rules
+
+ if (is_dir($outFileOrDir)) {
+ if (!$processor->setParameter('', 'base.dir', realpath($outFileOrDir))) {
+ echo "setting param base.dir KO\n";
+ }
+ }
+
+ $out = $processor->transformToXML($xml);
+
+ if (!is_dir($outFileOrDir)) {
+ file_put_contents($outFileOrDir, $out);
+ }
+ }
+
+ public static function highlightPhpInHtml($content)
+ {
+ $startTag = '<pre class="programlisting">';
+ $endTag = '</pre>';
+
+ //$content = file_get_contents($inFile);
+ $last = 0;
+ $out = '';
+ while (($start = strpos($content, $startTag, $last)) !== false) {
+ $end = strpos($content, $endTag, $start);
+ $code = substr($content, $start + strlen($startTag), $end - $start - strlen($startTag));
+ if ($code[strlen($code) - 1] == "\n") {
+ $code = substr($code, 0, -1);
+ }
+
+ $code = str_replace(array('>', '<'), array('>', '<'), $code);
+ $code = highlight_string('<?php ' . $code, true);
+ $code = str_replace('<span style="color: #0000BB"><?php <br />', '<span style="color: #0000BB">', $code);
+
+ $out = $out . substr($content, $last, $start + strlen($startTag) - $last) . $code . $endTag;
+ $last = $end + strlen($endTag);
+ }
+ $out .= substr($content, $last, strlen($content));
+
+ return $out;