ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HTMLPurifier_ChildDef_Table Class Reference

Definition for tables. More...

+ Inheritance diagram for HTMLPurifier_ChildDef_Table:
+ Collaboration diagram for HTMLPurifier_ChildDef_Table:

Public Member Functions

 __construct ()
 
 validateChildren ($children, $config, $context)
 
- Public Member Functions inherited from HTMLPurifier_ChildDef
 getAllowedElements ($config)
 Get lookup of tag names that should not close this element automatically. More...
 
 validateChildren ($children, $config, $context)
 Validates nodes according to definition and returns modification. More...
 

Data Fields

 $allow_empty = false
 bool More...
 
 $type = 'table'
 string More...
 
 $elements
 array More...
 
- Data Fields inherited from HTMLPurifier_ChildDef
 $type
 Type of child definition, usually right-most part of class name lowercase. More...
 
 $allow_empty
 Indicates whether or not an empty array of children is okay. More...
 
 $elements = array()
 Lookup array of all elements that this definition could possibly allow. More...
 

Detailed Description

Definition for tables.

The general idea is to extract out all of the essential bits, and then reconstruct it later.

This is a bit confusing, because the DTDs and the W3C validators seem to disagree on the appropriate definition. The DTD claims:

 (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)

But actually, the HTML4 spec then has this to say:

 The TBODY start tag is always required except when the table
 contains only one table body and no table head or foot sections.
 The TBODY end tag may always be safely omitted.

So the DTD is kind of wrong. The validator is, unfortunately, kind of on crack.

The definition changed again in XHTML1.1; and in my opinion, this formulation makes the most sense.

 caption?, ( col* | colgroup* ), (( thead?, tfoot?, tbody+ ) | ( tr+ ))

Essentially, we have two modes: thead/tfoot/tbody mode, and tr mode. If we encounter a thead, tfoot or tbody, we are placed in the former mode, and we must wrap any stray tr segments with a tbody. But if we don't run into any of them, just have tr tags is OK.

Definition at line 32 of file Table.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_ChildDef_Table::__construct ( )

Definition at line 57 of file Table.php.

58  {
59  }

Member Function Documentation

◆ validateChildren()

HTMLPurifier_ChildDef_Table::validateChildren (   $children,
  $config,
  $context 
)
Parameters
array$children
HTMLPurifier_Config$config
HTMLPurifier_Context$context
Returns
array

Definition at line 67 of file Table.php.

References $cols, $ret, and array.

68  {
69  if (empty($children)) {
70  return false;
71  }
72 
73  // only one of these elements is allowed in a table
74  $caption = false;
75  $thead = false;
76  $tfoot = false;
77 
78  // whitespace
79  $initial_ws = array();
80  $after_caption_ws = array();
81  $after_thead_ws = array();
82  $after_tfoot_ws = array();
83 
84  // as many of these as you want
85  $cols = array();
86  $content = array();
87 
88  $tbody_mode = false; // if true, then we need to wrap any stray
89  // <tr>s with a <tbody>.
90 
91  $ws_accum =& $initial_ws;
92 
93  foreach ($children as $node) {
94  if ($node instanceof HTMLPurifier_Node_Comment) {
95  $ws_accum[] = $node;
96  continue;
97  }
98  switch ($node->name) {
99  case 'tbody':
100  $tbody_mode = true;
101  // fall through
102  case 'tr':
103  $content[] = $node;
104  $ws_accum =& $content;
105  break;
106  case 'caption':
107  // there can only be one caption!
108  if ($caption !== false) break;
109  $caption = $node;
110  $ws_accum =& $after_caption_ws;
111  break;
112  case 'thead':
113  $tbody_mode = true;
114  // XXX This breaks rendering properties with
115  // Firefox, which never floats a <thead> to
116  // the top. Ever. (Our scheme will float the
117  // first <thead> to the top.) So maybe
118  // <thead>s that are not first should be
119  // turned into <tbody>? Very tricky, indeed.
120  if ($thead === false) {
121  $thead = $node;
122  $ws_accum =& $after_thead_ws;
123  } else {
124  // Oops, there's a second one! What
125  // should we do? Current behavior is to
126  // transmutate the first and last entries into
127  // tbody tags, and then put into content.
128  // Maybe a better idea is to *attach
129  // it* to the existing thead or tfoot?
130  // We don't do this, because Firefox
131  // doesn't float an extra tfoot to the
132  // bottom like it does for the first one.
133  $node->name = 'tbody';
134  $content[] = $node;
135  $ws_accum =& $content;
136  }
137  break;
138  case 'tfoot':
139  // see above for some aveats
140  $tbody_mode = true;
141  if ($tfoot === false) {
142  $tfoot = $node;
143  $ws_accum =& $after_tfoot_ws;
144  } else {
145  $node->name = 'tbody';
146  $content[] = $node;
147  $ws_accum =& $content;
148  }
149  break;
150  case 'colgroup':
151  case 'col':
152  $cols[] = $node;
153  $ws_accum =& $cols;
154  break;
155  case '#PCDATA':
156  // How is whitespace handled? We treat is as sticky to
157  // the *end* of the previous element. So all of the
158  // nonsense we have worked on is to keep things
159  // together.
160  if (!empty($node->is_whitespace)) {
161  $ws_accum[] = $node;
162  }
163  break;
164  }
165  }
166 
167  if (empty($content)) {
168  return false;
169  }
170 
171  $ret = $initial_ws;
172  if ($caption !== false) {
173  $ret[] = $caption;
174  $ret = array_merge($ret, $after_caption_ws);
175  }
176  if ($cols !== false) {
177  $ret = array_merge($ret, $cols);
178  }
179  if ($thead !== false) {
180  $ret[] = $thead;
181  $ret = array_merge($ret, $after_thead_ws);
182  }
183  if ($tfoot !== false) {
184  $ret[] = $tfoot;
185  $ret = array_merge($ret, $after_tfoot_ws);
186  }
187 
188  if ($tbody_mode) {
189  // we have to shuffle tr into tbody
190  $current_tr_tbody = null;
191 
192  foreach($content as $node) {
193  switch ($node->name) {
194  case 'tbody':
195  $current_tr_tbody = null;
196  $ret[] = $node;
197  break;
198  case 'tr':
199  if ($current_tr_tbody === null) {
200  $current_tr_tbody = new HTMLPurifier_Node_Element('tbody');
201  $ret[] = $current_tr_tbody;
202  }
203  $current_tr_tbody->children[] = $node;
204  break;
205  case '#PCDATA':
206  //assert($node->is_whitespace);
207  if ($current_tr_tbody === null) {
208  $ret[] = $node;
209  } else {
210  $current_tr_tbody->children[] = $node;
211  }
212  break;
213  }
214  }
215  } else {
216  $ret = array_merge($ret, $content);
217  }
218 
219  return $ret;
220 
221  }
Concrete element node class.
Definition: Element.php:6
Concrete comment node class.
Definition: Comment.php:6
Create styles array
The data for the language used.
$ret
Definition: parser.php:6
$cols
Definition: xhr_table.php:11

Field Documentation

◆ $allow_empty

HTMLPurifier_ChildDef_Table::$allow_empty = false

bool

Definition at line 37 of file Table.php.

◆ $elements

HTMLPurifier_ChildDef_Table::$elements
Initial value:
'tr' => true,
'tbody' => true,
'thead' => true,
'tfoot' => true,
'caption' => true,
'colgroup' => true,
'col' => true
)

array

Definition at line 47 of file Table.php.

◆ $type

HTMLPurifier_ChildDef_Table::$type = 'table'

string

Definition at line 42 of file Table.php.


The documentation for this class was generated from the following file: