2008-04-22 01:58:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts HTMLPurifier_ConfigSchema_Interchange to an XML format,
|
|
|
|
* which can be further processed to generate documentation.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
protected $interchange;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
protected function writeHTMLDiv($html) {
|
|
|
|
$this->startElement('div');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$purifier = HTMLPurifier::getInstance();
|
|
|
|
$html = $purifier->purify($html);
|
|
|
|
$this->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
|
|
$this->writeRaw($html);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->endElement(); // div
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
protected function export($var) {
|
|
|
|
if ($var === array()) return 'array()';
|
|
|
|
return var_export($var, true);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
public function build($interchange) {
|
|
|
|
// global access, only use as last resort
|
|
|
|
$this->interchange = $interchange;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->setIndent(true);
|
|
|
|
$this->startDocument('1.0', 'UTF-8');
|
|
|
|
$this->startElement('configdoc');
|
|
|
|
$this->writeElement('title', $interchange->name);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
foreach ($interchange->namespaces as $namespace) {
|
|
|
|
$this->buildNamespace($namespace);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->endElement(); // configdoc
|
|
|
|
$this->flush();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
public function buildNamespace($namespace) {
|
|
|
|
$this->startElement('namespace');
|
|
|
|
$this->writeAttribute('id', $namespace->namespace);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->writeElement('name', $namespace->namespace);
|
|
|
|
$this->startElement('description');
|
|
|
|
$this->writeHTMLDiv($namespace->description);
|
|
|
|
$this->endElement(); // description
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
foreach ($this->interchange->directives as $directive) {
|
|
|
|
if ($directive->id->namespace !== $namespace->namespace) continue;
|
|
|
|
$this->buildDirective($directive);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->endElement(); // namespace
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
public function buildDirective($directive) {
|
|
|
|
$this->startElement('directive');
|
|
|
|
$this->writeAttribute('id', $directive->id->toString());
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->writeElement('name', $directive->id->directive);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->startElement('aliases');
|
|
|
|
foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString());
|
|
|
|
$this->endElement(); // aliases
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->startElement('constraints');
|
2008-04-22 02:19:40 +00:00
|
|
|
if ($directive->version) $this->writeElement('version', $directive->version);
|
2008-04-26 03:14:01 +00:00
|
|
|
$this->startElement('type');
|
|
|
|
if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes');
|
|
|
|
$this->text($directive->type);
|
|
|
|
$this->endElement(); // type
|
2008-04-22 01:58:06 +00:00
|
|
|
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');
|
2008-04-22 06:40:04 +00:00
|
|
|
if ($directive->external) {
|
|
|
|
$this->startElement('external');
|
|
|
|
foreach ($directive->external as $project) $this->writeElement('project', $project);
|
|
|
|
$this->endElement();
|
|
|
|
}
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->endElement(); // constraints
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 02:19:40 +00:00
|
|
|
if ($directive->deprecatedVersion) {
|
|
|
|
$this->startElement('deprecated');
|
|
|
|
$this->writeElement('version', $directive->deprecatedVersion);
|
|
|
|
$this->writeElement('use', $directive->deprecatedUse->toString());
|
|
|
|
$this->endElement(); // deprecated
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->startElement('description');
|
|
|
|
$this->writeHTMLDiv($directive->description);
|
|
|
|
$this->endElement(); // description
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
$this->endElement(); // directive
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-04-22 01:58:06 +00:00
|
|
|
}
|