Entry.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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-2010 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. * @see Zend_Feed_Writer_Extension_RendererAbstract
  23. */
  24. require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Feed_Writer
  28. * @copyright Copyright (c) 2005-2010 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_Writer_Extension_ITunes_Renderer_Entry
  32. extends Zend_Feed_Writer_Extension_RendererAbstract
  33. {
  34. /**
  35. * Render entry
  36. *
  37. * @return void
  38. */
  39. public function render()
  40. {
  41. $this->_appendNamespaces();
  42. $this->_setAuthors($this->_dom, $this->_base);
  43. $this->_setBlock($this->_dom, $this->_base);
  44. $this->_setDuration($this->_dom, $this->_base);
  45. $this->_setExplicit($this->_dom, $this->_base);
  46. $this->_setKeywords($this->_dom, $this->_base);
  47. $this->_setSubtitle($this->_dom, $this->_base);
  48. $this->_setSummary($this->_dom, $this->_base);
  49. }
  50. /**
  51. * Append namespaces to entry root
  52. *
  53. * @return void
  54. */
  55. protected function _appendNamespaces()
  56. {
  57. $this->getRootElement()->setAttribute('xmlns:itunes',
  58. 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  59. }
  60. /**
  61. * Set entry authors
  62. *
  63. * @param DOMDocument $dom
  64. * @param DOMElement $root
  65. * @return void
  66. */
  67. protected function _setAuthors(DOMDocument $dom, DOMElement $root)
  68. {
  69. $authors = $this->getDataContainer()->getItunesAuthors();
  70. if (!$authors || empty($authors)) {
  71. return;
  72. }
  73. foreach ($authors as $author) {
  74. $el = $dom->createElement('itunes:author');
  75. $text = $dom->createTextNode($author);
  76. $el->appendChild($text);
  77. $root->appendChild($el);
  78. }
  79. }
  80. /**
  81. * Set itunes block
  82. *
  83. * @param DOMDocument $dom
  84. * @param DOMElement $root
  85. * @return void
  86. */
  87. protected function _setBlock(DOMDocument $dom, DOMElement $root)
  88. {
  89. $block = $this->getDataContainer()->getItunesBlock();
  90. if (is_null($block)) {
  91. return;
  92. }
  93. $el = $dom->createElement('itunes:block');
  94. $text = $dom->createTextNode($block);
  95. $el->appendChild($text);
  96. $root->appendChild($el);
  97. }
  98. /**
  99. * Set entry duration
  100. *
  101. * @param DOMDocument $dom
  102. * @param DOMElement $root
  103. * @return void
  104. */
  105. protected function _setDuration(DOMDocument $dom, DOMElement $root)
  106. {
  107. $duration = $this->getDataContainer()->getItunesDuration();
  108. if (!$duration) {
  109. return;
  110. }
  111. $el = $dom->createElement('itunes:duration');
  112. $text = $dom->createTextNode($duration);
  113. $el->appendChild($text);
  114. $root->appendChild($el);
  115. }
  116. /**
  117. * Set explicit flag
  118. *
  119. * @param DOMDocument $dom
  120. * @param DOMElement $root
  121. * @return void
  122. */
  123. protected function _setExplicit(DOMDocument $dom, DOMElement $root)
  124. {
  125. $explicit = $this->getDataContainer()->getItunesExplicit();
  126. if (is_null($explicit)) {
  127. return;
  128. }
  129. $el = $dom->createElement('itunes:explicit');
  130. $text = $dom->createTextNode($explicit);
  131. $el->appendChild($text);
  132. $root->appendChild($el);
  133. }
  134. /**
  135. * Set entry keywords
  136. *
  137. * @param DOMDocument $dom
  138. * @param DOMElement $root
  139. * @return void
  140. */
  141. protected function _setKeywords(DOMDocument $dom, DOMElement $root)
  142. {
  143. $keywords = $this->getDataContainer()->getItunesKeywords();
  144. if (!$keywords || empty($keywords)) {
  145. return;
  146. }
  147. $el = $dom->createElement('itunes:keywords');
  148. $text = $dom->createTextNode(implode(',', $keywords));
  149. $el->appendChild($text);
  150. $root->appendChild($el);
  151. }
  152. /**
  153. * Set entry subtitle
  154. *
  155. * @param DOMDocument $dom
  156. * @param DOMElement $root
  157. * @return void
  158. */
  159. protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
  160. {
  161. $subtitle = $this->getDataContainer()->getItunesSubtitle();
  162. if (!$subtitle) {
  163. return;
  164. }
  165. $el = $dom->createElement('itunes:subtitle');
  166. $text = $dom->createTextNode($subtitle);
  167. $el->appendChild($text);
  168. $root->appendChild($el);
  169. }
  170. /**
  171. * Set entry summary
  172. *
  173. * @param DOMDocument $dom
  174. * @param DOMElement $root
  175. * @return void
  176. */
  177. protected function _setSummary(DOMDocument $dom, DOMElement $root)
  178. {
  179. $summary = $this->getDataContainer()->getItunesSummary();
  180. if (!$summary) {
  181. return;
  182. }
  183. $el = $dom->createElement('itunes:summary');
  184. $text = $dom->createTextNode($summary);
  185. $el->appendChild($text);
  186. $root->appendChild($el);
  187. }
  188. }