PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/Feed/Writer/Extension/ITunes/Entry.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 242 lines | 128 code | 13 blank | 101 comment | 17 complexity | 55d8a93f767bb75ffa32d486b6af75f6 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_Writer
  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. * @category Zend
  23. * @package Zend_Feed_Writer
  24. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Feed_Writer_Extension_ITunes_Entry
  28. {
  29. /**
  30. * Array of Feed data for rendering by Extension's renderers
  31. *
  32. * @var array
  33. */
  34. protected $_data = array();
  35. /**
  36. * Encoding of all text values
  37. *
  38. * @var string
  39. */
  40. protected $_encoding = 'UTF-8';
  41. /**
  42. * Set feed encoding
  43. *
  44. * @param string $enc
  45. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  46. */
  47. public function setEncoding($enc)
  48. {
  49. $this->_encoding = $enc;
  50. return $this;
  51. }
  52. /**
  53. * Get feed encoding
  54. *
  55. * @return string
  56. */
  57. public function getEncoding()
  58. {
  59. return $this->_encoding;
  60. }
  61. /**
  62. * Set a block value of "yes" or "no". You may also set an empty string.
  63. *
  64. * @param string
  65. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  66. */
  67. public function setItunesBlock($value)
  68. {
  69. if (!ctype_alpha($value) && strlen($value) > 0) {
  70. require_once 'Zend/Feed/Exception.php';
  71. throw new Zend_Feed_Exception('invalid parameter: "block" may only'
  72. . ' contain alphabetic characters');
  73. }
  74. if (iconv_strlen($value, $this->getEncoding()) > 255) {
  75. require_once 'Zend/Feed/Exception.php';
  76. throw new Zend_Feed_Exception('invalid parameter: "block" may only'
  77. . ' contain a maximum of 255 characters');
  78. }
  79. $this->_data['block'] = $value;
  80. }
  81. /**
  82. * Add authors to itunes entry
  83. *
  84. * @param array $values
  85. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  86. */
  87. public function addItunesAuthors(array $values)
  88. {
  89. foreach ($values as $value) {
  90. $this->addItunesAuthor($value);
  91. }
  92. return $this;
  93. }
  94. /**
  95. * Add author to itunes entry
  96. *
  97. * @param string $value
  98. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  99. */
  100. public function addItunesAuthor($value)
  101. {
  102. if (iconv_strlen($value, $this->getEncoding()) > 255) {
  103. require_once 'Zend/Feed/Exception.php';
  104. throw new Zend_Feed_Exception('invalid parameter: any "author" may only'
  105. . ' contain a maximum of 255 characters each');
  106. }
  107. if (!isset($this->_data['authors'])) {
  108. $this->_data['authors'] = array();
  109. }
  110. $this->_data['authors'][] = $value;
  111. return $this;
  112. }
  113. /**
  114. * Set duration
  115. *
  116. * @param int $value
  117. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  118. */
  119. public function setItunesDuration($value)
  120. {
  121. $value = (string) $value;
  122. if (!ctype_digit($value)
  123. && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value)
  124. && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value)
  125. ) {
  126. require_once 'Zend/Feed/Exception.php';
  127. throw new Zend_Feed_Exception('invalid parameter: "duration" may only'
  128. . ' be of a specified [[HH:]MM:]SS format');
  129. }
  130. $this->_data['duration'] = $value;
  131. return $this;
  132. }
  133. /**
  134. * Set "explicit" flag
  135. *
  136. * @param bool $value
  137. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  138. */
  139. public function setItunesExplicit($value)
  140. {
  141. if (!in_array($value, array('yes','no','clean'))) {
  142. require_once 'Zend/Feed/Exception.php';
  143. throw new Zend_Feed_Exception('invalid parameter: "explicit" may only'
  144. . ' be one of "yes", "no" or "clean"');
  145. }
  146. $this->_data['explicit'] = $value;
  147. return $this;
  148. }
  149. /**
  150. * Set keywords
  151. *
  152. * @param array $value
  153. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  154. */
  155. public function setItunesKeywords(array $value)
  156. {
  157. if (count($value) > 12) {
  158. require_once 'Zend/Feed/Exception.php';
  159. throw new Zend_Feed_Exception('invalid parameter: "keywords" may only'
  160. . ' contain a maximum of 12 terms');
  161. }
  162. $concat = implode(',', $value);
  163. if (iconv_strlen($concat, $this->getEncoding()) > 255) {
  164. require_once 'Zend/Feed/Exception.php';
  165. throw new Zend_Feed_Exception('invalid parameter: "keywords" may only'
  166. . ' have a concatenated length of 255 chars where terms are delimited'
  167. . ' by a comma');
  168. }
  169. $this->_data['keywords'] = $value;
  170. return $this;
  171. }
  172. /**
  173. * Set subtitle
  174. *
  175. * @param string $value
  176. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  177. */
  178. public function setItunesSubtitle($value)
  179. {
  180. if (iconv_strlen($value, $this->getEncoding()) > 255) {
  181. require_once 'Zend/Feed/Exception.php';
  182. throw new Zend_Feed_Exception('invalid parameter: "subtitle" may only'
  183. . ' contain a maximum of 255 characters');
  184. }
  185. $this->_data['subtitle'] = $value;
  186. return $this;
  187. }
  188. /**
  189. * Set summary
  190. *
  191. * @param string $value
  192. * @return Zend_Feed_Writer_Extension_ITunes_Entry
  193. */
  194. public function setItunesSummary($value)
  195. {
  196. if (iconv_strlen($value, $this->getEncoding()) > 4000) {
  197. require_once 'Zend/Feed/Exception.php';
  198. throw new Zend_Feed_Exception('invalid parameter: "summary" may only'
  199. . ' contain a maximum of 4000 characters');
  200. }
  201. $this->_data['summary'] = $value;
  202. return $this;
  203. }
  204. /**
  205. * Overloading to itunes specific setters
  206. *
  207. * @param string $method
  208. * @param array $params
  209. * @return mixed
  210. */
  211. public function __call($method, array $params)
  212. {
  213. $point = Zend_Feed_Writer::lcfirst(substr($method, 9));
  214. if (!method_exists($this, 'setItunes' . ucfirst($point))
  215. && !method_exists($this, 'addItunes' . ucfirst($point))
  216. ) {
  217. require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php';
  218. throw new Zend_Feed_Writer_Exception_InvalidMethodException(
  219. 'invalid method: ' . $method
  220. );
  221. }
  222. if (!array_key_exists($point, $this->_data)
  223. || empty($this->_data[$point])
  224. ) {
  225. return null;
  226. }
  227. return $this->_data[$point];
  228. }
  229. }