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