5 * A PHP-Based RSS and Atom Feed Framework.
6 * Takes the hard work out of managing a complete RSS/Atom solution.
8 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
11 * Redistribution and use in source and binary forms, with or without modification, are
12 * permitted provided that the following conditions are met:
14 * * Redistributions of source code must retain the above copyright notice, this list of
15 * conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright notice, this list
18 * of conditions and the following disclaimer in the documentation and/or other materials
19 * provided with the distribution.
21 * * Neither the name of the SimplePie Team nor the names of its contributors may be used
22 * to endorse or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
26 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
28 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
37 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
39 * @author Geoffrey Sneddon
41 * @link http://simplepie.org/ SimplePie
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
48 define('SIMPLEPIE_NAME', 'SimplePie');
53 define('SIMPLEPIE_VERSION', '1.3.1');
57 * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
59 define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc
::get_build()));
62 * SimplePie Website URL
64 define('SIMPLEPIE_URL', 'http://simplepie.org');
68 * @see SimplePie::set_useragent()
70 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME
. '/' . SIMPLEPIE_VERSION
. ' (Feed Parser; ' . SIMPLEPIE_URL
. '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD
);
75 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL
. '" title="' . SIMPLEPIE_NAME
. ' ' . SIMPLEPIE_VERSION
. '">' . SIMPLEPIE_NAME
. '</a>');
79 * @see SimplePie::set_autodiscovery_level()
81 define('SIMPLEPIE_LOCATOR_NONE', 0);
84 * Feed Link Element Autodiscovery
85 * @see SimplePie::set_autodiscovery_level()
87 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
90 * Local Feed Extension Autodiscovery
91 * @see SimplePie::set_autodiscovery_level()
93 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
96 * Local Feed Body Autodiscovery
97 * @see SimplePie::set_autodiscovery_level()
99 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
102 * Remote Feed Extension Autodiscovery
103 * @see SimplePie::set_autodiscovery_level()
105 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
108 * Remote Feed Body Autodiscovery
109 * @see SimplePie::set_autodiscovery_level()
111 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
114 * All Feed Autodiscovery
115 * @see SimplePie::set_autodiscovery_level()
117 define('SIMPLEPIE_LOCATOR_ALL', 31);
122 define('SIMPLEPIE_TYPE_NONE', 0);
127 define('SIMPLEPIE_TYPE_RSS_090', 1);
130 * RSS 0.91 (Netscape)
132 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
135 * RSS 0.91 (Userland)
137 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
140 * RSS 0.91 (both Netscape and Userland)
142 define('SIMPLEPIE_TYPE_RSS_091', 6);
147 define('SIMPLEPIE_TYPE_RSS_092', 8);
152 define('SIMPLEPIE_TYPE_RSS_093', 16);
157 define('SIMPLEPIE_TYPE_RSS_094', 32);
162 define('SIMPLEPIE_TYPE_RSS_10', 64);
167 define('SIMPLEPIE_TYPE_RSS_20', 128);
172 define('SIMPLEPIE_TYPE_RSS_RDF', 65);
175 * Non-RDF-based RSS (truly intended as syndication format)
177 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
182 define('SIMPLEPIE_TYPE_RSS_ALL', 255);
187 define('SIMPLEPIE_TYPE_ATOM_03', 256);
192 define('SIMPLEPIE_TYPE_ATOM_10', 512);
197 define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
202 define('SIMPLEPIE_TYPE_ALL', 1023);
207 define('SIMPLEPIE_CONSTRUCT_NONE', 0);
212 define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
217 define('SIMPLEPIE_CONSTRUCT_HTML', 2);
222 define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
225 * base64-encoded construct
227 define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
232 define('SIMPLEPIE_CONSTRUCT_IRI', 16);
235 * A construct that might be HTML
237 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
242 define('SIMPLEPIE_CONSTRUCT_ALL', 63);
247 define('SIMPLEPIE_SAME_CASE', 1);
250 * Change to lowercase
252 define('SIMPLEPIE_LOWERCASE', 2);
255 * Change to uppercase
257 define('SIMPLEPIE_UPPERCASE', 4);
260 * PCRE for HTML attributes
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]*');
265 * PCRE for XML attributes
267 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
272 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
277 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
282 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
287 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
292 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
297 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
300 * RSS 1.0 Content Module Namespace
302 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
306 * (Stupid, I know, but I'm certain it will confuse people less with support.)
308 define('SIMPLEPIE_NAMESPACE_RSS_20', '');
313 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
318 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
321 * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
323 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
328 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
331 * Media RSS Namespace
333 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
336 * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
338 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
341 * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
343 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
346 * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
348 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
351 * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
353 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
356 * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
358 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
361 * iTunes RSS Namespace
363 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
368 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
371 * IANA Link Relations Registry
373 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
378 define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
383 define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
388 define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
391 * fsockopen() file source
393 define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
398 define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
401 * file_get_contents() file source
403 define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
416 * @var array Raw data
419 public $data = array();
422 * @var mixed Error string
428 * @var object Instance of SimplePie_Sanitize (or other class)
429 * @see SimplePie::set_sanitize_class()
435 * @var string SimplePie Useragent
436 * @see SimplePie::set_useragent()
439 public $useragent = SIMPLEPIE_USERAGENT
;
442 * @var string Feed URL
443 * @see SimplePie::set_feed_url()
449 * @var object Instance of SimplePie_File to use as a feed
450 * @see SimplePie::set_file()
456 * @var string Raw feed data
457 * @see SimplePie::set_raw_data()
463 * @var int Timeout for fetching remote files
464 * @see SimplePie::set_timeout()
467 public $timeout = 10;
470 * @var bool Forces fsockopen() to be used for remote files instead
471 * of cURL, even if a new enough version is installed
472 * @see SimplePie::force_fsockopen()
475 public $force_fsockopen = false;
478 * @var bool Force the given data/URL to be treated as a feed no matter what
480 * @see SimplePie::force_feed()
483 public $force_feed = false;
486 * @var bool Enable/Disable Caching
487 * @see SimplePie::enable_cache()
490 public $cache = true;
493 * @var int Cache duration (in seconds)
494 * @see SimplePie::set_cache_duration()
497 public $cache_duration = 3600;
500 * @var int Auto-discovery cache duration (in seconds)
501 * @see SimplePie::set_autodiscovery_cache_duration()
504 public $autodiscovery_cache_duration = 604800; // 7 Days.
507 * @var string Cache location (relative to executing script)
508 * @see SimplePie::set_cache_location()
511 public $cache_location = './cache';
514 * @var string Function that creates the cache filename
515 * @see SimplePie::set_cache_name_function()
518 public $cache_name_function = 'md5';
521 * @var bool Reorder feed by date descending
522 * @see SimplePie::enable_order_by_date()
525 public $order_by_date = true;
528 * @var mixed Force input encoding to be set to the follow value
529 * (false, or anything type-cast to false, disables this feature)
530 * @see SimplePie::set_input_encoding()
533 public $input_encoding = false;
536 * @var int Feed Autodiscovery Level
537 * @see SimplePie::set_autodiscovery_level()
540 public $autodiscovery = SIMPLEPIE_LOCATOR_ALL
;
543 * Class registry object
545 * @var SimplePie_Registry
550 * @var int Maximum number of feeds to check with autodiscovery
551 * @see SimplePie::set_max_checked_feeds()
554 public $max_checked_feeds = 10;
557 * @var array All the feeds found during the autodiscovery process
558 * @see SimplePie::get_all_discovered_feeds()
561 public $all_discovered_feeds = array();
564 * @var string Web-accessible path to the handler_image.php file.
565 * @see SimplePie::set_image_handler()
568 public $image_handler = '';
571 * @var array Stores the URLs when multiple feeds are being initialized.
572 * @see SimplePie::set_feed_url()
575 public $multifeed_url = array();
578 * @var array Stores SimplePie objects when multiple feeds initialized.
581 public $multifeed_objects = array();
584 * @var array Stores the get_object_vars() array for use with multifeeds.
585 * @see SimplePie::set_feed_url()
588 public $config_settings = null;
591 * @var integer Stores the number of items to return per-feed with multifeeds.
592 * @see SimplePie::set_item_limit()
595 public $item_limit = 0;
598 * @var array Stores the default attributes to be stripped by strip_attributes().
599 * @see SimplePie::strip_attributes()
602 public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
605 * @var array Stores the default tags to be stripped by strip_htmltags().
606 * @see SimplePie::strip_htmltags()
609 public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
612 * The SimplePie class contains feed level data and options
614 * To use SimplePie, create the SimplePie object with no parameters. You can
615 * then set configuration options using the provided methods. After setting
616 * them, you must initialise the feed using $feed->init(). At that point the
617 * object's methods and properties will be available to you.
619 * Previously, it was possible to pass in the feed URL along with cache
620 * options directly into the constructor. This has been removed as of 1.3 as
621 * it caused a lot of confusion.
623 * @since 1.0 Preview Release
625 public function __construct()
627 if (version_compare(PHP_VERSION
, '5.2', '<'))
629 trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
633 // Other objects, instances created here so we can set options on them
634 $this->sanitize
= new SimplePie_Sanitize();
635 $this->registry
= new SimplePie_Registry();
637 if (func_num_args() > 0)
639 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED
: E_USER_WARNING
;
640 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);
642 $args = func_get_args();
643 switch (count($args)) {
645 $this->set_cache_duration($args[2]);
647 $this->set_cache_location($args[1]);
649 $this->set_feed_url($args[0]);
656 * Used for converting object to a string
658 public function __toString()
660 return md5(serialize($this->data
));
664 * Remove items that link back to this before destroying this object
666 public function __destruct()
668 if ((version_compare(PHP_VERSION
, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
670 if (!empty($this->data
['items']))
672 foreach ($this->data
['items'] as $item)
676 unset($item, $this->data
['items']);
678 if (!empty($this->data
['ordered_items']))
680 foreach ($this->data
['ordered_items'] as $item)
684 unset($item, $this->data
['ordered_items']);
690 * Force the given data/URL to be treated as a feed
692 * This tells SimplePie to ignore the content-type provided by the server.
693 * Be careful when using this option, as it will also disable autodiscovery.
696 * @param bool $enable Force the given data/URL to be treated as a feed
698 public function force_feed($enable = false)
700 $this->force_feed
= (bool) $enable;
704 * Set the URL of the feed you want to parse
706 * This allows you to enter the URL of the feed you want to parse, or the
707 * website you want to try to use auto-discovery on. This takes priority
708 * over any set raw data.
710 * You can set multiple feeds to mash together by passing an array instead
711 * of a string for the $url. Remember that with each additional feed comes
712 * additional processing and resources.
714 * @since 1.0 Preview Release
715 * @see set_raw_data()
716 * @param string|array $url This is the URL (or array of URLs) that you want to parse.
718 public function set_feed_url($url)
720 $this->multifeed_url
= array();
723 foreach ($url as $value)
725 $this->multifeed_url
[] = $this->registry
->call('Misc', 'fix_protocol', array($value, 1));
730 $this->feed_url
= $this->registry
->call('Misc', 'fix_protocol', array($url, 1));
735 * Set an instance of {@see SimplePie_File} to use as a feed
737 * @param SimplePie_File &$file
738 * @return bool True on success, false on failure
740 public function set_file(&$file)
742 if ($file instanceof SimplePie_File
)
744 $this->feed_url
= $file->url
;
745 $this->file
=& $file;
752 * Set the raw XML data to parse
754 * Allows you to use a string of RSS/Atom data instead of a remote feed.
756 * If you have a feed available as a string in PHP, you can tell SimplePie
757 * to parse that data string instead of a remote feed. Any set feed URL
761 * @param string $data RSS or Atom data as a string.
762 * @see set_feed_url()
764 public function set_raw_data($data)
766 $this->raw_data
= $data;
770 * Set the the default timeout for fetching remote feeds
772 * This allows you to change the maximum time the feed's server to respond
773 * and send the feed back.
776 * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
778 public function set_timeout($timeout = 10)
780 $this->timeout
= (int) $timeout;
784 * Force SimplePie to use fsockopen() instead of cURL
787 * @param bool $enable Force fsockopen() to be used
789 public function force_fsockopen($enable = false)
791 $this->force_fsockopen
= (bool) $enable;
795 * Enable/disable caching in SimplePie.
797 * This option allows you to disable caching all-together in SimplePie.
798 * However, disabling the cache can lead to longer load times.
800 * @since 1.0 Preview Release
801 * @param bool $enable Enable caching
803 public function enable_cache($enable = true)
805 $this->cache
= (bool) $enable;
809 * Set the length of time (in seconds) that the contents of a feed will be
812 * @param int $seconds The feed content cache duration
814 public function set_cache_duration($seconds = 3600)
816 $this->cache_duration
= (int) $seconds;
820 * Set the length of time (in seconds) that the autodiscovered feed URL will
823 * @param int $seconds The autodiscovered feed URL cache duration.
825 public function set_autodiscovery_cache_duration($seconds = 604800)
827 $this->autodiscovery_cache_duration
= (int) $seconds;
831 * Set the file system location where the cached files should be stored
833 * @param string $location The file system location.
835 public function set_cache_location($location = './cache')
837 $this->cache_location
= (string) $location;
841 * Set whether feed items should be sorted into reverse chronological order
843 * @param bool $enable Sort as reverse chronological order.
845 public function enable_order_by_date($enable = true)
847 $this->order_by_date
= (bool) $enable;
851 * Set the character encoding used to parse the feed
853 * This overrides the encoding reported by the feed, however it will fall
854 * back to the normal encoding detection if the override fails
856 * @param string $encoding Character encoding
858 public function set_input_encoding($encoding = false)
862 $this->input_encoding
= (string) $encoding;
866 $this->input_encoding
= false;
871 * Set how much feed autodiscovery to do
873 * @see SIMPLEPIE_LOCATOR_NONE
874 * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
875 * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
876 * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
877 * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
878 * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
879 * @see SIMPLEPIE_LOCATOR_ALL
880 * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator)
882 public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL
)
884 $this->autodiscovery
= (int) $level;
888 * Get the class registry
890 * Use this to override SimplePie's default classes
891 * @see SimplePie_Registry
892 * @return SimplePie_Registry
894 public function &get_registry()
896 return $this->registry
;
900 * Useful when you are overloading or extending SimplePie's default classes.
902 * @deprecated Use {@see get_registry()} instead
903 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
904 * @param string $class Name of custom class
905 * @return boolean True on success, false otherwise
908 * Set which class SimplePie uses for caching
910 public function set_cache_class($class = 'SimplePie_Cache')
912 return $this->registry
->register('Cache', $class, true);
916 * Set which class SimplePie uses for auto-discovery
918 public function set_locator_class($class = 'SimplePie_Locator')
920 return $this->registry
->register('Locator', $class, true);
924 * Set which class SimplePie uses for XML parsing
926 public function set_parser_class($class = 'SimplePie_Parser')
928 return $this->registry
->register('Parser', $class, true);
932 * Set which class SimplePie uses for remote file fetching
934 public function set_file_class($class = 'SimplePie_File')
936 return $this->registry
->register('File', $class, true);
940 * Set which class SimplePie uses for data sanitization
942 public function set_sanitize_class($class = 'SimplePie_Sanitize')
944 return $this->registry
->register('Sanitize', $class, true);
948 * Set which class SimplePie uses for handling feed items
950 public function set_item_class($class = 'SimplePie_Item')
952 return $this->registry
->register('Item', $class, true);
956 * Set which class SimplePie uses for handling author data
958 public function set_author_class($class = 'SimplePie_Author')
960 return $this->registry
->register('Author', $class, true);
964 * Set which class SimplePie uses for handling category data
966 public function set_category_class($class = 'SimplePie_Category')
968 return $this->registry
->register('Category', $class, true);
972 * Set which class SimplePie uses for feed enclosures
974 public function set_enclosure_class($class = 'SimplePie_Enclosure')
976 return $this->registry
->register('Enclosure', $class, true);
980 * Set which class SimplePie uses for `<media:text>` captions
982 public function set_caption_class($class = 'SimplePie_Caption')
984 return $this->registry
->register('Caption', $class, true);
988 * Set which class SimplePie uses for `<media:copyright>`
990 public function set_copyright_class($class = 'SimplePie_Copyright')
992 return $this->registry
->register('Copyright', $class, true);
996 * Set which class SimplePie uses for `<media:credit>`
998 public function set_credit_class($class = 'SimplePie_Credit')
1000 return $this->registry
->register('Credit', $class, true);
1004 * Set which class SimplePie uses for `<media:rating>`
1006 public function set_rating_class($class = 'SimplePie_Rating')
1008 return $this->registry
->register('Rating', $class, true);
1012 * Set which class SimplePie uses for `<media:restriction>`
1014 public function set_restriction_class($class = 'SimplePie_Restriction')
1016 return $this->registry
->register('Restriction', $class, true);
1020 * Set which class SimplePie uses for content-type sniffing
1022 public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
1024 return $this->registry
->register('Content_Type_Sniffer', $class, true);
1028 * Set which class SimplePie uses item sources
1030 public function set_source_class($class = 'SimplePie_Source')
1032 return $this->registry
->register('Source', $class, true);
1037 * Set the user agent string
1039 * @param string $ua New user agent string.
1041 public function set_useragent($ua = SIMPLEPIE_USERAGENT
)
1043 $this->useragent
= (string) $ua;
1047 * Set callback function to create cache filename with
1049 * @param mixed $function Callback function
1051 public function set_cache_name_function($function = 'md5')
1053 if (is_callable($function))
1055 $this->cache_name_function
= $function;
1060 * Set options to make SP as fast as possible
1062 * Forgoes a substantial amount of data sanitization in favor of speed. This
1063 * turns SimplePie into a dumb parser of feeds.
1065 * @param bool $set Whether to set them or not
1067 public function set_stupidly_fast($set = false)
1071 $this->enable_order_by_date(false);
1072 $this->remove_div(false);
1073 $this->strip_comments(false);
1074 $this->strip_htmltags(false);
1075 $this->strip_attributes(false);
1076 $this->set_image_handler(false);
1081 * Set maximum number of feeds to check with autodiscovery
1083 * @param int $max Maximum number of feeds to check
1085 public function set_max_checked_feeds($max = 10)
1087 $this->max_checked_feeds
= (int) $max;
1090 public function remove_div($enable = true)
1092 $this->sanitize
->remove_div($enable);
1095 public function strip_htmltags($tags = '', $encode = null)
1099 $tags = $this->strip_htmltags
;
1101 $this->sanitize
->strip_htmltags($tags);
1102 if ($encode !== null)
1104 $this->sanitize
->encode_instead_of_strip($tags);
1108 public function encode_instead_of_strip($enable = true)
1110 $this->sanitize
->encode_instead_of_strip($enable);
1113 public function strip_attributes($attribs = '')
1115 if ($attribs === '')
1117 $attribs = $this->strip_attributes
;
1119 $this->sanitize
->strip_attributes($attribs);
1123 * Set the output encoding
1125 * Allows you to override SimplePie's output to match that of your webpage.
1126 * This is useful for times when your webpages are not being served as
1127 * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
1128 * is similar to {@see set_input_encoding()}.
1130 * It should be noted, however, that not all character encodings can support
1131 * all characters. If your page is being served as ISO-8859-1 and you try
1132 * to display a Japanese feed, you'll likely see garbled characters.
1133 * Because of this, it is highly recommended to ensure that your webpages
1134 * are served as UTF-8.
1136 * The number of supported character encodings depends on whether your web
1137 * host supports {@link http://php.net/mbstring mbstring},
1138 * {@link http://php.net/iconv iconv}, or both. See
1139 * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for
1142 * @param string $encoding
1144 public function set_output_encoding($encoding = 'UTF-8')
1146 $this->sanitize
->set_output_encoding($encoding);
1149 public function strip_comments($strip = false)
1151 $this->sanitize
->strip_comments($strip);
1155 * Set element/attribute key/value pairs of HTML attributes
1156 * containing URLs that need to be resolved relative to the feed
1158 * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
1159 * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
1163 * @param array|null $element_attribute Element/attribute key/value pairs, null for default
1165 public function set_url_replacements($element_attribute = null)
1167 $this->sanitize
->set_url_replacements($element_attribute);
1171 * Set the handler to enable the display of cached images.
1173 * @param str $page Web-accessible path to the handler_image.php file.
1174 * @param str $qs The query string that the value should be passed to.
1176 public function set_image_handler($page = false, $qs = 'i')
1178 if ($page !== false)
1180 $this->sanitize
->set_image_handler($page . '?' . $qs . '=');
1184 $this->image_handler
= '';
1189 * Set the limit for items returned per-feed with multifeeds
1191 * @param integer $limit The maximum number of items to return.
1193 public function set_item_limit($limit = 0)
1195 $this->item_limit
= (int) $limit;
1199 * Initialize the feed object
1201 * This is what makes everything happen. Period. This is where all of the
1202 * configuration options get processed, feeds are fetched, cached, and
1203 * parsed, and all of that other good stuff.
1205 * @return boolean True if successful, false otherwise
1207 public function init()
1209 // Check absolute bare minimum requirements.
1210 if (!extension_loaded('xml') || !extension_loaded('pcre'))
1214 // 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.
1215 elseif (!extension_loaded('xmlreader'))
1217 static $xml_is_sane = null;
1218 if ($xml_is_sane === null)
1220 $parser_check = xml_parser_create();
1221 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
1222 xml_parser_free($parser_check);
1223 $xml_is_sane = isset($values[0]['value']);
1231 if (method_exists($this->sanitize
, 'set_registry'))
1233 $this->sanitize
->set_registry($this->registry
);
1236 // Pass whatever was set with config options over to the sanitizer.
1237 // Pass the classes in for legacy support; new classes should use the registry instead
1238 $this->sanitize
->pass_cache_data($this->cache
, $this->cache_location
, $this->cache_name_function
, $this->registry
->get_class('Cache'));
1239 $this->sanitize
->pass_file_data($this->registry
->get_class('File'), $this->timeout
, $this->useragent
, $this->force_fsockopen
);
1241 if (!empty($this->multifeed_url
))
1245 $this->multifeed_objects
= array();
1246 $this->error
= array();
1247 foreach ($this->multifeed_url
as $url)
1249 $this->multifeed_objects
[$i] = clone $this;
1250 $this->multifeed_objects
[$i]->set_feed_url($url);
1251 $single_success = $this->multifeed_objects
[$i]->init();
1252 $success |= $single_success;
1253 if (!$single_success)
1255 $this->error
[$i] = $this->multifeed_objects
[$i]->error();
1259 return (bool) $success;
1261 elseif ($this->feed_url
=== null && $this->raw_data
=== null)
1266 $this->error
= null;
1267 $this->data
= array();
1268 $this->multifeed_objects
= array();
1271 if ($this->feed_url
!== null)
1273 $parsed_feed_url = $this->registry
->call('Misc', 'parse_url', array($this->feed_url
));
1275 // Decide whether to enable caching
1276 if ($this->cache
&& $parsed_feed_url['scheme'] !== '')
1278 $cache = $this->registry
->call('Cache', 'get_handler', array($this->cache_location
, call_user_func($this->cache_name_function
, $this->feed_url
), 'spc'));
1281 // Fetch the data via SimplePie_File into $this->raw_data
1282 if (($fetched = $this->fetch_data($cache)) === true)
1286 elseif ($fetched === false) {
1290 list($headers, $sniffed) = $fetched;
1293 // Set up array of possible encodings
1294 $encodings = array();
1296 // First check to see if input has been overridden.
1297 if ($this->input_encoding
!== false)
1299 $encodings[] = $this->input_encoding
;
1302 $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
1303 $text_types = array('text/xml', 'text/xml-external-parsed-entity');
1305 // RFC 3023 (only applies to sniffed content)
1306 if (isset($sniffed))
1308 if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
1310 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1312 $encodings[] = strtoupper($charset[1]);
1314 $encodings = array_merge($encodings, $this->registry
->call('Misc', 'xml_encoding', array($this->raw_data
, &$this->registry
)));
1315 $encodings[] = 'UTF-8';
1317 elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1319 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1321 $encodings[] = $charset[1];
1323 $encodings[] = 'US-ASCII';
1325 // Text MIME-type default
1326 elseif (substr($sniffed, 0, 5) === 'text/')
1328 $encodings[] = 'US-ASCII';
1332 // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
1333 $encodings = array_merge($encodings, $this->registry
->call('Misc', 'xml_encoding', array($this->raw_data
, &$this->registry
)));
1334 $encodings[] = 'UTF-8';
1335 $encodings[] = 'ISO-8859-1';
1337 // There's no point in trying an encoding twice
1338 $encodings = array_unique($encodings);
1340 // Loop through each possible encoding, till we return something, or run out of possibilities
1341 foreach ($encodings as $encoding)
1343 // Change the encoding to UTF-8 (as we always use UTF-8 internally)
1344 if ($utf8_data = $this->registry
->call('Misc', 'change_encoding', array($this->raw_data
, $encoding, 'UTF-8')))
1346 // Create new parser
1347 $parser = $this->registry
->create('Parser');
1349 // If it's parsed fine
1350 if ($parser->parse($utf8_data, 'UTF-8'))
1352 $this->data
= $parser->get_data();
1353 if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE
))
1355 $this->error
= "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
1356 $this->registry
->call('Misc', 'error', array($this->error
, E_USER_NOTICE
, __FILE__
, __LINE__
));
1360 if (isset($headers))
1362 $this->data
['headers'] = $headers;
1364 $this->data
['build'] = SIMPLEPIE_BUILD
;
1366 // Cache the file if caching is enabled
1367 if ($cache && !$cache->save($this))
1369 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
);
1378 // We have an error, just set SimplePie_Misc::error to it and quit
1379 $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());
1383 $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.';
1386 $this->registry
->call('Misc', 'error', array($this->error
, E_USER_NOTICE
, __FILE__
, __LINE__
));
1392 * Fetch the data via SimplePie_File
1394 * If the data is already cached, attempt to fetch it from there instead
1395 * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache
1396 * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
1398 protected function fetch_data(&$cache)
1400 // If it's enabled, use the cache
1404 $this->data
= $cache->load();
1405 if (!empty($this->data
))
1407 // If the cache is for an outdated build of SimplePie
1408 if (!isset($this->data
['build']) || $this->data
['build'] !== SIMPLEPIE_BUILD
)
1411 $this->data
= array();
1413 // If we've hit a collision just rerun it with caching disabled
1414 elseif (isset($this->data
['url']) && $this->data
['url'] !== $this->feed_url
)
1417 $this->data
= array();
1419 // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
1420 elseif (isset($this->data
['feed_url']))
1422 // If the autodiscovery cache is still valid use it.
1423 if ($cache->mtime() +
$this->autodiscovery_cache_duration
> time())
1425 // Do not need to do feed autodiscovery yet.
1426 if ($this->data
['feed_url'] !== $this->data
['url'])
1428 $this->set_feed_url($this->data
['feed_url']);
1429 return $this->init();
1433 $this->data
= array();
1436 // Check if the cache has been updated
1437 elseif ($cache->mtime() +
$this->cache_duration
< time())
1439 // If we have last-modified and/or etag set
1440 if (isset($this->data
['headers']['last-modified']) || isset($this->data
['headers']['etag']))
1443 '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',
1445 if (isset($this->data
['headers']['last-modified']))
1447 $headers['if-modified-since'] = $this->data
['headers']['last-modified'];
1449 if (isset($this->data
['headers']['etag']))
1451 $headers['if-none-match'] = $this->data
['headers']['etag'];
1454 $file = $this->registry
->create('File', array($this->feed_url
, $this->timeout
/10, 5, $headers, $this->useragent
, $this->force_fsockopen
));
1458 if ($file->status_code
=== 304)
1470 // If the cache is still valid, just return true
1473 $this->raw_data
= false;
1477 // If the cache is empty, delete it
1481 $this->data
= array();
1484 // 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.
1487 if ($this->file
instanceof SimplePie_File
&& $this->file
->url
=== $this->feed_url
)
1489 $file =& $this->file
;
1494 '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',
1496 $file = $this->registry
->create('File', array($this->feed_url
, $this->timeout
, 5, $headers, $this->useragent
, $this->force_fsockopen
));
1499 // If the file connection has an error, set SimplePie::error to that and quit
1500 if (!$file->success
&& !($file->method
& SIMPLEPIE_FILE_SOURCE_REMOTE
=== 0 || ($file->status_code
=== 200 || $file->status_code
> 206 && $file->status_code
< 300)))
1502 $this->error
= $file->error
;
1503 return !empty($this->data
);
1506 if (!$this->force_feed
)
1508 // Check if the supplied URL is a feed, if it isn't, look for it.
1509 $locate = $this->registry
->create('Locator', array(&$file, $this->timeout
, $this->useragent
, $this->max_checked_feeds
));
1511 if (!$locate->is_feed($file))
1513 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
1517 if (!($file = $locate->find($this->autodiscovery
, $this->all_discovered_feeds
)))
1519 $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.";
1520 $this->registry
->call('Misc', 'error', array($this->error
, E_USER_NOTICE
, __FILE__
, __LINE__
));
1524 catch (SimplePie_Exception
$e)
1526 // This is usually because DOMDocument doesn't exist
1527 $this->error
= $e->getMessage();
1528 $this->registry
->call('Misc', 'error', array($this->error
, E_USER_NOTICE
, $e->getFile(), $e->getLine()));
1533 $this->data
= array('url' => $this->feed_url
, 'feed_url' => $file->url
, 'build' => SIMPLEPIE_BUILD
);
1534 if (!$cache->save($this))
1536 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
);
1538 $cache = $this->registry
->call('Cache', 'get_handler', array($this->cache_location
, call_user_func($this->cache_name_function
, $file->url
), 'spc'));
1540 $this->feed_url
= $file->url
;
1545 $this->raw_data
= $file->body
;
1547 $headers = $file->headers
;
1548 $sniffer = $this->registry
->create('Content_Type_Sniffer', array(&$file));
1549 $sniffed = $sniffer->get_type();
1551 return array($headers, $sniffed);
1555 * Get the error message for the occured error
1557 * @return string|array Error message, or array of messages for multifeeds
1559 public function error()
1561 return $this->error
;
1567 * This is the same as the old `$feed->enable_xml_dump(true)`, but returns
1568 * the data instead of printing it.
1570 * @return string|boolean Raw XML data, false if the cache is used
1572 public function get_raw_data()
1574 return $this->raw_data
;
1578 * Get the character encoding used for output
1580 * @since Preview Release
1583 public function get_encoding()
1585 return $this->sanitize
->output_encoding
;
1589 * Send the content-type header with correct encoding
1591 * This method ensures that the SimplePie-enabled page is being served with
1592 * the correct {@link http://www.iana.org/assignments/media-types/ mime-type}
1593 * and character encoding HTTP headers (character encoding determined by the
1594 * {@see set_output_encoding} config option).
1596 * This won't work properly if any content or whitespace has already been
1597 * sent to the browser, because it relies on PHP's
1598 * {@link http://php.net/header header()} function, and these are the
1599 * circumstances under which the function works.
1601 * Because it's setting these settings for the entire page (as is the nature
1602 * of HTTP headers), this should only be used once per page (again, at the
1605 * @param string $mime MIME type to serve the page as
1607 public function handle_content_type($mime = 'text/html')
1609 if (!headers_sent())
1611 $header = "Content-type: $mime;";
1612 if ($this->get_encoding())
1614 $header .= ' charset=' . $this->get_encoding();
1618 $header .= ' charset=UTF-8';
1625 * Get the type of the feed
1627 * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against
1628 * using {@link http://php.net/language.operators.bitwise bitwise operators}
1630 * @since 0.8 (usage changed to using constants in 1.0)
1631 * @see SIMPLEPIE_TYPE_NONE Unknown.
1632 * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90.
1633 * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
1634 * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
1635 * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91.
1636 * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92.
1637 * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93.
1638 * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94.
1639 * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0.
1640 * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x.
1641 * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS.
1642 * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format).
1643 * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS.
1644 * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3.
1645 * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0.
1646 * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom.
1647 * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type.
1648 * @return int SIMPLEPIE_TYPE_* constant
1650 public function get_type()
1652 if (!isset($this->data
['type']))
1654 $this->data
['type'] = SIMPLEPIE_TYPE_ALL
;
1655 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed']))
1657 $this->data
['type'] &= SIMPLEPIE_TYPE_ATOM_10
;
1659 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed']))
1661 $this->data
['type'] &= SIMPLEPIE_TYPE_ATOM_03
;
1663 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF']))
1665 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['channel'])
1666 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['image'])
1667 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['item'])
1668 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['textinput']))
1670 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_10
;
1672 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['channel'])
1673 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['image'])
1674 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['item'])
1675 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['textinput']))
1677 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_090
;
1680 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss']))
1682 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_ALL
;
1683 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['attribs']['']['version']))
1685 switch (trim($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['attribs']['']['version']))
1688 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_091
;
1689 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['skiphours']['hour'][0]['data']))
1691 switch (trim($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['skiphours']['hour'][0]['data']))
1694 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE
;
1698 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND
;
1705 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_092
;
1709 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_093
;
1713 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_094
;
1717 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_20
;
1724 $this->data
['type'] = SIMPLEPIE_TYPE_NONE
;
1727 return $this->data
['type'];
1731 * Get the URL for the feed
1733 * May or may not be different from the URL passed to {@see set_feed_url()},
1734 * depending on whether auto-discovery was used.
1736 * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
1737 * @todo If we have a perm redirect we should return the new URL
1738 * @todo When we make the above change, let's support <itunes:new-feed-url> as well
1739 * @todo Also, |atom:link|@rel=self
1740 * @return string|null
1742 public function subscribe_url()
1744 if ($this->feed_url
!== null)
1746 return $this->sanitize($this->feed_url
, SIMPLEPIE_CONSTRUCT_IRI
);
1755 * Get data for an feed-level element
1757 * This method allows you to get access to ANY element/attribute that is a
1758 * sub-element of the opening feed tag.
1760 * The return value is an indexed array of elements matching the given
1761 * namespace and tag name. Each element has `attribs`, `data` and `child`
1762 * subkeys. For `attribs` and `child`, these contain namespace subkeys.
1763 * `attribs` then has one level of associative name => value data (where
1764 * `value` is a string) after the namespace. `child` has tag-indexed keys
1765 * after the namespace, each member of which is an indexed array matching
1770 * // This is probably a bad example because we already support
1771 * // <media:content> natively, but it shows you how to parse through
1773 * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
1774 * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
1775 * $file = $content[0]['attribs']['']['url'];
1780 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1781 * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1782 * @param string $tag Tag name
1785 public function get_feed_tags($namespace, $tag)
1787 $type = $this->get_type();
1788 if ($type & SIMPLEPIE_TYPE_ATOM_10
)
1790 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['child'][$namespace][$tag]))
1792 return $this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['child'][$namespace][$tag];
1795 if ($type & SIMPLEPIE_TYPE_ATOM_03
)
1797 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['child'][$namespace][$tag]))
1799 return $this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['child'][$namespace][$tag];
1802 if ($type & SIMPLEPIE_TYPE_RSS_RDF
)
1804 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][$namespace][$tag]))
1806 return $this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][$namespace][$tag];
1809 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION
)
1811 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][$namespace][$tag]))
1813 return $this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][$namespace][$tag];
1820 * Get data for an channel-level element
1822 * This method allows you to get access to ANY element/attribute in the
1823 * channel/header section of the feed.
1825 * See {@see SimplePie::get_feed_tags()} for a description of the return value
1828 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1829 * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1830 * @param string $tag Tag name
1833 public function get_channel_tags($namespace, $tag)
1835 $type = $this->get_type();
1836 if ($type & SIMPLEPIE_TYPE_ATOM_ALL
)
1838 if ($return = $this->get_feed_tags($namespace, $tag))
1843 if ($type & SIMPLEPIE_TYPE_RSS_10
)
1845 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'channel'))
1847 if (isset($channel[0]['child'][$namespace][$tag]))
1849 return $channel[0]['child'][$namespace][$tag];
1853 if ($type & SIMPLEPIE_TYPE_RSS_090
)
1855 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'channel'))
1857 if (isset($channel[0]['child'][$namespace][$tag]))
1859 return $channel[0]['child'][$namespace][$tag];
1863 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION
)
1865 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'channel'))
1867 if (isset($channel[0]['child'][$namespace][$tag]))
1869 return $channel[0]['child'][$namespace][$tag];
1877 * Get data for an channel-level element
1879 * This method allows you to get access to ANY element/attribute in the
1880 * image/logo section of the feed.
1882 * See {@see SimplePie::get_feed_tags()} for a description of the return value
1885 * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
1886 * @param string $namespace The URL of the XML namespace of the elements you're trying to access
1887 * @param string $tag Tag name
1890 public function get_image_tags($namespace, $tag)
1892 $type = $this->get_type();
1893 if ($type & SIMPLEPIE_TYPE_RSS_10
)
1895 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'image'))
1897 if (isset($image[0]['child'][$namespace][$tag]))
1899 return $image[0]['child'][$namespace][$tag];
1903 if ($type & SIMPLEPIE_TYPE_RSS_090
)
1905 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'image'))
1907 if (isset($image[0]['child'][$namespace][$tag]))
1909 return $image[0]['child'][$namespace][$tag];
1913 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION
)
1915 if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'image'))
1917 if (isset($image[0]['child'][$namespace][$tag]))
1919 return $image[0]['child'][$namespace][$tag];
1927 * Get the base URL value from the feed
1929 * Uses `<xml:base>` if available, otherwise uses the first link in the
1930 * feed, or failing that, the URL of the feed itself.
1933 * @see subscribe_url
1935 * @param array $element
1938 public function get_base($element = array())
1940 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION
) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
1942 return $element['xml_base'];
1944 elseif ($this->get_link() !== null)
1946 return $this->get_link();
1950 return $this->subscribe_url();
1955 * Sanitize feed data
1958 * @see SimplePie_Sanitize::sanitize()
1959 * @param string $data Data to sanitize
1960 * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
1961 * @param string $base Base URL to resolve URLs against
1962 * @return string Sanitized data
1964 public function sanitize($data, $type, $base = '')
1966 return $this->sanitize
->sanitize($data, $type, $base);
1970 * Get the title of the feed
1972 * Uses `<atom:title>`, `<title>` or `<dc:title>`
1974 * @since 1.0 (previously called `get_feed_title` since 0.8)
1975 * @return string|null
1977 public function get_title()
1979 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'title'))
1981 return $this->sanitize($return[0]['data'], $this->registry
->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1983 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'title'))
1985 return $this->sanitize($return[0]['data'], $this->registry
->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
1987 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'title'))
1989 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
1991 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'title'))
1993 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
1995 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'title'))
1997 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
1999 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'title'))
2001 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2003 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'title'))
2005 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2014 * Get a category for the feed
2017 * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
2018 * @return SimplePie_Category|null
2020 public function get_category($key = 0)
2022 $categories = $this->get_categories();
2023 if (isset($categories[$key]))
2025 return $categories[$key];
2034 * Get all categories for the feed
2036 * Uses `<atom:category>`, `<category>` or `<dc:subject>`
2039 * @return array|null List of {@see SimplePie_Category} objects
2041 public function get_categories()
2043 $categories = array();
2045 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'category') as $category)
2050 if (isset($category['attribs']['']['term']))
2052 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT
);
2054 if (isset($category['attribs']['']['scheme']))
2056 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
2058 if (isset($category['attribs']['']['label']))
2060 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
2062 $categories[] = $this->registry
->create('Category', array($term, $scheme, $label));
2064 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'category') as $category)
2066 // This is really the label, but keep this as the term also for BC.
2067 // Label will also work on retrieving because that falls back to term.
2068 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2069 if (isset($category['attribs']['']['domain']))
2071 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT
);
2077 $categories[] = $this->registry
->create('Category', array($term, $scheme, null));
2079 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'subject') as $category)
2081 $categories[] = $this->registry
->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null));
2083 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'subject') as $category)
2085 $categories[] = $this->registry
->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null));
2088 if (!empty($categories))
2090 return array_unique($categories);
2099 * Get an author for the feed
2102 * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
2103 * @return SimplePie_Author|null
2105 public function get_author($key = 0)
2107 $authors = $this->get_authors();
2108 if (isset($authors[$key]))
2110 return $authors[$key];
2119 * Get all authors for the feed
2121 * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
2124 * @return array|null List of {@see SimplePie_Author} objects
2126 public function get_authors()
2129 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'author') as $author)
2134 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data']))
2136 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2138 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['uri'][0]['data']))
2140 $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]));
2142 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data']))
2144 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2146 if ($name !== null || $email !== null || $uri !== null)
2148 $authors[] = $this->registry
->create('Author', array($name, $uri, $email));
2151 if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'author'))
2156 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data']))
2158 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2160 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['url'][0]['data']))
2162 $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]));
2164 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data']))
2166 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2168 if ($name !== null || $email !== null || $url !== null)
2170 $authors[] = $this->registry
->create('Author', array($name, $url, $email));
2173 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'creator') as $author)
2175 $authors[] = $this->registry
->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null));
2177 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'creator') as $author)
2179 $authors[] = $this->registry
->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null));
2181 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'author') as $author)
2183 $authors[] = $this->registry
->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null));
2186 if (!empty($authors))
2188 return array_unique($authors);
2197 * Get a contributor for the feed
2200 * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
2201 * @return SimplePie_Author|null
2203 public function get_contributor($key = 0)
2205 $contributors = $this->get_contributors();
2206 if (isset($contributors[$key]))
2208 return $contributors[$key];
2217 * Get all contributors for the feed
2219 * Uses `<atom:contributor>`
2222 * @return array|null List of {@see SimplePie_Author} objects
2224 public function get_contributors()
2226 $contributors = array();
2227 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'contributor') as $contributor)
2232 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data']))
2234 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2236 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['uri'][0]['data']))
2238 $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]));
2240 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data']))
2242 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2244 if ($name !== null || $email !== null || $uri !== null)
2246 $contributors[] = $this->registry
->create('Author', array($name, $uri, $email));
2249 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'contributor') as $contributor)
2254 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data']))
2256 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2258 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['url'][0]['data']))
2260 $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]));
2262 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data']))
2264 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2266 if ($name !== null || $email !== null || $url !== null)
2268 $contributors[] = $this->registry
->create('Author', array($name, $url, $email));
2272 if (!empty($contributors))
2274 return array_unique($contributors);
2283 * Get a single link for the feed
2285 * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
2286 * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
2287 * @param string $rel The relationship of the link to return
2288 * @return string|null Link URL
2290 public function get_link($key = 0, $rel = 'alternate')
2292 $links = $this->get_links($rel);
2293 if (isset($links[$key]))
2295 return $links[$key];
2304 * Get the permalink for the item
2306 * Returns the first link available with a relationship of "alternate".
2307 * Identical to {@see get_link()} with key 0
2310 * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
2311 * @internal Added for parity between the parent-level and the item/entry-level.
2312 * @return string|null Link URL
2314 public function get_permalink()
2316 return $this->get_link(0);
2320 * Get all links for the feed
2322 * Uses `<atom:link>` or `<link>`
2325 * @param string $rel The relationship of links to return
2326 * @return array|null Links found for the feed (strings)
2328 public function get_links($rel = 'alternate')
2330 if (!isset($this->data
['links']))
2332 $this->data
['links'] = array();
2333 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'link'))
2335 foreach ($links as $link)
2337 if (isset($link['attribs']['']['href']))
2339 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2340 $this->data
['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
2344 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'link'))
2346 foreach ($links as $link)
2348 if (isset($link['attribs']['']['href']))
2350 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2351 $this->data
['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
2356 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'link'))
2358 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
2360 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'link'))
2362 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
2364 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'link'))
2366 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
2369 $keys = array_keys($this->data
['links']);
2370 foreach ($keys as $key)
2372 if ($this->registry
->call('Misc', 'is_isegment_nz_nc', array($key)))
2374 if (isset($this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key]))
2376 $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key] = array_merge($this->data
['links'][$key], $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key]);
2377 $this->data
['links'][$key] =& $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key];
2381 $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key] =& $this->data
['links'][$key];
2384 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
)
2386 $this->data
['links'][substr($key, 41)] =& $this->data
['links'][$key];
2388 $this->data
['links'][$key] = array_unique($this->data
['links'][$key]);
2392 if (isset($this->data
['links'][$rel]))
2394 return $this->data
['links'][$rel];
2402 public function get_all_discovered_feeds()
2404 return $this->all_discovered_feeds
;
2408 * Get the content for the item
2410 * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,
2411 * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>`
2413 * @since 1.0 (previously called `get_feed_description()` since 0.8)
2414 * @return string|null
2416 public function get_description()
2418 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'subtitle'))
2420 return $this->sanitize($return[0]['data'], $this->registry
->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2422 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'tagline'))
2424 return $this->sanitize($return[0]['data'], $this->registry
->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2426 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'description'))
2428 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2430 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'description'))
2432 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2434 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'description'))
2436 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
2438 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'description'))
2440 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2442 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'description'))
2444 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2446 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'summary'))
2448 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
2450 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'subtitle'))
2452 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
2461 * Get the copyright info for the feed
2463 * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>`
2465 * @since 1.0 (previously called `get_feed_copyright()` since 0.8)
2466 * @return string|null
2468 public function get_copyright()
2470 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'rights'))
2472 return $this->sanitize($return[0]['data'], $this->registry
->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2474 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'copyright'))
2476 return $this->sanitize($return[0]['data'], $this->registry
->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
2478 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'copyright'))
2480 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2482 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'rights'))
2484 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2486 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'rights'))
2488 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2497 * Get the language for the feed
2499 * Uses `<language>`, `<dc:language>`, or @xml_lang
2501 * @since 1.0 (previously called `get_feed_language()` since 0.8)
2502 * @return string|null
2504 public function get_language()
2506 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'language'))
2508 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2510 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'language'))
2512 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2514 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'language'))
2516 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2518 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['xml_lang']))
2520 return $this->sanitize($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2522 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['xml_lang']))
2524 return $this->sanitize($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2526 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['xml_lang']))
2528 return $this->sanitize($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2530 elseif (isset($this->data
['headers']['content-language']))
2532 return $this->sanitize($this->data
['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT
);
2541 * Get the latitude coordinates for the item
2543 * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
2545 * Uses `<geo:lat>` or `<georss:point>`
2548 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2549 * @link http://www.georss.org/ GeoRSS
2550 * @return string|null
2552 public function get_latitude()
2555 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'lat'))
2557 return (float) $return[0]['data'];
2559 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))
2561 return (float) $match[1];
2570 * Get the longitude coordinates for the feed
2572 * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
2574 * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
2577 * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
2578 * @link http://www.georss.org/ GeoRSS
2579 * @return string|null
2581 public function get_longitude()
2583 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'long'))
2585 return (float) $return[0]['data'];
2587 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'lon'))
2589 return (float) $return[0]['data'];
2591 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))
2593 return (float) $match[2];
2602 * Get the feed logo's title
2604 * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title.
2606 * Uses `<image><title>` or `<image><dc:title>`
2608 * @return string|null
2610 public function get_image_title()
2612 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'title'))
2614 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2616 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'title'))
2618 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2620 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'title'))
2622 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2624 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'title'))
2626 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2628 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'title'))
2630 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2639 * Get the feed logo's URL
2641 * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to
2642 * have a "feed logo" URL. This points directly to the image itself.
2644 * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
2645 * `<image><title>` or `<image><dc:title>`
2647 * @return string|null
2649 public function get_image_url()
2651 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'image'))
2653 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
);
2655 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'logo'))
2657 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2659 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'icon'))
2661 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2663 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'url'))
2665 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2667 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'url'))
2669 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2671 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'url'))
2673 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2683 * Get the feed logo's link
2685 * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This
2686 * points to a human-readable page that the image should link to.
2688 * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
2689 * `<image><title>` or `<image><dc:title>`
2691 * @return string|null
2693 public function get_image_link()
2695 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'link'))
2697 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2699 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'link'))
2701 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2703 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'link'))
2705 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2714 * Get the feed logo's link
2716 * RSS 2.0 feeds are allowed to have a "feed logo" width.
2718 * Uses `<image><width>` or defaults to 88.0 if no width is specified and
2719 * the feed is an RSS 2.0 feed.
2721 * @return int|float|null
2723 public function get_image_width()
2725 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'width'))
2727 return round($return[0]['data']);
2729 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION
&& $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'url'))
2740 * Get the feed logo's height
2742 * RSS 2.0 feeds are allowed to have a "feed logo" height.
2744 * Uses `<image><height>` or defaults to 31.0 if no height is specified and
2745 * the feed is an RSS 2.0 feed.
2747 * @return int|float|null
2749 public function get_image_height()
2751 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'height'))
2753 return round($return[0]['data']);
2755 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION
&& $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'url'))
2766 * Get the number of items in the feed
2768 * This is well-suited for {@link http://php.net/for for()} loops with
2771 * @param int $max Maximum value to return. 0 for no limit
2772 * @return int Number of items in the feed
2774 public function get_item_quantity($max = 0)
2777 $qty = count($this->get_items());
2784 return ($qty > $max) ? $max : $qty;
2789 * Get a single item from the feed
2791 * This is better suited for {@link http://php.net/for for()} loops, whereas
2792 * {@see get_items()} is better suited for
2793 * {@link http://php.net/foreach foreach()} loops.
2795 * @see get_item_quantity()
2797 * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1
2798 * @return SimplePie_Item|null
2800 public function get_item($key = 0)
2802 $items = $this->get_items();
2803 if (isset($items[$key]))
2805 return $items[$key];
2814 * Get all items from the feed
2816 * This is better suited for {@link http://php.net/for for()} loops, whereas
2817 * {@see get_items()} is better suited for
2818 * {@link http://php.net/foreach foreach()} loops.
2820 * @see get_item_quantity
2822 * @param int $start Index to start at
2823 * @param int $end Number of items to return. 0 for all items after `$start`
2824 * @return array|null List of {@see SimplePie_Item} objects
2826 public function get_items($start = 0, $end = 0)
2828 if (!isset($this->data
['items']))
2830 if (!empty($this->multifeed_objects
))
2832 $this->data
['items'] = SimplePie
::merge_items($this->multifeed_objects
, $start, $end, $this->item_limit
);
2836 $this->data
['items'] = array();
2837 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'entry'))
2839 $keys = array_keys($items);
2840 foreach ($keys as $key)
2842 $this->data
['items'][] = $this->registry
->create('Item', array($this, $items[$key]));
2845 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'entry'))
2847 $keys = array_keys($items);
2848 foreach ($keys as $key)
2850 $this->data
['items'][] = $this->registry
->create('Item', array($this, $items[$key]));
2853 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'item'))
2855 $keys = array_keys($items);
2856 foreach ($keys as $key)
2858 $this->data
['items'][] = $this->registry
->create('Item', array($this, $items[$key]));
2861 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'item'))
2863 $keys = array_keys($items);
2864 foreach ($keys as $key)
2866 $this->data
['items'][] = $this->registry
->create('Item', array($this, $items[$key]));
2869 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'item'))
2871 $keys = array_keys($items);
2872 foreach ($keys as $key)
2874 $this->data
['items'][] = $this->registry
->create('Item', array($this, $items[$key]));
2880 if (!empty($this->data
['items']))
2882 // If we want to order it by date, check if all items have a date, and then sort it
2883 if ($this->order_by_date
&& empty($this->multifeed_objects
))
2885 if (!isset($this->data
['ordered_items']))
2888 foreach ($this->data
['items'] as $item)
2890 if (!$item->get_date('U'))
2897 $this->data
['ordered_items'] = $this->data
['items'];
2900 usort($this->data
['ordered_items'], array(get_class($this), 'sort_items'));
2903 $items = $this->data
['ordered_items'];
2907 $items = $this->data
['items'];
2910 // Slice the data as desired
2913 return array_slice($items, $start);
2917 return array_slice($items, $start, $end);
2927 * Set the favicon handler
2929 * @deprecated Use your own favicon handling instead
2931 public function set_favicon_handler($page = false, $qs = 'i')
2933 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED
: E_USER_WARNING
;
2934 trigger_error('Favicon handling has been removed, please use your own handling', $level);
2939 * Get the favicon for the current feed
2941 * @deprecated Use your own favicon handling instead
2943 public function get_favicon()
2945 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED
: E_USER_WARNING
;
2946 trigger_error('Favicon handling has been removed, please use your own handling', $level);
2948 if (($url = $this->get_link()) !== null)
2950 return 'http://g.etfv.co/' . urlencode($url);
2957 * Magic method handler
2959 * @param string $method Method name
2960 * @param array $args Arguments to the method
2963 public function __call($method, $args)
2965 if (strpos($method, 'subscribe_') === 0)
2967 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED
: E_USER_WARNING
;
2968 trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level);
2971 if ($method === 'enable_xml_dump')
2973 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED
: E_USER_WARNING
;
2974 trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level);
2978 $class = get_class($this);
2979 $trace = debug_backtrace();
2980 $file = $trace[0]['file'];
2981 $line = $trace[0]['line'];
2982 trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);
2986 * Sorting callback for items
2989 * @param SimplePie $a
2990 * @param SimplePie $b
2993 public static function sort_items($a, $b)
2995 return $a->get_date('U') <= $b->get_date('U');
2999 * Merge items from several feeds into one
3001 * If you're merging multiple feeds together, they need to all have dates
3002 * for the items or else SimplePie will refuse to sort them.
3004 * @link http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date#if_feeds_require_separate_per-feed_settings
3005 * @param array $urls List of SimplePie feed objects to merge
3006 * @param int $start Starting item
3007 * @param int $end Number of items to return
3008 * @param int $limit Maximum number of items per feed
3011 public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
3013 if (is_array($urls) && sizeof($urls) > 0)
3016 foreach ($urls as $arg)
3018 if ($arg instanceof SimplePie)
3020 $items = array_merge($items, $arg->get_items(0, $limit));
3024 trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
3029 foreach ($items as $item)
3031 if (!$item->get_date('U'))
3040 usort($items, array(get_class($urls[0]), 'sort_items'));
3045 return array_slice($items, $start);
3049 return array_slice($items, $start, $end);
3054 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);