## Apache Zeta Components Manual :: File Source for creativecommons_module.php

## Source for file creativecommons_module.php

Documentation is available at creativecommons_module.php

1. <?php
2. /**
3. * File containing the ezcFeedCreativeCommonsModule class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @package Feed
23. * @version //autogentag//
24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
25. * @filesource
26. */
28. /**
29. * Support for the CreativeCommons module: data container, generator, parser.
30. *
31. * Specifications: {@link http://backend.userland.com/creativeCommonsRssModule}.
32. *
33. * Create example:
34. *
35. * <code>
36. * <?php
37. * // $feed is an ezcFeed object
38. * $item = $feed->add( 'item' );
39. * $module = $item->addModule( 'CreativeCommons' );
40. * $module->license = 'text content';
41. * ?>
42. * </code>
43. *
44. * Parse example:
45. *
46. * <code>
47. * <?php
48. * // $item is an ezcFeedEntryElement object
49. * $text = $item->CreativeCommons->license;
50. * ?>
51. * </code>
52. *
53. * @property ezcFeedElement $license
54. * An URL to a license description. Can appear at both
55. * feed-level and item-level. A list of possible licenses
56. * are found here {@link http://creativecommons.org/licenses/},
57. * but other licenses can be used as well.
58. *
59. * @package Feed
60. * @version //autogentag//
61. */
62. class ezcFeedCreativeCommonsModule extends ezcFeedModule
63. {
64. /**
65. * Constructs a new ezcFeedCreativeCommonsModule object.
66. *
67. * @param string $level The level of the data container ('feed' or 'item')
68. */
69. public function __construct ( $level = 'feed' )
70. {
71. parent:: __construct ( $level );
72. }
74. /**
75. * Sets the property $name to $value.
76. *
77. * @throws ezcBasePropertyNotFoundException
78. * if the property $name is not defined
79. *
80. * @param string $name The property name
81. * @param mixed $value The property value
82. * @ignore
83. */
84. public function __set( $name, $value )
85. {
86. if ( $this-> isElementAllowed ( $name ) )
87. {
88. $node = $this-> add ( $name );
89. $node->text = $value;
90. }
91. else
92. {
93. parent::__set( $name, $value );
94. }
95. }
97. /**
98. * Returns the value of property $name.
99. *
100. * @throws ezcBasePropertyNotFoundException
101. * if the property $name is not defined
102. *
103. * @param string $name The property name
104. * @return mixed
105. * @ignore
106. */
107. public function __get( $name )
108. {
109. if ( $this-> isElementAllowed ( $name ) )
110. {
111. return $this-> properties [$name];
112. }
113. else
114. {
115. return parent::__get( $name );
116. }
117. }
119. /**
120. * Returns if the property $name is set.
121. *
122. * @param string $name The property name
123. * @return bool
124. * @ignore
125. */
126. public function __isset( $name )
127. {
128. if ( $this-> isElementAllowed ( $name ) )
129. {
130. return isset( $this-> properties [$name] );
131. }
132. else
133. {
134. return parent::__isset( $name );
135. }
136. }
138. /**
139. * Returns true if the element $name is allowed in the current module at the
140. * current level (feed or item), and false otherwise.
141. *
142. * @param string $name The element name to check if allowed in the current module and level (feed or item)
143. * @return bool
144. */
145. public function isElementAllowed ( $name )
146. {
147. switch ( $this-> level )
148. {
149. case 'feed':
150. if ( in_array ( $name, array( 'license' ) ) )
151. {
152. return true;
153. }
154. break;
156. case 'item':
157. if ( in_array ( $name, array( 'license' ) ) )
158. {
159. return true;
160. }
161. break;
162. }
163. return false;
164. }
166. /**
167. * Adds a new ezcFeedElement element with name $name to this module and
168. * returns it.
169. *
170. * @throws ezcFeedUnsupportedElementException
171. * if trying to add an element which is not supported.
172. *
173. * @param string $name The element name
174. * @return ezcFeedElement
175. */
176. public function add ( $name )
177. {
178. if ( $this-> isElementAllowed ( $name ) )
179. {
180. switch ( $name )
181. {
182. case 'license':
183. $node = new ezcFeedTextElement ();
184. break;
185. }
187. $this-> properties [$name] = $node;
188. return $node;
189. }
190. else
191. {
192. throw new ezcFeedUnsupportedElementException ( $name );
193. }
194. }
196. /**
197. * Adds the module elements to the $xml XML document, in the container $root.
198. *
199. * @param DOMDocument $xml The XML document in which to add the module elements
200. * @param DOMNode $root The parent node which will contain the module elements
201. */
202. public function generate ( DOMDocument $xml, DOMNode $root )
203. {
204. if ( isset( $this->license ) )
205. {
206. $elementTag = $xml->createElement( $this-> getNamespacePrefix () . ':' . 'license' );
207. $root->appendChild( $elementTag );
209. $elementTag->nodeValue = $this->license->__toString();
210. }
211. }
213. /**
214. * Parses the XML element $node and creates a feed element in the current
215. * module with name $name.
216. *
217. * @param string $name The name of the element belonging to the module
218. * @param DOMElement $node The XML child from which to take the values for $name
219. */
220. public function parse ( $name, DOMElement $node )
221. {
222. if ( $this-> isElementAllowed ( $name ) )
223. {
224. $element = $this-> add ( $name );
225. $value = $node->textContent;
227. switch ( $name )
228. {
229. case 'license':
230. $element->text = $value;
231. break;
232. }
233. }
234. }
236. /**
237. * Returns the module name ('CreativeCommons').
238. *
239. * @return string
240. */
241. public static function getModuleName ()
242. {
243. return 'CreativeCommons';
244. }
246. /**
247. * Returns the namespace for this module ('http://backend.userland.com/creativeCommonsRssModule').
248. *
249. * @return string
250. */
251. public static function getNamespace ()
252. {
253. return 'http://backend.userland.com/creativeCommonsRssModule';
254. }
256. /**
257. * Returns the namespace prefix for this module ('creativeCommons').
258. *
259. * @return string
260. */
261. public static function getNamespacePrefix ()
262. {
263. return 'creativeCommons';
264. }
265. }
266. ?>

Documentation generated by phpDocumentor 1.4.3