3 class HTMLPurifier_Printer_HTMLDefinition
extends HTMLPurifier_Printer
7 * @type HTMLPurifier_HTMLDefinition, for easy access
12 * @param HTMLPurifier_Config $config
15 public function render($config)
18 $this->config
=& $config;
20 $this->def
= $config->getHTMLDefinition();
22 $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
24 $ret .= $this->renderDoctype();
25 $ret .= $this->renderEnvironment();
26 $ret .= $this->renderContentSets();
27 $ret .= $this->renderInfo();
29 $ret .= $this->end('div');
35 * Renders the Doctype table
38 protected function renderDoctype()
40 $doctype = $this->def
->doctype
;
42 $ret .= $this->start('table');
43 $ret .= $this->element('caption', 'Doctype');
44 $ret .= $this->row('Name', $doctype->name
);
45 $ret .= $this->row('XML', $doctype->xml ?
'Yes' : 'No');
46 $ret .= $this->row('Default Modules', implode($doctype->modules
, ', '));
47 $ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules
, ', '));
48 $ret .= $this->end('table');
54 * Renders environment table, which is miscellaneous info
57 protected function renderEnvironment()
63 $ret .= $this->start('table');
64 $ret .= $this->element('caption', 'Environment');
66 $ret .= $this->row('Parent of fragment', $def->info_parent
);
67 $ret .= $this->renderChildren($def->info_parent_def
->child
);
68 $ret .= $this->row('Block wrap name', $def->info_block_wrapper
);
70 $ret .= $this->start('tr');
71 $ret .= $this->element('th', 'Global attributes');
72 $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr
), null, 0);
73 $ret .= $this->end('tr');
75 $ret .= $this->start('tr');
76 $ret .= $this->element('th', 'Tag transforms');
78 foreach ($def->info_tag_transform
as $old => $new) {
79 $new = $this->getClass($new, 'TagTransform_');
80 $list[] = "<$old> with $new";
82 $ret .= $this->element('td', $this->listify($list));
83 $ret .= $this->end('tr');
85 $ret .= $this->start('tr');
86 $ret .= $this->element('th', 'Pre-AttrTransform');
87 $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre
));
88 $ret .= $this->end('tr');
90 $ret .= $this->start('tr');
91 $ret .= $this->element('th', 'Post-AttrTransform');
92 $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post
));
93 $ret .= $this->end('tr');
95 $ret .= $this->end('table');
100 * Renders the Content Sets table
103 protected function renderContentSets()
106 $ret .= $this->start('table');
107 $ret .= $this->element('caption', 'Content Sets');
108 foreach ($this->def
->info_content_sets
as $name => $lookup) {
109 $ret .= $this->heavyHeader($name);
110 $ret .= $this->start('tr');
111 $ret .= $this->element('td', $this->listifyTagLookup($lookup));
112 $ret .= $this->end('tr');
114 $ret .= $this->end('table');
119 * Renders the Elements ($info) table
122 protected function renderInfo()
125 $ret .= $this->start('table');
126 $ret .= $this->element('caption', 'Elements ($info)');
127 ksort($this->def
->info
);
128 $ret .= $this->heavyHeader('Allowed tags', 2);
129 $ret .= $this->start('tr');
130 $ret .= $this->element('td', $this->listifyTagLookup($this->def
->info
), array('colspan' => 2));
131 $ret .= $this->end('tr');
132 foreach ($this->def
->info
as $name => $def) {
133 $ret .= $this->start('tr');
134 $ret .= $this->element('th', "<$name>", array('class' => 'heavy', 'colspan' => 2));
135 $ret .= $this->end('tr');
136 $ret .= $this->start('tr');
137 $ret .= $this->element('th', 'Inline content');
138 $ret .= $this->element('td', $def->descendants_are_inline ?
'Yes' : 'No');
139 $ret .= $this->end('tr');
140 if (!empty($def->excludes
)) {
141 $ret .= $this->start('tr');
142 $ret .= $this->element('th', 'Excludes');
143 $ret .= $this->element('td', $this->listifyTagLookup($def->excludes
));
144 $ret .= $this->end('tr');
146 if (!empty($def->attr_transform_pre
)) {
147 $ret .= $this->start('tr');
148 $ret .= $this->element('th', 'Pre-AttrTransform');
149 $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre
));
150 $ret .= $this->end('tr');
152 if (!empty($def->attr_transform_post
)) {
153 $ret .= $this->start('tr');
154 $ret .= $this->element('th', 'Post-AttrTransform');
155 $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post
));
156 $ret .= $this->end('tr');
158 if (!empty($def->auto_close
)) {
159 $ret .= $this->start('tr');
160 $ret .= $this->element('th', 'Auto closed by');
161 $ret .= $this->element('td', $this->listifyTagLookup($def->auto_close
));
162 $ret .= $this->end('tr');
164 $ret .= $this->start('tr');
165 $ret .= $this->element('th', 'Allowed attributes');
166 $ret .= $this->element('td', $this->listifyAttr($def->attr
), array(), 0);
167 $ret .= $this->end('tr');
169 if (!empty($def->required_attr
)) {
170 $ret .= $this->row('Required attributes', $this->listify($def->required_attr
));
173 $ret .= $this->renderChildren($def->child
);
175 $ret .= $this->end('table');
180 * Renders a row describing the allowed children of an element
181 * @param HTMLPurifier_ChildDef $def HTMLPurifier_ChildDef of pertinent element
184 protected function renderChildren($def)
186 $context = new HTMLPurifier_Context();
188 $ret .= $this->start('tr');
191 if (isset($def->elements
)) {
192 if ($def->type
== 'strictblockquote') {
193 $def->validateChildren(array(), $this->config
, $context);
195 $elements = $def->elements
;
197 if ($def->type
== 'chameleon') {
198 $attr['rowspan'] = 2;
199 } elseif ($def->type
== 'empty') {
201 } elseif ($def->type
== 'table') {
202 $elements = array_flip(
214 $ret .= $this->element('th', 'Allowed children', $attr);
216 if ($def->type
== 'chameleon') {
218 $ret .= $this->element(
221 $this->escape($this->listifyTagLookup($def->block
->elements
)),
225 $ret .= $this->end('tr');
226 $ret .= $this->start('tr');
227 $ret .= $this->element(
229 '<em>Inline</em>: ' .
230 $this->escape($this->listifyTagLookup($def->inline
->elements
)),
235 } elseif ($def->type
== 'custom') {
237 $ret .= $this->element(
239 '<em>' . ucfirst($def->type
) . '</em>: ' .
244 $ret .= $this->element(
246 '<em>' . ucfirst($def->type
) . '</em>: ' .
247 $this->escape($this->listifyTagLookup($elements)),
252 $ret .= $this->end('tr');
257 * Listifies a tag lookup table.
258 * @param array $array Tag lookup array in form of array('tagname' => true)
261 protected function listifyTagLookup($array)
265 foreach ($array as $name => $discard) {
266 if ($name !== '#PCDATA' && !isset($this->def
->info
[$name])) {
271 return $this->listify($list);
275 * Listifies a list of objects by retrieving class names and internal state
276 * @param array $array List of objects
278 * @todo Also add information about internal state
280 protected function listifyObjectList($array)
284 foreach ($array as $obj) {
285 $list[] = $this->getClass($obj, 'AttrTransform_');
287 return $this->listify($list);
291 * Listifies a hash of attributes to AttrDef classes
292 * @param array $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
295 protected function listifyAttr($array)
299 foreach ($array as $name => $obj) {
300 if ($obj === false) {
303 $list[] = "$name = <i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
305 return $this->listify($list);
309 * Creates a heavy header row
310 * @param string $text
314 protected function heavyHeader($text, $num = 1)
317 $ret .= $this->start('tr');
318 $ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
319 $ret .= $this->end('tr');
324 // vim: et sw=4 sts=4