2 if ( ! class_exists( 'SimplePie', false ) ) :
4 // Load classes we will need.
5 require ABSPATH . WPINC . '/SimplePie/Misc.php';
6 require ABSPATH . WPINC . '/SimplePie/Cache.php';
7 require ABSPATH . WPINC . '/SimplePie/File.php';
8 require ABSPATH . WPINC . '/SimplePie/Sanitize.php';
9 require ABSPATH . WPINC . '/SimplePie/Registry.php';
10 require ABSPATH . WPINC . '/SimplePie/IRI.php';
11 require ABSPATH . WPINC . '/SimplePie/Locator.php';
12 require ABSPATH . WPINC . '/SimplePie/Content/Type/Sniffer.php';
13 require ABSPATH . WPINC . '/SimplePie/XML/Declaration/Parser.php';
14 require ABSPATH . WPINC . '/SimplePie/Parser.php';
15 require ABSPATH . WPINC . '/SimplePie/Item.php';
16 require ABSPATH . WPINC . '/SimplePie/Parse/Date.php';
17 require ABSPATH . WPINC . '/SimplePie/Author.php';
20 * WordPress autoloader for SimplePie.
24 function wp_simplepie_autoload( $class ) {
25 if ( 0 !== strpos( $class, 'SimplePie_' ) )
28 $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php';
33 * We autoload classes we may not need.
35 spl_autoload_register( 'wp_simplepie_autoload' );
40 * A PHP-Based RSS and Atom Feed Framework.
41 * Takes the hard work out of managing a complete RSS/Atom solution.
43 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
44 * All rights reserved.
46 * Redistribution and use in source and binary forms, with or without modification, are
47 * permitted provided that the following conditions are met:
49 * * Redistributions of source code must retain the above copyright notice, this list of
50 * conditions and the following disclaimer.
52 * * Redistributions in binary form must reproduce the above copyright notice, this list
53 * of conditions and the following disclaimer in the documentation and/or other materials
54 * provided with the distribution.
56 * * Neither the name of the SimplePie Team nor the names of its contributors may be used
57 * to endorse or promote products derived from this software without specific prior
60 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
61 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
62 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
63 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
67 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 * POSSIBILITY OF SUCH DAMAGE.
72 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
74 * @author Geoffrey Sneddon
76 * @link http://simplepie.org/ SimplePie
77 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
83 define('SIMPLEPIE_NAME', 'SimplePie');
88 define('SIMPLEPIE_VERSION', '1.3.1');
92 * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
94 define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()));
97 * SimplePie Website URL
99 define('SIMPLEPIE_URL', 'http://simplepie.org');
102 * SimplePie Useragent
103 * @see SimplePie::set_useragent()
105 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
110 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
114 * @see SimplePie::set_autodiscovery_level()
116 define('SIMPLEPIE_LOCATOR_NONE', 0);
119 * Feed Link Element Autodiscovery
120 * @see SimplePie::set_autodiscovery_level()
122 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
125 * Local Feed Extension Autodiscovery
126 * @see SimplePie::set_autodiscovery_level()
128 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
131 * Local Feed Body Autodiscovery
132 * @see SimplePie::set_autodiscovery_level()
134 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
137 * Remote Feed Extension Autodiscovery
138 * @see SimplePie::set_autodiscovery_level()
140 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
143 * Remote Feed Body Autodiscovery
144 * @see SimplePie::set_autodiscovery_level()
146 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
149 * All Feed Autodiscovery
150 * @see SimplePie::set_autodiscovery_level()
152 define('SIMPLEPIE_LOCATOR_ALL', 31);
157 define('SIMPLEPIE_TYPE_NONE', 0);
162 define('SIMPLEPIE_TYPE_RSS_090', 1);
165 * RSS 0.91 (Netscape)
167 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
170 * RSS 0.91 (Userland)
172 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
175 * RSS 0.91 (both Netscape and Userland)
177 define('SIMPLEPIE_TYPE_RSS_091', 6);
182 define('SIMPLEPIE_TYPE_RSS_092', 8);
187 define('SIMPLEPIE_TYPE_RSS_093', 16);
192 define('SIMPLEPIE_TYPE_RSS_094', 32);
197 define('SIMPLEPIE_TYPE_RSS_10', 64);
202 define('SIMPLEPIE_TYPE_RSS_20', 128);
207 define('SIMPLEPIE_TYPE_RSS_RDF', 65);
210 * Non-RDF-based RSS (truly intended as syndication format)
212 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
217 define('SIMPLEPIE_TYPE_RSS_ALL', 255);
222 define('SIMPLEPIE_TYPE_ATOM_03', 256);
227 define('SIMPLEPIE_TYPE_ATOM_10', 512);
232 define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
237 define('SIMPLEPIE_TYPE_ALL', 1023);
242 define('SIMPLEPIE_CONSTRUCT_NONE', 0);
247 define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
252 define('SIMPLEPIE_CONSTRUCT_HTML', 2);
257 define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
260 * base64-encoded construct
262 define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
267 define('SIMPLEPIE_CONSTRUCT_IRI', 16);
270 * A construct that might be HTML
272 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
277 define('SIMPLEPIE_CONSTRUCT_ALL', 63);
282 define('SIMPLEPIE_SAME_CASE', 1);
285 * Change to lowercase
287 define('SIMPLEPIE_LOWERCASE', 2);
290 * Change to uppercase
292 define('SIMPLEPIE_UPPERCASE', 4);
295 * PCRE for HTML attributes
297 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]*');
300 * PCRE for XML attributes
302 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
307 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
312 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
317 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
322 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
327 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
332 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
335 * RSS 1.0 Content Module Namespace
337 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
341 * (Stupid, I know, but I'm certain it will confuse people less with support.)
343 define('SIMPLEPIE_NAMESPACE_RSS_20', '');
348 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
353 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
356 * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
358 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
363 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
366 * Media RSS Namespace
368 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
371 * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
373 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
376 * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
378 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
381 * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
383 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
386 * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
388 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
391 * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
393 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
396 * iTunes RSS Namespace
398 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
403 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
406 * IANA Link Relations Registry
408 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
413 define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
418 define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
423 define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
426 * fsockopen() file source
428 define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
433 define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
436 * file_get_contents() file source
438 define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
451 * @var array Raw data
454 public $data = array();
457 * @var mixed Error string
463 * @var object Instance of SimplePie_Sanitize (or other class)
464 * @see SimplePie::set_sanitize_class()
470 * @var string SimplePie Useragent
471 * @see SimplePie::set_useragent()
474 public $useragent = SIMPLEPIE_USERAGENT;
477 * @var string Feed URL
478 * @see SimplePie::set_feed_url()
484 * @var object Instance of SimplePie_File to use as a feed
485 * @see SimplePie::set_file()
491 * @var string Raw feed data
492 * @see SimplePie::set_raw_data()
498 * @var int Timeout for fetching remote files
499 * @see SimplePie::set_timeout()
502 public $timeout = 10;
505 * @var bool Forces fsockopen() to be used for remote files instead
506 * of cURL, even if a new enough version is installed
507 * @see SimplePie::force_fsockopen()
510 public $force_fsockopen = false;
513 * @var bool Force the given data/URL to be treated as a feed no matter what
515 * @see SimplePie::force_feed()
518 public $force_feed = false;
521 * @var bool Enable/Disable Caching
522 * @see SimplePie::enable_cache()
525 public $cache = true;
528 * @var int Cache duration (in seconds)
529 * @see SimplePie::set_cache_duration()
532 public $cache_duration = 3600;
535 * @var int Auto-discovery cache duration (in seconds)
536 * @see SimplePie::set_autodiscovery_cache_duration()
539 public $autodiscovery_cache_duration = 604800; // 7 Days.
542 * @var string Cache location (relative to executing script)
543 * @see SimplePie::set_cache_location()
546 public $cache_location = './cache';
549 * @var string Function that creates the cache filename
550 * @see SimplePie::set_cache_name_function()
553 public $cache_name_function = 'md5';
556 * @var bool Reorder feed by date descending
557 * @see SimplePie::enable_order_by_date()
560 public $order_by_date = true;
563 * @var mixed Force input encoding to be set to the follow value
564 * (false, or anything type-cast to false, disables this feature)
565 * @see SimplePie::set_input_encoding()
568 public $input_encoding = false;
571 * @var int Feed Autodiscovery Level
572 * @see SimplePie::set_autodiscovery_level()
575 public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
578 * Class registry object
580 * @var SimplePie_Registry
585 * @var int Maximum number of feeds to check with autodiscovery
586 * @see SimplePie::set_max_checked_feeds()
589 public $max_checked_feeds = 10;
592 * @var array All the feeds found during the autodiscovery process
593 * @see SimplePie::get_all_discovered_feeds()
596 public $all_discovered_feeds = array();
599 * @var string Web-accessible path to the handler_image.php file.
600 * @see SimplePie::set_image_handler()
603 public $image_handler = '';
606 * @var array Stores the URLs when multiple feeds are being initialized.
607 * @see SimplePie::set_feed_url()
610 public $multifeed_url = array();
613 * @var array Stores SimplePie objects when multiple feeds initialized.
616 public $multifeed_objects = array();
619 * @var array Stores the get_object_vars() array for use with multifeeds.
620 * @see SimplePie::set_feed_url()
623 public $config_settings = null;
626 * @var integer Stores the number of items to return per-feed with multifeeds.
627 * @see SimplePie::set_item_limit()
630 public $item_limit = 0;
633 * @var array Stores the default attributes to be stripped by strip_attributes().
634 * @see SimplePie::strip_attributes()
637 public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
640 * @var array Stores the default tags to be stripped by strip_htmltags().
641 * @see SimplePie::strip_htmltags()
644 public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
647 * The SimplePie class contains feed level data and options
649 * To use SimplePie, create the SimplePie object with no parameters. You can
650 * then set configuration options using the provided methods. After setting
651 * them, you must initialise the feed using $feed->init(). At that point the
652 * object's methods and properties will be available to you.
654 * Previously, it was possible to pass in the feed URL along with cache
655 * options directly into the constructor. This has been removed as of 1.3 as
656 * it caused a lot of confusion.
658 * @since 1.0 Preview Release
660 public function __construct()
662 if (version_compare(PHP_VERSION, '5.2', '<'))
664 trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
668 // Other objects, instances created here so we can set options on them
669 $this->sanitize = new SimplePie_Sanitize();
670 $this->registry = new SimplePie_Registry();
672 if (func_num_args() > 0)
674 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
675 trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.', $level);
677 $args = func_get_args();
678 switch (count($args)) {
680 $this->set_cache_duration($args[2]);
682 $this->set_cache_location($args[1]);
684 $this->set_feed_url($args[0]);
691 * Used for converting object to a string
693 public function __toString()
695 return md5(serialize($this->data));
699 * Remove items that link back to this before destroying this object
701 public function __destruct()
703 if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
705 if (!empty($this->data['items']))
707 foreach ($this->data['items'] as $item)
711 unset($item, $this->data['items']);
713 if (!empty($this->data['ordered_items']))
715 foreach ($this->data['ordered_items'] as $item)
719 unset($item, $this->data['ordered_items']);
725 * Force the given data/URL to be treated as a feed
727 * This tells SimplePie to ignore the content-type provided by the server.
728 * Be careful when using this option, as it will also disable autodiscovery.
731 * @param bool $enable Force the given data/URL to be treated as a feed
733 public function force_feed($enable = false)
735 $this->force_feed = (bool) $enable;
739 * Set the URL of the feed you want to parse
741 * This allows you to enter the URL of the feed you want to parse, or the
742 * website you want to try to use auto-discovery on. This takes priority
743 * over any set raw data.
745 * You can set multiple feeds to mash together by passing an array instead
746 * of a string for the $url. Remember that with each additional feed comes
747 * additional processing and resources.
749 * @since 1.0 Preview Release
750 * @see set_raw_data()
751 * @param string|array $url This is the URL (or array of URLs) that you want to parse.
753 public function set_feed_url($url)
755 $this->multifeed_url = array();
758 foreach ($url as $value)
760 $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
765 $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
770 * Set an instance of {@see SimplePie_File} to use as a feed
772 * @param SimplePie_File &$file
773 * @return bool True on success, false on failure
775 public function set_file(&$file)
777 if ($file instanceof SimplePie_File)
779 $this->feed_url = $file->url;
780 $this->file =& $file;
787 * Set the raw XML data to parse
789 * Allows you to use a string of RSS/Atom data instead of a remote feed.
791 * If you have a feed available as a string in PHP, you can tell SimplePie
792 * to parse that data string instead of a remote feed. Any set feed URL
796 * @param string $data RSS or Atom data as a string.
797 * @see set_feed_url()
799 public function set_raw_data($data)
801 $this->raw_data = $data;
805 * Set the the default timeout for fetching remote feeds
807 * This allows you to change the maximum time the feed's server to respond
808 * and send the feed back.
811 * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
813 public function set_timeout($timeout = 10)
815 $this->timeout = (int) $timeout;
819 * Force SimplePie to use fsockopen() instead of cURL
822 * @param bool $enable Force fsockopen() to be used
824 public function force_fsockopen($enable = false)
826 $this->force_fsockopen = (bool) $enable;
830 * Enable/disable caching in SimplePie.
832 * This option allows you to disable caching all-together in SimplePie.
833 * However, disabling the cache can lead to longer load times.
835 * @since 1.0 Preview Release
836 * @param bool $enable Enable caching
838 public function enable_cache($enable = true)
840 $this->cache = (bool) $enable;
844 * Set the length of time (in seconds) that the contents of a feed will be
847 * @param int $seconds The feed content cache duration
849 public function set_cache_duration($seconds = 3600)
851 $this->cache_duration = (int) $seconds;
855 * Set the length of time (in seconds) that the autodiscovered feed URL will
858 * @param int $seconds The autodiscovered feed URL cache duration.
860 public function set_autodiscovery_cache_duration($seconds = 604800)
862 $this->autodiscovery_cache_duration = (int) $seconds;
866 * Set the file system location where the cached files should be stored
868 * @param string $location The file system location.
870 public function set_cache_location($location = './cache')
872 $this->cache_location = (string) $location;
876 * Set whether feed items should be sorted into reverse chronological order
878 * @param bool $enable Sort as reverse chronological order.
880 public function enable_order_by_date($enable = true)
882 $this->order_by_date = (bool) $enable;
886 * Set the character encoding used to parse the feed
888 * This overrides the encoding reported by the feed, however it will fall
889 * back to the normal encoding detection if the override fails
891 * @param string $encoding Character encoding
893 public function set_input_encoding($encoding = false)
897 $this->input_encoding = (string) $encoding;
901 $this->input_encoding = false;
906 * Set how much feed autodiscovery to do
908 * @see SIMPLEPIE_LOCATOR_NONE
909 * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
910 * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
911 * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
912 * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
913 * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
914 * @see SIMPLEPIE_LOCATOR_ALL
915 * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator)
917 public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
919 $this->autodiscovery = (int) $level;
923 * Get the class registry
925 * Use this to override SimplePie's default classes
926 * @see SimplePie_Registry
927 * @return SimplePie_Registry
929 public function &get_registry()
931 return $this->registry;
935 * Useful when you are overloading or extending SimplePie's default classes.
937 * @deprecated Use {@see get_registry()} instead
938 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
939 * @param string $class Name of custom class
940 * @return boolean True on success, false otherwise
943 * Set which class SimplePie uses for caching
945 public function set_cache_class($class = 'SimplePie_Cache')
947 return $this->registry->register('Cache', $class, true);
951 * Set which class SimplePie uses for auto-discovery
953 public function set_locator_class($class = 'SimplePie_Locator')
955 return $this->registry->register('Locator', $class, true);
959 * Set which class SimplePie uses for XML parsing
961 public function set_parser_class($class = 'SimplePie_Parser')
963 return $this->registry->register('Parser', $class, true);
967 * Set which class SimplePie uses for remote file fetching
969 public function set_file_class($class = 'SimplePie_File')
971 return $this->registry->register('File', $class, true);
975 * Set which class SimplePie uses for data sanitization
977 public function set_sanitize_class($class = 'SimplePie_Sanitize')
979 return $this->registry->register('Sanitize', $class, true);
983 * Set which class SimplePie uses for handling feed items
985 public function set_item_class($class = 'SimplePie_Item')
987 return $this->registry->register('Item', $class, true);
991 * Set which class SimplePie uses for handling author data
993 public function set_author_class($class = 'SimplePie_Author')
995 return $this->registry->register('Author', $class, true);
999 * Set which class SimplePie uses for handling category data
1001 public function set_category_class($class = 'SimplePie_Category')
1003 return $this->registry->register('Category', $class, true);
1007 * Set which class SimplePie uses for feed enclosures
1009 public function set_enclosure_class($class = 'SimplePie_Enclosure')
1011 return $this->registry->register('Enclosure', $class, true);
1015 * Set which class SimplePie uses for `<media:text>` captions
1017 public function set_caption_class($class = 'SimplePie_Caption')
1019 return $this->registry->register('Caption', $class, true);
1023 * Set which class SimplePie uses for `<media:copyright>`
1025 public function set_copyright_class($class = 'SimplePie_Copyright')
1027 return $this->registry->register('Copyright', $class, true);
1031 * Set which class SimplePie uses for `<media:credit>`
1033 public function set_credit_class($class = 'SimplePie_Credit')
1035 return $this->registry->register('Credit', $class, true);
1039 * Set which class SimplePie uses for `<media:rating>`
1041 public function set_rating_class($class = 'SimplePie_Rating')
1043 return $this->registry->register('Rating', $class, true);
1047 * Set which class SimplePie uses for `<media:restriction>`
1049 public function set_restriction_class($class = 'SimplePie_Restriction')
1051 return $this->registry->register('Restriction', $class, true);
1055 * Set which class SimplePie uses for content-type sniffing
1057 public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
1059 return $this->registry->register('Content_Type_Sniffer', $class, true);
1063 * Set which class SimplePie uses item sources
1065 public function set_source_class($class = 'SimplePie_Source')
1067 return $this->registry->register('Source', $class, true);
1072 * Set the user agent string
1074 * @param string $ua New user agent string.
1076 public function set_useragent($ua = SIMPLEPIE_USERAGENT)
1078 $this->useragent = (string) $ua;
1082 * Set callback function to create cache filename with
1084 * @param mixed $function Callback function
1086 public function set_cache_name_function($function = 'md5')
1088 if (is_callable($function))
1090 $this->cache_name_function = $function;
1095 * Set options to make SP as fast as possible
1097 * Forgoes a substantial amount of data sanitization in favor of speed. This
1098 * turns SimplePie into a dumb parser of feeds.
1100 * @param bool $set Whether to set them or not
1102 public function set_stupidly_fast($set = false)
1106 $this->enable_order_by_date(false);
1107 $this->remove_div(false);
1108 $this->strip_comments(false);
1109 $this->strip_htmltags(false);
1110 $this->strip_attributes(false);
1111 $this->set_image_handler(false);
1116 * Set maximum number of feeds to check with autodiscovery
1118 * @param int $max Maximum number of feeds to check
1120 public function set_max_checked_feeds($max = 10)
1122 $this->max_checked_feeds = (int) $max;
1125 public function remove_div($enable = true)
1127 $this->sanitize->remove_div($enable);
1130 public function strip_htmltags($tags = '', $encode = null)
1134 $tags = $this->strip_htmltags;
1136 $this->sanitize->strip_htmltags($tags);
1137 if ($encode !== null)
1139 $this->sanitize->encode_instead_of_strip($tags);
1143 public function encode_instead_of_strip($enable = true)
1145 $this->sanitize->encode_instead_of_strip($enable);
1148 public function strip_attributes($attribs = '')
1150 if ($attribs === '')
1152 $attribs = $this->strip_attributes;
1154 $this->sanitize->strip_attributes($attribs);
1158 * Set the output encoding
1160 * Allows you to override SimplePie's output to match that of your webpage.
1161 * This is useful for times when your webpages are not being served as
1162 * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
1163 * is similar to {@see set_input_encoding()}.
1165 * It should be noted, however, that not all character encodings can support
1166 * all characters. If your page is being served as ISO-8859-1 and you try
1167 * to display a Japanese feed, you'll likely see garbled characters.
1168 * Because of this, it is highly recommended to ensure that your webpages
1169 * are served as UTF-8.
1171 * The number of supported character encodings depends on whether your web
1172 * host supports {@link http://php.net/mbstring mbstring},
1173 * {@link http://php.net/iconv iconv}, or both. See
1174 * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for
1177 * @param string $encoding
1179 public function set_output_encoding($encoding = 'UTF-8')
1181 $this->sanitize->set_output_encoding($encoding);
1184 public function strip_comments($strip = false)
1186 $this->sanitize->strip_comments($strip);
1190 * Set element/attribute key/value pairs of HTML attributes
1191 * containing URLs that need to be resolved relative to the feed
1193 * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
1194 * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
1198 * @param array|null $element_attribute Element/attribute key/value pairs, null for default
1200 public function set_url_replacements($element_attribute = null)
1202 $this->sanitize->set_url_replacements($element_attribute);
1206 * Set the handler to enable the display of cached images.
1208 * @param str $page Web-accessible path to the handler_image.php file.
1209 * @param str $qs The query string that the value should be passed to.
1211 public function set_image_handler($page = false, $qs = 'i')
1213 if ($page !== false)
1215 $this->sanitize->set_image_handler($page . '?' . $qs . '=');
1219 $this->image_handler = '';
1224 * Set the limit for items returned per-feed with multifeeds
1226 * @param integer $limit The maximum number of items to return.
1228 public function set_item_limit($limit = 0)
1230 $this->item_limit = (int) $limit;
1234 * Initialize the feed object
1236 * This is what makes everything happen. Period. This is where all of the
1237 * configuration options get processed, feeds are fetched, cached, and
1238 * parsed, and all of that other good stuff.
1240 * @return boolean True if successful, false otherwise
1242 public function init()
1244 // Check absolute bare minimum requirements.
1245 if (!extension_loaded('xml') || !extension_loaded('pcre'))
1249 // 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.
1250 elseif (!extension_loaded('xmlreader'))
1252 static $xml_is_sane = null;
1253 if ($xml_is_sane === null)
1255 $parser_check = xml_parser_create();
1256 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
1257 xml_parser_free($parser_check);
1258 $xml_is_sane = isset($values[0]['value']);
1266 if (method_exists($this->sanitize, 'set_registry'))
1268 $this->sanitize->set_registry($this->registry);
1271 // Pass whatever was set with config options over to the sanitizer.
1272 // Pass the classes in for legacy support; new classes should use the registry instead
1273 $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
1274 $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
1276 if (!empty($this->multifeed_url))
1280 $this->multifeed_objects = array();
1281 $this->error = array();
1282 foreach ($this->multifeed_url as $url)
1284 $this->multifeed_objects[$i] = clone $this;
1285 $this->multifeed_objects[$i]->set_feed_url($url);
1286 $single_success = $this->multifeed_objects[$i]->init();
1287 $success |= $single_success;
1288 if (!$single_success)
1290 $this->error[$i] = $this->multifeed_objects[$i]->error();
1294 return (bool) $success;
1296 elseif ($this->feed_url === null && $this->raw_data === null)
1301 $this->error = null;
1302 $this->data = array();
1303 $this->multifeed_objects = array();
1306 if ($this->feed_url !== null)
1308 $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
1310 // Decide whether to enable caching
1311 if ($this->cache && $parsed_feed_url['scheme'] !== '')
1313 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
1316 // Fetch the data via SimplePie_File into $this->raw_data
1317 if (($fetched = $this->fetch_data($cache)) === true)
1321 elseif ($fetched === false) {
1325 list($headers, $sniffed) = $fetched;
1328 // Set up array of possible encodings
1329 $encodings = array();
1331 // First check to see if input has been overridden.
1332 if ($this->input_encoding !== false)
1334 $encodings[] = $this->input_encoding;
1337 $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
1338 $text_types = array('text/xml', 'text/xml-external-parsed-entity');
1340 // RFC 3023 (only applies to sniffed content)
1341 if (isset($sniffed))
1343 if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
1345 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1347 $encodings[] = strtoupper($charset[1]);
1349 $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1350 $encodings[] = 'UTF-8';
1352 elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1354 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1356 $encodings[] = $charset[1];
1358 $encodings[] = 'US-ASCII';
1360 // Text MIME-type default
1361 elseif (substr($sniffed, 0, 5) === 'text/')
1363 $encodings[] = 'US-ASCII';
1367 // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
1368 $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
1369 $encodings[] = 'UTF-8';
1370 $encodings[] = 'ISO-8859-1';
1372 // There's no point in trying an encoding twice
1373 $encodings = array_unique($encodings);
1375 // Loop through each possible encoding, till we return something, or run out of possibilities
1376 foreach ($encodings as $encoding)
1378 // Change the encoding to UTF-8 (as we always use UTF-8 internally)
1379 if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
1381 // Create new parser
1382 $parser = $this->registry->create('Parser');
1384 // If it's parsed fine
1385 if ($parser->parse($utf8_data, 'UTF-8'))
1387 $this->data = $parser->get_data();
1388 if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
1390 $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
1391 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1395 if (isset($headers))
1397 $this->data['headers'] = $headers;
1399 $this->data['build'] = SIMPLEPIE_BUILD;
1401 // Cache the file if caching is enabled
1402 if ($cache && !$cache->save($this))
1404 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);
1413 // We have an error, just set SimplePie_Misc::error to it and quit
1414 $this->error = sprintf('This XML document is invalid, 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());
1418 $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
1421 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1427 * Fetch the data via SimplePie_File
1429 * If the data is already cached, attempt to fetch it from there instead
1430 * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache
1431 * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
1433 protected function fetch_data(&$cache)
1435 // If it's enabled, use the cache
1439 $this->data = $cache->load();
1440 if (!empty($this->data))
1442 // If the cache is for an outdated build of SimplePie
1443 if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
1446 $this->data = array();
1448 // If we've hit a collision just rerun it with caching disabled
1449 elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
1452 $this->data = array();
1454 // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
1455 elseif (isset($this->data['feed_url']))
1457 // If the autodiscovery cache is still valid use it.
1458 if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
1460 // Do not need to do feed autodiscovery yet.
1461 if ($this->data['feed_url'] !== $this->data['url'])
1463 $this->set_feed_url($this->data['feed_url']);
1464 return $this->init();
1468 $this->data = array();
1471 // Check if the cache has been updated
1472 elseif ($cache->mtime() + $this->cache_duration < time())
1474 // If we have last-modified and/or etag set
1475 if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
1478 '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',
1480 if (isset($this->data['headers']['last-modified']))
1482 $headers['if-modified-since'] = $this->data['headers']['last-modified'];
1484 if (isset($this->data['headers']['etag']))
1486 $headers['if-none-match'] = $this->data['headers']['etag'];
1489 $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
1493 if ($file->status_code === 304)
1505 // If the cache is still valid, just return true
1508 $this->raw_data = false;
1512 // If the cache is empty, delete it
1516 $this->data = array();
1519 // 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.
1522 if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
1524 $file =& $this->file;
1529 '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',
1531 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
1534 // If the file connection has an error, set SimplePie::error to that and quit
1535 if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
1537 $this->error = $file->error;
1538 return !empty($this->data);
1541 if (!$this->force_feed)
1543 // Check if the supplied URL is a feed, if it isn't, look for it.
1544 $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
1546 if (!$locate->is_feed($file))
1548 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
1552 if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
1554 $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
1555 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
1559 catch (SimplePie_Exception $e)
1561 // This is usually because DOMDocument doesn't exist
1562 $this->error = $e->getMessage();
1563 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
1568 $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
1569 if (!$cache->save($this))
1571 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);
1573 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
1575 $this->feed_url = $file->url;
1580 $this->raw_data = $file->body;
1582 $headers = $file->headers;
1583 $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
1584 $sniffed = $sniffer->get_type();
1586 return array($headers, $sniffed);
1590 * Get the error message for the occurred error.
1592 * @return string|array Error message, or array of messages for multifeeds
1594 public function error()
1596 return $this->error;
1602 * This is the same as the old `$feed->enable_xml_dump(true)`, but returns
1603 * the data instead of printing it.
1605 * @return string|boolean Raw XML data, false if the cache is used
1607 public function get_raw_data()
1609 return $this->raw_data;
1613 * Get the character encoding used for output
1615 * @since Preview Release
1618 public function get_encoding()
1620 return $this->sanitize->output_encoding;
1624 * Send the content-type header with correct encoding
1626 * This method ensures that the SimplePie-enabled page is being served with
1627 * the correct {@link http://www.iana.org/assignments/media-types/ mime-type}
1628 * and character encoding HTTP headers (character encoding determined by the
1629 * {@see set_output_encoding} config option).
1631 * This won't work properly if any content or whitespace has already been
1632 * sent to the browser, because it relies on PHP's
1633 * {@link http://php.net/header header()} function, and these are the
1634 * circumstances under which the function works.
1636 * Because it's setting these settings for the entire page (as is the nature
1637 * of HTTP headers), this should only be used once per page (again, at the
1640 * @param string $mime MIME type to serve the page as
1642 public function handle_content_type($mime = 'text/html')
1644 if (!headers_sent())
1646 $header = "Content-type: $mime;";
1647 if ($this->get_encoding())
1649 $header .= ' charset=' . $this->get_encoding();
1653 $header .= ' charset=UTF-8';
1660 * Get the type of the feed
1662 * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against
1663 * using {@link http://php.net/language.operators.bitwise bitwise operators}
1665 * @since 0.8 (usage changed to using constants in 1.0)
1666 * @see SIMPLEPIE_TYPE_NONE Unknown.
1667 * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90.
1668 * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
1669 * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
1670 * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91.
1671 * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92.
1672 * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93.
1673 * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94.
1674 * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0.
1675 * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x.
1676 * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS.
1677 * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format).
1678 * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS.
1679 * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3.
1680 * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0.
1681 * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom.
1682 * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type.
1683 * @return int SIMPLEPIE_TYPE_* constant
1685 public function get_type()
1687 if (!isset($this->data['type']))
1689 $this->data['type'] = SIMPLEPIE_TYPE_ALL;
1690 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
1692 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
1694 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
1696 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
1698 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
1700 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
1701 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
1702 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
1703 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
1705 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
1707 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
1708 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
1709 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
1710 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
1712 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
1715 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
1717 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
1718 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1720 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
1723 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
1724 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1726 switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
1729 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
1733 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
1740 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
1744 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
1748 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
1752 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
1759 $this->data['type'] = SIMPLEPIE_TYPE_NONE;
1762 return $this->data['type'];
1766 * Get the URL for the feed
1768 * May or may not be different from the URL passed to {@see set_feed_url()},
1769 * depending on whether auto-discovery was used.
1771 * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
1772 * @todo If we have a perm redirect we should return the new URL
1773 * @todo When we make the above change, let's support <itunes:new-feed-url> as well
1774 * @todo Also, |atom:link|@rel=self
1775 * @return string|null
1777 public function subscribe_url()
1779 if ($this->feed_url !== null)
1781 return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
1790 * Get data for an feed-level element
1792 * This method allows you to get access to ANY element/attribute that is a
1793 * sub-element of the opening feed tag.
1795 * The return value is an indexed array of elements matching the given
1796 * namespace and tag name. Each element has `attribs`, `data` and `child`
1797 * subkeys. For `attribs` and `child`, these contain namespace subkeys.
1798 * `attribs` then has one level of associative name => value data (where
1799 * `value` is a string) after the namespace. `child` has tag-indexed keys
1800 * after the namespace, each member of which is an indexed array matching
1805 * // This is probably a bad example because we already support
1806 * // <media:content> natively, but it shows you how to parse through
1808 * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
1809 * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
1810 * $file = $content[0]['attribs']['']['url'];
1815 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1816 * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1817 * @param string $tag Tag name
1820 public function get_feed_tags($namespace, $tag)
1822 $type = $this->get_type();
1823 if ($type & SIMPLEPIE_TYPE_ATOM_10)
1825 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
1827 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
1830 if ($type & SIMPLEPIE_TYPE_ATOM_03)
1832 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
1834 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
1837 if ($type & SIMPLEPIE_TYPE_RSS_RDF)
1839 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
1841 return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
1844 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1846 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
1848 return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
1855 * Get data for an channel-level element
1857 * This method allows you to get access to ANY element/attribute in the
1858 * channel/header section of the feed.
1860 * See {@see SimplePie::get_feed_tags()} for a description of the return value
1863 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1864 * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1865 * @param string $tag Tag name
1868 public function get_channel_tags($namespace, $tag)
1870 $type = $this->get_type();
1871 if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
1873 if ($return = $this->get_feed_tags($namespace, $tag))
1878 if ($type & SIMPLEPIE_TYPE_RSS_10)
1880 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
1882 if (isset($channel[0]['child'][$namespace][$tag]))
1884 return $channel[0]['child'][$namespace][$tag];
1888 if ($type & SIMPLEPIE_TYPE_RSS_090)
1890 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
1892 if (isset($channel[0]['child'][$namespace][$tag]))
1894 return $channel[0]['child'][$namespace][$tag];
1898 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1900 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
1902 if (isset($channel[0]['child'][$namespace][$tag]))
1904 return $channel[0]['child'][$namespace][$tag];
1912 * Get data for an channel-level element
1914 * This method allows you to get access to ANY element/attribute in the
1915 * image/logo section of the feed.
1917 * See {@see SimplePie::get_feed_tags()} for a description of the return value
1920 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1921 * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1922 * @param string $tag Tag name
1925 public function get_image_tags($namespace, $tag)
1927 $type = $this->get_type();
1928 if ($type & SIMPLEPIE_TYPE_RSS_10)
1930 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
1932 if (isset($image[0]['child'][$namespace][$tag]))
1934 return $image[0]['child'][$namespace][$tag];
1938 if ($type & SIMPLEPIE_TYPE_RSS_090)
1940 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
1942 if (isset($image[0]['child'][$namespace][$tag]))
1944 return $image[0]['child'][$namespace][$tag];
1948 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
1950 if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
1952 if (isset($image[0]['child'][$namespace][$tag]))
1954 return $image[0]['child'][$namespace][$tag];
1962 * Get the base URL value from the feed
1964 * Uses `<xml:base>` if available, otherwise uses the first link in the
1965 * feed, or failing that, the URL of the feed itself.
1968 * @see subscribe_url
1970 * @param array $element
1973 public function get_base($element = array())
1975 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
1977 return $element['xml_base'];
1979 elseif ($this->get_link() !== null)
1981 return $this->get_link();
1985 return $this->subscribe_url();
1990 * Sanitize feed data
1993 * @see SimplePie_Sanitize::sanitize()
1994 * @param string $data Data to sanitize
1995 * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
1996 * @param string $base Base URL to resolve URLs against
1997 * @return string Sanitized data
1999 public function sanitize($data, $type, $base = '')
2001 return $this->sanitize->sanitize($data, $type, $base);
2005 * Get the title of the feed
2007 * Uses `<atom:title>`, `<title>` or `<dc:title>`
2009 * @since 1.0 (previously called `get_feed_title` since 0.8)
2010 * @return string|null
2012 public function get_title()
2014 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
2016 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2018 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
2020 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2022 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2024 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2026 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2028 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2030 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2032 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2034 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2036 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2038 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2040 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2049 * Get a category for the feed
2052 * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
2053 * @return SimplePie_Category|null
2055 public function get_category($key = 0)
2057 $categories = $this->get_categories();
2058 if (isset($categories[$key]))
2060 return $categories[$key];
2069 * Get all categories for the feed
2071 * Uses `<atom:category>`, `<category>` or `<dc:subject>`
2074 * @return array|null List of {@see SimplePie_Category} objects
2076 public function get_categories()
2078 $categories = array();
2080 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
2085 if (isset($category['attribs']['']['term']))
2087 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
2089 if (isset($category['attribs']['']['scheme']))
2091 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
2093 if (isset($category['attribs']['']['label']))
2095 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
2097 $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
2099 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
2101 // This is really the label, but keep this as the term also for BC.
2102 // Label will also work on retrieving because that falls back to term.
2103 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2104 if (isset($category['attribs']['']['domain']))
2106 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
2112 $categories[] = $this->registry->create('Category', array($term, $scheme, null));
2114 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
2116 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2118 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
2120 $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2123 if (!empty($categories))
2125 return array_unique($categories);
2134 * Get an author for the feed
2137 * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
2138 * @return SimplePie_Author|null
2140 public function get_author($key = 0)
2142 $authors = $this->get_authors();
2143 if (isset($authors[$key]))
2145 return $authors[$key];
2154 * Get all authors for the feed
2156 * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
2159 * @return array|null List of {@see SimplePie_Author} objects
2161 public function get_authors()
2164 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
2169 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2171 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2173 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2175 $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]));
2177 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2179 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2181 if ($name !== null || $email !== null || $uri !== null)
2183 $authors[] = $this->registry->create('Author', array($name, $uri, $email));
2186 if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
2191 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2193 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2195 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2197 $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]));
2199 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2201 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2203 if ($name !== null || $email !== null || $url !== null)
2205 $authors[] = $this->registry->create('Author', array($name, $url, $email));
2208 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
2210 $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2212 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
2214 $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2216 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
2218 $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
2221 if (!empty($authors))
2223 return array_unique($authors);
2232 * Get a contributor for the feed
2235 * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
2236 * @return SimplePie_Author|null
2238 public function get_contributor($key = 0)
2240 $contributors = $this->get_contributors();
2241 if (isset($contributors[$key]))
2243 return $contributors[$key];
2252 * Get all contributors for the feed
2254 * Uses `<atom:contributor>`
2257 * @return array|null List of {@see SimplePie_Author} objects
2259 public function get_contributors()
2261 $contributors = array();
2262 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
2267 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
2269 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2271 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
2273 $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]));
2275 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
2277 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2279 if ($name !== null || $email !== null || $uri !== null)
2281 $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
2284 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
2289 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
2291 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2293 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
2295 $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]));
2297 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
2299 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2301 if ($name !== null || $email !== null || $url !== null)
2303 $contributors[] = $this->registry->create('Author', array($name, $url, $email));
2307 if (!empty($contributors))
2309 return array_unique($contributors);
2318 * Get a single link for the feed
2320 * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
2321 * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
2322 * @param string $rel The relationship of the link to return
2323 * @return string|null Link URL
2325 public function get_link($key = 0, $rel = 'alternate')
2327 $links = $this->get_links($rel);
2328 if (isset($links[$key]))
2330 return $links[$key];
2339 * Get the permalink for the item
2341 * Returns the first link available with a relationship of "alternate".
2342 * Identical to {@see get_link()} with key 0
2345 * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
2346 * @internal Added for parity between the parent-level and the item/entry-level.
2347 * @return string|null Link URL
2349 public function get_permalink()
2351 return $this->get_link(0);
2355 * Get all links for the feed
2357 * Uses `<atom:link>` or `<link>`
2360 * @param string $rel The relationship of links to return
2361 * @return array|null Links found for the feed (strings)
2363 public function get_links($rel = 'alternate')
2365 if (!isset($this->data['links']))
2367 $this->data['links'] = array();
2368 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
2370 foreach ($links as $link)
2372 if (isset($link['attribs']['']['href']))
2374 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2375 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2379 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
2381 foreach ($links as $link)
2383 if (isset($link['attribs']['']['href']))
2385 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2386 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
2391 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2393 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2395 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2397 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2399 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2401 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
2404 $keys = array_keys($this->data['links']);
2405 foreach ($keys as $key)
2407 if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
2409 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
2411 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
2412 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
2416 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
2419 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
2421 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
2423 $this->data['links'][$key] = array_unique($this->data['links'][$key]);
2427 if (isset($this->data['links'][$rel]))
2429 return $this->data['links'][$rel];
2437 public function get_all_discovered_feeds()
2439 return $this->all_discovered_feeds;
2443 * Get the content for the item
2445 * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,
2446 * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>`
2448 * @since 1.0 (previously called `get_feed_description()` since 0.8)
2449 * @return string|null
2451 public function get_description()
2453 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
2455 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2457 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
2459 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2461 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
2463 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2465 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
2467 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
2469 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
2471 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2473 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
2475 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2477 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
2479 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2481 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
2483 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2485 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
2487 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
2496 * Get the copyright info for the feed
2498 * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>`
2500 * @since 1.0 (previously called `get_feed_copyright()` since 0.8)
2501 * @return string|null
2503 public function get_copyright()
2505 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
2507 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2509 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
2511 return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2513 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
2515 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2517 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
2519 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2521 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
2523 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2532 * Get the language for the feed
2534 * Uses `<language>`, `<dc:language>`, or @xml_lang
2536 * @since 1.0 (previously called `get_feed_language()` since 0.8)
2537 * @return string|null
2539 public function get_language()
2541 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
2543 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2545 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
2547 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2549 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
2551 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2553 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
2555 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2557 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
2559 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2561 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
2563 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
2565 elseif (isset($this->data['headers']['content-language']))
2567 return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
2576 * Get the latitude coordinates for the item
2578 * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
2580 * Uses `<geo:lat>` or `<georss:point>`
2583 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2584 * @link http://www.georss.org/ GeoRSS
2585 * @return string|null
2587 public function get_latitude()
2590 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
2592 return (float) $return[0]['data'];
2594 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))
2596 return (float) $match[1];
2605 * Get the longitude coordinates for the feed
2607 * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
2609 * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
2612 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2613 * @link http://www.georss.org/ GeoRSS
2614 * @return string|null
2616 public function get_longitude()
2618 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
2620 return (float) $return[0]['data'];
2622 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
2624 return (float) $return[0]['data'];
2626 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))
2628 return (float) $match[2];
2637 * Get the feed logo's title
2639 * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title.
2641 * Uses `<image><title>` or `<image><dc:title>`
2643 * @return string|null
2645 public function get_image_title()
2647 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
2649 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2651 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
2653 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2655 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
2657 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2659 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
2661 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2663 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
2665 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
2674 * Get the feed logo's URL
2676 * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to
2677 * have a "feed logo" URL. This points directly to the image itself.
2679 * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
2680 * `<image><title>` or `<image><dc:title>`
2682 * @return string|null
2684 public function get_image_url()
2686 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
2688 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
2690 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
2692 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2694 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
2696 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2698 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
2700 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2702 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
2704 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2706 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2708 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2718 * Get the feed logo's link
2720 * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This
2721 * points to a human-readable page that the image should link to.
2723 * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
2724 * `<image><title>` or `<image><dc:title>`
2726 * @return string|null
2728 public function get_image_link()
2730 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
2732 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2734 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
2736 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2738 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
2740 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
2749 * Get the feed logo's link
2751 * RSS 2.0 feeds are allowed to have a "feed logo" width.
2753 * Uses `<image><width>` or defaults to 88.0 if no width is specified and
2754 * the feed is an RSS 2.0 feed.
2756 * @return int|float|null
2758 public function get_image_width()
2760 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
2762 return round($return[0]['data']);
2764 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2775 * Get the feed logo's height
2777 * RSS 2.0 feeds are allowed to have a "feed logo" height.
2779 * Uses `<image><height>` or defaults to 31.0 if no height is specified and
2780 * the feed is an RSS 2.0 feed.
2782 * @return int|float|null
2784 public function get_image_height()
2786 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
2788 return round($return[0]['data']);
2790 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
2801 * Get the number of items in the feed
2803 * This is well-suited for {@link http://php.net/for for()} loops with
2806 * @param int $max Maximum value to return. 0 for no limit
2807 * @return int Number of items in the feed
2809 public function get_item_quantity($max = 0)
2812 $qty = count($this->get_items());
2819 return ($qty > $max) ? $max : $qty;
2824 * Get a single item from the feed
2826 * This is better suited for {@link http://php.net/for for()} loops, whereas
2827 * {@see get_items()} is better suited for
2828 * {@link http://php.net/foreach foreach()} loops.
2830 * @see get_item_quantity()
2832 * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1
2833 * @return SimplePie_Item|null
2835 public function get_item($key = 0)
2837 $items = $this->get_items();
2838 if (isset($items[$key]))
2840 return $items[$key];
2849 * Get all items from the feed
2851 * This is better suited for {@link http://php.net/for for()} loops, whereas
2852 * {@see get_items()} is better suited for
2853 * {@link http://php.net/foreach foreach()} loops.
2855 * @see get_item_quantity
2857 * @param int $start Index to start at
2858 * @param int $end Number of items to return. 0 for all items after `$start`
2859 * @return array|null List of {@see SimplePie_Item} objects
2861 public function get_items($start = 0, $end = 0)
2863 if (!isset($this->data['items']))
2865 if (!empty($this->multifeed_objects))
2867 $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
2871 $this->data['items'] = array();
2872 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
2874 $keys = array_keys($items);
2875 foreach ($keys as $key)
2877 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2880 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
2882 $keys = array_keys($items);
2883 foreach ($keys as $key)
2885 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2888 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
2890 $keys = array_keys($items);
2891 foreach ($keys as $key)
2893 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2896 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
2898 $keys = array_keys($items);
2899 foreach ($keys as $key)
2901 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2904 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
2906 $keys = array_keys($items);
2907 foreach ($keys as $key)
2909 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
2915 if (!empty($this->data['items']))
2917 // If we want to order it by date, check if all items have a date, and then sort it
2918 if ($this->order_by_date && empty($this->multifeed_objects))
2920 if (!isset($this->data['ordered_items']))
2923 foreach ($this->data['items'] as $item)
2925 if (!$item->get_date('U'))
2932 $this->data['ordered_items'] = $this->data['items'];
2935 usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
2938 $items = $this->data['ordered_items'];
2942 $items = $this->data['items'];
2945 // Slice the data as desired
2948 return array_slice($items, $start);
2952 return array_slice($items, $start, $end);
2962 * Set the favicon handler
2964 * @deprecated Use your own favicon handling instead
2966 public function set_favicon_handler($page = false, $qs = 'i')
2968 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
2969 trigger_error('Favicon handling has been removed, please use your own handling', $level);
2974 * Get the favicon for the current feed
2976 * @deprecated Use your own favicon handling instead
2978 public function get_favicon()
2980 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
2981 trigger_error('Favicon handling has been removed, please use your own handling', $level);
2983 if (($url = $this->get_link()) !== null)
2985 return 'http://g.etfv.co/' . urlencode($url);
2992 * Magic method handler
2994 * @param string $method Method name
2995 * @param array $args Arguments to the method
2998 public function __call($method, $args)
3000 if (strpos($method, 'subscribe_') === 0)
3002 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
3003 trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level);
3006 if ($method === 'enable_xml_dump')
3008 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
3009 trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level);
3013 $class = get_class($this);
3014 $trace = debug_backtrace();
3015 $file = $trace[0]['file'];
3016 $line = $trace[0]['line'];
3017 trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);
3021 * Sorting callback for items
3024 * @param SimplePie $a
3025 * @param SimplePie $b
3028 public static function sort_items($a, $b)
3030 return $a->get_date('U') <= $b->get_date('U');
3034 * Merge items from several feeds into one
3036 * If you're merging multiple feeds together, they need to all have dates
3037 * for the items or else SimplePie will refuse to sort them.
3039 * @link http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date#if_feeds_require_separate_per-feed_settings
3040 * @param array $urls List of SimplePie feed objects to merge
3041 * @param int $start Starting item
3042 * @param int $end Number of items to return
3043 * @param int $limit Maximum number of items per feed
3046 public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
3048 if (is_array($urls) && sizeof($urls) > 0)
3051 foreach ($urls as $arg)
3053 if ($arg instanceof SimplePie)
3055 $items = array_merge($items, $arg->get_items(0, $limit));
3059 trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
3064 foreach ($items as $item)
3066 if (!$item->get_date('U'))
3075 usort($items, array(get_class($urls[0]), 'sort_items'));
3080 return array_slice($items, $start);
3084 return array_slice($items, $start, $end);
3089 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);