PageRenderTime 87ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Feed/Reader/Extension/Podcast/Feed.php

https://bitbucket.org/hamidrezas/melobit
PHP | 293 lines | 151 code | 60 blank | 82 comment | 26 complexity | 0161294791fce0170465c4abb77df336 MD5 | raw file
Possible License(s): AGPL-1.0
  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_Reader
  17. * @copyright Copyright (c) 2005-2012 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 24594 2012-01-05 21:27:01Z matthew $
  20. */
  21. /**
  22. * @see Zend_Feed_Reader_Extension_FeedAbstract
  23. */
  24. require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Feed_Reader
  28. * @copyright Copyright (c) 2005-2012 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_Reader_Extension_Podcast_Feed extends Zend_Feed_Reader_Extension_FeedAbstract
  32. {
  33. /**
  34. * Get the entry author
  35. *
  36. * @return string
  37. */
  38. public function getCastAuthor()
  39. {
  40. if (isset($this->_data['author'])) {
  41. return $this->_data['author'];
  42. }
  43. $author = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:author)');
  44. if (!$author) {
  45. $author = null;
  46. }
  47. $this->_data['author'] = $author;
  48. return $this->_data['author'];
  49. }
  50. /**
  51. * Get the entry block
  52. *
  53. * @return string
  54. */
  55. public function getBlock()
  56. {
  57. if (isset($this->_data['block'])) {
  58. return $this->_data['block'];
  59. }
  60. $block = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:block)');
  61. if (!$block) {
  62. $block = null;
  63. }
  64. $this->_data['block'] = $block;
  65. return $this->_data['block'];
  66. }
  67. /**
  68. * Get the entry category
  69. *
  70. * @return string
  71. */
  72. public function getCategories()
  73. {
  74. if (isset($this->_data['categories'])) {
  75. return $this->_data['categories'];
  76. }
  77. $categoryList = $this->_xpath->query($this->getXpathPrefix() . '/itunes:category');
  78. $categories = array();
  79. if ($categoryList->length > 0) {
  80. foreach ($categoryList as $node) {
  81. $children = null;
  82. if ($node->childNodes->length > 0) {
  83. $children = array();
  84. foreach ($node->childNodes as $childNode) {
  85. if (!($childNode instanceof DOMText)) {
  86. $children[$childNode->getAttribute('text')] = null;
  87. }
  88. }
  89. }
  90. $categories[$node->getAttribute('text')] = $children;
  91. }
  92. }
  93. if (!$categories) {
  94. $categories = null;
  95. }
  96. $this->_data['categories'] = $categories;
  97. return $this->_data['categories'];
  98. }
  99. /**
  100. * Get the entry explicit
  101. *
  102. * @return string
  103. */
  104. public function getExplicit()
  105. {
  106. if (isset($this->_data['explicit'])) {
  107. return $this->_data['explicit'];
  108. }
  109. $explicit = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:explicit)');
  110. if (!$explicit) {
  111. $explicit = null;
  112. }
  113. $this->_data['explicit'] = $explicit;
  114. return $this->_data['explicit'];
  115. }
  116. /**
  117. * Get the entry image
  118. *
  119. * @return string
  120. */
  121. public function getImage()
  122. {
  123. if (isset($this->_data['image'])) {
  124. return $this->_data['image'];
  125. }
  126. $image = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:image/@href)');
  127. if (!$image) {
  128. $image = null;
  129. }
  130. $this->_data['image'] = $image;
  131. return $this->_data['image'];
  132. }
  133. /**
  134. * Get the entry keywords
  135. *
  136. * @return string
  137. */
  138. public function getKeywords()
  139. {
  140. if (isset($this->_data['keywords'])) {
  141. return $this->_data['keywords'];
  142. }
  143. $keywords = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:keywords)');
  144. if (!$keywords) {
  145. $keywords = null;
  146. }
  147. $this->_data['keywords'] = $keywords;
  148. return $this->_data['keywords'];
  149. }
  150. /**
  151. * Get the entry's new feed url
  152. *
  153. * @return string
  154. */
  155. public function getNewFeedUrl()
  156. {
  157. if (isset($this->_data['new-feed-url'])) {
  158. return $this->_data['new-feed-url'];
  159. }
  160. $newFeedUrl = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:new-feed-url)');
  161. if (!$newFeedUrl) {
  162. $newFeedUrl = null;
  163. }
  164. $this->_data['new-feed-url'] = $newFeedUrl;
  165. return $this->_data['new-feed-url'];
  166. }
  167. /**
  168. * Get the entry owner
  169. *
  170. * @return string
  171. */
  172. public function getOwner()
  173. {
  174. if (isset($this->_data['owner'])) {
  175. return $this->_data['owner'];
  176. }
  177. $owner = null;
  178. $email = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:email)');
  179. $name = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:name)');
  180. if (!empty($email)) {
  181. $owner = $email . (empty($name) ? '' : ' (' . $name . ')');
  182. } else if (!empty($name)) {
  183. $owner = $name;
  184. }
  185. if (!$owner) {
  186. $owner = null;
  187. }
  188. $this->_data['owner'] = $owner;
  189. return $this->_data['owner'];
  190. }
  191. /**
  192. * Get the entry subtitle
  193. *
  194. * @return string
  195. */
  196. public function getSubtitle()
  197. {
  198. if (isset($this->_data['subtitle'])) {
  199. return $this->_data['subtitle'];
  200. }
  201. $subtitle = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:subtitle)');
  202. if (!$subtitle) {
  203. $subtitle = null;
  204. }
  205. $this->_data['subtitle'] = $subtitle;
  206. return $this->_data['subtitle'];
  207. }
  208. /**
  209. * Get the entry summary
  210. *
  211. * @return string
  212. */
  213. public function getSummary()
  214. {
  215. if (isset($this->_data['summary'])) {
  216. return $this->_data['summary'];
  217. }
  218. $summary = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:summary)');
  219. if (!$summary) {
  220. $summary = null;
  221. }
  222. $this->_data['summary'] = $summary;
  223. return $this->_data['summary'];
  224. }
  225. /**
  226. * Register iTunes namespace
  227. *
  228. */
  229. protected function _registerNamespaces()
  230. {
  231. $this->_xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  232. }
  233. }