annotate vendor/zendframework/zend-feed/src/Reader/Extension/Podcast/Feed.php @ 19:fa3358dc1485 tip

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