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

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

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 216 lines | 111 code | 11 blank | 94 comment | 10 complexity | 2f9ab216d00ae30f4b1a08806cb8c9c6 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. * @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-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_Writer_Extension_ITunes_Renderer_Entry
  32. extends Zend_Feed_Writer_Extension_RendererAbstract
  33. {
  34. /**
  35. * Set to TRUE if a rendering method actually renders something. This
  36. * is used to prevent premature appending of a XML namespace declaration
  37. * until an element which requires it is actually appended.
  38. *
  39. * @var bool
  40. */
  41. protected $_called = false;
  42. /**
  43. * Render entry
  44. *
  45. * @return void
  46. */
  47. public function render()
  48. {
  49. $this->_setAuthors($this->_dom, $this->_base);
  50. $this->_setBlock($this->_dom, $this->_base);
  51. $this->_setDuration($this->_dom, $this->_base);
  52. $this->_setExplicit($this->_dom, $this->_base);
  53. $this->_setKeywords($this->_dom, $this->_base);
  54. $this->_setSubtitle($this->_dom, $this->_base);
  55. $this->_setSummary($this->_dom, $this->_base);
  56. if ($this->_called) {
  57. $this->_appendNamespaces();
  58. }
  59. }
  60. /**
  61. * Append namespaces to entry root
  62. *
  63. * @return void
  64. */
  65. protected function _appendNamespaces()
  66. {
  67. $this->getRootElement()->setAttribute('xmlns:itunes',
  68. 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  69. }
  70. /**
  71. * Set entry authors
  72. *
  73. * @param DOMDocument $dom
  74. * @param DOMElement $root
  75. * @return void
  76. */
  77. protected function _setAuthors(DOMDocument $dom, DOMElement $root)
  78. {
  79. $authors = $this->getDataContainer()->getItunesAuthors();
  80. if (!$authors || empty($authors)) {
  81. return;
  82. }
  83. foreach ($authors as $author) {
  84. $el = $dom->createElement('itunes:author');
  85. $text = $dom->createTextNode($author);
  86. $el->appendChild($text);
  87. $root->appendChild($el);
  88. $this->_called = true;
  89. }
  90. }
  91. /**
  92. * Set itunes block
  93. *
  94. * @param DOMDocument $dom
  95. * @param DOMElement $root
  96. * @return void
  97. */
  98. protected function _setBlock(DOMDocument $dom, DOMElement $root)
  99. {
  100. $block = $this->getDataContainer()->getItunesBlock();
  101. if ($block === null) {
  102. return;
  103. }
  104. $el = $dom->createElement('itunes:block');
  105. $text = $dom->createTextNode($block);
  106. $el->appendChild($text);
  107. $root->appendChild($el);
  108. $this->_called = true;
  109. }
  110. /**
  111. * Set entry duration
  112. *
  113. * @param DOMDocument $dom
  114. * @param DOMElement $root
  115. * @return void
  116. */
  117. protected function _setDuration(DOMDocument $dom, DOMElement $root)
  118. {
  119. $duration = $this->getDataContainer()->getItunesDuration();
  120. if (!$duration) {
  121. return;
  122. }
  123. $el = $dom->createElement('itunes:duration');
  124. $text = $dom->createTextNode($duration);
  125. $el->appendChild($text);
  126. $root->appendChild($el);
  127. $this->_called = true;
  128. }
  129. /**
  130. * Set explicit flag
  131. *
  132. * @param DOMDocument $dom
  133. * @param DOMElement $root
  134. * @return void
  135. */
  136. protected function _setExplicit(DOMDocument $dom, DOMElement $root)
  137. {
  138. $explicit = $this->getDataContainer()->getItunesExplicit();
  139. if ($explicit === null) {
  140. return;
  141. }
  142. $el = $dom->createElement('itunes:explicit');
  143. $text = $dom->createTextNode($explicit);
  144. $el->appendChild($text);
  145. $root->appendChild($el);
  146. $this->_called = true;
  147. }
  148. /**
  149. * Set entry keywords
  150. *
  151. * @param DOMDocument $dom
  152. * @param DOMElement $root
  153. * @return void
  154. */
  155. protected function _setKeywords(DOMDocument $dom, DOMElement $root)
  156. {
  157. $keywords = $this->getDataContainer()->getItunesKeywords();
  158. if (!$keywords || empty($keywords)) {
  159. return;
  160. }
  161. $el = $dom->createElement('itunes:keywords');
  162. $text = $dom->createTextNode(implode(',', $keywords));
  163. $el->appendChild($text);
  164. $root->appendChild($el);
  165. $this->_called = true;
  166. }
  167. /**
  168. * Set entry subtitle
  169. *
  170. * @param DOMDocument $dom
  171. * @param DOMElement $root
  172. * @return void
  173. */
  174. protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
  175. {
  176. $subtitle = $this->getDataContainer()->getItunesSubtitle();
  177. if (!$subtitle) {
  178. return;
  179. }
  180. $el = $dom->createElement('itunes:subtitle');
  181. $text = $dom->createTextNode($subtitle);
  182. $el->appendChild($text);
  183. $root->appendChild($el);
  184. $this->_called = true;
  185. }
  186. /**
  187. * Set entry summary
  188. *
  189. * @param DOMDocument $dom
  190. * @param DOMElement $root
  191. * @return void
  192. */
  193. protected function _setSummary(DOMDocument $dom, DOMElement $root)
  194. {
  195. $summary = $this->getDataContainer()->getItunesSummary();
  196. if (!$summary) {
  197. return;
  198. }
  199. $el = $dom->createElement('itunes:summary');
  200. $text = $dom->createTextNode($summary);
  201. $el->appendChild($text);
  202. $root->appendChild($el);
  203. $this->_called = true;
  204. }
  205. }