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