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