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