/library/Zend/Feed/Reader/Extension/Podcast/Feed.php
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/**
23 * @see Zend_Feed_Reader_Extension_FeedAbstract
24 */
25require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
26
27/**
28 * @category Zend
29 * @package Zend_Feed_Reader
30 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
32 */
33class Zend_Feed_Reader_Extension_Podcast_Feed extends Zend_Feed_Reader_Extension_FeedAbstract
34{
35 /**
36 * Get the entry author
37 *
38 * @return string
39 */
40 public function getCastAuthor()
41 {
42 if (isset($this->_data['author'])) {
43 return $this->_data['author'];
44 }
45
46 $author = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:author)');
47
48 if (!$author) {
49 $author = null;
50 }
51
52 $this->_data['author'] = $author;
53
54 return $this->_data['author'];
55 }
56
57 /**
58 * Get the entry block
59 *
60 * @return string
61 */
62 public function getBlock()
63 {
64 if (isset($this->_data['block'])) {
65 return $this->_data['block'];
66 }
67
68 $block = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:block)');
69
70 if (!$block) {
71 $block = null;
72 }
73
74 $this->_data['block'] = $block;
75
76 return $this->_data['block'];
77 }
78
79 /**
80 * Get the entry category
81 *
82 * @return string
83 */
84 public function getCategories()
85 {
86 if (isset($this->_data['categories'])) {
87 return $this->_data['categories'];
88 }
89
90 $categoryList = $this->_xpath->query($this->getXpathPrefix() . '/itunes:category');
91
92 $categories = array();
93
94 if ($categoryList->length > 0) {
95 foreach ($categoryList as $node) {
96 $children = null;
97
98 if ($node->childNodes->length > 0) {
99 $children = array();
100
101 foreach ($node->childNodes as $childNode) {
102 if (!($childNode instanceof DOMText)) {
103 $children[$childNode->getAttribute('text')] = null;
104 }
105 }
106 }
107
108 $categories[$node->getAttribute('text')] = $children;
109 }
110 }
111
112
113 if (!$categories) {
114 $categories = null;
115 }
116
117 $this->_data['categories'] = $categories;
118
119 return $this->_data['categories'];
120 }
121
122 /**
123 * Get the entry explicit
124 *
125 * @return string
126 */
127 public function getExplicit()
128 {
129 if (isset($this->_data['explicit'])) {
130 return $this->_data['explicit'];
131 }
132
133 $explicit = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:explicit)');
134
135 if (!$explicit) {
136 $explicit = null;
137 }
138
139 $this->_data['explicit'] = $explicit;
140
141 return $this->_data['explicit'];
142 }
143
144 /**
145 * Get the entry image
146 *
147 * @return string
148 */
149 public function getImage()
150 {
151 if (isset($this->_data['image'])) {
152 return $this->_data['image'];
153 }
154
155 $image = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:image/@href)');
156
157 if (!$image) {
158 $image = null;
159 }
160
161 $this->_data['image'] = $image;
162
163 return $this->_data['image'];
164 }
165
166 /**
167 * Get the entry keywords
168 *
169 * @return string
170 */
171 public function getKeywords()
172 {
173 if (isset($this->_data['keywords'])) {
174 return $this->_data['keywords'];
175 }
176
177 $keywords = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:keywords)');
178
179 if (!$keywords) {
180 $keywords = null;
181 }
182
183 $this->_data['keywords'] = $keywords;
184
185 return $this->_data['keywords'];
186 }
187
188 /**
189 * Get the entry's new feed url
190 *
191 * @return string
192 */
193 public function getNewFeedUrl()
194 {
195 if (isset($this->_data['new-feed-url'])) {
196 return $this->_data['new-feed-url'];
197 }
198
199 $newFeedUrl = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:new-feed-url)');
200
201 if (!$newFeedUrl) {
202 $newFeedUrl = null;
203 }
204
205 $this->_data['new-feed-url'] = $newFeedUrl;
206
207 return $this->_data['new-feed-url'];
208 }
209
210 /**
211 * Get the entry owner
212 *
213 * @return string
214 */
215 public function getOwner()
216 {
217 if (isset($this->_data['owner'])) {
218 return $this->_data['owner'];
219 }
220
221 $owner = null;
222
223 $email = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:email)');
224 $name = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:name)');
225
226 if (!empty($email)) {
227 $owner = $email . (empty($name) ? '' : ' (' . $name . ')');
228 } else if (!empty($name)) {
229 $owner = $name;
230 }
231
232 if (!$owner) {
233 $owner = null;
234 }
235
236 $this->_data['owner'] = $owner;
237
238 return $this->_data['owner'];
239 }
240
241 /**
242 * Get the entry subtitle
243 *
244 * @return string
245 */
246 public function getSubtitle()
247 {
248 if (isset($this->_data['subtitle'])) {
249 return $this->_data['subtitle'];
250 }
251
252 $subtitle = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:subtitle)');
253
254 if (!$subtitle) {
255 $subtitle = null;
256 }
257
258 $this->_data['subtitle'] = $subtitle;
259
260 return $this->_data['subtitle'];
261 }
262
263 /**
264 * Get the entry summary
265 *
266 * @return string
267 */
268 public function getSummary()
269 {
270 if (isset($this->_data['summary'])) {
271 return $this->_data['summary'];
272 }
273
274 $summary = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:summary)');
275
276 if (!$summary) {
277 $summary = null;
278 }
279
280 $this->_data['summary'] = $summary;
281
282 return $this->_data['summary'];
283 }
284
285 /**
286 * Register iTunes namespace
287 *
288 */
289 protected function _registerNamespaces()
290 {
291 $this->_xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
292 }
293}