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