3 class HTMLPurifier_Printer_HTMLDefinition
extends HTMLPurifier_Printer
7 * Instance of HTMLPurifier_HTMLDefinition, for easy access
11 public function render($config) {
13 $this->config
=& $config;
15 $this->def
= $config->getHTMLDefinition();
17 $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
19 $ret .= $this->renderDoctype();
20 $ret .= $this->renderEnvironment();
21 $ret .= $this->renderContentSets();
22 $ret .= $this->renderInfo();
24 $ret .= $this->end('div');
30 * Renders the Doctype table
32 protected function renderDoctype() {
33 $doctype = $this->def
->doctype
;
35 $ret .= $this->start('table');
36 $ret .= $this->element('caption', 'Doctype');
37 $ret .= $this->row('Name', $doctype->name
);
38 $ret .= $this->row('XML', $doctype->xml ?
'Yes' : 'No');
39 $ret .= $this->row('Default Modules', implode($doctype->modules
, ', '));
40 $ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules
, ', '));
41 $ret .= $this->end('table');
47 * Renders environment table, which is miscellaneous info
49 protected function renderEnvironment() {
54 $ret .= $this->start('table');
55 $ret .= $this->element('caption', 'Environment');
57 $ret .= $this->row('Parent of fragment', $def->info_parent
);
58 $ret .= $this->renderChildren($def->info_parent_def
->child
);
59 $ret .= $this->row('Block wrap name', $def->info_block_wrapper
);
61 $ret .= $this->start('tr');
62 $ret .= $this->element('th', 'Global attributes');
63 $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr
),0,0);
64 $ret .= $this->end('tr');
66 $ret .= $this->start('tr');
67 $ret .= $this->element('th', 'Tag transforms');
69 foreach ($def->info_tag_transform
as $old => $new) {
70 $new = $this->getClass($new, 'TagTransform_');
71 $list[] = "<$old> with $new";
73 $ret .= $this->element('td', $this->listify($list));
74 $ret .= $this->end('tr');
76 $ret .= $this->start('tr');
77 $ret .= $this->element('th', 'Pre-AttrTransform');
78 $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre
));
79 $ret .= $this->end('tr');
81 $ret .= $this->start('tr');
82 $ret .= $this->element('th', 'Post-AttrTransform');
83 $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post
));
84 $ret .= $this->end('tr');
86 $ret .= $this->end('table');
91 * Renders the Content Sets table
93 protected function renderContentSets() {
95 $ret .= $this->start('table');
96 $ret .= $this->element('caption', 'Content Sets');
97 foreach ($this->def
->info_content_sets
as $name => $lookup) {
98 $ret .= $this->heavyHeader($name);
99 $ret .= $this->start('tr');
100 $ret .= $this->element('td', $this->listifyTagLookup($lookup));
101 $ret .= $this->end('tr');
103 $ret .= $this->end('table');
108 * Renders the Elements ($info) table
110 protected function renderInfo() {
112 $ret .= $this->start('table');
113 $ret .= $this->element('caption', 'Elements ($info)');
114 ksort($this->def
->info
);
115 $ret .= $this->heavyHeader('Allowed tags', 2);
116 $ret .= $this->start('tr');
117 $ret .= $this->element('td', $this->listifyTagLookup($this->def
->info
), array('colspan' => 2));
118 $ret .= $this->end('tr');
119 foreach ($this->def
->info
as $name => $def) {
120 $ret .= $this->start('tr');
121 $ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
122 $ret .= $this->end('tr');
123 $ret .= $this->start('tr');
124 $ret .= $this->element('th', 'Inline content');
125 $ret .= $this->element('td', $def->descendants_are_inline ?
'Yes' : 'No');
126 $ret .= $this->end('tr');
127 if (!empty($def->excludes
)) {
128 $ret .= $this->start('tr');
129 $ret .= $this->element('th', 'Excludes');
130 $ret .= $this->element('td', $this->listifyTagLookup($def->excludes
));
131 $ret .= $this->end('tr');
133 if (!empty($def->attr_transform_pre
)) {
134 $ret .= $this->start('tr');
135 $ret .= $this->element('th', 'Pre-AttrTransform');
136 $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre
));
137 $ret .= $this->end('tr');
139 if (!empty($def->attr_transform_post
)) {
140 $ret .= $this->start('tr');
141 $ret .= $this->element('th', 'Post-AttrTransform');
142 $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post
));
143 $ret .= $this->end('tr');
145 if (!empty($def->auto_close
)) {
146 $ret .= $this->start('tr');
147 $ret .= $this->element('th', 'Auto closed by');
148 $ret .= $this->element('td', $this->listifyTagLookup($def->auto_close
));
149 $ret .= $this->end('tr');
151 $ret .= $this->start('tr');
152 $ret .= $this->element('th', 'Allowed attributes');
153 $ret .= $this->element('td',$this->listifyAttr($def->attr
), array(), 0);
154 $ret .= $this->end('tr');
156 if (!empty($def->required_attr
)) {
157 $ret .= $this->row('Required attributes', $this->listify($def->required_attr
));
160 $ret .= $this->renderChildren($def->child
);
162 $ret .= $this->end('table');
167 * Renders a row describing the allowed children of an element
168 * @param $def HTMLPurifier_ChildDef of pertinent element
170 protected function renderChildren($def) {
171 $context = new HTMLPurifier_Context();
173 $ret .= $this->start('tr');
176 if (isset($def->elements
)) {
177 if ($def->type
== 'strictblockquote') {
178 $def->validateChildren(array(), $this->config
, $context);
180 $elements = $def->elements
;
182 if ($def->type
== 'chameleon') {
183 $attr['rowspan'] = 2;
184 } elseif ($def->type
== 'empty') {
186 } elseif ($def->type
== 'table') {
187 $elements = array_flip(array('col', 'caption', 'colgroup', 'thead',
188 'tfoot', 'tbody', 'tr'));
190 $ret .= $this->element('th', 'Allowed children', $attr);
192 if ($def->type
== 'chameleon') {
194 $ret .= $this->element('td',
196 $this->escape($this->listifyTagLookup($def->block
->elements
)),0,0);
197 $ret .= $this->end('tr');
198 $ret .= $this->start('tr');
199 $ret .= $this->element('td',
200 '<em>Inline</em>: ' .
201 $this->escape($this->listifyTagLookup($def->inline
->elements
)),0,0);
203 } elseif ($def->type
== 'custom') {
205 $ret .= $this->element('td', '<em>'.ucfirst($def->type
).'</em>: ' .
209 $ret .= $this->element('td',
210 '<em>'.ucfirst($def->type
).'</em>: ' .
211 $this->escape($this->listifyTagLookup($elements)),0,0);
213 $ret .= $this->end('tr');
218 * Listifies a tag lookup table.
219 * @param $array Tag lookup array in form of array('tagname' => true)
221 protected function listifyTagLookup($array) {
224 foreach ($array as $name => $discard) {
225 if ($name !== '#PCDATA' && !isset($this->def
->info
[$name])) continue;
228 return $this->listify($list);
232 * Listifies a list of objects by retrieving class names and internal state
233 * @param $array List of objects
234 * @todo Also add information about internal state
236 protected function listifyObjectList($array) {
239 foreach ($array as $discard => $obj) {
240 $list[] = $this->getClass($obj, 'AttrTransform_');
242 return $this->listify($list);
246 * Listifies a hash of attributes to AttrDef classes
247 * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
249 protected function listifyAttr($array) {
252 foreach ($array as $name => $obj) {
253 if ($obj === false) continue;
254 $list[] = "$name = <i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
256 return $this->listify($list);
260 * Creates a heavy header row
262 protected function heavyHeader($text, $num = 1) {
264 $ret .= $this->start('tr');
265 $ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
266 $ret .= $this->end('tr');
272 // vim: et sw=4 sts=4