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