PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 320 lines | 182 code | 16 blank | 122 comment | 18 complexity | bf65e454f45a5f45c65ac65c6cfbe109 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: Feed.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_Feed
  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 feed
  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->_setCategories($this->_dom, $this->_base);
  52. $this->_setImage($this->_dom, $this->_base);
  53. $this->_setDuration($this->_dom, $this->_base);
  54. $this->_setExplicit($this->_dom, $this->_base);
  55. $this->_setKeywords($this->_dom, $this->_base);
  56. $this->_setNewFeedUrl($this->_dom, $this->_base);
  57. $this->_setOwners($this->_dom, $this->_base);
  58. $this->_setSubtitle($this->_dom, $this->_base);
  59. $this->_setSummary($this->_dom, $this->_base);
  60. if ($this->_called) {
  61. $this->_appendNamespaces();
  62. }
  63. }
  64. /**
  65. * Append feed namespaces
  66. *
  67. * @return void
  68. */
  69. protected function _appendNamespaces()
  70. {
  71. $this->getRootElement()->setAttribute('xmlns:itunes',
  72. 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  73. }
  74. /**
  75. * Set feed authors
  76. *
  77. * @param DOMDocument $dom
  78. * @param DOMElement $root
  79. * @return void
  80. */
  81. protected function _setAuthors(DOMDocument $dom, DOMElement $root)
  82. {
  83. $authors = $this->getDataContainer()->getItunesAuthors();
  84. if (!$authors || empty($authors)) {
  85. return;
  86. }
  87. foreach ($authors as $author) {
  88. $el = $dom->createElement('itunes:author');
  89. $text = $dom->createTextNode($author);
  90. $el->appendChild($text);
  91. $root->appendChild($el);
  92. }
  93. $this->_called = true;
  94. }
  95. /**
  96. * Set feed itunes block
  97. *
  98. * @param DOMDocument $dom
  99. * @param DOMElement $root
  100. * @return void
  101. */
  102. protected function _setBlock(DOMDocument $dom, DOMElement $root)
  103. {
  104. $block = $this->getDataContainer()->getItunesBlock();
  105. if ($block === null) {
  106. return;
  107. }
  108. $el = $dom->createElement('itunes:block');
  109. $text = $dom->createTextNode($block);
  110. $el->appendChild($text);
  111. $root->appendChild($el);
  112. $this->_called = true;
  113. }
  114. /**
  115. * Set feed categories
  116. *
  117. * @param DOMDocument $dom
  118. * @param DOMElement $root
  119. * @return void
  120. */
  121. protected function _setCategories(DOMDocument $dom, DOMElement $root)
  122. {
  123. $cats = $this->getDataContainer()->getItunesCategories();
  124. if (!$cats || empty($cats)) {
  125. return;
  126. }
  127. foreach ($cats as $key=>$cat) {
  128. if (!is_array($cat)) {
  129. $el = $dom->createElement('itunes:category');
  130. $el->setAttribute('text', $cat);
  131. $root->appendChild($el);
  132. } else {
  133. $el = $dom->createElement('itunes:category');
  134. $el->setAttribute('text', $key);
  135. $root->appendChild($el);
  136. foreach ($cat as $subcat) {
  137. $el2 = $dom->createElement('itunes:category');
  138. $el2->setAttribute('text', $subcat);
  139. $el->appendChild($el2);
  140. }
  141. }
  142. }
  143. $this->_called = true;
  144. }
  145. /**
  146. * Set feed image (icon)
  147. *
  148. * @param DOMDocument $dom
  149. * @param DOMElement $root
  150. * @return void
  151. */
  152. protected function _setImage(DOMDocument $dom, DOMElement $root)
  153. {
  154. $image = $this->getDataContainer()->getItunesImage();
  155. if (!$image) {
  156. return;
  157. }
  158. $el = $dom->createElement('itunes:image');
  159. $el->setAttribute('href', $image);
  160. $root->appendChild($el);
  161. $this->_called = true;
  162. }
  163. /**
  164. * Set feed cumulative duration
  165. *
  166. * @param DOMDocument $dom
  167. * @param DOMElement $root
  168. * @return void
  169. */
  170. protected function _setDuration(DOMDocument $dom, DOMElement $root)
  171. {
  172. $duration = $this->getDataContainer()->getItunesDuration();
  173. if (!$duration) {
  174. return;
  175. }
  176. $el = $dom->createElement('itunes:duration');
  177. $text = $dom->createTextNode($duration);
  178. $el->appendChild($text);
  179. $root->appendChild($el);
  180. $this->_called = true;
  181. }
  182. /**
  183. * Set explicit flag
  184. *
  185. * @param DOMDocument $dom
  186. * @param DOMElement $root
  187. * @return void
  188. */
  189. protected function _setExplicit(DOMDocument $dom, DOMElement $root)
  190. {
  191. $explicit = $this->getDataContainer()->getItunesExplicit();
  192. if ($explicit === null) {
  193. return;
  194. }
  195. $el = $dom->createElement('itunes:explicit');
  196. $text = $dom->createTextNode($explicit);
  197. $el->appendChild($text);
  198. $root->appendChild($el);
  199. $this->_called = true;
  200. }
  201. /**
  202. * Set feed keywords
  203. *
  204. * @param DOMDocument $dom
  205. * @param DOMElement $root
  206. * @return void
  207. */
  208. protected function _setKeywords(DOMDocument $dom, DOMElement $root)
  209. {
  210. $keywords = $this->getDataContainer()->getItunesKeywords();
  211. if (!$keywords || empty($keywords)) {
  212. return;
  213. }
  214. $el = $dom->createElement('itunes:keywords');
  215. $text = $dom->createTextNode(implode(',', $keywords));
  216. $el->appendChild($text);
  217. $root->appendChild($el);
  218. $this->_called = true;
  219. }
  220. /**
  221. * Set feed's new URL
  222. *
  223. * @param DOMDocument $dom
  224. * @param DOMElement $root
  225. * @return void
  226. */
  227. protected function _setNewFeedUrl(DOMDocument $dom, DOMElement $root)
  228. {
  229. $url = $this->getDataContainer()->getItunesNewFeedUrl();
  230. if (!$url) {
  231. return;
  232. }
  233. $el = $dom->createElement('itunes:new-feed-url');
  234. $text = $dom->createTextNode($url);
  235. $el->appendChild($text);
  236. $root->appendChild($el);
  237. $this->_called = true;
  238. }
  239. /**
  240. * Set feed owners
  241. *
  242. * @param DOMDocument $dom
  243. * @param DOMElement $root
  244. * @return void
  245. */
  246. protected function _setOwners(DOMDocument $dom, DOMElement $root)
  247. {
  248. $owners = $this->getDataContainer()->getItunesOwners();
  249. if (!$owners || empty($owners)) {
  250. return;
  251. }
  252. foreach ($owners as $owner) {
  253. $el = $dom->createElement('itunes:owner');
  254. $name = $dom->createElement('itunes:name');
  255. $text = $dom->createTextNode($owner['name']);
  256. $name->appendChild($text);
  257. $email = $dom->createElement('itunes:email');
  258. $text = $dom->createTextNode($owner['email']);
  259. $email->appendChild($text);
  260. $root->appendChild($el);
  261. $el->appendChild($name);
  262. $el->appendChild($email);
  263. }
  264. $this->_called = true;
  265. }
  266. /**
  267. * Set feed subtitle
  268. *
  269. * @param DOMDocument $dom
  270. * @param DOMElement $root
  271. * @return void
  272. */
  273. protected function _setSubtitle(DOMDocument $dom, DOMElement $root)
  274. {
  275. $subtitle = $this->getDataContainer()->getItunesSubtitle();
  276. if (!$subtitle) {
  277. return;
  278. }
  279. $el = $dom->createElement('itunes:subtitle');
  280. $text = $dom->createTextNode($subtitle);
  281. $el->appendChild($text);
  282. $root->appendChild($el);
  283. $this->_called = true;
  284. }
  285. /**
  286. * Set feed summary
  287. *
  288. * @param DOMDocument $dom
  289. * @param DOMElement $root
  290. * @return void
  291. */
  292. protected function _setSummary(DOMDocument $dom, DOMElement $root)
  293. {
  294. $summary = $this->getDataContainer()->getItunesSummary();
  295. if (!$summary) {
  296. return;
  297. }
  298. $el = $dom->createElement('itunes:summary');
  299. $text = $dom->createTextNode($summary);
  300. $el->appendChild($text);
  301. $root->appendChild($el);
  302. $this->_called = true;
  303. }
  304. }