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