explicitly mark functions as public
[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 //
61cc8aa9 34 // public function appendElement($name, [$value])
cea5b93a
RK
35 // appends a DOMDocument::createElement() as a child of this document (see there for params)
36 // returns the new child
37 //
61cc8aa9 38 // public function appendElementXML($name, $xmldata)
cea5b93a
RK
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 //
61cc8aa9 43 // public function appendLink($target, [$value])
cea5b93a
RK
44 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
45 // returns the new child
46 //
61cc8aa9 47 // public function appendImage($src, [$alt_text])
53510e9e
RK
48 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
49 // returns the new child
50 //
61cc8aa9 51 // public function appendForm($action, $method, $name, [$id])
b8d16837
RK
52 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
53 // returns the new child
54 //
61cc8aa9 55 // public 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 //
61cc8aa9 59 // public function appendInputHidden($name, $value)
ae41c41b
RK
60 // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
61 // returns the new child
62 //
61cc8aa9 63 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
ae41c41b
RK
64 // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
65 // returns the new child
66 //
61cc8aa9 67 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
68 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
69 // returns the new child
70 //
61cc8aa9 71 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
645a7eb6
RK
72 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
73 // returns the new child
74 //
61cc8aa9 75 // public function appendInputRadio($name, $id, $value, $checked)
ae41c41b
RK
76 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
77 // returns the new child
78 //
61cc8aa9 79 // public function appendInputCheckbox($name, $id, $value, $checked)
ae41c41b
RK
80 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
81 // returns the new child
82 //
61cc8aa9 83 // public function appendInputFile($name, $id, $accept)
4bb9d784
RK
84 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
85 // returns the new child
86 //
61cc8aa9 87 // public function appendInputSubmit($value)
ae41c41b
RK
88 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
89 // returns the new child
90 //
61cc8aa9 91 // public function appendButton($value, $onclick = null)
1109f526
RK
92 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
93 // returns the new child
94 //
61cc8aa9 95 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
96 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
97 // returns the new child
98 //
61cc8aa9 99 // public function appendElementSelect($name, [$id], [$options], [$default])
bf91764c
RK
100 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
101 // returns the new child
102 //
61cc8aa9 103 // public function appendElementOption($key, $desc, [$selected])
bf91764c
RK
104 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
105 // returns the new child
106 //
61cc8aa9 107 // public function appendLabel($for_id, $value)
ae41c41b
RK
108 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
109 // returns the new child
110 //
61cc8aa9 111 // public function appendText($text)
cea5b93a
RK
112 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
113 // returns the new child
114 //
61cc8aa9 115 // public function appendComment($comment_data)
cadc5980
RK
116 // appends a DOMDocument::createComment() as a child of this document (see there for params)
117 // returns the new child
118 //
61cc8aa9 119 // public function appendHTMLMarkup($htmldata, [$parentNode])
ae41c41b
RK
120 // appends a representation of the HTML data as children of the given parent node, by default this document
121 // NO return value!
122 //
61cc8aa9 123 // public function appendXMLMarkup($xmldata, [$parentNode])
ae41c41b 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 //
61cc8aa9 127 // public function appendJSElement($jsdata)
cea5b93a
RK
128 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
129 // NO return value!
130 //
61cc8aa9 131 // public function appendCOMElement($module, $attributes)
c1666e91
RK
132 // appends an ExtendedDocument::createCOMElement() as a child of this document (see there for params)
133 // returns the new child
134 //
61cc8aa9 135 // public function createElementLink($target, [$value])
cea5b93a
RK
136 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
137 //
61cc8aa9 138 // public function createElementImage($src, [$alt_text])
53510e9e
RK
139 // returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
140 //
61cc8aa9 141 // public function createElementForm($action, $method, $name)
ae41c41b
RK
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 //
61cc8aa9 145 // public function createElementInputHidden($name, $value)
ae41c41b
RK
146 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
147 //
61cc8aa9 148 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
ae41c41b
RK
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 //
61cc8aa9 152 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
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 //
61cc8aa9 156 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
645a7eb6
RK
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 //
61cc8aa9 160 // public function createElementInputRadio($name, $id, $value, $checked)
ae41c41b
RK
161 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
162 // checked state
163 //
61cc8aa9 164 // public function createElementInputCheckbox($name, $id, $value, $checked)
ae41c41b
RK
165 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
166 // checked state
167 //
61cc8aa9 168 // public function createElementInputFile($name, $id, $accept)
4bb9d784
RK
169 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
170 //
61cc8aa9 171 // public function createElementInputSubmit($value)
1109f526
RK
172 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
173 //
61cc8aa9 174 // public function createElementButton($value, $onclick = null)
1109f526 175 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
ae41c41b 176 //
61cc8aa9 177 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
178 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
179 // and optionally id and value
180 //
61cc8aa9 181 // public function createElementSelect($name, [$id], [$options], [$default])
bf91764c
RK
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 //
61cc8aa9 185 // public function createElementOption($key, $desc, [$selected])
bf91764c
RK
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 //
61cc8aa9 189 // public function createElementLabel($for_id, $value)
ae41c41b 190 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
cea5b93a 191 //
61cc8aa9 192 // public function createElementJS($jsdata)
cea5b93a 193 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
c1666e91 194 //
61cc8aa9 195 // public function createCOMElement($module, $attributes)
c1666e91
RK
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
61cc8aa9 223 public function appendElement($name, $value = '') {
a8816f43 224 return $this->appendChild($this->createElement($name, $value));
cea5b93a 225 }
61cc8aa9 226 public function appendElementXML($name, $xmldata) {
cea5b93a 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 }
61cc8aa9 232 public function appendLink($target, $value = '') {
cea5b93a
RK
233 return $this->appendChild($this->createElementLink($target, $value));
234 }
61cc8aa9 235 public function appendImage($src, $alt_text = '') {
4aa31782
RK
236 return $this->appendChild($this->createElementImage($src, $alt_text));
237 }
61cc8aa9 238 public function appendForm($action, $method, $name, $id = null) {
b8d16837
RK
239 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
240 }
61cc8aa9 241 public function appendFormDiv($action, $method, $name, $id = null) {
b8d16837 242 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
ae41c41b
RK
243 return $formelem->appendElement('div');
244 }
61cc8aa9 245 public function appendInputHidden($name, $value) {
ae41c41b
RK
246 return $this->appendChild($this->createElementInputHidden($name, $value));
247 }
61cc8aa9 248 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
ae41c41b
RK
249 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
250 }
61cc8aa9 251 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
252 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
253 }
61cc8aa9 254 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
645a7eb6
RK
255 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
256 }
61cc8aa9 257 public function appendInputRadio($name, $id, $value, $checked) {
ae41c41b
RK
258 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
259 }
61cc8aa9 260 public function appendInputCheckbox($name, $id, $value, $checked) {
ae41c41b
RK
261 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
262 }
61cc8aa9 263 public function appendInputFile($name, $id, $accept) {
4bb9d784
RK
264 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
265 }
61cc8aa9 266 public function appendInputSubmit($value) {
ae41c41b
RK
267 return $this->appendChild($this->createElementInputSubmit($value));
268 }
61cc8aa9 269 public function appendButton($value, $onclick = null) {
1109f526
RK
270 return $this->appendChild($this->createElementButton($value, $onclick));
271 }
61cc8aa9 272 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
273 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
274 }
61cc8aa9 275 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
bf91764c
RK
276 return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
277 }
61cc8aa9 278 public function appendElementOption($key, $desc, $selected = false) {
bf91764c
RK
279 return $this->appendChild($this->createElementOption($key, $desc, $selected));
280 }
61cc8aa9 281 public function appendLabel($for_id, $value) {
ae41c41b
RK
282 return $this->appendChild($this->createElementLabel($for_id, $value));
283 }
61cc8aa9 284 public function appendText($text) {
cea5b93a
RK
285 return $this->appendChild($this->createTextNode($text));
286 }
61cc8aa9 287 public function appendComment($comment_data) {
cadc5980
RK
288 return $this->appendChild($this->createComment($comment_data));
289 }
61cc8aa9 290 public function appendJSElement($jsdata) {
cea5b93a
RK
291 $this->appendChild($this->createElementJS($jsdata));
292 }
61cc8aa9 293 public function appendCOMElement($module, $attributes) {
c1666e91
RK
294 $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
295 }
cea5b93a 296
61cc8aa9 297 public function appendHTMLMarkup($htmldata, $parentNode = null) {
ae41c41b
RK
298 if (is_null($parentNode)) { $parentNode =& $this; }
299 // XXX: just a workaround for now!
300 $parentNode->appendChild($this->createCDATASection($htmldata));
301 }
302
61cc8aa9 303 public function appendXMLMarkup($xmldata, $parentNode = null) {
ae41c41b
RK
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
61cc8aa9 315 public function createElement($name, $value = '') {
a8816f43
RK
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
61cc8aa9 322 public 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
61cc8aa9 328 public 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
61cc8aa9 335 public 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
61cc8aa9 344 public function createElementInputHidden($name, $value) {
ae41c41b
RK
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
61cc8aa9 352 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
ae41c41b
RK
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
61cc8aa9 363 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
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
61cc8aa9 374 public 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
61cc8aa9 385 public function createElementInputRadio($name, $id, $value, $checked) {
ae41c41b
RK
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
61cc8aa9 395 public function createElementInputCheckbox($name, $id, $value, $checked) {
ae41c41b
RK
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
61cc8aa9 405 public function createElementInputFile($name, $id, $accept) {
4bb9d784
RK
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
61cc8aa9 414 public function createElementInputSubmit($value) {
ae41c41b
RK
415 $submitbtn = $this->createElement('input');
416 $submitbtn->setAttribute('type', 'submit');
417 $submitbtn->setAttribute('value', $value);
418 return $submitbtn;
419 }
420
61cc8aa9 421 public function createElementButton($value, $onclick = null) {
1109f526
RK
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
61cc8aa9 429 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
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
61cc8aa9 438 public function createElementSelect($name, $id = null, $options = array(), $default = null) {
bf91764c
RK
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
61cc8aa9 448 public function createElementOption($key, $desc, $selected = false) {
bf91764c
RK
449 $option = $this->createElement('option', $desc);
450 $option->setAttribute('value', $key);
451 if ($selected) { $option->setAttribute('selected', ''); }
452 return $option;
453 }
454
61cc8aa9 455 public function createElementLabel($for_id, $value) {
ae41c41b
RK
456 $label = $this->createElement('label', $value);
457 $label->setAttribute('for', $for_id);
458 return $label;
cea5b93a
RK
459 }
460
61cc8aa9 461 public function createElementJS($jsdata) {
cea5b93a
RK
462 $jselem = $this->createElement('script');
463 $jselem->setAttribute('type', 'text/javascript');
464 $jselem->appendChild($this->createCDATASection($jsdata));
465 return $jselem;
466 }
c1666e91 467
61cc8aa9 468 public function createCOMElement($module, $attributes) {
c1666e91
RK
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 //
61cc8aa9 483 // public function appendElement($name, [$value])
cea5b93a
RK
484 // appends a DOMDocument::createElement() as a child of this element (see there for params)
485 // returns the new child
486 //
61cc8aa9 487 // public function appendElementXML($name, $xmldata)
cea5b93a
RK
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 //
61cc8aa9 492 // public function appendLink($target, [$value])
cea5b93a
RK
493 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
494 // returns the new child
495 //
61cc8aa9 496 // public function appendImage($src, [$alt_text])
53510e9e
RK
497 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
498 // returns the new child
499 //
61cc8aa9 500 // public function appendForm($action, $method, $name, [$id])
b8d16837
RK
501 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
502 // returns the new child
503 //
61cc8aa9 504 // public 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 //
61cc8aa9 508 // public function appendInputHidden($name, $value)
ae41c41b
RK
509 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
510 // returns the new child
511 //
61cc8aa9 512 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
ae41c41b
RK
513 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
514 // returns the new child
515 //
61cc8aa9 516 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
517 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
518 // returns the new child
519 //
61cc8aa9 520 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
645a7eb6
RK
521 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
522 // returns the new child
523 //
61cc8aa9 524 // public function appendInputRadio($name, $id, $value, $checked)
ae41c41b
RK
525 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
526 // returns the new child
527 //
61cc8aa9 528 // public function appendInputCheckbox($name, $id, $value, $checked)
ae41c41b
RK
529 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
530 // returns the new child
531 //
61cc8aa9 532 // public function appendInputFile($name, $id, $accept)
4bb9d784
RK
533 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
534 // returns the new child
535 //
61cc8aa9 536 // public function appendInputSubmit($value)
ae41c41b
RK
537 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
538 // returns the new child
539 //
61cc8aa9 540 // public function appendButton($value, $onclick = null)
1109f526
RK
541 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
542 // returns the new child
543 //
61cc8aa9 544 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
545 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
546 // returns the new child
547 //
61cc8aa9 548 // public function appendElementSelect($name, [$id], [$options], [$default])
bf91764c
RK
549 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
550 // returns the new child
551 //
61cc8aa9 552 // public function appendElementOption($key, $desc, [$selected])
bf91764c
RK
553 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
554 // returns the new child
555 //
61cc8aa9 556 // public function appendLabel($for_id, $value)
ae41c41b
RK
557 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
558 // returns the new child
559 //
61cc8aa9 560 // public function appendText($text)
cea5b93a
RK
561 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
562 // returns the new child
563 //
61cc8aa9 564 // public function appendComment($comment_data)
cadc5980
RK
565 // appends a DOMDocument::createComment() as a child of this element (see there for params)
566 // returns the new child
567 //
61cc8aa9 568 // public function appendHTMLMarkup($htmldata)
ae41c41b
RK
569 // appends a representation of the HTML data as children of this element
570 // NO return value!
571 //
61cc8aa9 572 // public function appendXMLMarkup($xmldata)
ae41c41b 573 // appends a representation of the XML data as children of this element
cea5b93a
RK
574 // NO return value!
575 //
61cc8aa9 576 // public function appendJSElement($jsdata)
cea5b93a
RK
577 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
578 // NO return value!
c1666e91 579 //
61cc8aa9 580 // public function appendCOMElement($module, $attributes)
c1666e91
RK
581 // appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
582 // returns the new child
cea5b93a 583
61cc8aa9 584 public function appendElement($name, $value = '') {
a8816f43 585 return $this->appendChild($this->ownerDocument->createElement($name, $value));
cea5b93a 586 }
61cc8aa9 587 public function appendElementXML($name, $xmldata) {
cea5b93a 588 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
ae41c41b 589 $aelem->appendXMLMarkup($xmldata);
cea5b93a
RK
590 return $aelem;
591 }
61cc8aa9 592 public function appendLink($target, $value = '') {
cea5b93a
RK
593 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
594 }
61cc8aa9 595 public function appendImage($src, $alt_text = '') {
53510e9e
RK
596 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
597 }
61cc8aa9 598 public function appendForm($action, $method, $name, $id = null) {
b8d16837
RK
599 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
600 }
61cc8aa9 601 public function appendFormDiv($action, $method, $name, $id = null) {
b8d16837 602 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
ae41c41b
RK
603 return $formelem->appendElement('div');
604 }
61cc8aa9 605 public function appendInputHidden($name, $value) {
ae41c41b
RK
606 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
607 }
61cc8aa9 608 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
ae41c41b
RK
609 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
610 }
61cc8aa9 611 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
612 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
613 }
61cc8aa9 614 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
645a7eb6
RK
615 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
616 }
61cc8aa9 617 public function appendInputRadio($name, $id, $value, $checked) {
ae41c41b
RK
618 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
619 }
61cc8aa9 620 public function appendInputCheckbox($name, $id, $value, $checked) {
ae41c41b
RK
621 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
622 }
61cc8aa9 623 public function appendInputFile($name, $id, $accept) {
4bb9d784
RK
624 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
625 }
61cc8aa9 626 public function appendInputSubmit($value) {
ae41c41b
RK
627 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
628 }
61cc8aa9 629 public function appendButton($value, $onclick = null) {
1109f526
RK
630 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
631 }
61cc8aa9 632 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
633 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
634 }
61cc8aa9 635 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
bf91764c
RK
636 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
637 }
61cc8aa9 638 public function appendElementOption($key, $desc, $selected = false) {
bf91764c
RK
639 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
640 }
61cc8aa9 641 public function appendLabel($for_id, $value) {
bf91764c
RK
642 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
643 }
61cc8aa9 644 public function appendText($text) {
bf91764c
RK
645 return $this->appendChild($this->ownerDocument->createTextNode($text));
646 }
61cc8aa9 647 public function appendComment($comment_data) {
cadc5980
RK
648 return $this->appendChild($this->ownerDocument->createComment($comment_data));
649 }
61cc8aa9 650 public function appendHTMLMarkup($htmldata) {
bf91764c
RK
651 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
652 }
61cc8aa9 653 public function appendXMLMarkup($xmldata) {
bf91764c
RK
654 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
655 }
61cc8aa9 656 public function appendJSElement($jsdata) {
bf91764c
RK
657 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
658 }
61cc8aa9 659 public function appendCOMElement($module, $attributes) {
c1666e91
RK
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 //
61cc8aa9 668 // public function appendElement($name, [$value])
bf91764c
RK
669 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
670 // returns the new child
671 //
61cc8aa9 672 // public function appendElementXML($name, $xmldata)
bf91764c
RK
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 //
61cc8aa9 677 // public function appendLink($target, [$value])
bf91764c
RK
678 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
679 // returns the new child
680 //
61cc8aa9 681 // public function appendImage($src, [$alt_text])
53510e9e
RK
682 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
683 // returns the new child
684 //
61cc8aa9 685 // public function appendForm($action, $method, $name, [$id])
b8d16837
RK
686 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
687 // returns the new child
688 //
61cc8aa9 689 // public 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 //
61cc8aa9 693 // public function appendInputHidden($name, $value)
bf91764c
RK
694 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
695 // returns the new child
696 //
61cc8aa9 697 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
bf91764c
RK
698 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
699 // returns the new child
700 //
61cc8aa9 701 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
702 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
703 // returns the new child
704 //
61cc8aa9 705 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
645a7eb6
RK
706 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
707 // returns the new child
708 //
61cc8aa9 709 // public function appendInputRadio($name, $id, $value, $checked)
bf91764c
RK
710 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
711 // returns the new child
712 //
61cc8aa9 713 // public function appendInputCheckbox($name, $id, $value, $checked)
bf91764c
RK
714 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
715 // returns the new child
716 //
61cc8aa9 717 // public function appendInputFile($name, $id, $accept)
4bb9d784
RK
718 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
719 // returns the new child
720 //
61cc8aa9 721 // public function appendInputSubmit($value)
bf91764c
RK
722 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
723 // returns the new child
724 //
61cc8aa9 725 // public function appendButton($value, $onclick = null)
1109f526
RK
726 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
727 // returns the new child
728 //
61cc8aa9 729 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
730 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
731 // returns the new child
732 //
61cc8aa9 733 // public function appendElementSelect($name, [$id], [$options], [$default])
bf91764c
RK
734 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
735 // returns the new child
736 //
61cc8aa9 737 // public function appendElementOption($key, $desc, [$selected])
bf91764c
RK
738 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
739 // returns the new child
740 //
61cc8aa9 741 // public function appendLabel($for_id, $value)
bf91764c
RK
742 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
743 // returns the new child
744 //
61cc8aa9 745 // public function appendText($text)
bf91764c
RK
746 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
747 // returns the new child
748 //
61cc8aa9 749 // public function appendComment($comment_data)
cadc5980
RK
750 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
751 // returns the new child
752 //
61cc8aa9 753 // public function appendHTMLMarkup($htmldata)
bf91764c
RK
754 // appends a representation of the HTML data as children of this fragment
755 // NO return value!
756 //
61cc8aa9 757 // public function appendXMLMarkup($xmldata)
bf91764c
RK
758 // appends a representation of the XML data as children of this fragment
759 // NO return value!
760 //
61cc8aa9 761 // public function appendJSElement($jsdata)
bf91764c
RK
762 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
763 // NO return value!
c1666e91 764 //
61cc8aa9 765 // public function appendCOMElement($module, $attributes)
c1666e91
RK
766 // appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
767 // returns the new child
bf91764c 768
61cc8aa9 769 public function appendElement($name, $value = '') {
a8816f43 770 return $this->appendChild($this->ownerDocument->createElement($name, $value));
bf91764c 771 }
61cc8aa9 772 public function appendElementXML($name, $xmldata) {
bf91764c
RK
773 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
774 $aelem->appendXMLMarkup($xmldata);
775 return $aelem;
776 }
61cc8aa9 777 public function appendLink($target, $value = '') {
bf91764c
RK
778 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
779 }
61cc8aa9 780 public function appendImage($src, $alt_text = '') {
53510e9e
RK
781 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
782 }
61cc8aa9 783 public function appendForm($action, $method, $name, $id = null) {
b8d16837
RK
784 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
785 }
61cc8aa9 786 public function appendFormDiv($action, $method, $name, $id = null) {
b8d16837 787 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
bf91764c
RK
788 return $formelem->appendElement('div');
789 }
61cc8aa9 790 public function appendInputHidden($name, $value) {
bf91764c
RK
791 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
792 }
61cc8aa9 793 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
bf91764c 794 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
645a7eb6 795 }
61cc8aa9 796 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
797 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
798 }
61cc8aa9 799 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
645a7eb6 800 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
bf91764c 801 }
61cc8aa9 802 public function appendInputRadio($name, $id, $value, $checked) {
bf91764c
RK
803 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
804 }
61cc8aa9 805 public function appendInputCheckbox($name, $id, $value, $checked) {
bf91764c
RK
806 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
807 }
61cc8aa9 808 public function appendInputFile($name, $id, $accept) {
4bb9d784
RK
809 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
810 }
61cc8aa9 811 public function appendInputSubmit($value) {
bf91764c
RK
812 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
813 }
61cc8aa9 814 public function appendButton($value, $onclick = null) {
1109f526
RK
815 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
816 }
61cc8aa9 817 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
818 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
819 }
61cc8aa9 820 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
bf91764c
RK
821 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
822 }
61cc8aa9 823 public function appendElementOption($key, $desc, $selected = false) {
bf91764c
RK
824 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
825 }
61cc8aa9 826 public function appendLabel($for_id, $value) {
ae41c41b
RK
827 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
828 }
61cc8aa9 829 public function appendText($text) {
cea5b93a
RK
830 return $this->appendChild($this->ownerDocument->createTextNode($text));
831 }
61cc8aa9 832 public function appendComment($comment_data) {
cadc5980
RK
833 return $this->appendChild($this->ownerDocument->createComment($comment_data));
834 }
61cc8aa9 835 public function appendHTMLMarkup($htmldata) {
ae41c41b
RK
836 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
837 }
61cc8aa9 838 public function appendXMLMarkup($xmldata) {
ae41c41b 839 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
cea5b93a 840 }
61cc8aa9 841 public function appendJSElement($jsdata) {
cea5b93a
RK
842 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
843 }
61cc8aa9 844 public function appendCOMElement($module, $attributes) {
c1666e91
RK
845 $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
846 }
cea5b93a
RK
847}
848?>