32d4e3ee23a715d281353d11f0b1c04024563e07
[php-utility-classes.git] / include / cbsm / util / document.php-class
1 <?php
2 /* ***** BEGIN LICENSE BLOCK *****
3  *
4  * The contents of this file are subject to Austrian copyright reegulations
5  * ("Urheberrecht"); you may not use this file except in compliance with
6  * those laws.
7  * This contents and any derived work, if it gets distributed in any way,
8  * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9  * either express or implied.
10  *
11  * The Original Code is KaiRo's extended DOM document classes.
12  *
13  * The Initial Developer of the Original Code is
14  * KaiRo - Robert Kaiser.
15  * Portions created by the Initial Developer are Copyright (C) 2010
16  * the Initial Developer. All Rights Reserved.
17  *
18  * Contributor(s): Robert Kaiser <kairo@kairo.at>
19  *
20  * ***** END LICENSE BLOCK ***** */
21
22 class ExtendedDocument extends DOMDocument {
23   // ExtendedDocument PHP class
24   // this extends the general PHP DOM Document class to simplify some usual constructs
25   //
26   // function __construct([$version], [$encoding])
27   //   CONSTRUCTOR
28   //   construct a new DOM Document that uses our element definitions
29   //
30   // static function initHTML5()
31   //   initialize as an HTML5 document and return references to its basic elements.
32   //     returns an associative array with the following elements: 'html', 'head', 'title', 'body'
33   //
34   // public function appendElement($name, [$value])
35   //   appends a DOMDocument::createElement() as a child of this document (see there for params)
36   //     returns the new child
37   //
38   // public function appendElementXML($name, $xmldata)
39   //   appends a DOMDocument::createElement() with the given name as a child of this document,
40   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
41   //     returns the new child
42   //
43   // public function appendLink($target, [$value])
44   //   appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
45   //     returns the new child
46   //
47   // public function appendImage($src, [$alt_text])
48   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
49   //     returns the new child
50   //
51   // public function appendForm($action, $method, $name, [$id])
52   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
53   //     returns the new child
54   //
55   // public function appendFormDiv($action, $method, $name, [$id])
56   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
57   //     returns an HTML <div> that is a child of the new child
58   //
59   // public function appendInputHidden($name, $value)
60   //   appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
61   //     returns the new child
62   //
63   // public function appendInputText($name, $maxlength, $size, [$id], [$value])
64   //   appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
65   //     returns the new child
66   //
67   // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
68   //   appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
69   //     returns the new child
70   //
71   // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
72   //   appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
73   //     returns the new child
74   //
75   // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
76   //   appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
77   //     returns the new child
78   //
79   // public function appendInputRadio($name, $id, $value, $checked)
80   //   appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
81   //     returns the new child
82   //
83   // public function appendInputCheckbox($name, $id, $value, $checked)
84   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
85   //     returns the new child
86   //
87   // public function appendInputFile($name, $id, $accept)
88   //   appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
89   //     returns the new child
90   //
91   // public function appendInputSubmit($value)
92   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
93   //     returns the new child
94   //
95   // public function appendButton($value, $onclick = null)
96   //   appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
97   //     returns the new child
98   //
99   // public function appendTextArea($name, $columns, $rows, [$id], [$value])
100   //   appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
101   //     returns the new child
102   //
103   // public function appendElementSelect($name, [$id], [$options], [$default])
104   //   appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
105   //     returns the new child
106   //
107   // public function appendElementOption($key, $desc, [$selected])
108   //   appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
109   //     returns the new child
110   //
111   // public function appendLabel($for_id, $value)
112   //   appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
113   //     returns the new child
114   //
115   // public function appendText($text)
116   //   appends a DOMDocument::createTextNode() as a child of this document (see there for params)
117   //     returns the new child
118   //
119   // public function appendComment($comment_data)
120   //   appends a DOMDocument::createComment() as a child of this document (see there for params)
121   //     returns the new child
122   //
123   // public function appendHTMLMarkup($htmldata, [$parentNode])
124   //   appends a representation of the HTML data as children of the given parent node, by default this document
125   //     NO return value!
126   //
127   // public function appendXMLMarkup($xmldata, [$parentNode])
128   //   appends a representation of the XML data as children of the given parent node, by default this document
129   //     NO return value!
130   //
131   // public function appendJSElement($jsdata)
132   //   appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
133   //     NO return value!
134   //
135   // public function appendJSFile($jsURL)
136   //   appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
137   //     returns the new child
138   //
139   // public function appendCOMElement($module, $attributes)
140   //   appends an ExtendedDocument::createCOMElement() as a child of this document (see there for params)
141   //     returns the new child
142   //
143   // public function createElementLink($target, [$value])
144   //   returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
145   //
146   // public function createElementImage($src, [$alt_text])
147   //   returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
148   //
149   // public function createElementForm($action, $method, $name)
150   //   returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
151   //   with the given action, method, and name
152   //
153   // public function createElementInputHidden($name, $value)
154   //   returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
155   //
156   // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
157   //   returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
158   //   and optionally id and value
159   //
160   // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
161   //   returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
162   //   and optionally id and value
163   //
164   // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
165   //   returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
166   //   and optionally id and value
167   //
168   // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
169   //   returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
170   //   and optionally id and value
171   //
172   // public function createElementInputRadio($name, $id, $value, $checked)
173   //   returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
174   //   checked state
175   //
176   // public function createElementInputCheckbox($name, $id, $value, $checked)
177   //   returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
178   //   checked state
179   //
180   // public function createElementInputFile($name, $id, $accept)
181   //   returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
182   //
183   // public function createElementInputSubmit($value)
184   //   returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
185   //
186   // public function createElementButton($value, $onclick = null)
187   //   returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
188   //
189   // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
190   //   returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
191   //   and optionally id and value
192   //
193   // public function createElementSelect($name, [$id], [$options], [$default])
194   //   returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
195   //   array of options (key => description) and key of the by-default selected entry
196   //
197   // public function createElementOption($key, $desc, [$selected])
198   //   returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
199   //   and optionally bool that tells if the entry is selected
200   //
201   // public function createElementLabel($for_id, $value)
202   //   returns an ExtendedElement that is an HTML <label> with the given 'for' and value
203   //
204   // public function createElementJS($jsdata)
205   //   returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
206   //
207   // public function createElementJSFile($jsURL)
208   //   returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
209   //
210   // public function createCOMElement($module, $attributes)
211   //   returns an ExtendedElement that is in COM_NS namespace, with the given module as name and the
212   //     given name=>value array as attributes
213
214   function __construct($version = '1.0', $encoding = 'utf-8') {
215     // make sure the default DOMDocument constructor runs
216     parent::__construct($version, $encoding);
217     $this->registerNodeClass('DOMElement', 'ExtendedElement');
218     $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
219   }
220
221   static function initHTML5() {
222     $doc = new ExtendedDocument();
223     $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
224
225     // Created basic HTML document structure.
226     $root = $doc->getElementsByTagName('html')->item(0);
227     $head = $root->appendElement('head');
228     $title = $head->appendElement('title');
229     $body = $root->appendElement('body');
230
231     return array('document' => $doc,
232                  'html' => $root,
233                  'head' => $head,
234                  'title' => $title,
235                  'body' => $body);
236   }
237
238   public function appendElement($name, $value = '') {
239     return $this->appendChild($this->createElement($name, $value));
240   }
241   public function appendElementXML($name, $xmldata) {
242     $aelem = $this->appendChild($this->createElement($name));
243     $aelem->appendXMLMarkup($xmldata);
244     //$aelem->appendChild($this->createXMLFragment($xmldata));
245     return $aelem;
246   }
247   public function appendLink($target, $value = '') {
248     return $this->appendChild($this->createElementLink($target, $value));
249   }
250   public function appendImage($src, $alt_text = '') {
251     return $this->appendChild($this->createElementImage($src, $alt_text));
252   }
253   public function appendForm($action, $method, $name, $id = null) {
254     return $this->appendChild($this->createElementForm($action, $method, $name, $id));
255   }
256   public function appendFormDiv($action, $method, $name, $id = null) {
257     $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
258     return $formelem->appendElement('div');
259   }
260   public function appendInputHidden($name, $value) {
261     return $this->appendChild($this->createElementInputHidden($name, $value));
262   }
263   public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
264     return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
265   }
266   public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
267     return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
268   }
269   public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
270     return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
271   }
272   public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
273     return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
274   }
275   public function appendInputRadio($name, $id, $value, $checked) {
276     return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
277   }
278   public function appendInputCheckbox($name, $id, $value, $checked) {
279     return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
280   }
281   public function appendInputFile($name, $id, $accept) {
282     return $this->appendChild($this->createElementInputFile($name, $id, $accept));
283   }
284   public function appendInputSubmit($value) {
285     return $this->appendChild($this->createElementInputSubmit($value));
286   }
287   public function appendButton($value, $onclick = null) {
288     return $this->appendChild($this->createElementButton($value, $onclick));
289   }
290   public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
291     return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
292   }
293   public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
294     return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
295   }
296   public function appendElementOption($key, $desc, $selected = false) {
297     return $this->appendChild($this->createElementOption($key, $desc, $selected));
298   }
299   public function appendLabel($for_id, $value) {
300     return $this->appendChild($this->createElementLabel($for_id, $value));
301   }
302   public function appendText($text) {
303     return $this->appendChild($this->createTextNode($text));
304   }
305   public function appendComment($comment_data) {
306     return $this->appendChild($this->createComment($comment_data));
307   }
308   public function appendJSElement($jsdata) {
309     $this->appendChild($this->createElementJS($jsdata));
310   }
311   public function appendJSFile($jsdata) {
312     return $this->appendChild($this->createElementJSFile($jsdata));
313   }
314   public function appendCOMElement($module, $attributes) {
315     return $this->appendChild($this->createCOMElement($module, $attributes));
316   }
317
318   public function appendHTMLMarkup($htmldata, $parentNode = null) {
319     if (is_null($parentNode)) { $parentNode =& $this; }
320     // XXX: just a workaround for now!
321     $parentNode->appendChild($this->createCDATASection($htmldata));
322   }
323
324   public function appendXMLMarkup($xmldata, $parentNode = null) {
325     if (is_null($parentNode)) { $parentNode =& $this; }
326     $tmpdoc = new ExtendedDocument;
327     $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
328     $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
329     $tmpxml .= '<root>'.$xmldata.'</root>';
330     $tmpdoc->loadXML($tmpxml);
331     foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
332       $parentNode->appendChild($this->importNode($child, true));
333     }
334   }
335
336   public function createElement($name, $value = '') {
337     // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
338     $aelem = parent::createElement($name);
339     $aelem->appendText($value);
340     return $aelem;
341   }
342
343   public function createElementLink($target, $value = '') {
344     $link = $this->createElement('a', $value);
345     $link->setAttribute('href', $target); // XXX: take care of & etc. in links
346     return $link;
347   }
348
349   public function createElementImage($src, $alt_text = '') {
350     $img = $this->createElement('img');
351     $img->setAttribute('src', $src);
352     $img->setAttribute('alt', $alt_text);
353     return $img;
354   }
355
356   public function createElementForm($action, $method, $name, $id = null) {
357     $formelem = $this->createElement('form');
358     $formelem->setAttribute('action', $action);
359     $formelem->setAttribute('method', $method);
360     $formelem->setAttribute('name', $name);
361     $formelem->setAttribute('id', $id);
362     return $formelem;
363   }
364
365   public function createElementInputHidden($name, $value) {
366     $hidden = $this->createElement('input');
367     $hidden->setAttribute('type', 'hidden');
368     $hidden->setAttribute('name', $name);
369     $hidden->setAttribute('value', $value);
370     return $hidden;
371   }
372
373   public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
374     $txfield = $this->createElement('input');
375     $txfield->setAttribute('type', 'text');
376     if (!is_null($id)) { $txfield->setAttribute('id', $id); }
377     $txfield->setAttribute('name', $name);
378     $txfield->setAttribute('maxlength', $maxlength);
379     $txfield->setAttribute('size', $size);
380     if (!is_null($value)) { $txfield->setAttribute('value', $value); }
381     return $txfield;
382   }
383
384   public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
385     $txfield = $this->createElement('input');
386     $txfield->setAttribute('type', 'number');
387     if (!is_null($id)) { $txfield->setAttribute('id', $id); }
388     $txfield->setAttribute('name', $name);
389     $txfield->setAttribute('maxlength', $maxlength);
390     $txfield->setAttribute('size', $size);
391     if (!is_null($value)) { $txfield->setAttribute('value', $value); }
392     return $txfield;
393   }
394
395   public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
396     $txfield = $this->createElement('input');
397     $txfield->setAttribute('type', 'email');
398     if (!is_null($id)) { $txfield->setAttribute('id', $id); }
399     $txfield->setAttribute('name', $name);
400     $txfield->setAttribute('maxlength', $maxlength);
401     $txfield->setAttribute('size', $size);
402     if (!is_null($value)) { $txfield->setAttribute('value', $value); }
403     return $txfield;
404   }
405
406   public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
407     $pwfield = $this->createElement('input');
408     $pwfield->setAttribute('type', 'password');
409     if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
410     $pwfield->setAttribute('name', $name);
411     $pwfield->setAttribute('maxlength', $maxlength);
412     $pwfield->setAttribute('size', $size);
413     if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
414     return $pwfield;
415   }
416
417   public function createElementInputRadio($name, $id, $value, $checked) {
418     $radio = $this->createElement('input');
419     $radio->setAttribute('type', 'radio');
420     $radio->setAttribute('name', $name);
421     if (!is_null($id)) { $radio->setAttribute('id', $id); }
422     $radio->setAttribute('value', $value);
423     if ($checked) { $radio->setAttribute('checked', ''); }
424     return $radio;
425   }
426
427   public function createElementInputCheckbox($name, $id, $value, $checked) {
428     $cbox = $this->createElement('input');
429     $cbox->setAttribute('type', 'checkbox');
430     $cbox->setAttribute('name', $name);
431     if (!is_null($id)) { $cbox->setAttribute('id', $id); }
432     $cbox->setAttribute('value', $value);
433     if ($checked) { $cbox->setAttribute('checked', ''); }
434     return $cbox;
435   }
436
437   public function createElementInputFile($name, $id, $accept) {
438     $fileinput = $this->createElement('input');
439     $fileinput->setAttribute('type', 'file');
440     $fileinput->setAttribute('name', $name);
441     if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
442     $fileinput->setAttribute('accept', $accept);
443     return $fileinput;
444   }
445
446   public function createElementInputSubmit($value) {
447     $submitbtn = $this->createElement('input');
448     $submitbtn->setAttribute('type', 'submit');
449     $submitbtn->setAttribute('value', $value);
450     return $submitbtn;
451   }
452
453   public function createElementButton($value, $onclick = null) {
454     $btn = $this->createElement('input');
455     $btn->setAttribute('type', 'button');
456     $btn->setAttribute('value', $value);
457     if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
458     return $btn;
459   }
460
461   public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
462     $txtarea = $this->createElement('textarea', $value);
463     $txtarea->setAttribute('name', $name);
464     $txtarea->setAttribute('cols', $columns);
465     $txtarea->setAttribute('rows', $rows);
466     if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
467     return $txtarea;
468   }
469
470   public function createElementSelect($name, $id = null, $options = array(), $default = null) {
471     $select = $this->createElement('select');
472     $select->setAttribute('name', $name);
473     if (!is_null($id)) { $select->setAttribute('id', $id); }
474     foreach ($options as $key => $desc) {
475       $select->appendElementOption($key, $desc, ($key == $default));
476     }
477     return $select;
478   }
479
480   public function createElementOption($key, $desc, $selected = false) {
481     $option = $this->createElement('option', $desc);
482     $option->setAttribute('value', $key);
483     if ($selected) { $option->setAttribute('selected', ''); }
484     return $option;
485   }
486
487   public function createElementLabel($for_id, $value) {
488     $label = $this->createElement('label', $value);
489     $label->setAttribute('for', $for_id);
490     return $label;
491   }
492
493   public function createElementJS($jsdata) {
494     $jselem = $this->createElement('script');
495     // Note: type can/should be left out for HTML5.
496     $jselem->setAttribute('type', 'text/javascript');
497     $jselem->appendChild($this->createCDATASection($jsdata));
498     return $jselem;
499   }
500
501   public function createElementJSFile($jsURL) {
502     $jselem = $this->createElement('script');
503     // Note: type can/should be left out for HTML5.
504     $jselem->setAttribute('type', 'text/javascript');
505     $jselem->setAttribute('src', $jsURL);
506     return $jselem;
507   }
508
509   public function createCOMElement($module, $attributes) {
510     $com_elem = $this->createElementNS(COM_NS, $module);
511     if (is_array($attributes) && count($attributes)) {
512       foreach ($attributes as $name=>$value) {
513         $com_elem->setAttribute($name, $value);
514       }
515     }
516     return $com_elem;
517   }
518 }
519
520 class ExtendedElement extends DOMElement {
521   // ExtendedElement PHP class
522   // this extends the general PHP DOM Element class to simplify some usual constructs
523   //
524   // public function appendElement($name, [$value])
525   //   appends a DOMDocument::createElement() as a child of this element (see there for params)
526   //     returns the new child
527   //
528   // public function appendElementXML($name, $xmldata)
529   //   appends a DOMDocument::createElement() with the given name as a child of this element,
530   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
531   //     returns the new child
532   //
533   // public function appendLink($target, [$value])
534   //   appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
535   //     returns the new child
536   //
537   // public function appendImage($src, [$alt_text])
538   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
539   //     returns the new child
540   //
541   // public function appendForm($action, $method, $name, [$id])
542   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
543   //     returns the new child
544   //
545   // public function appendFormDiv($action, $method, $name, [$id])
546   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
547   //     returns an HTML <div> that is a child of the new child
548   //
549   // public function appendInputHidden($name, $value)
550   //   appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
551   //     returns the new child
552   //
553   // public function appendInputText($name, $maxlength, $size, [$id], [$value])
554   //   appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
555   //     returns the new child
556   //
557   // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
558   //   appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
559   //     returns the new child
560   //
561   // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
562   //   appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
563   //     returns the new child
564   //
565   // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
566   //   appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
567   //     returns the new child
568   //
569   // public function appendInputRadio($name, $id, $value, $checked)
570   //   appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
571   //     returns the new child
572   //
573   // public function appendInputCheckbox($name, $id, $value, $checked)
574   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
575   //     returns the new child
576   //
577   // public function appendInputFile($name, $id, $accept)
578   //   appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
579   //     returns the new child
580   //
581   // public function appendInputSubmit($value)
582   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
583   //     returns the new child
584   //
585   // public function appendButton($value, $onclick = null)
586   //   appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
587   //     returns the new child
588   //
589   // public function appendTextArea($name, $columns, $rows, [$id], [$value])
590   //   appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
591   //     returns the new child
592   //
593   // public function appendElementSelect($name, [$id], [$options], [$default])
594   //   appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
595   //     returns the new child
596   //
597   // public function appendElementOption($key, $desc, [$selected])
598   //   appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
599   //     returns the new child
600   //
601   // public function appendLabel($for_id, $value)
602   //   appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
603   //     returns the new child
604   //
605   // public function appendText($text)
606   //   appends a DOMDocument::createTextNode() as a child of this element (see there for params)
607   //     returns the new child
608   //
609   // public function appendComment($comment_data)
610   //   appends a DOMDocument::createComment() as a child of this element (see there for params)
611   //     returns the new child
612   //
613   // public function appendHTMLMarkup($htmldata)
614   //   appends a representation of the HTML data as children of this element
615   //     NO return value!
616   //
617   // public function appendXMLMarkup($xmldata)
618   //   appends a representation of the XML data as children of this element
619   //     NO return value!
620   //
621   // public function appendJSElement($jsdata)
622   //   appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
623   //     NO return value!
624   //
625   // public function appendCOMElement($module, $attributes)
626   //   appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
627   //     returns the new child
628   //
629   // public function appendCOMElement($module, $attributes)
630   //   appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
631   //     returns the new child
632
633   public function appendElement($name, $value = '') {
634     return $this->appendChild($this->ownerDocument->createElement($name, $value));
635   }
636   public function appendElementXML($name, $xmldata) {
637     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
638     $aelem->appendXMLMarkup($xmldata);
639     return $aelem;
640   }
641   public function appendLink($target, $value = '') {
642     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
643   }
644   public function appendImage($src, $alt_text = '') {
645     return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
646   }
647   public function appendForm($action, $method, $name, $id = null) {
648     return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
649   }
650   public function appendFormDiv($action, $method, $name, $id = null) {
651     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
652     return $formelem->appendElement('div');
653   }
654   public function appendInputHidden($name, $value) {
655     return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
656   }
657   public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
658     return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
659   }
660   public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
661     return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
662   }
663   public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
664     return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
665   }
666   public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
667     return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
668   }
669   public function appendInputRadio($name, $id, $value, $checked) {
670     return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
671   }
672   public function appendInputCheckbox($name, $id, $value, $checked) {
673     return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
674   }
675   public function appendInputFile($name, $id, $accept) {
676     return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
677   }
678   public function appendInputSubmit($value) {
679     return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
680   }
681   public function appendButton($value, $onclick = null) {
682     return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
683   }
684   public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
685     return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
686   }
687   public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
688     return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
689   }
690   public function appendElementOption($key, $desc, $selected = false) {
691     return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
692   }
693   public function appendLabel($for_id, $value) {
694     return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
695   }
696   public function appendText($text) {
697     return $this->appendChild($this->ownerDocument->createTextNode($text));
698   }
699   public function appendComment($comment_data) {
700     return $this->appendChild($this->ownerDocument->createComment($comment_data));
701   }
702   public function appendHTMLMarkup($htmldata) {
703     $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
704   }
705   public function appendXMLMarkup($xmldata) {
706     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
707   }
708   public function appendJSElement($jsdata) {
709     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
710   }
711   public function appendJSFile($jsdata) {
712     return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
713   }
714   public function appendCOMElement($module, $attributes) {
715     return $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
716   }
717 }
718
719 class ExtendedDocumentFragment extends DOMDocumentFragment {
720   // ExtendedDocumentFragment PHP class
721   // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
722   //
723   // public function appendElement($name, [$value])
724   //   appends a DOMDocument::createElement() as a child of this fragment (see there for params)
725   //     returns the new child
726   //
727   // public function appendElementXML($name, $xmldata)
728   //   appends a DOMDocument::createElement() with the given name as a child of this fragment,
729   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
730   //     returns the new child
731   //
732   // public function appendLink($target, [$value])
733   //   appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
734   //     returns the new child
735   //
736   // public function appendImage($src, [$alt_text])
737   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
738   //     returns the new child
739   //
740   // public function appendForm($action, $method, $name, [$id])
741   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
742   //     returns the new child
743   //
744   // public function appendFormDiv($action, $method, $name, [$id])
745   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
746   //     returns an HTML <div> that is a child of the new child
747   //
748   // public function appendInputHidden($name, $value)
749   //   appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
750   //     returns the new child
751   //
752   // public function appendInputText($name, $maxlength, $size, [$id], [$value])
753   //   appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
754   //     returns the new child
755   //
756   // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
757   //   appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
758   //     returns the new child
759   //
760   // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
761   //   appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
762   //     returns the new child
763   //
764   // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
765   //   appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
766   //     returns the new child
767   //
768   // public function appendInputRadio($name, $id, $value, $checked)
769   //   appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
770   //     returns the new child
771   //
772   // public function appendInputCheckbox($name, $id, $value, $checked)
773   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
774   //     returns the new child
775   //
776   // public function appendInputFile($name, $id, $accept)
777   //   appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
778   //     returns the new child
779   //
780   // public function appendInputSubmit($value)
781   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
782   //     returns the new child
783   //
784   // public function appendButton($value, $onclick = null)
785   //   appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
786   //     returns the new child
787   //
788   // public function appendTextArea($name, $columns, $rows, [$id], [$value])
789   //   appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
790   //     returns the new child
791   //
792   // public function appendElementSelect($name, [$id], [$options], [$default])
793   //   appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
794   //     returns the new child
795   //
796   // public function appendElementOption($key, $desc, [$selected])
797   //   appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
798   //     returns the new child
799   //
800   // public function appendLabel($for_id, $value)
801   //   appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
802   //     returns the new child
803   //
804   // public function appendText($text)
805   //   appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
806   //     returns the new child
807   //
808   // public function appendComment($comment_data)
809   //   appends a DOMDocument::createComment() as a child of this fragment (see there for params)
810   //     returns the new child
811   //
812   // public function appendHTMLMarkup($htmldata)
813   //   appends a representation of the HTML data as children of this fragment
814   //     NO return value!
815   //
816   // public function appendXMLMarkup($xmldata)
817   //   appends a representation of the XML data as children of this fragment
818   //     NO return value!
819   //
820   // public function appendJSElement($jsdata)
821   //   appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
822   //     NO return value!
823   //
824   // public function appendCOMElement($module, $attributes)
825   //   appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
826   //     returns the new child
827   //
828   // public function appendCOMElement($module, $attributes)
829   //   appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
830   //     returns the new child
831
832   public function appendElement($name, $value = '') {
833     return $this->appendChild($this->ownerDocument->createElement($name, $value));
834   }
835   public function appendElementXML($name, $xmldata) {
836     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
837     $aelem->appendXMLMarkup($xmldata);
838     return $aelem;
839   }
840   public function appendLink($target, $value = '') {
841     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
842   }
843   public function appendImage($src, $alt_text = '') {
844     return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
845   }
846   public function appendForm($action, $method, $name, $id = null) {
847     return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
848   }
849   public function appendFormDiv($action, $method, $name, $id = null) {
850     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
851     return $formelem->appendElement('div');
852   }
853   public function appendInputHidden($name, $value) {
854     return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
855   }
856   public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
857     return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
858   }
859   public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
860     return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
861   }
862   public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
863     return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
864   }
865   public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
866     return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
867   }
868   public function appendInputRadio($name, $id, $value, $checked) {
869     return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
870   }
871   public function appendInputCheckbox($name, $id, $value, $checked) {
872     return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
873   }
874   public function appendInputFile($name, $id, $accept) {
875     return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
876   }
877   public function appendInputSubmit($value) {
878     return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
879   }
880   public function appendButton($value, $onclick = null) {
881     return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
882   }
883   public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
884     return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
885   }
886   public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
887     return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
888   }
889   public function appendElementOption($key, $desc, $selected = false) {
890     return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
891   }
892   public function appendLabel($for_id, $value) {
893     return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
894   }
895   public function appendText($text) {
896     return $this->appendChild($this->ownerDocument->createTextNode($text));
897   }
898   public function appendComment($comment_data) {
899     return $this->appendChild($this->ownerDocument->createComment($comment_data));
900   }
901   public function appendHTMLMarkup($htmldata) {
902     $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
903   }
904   public function appendXMLMarkup($xmldata) {
905     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
906   }
907   public function appendJSElement($jsdata) {
908     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
909   }
910   public function appendJSFile($jsdata) {
911     return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
912   }
913   public function appendCOMElement($module, $attributes) {
914     return $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
915   }
916 }
917 ?>