Entry.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * @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-2008 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. public function render()
  35. {
  36. $this->_appendNamespaces();
  37. $this->_setAuthors($this->_dom, $this->_base);
  38. $this->_setBlock($this->_dom, $this->_base);
  39. $this->_setDuration($this->_dom, $this->_base);
  40. $this->_setExplicit($this->_dom, $this->_base);
  41. $this->_setKeywords($this->_dom, $this->_base);
  42. $this->_setSubtitle($this->_dom, $this->_base);
  43. $this->_setSummary($this->_dom, $this->_base);
  44. }
  45. protected function _appendNamespaces()
  46. {
  47. $this->getRootElement()->setAttribute('xmlns:itunes',
  48. 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  49. }
  50. protected function _setAuthors(DOMDocument $dom, DOMElement $root)
  51. {
  52. $authors = $this->getDataContainer()->getItunesAuthors();
  53. if (!$authors || empty($authors)) {
  54. return;
  55. }
  56. foreach ($authors as $author) {
  57. $el = $dom->createElement('itunes:author');
  58. $el->nodeValue = Zend_Feed_Writer::xmlentities(
  59. $author, $this->getEncoding()
  60. );
  61. $root->appendChild($el);
  62. }
  63. }
  64. protected function _setBlock(DOMDocument $dom, DOMElement $root)
  65. {
  66. $block = $this->getDataContainer()->getItunesBlock();
  67. if (is_null($block)) {
  68. return;
  69. }
  70. $el = $dom->createElement('itunes:block');
  71. $el->nodeValue = $block;
  72. $root->appendChild($el);
  73. }
  74. protected function _setDuration(DOMDocument $dom, DOMElement $root)
  75. {
  76. $duration = $this->getDataContainer()->getItunesDuration();
  77. if (!$duration) {
  78. return;
  79. }
  80. $el = $dom->createElement('itunes:duration');
  81. $el->nodeValue = $duration;
  82. $root->appendChild($el);
  83. }
  84. protected function _setExplicit(DOMDocument $dom, DOMElement $root)
  85. {
  86. $explicit = $this->getDataContainer()->getItunesExplicit();
  87. if (is_null($explicit)) {
  88. return;
  89. }
  90. $el = $dom->createElement('itunes:explicit');
  91. $el->nodeValue = $explicit;
  92. $root->appendChild($el);
  93. }
  94. protected function _setKeywords(DOMDocument $dom, DOMElement $root)
  95. {
  96. $keywords = $this->getDataContainer()->getItunesKeywords();
  97. if (!$keywords || empty($keywords)) {
  98. return;
  99. }
  100. $el = $dom->createElement('itunes:keywords');
  101. $el->nodeValue = Zend_Feed_Writer::xmlentities(
  102. implode(',', $keywords), $this->getEncoding()
  103. );
  104. $root->appendChild($el);
  105. }
  106. protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
  107. {
  108. $subtitle = $this->getDataContainer()->getItunesSubtitle();
  109. if (!$subtitle) {
  110. return;
  111. }
  112. $el = $dom->createElement('itunes:subtitle');
  113. $el->nodeValue = Zend_Feed_Writer::xmlentities(
  114. $subtitle, $this->getEncoding()
  115. );
  116. $root->appendChild($el);
  117. }
  118. protected function _setSummary(DOMDocument $dom, DOMElement $root)
  119. {
  120. $summary = $this->getDataContainer()->getItunesSummary();
  121. if (!$summary) {
  122. return;
  123. }
  124. $el = $dom->createElement('itunes:summary');
  125. $el->nodeValue = Zend_Feed_Writer::xmlentities(
  126. $summary, $this->getEncoding()
  127. );
  128. $root->appendChild($el);
  129. }
  130. }