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