[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * SimplePie 5 * 6 * A PHP-Based RSS and Atom Feed Framework. 7 * Takes the hard work out of managing a complete RSS/Atom solution. 8 * 9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without modification, are 13 * permitted provided that the following conditions are met: 14 * 15 * * Redistributions of source code must retain the above copyright notice, this list of 16 * conditions and the following disclaimer. 17 * 18 * * Redistributions in binary form must reproduce the above copyright notice, this list 19 * of conditions and the following disclaimer in the documentation and/or other materials 20 * provided with the distribution. 21 * 22 * * Neither the name of the SimplePie Team nor the names of its contributors may be used 23 * to endorse or promote products derived from this software without specific prior 24 * written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 27 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 29 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 * 36 * @package SimplePie 37 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue 38 * @author Ryan Parman 39 * @author Sam Sneddon 40 * @author Ryan McCue 41 * @link http://simplepie.org/ SimplePie 42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 43 */ 44 45 namespace SimplePie; 46 47 /** 48 * Manages all item-related data 49 * 50 * Used by {@see \SimplePie\SimplePie::get_item()} and {@see \SimplePie\SimplePie::get_items()} 51 * 52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_item_class()} 53 * 54 * @package \SimplePie\SimplePie 55 * @subpackage API 56 */ 57 class Item implements RegistryAware 58 { 59 /** 60 * Parent feed 61 * 62 * @access private 63 * @var \SimplePie\SimplePie 64 */ 65 public $feed; 66 67 /** 68 * Raw data 69 * 70 * @access private 71 * @var array 72 */ 73 public $data = []; 74 75 /** 76 * Registry object 77 * 78 * @see set_registry 79 * @var \SimplePie\Registry 80 */ 81 protected $registry; 82 83 /** 84 * Create a new item object 85 * 86 * This is usually used by {@see \SimplePie\SimplePie::get_items} and 87 * {@see \SimplePie\SimplePie::get_item}. Avoid creating this manually. 88 * 89 * @param \SimplePie\SimplePie $feed Parent feed 90 * @param array $data Raw data 91 */ 92 public function __construct($feed, $data) 93 { 94 $this->feed = $feed; 95 $this->data = $data; 96 } 97 98 /** 99 * Set the registry handler 100 * 101 * This is usually used by {@see \SimplePie\Registry::create} 102 * 103 * @since 1.3 104 * @param \SimplePie\Registry $registry 105 */ 106 public function set_registry(\SimplePie\Registry $registry)/* : void */ 107 { 108 $this->registry = $registry; 109 } 110 111 /** 112 * Get a string representation of the item 113 * 114 * @return string 115 */ 116 public function __toString() 117 { 118 return md5(serialize($this->data)); 119 } 120 121 /** 122 * Remove items that link back to this before destroying this object 123 */ 124 public function __destruct() 125 { 126 if (!gc_enabled()) { 127 unset($this->feed); 128 } 129 } 130 131 /** 132 * Get data for an item-level element 133 * 134 * This method allows you to get access to ANY element/attribute that is a 135 * sub-element of the item/entry tag. 136 * 137 * See {@see \SimplePie\SimplePie::get_feed_tags()} for a description of the return value 138 * 139 * @since 1.0 140 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 141 * @param string $namespace The URL of the XML namespace of the elements you're trying to access 142 * @param string $tag Tag name 143 * @return array 144 */ 145 public function get_item_tags($namespace, $tag) 146 { 147 if (isset($this->data['child'][$namespace][$tag])) { 148 return $this->data['child'][$namespace][$tag]; 149 } 150 151 return null; 152 } 153 154 /** 155 * Get the base URL value. 156 * Uses `<xml:base>`, or item link, or feed base URL. 157 * 158 * @param array $element 159 * @return string 160 */ 161 public function get_base($element = []) 162 { 163 if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) { 164 return $element['xml_base']; 165 } 166 $link = $this->get_permalink(); 167 if ($link != null) { 168 return $link; 169 } 170 return $this->feed->get_base($element); 171 } 172 173 /** 174 * Sanitize feed data 175 * 176 * @access private 177 * @see \SimplePie\SimplePie::sanitize() 178 * @param string $data Data to sanitize 179 * @param int $type One of the \SimplePie\SimplePie::CONSTRUCT_* constants 180 * @param string $base Base URL to resolve URLs against 181 * @return string Sanitized data 182 */ 183 public function sanitize($data, $type, $base = '') 184 { 185 return $this->feed->sanitize($data, $type, $base); 186 } 187 188 /** 189 * Get the parent feed 190 * 191 * Note: this may not work as you think for multifeeds! 192 * 193 * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed 194 * @since 1.0 195 * @return \SimplePie\SimplePie 196 */ 197 public function get_feed() 198 { 199 return $this->feed; 200 } 201 202 /** 203 * Get the unique identifier for the item 204 * 205 * This is usually used when writing code to check for new items in a feed. 206 * 207 * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute 208 * for RDF. If none of these are supplied (or `$hash` is true), creates an 209 * MD5 hash based on the permalink, title and content. 210 * 211 * @since Beta 2 212 * @param boolean $hash Should we force using a hash instead of the supplied ID? 213 * @param string|false $fn User-supplied function to generate an hash 214 * @return string|null 215 */ 216 public function get_id($hash = false, $fn = 'md5') 217 { 218 if (!$hash) { 219 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'id')) { 220 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 221 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'id')) { 222 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 223 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'guid')) { 224 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 225 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'identifier')) { 226 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 227 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'identifier')) { 228 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 229 } elseif (isset($this->data['attribs'][\SimplePie\SimplePie::NAMESPACE_RDF]['about'])) { 230 return $this->sanitize($this->data['attribs'][\SimplePie\SimplePie::NAMESPACE_RDF]['about'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 231 } 232 } 233 if ($fn === false) { 234 return null; 235 } elseif (!is_callable($fn)) { 236 trigger_error('User-supplied function $fn must be callable', E_USER_WARNING); 237 $fn = 'md5'; 238 } 239 return call_user_func( 240 $fn, 241 $this->get_permalink().$this->get_title().$this->get_content() 242 ); 243 } 244 245 /** 246 * Get the title of the item 247 * 248 * Uses `<atom:title>`, `<title>` or `<dc:title>` 249 * 250 * @since Beta 2 (previously called `get_item_title` since 0.8) 251 * @return string|null 252 */ 253 public function get_title() 254 { 255 if (!isset($this->data['title'])) { 256 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'title')) { 257 $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); 258 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'title')) { 259 $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); 260 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10, 'title')) { 261 $this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 262 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_090, 'title')) { 263 $this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 264 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'title')) { 265 $this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 266 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'title')) { 267 $this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 268 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'title')) { 269 $this->data['title'] = $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 270 } else { 271 $this->data['title'] = null; 272 } 273 } 274 return $this->data['title']; 275 } 276 277 /** 278 * Get the content for the item 279 * 280 * Prefers summaries over full content , but will return full content if a 281 * summary does not exist. 282 * 283 * To prefer full content instead, use {@see get_content} 284 * 285 * Uses `<atom:summary>`, `<description>`, `<dc:description>` or 286 * `<itunes:subtitle>` 287 * 288 * @since 0.8 289 * @param boolean $description_only Should we avoid falling back to the content? 290 * @return string|null 291 */ 292 public function get_description($description_only = false) 293 { 294 if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'summary')) && 295 ($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) { 296 return $return; 297 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'summary')) && 298 ($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) { 299 return $return; 300 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10, 'description')) && 301 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0])))) { 302 return $return; 303 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'description')) && 304 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML, $this->get_base($tags[0])))) { 305 return $return; 306 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'description')) && 307 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT))) { 308 return $return; 309 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'description')) && 310 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT))) { 311 return $return; 312 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'summary')) && 313 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML, $this->get_base($tags[0])))) { 314 return $return; 315 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'subtitle')) && 316 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT))) { 317 return $return; 318 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_090, 'description')) && 319 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML))) { 320 return $return; 321 } elseif (!$description_only) { 322 return $this->get_content(true); 323 } 324 325 return null; 326 } 327 328 /** 329 * Get the content for the item 330 * 331 * Prefers full content over summaries, but will return a summary if full 332 * content does not exist. 333 * 334 * To prefer summaries instead, use {@see get_description} 335 * 336 * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module) 337 * 338 * @since 1.0 339 * @param boolean $content_only Should we avoid falling back to the description? 340 * @return string|null 341 */ 342 public function get_content($content_only = false) 343 { 344 if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'content')) && 345 ($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_10_content_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) { 346 return $return; 347 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'content')) && 348 ($return = $this->sanitize($tags[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$tags[0]['attribs']]), $this->get_base($tags[0])))) { 349 return $return; 350 } elseif (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) && 351 ($return = $this->sanitize($tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_HTML, $this->get_base($tags[0])))) { 352 return $return; 353 } elseif (!$content_only) { 354 return $this->get_description(true); 355 } 356 357 return null; 358 } 359 360 /** 361 * Get the media:thumbnail of the item 362 * 363 * Uses `<media:thumbnail>` 364 * 365 * 366 * @return array|null 367 */ 368 public function get_thumbnail() 369 { 370 if (!isset($this->data['thumbnail'])) { 371 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'thumbnail')) { 372 $thumbnail = $return[0]['attribs']['']; 373 if (empty($thumbnail['url'])) { 374 $this->data['thumbnail'] = null; 375 } else { 376 $thumbnail['url'] = $this->sanitize($thumbnail['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($return[0])); 377 $this->data['thumbnail'] = $thumbnail; 378 } 379 } else { 380 $this->data['thumbnail'] = null; 381 } 382 } 383 return $this->data['thumbnail']; 384 } 385 386 /** 387 * Get a category for the item 388 * 389 * @since Beta 3 (previously called `get_categories()` since Beta 2) 390 * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1 391 * @return \SimplePie\Category|null 392 */ 393 public function get_category($key = 0) 394 { 395 $categories = $this->get_categories(); 396 if (isset($categories[$key])) { 397 return $categories[$key]; 398 } 399 400 return null; 401 } 402 403 /** 404 * Get all categories for the item 405 * 406 * Uses `<atom:category>`, `<category>` or `<dc:subject>` 407 * 408 * @since Beta 3 409 * @return \SimplePie\Category[]|null List of {@see \SimplePie\Category} objects 410 */ 411 public function get_categories() 412 { 413 $categories = []; 414 415 $type = 'category'; 416 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, $type) as $category) { 417 $term = null; 418 $scheme = null; 419 $label = null; 420 if (isset($category['attribs']['']['term'])) { 421 $term = $this->sanitize($category['attribs']['']['term'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 422 } 423 if (isset($category['attribs']['']['scheme'])) { 424 $scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 425 } 426 if (isset($category['attribs']['']['label'])) { 427 $label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 428 } 429 $categories[] = $this->registry->create(Category::class, [$term, $scheme, $label, $type]); 430 } 431 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, $type) as $category) { 432 // This is really the label, but keep this as the term also for BC. 433 // Label will also work on retrieving because that falls back to term. 434 $term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 435 if (isset($category['attribs']['']['domain'])) { 436 $scheme = $this->sanitize($category['attribs']['']['domain'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 437 } else { 438 $scheme = null; 439 } 440 $categories[] = $this->registry->create(Category::class, [$term, $scheme, null, $type]); 441 } 442 443 $type = 'subject'; 444 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, $type) as $category) { 445 $categories[] = $this->registry->create(Category::class, [$this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null, $type]); 446 } 447 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, $type) as $category) { 448 $categories[] = $this->registry->create(Category::class, [$this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null, $type]); 449 } 450 451 if (!empty($categories)) { 452 return array_unique($categories); 453 } 454 455 return null; 456 } 457 458 /** 459 * Get an author for the item 460 * 461 * @since Beta 2 462 * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1 463 * @return \SimplePie\Author|null 464 */ 465 public function get_author($key = 0) 466 { 467 $authors = $this->get_authors(); 468 if (isset($authors[$key])) { 469 return $authors[$key]; 470 } 471 472 return null; 473 } 474 475 /** 476 * Get a contributor for the item 477 * 478 * @since 1.1 479 * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1 480 * @return \SimplePie\Author|null 481 */ 482 public function get_contributor($key = 0) 483 { 484 $contributors = $this->get_contributors(); 485 if (isset($contributors[$key])) { 486 return $contributors[$key]; 487 } 488 489 return null; 490 } 491 492 /** 493 * Get all contributors for the item 494 * 495 * Uses `<atom:contributor>` 496 * 497 * @since 1.1 498 * @return \SimplePie\Author[]|null List of {@see \SimplePie\Author} objects 499 */ 500 public function get_contributors() 501 { 502 $contributors = []; 503 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'contributor') as $contributor) { 504 $name = null; 505 $uri = null; 506 $email = null; 507 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['name'][0]['data'])) { 508 $name = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['name'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 509 } 510 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]['data'])) { 511 $uri = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0])); 512 } 513 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) { 514 $email = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 515 } 516 if ($name !== null || $email !== null || $uri !== null) { 517 $contributors[] = $this->registry->create(Author::class, [$name, $uri, $email]); 518 } 519 } 520 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'contributor') as $contributor) { 521 $name = null; 522 $url = null; 523 $email = null; 524 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['name'][0]['data'])) { 525 $name = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['name'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 526 } 527 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0]['data'])) { 528 $url = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0])); 529 } 530 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'])) { 531 $email = $this->sanitize($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 532 } 533 if ($name !== null || $email !== null || $url !== null) { 534 $contributors[] = $this->registry->create(Author::class, [$name, $url, $email]); 535 } 536 } 537 538 if (!empty($contributors)) { 539 return array_unique($contributors); 540 } 541 542 return null; 543 } 544 545 /** 546 * Get all authors for the item 547 * 548 * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>` 549 * 550 * @since Beta 2 551 * @return \SimplePie\Author[]|null List of {@see \SimplePie\Author} objects 552 */ 553 public function get_authors() 554 { 555 $authors = []; 556 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'author') as $author) { 557 $name = null; 558 $uri = null; 559 $email = null; 560 if (isset($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['name'][0]['data'])) { 561 $name = $this->sanitize($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['name'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 562 } 563 if (isset($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]['data'])) { 564 $uri = $this->sanitize($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0])); 565 } 566 if (isset($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) { 567 $email = $this->sanitize($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 568 } 569 if ($name !== null || $email !== null || $uri !== null) { 570 $authors[] = $this->registry->create(Author::class, [$name, $uri, $email]); 571 } 572 } 573 if ($author = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'author')) { 574 $name = null; 575 $url = null; 576 $email = null; 577 if (isset($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['name'][0]['data'])) { 578 $name = $this->sanitize($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['name'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 579 } 580 if (isset($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0]['data'])) { 581 $url = $this->sanitize($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0])); 582 } 583 if (isset($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'])) { 584 $email = $this->sanitize($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 585 } 586 if ($name !== null || $email !== null || $url !== null) { 587 $authors[] = $this->registry->create(Author::class, [$name, $url, $email]); 588 } 589 } 590 if ($author = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'author')) { 591 $authors[] = $this->registry->create(Author::class, [null, null, $this->sanitize($author[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)]); 592 } 593 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'creator') as $author) { 594 $authors[] = $this->registry->create(Author::class, [$this->sanitize($author['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null]); 595 } 596 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'creator') as $author) { 597 $authors[] = $this->registry->create(Author::class, [$this->sanitize($author['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null]); 598 } 599 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'author') as $author) { 600 $authors[] = $this->registry->create(Author::class, [$this->sanitize($author['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT), null, null]); 601 } 602 603 if (!empty($authors)) { 604 return array_unique($authors); 605 } elseif (($source = $this->get_source()) && ($authors = $source->get_authors())) { 606 return $authors; 607 } elseif ($authors = $this->feed->get_authors()) { 608 return $authors; 609 } 610 611 return null; 612 } 613 614 /** 615 * Get the copyright info for the item 616 * 617 * Uses `<atom:rights>` or `<dc:rights>` 618 * 619 * @since 1.1 620 * @return string 621 */ 622 public function get_copyright() 623 { 624 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'rights')) { 625 return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); 626 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'rights')) { 627 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 628 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'rights')) { 629 return $this->sanitize($return[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 630 } 631 632 return null; 633 } 634 635 /** 636 * Get the posting date/time for the item 637 * 638 * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`, 639 * `<atom:modified>`, `<pubDate>` or `<dc:date>` 640 * 641 * Note: obeys PHP's timezone setting. To get a UTC date/time, use 642 * {@see get_gmdate} 643 * 644 * @since Beta 2 (previously called `get_item_date` since 0.8) 645 * 646 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data) 647 * @return int|string|null 648 */ 649 public function get_date($date_format = 'j F Y, g:i a') 650 { 651 if (!isset($this->data['date'])) { 652 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'published')) { 653 $this->data['date']['raw'] = $return[0]['data']; 654 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'pubDate')) { 655 $this->data['date']['raw'] = $return[0]['data']; 656 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_11, 'date')) { 657 $this->data['date']['raw'] = $return[0]['data']; 658 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_DC_10, 'date')) { 659 $this->data['date']['raw'] = $return[0]['data']; 660 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'updated')) { 661 $this->data['date']['raw'] = $return[0]['data']; 662 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'issued')) { 663 $this->data['date']['raw'] = $return[0]['data']; 664 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'created')) { 665 $this->data['date']['raw'] = $return[0]['data']; 666 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'modified')) { 667 $this->data['date']['raw'] = $return[0]['data']; 668 } 669 670 if (!empty($this->data['date']['raw'])) { 671 $parser = $this->registry->call(Parse\Date::class, 'get'); 672 $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']) ?: null; 673 } else { 674 $this->data['date'] = null; 675 } 676 } 677 if ($this->data['date']) { 678 $date_format = (string) $date_format; 679 switch ($date_format) { 680 case '': 681 return $this->sanitize($this->data['date']['raw'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 682 683 case 'U': 684 return $this->data['date']['parsed']; 685 686 default: 687 return date($date_format, $this->data['date']['parsed']); 688 } 689 } 690 691 return null; 692 } 693 694 /** 695 * Get the update date/time for the item 696 * 697 * Uses `<atom:updated>` 698 * 699 * Note: obeys PHP's timezone setting. To get a UTC date/time, use 700 * {@see get_gmdate} 701 * 702 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data) 703 * @return int|string|null 704 */ 705 public function get_updated_date($date_format = 'j F Y, g:i a') 706 { 707 if (!isset($this->data['updated'])) { 708 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'updated')) { 709 $this->data['updated']['raw'] = $return[0]['data']; 710 } 711 712 if (!empty($this->data['updated']['raw'])) { 713 $parser = $this->registry->call(Parse\Date::class, 'get'); 714 $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']) ?: null; 715 } else { 716 $this->data['updated'] = null; 717 } 718 } 719 if ($this->data['updated']) { 720 $date_format = (string) $date_format; 721 switch ($date_format) { 722 case '': 723 return $this->sanitize($this->data['updated']['raw'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 724 725 case 'U': 726 return $this->data['updated']['parsed']; 727 728 default: 729 return date($date_format, $this->data['updated']['parsed']); 730 } 731 } 732 733 return null; 734 } 735 736 /** 737 * Get the localized posting date/time for the item 738 * 739 * Returns the date formatted in the localized language. To display in 740 * languages other than the server's default, you need to change the locale 741 * with {@link http://php.net/setlocale setlocale()}. The available 742 * localizations depend on which ones are installed on your web server. 743 * 744 * @since 1.0 745 * 746 * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data) 747 * @return int|string|null 748 */ 749 public function get_local_date($date_format = '%c') 750 { 751 if (!$date_format) { 752 return $this->sanitize($this->get_date(''), \SimplePie\SimplePie::CONSTRUCT_TEXT); 753 } elseif (($date = $this->get_date('U')) !== null && $date !== false) { 754 return strftime($date_format, $date); 755 } 756 757 return null; 758 } 759 760 /** 761 * Get the posting date/time for the item (UTC time) 762 * 763 * @see get_date 764 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} 765 * @return int|string|null 766 */ 767 public function get_gmdate($date_format = 'j F Y, g:i a') 768 { 769 $date = $this->get_date('U'); 770 if ($date === null) { 771 return null; 772 } 773 774 return gmdate($date_format, $date); 775 } 776 777 /** 778 * Get the update date/time for the item (UTC time) 779 * 780 * @see get_updated_date 781 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} 782 * @return int|string|null 783 */ 784 public function get_updated_gmdate($date_format = 'j F Y, g:i a') 785 { 786 $date = $this->get_updated_date('U'); 787 if ($date === null) { 788 return null; 789 } 790 791 return gmdate($date_format, $date); 792 } 793 794 /** 795 * Get the permalink for the item 796 * 797 * Returns the first link available with a relationship of "alternate". 798 * Identical to {@see get_link()} with key 0 799 * 800 * @see get_link 801 * @since 0.8 802 * @return string|null Permalink URL 803 */ 804 public function get_permalink() 805 { 806 $link = $this->get_link(); 807 $enclosure = $this->get_enclosure(0); 808 if ($link !== null) { 809 return $link; 810 } elseif ($enclosure !== null) { 811 return $enclosure->get_link(); 812 } 813 814 return null; 815 } 816 817 /** 818 * Get a single link for the item 819 * 820 * @since Beta 3 821 * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1 822 * @param string $rel The relationship of the link to return 823 * @return string|null Link URL 824 */ 825 public function get_link($key = 0, $rel = 'alternate') 826 { 827 $links = $this->get_links($rel); 828 if ($links && $links[$key] !== null) { 829 return $links[$key]; 830 } 831 832 return null; 833 } 834 835 /** 836 * Get all links for the item 837 * 838 * Uses `<atom:link>`, `<link>` or `<guid>` 839 * 840 * @since Beta 2 841 * @param string $rel The relationship of links to return 842 * @return array|null Links found for the item (strings) 843 */ 844 public function get_links($rel = 'alternate') 845 { 846 if (!isset($this->data['links'])) { 847 $this->data['links'] = []; 848 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'link') as $link) { 849 if (isset($link['attribs']['']['href'])) { 850 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 851 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($link)); 852 } 853 } 854 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'link') as $link) { 855 if (isset($link['attribs']['']['href'])) { 856 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 857 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($link)); 858 } 859 } 860 if ($links = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_10, 'link')) { 861 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($links[0])); 862 } 863 if ($links = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_090, 'link')) { 864 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($links[0])); 865 } 866 if ($links = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'link')) { 867 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($links[0])); 868 } 869 if ($links = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'guid')) { 870 if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true') { 871 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($links[0])); 872 } 873 } 874 875 $keys = array_keys($this->data['links']); 876 foreach ($keys as $key) { 877 if ($this->registry->call(Misc::class, 'is_isegment_nz_nc', [$key])) { 878 if (isset($this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key])) { 879 $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key]); 880 $this->data['links'][$key] = &$this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key]; 881 } else { 882 $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = &$this->data['links'][$key]; 883 } 884 } elseif (substr($key, 0, 41) === \SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY) { 885 $this->data['links'][substr($key, 41)] = &$this->data['links'][$key]; 886 } 887 $this->data['links'][$key] = array_unique($this->data['links'][$key]); 888 } 889 } 890 if (isset($this->data['links'][$rel])) { 891 return $this->data['links'][$rel]; 892 } 893 894 return null; 895 } 896 897 /** 898 * Get an enclosure from the item 899 * 900 * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS. 901 * 902 * @since Beta 2 903 * @todo Add ability to prefer one type of content over another (in a media group). 904 * @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1 905 * @return \SimplePie\Enclosure|null 906 */ 907 public function get_enclosure($key = 0, $prefer = null) 908 { 909 $enclosures = $this->get_enclosures(); 910 if (isset($enclosures[$key])) { 911 return $enclosures[$key]; 912 } 913 914 return null; 915 } 916 917 /** 918 * Get all available enclosures (podcasts, etc.) 919 * 920 * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS. 921 * 922 * At this point, we're pretty much assuming that all enclosures for an item 923 * are the same content. Anything else is too complicated to 924 * properly support. 925 * 926 * @since Beta 2 927 * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4). 928 * @todo If an element exists at a level, but its value is empty, we should fall back to the value from the parent (if it exists). 929 * @return \SimplePie\Enclosure[]|null List of \SimplePie\Enclosure items 930 */ 931 public function get_enclosures() 932 { 933 if (!isset($this->data['enclosures'])) { 934 $this->data['enclosures'] = []; 935 936 // Elements 937 $captions_parent = null; 938 $categories_parent = null; 939 $copyrights_parent = null; 940 $credits_parent = null; 941 $description_parent = null; 942 $duration_parent = null; 943 $hashes_parent = null; 944 $keywords_parent = null; 945 $player_parent = null; 946 $ratings_parent = null; 947 $restrictions_parent = null; 948 $thumbnails_parent = null; 949 $title_parent = null; 950 951 // Let's do the channel and item-level ones first, and just re-use them if we need to. 952 $parent = $this->get_feed(); 953 954 // CAPTIONS 955 if ($captions = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'text')) { 956 foreach ($captions as $caption) { 957 $caption_type = null; 958 $caption_lang = null; 959 $caption_startTime = null; 960 $caption_endTime = null; 961 $caption_text = null; 962 if (isset($caption['attribs']['']['type'])) { 963 $caption_type = $this->sanitize($caption['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 964 } 965 if (isset($caption['attribs']['']['lang'])) { 966 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 967 } 968 if (isset($caption['attribs']['']['start'])) { 969 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 970 } 971 if (isset($caption['attribs']['']['end'])) { 972 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 973 } 974 if (isset($caption['data'])) { 975 $caption_text = $this->sanitize($caption['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 976 } 977 $captions_parent[] = $this->registry->create(Caption::class, [$caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text]); 978 } 979 } elseif ($captions = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'text')) { 980 foreach ($captions as $caption) { 981 $caption_type = null; 982 $caption_lang = null; 983 $caption_startTime = null; 984 $caption_endTime = null; 985 $caption_text = null; 986 if (isset($caption['attribs']['']['type'])) { 987 $caption_type = $this->sanitize($caption['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 988 } 989 if (isset($caption['attribs']['']['lang'])) { 990 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 991 } 992 if (isset($caption['attribs']['']['start'])) { 993 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 994 } 995 if (isset($caption['attribs']['']['end'])) { 996 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 997 } 998 if (isset($caption['data'])) { 999 $caption_text = $this->sanitize($caption['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1000 } 1001 $captions_parent[] = $this->registry->create(Caption::class, [$caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text]); 1002 } 1003 } 1004 if (is_array($captions_parent)) { 1005 $captions_parent = array_values(array_unique($captions_parent)); 1006 } 1007 1008 // CATEGORIES 1009 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'category') as $category) { 1010 $term = null; 1011 $scheme = null; 1012 $label = null; 1013 if (isset($category['data'])) { 1014 $term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1015 } 1016 if (isset($category['attribs']['']['scheme'])) { 1017 $scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1018 } else { 1019 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 1020 } 1021 if (isset($category['attribs']['']['label'])) { 1022 $label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1023 } 1024 $categories_parent[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 1025 } 1026 foreach ((array) $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'category') as $category) { 1027 $term = null; 1028 $scheme = null; 1029 $label = null; 1030 if (isset($category['data'])) { 1031 $term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1032 } 1033 if (isset($category['attribs']['']['scheme'])) { 1034 $scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1035 } else { 1036 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 1037 } 1038 if (isset($category['attribs']['']['label'])) { 1039 $label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1040 } 1041 $categories_parent[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 1042 } 1043 foreach ((array) $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'category') as $category) { 1044 $term = null; 1045 $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; 1046 $label = null; 1047 if (isset($category['attribs']['']['text'])) { 1048 $label = $this->sanitize($category['attribs']['']['text'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1049 } 1050 $categories_parent[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 1051 1052 if (isset($category['child'][\SimplePie\SimplePie::NAMESPACE_ITUNES]['category'])) { 1053 foreach ((array) $category['child'][\SimplePie\SimplePie::NAMESPACE_ITUNES]['category'] as $subcategory) { 1054 if (isset($subcategory['attribs']['']['text'])) { 1055 $label = $this->sanitize($subcategory['attribs']['']['text'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1056 } 1057 $categories_parent[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 1058 } 1059 } 1060 } 1061 if (is_array($categories_parent)) { 1062 $categories_parent = array_values(array_unique($categories_parent)); 1063 } 1064 1065 // COPYRIGHT 1066 if ($copyright = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'copyright')) { 1067 $copyright_url = null; 1068 $copyright_label = null; 1069 if (isset($copyright[0]['attribs']['']['url'])) { 1070 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1071 } 1072 if (isset($copyright[0]['data'])) { 1073 $copyright_label = $this->sanitize($copyright[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1074 } 1075 $copyrights_parent = $this->registry->create(Copyright::class, [$copyright_url, $copyright_label]); 1076 } elseif ($copyright = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'copyright')) { 1077 $copyright_url = null; 1078 $copyright_label = null; 1079 if (isset($copyright[0]['attribs']['']['url'])) { 1080 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1081 } 1082 if (isset($copyright[0]['data'])) { 1083 $copyright_label = $this->sanitize($copyright[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1084 } 1085 $copyrights_parent = $this->registry->create(Copyright::class, [$copyright_url, $copyright_label]); 1086 } 1087 1088 // CREDITS 1089 if ($credits = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'credit')) { 1090 foreach ($credits as $credit) { 1091 $credit_role = null; 1092 $credit_scheme = null; 1093 $credit_name = null; 1094 if (isset($credit['attribs']['']['role'])) { 1095 $credit_role = $this->sanitize($credit['attribs']['']['role'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1096 } 1097 if (isset($credit['attribs']['']['scheme'])) { 1098 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1099 } else { 1100 $credit_scheme = 'urn:ebu'; 1101 } 1102 if (isset($credit['data'])) { 1103 $credit_name = $this->sanitize($credit['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1104 } 1105 $credits_parent[] = $this->registry->create(Credit::class, [$credit_role, $credit_scheme, $credit_name]); 1106 } 1107 } elseif ($credits = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'credit')) { 1108 foreach ($credits as $credit) { 1109 $credit_role = null; 1110 $credit_scheme = null; 1111 $credit_name = null; 1112 if (isset($credit['attribs']['']['role'])) { 1113 $credit_role = $this->sanitize($credit['attribs']['']['role'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1114 } 1115 if (isset($credit['attribs']['']['scheme'])) { 1116 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1117 } else { 1118 $credit_scheme = 'urn:ebu'; 1119 } 1120 if (isset($credit['data'])) { 1121 $credit_name = $this->sanitize($credit['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1122 } 1123 $credits_parent[] = $this->registry->create(Credit::class, [$credit_role, $credit_scheme, $credit_name]); 1124 } 1125 } 1126 if (is_array($credits_parent)) { 1127 $credits_parent = array_values(array_unique($credits_parent)); 1128 } 1129 1130 // DESCRIPTION 1131 if ($description_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'description')) { 1132 if (isset($description_parent[0]['data'])) { 1133 $description_parent = $this->sanitize($description_parent[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1134 } 1135 } elseif ($description_parent = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'description')) { 1136 if (isset($description_parent[0]['data'])) { 1137 $description_parent = $this->sanitize($description_parent[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1138 } 1139 } 1140 1141 // DURATION 1142 if ($duration_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'duration')) { 1143 $seconds = null; 1144 $minutes = null; 1145 $hours = null; 1146 if (isset($duration_parent[0]['data'])) { 1147 $temp = explode(':', $this->sanitize($duration_parent[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1148 if (sizeof($temp) > 0) { 1149 $seconds = (int) array_pop($temp); 1150 } 1151 if (sizeof($temp) > 0) { 1152 $minutes = (int) array_pop($temp); 1153 $seconds += $minutes * 60; 1154 } 1155 if (sizeof($temp) > 0) { 1156 $hours = (int) array_pop($temp); 1157 $seconds += $hours * 3600; 1158 } 1159 unset($temp); 1160 $duration_parent = $seconds; 1161 } 1162 } 1163 1164 // HASHES 1165 if ($hashes_iterator = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'hash')) { 1166 foreach ($hashes_iterator as $hash) { 1167 $value = null; 1168 $algo = null; 1169 if (isset($hash['data'])) { 1170 $value = $this->sanitize($hash['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1171 } 1172 if (isset($hash['attribs']['']['algo'])) { 1173 $algo = $this->sanitize($hash['attribs']['']['algo'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1174 } else { 1175 $algo = 'md5'; 1176 } 1177 $hashes_parent[] = $algo.':'.$value; 1178 } 1179 } elseif ($hashes_iterator = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'hash')) { 1180 foreach ($hashes_iterator as $hash) { 1181 $value = null; 1182 $algo = null; 1183 if (isset($hash['data'])) { 1184 $value = $this->sanitize($hash['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1185 } 1186 if (isset($hash['attribs']['']['algo'])) { 1187 $algo = $this->sanitize($hash['attribs']['']['algo'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1188 } else { 1189 $algo = 'md5'; 1190 } 1191 $hashes_parent[] = $algo.':'.$value; 1192 } 1193 } 1194 if (is_array($hashes_parent)) { 1195 $hashes_parent = array_values(array_unique($hashes_parent)); 1196 } 1197 1198 // KEYWORDS 1199 if ($keywords = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'keywords')) { 1200 if (isset($keywords[0]['data'])) { 1201 $temp = explode(',', $this->sanitize($keywords[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1202 foreach ($temp as $word) { 1203 $keywords_parent[] = trim($word); 1204 } 1205 } 1206 unset($temp); 1207 } elseif ($keywords = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'keywords')) { 1208 if (isset($keywords[0]['data'])) { 1209 $temp = explode(',', $this->sanitize($keywords[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1210 foreach ($temp as $word) { 1211 $keywords_parent[] = trim($word); 1212 } 1213 } 1214 unset($temp); 1215 } elseif ($keywords = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'keywords')) { 1216 if (isset($keywords[0]['data'])) { 1217 $temp = explode(',', $this->sanitize($keywords[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1218 foreach ($temp as $word) { 1219 $keywords_parent[] = trim($word); 1220 } 1221 } 1222 unset($temp); 1223 } elseif ($keywords = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'keywords')) { 1224 if (isset($keywords[0]['data'])) { 1225 $temp = explode(',', $this->sanitize($keywords[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1226 foreach ($temp as $word) { 1227 $keywords_parent[] = trim($word); 1228 } 1229 } 1230 unset($temp); 1231 } 1232 if (is_array($keywords_parent)) { 1233 $keywords_parent = array_values(array_unique($keywords_parent)); 1234 } 1235 1236 // PLAYER 1237 if ($player_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'player')) { 1238 if (isset($player_parent[0]['attribs']['']['url'])) { 1239 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1240 } 1241 } elseif ($player_parent = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'player')) { 1242 if (isset($player_parent[0]['attribs']['']['url'])) { 1243 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1244 } 1245 } 1246 1247 // RATINGS 1248 if ($ratings = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'rating')) { 1249 foreach ($ratings as $rating) { 1250 $rating_scheme = null; 1251 $rating_value = null; 1252 if (isset($rating['attribs']['']['scheme'])) { 1253 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1254 } else { 1255 $rating_scheme = 'urn:simple'; 1256 } 1257 if (isset($rating['data'])) { 1258 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1259 } 1260 $ratings_parent[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 1261 } 1262 } elseif ($ratings = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'explicit')) { 1263 foreach ($ratings as $rating) { 1264 $rating_scheme = 'urn:itunes'; 1265 $rating_value = null; 1266 if (isset($rating['data'])) { 1267 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1268 } 1269 $ratings_parent[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 1270 } 1271 } elseif ($ratings = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'rating')) { 1272 foreach ($ratings as $rating) { 1273 $rating_scheme = null; 1274 $rating_value = null; 1275 if (isset($rating['attribs']['']['scheme'])) { 1276 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1277 } else { 1278 $rating_scheme = 'urn:simple'; 1279 } 1280 if (isset($rating['data'])) { 1281 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1282 } 1283 $ratings_parent[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 1284 } 1285 } elseif ($ratings = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'explicit')) { 1286 foreach ($ratings as $rating) { 1287 $rating_scheme = 'urn:itunes'; 1288 $rating_value = null; 1289 if (isset($rating['data'])) { 1290 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1291 } 1292 $ratings_parent[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 1293 } 1294 } 1295 if (is_array($ratings_parent)) { 1296 $ratings_parent = array_values(array_unique($ratings_parent)); 1297 } 1298 1299 // RESTRICTIONS 1300 if ($restrictions = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'restriction')) { 1301 foreach ($restrictions as $restriction) { 1302 $restriction_relationship = null; 1303 $restriction_type = null; 1304 $restriction_value = null; 1305 if (isset($restriction['attribs']['']['relationship'])) { 1306 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1307 } 1308 if (isset($restriction['attribs']['']['type'])) { 1309 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1310 } 1311 if (isset($restriction['data'])) { 1312 $restriction_value = $this->sanitize($restriction['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1313 } 1314 $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1315 } 1316 } elseif ($restrictions = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'block')) { 1317 foreach ($restrictions as $restriction) { 1318 $restriction_relationship = 'allow'; 1319 $restriction_type = null; 1320 $restriction_value = 'itunes'; 1321 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') { 1322 $restriction_relationship = 'deny'; 1323 } 1324 $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1325 } 1326 } elseif ($restrictions = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'restriction')) { 1327 foreach ($restrictions as $restriction) { 1328 $restriction_relationship = null; 1329 $restriction_type = null; 1330 $restriction_value = null; 1331 if (isset($restriction['attribs']['']['relationship'])) { 1332 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1333 } 1334 if (isset($restriction['attribs']['']['type'])) { 1335 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1336 } 1337 if (isset($restriction['data'])) { 1338 $restriction_value = $this->sanitize($restriction['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1339 } 1340 $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1341 } 1342 } elseif ($restrictions = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'block')) { 1343 foreach ($restrictions as $restriction) { 1344 $restriction_relationship = 'allow'; 1345 $restriction_type = null; 1346 $restriction_value = 'itunes'; 1347 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') { 1348 $restriction_relationship = 'deny'; 1349 } 1350 $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1351 } 1352 } 1353 if (is_array($restrictions_parent)) { 1354 $restrictions_parent = array_values(array_unique($restrictions_parent)); 1355 } else { 1356 $restrictions_parent = [new \SimplePie\Restriction('allow', null, 'default')]; 1357 } 1358 1359 // THUMBNAILS 1360 if ($thumbnails = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'thumbnail')) { 1361 foreach ($thumbnails as $thumbnail) { 1362 if (isset($thumbnail['attribs']['']['url'])) { 1363 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1364 } 1365 } 1366 } elseif ($thumbnails = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'thumbnail')) { 1367 foreach ($thumbnails as $thumbnail) { 1368 if (isset($thumbnail['attribs']['']['url'])) { 1369 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1370 } 1371 } 1372 } 1373 1374 // TITLES 1375 if ($title_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'title')) { 1376 if (isset($title_parent[0]['data'])) { 1377 $title_parent = $this->sanitize($title_parent[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1378 } 1379 } elseif ($title_parent = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'title')) { 1380 if (isset($title_parent[0]['data'])) { 1381 $title_parent = $this->sanitize($title_parent[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1382 } 1383 } 1384 1385 // Clear the memory 1386 unset($parent); 1387 1388 // Attributes 1389 $bitrate = null; 1390 $channels = null; 1391 $duration = null; 1392 $expression = null; 1393 $framerate = null; 1394 $height = null; 1395 $javascript = null; 1396 $lang = null; 1397 $length = null; 1398 $medium = null; 1399 $samplingrate = null; 1400 $type = null; 1401 $url = null; 1402 $width = null; 1403 1404 // Elements 1405 $captions = null; 1406 $categories = null; 1407 $copyrights = null; 1408 $credits = null; 1409 $description = null; 1410 $hashes = null; 1411 $keywords = null; 1412 $player = null; 1413 $ratings = null; 1414 $restrictions = null; 1415 $thumbnails = null; 1416 $title = null; 1417 1418 // If we have media:group tags, loop through them. 1419 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'group') as $group) { 1420 if (isset($group['child']) && isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['content'])) { 1421 // If we have media:content tags, loop through them. 1422 foreach ((array) $group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['content'] as $content) { 1423 if (isset($content['attribs']['']['url'])) { 1424 // Attributes 1425 $bitrate = null; 1426 $channels = null; 1427 $duration = null; 1428 $expression = null; 1429 $framerate = null; 1430 $height = null; 1431 $javascript = null; 1432 $lang = null; 1433 $length = null; 1434 $medium = null; 1435 $samplingrate = null; 1436 $type = null; 1437 $url = null; 1438 $width = null; 1439 1440 // Elements 1441 $captions = null; 1442 $categories = null; 1443 $copyrights = null; 1444 $credits = null; 1445 $description = null; 1446 $hashes = null; 1447 $keywords = null; 1448 $player = null; 1449 $ratings = null; 1450 $restrictions = null; 1451 $thumbnails = null; 1452 $title = null; 1453 1454 // Start checking the attributes of media:content 1455 if (isset($content['attribs']['']['bitrate'])) { 1456 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1457 } 1458 if (isset($content['attribs']['']['channels'])) { 1459 $channels = $this->sanitize($content['attribs']['']['channels'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1460 } 1461 if (isset($content['attribs']['']['duration'])) { 1462 $duration = $this->sanitize($content['attribs']['']['duration'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1463 } else { 1464 $duration = $duration_parent; 1465 } 1466 if (isset($content['attribs']['']['expression'])) { 1467 $expression = $this->sanitize($content['attribs']['']['expression'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1468 } 1469 if (isset($content['attribs']['']['framerate'])) { 1470 $framerate = $this->sanitize($content['attribs']['']['framerate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1471 } 1472 if (isset($content['attribs']['']['height'])) { 1473 $height = $this->sanitize($content['attribs']['']['height'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1474 } 1475 if (isset($content['attribs']['']['lang'])) { 1476 $lang = $this->sanitize($content['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1477 } 1478 if (isset($content['attribs']['']['fileSize'])) { 1479 $length = intval($content['attribs']['']['fileSize']); 1480 } 1481 if (isset($content['attribs']['']['medium'])) { 1482 $medium = $this->sanitize($content['attribs']['']['medium'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1483 } 1484 if (isset($content['attribs']['']['samplingrate'])) { 1485 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1486 } 1487 if (isset($content['attribs']['']['type'])) { 1488 $type = $this->sanitize($content['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1489 } 1490 if (isset($content['attribs']['']['width'])) { 1491 $width = $this->sanitize($content['attribs']['']['width'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1492 } 1493 $url = $this->sanitize($content['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1494 1495 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel 1496 1497 // CAPTIONS 1498 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['text'])) { 1499 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['text'] as $caption) { 1500 $caption_type = null; 1501 $caption_lang = null; 1502 $caption_startTime = null; 1503 $caption_endTime = null; 1504 $caption_text = null; 1505 if (isset($caption['attribs']['']['type'])) { 1506 $caption_type = $this->sanitize($caption['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1507 } 1508 if (isset($caption['attribs']['']['lang'])) { 1509 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1510 } 1511 if (isset($caption['attribs']['']['start'])) { 1512 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1513 } 1514 if (isset($caption['attribs']['']['end'])) { 1515 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1516 } 1517 if (isset($caption['data'])) { 1518 $caption_text = $this->sanitize($caption['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1519 } 1520 $captions[] = $this->registry->create(Caption::class, [$caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text]); 1521 } 1522 if (is_array($captions)) { 1523 $captions = array_values(array_unique($captions)); 1524 } 1525 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['text'])) { 1526 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['text'] as $caption) { 1527 $caption_type = null; 1528 $caption_lang = null; 1529 $caption_startTime = null; 1530 $caption_endTime = null; 1531 $caption_text = null; 1532 if (isset($caption['attribs']['']['type'])) { 1533 $caption_type = $this->sanitize($caption['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1534 } 1535 if (isset($caption['attribs']['']['lang'])) { 1536 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1537 } 1538 if (isset($caption['attribs']['']['start'])) { 1539 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1540 } 1541 if (isset($caption['attribs']['']['end'])) { 1542 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1543 } 1544 if (isset($caption['data'])) { 1545 $caption_text = $this->sanitize($caption['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1546 } 1547 $captions[] = $this->registry->create(Caption::class, [$caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text]); 1548 } 1549 if (is_array($captions)) { 1550 $captions = array_values(array_unique($captions)); 1551 } 1552 } else { 1553 $captions = $captions_parent; 1554 } 1555 1556 // CATEGORIES 1557 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['category'])) { 1558 foreach ((array) $content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['category'] as $category) { 1559 $term = null; 1560 $scheme = null; 1561 $label = null; 1562 if (isset($category['data'])) { 1563 $term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1564 } 1565 if (isset($category['attribs']['']['scheme'])) { 1566 $scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1567 } else { 1568 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 1569 } 1570 if (isset($category['attribs']['']['label'])) { 1571 $label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1572 } 1573 $categories[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 1574 } 1575 } 1576 if (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['category'])) { 1577 foreach ((array) $group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['category'] as $category) { 1578 $term = null; 1579 $scheme = null; 1580 $label = null; 1581 if (isset($category['data'])) { 1582 $term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1583 } 1584 if (isset($category['attribs']['']['scheme'])) { 1585 $scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1586 } else { 1587 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 1588 } 1589 if (isset($category['attribs']['']['label'])) { 1590 $label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1591 } 1592 $categories[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 1593 } 1594 } 1595 if (is_array($categories) && is_array($categories_parent)) { 1596 $categories = array_values(array_unique(array_merge($categories, $categories_parent))); 1597 } elseif (is_array($categories)) { 1598 $categories = array_values(array_unique($categories)); 1599 } elseif (is_array($categories_parent)) { 1600 $categories = array_values(array_unique($categories_parent)); 1601 } 1602 1603 // COPYRIGHTS 1604 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'])) { 1605 $copyright_url = null; 1606 $copyright_label = null; 1607 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) { 1608 $copyright_url = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1609 } 1610 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['data'])) { 1611 $copyright_label = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1612 } 1613 $copyrights = $this->registry->create(Copyright::class, [$copyright_url, $copyright_label]); 1614 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'])) { 1615 $copyright_url = null; 1616 $copyright_label = null; 1617 if (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) { 1618 $copyright_url = $this->sanitize($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1619 } 1620 if (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['data'])) { 1621 $copyright_label = $this->sanitize($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1622 } 1623 $copyrights = $this->registry->create(Copyright::class, [$copyright_url, $copyright_label]); 1624 } else { 1625 $copyrights = $copyrights_parent; 1626 } 1627 1628 // CREDITS 1629 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['credit'])) { 1630 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['credit'] as $credit) { 1631 $credit_role = null; 1632 $credit_scheme = null; 1633 $credit_name = null; 1634 if (isset($credit['attribs']['']['role'])) { 1635 $credit_role = $this->sanitize($credit['attribs']['']['role'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1636 } 1637 if (isset($credit['attribs']['']['scheme'])) { 1638 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1639 } else { 1640 $credit_scheme = 'urn:ebu'; 1641 } 1642 if (isset($credit['data'])) { 1643 $credit_name = $this->sanitize($credit['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1644 } 1645 $credits[] = $this->registry->create(Credit::class, [$credit_role, $credit_scheme, $credit_name]); 1646 } 1647 if (is_array($credits)) { 1648 $credits = array_values(array_unique($credits)); 1649 } 1650 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['credit'])) { 1651 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['credit'] as $credit) { 1652 $credit_role = null; 1653 $credit_scheme = null; 1654 $credit_name = null; 1655 if (isset($credit['attribs']['']['role'])) { 1656 $credit_role = $this->sanitize($credit['attribs']['']['role'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1657 } 1658 if (isset($credit['attribs']['']['scheme'])) { 1659 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1660 } else { 1661 $credit_scheme = 'urn:ebu'; 1662 } 1663 if (isset($credit['data'])) { 1664 $credit_name = $this->sanitize($credit['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1665 } 1666 $credits[] = $this->registry->create(Credit::class, [$credit_role, $credit_scheme, $credit_name]); 1667 } 1668 if (is_array($credits)) { 1669 $credits = array_values(array_unique($credits)); 1670 } 1671 } else { 1672 $credits = $credits_parent; 1673 } 1674 1675 // DESCRIPTION 1676 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['description'])) { 1677 $description = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['description'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1678 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['description'])) { 1679 $description = $this->sanitize($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['description'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1680 } else { 1681 $description = $description_parent; 1682 } 1683 1684 // HASHES 1685 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['hash'])) { 1686 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['hash'] as $hash) { 1687 $value = null; 1688 $algo = null; 1689 if (isset($hash['data'])) { 1690 $value = $this->sanitize($hash['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1691 } 1692 if (isset($hash['attribs']['']['algo'])) { 1693 $algo = $this->sanitize($hash['attribs']['']['algo'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1694 } else { 1695 $algo = 'md5'; 1696 } 1697 $hashes[] = $algo.':'.$value; 1698 } 1699 if (is_array($hashes)) { 1700 $hashes = array_values(array_unique($hashes)); 1701 } 1702 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['hash'])) { 1703 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['hash'] as $hash) { 1704 $value = null; 1705 $algo = null; 1706 if (isset($hash['data'])) { 1707 $value = $this->sanitize($hash['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1708 } 1709 if (isset($hash['attribs']['']['algo'])) { 1710 $algo = $this->sanitize($hash['attribs']['']['algo'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1711 } else { 1712 $algo = 'md5'; 1713 } 1714 $hashes[] = $algo.':'.$value; 1715 } 1716 if (is_array($hashes)) { 1717 $hashes = array_values(array_unique($hashes)); 1718 } 1719 } else { 1720 $hashes = $hashes_parent; 1721 } 1722 1723 // KEYWORDS 1724 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'])) { 1725 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'][0]['data'])) { 1726 $temp = explode(',', $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1727 foreach ($temp as $word) { 1728 $keywords[] = trim($word); 1729 } 1730 unset($temp); 1731 } 1732 if (is_array($keywords)) { 1733 $keywords = array_values(array_unique($keywords)); 1734 } 1735 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'])) { 1736 if (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'][0]['data'])) { 1737 $temp = explode(',', $this->sanitize($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1738 foreach ($temp as $word) { 1739 $keywords[] = trim($word); 1740 } 1741 unset($temp); 1742 } 1743 if (is_array($keywords)) { 1744 $keywords = array_values(array_unique($keywords)); 1745 } 1746 } else { 1747 $keywords = $keywords_parent; 1748 } 1749 1750 // PLAYER 1751 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'])) { 1752 $player = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1753 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'])) { 1754 $player = $this->sanitize($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1755 } else { 1756 $player = $player_parent; 1757 } 1758 1759 // RATINGS 1760 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['rating'])) { 1761 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['rating'] as $rating) { 1762 $rating_scheme = null; 1763 $rating_value = null; 1764 if (isset($rating['attribs']['']['scheme'])) { 1765 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1766 } else { 1767 $rating_scheme = 'urn:simple'; 1768 } 1769 if (isset($rating['data'])) { 1770 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1771 } 1772 $ratings[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 1773 } 1774 if (is_array($ratings)) { 1775 $ratings = array_values(array_unique($ratings)); 1776 } 1777 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['rating'])) { 1778 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['rating'] as $rating) { 1779 $rating_scheme = null; 1780 $rating_value = null; 1781 if (isset($rating['attribs']['']['scheme'])) { 1782 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1783 } else { 1784 $rating_scheme = 'urn:simple'; 1785 } 1786 if (isset($rating['data'])) { 1787 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1788 } 1789 $ratings[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 1790 } 1791 if (is_array($ratings)) { 1792 $ratings = array_values(array_unique($ratings)); 1793 } 1794 } else { 1795 $ratings = $ratings_parent; 1796 } 1797 1798 // RESTRICTIONS 1799 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['restriction'])) { 1800 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['restriction'] as $restriction) { 1801 $restriction_relationship = null; 1802 $restriction_type = null; 1803 $restriction_value = null; 1804 if (isset($restriction['attribs']['']['relationship'])) { 1805 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1806 } 1807 if (isset($restriction['attribs']['']['type'])) { 1808 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1809 } 1810 if (isset($restriction['data'])) { 1811 $restriction_value = $this->sanitize($restriction['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1812 } 1813 $restrictions[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1814 } 1815 if (is_array($restrictions)) { 1816 $restrictions = array_values(array_unique($restrictions)); 1817 } 1818 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['restriction'])) { 1819 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['restriction'] as $restriction) { 1820 $restriction_relationship = null; 1821 $restriction_type = null; 1822 $restriction_value = null; 1823 if (isset($restriction['attribs']['']['relationship'])) { 1824 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1825 } 1826 if (isset($restriction['attribs']['']['type'])) { 1827 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1828 } 1829 if (isset($restriction['data'])) { 1830 $restriction_value = $this->sanitize($restriction['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1831 } 1832 $restrictions[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1833 } 1834 if (is_array($restrictions)) { 1835 $restrictions = array_values(array_unique($restrictions)); 1836 } 1837 } else { 1838 $restrictions = $restrictions_parent; 1839 } 1840 1841 // THUMBNAILS 1842 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) { 1843 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) { 1844 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1845 } 1846 if (is_array($thumbnails)) { 1847 $thumbnails = array_values(array_unique($thumbnails)); 1848 } 1849 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) { 1850 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) { 1851 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1852 } 1853 if (is_array($thumbnails)) { 1854 $thumbnails = array_values(array_unique($thumbnails)); 1855 } 1856 } else { 1857 $thumbnails = $thumbnails_parent; 1858 } 1859 1860 // TITLES 1861 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['title'])) { 1862 $title = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['title'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1863 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['title'])) { 1864 $title = $this->sanitize($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['title'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1865 } else { 1866 $title = $title_parent; 1867 } 1868 1869 $this->data['enclosures'][] = $this->registry->create(Enclosure::class, [$url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width]); 1870 } 1871 } 1872 } 1873 } 1874 1875 // If we have standalone media:content tags, loop through them. 1876 if (isset($this->data['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['content'])) { 1877 foreach ((array) $this->data['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['content'] as $content) { 1878 if (isset($content['attribs']['']['url']) || isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'])) { 1879 // Attributes 1880 $bitrate = null; 1881 $channels = null; 1882 $duration = null; 1883 $expression = null; 1884 $framerate = null; 1885 $height = null; 1886 $javascript = null; 1887 $lang = null; 1888 $length = null; 1889 $medium = null; 1890 $samplingrate = null; 1891 $type = null; 1892 $url = null; 1893 $width = null; 1894 1895 // Elements 1896 $captions = null; 1897 $categories = null; 1898 $copyrights = null; 1899 $credits = null; 1900 $description = null; 1901 $hashes = null; 1902 $keywords = null; 1903 $player = null; 1904 $ratings = null; 1905 $restrictions = null; 1906 $thumbnails = null; 1907 $title = null; 1908 1909 // Start checking the attributes of media:content 1910 if (isset($content['attribs']['']['bitrate'])) { 1911 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1912 } 1913 if (isset($content['attribs']['']['channels'])) { 1914 $channels = $this->sanitize($content['attribs']['']['channels'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1915 } 1916 if (isset($content['attribs']['']['duration'])) { 1917 $duration = $this->sanitize($content['attribs']['']['duration'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1918 } else { 1919 $duration = $duration_parent; 1920 } 1921 if (isset($content['attribs']['']['expression'])) { 1922 $expression = $this->sanitize($content['attribs']['']['expression'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1923 } 1924 if (isset($content['attribs']['']['framerate'])) { 1925 $framerate = $this->sanitize($content['attribs']['']['framerate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1926 } 1927 if (isset($content['attribs']['']['height'])) { 1928 $height = $this->sanitize($content['attribs']['']['height'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1929 } 1930 if (isset($content['attribs']['']['lang'])) { 1931 $lang = $this->sanitize($content['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1932 } 1933 if (isset($content['attribs']['']['fileSize'])) { 1934 $length = intval($content['attribs']['']['fileSize']); 1935 } 1936 if (isset($content['attribs']['']['medium'])) { 1937 $medium = $this->sanitize($content['attribs']['']['medium'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1938 } 1939 if (isset($content['attribs']['']['samplingrate'])) { 1940 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1941 } 1942 if (isset($content['attribs']['']['type'])) { 1943 $type = $this->sanitize($content['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1944 } 1945 if (isset($content['attribs']['']['width'])) { 1946 $width = $this->sanitize($content['attribs']['']['width'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1947 } 1948 if (isset($content['attribs']['']['url'])) { 1949 $url = $this->sanitize($content['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 1950 } 1951 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel 1952 1953 // CAPTIONS 1954 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['text'])) { 1955 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['text'] as $caption) { 1956 $caption_type = null; 1957 $caption_lang = null; 1958 $caption_startTime = null; 1959 $caption_endTime = null; 1960 $caption_text = null; 1961 if (isset($caption['attribs']['']['type'])) { 1962 $caption_type = $this->sanitize($caption['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1963 } 1964 if (isset($caption['attribs']['']['lang'])) { 1965 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1966 } 1967 if (isset($caption['attribs']['']['start'])) { 1968 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1969 } 1970 if (isset($caption['attribs']['']['end'])) { 1971 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1972 } 1973 if (isset($caption['data'])) { 1974 $caption_text = $this->sanitize($caption['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1975 } 1976 $captions[] = $this->registry->create(Caption::class, [$caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text]); 1977 } 1978 if (is_array($captions)) { 1979 $captions = array_values(array_unique($captions)); 1980 } 1981 } else { 1982 $captions = $captions_parent; 1983 } 1984 1985 // CATEGORIES 1986 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['category'])) { 1987 foreach ((array) $content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['category'] as $category) { 1988 $term = null; 1989 $scheme = null; 1990 $label = null; 1991 if (isset($category['data'])) { 1992 $term = $this->sanitize($category['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1993 } 1994 if (isset($category['attribs']['']['scheme'])) { 1995 $scheme = $this->sanitize($category['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1996 } else { 1997 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 1998 } 1999 if (isset($category['attribs']['']['label'])) { 2000 $label = $this->sanitize($category['attribs']['']['label'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2001 } 2002 $categories[] = $this->registry->create(Category::class, [$term, $scheme, $label]); 2003 } 2004 } 2005 if (is_array($categories) && is_array($categories_parent)) { 2006 $categories = array_values(array_unique(array_merge($categories, $categories_parent))); 2007 } elseif (is_array($categories)) { 2008 $categories = array_values(array_unique($categories)); 2009 } elseif (is_array($categories_parent)) { 2010 $categories = array_values(array_unique($categories_parent)); 2011 } else { 2012 $categories = null; 2013 } 2014 2015 // COPYRIGHTS 2016 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'])) { 2017 $copyright_url = null; 2018 $copyright_label = null; 2019 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'])) { 2020 $copyright_url = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2021 } 2022 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['data'])) { 2023 $copyright_label = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['copyright'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2024 } 2025 $copyrights = $this->registry->create(Copyright::class, [$copyright_url, $copyright_label]); 2026 } else { 2027 $copyrights = $copyrights_parent; 2028 } 2029 2030 // CREDITS 2031 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['credit'])) { 2032 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['credit'] as $credit) { 2033 $credit_role = null; 2034 $credit_scheme = null; 2035 $credit_name = null; 2036 if (isset($credit['attribs']['']['role'])) { 2037 $credit_role = $this->sanitize($credit['attribs']['']['role'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2038 } 2039 if (isset($credit['attribs']['']['scheme'])) { 2040 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2041 } else { 2042 $credit_scheme = 'urn:ebu'; 2043 } 2044 if (isset($credit['data'])) { 2045 $credit_name = $this->sanitize($credit['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2046 } 2047 $credits[] = $this->registry->create(Credit::class, [$credit_role, $credit_scheme, $credit_name]); 2048 } 2049 if (is_array($credits)) { 2050 $credits = array_values(array_unique($credits)); 2051 } 2052 } else { 2053 $credits = $credits_parent; 2054 } 2055 2056 // DESCRIPTION 2057 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['description'])) { 2058 $description = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['description'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2059 } else { 2060 $description = $description_parent; 2061 } 2062 2063 // HASHES 2064 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['hash'])) { 2065 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['hash'] as $hash) { 2066 $value = null; 2067 $algo = null; 2068 if (isset($hash['data'])) { 2069 $value = $this->sanitize($hash['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2070 } 2071 if (isset($hash['attribs']['']['algo'])) { 2072 $algo = $this->sanitize($hash['attribs']['']['algo'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2073 } else { 2074 $algo = 'md5'; 2075 } 2076 $hashes[] = $algo.':'.$value; 2077 } 2078 if (is_array($hashes)) { 2079 $hashes = array_values(array_unique($hashes)); 2080 } 2081 } else { 2082 $hashes = $hashes_parent; 2083 } 2084 2085 // KEYWORDS 2086 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'])) { 2087 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'][0]['data'])) { 2088 $temp = explode(',', $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['keywords'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 2089 foreach ($temp as $word) { 2090 $keywords[] = trim($word); 2091 } 2092 unset($temp); 2093 } 2094 if (is_array($keywords)) { 2095 $keywords = array_values(array_unique($keywords)); 2096 } 2097 } else { 2098 $keywords = $keywords_parent; 2099 } 2100 2101 // PLAYER 2102 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'])) { 2103 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'])) { 2104 $player = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 2105 } 2106 } else { 2107 $player = $player_parent; 2108 } 2109 2110 // RATINGS 2111 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['rating'])) { 2112 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['rating'] as $rating) { 2113 $rating_scheme = null; 2114 $rating_value = null; 2115 if (isset($rating['attribs']['']['scheme'])) { 2116 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2117 } else { 2118 $rating_scheme = 'urn:simple'; 2119 } 2120 if (isset($rating['data'])) { 2121 $rating_value = $this->sanitize($rating['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2122 } 2123 $ratings[] = $this->registry->create(Rating::class, [$rating_scheme, $rating_value]); 2124 } 2125 if (is_array($ratings)) { 2126 $ratings = array_values(array_unique($ratings)); 2127 } 2128 } else { 2129 $ratings = $ratings_parent; 2130 } 2131 2132 // RESTRICTIONS 2133 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['restriction'])) { 2134 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['restriction'] as $restriction) { 2135 $restriction_relationship = null; 2136 $restriction_type = null; 2137 $restriction_value = null; 2138 if (isset($restriction['attribs']['']['relationship'])) { 2139 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2140 } 2141 if (isset($restriction['attribs']['']['type'])) { 2142 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2143 } 2144 if (isset($restriction['data'])) { 2145 $restriction_value = $this->sanitize($restriction['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2146 } 2147 $restrictions[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 2148 } 2149 if (is_array($restrictions)) { 2150 $restrictions = array_values(array_unique($restrictions)); 2151 } 2152 } else { 2153 $restrictions = $restrictions_parent; 2154 } 2155 2156 // THUMBNAILS 2157 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) { 2158 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) { 2159 if (isset($thumbnail['attribs']['']['url'])) { 2160 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI); 2161 } 2162 } 2163 if (is_array($thumbnails)) { 2164 $thumbnails = array_values(array_unique($thumbnails)); 2165 } 2166 } else { 2167 $thumbnails = $thumbnails_parent; 2168 } 2169 2170 // TITLES 2171 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['title'])) { 2172 $title = $this->sanitize($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['title'][0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2173 } else { 2174 $title = $title_parent; 2175 } 2176 2177 $this->data['enclosures'][] = $this->registry->create(Enclosure::class, [$url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width]); 2178 } 2179 } 2180 } 2181 2182 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'link') as $link) { 2183 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure') { 2184 // Attributes 2185 $bitrate = null; 2186 $channels = null; 2187 $duration = null; 2188 $expression = null; 2189 $framerate = null; 2190 $height = null; 2191 $javascript = null; 2192 $lang = null; 2193 $length = null; 2194 $medium = null; 2195 $samplingrate = null; 2196 $type = null; 2197 $url = null; 2198 $width = null; 2199 2200 $url = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($link)); 2201 if (isset($link['attribs']['']['type'])) { 2202 $type = $this->sanitize($link['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2203 } 2204 if (isset($link['attribs']['']['length'])) { 2205 $length = intval($link['attribs']['']['length']); 2206 } 2207 if (isset($link['attribs']['']['title'])) { 2208 $title = $this->sanitize($link['attribs']['']['title'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2209 } else { 2210 $title = $title_parent; 2211 } 2212 2213 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 2214 $this->data['enclosures'][] = $this->registry->create(Enclosure::class, [$url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title, $width]); 2215 } 2216 } 2217 2218 foreach ((array) $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_03, 'link') as $link) { 2219 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure') { 2220 // Attributes 2221 $bitrate = null; 2222 $channels = null; 2223 $duration = null; 2224 $expression = null; 2225 $framerate = null; 2226 $height = null; 2227 $javascript = null; 2228 $lang = null; 2229 $length = null; 2230 $medium = null; 2231 $samplingrate = null; 2232 $type = null; 2233 $url = null; 2234 $width = null; 2235 2236 $url = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($link)); 2237 if (isset($link['attribs']['']['type'])) { 2238 $type = $this->sanitize($link['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2239 } 2240 if (isset($link['attribs']['']['length'])) { 2241 $length = intval($link['attribs']['']['length']); 2242 } 2243 2244 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 2245 $this->data['enclosures'][] = $this->registry->create(Enclosure::class, [$url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width]); 2246 } 2247 } 2248 2249 foreach ($this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'enclosure') ?? [] as $enclosure) { 2250 if (isset($enclosure['attribs']['']['url'])) { 2251 // Attributes 2252 $bitrate = null; 2253 $channels = null; 2254 $duration = null; 2255 $expression = null; 2256 $framerate = null; 2257 $height = null; 2258 $javascript = null; 2259 $lang = null; 2260 $length = null; 2261 $medium = null; 2262 $samplingrate = null; 2263 $type = null; 2264 $url = null; 2265 $width = null; 2266 2267 $url = $this->sanitize($enclosure['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($enclosure)); 2268 $url = $this->feed->sanitize->https_url($url); 2269 if (isset($enclosure['attribs']['']['type'])) { 2270 $type = $this->sanitize($enclosure['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 2271 } 2272 if (isset($enclosure['attribs']['']['length'])) { 2273 $length = intval($enclosure['attribs']['']['length']); 2274 } 2275 2276 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 2277 $this->data['enclosures'][] = $this->registry->create(Enclosure::class, [$url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width]); 2278 } 2279 } 2280 2281 if (sizeof($this->data['enclosures']) === 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width)) { 2282 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 2283 $this->data['enclosures'][] = $this->registry->create(Enclosure::class, [$url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width]); 2284 } 2285 2286 $this->data['enclosures'] = array_values(array_unique($this->data['enclosures'])); 2287 } 2288 if (!empty($this->data['enclosures'])) { 2289 return $this->data['enclosures']; 2290 } 2291 2292 return null; 2293 } 2294 2295 /** 2296 * Get the latitude coordinates for the item 2297 * 2298 * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications 2299 * 2300 * Uses `<geo:lat>` or `<georss:point>` 2301 * 2302 * @since 1.0 2303 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 2304 * @link http://www.georss.org/ GeoRSS 2305 * @return string|null 2306 */ 2307 public function get_latitude() 2308 { 2309 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_W3C_BASIC_GEO, 'lat')) { 2310 return (float) $return[0]['data']; 2311 } elseif (($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) { 2312 return (float) $match[1]; 2313 } 2314 2315 return null; 2316 } 2317 2318 /** 2319 * Get the longitude coordinates for the item 2320 * 2321 * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications 2322 * 2323 * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>` 2324 * 2325 * @since 1.0 2326 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 2327 * @link http://www.georss.org/ GeoRSS 2328 * @return string|null 2329 */ 2330 public function get_longitude() 2331 { 2332 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_W3C_BASIC_GEO, 'long')) { 2333 return (float) $return[0]['data']; 2334 } elseif ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_W3C_BASIC_GEO, 'lon')) { 2335 return (float) $return[0]['data']; 2336 } elseif (($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) { 2337 return (float) $match[2]; 2338 } 2339 2340 return null; 2341 } 2342 2343 /** 2344 * Get the `<atom:source>` for the item 2345 * 2346 * @since 1.1 2347 * @return \SimplePie\Source|null 2348 */ 2349 public function get_source() 2350 { 2351 if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'source')) { 2352 return $this->registry->create(Source::class, [$this, $return[0]]); 2353 } 2354 2355 return null; 2356 } 2357 } 2358 2359 class_alias('SimplePie\Item', 'SimplePie_Item');
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Tue Dec 24 08:20:01 2024 | Cross-referenced by PHPXref |