5ffc2d2112a841d551837f46d1469b9de05e11d6
[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          * @return string
210          */
211         public function get_id($hash = false, $fn = '')
212         {
213                 if (!$hash)
214                 {
215                         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
216                         {
217                                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
218                         }
219                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
220                         {
221                                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
222                         }
223                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
224                         {
225                                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
226                         }
227                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
228                         {
229                                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
230                         }
231                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
232                         {
233                                 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
234                         }
235                         elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
236                         {
237                                 return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
238                         }
239                 }
240                 if ($fn === '' || !is_callable($fn)) $fn = 'md5';
241                 return call_user_func($fn,
242                        $this->get_permalink().$this->get_title().$this->get_content());
243         }
245         /**
246          * Get the title of the item
247          *
248          * Uses `<atom:title>`, `<title>` or `<dc:title>`
249          *
250          * @since Beta 2 (previously called `get_item_title` since 0.8)
251          * @return string|null
252          */
253         public function get_title()
254         {
255                 if (!isset($this->data['title']))
256                 {
257                         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
258                         {
259                                 $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]));
260                         }
261                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
262                         {
263                                 $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]));
264                         }
265                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
266                         {
267                                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
268                         }
269                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
270                         {
271                                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
272                         }
273                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
274                         {
275                                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
276                         }
277                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
278                         {
279                                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
280                         }
281                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
282                         {
283                                 $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
284                         }
285                         else
286                         {
287                                 $this->data['title'] = null;
288                         }
289                 }
290                 return $this->data['title'];
291         }
293         /**
294          * Get the content for the item
295          *
296          * Prefers summaries over full content , but will return full content if a
297          * summary does not exist.
298          *
299          * To prefer full content instead, use {@see get_content}
300          *
301          * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
302          * `<itunes:subtitle>`
303          *
304          * @since 0.8
305          * @param boolean $description_only Should we avoid falling back to the content?
306          * @return string|null
307          */
308         public function get_description($description_only = false)
309         {
310                 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
311                 {
312                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
313                 }
314                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
315                 {
316                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
317                 }
318                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
319                 {
320                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
321                 }
322                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
323                 {
324                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
325                 }
326                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
327                 {
328                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
329                 }
330                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
331                 {
332                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
333                 }
334                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
335                 {
336                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
337                 }
338                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
339                 {
340                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
341                 }
342                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
343                 {
344                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
345                 }
347                 elseif (!$description_only)
348                 {
349                         return $this->get_content(true);
350                 }
351                 else
352                 {
353                         return null;
354                 }
355         }
357         /**
358          * Get the content for the item
359          *
360          * Prefers full content over summaries, but will return a summary if full
361          * content does not exist.
362          *
363          * To prefer summaries instead, use {@see get_description}
364          *
365          * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
366          *
367          * @since 1.0
368          * @param boolean $content_only Should we avoid falling back to the description?
369          * @return string|null
370          */
371         public function get_content($content_only = false)
372         {
373                 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
374                 {
375                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
376                 }
377                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
378                 {
379                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
380                 }
381                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
382                 {
383                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
384                 }
385                 elseif (!$content_only)
386                 {
387                         return $this->get_description(true);
388                 }
389                 else
390                 {
391                         return null;
392                 }
393         }
394         
395         /**
396          * Get the media:thumbnail of the item
397          *
398          * Uses `<media:thumbnail>`
399          *
400          * 
401          * @return array|null
402          */
403         public function get_thumbnail()
404         {
405                 if (!isset($this->data['thumbnail']))
406                 {
407                         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
408                         {
409                                 $this->data['thumbnail'] = $return[0]['attribs'][''];
410                         }
411                         else
412                         {
413                                 $this->data['thumbnail'] = null;
414                         }
415                 }
416                 return $this->data['thumbnail'];
417         }       
419         /**
420          * Get a category for the item
421          *
422          * @since Beta 3 (previously called `get_categories()` since Beta 2)
423          * @param int $key The category that you want to return.  Remember that arrays begin with 0, not 1
424          * @return SimplePie_Category|null
425          */
426         public function get_category($key = 0)
427         {
428                 $categories = $this->get_categories();
429                 if (isset($categories[$key]))
430                 {
431                         return $categories[$key];
432                 }
433                 else
434                 {
435                         return null;
436                 }
437         }
439         /**
440          * Get all categories for the item
441          *
442          * Uses `<atom:category>`, `<category>` or `<dc:subject>`
443          *
444          * @since Beta 3
445          * @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects
446          */
447         public function get_categories()
448         {
449                 $categories = array();
451                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
452                 {
453                         $term = null;
454                         $scheme = null;
455                         $label = null;
456                         if (isset($category['attribs']['']['term']))
457                         {
458                                 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_HTML);
459                         }
460                         if (isset($category['attribs']['']['scheme']))
461                         {
462                                 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_HTML);
463                         }
464                         if (isset($category['attribs']['']['label']))
465                         {
466                                 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_HTML);
467                         }
468                         $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
469                 }
470                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
471                 {
472                         // This is really the label, but keep this as the term also for BC.
473                         // Label will also work on retrieving because that falls back to term.
474                         $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML);
475                         if (isset($category['attribs']['']['domain']))
476                         {
477                                 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_HTML);
478                         }
479                         else
480                         {
481                                 $scheme = null;
482                         }
483                         $categories[] = $this->registry->create('Category', array($term, $scheme, null));
484                 }
485                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
486                 {
487                         $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
488                 }
489                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
490                 {
491                         $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
492                 }
494                 if (!empty($categories))
495                 {
496                         return array_unique($categories);
497                 }
498                 else
499                 {
500                         return null;
501                 }
502         }
504         /**
505          * Get an author for the item
506          *
507          * @since Beta 2
508          * @param int $key The author that you want to return.  Remember that arrays begin with 0, not 1
509          * @return SimplePie_Author|null
510          */
511         public function get_author($key = 0)
512         {
513                 $authors = $this->get_authors();
514                 if (isset($authors[$key]))
515                 {
516                         return $authors[$key];
517                 }
518                 else
519                 {
520                         return null;
521                 }
522         }
524         /**
525          * Get a contributor for the item
526          *
527          * @since 1.1
528          * @param int $key The contrbutor that you want to return.  Remember that arrays begin with 0, not 1
529          * @return SimplePie_Author|null
530          */
531         public function get_contributor($key = 0)
532         {
533                 $contributors = $this->get_contributors();
534                 if (isset($contributors[$key]))
535                 {
536                         return $contributors[$key];
537                 }
538                 else
539                 {
540                         return null;
541                 }
542         }
544         /**
545          * Get all contributors for the item
546          *
547          * Uses `<atom:contributor>`
548          *
549          * @since 1.1
550          * @return array|null List of {@see SimplePie_Author} objects
551          */
552         public function get_contributors()
553         {
554                 $contributors = array();
555                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
556                 {
557                         $name = null;
558                         $uri = null;
559                         $email = null;
560                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
561                         {
562                                 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
563                         }
564                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
565                         {
566                                 $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]));
567                         }
568                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
569                         {
570                                 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
571                         }
572                         if ($name !== null || $email !== null || $uri !== null)
573                         {
574                                 $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
575                         }
576                 }
577                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
578                 {
579                         $name = null;
580                         $url = null;
581                         $email = null;
582                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
583                         {
584                                 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
585                         }
586                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
587                         {
588                                 $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]));
589                         }
590                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
591                         {
592                                 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
593                         }
594                         if ($name !== null || $email !== null || $url !== null)
595                         {
596                                 $contributors[] = $this->registry->create('Author', array($name, $url, $email));
597                         }
598                 }
600                 if (!empty($contributors))
601                 {
602                         return array_unique($contributors);
603                 }
604                 else
605                 {
606                         return null;
607                 }
608         }
610         /**
611          * Get all authors for the item
612          *
613          * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
614          *
615          * @since Beta 2
616          * @return array|null List of {@see SimplePie_Author} objects
617          */
618         public function get_authors()
619         {
620                 $authors = array();
621                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
622                 {
623                         $name = null;
624                         $uri = null;
625                         $email = null;
626                         if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
627                         {
628                                 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
629                         }
630                         if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
631                         {
632                                 $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]));
633                         }
634                         if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
635                         {
636                                 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
637                         }
638                         if ($name !== null || $email !== null || $uri !== null)
639                         {
640                                 $authors[] = $this->registry->create('Author', array($name, $uri, $email));
641                         }
642                 }
643                 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
644                 {
645                         $name = null;
646                         $url = null;
647                         $email = null;
648                         if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
649                         {
650                                 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
651                         }
652                         if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
653                         {
654                                 $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]));
655                         }
656                         if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
657                         {
658                                 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
659                         }
660                         if ($name !== null || $email !== null || $url !== null)
661                         {
662                                 $authors[] = $this->registry->create('Author', array($name, $url, $email));
663                         }
664                 }
665                 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
666                 {
667                         $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)));
668                 }
669                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
670                 {
671                         $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
672                 }
673                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
674                 {
675                         $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
676                 }
677                 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
678                 {
679                         $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
680                 }
682                 if (!empty($authors))
683                 {
684                         return array_unique($authors);
685                 }
686                 elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
687                 {
688                         return $authors;
689                 }
690                 elseif ($authors = $this->feed->get_authors())
691                 {
692                         return $authors;
693                 }
694                 else
695                 {
696                         return null;
697                 }
698         }
700         /**
701          * Get the copyright info for the item
702          *
703          * Uses `<atom:rights>` or `<dc:rights>`
704          *
705          * @since 1.1
706          * @return string
707          */
708         public function get_copyright()
709         {
710                 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
711                 {
712                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
713                 }
714                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
715                 {
716                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
717                 }
718                 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
719                 {
720                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
721                 }
722                 else
723                 {
724                         return null;
725                 }
726         }
728         /**
729          * Get the posting date/time for the item
730          *
731          * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
732          * `<atom:modified>`, `<pubDate>` or `<dc:date>`
733          *
734          * Note: obeys PHP's timezone setting. To get a UTC date/time, use
735          * {@see get_gmdate}
736          *
737          * @since Beta 2 (previously called `get_item_date` since 0.8)
738          *
739          * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
740          * @return int|string|null
741          */
742         public function get_date($date_format = 'j F Y, g:i a')
743         {
744                 if (!isset($this->data['date']))
745                 {
746                         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
747                         {
748                                 $this->data['date']['raw'] = $return[0]['data'];
749                         }
750                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
751                         {
752                                 $this->data['date']['raw'] = $return[0]['data'];
753                         }
754                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
755                         {
756                                 $this->data['date']['raw'] = $return[0]['data'];
757                         }
758                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
759                         {
760                                 $this->data['date']['raw'] = $return[0]['data'];
761                         }
762                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
763                         {
764                                 $this->data['date']['raw'] = $return[0]['data'];
765                         }
766                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
767                         {
768                                 $this->data['date']['raw'] = $return[0]['data'];
769                         }
770                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
771                         {
772                                 $this->data['date']['raw'] = $return[0]['data'];
773                         }
774                         elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
775                         {
776                                 $this->data['date']['raw'] = $return[0]['data'];
777                         }
779                         if (!empty($this->data['date']['raw']))
780                         {
781                                 $parser = $this->registry->call('Parse_Date', 'get');
782                                 $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
783                         }
784                         else
785                         {
786                                 $this->data['date'] = null;
787                         }
788                 }
789                 if ($this->data['date'])
790                 {
791                         $date_format = (string) $date_format;
792                         switch ($date_format)
793                         {
794                                 case '':
795                                         return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
797                                 case 'U':
798                                         return $this->data['date']['parsed'];
800                                 default:
801                                         return date($date_format, $this->data['date']['parsed']);
802                         }
803                 }
804                 else
805                 {
806                         return null;
807                 }
808         }
810         /**
811          * Get the update date/time for the item
812          *
813          * Uses `<atom:updated>`
814          *
815          * Note: obeys PHP's timezone setting. To get a UTC date/time, use
816          * {@see get_gmdate}
817          *
818          * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
819          * @return int|string|null
820          */
821         public function get_updated_date($date_format = 'j F Y, g:i a')
822         {
823                 if (!isset($this->data['updated']))
824                 {
825                         if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
826                         {
827                                 $this->data['updated']['raw'] = $return[0]['data'];
828                         }
830                         if (!empty($this->data['updated']['raw']))
831                         {
832                                 $parser = $this->registry->call('Parse_Date', 'get');
833                                 $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']);
834                         }
835                         else
836                         {
837                                 $this->data['updated'] = null;
838                         }
839                 }
840                 if ($this->data['updated'])
841                 {
842                         $date_format = (string) $date_format;
843                         switch ($date_format)
844                         {
845                                 case '':
846                                         return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
848                                 case 'U':
849                                         return $this->data['updated']['parsed'];
851                                 default:
852                                         return date($date_format, $this->data['updated']['parsed']);
853                         }
854                 }
855                 else
856                 {
857                         return null;
858                 }
859         }
861         /**
862          * Get the localized posting date/time for the item
863          *
864          * Returns the date formatted in the localized language. To display in
865          * languages other than the server's default, you need to change the locale
866          * with {@link http://php.net/setlocale setlocale()}. The available
867          * localizations depend on which ones are installed on your web server.
868          *
869          * @since 1.0
870          *
871          * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
872          * @return int|string|null
873          */
874         public function get_local_date($date_format = '%c')
875         {
876                 if (!$date_format)
877                 {
878                         return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
879                 }
880                 elseif (($date = $this->get_date('U')) !== null && $date !== false)
881                 {
882                         return strftime($date_format, $date);
883                 }
884                 else
885                 {
886                         return null;
887                 }
888         }
890         /**
891          * Get the posting date/time for the item (UTC time)
892          *
893          * @see get_date
894          * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
895          * @return int|string|null
896          */
897         public function get_gmdate($date_format = 'j F Y, g:i a')
898         {
899                 $date = $this->get_date('U');
900                 if ($date === null)
901                 {
902                         return null;
903                 }
905                 return gmdate($date_format, $date);
906         }
908         /**
909          * Get the update date/time for the item (UTC time)
910          *
911          * @see get_updated_date
912          * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
913          * @return int|string|null
914          */
915         public function get_updated_gmdate($date_format = 'j F Y, g:i a')
916         {
917                 $date = $this->get_updated_date('U');
918                 if ($date === null)
919                 {
920                         return null;
921                 }
923                 return gmdate($date_format, $date);
924         }
926         /**
927          * Get the permalink for the item
928          *
929          * Returns the first link available with a relationship of "alternate".
930          * Identical to {@see get_link()} with key 0
931          *
932          * @see get_link
933          * @since 0.8
934          * @return string|null Permalink URL
935          */
936         public function get_permalink()
937         {
938                 $link = $this->get_link();
939                 $enclosure = $this->get_enclosure(0);
940                 if ($link !== null)
941                 {
942                         return $link;
943                 }
944                 elseif ($enclosure !== null)
945                 {
946                         return $enclosure->get_link();
947                 }
948                 else
949                 {
950                         return null;
951                 }
952         }
954         /**
955          * Get a single link for the item
956          *
957          * @since Beta 3
958          * @param int $key The link that you want to return.  Remember that arrays begin with 0, not 1
959          * @param string $rel The relationship of the link to return
960          * @return string|null Link URL
961          */
962         public function get_link($key = 0, $rel = 'alternate')
963         {
964                 $links = $this->get_links($rel);
965                 if ($links[$key] !== null)
966                 {
967                         return $links[$key];
968                 }
969                 else
970                 {
971                         return null;
972                 }
973         }
975         /**
976          * Get all links for the item
977          *
978          * Uses `<atom:link>`, `<link>` or `<guid>`
979          *
980          * @since Beta 2
981          * @param string $rel The relationship of links to return
982          * @return array|null Links found for the item (strings)
983          */
984         public function get_links($rel = 'alternate')
985         {
986                 if (!isset($this->data['links']))
987                 {
988                         $this->data['links'] = array();
989                         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
990                         {
991                                 if (isset($link['attribs']['']['href']))
992                                 {
993                                         $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
994                                         $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
996                                 }
997                         }
998                         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
999                         {
1000                                 if (isset($link['attribs']['']['href']))
1001                                 {
1002                                         $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
1003                                         $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
1004                                 }
1005                         }
1006                         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
1007                         {
1008                                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1009                         }
1010                         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
1011                         {
1012                                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1013                         }
1014                         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
1015                         {
1016                                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1017                         }
1018                         if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
1019                         {
1020                                 if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
1021                                 {
1022                                         $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
1023                                 }
1024                         }
1026                         $keys = array_keys($this->data['links']);
1027                         foreach ($keys as $key)
1028                         {
1029                                 if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
1030                                 {
1031                                         if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
1032                                         {
1033                                                 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
1034                                                 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
1035                                         }
1036                                         else
1037                                         {
1038                                                 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
1039                                         }
1040                                 }
1041                                 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
1042                                 {
1043                                         $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
1044                                 }
1045                                 $this->data['links'][$key] = array_unique($this->data['links'][$key]);
1046                         }
1047                 }
1048                 if (isset($this->data['links'][$rel]))
1049                 {
1050                         return $this->data['links'][$rel];
1051                 }
1052                 else
1053                 {
1054                         return null;
1055                 }
1056         }
1058         /**
1059          * Get an enclosure from the item
1060          *
1061          * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
1062          *
1063          * @since Beta 2
1064          * @todo Add ability to prefer one type of content over another (in a media group).
1065          * @param int $key The enclosure that you want to return.  Remember that arrays begin with 0, not 1
1066          * @return SimplePie_Enclosure|null
1067          */
1068         public function get_enclosure($key = 0, $prefer = null)
1069         {
1070                 $enclosures = $this->get_enclosures();
1071                 if (isset($enclosures[$key]))
1072                 {
1073                         return $enclosures[$key];
1074                 }
1075                 else
1076                 {
1077                         return null;
1078                 }
1079         }
1081         /**
1082          * Get all available enclosures (podcasts, etc.)
1083          *
1084          * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
1085          *
1086          * At this point, we're pretty much assuming that all enclosures for an item
1087          * are the same content.  Anything else is too complicated to
1088          * properly support.
1089          *
1090          * @since Beta 2
1091          * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
1092          * @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).
1093          * @return SimplePie_Enclosure[]|null List of SimplePie_Enclosure items
1094          */
1095         public function get_enclosures()
1096         {
1097                 if (!isset($this->data['enclosures']))
1098                 {
1099                         $this->data['enclosures'] = array();
1101                         // Elements
1102                         $captions_parent = null;
1103                         $categories_parent = null;
1104                         $copyrights_parent = null;
1105                         $credits_parent = null;
1106                         $description_parent = null;
1107                         $duration_parent = null;
1108                         $hashes_parent = null;
1109                         $keywords_parent = null;
1110                         $player_parent = null;
1111                         $ratings_parent = null;
1112                         $restrictions_parent = null;
1113                         $thumbnails_parent = null;
1114                         $title_parent = null;
1116                         // Let's do the channel and item-level ones first, and just re-use them if we need to.
1117                         $parent = $this->get_feed();
1119                         // CAPTIONS
1120                         if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
1121                         {
1122                                 foreach ($captions as $caption)
1123                                 {
1124                                         $caption_type = null;
1125                                         $caption_lang = null;
1126                                         $caption_startTime = null;
1127                                         $caption_endTime = null;
1128                                         $caption_text = null;
1129                                         if (isset($caption['attribs']['']['type']))
1130                                         {
1131                                                 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1132                                         }
1133                                         if (isset($caption['attribs']['']['lang']))
1134                                         {
1135                                                 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1136                                         }
1137                                         if (isset($caption['attribs']['']['start']))
1138                                         {
1139                                                 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
1140                                         }
1141                                         if (isset($caption['attribs']['']['end']))
1142                                         {
1143                                                 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
1144                                         }
1145                                         if (isset($caption['data']))
1146                                         {
1147                                                 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1148                                         }
1149                                         $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
1150                                 }
1151                         }
1152                         elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
1153                         {
1154                                 foreach ($captions as $caption)
1155                                 {
1156                                         $caption_type = null;
1157                                         $caption_lang = null;
1158                                         $caption_startTime = null;
1159                                         $caption_endTime = null;
1160                                         $caption_text = null;
1161                                         if (isset($caption['attribs']['']['type']))
1162                                         {
1163                                                 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1164                                         }
1165                                         if (isset($caption['attribs']['']['lang']))
1166                                         {
1167                                                 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1168                                         }
1169                                         if (isset($caption['attribs']['']['start']))
1170                                         {
1171                                                 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
1172                                         }
1173                                         if (isset($caption['attribs']['']['end']))
1174                                         {
1175                                                 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
1176                                         }
1177                                         if (isset($caption['data']))
1178                                         {
1179                                                 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1180                                         }
1181                                         $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
1182                                 }
1183                         }
1184                         if (is_array($captions_parent))
1185                         {
1186                                 $captions_parent = array_values(array_unique($captions_parent));
1187                         }
1189                         // CATEGORIES
1190                         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
1191                         {
1192                                 $term = null;
1193                                 $scheme = null;
1194                                 $label = null;
1195                                 if (isset($category['data']))
1196                                 {
1197                                         $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1198                                 }
1199                                 if (isset($category['attribs']['']['scheme']))
1200                                 {
1201                                         $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1202                                 }
1203                                 else
1204                                 {
1205                                         $scheme = 'http://search.yahoo.com/mrss/category_schema';
1206                                 }
1207                                 if (isset($category['attribs']['']['label']))
1208                                 {
1209                                         $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
1210                                 }
1211                                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
1212                         }
1213                         foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
1214                         {
1215                                 $term = null;
1216                                 $scheme = null;
1217                                 $label = null;
1218                                 if (isset($category['data']))
1219                                 {
1220                                         $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1221                                 }
1222                                 if (isset($category['attribs']['']['scheme']))
1223                                 {
1224                                         $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1225                                 }
1226                                 else
1227                                 {
1228                                         $scheme = 'http://search.yahoo.com/mrss/category_schema';
1229                                 }
1230                                 if (isset($category['attribs']['']['label']))
1231                                 {
1232                                         $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
1233                                 }
1234                                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
1235                         }
1236                         foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
1237                         {
1238                                 $term = null;
1239                                 $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
1240                                 $label = null;
1241                                 if (isset($category['attribs']['']['text']))
1242                                 {
1243                                         $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
1244                                 }
1245                                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
1247                                 if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
1248                                 {
1249                                         foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
1250                                         {
1251                                                 if (isset($subcategory['attribs']['']['text']))
1252                                                 {
1253                                                         $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
1254                                                 }
1255                                                 $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
1256                                         }
1257                                 }
1258                         }
1259                         if (is_array($categories_parent))
1260                         {
1261                                 $categories_parent = array_values(array_unique($categories_parent));
1262                         }
1264                         // COPYRIGHT
1265                         if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
1266                         {
1267                                 $copyright_url = null;
1268                                 $copyright_label = null;
1269                                 if (isset($copyright[0]['attribs']['']['url']))
1270                                 {
1271                                         $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
1272                                 }
1273                                 if (isset($copyright[0]['data']))
1274                                 {
1275                                         $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1276                                 }
1277                                 $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
1278                         }
1279                         elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
1280                         {
1281                                 $copyright_url = null;
1282                                 $copyright_label = null;
1283                                 if (isset($copyright[0]['attribs']['']['url']))
1284                                 {
1285                                         $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
1286                                 }
1287                                 if (isset($copyright[0]['data']))
1288                                 {
1289                                         $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1290                                 }
1291                                 $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
1292                         }
1294                         // CREDITS
1295                         if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
1296                         {
1297                                 foreach ($credits as $credit)
1298                                 {
1299                                         $credit_role = null;
1300                                         $credit_scheme = null;
1301                                         $credit_name = null;
1302                                         if (isset($credit['attribs']['']['role']))
1303                                         {
1304                                                 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
1305                                         }
1306                                         if (isset($credit['attribs']['']['scheme']))
1307                                         {
1308                                                 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1309                                         }
1310                                         else
1311                                         {
1312                                                 $credit_scheme = 'urn:ebu';
1313                                         }
1314                                         if (isset($credit['data']))
1315                                         {
1316                                                 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1317                                         }
1318                                         $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
1319                                 }
1320                         }
1321                         elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
1322                         {
1323                                 foreach ($credits as $credit)
1324                                 {
1325                                         $credit_role = null;
1326                                         $credit_scheme = null;
1327                                         $credit_name = null;
1328                                         if (isset($credit['attribs']['']['role']))
1329                                         {
1330                                                 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
1331                                         }
1332                                         if (isset($credit['attribs']['']['scheme']))
1333                                         {
1334                                                 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1335                                         }
1336                                         else
1337                                         {
1338                                                 $credit_scheme = 'urn:ebu';
1339                                         }
1340                                         if (isset($credit['data']))
1341                                         {
1342                                                 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1343                                         }
1344                                         $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
1345                                 }
1346                         }
1347                         if (is_array($credits_parent))
1348                         {
1349                                 $credits_parent = array_values(array_unique($credits_parent));
1350                         }
1352                         // DESCRIPTION
1353                         if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
1354                         {
1355                                 if (isset($description_parent[0]['data']))
1356                                 {
1357                                         $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1358                                 }
1359                         }
1360                         elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
1361                         {
1362                                 if (isset($description_parent[0]['data']))
1363                                 {
1364                                         $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1365                                 }
1366                         }
1368                         // DURATION
1369                         if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
1370                         {
1371                                 $seconds = null;
1372                                 $minutes = null;
1373                                 $hours = null;
1374                                 if (isset($duration_parent[0]['data']))
1375                                 {
1376                                         $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
1377                                         if (sizeof($temp) > 0)
1378                                         {
1379                                                 $seconds = (int) array_pop($temp);
1380                                         }
1381                                         if (sizeof($temp) > 0)
1382                                         {
1383                                                 $minutes = (int) array_pop($temp);
1384                                                 $seconds += $minutes * 60;
1385                                         }
1386                                         if (sizeof($temp) > 0)
1387                                         {
1388                                                 $hours = (int) array_pop($temp);
1389                                                 $seconds += $hours * 3600;
1390                                         }
1391                                         unset($temp);
1392                                         $duration_parent = $seconds;
1393                                 }
1394                         }
1396                         // HASHES
1397                         if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
1398                         {
1399                                 foreach ($hashes_iterator as $hash)
1400                                 {
1401                                         $value = null;
1402                                         $algo = null;
1403                                         if (isset($hash['data']))
1404                                         {
1405                                                 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1406                                         }
1407                                         if (isset($hash['attribs']['']['algo']))
1408                                         {
1409                                                 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
1410                                         }
1411                                         else
1412                                         {
1413                                                 $algo = 'md5';
1414                                         }
1415                                         $hashes_parent[] = $algo.':'.$value;
1416                                 }
1417                         }
1418                         elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
1419                         {
1420                                 foreach ($hashes_iterator as $hash)
1421                                 {
1422                                         $value = null;
1423                                         $algo = null;
1424                                         if (isset($hash['data']))
1425                                         {
1426                                                 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1427                                         }
1428                                         if (isset($hash['attribs']['']['algo']))
1429                                         {
1430                                                 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
1431                                         }
1432                                         else
1433                                         {
1434                                                 $algo = 'md5';
1435                                         }
1436                                         $hashes_parent[] = $algo.':'.$value;
1437                                 }
1438                         }
1439                         if (is_array($hashes_parent))
1440                         {
1441                                 $hashes_parent = array_values(array_unique($hashes_parent));
1442                         }
1444                         // KEYWORDS
1445                         if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
1446                         {
1447                                 if (isset($keywords[0]['data']))
1448                                 {
1449                                         $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
1450                                         foreach ($temp as $word)
1451                                         {
1452                                                 $keywords_parent[] = trim($word);
1453                                         }
1454                                 }
1455                                 unset($temp);
1456                         }
1457                         elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
1458                         {
1459                                 if (isset($keywords[0]['data']))
1460                                 {
1461                                         $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
1462                                         foreach ($temp as $word)
1463                                         {
1464                                                 $keywords_parent[] = trim($word);
1465                                         }
1466                                 }
1467                                 unset($temp);
1468                         }
1469                         elseif ($keywords = $parent->get_channel_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 = $parent->get_channel_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                         if (is_array($keywords_parent))
1494                         {
1495                                 $keywords_parent = array_values(array_unique($keywords_parent));
1496                         }
1498                         // PLAYER
1499                         if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
1500                         {
1501                                 if (isset($player_parent[0]['attribs']['']['url']))
1502                                 {
1503                                         $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
1504                                 }
1505                         }
1506                         elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
1507                         {
1508                                 if (isset($player_parent[0]['attribs']['']['url']))
1509                                 {
1510                                         $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
1511                                 }
1512                         }
1514                         // RATINGS
1515                         if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
1516                         {
1517                                 foreach ($ratings as $rating)
1518                                 {
1519                                         $rating_scheme = null;
1520                                         $rating_value = null;
1521                                         if (isset($rating['attribs']['']['scheme']))
1522                                         {
1523                                                 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1524                                         }
1525                                         else
1526                                         {
1527                                                 $rating_scheme = 'urn:simple';
1528                                         }
1529                                         if (isset($rating['data']))
1530                                         {
1531                                                 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1532                                         }
1533                                         $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
1534                                 }
1535                         }
1536                         elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
1537                         {
1538                                 foreach ($ratings as $rating)
1539                                 {
1540                                         $rating_scheme = 'urn:itunes';
1541                                         $rating_value = null;
1542                                         if (isset($rating['data']))
1543                                         {
1544                                                 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1545                                         }
1546                                         $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
1547                                 }
1548                         }
1549                         elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
1550                         {
1551                                 foreach ($ratings as $rating)
1552                                 {
1553                                         $rating_scheme = null;
1554                                         $rating_value = null;
1555                                         if (isset($rating['attribs']['']['scheme']))
1556                                         {
1557                                                 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1558                                         }
1559                                         else
1560                                         {
1561                                                 $rating_scheme = 'urn:simple';
1562                                         }
1563                                         if (isset($rating['data']))
1564                                         {
1565                                                 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1566                                         }
1567                                         $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
1568                                 }
1569                         }
1570                         elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
1571                         {
1572                                 foreach ($ratings as $rating)
1573                                 {
1574                                         $rating_scheme = 'urn:itunes';
1575                                         $rating_value = null;
1576                                         if (isset($rating['data']))
1577                                         {
1578                                                 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1579                                         }
1580                                         $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
1581                                 }
1582                         }
1583                         if (is_array($ratings_parent))
1584                         {
1585                                 $ratings_parent = array_values(array_unique($ratings_parent));
1586                         }
1588                         // RESTRICTIONS
1589                         if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
1590                         {
1591                                 foreach ($restrictions as $restriction)
1592                                 {
1593                                         $restriction_relationship = null;
1594                                         $restriction_type = null;
1595                                         $restriction_value = null;
1596                                         if (isset($restriction['attribs']['']['relationship']))
1597                                         {
1598                                                 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
1599                                         }
1600                                         if (isset($restriction['attribs']['']['type']))
1601                                         {
1602                                                 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1603                                         }
1604                                         if (isset($restriction['data']))
1605                                         {
1606                                                 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1607                                         }
1608                                         $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
1609                                 }
1610                         }
1611                         elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
1612                         {
1613                                 foreach ($restrictions as $restriction)
1614                                 {
1615                                         $restriction_relationship = 'allow';
1616                                         $restriction_type = null;
1617                                         $restriction_value = 'itunes';
1618                                         if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
1619                                         {
1620                                                 $restriction_relationship = 'deny';
1621                                         }
1622                                         $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
1623                                 }
1624                         }
1625                         elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
1626                         {
1627                                 foreach ($restrictions as $restriction)
1628                                 {
1629                                         $restriction_relationship = null;
1630                                         $restriction_type = null;
1631                                         $restriction_value = null;
1632                                         if (isset($restriction['attribs']['']['relationship']))
1633                                         {
1634                                                 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
1635                                         }
1636                                         if (isset($restriction['attribs']['']['type']))
1637                                         {
1638                                                 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1639                                         }
1640                                         if (isset($restriction['data']))
1641                                         {
1642                                                 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1643                                         }
1644                                         $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
1645                                 }
1646                         }
1647                         elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
1648                         {
1649                                 foreach ($restrictions as $restriction)
1650                                 {
1651                                         $restriction_relationship = 'allow';
1652                                         $restriction_type = null;
1653                                         $restriction_value = 'itunes';
1654                                         if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
1655                                         {
1656                                                 $restriction_relationship = 'deny';
1657                                         }
1658                                         $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
1659                                 }
1660                         }
1661                         if (is_array($restrictions_parent))
1662                         {
1663                                 $restrictions_parent = array_values(array_unique($restrictions_parent));
1664                         }
1665                         else
1666                         {
1667                                 $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
1668                         }
1670                         // THUMBNAILS
1671                         if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
1672                         {
1673                                 foreach ($thumbnails as $thumbnail)
1674                                 {
1675                                         if (isset($thumbnail['attribs']['']['url']))
1676                                         {
1677                                                 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
1678                                         }
1679                                 }
1680                         }
1681                         elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
1682                         {
1683                                 foreach ($thumbnails as $thumbnail)
1684                                 {
1685                                         if (isset($thumbnail['attribs']['']['url']))
1686                                         {
1687                                                 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
1688                                         }
1689                                 }
1690                         }
1692                         // TITLES
1693                         if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
1694                         {
1695                                 if (isset($title_parent[0]['data']))
1696                                 {
1697                                         $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1698                                 }
1699                         }
1700                         elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
1701                         {
1702                                 if (isset($title_parent[0]['data']))
1703                                 {
1704                                         $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1705                                 }
1706                         }
1708                         // Clear the memory
1709                         unset($parent);
1711                         // Attributes
1712                         $bitrate = null;
1713                         $channels = null;
1714                         $duration = null;
1715                         $expression = null;
1716                         $framerate = null;
1717                         $height = null;
1718                         $javascript = null;
1719                         $lang = null;
1720                         $length = null;
1721                         $medium = null;
1722                         $samplingrate = null;
1723                         $type = null;
1724                         $url = null;
1725                         $width = null;
1727                         // Elements
1728                         $captions = null;
1729                         $categories = null;
1730                         $copyrights = null;
1731                         $credits = null;
1732                         $description = null;
1733                         $hashes = null;
1734                         $keywords = null;
1735                         $player = null;
1736                         $ratings = null;
1737                         $restrictions = null;
1738                         $thumbnails = null;
1739                         $title = null;
1741                         // If we have media:group tags, loop through them.
1742                         foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
1743                         {
1744                                 if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
1745                                 {
1746                                         // If we have media:content tags, loop through them.
1747                                         foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
1748                                         {
1749                                                 if (isset($content['attribs']['']['url']))
1750                                                 {
1751                                                         // Attributes
1752                                                         $bitrate = null;
1753                                                         $channels = null;
1754                                                         $duration = null;
1755                                                         $expression = null;
1756                                                         $framerate = null;
1757                                                         $height = null;
1758                                                         $javascript = null;
1759                                                         $lang = null;
1760                                                         $length = null;
1761                                                         $medium = null;
1762                                                         $samplingrate = null;
1763                                                         $type = null;
1764                                                         $url = null;
1765                                                         $width = null;
1767                                                         // Elements
1768                                                         $captions = null;
1769                                                         $categories = null;
1770                                                         $copyrights = null;
1771                                                         $credits = null;
1772                                                         $description = null;
1773                                                         $hashes = null;
1774                                                         $keywords = null;
1775                                                         $player = null;
1776                                                         $ratings = null;
1777                                                         $restrictions = null;
1778                                                         $thumbnails = null;
1779                                                         $title = null;
1781                                                         // Start checking the attributes of media:content
1782                                                         if (isset($content['attribs']['']['bitrate']))
1783                                                         {
1784                                                                 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
1785                                                         }
1786                                                         if (isset($content['attribs']['']['channels']))
1787                                                         {
1788                                                                 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
1789                                                         }
1790                                                         if (isset($content['attribs']['']['duration']))
1791                                                         {
1792                                                                 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
1793                                                         }
1794                                                         else
1795                                                         {
1796                                                                 $duration = $duration_parent;
1797                                                         }
1798                                                         if (isset($content['attribs']['']['expression']))
1799                                                         {
1800                                                                 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
1801                                                         }
1802                                                         if (isset($content['attribs']['']['framerate']))
1803                                                         {
1804                                                                 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
1805                                                         }
1806                                                         if (isset($content['attribs']['']['height']))
1807                                                         {
1808                                                                 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
1809                                                         }
1810                                                         if (isset($content['attribs']['']['lang']))
1811                                                         {
1812                                                                 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1813                                                         }
1814                                                         if (isset($content['attribs']['']['fileSize']))
1815                                                         {
1816                                                                 $length = ceil($content['attribs']['']['fileSize']);
1817                                                         }
1818                                                         if (isset($content['attribs']['']['medium']))
1819                                                         {
1820                                                                 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
1821                                                         }
1822                                                         if (isset($content['attribs']['']['samplingrate']))
1823                                                         {
1824                                                                 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
1825                                                         }
1826                                                         if (isset($content['attribs']['']['type']))
1827                                                         {
1828                                                                 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1829                                                         }
1830                                                         if (isset($content['attribs']['']['width']))
1831                                                         {
1832                                                                 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
1833                                                         }
1834                                                         $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
1836                                                         // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
1838                                                         // CAPTIONS
1839                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
1840                                                         {
1841                                                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
1842                                                                 {
1843                                                                         $caption_type = null;
1844                                                                         $caption_lang = null;
1845                                                                         $caption_startTime = null;
1846                                                                         $caption_endTime = null;
1847                                                                         $caption_text = null;
1848                                                                         if (isset($caption['attribs']['']['type']))
1849                                                                         {
1850                                                                                 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1851                                                                         }
1852                                                                         if (isset($caption['attribs']['']['lang']))
1853                                                                         {
1854                                                                                 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1855                                                                         }
1856                                                                         if (isset($caption['attribs']['']['start']))
1857                                                                         {
1858                                                                                 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
1859                                                                         }
1860                                                                         if (isset($caption['attribs']['']['end']))
1861                                                                         {
1862                                                                                 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
1863                                                                         }
1864                                                                         if (isset($caption['data']))
1865                                                                         {
1866                                                                                 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1867                                                                         }
1868                                                                         $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
1869                                                                 }
1870                                                                 if (is_array($captions))
1871                                                                 {
1872                                                                         $captions = array_values(array_unique($captions));
1873                                                                 }
1874                                                         }
1875                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
1876                                                         {
1877                                                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
1878                                                                 {
1879                                                                         $caption_type = null;
1880                                                                         $caption_lang = null;
1881                                                                         $caption_startTime = null;
1882                                                                         $caption_endTime = null;
1883                                                                         $caption_text = null;
1884                                                                         if (isset($caption['attribs']['']['type']))
1885                                                                         {
1886                                                                                 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
1887                                                                         }
1888                                                                         if (isset($caption['attribs']['']['lang']))
1889                                                                         {
1890                                                                                 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
1891                                                                         }
1892                                                                         if (isset($caption['attribs']['']['start']))
1893                                                                         {
1894                                                                                 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
1895                                                                         }
1896                                                                         if (isset($caption['attribs']['']['end']))
1897                                                                         {
1898                                                                                 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
1899                                                                         }
1900                                                                         if (isset($caption['data']))
1901                                                                         {
1902                                                                                 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1903                                                                         }
1904                                                                         $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
1905                                                                 }
1906                                                                 if (is_array($captions))
1907                                                                 {
1908                                                                         $captions = array_values(array_unique($captions));
1909                                                                 }
1910                                                         }
1911                                                         else
1912                                                         {
1913                                                                 $captions = $captions_parent;
1914                                                         }
1916                                                         // CATEGORIES
1917                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
1918                                                         {
1919                                                                 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
1920                                                                 {
1921                                                                         $term = null;
1922                                                                         $scheme = null;
1923                                                                         $label = null;
1924                                                                         if (isset($category['data']))
1925                                                                         {
1926                                                                                 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1927                                                                         }
1928                                                                         if (isset($category['attribs']['']['scheme']))
1929                                                                         {
1930                                                                                 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1931                                                                         }
1932                                                                         else
1933                                                                         {
1934                                                                                 $scheme = 'http://search.yahoo.com/mrss/category_schema';
1935                                                                         }
1936                                                                         if (isset($category['attribs']['']['label']))
1937                                                                         {
1938                                                                                 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
1939                                                                         }
1940                                                                         $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
1941                                                                 }
1942                                                         }
1943                                                         if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
1944                                                         {
1945                                                                 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
1946                                                                 {
1947                                                                         $term = null;
1948                                                                         $scheme = null;
1949                                                                         $label = null;
1950                                                                         if (isset($category['data']))
1951                                                                         {
1952                                                                                 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1953                                                                         }
1954                                                                         if (isset($category['attribs']['']['scheme']))
1955                                                                         {
1956                                                                                 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
1957                                                                         }
1958                                                                         else
1959                                                                         {
1960                                                                                 $scheme = 'http://search.yahoo.com/mrss/category_schema';
1961                                                                         }
1962                                                                         if (isset($category['attribs']['']['label']))
1963                                                                         {
1964                                                                                 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
1965                                                                         }
1966                                                                         $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
1967                                                                 }
1968                                                         }
1969                                                         if (is_array($categories) && is_array($categories_parent))
1970                                                         {
1971                                                                 $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
1972                                                         }
1973                                                         elseif (is_array($categories))
1974                                                         {
1975                                                                 $categories = array_values(array_unique($categories));
1976                                                         }
1977                                                         elseif (is_array($categories_parent))
1978                                                         {
1979                                                                 $categories = array_values(array_unique($categories_parent));
1980                                                         }
1982                                                         // COPYRIGHTS
1983                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
1984                                                         {
1985                                                                 $copyright_url = null;
1986                                                                 $copyright_label = null;
1987                                                                 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
1988                                                                 {
1989                                                                         $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
1990                                                                 }
1991                                                                 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
1992                                                                 {
1993                                                                         $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
1994                                                                 }
1995                                                                 $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
1996                                                         }
1997                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
1998                                                         {
1999                                                                 $copyright_url = null;
2000                                                                 $copyright_label = null;
2001                                                                 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
2002                                                                 {
2003                                                                         $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
2004                                                                 }
2005                                                                 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
2006                                                                 {
2007                                                                         $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2008                                                                 }
2009                                                                 $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
2010                                                         }
2011                                                         else
2012                                                         {
2013                                                                 $copyrights = $copyrights_parent;
2014                                                         }
2016                                                         // CREDITS
2017                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
2018                                                         {
2019                                                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
2020                                                                 {
2021                                                                         $credit_role = null;
2022                                                                         $credit_scheme = null;
2023                                                                         $credit_name = null;
2024                                                                         if (isset($credit['attribs']['']['role']))
2025                                                                         {
2026                                                                                 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
2027                                                                         }
2028                                                                         if (isset($credit['attribs']['']['scheme']))
2029                                                                         {
2030                                                                                 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2031                                                                         }
2032                                                                         else
2033                                                                         {
2034                                                                                 $credit_scheme = 'urn:ebu';
2035                                                                         }
2036                                                                         if (isset($credit['data']))
2037                                                                         {
2038                                                                                 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2039                                                                         }
2040                                                                         $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
2041                                                                 }
2042                                                                 if (is_array($credits))
2043                                                                 {
2044                                                                         $credits = array_values(array_unique($credits));
2045                                                                 }
2046                                                         }
2047                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
2048                                                         {
2049                                                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
2050                                                                 {
2051                                                                         $credit_role = null;
2052                                                                         $credit_scheme = null;
2053                                                                         $credit_name = null;
2054                                                                         if (isset($credit['attribs']['']['role']))
2055                                                                         {
2056                                                                                 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
2057                                                                         }
2058                                                                         if (isset($credit['attribs']['']['scheme']))
2059                                                                         {
2060                                                                                 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2061                                                                         }
2062                                                                         else
2063                                                                         {
2064                                                                                 $credit_scheme = 'urn:ebu';
2065                                                                         }
2066                                                                         if (isset($credit['data']))
2067                                                                         {
2068                                                                                 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2069                                                                         }
2070                                                                         $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
2071                                                                 }
2072                                                                 if (is_array($credits))
2073                                                                 {
2074                                                                         $credits = array_values(array_unique($credits));
2075                                                                 }
2076                                                         }
2077                                                         else
2078                                                         {
2079                                                                 $credits = $credits_parent;
2080                                                         }
2082                                                         // DESCRIPTION
2083                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
2084                                                         {
2085                                                                 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2086                                                         }
2087                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
2088                                                         {
2089                                                                 $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2090                                                         }
2091                                                         else
2092                                                         {
2093                                                                 $description = $description_parent;
2094                                                         }
2096                                                         // HASHES
2097                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
2098                                                         {
2099                                                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
2100                                                                 {
2101                                                                         $value = null;
2102                                                                         $algo = null;
2103                                                                         if (isset($hash['data']))
2104                                                                         {
2105                                                                                 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2106                                                                         }
2107                                                                         if (isset($hash['attribs']['']['algo']))
2108                                                                         {
2109                                                                                 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
2110                                                                         }
2111                                                                         else
2112                                                                         {
2113                                                                                 $algo = 'md5';
2114                                                                         }
2115                                                                         $hashes[] = $algo.':'.$value;
2116                                                                 }
2117                                                                 if (is_array($hashes))
2118                                                                 {
2119                                                                         $hashes = array_values(array_unique($hashes));
2120                                                                 }
2121                                                         }
2122                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
2123                                                         {
2124                                                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
2125                                                                 {
2126                                                                         $value = null;
2127                                                                         $algo = null;
2128                                                                         if (isset($hash['data']))
2129                                                                         {
2130                                                                                 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2131                                                                         }
2132                                                                         if (isset($hash['attribs']['']['algo']))
2133                                                                         {
2134                                                                                 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
2135                                                                         }
2136                                                                         else
2137                                                                         {
2138                                                                                 $algo = 'md5';
2139                                                                         }
2140                                                                         $hashes[] = $algo.':'.$value;
2141                                                                 }
2142                                                                 if (is_array($hashes))
2143                                                                 {
2144                                                                         $hashes = array_values(array_unique($hashes));
2145                                                                 }
2146                                                         }
2147                                                         else
2148                                                         {
2149                                                                 $hashes = $hashes_parent;
2150                                                         }
2152                                                         // KEYWORDS
2153                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
2154                                                         {
2155                                                                 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
2156                                                                 {
2157                                                                         $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
2158                                                                         foreach ($temp as $word)
2159                                                                         {
2160                                                                                 $keywords[] = trim($word);
2161                                                                         }
2162                                                                         unset($temp);
2163                                                                 }
2164                                                                 if (is_array($keywords))
2165                                                                 {
2166                                                                         $keywords = array_values(array_unique($keywords));
2167                                                                 }
2168                                                         }
2169                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
2170                                                         {
2171                                                                 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
2172                                                                 {
2173                                                                         $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
2174                                                                         foreach ($temp as $word)
2175                                                                         {
2176                                                                                 $keywords[] = trim($word);
2177                                                                         }
2178                                                                         unset($temp);
2179                                                                 }
2180                                                                 if (is_array($keywords))
2181                                                                 {
2182                                                                         $keywords = array_values(array_unique($keywords));
2183                                                                 }
2184                                                         }
2185                                                         else
2186                                                         {
2187                                                                 $keywords = $keywords_parent;
2188                                                         }
2190                                                         // PLAYER
2191                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
2192                                                         {
2193                                                                 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
2194                                                         }
2195                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
2196                                                         {
2197                                                                 $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
2198                                                         }
2199                                                         else
2200                                                         {
2201                                                                 $player = $player_parent;
2202                                                         }
2204                                                         // RATINGS
2205                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
2206                                                         {
2207                                                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
2208                                                                 {
2209                                                                         $rating_scheme = null;
2210                                                                         $rating_value = null;
2211                                                                         if (isset($rating['attribs']['']['scheme']))
2212                                                                         {
2213                                                                                 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2214                                                                         }
2215                                                                         else
2216                                                                         {
2217                                                                                 $rating_scheme = 'urn:simple';
2218                                                                         }
2219                                                                         if (isset($rating['data']))
2220                                                                         {
2221                                                                                 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2222                                                                         }
2223                                                                         $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
2224                                                                 }
2225                                                                 if (is_array($ratings))
2226                                                                 {
2227                                                                         $ratings = array_values(array_unique($ratings));
2228                                                                 }
2229                                                         }
2230                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
2231                                                         {
2232                                                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
2233                                                                 {
2234                                                                         $rating_scheme = null;
2235                                                                         $rating_value = null;
2236                                                                         if (isset($rating['attribs']['']['scheme']))
2237                                                                         {
2238                                                                                 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2239                                                                         }
2240                                                                         else
2241                                                                         {
2242                                                                                 $rating_scheme = 'urn:simple';
2243                                                                         }
2244                                                                         if (isset($rating['data']))
2245                                                                         {
2246                                                                                 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2247                                                                         }
2248                                                                         $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
2249                                                                 }
2250                                                                 if (is_array($ratings))
2251                                                                 {
2252                                                                         $ratings = array_values(array_unique($ratings));
2253                                                                 }
2254                                                         }
2255                                                         else
2256                                                         {
2257                                                                 $ratings = $ratings_parent;
2258                                                         }
2260                                                         // RESTRICTIONS
2261                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
2262                                                         {
2263                                                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
2264                                                                 {
2265                                                                         $restriction_relationship = null;
2266                                                                         $restriction_type = null;
2267                                                                         $restriction_value = null;
2268                                                                         if (isset($restriction['attribs']['']['relationship']))
2269                                                                         {
2270                                                                                 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
2271                                                                         }
2272                                                                         if (isset($restriction['attribs']['']['type']))
2273                                                                         {
2274                                                                                 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
2275                                                                         }
2276                                                                         if (isset($restriction['data']))
2277                                                                         {
2278                                                                                 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2279                                                                         }
2280                                                                         $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
2281                                                                 }
2282                                                                 if (is_array($restrictions))
2283                                                                 {
2284                                                                         $restrictions = array_values(array_unique($restrictions));
2285                                                                 }
2286                                                         }
2287                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
2288                                                         {
2289                                                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
2290                                                                 {
2291                                                                         $restriction_relationship = null;
2292                                                                         $restriction_type = null;
2293                                                                         $restriction_value = null;
2294                                                                         if (isset($restriction['attribs']['']['relationship']))
2295                                                                         {
2296                                                                                 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
2297                                                                         }
2298                                                                         if (isset($restriction['attribs']['']['type']))
2299                                                                         {
2300                                                                                 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
2301                                                                         }
2302                                                                         if (isset($restriction['data']))
2303                                                                         {
2304                                                                                 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2305                                                                         }
2306                                                                         $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
2307                                                                 }
2308                                                                 if (is_array($restrictions))
2309                                                                 {
2310                                                                         $restrictions = array_values(array_unique($restrictions));
2311                                                                 }
2312                                                         }
2313                                                         else
2314                                                         {
2315                                                                 $restrictions = $restrictions_parent;
2316                                                         }
2318                                                         // THUMBNAILS
2319                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
2320                                                         {
2321                                                                 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
2322                                                                 {
2323                                                                         $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
2324                                                                 }
2325                                                                 if (is_array($thumbnails))
2326                                                                 {
2327                                                                         $thumbnails = array_values(array_unique($thumbnails));
2328                                                                 }
2329                                                         }
2330                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
2331                                                         {
2332                                                                 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
2333                                                                 {
2334                                                                         $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
2335                                                                 }
2336                                                                 if (is_array($thumbnails))
2337                                                                 {
2338                                                                         $thumbnails = array_values(array_unique($thumbnails));
2339                                                                 }
2340                                                         }
2341                                                         else
2342                                                         {
2343                                                                 $thumbnails = $thumbnails_parent;
2344                                                         }
2346                                                         // TITLES
2347                                                         if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
2348                                                         {
2349                                                                 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2350                                                         }
2351                                                         elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
2352                                                         {
2353                                                                 $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2354                                                         }
2355                                                         else
2356                                                         {
2357                                                                 $title = $title_parent;
2358                                                         }
2360                                                         $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
2361                                                 }
2362                                         }
2363                                 }
2364                         }
2366                         // If we have standalone media:content tags, loop through them.
2367                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
2368                         {
2369                                 foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
2370                                 {
2371                                         if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
2372                                         {
2373                                                 // Attributes
2374                                                 $bitrate = null;
2375                                                 $channels = null;
2376                                                 $duration = null;
2377                                                 $expression = null;
2378                                                 $framerate = null;
2379                                                 $height = null;
2380                                                 $javascript = null;
2381                                                 $lang = null;
2382                                                 $length = null;
2383                                                 $medium = null;
2384                                                 $samplingrate = null;
2385                                                 $type = null;
2386                                                 $url = null;
2387                                                 $width = null;
2389                                                 // Elements
2390                                                 $captions = null;
2391                                                 $categories = null;
2392                                                 $copyrights = null;
2393                                                 $credits = null;
2394                                                 $description = null;
2395                                                 $hashes = null;
2396                                                 $keywords = null;
2397                                                 $player = null;
2398                                                 $ratings = null;
2399                                                 $restrictions = null;
2400                                                 $thumbnails = null;
2401                                                 $title = null;
2403                                                 // Start checking the attributes of media:content
2404                                                 if (isset($content['attribs']['']['bitrate']))
2405                                                 {
2406                                                         $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
2407                                                 }
2408                                                 if (isset($content['attribs']['']['channels']))
2409                                                 {
2410                                                         $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
2411                                                 }
2412                                                 if (isset($content['attribs']['']['duration']))
2413                                                 {
2414                                                         $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
2415                                                 }
2416                                                 else
2417                                                 {
2418                                                         $duration = $duration_parent;
2419                                                 }
2420                                                 if (isset($content['attribs']['']['expression']))
2421                                                 {
2422                                                         $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
2423                                                 }
2424                                                 if (isset($content['attribs']['']['framerate']))
2425                                                 {
2426                                                         $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
2427                                                 }
2428                                                 if (isset($content['attribs']['']['height']))
2429                                                 {
2430                                                         $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
2431                                                 }
2432                                                 if (isset($content['attribs']['']['lang']))
2433                                                 {
2434                                                         $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2435                                                 }
2436                                                 if (isset($content['attribs']['']['fileSize']))
2437                                                 {
2438                                                         $length = ceil($content['attribs']['']['fileSize']);
2439                                                 }
2440                                                 if (isset($content['attribs']['']['medium']))
2441                                                 {
2442                                                         $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
2443                                                 }
2444                                                 if (isset($content['attribs']['']['samplingrate']))
2445                                                 {
2446                                                         $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
2447                                                 }
2448                                                 if (isset($content['attribs']['']['type']))
2449                                                 {
2450                                                         $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
2451                                                 }
2452                                                 if (isset($content['attribs']['']['width']))
2453                                                 {
2454                                                         $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
2455                                                 }
2456                                                 if (isset($content['attribs']['']['url']))
2457                                                 {
2458                                           &n