Make WordPress Core


Ignore:
Timestamp:
09/30/2024 10:48:16 PM (8 months ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update the SimplePie library to version 1.8.0.

The most notable change in this update is that all code is now namespaced and uses PSR-4 classes, though there is a compatibility layer available for extenders using the older class names, so plugin or theme authors directly using SimplePie can decide for themselves when they want to change to using the namespaced names for SimplePie classes.

Note: This commit includes additional fixes for PHP 8.4 compatibility (PR 875, PR 888) from the one-dot-eight branch of SimplePie, which is expected to be released as SimplePie 1.8.1 soon.

References:

Follow-up to [47733], [49176], [52393], [52413].

Props jrf, peterwilsoncc, chaion07, cu121, markparnell, audrasjb, costdev, Presskopp, desrosj, faisal03, mukesh27, SergeyBiryukov.
See #55604.

Location:
trunk/src/wp-includes/SimplePie/src
Files:
1 added
1 moved

Legend:

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

    r59140 r59141  
    11<?php
     2
    23/**
    34 * SimplePie
     
    67 * Takes the hard work out of managing a complete RSS/Atom solution.
    78 *
    8  * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
     9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
    910 * All rights reserved.
    1011 *
     
    4243 */
    4344
     45namespace SimplePie;
    4446
    4547/**
    4648 * Manages all item-related data
    4749 *
    48  * Used by {@see SimplePie::get_item()} and {@see SimplePie::get_items()}
     50 * Used by {@see \SimplePie\SimplePie::get_item()} and {@see \SimplePie\SimplePie::get_items()}
    4951 *
    50  * This class can be overloaded with {@see SimplePie::set_item_class()}
     52 * This class can be overloaded with {@see \SimplePie\SimplePie::set_item_class()}
    5153 *
    52  * @package SimplePie
     54 * @package \SimplePie\SimplePie
    5355 * @subpackage API
    5456 */
    55 class SimplePie_Item
     57class Item implements RegistryAware
    5658{
    57     /**
    58      * Parent feed
    59      *
    60      * @access private
    61      * @var SimplePie
    62      */
    63     var $feed;
    64 
    65     /**
    66      * Raw data
    67      *
    68      * @access private
    69      * @var array
    70      */
    71     var $data = array();
    72 
    73     /**
    74      * Registry object
    75      *
    76      * @see set_registry
    77      * @var SimplePie_Registry
    78      */
    79     protected $registry;
    80 
    81     /**
    82      * Create a new item object
    83      *
    84      * This is usually used by {@see SimplePie::get_items} and
    85      * {@see SimplePie::get_item}. Avoid creating this manually.
    86      *
    87      * @param SimplePie $feed Parent feed
    88      * @param array $data Raw data
    89      */
    90     public function __construct($feed, $data)
    91     {
    92         $this->feed = $feed;
    93         $this->data = $data;
    94     }
    95 
    96     /**
    97      * Set the registry handler
    98      *
    99      * This is usually used by {@see SimplePie_Registry::create}
    100      *
    101      * @since 1.3
    102      * @param SimplePie_Registry $registry
    103      */
    104     public function set_registry(SimplePie_Registry $registry)
    105     {
    106         $this->registry = $registry;
    107     }
    108 
    109     /**
    110      * Get a string representation of the item
    111      *
    112      * @return string
    113      */
    114     public function __toString()
    115     {
    116         return md5(serialize($this->data));
    117     }
    118 
    119     /**
    120      * Remove items that link back to this before destroying this object
    121      */
    122     public function __destruct()
    123     {
    124         if (!gc_enabled())
    125         {
    126             unset($this->feed);
    127         }
    128     }
    129 
    130     /**
    131      * Get data for an item-level element
    132      *
    133      * This method allows you to get access to ANY element/attribute that is a
    134      * sub-element of the item/entry tag.
    135      *
    136      * See {@see SimplePie::get_feed_tags()} for a description of the return value
    137      *
    138      * @since 1.0
    139      * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
    140      * @param string $namespace The URL of the XML namespace of the elements you're trying to access
    141      * @param string $tag Tag name
    142      * @return array
    143      */
    144     public function get_item_tags($namespace, $tag)
    145     {
    146         if (isset($this->data['child'][$namespace][$tag]))
    147         {
    148             return $this->data['child'][$namespace][$tag];
    149         }
    150 
    151         return null;
    152     }
    153 
    154     /**
    155      * Get the base URL value from the parent feed
    156      *
    157      * Uses `<xml:base>`
    158      *
    159      * @param array $element
    160      * @return string
    161      */
    162     public function get_base($element = array())
    163     {
    164         return $this->feed->get_base($element);
    165     }
    166 
    167     /**
    168      * Sanitize feed data
    169      *
    170      * @access private
    171      * @see SimplePie::sanitize()
    172      * @param string $data Data to sanitize
    173      * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
    174      * @param string $base Base URL to resolve URLs against
    175      * @return string Sanitized data
    176      */
    177     public function sanitize($data, $type, $base = '')
    178     {
    179         return $this->feed->sanitize($data, $type, $base);
    180     }
    181 
    182     /**
    183      * Get the parent feed
    184      *
    185      * Note: this may not work as you think for multifeeds!
    186      *
    187      * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
    188      * @since 1.0
    189      * @return SimplePie
    190      */
    191     public function get_feed()
    192     {
    193         return $this->feed;
    194     }
    195 
    196     /**
    197      * Get the unique identifier for the item
    198      *
    199      * This is usually used when writing code to check for new items in a feed.
    200      *
    201      * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
    202      * for RDF. If none of these are supplied (or `$hash` is true), creates an
    203      * MD5 hash based on the permalink, title and content.
    204      *
    205      * @since Beta 2
    206      * @param boolean $hash Should we force using a hash instead of the supplied ID?
    207      * @param string|false $fn User-supplied function to generate an hash
    208      * @return string|null
    209      */
    210     public function get_id($hash = false, $fn = 'md5')
    211     {
    212         if (!$hash)
    213         {
    214             if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
    215             {
    216                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    217             }
    218             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
    219             {
    220                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    221             }
    222             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
    223             {
    224                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    225             }
    226             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
    227             {
    228                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    229             }
    230             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
    231             {
    232                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    233             }
    234             elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
    235             {
    236                 return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
    237             }
    238         }
    239         if ($fn === false)
    240         {
    241             return null;
    242         }
    243         elseif (!is_callable($fn))
    244         {
    245             trigger_error('User-supplied function $fn must be callable', E_USER_WARNING);
    246             $fn = 'md5';
    247         }
    248         return call_user_func($fn,
    249                $this->get_permalink().$this->get_title().$this->get_content());
    250     }
    251 
    252     /**
    253      * Get the title of the item
    254      *
    255      * Uses `<atom:title>`, `<title>` or `<dc:title>`
    256      *
    257      * @since Beta 2 (previously called `get_item_title` since 0.8)
    258      * @return string|null
    259      */
    260     public function get_title()
    261     {
    262         if (!isset($this->data['title']))
    263         {
    264             if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
    265             {
    266                 $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
    267             }
    268             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
    269             {
    270                 $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
    271             }
    272             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
    273             {
    274                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
    275             }
    276             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
    277             {
    278                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
    279             }
    280             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
    281             {
    282                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
    283             }
    284             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
    285             {
    286                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    287             }
    288             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
    289             {
    290                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    291             }
    292             else
    293             {
    294                 $this->data['title'] = null;
    295             }
    296         }
    297         return $this->data['title'];
    298     }
    299 
    300     /**
    301      * Get the content for the item
    302      *
    303      * Prefers summaries over full content , but will return full content if a
    304      * summary does not exist.
    305      *
    306      * To prefer full content instead, use {@see get_content}
    307      *
    308      * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
    309      * `<itunes:subtitle>`
    310      *
    311      * @since 0.8
    312      * @param boolean $description_only Should we avoid falling back to the content?
    313      * @return string|null
    314      */
    315     public function get_description($description_only = false)
    316     {
    317         if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) &&
    318             ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
    319         {
    320             return $return;
    321         }
    322         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) &&
    323                 ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
    324         {
    325             return $return;
    326         }
    327         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) &&
    328                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0]))))
    329         {
    330             return $return;
    331         }
    332         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) &&
    333                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
    334         {
    335             return $return;
    336         }
    337         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) &&
    338                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
    339         {
    340             return $return;
    341         }
    342         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) &&
    343                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
    344         {
    345             return $return;
    346         }
    347         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) &&
    348                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
    349         {
    350             return $return;
    351         }
    352         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) &&
    353                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
    354         {
    355             return $return;
    356         }
    357         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) &&
    358                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)))
    359         {
    360             return $return;
    361         }
    362 
    363         elseif (!$description_only)
    364         {
    365             return $this->get_content(true);
    366         }
    367 
    368         return null;
    369     }
    370 
    371     /**
    372      * Get the content for the item
    373      *
    374      * Prefers full content over summaries, but will return a summary if full
    375      * content does not exist.
    376      *
    377      * To prefer summaries instead, use {@see get_description}
    378      *
    379      * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
    380      *
    381      * @since 1.0
    382      * @param boolean $content_only Should we avoid falling back to the description?
    383      * @return string|null
    384      */
    385     public function get_content($content_only = false)
    386     {
    387         if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) &&
    388             ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
    389         {
    390             return $return;
    391         }
    392         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) &&
    393                 ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
    394         {
    395             return $return;
    396         }
    397         elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) &&
    398                 ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
    399         {
    400             return $return;
    401         }
    402         elseif (!$content_only)
    403         {
    404             return $this->get_description(true);
    405         }
    406 
    407         return null;
    408     }
    409 
    410     /**
    411      * Get the media:thumbnail of the item
    412      *
    413      * Uses `<media:thumbnail>`
    414      *
    415      *
    416      * @return array|null
    417      */
    418     public function get_thumbnail()
    419     {
    420         if (!isset($this->data['thumbnail']))
    421         {
    422             if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
    423             {
    424                 $this->data['thumbnail'] = $return[0]['attribs'][''];
    425             }
    426             else
    427             {
    428                 $this->data['thumbnail'] = null;
    429             }
    430         }
    431         return $this->data['thumbnail'];
    432     }
    433 
    434     /**
    435      * Get a category for the item
    436      *
    437      * @since Beta 3 (previously called `get_categories()` since Beta 2)
    438      * @param int $key The category that you want to return.  Remember that arrays begin with 0, not 1
    439      * @return SimplePie_Category|null
    440      */
    441     public function get_category($key = 0)
    442     {
    443         $categories = $this->get_categories();
    444         if (isset($categories[$key]))
    445         {
    446             return $categories[$key];
    447         }
    448 
    449         return null;
    450     }
    451 
    452     /**
    453      * Get all categories for the item
    454      *
    455      * Uses `<atom:category>`, `<category>` or `<dc:subject>`
    456      *
    457      * @since Beta 3
    458      * @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects
    459      */
    460     public function get_categories()
    461     {
    462         $categories = array();
    463 
    464         $type = 'category';
    465         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, $type) as $category)
    466         {
    467             $term = null;
    468             $scheme = null;
    469             $label = null;
    470             if (isset($category['attribs']['']['term']))
    471             {
    472                 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
    473             }
    474             if (isset($category['attribs']['']['scheme']))
    475             {
    476                 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    477             }
    478             if (isset($category['attribs']['']['label']))
    479             {
    480                 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
    481             }
    482             $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type));
    483         }
    484         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, $type) as $category)
    485         {
    486             // This is really the label, but keep this as the term also for BC.
    487             // Label will also work on retrieving because that falls back to term.
    488             $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    489             if (isset($category['attribs']['']['domain']))
    490             {
    491                 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
    492             }
    493             else
    494             {
    495                 $scheme = null;
    496             }
    497             $categories[] = $this->registry->create('Category', array($term, $scheme, null, $type));
    498         }
    499 
    500         $type = 'subject';
    501         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category)
    502         {
    503             $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type));
    504         }
    505         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category)
    506         {
    507             $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type));
    508         }
    509 
    510         if (!empty($categories))
    511         {
    512             return array_unique($categories);
    513         }
    514 
    515         return null;
    516     }
    517 
    518     /**
    519      * Get an author for the item
    520      *
    521      * @since Beta 2
    522      * @param int $key The author that you want to return.  Remember that arrays begin with 0, not 1
    523      * @return SimplePie_Author|null
    524      */
    525     public function get_author($key = 0)
    526     {
    527         $authors = $this->get_authors();
    528         if (isset($authors[$key]))
    529         {
    530             return $authors[$key];
    531         }
    532 
    533         return null;
    534     }
    535 
    536     /**
    537      * Get a contributor for the item
    538      *
    539      * @since 1.1
    540      * @param int $key The contrbutor that you want to return.  Remember that arrays begin with 0, not 1
    541      * @return SimplePie_Author|null
    542      */
    543     public function get_contributor($key = 0)
    544     {
    545         $contributors = $this->get_contributors();
    546         if (isset($contributors[$key]))
    547         {
    548             return $contributors[$key];
    549         }
    550 
    551         return null;
    552     }
    553 
    554     /**
    555      * Get all contributors for the item
    556      *
    557      * Uses `<atom:contributor>`
    558      *
    559      * @since 1.1
    560      * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects
    561      */
    562     public function get_contributors()
    563     {
    564         $contributors = array();
    565         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
    566         {
    567             $name = null;
    568             $uri = null;
    569             $email = null;
    570             if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
    571             {
    572                 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    573             }
    574             if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
    575             {
    576                 $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
    577             }
    578             if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
    579             {
    580                 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    581             }
    582             if ($name !== null || $email !== null || $uri !== null)
    583             {
    584                 $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
    585             }
    586         }
    587         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
    588         {
    589             $name = null;
    590             $url = null;
    591             $email = null;
    592             if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
    593             {
    594                 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    595             }
    596             if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
    597             {
    598                 $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
    599             }
    600             if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
    601             {
    602                 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    603             }
    604             if ($name !== null || $email !== null || $url !== null)
    605             {
    606                 $contributors[] = $this->registry->create('Author', array($name, $url, $email));
    607             }
    608         }
    609 
    610         if (!empty($contributors))
    611         {
    612             return array_unique($contributors);
    613         }
    614 
    615         return null;
    616     }
    617 
    618     /**
    619      * Get all authors for the item
    620      *
    621      * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
    622      *
    623      * @since Beta 2
    624      * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects
    625      */
    626     public function get_authors()
    627     {
    628         $authors = array();
    629         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
    630         {
    631             $name = null;
    632             $uri = null;
    633             $email = null;
    634             if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
    635             {
    636                 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    637             }
    638             if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
    639             {
    640                 $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
    641             }
    642             if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
    643             {
    644                 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    645             }
    646             if ($name !== null || $email !== null || $uri !== null)
    647             {
    648                 $authors[] = $this->registry->create('Author', array($name, $uri, $email));
    649             }
    650         }
    651         if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
    652         {
    653             $name = null;
    654             $url = null;
    655             $email = null;
    656             if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
    657             {
    658                 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    659             }
    660             if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
    661             {
    662                 $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
    663             }
    664             if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
    665             {
    666                 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    667             }
    668             if ($name !== null || $email !== null || $url !== null)
    669             {
    670                 $authors[] = $this->registry->create('Author', array($name, $url, $email));
    671             }
    672         }
    673         if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
    674         {
    675             $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
    676         }
    677         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
    678         {
    679             $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
    680         }
    681         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
    682         {
    683             $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
    684         }
    685         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
    686         {
    687             $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
    688         }
    689 
    690         if (!empty($authors))
    691         {
    692             return array_unique($authors);
    693         }
    694         elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
    695         {
    696             return $authors;
    697         }
    698         elseif ($authors = $this->feed->get_authors())
    699         {
    700             return $authors;
    701         }
    702 
    703         return null;
    704     }
    705 
    706     /**
    707      * Get the copyright info for the item
    708      *
    709      * Uses `<atom:rights>` or `<dc:rights>`
    710      *
    711      * @since 1.1
    712      * @return string
    713      */
    714     public function get_copyright()
    715     {
    716         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
    717         {
    718             return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
    719         }
    720         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
    721         {
    722             return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    723         }
    724         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
    725         {
    726             return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    727         }
    728 
    729         return null;
    730     }
    731 
    732     /**
    733      * Get the posting date/time for the item
    734      *
    735      * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
    736      * `<atom:modified>`, `<pubDate>` or `<dc:date>`
    737      *
    738      * Note: obeys PHP's timezone setting. To get a UTC date/time, use
    739      * {@see get_gmdate}
    740      *
    741      * @since Beta 2 (previously called `get_item_date` since 0.8)
    742      *
    743      * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
    744      * @return int|string|null
    745      */
    746     public function get_date($date_format = 'j F Y, g:i a')
    747     {
    748         if (!isset($this->data['date']))
    749         {
    750             if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
    751             {
    752                 $this->data['date']['raw'] = $return[0]['data'];
    753             }
    754             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
    755             {
    756                 $this->data['date']['raw'] = $return[0]['data'];
    757             }
    758             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
    759             {
    760                 $this->data['date']['raw'] = $return[0]['data'];
    761             }
    762             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
    763             {
    764                 $this->data['date']['raw'] = $return[0]['data'];
    765             }
    766             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
    767             {
    768                 $this->data['date']['raw'] = $return[0]['data'];
    769             }
    770             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
    771             {
    772                 $this->data['date']['raw'] = $return[0]['data'];
    773             }
    774             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
    775             {
    776                 $this->data['date']['raw'] = $return[0]['data'];
    777             }
    778             elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
    779             {
    780                 $this->data['date']['raw'] = $return[0]['data'];
    781             }
    782 
    783             if (!empty($this->data['date']['raw']))
    784             {
    785                 $parser = $this->registry->call('Parse_Date', 'get');
    786                 $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
    787             }
    788             else
    789             {
    790                 $this->data['date'] = null;
    791             }
    792         }
    793         if ($this->data['date'])
    794         {
    795             $date_format = (string) $date_format;
    796             switch ($date_format)
    797             {
    798                 case '':
    799                     return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
    800 
    801                 case 'U':
    802                     return $this->data['date']['parsed'];
    803 
    804                 default:
    805                     return date($date_format, $this->data['date']['parsed']);
    806             }
    807         }
    808 
    809         return null;
    810     }
    811 
    812     /**
    813      * Get the update date/time for the item
    814      *
    815      * Uses `<atom:updated>`
    816      *
    817      * Note: obeys PHP's timezone setting. To get a UTC date/time, use
    818      * {@see get_gmdate}
    819      *
    820      * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
    821      * @return int|string|null
    822      */
    823     public function get_updated_date($date_format = 'j F Y, g:i a')
    824     {
    825         if (!isset($this->data['updated']))
    826         {
    827             if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
    828             {
    829                 $this->data['updated']['raw'] = $return[0]['data'];
    830             }
    831 
    832             if (!empty($this->data['updated']['raw']))
    833             {
    834                 $parser = $this->registry->call('Parse_Date', 'get');
    835                 $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']);
    836             }
    837             else
    838             {
    839                 $this->data['updated'] = null;
    840             }
    841         }
    842         if ($this->data['updated'])
    843         {
    844             $date_format = (string) $date_format;
    845             switch ($date_format)
    846             {
    847                 case '':
    848                     return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
    849 
    850                 case 'U':
    851                     return $this->data['updated']['parsed'];
    852 
    853                 default:
    854                     return date($date_format, $this->data['updated']['parsed']);
    855             }
    856         }
    857 
    858         return null;
    859     }
    860 
    861     /**
    862      * Get the localized posting date/time for the item
    863      *
    864      * Returns the date formatted in the localized language. To display in
    865      * languages other than the server's default, you need to change the locale
    866      * with {@link http://php.net/setlocale setlocale()}. The available
    867      * localizations depend on which ones are installed on your web server.
    868      *
    869      * @since 1.0
    870      *
    871      * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
    872      * @return int|string|null
    873      */
    874     public function get_local_date($date_format = '%c')
    875     {
    876         if (!$date_format)
    877         {
    878             return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
    879         }
    880         elseif (($date = $this->get_date('U')) !== null && $date !== false)
    881         {
    882             return strftime($date_format, $date);
    883         }
    884 
    885         return null;
    886     }
    887 
    888     /**
    889      * Get the posting date/time for the item (UTC time)
    890      *
    891      * @see get_date
    892      * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
    893      * @return int|string|null
    894      */
    895     public function get_gmdate($date_format = 'j F Y, g:i a')
    896     {
    897         $date = $this->get_date('U');
    898         if ($date === null)
    899         {
    900             return null;
    901         }
    902 
    903         return gmdate($date_format, $date);
    904     }
    905 
    906     /**
    907      * Get the update date/time for the item (UTC time)
    908      *
    909      * @see get_updated_date
    910      * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
    911      * @return int|string|null
    912      */
    913     public function get_updated_gmdate($date_format = 'j F Y, g:i a')
    914     {
    915         $date = $this->get_updated_date('U');
    916         if ($date === null)
    917         {
    918             return null;
    919         }
    920 
    921         return gmdate($date_format, $date);
    922     }
    923 
    924     /**
    925      * Get the permalink for the item
    926      *
    927      * Returns the first link available with a relationship of "alternate".
    928      * Identical to {@see get_link()} with key 0
    929      *
    930      * @see get_link
    931      * @since 0.8
    932      * @return string|null Permalink URL
    933      */
    934     public function get_permalink()
    935     {
    936         $link = $this->get_link();
    937         $enclosure = $this->get_enclosure(0);
    938         if ($link !== null)
    939         {
    940             return $link;
    941         }
    942         elseif ($enclosure !== null)
    943         {
    944             return $enclosure->get_link();
    945         }
    946 
    947         return null;
    948     }
    949 
    950     /**
    951      * Get a single link for the item
    952      *
    953      * @since Beta 3
    954      * @param int $key The link that you want to return.  Remember that arrays begin with 0, not 1
    955      * @param string $rel The relationship of the link to return
    956      * @return string|null Link URL
    957      */
    958     public function get_link($key = 0, $rel = 'alternate')
    959     {
    960         $links = $this->get_links($rel);
    961         if ($links && $links[$key] !== null)
    962         {
    963             return $links[$key];
    964         }
    965 
    966         return null;
    967     }
    968 
    969     /**
    970      * Get all links for the item
    971      *
    972      * Uses `<atom:link>`, `<link>` or `<guid>`
    973      *
    974      * @since Beta 2
    975      * @param string $rel The relationship of links to return
    976      * @return array|null Links found for the item (strings)
    977      */
    978     public function get_links($rel = 'alternate')
    979     {
    980         if (!isset($this->data['links']))
    981         {
    982             $this->data['links'] = array();
    983             foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
    984             {
    985                 if (isset($link['attribs']['']['href']))
    986                 {
    987                     $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
    988                     $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
    989 
    990                 }
    991             }
    992             foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
    993             {
    994                 if (isset($link['attribs']['']['href']))
    995                 {
    996                     $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
    997                     $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
    998                 }
    999             }
    1000             if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
    1001             {
    1002                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
    1003             }
    1004             if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
    1005             {
    1006                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
    1007             }
    1008             if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
    1009             {
    1010                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
    1011             }
    1012             if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
    1013             {
    1014                 if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
    1015                 {
    1016                     $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
    1017                 }
    1018             }
    1019 
    1020             $keys = array_keys($this->data['links']);
    1021             foreach ($keys as $key)
    1022             {
    1023                 if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
    1024                 {
    1025                     if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
    1026                     {
    1027                         $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
    1028                         $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
    1029                     }
    1030                     else
    1031                     {
    1032                         $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
    1033                     }
    1034                 }
    1035                 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
    1036                 {
    1037                     $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
    1038                 }
    1039                 $this->data['links'][$key] = array_unique($this->data['links'][$key]);
    1040             }
    1041         }
    1042         if (isset($this->data['links'][$rel]))
    1043         {
    1044             return $this->data['links'][$rel];
    1045         }
    1046 
    1047         return null;
    1048     }
    1049 
    1050     /**
    1051      * Get an enclosure from the item
    1052      *
    1053      * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
    1054      *
    1055      * @since Beta 2
    1056      * @todo Add ability to prefer one type of content over another (in a media group).
    1057      * @param int $key The enclosure that you want to return.  Remember that arrays begin with 0, not 1
    1058      * @return SimplePie_Enclosure|null
    1059      */
    1060     public function get_enclosure($key = 0, $prefer = null)
    1061     {
    1062         $enclosures = $this->get_enclosures();
    1063         if (isset($enclosures[$key]))
    1064         {
    1065             return $enclosures[$key];
    1066         }
    1067 
    1068         return null;
    1069     }
    1070 
    1071     /**
    1072      * Get all available enclosures (podcasts, etc.)
    1073      *
    1074      * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
    1075      *
    1076      * At this point, we're pretty much assuming that all enclosures for an item
    1077      * are the same content.  Anything else is too complicated to
    1078      * properly support.
    1079      *
    1080      * @since Beta 2
    1081      * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
    1082      * @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).
    1083      * @return SimplePie_Enclosure[]|null List of SimplePie_Enclosure items
    1084      */
    1085     public function get_enclosures()
    1086     {
    1087         if (!isset($this->data['enclosures']))
    1088         {
    1089             $this->data['enclosures'] = array();
    1090 
    1091             // Elements
    1092             $captions_parent = null;
    1093             $categories_parent = null;
    1094             $copyrights_parent = null;
    1095             $credits_parent = null;
    1096             $description_parent = null;
    1097             $duration_parent = null;
    1098             $hashes_parent = null;
    1099             $keywords_parent = null;
    1100             $player_parent = null;
    1101             $ratings_parent = null;
    1102             $restrictions_parent = null;
    1103             $thumbnails_parent = null;
    1104             $title_parent = null;
    1105 
    1106             // Let's do the channel and item-level ones first, and just re-use them if we need to.
    1107             $parent = $this->get_feed();
    1108 
    1109             // CAPTIONS
    1110             if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
    1111             {
    1112                 foreach ($captions as $caption)
    1113                 {
    1114                     $caption_type = null;
    1115                     $caption_lang = null;
    1116                     $caption_startTime = null;
    1117                     $caption_endTime = null;
    1118                     $caption_text = null;
    1119                     if (isset($caption['attribs']['']['type']))
    1120                     {
    1121                         $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1122                     }
    1123                     if (isset($caption['attribs']['']['lang']))
    1124                     {
    1125                         $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    1126                     }
    1127                     if (isset($caption['attribs']['']['start']))
    1128                     {
    1129                         $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
    1130                     }
    1131                     if (isset($caption['attribs']['']['end']))
    1132                     {
    1133                         $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
    1134                     }
    1135                     if (isset($caption['data']))
    1136                     {
    1137                         $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1138                     }
    1139                     $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
    1140                 }
    1141             }
    1142             elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
    1143             {
    1144                 foreach ($captions as $caption)
    1145                 {
    1146                     $caption_type = null;
    1147                     $caption_lang = null;
    1148                     $caption_startTime = null;
    1149                     $caption_endTime = null;
    1150                     $caption_text = null;
    1151                     if (isset($caption['attribs']['']['type']))
    1152                     {
    1153                         $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1154                     }
    1155                     if (isset($caption['attribs']['']['lang']))
    1156                     {
    1157                         $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    1158                     }
    1159                     if (isset($caption['attribs']['']['start']))
    1160                     {
    1161                         $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
    1162                     }
    1163                     if (isset($caption['attribs']['']['end']))
    1164                     {
    1165                         $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
    1166                     }
    1167                     if (isset($caption['data']))
    1168                     {
    1169                         $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1170                     }
    1171                     $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
    1172                 }
    1173             }
    1174             if (is_array($captions_parent))
    1175             {
    1176                 $captions_parent = array_values(array_unique($captions_parent));
    1177             }
    1178 
    1179             // CATEGORIES
    1180             foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
    1181             {
    1182                 $term = null;
    1183                 $scheme = null;
    1184                 $label = null;
    1185                 if (isset($category['data']))
    1186                 {
    1187                     $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1188                 }
    1189                 if (isset($category['attribs']['']['scheme']))
    1190                 {
    1191                     $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1192                 }
    1193                 else
    1194                 {
    1195                     $scheme = 'http://search.yahoo.com/mrss/category_schema';
    1196                 }
    1197                 if (isset($category['attribs']['']['label']))
    1198                 {
    1199                     $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
    1200                 }
    1201                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
    1202             }
    1203             foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
    1204             {
    1205                 $term = null;
    1206                 $scheme = null;
    1207                 $label = null;
    1208                 if (isset($category['data']))
    1209                 {
    1210                     $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1211                 }
    1212                 if (isset($category['attribs']['']['scheme']))
    1213                 {
    1214                     $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1215                 }
    1216                 else
    1217                 {
    1218                     $scheme = 'http://search.yahoo.com/mrss/category_schema';
    1219                 }
    1220                 if (isset($category['attribs']['']['label']))
    1221                 {
    1222                     $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
    1223                 }
    1224                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
    1225             }
    1226             foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
    1227             {
    1228                 $term = null;
    1229                 $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
    1230                 $label = null;
    1231                 if (isset($category['attribs']['']['text']))
    1232                 {
    1233                     $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
    1234                 }
    1235                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
    1236 
    1237                 if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
    1238                 {
    1239                     foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
    1240                     {
    1241                         if (isset($subcategory['attribs']['']['text']))
    1242                         {
    1243                             $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
    1244                         }
    1245                         $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
    1246                     }
    1247                 }
    1248             }
    1249             if (is_array($categories_parent))
    1250             {
    1251                 $categories_parent = array_values(array_unique($categories_parent));
    1252             }
    1253 
    1254             // COPYRIGHT
    1255             if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
    1256             {
    1257                 $copyright_url = null;
    1258                 $copyright_label = null;
    1259                 if (isset($copyright[0]['attribs']['']['url']))
    1260                 {
    1261                     $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
    1262                 }
    1263                 if (isset($copyright[0]['data']))
    1264                 {
    1265                     $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1266                 }
    1267                 $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
    1268             }
    1269             elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
    1270             {
    1271                 $copyright_url = null;
    1272                 $copyright_label = null;
    1273                 if (isset($copyright[0]['attribs']['']['url']))
    1274                 {
    1275                     $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
    1276                 }
    1277                 if (isset($copyright[0]['data']))
    1278                 {
    1279                     $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1280                 }
    1281                 $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
    1282             }
    1283 
    1284             // CREDITS
    1285             if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
    1286             {
    1287                 foreach ($credits as $credit)
    1288                 {
    1289                     $credit_role = null;
    1290                     $credit_scheme = null;
    1291                     $credit_name = null;
    1292                     if (isset($credit['attribs']['']['role']))
    1293                     {
    1294                         $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
    1295                     }
    1296                     if (isset($credit['attribs']['']['scheme']))
    1297                     {
    1298                         $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1299                     }
    1300                     else
    1301                     {
    1302                         $credit_scheme = 'urn:ebu';
    1303                     }
    1304                     if (isset($credit['data']))
    1305                     {
    1306                         $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1307                     }
    1308                     $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
    1309                 }
    1310             }
    1311             elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
    1312             {
    1313                 foreach ($credits as $credit)
    1314                 {
    1315                     $credit_role = null;
    1316                     $credit_scheme = null;
    1317                     $credit_name = null;
    1318                     if (isset($credit['attribs']['']['role']))
    1319                     {
    1320                         $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
    1321                     }
    1322                     if (isset($credit['attribs']['']['scheme']))
    1323                     {
    1324                         $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1325                     }
    1326                     else
    1327                     {
    1328                         $credit_scheme = 'urn:ebu';
    1329                     }
    1330                     if (isset($credit['data']))
    1331                     {
    1332                         $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1333                     }
    1334                     $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
    1335                 }
    1336             }
    1337             if (is_array($credits_parent))
    1338             {
    1339                 $credits_parent = array_values(array_unique($credits_parent));
    1340             }
    1341 
    1342             // DESCRIPTION
    1343             if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
    1344             {
    1345                 if (isset($description_parent[0]['data']))
    1346                 {
    1347                     $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1348                 }
    1349             }
    1350             elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
    1351             {
    1352                 if (isset($description_parent[0]['data']))
    1353                 {
    1354                     $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1355                 }
    1356             }
    1357 
    1358             // DURATION
    1359             if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
    1360             {
    1361                 $seconds = null;
    1362                 $minutes = null;
    1363                 $hours = null;
    1364                 if (isset($duration_parent[0]['data']))
    1365                 {
    1366                     $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    1367                     if (sizeof($temp) > 0)
    1368                     {
    1369                         $seconds = (int) array_pop($temp);
    1370                     }
    1371                     if (sizeof($temp) > 0)
    1372                     {
    1373                         $minutes = (int) array_pop($temp);
    1374                         $seconds += $minutes * 60;
    1375                     }
    1376                     if (sizeof($temp) > 0)
    1377                     {
    1378                         $hours = (int) array_pop($temp);
    1379                         $seconds += $hours * 3600;
    1380                     }
    1381                     unset($temp);
    1382                     $duration_parent = $seconds;
    1383                 }
    1384             }
    1385 
    1386             // HASHES
    1387             if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
    1388             {
    1389                 foreach ($hashes_iterator as $hash)
    1390                 {
    1391                     $value = null;
    1392                     $algo = null;
    1393                     if (isset($hash['data']))
    1394                     {
    1395                         $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1396                     }
    1397                     if (isset($hash['attribs']['']['algo']))
    1398                     {
    1399                         $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
    1400                     }
    1401                     else
    1402                     {
    1403                         $algo = 'md5';
    1404                     }
    1405                     $hashes_parent[] = $algo.':'.$value;
    1406                 }
    1407             }
    1408             elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
    1409             {
    1410                 foreach ($hashes_iterator as $hash)
    1411                 {
    1412                     $value = null;
    1413                     $algo = null;
    1414                     if (isset($hash['data']))
    1415                     {
    1416                         $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1417                     }
    1418                     if (isset($hash['attribs']['']['algo']))
    1419                     {
    1420                         $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
    1421                     }
    1422                     else
    1423                     {
    1424                         $algo = 'md5';
    1425                     }
    1426                     $hashes_parent[] = $algo.':'.$value;
    1427                 }
    1428             }
    1429             if (is_array($hashes_parent))
    1430             {
    1431                 $hashes_parent = array_values(array_unique($hashes_parent));
    1432             }
    1433 
    1434             // KEYWORDS
    1435             if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
    1436             {
    1437                 if (isset($keywords[0]['data']))
    1438                 {
    1439                     $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    1440                     foreach ($temp as $word)
    1441                     {
    1442                         $keywords_parent[] = trim($word);
    1443                     }
    1444                 }
    1445                 unset($temp);
    1446             }
    1447             elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
    1448             {
    1449                 if (isset($keywords[0]['data']))
    1450                 {
    1451                     $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    1452                     foreach ($temp as $word)
    1453                     {
    1454                         $keywords_parent[] = trim($word);
    1455                     }
    1456                 }
    1457                 unset($temp);
    1458             }
    1459             elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
    1460             {
    1461                 if (isset($keywords[0]['data']))
    1462                 {
    1463                     $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    1464                     foreach ($temp as $word)
    1465                     {
    1466                         $keywords_parent[] = trim($word);
    1467                     }
    1468                 }
    1469                 unset($temp);
    1470             }
    1471             elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
    1472             {
    1473                 if (isset($keywords[0]['data']))
    1474                 {
    1475                     $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    1476                     foreach ($temp as $word)
    1477                     {
    1478                         $keywords_parent[] = trim($word);
    1479                     }
    1480                 }
    1481                 unset($temp);
    1482             }
    1483             if (is_array($keywords_parent))
    1484             {
    1485                 $keywords_parent = array_values(array_unique($keywords_parent));
    1486             }
    1487 
    1488             // PLAYER
    1489             if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
    1490             {
    1491                 if (isset($player_parent[0]['attribs']['']['url']))
    1492                 {
    1493                     $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    1494                 }
    1495             }
    1496             elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
    1497             {
    1498                 if (isset($player_parent[0]['attribs']['']['url']))
    1499                 {
    1500                     $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    1501                 }
    1502             }
    1503 
    1504             // RATINGS
    1505             if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
    1506             {
    1507                 foreach ($ratings as $rating)
    1508                 {
    1509                     $rating_scheme = null;
    1510                     $rating_value = null;
    1511                     if (isset($rating['attribs']['']['scheme']))
    1512                     {
    1513                         $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1514                     }
    1515                     else
    1516                     {
    1517                         $rating_scheme = 'urn:simple';
    1518                     }
    1519                     if (isset($rating['data']))
    1520                     {
    1521                         $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1522                     }
    1523                     $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    1524                 }
    1525             }
    1526             elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
    1527             {
    1528                 foreach ($ratings as $rating)
    1529                 {
    1530                     $rating_scheme = 'urn:itunes';
    1531                     $rating_value = null;
    1532                     if (isset($rating['data']))
    1533                     {
    1534                         $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1535                     }
    1536                     $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    1537                 }
    1538             }
    1539             elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
    1540             {
    1541                 foreach ($ratings as $rating)
    1542                 {
    1543                     $rating_scheme = null;
    1544                     $rating_value = null;
    1545                     if (isset($rating['attribs']['']['scheme']))
    1546                     {
    1547                         $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1548                     }
    1549                     else
    1550                     {
    1551                         $rating_scheme = 'urn:simple';
    1552                     }
    1553                     if (isset($rating['data']))
    1554                     {
    1555                         $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1556                     }
    1557                     $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    1558                 }
    1559             }
    1560             elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
    1561             {
    1562                 foreach ($ratings as $rating)
    1563                 {
    1564                     $rating_scheme = 'urn:itunes';
    1565                     $rating_value = null;
    1566                     if (isset($rating['data']))
    1567                     {
    1568                         $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1569                     }
    1570                     $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    1571                 }
    1572             }
    1573             if (is_array($ratings_parent))
    1574             {
    1575                 $ratings_parent = array_values(array_unique($ratings_parent));
    1576             }
    1577 
    1578             // RESTRICTIONS
    1579             if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
    1580             {
    1581                 foreach ($restrictions as $restriction)
    1582                 {
    1583                     $restriction_relationship = null;
    1584                     $restriction_type = null;
    1585                     $restriction_value = null;
    1586                     if (isset($restriction['attribs']['']['relationship']))
    1587                     {
    1588                         $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
    1589                     }
    1590                     if (isset($restriction['attribs']['']['type']))
    1591                     {
    1592                         $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1593                     }
    1594                     if (isset($restriction['data']))
    1595                     {
    1596                         $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1597                     }
    1598                     $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    1599                 }
    1600             }
    1601             elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
    1602             {
    1603                 foreach ($restrictions as $restriction)
    1604                 {
    1605                     $restriction_relationship = 'allow';
    1606                     $restriction_type = null;
    1607                     $restriction_value = 'itunes';
    1608                     if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
    1609                     {
    1610                         $restriction_relationship = 'deny';
    1611                     }
    1612                     $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    1613                 }
    1614             }
    1615             elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
    1616             {
    1617                 foreach ($restrictions as $restriction)
    1618                 {
    1619                     $restriction_relationship = null;
    1620                     $restriction_type = null;
    1621                     $restriction_value = null;
    1622                     if (isset($restriction['attribs']['']['relationship']))
    1623                     {
    1624                         $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
    1625                     }
    1626                     if (isset($restriction['attribs']['']['type']))
    1627                     {
    1628                         $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1629                     }
    1630                     if (isset($restriction['data']))
    1631                     {
    1632                         $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1633                     }
    1634                     $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    1635                 }
    1636             }
    1637             elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
    1638             {
    1639                 foreach ($restrictions as $restriction)
    1640                 {
    1641                     $restriction_relationship = 'allow';
    1642                     $restriction_type = null;
    1643                     $restriction_value = 'itunes';
    1644                     if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
    1645                     {
    1646                         $restriction_relationship = 'deny';
    1647                     }
    1648                     $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    1649                 }
    1650             }
    1651             if (is_array($restrictions_parent))
    1652             {
    1653                 $restrictions_parent = array_values(array_unique($restrictions_parent));
    1654             }
    1655             else
    1656             {
    1657                 $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
    1658             }
    1659 
    1660             // THUMBNAILS
    1661             if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
    1662             {
    1663                 foreach ($thumbnails as $thumbnail)
    1664                 {
    1665                     if (isset($thumbnail['attribs']['']['url']))
    1666                     {
    1667                         $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    1668                     }
    1669                 }
    1670             }
    1671             elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
    1672             {
    1673                 foreach ($thumbnails as $thumbnail)
    1674                 {
    1675                     if (isset($thumbnail['attribs']['']['url']))
    1676                     {
    1677                         $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    1678                     }
    1679                 }
    1680             }
    1681 
    1682             // TITLES
    1683             if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
    1684             {
    1685                 if (isset($title_parent[0]['data']))
    1686                 {
    1687                     $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1688                 }
    1689             }
    1690             elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
    1691             {
    1692                 if (isset($title_parent[0]['data']))
    1693                 {
    1694                     $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1695                 }
    1696             }
    1697 
    1698             // Clear the memory
    1699             unset($parent);
    1700 
    1701             // Attributes
    1702             $bitrate = null;
    1703             $channels = null;
    1704             $duration = null;
    1705             $expression = null;
    1706             $framerate = null;
    1707             $height = null;
    1708             $javascript = null;
    1709             $lang = null;
    1710             $length = null;
    1711             $medium = null;
    1712             $samplingrate = null;
    1713             $type = null;
    1714             $url = null;
    1715             $width = null;
    1716 
    1717             // Elements
    1718             $captions = null;
    1719             $categories = null;
    1720             $copyrights = null;
    1721             $credits = null;
    1722             $description = null;
    1723             $hashes = null;
    1724             $keywords = null;
    1725             $player = null;
    1726             $ratings = null;
    1727             $restrictions = null;
    1728             $thumbnails = null;
    1729             $title = null;
    1730 
    1731             // If we have media:group tags, loop through them.
    1732             foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
    1733             {
    1734                 if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
    1735                 {
    1736                     // If we have media:content tags, loop through them.
    1737                     foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
    1738                     {
    1739                         if (isset($content['attribs']['']['url']))
    1740                         {
    1741                             // Attributes
    1742                             $bitrate = null;
    1743                             $channels = null;
    1744                             $duration = null;
    1745                             $expression = null;
    1746                             $framerate = null;
    1747                             $height = null;
    1748                             $javascript = null;
    1749                             $lang = null;
    1750                             $length = null;
    1751                             $medium = null;
    1752                             $samplingrate = null;
    1753                             $type = null;
    1754                             $url = null;
    1755                             $width = null;
    1756 
    1757                             // Elements
    1758                             $captions = null;
    1759                             $categories = null;
    1760                             $copyrights = null;
    1761                             $credits = null;
    1762                             $description = null;
    1763                             $hashes = null;
    1764                             $keywords = null;
    1765                             $player = null;
    1766                             $ratings = null;
    1767                             $restrictions = null;
    1768                             $thumbnails = null;
    1769                             $title = null;
    1770 
    1771                             // Start checking the attributes of media:content
    1772                             if (isset($content['attribs']['']['bitrate']))
    1773                             {
    1774                                 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
    1775                             }
    1776                             if (isset($content['attribs']['']['channels']))
    1777                             {
    1778                                 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
    1779                             }
    1780                             if (isset($content['attribs']['']['duration']))
    1781                             {
    1782                                 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
    1783                             }
    1784                             else
    1785                             {
    1786                                 $duration = $duration_parent;
    1787                             }
    1788                             if (isset($content['attribs']['']['expression']))
    1789                             {
    1790                                 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
    1791                             }
    1792                             if (isset($content['attribs']['']['framerate']))
    1793                             {
    1794                                 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
    1795                             }
    1796                             if (isset($content['attribs']['']['height']))
    1797                             {
    1798                                 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
    1799                             }
    1800                             if (isset($content['attribs']['']['lang']))
    1801                             {
    1802                                 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    1803                             }
    1804                             if (isset($content['attribs']['']['fileSize']))
    1805                             {
    1806                                 $length = intval($content['attribs']['']['fileSize']);
    1807                             }
    1808                             if (isset($content['attribs']['']['medium']))
    1809                             {
    1810                                 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
    1811                             }
    1812                             if (isset($content['attribs']['']['samplingrate']))
    1813                             {
    1814                                 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
    1815                             }
    1816                             if (isset($content['attribs']['']['type']))
    1817                             {
    1818                                 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1819                             }
    1820                             if (isset($content['attribs']['']['width']))
    1821                             {
    1822                                 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
    1823                             }
    1824                             $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    1825 
    1826                             // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
    1827 
    1828                             // CAPTIONS
    1829                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
    1830                             {
    1831                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
    1832                                 {
    1833                                     $caption_type = null;
    1834                                     $caption_lang = null;
    1835                                     $caption_startTime = null;
    1836                                     $caption_endTime = null;
    1837                                     $caption_text = null;
    1838                                     if (isset($caption['attribs']['']['type']))
    1839                                     {
    1840                                         $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1841                                     }
    1842                                     if (isset($caption['attribs']['']['lang']))
    1843                                     {
    1844                                         $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    1845                                     }
    1846                                     if (isset($caption['attribs']['']['start']))
    1847                                     {
    1848                                         $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
    1849                                     }
    1850                                     if (isset($caption['attribs']['']['end']))
    1851                                     {
    1852                                         $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
    1853                                     }
    1854                                     if (isset($caption['data']))
    1855                                     {
    1856                                         $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1857                                     }
    1858                                     $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
    1859                                 }
    1860                                 if (is_array($captions))
    1861                                 {
    1862                                     $captions = array_values(array_unique($captions));
    1863                                 }
    1864                             }
    1865                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
    1866                             {
    1867                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
    1868                                 {
    1869                                     $caption_type = null;
    1870                                     $caption_lang = null;
    1871                                     $caption_startTime = null;
    1872                                     $caption_endTime = null;
    1873                                     $caption_text = null;
    1874                                     if (isset($caption['attribs']['']['type']))
    1875                                     {
    1876                                         $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    1877                                     }
    1878                                     if (isset($caption['attribs']['']['lang']))
    1879                                     {
    1880                                         $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    1881                                     }
    1882                                     if (isset($caption['attribs']['']['start']))
    1883                                     {
    1884                                         $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
    1885                                     }
    1886                                     if (isset($caption['attribs']['']['end']))
    1887                                     {
    1888                                         $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
    1889                                     }
    1890                                     if (isset($caption['data']))
    1891                                     {
    1892                                         $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1893                                     }
    1894                                     $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
    1895                                 }
    1896                                 if (is_array($captions))
    1897                                 {
    1898                                     $captions = array_values(array_unique($captions));
    1899                                 }
    1900                             }
    1901                             else
    1902                             {
    1903                                 $captions = $captions_parent;
    1904                             }
    1905 
    1906                             // CATEGORIES
    1907                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
    1908                             {
    1909                                 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
    1910                                 {
    1911                                     $term = null;
    1912                                     $scheme = null;
    1913                                     $label = null;
    1914                                     if (isset($category['data']))
    1915                                     {
    1916                                         $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1917                                     }
    1918                                     if (isset($category['attribs']['']['scheme']))
    1919                                     {
    1920                                         $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1921                                     }
    1922                                     else
    1923                                     {
    1924                                         $scheme = 'http://search.yahoo.com/mrss/category_schema';
    1925                                     }
    1926                                     if (isset($category['attribs']['']['label']))
    1927                                     {
    1928                                         $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
    1929                                     }
    1930                                     $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
    1931                                 }
    1932                             }
    1933                             if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
    1934                             {
    1935                                 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
    1936                                 {
    1937                                     $term = null;
    1938                                     $scheme = null;
    1939                                     $label = null;
    1940                                     if (isset($category['data']))
    1941                                     {
    1942                                         $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1943                                     }
    1944                                     if (isset($category['attribs']['']['scheme']))
    1945                                     {
    1946                                         $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    1947                                     }
    1948                                     else
    1949                                     {
    1950                                         $scheme = 'http://search.yahoo.com/mrss/category_schema';
    1951                                     }
    1952                                     if (isset($category['attribs']['']['label']))
    1953                                     {
    1954                                         $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
    1955                                     }
    1956                                     $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
    1957                                 }
    1958                             }
    1959                             if (is_array($categories) && is_array($categories_parent))
    1960                             {
    1961                                 $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
    1962                             }
    1963                             elseif (is_array($categories))
    1964                             {
    1965                                 $categories = array_values(array_unique($categories));
    1966                             }
    1967                             elseif (is_array($categories_parent))
    1968                             {
    1969                                 $categories = array_values(array_unique($categories_parent));
    1970                             }
    1971 
    1972                             // COPYRIGHTS
    1973                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
    1974                             {
    1975                                 $copyright_url = null;
    1976                                 $copyright_label = null;
    1977                                 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
    1978                                 {
    1979                                     $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
    1980                                 }
    1981                                 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
    1982                                 {
    1983                                     $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1984                                 }
    1985                                 $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
    1986                             }
    1987                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
    1988                             {
    1989                                 $copyright_url = null;
    1990                                 $copyright_label = null;
    1991                                 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
    1992                                 {
    1993                                     $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
    1994                                 }
    1995                                 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
    1996                                 {
    1997                                     $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    1998                                 }
    1999                                 $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
    2000                             }
    2001                             else
    2002                             {
    2003                                 $copyrights = $copyrights_parent;
    2004                             }
    2005 
    2006                             // CREDITS
    2007                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
    2008                             {
    2009                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
    2010                                 {
    2011                                     $credit_role = null;
    2012                                     $credit_scheme = null;
    2013                                     $credit_name = null;
    2014                                     if (isset($credit['attribs']['']['role']))
    2015                                     {
    2016                                         $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
    2017                                     }
    2018                                     if (isset($credit['attribs']['']['scheme']))
    2019                                     {
    2020                                         $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2021                                     }
    2022                                     else
    2023                                     {
    2024                                         $credit_scheme = 'urn:ebu';
    2025                                     }
    2026                                     if (isset($credit['data']))
    2027                                     {
    2028                                         $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2029                                     }
    2030                                     $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
    2031                                 }
    2032                                 if (is_array($credits))
    2033                                 {
    2034                                     $credits = array_values(array_unique($credits));
    2035                                 }
    2036                             }
    2037                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
    2038                             {
    2039                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
    2040                                 {
    2041                                     $credit_role = null;
    2042                                     $credit_scheme = null;
    2043                                     $credit_name = null;
    2044                                     if (isset($credit['attribs']['']['role']))
    2045                                     {
    2046                                         $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
    2047                                     }
    2048                                     if (isset($credit['attribs']['']['scheme']))
    2049                                     {
    2050                                         $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2051                                     }
    2052                                     else
    2053                                     {
    2054                                         $credit_scheme = 'urn:ebu';
    2055                                     }
    2056                                     if (isset($credit['data']))
    2057                                     {
    2058                                         $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2059                                     }
    2060                                     $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
    2061                                 }
    2062                                 if (is_array($credits))
    2063                                 {
    2064                                     $credits = array_values(array_unique($credits));
    2065                                 }
    2066                             }
    2067                             else
    2068                             {
    2069                                 $credits = $credits_parent;
    2070                             }
    2071 
    2072                             // DESCRIPTION
    2073                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
    2074                             {
    2075                                 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2076                             }
    2077                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
    2078                             {
    2079                                 $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2080                             }
    2081                             else
    2082                             {
    2083                                 $description = $description_parent;
    2084                             }
    2085 
    2086                             // HASHES
    2087                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
    2088                             {
    2089                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
    2090                                 {
    2091                                     $value = null;
    2092                                     $algo = null;
    2093                                     if (isset($hash['data']))
    2094                                     {
    2095                                         $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2096                                     }
    2097                                     if (isset($hash['attribs']['']['algo']))
    2098                                     {
    2099                                         $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
    2100                                     }
    2101                                     else
    2102                                     {
    2103                                         $algo = 'md5';
    2104                                     }
    2105                                     $hashes[] = $algo.':'.$value;
    2106                                 }
    2107                                 if (is_array($hashes))
    2108                                 {
    2109                                     $hashes = array_values(array_unique($hashes));
    2110                                 }
    2111                             }
    2112                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
    2113                             {
    2114                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
    2115                                 {
    2116                                     $value = null;
    2117                                     $algo = null;
    2118                                     if (isset($hash['data']))
    2119                                     {
    2120                                         $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2121                                     }
    2122                                     if (isset($hash['attribs']['']['algo']))
    2123                                     {
    2124                                         $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
    2125                                     }
    2126                                     else
    2127                                     {
    2128                                         $algo = 'md5';
    2129                                     }
    2130                                     $hashes[] = $algo.':'.$value;
    2131                                 }
    2132                                 if (is_array($hashes))
    2133                                 {
    2134                                     $hashes = array_values(array_unique($hashes));
    2135                                 }
    2136                             }
    2137                             else
    2138                             {
    2139                                 $hashes = $hashes_parent;
    2140                             }
    2141 
    2142                             // KEYWORDS
    2143                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
    2144                             {
    2145                                 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
    2146                                 {
    2147                                     $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    2148                                     foreach ($temp as $word)
    2149                                     {
    2150                                         $keywords[] = trim($word);
    2151                                     }
    2152                                     unset($temp);
    2153                                 }
    2154                                 if (is_array($keywords))
    2155                                 {
    2156                                     $keywords = array_values(array_unique($keywords));
    2157                                 }
    2158                             }
    2159                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
    2160                             {
    2161                                 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
    2162                                 {
    2163                                     $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    2164                                     foreach ($temp as $word)
    2165                                     {
    2166                                         $keywords[] = trim($word);
    2167                                     }
    2168                                     unset($temp);
    2169                                 }
    2170                                 if (is_array($keywords))
    2171                                 {
    2172                                     $keywords = array_values(array_unique($keywords));
    2173                                 }
    2174                             }
    2175                             else
    2176                             {
    2177                                 $keywords = $keywords_parent;
    2178                             }
    2179 
    2180                             // PLAYER
    2181                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
    2182                             {
    2183                                 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2184                             }
    2185                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
    2186                             {
    2187                                 $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2188                             }
    2189                             else
    2190                             {
    2191                                 $player = $player_parent;
    2192                             }
    2193 
    2194                             // RATINGS
    2195                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
    2196                             {
    2197                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
    2198                                 {
    2199                                     $rating_scheme = null;
    2200                                     $rating_value = null;
    2201                                     if (isset($rating['attribs']['']['scheme']))
    2202                                     {
    2203                                         $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2204                                     }
    2205                                     else
    2206                                     {
    2207                                         $rating_scheme = 'urn:simple';
    2208                                     }
    2209                                     if (isset($rating['data']))
    2210                                     {
    2211                                         $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2212                                     }
    2213                                     $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    2214                                 }
    2215                                 if (is_array($ratings))
    2216                                 {
    2217                                     $ratings = array_values(array_unique($ratings));
    2218                                 }
    2219                             }
    2220                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
    2221                             {
    2222                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
    2223                                 {
    2224                                     $rating_scheme = null;
    2225                                     $rating_value = null;
    2226                                     if (isset($rating['attribs']['']['scheme']))
    2227                                     {
    2228                                         $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2229                                     }
    2230                                     else
    2231                                     {
    2232                                         $rating_scheme = 'urn:simple';
    2233                                     }
    2234                                     if (isset($rating['data']))
    2235                                     {
    2236                                         $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2237                                     }
    2238                                     $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    2239                                 }
    2240                                 if (is_array($ratings))
    2241                                 {
    2242                                     $ratings = array_values(array_unique($ratings));
    2243                                 }
    2244                             }
    2245                             else
    2246                             {
    2247                                 $ratings = $ratings_parent;
    2248                             }
    2249 
    2250                             // RESTRICTIONS
    2251                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
    2252                             {
    2253                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
    2254                                 {
    2255                                     $restriction_relationship = null;
    2256                                     $restriction_type = null;
    2257                                     $restriction_value = null;
    2258                                     if (isset($restriction['attribs']['']['relationship']))
    2259                                     {
    2260                                         $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
    2261                                     }
    2262                                     if (isset($restriction['attribs']['']['type']))
    2263                                     {
    2264                                         $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2265                                     }
    2266                                     if (isset($restriction['data']))
    2267                                     {
    2268                                         $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2269                                     }
    2270                                     $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    2271                                 }
    2272                                 if (is_array($restrictions))
    2273                                 {
    2274                                     $restrictions = array_values(array_unique($restrictions));
    2275                                 }
    2276                             }
    2277                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
    2278                             {
    2279                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
    2280                                 {
    2281                                     $restriction_relationship = null;
    2282                                     $restriction_type = null;
    2283                                     $restriction_value = null;
    2284                                     if (isset($restriction['attribs']['']['relationship']))
    2285                                     {
    2286                                         $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
    2287                                     }
    2288                                     if (isset($restriction['attribs']['']['type']))
    2289                                     {
    2290                                         $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2291                                     }
    2292                                     if (isset($restriction['data']))
    2293                                     {
    2294                                         $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2295                                     }
    2296                                     $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    2297                                 }
    2298                                 if (is_array($restrictions))
    2299                                 {
    2300                                     $restrictions = array_values(array_unique($restrictions));
    2301                                 }
    2302                             }
    2303                             else
    2304                             {
    2305                                 $restrictions = $restrictions_parent;
    2306                             }
    2307 
    2308                             // THUMBNAILS
    2309                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
    2310                             {
    2311                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
    2312                                 {
    2313                                     $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2314                                 }
    2315                                 if (is_array($thumbnails))
    2316                                 {
    2317                                     $thumbnails = array_values(array_unique($thumbnails));
    2318                                 }
    2319                             }
    2320                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
    2321                             {
    2322                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
    2323                                 {
    2324                                     $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2325                                 }
    2326                                 if (is_array($thumbnails))
    2327                                 {
    2328                                     $thumbnails = array_values(array_unique($thumbnails));
    2329                                 }
    2330                             }
    2331                             else
    2332                             {
    2333                                 $thumbnails = $thumbnails_parent;
    2334                             }
    2335 
    2336                             // TITLES
    2337                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
    2338                             {
    2339                                 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2340                             }
    2341                             elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
    2342                             {
    2343                                 $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2344                             }
    2345                             else
    2346                             {
    2347                                 $title = $title_parent;
    2348                             }
    2349 
    2350                             $this->data['enclosures'][] = $this->registry->create('Enclosure', array($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));
    2351                         }
    2352                     }
    2353                 }
    2354             }
    2355 
    2356             // If we have standalone media:content tags, loop through them.
    2357             if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
    2358             {
    2359                 foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
    2360                 {
    2361                     if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
    2362                     {
    2363                         // Attributes
    2364                         $bitrate = null;
    2365                         $channels = null;
    2366                         $duration = null;
    2367                         $expression = null;
    2368                         $framerate = null;
    2369                         $height = null;
    2370                         $javascript = null;
    2371                         $lang = null;
    2372                         $length = null;
    2373                         $medium = null;
    2374                         $samplingrate = null;
    2375                         $type = null;
    2376                         $url = null;
    2377                         $width = null;
    2378 
    2379                         // Elements
    2380                         $captions = null;
    2381                         $categories = null;
    2382                         $copyrights = null;
    2383                         $credits = null;
    2384                         $description = null;
    2385                         $hashes = null;
    2386                         $keywords = null;
    2387                         $player = null;
    2388                         $ratings = null;
    2389                         $restrictions = null;
    2390                         $thumbnails = null;
    2391                         $title = null;
    2392 
    2393                         // Start checking the attributes of media:content
    2394                         if (isset($content['attribs']['']['bitrate']))
    2395                         {
    2396                             $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
    2397                         }
    2398                         if (isset($content['attribs']['']['channels']))
    2399                         {
    2400                             $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
    2401                         }
    2402                         if (isset($content['attribs']['']['duration']))
    2403                         {
    2404                             $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
    2405                         }
    2406                         else
    2407                         {
    2408                             $duration = $duration_parent;
    2409                         }
    2410                         if (isset($content['attribs']['']['expression']))
    2411                         {
    2412                             $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
    2413                         }
    2414                         if (isset($content['attribs']['']['framerate']))
    2415                         {
    2416                             $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
    2417                         }
    2418                         if (isset($content['attribs']['']['height']))
    2419                         {
    2420                             $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
    2421                         }
    2422                         if (isset($content['attribs']['']['lang']))
    2423                         {
    2424                             $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    2425                         }
    2426                         if (isset($content['attribs']['']['fileSize']))
    2427                         {
    2428                             $length = intval($content['attribs']['']['fileSize']);
    2429                         }
    2430                         if (isset($content['attribs']['']['medium']))
    2431                         {
    2432                             $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
    2433                         }
    2434                         if (isset($content['attribs']['']['samplingrate']))
    2435                         {
    2436                             $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
    2437                         }
    2438                         if (isset($content['attribs']['']['type']))
    2439                         {
    2440                             $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2441                         }
    2442                         if (isset($content['attribs']['']['width']))
    2443                         {
    2444                             $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
    2445                         }
    2446                         if (isset($content['attribs']['']['url']))
    2447                         {
    2448                             $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2449                         }
    2450                         // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
    2451 
    2452                         // CAPTIONS
    2453                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
    2454                         {
    2455                             foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
    2456                             {
    2457                                 $caption_type = null;
    2458                                 $caption_lang = null;
    2459                                 $caption_startTime = null;
    2460                                 $caption_endTime = null;
    2461                                 $caption_text = null;
    2462                                 if (isset($caption['attribs']['']['type']))
    2463                                 {
    2464                                     $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2465                                 }
    2466                                 if (isset($caption['attribs']['']['lang']))
    2467                                 {
    2468                                     $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
    2469                                 }
    2470                                 if (isset($caption['attribs']['']['start']))
    2471                                 {
    2472                                     $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
    2473                                 }
    2474                                 if (isset($caption['attribs']['']['end']))
    2475                                 {
    2476                                     $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
    2477                                 }
    2478                                 if (isset($caption['data']))
    2479                                 {
    2480                                     $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2481                                 }
    2482                                 $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
    2483                             }
    2484                             if (is_array($captions))
    2485                             {
    2486                                 $captions = array_values(array_unique($captions));
    2487                             }
    2488                         }
    2489                         else
    2490                         {
    2491                             $captions = $captions_parent;
    2492                         }
    2493 
    2494                         // CATEGORIES
    2495                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
    2496                         {
    2497                             foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
    2498                             {
    2499                                 $term = null;
    2500                                 $scheme = null;
    2501                                 $label = null;
    2502                                 if (isset($category['data']))
    2503                                 {
    2504                                     $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2505                                 }
    2506                                 if (isset($category['attribs']['']['scheme']))
    2507                                 {
    2508                                     $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2509                                 }
    2510                                 else
    2511                                 {
    2512                                     $scheme = 'http://search.yahoo.com/mrss/category_schema';
    2513                                 }
    2514                                 if (isset($category['attribs']['']['label']))
    2515                                 {
    2516                                     $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
    2517                                 }
    2518                                 $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
    2519                             }
    2520                         }
    2521                         if (is_array($categories) && is_array($categories_parent))
    2522                         {
    2523                             $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
    2524                         }
    2525                         elseif (is_array($categories))
    2526                         {
    2527                             $categories = array_values(array_unique($categories));
    2528                         }
    2529                         elseif (is_array($categories_parent))
    2530                         {
    2531                             $categories = array_values(array_unique($categories_parent));
    2532                         }
    2533                         else
    2534                         {
    2535                             $categories = null;
    2536                         }
    2537 
    2538                         // COPYRIGHTS
    2539                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
    2540                         {
    2541                             $copyright_url = null;
    2542                             $copyright_label = null;
    2543                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
    2544                             {
    2545                                 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
    2546                             }
    2547                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
    2548                             {
    2549                                 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2550                             }
    2551                             $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
    2552                         }
    2553                         else
    2554                         {
    2555                             $copyrights = $copyrights_parent;
    2556                         }
    2557 
    2558                         // CREDITS
    2559                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
    2560                         {
    2561                             foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
    2562                             {
    2563                                 $credit_role = null;
    2564                                 $credit_scheme = null;
    2565                                 $credit_name = null;
    2566                                 if (isset($credit['attribs']['']['role']))
    2567                                 {
    2568                                     $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
    2569                                 }
    2570                                 if (isset($credit['attribs']['']['scheme']))
    2571                                 {
    2572                                     $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2573                                 }
    2574                                 else
    2575                                 {
    2576                                     $credit_scheme = 'urn:ebu';
    2577                                 }
    2578                                 if (isset($credit['data']))
    2579                                 {
    2580                                     $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2581                                 }
    2582                                 $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
    2583                             }
    2584                             if (is_array($credits))
    2585                             {
    2586                                 $credits = array_values(array_unique($credits));
    2587                             }
    2588                         }
    2589                         else
    2590                         {
    2591                             $credits = $credits_parent;
    2592                         }
    2593 
    2594                         // DESCRIPTION
    2595                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
    2596                         {
    2597                             $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2598                         }
    2599                         else
    2600                         {
    2601                             $description = $description_parent;
    2602                         }
    2603 
    2604                         // HASHES
    2605                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
    2606                         {
    2607                             foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
    2608                             {
    2609                                 $value = null;
    2610                                 $algo = null;
    2611                                 if (isset($hash['data']))
    2612                                 {
    2613                                     $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2614                                 }
    2615                                 if (isset($hash['attribs']['']['algo']))
    2616                                 {
    2617                                     $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
    2618                                 }
    2619                                 else
    2620                                 {
    2621                                     $algo = 'md5';
    2622                                 }
    2623                                 $hashes[] = $algo.':'.$value;
    2624                             }
    2625                             if (is_array($hashes))
    2626                             {
    2627                                 $hashes = array_values(array_unique($hashes));
    2628                             }
    2629                         }
    2630                         else
    2631                         {
    2632                             $hashes = $hashes_parent;
    2633                         }
    2634 
    2635                         // KEYWORDS
    2636                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
    2637                         {
    2638                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
    2639                             {
    2640                                 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
    2641                                 foreach ($temp as $word)
    2642                                 {
    2643                                     $keywords[] = trim($word);
    2644                                 }
    2645                                 unset($temp);
    2646                             }
    2647                             if (is_array($keywords))
    2648                             {
    2649                                 $keywords = array_values(array_unique($keywords));
    2650                             }
    2651                         }
    2652                         else
    2653                         {
    2654                             $keywords = $keywords_parent;
    2655                         }
    2656 
    2657                         // PLAYER
    2658                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
    2659                         {
    2660                             if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'])) {
    2661                                 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2662                             }
    2663                         }
    2664                         else
    2665                         {
    2666                             $player = $player_parent;
    2667                         }
    2668 
    2669                         // RATINGS
    2670                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
    2671                         {
    2672                             foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
    2673                             {
    2674                                 $rating_scheme = null;
    2675                                 $rating_value = null;
    2676                                 if (isset($rating['attribs']['']['scheme']))
    2677                                 {
    2678                                     $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
    2679                                 }
    2680                                 else
    2681                                 {
    2682                                     $rating_scheme = 'urn:simple';
    2683                                 }
    2684                                 if (isset($rating['data']))
    2685                                 {
    2686                                     $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2687                                 }
    2688                                 $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
    2689                             }
    2690                             if (is_array($ratings))
    2691                             {
    2692                                 $ratings = array_values(array_unique($ratings));
    2693                             }
    2694                         }
    2695                         else
    2696                         {
    2697                             $ratings = $ratings_parent;
    2698                         }
    2699 
    2700                         // RESTRICTIONS
    2701                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
    2702                         {
    2703                             foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
    2704                             {
    2705                                 $restriction_relationship = null;
    2706                                 $restriction_type = null;
    2707                                 $restriction_value = null;
    2708                                 if (isset($restriction['attribs']['']['relationship']))
    2709                                 {
    2710                                     $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
    2711                                 }
    2712                                 if (isset($restriction['attribs']['']['type']))
    2713                                 {
    2714                                     $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2715                                 }
    2716                                 if (isset($restriction['data']))
    2717                                 {
    2718                                     $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2719                                 }
    2720                                 $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
    2721                             }
    2722                             if (is_array($restrictions))
    2723                             {
    2724                                 $restrictions = array_values(array_unique($restrictions));
    2725                             }
    2726                         }
    2727                         else
    2728                         {
    2729                             $restrictions = $restrictions_parent;
    2730                         }
    2731 
    2732                         // THUMBNAILS
    2733                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
    2734                         {
    2735                             foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
    2736                             {
    2737                                 if (isset($thumbnail['attribs']['']['url'])) {
    2738                                     $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
    2739                                 }
    2740                             }
    2741                             if (is_array($thumbnails))
    2742                             {
    2743                                 $thumbnails = array_values(array_unique($thumbnails));
    2744                             }
    2745                         }
    2746                         else
    2747                         {
    2748                             $thumbnails = $thumbnails_parent;
    2749                         }
    2750 
    2751                         // TITLES
    2752                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
    2753                         {
    2754                             $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    2755                         }
    2756                         else
    2757                         {
    2758                             $title = $title_parent;
    2759                         }
    2760 
    2761                         $this->data['enclosures'][] = $this->registry->create('Enclosure', array($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));
    2762                     }
    2763                 }
    2764             }
    2765 
    2766             foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
    2767             {
    2768                 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
    2769                 {
    2770                     // Attributes
    2771                     $bitrate = null;
    2772                     $channels = null;
    2773                     $duration = null;
    2774                     $expression = null;
    2775                     $framerate = null;
    2776                     $height = null;
    2777                     $javascript = null;
    2778                     $lang = null;
    2779                     $length = null;
    2780                     $medium = null;
    2781                     $samplingrate = null;
    2782                     $type = null;
    2783                     $url = null;
    2784                     $width = null;
    2785 
    2786                     $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
    2787                     if (isset($link['attribs']['']['type']))
    2788                     {
    2789                         $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2790                     }
    2791                     if (isset($link['attribs']['']['length']))
    2792                     {
    2793                         $length = intval($link['attribs']['']['length']);
    2794                     }
    2795                     if (isset($link['attribs']['']['title']))
    2796                     {
    2797                         $title = $this->sanitize($link['attribs']['']['title'], SIMPLEPIE_CONSTRUCT_TEXT);
    2798                     }
    2799                     else
    2800                     {
    2801                         $title = $title_parent;
    2802                     }
    2803 
    2804                     // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
    2805                     $this->data['enclosures'][] = $this->registry->create('Enclosure', array($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));
    2806                 }
    2807             }
    2808 
    2809             foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
    2810             {
    2811                 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
    2812                 {
    2813                     // Attributes
    2814                     $bitrate = null;
    2815                     $channels = null;
    2816                     $duration = null;
    2817                     $expression = null;
    2818                     $framerate = null;
    2819                     $height = null;
    2820                     $javascript = null;
    2821                     $lang = null;
    2822                     $length = null;
    2823                     $medium = null;
    2824                     $samplingrate = null;
    2825                     $type = null;
    2826                     $url = null;
    2827                     $width = null;
    2828 
    2829                     $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
    2830                     if (isset($link['attribs']['']['type']))
    2831                     {
    2832                         $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2833                     }
    2834                     if (isset($link['attribs']['']['length']))
    2835                     {
    2836                         $length = intval($link['attribs']['']['length']);
    2837                     }
    2838 
    2839                     // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
    2840                     $this->data['enclosures'][] = $this->registry->create('Enclosure', array($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));
    2841                 }
    2842             }
    2843 
    2844             if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
    2845             {
    2846                 if (isset($enclosure[0]['attribs']['']['url']))
    2847                 {
    2848                     // Attributes
    2849                     $bitrate = null;
    2850                     $channels = null;
    2851                     $duration = null;
    2852                     $expression = null;
    2853                     $framerate = null;
    2854                     $height = null;
    2855                     $javascript = null;
    2856                     $lang = null;
    2857                     $length = null;
    2858                     $medium = null;
    2859                     $samplingrate = null;
    2860                     $type = null;
    2861                     $url = null;
    2862                     $width = null;
    2863 
    2864                     $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
    2865                     $url = $this->feed->sanitize->https_url($url);
    2866                     if (isset($enclosure[0]['attribs']['']['type']))
    2867                     {
    2868                         $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
    2869                     }
    2870                     if (isset($enclosure[0]['attribs']['']['length']))
    2871                     {
    2872                         $length = intval($enclosure[0]['attribs']['']['length']);
    2873                     }
    2874 
    2875                     // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
    2876                     $this->data['enclosures'][] = $this->registry->create('Enclosure', array($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));
    2877                 }
    2878             }
    2879 
    2880             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))
    2881             {
    2882                 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
    2883                 $this->data['enclosures'][] = $this->registry->create('Enclosure', array($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));
    2884             }
    2885 
    2886             $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
    2887         }
    2888         if (!empty($this->data['enclosures']))
    2889         {
    2890             return $this->data['enclosures'];
    2891         }
    2892 
    2893         return null;
    2894     }
    2895 
    2896     /**
    2897      * Get the latitude coordinates for the item
    2898      *
    2899      * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
    2900      *
    2901      * Uses `<geo:lat>` or `<georss:point>`
    2902      *
    2903      * @since 1.0
    2904      * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
    2905      * @link http://www.georss.org/ GeoRSS
    2906      * @return string|null
    2907      */
    2908     public function get_latitude()
    2909     {
    2910         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
    2911         {
    2912             return (float) $return[0]['data'];
    2913         }
    2914         elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
    2915         {
    2916             return (float) $match[1];
    2917         }
    2918 
    2919         return null;
    2920     }
    2921 
    2922     /**
    2923      * Get the longitude coordinates for the item
    2924      *
    2925      * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
    2926      *
    2927      * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
    2928      *
    2929      * @since 1.0
    2930      * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
    2931      * @link http://www.georss.org/ GeoRSS
    2932      * @return string|null
    2933      */
    2934     public function get_longitude()
    2935     {
    2936         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
    2937         {
    2938             return (float) $return[0]['data'];
    2939         }
    2940         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
    2941         {
    2942             return (float) $return[0]['data'];
    2943         }
    2944         elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
    2945         {
    2946             return (float) $match[2];
    2947         }
    2948 
    2949         return null;
    2950     }
    2951 
    2952     /**
    2953      * Get the `<atom:source>` for the item
    2954      *
    2955      * @since 1.1
    2956      * @return SimplePie_Source|null
    2957      */
    2958     public function get_source()
    2959     {
    2960         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
    2961         {
    2962             return $this->registry->create('Source', array($this, $return[0]));
    2963         }
    2964 
    2965         return null;
    2966     }
     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    }
    29672357}
     2358
     2359class_alias('SimplePie\Item', 'SimplePie_Item');
Note: See TracChangeset for help on using the changeset viewer.