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

## Source for file content_module.php

Documentation is available at content_module.php

1. <?php
2. /**
3. * File containing the ezcFeedContentModule 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 Content module: data container, generator, parser.
30. *
31. * Specifications: {@link http://purl.org/rss/1.0/modules/content/}. Only support
32. * for the 'encoded' element of the Content module is provided.
33. *
34. * Create example:
35. *
36. * <code>
37. * <?php
38. * // $feed is an ezcFeed object
39. * $item = $feed->add( 'item' );
40. * $module = $item->addModule( 'Content' );
41. * $module->encoded = 'text content';
42. * ?>
43. * </code>
44. *
45. * Parse example:
46. *
47. * <code>
48. * <?php
49. * // $item is an ezcFeedEntryElement object
50. * $text = $item->Content->encoded;
51. * ?>
52. * </code>
53. *
54. * @property ezcFeedTextElement $encoded
55. * Item-level container for text. The text is stored
56. * in a feed by applying htmlspecialchars() with
57. * ENT_NOQUOTES and restored from a feed with
58. * htmlspecialchars_decode() with ENT_NOQUOTES.
59. *
60. * @package Feed
61. * @version //autogentag//
62. */
63. class ezcFeedContentModule extends ezcFeedModule
64. {
65. /**
66. * Constructs a new ezcFeedContentModule object.
67. *
68. * @param string $level The level of the data container ('feed' or 'item')
69. */
70. public function __construct ( $level = 'feed' )
71. {
72. parent:: __construct ( $level );
73. }
75. /**
76. * Sets the property $name to $value.
77. *
78. * @throws ezcBasePropertyNotFoundException
79. * if the property $name is not defined
80. *
81. * @param string $name The property name
82. * @param mixed $value The property value
83. * @ignore
84. */
85. public function __set( $name, $value )
86. {
87. if ( $this-> isElementAllowed ( $name ) )
88. {
89. $node = $this-> add ( $name );
90. $node->text = $value;
91. }
92. else
93. {
94. parent::__set( $name, $value );
95. }
96. }
98. /**
99. * Returns the value of property $name.
100. *
101. * @throws ezcBasePropertyNotFoundException
102. * if the property $name is not defined
103. *
104. * @param string $name The property name
105. * @return mixed
106. * @ignore
107. */
108. public function __get( $name )
109. {
110. if ( $this-> isElementAllowed ( $name ) )
111. {
112. if ( isset( $this-> properties [$name] ) )
113. {
114. return $this-> properties [$name];
115. }
116. }
117. return parent::__get( $name );
118. }
120. /**
121. * Returns if the property $name is set.
122. *
123. * @param string $name The property name
124. * @return bool
125. * @ignore
126. */
127. public function __isset( $name )
128. {
129. if ( $this-> isElementAllowed ( $name ) )
130. {
131. return isset( $this-> properties [$name] );
132. }
133. else
134. {
135. return parent::__isset( $name );
136. }
137. }
139. /**
140. * Returns true if the element $name is allowed in the current module at the
141. * current level (feed or item), and false otherwise.
142. *
143. * @param string $name The element name to check if allowed in the current module and level (feed or item)
144. * @return bool
145. */
146. public function isElementAllowed ( $name )
147. {
148. switch ( $this-> level )
149. {
150. case 'feed':
151. // no support yet for content:encoded element at feed-level
152. return false;
154. case 'item':
155. if ( in_array ( $name, array( 'encoded' ) ) )
156. {
157. return true;
158. }
159. break;
160. }
161. return false;
162. }
164. /**
165. * Adds a new ezcFeedElement element with name $name to this module and
166. * returns it.
167. *
168. * @throws ezcFeedUnsupportedElementException
169. * if trying to add an element which is not supported.
170. *
171. * @param string $name The element name
172. * @return ezcFeedElement
173. */
174. public function add ( $name )
175. {
176. if ( $this-> isElementAllowed ( $name ) )
177. {
178. switch ( $name )
179. {
180. case 'encoded':
181. $node = new ezcFeedTextElement ();
182. break;
183. }
184. $this-> properties [$name] = $node;
185. return $node;
186. }
187. else
188. {
189. throw new ezcFeedUnsupportedElementException ( $name );
190. }
191. }
193. /**
194. * Adds the module elements to the $xml XML document, in the container $root.
195. *
196. * @param DOMDocument $xml The XML document in which to add the module elements
197. * @param DOMNode $root The parent node which will contain the module elements
198. */
199. public function generate ( DOMDocument $xml, DOMNode $root )
200. {
201. if ( isset( $this->encoded ) )
202. {
203. $elementTag = $xml->createElement( $this-> getNamespacePrefix () . ':' . 'encoded' );
204. $root->appendChild( $elementTag );
205. $elementTag->nodeValue = htmlspecialchars ( $this->encoded->__toString(), ENT_NOQUOTES );
206. }
207. }
209. /**
210. * Parses the XML element $node and creates a feed element in the current
211. * module with name $name.
212. *
213. * @param string $name The name of the element belonging to the module
214. * @param DOMElement $node The XML child from which to take the values for $name
215. */
216. public function parse ( $name, DOMElement $node )
217. {
218. if ( $this-> isElementAllowed ( $name ) )
219. {
220. $element = $this-> add ( $name );
221. $value = $node->textContent;
223. switch ( $name )
224. {
225. case 'encoded':
226. $element->text = htmlspecialchars_decode ( $value, ENT_NOQUOTES );
227. break;
228. }
229. }
230. }
232. /**
233. * Returns the module name ('Content').
234. *
235. * @return string
236. */
237. public static function getModuleName ()
238. {
239. return 'Content';
240. }
242. /**
243. * Returns the namespace for this module ('http://purl.org/rss/1.0/modules/content/').
244. *
245. * @return string
246. */
247. public static function getNamespace ()
248. {
249. return 'http://purl.org/rss/1.0/modules/content/';
250. }
252. /**
253. * Returns the namespace prefix for this module ('content').
254. *
255. * @return string
256. */
257. public static function getNamespacePrefix ()
258. {
259. return 'content';
260. }
261. }
262. ?>

Documentation generated by phpDocumentor 1.4.3