diff options
author | Andrew Dolgov <[email protected]> | 2009-06-22 13:56:49 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2009-06-22 13:56:49 +0400 |
commit | f45a286b8d62f710b519a98c7d4b75a0c34d5d10 (patch) | |
tree | 0c310b7b9d44e12fac1cd11e1563c4cef9b5eab2 /lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder | |
parent | 5c4461432c290ad4863fd7dc4107121db59b298c (diff) |
strip_tags_long: use htmlpurifier to properly reformat html content
Diffstat (limited to 'lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder')
-rwxr-xr-x | lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php | 52 | ||||
-rwxr-xr-x | lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/Xml.php | 108 |
2 files changed, 160 insertions, 0 deletions
diff --git a/lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php b/lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php new file mode 100755 index 000000000..987f547bc --- /dev/null +++ b/lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php @@ -0,0 +1,52 @@ +<?php + +/** + * Converts HTMLPurifier_ConfigSchema_Interchange to our runtime + * representation used to perform checks on user configuration. + */ +class HTMLPurifier_ConfigSchema_Builder_ConfigSchema +{ + + public function build($interchange) { + $schema = new HTMLPurifier_ConfigSchema(); + foreach ($interchange->namespaces as $n) { + $schema->addNamespace($n->namespace); + } + foreach ($interchange->directives as $d) { + $schema->add( + $d->id->namespace, + $d->id->directive, + $d->default, + $d->type, + $d->typeAllowsNull + ); + if ($d->allowed !== null) { + $schema->addAllowedValues( + $d->id->namespace, + $d->id->directive, + $d->allowed + ); + } + foreach ($d->aliases as $alias) { + $schema->addAlias( + $alias->namespace, + $alias->directive, + $d->id->namespace, + $d->id->directive + ); + } + if ($d->valueAliases !== null) { + $schema->addValueAliases( + $d->id->namespace, + $d->id->directive, + $d->valueAliases + ); + } + } + $schema->postProcess(); + return $schema; + } + +} + +// vim: et sw=4 sts=4 diff --git a/lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/Xml.php b/lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/Xml.php new file mode 100755 index 000000000..51bcab78c --- /dev/null +++ b/lib/htmlpurifier/library/HTMLPurifier/ConfigSchema/Builder/Xml.php @@ -0,0 +1,108 @@ +<?php + +/** + * Converts HTMLPurifier_ConfigSchema_Interchange to an XML format, + * which can be further processed to generate documentation. + */ +class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter +{ + + protected $interchange; + + protected function writeHTMLDiv($html) { + $this->startElement('div'); + + $purifier = HTMLPurifier::getInstance(); + $html = $purifier->purify($html); + $this->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); + $this->writeRaw($html); + + $this->endElement(); // div + } + + protected function export($var) { + if ($var === array()) return 'array()'; + return var_export($var, true); + } + + public function build($interchange) { + // global access, only use as last resort + $this->interchange = $interchange; + + $this->setIndent(true); + $this->startDocument('1.0', 'UTF-8'); + $this->startElement('configdoc'); + $this->writeElement('title', $interchange->name); + + foreach ($interchange->namespaces as $namespace) { + $this->buildNamespace($namespace); + } + + $this->endElement(); // configdoc + $this->flush(); + } + + public function buildNamespace($namespace) { + $this->startElement('namespace'); + $this->writeAttribute('id', $namespace->namespace); + + $this->writeElement('name', $namespace->namespace); + $this->startElement('description'); + $this->writeHTMLDiv($namespace->description); + $this->endElement(); // description + + foreach ($this->interchange->directives as $directive) { + if ($directive->id->namespace !== $namespace->namespace) continue; + $this->buildDirective($directive); + } + + $this->endElement(); // namespace + } + + public function buildDirective($directive) { + $this->startElement('directive'); + $this->writeAttribute('id', $directive->id->toString()); + + $this->writeElement('name', $directive->id->directive); + + $this->startElement('aliases'); + foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString()); + $this->endElement(); // aliases + + $this->startElement('constraints'); + if ($directive->version) $this->writeElement('version', $directive->version); + $this->startElement('type'); + if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes'); + $this->text($directive->type); + $this->endElement(); // type + if ($directive->allowed) { + $this->startElement('allowed'); + foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value); + $this->endElement(); // allowed + } + $this->writeElement('default', $this->export($directive->default)); + $this->writeAttribute('xml:space', 'preserve'); + if ($directive->external) { + $this->startElement('external'); + foreach ($directive->external as $project) $this->writeElement('project', $project); + $this->endElement(); + } + $this->endElement(); // constraints + + if ($directive->deprecatedVersion) { + $this->startElement('deprecated'); + $this->writeElement('version', $directive->deprecatedVersion); + $this->writeElement('use', $directive->deprecatedUse->toString()); + $this->endElement(); // deprecated + } + + $this->startElement('description'); + $this->writeHTMLDiv($directive->description); + $this->endElement(); // description + + $this->endElement(); // directive + } + +} + +// vim: et sw=4 sts=4 |