PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/src/application/libraries/Zend/Feed/Builder/Entry.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 297 lines | 116 code | 20 blank | 161 comment | 9 complexity | a562fefd4f481178071b40713a33f921 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Feed
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Entry.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * An entry of a custom build feed
  23. *
  24. * Classes implementing the Zend_Feed_Builder_Interface interface
  25. * uses this class to describe an entry of a feed
  26. *
  27. * @category Zend
  28. * @package Zend_Feed
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Feed_Builder_Entry extends ArrayObject
  33. {
  34. /**
  35. * Create a new builder entry
  36. *
  37. * @param string $title
  38. * @param string $link
  39. * @param string $description short version of the entry, no html
  40. * @return void
  41. */
  42. public function __construct($title, $link, $description)
  43. {
  44. $this->offsetSet('title', $title);
  45. $this->offsetSet('link', $link);
  46. $this->offsetSet('description', $description);
  47. $this->setLastUpdate(time());
  48. }
  49. /**
  50. * Read only properties accessor
  51. *
  52. * @param string $name property to read
  53. * @return mixed
  54. */
  55. public function __get($name)
  56. {
  57. if (!$this->offsetExists($name)) {
  58. return NULL;
  59. }
  60. return $this->offsetGet($name);
  61. }
  62. /**
  63. * Write properties accessor
  64. *
  65. * @param string $name name of the property to set
  66. * @param mixed $value value to set
  67. * @return void
  68. */
  69. public function __set($name, $value)
  70. {
  71. $this->offsetSet($name, $value);
  72. }
  73. /**
  74. * Isset accessor
  75. *
  76. * @param string $key
  77. * @return boolean
  78. */
  79. public function __isset($key)
  80. {
  81. return $this->offsetExists($key);
  82. }
  83. /**
  84. * Unset accessor
  85. *
  86. * @param string $key
  87. * @return void
  88. */
  89. public function __unset($key)
  90. {
  91. if ($this->offsetExists($key)) {
  92. $this->offsetUnset($key);
  93. }
  94. }
  95. /**
  96. * Sets the author of the entry
  97. *
  98. * @param string $author
  99. * @return Zend_Feed_Builder_Entry
  100. */
  101. public function setAuthor($author)
  102. {
  103. $this->offsetSet('author', $author);
  104. return $this;
  105. }
  106. /**
  107. * Sets the id/guid of the entry
  108. *
  109. * @param string $id
  110. * @return Zend_Feed_Builder_Entry
  111. */
  112. public function setId($id)
  113. {
  114. $this->offsetSet('guid', $id);
  115. return $this;
  116. }
  117. /**
  118. * Sets the full html content of the entry
  119. *
  120. * @param string $content
  121. * @return Zend_Feed_Builder_Entry
  122. */
  123. public function setContent($content)
  124. {
  125. $this->offsetSet('content', $content);
  126. return $this;
  127. }
  128. /**
  129. * Timestamp of the update date
  130. *
  131. * @param int $lastUpdate
  132. * @return Zend_Feed_Builder_Entry
  133. */
  134. public function setLastUpdate($lastUpdate)
  135. {
  136. $this->offsetSet('lastUpdate', $lastUpdate);
  137. return $this;
  138. }
  139. /**
  140. * Sets the url of the commented page associated to the entry
  141. *
  142. * @param string $comments
  143. * @return Zend_Feed_Builder_Entry
  144. */
  145. public function setCommentsUrl($comments)
  146. {
  147. $this->offsetSet('comments', $comments);
  148. return $this;
  149. }
  150. /**
  151. * Sets the url of the comments feed link
  152. *
  153. * @param string $commentRss
  154. * @return Zend_Feed_Builder_Entry
  155. */
  156. public function setCommentsRssUrl($commentRss)
  157. {
  158. $this->offsetSet('commentRss', $commentRss);
  159. return $this;
  160. }
  161. /**
  162. * Defines a reference to the original source
  163. *
  164. * @param string $title
  165. * @param string $url
  166. * @return Zend_Feed_Builder_Entry
  167. */
  168. public function setSource($title, $url)
  169. {
  170. $this->offsetSet('source', array('title' => $title,
  171. 'url' => $url));
  172. return $this;
  173. }
  174. /**
  175. * Sets the categories of the entry
  176. * Format of the array:
  177. * <code>
  178. * array(
  179. * array(
  180. * 'term' => 'first category label',
  181. * 'scheme' => 'url that identifies a categorization scheme' // optional
  182. * ),
  183. * // second category and so one
  184. * )
  185. * </code>
  186. *
  187. * @param array $categories
  188. * @return Zend_Feed_Builder_Entry
  189. */
  190. public function setCategories(array $categories)
  191. {
  192. foreach ($categories as $category) {
  193. $this->addCategory($category);
  194. }
  195. return $this;
  196. }
  197. /**
  198. * Add a category to the entry
  199. *
  200. * @param array $category see Zend_Feed_Builder_Entry::setCategories() for format
  201. * @return Zend_Feed_Builder_Entry
  202. * @throws Zend_Feed_Builder_Exception
  203. */
  204. public function addCategory(array $category)
  205. {
  206. if (empty($category['term'])) {
  207. /**
  208. * @see Zend_Feed_Builder_Exception
  209. */
  210. require_once 'Zend/Feed/Builder/Exception.php';
  211. throw new Zend_Feed_Builder_Exception("you have to define the name of the category");
  212. }
  213. if (!$this->offsetExists('category')) {
  214. $categories = array($category);
  215. } else {
  216. $categories = $this->offsetGet('category');
  217. $categories[] = $category;
  218. }
  219. $this->offsetSet('category', $categories);
  220. return $this;
  221. }
  222. /**
  223. * Sets the enclosures of the entry
  224. * Format of the array:
  225. * <code>
  226. * array(
  227. * array(
  228. * 'url' => 'url of the linked enclosure',
  229. * 'type' => 'mime type of the enclosure' // optional
  230. * 'length' => 'length of the linked content in octets' // optional
  231. * ),
  232. * // second enclosure and so one
  233. * )
  234. * </code>
  235. *
  236. * @param array $enclosures
  237. * @return Zend_Feed_Builder_Entry
  238. * @throws Zend_Feed_Builder_Exception
  239. */
  240. public function setEnclosures(array $enclosures)
  241. {
  242. foreach ($enclosures as $enclosure) {
  243. if (empty($enclosure['url'])) {
  244. /**
  245. * @see Zend_Feed_Builder_Exception
  246. */
  247. require_once 'Zend/Feed/Builder/Exception.php';
  248. throw new Zend_Feed_Builder_Exception("you have to supply an url for your enclosure");
  249. }
  250. $type = isset($enclosure['type']) ? $enclosure['type'] : '';
  251. $length = isset($enclosure['length']) ? $enclosure['length'] : '';
  252. $this->addEnclosure($enclosure['url'], $type, $length);
  253. }
  254. return $this;
  255. }
  256. /**
  257. * Add an enclosure to the entry
  258. *
  259. * @param string $url
  260. * @param string $type
  261. * @param string $length
  262. * @return Zend_Feed_Builder_Entry
  263. */
  264. public function addEnclosure($url, $type = '', $length = '')
  265. {
  266. if (!$this->offsetExists('enclosure')) {
  267. $enclosure = array();
  268. } else {
  269. $enclosure = $this->offsetGet('enclosure');
  270. }
  271. $enclosure[] = array('url' => $url,
  272. 'type' => $type,
  273. 'length' => $length);
  274. $this->offsetSet('enclosure', $enclosure);
  275. return $this;
  276. }
  277. }