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