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