mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-12 18:26:19 +02:00
[1.7.0] Update HTMLDefinition printer with some of the new attributes.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1192 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
/**
|
||||
* Represents a document type, contains information on which modules
|
||||
* need to be loaded.
|
||||
* @note This class is inspected by Printer_HTMLDefinition->renderDoctype.
|
||||
* If structure changes, please update that function.
|
||||
*/
|
||||
class HTMLPurifier_Doctype
|
||||
{
|
||||
|
@ -3,6 +3,8 @@
|
||||
/**
|
||||
* Structure that stores an HTML element definition. Used by
|
||||
* HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
|
||||
* @note This class is inspected by HTMLPurifier_Printer_HTMLDefinition.
|
||||
* Please update that class too.
|
||||
*/
|
||||
class HTMLPurifier_ElementDef
|
||||
{
|
||||
|
@ -145,8 +145,8 @@ HTMLPurifier_ConfigSchema::define(
|
||||
* Purifier internals. Many of them, however, are public, and may be
|
||||
* edited by userspace code to tweak the behavior of HTMLDefinition.
|
||||
*
|
||||
* HTMLPurifier_Printer_HTMLDefinition is a notable exception to this
|
||||
* rule: in the interest of comprehensiveness, it will sniff everything.
|
||||
* @note This class is inspected by Printer_HTMLDefinition; please
|
||||
* update that class if things here change.
|
||||
*/
|
||||
class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
{
|
||||
|
@ -15,9 +15,44 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$this->config =& $config;
|
||||
|
||||
$this->def = $config->getHTMLDefinition();
|
||||
$def =& $this->def;
|
||||
|
||||
$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
|
||||
|
||||
$ret .= $this->renderDoctype();
|
||||
$ret .= $this->renderEnvironment();
|
||||
$ret .= $this->renderContentSets();
|
||||
$ret .= $this->renderInfo();
|
||||
|
||||
$ret .= $this->end('div');
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Doctype table
|
||||
*/
|
||||
function renderDoctype() {
|
||||
$doctype = $this->def->doctype;
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Doctype');
|
||||
$ret .= $this->row('Name', $doctype->name);
|
||||
$ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No');
|
||||
$ret .= $this->row('Default Modules', implode($doctype->modules, ', '));
|
||||
$ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', '));
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders environment table, which is miscellaneous info
|
||||
*/
|
||||
function renderEnvironment() {
|
||||
$def = $this->def;
|
||||
|
||||
$ret = '';
|
||||
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Environment');
|
||||
|
||||
@ -51,13 +86,22 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
$ret .= $this->end('table');
|
||||
|
||||
|
||||
$ret .= $this->renderInfo();
|
||||
|
||||
|
||||
$ret .= $this->end('div');
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Content Sets table
|
||||
*/
|
||||
function renderContentSets() {
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Content Sets');
|
||||
foreach ($this->def->info_content_sets as $name => $lookup) {
|
||||
$ret .= $this->heavyHeader($name);
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('td', $this->listifyTagLookup($lookup));
|
||||
$ret .= $this->end('tr');
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@ -69,15 +113,13 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Elements ($info)');
|
||||
ksort($this->def->info);
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Allowed tags', array('colspan' => 2, 'class' => 'heavy'));
|
||||
$ret .= $this->end('tr');
|
||||
$ret .= $this->heavyHeader('Allowed tags', 2);
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2));
|
||||
$ret .= $this->end('tr');
|
||||
foreach ($this->def->info as $name => $def) {
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
|
||||
$ret .= $this->element('th', "<$name>" . ($def->safe ? '' : ' (unsafe)'), array('class'=>'heavy' . ($def->safe ? '' : ' unsafe'), 'colspan' => 2));
|
||||
$ret .= $this->end('tr');
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Inline content');
|
||||
@ -109,9 +151,13 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
}
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Allowed attributes');
|
||||
$ret .= $this->element('td',$this->listifyAttr($def->attr),0,0);
|
||||
$ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0);
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
if (!empty($def->required_attr)) {
|
||||
$ret .= $this->row('Required attributes', $this->listify($def->required_attr));
|
||||
}
|
||||
|
||||
$ret .= $this->renderChildren($def->child);
|
||||
}
|
||||
$ret .= $this->end('table');
|
||||
@ -154,6 +200,11 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
'<em>Inline</em>: ' .
|
||||
$this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
|
||||
|
||||
} elseif ($def->type == 'custom') {
|
||||
|
||||
$ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' .
|
||||
$def->dtd_regex);
|
||||
|
||||
} else {
|
||||
$ret .= $this->element('td',
|
||||
'<em>'.ucfirst($def->type).'</em>: ' .
|
||||
@ -205,6 +256,17 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
return $this->listify($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a heavy header row
|
||||
*/
|
||||
function heavyHeader($text, $num = 1) {
|
||||
$ret = '';
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
|
||||
$ret .= $this->end('tr');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user