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