MDL-60236 libraries: Upgrade simplepie to 1.5.0
[moodle.git] / lib / simplepie / library / SimplePie.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-2017, 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  * @version 1.5
37  * @copyright 2004-2017 Ryan Parman, Geoffrey Sneddon, Ryan McCue
38  * @author Ryan Parman
39  * @author Geoffrey Sneddon
40  * @author Ryan McCue
41  * @link http://simplepie.org/ SimplePie
42  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43  */
45 /**
46  * SimplePie Name
47  */
48 define('SIMPLEPIE_NAME', 'SimplePie');
50 /**
51  * SimplePie Version
52  */
53 define('SIMPLEPIE_VERSION', '1.5');
55 /**
56  * SimplePie Build
57  * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
58  */
59 define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()));
61 /**
62  * SimplePie Website URL
63  */
64 define('SIMPLEPIE_URL', 'http://simplepie.org');
66 /**
67  * SimplePie Useragent
68  * @see SimplePie::set_useragent()
69  */
70 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
72 /**
73  * SimplePie Linkback
74  */
75 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
77 /**
78  * No Autodiscovery
79  * @see SimplePie::set_autodiscovery_level()
80  */
81 define('SIMPLEPIE_LOCATOR_NONE', 0);
83 /**
84  * Feed Link Element Autodiscovery
85  * @see SimplePie::set_autodiscovery_level()
86  */
87 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
89 /**
90  * Local Feed Extension Autodiscovery
91  * @see SimplePie::set_autodiscovery_level()
92  */
93 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
95 /**
96  * Local Feed Body Autodiscovery
97  * @see SimplePie::set_autodiscovery_level()
98  */
99 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
101 /**
102  * Remote Feed Extension Autodiscovery
103  * @see SimplePie::set_autodiscovery_level()
104  */
105 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
107 /**
108  * Remote Feed Body Autodiscovery
109  * @see SimplePie::set_autodiscovery_level()
110  */
111 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
113 /**
114  * All Feed Autodiscovery
115  * @see SimplePie::set_autodiscovery_level()
116  */
117 define('SIMPLEPIE_LOCATOR_ALL', 31);
119 /**
120  * No known feed type
121  */
122 define('SIMPLEPIE_TYPE_NONE', 0);
124 /**
125  * RSS 0.90
126  */
127 define('SIMPLEPIE_TYPE_RSS_090', 1);
129 /**
130  * RSS 0.91 (Netscape)
131  */
132 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
134 /**
135  * RSS 0.91 (Userland)
136  */
137 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
139 /**
140  * RSS 0.91 (both Netscape and Userland)
141  */
142 define('SIMPLEPIE_TYPE_RSS_091', 6);
144 /**
145  * RSS 0.92
146  */
147 define('SIMPLEPIE_TYPE_RSS_092', 8);
149 /**
150  * RSS 0.93
151  */
152 define('SIMPLEPIE_TYPE_RSS_093', 16);
154 /**
155  * RSS 0.94
156  */
157 define('SIMPLEPIE_TYPE_RSS_094', 32);
159 /**
160  * RSS 1.0
161  */
162 define('SIMPLEPIE_TYPE_RSS_10', 64);
164 /**
165  * RSS 2.0
166  */
167 define('SIMPLEPIE_TYPE_RSS_20', 128);
169 /**
170  * RDF-based RSS
171  */
172 define('SIMPLEPIE_TYPE_RSS_RDF', 65);
174 /**
175  * Non-RDF-based RSS (truly intended as syndication format)
176  */
177 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
179 /**
180  * All RSS
181  */
182 define('SIMPLEPIE_TYPE_RSS_ALL', 255);
184 /**
185  * Atom 0.3
186  */
187 define('SIMPLEPIE_TYPE_ATOM_03', 256);
189 /**
190  * Atom 1.0
191  */
192 define('SIMPLEPIE_TYPE_ATOM_10', 512);
194 /**
195  * All Atom
196  */
197 define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
199 /**
200  * All feed types
201  */
202 define('SIMPLEPIE_TYPE_ALL', 1023);
204 /**
205  * No construct
206  */
207 define('SIMPLEPIE_CONSTRUCT_NONE', 0);
209 /**
210  * Text construct
211  */
212 define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
214 /**
215  * HTML construct
216  */
217 define('SIMPLEPIE_CONSTRUCT_HTML', 2);
219 /**
220  * XHTML construct
221  */
222 define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
224 /**
225  * base64-encoded construct
226  */
227 define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
229 /**
230  * IRI construct
231  */
232 define('SIMPLEPIE_CONSTRUCT_IRI', 16);
234 /**
235  * A construct that might be HTML
236  */
237 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
239 /**
240  * All constructs
241  */
242 define('SIMPLEPIE_CONSTRUCT_ALL', 63);
244 /**
245  * Don't change case
246  */
247 define('SIMPLEPIE_SAME_CASE', 1);
249 /**
250  * Change to lowercase
251  */
252 define('SIMPLEPIE_LOWERCASE', 2);
254 /**
255  * Change to uppercase
256  */
257 define('SIMPLEPIE_UPPERCASE', 4);
259 /**
260  * PCRE for HTML attributes
261  */
262 define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
264 /**
265  * PCRE for XML attributes
266  */
267 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
269 /**
270  * XML Namespace
271  */
272 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
274 /**
275  * Atom 1.0 Namespace
276  */
277 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
279 /**
280  * Atom 0.3 Namespace
281  */
282 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
284 /**
285  * RDF Namespace
286  */
287 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
289 /**
290  * RSS 0.90 Namespace
291  */
292 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
294 /**
295  * RSS 1.0 Namespace
296  */
297 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
299 /**
300  * RSS 1.0 Content Module Namespace
301  */
302 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
304 /**
305  * RSS 2.0 Namespace
306  * (Stupid, I know, but I'm certain it will confuse people less with support.)
307  */
308 define('SIMPLEPIE_NAMESPACE_RSS_20', '');
310 /**
311  * DC 1.0 Namespace
312  */
313 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
315 /**
316  * DC 1.1 Namespace
317  */
318 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
320 /**
321  * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
322  */
323 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
325 /**
326  * GeoRSS Namespace
327  */
328 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
330 /**
331  * Media RSS Namespace
332  */
333 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
335 /**
336  * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
337  */
338 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
340 /**
341  * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
342  */
343 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
345 /**
346  * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
347  */
348 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
350 /**
351  * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
352  */
353 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
355 /**
356  * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
357  */
358 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
360 /**
361  * iTunes RSS Namespace
362  */
363 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
365 /**
366  * XHTML Namespace
367  */
368 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
370 /**
371  * IANA Link Relations Registry
372  */
373 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
375 /**
376  * No file source
377  */
378 define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
380 /**
381  * Remote file source
382  */
383 define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
385 /**
386  * Local file source
387  */
388 define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
390 /**
391  * fsockopen() file source
392  */
393 define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
395 /**
396  * cURL file source
397  */
398 define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
400 /**
401  * file_get_contents() file source
402  */
403 define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
407 /**
408  * SimplePie
409  *
410  * @package SimplePie
411  * @subpackage API
412  */
413 class SimplePie
415         /**
416          * @var array Raw data
417          * @access private
418          */
419         public $data = array();
421         /**
422          * @var mixed Error string
423          * @access private
424          */
425         public $error;
427         /**
428          * @var object Instance of SimplePie_Sanitize (or other class)
429          * @see SimplePie::set_sanitize_class()
430          * @access private
431          */
432         public $sanitize;
434         /**
435          * @var string SimplePie Useragent
436          * @see SimplePie::set_useragent()
437          * @access private
438          */
439         public $useragent = SIMPLEPIE_USERAGENT;
441         /**
442          * @var string Feed URL
443          * @see SimplePie::set_feed_url()
444          * @access private
445          */
446         public $feed_url;
448         /**
449          * @var string Original feed URL, or new feed URL iff HTTP 301 Moved Permanently
450          * @see SimplePie::subscribe_url()
451          * @access private
452          */
453         public $permanent_url = null;
455         /**
456          * @var object Instance of SimplePie_File to use as a feed
457          * @see SimplePie::set_file()
458          * @access private
459          */
460         public $file;
462         /**
463          * @var string Raw feed data
464          * @see SimplePie::set_raw_data()
465          * @access private
466          */
467         public $raw_data;
469         /**
470          * @var int Timeout for fetching remote files
471          * @see SimplePie::set_timeout()
472          * @access private
473          */
474         public $timeout = 10;
476         /**
477          * @var array Custom curl options
478          * @see SimplePie::set_curl_options()
479          * @access private
480          */
481         public $curl_options = array();
483         /**
484          * @var bool Forces fsockopen() to be used for remote files instead
485          * of cURL, even if a new enough version is installed
486          * @see SimplePie::force_fsockopen()
487          * @access private
488          */
489         public $force_fsockopen = false;
491         /**
492          * @var bool Force the given data/URL to be treated as a feed no matter what
493          * it appears like
494          * @see SimplePie::force_feed()
495          * @access private
496          */
497         public $force_feed = false;
499         /**
500          * @var bool Enable/Disable Caching
501          * @see SimplePie::enable_cache()
502          * @access private
503          */
504         public $cache = true;
506         /**
507          * @var bool Force SimplePie to fallback to expired cache, if enabled,
508          * when feed is unavailable.
509          * @see SimplePie::force_cache_fallback()
510          * @access private
511          */
512         public $force_cache_fallback = false;
514         /**
515          * @var int Cache duration (in seconds)
516          * @see SimplePie::set_cache_duration()
517          * @access private
518          */
519         public $cache_duration = 3600;
521         /**
522          * @var int Auto-discovery cache duration (in seconds)
523          * @see SimplePie::set_autodiscovery_cache_duration()
524          * @access private
525          */
526         public $autodiscovery_cache_duration = 604800; // 7 Days.
528         /**
529          * @var string Cache location (relative to executing script)
530          * @see SimplePie::set_cache_location()
531          * @access private
532          */
533         public $cache_location = './cache';
535         /**
536          * @var string Function that creates the cache filename
537          * @see SimplePie::set_cache_name_function()
538          * @access private
539          */
540         public $cache_name_function = 'md5';
542         /**
543          * @var bool Reorder feed by date descending
544          * @see SimplePie::enable_order_by_date()
545          * @access private
546          */
547         public $order_by_date = true;
549         /**
550          * @var mixed Force input encoding to be set to the follow value
551          * (false, or anything type-cast to false, disables this feature)
552          * @see SimplePie::set_input_encoding()
553          * @access private
554          */
555         public $input_encoding = false;
557         /**
558          * @var int Feed Autodiscovery Level
559          * @see SimplePie::set_autodiscovery_level()
560          * @access private
561          */
562         public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
564         /**
565          * Class registry object
566          *
567          * @var SimplePie_Registry
568          */
569         public $registry;
571         /**
572          * @var int Maximum number of feeds to check with autodiscovery
573          * @see SimplePie::set_max_checked_feeds()
574          * @access private
575          */
576         public $max_checked_feeds = 10;
578         /**
579          * @var array All the feeds found during the autodiscovery process
580          * @see SimplePie::get_all_discovered_feeds()
581          * @access private
582          */
583         public $all_discovered_feeds = array();
585         /**
586          * @var string Web-accessible path to the handler_image.php file.
587          * @see SimplePie::set_image_handler()
588          * @access private
589          */
590         public $image_handler = '';
592         /**
593          * @var array Stores the URLs when multiple feeds are being initialized.
594          * @see SimplePie::set_feed_url()
595          * @access private
596          */
597         public $multifeed_url = array();
599         /**
600          * @var array Stores SimplePie objects when multiple feeds initialized.
601          * @access private
602          */
603         public $multifeed_objects = array();
605         /**
606          * @var array Stores the get_object_vars() array for use with multifeeds.
607          * @see SimplePie::set_feed_url()
608          * @access private
609          */
610         public $config_settings = null;
612         /**
613          * @var integer Stores the number of items to return per-feed with multifeeds.
614          * @see SimplePie::set_item_limit()
615          * @access private
616          */
617         public $item_limit = 0;
619         /**
620          * @var bool Stores if last-modified and/or etag headers were sent with the
621          * request when checking a feed.
622          */
623         public $check_modified = false;
625         /**
626          * @var array Stores the default attributes to be stripped by strip_attributes().
627          * @see SimplePie::strip_attributes()
628          * @access private
629          */
630         public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
632         /**
633          * @var array Stores the default attributes to add to different tags by add_attributes().
634          * @see SimplePie::add_attributes()
635          * @access private
636          */
637         public $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none'));
639         /**
640          * @var array Stores the default tags to be stripped by strip_htmltags().
641          * @see SimplePie::strip_htmltags()
642          * @access private
643          */
644         public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
646         /**
647          * @var bool Should we throw exceptions, or use the old-style error property?
648          * @access private
649          */
650         public $enable_exceptions = false;
651         
652         /**
653          * The SimplePie class contains feed level data and options
654          *
655          * To use SimplePie, create the SimplePie object with no parameters. You can
656          * then set configuration options using the provided methods. After setting
657          * them, you must initialise the feed using $feed->init(). At that point the
658          * object's methods and properties will be available to you.
659          *
660          * Previously, it was possible to pass in the feed URL along with cache
661          * options directly into the constructor. This has been removed as of 1.3 as
662          * it caused a lot of confusion.
663          *
664          * @since 1.0 Preview Release
665          */
666         public function __construct()
667         {
668                 if (version_compare(PHP_VERSION, '5.3', '<'))
669                 {
670                         trigger_error('Please upgrade to PHP 5.3 or newer.');
671                         die();
672                 }
674                 // Other objects, instances created here so we can set options on them
675                 $this->sanitize = new SimplePie_Sanitize();
676                 $this->registry = new SimplePie_Registry();
678                 if (func_num_args() > 0)
679                 {
680                         $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
681                         trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', $level);
683                         $args = func_get_args();
684                         switch (count($args)) {
685                                 case 3:
686                                         $this->set_cache_duration($args[2]);
687                                 case 2:
688                                         $this->set_cache_location($args[1]);
689                                 case 1:
690                                         $this->set_feed_url($args[0]);
691                                         $this->init();
692                         }
693                 }
694         }
696         /**
697          * Used for converting object to a string
698          */
699         public function __toString()
700         {
701                 return md5(serialize($this->data));
702         }
704         /**
705          * Remove items that link back to this before destroying this object
706          */
707         public function __destruct()
708         {
709                 if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
710                 {
711                         if (!empty($this->data['items']))
712                         {
713                                 foreach ($this->data['items'] as $item)
714                                 {
715                                         $item->__destruct();
716                                 }
717                                 unset($item, $this->data['items']);
718                         }
719                         if (!empty($this->data['ordered_items']))
720                         {
721                                 foreach ($this->data['ordered_items'] as $item)
722                                 {
723                                         $item->__destruct();
724                                 }
725                                 unset($item, $this->data['ordered_items']);
726                         }
727                 }
728         }
730         /**
731          * Force the given data/URL to be treated as a feed
732          *
733          * This tells SimplePie to ignore the content-type provided by the server.
734          * Be careful when using this option, as it will also disable autodiscovery.
735          *
736          * @since 1.1
737          * @param bool $enable Force the given data/URL to be treated as a feed
738          */
739         public function force_feed($enable = false)
740         {
741                 $this->force_feed = (bool) $enable;
742         }
744         /**
745          * Set the URL of the feed you want to parse
746          *
747          * This allows you to enter the URL of the feed you want to parse, or the
748          * website you want to try to use auto-discovery on. This takes priority
749          * over any set raw data.
750          *
751          * You can set multiple feeds to mash together by passing an array instead
752          * of a string for the $url. Remember that with each additional feed comes
753          * additional processing and resources.
754          *
755          * @since 1.0 Preview Release
756          * @see set_raw_data()
757          * @param string|array $url This is the URL (or array of URLs) that you want to parse.
758          */
759         public function set_feed_url($url)
760         {
761                 $this->multifeed_url = array();
762                 if (is_array($url))
763                 {
764                         foreach ($url as $value)
765                         {
766                                 $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
767                         }
768                 }
769                 else
770                 {
771                         $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
772                         $this->permanent_url = $this->feed_url;
773                 }
774         }
776         /**
777          * Set an instance of {@see SimplePie_File} to use as a feed
778          *
779          * @param SimplePie_File &$file
780          * @return bool True on success, false on failure
781          */
782         public function set_file(&$file)
783         {
784                 if ($file instanceof SimplePie_File)
785                 {
786                         $this->feed_url = $file->url;
787                         $this->permanent_url = $this->feed_url;
788                         $this->file =& $file;
789                         return true;
790                 }
791                 return false;
792         }
794         /**
795          * Set the raw XML data to parse
796          *
797          * Allows you to use a string of RSS/Atom data instead of a remote feed.
798          *
799          * If you have a feed available as a string in PHP, you can tell SimplePie
800          * to parse that data string instead of a remote feed. Any set feed URL
801          * takes precedence.
802          *
803          * @since 1.0 Beta 3
804          * @param string $data RSS or Atom data as a string.
805          * @see set_feed_url()
806          */
807         public function set_raw_data($data)
808         {
809                 $this->raw_data = $data;
810         }
812         /**
813          * Set the the default timeout for fetching remote feeds
814          *
815          * This allows you to change the maximum time the feed's server to respond
816          * and send the feed back.
817          *
818          * @since 1.0 Beta 3
819          * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
820          */
821         public function set_timeout($timeout = 10)
822         {
823                 $this->timeout = (int) $timeout;
824         }
826         /**
827          * Set custom curl options
828          *
829          * This allows you to change default curl options
830          *
831          * @since 1.0 Beta 3
832          * @param array $curl_options Curl options to add to default settings
833          */
834         public function set_curl_options(array $curl_options = array())
835         {
836                 $this->curl_options = $curl_options;
837         }
839         /**
840          * Force SimplePie to use fsockopen() instead of cURL
841          *
842          * @since 1.0 Beta 3
843          * @param bool $enable Force fsockopen() to be used
844          */
845         public function force_fsockopen($enable = false)
846         {
847                 $this->force_fsockopen = (bool) $enable;
848         }
850         /**
851          * Enable/disable caching in SimplePie.
852          *
853          * This option allows you to disable caching all-together in SimplePie.
854          * However, disabling the cache can lead to longer load times.
855          *
856          * @since 1.0 Preview Release
857          * @param bool $enable Enable caching
858          */
859         public function enable_cache($enable = true)
860         {
861                 $this->cache = (bool) $enable;
862         }
864         /**
865          * SimplePie to continue to fall back to expired cache, if enabled, when
866          * feed is unavailable.
867          *
868          * This tells SimplePie to ignore any file errors and fall back to cache
869          * instead. This only works if caching is enabled and cached content
870          * still exists.
872          * @param bool $enable Force use of cache on fail.
873          */
874         public function force_cache_fallback($enable = false)
875         {
876                 $this->force_cache_fallback= (bool) $enable;
877         }
879         /**
880          * Set the length of time (in seconds) that the contents of a feed will be
881          * cached
882          *
883          * @param int $seconds The feed content cache duration
884          */
885         public function set_cache_duration($seconds = 3600)
886         {
887                 $this->cache_duration = (int) $seconds;
888         }
890         /**
891          * Set the length of time (in seconds) that the autodiscovered feed URL will
892          * be cached
893          *
894          * @param int $seconds The autodiscovered feed URL cache duration.
895          */
896         public function set_autodiscovery_cache_duration($seconds = 604800)
897         {
898                 $this->autodiscovery_cache_duration = (int) $seconds;
899         }
901         /**
902          * Set the file system location where the cached files should be stored
903          *
904          * @param string $location The file system location.
905          */
906         public function set_cache_location($location = './cache')
907         {
908                 $this->cache_location = (string) $location;
909         }
911         /**
912          * Set whether feed items should be sorted into reverse chronological order
913          *
914          * @param bool $enable Sort as reverse chronological order.
915          */
916         public function enable_order_by_date($enable = true)
917         {
918                 $this->order_by_date = (bool) $enable;
919         }
921         /**
922          * Set the character encoding used to parse the feed
923          *
924          * This overrides the encoding reported by the feed, however it will fall
925          * back to the normal encoding detection if the override fails
926          *
927          * @param string $encoding Character encoding
928          */
929         public function set_input_encoding($encoding = false)
930         {
931                 if ($encoding)
932                 {
933                         $this->input_encoding = (string) $encoding;
934                 }
935                 else
936                 {
937                         $this->input_encoding = false;
938                 }
939         }
941         /**
942          * Set how much feed autodiscovery to do
943          *
944          * @see SIMPLEPIE_LOCATOR_NONE
945          * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
946          * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
947          * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
948          * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
949          * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
950          * @see SIMPLEPIE_LOCATOR_ALL
951          * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator)
952          */
953         public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
954         {
955                 $this->autodiscovery = (int) $level;
956         }
958         /**
959          * Get the class registry
960          *
961          * Use this to override SimplePie's default classes
962          * @see SimplePie_Registry
963          * @return SimplePie_Registry
964          */
965         public function &get_registry()
966         {
967                 return $this->registry;
968         }
970         /**#@+
971          * Useful when you are overloading or extending SimplePie's default classes.
972          *
973          * @deprecated Use {@see get_registry()} instead
974          * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
975          * @param string $class Name of custom class
976          * @return boolean True on success, false otherwise
977          */
978         /**
979          * Set which class SimplePie uses for caching
980          */
981         public function set_cache_class($class = 'SimplePie_Cache')
982         {
983                 return $this->registry->register('Cache', $class, true);
984         }
986         /**
987          * Set which class SimplePie uses for auto-discovery
988          */
989         public function set_locator_class($class = 'SimplePie_Locator')
990         {
991                 return $this->registry->register('Locator', $class, true);
992         }
994         /**
995          * Set which class SimplePie uses for XML parsing
996          */
997         public function set_parser_class($class = 'SimplePie_Parser')
998         {
999                 return $this->registry->register('Parser', $class, true);
1000         }
1002         /**
1003          * Set which class SimplePie uses for remote file fetching
1004          */
1005         public function set_file_class($class = 'SimplePie_File')
1006         {
1007                 return $this->registry->register('File', $class, true);
1008         }
1010         /**
1011          * Set which class SimplePie uses for data sanitization
1012          */
1013         public function set_sanitize_class($class = 'SimplePie_Sanitize')
1014         {
1015                 return $this->registry->register('Sanitize', $class, true);
1016         }
1018         /**
1019          * Set which class SimplePie uses for handling feed items
1020          */
1021         public function set_item_class($class = 'SimplePie_Item')
1022         {
1023                 return $this->registry->register('Item', $class, true);
1024         }
1026         /**
1027          * Set which class SimplePie uses for handling author data
1028          */
1029         public function set_author_class($class = 'SimplePie_Author')
1030         {
1031                 return $this->registry->register('Author', $class, true);
1032         }
1034         /**
1035          * Set which class SimplePie uses for handling category data
1036          */
1037         public function set_category_class($class = 'SimplePie_Category')
1038         {
1039                 return $this->registry->register('Category', $class, true);
1040         }
1042         /**
1043          * Set which class SimplePie uses for feed enclosures
1044          */
1045         public function set_enclosure_class($class = 'SimplePie_Enclosure')
1046         {
1047                 return $this->registry->register('Enclosure', $class, true);
1048         }
1050         /**
1051          * Set which class SimplePie uses for `<media:text>` captions
1052          */
1053         public function set_caption_class($class = 'SimplePie_Caption')
1054         {
1055                 return $this->registry->register('Caption', $class, true);
1056         }
1058         /**
1059          * Set which class SimplePie uses for `<media:copyright>`
1060          */
1061         public function set_copyright_class($class = 'SimplePie_Copyright')
1062         {
1063                 return $this->registry->register('Copyright', $class, true);
1064         }
1066         /**
1067          * Set which class SimplePie uses for `<media:credit>`
1068          */
1069         public function set_credit_class($class = 'SimplePie_Credit')
1070         {
1071                 return $this->registry->register('Credit', $class, true);
1072         }
1074         /**
1075          * Set which class SimplePie uses for `<media:rating>`
1076          */
1077         public function set_rating_class($class = 'SimplePie_Rating')
1078         {
1079                 return $this->registry->register('Rating', $class, true);
1080         }
1082         /**
1083          * Set which class SimplePie uses for `<media:restriction>`
1084          */
1085         public function set_restriction_class($class = 'SimplePie_Restriction')
1086         {
1087                 return $this->registry->register('Restriction', $class, true);
1088         }
1090         /**
1091          * Set which class SimplePie uses for content-type sniffing
1092          */
1093         public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
1094         {
1095                 return $this->registry->register('Content_Type_Sniffer', $class, true);
1096         }
1098         /**
1099          * Set which class SimplePie uses item sources
1100          */
1101         public function set_source_class($class = 'SimplePie_Source')
1102         {
1103                 return $this->registry->register('Source', $class, true);
1104         }
1105         /**#@-*/
1107         /**
1108          * Set the user agent string
1109          *
1110          * @param string $ua New user agent string.
1111          */
1112         public function set_useragent($ua = SIMPLEPIE_USERAGENT)
1113         {
1114                 $this->useragent = (string) $ua;
1115         }
1117         /**
1118          * Set callback function to create cache filename with
1119          *
1120          * @param mixed $function Callback function
1121          */
1122         public function set_cache_name_function($function = 'md5')
1123         {
1124                 if (is_callable($function))
1125                 {
1126                         $this->cache_name_function = $function;
1127                 }
1128         }
1130         /**
1131          * Set options to make SP as fast as possible
1132          *
1133          * Forgoes a substantial amount of data sanitization in favor of speed. This
1134          * turns SimplePie into a dumb parser of feeds.
1135          *
1136          * @param bool $set Whether to set them or not
1137          */
1138         public function set_stupidly_fast($set = false)
1139         {
1140                 if ($set)
1141                 {
1142                         $this->enable_order_by_date(false);
1143                         $this->remove_div(false);
1144                         $this->strip_comments(false);
1145                         $this->strip_htmltags(false);
1146                         $this->strip_attributes(false);
1147                         $this->add_attributes(false);
1148                         $this->set_image_handler(false);
1149                 }
1150         }
1152         /**
1153          * Set maximum number of feeds to check with autodiscovery
1154          *
1155          * @param int $max Maximum number of feeds to check
1156          */
1157         public function set_max_checked_feeds($max = 10)
1158         {
1159                 $this->max_checked_feeds = (int) $max;
1160         }
1162         public function remove_div($enable = true)
1163         {
1164                 $this->sanitize->remove_div($enable);
1165         }
1167         public function strip_htmltags($tags = '', $encode = null)
1168         {
1169                 if ($tags === '')
1170                 {
1171                         $tags = $this->strip_htmltags;
1172                 }
1173                 $this->sanitize->strip_htmltags($tags);
1174                 if ($encode !== null)
1175                 {
1176                         $this->sanitize->encode_instead_of_strip($tags);
1177                 }
1178         }
1180         public function encode_instead_of_strip($enable = true)
1181         {
1182                 $this->sanitize->encode_instead_of_strip($enable);
1183         }
1185         public function strip_attributes($attribs = '')
1186         {
1187                 if ($attribs === '')
1188                 {
1189                         $attribs = $this->strip_attributes;
1190                 }
1191                 $this->sanitize->strip_attributes($attribs);
1192         }
1194         public function add_attributes($attribs = '')
1195         {
1196                 if ($attribs === '')
1197                 {
1198                         $attribs = $this->add_attributes;
1199                 }
1200                 $this->sanitize->add_attributes($attribs);
1201         }
1203         /**
1204          * Set the output encoding
1205          *
1206          * Allows you to override SimplePie's output to match that of your webpage.
1207          * This is useful for times when your webpages are not being served as
1208          * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
1209          * is similar to {@see set_input_encoding()}.
1210          *
1211          * It should be noted, however, that not all character encodings can support
1212          * all characters. If your page is being served as ISO-8859-1 and you try
1213          * to display a Japanese feed, you'll likely see garbled characters.
1214          * Because of this, it is highly recommended to ensure that your webpages
1215          * are served as UTF-8.
1216          *
1217          * The number of supported character encodings depends on whether your web
1218          * host supports {@link http://php.net/mbstring mbstring},
1219          * {@link http://php.net/iconv iconv}, or both. See
1220          * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for
1221          * more information.
1222          *
1223          * @param string $encoding
1224          */
1225         public function set_output_encoding($encoding = 'UTF-8')
1226         {
1227                 $this->sanitize->set_output_encoding($encoding);
1228         }
1230         public function strip_comments($strip = false)
1231         {
1232                 $this->sanitize->strip_comments($strip);
1233         }
1235         /**
1236          * Set element/attribute key/value pairs of HTML attributes
1237          * containing URLs that need to be resolved relative to the feed
1238          *
1239          * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
1240          * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
1241          * |q|@cite
1242          *
1243          * @since 1.0
1244          * @param array|null $element_attribute Element/attribute key/value pairs, null for default
1245          */
1246         public function set_url_replacements($element_attribute = null)
1247         {
1248                 $this->sanitize->set_url_replacements($element_attribute);
1249         }
1251         /**
1252          * Set the handler to enable the display of cached images.
1253          *
1254          * @param str $page Web-accessible path to the handler_image.php file.
1255          * @param str $qs The query string that the value should be passed to.
1256          */
1257         public function set_image_handler($page = false, $qs = 'i')
1258         {
1259                 if ($page !== false)
1260                 {
1261                         $this->sanitize->set_image_handler($page . '?' . $qs . '=');
1262                 }
1263                 else
1264                 {
1265                         $this->image_handler = '';
1266                 }
1267         }
1269         /**
1270          * Set the limit for items returned per-feed with multifeeds
1271          *
1272          * @param integer $limit The maximum number of items to return.
1273          */
1274         public function set_item_limit($limit = 0)
1275         {
1276                 $this->item_limit = (int) $limit;
1277         }
1279         /**
1280          * Enable throwing exceptions
1281          *
1282          * @param boolean $enable Should we throw exceptions, or use the old-style error property?
1283          */
1284         public function enable_exceptions($enable = true)
1285         {
1286                 $this->enable_exceptions = $enable;
1287         }
1289         /**
1290          * Initialize the feed object
1291          *
1292          * This is what makes everything happen. Period. This is where all of the
1293          * configuration options get processed, feeds are fetched, cached, and
1294          * parsed, and all of that other good stuff.
1295          *
1296          * @return boolean True if successful, false otherwise
1297          */
1298         public function init()
1299         {
1300                 // Check absolute bare minimum requirements.
1301                 if (!extension_loaded('xml') || !extension_loaded('pcre'))
1302                 {
1303                         $this->error = 'XML or PCRE extensions not loaded!';
1304                         return false;
1305                 }
1306                 // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
1307                 elseif (!extension_loaded('xmlreader'))
1308                 {
1309                         static $xml_is_sane = null;
1310                         if ($xml_is_sane === null)
1311                         {
1312                                 $parser_check = xml_parser_create();
1313                                 xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
1314                                 xml_parser_free($parser_check);
1315                                 $xml_is_sane = isset($values[0]['value']);
1316                         }
1317                         if (!$xml_is_sane)
1318                         {
1319                                 return false;
1320                         }
1321                 }
1323                 if (method_exists($this->sanitize, 'set_registry'))
1324                 {
1325                         $this->sanitize->set_registry($this->registry);
1326                 }
1328                 // Pass whatever was set with config options over to the sanitizer.
1329                 // Pass the classes in for legacy support; new classes should use the registry instead
1330                 $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
1331                 $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options);
1333                 if (!empty($this->multifeed_url))
1334                 {
1335                         $i = 0;
1336                         $success = 0;
1337                         $this->multifeed_objects = array();
1338                         $this->error = array();
1339                         foreach ($this->multifeed_url as $url)
1340                         {
1341                                 $this->multifeed_objects[$i] = clone $this;
1342                                 $this->multifeed_objects[$i]->set_feed_url($url);
1343                                 $single_success = $this->multifeed_objects[$i]->init();
1344                                 $success |= $single_success;
1345                                 if (!$single_success)
1346                                 {
1347                                         $this->error[$i] = $this->multifeed_objects[$i]->error();
1348                                 }
1349                                 $i++;
1350                         }
1351                         return (bool) $success;
1352                 }
1353                 elseif ($this->feed_url === null && $this->raw_data === null)
1354                 {
1355                         return false;
1356                 }
1358                 $this->error = null;
1359                 $this->data = array();
1360                 $this->check_modified = false;
1361                 $this->multifeed_objects = array();
1362                 $cache = false;
1364                 if ($this->feed_url !== null)
1365                 {
1366                         $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
1368                         // Decide whether to enable caching
1369                         if ($this->cache && $parsed_feed_url['scheme'] !== '')
1370                         {
1371                                 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
1372                         }
1374                         // Fetch the data via SimplePie_File into $this->raw_data
1375                         if (($fetched = $this->fetch_data($cache)) === true)
1376                         {
1377                                 return true;
1378                         }
1379                         elseif ($fetched === false) {
1380                                 return false;
1381                         }
1383                         list($headers, $sniffed) = $fetched;
1384                 }
1385                 
1386                 // Empty response check
1387                 if(empty($this->raw_data)){
1388                         $this->error = "A feed could not be found at `$this->feed_url`. Empty body.";
1389                         $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1390                         return false;
1391                 }
1393                 // Set up array of possible encodings
1394                 $encodings = array();
1396                 // First check to see if input has been overridden.
1397                 if ($this->input_encoding !== false)
1398                 {
1399                         $encodings[] = strtoupper($this->input_encoding);
1400                 }
1402                 $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
1403                 $text_types = array('text/xml', 'text/xml-external-parsed-entity');
1405                 // RFC 3023 (only applies to sniffed content)
1406                 if (isset($sniffed))
1407                 {
1408                         if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
1409                         {
1410                                 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1411                                 {
1412                                         $encodings[] = strtoupper($charset[1]);
1413                                 }
1414                                 $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1415                                 $encodings[] = 'UTF-8';
1416                         }
1417                         elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1418                         {
1419                                 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1420                                 {
1421                                         $encodings[] = strtoupper($charset[1]);
1422                                 }
1423                                 $encodings[] = 'US-ASCII';
1424                         }
1425                         // Text MIME-type default
1426                         elseif (substr($sniffed, 0, 5) === 'text/')
1427                         {
1428                                 $encodings[] = 'UTF-8';
1429                         }
1430                 }
1432                 // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
1433                 $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1434                 $encodings[] = 'UTF-8';
1435                 $encodings[] = 'ISO-8859-1';
1437                 // There's no point in trying an encoding twice
1438                 $encodings = array_unique($encodings);
1440                 // Loop through each possible encoding, till we return something, or run out of possibilities
1441                 foreach ($encodings as $encoding)
1442                 {
1443                         // Change the encoding to UTF-8 (as we always use UTF-8 internally)
1444                         if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
1445                         {
1446                                 // Create new parser
1447                                 $parser = $this->registry->create('Parser');
1449                                 // If it's parsed fine
1450                                 if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url))
1451                                 {
1452                                         $this->data = $parser->get_data();
1453                                         if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
1454                                         {
1455                                                 $this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed.";
1456                                                 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1457                                                 return false;
1458                                         }
1460                                         if (isset($headers))
1461                                         {
1462                                                 $this->data['headers'] = $headers;
1463                                         }
1464                                         $this->data['build'] = SIMPLEPIE_BUILD;
1466                                         // Cache the file if caching is enabled
1467                                         if ($cache && !$cache->save($this))
1468                                         {
1469                                                 trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
1470                                         }
1471                                         return true;
1472                                 }
1473                         }
1474                 }
1476                 if (isset($parser))
1477                 {
1478                         // We have an error, just set SimplePie_Misc::error to it and quit
1479                         $this->error = $this->feed_url;
1480                         $this->error .= sprintf(' is invalid XML, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
1481                 }
1482                 else
1483                 {
1484                         $this->error = 'The data could not be converted to UTF-8.';
1485                         if (!extension_loaded('mbstring') && !extension_loaded('iconv') && !class_exists('\UConverter')) {
1486                                 $this->error .= ' You MUST have either the iconv, mbstring or intl (PHP 5.5+) extension installed and enabled.';
1487                         } else {
1488                                 $missingExtensions = array();
1489                                 if (!extension_loaded('iconv')) {
1490                                         $missingExtensions[] = 'iconv';
1491                                 }
1492                                 if (!extension_loaded('mbstring')) {
1493                                         $missingExtensions[] = 'mbstring';
1494                                 }
1495                                 if (!class_exists('\UConverter')) {
1496                                         $missingExtensions[] = 'intl (PHP 5.5+)';
1497                                 }
1498                                 $this->error .= ' Try installing/enabling the ' . implode(' or ', $missingExtensions) . ' extension.';
1499                         }
1500                 }
1502                 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1504                 return false;
1505         }
1507         /**
1508          * Fetch the data via SimplePie_File
1509          *
1510          * If the data is already cached, attempt to fetch it from there instead
1511          * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache
1512          * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
1513          */
1514         protected function fetch_data(&$cache)
1515         {
1516                 // If it's enabled, use the cache
1517                 if ($cache)
1518                 {
1519                         // Load the Cache
1520                         $this->data = $cache->load();
1521                         if (!empty($this->data))
1522                         {
1523                                 // If the cache is for an outdated build of SimplePie
1524                                 if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
1525                                 {
1526                                         $cache->unlink();
1527                                         $this->data = array();
1528                                 }
1529                                 // If we've hit a collision just rerun it with caching disabled
1530                                 elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
1531                                 {
1532                                         $cache = false;
1533                                         $this->data = array();
1534                                 }
1535                                 // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
1536                                 elseif (isset($this->data['feed_url']))
1537                                 {
1538                                         // If the autodiscovery cache is still valid use it.
1539                                         if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
1540                                         {
1541                                                 // Do not need to do feed autodiscovery yet.
1542                                                 if ($this->data['feed_url'] !== $this->data['url'])
1543                                                 {
1544                                                         $this->set_feed_url($this->data['feed_url']);
1545                                                         return $this->init();
1546                                                 }
1548                                                 $cache->unlink();
1549                                                 $this->data = array();
1550                                         }
1551                                 }
1552                                 // Check if the cache has been updated
1553                                 elseif ($cache->mtime() + $this->cache_duration < time())
1554                                 {
1555                                         // Want to know if we tried to send last-modified and/or etag headers
1556                                         // when requesting this file. (Note that it's up to the file to
1557                                         // support this, but we don't always send the headers either.)
1558                                         $this->check_modified = true;
1559                                         if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
1560                                         {
1561                                                 $headers = array(
1562                                                         'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
1563                                                 );
1564                                                 if (isset($this->data['headers']['last-modified']))
1565                                                 {
1566                                                         $headers['if-modified-since'] = $this->data['headers']['last-modified'];
1567                                                 }
1568                                                 if (isset($this->data['headers']['etag']))
1569                                                 {
1570                                                         $headers['if-none-match'] = $this->data['headers']['etag'];
1571                                                 }
1573                                                 $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
1575                                                 if ($file->success)
1576                                                 {
1577                                                         if ($file->status_code === 304)
1578                                                         {
1579                                                                 // Set raw_data to false here too, to signify that the cache
1580                                                                 // is still valid.
1581                                                                 $this->raw_data = false;
1582                                                                 $cache->touch();
1583                                                                 return true;
1584                                                         }
1585                                                 }
1586                                                 else
1587                                                 {
1588                                                         $this->check_modified = false;
1589                                                         if($this->force_cache_fallback)
1590                                                         {
1591                                                                 $cache->touch();
1592                                                                 return true;
1593                                                         }
1595                                                         unset($file);
1596                                                 }
1597                                         }
1598                                 }
1599                                 // If the cache is still valid, just return true
1600                                 else
1601                                 {
1602                                         $this->raw_data = false;
1603                                         return true;
1604                                 }
1605                         }
1606                         // If the cache is empty, delete it
1607                         else
1608                         {
1609                                 $cache->unlink();
1610                                 $this->data = array();
1611                         }
1612                 }
1613                 // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
1614                 if (!isset($file))
1615                 {
1616                         if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
1617                         {
1618                                 $file =& $this->file;
1619                         }
1620                         else
1621                         {
1622                                 $headers = array(
1623                                         'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
1624                                 );
1625                                 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
1626                         }
1627                 }
1628                 // If the file connection has an error, set SimplePie::error to that and quit
1629                 if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
1630                 {
1631                         $this->error = $file->error;
1632                         return !empty($this->data);
1633                 }
1635                 if (!$this->force_feed)
1636                 {
1637                         // Check if the supplied URL is a feed, if it isn't, look for it.
1638                         $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
1640                         if (!$locate->is_feed($file))
1641                         {
1642                                 $copyStatusCode = $file->status_code;
1643                                 $copyContentType = $file->headers['content-type'];
1644                                 try
1645                                 {
1646                                         $microformats = false;
1647                                         if (function_exists('Mf2\parse')) {
1648                                                 // Check for both h-feed and h-entry, as both a feed with no entries
1649                                                 // and a list of entries without an h-feed wrapper are both valid.
1650                                                 $position = 0;
1651                                                 while ($position = strpos($file->body, 'h-feed', $position))
1652                                                 {
1653                                                         $start = $position < 200 ? 0 : $position - 200;
1654                                                         $check = substr($file->body, $start, 400);
1655                                                         if ($microformats = preg_match('/class="[^"]*h-feed/', $check))
1656                                                         {
1657                                                                 break;
1658                                                         }
1659                                                         $position += 7;
1660                                                 }
1661                                                 $position = 0;
1662                                                 while ($position = strpos($file->body, 'h-entry', $position))
1663                                                 {
1664                                                         $start = $position < 200 ? 0 : $position - 200;
1665                                                         $check = substr($file->body, $start, 400);
1666                                                         if ($microformats = preg_match('/class="[^"]*h-entry/', $check))
1667                                                         {
1668                                                                 break;
1669                                                         }
1670                                                         $position += 7;
1671                                                 }
1672                                         }
1673                                         // Now also do feed discovery, but if an h-entry was found don't
1674                                         // overwrite the current value of file.
1675                                         $discovered = $locate->find($this->autodiscovery,
1676                                                                     $this->all_discovered_feeds);
1677                                         if ($microformats)
1678                                         {
1679                                                 if ($hub = $locate->get_rel_link('hub'))
1680                                                 {
1681                                                         $self = $locate->get_rel_link('self');
1682                                                         $this->store_links($file, $hub, $self);
1683                                                 }
1684                                                 // Push the current file onto all_discovered feeds so the user can
1685                                                 // be shown this as one of the options.
1686                                                 if (isset($this->all_discovered_feeds)) {
1687                                                         $this->all_discovered_feeds[] = $file;
1688                                                 }
1689                                         }
1690                                         else
1691                                         {
1692                                                 if ($discovered)
1693                                                 {
1694                                                         $file = $discovered;
1695                                                 }
1696                                                 else
1697                                                 {
1698                                                         // We need to unset this so that if SimplePie::set_file() has
1699                                                         // been called that object is untouched
1700                                                         unset($file);
1701                                                         $this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`";
1702                                                         $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1703                                                         return false;
1704                                                 }
1705                                         }
1706                                 }
1707                                 catch (SimplePie_Exception $e)
1708                                 {
1709                                         // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
1710                                         unset($file);
1711                                         // This is usually because DOMDocument doesn't exist
1712                                         $this->error = $e->getMessage();
1713                                         $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
1714                                         return false;
1715                                 }
1716                                 if ($cache)
1717                                 {
1718                                         $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
1719                                         if (!$cache->save($this))
1720                                         {
1721                                                 trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
1722                                         }
1723                                         $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
1724                                 }
1725                                 $this->feed_url = $file->url;
1726                         }
1727                         $locate = null;
1728                 }
1730                 $this->raw_data = $file->body;
1731                 $this->permanent_url = $file->permanent_url;
1732                 $headers = $file->headers;
1733                 $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
1734                 $sniffed = $sniffer->get_type();
1736                 return array($headers, $sniffed);
1737         }
1739         /**
1740          * Get the error message for the occured error
1741          *
1742          * @return string|array Error message, or array of messages for multifeeds
1743          */
1744         public function error()
1745         {
1746                 return $this->error;
1747         }
1749         /**
1750          * Get the raw XML
1751          *
1752          * This is the same as the old `$feed->enable_xml_dump(true)`, but returns
1753          * the data instead of printing it.
1754          *
1755          * @return string|boolean Raw XML data, false if the cache is used
1756          */
1757         public function get_raw_data()
1758         {
1759                 return $this->raw_data;
1760         }
1762         /**
1763          * Get the character encoding used for output
1764          *
1765          * @since Preview Release
1766          * @return string
1767          */
1768         public function get_encoding()
1769         {
1770                 return $this->sanitize->output_encoding;
1771         }
1773         /**
1774          * Send the content-type header with correct encoding
1775          *
1776          * This method ensures that the SimplePie-enabled page is being served with
1777          * the correct {@link http://www.iana.org/assignments/media-types/ mime-type}
1778          * and character encoding HTTP headers (character encoding determined by the
1779          * {@see set_output_encoding} config option).
1780          *
1781          * This won't work properly if any content or whitespace has already been
1782          * sent to the browser, because it relies on PHP's
1783          * {@link http://php.net/header header()} function, and these are the
1784          * circumstances under which the function works.
1785          *
1786          * Because it's setting these settings for the entire page (as is the nature
1787          * of HTTP headers), this should only be used once per page (again, at the
1788          * top).
1789          *
1790          * @param string $mime MIME type to serve the page as
1791          */
1792         public function handle_content_type($mime = 'text/html')
1793         {
1794                 if (!headers_sent())
1795                 {
1796                         $header = "Content-type: $mime;";
1797                         if ($this->get_encoding())
1798                         {
1799                                 $header .= ' charset=' . $this->get_encoding();
1800                         }
1801                         else
1802                         {
1803                                 $header .= ' charset=UTF-8';
1804                         }
1805                         header($header);
1806                 }
1807         }
1809         /**
1810          * Get the type of the feed
1811          *
1812          * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against
1813          * using {@link http://php.net/language.operators.bitwise bitwise operators}
1814          *
1815          * @since 0.8 (usage changed to using constants in 1.0)
1816          * @see SIMPLEPIE_TYPE_NONE Unknown.
1817          * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90.
1818          * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
1819          * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
1820          * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91.
1821          * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92.
1822          * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93.
1823          * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94.
1824          * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0.
1825          * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x.
1826          * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS.
1827          * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format).
1828          * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS.
1829          * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3.
1830          * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0.
1831          * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom.
1832          * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type.
1833          * @return int SIMPLEPIE_TYPE_* constant
1834          */
1835         public function get_type()
1836         {
1837                 if (!isset($this->data['type']))
1838                 {
1839                         $this->data['type'] = SIMPLEPIE_TYPE_ALL;
1840                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
1841                         {
1842                                 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
1843                         }
1844                         elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
1845                         {
1846                                 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
1847                         }
1848                         elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
1849                         {
1850                                 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
1851                                 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
1852                                 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
1853                                 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
1854                                 {
1855                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
1856                                 }
1857                                 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
1858                                 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
1859                                 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
1860                                 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
1861                                 {
1862                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
1863                                 }
1864                         }
1865                         elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
1866                         {
1867                                 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
1868                                 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1869                                 {
1870                                         switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1871                                         {
1872                                                 case '0.91':
1873                                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
1874                                                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1875                                                         {
1876                                                                 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1877                                                                 {
1878                                                                         case '0':
1879                                                                                 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
1880                                                                                 break;
1882                                                                         case '24':
1883                                                                                 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
1884                                                                                 break;
1885                                                                 }
1886                                                         }
1887                                                         break;
1889                                                 case '0.92':
1890                                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
1891                                                         break;
1893                                                 case '0.93':
1894                                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
1895                                                         break;
1897                                                 case '0.94':
1898                                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
1899                                                         break;
1901                                                 case '2.0':
1902                                                         $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
1903                                                         break;
1904                                         }
1905                                 }
1906                         }
1907                         else
1908                         {
1909                                 $this->data['type'] = SIMPLEPIE_TYPE_NONE;
1910                         }
1911                 }
1912                 return $this->data['type'];
1913         }
1915         /**
1916          * Get the URL for the feed
1917          * 
1918          * When the 'permanent' mode is enabled, returns the original feed URL,
1919          * except in the case of an `HTTP 301 Moved Permanently` status response,
1920          * in which case the location of the first redirection is returned.
1921          *
1922          * When the 'permanent' mode is disabled (default),
1923          * may or may not be different from the URL passed to {@see set_feed_url()},
1924          * depending on whether auto-discovery was used.
1925          *
1926          * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
1927          * @todo Support <itunes:new-feed-url>
1928          * @todo Also, |atom:link|@rel=self
1929          * @param bool $permanent Permanent mode to return only the original URL or the first redirection
1930          * iff it is a 301 redirection
1931          * @return string|null
1932          */
1933         public function subscribe_url($permanent = false)
1934         {
1935                 if ($permanent)
1936                 {
1937                         if ($this->permanent_url !== null)
1938                         {
1939                                 // sanitize encodes ampersands which are required when used in a url.
1940                                 return str_replace('&amp;', '&',
1941                                                    $this->sanitize($this->permanent_url,
1942                                                                    SIMPLEPIE_CONSTRUCT_IRI));
1943                         }
1944                 }
1945                 else
1946                 {
1947                         if ($this->feed_url !== null)
1948                         {
1949                                 return str_replace('&amp;', '&',
1950                                                    $this->sanitize($this->feed_url,
1951                                                                    SIMPLEPIE_CONSTRUCT_IRI));
1952                         }
1953                 }
1954                 return null;
1955         }
1957         /**
1958          * Get data for an feed-level element
1959          *
1960          * This method allows you to get access to ANY element/attribute that is a
1961          * sub-element of the opening feed tag.
1962          *
1963          * The return value is an indexed array of elements matching the given
1964          * namespace and tag name. Each element has `attribs`, `data` and `child`
1965          * subkeys. For `attribs` and `child`, these contain namespace subkeys.
1966          * `attribs` then has one level of associative name => value data (where
1967          * `value` is a string) after the namespace. `child` has tag-indexed keys
1968          * after the namespace, each member of which is an indexed array matching
1969          * this same format.
1970          *
1971          * For example:
1972          * <pre>
1973          * // This is probably a bad example because we already support
1974          * // <media:content> natively, but it shows you how to parse through
1975          * // the nodes.
1976          * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
1977          * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
1978          * $file = $content[0]['attribs']['']['url'];
1979          * echo $file;
1980          * </pre>
1981          *
1982          * @since 1.0
1983          * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1984          * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1985          * @param string $tag Tag name
1986          * @return array
1987          */
1988         public function get_feed_tags($namespace, $tag)
1989         {
1990                 $type = $this->get_type();
1991                 if ($type & SIMPLEPIE_TYPE_ATOM_10)
1992                 {
1993                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
1994                         {
1995                                 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
1996                         }
1997                 }
1998                 if ($type & SIMPLEPIE_TYPE_ATOM_03)
1999                 {
2000                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
2001                         {
2002                                 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
2003                         }
2004                 }
2005                 if ($type & SIMPLEPIE_TYPE_RSS_RDF)
2006                 {
2007                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
2008                         {
2009                                 return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
2010                         }
2011                 }
2012                 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
2013                 {
2014                         if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
2015                         {
2016                                 return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
2017                         }
2018                 }
2019                 return null;
2020         }
2022         /**
2023          * Get data for an channel-level element
2024          *
2025          * This method allows you to get access to ANY element/attribute in the
2026          * channel/header section of the feed.
2027          *
2028          * See {@see SimplePie::get_feed_tags()} for a description of the return value
2029          *
2030          * @since 1.0
2031          * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
2032          * @param string $namespace The URL of the XML namespace of the elements you're trying to access
2033          * @param string $tag Tag name
2034          * @return array
2035          */
2036         public function get_channel_tags($namespace, $tag)
2037         {
2038                 $type = $this->get_type();
2039                 if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
2040                 {
2041                         if ($return = $this->get_feed_tags($namespace, $tag))
2042                         {
2043                                 return $return;
2044                         }
2045                 }
2046                 if ($type & SIMPLEPIE_TYPE_RSS_10)
2047                 {
2048                         if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
2049                         {
2050                                 if (isset($channel[0]['child'][$namespace][$tag]))
2051                                 {
2052                                         return $channel[0]['child'][$namespace][$tag];
2053                                 }
2054                         }
2055                 }
2056                 if ($type & SIMPLEPIE_TYPE_RSS_090)
2057                 {
2058                         if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
2059                         {
2060                                 if (isset($channel[0]['child'][$namespace][$tag]))
2061                                 {
2062                                         return $channel[0]['child'][$namespace][$tag];
2063                                 }
2064                         }
2065                 }
2066                 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
2067                 {
2068                         if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
2069                         {
2070                                 if (isset($channel[0]['child'][$namespace][$tag]))
2071                                 {
2072                                         return $channel[0]['child'][$namespace][$tag];
2073                                 }
2074                         }
2075                 }
2076                 return null;
2077         }
2079         /**
2080          * Get data for an channel-level element
2081          *
2082          * This method allows you to get access to ANY element/attribute in the
2083          * image/logo section of the feed.
2084          *
2085          * See {@see SimplePie::get_feed_tags()} for a description of the return value
2086          *
2087          * @since 1.0
2088          * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
2089          * @param string $namespace The URL of the XML namespace of the elements you're trying to access
2090          * @param string $tag Tag name
2091          * @return array
2092          */
2093         public function get_image_tags($namespace, $tag)
2094         {
2095                 $type = $this->get_type();
2096                 if ($type & SIMPLEPIE_TYPE_RSS_10)
2097                 {
2098                         if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
2099                         {
2100                                 if (isset($image[0]['child'][$namespace][$tag]))
2101                                 {
2102                                         return $image[0]['child'][$namespace][$tag];
2103                                 }
2104                         }
2105                 }
2106                 if ($type & SIMPLEPIE_TYPE_RSS_090)
2107                 {
2108                         if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
2109                         {
2110                                 if (isset($image[0]['child'][$namespace][$tag]))
2111                                 {
2112                                         return $image[0]['child'][$namespace][$tag];
2113                                 }
2114                         }
2115                 }
2116                 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
2117                 {
2118                         if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
2119                         {
2120                                 if (isset($image[0]['child'][$namespace][$tag]))
2121                                 {
2122                                         return $image[0]['child'][$namespace][$tag];
2123                                 }
2124                         }
2125                 }
2126                 return null;
2127         }
2129         /**
2130          * Get the base URL value from the feed
2131          *
2132          * Uses `<xml:base>` if available, otherwise uses the first link in the
2133          * feed, or failing that, the URL of the feed itself.
2134          *
2135          * @see get_link
2136          * @see subscribe_url
2137          *
2138          * @param array $element
2139          * @return string
2140          */
2141         public function get_base($element = array())
2142         {
2143                 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
2144                 {
2145                         return $element['xml_base'];
2146                 }
2147                 elseif ($this->get_link() !== null)
2148                 {
2149                         return $this->get_link();
2150                 }
2151                 else
2152                 {
2153                         return $this->subscribe_url();
2154                 }
2155         }
2157         /**
2158          * Sanitize feed data
2159          *
2160          * @access private
2161          * @see SimplePie_Sanitize::sanitize()
2162          * @param string $data Data to sanitize
2163          * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
2164          * @param string $base Base URL to resolve URLs against
2165          * @return string Sanitized data
2166          */
2167         public function sanitize($data, $type, $base = '')
2168         {
2169                 try
2170                 {
2171                         return $this->sanitize->sanitize($data, $type, $base);
2172                 }
2173                 catch (SimplePie_Exception $e)
2174                 {
2175                         if (!$this->enable_exceptions)
2176                         {
2177                                 $this->error = $e->getMessage();
2178                                 $this->registry->call('Misc', 'error', array($this->error, E_USER_WARNING, $e->getFile(), $e->getLine()));
2179                                 return '';
2180                         }
2182                         throw $e;
2183                 }
2184         }
2186         /**
2187          * Get the title of the feed
2188          *
2189          * Uses `<atom:title>`, `<title>` or `<dc:title>`
2190          *
2191          * @since 1.0 (previously called `get_feed_title` since 0.8)
2192          * @return string|null
2193          */
2194         public function get_title()
2195         {
2196                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
2197                 {
2198                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2199                 }
2200                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
2201                 {
2202                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2203                 }
2204                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2205                 {
2206                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2207                 }
2208                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2209                 {
2210                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2211                 }
2212                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2213                 {
2214                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2215                 }
2216                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2217                 {
2218                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2219                 }
2220                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2221                 {
2222                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2223                 }
2224                 else
2225                 {
2226                         return null;
2227                 }
2228         }
2230         /**
2231          * Get a category for the feed
2232          *
2233          * @since Unknown
2234          * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
2235          * @return SimplePie_Category|null
2236          */
2237         public function get_category($key = 0)
2238         {
2239                 $categories = $this->get_categories();
2240                 if (isset($categories[$key]))
2241                 {
2242                         return $categories[$key];
2243                 }
2244                 else
2245                 {
2246                         return null;
2247                 }
2248         }
2250         /**
2251          * Get all categories for the feed
2252          *
2253          * Uses `<atom:category>`, `<category>` or `<dc:subject>`
2254          *
2255          * @since Unknown
2256          * @return array|null List of {@see SimplePie_Category} objects
2257          */
2258         public function get_categories()
2259         {
2260                 $categories = array();
2262                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
2263                 {
2264                         $term = null;
2265                         $scheme = null;
2266                         $label = null;
2267                         if (isset($category['attribs']['']['term']))
2268                         {
2269                                 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
2270                         }
2271                         if (isset($category['attribs']['']['scheme']))
2272                         {
2273                                 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2274                         }
2275                         if (isset($category['attribs']['']['label']))
2276                         {
2277                                 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
2278                         }
2279                         $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
2280                 }
2281                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
2282                 {
2283                         // This is really the label, but keep this as the term also for BC.
2284                         // Label will also work on retrieving because that falls back to term.
2285                         $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2286                         if (isset($category['attribs']['']['domain']))
2287                         {
2288                                 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
2289                         }
2290                         else
2291                         {
2292                                 $scheme = null;
2293                         }
2294                         $categories[] = $this->registry->create('Category', array($term, $scheme, null));
2295                 }
2296                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
2297                 {
2298                         $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2299                 }
2300                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
2301                 {
2302                         $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2303                 }
2305                 if (!empty($categories))
2306                 {
2307                         return array_unique($categories);
2308                 }
2309                 else
2310                 {
2311                         return null;
2312                 }
2313         }
2315         /**
2316          * Get an author for the feed
2317          *
2318          * @since 1.1
2319          * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
2320          * @return SimplePie_Author|null
2321          */
2322         public function get_author($key = 0)
2323         {
2324                 $authors = $this->get_authors();
2325                 if (isset($authors[$key]))
2326                 {
2327                         return $authors[$key];
2328                 }
2329                 else
2330                 {
2331                         return null;
2332                 }
2333         }
2335         /**
2336          * Get all authors for the feed
2337          *
2338          * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
2339          *
2340          * @since 1.1
2341          * @return array|null List of {@see SimplePie_Author} objects
2342          */
2343         public function get_authors()
2344         {
2345                 $authors = array();
2346                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
2347                 {
2348                         $name = null;
2349                         $uri = null;
2350                         $email = null;
2351                         if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2352                         {
2353                                 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2354                         }
2355                         if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2356                         {
2357                                 $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]));
2358                         }
2359                         if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2360                         {
2361                                 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2362                         }
2363                         if ($name !== null || $email !== null || $uri !== null)
2364                         {
2365                                 $authors[] = $this->registry->create('Author', array($name, $uri, $email));
2366                         }
2367                 }
2368                 if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
2369                 {
2370                         $name = null;
2371                         $url = null;
2372                         $email = null;
2373                         if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2374                         {
2375                                 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2376                         }
2377                         if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2378                         {
2379                                 $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]));
2380                         }
2381                         if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2382                         {
2383                                 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2384                         }
2385                         if ($name !== null || $email !== null || $url !== null)
2386                         {
2387                                 $authors[] = $this->registry->create('Author', array($name, $url, $email));
2388                         }
2389                 }
2390                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
2391                 {
2392                         $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2393                 }
2394                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
2395                 {
2396                         $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2397                 }
2398                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
2399                 {
2400                         $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2401                 }
2403                 if (!empty($authors))
2404                 {
2405                         return array_unique($authors);
2406                 }
2407                 else
2408                 {
2409                         return null;
2410                 }
2411         }
2413         /**
2414          * Get a contributor for the feed
2415          *
2416          * @since 1.1
2417          * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
2418          * @return SimplePie_Author|null
2419          */
2420         public function get_contributor($key = 0)
2421         {
2422                 $contributors = $this->get_contributors();
2423                 if (isset($contributors[$key]))
2424                 {
2425                         return $contributors[$key];
2426                 }
2427                 else
2428                 {
2429                         return null;
2430                 }
2431         }
2433         /**
2434          * Get all contributors for the feed
2435          *
2436          * Uses `<atom:contributor>`
2437          *
2438          * @since 1.1
2439          * @return array|null List of {@see SimplePie_Author} objects
2440          */
2441         public function get_contributors()
2442         {
2443                 $contributors = array();
2444                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
2445                 {
2446                         $name = null;
2447                         $uri = null;
2448                         $email = null;
2449                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2450                         {
2451                                 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2452                         }
2453                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2454                         {
2455                                 $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]));
2456                         }
2457                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2458                         {
2459                                 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2460                         }
2461                         if ($name !== null || $email !== null || $uri !== null)
2462                         {
2463                                 $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
2464                         }
2465                 }
2466                 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
2467                 {
2468                         $name = null;
2469                         $url = null;
2470                         $email = null;
2471                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2472                         {
2473                                 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2474                         }
2475                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2476                         {
2477                                 $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]));
2478                         }
2479                         if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2480                         {
2481                                 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2482                         }
2483                         if ($name !== null || $email !== null || $url !== null)
2484                         {
2485                                 $contributors[] = $this->registry->create('Author', array($name, $url, $email));
2486                         }
2487                 }
2489                 if (!empty($contributors))
2490                 {
2491                         return array_unique($contributors);
2492                 }
2493                 else
2494                 {
2495                         return null;
2496                 }
2497         }
2499         /**
2500          * Get a single link for the feed
2501          *
2502          * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
2503          * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
2504          * @param string $rel The relationship of the link to return
2505          * @return string|null Link URL
2506          */
2507         public function get_link($key = 0, $rel = 'alternate')
2508         {
2509                 $links = $this->get_links($rel);
2510                 if (isset($links[$key]))
2511                 {
2512                         return $links[$key];
2513                 }
2514                 else
2515                 {
2516                         return null;
2517                 }
2518         }
2520         /**
2521          * Get the permalink for the item
2522          *
2523          * Returns the first link available with a relationship of "alternate".
2524          * Identical to {@see get_link()} with key 0
2525          *
2526          * @see get_link
2527          * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
2528          * @internal Added for parity between the parent-level and the item/entry-level.
2529          * @return string|null Link URL
2530          */
2531         public function get_permalink()
2532         {
2533                 return $this->get_link(0);
2534         }
2536         /**
2537          * Get all links for the feed
2538          *
2539          * Uses `<atom:link>` or `<link>`
2540          *
2541          * @since Beta 2
2542          * @param string $rel The relationship of links to return
2543          * @return array|null Links found for the feed (strings)
2544          */
2545         public function get_links($rel = 'alternate')
2546         {
2547                 if (!isset($this->data['links']))
2548                 {
2549                         $this->data['links'] = array();
2550                         if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
2551                         {
2552                                 foreach ($links as $link)
2553                                 {
2554                                         if (isset($link['attribs']['']['href']))
2555                                         {
2556                                                 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2557                                                 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2558                                         }
2559                                 }
2560                         }
2561                         if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
2562                         {
2563                                 foreach ($links as $link)
2564                                 {
2565                                         if (isset($link['attribs']['']['href']))
2566                                         {
2567                                                 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2568                                                 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2570                                         }
2571                                 }
2572                         }
2573                         if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2574                         {
2575                                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2576                         }
2577                         if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2578                         {
2579                                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2580                         }
2581                         if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2582                         {
2583                                 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2584                         }
2586                         $keys = array_keys($this->data['links']);
2587                         foreach ($keys as $key)
2588                         {
2589                                 if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
2590                                 {
2591                                         if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
2592                                         {
2593                                                 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
2594                                                 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
2595                                         }
2596                                         else
2597                                         {
2598                                                 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
2599                                         }
2600                                 }
2601                                 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2602                                 {
2603                                         $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
2604                                 }
2605                                 $this->data['links'][$key] = array_unique($this->data['links'][$key]);
2606                         }
2607                 }
2609                 if (isset($this->data['links'][$rel]))
2610                 {
2611                         return $this->data['links'][$rel];
2612                 }
2613                 else if (isset($this->data['headers']['link']) &&
2614                          preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/',
2615                                     $this->data['headers']['link'], $match))
2616                 {
2617                         return array($match[1]);
2618                 }
2619                 else
2620                 {
2621                         return null;
2622                 }
2623         }
2625         public function get_all_discovered_feeds()
2626         {
2627                 return $this->all_discovered_feeds;
2628         }
2630         /**
2631          * Get the content for the item
2632          *
2633          * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,
2634          * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>`
2635          *
2636          * @since 1.0 (previously called `get_feed_description()` since 0.8)
2637          * @return string|null
2638          */
2639         public function get_description()
2640         {
2641                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
2642                 {
2643                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2644                 }
2645                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
2646                 {
2647                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2648                 }
2649                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
2650                 {
2651                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2652                 }
2653                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
2654                 {
2655                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2656                 }
2657                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
2658                 {
2659                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2660                 }
2661                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
2662                 {
2663                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2664                 }
2665                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
2666                 {
2667                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2668                 }
2669                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
2670                 {
2671                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2672                 }
2673                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
2674                 {
2675                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2676                 }
2677                 else
2678                 {
2679                         return null;
2680                 }
2681         }
2683         /**
2684          * Get the copyright info for the feed
2685          *
2686          * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>`
2687          *
2688          * @since 1.0 (previously called `get_feed_copyright()` since 0.8)
2689          * @return string|null
2690          */
2691         public function get_copyright()
2692         {
2693                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
2694                 {
2695                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2696                 }
2697                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
2698                 {
2699                         return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2700                 }
2701                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
2702                 {
2703                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2704                 }
2705                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
2706                 {
2707                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2708                 }
2709                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
2710                 {
2711                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2712                 }
2713                 else
2714                 {
2715                         return null;
2716                 }
2717         }
2719         /**
2720          * Get the language for the feed
2721          *
2722          * Uses `<language>`, `<dc:language>`, or @xml_lang
2723          *
2724          * @since 1.0 (previously called `get_feed_language()` since 0.8)
2725          * @return string|null
2726          */
2727         public function get_language()
2728         {
2729                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
2730                 {
2731                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2732                 }
2733                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
2734                 {
2735                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2736                 }
2737                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
2738                 {
2739                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2740                 }
2741                 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
2742                 {
2743                         return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2744                 }
2745                 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
2746                 {
2747                         return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2748                 }
2749                 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
2750                 {
2751                         return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2752                 }
2753                 elseif (isset($this->data['headers']['content-language']))
2754                 {
2755                         return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
2756                 }
2757                 else
2758                 {
2759                         return null;
2760                 }
2761         }
2763         /**
2764          * Get the latitude coordinates for the item
2765          *
2766          * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
2767          *
2768          * Uses `<geo:lat>` or `<georss:point>`
2769          *
2770          * @since 1.0
2771          * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2772          * @link http://www.georss.org/ GeoRSS
2773          * @return string|null
2774          */
2775         public function get_latitude()
2776         {
2778                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
2779                 {
2780                         return (float) $return[0]['data'];
2781                 }
2782                 elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2783                 {
2784                         return (float) $match[1];
2785                 }
2786                 else
2787                 {
2788                         return null;
2789                 }
2790         }
2792         /**
2793          * Get the longitude coordinates for the feed
2794          *
2795          * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
2796          *
2797          * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
2798          *
2799          * @since 1.0
2800          * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2801          * @link http://www.georss.org/ GeoRSS
2802          * @return string|null
2803          */
2804         public function get_longitude()
2805         {
2806                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
2807                 {
2808                         return (float) $return[0]['data'];
2809                 }
2810                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
2811                 {
2812                         return (float) $return[0]['data'];
2813                 }
2814                 elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
2815                 {
2816                         return (float) $match[2];
2817                 }
2818                 else
2819                 {
2820                         return null;
2821                 }
2822         }
2824         /**
2825          * Get the feed logo's title
2826          *
2827          * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title.
2828          *
2829          * Uses `<image><title>` or `<image><dc:title>`
2830          *
2831          * @return string|null
2832          */
2833         public function get_image_title()
2834         {
2835                 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2836                 {
2837                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2838                 }
2839                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2840                 {
2841                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2842                 }
2843                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2844                 {
2845                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2846                 }
2847                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2848                 {
2849                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2850                 }
2851                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2852                 {
2853                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2854                 }
2855                 else
2856                 {
2857                         return null;
2858                 }
2859         }
2861         /**
2862          * Get the feed logo's URL
2863          *
2864          * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to
2865          * have a "feed logo" URL. This points directly to the image itself.
2866          *
2867          * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
2868          * `<image><title>` or `<image><dc:title>`
2869          *
2870          * @return string|null
2871          */
2872         public function get_image_url()
2873         {
2874                 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
2875                 {
2876                         return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
2877                 }
2878                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
2879                 {
2880                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2881                 }
2882                 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
2883                 {
2884                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2885                 }
2886                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
2887                 {
2888                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2889                 }
2890                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
2891                 {
2892                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2893                 }
2894                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2895                 {
2896                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2897                 }
2898                 else
2899                 {
2900                         return null;
2901                 }
2902         }
2905         /**
2906          * Get the feed logo's link
2907          *
2908          * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This
2909          * points to a human-readable page that the image should link to.
2910          *
2911          * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
2912          * `<image><title>` or `<image><dc:title>`
2913          *
2914          * @return string|null
2915          */
2916         public function get_image_link()
2917         {
2918                 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2919                 {
2920                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2921                 }
2922                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2923                 {
2924                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2925                 }
2926                 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2927                 {
2928                         return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2929                 }
2930                 else
2931                 {
2932                         return null;
2933                 }
2934         }
2936         /**
2937          * Get the feed logo's link
2938          *
2939          * RSS 2.0 feeds are allowed to have a "feed logo" width.
2940          *
2941          * Uses `<image><width>` or defaults to 88.0 if no width is specified and
2942          * the feed is an RSS 2.0 feed.
2943          *
2944          * @return int|float|null
2945          */
2946         public function get_image_width()
2947         {
2948                 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
2949                 {
2950                         return round($return[0]['data']);
2951                 }
2952                 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2953                 {
2954                         return 88.0;
2955                 }
2956                 else
2957                 {
2958                         return null;
2959                 }
2960         }
2962         /**