0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Reorganize configdoc, but it's still broken.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1577 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-02-25 21:21:12 +00:00
parent 002fe649f7
commit a2d044f58d
14 changed files with 98 additions and 65 deletions

View File

@ -15,17 +15,18 @@ TODO:
- add blurbs to ToC - add blurbs to ToC
*/ */
if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.'); if (version_compare(PHP_VERSION, '5.2.0', '<')) exit('PHP 5.2.0 or greater required.');
error_reporting(E_ALL); // probably not possible to use E_STRICT error_reporting(E_ALL | E_STRICT);
define('HTMLPURIFIER_SCHEMA_STRICT', true); // description data needs to be collected echo 'Currently broken!';
exit;
// load dual-libraries // load dual-libraries
set_include_path(realpath('../library') . PATH_SEPARATOR . get_include_path() ); require_once '../extras/HTMLPurifierExtras.auto.php';
require_once '../library/HTMLPurifier.includes.php'; require_once '../library/HTMLPurifier.auto.php';
require_once 'library/ConfigDoc.auto.php';
$purifier = HTMLPurifier::getInstance(array( // setup HTML Purifier singleton
HTMLPurifier::getInstance(array(
'AutoFormat.PurifierLinkify' => true 'AutoFormat.PurifierLinkify' => true
)); ));
@ -34,11 +35,16 @@ $style = 'plain'; // use $_GET in the future
$configdoc = new ConfigDoc(); $configdoc = new ConfigDoc();
$output = $configdoc->generate($schema, $style); $output = $configdoc->generate($schema, $style);
if (!$output) {
echo "Error in generating files\n";
exit(1);
}
// write out // write out
file_put_contents("$style.html", $output); file_put_contents("$style.html", $output);
if (php_sapi_name() != 'cli') { if (php_sapi_name() != 'cli') {
// output = instant feedback // output (instant feedback if it's a browser)
echo $output; echo $output;
} else { } else {
echo 'Files generated successfully.'; echo 'Files generated successfully.';

View File

@ -1,9 +0,0 @@
<?php
/**
* This is a stub include that automatically configures the include path.
*/
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
require_once 'ConfigDoc.php';

View File

@ -1,31 +0,0 @@
<?php
/**
* The XMLSerializer hierarchy of classes consist of classes that take
* objects and serialize them into XML, specifically DOM, form; this
* super-class contains convenience functions for those classes.
*/
class ConfigDoc_XMLSerializer
{
/**
* Appends a div containing HTML into a node
* @param $document Base document node belongs to
* @param $node Node to append to
* @param $html HTML to place inside div to append
* @todo Place this directly in DOMNode, using registerNodeClass to
* override.
*/
protected function appendHTMLDiv($document, $node, $html) {
$purifier = HTMLPurifier::getInstance();
$html = $purifier->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);
}
}

View File

@ -1,9 +1,5 @@
<?php <?php
require_once 'ConfigDoc/HTMLXSLTProcessor.php';
require_once 'ConfigDoc/XMLSerializer/Types.php';
require_once 'ConfigDoc/XMLSerializer/ConfigSchema.php';
/** /**
* Facade class for configuration documentation system * Facade class for configuration documentation system
*/ */

View File

@ -0,0 +1,13 @@
<?php
class ConfigDoc_DOM_Document extends DOMDocument
{
/**
* Register our classes
*/
public function __construct($version = "1.0", $encoding = "UTF-8") {
parent::__construct($version, $encoding);
parent::registerNodeClass('DOMDocument', 'ConfigDoc_DOM_Document');
parent::registerNodeClass('DOMElement', 'ConfigDoc_DOM_Element');
}
}

View File

@ -0,0 +1,27 @@
<?php
class ConfigDoc_DOM_Element extends DOMElement
{
/**
* Appends an HTML div to this node
*/
public function appendHTMLDiv($html) {
$this->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;
}
}

View File

@ -1,8 +1,7 @@
<?php <?php
/** /**
* Special XSLT processor specifically for HTML documents. Loosely * Decorator/extender XSLT processor specifically for HTML documents.
* based off of XSLTProcessor, but does not inherit from that class
*/ */
class ConfigDoc_HTMLXSLTProcessor class ConfigDoc_HTMLXSLTProcessor
{ {
@ -12,14 +11,13 @@ class ConfigDoc_HTMLXSLTProcessor
*/ */
protected $xsltProcessor; protected $xsltProcessor;
public function __construct() { public function __construct($proc = false) {
$this->xsltProcessor = new XSLTProcessor(); if ($proc === false) $proc = new XSLTProcessor();
$this->xsltProcessor = $proc;
} }
/** /**
* Imports stylesheet for processor to use * @note Allows a string $xsl filename to be passed
* @param $xsl XSLT DOM tree, or filename of the XSL transformation
* @return bool Success?
*/ */
public function importStylesheet($xsl) { public function importStylesheet($xsl) {
if (is_string($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);
}
} }

View File

@ -0,0 +1,11 @@
<?php
/**
* The XMLSerializer hierarchy of classes consist of classes that take
* objects and convert them to XML form.
*/
class ConfigDoc_XMLSerializer
{
}

View File

@ -1,7 +1,5 @@
<?php <?php
require_once 'ConfigDoc/XMLSerializer.php';
class ConfigDoc_XMLSerializer_ConfigSchema extends ConfigDoc_XMLSerializer class ConfigDoc_XMLSerializer_ConfigSchema extends ConfigDoc_XMLSerializer
{ {

View File

@ -1,7 +1,5 @@
<?php <?php
require_once 'ConfigDoc/XMLSerializer.php';
class ConfigDoc_XMLSerializer_Types extends ConfigDoc_XMLSerializer class ConfigDoc_XMLSerializer_Types extends ConfigDoc_XMLSerializer
{ {

View File

@ -3,6 +3,11 @@
/** /**
* @file * @file
* Convenience file that registers autoload handler for HTML Purifier. * Convenience file that registers autoload handler for HTML Purifier.
*
* @warning
* This autoloader does not contain the compatibility code seen in
* HTMLPurifier_Bootstrap; the user is expected to make any necessary
* changes to use this library.
*/ */
if (function_exists('spl_autoload_register')) { if (function_exists('spl_autoload_register')) {

View File

@ -16,7 +16,8 @@ class HTMLPurifierExtras
public static function getPath($class) { public static function getPath($class) {
if ( if (
strncmp('FSTools', $class, 7) !== 0 strncmp('FSTools', $class, 7) !== 0 &&
strncmp('ConfigDoc', $class, 9) !== 0
) return false; ) return false;
// Custom implementations can go here // Custom implementations can go here
// Standard implementation: // Standard implementation:

View File

@ -0,0 +1,11 @@
<?php
class ConfigDoc_DOM_DocumentTest extends UnitTestCase
{
function testOverload() {
$dom = new ConfigDoc_DOM_Document();
$this->assertIsA($dom->createElement('a'), 'ConfigDoc_DOM_Element');
}
}

View File

@ -134,7 +134,9 @@ if ($csstidy_location) {
// ConfigDoc auxiliary library // ConfigDoc auxiliary library
// ... none yet if (version_compare(PHP_VERSION, '5.2', '>=')) {
$test_files[] = 'ConfigDoc/DOM/DocumentTest.php';
}
// FSTools auxiliary library // FSTools auxiliary library