987fc6927163353bb8c90e0da039b1f6033eea23
[yaffs-website] / vendor / zendframework / zend-feed / src / Reader / Extension / Podcast / Feed.php
1 <?php
2 /**
3  * @see       https://github.com/zendframework/zend-feed for the canonical source repository
4  * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5  * @license   https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License
6  */
7
8 namespace Zend\Feed\Reader\Extension\Podcast;
9
10 use DOMText;
11 use Zend\Feed\Reader\Extension;
12
13 class Feed extends Extension\AbstractFeed
14 {
15     /**
16      * Get the entry author
17      *
18      * @return string
19      */
20     public function getCastAuthor()
21     {
22         if (isset($this->data['author'])) {
23             return $this->data['author'];
24         }
25
26         $author = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:author)');
27
28         if (! $author) {
29             $author = null;
30         }
31
32         $this->data['author'] = $author;
33
34         return $this->data['author'];
35     }
36
37     /**
38      * Get the entry block
39      *
40      * @return string
41      */
42     public function getBlock()
43     {
44         if (isset($this->data['block'])) {
45             return $this->data['block'];
46         }
47
48         $block = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:block)');
49
50         if (! $block) {
51             $block = null;
52         }
53
54         $this->data['block'] = $block;
55
56         return $this->data['block'];
57     }
58
59     /**
60      * Get the entry category
61      *
62      * @return array|null
63      */
64     public function getItunesCategories()
65     {
66         if (isset($this->data['categories'])) {
67             return $this->data['categories'];
68         }
69
70         $categoryList = $this->xpath->query($this->getXpathPrefix() . '/itunes:category');
71
72         $categories = [];
73
74         if ($categoryList->length > 0) {
75             foreach ($categoryList as $node) {
76                 $children = null;
77
78                 if ($node->childNodes->length > 0) {
79                     $children = [];
80
81                     foreach ($node->childNodes as $childNode) {
82                         if (! ($childNode instanceof DOMText)) {
83                             $children[$childNode->getAttribute('text')] = null;
84                         }
85                     }
86                 }
87
88                 $categories[$node->getAttribute('text')] = $children;
89             }
90         }
91
92         if (! $categories) {
93             $categories = null;
94         }
95
96         $this->data['categories'] = $categories;
97
98         return $this->data['categories'];
99     }
100
101     /**
102      * Get the entry explicit
103      *
104      * @return string
105      */
106     public function getExplicit()
107     {
108         if (isset($this->data['explicit'])) {
109             return $this->data['explicit'];
110         }
111
112         $explicit = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:explicit)');
113
114         if (! $explicit) {
115             $explicit = null;
116         }
117
118         $this->data['explicit'] = $explicit;
119
120         return $this->data['explicit'];
121     }
122
123     /**
124      * Get the feed/podcast image
125      *
126      * @return string
127      */
128     public function getItunesImage()
129     {
130         if (isset($this->data['image'])) {
131             return $this->data['image'];
132         }
133
134         $image = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:image/@href)');
135
136         if (! $image) {
137             $image = null;
138         }
139
140         $this->data['image'] = $image;
141
142         return $this->data['image'];
143     }
144
145     /**
146      * Get the entry keywords
147      *
148      * @deprecated since 2.10.0; itunes:keywords is no longer part of the
149      *     iTunes podcast RSS specification.
150      * @return string
151      */
152     public function getKeywords()
153     {
154         trigger_error(
155             'itunes:keywords has been deprecated in the iTunes podcast RSS specification,'
156             . ' and should not be relied on.',
157             \E_USER_DEPRECATED
158         );
159
160         if (isset($this->data['keywords'])) {
161             return $this->data['keywords'];
162         }
163
164         $keywords = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:keywords)');
165
166         if (! $keywords) {
167             $keywords = null;
168         }
169
170         $this->data['keywords'] = $keywords;
171
172         return $this->data['keywords'];
173     }
174
175     /**
176      * Get the entry's new feed url
177      *
178      * @return string
179      */
180     public function getNewFeedUrl()
181     {
182         if (isset($this->data['new-feed-url'])) {
183             return $this->data['new-feed-url'];
184         }
185
186         $newFeedUrl = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:new-feed-url)');
187
188         if (! $newFeedUrl) {
189             $newFeedUrl = null;
190         }
191
192         $this->data['new-feed-url'] = $newFeedUrl;
193
194         return $this->data['new-feed-url'];
195     }
196
197     /**
198      * Get the entry owner
199      *
200      * @return string
201      */
202     public function getOwner()
203     {
204         if (isset($this->data['owner'])) {
205             return $this->data['owner'];
206         }
207
208         $owner = null;
209
210         $email = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:email)');
211         $name  = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:owner/itunes:name)');
212
213         if (! empty($email)) {
214             $owner = $email . (empty($name) ? '' : ' (' . $name . ')');
215         } elseif (! empty($name)) {
216             $owner = $name;
217         }
218
219         if (! $owner) {
220             $owner = null;
221         }
222
223         $this->data['owner'] = $owner;
224
225         return $this->data['owner'];
226     }
227
228     /**
229      * Get the entry subtitle
230      *
231      * @return string
232      */
233     public function getSubtitle()
234     {
235         if (isset($this->data['subtitle'])) {
236             return $this->data['subtitle'];
237         }
238
239         $subtitle = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:subtitle)');
240
241         if (! $subtitle) {
242             $subtitle = null;
243         }
244
245         $this->data['subtitle'] = $subtitle;
246
247         return $this->data['subtitle'];
248     }
249
250     /**
251      * Get the entry summary
252      *
253      * @return string
254      */
255     public function getSummary()
256     {
257         if (isset($this->data['summary'])) {
258             return $this->data['summary'];
259         }
260
261         $summary = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:summary)');
262
263         if (! $summary) {
264             $summary = null;
265         }
266
267         $this->data['summary'] = $summary;
268
269         return $this->data['summary'];
270     }
271
272     /**
273      * Get the type of podcast
274      *
275      * @return string One of "episodic" or "serial". Defaults to "episodic"
276      *     if no itunes:type tag is encountered.
277      */
278     public function getPodcastType()
279     {
280         if (isset($this->data['podcastType'])) {
281             return $this->data['podcastType'];
282         }
283
284         $type = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:type)');
285
286         if (! $type) {
287             $type = 'episodic';
288         }
289
290         $this->data['podcastType'] = (string) $type;
291
292         return $this->data['podcastType'];
293     }
294
295     /**
296      * Is the podcast complete (no more episodes will post)?
297      *
298      * @return bool
299      */
300     public function isComplete()
301     {
302         if (isset($this->data['complete'])) {
303             return $this->data['complete'];
304         }
305
306         $complete = $this->xpath->evaluate('string(' . $this->getXpathPrefix() . '/itunes:complete)');
307
308         if (! $complete) {
309             $complete = false;
310         }
311
312         $this->data['complete'] = $complete === 'Yes';
313
314         return $this->data['complete'];
315     }
316
317     /**
318      * Register iTunes namespace
319      *
320      */
321     protected function registerNamespaces()
322     {
323         $this->xpath->registerNamespace('itunes', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
324     }
325 }