PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ezc/Feed/src/structs/entry.php

https://bitbucket.org/crevillo/enetcall
PHP | 375 lines | 189 code | 28 blank | 158 comment | 9 complexity | c5f9f50f24183fd6ecb56c097d363fbf MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * File containing the ezcFeedEntryElement class.
  4. *
  5. * @package Feed
  6. * @version //autogentag//
  7. * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
  8. * @license http://ez.no/licenses/new_bsd New BSD License
  9. * @filesource
  10. */
  11. /**
  12. * Class defining a feed entry.
  13. *
  14. * @property array(ezcFeedPersonElement) $author
  15. * The authors of the entry. Equivalents:
  16. * ATOM-author (required, multiple),
  17. * RSS1-none,
  18. * RSS2-author (optional, recommended, single).
  19. * @property array(ezcFeedCategoryElement) $category
  20. * The categories of the entry. Equivalents:
  21. * ATOM-author (optional, multiple),
  22. * RSS1-none,
  23. * RSS2-category (optional, multiple).
  24. * @property ezcFeedTextElement $comments
  25. * The comments of the entry. Equivalents:
  26. * ATOM-none,
  27. * RSS1-none,
  28. * RSS2-author (optional, single).
  29. * @property ezcFeedContentElement $content
  30. * The complex text content of the entry. Equivalents:
  31. * ATOM-content (optional, single),
  32. * RSS1-none,
  33. * RSS2-none.
  34. * @property array(ezcFeedPersonElement) $contributor
  35. * The contributors of the entry. Equivalents:
  36. * ATOM-contributor (optional, not recommended, multiple),
  37. * RSS1-none,
  38. * RSS2-none.
  39. * @property ezcFeedTextElement $copyright
  40. * The copyright of the entry. Equivalents:
  41. * ATOM-rights (optional, single),
  42. * RSS1-none,
  43. * RSS2-none.
  44. * @property ezcFeedTextElement $description
  45. * The description of the entry. Equivalents:
  46. * ATOM-summary (required, single),
  47. * RSS1-description (required, single),
  48. * RSS2-description (required, single).
  49. * @property array(ezcFeedEnclosureElement) $enclosure
  50. * The enclosures of the entry. Equivalents:
  51. * ATOM-link@rel="enclosure" (optional, multiple),
  52. * RSS1-none,
  53. * RSS2-enclosure (optional, single).
  54. * @property ezcFeedTextElement $id
  55. * The id of the entry. Equivalents:
  56. * ATOM-id (required, single),
  57. * RSS1-about (required, single),
  58. * RSS2-guid (optional, single).
  59. * @property array(ezcFeedLinkElement) $link
  60. * The links of the entry. Equivalents:
  61. * ATOM-link (required, multiple),
  62. * RSS1-link (required, single),
  63. * RSS2-link (required, single).
  64. * @property ezcFeedDateElement $published
  65. * The published date of the entry. Equivalents:
  66. * ATOM-published (optional, single),
  67. * RSS1-none,
  68. * RSS2-pubDate (optional, single).
  69. * @property ezcFeedTextElement $title
  70. * The title of the entry. Equivalents:
  71. * ATOM-title (required, single),
  72. * RSS1-title (required, single),
  73. * RSS2-title (required, single).
  74. * @property ezcFeedDateElement $updated
  75. * The updated date of the entry. Equivalents:
  76. * ATOM-updated (required, single),
  77. * RSS1-none,
  78. * RSS2-none.
  79. * @property ezcFeedSourceElement $source
  80. * The source of the entry. Equivalents:
  81. * ATOM-source (optional, not recommended, single),
  82. * RSS1-none,
  83. * RSS2-source (optional, not recommended, single).
  84. * @property ezcFeedTextElement $language
  85. * The language of the entry. Equivalents:
  86. * ATOM-source (optional, not recommended, single ),
  87. * RSS1-none,
  88. * RSS2-none.
  89. *
  90. * @package Feed
  91. * @version //autogentag//
  92. * @mainclass
  93. */
  94. class ezcFeedEntryElement extends ezcFeedElement
  95. {
  96. /**
  97. * Holds the modules used by this feed item.
  98. *
  99. * @var array(string=>ezcFeedModule)
  100. */
  101. private $modules = array();
  102. /**
  103. * Sets the property $name to $value.
  104. *
  105. * @param string $name The property name
  106. * @param mixed $value The property value
  107. * @ignore
  108. */
  109. public function __set( $name, $value )
  110. {
  111. switch ( $name )
  112. {
  113. case 'title':
  114. case 'description':
  115. case 'comments':
  116. case 'copyright':
  117. case 'language':
  118. $element = $this->add( $name );
  119. $element->text = $value;
  120. break;
  121. case 'content':
  122. $element = $this->add( $name );
  123. $element->text = $value;
  124. break;
  125. case 'author':
  126. case 'contributor':
  127. $element = $this->add( $name );
  128. $element->name = $value;
  129. break;
  130. case 'updated':
  131. case 'published':
  132. $element = $this->add( $name );
  133. $element->date = $value;
  134. break;
  135. case 'id':
  136. $element = $this->add( $name );
  137. $element->id = $value;
  138. break;
  139. case 'link':
  140. $element = $this->add( $name );
  141. $element->href = $value;
  142. break;
  143. case 'enclosure':
  144. $element = $this->add( $name );
  145. $element->url = $value;
  146. break;
  147. case 'source':
  148. $element = $this->add( $name );
  149. $element->source = $value;
  150. break;
  151. default:
  152. $supportedModules = ezcFeed::getSupportedModules();
  153. if ( isset( $supportedModules[$name] ) )
  154. {
  155. $this->modules[$name] = $value;
  156. }
  157. break;
  158. }
  159. }
  160. /**
  161. * Returns the value of property $name.
  162. *
  163. * @throws ezcFeedUndefinedModuleException
  164. * if trying to fetch a module not defined yet
  165. *
  166. * @param string $name The property name
  167. * @return mixed
  168. * @ignore
  169. */
  170. public function __get( $name )
  171. {
  172. switch ( $name )
  173. {
  174. case 'author':
  175. case 'category':
  176. case 'comments':
  177. case 'content':
  178. case 'contributor':
  179. case 'copyright':
  180. case 'description':
  181. case 'enclosure':
  182. case 'id':
  183. case 'link':
  184. case 'published':
  185. case 'title':
  186. case 'updated':
  187. case 'source':
  188. case 'language':
  189. if ( isset( $this->properties[$name] ) )
  190. {
  191. return $this->properties[$name];
  192. }
  193. break;
  194. default:
  195. $supportedModules = ezcFeed::getSupportedModules();
  196. if ( isset( $supportedModules[$name] ) )
  197. {
  198. if ( isset( $this->$name ) )
  199. {
  200. return $this->modules[$name];
  201. }
  202. else
  203. {
  204. throw new ezcFeedUndefinedModuleException( $name );
  205. }
  206. }
  207. break;
  208. }
  209. }
  210. /**
  211. * Returns if the property $name is set.
  212. *
  213. * @param string $name The property name
  214. * @return bool
  215. * @ignore
  216. */
  217. public function __isset( $name )
  218. {
  219. switch ( $name )
  220. {
  221. case 'author':
  222. case 'category':
  223. case 'comments':
  224. case 'content':
  225. case 'contributor':
  226. case 'copyright':
  227. case 'description':
  228. case 'enclosure':
  229. case 'id':
  230. case 'link':
  231. case 'published':
  232. case 'title':
  233. case 'updated':
  234. case 'source':
  235. case 'language':
  236. return isset( $this->properties[$name] );
  237. default:
  238. $supportedModules = ezcFeed::getSupportedModules();
  239. if ( isset( $supportedModules[$name] ) )
  240. {
  241. return isset( $this->modules[$name] );
  242. }
  243. }
  244. }
  245. /**
  246. * Adds a new element with name $name to the feed item and returns it.
  247. *
  248. * Example:
  249. * <code>
  250. * // $item is an ezcFeedEntryElement object
  251. * $link = $item->add( 'link' );
  252. * $link->href = 'http://ez.no/';
  253. * </code>
  254. *
  255. * @throws ezcFeedUnsupportedElementException
  256. * if the element $name is not supported
  257. *
  258. * @apichange All items are not encoded at all, in future versions this
  259. * should be done in one of the ways as described in
  260. * http://issues.ez.no/14093
  261. *
  262. * @param string $name The name of the element to add
  263. * @return ezcFeedElement
  264. */
  265. public function add( $name )
  266. {
  267. switch ( $name )
  268. {
  269. case 'author':
  270. case 'contributor':
  271. $element = new ezcFeedPersonElement();
  272. $this->properties[$name][] = $element;
  273. break;
  274. case 'id':
  275. $element = new ezcFeedIdElement();
  276. $this->properties[$name] = $element;
  277. break;
  278. case 'category':
  279. $element = new ezcFeedCategoryElement();
  280. $this->properties[$name][] = $element;
  281. break;
  282. case 'title':
  283. case 'description':
  284. case 'comments':
  285. case 'copyright':
  286. case 'language':
  287. $element = new ezcFeedTextElement();
  288. $this->properties[$name] = $element;
  289. break;
  290. case 'content':
  291. $element = new ezcFeedContentElement();
  292. $this->properties[$name] = $element;
  293. break;
  294. case 'updated':
  295. case 'published':
  296. $element = new ezcFeedDateElement();
  297. $this->properties[$name] = $element;
  298. break;
  299. case 'link':
  300. $element = new ezcFeedLinkElement();
  301. $this->properties[$name][] = $element;
  302. break;
  303. case 'enclosure':
  304. $element = new ezcFeedEnclosureElement();
  305. $this->properties[$name][] = $element;
  306. break;
  307. case 'source':
  308. $element = new ezcFeedSourceElement();
  309. $this->properties[$name] = $element;
  310. break;
  311. default:
  312. throw new ezcFeedUnsupportedElementException( $name );
  313. }
  314. return $element;
  315. }
  316. /**
  317. * Adds a new module to this item and returns it.
  318. *
  319. * @param string $name The name of the module to add
  320. * @return ezcFeedModule
  321. */
  322. public function addModule( $name )
  323. {
  324. $this->$name = ezcFeedModule::create( $name, 'item' );
  325. return $this->$name;
  326. }
  327. /**
  328. * Returns true if the module $name is loaded, false otherwise.
  329. *
  330. * @param string $name The name of the module to check if loaded for this item
  331. * @return bool
  332. */
  333. public function hasModule( $name )
  334. {
  335. return isset( $this->modules[$name] );
  336. }
  337. /**
  338. * Returns an array with all the modules defined for this feed item.
  339. *
  340. * @return array(ezcFeedModule)
  341. */
  342. public function getModules()
  343. {
  344. return $this->modules;
  345. }
  346. }
  347. ?>