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