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