Changeset 60771 for trunk/src/wp-includes/SimplePie/src/Item.php
- Timestamp:
- 09/16/2025 10:45:37 PM (2 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/SimplePie/src/Item.php (modified) (55 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Item.php
r59141 r60771 1 1 <?php 2 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 */ 3 // SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue 4 // SPDX-License-Identifier: BSD-3-Clause 5 6 declare(strict_types=1); 44 7 45 8 namespace SimplePie; … … 51 14 * 52 15 * This class can be overloaded with {@see \SimplePie\SimplePie::set_item_class()} 53 *54 * @package \SimplePie\SimplePie55 * @subpackage API56 16 */ 57 17 class Item implements RegistryAware … … 69 29 * 70 30 * @access private 71 * @var array 31 * @var array<string, mixed> 72 32 */ 73 33 public $data = []; … … 82 42 83 43 /** 44 * @var Sanitize|null 45 */ 46 private $sanitize = null; 47 48 /** 84 49 * Create a new item object 85 50 * … … 88 53 * 89 54 * @param \SimplePie\SimplePie $feed Parent feed 90 * @param array $data Raw data91 */ 92 public function __construct( $feed,$data)55 * @param array<string, mixed> $data Raw data 56 */ 57 public function __construct(\SimplePie\SimplePie $feed, array $data) 93 58 { 94 59 $this->feed = $feed; … … 103 68 * @since 1.3 104 69 * @param \SimplePie\Registry $registry 105 */ 106 public function set_registry(\SimplePie\Registry $registry)/* : void */ 70 * @return void 71 */ 72 public function set_registry(\SimplePie\Registry $registry) 107 73 { 108 74 $this->registry = $registry; … … 141 107 * @param string $namespace The URL of the XML namespace of the elements you're trying to access 142 108 * @param string $tag Tag name 143 * @return array 144 */ 145 public function get_item_tags( $namespace,$tag)109 * @return array<array<string, mixed>>|null 110 */ 111 public function get_item_tags(string $namespace, string $tag) 146 112 { 147 113 if (isset($this->data['child'][$namespace][$tag])) { … … 153 119 154 120 /** 121 * Get base URL of the item itself. 122 * Returns `<xml:base>` or feed base URL. 123 * Similar to `Item::get_base()` but can safely be used during initialisation methods 124 * such as `Item::get_links()` (`Item::get_base()` and `Item::get_links()` call each-other) 125 * and is not affected by enclosures. 126 * 127 * @param array<string, mixed> $element 128 * @see get_base 129 */ 130 private function get_own_base(array $element = []): string 131 { 132 if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) { 133 return $element['xml_base']; 134 } 135 return $this->feed->get_base(); 136 } 137 138 /** 155 139 * Get the base URL value. 156 * Uses `<xml:base>`, or item link, or feed base URL.157 * 158 * @param array $element140 * Uses `<xml:base>`, or item link, or enclosure link, or feed base URL. 141 * 142 * @param array<string, mixed> $element 159 143 * @return string 160 144 */ 161 public function get_base( $element = [])145 public function get_base(array $element = []) 162 146 { 163 147 if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) { … … 177 161 * @see \SimplePie\SimplePie::sanitize() 178 162 * @param string $data Data to sanitize 179 * @param int $type One of the \SimplePie\SimplePie::CONSTRUCT_* constants163 * @param int-mask-of<SimplePie::CONSTRUCT_*> $type 180 164 * @param string $base Base URL to resolve URLs against 181 165 * @return string Sanitized data 182 166 */ 183 public function sanitize($data, $type, $base = '') 184 { 167 public function sanitize(string $data, int $type, string $base = '') 168 { 169 // This really returns string|false but changing encoding is uncommon and we are going to deprecate it, so let’s just lie to PHPStan in the interest of cleaner annotations. 185 170 return $this->feed->sanitize($data, $type, $base); 186 171 } … … 210 195 * 211 196 * @since Beta 2 212 * @param bool ean$hash Should we force using a hash instead of the supplied ID?197 * @param bool $hash Should we force using a hash instead of the supplied ID? 213 198 * @param string|false $fn User-supplied function to generate an hash 214 199 * @return string|null 215 200 */ 216 public function get_id( $hash = false, $fn = 'md5')201 public function get_id(bool $hash = false, $fn = 'md5') 217 202 { 218 203 if (!$hash) { … … 287 272 * 288 273 * @since 0.8 289 * @param bool ean$description_only Should we avoid falling back to the content?274 * @param bool $description_only Should we avoid falling back to the content? 290 275 * @return string|null 291 276 */ 292 public function get_description( $description_only = false)277 public function get_description(bool $description_only = false) 293 278 { 294 279 if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'summary')) && … … 337 322 * 338 323 * @since 1.0 339 * @param bool ean$content_only Should we avoid falling back to the description?324 * @param bool $content_only Should we avoid falling back to the description? 340 325 * @return string|null 341 326 */ 342 public function get_content( $content_only = false)327 public function get_content(bool $content_only = false) 343 328 { 344 329 if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'content')) && … … 364 349 * 365 350 * 366 * @return array |null351 * @return array{url: string, height?: string, width?: string, time?: string}|null 367 352 */ 368 353 public function get_thumbnail() … … 391 376 * @return \SimplePie\Category|null 392 377 */ 393 public function get_category( $key = 0)378 public function get_category(int $key = 0) 394 379 { 395 380 $categories = $this->get_categories(); … … 463 448 * @return \SimplePie\Author|null 464 449 */ 465 public function get_author( $key = 0)450 public function get_author(int $key = 0) 466 451 { 467 452 $authors = $this->get_authors(); … … 480 465 * @return \SimplePie\Author|null 481 466 */ 482 public function get_contributor( $key = 0)467 public function get_contributor(int $key = 0) 483 468 { 484 469 $contributors = $this->get_contributors(); … … 509 494 } 510 495 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])); 496 $uri = $contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]; 497 $uri = $this->sanitize($uri['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($uri)); 512 498 } 513 499 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) { … … 526 512 } 527 513 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])); 514 $url = $contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0]; 515 $url = $this->sanitize($url['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($url)); 529 516 } 530 517 if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'])) { … … 562 549 } 563 550 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])); 551 $uri = $author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['uri'][0]; 552 $uri = $this->sanitize($uri['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($uri)); 565 553 } 566 554 if (isset($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) { … … 579 567 } 580 568 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])); 569 $url = $author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['url'][0]; 570 $url = $this->sanitize($url['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_base($url)); 582 571 } 583 572 if (isset($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'])) { … … 618 607 * 619 608 * @since 1.1 620 * @return string 609 * @return string|null 621 610 */ 622 611 public function get_copyright() … … 645 634 * 646 635 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data) 647 * @return int|string|null648 */ 649 public function get_date( $date_format = 'j F Y, g:i a')636 * @return ($date_format is 'U' ? ?int : ?string) 637 */ 638 public function get_date(string $date_format = 'j F Y, g:i a') 650 639 { 651 640 if (!isset($this->data['date'])) { … … 676 665 } 677 666 if ($this->data['date']) { 678 $date_format = (string) $date_format;679 667 switch ($date_format) { 680 668 case '': … … 701 689 * 702 690 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data) 703 * @return int|string|null704 */ 705 public function get_updated_date( $date_format = 'j F Y, g:i a')691 * @return ($date_format is 'U' ? ?int : ?string) 692 */ 693 public function get_updated_date(string $date_format = 'j F Y, g:i a') 706 694 { 707 695 if (!isset($this->data['updated'])) { … … 718 706 } 719 707 if ($this->data['updated']) { 720 $date_format = (string) $date_format;721 708 switch ($date_format) { 722 709 case '': … … 745 732 * 746 733 * @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); 734 * @return string|null|false see `strftime` for when this can return `false` 735 */ 736 public function get_local_date(string $date_format = '%c') 737 { 738 if ($date_format === '') { 739 if (($raw_date = $this->get_date('')) === null) { 740 return null; 741 } 742 743 return $this->sanitize($raw_date, \SimplePie\SimplePie::CONSTRUCT_TEXT); 753 744 } elseif (($date = $this->get_date('U')) !== null && $date !== false) { 754 745 return strftime($date_format, $date); … … 763 754 * @see get_date 764 755 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} 765 * @return int|string|null766 */ 767 public function get_gmdate( $date_format = 'j F Y, g:i a')756 * @return string|null 757 */ 758 public function get_gmdate(string $date_format = 'j F Y, g:i a') 768 759 { 769 760 $date = $this->get_date('U'); … … 780 771 * @see get_updated_date 781 772 * @param string $date_format Supports any PHP date format from {@see http://php.net/date} 782 * @return int|string|null783 */ 784 public function get_updated_gmdate( $date_format = 'j F Y, g:i a')773 * @return string|null 774 */ 775 public function get_updated_gmdate(string $date_format = 'j F Y, g:i a') 785 776 { 786 777 $date = $this->get_updated_date('U'); … … 823 814 * @return string|null Link URL 824 815 */ 825 public function get_link( $key = 0,$rel = 'alternate')816 public function get_link(int $key = 0, string $rel = 'alternate') 826 817 { 827 818 $links = $this->get_links($rel); … … 840 831 * @since Beta 2 841 832 * @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')833 * @return array<string>|null Links found for the item (strings) 834 */ 835 public function get_links(string $rel = 'alternate') 845 836 { 846 837 if (!isset($this->data['links'])) { … … 849 840 if (isset($link['attribs']['']['href'])) { 850 841 $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));842 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($link)); 852 843 } 853 844 } … … 855 846 if (isset($link['attribs']['']['href'])) { 856 847 $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));848 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($link)); 858 849 } 859 850 } 860 851 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]));852 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($links[0])); 862 853 } 863 854 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]));855 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($links[0])); 865 856 } 866 857 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]));858 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($links[0])); 868 859 } 869 860 if ($links = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'guid')) { 870 861 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]));862 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($links[0])); 872 863 } 873 864 } … … 882 873 $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = &$this->data['links'][$key]; 883 874 } 884 } elseif (substr( $key, 0, 41) === \SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY) {885 $this->data['links'][substr( $key, 41)] = &$this->data['links'][$key];875 } elseif (substr((string) $key, 0, 41) === \SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY) { 876 $this->data['links'][substr((string) $key, 41)] = &$this->data['links'][$key]; 886 877 } 887 878 $this->data['links'][$key] = array_unique($this->data['links'][$key]); … … 905 896 * @return \SimplePie\Enclosure|null 906 897 */ 907 public function get_enclosure( $key = 0, $prefer = null)898 public function get_enclosure(int $key = 0) 908 899 { 909 900 $enclosures = $this->get_enclosures(); … … 945 936 $player_parent = null; 946 937 $ratings_parent = null; 947 $restrictions_parent = null;938 $restrictions_parent = []; 948 939 $thumbnails_parent = null; 949 940 $title_parent = null; … … 1140 1131 1141 1132 // DURATION 1142 if ($duration_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'duration')) { 1133 $duration_tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'duration'); 1134 if ($duration_tags !== null) { 1143 1135 $seconds = null; 1144 1136 $minutes = null; 1145 1137 $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) { 1138 if (isset($duration_tags[0]['data'])) { 1139 $temp = explode(':', $this->sanitize($duration_tags[0]['data'], \SimplePie\SimplePie::CONSTRUCT_TEXT)); 1140 $seconds = (int) array_pop($temp); 1141 if (count($temp) > 0) { 1152 1142 $minutes = (int) array_pop($temp); 1153 1143 $seconds += $minutes * 60; 1154 1144 } 1155 if ( sizeof($temp) > 0) {1145 if (count($temp) > 0) { 1156 1146 $hours = (int) array_pop($temp); 1157 1147 $seconds += $hours * 3600; … … 1237 1227 if ($player_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'player')) { 1238 1228 if (isset($player_parent[0]['attribs']['']['url'])) { 1239 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1229 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($player_parent[0])); 1240 1230 } 1241 1231 } elseif ($player_parent = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'player')) { 1242 1232 if (isset($player_parent[0]['attribs']['']['url'])) { 1243 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1233 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($player_parent[0])); 1244 1234 } 1245 1235 } … … 1316 1306 } elseif ($restrictions = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'block')) { 1317 1307 foreach ($restrictions as $restriction) { 1318 $restriction_relationship = 'allow';1308 $restriction_relationship = Restriction::RELATIONSHIP_ALLOW; 1319 1309 $restriction_type = null; 1320 1310 $restriction_value = 'itunes'; 1321 1311 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') { 1322 $restriction_relationship = 'deny';1312 $restriction_relationship = Restriction::RELATIONSHIP_DENY; 1323 1313 } 1324 1314 $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); … … 1342 1332 } elseif ($restrictions = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'block')) { 1343 1333 foreach ($restrictions as $restriction) { 1344 $restriction_relationship = 'allow';1334 $restriction_relationship = Restriction::RELATIONSHIP_ALLOW; 1345 1335 $restriction_type = null; 1346 1336 $restriction_value = 'itunes'; 1347 1337 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') { 1348 $restriction_relationship = 'deny';1338 $restriction_relationship = Restriction::RELATIONSHIP_DENY; 1349 1339 } 1350 1340 $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]); 1351 1341 } 1352 1342 } 1353 if ( is_array($restrictions_parent)) {1343 if (count($restrictions_parent) > 0) { 1354 1344 $restrictions_parent = array_values(array_unique($restrictions_parent)); 1355 1345 } else { 1356 $restrictions_parent = [new \SimplePie\Restriction( 'allow', null, 'default')];1346 $restrictions_parent = [new \SimplePie\Restriction(Restriction::RELATIONSHIP_ALLOW, null, 'default')]; 1357 1347 } 1358 1348 … … 1361 1351 foreach ($thumbnails as $thumbnail) { 1362 1352 if (isset($thumbnail['attribs']['']['url'])) { 1363 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1353 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($thumbnail)); 1364 1354 } 1365 1355 } … … 1367 1357 foreach ($thumbnails as $thumbnail) { 1368 1358 if (isset($thumbnail['attribs']['']['url'])) { 1369 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1359 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($thumbnail)); 1370 1360 } 1371 1361 } … … 1491 1481 $width = $this->sanitize($content['attribs']['']['width'], \SimplePie\SimplePie::CONSTRUCT_TEXT); 1492 1482 } 1493 $url = $this->sanitize($content['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1483 $url = $this->sanitize($content['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($content)); 1494 1484 1495 1485 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel … … 1750 1740 // PLAYER 1751 1741 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); 1742 $playerElem = $content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]; 1743 $player = $this->sanitize($playerElem['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($playerElem)); 1753 1744 } 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); 1745 $playerElem = $group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]; 1746 $player = $this->sanitize($playerElem['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($playerElem)); 1755 1747 } else { 1756 1748 $player = $player_parent; … … 1842 1834 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) { 1843 1835 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) { 1844 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1836 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($thumbnail)); 1845 1837 } 1846 1838 if (is_array($thumbnails)) { … … 1849 1841 } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) { 1850 1842 foreach ($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) { 1851 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1843 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($thumbnail)); 1852 1844 } 1853 1845 if (is_array($thumbnails)) { … … 1947 1939 } 1948 1940 if (isset($content['attribs']['']['url'])) { 1949 $url = $this->sanitize($content['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );1941 $url = $this->sanitize($content['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($content)); 1950 1942 } 1951 1943 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel … … 2102 2094 if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'])) { 2103 2095 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); 2096 $playerElem = $content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'][0]; 2097 $player = $this->sanitize($playerElem['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($playerElem)); 2105 2098 } 2106 2099 } else { … … 2158 2151 foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) { 2159 2152 if (isset($thumbnail['attribs']['']['url'])) { 2160 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI );2153 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($thumbnail)); 2161 2154 } 2162 2155 } … … 2198 2191 $width = null; 2199 2192 2200 $url = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_ base($link));2193 $url = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($link)); 2201 2194 if (isset($link['attribs']['']['type'])) { 2202 2195 $type = $this->sanitize($link['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); … … 2234 2227 $width = null; 2235 2228 2236 $url = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_ base($link));2229 $url = $this->sanitize($link['attribs']['']['href'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($link)); 2237 2230 if (isset($link['attribs']['']['type'])) { 2238 2231 $type = $this->sanitize($link['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); … … 2265 2258 $width = null; 2266 2259 2267 $url = $this->sanitize($enclosure['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_ base($enclosure));2268 $url = $this-> feed->sanitize->https_url($url);2260 $url = $this->sanitize($enclosure['attribs']['']['url'], \SimplePie\SimplePie::CONSTRUCT_IRI, $this->get_own_base($enclosure)); 2261 $url = $this->get_sanitize()->https_url($url); 2269 2262 if (isset($enclosure['attribs']['']['type'])) { 2270 2263 $type = $this->sanitize($enclosure['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT); … … 2279 2272 } 2280 2273 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)) {2274 if (count($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 || $samplingrate || $thumbnails_parent || $title_parent || $width)) { 2282 2275 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor 2283 2276 $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]); … … 2303 2296 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 2304 2297 * @link http://www.georss.org/ GeoRSS 2305 * @return string|null2298 * @return float|null 2306 2299 */ 2307 2300 public function get_latitude() … … 2326 2319 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 2327 2320 * @link http://www.georss.org/ GeoRSS 2328 * @return string|null2321 * @return float|null 2329 2322 */ 2330 2323 public function get_longitude() … … 2355 2348 return null; 2356 2349 } 2350 2351 public function set_sanitize(Sanitize $sanitize): void 2352 { 2353 $this->sanitize = $sanitize; 2354 } 2355 2356 protected function get_sanitize(): Sanitize 2357 { 2358 if ($this->sanitize === null) { 2359 $this->sanitize = new Sanitize(); 2360 } 2361 2362 return $this->sanitize; 2363 } 2357 2364 } 2358 2365
Note: See TracChangeset
for help on using the changeset viewer.