add a loadHTML5() function that ignores 'invalid' tag names when loading content
[php-utility-classes.git] / classes / document.php-class
1 <?php
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 class ExtendedDocument extends DOMDocument {
7   // ExtendedDocument PHP class
8   // this extends the general PHP DOM Document class to simplify some usual constructs
9   //
10   // function __construct([$version], [$encoding])
11   //   CONSTRUCTOR
12   //   construct a new DOM Document that uses our element definitions
13   //
14   // static function initHTML5([$doc])
15   //   initialize as an HTML5 document and return references to its basic elements.
16   //     If a $doc is handed over (an ExtendedDocument or a derived class), load the content into that document.
17   //     returns an associative array with the following elements: 'html', 'head', 'title', 'body'
18   //
19   // public function loadHTML5($source) {
20   //   A version of loadHTML() - see DOMDocument documentation - that is made for loading HTML5 and not emitting warnings/errors for unknown elements.
21   //     returns true on success, false otherwise, just like loadHTML5.
22   //
23   // public function appendElement($name, [$value])
24   //   appends a DOMDocument::createElement() as a child of this document (see there for params)
25   //     returns the new child
26   //
27   // public function appendElementXML($name, $xmldata)
28   //   appends a DOMDocument::createElement() with the given name as a child of this document,
29   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
30   //     returns the new child
31   //
32   // public function appendLink($target, [$value], [$title])
33   //   appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
34   //     returns the new child
35   //
36   // public function appendImage($src, [$alt_text])
37   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
38   //     returns the new child
39   //
40   // public function appendForm($action, $method, $name, [$id])
41   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
42   //     returns the new child
43   //
44   // public function appendFormDiv($action, $method, $name, [$id])
45   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
46   //     returns an HTML <div> that is a child of the new child
47   //
48   // public function appendInputHidden($name, $value)
49   //   appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
50   //     returns the new child
51   //
52   // public function appendInputText($name, $maxlength, $size, [$id], [$value])
53   //   appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
54   //     returns the new child
55   //
56   // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
57   //   appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
58   //     returns the new child
59   //
60   // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
61   //   appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
62   //     returns the new child
63   //
64   // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
65   //   appends an ExtendedDocument::createElementInputRange() as a child of this document (see there for params)
66   //     returns the new child
67   //
68   // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
69   //   appends an ExtendedDocument::createElementInputUrl() as a child of this document (see there for params)
70   //     returns the new child
71   //
72   // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
73   //   appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
74   //     returns the new child
75   //
76   // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
77   //   appends an ExtendedDocument::createElementInputTel() as a child of this document (see there for params)
78   //     returns the new child
79   //
80   // public function appendInputDate($name, [$id], [$min], [$max], [$value])
81   //   appends an ExtendedDocument::createElementInputDate() as a child of this document (see there for params)
82   //     returns the new child
83   //
84   // public function appendInputTime($name, [$id], [$min], [$max], [$value])
85   //   appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params)
86   //     returns the new child
87   //
88   // public function appendInputColor($name, [$id], [$value])
89   //   appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params)
90   //     returns the new child
91   //
92   // public function appendInputRadio($name, $id, $value, $checked)
93   //   appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
94   //     returns the new child
95   //
96   // public function appendInputCheckbox($name, $id, $value, $checked)
97   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
98   //     returns the new child
99   //
100   // public function appendInputFile($name, $id, $accept)
101   //   appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
102   //     returns the new child
103   //
104   // public function appendInputSubmit($value)
105   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
106   //     returns the new child
107   //
108   // public function appendButton($value, $onclick = null)
109   //   appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
110   //     returns the new child
111   //
112   // public function appendTextArea($name, $columns, $rows, [$id], [$value])
113   //   appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
114   //     returns the new child
115   //
116   // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
117   //   appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
118   //     returns the new child
119   //
120   // public function appendElementOption($key, $desc, [$selected])
121   //   appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
122   //     returns the new child
123   //
124   // public function appendLabel($for_id, $value)
125   //   appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
126   //     returns the new child
127   //
128   // public function appendText($text)
129   //   appends a DOMDocument::createTextNode() as a child of this document (see there for params)
130   //     returns the new child
131   //
132   // public function appendLinebreak()
133   //   appends a <br> as a child of this document
134   //     returns the new child
135   //
136   // public function appendEntity($name)
137   //   appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
138   //     returns the new child
139   //
140   // public function appendComment($comment_data)
141   //   appends a DOMDocument::createComment() as a child of this document (see there for params)
142   //     returns the new child
143   //
144   // public function appendClonedElement($dom_element, [$deep])
145   //   appends a clone of the given DOMElement as a child of this document
146   //     the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
147   //     returns the new child
148   //
149   // public function appendHTMLMarkup($htmldata, [$parentNode])
150   //   appends a representation of the HTML data as children of the given parent node, by default this document
151   //     NO return value!
152   //
153   // public function appendXMLMarkup($xmldata, [$parentNode])
154   //   appends a representation of the XML data as children of the given parent node, by default this document
155   //     NO return value!
156   //
157   // public function appendStyleElement($styledata)
158   //   appends an ExtendedDocument::createElementStyle() as a child of this document (see there for params)
159   //     returns the new child
160   //
161   // public function appendJSElement($jsdata)
162   //   appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
163   //     returns the new child
164   //
165   // public function appendJSFile($jsURL, [$defer], [$async])
166   //   appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
167   //     returns the new child
168   //
169   // public function createElementLink($target, [$value], [$title])
170   //   returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value as well as (optional) title attribute
171   //
172   // public function createElementImage($src, [$alt_text])
173   //   returns an ExtendedElement that is an HTML <img> with the given src and alt attributes (set to '' by default)
174   //
175   // public function createElementForm($action, $method, $name)
176   //   returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
177   //   with the given action, method, and name
178   //
179   // public function createElementInputHidden($name, $value)
180   //   returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
181   //
182   // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
183   //   returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
184   //   and optionally id and value
185   //
186   // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
187   //   returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
188   //   and optionally id and value
189   //
190   // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
191   //   returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
192   //   and optionally id and value
193   //
194   // public function createElementInputRange($name, $id, $min, $max, [$step], [$value])
195   //   returns an ExtendedElement that is an HTML <input> of type 'range' with the given name, id, min, max,
196   //   and optionally step and value
197   //
198   // public function createElementInputUrl($name, $maxlength, $size, [$id], [$value])
199   //   returns an ExtendedElement that is an HTML <input> of type 'url' with the given name, maxlength, size,
200   //   and optionally id and value
201   //
202   // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
203   //   returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
204   //   and optionally id and value
205   //
206   // public function createElementInputTel($name, $maxlength, $size, [$id], [$value])
207   //   returns an ExtendedElement that is an HTML <input> of type 'tel' with the given name, maxlength, size,
208   //   and optionally id and value
209   //
210   // public function createElementInputDate($name, [$id], [$min], [$max], [$value])
211   //   returns an ExtendedElement that is an HTML <input> of type 'date' with the given name,
212   //   and optionally id, min, max, and value
213   //
214   // public function createElementInputTime($name, [$id], [$min], [$max], [$value])
215   //   returns an ExtendedElement that is an HTML <input> of type 'time' with the given name,
216   //   and optionally id, min, max, and value
217   //
218   // public function createElementInputColor($name, [$id], [$value])
219   //   returns an ExtendedElement that is an HTML <input> of type 'color' with the given name,
220   //   and optionally id and value
221   //
222   // public function createElementInputRadio($name, $id, $value, $checked)
223   //   returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
224   //   checked state
225   //
226   // public function createElementInputCheckbox($name, $id, $value, $checked)
227   //   returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
228   //   checked state
229   //
230   // public function createElementInputFile($name, $id, $accept)
231   //   returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
232   //
233   // public function createElementInputSubmit($value)
234   //   returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
235   //
236   // public function createElementButton($value, $onclick = null)
237   //   returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
238   //
239   // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
240   //   returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
241   //   and optionally id and value
242   //
243   // public function createElementSelect($name, [$id], [$options], [$default], [$strictmatch])
244   //   returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
245   //   array of options (key => description) and key of the by-default selected entry (matched including type when strictmatch is true)
246   //
247   // public function createElementOption($key, $desc, [$selected])
248   //   returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
249   //   and optionally bool that tells if the entry is selected
250   //
251   // public function createElementLabel($for_id, $value)
252   //   returns an ExtendedElement that is an HTML <label> with the given 'for' and value
253   //
254   // public function createElementStyle($styledata)
255   //   returns an ExtendedElement that is an HTML <style> of CSS type with the style data inside
256   //
257   // public function createElementJS($jsdata)
258   //   returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
259   //
260   // public function createElementJSFile($jsURL, [$defer], [$async])
261   //   returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
262   //     $defer and $async are boolean attributes that set if the script should be executed after parsing but before onload, and if it should be loaded asynchronously.
263
264   function __construct($version = '1.0', $encoding = 'utf-8') {
265     // make sure the default DOMDocument constructor runs
266     parent::__construct($version, $encoding);
267     $this->registerNodeClass('DOMElement', 'ExtendedElement');
268     $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
269   }
270
271   static function initHTML5($doc = null) {
272     if (is_null($doc)) { $doc = new ExtendedDocument(); }
273     $doc->loadHTML5('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
274
275     // Created basic HTML document structure.
276     $root = $doc->getElementsByTagName('html')->item(0);
277     $head = $root->appendElement('head');
278     $title = $head->appendElement('title');
279     $body = $root->appendElement('body');
280
281     return array('document' => $doc,
282                  'html' => $root,
283                  'head' => $head,
284                  'title' => $title,
285                  'body' => $body);
286   }
287
288   public function loadHTML5($source) {
289     // Do our own handling of DOMDocument error reporting so we can ignore "unknown tags" which are usually fine in HTML5.
290     libxml_use_internal_errors(true);
291     if (!preg_match('/^\s*<?xml /', $source)) {
292       // Add an XML declaration to force DOMDocument into UTF-8 mode.
293       $source = '<?xml version="1.0" encoding="utf-8"?>'."\n".$source;
294     }
295     $result = $this->loadHTML($source);
296     // Handle DOMDocument loading errors, throw away warnings on unknown tags as HTML5 allows all kinds.
297     $errseverity = array(LIBXML_ERR_WARNING => 'Warning', LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal');
298     foreach (libxml_get_errors() as $error) {
299       // $error is a libXMLError, see https://www.php.net/manual/en/class.libxmlerror.php
300       // See http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors for error numbers
301       if ($error->code != 801) { // XML_HTML_UNKNOWN_TAG gets no output, should not exist for HTML5.
302         trigger_error($errseverity[$error->level].' loading HTML5: '.$error->message.' (code '.$error->code.'), line: '.$error->line, E_USER_WARNING);
303       }
304     }
305     libxml_clear_errors();
306     libxml_use_internal_errors(false);
307     return $result;
308   }
309
310   public function appendElement($name, $value = '') {
311     return $this->appendChild($this->createElement($name, $value));
312   }
313   public function appendElementXML($name, $xmldata) {
314     $aelem = $this->appendChild($this->createElement($name));
315     $aelem->appendXMLMarkup($xmldata);
316     //$aelem->appendChild($this->createXMLFragment($xmldata));
317     return $aelem;
318   }
319   public function appendLink($target, $value = '', $title = null) {
320     return $this->appendChild($this->createElementLink($target, $value, $title));
321   }
322   public function appendImage($src, $alt_text = '') {
323     return $this->appendChild($this->createElementImage($src, $alt_text));
324   }
325   public function appendForm($action, $method, $name, $id = null) {
326     return $this->appendChild($this->createElementForm($action, $method, $name, $id));
327   }
328   public function appendFormDiv($action, $method, $name, $id = null) {
329     $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
330     return $formelem->appendElement('div');
331   }
332   public function appendInputHidden($name, $value) {
333     return $this->appendChild($this->createElementInputHidden($name, $value));
334   }
335   public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
336     return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
337   }
338   public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
339     return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
340   }
341   public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
342     return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
343   }
344   public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
345     return $this->appendChild($this->createElementInputRange($name, $id, $min, $max, $step, $value));
346   }
347   public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
348     return $this->appendChild($this->createElementInputUrl($name, $maxlength, $size, $id, $value));
349   }
350   public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
351     return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
352   }
353   public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
354     return $this->appendChild($this->createElementInputTel($name, $maxlength, $size, $id, $value));
355   }
356   public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
357     return $this->appendChild($this->createElementInputDate($name, $id, $min, $max, $value));
358   }
359   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
360     return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value));
361   }
362   public function appendInputColor($name, $id = null, $value = null) {
363     return $this->appendChild($this->createElementInputColor($name, $id, $value));
364   }
365   public function appendInputRadio($name, $id, $value, $checked) {
366     return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
367   }
368   public function appendInputCheckbox($name, $id, $value, $checked) {
369     return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
370   }
371   public function appendInputFile($name, $id, $accept) {
372     return $this->appendChild($this->createElementInputFile($name, $id, $accept));
373   }
374   public function appendInputSubmit($value) {
375     return $this->appendChild($this->createElementInputSubmit($value));
376   }
377   public function appendButton($value, $onclick = null) {
378     return $this->appendChild($this->createElementButton($value, $onclick));
379   }
380   public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
381     return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
382   }
383   public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
384     return $this->appendChild($this->createElementSelect($name, $id, $options, $default, $strictmatch));
385   }
386   public function appendElementOption($key, $desc, $selected = false) {
387     return $this->appendChild($this->createElementOption($key, $desc, $selected));
388   }
389   public function appendLabel($for_id, $value) {
390     return $this->appendChild($this->createElementLabel($for_id, $value));
391   }
392   public function appendText($text) {
393     return $this->appendChild($this->createTextNode($text));
394   }
395   public function appendLinebreak() {
396     return $this->appendChild($this->createElement('br'));
397   }
398   public function appendEntity($name) {
399     return $this->appendChild($this->createEntityReference($name));
400   }
401   public function appendComment($comment_data) {
402     return $this->appendChild($this->createComment($comment_data));
403   }
404   public function appendClonedElement($dom_element, $deep = true) {
405     return $this->appendChild($dom_element->cloneNode($deep));
406   }
407   public function appendStyleElement($styledata) {
408     return $this->appendChild($this->createElementStyle($styledata));
409   }
410   public function appendJSElement($jsdata) {
411     return $this->appendChild($this->createElementJS($jsdata));
412   }
413   public function appendJSFile($jsURL, $defer = false, $async = false) {
414     return $this->appendChild($this->createElementJSFile($jsURL, $defer, $async));
415   }
416
417   public function appendHTMLMarkup($htmldata, $parentNode = null) {
418     if (is_null($parentNode)) { $parentNode =& $this; }
419     // Use loadHTML5() to parse and turn the markup into proper HTML.
420     $tmpdoc = new ExtendedDocument;
421     // The XML line is needed to tell the parser that we need UTF-8 parsing.
422     $tmpdoc->loadHTML5('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><body>'.$htmldata.'</body></html>');
423     foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) {
424       $parentNode->appendChild($this->importNode($child, true));
425     }
426   }
427
428   public function appendXMLMarkup($xmldata, $parentNode = null) {
429     if (is_null($parentNode)) { $parentNode =& $this; }
430     $tmpdoc = new ExtendedDocument;
431     $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
432     $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
433     $tmpxml .= '<root>'.$xmldata.'</root>';
434     $tmpdoc->loadXML($tmpxml);
435     foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
436       $parentNode->appendChild($this->importNode($child, true));
437     }
438   }
439
440   public function createElement($name, $value = '') {
441     // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
442     $aelem = parent::createElement($name);
443     if (strlen($value)) { $aelem->appendText($value); }
444     return $aelem;
445   }
446
447   public function createElementLink($target, $value = '', $title = null) {
448     $link = $this->createElement('a', $value);
449     $link->setAttribute('href', $target); // XXX: take care of & etc. in links
450     if (!is_null($title)) { $link->setAttribute('title', $title); }
451     return $link;
452   }
453
454   public function createElementImage($src, $alt_text = '') {
455     $img = $this->createElement('img');
456     $img->setAttribute('src', $src);
457     $img->setAttribute('alt', $alt_text);
458     return $img;
459   }
460
461   public function createElementForm($action, $method, $name, $id = null) {
462     $formelem = $this->createElement('form');
463     $formelem->setAttribute('action', $action);
464     $formelem->setAttribute('method', $method);
465     $formelem->setAttribute('name', $name);
466     if (!is_null($id)) { $formelem->setAttribute('id', $id); }
467     return $formelem;
468   }
469
470   public function createElementInputHidden($name, $value) {
471     $hidden = $this->createElement('input');
472     $hidden->setAttribute('type', 'hidden');
473     $hidden->setAttribute('name', $name);
474     $hidden->setAttribute('value', $value);
475     return $hidden;
476   }
477
478   public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
479     $txfield = $this->createElement('input');
480     $txfield->setAttribute('type', 'text');
481     if (!is_null($id)) { $txfield->setAttribute('id', $id); }
482     $txfield->setAttribute('name', $name);
483     $txfield->setAttribute('maxlength', $maxlength);
484     $txfield->setAttribute('size', $size);
485     if (!is_null($value)) { $txfield->setAttribute('value', $value); }
486     return $txfield;
487   }
488
489   public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
490     $pwfield = $this->createElement('input');
491     $pwfield->setAttribute('type', 'password');
492     if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
493     $pwfield->setAttribute('name', $name);
494     $pwfield->setAttribute('maxlength', $maxlength);
495     $pwfield->setAttribute('size', $size);
496     if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
497     return $pwfield;
498   }
499
500   public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
501     $numfield = $this->createElement('input');
502     $numfield->setAttribute('type', 'number');
503     if (!is_null($id)) { $numfield->setAttribute('id', $id); }
504     $numfield->setAttribute('name', $name);
505     $numfield->setAttribute('maxlength', $maxlength);
506     $numfield->setAttribute('size', $size);
507     if (!is_null($value)) { $numfield->setAttribute('value', $value); }
508     return $numfield;
509   }
510
511   public function createElementInputRange($name, $id, $min, $max, $step = null, $value = null) {
512     $rgfield = $this->createElement('input');
513     $rgfield->setAttribute('type', 'range');
514     if (!is_null($id)) { $rgfield->setAttribute('id', $id); }
515     $rgfield->setAttribute('name', $name);
516     if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
517     if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
518     if (!is_null($step)) { $rgfield->setAttribute('step', $step); }
519     if (!is_null($value)) { $rgfield->setAttribute('value', $value); }
520     return $rgfield;
521   }
522
523   public function createElementInputUrl($name, $maxlength, $size, $id = null, $value = null) {
524     $urlfield = $this->createElement('input');
525     $urlfield->setAttribute('type', 'url');
526     if (!is_null($id)) { $urlfield->setAttribute('id', $id); }
527     $urlfield->setAttribute('name', $name);
528     $urlfield->setAttribute('maxlength', $maxlength);
529     $urlfield->setAttribute('size', $size);
530     if (!is_null($value)) { $urlfield->setAttribute('value', $value); }
531     return $urlfield;
532   }
533
534   public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
535     $mailfield = $this->createElement('input');
536     $mailfield->setAttribute('type', 'email');
537     if (!is_null($id)) { $mailfield->setAttribute('id', $id); }
538     $mailfield->setAttribute('name', $name);
539     $mailfield->setAttribute('maxlength', $maxlength);
540     $mailfield->setAttribute('size', $size);
541     if (!is_null($value)) { $mailfield->setAttribute('value', $value); }
542     return $mailfield;
543   }
544
545   public function createElementInputTel($name, $maxlength, $size, $id = null, $value = null) {
546     $telfield = $this->createElement('input');
547     $telfield->setAttribute('type', 'tel');
548     if (!is_null($id)) { $telfield->setAttribute('id', $id); }
549     $telfield->setAttribute('name', $name);
550     $telfield->setAttribute('maxlength', $maxlength);
551     $telfield->setAttribute('size', $size);
552     if (!is_null($value)) { $telfield->setAttribute('value', $value); }
553     return $telfield;
554   }
555
556   public function createElementInputDate($name, $id = null, $min = null, $max = null, $value = null) {
557     $telfield = $this->createElement('input');
558     $telfield->setAttribute('type', 'date');
559     if (!is_null($id)) { $telfield->setAttribute('id', $id); }
560     if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
561     if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
562     if (!is_null($value)) { $telfield->setAttribute('value', $value); }
563     return $telfield;
564   }
565
566   public function createElementInputTime($name, $id = null, $min = null, $max = null, $value = null) {
567     $telfield = $this->createElement('input');
568     $telfield->setAttribute('type', 'time');
569     if (!is_null($id)) { $telfield->setAttribute('id', $id); }
570     if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
571     if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
572     if (!is_null($value)) { $telfield->setAttribute('value', $value); }
573     return $telfield;
574   }
575
576   public function createElementInputColor($name, $id = null, $value = null) {
577     $colfield = $this->createElement('input');
578     $colfield->setAttribute('type', 'color');
579     if (!is_null($id)) { $colfield->setAttribute('id', $id); }
580     $colfield->setAttribute('name', $name);
581     if (!is_null($value)) { $colfield->setAttribute('value', $value); }
582     return $colfield;
583   }
584
585   public function createElementInputRadio($name, $id, $value, $checked) {
586     $radio = $this->createElement('input');
587     $radio->setAttribute('type', 'radio');
588     $radio->setAttribute('name', $name);
589     if (!is_null($id)) { $radio->setAttribute('id', $id); }
590     $radio->setAttribute('value', $value);
591     if ($checked) { $radio->setAttribute('checked', ''); }
592     return $radio;
593   }
594
595   public function createElementInputCheckbox($name, $id, $value, $checked) {
596     $cbox = $this->createElement('input');
597     $cbox->setAttribute('type', 'checkbox');
598     $cbox->setAttribute('name', $name);
599     if (!is_null($id)) { $cbox->setAttribute('id', $id); }
600     $cbox->setAttribute('value', $value);
601     if ($checked) { $cbox->setAttribute('checked', ''); }
602     return $cbox;
603   }
604
605   public function createElementInputFile($name, $id, $accept) {
606     $fileinput = $this->createElement('input');
607     $fileinput->setAttribute('type', 'file');
608     $fileinput->setAttribute('name', $name);
609     if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
610     $fileinput->setAttribute('accept', $accept);
611     return $fileinput;
612   }
613
614   public function createElementInputSubmit($value) {
615     $submitbtn = $this->createElement('input');
616     $submitbtn->setAttribute('type', 'submit');
617     $submitbtn->setAttribute('value', $value);
618     return $submitbtn;
619   }
620
621   public function createElementButton($value, $onclick = null) {
622     $btn = $this->createElement('input');
623     $btn->setAttribute('type', 'button');
624     $btn->setAttribute('value', $value);
625     if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
626     return $btn;
627   }
628
629   public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
630     $txtarea = $this->createElement('textarea', $value);
631     $txtarea->setAttribute('name', $name);
632     $txtarea->setAttribute('cols', $columns);
633     $txtarea->setAttribute('rows', $rows);
634     if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
635     return $txtarea;
636   }
637
638   public function createElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
639     $select = $this->createElement('select');
640     $select->setAttribute('name', $name);
641     if (!is_null($id)) { $select->setAttribute('id', $id); }
642     foreach ($options as $key => $desc) {
643       $select->appendElementOption($key, $desc, $strictmatch ? ($key === $default) : ($key == $default));
644     }
645     return $select;
646   }
647
648   public function createElementOption($key, $desc, $selected = false) {
649     $option = $this->createElement('option', $desc);
650     $option->setAttribute('value', $key);
651     if ($selected) { $option->setAttribute('selected', ''); }
652     return $option;
653   }
654
655   public function createElementLabel($for_id, $value) {
656     $label = $this->createElement('label', $value);
657     $label->setAttribute('for', $for_id);
658     return $label;
659   }
660
661   public function createElementStyle($styledata) {
662     $style_elem = $this->createElement('style');
663     // Note: type can/should be left out for HTML5.
664     $style_elem->setAttribute('type', 'text/css');
665     $style_elem->appendChild($this->createCDATASection($styledata));
666     return $style_elem;
667   }
668
669   public function createElementJS($jsdata) {
670     $jselem = $this->createElement('script');
671     // Note: type can/should be left out for HTML5.
672     $jselem->setAttribute('type', 'text/javascript');
673     $jselem->appendChild($this->createCDATASection($jsdata));
674     return $jselem;
675   }
676
677   public function createElementJSFile($jsURL, $defer = false, $async = false) {
678     $jselem = $this->createElement('script');
679     // Note: type can/should be left out for HTML5.
680     $jselem->setAttribute('type', 'text/javascript');
681     if ($defer) {
682       $jselem->setAttribute('defer', '');
683     }
684     if ($async) {
685       $jselem->setAttribute('async', '');
686     }
687     $jselem->setAttribute('src', $jsURL);
688     return $jselem;
689   }
690 }
691
692 class ExtendedElement extends DOMElement {
693   // ExtendedElement PHP class
694   // this extends the general PHP DOM Element class to simplify some usual constructs
695   //
696   // public function appendElement($name, [$value])
697   //   appends a DOMDocument::createElement() as a child of this element (see there for params)
698   //     returns the new child
699   //
700   // public function appendElementXML($name, $xmldata)
701   //   appends a DOMDocument::createElement() with the given name as a child of this element,
702   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
703   //     returns the new child
704   //
705   // public function appendLink($target, [$value], [$title])
706   //   appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
707   //     returns the new child
708   //
709   // public function appendImage($src, [$alt_text])
710   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
711   //     returns the new child
712   //
713   // public function appendForm($action, $method, $name, [$id])
714   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
715   //     returns the new child
716   //
717   // public function appendFormDiv($action, $method, $name, [$id])
718   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
719   //     returns an HTML <div> that is a child of the new child
720   //
721   // public function appendInputHidden($name, $value)
722   //   appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
723   //     returns the new child
724   //
725   // public function appendInputText($name, $maxlength, $size, [$id], [$value])
726   //   appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
727   //     returns the new child
728   //
729   // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
730   //   appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
731   //     returns the new child
732   //
733   // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
734   //   appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
735   //     returns the new child
736   //
737   // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
738   //   appends an ExtendedDocument::createElementInputRange() as a child of this element (see there for params)
739   //     returns the new child
740   //
741   // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
742   //   appends an ExtendedDocument::createElementInputUrl() as a child of this element (see there for params)
743   //     returns the new child
744   //
745   // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
746   //   appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
747   //     returns the new child
748   //
749   // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
750   //   appends an ExtendedDocument::createElementInputTel() as a child of this element (see there for params)
751   //     returns the new child
752   //
753   // public function appendInputDate($name, [$id], [$min], [$max], [$value])
754   //   appends an ExtendedDocument::createElementInputDate() as a child of this element (see there for params)
755   //     returns the new child
756   //
757   // public function appendInputTime($name, [$id], [$min], [$max], [$value])
758   //   appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params)
759   //     returns the new child
760   //
761   // public function appendInputColor($name, [$id], [$value])
762   //   appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params)
763   //
764   // public function appendInputRadio($name, $id, $value, $checked)
765   //   appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
766   //     returns the new child
767   //
768   // public function appendInputCheckbox($name, $id, $value, $checked)
769   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
770   //     returns the new child
771   //
772   // public function appendInputFile($name, $id, $accept)
773   //   appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
774   //     returns the new child
775   //
776   // public function appendInputSubmit($value)
777   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
778   //     returns the new child
779   //
780   // public function appendButton($value, $onclick = null)
781   //   appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
782   //     returns the new child
783   //
784   // public function appendTextArea($name, $columns, $rows, [$id], [$value])
785   //   appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
786   //     returns the new child
787   //
788   // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
789   //   appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
790   //     returns the new child
791   //
792   // public function appendElementOption($key, $desc, [$selected])
793   //   appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
794   //     returns the new child
795   //
796   // public function appendLabel($for_id, $value)
797   //   appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
798   //     returns the new child
799   //
800   // public function appendText($text)
801   //   appends a DOMDocument::createTextNode() as a child of this element (see there for params)
802   //     returns the new child
803   //
804   // public function appendLinebreak()
805   //   appends a <br> as a child of this element
806   //     returns the new child
807   //
808   // public function appendEntity($name)
809   //   appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
810   //     returns the new child
811   //
812   // public function appendComment($comment_data)
813   //   appends a DOMDocument::createComment() as a child of this element (see there for params)
814   //     returns the new child
815   //
816   // public function appendClonedElement($dom_element, [$deep])
817   //   appends a clone of the given DOMElement as a child of this element
818   //     the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
819   //     returns the new child
820   //
821   // public function appendHTMLMarkup($htmldata)
822   //   appends a representation of the HTML data as children of this element
823   //     NO return value!
824   //
825   // public function appendXMLMarkup($xmldata)
826   //   appends a representation of the XML data as children of this element
827   //     NO return value!
828   //
829   // public function appendStyleElement($styledata)
830   //   appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
831   //     returns the new child
832   //
833   // public function appendJSElement($jsdata)
834   //   appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
835   //     returns the new child
836   //
837   // public function appendJSFile($jsURL, [$defer], [$async])
838   //   appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
839   //     returns the new child
840   //
841   // public function setClass($classname)
842   //   sets the 'class' attribute of the element to the given classname value
843   //
844   // public function addClass($classname)
845   //   adds the given classname value to the space-separated list in the 'class' attribute
846   //     returns the value of the 'class' attribute
847   //
848   // public function setID($elem_id)
849   //   sets the 'id' attribute of the element to the given elem_id value
850
851   public function appendElement($name, $value = '') {
852     return $this->appendChild($this->ownerDocument->createElement($name, $value));
853   }
854   public function appendElementXML($name, $xmldata) {
855     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
856     $aelem->appendXMLMarkup($xmldata);
857     return $aelem;
858   }
859   public function appendLink($target, $value = '', $title = null) {
860     return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
861   }
862   public function appendImage($src, $alt_text = '') {
863     return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
864   }
865   public function appendForm($action, $method, $name, $id = null) {
866     return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
867   }
868   public function appendFormDiv($action, $method, $name, $id = null) {
869     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
870     return $formelem->appendElement('div');
871   }
872   public function appendInputHidden($name, $value) {
873     return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
874   }
875   public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
876     return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
877   }
878   public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
879     return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
880   }
881   public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
882     return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
883   }
884   public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
885     return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value));
886   }
887   public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
888     return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value));
889   }
890   public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
891     return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
892   }
893   public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
894     return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value));
895   }
896   public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
897     return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value));
898   }
899   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
900     return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
901   }
902   public function appendInputColor($name, $id = null, $value = null) {
903     return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
904   }
905   public function appendInputRadio($name, $id, $value, $checked) {
906     return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
907   }
908   public function appendInputCheckbox($name, $id, $value, $checked) {
909     return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
910   }
911   public function appendInputFile($name, $id, $accept) {
912     return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
913   }
914   public function appendInputSubmit($value) {
915     return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
916   }
917   public function appendButton($value, $onclick = null) {
918     return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
919   }
920   public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
921     return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
922   }
923   public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
924     return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
925   }
926   public function appendElementOption($key, $desc, $selected = false) {
927     return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
928   }
929   public function appendLabel($for_id, $value) {
930     return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
931   }
932   public function appendText($text) {
933     return $this->appendChild($this->ownerDocument->createTextNode($text));
934   }
935   public function appendLinebreak() {
936     return $this->appendChild($this->ownerDocument->createElement('br'));
937   }
938   public function appendEntity($name) {
939     return $this->appendChild($this->ownerDocument->createEntityReference($name));
940   }
941   public function appendComment($comment_data) {
942     return $this->appendChild($this->ownerDocument->createComment($comment_data));
943   }
944   public function appendClonedElement($dom_element, $deep = true) {
945     return $this->appendChild($dom_element->cloneNode($deep));
946   }
947   public function appendHTMLMarkup($htmldata) {
948     $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
949   }
950   public function appendXMLMarkup($xmldata) {
951     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
952   }
953   public function appendStyleElement($styledata) {
954     return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
955   }
956   public function appendJSElement($jsdata) {
957     return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
958   }
959   public function appendJSFile($jsURL, $defer = false, $async = false) {
960     return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
961   }
962   public function setClass($classname) {
963     $this->setAttribute('class', $classname);
964   }
965   public function addClass($classname) {
966     $classval = $this->getAttribute('class');
967     if (strlen($classval)) { $classval .= ' '; }
968     $classval .= $classname;
969     $this->setClass($classval);
970     return $classval;
971   }
972   public function setID($elem_id) {
973     $this->setAttribute('id', $elem_id);
974   }
975 }
976
977 class ExtendedDocumentFragment extends DOMDocumentFragment {
978   // ExtendedDocumentFragment PHP class
979   // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
980   //
981   // public function appendElement($name, [$value])
982   //   appends a DOMDocument::createElement() as a child of this fragment (see there for params)
983   //     returns the new child
984   //
985   // public function appendElementXML($name, $xmldata)
986   //   appends a DOMDocument::createElement() with the given name as a child of this fragment,
987   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
988   //     returns the new child
989   //
990   // public function appendLink($target, [$value], [$title])
991   //   appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
992   //     returns the new child
993   //
994   // public function appendImage($src, [$alt_text])
995   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
996   //     returns the new child
997   //
998   // public function appendForm($action, $method, $name, [$id])
999   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
1000   //     returns the new child
1001   //
1002   // public function appendFormDiv($action, $method, $name, [$id])
1003   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
1004   //     returns an HTML <div> that is a child of the new child
1005   //
1006   // public function appendInputHidden($name, $value)
1007   //   appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
1008   //     returns the new child
1009   //
1010   // public function appendInputText($name, $maxlength, $size, [$id], [$value])
1011   //   appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
1012   //     returns the new child
1013   //
1014   // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
1015   //   appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
1016   //     returns the new child
1017   //
1018   // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
1019   //   appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
1020   //     returns the new child
1021   //
1022   // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
1023   //   appends an ExtendedDocument::createElementInputRange() as a child of this fragment (see there for params)
1024   //     returns the new child
1025   //
1026   // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
1027   //   appends an ExtendedDocument::createElementInputUrl() as a child of this fragment (see there for params)
1028   //     returns the new child
1029   //
1030   // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
1031   //   appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
1032   //     returns the new child
1033   //
1034   // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
1035   //   appends an ExtendedDocument::createElementInputTel() as a child of this fragment (see there for params)
1036   //     returns the new child
1037   //
1038   // public function appendInputDate($name, [$id], [$min], [$max], [$value])
1039   //   appends an ExtendedDocument::createElementInputDate() as a child of this fragment (see there for params)
1040   //     returns the new child
1041   //
1042   // public function appendInputTime($name, [$id], [$min], [$max], [$value])
1043   //   appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params)
1044   //     returns the new child
1045   //
1046   // public function appendInputColor($name, [$id], [$value])
1047   //   appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params)
1048   //
1049   // public function appendInputRadio($name, $id, $value, $checked)
1050   //   appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
1051   //     returns the new child
1052   //
1053   // public function appendInputCheckbox($name, $id, $value, $checked)
1054   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
1055   //     returns the new child
1056   //
1057   // public function appendInputFile($name, $id, $accept)
1058   //   appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
1059   //     returns the new child
1060   //
1061   // public function appendInputSubmit($value)
1062   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
1063   //     returns the new child
1064   //
1065   // public function appendButton($value, $onclick = null)
1066   //   appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
1067   //     returns the new child
1068   //
1069   // public function appendTextArea($name, $columns, $rows, [$id], [$value])
1070   //   appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
1071   //     returns the new child
1072   //
1073   // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
1074   //   appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
1075   //     returns the new child
1076   //
1077   // public function appendElementOption($key, $desc, [$selected])
1078   //   appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
1079   //     returns the new child
1080   //
1081   // public function appendLabel($for_id, $value)
1082   //   appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
1083   //     returns the new child
1084   //
1085   // public function appendText($text)
1086   //   appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
1087   //     returns the new child
1088   //
1089   // public function appendLinebreak()
1090   //   appends a <br> as a child of this fragment
1091   //     returns the new child
1092   //
1093   // public function appendEntity($name)
1094   //   appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
1095   //     returns the new child
1096   //
1097   // public function appendComment($comment_data)
1098   //   appends a DOMDocument::createComment() as a child of this fragment (see there for params)
1099   //     returns the new child
1100   //
1101   // public function appendClonedElement($dom_element, [$deep])
1102   //   appends a clone of the given DOMElement as a child of this fragment
1103   //     the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
1104   //     returns the new child
1105   //
1106   // public function appendHTMLMarkup($htmldata)
1107   //   appends a representation of the HTML data as children of this fragment
1108   //     NO return value!
1109   //
1110   // public function appendXMLMarkup($xmldata)
1111   //   appends a representation of the XML data as children of this fragment
1112   //     NO return value!
1113   //
1114   // public function appendStyleElement($styledata)
1115   //   appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
1116   //     returns the new child
1117   //
1118   // public function appendJSElement($jsdata)
1119   //   appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
1120   //     returns the new child
1121   //
1122   // public function appendJSFile($jsURL, [$defer], [$async])
1123   //   appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
1124   //     returns the new child
1125
1126   public function appendElement($name, $value = '') {
1127     return $this->appendChild($this->ownerDocument->createElement($name, $value));
1128   }
1129   public function appendElementXML($name, $xmldata) {
1130     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
1131     $aelem->appendXMLMarkup($xmldata);
1132     return $aelem;
1133   }
1134   public function appendLink($target, $value = '', $title = null) {
1135     return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
1136   }
1137   public function appendImage($src, $alt_text = '') {
1138     return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
1139   }
1140   public function appendForm($action, $method, $name, $id = null) {
1141     return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
1142   }
1143   public function appendFormDiv($action, $method, $name, $id = null) {
1144     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
1145     return $formelem->appendElement('div');
1146   }
1147   public function appendInputHidden($name, $value) {
1148     return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
1149   }
1150   public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
1151     return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
1152   }
1153   public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
1154     return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
1155   }
1156   public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
1157     return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
1158   }
1159   public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
1160     return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value));
1161   }
1162   public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
1163     return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value));
1164   }
1165   public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
1166     return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
1167   }
1168   public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
1169     return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value));
1170   }
1171   public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
1172     return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value));
1173   }
1174   public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
1175     return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
1176   }
1177   public function appendInputColor($name, $id = null, $value = null) {
1178     return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
1179   }
1180   public function appendInputRadio($name, $id, $value, $checked) {
1181     return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
1182   }
1183   public function appendInputCheckbox($name, $id, $value, $checked) {
1184     return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
1185   }
1186   public function appendInputFile($name, $id, $accept) {
1187     return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
1188   }
1189   public function appendInputSubmit($value) {
1190     return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
1191   }
1192   public function appendButton($value, $onclick = null) {
1193     return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
1194   }
1195   public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
1196     return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
1197   }
1198   public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
1199     return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
1200   }
1201   public function appendElementOption($key, $desc, $selected = false) {
1202     return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
1203   }
1204   public function appendLabel($for_id, $value) {
1205     return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
1206   }
1207   public function appendText($text) {
1208     return $this->appendChild($this->ownerDocument->createTextNode($text));
1209   }
1210   public function appendLinebreak() {
1211     return $this->appendChild($this->ownerDocument->createElement('br'));
1212   }
1213   public function appendEntity($name) {
1214     return $this->appendChild($this->ownerDocument->createEntityReference($name));
1215   }
1216   public function appendComment($comment_data) {
1217     return $this->appendChild($this->ownerDocument->createComment($comment_data));
1218   }
1219   public function appendClonedElement($dom_element, $deep = true) {
1220     return $this->appendChild($dom_element->cloneNode($deep));
1221   }
1222   public function appendHTMLMarkup($htmldata) {
1223     $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
1224   }
1225   public function appendXMLMarkup($xmldata) {
1226     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
1227   }
1228   public function appendStyleElement($styledata) {
1229     return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
1230   }
1231   public function appendJSElement($jsdata) {
1232     return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
1233   }
1234   public function appendJSFile($jsURL, $defer = false, $async = false) {
1235     return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
1236   }
1237 }
1238 ?>