Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / Printer / HTMLDefinition.php
bloba677c58bf64df1472d1e846c05acbd9f3070e36c
1 <?php
3 require_once 'HTMLPurifier/Printer.php';
5 class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
8 /**
9 * Instance of HTMLPurifier_HTMLDefinition, for easy access
11 var $def;
13 function render($config) {
14 $ret = '';
15 $this->config =& $config;
17 $this->def = $config->getHTMLDefinition();
18 $def =& $this->def;
20 $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
21 $ret .= $this->start('table');
22 $ret .= $this->element('caption', 'Environment');
24 $ret .= $this->row('Parent of fragment', $def->info_parent);
25 $ret .= $this->renderChildren($def->info_parent_def->child);
26 $ret .= $this->row('Block wrap name', $def->info_block_wrapper);
28 $ret .= $this->start('tr');
29 $ret .= $this->element('th', 'Global attributes');
30 $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0);
31 $ret .= $this->end('tr');
33 $ret .= $this->start('tr');
34 $ret .= $this->element('th', 'Tag transforms');
35 $list = array();
36 foreach ($def->info_tag_transform as $old => $new) {
37 $new = $this->getClass($new, 'TagTransform_');
38 $list[] = "<$old> with $new";
40 $ret .= $this->element('td', $this->listify($list));
41 $ret .= $this->end('tr');
43 $ret .= $this->start('tr');
44 $ret .= $this->element('th', 'Pre-AttrTransform');
45 $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre));
46 $ret .= $this->end('tr');
48 $ret .= $this->start('tr');
49 $ret .= $this->element('th', 'Post-AttrTransform');
50 $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post));
51 $ret .= $this->end('tr');
53 $ret .= $this->end('table');
56 $ret .= $this->renderInfo();
59 $ret .= $this->end('div');
61 return $ret;
64 /**
65 * Renders the Elements ($info) table
67 function renderInfo() {
68 $ret = '';
69 $ret .= $this->start('table');
70 $ret .= $this->element('caption', 'Elements ($info)');
71 ksort($this->def->info);
72 $ret .= $this->start('tr');
73 $ret .= $this->element('th', 'Allowed tags', array('colspan' => 2, 'class' => 'heavy'));
74 $ret .= $this->end('tr');
75 $ret .= $this->start('tr');
76 $ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2));
77 $ret .= $this->end('tr');
78 foreach ($this->def->info as $name => $def) {
79 $ret .= $this->start('tr');
80 $ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
81 $ret .= $this->end('tr');
82 $ret .= $this->start('tr');
83 $ret .= $this->element('th', 'Inline content');
84 $ret .= $this->element('td', $def->descendants_are_inline ? 'Yes' : 'No');
85 $ret .= $this->end('tr');
86 if (!empty($def->excludes)) {
87 $ret .= $this->start('tr');
88 $ret .= $this->element('th', 'Excludes');
89 $ret .= $this->element('td', $this->listifyTagLookup($def->excludes));
90 $ret .= $this->end('tr');
92 if (!empty($def->attr_transform_pre)) {
93 $ret .= $this->start('tr');
94 $ret .= $this->element('th', 'Pre-AttrTransform');
95 $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre));
96 $ret .= $this->end('tr');
98 if (!empty($def->attr_transform_post)) {
99 $ret .= $this->start('tr');
100 $ret .= $this->element('th', 'Post-AttrTransform');
101 $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post));
102 $ret .= $this->end('tr');
104 if (!empty($def->auto_close)) {
105 $ret .= $this->start('tr');
106 $ret .= $this->element('th', 'Auto closed by');
107 $ret .= $this->element('td', $this->listifyTagLookup($def->auto_close));
108 $ret .= $this->end('tr');
110 $ret .= $this->start('tr');
111 $ret .= $this->element('th', 'Allowed attributes');
112 $ret .= $this->element('td',$this->listifyAttr($def->attr),0,0);
113 $ret .= $this->end('tr');
115 $ret .= $this->renderChildren($def->child);
117 $ret .= $this->end('table');
118 return $ret;
121 /**
122 * Renders a row describing the allowed children of an element
123 * @param $def HTMLPurifier_ChildDef of pertinent element
125 function renderChildren($def) {
126 $context = new HTMLPurifier_Context();
127 $ret = '';
128 $ret .= $this->start('tr');
129 $elements = array();
130 $attr = array();
131 if (isset($def->elements)) {
132 if ($def->type == 'strictblockquote') {
133 $def->validateChildren(array(), $this->config, $context);
135 $elements = $def->elements;
136 } elseif ($def->type == 'chameleon') {
137 $attr['rowspan'] = 2;
138 } elseif ($def->type == 'empty') {
139 $elements = array();
140 } elseif ($def->type == 'table') {
141 $elements = array_flip(array('col', 'caption', 'colgroup', 'thead',
142 'tfoot', 'tbody', 'tr'));
144 $ret .= $this->element('th', 'Allowed children', $attr);
146 if ($def->type == 'chameleon') {
148 $ret .= $this->element('td',
149 '<em>Block</em>: ' .
150 $this->escape($this->listifyTagLookup($def->block->elements)),0,0);
151 $ret .= $this->end('tr');
152 $ret .= $this->start('tr');
153 $ret .= $this->element('td',
154 '<em>Inline</em>: ' .
155 $this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
157 } else {
158 $ret .= $this->element('td',
159 '<em>'.ucfirst($def->type).'</em>: ' .
160 $this->escape($this->listifyTagLookup($elements)),0,0);
162 $ret .= $this->end('tr');
163 return $ret;
166 /**
167 * Listifies a tag lookup table.
168 * @param $array Tag lookup array in form of array('tagname' => true)
170 function listifyTagLookup($array) {
171 ksort($array);
172 $list = array();
173 foreach ($array as $name => $discard) {
174 if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue;
175 $list[] = $name;
177 return $this->listify($list);
181 * Listifies a list of objects by retrieving class names and internal state
182 * @param $array List of objects
183 * @todo Also add information about internal state
185 function listifyObjectList($array) {
186 ksort($array);
187 $list = array();
188 foreach ($array as $discard => $obj) {
189 $list[] = $this->getClass($obj, 'AttrTransform_');
191 return $this->listify($list);
195 * Listifies a hash of attributes to AttrDef classes
196 * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
198 function listifyAttr($array) {
199 ksort($array);
200 $list = array();
201 foreach ($array as $name => $obj) {
202 if ($obj === false) continue;
203 $list[] = "$name&nbsp;=&nbsp;<i>" . $this->getClass($obj, 'AttrDef_') . '</i>';
205 return $this->listify($list);