5 * A PHP-Based RSS and Atom Feed Framework.
6 * Takes the hard work out of managing a complete RSS/Atom solution.
8 * Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
11 * Redistribution and use in source and binary forms, with or without modification, are
12 * permitted provided that the following conditions are met:
14 * * Redistributions of source code must retain the above copyright notice, this list of
15 * conditions and the following disclaimer.
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.
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
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.
37 * @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
39 * @author Geoffrey Sneddon
41 * @link http://simplepie.org/ SimplePie
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @todo phpDoc comments
52 public function __construct($feed, $data)
58 public function __toString()
60 return md5(serialize($this->data
));
64 * Remove items that link back to this before destroying this object
66 public function __destruct()
68 if ((version_compare(PHP_VERSION
, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
74 public function get_item_tags($namespace, $tag)
76 if (isset($this->data
['child'][$namespace][$tag]))
78 return $this->data
['child'][$namespace][$tag];
86 public function get_base($element = array())
88 return $this->feed
->get_base($element);
91 public function sanitize($data, $type, $base = '')
93 return $this->feed
->sanitize($data, $type, $base);
96 public function get_feed()
101 public function get_id($hash = false)
105 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'id'))
107 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
109 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'id'))
111 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
113 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'guid'))
115 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
117 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'identifier'))
119 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
121 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'identifier'))
123 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
125 elseif (isset($this->data
['attribs'][SIMPLEPIE_NAMESPACE_RDF
]['about']))
127 return $this->sanitize($this->data
['attribs'][SIMPLEPIE_NAMESPACE_RDF
]['about'], SIMPLEPIE_CONSTRUCT_TEXT
);
129 elseif (($return = $this->get_permalink()) !== null)
133 elseif (($return = $this->get_title()) !== null)
138 if ($this->get_permalink() !== null || $this->get_title() !== null)
140 return md5($this->get_permalink() . $this->get_title());
144 return md5(serialize($this->data
));
148 public function get_title()
150 if (!isset($this->data
['title']))
152 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'title'))
154 $this->data
['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
156 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'title'))
158 $this->data
['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
160 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'title'))
162 $this->data
['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
164 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'title'))
166 $this->data
['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
168 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'title'))
170 $this->data
['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
172 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'title'))
174 $this->data
['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
176 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'title'))
178 $this->data
['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
182 $this->data
['title'] = null;
185 return $this->data
['title'];
188 public function get_description($description_only = false)
190 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'summary'))
192 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
194 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'summary'))
196 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
198 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'description'))
200 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
202 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'description'))
204 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
206 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'description'))
208 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
210 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'description'))
212 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
214 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'summary'))
216 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
218 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'subtitle'))
220 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
222 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'description'))
224 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
);
227 elseif (!$description_only)
229 return $this->get_content(true);
237 public function get_content($content_only = false)
239 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'content'))
241 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_content_construct_type($return[0]['attribs']), $this->get_base($return[0]));
243 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'content'))
245 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
247 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT
, 'encoded'))
249 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
251 elseif (!$content_only)
253 return $this->get_description(true);
261 public function get_category($key = 0)
263 $categories = $this->get_categories();
264 if (isset($categories[$key]))
266 return $categories[$key];
274 public function get_categories()
276 $categories = array();
278 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'category') as $category)
283 if (isset($category['attribs']['']['term']))
285 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT
);
287 if (isset($category['attribs']['']['scheme']))
289 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
291 if (isset($category['attribs']['']['label']))
293 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
295 $categories[] = new $this->feed
->category_class($term, $scheme, $label);
297 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'category') as $category)
299 // This is really the label, but keep this as the term also for BC.
300 // Label will also work on retrieving because that falls back to term.
301 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
302 if (isset($category['attribs']['']['domain']))
304 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT
);
310 $categories[] = new $this->feed
->category_class($term, $scheme, null);
312 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'subject') as $category)
314 $categories[] = new $this->feed
->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
316 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'subject') as $category)
318 $categories[] = new $this->feed
->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
321 if (!empty($categories))
323 return SimplePie_Misc
::array_unique($categories);
331 public function get_author($key = 0)
333 $authors = $this->get_authors();
334 if (isset($authors[$key]))
336 return $authors[$key];
344 public function get_contributor($key = 0)
346 $contributors = $this->get_contributors();
347 if (isset($contributors[$key]))
349 return $contributors[$key];
357 public function get_contributors()
359 $contributors = array();
360 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'contributor') as $contributor)
365 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data']))
367 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
369 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['uri'][0]['data']))
371 $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]));
373 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data']))
375 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
377 if ($name !== null || $email !== null || $uri !== null)
379 $contributors[] = new $this->feed
->author_class($name, $uri, $email);
382 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'contributor') as $contributor)
387 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data']))
389 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
391 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['url'][0]['data']))
393 $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]));
395 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data']))
397 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
399 if ($name !== null || $email !== null || $url !== null)
401 $contributors[] = new $this->feed
->author_class($name, $url, $email);
405 if (!empty($contributors))
407 return SimplePie_Misc
::array_unique($contributors);
415 public function get_authors()
418 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'author') as $author)
423 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data']))
425 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
427 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['uri'][0]['data']))
429 $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]));
431 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data']))
433 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
435 if ($name !== null || $email !== null || $uri !== null)
437 $authors[] = new $this->feed
->author_class($name, $uri, $email);
440 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'author'))
445 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data']))
447 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
449 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['url'][0]['data']))
451 $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]));
453 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data']))
455 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
457 if ($name !== null || $email !== null || $url !== null)
459 $authors[] = new $this->feed
->author_class($name, $url, $email);
462 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'author'))
464 $authors[] = new $this->feed
->author_class(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
466 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'creator') as $author)
468 $authors[] = new $this->feed
->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
470 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'creator') as $author)
472 $authors[] = new $this->feed
->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
474 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'author') as $author)
476 $authors[] = new $this->feed
->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
479 if (!empty($authors))
481 return SimplePie_Misc
::array_unique($authors);
483 elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
487 elseif ($authors = $this->feed
->get_authors())
497 public function get_copyright()
499 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'rights'))
501 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
503 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'rights'))
505 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
507 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'rights'))
509 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
517 public function get_date($date_format = 'j F Y, g:i a')
519 if (!isset($this->data
['date']))
521 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'published'))
523 $this->data
['date']['raw'] = $return[0]['data'];
525 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'updated'))
527 $this->data
['date']['raw'] = $return[0]['data'];
529 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'issued'))
531 $this->data
['date']['raw'] = $return[0]['data'];
533 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'created'))
535 $this->data
['date']['raw'] = $return[0]['data'];
537 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'modified'))
539 $this->data
['date']['raw'] = $return[0]['data'];
541 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'pubDate'))
543 $this->data
['date']['raw'] = $return[0]['data'];
545 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'date'))
547 $this->data
['date']['raw'] = $return[0]['data'];
549 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'date'))
551 $this->data
['date']['raw'] = $return[0]['data'];
554 if (!empty($this->data
['date']['raw']))
556 $parser = SimplePie_Parse_Date
::get();
557 $this->data
['date']['parsed'] = $parser->parse($this->data
['date']['raw']);
561 $this->data
['date'] = null;
564 if ($this->data
['date'])
566 $date_format = (string) $date_format;
567 switch ($date_format)
570 return $this->sanitize($this->data
['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT
);
573 return $this->data
['date']['parsed'];
576 return date($date_format, $this->data
['date']['parsed']);
585 public function get_local_date($date_format = '%c')
589 return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT
);
591 elseif (($date = $this->get_date('U')) !== null && $date !== false)
593 return strftime($date_format, $date);
601 public function get_permalink()
603 $link = $this->get_link();
604 $enclosure = $this->get_enclosure(0);
609 elseif ($enclosure !== null)
611 return $enclosure->get_link();
619 public function get_link($key = 0, $rel = 'alternate')
621 $links = $this->get_links($rel);
622 if ($links[$key] !== null)
632 public function get_links($rel = 'alternate')
634 if (!isset($this->data
['links']))
636 $this->data
['links'] = array();
637 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'link') as $link)
639 if (isset($link['attribs']['']['href']))
641 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
642 $this->data
['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
646 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'link') as $link)
648 if (isset($link['attribs']['']['href']))
650 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
651 $this->data
['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
654 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'link'))
656 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
658 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'link'))
660 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
662 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'link'))
664 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
666 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'guid'))
668 if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
670 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
674 $keys = array_keys($this->data
['links']);
675 foreach ($keys as $key)
677 if (SimplePie_Misc
::is_isegment_nz_nc($key))
679 if (isset($this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key]))
681 $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key] = array_merge($this->data
['links'][$key], $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key]);
682 $this->data
['links'][$key] =& $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key];
686 $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key] =& $this->data
['links'][$key];
689 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
)
691 $this->data
['links'][substr($key, 41)] =& $this->data
['links'][$key];
693 $this->data
['links'][$key] = array_unique($this->data
['links'][$key]);
696 if (isset($this->data
['links'][$rel]))
698 return $this->data
['links'][$rel];
707 * @todo Add ability to prefer one type of content over another (in a media group).
709 public function get_enclosure($key = 0, $prefer = null)
711 $enclosures = $this->get_enclosures();
712 if (isset($enclosures[$key]))
714 return $enclosures[$key];
723 * Grabs all available enclosures (podcasts, etc.)
725 * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
727 * At this point, we're pretty much assuming that all enclosures for an item are the same content. Anything else is too complicated to properly support.
729 * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
730 * @todo If an element exists at a level, but it's value is empty, we should fall back to the value from the parent (if it exists).
732 public function get_enclosures()
734 if (!isset($this->data
['enclosures']))
736 $this->data
['enclosures'] = array();
739 $captions_parent = null;
740 $categories_parent = null;
741 $copyrights_parent = null;
742 $credits_parent = null;
743 $description_parent = null;
744 $duration_parent = null;
745 $hashes_parent = null;
746 $keywords_parent = null;
747 $player_parent = null;
748 $ratings_parent = null;
749 $restrictions_parent = null;
750 $thumbnails_parent = null;
751 $title_parent = null;
753 // Let's do the channel and item-level ones first, and just re-use them if we need to.
754 $parent = $this->get_feed();
757 if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'text'))
759 foreach ($captions as $caption)
761 $caption_type = null;
762 $caption_lang = null;
763 $caption_startTime = null;
764 $caption_endTime = null;
765 $caption_text = null;
766 if (isset($caption['attribs']['']['type']))
768 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
770 if (isset($caption['attribs']['']['lang']))
772 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
774 if (isset($caption['attribs']['']['start']))
776 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT
);
778 if (isset($caption['attribs']['']['end']))
780 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT
);
782 if (isset($caption['data']))
784 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
786 $captions_parent[] = new $this->feed
->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
789 elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'text'))
791 foreach ($captions as $caption)
793 $caption_type = null;
794 $caption_lang = null;
795 $caption_startTime = null;
796 $caption_endTime = null;
797 $caption_text = null;
798 if (isset($caption['attribs']['']['type']))
800 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
802 if (isset($caption['attribs']['']['lang']))
804 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
806 if (isset($caption['attribs']['']['start']))
808 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT
);
810 if (isset($caption['attribs']['']['end']))
812 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT
);
814 if (isset($caption['data']))
816 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
818 $captions_parent[] = new $this->feed
->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
821 if (is_array($captions_parent))
823 $captions_parent = array_values(SimplePie_Misc
::array_unique($captions_parent));
827 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'category') as $category)
832 if (isset($category['data']))
834 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
836 if (isset($category['attribs']['']['scheme']))
838 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
842 $scheme = 'http://search.yahoo.com/mrss/category_schema';
844 if (isset($category['attribs']['']['label']))
846 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
848 $categories_parent[] = new $this->feed
->category_class($term, $scheme, $label);
850 foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'category') as $category)
855 if (isset($category['data']))
857 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
859 if (isset($category['attribs']['']['scheme']))
861 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
865 $scheme = 'http://search.yahoo.com/mrss/category_schema';
867 if (isset($category['attribs']['']['label']))
869 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
871 $categories_parent[] = new $this->feed
->category_class($term, $scheme, $label);
873 foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'category') as $category)
876 $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
878 if (isset($category['attribs']['']['text']))
880 $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT
);
882 $categories_parent[] = new $this->feed
->category_class($term, $scheme, $label);
884 if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES
]['category']))
886 foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES
]['category'] as $subcategory)
888 if (isset($subcategory['attribs']['']['text']))
890 $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT
);
892 $categories_parent[] = new $this->feed
->category_class($term, $scheme, $label);
896 if (is_array($categories_parent))
898 $categories_parent = array_values(SimplePie_Misc
::array_unique($categories_parent));
902 if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'copyright'))
904 $copyright_url = null;
905 $copyright_label = null;
906 if (isset($copyright[0]['attribs']['']['url']))
908 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT
);
910 if (isset($copyright[0]['data']))
912 $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
914 $copyrights_parent = new $this->feed
->copyright_class($copyright_url, $copyright_label);
916 elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'copyright'))
918 $copyright_url = null;
919 $copyright_label = null;
920 if (isset($copyright[0]['attribs']['']['url']))
922 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT
);
924 if (isset($copyright[0]['data']))
926 $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
928 $copyrights_parent = new $this->feed
->copyright_class($copyright_url, $copyright_label);
932 if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'credit'))
934 foreach ($credits as $credit)
937 $credit_scheme = null;
939 if (isset($credit['attribs']['']['role']))
941 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT
);
943 if (isset($credit['attribs']['']['scheme']))
945 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
949 $credit_scheme = 'urn:ebu';
951 if (isset($credit['data']))
953 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
955 $credits_parent[] = new $this->feed
->credit_class($credit_role, $credit_scheme, $credit_name);
958 elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'credit'))
960 foreach ($credits as $credit)
963 $credit_scheme = null;
965 if (isset($credit['attribs']['']['role']))
967 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT
);
969 if (isset($credit['attribs']['']['scheme']))
971 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
975 $credit_scheme = 'urn:ebu';
977 if (isset($credit['data']))
979 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
981 $credits_parent[] = new $this->feed
->credit_class($credit_role, $credit_scheme, $credit_name);
984 if (is_array($credits_parent))
986 $credits_parent = array_values(SimplePie_Misc
::array_unique($credits_parent));
990 if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'description'))
992 if (isset($description_parent[0]['data']))
994 $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
997 elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'description'))
999 if (isset($description_parent[0]['data']))
1001 $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1006 if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'duration'))
1011 if (isset($duration_parent[0]['data']))
1013 $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1014 if (sizeof($temp) > 0)
1016 $seconds = (int) array_pop($temp);
1018 if (sizeof($temp) > 0)
1020 $minutes = (int) array_pop($temp);
1021 $seconds +
= $minutes * 60;
1023 if (sizeof($temp) > 0)
1025 $hours = (int) array_pop($temp);
1026 $seconds +
= $hours * 3600;
1029 $duration_parent = $seconds;
1034 if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'hash'))
1036 foreach ($hashes_iterator as $hash)
1040 if (isset($hash['data']))
1042 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1044 if (isset($hash['attribs']['']['algo']))
1046 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT
);
1052 $hashes_parent[] = $algo.':'.$value;
1055 elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'hash'))
1057 foreach ($hashes_iterator as $hash)
1061 if (isset($hash['data']))
1063 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1065 if (isset($hash['attribs']['']['algo']))
1067 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT
);
1073 $hashes_parent[] = $algo.':'.$value;
1076 if (is_array($hashes_parent))
1078 $hashes_parent = array_values(SimplePie_Misc
::array_unique($hashes_parent));
1082 if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'keywords'))
1084 if (isset($keywords[0]['data']))
1086 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1087 foreach ($temp as $word)
1089 $keywords_parent[] = trim($word);
1094 elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'keywords'))
1096 if (isset($keywords[0]['data']))
1098 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1099 foreach ($temp as $word)
1101 $keywords_parent[] = trim($word);
1106 elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'keywords'))
1108 if (isset($keywords[0]['data']))
1110 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1111 foreach ($temp as $word)
1113 $keywords_parent[] = trim($word);
1118 elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'keywords'))
1120 if (isset($keywords[0]['data']))
1122 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1123 foreach ($temp as $word)
1125 $keywords_parent[] = trim($word);
1130 if (is_array($keywords_parent))
1132 $keywords_parent = array_values(SimplePie_Misc
::array_unique($keywords_parent));
1136 if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'player'))
1138 if (isset($player_parent[0]['attribs']['']['url']))
1140 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1143 elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'player'))
1145 if (isset($player_parent[0]['attribs']['']['url']))
1147 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1152 if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'rating'))
1154 foreach ($ratings as $rating)
1156 $rating_scheme = null;
1157 $rating_value = null;
1158 if (isset($rating['attribs']['']['scheme']))
1160 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1164 $rating_scheme = 'urn:simple';
1166 if (isset($rating['data']))
1168 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1170 $ratings_parent[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
1173 elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'explicit'))
1175 foreach ($ratings as $rating)
1177 $rating_scheme = 'urn:itunes';
1178 $rating_value = null;
1179 if (isset($rating['data']))
1181 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1183 $ratings_parent[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
1186 elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'rating'))
1188 foreach ($ratings as $rating)
1190 $rating_scheme = null;
1191 $rating_value = null;
1192 if (isset($rating['attribs']['']['scheme']))
1194 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1198 $rating_scheme = 'urn:simple';
1200 if (isset($rating['data']))
1202 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1204 $ratings_parent[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
1207 elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'explicit'))
1209 foreach ($ratings as $rating)
1211 $rating_scheme = 'urn:itunes';
1212 $rating_value = null;
1213 if (isset($rating['data']))
1215 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1217 $ratings_parent[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
1220 if (is_array($ratings_parent))
1222 $ratings_parent = array_values(SimplePie_Misc
::array_unique($ratings_parent));
1226 if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'restriction'))
1228 foreach ($restrictions as $restriction)
1230 $restriction_relationship = null;
1231 $restriction_type = null;
1232 $restriction_value = null;
1233 if (isset($restriction['attribs']['']['relationship']))
1235 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT
);
1237 if (isset($restriction['attribs']['']['type']))
1239 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1241 if (isset($restriction['data']))
1243 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1245 $restrictions_parent[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
1248 elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'block'))
1250 foreach ($restrictions as $restriction)
1252 $restriction_relationship = 'allow';
1253 $restriction_type = null;
1254 $restriction_value = 'itunes';
1255 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
1257 $restriction_relationship = 'deny';
1259 $restrictions_parent[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
1262 elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'restriction'))
1264 foreach ($restrictions as $restriction)
1266 $restriction_relationship = null;
1267 $restriction_type = null;
1268 $restriction_value = null;
1269 if (isset($restriction['attribs']['']['relationship']))
1271 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT
);
1273 if (isset($restriction['attribs']['']['type']))
1275 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1277 if (isset($restriction['data']))
1279 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1281 $restrictions_parent[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
1284 elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'block'))
1286 foreach ($restrictions as $restriction)
1288 $restriction_relationship = 'allow';
1289 $restriction_type = null;
1290 $restriction_value = 'itunes';
1291 if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
1293 $restriction_relationship = 'deny';
1295 $restrictions_parent[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
1298 if (is_array($restrictions_parent))
1300 $restrictions_parent = array_values(SimplePie_Misc
::array_unique($restrictions_parent));
1304 if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'thumbnail'))
1306 foreach ($thumbnails as $thumbnail)
1308 if (isset($thumbnail['attribs']['']['url']))
1310 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1314 elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'thumbnail'))
1316 foreach ($thumbnails as $thumbnail)
1318 if (isset($thumbnail['attribs']['']['url']))
1320 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1326 if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'title'))
1328 if (isset($title_parent[0]['data']))
1330 $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1333 elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'title'))
1335 if (isset($title_parent[0]['data']))
1337 $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1355 $samplingrate = null;
1365 $description = null;
1370 $restrictions = null;
1374 // If we have media:group tags, loop through them.
1375 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS
, 'group') as $group)
1377 if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['content']))
1379 // If we have media:content tags, loop through them.
1380 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['content'] as $content)
1382 if (isset($content['attribs']['']['url']))
1395 $samplingrate = null;
1405 $description = null;
1410 $restrictions = null;
1414 // Start checking the attributes of media:content
1415 if (isset($content['attribs']['']['bitrate']))
1417 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT
);
1419 if (isset($content['attribs']['']['channels']))
1421 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT
);
1423 if (isset($content['attribs']['']['duration']))
1425 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT
);
1429 $duration = $duration_parent;
1431 if (isset($content['attribs']['']['expression']))
1433 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT
);
1435 if (isset($content['attribs']['']['framerate']))
1437 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT
);
1439 if (isset($content['attribs']['']['height']))
1441 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT
);
1443 if (isset($content['attribs']['']['lang']))
1445 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
1447 if (isset($content['attribs']['']['fileSize']))
1449 $length = ceil($content['attribs']['']['fileSize']);
1451 if (isset($content['attribs']['']['medium']))
1453 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT
);
1455 if (isset($content['attribs']['']['samplingrate']))
1457 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT
);
1459 if (isset($content['attribs']['']['type']))
1461 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1463 if (isset($content['attribs']['']['width']))
1465 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT
);
1467 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1469 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
1472 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['text']))
1474 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['text'] as $caption)
1476 $caption_type = null;
1477 $caption_lang = null;
1478 $caption_startTime = null;
1479 $caption_endTime = null;
1480 $caption_text = null;
1481 if (isset($caption['attribs']['']['type']))
1483 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1485 if (isset($caption['attribs']['']['lang']))
1487 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
1489 if (isset($caption['attribs']['']['start']))
1491 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT
);
1493 if (isset($caption['attribs']['']['end']))
1495 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT
);
1497 if (isset($caption['data']))
1499 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1501 $captions[] = new $this->feed
->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
1503 if (is_array($captions))
1505 $captions = array_values(SimplePie_Misc
::array_unique($captions));
1508 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['text']))
1510 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['text'] as $caption)
1512 $caption_type = null;
1513 $caption_lang = null;
1514 $caption_startTime = null;
1515 $caption_endTime = null;
1516 $caption_text = null;
1517 if (isset($caption['attribs']['']['type']))
1519 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1521 if (isset($caption['attribs']['']['lang']))
1523 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
1525 if (isset($caption['attribs']['']['start']))
1527 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT
);
1529 if (isset($caption['attribs']['']['end']))
1531 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT
);
1533 if (isset($caption['data']))
1535 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1537 $captions[] = new $this->feed
->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
1539 if (is_array($captions))
1541 $captions = array_values(SimplePie_Misc
::array_unique($captions));
1546 $captions = $captions_parent;
1550 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['category']))
1552 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['category'] as $category)
1557 if (isset($category['data']))
1559 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1561 if (isset($category['attribs']['']['scheme']))
1563 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1567 $scheme = 'http://search.yahoo.com/mrss/category_schema';
1569 if (isset($category['attribs']['']['label']))
1571 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
1573 $categories[] = new $this->feed
->category_class($term, $scheme, $label);
1576 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['category']))
1578 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['category'] as $category)
1583 if (isset($category['data']))
1585 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1587 if (isset($category['attribs']['']['scheme']))
1589 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1593 $scheme = 'http://search.yahoo.com/mrss/category_schema';
1595 if (isset($category['attribs']['']['label']))
1597 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
1599 $categories[] = new $this->feed
->category_class($term, $scheme, $label);
1602 if (is_array($categories) && is_array($categories_parent))
1604 $categories = array_values(SimplePie_Misc
::array_unique(array_merge($categories, $categories_parent)));
1606 elseif (is_array($categories))
1608 $categories = array_values(SimplePie_Misc
::array_unique($categories));
1610 elseif (is_array($categories_parent))
1612 $categories = array_values(SimplePie_Misc
::array_unique($categories_parent));
1616 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright']))
1618 $copyright_url = null;
1619 $copyright_label = null;
1620 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['attribs']['']['url']))
1622 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT
);
1624 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['data']))
1626 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1628 $copyrights = new $this->feed
->copyright_class($copyright_url, $copyright_label);
1630 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright']))
1632 $copyright_url = null;
1633 $copyright_label = null;
1634 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['attribs']['']['url']))
1636 $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT
);
1638 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['data']))
1640 $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1642 $copyrights = new $this->feed
->copyright_class($copyright_url, $copyright_label);
1646 $copyrights = $copyrights_parent;
1650 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['credit']))
1652 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['credit'] as $credit)
1654 $credit_role = null;
1655 $credit_scheme = null;
1656 $credit_name = null;
1657 if (isset($credit['attribs']['']['role']))
1659 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT
);
1661 if (isset($credit['attribs']['']['scheme']))
1663 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1667 $credit_scheme = 'urn:ebu';
1669 if (isset($credit['data']))
1671 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1673 $credits[] = new $this->feed
->credit_class($credit_role, $credit_scheme, $credit_name);
1675 if (is_array($credits))
1677 $credits = array_values(SimplePie_Misc
::array_unique($credits));
1680 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['credit']))
1682 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['credit'] as $credit)
1684 $credit_role = null;
1685 $credit_scheme = null;
1686 $credit_name = null;
1687 if (isset($credit['attribs']['']['role']))
1689 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT
);
1691 if (isset($credit['attribs']['']['scheme']))
1693 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1697 $credit_scheme = 'urn:ebu';
1699 if (isset($credit['data']))
1701 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1703 $credits[] = new $this->feed
->credit_class($credit_role, $credit_scheme, $credit_name);
1705 if (is_array($credits))
1707 $credits = array_values(SimplePie_Misc
::array_unique($credits));
1712 $credits = $credits_parent;
1716 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['description']))
1718 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1720 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['description']))
1722 $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1726 $description = $description_parent;
1730 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['hash']))
1732 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['hash'] as $hash)
1736 if (isset($hash['data']))
1738 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1740 if (isset($hash['attribs']['']['algo']))
1742 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT
);
1748 $hashes[] = $algo.':'.$value;
1750 if (is_array($hashes))
1752 $hashes = array_values(SimplePie_Misc
::array_unique($hashes));
1755 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['hash']))
1757 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['hash'] as $hash)
1761 if (isset($hash['data']))
1763 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1765 if (isset($hash['attribs']['']['algo']))
1767 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT
);
1773 $hashes[] = $algo.':'.$value;
1775 if (is_array($hashes))
1777 $hashes = array_values(SimplePie_Misc
::array_unique($hashes));
1782 $hashes = $hashes_parent;
1786 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords']))
1788 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords'][0]['data']))
1790 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1791 foreach ($temp as $word)
1793 $keywords[] = trim($word);
1797 if (is_array($keywords))
1799 $keywords = array_values(SimplePie_Misc
::array_unique($keywords));
1802 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords']))
1804 if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords'][0]['data']))
1806 $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
1807 foreach ($temp as $word)
1809 $keywords[] = trim($word);
1813 if (is_array($keywords))
1815 $keywords = array_values(SimplePie_Misc
::array_unique($keywords));
1820 $keywords = $keywords_parent;
1824 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player']))
1826 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1828 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player']))
1830 $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1834 $player = $player_parent;
1838 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['rating']))
1840 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['rating'] as $rating)
1842 $rating_scheme = null;
1843 $rating_value = null;
1844 if (isset($rating['attribs']['']['scheme']))
1846 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1850 $rating_scheme = 'urn:simple';
1852 if (isset($rating['data']))
1854 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1856 $ratings[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
1858 if (is_array($ratings))
1860 $ratings = array_values(SimplePie_Misc
::array_unique($ratings));
1863 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['rating']))
1865 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['rating'] as $rating)
1867 $rating_scheme = null;
1868 $rating_value = null;
1869 if (isset($rating['attribs']['']['scheme']))
1871 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
1875 $rating_scheme = 'urn:simple';
1877 if (isset($rating['data']))
1879 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1881 $ratings[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
1883 if (is_array($ratings))
1885 $ratings = array_values(SimplePie_Misc
::array_unique($ratings));
1890 $ratings = $ratings_parent;
1894 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['restriction']))
1896 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['restriction'] as $restriction)
1898 $restriction_relationship = null;
1899 $restriction_type = null;
1900 $restriction_value = null;
1901 if (isset($restriction['attribs']['']['relationship']))
1903 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT
);
1905 if (isset($restriction['attribs']['']['type']))
1907 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1909 if (isset($restriction['data']))
1911 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1913 $restrictions[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
1915 if (is_array($restrictions))
1917 $restrictions = array_values(SimplePie_Misc
::array_unique($restrictions));
1920 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['restriction']))
1922 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['restriction'] as $restriction)
1924 $restriction_relationship = null;
1925 $restriction_type = null;
1926 $restriction_value = null;
1927 if (isset($restriction['attribs']['']['relationship']))
1929 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT
);
1931 if (isset($restriction['attribs']['']['type']))
1933 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
1935 if (isset($restriction['data']))
1937 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1939 $restrictions[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
1941 if (is_array($restrictions))
1943 $restrictions = array_values(SimplePie_Misc
::array_unique($restrictions));
1948 $restrictions = $restrictions_parent;
1952 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['thumbnail']))
1954 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['thumbnail'] as $thumbnail)
1956 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1958 if (is_array($thumbnails))
1960 $thumbnails = array_values(SimplePie_Misc
::array_unique($thumbnails));
1963 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['thumbnail']))
1965 foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['thumbnail'] as $thumbnail)
1967 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
1969 if (is_array($thumbnails))
1971 $thumbnails = array_values(SimplePie_Misc
::array_unique($thumbnails));
1976 $thumbnails = $thumbnails_parent;
1980 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['title']))
1982 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1984 elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['title']))
1986 $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
1990 $title = $title_parent;
1993 $this->data
['enclosures'][] = new $this->feed
->enclosure_class($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width);
1999 // If we have standalone media:content tags, loop through them.
2000 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['content']))
2002 foreach ((array) $this->data
['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['content'] as $content)
2004 if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player']))
2017 $samplingrate = null;
2027 $description = null;
2032 $restrictions = null;
2036 // Start checking the attributes of media:content
2037 if (isset($content['attribs']['']['bitrate']))
2039 $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT
);
2041 if (isset($content['attribs']['']['channels']))
2043 $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT
);
2045 if (isset($content['attribs']['']['duration']))
2047 $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT
);
2051 $duration = $duration_parent;
2053 if (isset($content['attribs']['']['expression']))
2055 $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT
);
2057 if (isset($content['attribs']['']['framerate']))
2059 $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT
);
2061 if (isset($content['attribs']['']['height']))
2063 $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT
);
2065 if (isset($content['attribs']['']['lang']))
2067 $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2069 if (isset($content['attribs']['']['fileSize']))
2071 $length = ceil($content['attribs']['']['fileSize']);
2073 if (isset($content['attribs']['']['medium']))
2075 $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT
);
2077 if (isset($content['attribs']['']['samplingrate']))
2079 $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT
);
2081 if (isset($content['attribs']['']['type']))
2083 $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
2085 if (isset($content['attribs']['']['width']))
2087 $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT
);
2089 if (isset($content['attribs']['']['url']))
2091 $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
2093 // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
2096 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['text']))
2098 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['text'] as $caption)
2100 $caption_type = null;
2101 $caption_lang = null;
2102 $caption_startTime = null;
2103 $caption_endTime = null;
2104 $caption_text = null;
2105 if (isset($caption['attribs']['']['type']))
2107 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
2109 if (isset($caption['attribs']['']['lang']))
2111 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2113 if (isset($caption['attribs']['']['start']))
2115 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT
);
2117 if (isset($caption['attribs']['']['end']))
2119 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT
);
2121 if (isset($caption['data']))
2123 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2125 $captions[] = new $this->feed
->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
2127 if (is_array($captions))
2129 $captions = array_values(SimplePie_Misc
::array_unique($captions));
2134 $captions = $captions_parent;
2138 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['category']))
2140 foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['category'] as $category)
2145 if (isset($category['data']))
2147 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2149 if (isset($category['attribs']['']['scheme']))
2151 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
2155 $scheme = 'http://search.yahoo.com/mrss/category_schema';
2157 if (isset($category['attribs']['']['label']))
2159 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
2161 $categories[] = new $this->feed
->category_class($term, $scheme, $label);
2164 if (is_array($categories) && is_array($categories_parent))
2166 $categories = array_values(SimplePie_Misc
::array_unique(array_merge($categories, $categories_parent)));
2168 elseif (is_array($categories))
2170 $categories = array_values(SimplePie_Misc
::array_unique($categories));
2172 elseif (is_array($categories_parent))
2174 $categories = array_values(SimplePie_Misc
::array_unique($categories_parent));
2182 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright']))
2184 $copyright_url = null;
2185 $copyright_label = null;
2186 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['attribs']['']['url']))
2188 $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT
);
2190 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['data']))
2192 $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2194 $copyrights = new $this->feed
->copyright_class($copyright_url, $copyright_label);
2198 $copyrights = $copyrights_parent;
2202 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['credit']))
2204 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['credit'] as $credit)
2206 $credit_role = null;
2207 $credit_scheme = null;
2208 $credit_name = null;
2209 if (isset($credit['attribs']['']['role']))
2211 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT
);
2213 if (isset($credit['attribs']['']['scheme']))
2215 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
2219 $credit_scheme = 'urn:ebu';
2221 if (isset($credit['data']))
2223 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2225 $credits[] = new $this->feed
->credit_class($credit_role, $credit_scheme, $credit_name);
2227 if (is_array($credits))
2229 $credits = array_values(SimplePie_Misc
::array_unique($credits));
2234 $credits = $credits_parent;
2238 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['description']))
2240 $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2244 $description = $description_parent;
2248 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['hash']))
2250 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['hash'] as $hash)
2254 if (isset($hash['data']))
2256 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2258 if (isset($hash['attribs']['']['algo']))
2260 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT
);
2266 $hashes[] = $algo.':'.$value;
2268 if (is_array($hashes))
2270 $hashes = array_values(SimplePie_Misc
::array_unique($hashes));
2275 $hashes = $hashes_parent;
2279 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords']))
2281 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords'][0]['data']))
2283 $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
));
2284 foreach ($temp as $word)
2286 $keywords[] = trim($word);
2290 if (is_array($keywords))
2292 $keywords = array_values(SimplePie_Misc
::array_unique($keywords));
2297 $keywords = $keywords_parent;
2301 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player']))
2303 $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
2307 $player = $player_parent;
2311 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['rating']))
2313 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['rating'] as $rating)
2315 $rating_scheme = null;
2316 $rating_value = null;
2317 if (isset($rating['attribs']['']['scheme']))
2319 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
2323 $rating_scheme = 'urn:simple';
2325 if (isset($rating['data']))
2327 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2329 $ratings[] = new $this->feed
->rating_class($rating_scheme, $rating_value);
2331 if (is_array($ratings))
2333 $ratings = array_values(SimplePie_Misc
::array_unique($ratings));
2338 $ratings = $ratings_parent;
2342 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['restriction']))
2344 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['restriction'] as $restriction)
2346 $restriction_relationship = null;
2347 $restriction_type = null;
2348 $restriction_value = null;
2349 if (isset($restriction['attribs']['']['relationship']))
2351 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT
);
2353 if (isset($restriction['attribs']['']['type']))
2355 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
2357 if (isset($restriction['data']))
2359 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2361 $restrictions[] = new $this->feed
->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
2363 if (is_array($restrictions))
2365 $restrictions = array_values(SimplePie_Misc
::array_unique($restrictions));
2370 $restrictions = $restrictions_parent;
2374 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['thumbnail']))
2376 foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['thumbnail'] as $thumbnail)
2378 $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
);
2380 if (is_array($thumbnails))
2382 $thumbnails = array_values(SimplePie_Misc
::array_unique($thumbnails));
2387 $thumbnails = $thumbnails_parent;
2391 if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['title']))
2393 $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS
]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2397 $title = $title_parent;
2400 $this->data
['enclosures'][] = new $this->feed
->enclosure_class($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width);
2405 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'link') as $link)
2407 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
2420 $samplingrate = null;
2425 $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
2426 if (isset($link['attribs']['']['type']))
2428 $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
2430 if (isset($link['attribs']['']['length']))
2432 $length = ceil($link['attribs']['']['length']);
2435 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
2436 $this->data
['enclosures'][] = new $this->feed
->enclosure_class($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
2440 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'link') as $link)
2442 if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
2455 $samplingrate = null;
2460 $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
2461 if (isset($link['attribs']['']['type']))
2463 $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
2465 if (isset($link['attribs']['']['length']))
2467 $length = ceil($link['attribs']['']['length']);
2470 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
2471 $this->data
['enclosures'][] = new $this->feed
->enclosure_class($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
2475 if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'enclosure'))
2477 if (isset($enclosure[0]['attribs']['']['url']))
2490 $samplingrate = null;
2495 $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($enclosure[0]));
2496 if (isset($enclosure[0]['attribs']['']['type']))
2498 $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT
);
2500 if (isset($enclosure[0]['attribs']['']['length']))
2502 $length = ceil($enclosure[0]['attribs']['']['length']);
2505 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
2506 $this->data
['enclosures'][] = new $this->feed
->enclosure_class($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
2510 if (sizeof($this->data
['enclosures']) === 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width))
2512 // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
2513 $this->data
['enclosures'][] = new $this->feed
->enclosure_class($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
2516 $this->data
['enclosures'] = array_values(SimplePie_Misc
::array_unique($this->data
['enclosures']));
2518 if (!empty($this->data
['enclosures']))
2520 return $this->data
['enclosures'];
2528 public function get_latitude()
2530 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'lat'))
2532 return (float) $return[0]['data'];
2534 elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS
, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2536 return (float) $match[1];
2544 public function get_longitude()
2546 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'long'))
2548 return (float) $return[0]['data'];
2550 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'lon'))
2552 return (float) $return[0]['data'];
2554 elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS
, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2556 return (float) $match[2];
2564 public function get_source()
2566 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'source'))
2568 return new $this->feed
->source_class($this, $return[0]);