PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/Feed/Builder/Header/Itunes.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 288 lines | 120 code | 18 blank | 150 comment | 9 complexity | e71704a8a493c56a1aa25ff37049012d 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: Itunes.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * ITunes rss extension
  23. *
  24. * Classes used to describe the itunes channel extension
  25. *
  26. * @category Zend
  27. * @package Zend_Feed
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Feed_Builder_Header_Itunes extends ArrayObject
  32. {
  33. /**
  34. * Constructor
  35. *
  36. * @param array $categories Categories columns and in iTunes Music Store Browse
  37. * @return void
  38. */
  39. public function __construct(array $categories)
  40. {
  41. $this->setCategories($categories);
  42. }
  43. /**
  44. * Sets the categories column and in iTunes Music Store Browse
  45. * $categories must conform to the following format:
  46. * <code>
  47. * array(array('main' => 'main category',
  48. * 'sub' => 'sub category' // optionnal
  49. * ),
  50. * // up to 3 rows
  51. * )
  52. * </code>
  53. *
  54. * @param array $categories
  55. * @return Zend_Feed_Builder_Header_Itunes
  56. * @throws Zend_Feed_Builder_Exception
  57. */
  58. public function setCategories(array $categories)
  59. {
  60. $nb = count($categories);
  61. if (0 === $nb) {
  62. /**
  63. * @see Zend_Feed_Builder_Exception
  64. */
  65. require_once 'Zend/Feed/Builder/Exception.php';
  66. throw new Zend_Feed_Builder_Exception("you have to set at least one itunes category");
  67. }
  68. if ($nb > 3) {
  69. /**
  70. * @see Zend_Feed_Builder_Exception
  71. */
  72. require_once 'Zend/Feed/Builder/Exception.php';
  73. throw new Zend_Feed_Builder_Exception("you have to set at most three itunes categories");
  74. }
  75. foreach ($categories as $i => $category) {
  76. if (empty($category['main'])) {
  77. /**
  78. * @see Zend_Feed_Builder_Exception
  79. */
  80. require_once 'Zend/Feed/Builder/Exception.php';
  81. throw new Zend_Feed_Builder_Exception("you have to set the main category (category #$i)");
  82. }
  83. }
  84. $this->offsetSet('category', $categories);
  85. return $this;
  86. }
  87. /**
  88. * Sets the artist value, default to the feed's author value
  89. *
  90. * @param string $author
  91. * @return Zend_Feed_Builder_Header_Itunes
  92. */
  93. public function setAuthor($author)
  94. {
  95. $this->offsetSet('author', $author);
  96. return $this;
  97. }
  98. /**
  99. * Sets the owner of the postcast
  100. *
  101. * @param string $name default to the feed's author value
  102. * @param string $email default to the feed's email value
  103. * @return Zend_Feed_Builder_Header_Itunes
  104. * @throws Zend_Feed_Builder_Exception
  105. */
  106. public function setOwner($name = '', $email = '')
  107. {
  108. if (!empty($email)) {
  109. /**
  110. * @see Zend_Validate_EmailAddress
  111. */
  112. require_once 'Zend/Validate/EmailAddress.php';
  113. $validate = new Zend_Validate_EmailAddress();
  114. if (!$validate->isValid($email)) {
  115. /**
  116. * @see Zend_Feed_Builder_Exception
  117. */
  118. require_once 'Zend/Feed/Builder/Exception.php';
  119. throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the itunes owner's email property");
  120. }
  121. }
  122. $this->offsetSet('owner', array('name' => $name, 'email' => $email));
  123. return $this;
  124. }
  125. /**
  126. * Sets the album/podcast art picture
  127. * Default to the feed's image value
  128. *
  129. * @param string $image
  130. * @return Zend_Feed_Builder_Header_Itunes
  131. */
  132. public function setImage($image)
  133. {
  134. $this->offsetSet('image', $image);
  135. return $this;
  136. }
  137. /**
  138. * Sets the short description of the podcast
  139. * Default to the feed's description
  140. *
  141. * @param string $subtitle
  142. * @return Zend_Feed_Builder_Header_Itunes
  143. */
  144. public function setSubtitle($subtitle)
  145. {
  146. $this->offsetSet('subtitle', $subtitle);
  147. return $this;
  148. }
  149. /**
  150. * Sets the longer description of the podcast
  151. * Default to the feed's description
  152. *
  153. * @param string $summary
  154. * @return Zend_Feed_Builder_Header_Itunes
  155. */
  156. public function setSummary($summary)
  157. {
  158. $this->offsetSet('summary', $summary);
  159. return $this;
  160. }
  161. /**
  162. * Prevent a feed from appearing
  163. *
  164. * @param string $block can be 'yes' or 'no'
  165. * @return Zend_Feed_Builder_Header_Itunes
  166. * @throws Zend_Feed_Builder_Exception
  167. */
  168. public function setBlock($block)
  169. {
  170. $block = strtolower($block);
  171. if (!in_array($block, array('yes', 'no'))) {
  172. /**
  173. * @see Zend_Feed_Builder_Exception
  174. */
  175. require_once 'Zend/Feed/Builder/Exception.php';
  176. throw new Zend_Feed_Builder_Exception("you have to set yes or no to the itunes block property");
  177. }
  178. $this->offsetSet('block', $block);
  179. return $this;
  180. }
  181. /**
  182. * Configuration of the parental advisory graphic
  183. *
  184. * @param string $explicit can be 'yes', 'no' or 'clean'
  185. * @return Zend_Feed_Builder_Header_Itunes
  186. * @throws Zend_Feed_Builder_Exception
  187. */
  188. public function setExplicit($explicit)
  189. {
  190. $explicit = strtolower($explicit);
  191. if (!in_array($explicit, array('yes', 'no', 'clean'))) {
  192. /**
  193. * @see Zend_Feed_Builder_Exception
  194. */
  195. require_once 'Zend/Feed/Builder/Exception.php';
  196. throw new Zend_Feed_Builder_Exception("you have to set yes, no or clean to the itunes explicit property");
  197. }
  198. $this->offsetSet('explicit', $explicit);
  199. return $this;
  200. }
  201. /**
  202. * Sets a comma separated list of 12 keywords maximum
  203. *
  204. * @param string $keywords
  205. * @return Zend_Feed_Builder_Header_Itunes
  206. */
  207. public function setKeywords($keywords)
  208. {
  209. $this->offsetSet('keywords', $keywords);
  210. return $this;
  211. }
  212. /**
  213. * Sets the new feed URL location
  214. *
  215. * @param string $url
  216. * @return Zend_Feed_Builder_Header_Itunes
  217. */
  218. public function setNewFeedUrl($url)
  219. {
  220. $this->offsetSet('new_feed_url', $url);
  221. return $this;
  222. }
  223. /**
  224. * Read only properties accessor
  225. *
  226. * @param string $name property to read
  227. * @return mixed
  228. */
  229. public function __get($name)
  230. {
  231. if (!$this->offsetExists($name)) {
  232. return NULL;
  233. }
  234. return $this->offsetGet($name);
  235. }
  236. /**
  237. * Write properties accessor
  238. *
  239. * @param string $name name of the property to set
  240. * @param mixed $value value to set
  241. * @return void
  242. */
  243. public function __set($name, $value)
  244. {
  245. $this->offsetSet($name, $value);
  246. }
  247. /**
  248. * Isset accessor
  249. *
  250. * @param string $key
  251. * @return boolean
  252. */
  253. public function __isset($key)
  254. {
  255. return $this->offsetExists($key);
  256. }
  257. /**
  258. * Unset accessor
  259. *
  260. * @param string $key
  261. * @return void
  262. */
  263. public function __unset($key)
  264. {
  265. if ($this->offsetExists($key)) {
  266. $this->offsetUnset($key);
  267. }
  268. }
  269. }