Entry.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Feed_Writer
  24. * @copyright Copyright (c) 2005-2008 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. public function setEncoding($enc)
  42. {
  43. $this->_encoding = $enc;
  44. }
  45. public function getEncoding()
  46. {
  47. return $this->_encoding;
  48. }
  49. /**
  50. * Set a block value of "yes" or "no". You may also set an empty string.
  51. *
  52. * @param string
  53. */
  54. public function setItunesBlock($value)
  55. {
  56. if (!ctype_alpha($value) && strlen($value) > 0) {
  57. require_once 'Zend/Feed/Exception.php';
  58. throw new Zend_Feed_Exception('invalid parameter: "block" may only'
  59. . ' contain alphabetic characters');
  60. }
  61. if (iconv_strlen($value, $this->getEncoding()) > 255) {
  62. require_once 'Zend/Feed/Exception.php';
  63. throw new Zend_Feed_Exception('invalid parameter: "block" may only'
  64. . ' contain a maximum of 255 characters');
  65. }
  66. $this->_data['block'] = $value;
  67. }
  68. public function addItunesAuthors(array $values)
  69. {
  70. foreach ($values as $value) {
  71. $this->addItunesAuthor($value);
  72. }
  73. }
  74. public function addItunesAuthor($value)
  75. {
  76. if (iconv_strlen($value, $this->getEncoding()) > 255) {
  77. require_once 'Zend/Feed/Exception.php';
  78. throw new Zend_Feed_Exception('invalid parameter: any "author" may only'
  79. . ' contain a maximum of 255 characters each');
  80. }
  81. if (!isset($this->_data['authors'])) {
  82. $this->_data['authors'] = array();
  83. }
  84. $this->_data['authors'][] = $value;
  85. }
  86. public function setItunesDuration($value)
  87. {
  88. $value = (string) $value;
  89. if (!ctype_digit($value)
  90. && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value)
  91. && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value)) {
  92. require_once 'Zend/Feed/Exception.php';
  93. throw new Zend_Feed_Exception('invalid parameter: "duration" may only'
  94. . ' be of a specified [[HH:]MM:]SS format');
  95. }
  96. $this->_data['duration'] = $value;
  97. }
  98. public function setItunesExplicit($value)
  99. {
  100. if (!in_array($value, array('yes','no','clean'))) {
  101. require_once 'Zend/Feed/Exception.php';
  102. throw new Zend_Feed_Exception('invalid parameter: "explicit" may only'
  103. . ' be one of "yes", "no" or "clean"');
  104. }
  105. $this->_data['explicit'] = $value;
  106. }
  107. public function setItunesKeywords(array $value)
  108. {
  109. if (count($value) > 12) {
  110. require_once 'Zend/Feed/Exception.php';
  111. throw new Zend_Feed_Exception('invalid parameter: "keywords" may only'
  112. . ' contain a maximum of 12 terms');
  113. }
  114. $concat = implode(',', $value);
  115. if (iconv_strlen($concat, $this->getEncoding()) > 255) {
  116. require_once 'Zend/Feed/Exception.php';
  117. throw new Zend_Feed_Exception('invalid parameter: "keywords" may only'
  118. . ' have a concatenated length of 255 chars where terms are delimited'
  119. . ' by a comma');
  120. }
  121. $this->_data['keywords'] = $value;
  122. }
  123. public function setItunesSubtitle($value)
  124. {
  125. if (iconv_strlen($value, $this->getEncoding()) > 255) {
  126. require_once 'Zend/Feed/Exception.php';
  127. throw new Zend_Feed_Exception('invalid parameter: "subtitle" may only'
  128. . ' contain a maximum of 255 characters');
  129. }
  130. $this->_data['subtitle'] = $value;
  131. }
  132. public function setItunesSummary($value)
  133. {
  134. if (iconv_strlen($value, $this->getEncoding()) > 4000) {
  135. require_once 'Zend/Feed/Exception.php';
  136. throw new Zend_Feed_Exception('invalid parameter: "summary" may only'
  137. . ' contain a maximum of 4000 characters');
  138. }
  139. $this->_data['summary'] = $value;
  140. }
  141. public function __call($method, array $params)
  142. {
  143. $point = lcfirst(substr($method, 9));
  144. if (!method_exists($this, 'setItunes' . ucfirst($point))
  145. && !method_exists($this, 'addItunes' . ucfirst($point))) {
  146. require_once 'Zend/Feed/Writer/Exception/InvalidMethodException.php';
  147. throw new Zend_Feed_Writer_Exception_InvalidMethodException(
  148. 'invalid method: ' . $method
  149. );
  150. }
  151. if (!array_key_exists($point, $this->_data) || empty($this->_data[$point])) {
  152. return null;
  153. }
  154. return $this->_data[$point];
  155. }
  156. }