Make WordPress Core


Ignore:
Timestamp:
09/16/2025 10:45:37 PM (2 months ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update the SimplePie library to version 1.9.0.

References:

Follow-up to [59141], [60490].

Props swissspidy, TobiasBg, SergeyBiryukov.
Fixes #63961.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/SimplePie/src/Item.php

    r59141 r60771  
    11<?php
    22
    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
     6declare(strict_types=1);
    447
    458namespace SimplePie;
     
    5114 *
    5215 * This class can be overloaded with {@see \SimplePie\SimplePie::set_item_class()}
    53  *
    54  * @package \SimplePie\SimplePie
    55  * @subpackage API
    5616 */
    5717class Item implements RegistryAware
     
    6929     *
    7030     * @access private
    71      * @var array
     31     * @var array<string, mixed>
    7232     */
    7333    public $data = [];
     
    8242
    8343    /**
     44     * @var Sanitize|null
     45     */
     46    private $sanitize = null;
     47
     48    /**
    8449     * Create a new item object
    8550     *
     
    8853     *
    8954     * @param \SimplePie\SimplePie $feed Parent feed
    90      * @param array $data Raw data
    91      */
    92     public function __construct($feed, $data)
     55     * @param array<string, mixed> $data Raw data
     56     */
     57    public function __construct(\SimplePie\SimplePie $feed, array $data)
    9358    {
    9459        $this->feed = $feed;
     
    10368     * @since 1.3
    10469     * @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)
    10773    {
    10874        $this->registry = $registry;
     
    141107     * @param string $namespace The URL of the XML namespace of the elements you're trying to access
    142108     * @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)
    146112    {
    147113        if (isset($this->data['child'][$namespace][$tag])) {
     
    153119
    154120    /**
     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    /**
    155139     * Get the base URL value.
    156      * Uses `<xml:base>`, or item link, or feed base URL.
    157      *
    158      * @param array $element
     140     * Uses `<xml:base>`, or item link, or enclosure link, or feed base URL.
     141     *
     142     * @param array<string, mixed> $element
    159143     * @return string
    160144     */
    161     public function get_base($element = [])
     145    public function get_base(array $element = [])
    162146    {
    163147        if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) {
     
    177161     * @see \SimplePie\SimplePie::sanitize()
    178162     * @param string $data Data to sanitize
    179      * @param int $type One of the \SimplePie\SimplePie::CONSTRUCT_* constants
     163     * @param int-mask-of<SimplePie::CONSTRUCT_*> $type
    180164     * @param string $base Base URL to resolve URLs against
    181165     * @return string Sanitized data
    182166     */
    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.
    185170        return $this->feed->sanitize($data, $type, $base);
    186171    }
     
    210195     *
    211196     * @since Beta 2
    212      * @param boolean $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?
    213198     * @param string|false $fn User-supplied function to generate an hash
    214199     * @return string|null
    215200     */
    216     public function get_id($hash = false, $fn = 'md5')
     201    public function get_id(bool $hash = false, $fn = 'md5')
    217202    {
    218203        if (!$hash) {
     
    287272     *
    288273     * @since 0.8
    289      * @param boolean $description_only Should we avoid falling back to the content?
     274     * @param bool $description_only Should we avoid falling back to the content?
    290275     * @return string|null
    291276     */
    292     public function get_description($description_only = false)
     277    public function get_description(bool $description_only = false)
    293278    {
    294279        if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'summary')) &&
     
    337322     *
    338323     * @since 1.0
    339      * @param boolean $content_only Should we avoid falling back to the description?
     324     * @param bool $content_only Should we avoid falling back to the description?
    340325     * @return string|null
    341326     */
    342     public function get_content($content_only = false)
     327    public function get_content(bool $content_only = false)
    343328    {
    344329        if (($tags = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ATOM_10, 'content')) &&
     
    364349     *
    365350     *
    366      * @return array|null
     351     * @return array{url: string, height?: string, width?: string, time?: string}|null
    367352     */
    368353    public function get_thumbnail()
     
    391376     * @return \SimplePie\Category|null
    392377     */
    393     public function get_category($key = 0)
     378    public function get_category(int $key = 0)
    394379    {
    395380        $categories = $this->get_categories();
     
    463448     * @return \SimplePie\Author|null
    464449     */
    465     public function get_author($key = 0)
     450    public function get_author(int $key = 0)
    466451    {
    467452        $authors = $this->get_authors();
     
    480465     * @return \SimplePie\Author|null
    481466     */
    482     public function get_contributor($key = 0)
     467    public function get_contributor(int $key = 0)
    483468    {
    484469        $contributors = $this->get_contributors();
     
    509494            }
    510495            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));
    512498            }
    513499            if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) {
     
    526512            }
    527513            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));
    529516            }
    530517            if (isset($contributor['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'])) {
     
    562549            }
    563550            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));
    565553            }
    566554            if (isset($author['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['email'][0]['data'])) {
     
    579567            }
    580568            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));
    582571            }
    583572            if (isset($author[0]['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_03]['email'][0]['data'])) {
     
    618607     *
    619608     * @since 1.1
    620      * @return string
     609     * @return string|null
    621610     */
    622611    public function get_copyright()
     
    645634     *
    646635     * @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')
     636     * @return ($date_format is 'U' ? ?int : ?string)
     637     */
     638    public function get_date(string $date_format = 'j F Y, g:i a')
    650639    {
    651640        if (!isset($this->data['date'])) {
     
    676665        }
    677666        if ($this->data['date']) {
    678             $date_format = (string) $date_format;
    679667            switch ($date_format) {
    680668                case '':
     
    701689     *
    702690     * @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')
     691     * @return ($date_format is 'U' ? ?int : ?string)
     692     */
     693    public function get_updated_date(string $date_format = 'j F Y, g:i a')
    706694    {
    707695        if (!isset($this->data['updated'])) {
     
    718706        }
    719707        if ($this->data['updated']) {
    720             $date_format = (string) $date_format;
    721708            switch ($date_format) {
    722709                case '':
     
    745732     *
    746733     * @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);
    753744        } elseif (($date = $this->get_date('U')) !== null && $date !== false) {
    754745            return strftime($date_format, $date);
     
    763754     * @see get_date
    764755     * @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')
     756     * @return string|null
     757     */
     758    public function get_gmdate(string $date_format = 'j F Y, g:i a')
    768759    {
    769760        $date = $this->get_date('U');
     
    780771     * @see get_updated_date
    781772     * @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')
     773     * @return string|null
     774     */
     775    public function get_updated_gmdate(string $date_format = 'j F Y, g:i a')
    785776    {
    786777        $date = $this->get_updated_date('U');
     
    823814     * @return string|null Link URL
    824815     */
    825     public function get_link($key = 0, $rel = 'alternate')
     816    public function get_link(int $key = 0, string $rel = 'alternate')
    826817    {
    827818        $links = $this->get_links($rel);
     
    840831     * @since Beta 2
    841832     * @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')
    845836    {
    846837        if (!isset($this->data['links'])) {
     
    849840                if (isset($link['attribs']['']['href'])) {
    850841                    $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));
    852843                }
    853844            }
     
    855846                if (isset($link['attribs']['']['href'])) {
    856847                    $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));
    858849                }
    859850            }
    860851            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]));
    862853            }
    863854            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]));
    865856            }
    866857            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]));
    868859            }
    869860            if ($links = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_RSS_20, 'guid')) {
    870861                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]));
    872863                }
    873864            }
     
    882873                        $this->data['links'][\SimplePie\SimplePie::IANA_LINK_RELATIONS_REGISTRY . $key] = &$this->data['links'][$key];
    883874                    }
    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];
    886877                }
    887878                $this->data['links'][$key] = array_unique($this->data['links'][$key]);
     
    905896     * @return \SimplePie\Enclosure|null
    906897     */
    907     public function get_enclosure($key = 0, $prefer = null)
     898    public function get_enclosure(int $key = 0)
    908899    {
    909900        $enclosures = $this->get_enclosures();
     
    945936            $player_parent = null;
    946937            $ratings_parent = null;
    947             $restrictions_parent = null;
     938            $restrictions_parent = [];
    948939            $thumbnails_parent = null;
    949940            $title_parent = null;
     
    11401131
    11411132            // 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) {
    11431135                $seconds = null;
    11441136                $minutes = null;
    11451137                $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) {
    11521142                        $minutes = (int) array_pop($temp);
    11531143                        $seconds += $minutes * 60;
    11541144                    }
    1155                     if (sizeof($temp) > 0) {
     1145                    if (count($temp) > 0) {
    11561146                        $hours = (int) array_pop($temp);
    11571147                        $seconds += $hours * 3600;
     
    12371227            if ($player_parent = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'player')) {
    12381228                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]));
    12401230                }
    12411231            } elseif ($player_parent = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'player')) {
    12421232                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]));
    12441234                }
    12451235            }
     
    13161306            } elseif ($restrictions = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'block')) {
    13171307                foreach ($restrictions as $restriction) {
    1318                     $restriction_relationship = 'allow';
     1308                    $restriction_relationship = Restriction::RELATIONSHIP_ALLOW;
    13191309                    $restriction_type = null;
    13201310                    $restriction_value = 'itunes';
    13211311                    if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') {
    1322                         $restriction_relationship = 'deny';
     1312                        $restriction_relationship = Restriction::RELATIONSHIP_DENY;
    13231313                    }
    13241314                    $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]);
     
    13421332            } elseif ($restrictions = $parent->get_channel_tags(\SimplePie\SimplePie::NAMESPACE_ITUNES, 'block')) {
    13431333                foreach ($restrictions as $restriction) {
    1344                     $restriction_relationship = 'allow';
     1334                    $restriction_relationship = Restriction::RELATIONSHIP_ALLOW;
    13451335                    $restriction_type = null;
    13461336                    $restriction_value = 'itunes';
    13471337                    if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes') {
    1348                         $restriction_relationship = 'deny';
     1338                        $restriction_relationship = Restriction::RELATIONSHIP_DENY;
    13491339                    }
    13501340                    $restrictions_parent[] = $this->registry->create(Restriction::class, [$restriction_relationship, $restriction_type, $restriction_value]);
    13511341                }
    13521342            }
    1353             if (is_array($restrictions_parent)) {
     1343            if (count($restrictions_parent) > 0) {
    13541344                $restrictions_parent = array_values(array_unique($restrictions_parent));
    13551345            } else {
    1356                 $restrictions_parent = [new \SimplePie\Restriction('allow', null, 'default')];
     1346                $restrictions_parent = [new \SimplePie\Restriction(Restriction::RELATIONSHIP_ALLOW, null, 'default')];
    13571347            }
    13581348
     
    13611351                foreach ($thumbnails as $thumbnail) {
    13621352                    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));
    13641354                    }
    13651355                }
     
    13671357                foreach ($thumbnails as $thumbnail) {
    13681358                    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));
    13701360                    }
    13711361                }
     
    14911481                                $width = $this->sanitize($content['attribs']['']['width'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
    14921482                            }
    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));
    14941484
    14951485                            // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
     
    17501740                            // PLAYER
    17511741                            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));
    17531744                            } 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));
    17551747                            } else {
    17561748                                $player = $player_parent;
     
    18421834                            if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) {
    18431835                                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));
    18451837                                }
    18461838                                if (is_array($thumbnails)) {
     
    18491841                            } elseif (isset($group['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'])) {
    18501842                                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));
    18521844                                }
    18531845                                if (is_array($thumbnails)) {
     
    19471939                        }
    19481940                        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));
    19501942                        }
    19511943                        // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
     
    21022094                        if (isset($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['player'])) {
    21032095                            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));
    21052098                            }
    21062099                        } else {
     
    21582151                            foreach ($content['child'][\SimplePie\SimplePie::NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail) {
    21592152                                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));
    21612154                                }
    21622155                            }
     
    21982191                    $width = null;
    21992192
    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));
    22012194                    if (isset($link['attribs']['']['type'])) {
    22022195                        $type = $this->sanitize($link['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
     
    22342227                    $width = null;
    22352228
    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));
    22372230                    if (isset($link['attribs']['']['type'])) {
    22382231                        $type = $this->sanitize($link['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
     
    22652258                    $width = null;
    22662259
    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);
    22692262                    if (isset($enclosure['attribs']['']['type'])) {
    22702263                        $type = $this->sanitize($enclosure['attribs']['']['type'], \SimplePie\SimplePie::CONSTRUCT_TEXT);
     
    22792272            }
    22802273
    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)) {
    22822275                // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
    22832276                $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]);
     
    23032296     * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
    23042297     * @link http://www.georss.org/ GeoRSS
    2305      * @return string|null
     2298     * @return float|null
    23062299     */
    23072300    public function get_latitude()
     
    23262319     * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
    23272320     * @link http://www.georss.org/ GeoRSS
    2328      * @return string|null
     2321     * @return float|null
    23292322     */
    23302323    public function get_longitude()
     
    23552348        return null;
    23562349    }
     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    }
    23572364}
    23582365
Note: See TracChangeset for help on using the changeset viewer.