2 /* ***** BEGIN LICENSE BLOCK *****
4 * The contents of this file are subject to Austrian copyright reegulations
5 * ("Urheberrecht"); you may not use this file except in compliance with
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.
11 * The Original Code is KaiRo's extended DOM document classes.
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.
18 * Contributor(s): Robert Kaiser <kairo@kairo.at>
20 * ***** END LICENSE BLOCK ***** */
22 class ExtendedDocument extends DOMDocument {
23 // ExtendedDocument PHP class
24 // this extends the general PHP DOM Document class to simplify some usual constructs
26 // function __construct([$version], [$encoding])
28 // construct a new DOM Document that uses our element definitions
30 // function appendElement($name, [$value])
31 // appends a DOMDocument::createElement() as a child of this document (see there for params)
32 // returns the new child
34 // function appendElementXML($name, $xmldata)
35 // appends a DOMDocument::createElement() with the given name as a child of this document,
36 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
37 // returns the new child
39 // function appendLink($target, [$value])
40 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
41 // returns the new child
43 // function appendText($text)
44 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
45 // returns the new child
47 // function appendRawMarkup($markupdata)
48 // appends an ExtendedDocument::createElementRawMarkup() as a child of this document (see there for params)
51 // function appendJSElement($jsdata)
52 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
55 // function createXMLFragment($xmldata)
56 // returns a DOMDocumentFragment containing the DOM of the given XML data
58 // function createElementLink($target, [$value])
59 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
61 // function createElementRawMarkup($markupdata)
62 // returns a DOMNode containing a representation of the given raw markup data
64 // function createElementJS($jsdata)
65 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
67 function __construct($version = '1.0', $encoding = 'utf-8') {
68 // make sure the default DOMDocument constructor runs
69 parent::__construct($version, $encoding);
70 $this->registerNodeClass('DOMElement', 'ExtendedElement');
73 function appendElement($name, $value = '') {
74 return $this->appendChild($this->createElement($name, $value));
76 function appendElementXML($name, $xmldata) {
77 $aelem = $this->appendChild($this->createElement($name));
78 $aelem->appendChild($this->createXMLFragment($xmldata));
81 function appendLink($target, $value = '') {
82 return $this->appendChild($this->createElementLink($target, $value));
84 function appendText($text) {
85 return $this->appendChild($this->createTextNode($text));
87 function appendRawMarkup($markupdata) {
88 $this->appendChild($this->createElementRawMarkup($markupdata));
90 function appendJSElement($jsdata) {
91 $this->appendChild($this->createElementJS($jsdata));
94 function createXMLFragment($xmldata) {
95 $xmlfragment = $this->createDocumentFragment();
96 $xmlfragment->appendXML($xmldata);
100 function createElementLink($target, $value = '') {
101 $link = $this->createElement('a', $value);
102 $link->setAttribute('href', $target);
106 function createElementRawMarkup($markupdata) {
107 // XXX: just a workaround for now!
108 return $this->createCDATASection($markupdata);
111 function createElementJS($jsdata) {
112 $jselem = $this->createElement('script');
113 $jselem->setAttribute('type', 'text/javascript');
114 $jselem->appendChild($this->createCDATASection($jsdata));
119 class ExtendedElement extends DOMElement {
120 // ExtendedElement PHP class
121 // this extends the general PHP DOM Element class to simplify some usual constructs
123 // function appendElement($name, [$value])
124 // appends a DOMDocument::createElement() as a child of this element (see there for params)
125 // returns the new child
127 // function appendElementXML($name, $xmldata)
128 // appends a DOMDocument::createElement() with the given name as a child of this element,
129 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
130 // returns the new child
132 // function appendLink($target, [$value])
133 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
134 // returns the new child
136 // function appendText($text)
137 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
138 // returns the new child
140 // function appendRawMarkup($markupdata)
141 // appends an ExtendedDocument::createElementRawMarkup() as a child of this element (see there for params)
144 // function appendJSElement($jsdata)
145 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
148 function appendElement($name, $value = '') {
149 return $this->appendChild($this->ownerDocument->createElement($name, $value));
151 function appendElementXML($name, $xmldata) {
152 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
153 $aelem->appendChild($this->ownerDocument->createXMLFragment($xmldata));
156 function appendLink($target, $value = '') {
157 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
159 function appendText($text) {
160 return $this->appendChild($this->ownerDocument->createTextNode($text));
162 function appendRawMarkup($markupdata) {
163 $this->appendChild($this->ownerDocument->createElementRawMarkup($markupdata));
165 function appendJSElement($jsdata) {
166 $this->appendChild($this->ownerDocument->createElementJS($jsdata));