diff --git a/configdoc/generate.php b/configdoc/generate.php index 1f0d9fa5..f6b0c64f 100644 --- a/configdoc/generate.php +++ b/configdoc/generate.php @@ -15,17 +15,18 @@ TODO: - add blurbs to ToC */ -if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.'); -error_reporting(E_ALL); // probably not possible to use E_STRICT +if (version_compare(PHP_VERSION, '5.2.0', '<')) exit('PHP 5.2.0 or greater required.'); +error_reporting(E_ALL | E_STRICT); -define('HTMLPURIFIER_SCHEMA_STRICT', true); // description data needs to be collected +echo 'Currently broken!'; +exit; // load dual-libraries -set_include_path(realpath('../library') . PATH_SEPARATOR . get_include_path() ); -require_once '../library/HTMLPurifier.includes.php'; -require_once 'library/ConfigDoc.auto.php'; +require_once '../extras/HTMLPurifierExtras.auto.php'; +require_once '../library/HTMLPurifier.auto.php'; -$purifier = HTMLPurifier::getInstance(array( +// setup HTML Purifier singleton +HTMLPurifier::getInstance(array( 'AutoFormat.PurifierLinkify' => true )); @@ -34,11 +35,16 @@ $style = 'plain'; // use $_GET in the future $configdoc = new ConfigDoc(); $output = $configdoc->generate($schema, $style); +if (!$output) { + echo "Error in generating files\n"; + exit(1); +} + // write out file_put_contents("$style.html", $output); if (php_sapi_name() != 'cli') { - // output = instant feedback + // output (instant feedback if it's a browser) echo $output; } else { echo 'Files generated successfully.'; diff --git a/configdoc/library/ConfigDoc.auto.php b/configdoc/library/ConfigDoc.auto.php deleted file mode 100644 index 0dab4700..00000000 --- a/configdoc/library/ConfigDoc.auto.php +++ /dev/null @@ -1,9 +0,0 @@ -purify($html); - $dom_html = $document->createDocumentFragment(); - $dom_html->appendXML($html); - $dom_div = $document->createElement('div'); - $dom_div->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); - $dom_div->appendChild($dom_html); - $node->appendChild($dom_div); - } - -} - diff --git a/configdoc/library/ConfigDoc.php b/extras/ConfigDoc.php similarity index 91% rename from configdoc/library/ConfigDoc.php rename to extras/ConfigDoc.php index 980900d7..572c0f7a 100644 --- a/configdoc/library/ConfigDoc.php +++ b/extras/ConfigDoc.php @@ -1,9 +1,5 @@ appendChild($this->generateHTMLDiv($html)); + } + + /** + * Generates an HTML div that can contain arbitrary markup + */ + protected function generateHTMLDiv($html) { + $purifier = HTMLPurifier::getInstance(); + $html = $purifier->purify($html); + $dom_html = $this->ownerDocument->createDocumentFragment(); + $dom_html->appendXML($html); + $dom_div = $this->ownerDocument->createElement('div'); + $dom_div->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); + $dom_div->appendChild($dom_html); + return $dom_div; + } + +} diff --git a/configdoc/library/ConfigDoc/HTMLXSLTProcessor.php b/extras/ConfigDoc/HTMLXSLTProcessor.php similarity index 79% rename from configdoc/library/ConfigDoc/HTMLXSLTProcessor.php rename to extras/ConfigDoc/HTMLXSLTProcessor.php index f4722295..833f514c 100644 --- a/configdoc/library/ConfigDoc/HTMLXSLTProcessor.php +++ b/extras/ConfigDoc/HTMLXSLTProcessor.php @@ -1,8 +1,7 @@ xsltProcessor = new XSLTProcessor(); + public function __construct($proc = false) { + if ($proc === false) $proc = new XSLTProcessor(); + $this->xsltProcessor = $proc; } /** - * Imports stylesheet for processor to use - * @param $xsl XSLT DOM tree, or filename of the XSL transformation - * @return bool Success? + * @note Allows a string $xsl filename to be passed */ public function importStylesheet($xsl) { if (is_string($xsl)) { @@ -71,5 +69,12 @@ class ConfigDoc_HTMLXSLTProcessor } } + /** + * Forward any other calls to the XSLT processor + */ + public function __call($name, $arguments) { + call_user_func_array(array($this->xsltProcessor, $name), $arguments); + } + } diff --git a/extras/ConfigDoc/XMLSerializer.php b/extras/ConfigDoc/XMLSerializer.php new file mode 100644 index 00000000..a28b6706 --- /dev/null +++ b/extras/ConfigDoc/XMLSerializer.php @@ -0,0 +1,11 @@ +assertIsA($dom->createElement('a'), 'ConfigDoc_DOM_Element'); + } + +} diff --git a/tests/test_files.php b/tests/test_files.php index 207bd27f..9db2c0cc 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -134,7 +134,9 @@ if ($csstidy_location) { // ConfigDoc auxiliary library -// ... none yet +if (version_compare(PHP_VERSION, '5.2', '>=')) { + $test_files[] = 'ConfigDoc/DOM/DocumentTest.php'; +} // FSTools auxiliary library