5 * A PHP-Based RSS and Atom Feed Framework.
6 * Takes the hard work out of managing a complete RSS/Atom solution.
8 * Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
11 * Redistribution and use in source and binary forms, with or without modification, are
12 * permitted provided that the following conditions are met:
14 * * Redistributions of source code must retain the above copyright notice, this list of
15 * conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright notice, this list
18 * of conditions and the following disclaimer in the documentation and/or other materials
19 * provided with the distribution.
21 * * Neither the name of the SimplePie Team nor the names of its contributors may be used
22 * to endorse or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
26 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
28 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
37 * @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
39 * @author Geoffrey Sneddon
41 * @link http://simplepie.org/ SimplePie
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @todo phpDoc comments
49 define('SIMPLEPIE_NAME', 'SimplePie');
54 define('SIMPLEPIE_VERSION', '1.3-dev');
58 * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
60 define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc
::get_build()));
63 * SimplePie Website URL
65 define('SIMPLEPIE_URL', 'http://simplepie.org');
69 * @see SimplePie::set_useragent()
71 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME
. '/' . SIMPLEPIE_VERSION
. ' (Feed Parser; ' . SIMPLEPIE_URL
. '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD
);
76 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL
. '" title="' . SIMPLEPIE_NAME
. ' ' . SIMPLEPIE_VERSION
. '">' . SIMPLEPIE_NAME
. '</a>');
80 * @see SimplePie::set_autodiscovery_level()
82 define('SIMPLEPIE_LOCATOR_NONE', 0);
85 * Feed Link Element Autodiscovery
86 * @see SimplePie::set_autodiscovery_level()
88 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
91 * Local Feed Extension Autodiscovery
92 * @see SimplePie::set_autodiscovery_level()
94 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
97 * Local Feed Body Autodiscovery
98 * @see SimplePie::set_autodiscovery_level()
100 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
103 * Remote Feed Extension Autodiscovery
104 * @see SimplePie::set_autodiscovery_level()
106 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
109 * Remote Feed Body Autodiscovery
110 * @see SimplePie::set_autodiscovery_level()
112 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
115 * All Feed Autodiscovery
116 * @see SimplePie::set_autodiscovery_level()
118 define('SIMPLEPIE_LOCATOR_ALL', 31);
123 define('SIMPLEPIE_TYPE_NONE', 0);
128 define('SIMPLEPIE_TYPE_RSS_090', 1);
131 * RSS 0.91 (Netscape)
133 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
136 * RSS 0.91 (Userland)
138 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
141 * RSS 0.91 (both Netscape and Userland)
143 define('SIMPLEPIE_TYPE_RSS_091', 6);
148 define('SIMPLEPIE_TYPE_RSS_092', 8);
153 define('SIMPLEPIE_TYPE_RSS_093', 16);
158 define('SIMPLEPIE_TYPE_RSS_094', 32);
163 define('SIMPLEPIE_TYPE_RSS_10', 64);
168 define('SIMPLEPIE_TYPE_RSS_20', 128);
173 define('SIMPLEPIE_TYPE_RSS_RDF', 65);
176 * Non-RDF-based RSS (truly intended as syndication format)
178 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
183 define('SIMPLEPIE_TYPE_RSS_ALL', 255);
188 define('SIMPLEPIE_TYPE_ATOM_03', 256);
193 define('SIMPLEPIE_TYPE_ATOM_10', 512);
198 define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
203 define('SIMPLEPIE_TYPE_ALL', 1023);
208 define('SIMPLEPIE_CONSTRUCT_NONE', 0);
213 define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
218 define('SIMPLEPIE_CONSTRUCT_HTML', 2);
223 define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
226 * base64-encoded construct
228 define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
233 define('SIMPLEPIE_CONSTRUCT_IRI', 16);
236 * A construct that might be HTML
238 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
243 define('SIMPLEPIE_CONSTRUCT_ALL', 63);
248 define('SIMPLEPIE_SAME_CASE', 1);
251 * Change to lowercase
253 define('SIMPLEPIE_LOWERCASE', 2);
256 * Change to uppercase
258 define('SIMPLEPIE_UPPERCASE', 4);
261 * PCRE for HTML attributes
263 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]*');
266 * PCRE for XML attributes
268 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
273 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
278 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
283 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
288 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
293 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
298 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
301 * RSS 1.0 Content Module Namespace
303 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
307 * (Stupid, I know, but I'm certain it will confuse people less with support.)
309 define('SIMPLEPIE_NAMESPACE_RSS_20', '');
314 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
319 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
322 * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
324 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
329 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
332 * Media RSS Namespace
334 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
337 * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
339 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
342 * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
344 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
347 * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
349 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
352 * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
354 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
357 * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
359 define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
362 * iTunes RSS Namespace
364 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
369 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
372 * IANA Link Relations Registry
374 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
377 * Whether we're running on PHP5
379 define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION
, '5.0.0', '>='));
384 define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
389 define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
394 define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
397 * fsockopen() file source
399 define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
404 define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
407 * file_get_contents() file source
409 define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
421 * @var array Raw data
424 public $data = array();
427 * @var mixed Error string
433 * @var object Instance of SimplePie_Sanitize (or other class)
434 * @see SimplePie::set_sanitize_class()
440 * @var string SimplePie Useragent
441 * @see SimplePie::set_useragent()
444 public $useragent = SIMPLEPIE_USERAGENT
;
447 * @var string Feed URL
448 * @see SimplePie::set_feed_url()
454 * @var object Instance of SimplePie_File to use as a feed
455 * @see SimplePie::set_file()
461 * @var string Raw feed data
462 * @see SimplePie::set_raw_data()
468 * @var int Timeout for fetching remote files
469 * @see SimplePie::set_timeout()
472 public $timeout = 10;
475 * @var bool Forces fsockopen() to be used for remote files instead
476 * of cURL, even if a new enough version is installed
477 * @see SimplePie::force_fsockopen()
480 public $force_fsockopen = false;
483 * @var bool Force the given data/URL to be treated as a feed no matter what
485 * @see SimplePie::force_feed()
488 public $force_feed = false;
491 * @var bool Enable/Disable XML dump
492 * @see SimplePie::enable_xml_dump()
495 public $xml_dump = false;
498 * @var bool Enable/Disable Caching
499 * @see SimplePie::enable_cache()
502 public $cache = true;
505 * @var int Cache duration (in seconds)
506 * @see SimplePie::set_cache_duration()
509 public $cache_duration = 3600;
512 * @var int Auto-discovery cache duration (in seconds)
513 * @see SimplePie::set_autodiscovery_cache_duration()
516 public $autodiscovery_cache_duration = 604800; // 7 Days.
519 * @var string Cache location (relative to executing script)
520 * @see SimplePie::set_cache_location()
523 public $cache_location = './cache';
526 * @var string Function that creates the cache filename
527 * @see SimplePie::set_cache_name_function()
530 public $cache_name_function = 'md5';
533 * @var bool Reorder feed by date descending
534 * @see SimplePie::enable_order_by_date()
537 public $order_by_date = true;
540 * @var mixed Force input encoding to be set to the follow value
541 * (false, or anything type-cast to false, disables this feature)
542 * @see SimplePie::set_input_encoding()
545 public $input_encoding = false;
548 * @var int Feed Autodiscovery Level
549 * @see SimplePie::set_autodiscovery_level()
552 public $autodiscovery = SIMPLEPIE_LOCATOR_ALL
;
555 * @var string Class used for caching feeds
556 * @see SimplePie::set_cache_class()
559 public $cache_class = 'SimplePie_Cache';
562 * @var string Class used for locating feeds
563 * @see SimplePie::set_locator_class()
566 public $locator_class = 'SimplePie_Locator';
569 * @var string Class used for parsing feeds
570 * @see SimplePie::set_parser_class()
573 public $parser_class = 'SimplePie_Parser';
576 * @var string Class used for fetching feeds
577 * @see SimplePie::set_file_class()
580 public $file_class = 'SimplePie_File';
583 * @var string Class used for items
584 * @see SimplePie::set_item_class()
587 public $item_class = 'SimplePie_Item';
590 * @var string Class used for authors
591 * @see SimplePie::set_author_class()
594 public $author_class = 'SimplePie_Author';
597 * @var string Class used for categories
598 * @see SimplePie::set_category_class()
601 public $category_class = 'SimplePie_Category';
604 * @var string Class used for enclosures
605 * @see SimplePie::set_enclosures_class()
608 public $enclosure_class = 'SimplePie_Enclosure';
611 * @var string Class used for Media RSS <media:text> captions
612 * @see SimplePie::set_caption_class()
615 public $caption_class = 'SimplePie_Caption';
618 * @var string Class used for Media RSS <media:copyright>
619 * @see SimplePie::set_copyright_class()
622 public $copyright_class = 'SimplePie_Copyright';
625 * @var string Class used for Media RSS <media:credit>
626 * @see SimplePie::set_credit_class()
629 public $credit_class = 'SimplePie_Credit';
632 * @var string Class used for Media RSS <media:rating>
633 * @see SimplePie::set_rating_class()
636 public $rating_class = 'SimplePie_Rating';
639 * @var string Class used for Media RSS <media:restriction>
640 * @see SimplePie::set_restriction_class()
643 public $restriction_class = 'SimplePie_Restriction';
646 * @var string Class used for content-type sniffing
647 * @see SimplePie::set_content_type_sniffer_class()
650 public $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
653 * @var string Class used for item sources.
654 * @see SimplePie::set_source_class()
657 public $source_class = 'SimplePie_Source';
660 * @var int Maximum number of feeds to check with autodiscovery
661 * @see SimplePie::set_max_checked_feeds()
664 public $max_checked_feeds = 10;
667 * @var array All the feeds found during the autodiscovery process
668 * @see SimplePie::get_all_discovered_feeds()
671 public $all_discovered_feeds = array();
674 * @var string Web-accessible path to the handler_image.php file.
675 * @see SimplePie::set_image_handler()
678 public $image_handler = '';
681 * @var array Stores the URLs when multiple feeds are being initialized.
682 * @see SimplePie::set_feed_url()
685 public $multifeed_url = array();
688 * @var array Stores SimplePie objects when multiple feeds initialized.
691 public $multifeed_objects = array();
694 * @var array Stores the get_object_vars() array for use with multifeeds.
695 * @see SimplePie::set_feed_url()
698 public $config_settings = null;
701 * @var integer Stores the number of items to return per-feed with multifeeds.
702 * @see SimplePie::set_item_limit()
705 public $item_limit = 0;
708 * @var array Stores the default attributes to be stripped by strip_attributes().
709 * @see SimplePie::strip_attributes()
712 public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
715 * @var array Stores the default tags to be stripped by strip_htmltags().
716 * @see SimplePie::strip_htmltags()
719 public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
722 * The SimplePie class contains feed level data and options
724 * There are two ways that you can create a new SimplePie object. The first
725 * is by passing a feed URL as a parameter to the SimplePie constructor
726 * (as well as optionally setting the cache location and cache expiry). This
727 * will initialise the whole feed with all of the default settings, and you
728 * can begin accessing methods and properties immediately.
730 * The second way is to create the SimplePie object with no parameters
731 * at all. This will enable you to set configuration options. After setting
732 * them, you must initialise the feed using $feed->init(). At that point the
733 * object's methods and properties will be available to you. This format is
734 * what is used throughout this documentation.
737 * @since 1.0 Preview Release
739 public function __construct()
741 if (version_compare(PHP_VERSION
, '5.0', '<'))
743 trigger_error('PHP 4.x is no longer supported. Please upgrade to PHP 5.2 or newer.');
747 // Other objects, instances created here so we can set options on them
748 $this->sanitize
= new SimplePie_Sanitize();
750 if (func_num_args() > 0)
752 trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.');
757 * Used for converting object to a string
759 public function __toString()
761 return md5(serialize($this->data
));
765 * Remove items that link back to this before destroying this object
767 public function __destruct()
769 if ((version_compare(PHP_VERSION
, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
771 if (!empty($this->data
['items']))
773 foreach ($this->data
['items'] as $item)
777 unset($item, $this->data
['items']);
779 if (!empty($this->data
['ordered_items']))
781 foreach ($this->data
['ordered_items'] as $item)
785 unset($item, $this->data
['ordered_items']);
791 * Force the given data/URL to be treated as a feed no matter what it
796 * @param bool $enable Force the given data/URL to be treated as a feed
798 public function force_feed($enable = false)
800 $this->force_feed
= (bool) $enable;
804 * This is the URL of the feed you want to parse.
806 * This allows you to enter the URL of the feed you want to parse, or the
807 * website you want to try to use auto-discovery on. This takes priority
808 * over any set raw data.
810 * You can set multiple feeds to mash together by passing an array instead
811 * of a string for the $url. Remember that with each additional feed comes
812 * additional processing and resources.
815 * @since 1.0 Preview Release
816 * @param mixed $url This is the URL (or array of URLs) that you want to parse.
817 * @see SimplePie::set_raw_data()
819 public function set_feed_url($url)
823 $this->multifeed_url
= array();
824 foreach ($url as $value)
826 $this->multifeed_url
[] = SimplePie_Misc
::fix_protocol($value, 1);
831 $this->feed_url
= SimplePie_Misc
::fix_protocol($url, 1);
836 * Provides an instance of SimplePie_File to use as a feed
839 * @param object &$file Instance of SimplePie_File (or subclass)
840 * @return bool True on success, false on failure
842 public function set_file(&$file)
844 if (is_a($file, 'SimplePie_File'))
846 $this->feed_url
= $file->url
;
847 $this->file
=& $file;
854 * Allows you to use a string of RSS/Atom data instead of a remote feed.
856 * If you have a feed available as a string in PHP, you can tell SimplePie
857 * to parse that data string instead of a remote feed. Any set feed URL
862 * @param string $data RSS or Atom data as a string.
863 * @see SimplePie::set_feed_url()
865 public function set_raw_data($data)
867 $this->raw_data
= $data;
871 * Allows you to override the default timeout for fetching remote feeds.
873 * This allows you to change the maximum time the feed's server to respond
874 * and send the feed back.
878 * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
880 public function set_timeout($timeout = 10)
882 $this->timeout
= (int) $timeout;
886 * Forces SimplePie to use fsockopen() instead of the preferred cURL
891 * @param bool $enable Force fsockopen() to be used
893 public function force_fsockopen($enable = false)
895 $this->force_fsockopen
= (bool) $enable;
899 * Enables/disables caching in SimplePie.
901 * This option allows you to disable caching all-together in SimplePie.
902 * However, disabling the cache can lead to longer load times.
905 * @since 1.0 Preview Release
906 * @param bool $enable Enable caching
908 public function enable_cache($enable = true)
910 $this->cache
= (bool) $enable;
914 * Set the length of time (in seconds) that the contents of a feed
918 * @param int $seconds The feed content cache duration.
920 public function set_cache_duration($seconds = 3600)
922 $this->cache_duration
= (int) $seconds;
926 * Set the length of time (in seconds) that the autodiscovered feed
927 * URL will be cached.
930 * @param int $seconds The autodiscovered feed URL cache duration.
932 public function set_autodiscovery_cache_duration($seconds = 604800)
934 $this->autodiscovery_cache_duration
= (int) $seconds;
938 * Set the file system location where the cached files should be stored.
941 * @param string $location The file system location.
943 public function set_cache_location($location = './cache')
945 $this->cache_location
= (string) $location;
949 * Determines whether feed items should be sorted into reverse chronological order.
952 * @param bool $enable Sort as reverse chronological order.
954 public function enable_order_by_date($enable = true)
956 $this->order_by_date
= (bool) $enable;
960 * Allows you to override the character encoding reported by the feed.
963 * @param string $encoding Character encoding.
965 public function set_input_encoding($encoding = false)
969 $this->input_encoding
= (string) $encoding;
973 $this->input_encoding
= false;
978 * Set how much feed autodiscovery to do
981 * @see SIMPLEPIE_LOCATOR_NONE
982 * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
983 * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
984 * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
985 * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
986 * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
987 * @see SIMPLEPIE_LOCATOR_ALL
988 * @param int $level Feed Autodiscovery Level (level can be a
989 * combination of the above constants, see bitwise OR operator)
991 public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL
)
993 $this->autodiscovery
= (int) $level;
997 * Allows you to change which class SimplePie uses for caching.
998 * Useful when you are overloading or extending SimplePie's default classes.
1001 * @param string $class Name of custom class.
1002 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1004 public function set_cache_class($class = 'SimplePie_Cache')
1006 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Cache'))
1008 $this->cache_class
= $class;
1015 * Allows you to change which class SimplePie uses for auto-discovery.
1016 * Useful when you are overloading or extending SimplePie's default classes.
1019 * @param string $class Name of custom class.
1020 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1022 public function set_locator_class($class = 'SimplePie_Locator')
1024 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Locator'))
1026 $this->locator_class
= $class;
1033 * Allows you to change which class SimplePie uses for XML parsing.
1034 * Useful when you are overloading or extending SimplePie's default classes.
1037 * @param string $class Name of custom class.
1038 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1040 public function set_parser_class($class = 'SimplePie_Parser')
1042 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Parser'))
1044 $this->parser_class
= $class;
1051 * Allows you to change which class SimplePie uses for remote file fetching.
1052 * Useful when you are overloading or extending SimplePie's default classes.
1055 * @param string $class Name of custom class.
1056 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1058 public function set_file_class($class = 'SimplePie_File')
1060 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_File'))
1062 $this->file_class
= $class;
1069 * Allows you to change which class SimplePie uses for data sanitization.
1070 * Useful when you are overloading or extending SimplePie's default classes.
1073 * @param string $class Name of custom class.
1074 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1076 public function set_sanitize_class($class = 'SimplePie_Sanitize')
1078 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Sanitize'))
1080 $this->sanitize
= new $class();
1087 * Allows you to change which class SimplePie uses for handling feed items.
1088 * Useful when you are overloading or extending SimplePie's default classes.
1091 * @param string $class Name of custom class.
1092 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1094 public function set_item_class($class = 'SimplePie_Item')
1096 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Item'))
1098 $this->item_class
= $class;
1105 * Allows you to change which class SimplePie uses for handling author data.
1106 * Useful when you are overloading or extending SimplePie's default classes.
1109 * @param string $class Name of custom class.
1110 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1112 public function set_author_class($class = 'SimplePie_Author')
1114 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Author'))
1116 $this->author_class
= $class;
1123 * Allows you to change which class SimplePie uses for handling category data.
1124 * Useful when you are overloading or extending SimplePie's default classes.
1127 * @param string $class Name of custom class.
1128 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1130 public function set_category_class($class = 'SimplePie_Category')
1132 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Category'))
1134 $this->category_class
= $class;
1141 * Allows you to change which class SimplePie uses for feed enclosures.
1142 * Useful when you are overloading or extending SimplePie's default classes.
1145 * @param string $class Name of custom class.
1146 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1148 public function set_enclosure_class($class = 'SimplePie_Enclosure')
1150 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Enclosure'))
1152 $this->enclosure_class
= $class;
1159 * Allows you to change which class SimplePie uses for <media:text> captions
1160 * Useful when you are overloading or extending SimplePie's default classes.
1163 * @param string $class Name of custom class.
1164 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1166 public function set_caption_class($class = 'SimplePie_Caption')
1168 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Caption'))
1170 $this->caption_class
= $class;
1177 * Allows you to change which class SimplePie uses for <media:copyright>
1178 * Useful when you are overloading or extending SimplePie's default classes.
1181 * @param string $class Name of custom class.
1182 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1184 public function set_copyright_class($class = 'SimplePie_Copyright')
1186 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Copyright'))
1188 $this->copyright_class
= $class;
1195 * Allows you to change which class SimplePie uses for <media:credit>
1196 * Useful when you are overloading or extending SimplePie's default classes.
1199 * @param string $class Name of custom class.
1200 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1202 public function set_credit_class($class = 'SimplePie_Credit')
1204 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Credit'))
1206 $this->credit_class
= $class;
1213 * Allows you to change which class SimplePie uses for <media:rating>
1214 * Useful when you are overloading or extending SimplePie's default classes.
1217 * @param string $class Name of custom class.
1218 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1220 public function set_rating_class($class = 'SimplePie_Rating')
1222 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Rating'))
1224 $this->rating_class
= $class;
1231 * Allows you to change which class SimplePie uses for <media:restriction>
1232 * Useful when you are overloading or extending SimplePie's default classes.
1235 * @param string $class Name of custom class.
1236 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1238 public function set_restriction_class($class = 'SimplePie_Restriction')
1240 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Restriction'))
1242 $this->restriction_class
= $class;
1249 * Allows you to change which class SimplePie uses for content-type sniffing.
1250 * Useful when you are overloading or extending SimplePie's default classes.
1253 * @param string $class Name of custom class.
1254 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1256 public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
1258 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Content_Type_Sniffer'))
1260 $this->content_type_sniffer_class
= $class;
1267 * Allows you to change which class SimplePie uses item sources.
1268 * Useful when you are overloading or extending SimplePie's default classes.
1271 * @param string $class Name of custom class.
1272 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
1274 public function set_source_class($class = 'SimplePie_Source')
1276 if (SimplePie_Misc
::is_subclass_of($class, 'SimplePie_Source'))
1278 $this->source_class
= $class;
1285 * Allows you to override the default user agent string.
1288 * @param string $ua New user agent string.
1290 public function set_useragent($ua = SIMPLEPIE_USERAGENT
)
1292 $this->useragent
= (string) $ua;
1296 * Set callback function to create cache filename with
1299 * @param mixed $function Callback function
1301 public function set_cache_name_function($function = 'md5')
1303 if (is_callable($function))
1305 $this->cache_name_function
= $function;
1310 * Set options to make SP as fast as possible. Forgoes a
1311 * substantial amount of data sanitization in favor of speed.
1314 * @param bool $set Whether to set them or not
1316 public function set_stupidly_fast($set = false)
1320 $this->enable_order_by_date(false);
1321 $this->remove_div(false);
1322 $this->strip_comments(false);
1323 $this->strip_htmltags(false);
1324 $this->strip_attributes(false);
1325 $this->set_image_handler(false);
1330 * Set maximum number of feeds to check with autodiscovery
1333 * @param int $max Maximum number of feeds to check
1335 public function set_max_checked_feeds($max = 10)
1337 $this->max_checked_feeds
= (int) $max;
1340 public function remove_div($enable = true)
1342 $this->sanitize
->remove_div($enable);
1345 public function strip_htmltags($tags = '', $encode = null)
1349 $tags = $this->strip_htmltags
;
1351 $this->sanitize
->strip_htmltags($tags);
1352 if ($encode !== null)
1354 $this->sanitize
->encode_instead_of_strip($tags);
1358 public function encode_instead_of_strip($enable = true)
1360 $this->sanitize
->encode_instead_of_strip($enable);
1363 public function strip_attributes($attribs = '')
1365 if ($attribs === '')
1367 $attribs = $this->strip_attributes
;
1369 $this->sanitize
->strip_attributes($attribs);
1372 public function set_output_encoding($encoding = 'UTF-8')
1374 $this->sanitize
->set_output_encoding($encoding);
1377 public function strip_comments($strip = false)
1379 $this->sanitize
->strip_comments($strip);
1383 * Set element/attribute key/value pairs of HTML attributes
1384 * containing URLs that need to be resolved relative to the feed
1388 * @param array $element_attribute Element/attribute key/value pairs
1390 public function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
1392 $this->sanitize
->set_url_replacements($element_attribute);
1396 * Set the handler to enable the display of cached images.
1399 * @param str $page Web-accessible path to the handler_image.php file.
1400 * @param str $qs The query string that the value should be passed to.
1402 public function set_image_handler($page = false, $qs = 'i')
1404 if ($page !== false)
1406 $this->sanitize
->set_image_handler($page . '?' . $qs . '=');
1410 $this->image_handler
= '';
1415 * Set the limit for items returned per-feed with multifeeds.
1418 * @param integer $limit The maximum number of items to return.
1420 public function set_item_limit($limit = 0)
1422 $this->item_limit
= (int) $limit;
1425 public function init()
1427 // Check absolute bare minimum requirements.
1428 if ((function_exists('version_compare') && version_compare(PHP_VERSION
, '5.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre'))
1432 // 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.
1433 elseif (!extension_loaded('xmlreader'))
1435 static $xml_is_sane = null;
1436 if ($xml_is_sane === null)
1438 $parser_check = xml_parser_create();
1439 xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
1440 xml_parser_free($parser_check);
1441 $xml_is_sane = isset($values[0]['value']);
1449 // Pass whatever was set with config options over to the sanitizer.
1450 $this->sanitize
->pass_cache_data($this->cache
, $this->cache_location
, $this->cache_name_function
, $this->cache_class
);
1451 $this->sanitize
->pass_file_data($this->file_class
, $this->timeout
, $this->useragent
, $this->force_fsockopen
);
1453 if ($this->feed_url
!== null || $this->raw_data
!== null)
1455 $this->error
= null;
1456 $this->data
= array();
1457 $this->multifeed_objects
= array();
1460 if ($this->feed_url
!== null)
1462 $parsed_feed_url = SimplePie_Misc
::parse_url($this->feed_url
);
1463 // Decide whether to enable caching
1464 if ($this->cache
&& $parsed_feed_url['scheme'] !== '')
1466 $cache = call_user_func(array($this->cache_class
, 'create'), $this->cache_location
, call_user_func($this->cache_name_function
, $this->feed_url
), 'spc');
1468 // If it's enabled and we don't want an XML dump, use the cache
1469 if ($cache && !$this->xml_dump
)
1472 $this->data
= $cache->load();
1473 if (!empty($this->data
))
1475 // If the cache is for an outdated build of SimplePie
1476 if (!isset($this->data
['build']) || $this->data
['build'] !== SIMPLEPIE_BUILD
)
1479 $this->data
= array();
1481 // If we've hit a collision just rerun it with caching disabled
1482 elseif (isset($this->data
['url']) && $this->data
['url'] !== $this->feed_url
)
1485 $this->data
= array();
1487 // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
1488 elseif (isset($this->data
['feed_url']))
1490 // If the autodiscovery cache is still valid use it.
1491 if ($cache->mtime() +
$this->autodiscovery_cache_duration
> time())
1493 // Do not need to do feed autodiscovery yet.
1494 if ($this->data
['feed_url'] === $this->data
['url'])
1497 $this->data
= array();
1501 $this->set_feed_url($this->data
['feed_url']);
1502 return $this->init();
1506 // Check if the cache has been updated
1507 elseif ($cache->mtime() +
$this->cache_duration
< time())
1509 // If we have last-modified and/or etag set
1510 if (isset($this->data
['headers']['last-modified']) || isset($this->data
['headers']['etag']))
1513 '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',
1515 if (isset($this->data
['headers']['last-modified']))
1517 $headers['if-modified-since'] = $this->data
['headers']['last-modified'];
1519 if (isset($this->data
['headers']['etag']))
1521 $headers['if-none-match'] = $this->data
['headers']['etag'];
1524 $file = new $this->file_class($this->feed_url
, $this->timeout
/10, 5, $headers, $this->useragent
, $this->force_fsockopen
);
1528 if ($file->status_code
=== 304)
1535 $headers = $file->headers
;
1544 // If the cache is still valid, just return true
1547 $this->raw_data
= false;
1551 // If the cache is empty, delete it
1555 $this->data
= array();
1558 // 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.
1561 if (is_a($this->file
, 'SimplePie_File') && $this->file
->url
=== $this->feed_url
)
1563 $file =& $this->file
;
1568 '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',
1570 $file = new $this->file_class($this->feed_url
, $this->timeout
, 5, $headers, $this->useragent
, $this->force_fsockopen
);
1573 // If the file connection has an error, set SimplePie::error to that and quit
1574 if (!$file->success
&& !($file->method
& SIMPLEPIE_FILE_SOURCE_REMOTE
=== 0 || ($file->status_code
=== 200 || $file->status_code
> 206 && $file->status_code
< 300)))
1576 $this->error
= $file->error
;
1577 if (!empty($this->data
))
1587 if (!$this->force_feed
)
1589 // Check if the supplied URL is a feed, if it isn't, look for it.
1590 $locate = new $this->locator_class($file, $this->timeout
, $this->useragent
, $this->file_class
, $this->max_checked_feeds
, $this->content_type_sniffer_class
);
1592 if (!$locate->is_feed($file))
1594 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
1596 if ($file = $locate->find($this->autodiscovery
, $this->all_discovered_feeds
))
1600 $this->data
= array('url' => $this->feed_url
, 'feed_url' => $file->url
, 'build' => SIMPLEPIE_BUILD
);
1601 if (!$cache->save($this))
1603 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
);
1605 $cache = call_user_func(array($this->cache_class
, 'create'), $this->cache_location
, call_user_func($this->cache_name_function
, $file->url
), 'spc');
1607 $this->feed_url
= $file->url
;
1611 $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.";
1612 SimplePie_Misc
::error($this->error
, E_USER_NOTICE
, __FILE__
, __LINE__
);
1619 $headers = $file->headers
;
1620 $data = $file->body
;
1621 $sniffer = new $this->content_type_sniffer_class($file);
1622 $sniffed = $sniffer->get_type();
1626 $data = $this->raw_data
;
1629 // This is exposed via get_raw_data()
1630 $this->raw_data
= $data;
1632 // Set up array of possible encodings
1633 $encodings = array();
1635 // First check to see if input has been overridden.
1636 if ($this->input_encoding
!== false)
1638 $encodings[] = $this->input_encoding
;
1641 $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
1642 $text_types = array('text/xml', 'text/xml-external-parsed-entity');
1644 // RFC 3023 (only applies to sniffed content)
1645 if (isset($sniffed))
1647 if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
1649 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1651 $encodings[] = strtoupper($charset[1]);
1653 $encodings = array_merge($encodings, SimplePie_Misc
::xml_encoding($data));
1654 $encodings[] = 'UTF-8';
1656 elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
1658 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
1660 $encodings[] = $charset[1];
1662 $encodings[] = 'US-ASCII';
1664 // Text MIME-type default
1665 elseif (substr($sniffed, 0, 5) === 'text/')
1667 $encodings[] = 'US-ASCII';
1671 // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
1672 $encodings = array_merge($encodings, SimplePie_Misc
::xml_encoding($data));
1673 $encodings[] = 'UTF-8';
1674 $encodings[] = 'ISO-8859-1';
1676 // There's no point in trying an encoding twice
1677 $encodings = array_unique($encodings);
1679 // If we want the XML, just output that with the most likely encoding and quit
1680 if ($this->xml_dump
)
1682 header('Content-type: text/xml; charset=' . $encodings[0]);
1687 // Loop through each possible encoding, till we return something, or run out of possibilities
1688 foreach ($encodings as $encoding)
1690 // Change the encoding to UTF-8 (as we always use UTF-8 internally)
1691 if ($utf8_data = SimplePie_Misc
::change_encoding($data, $encoding, 'UTF-8'))
1693 // Create new parser
1694 $parser = new $this->parser_class();
1696 // If it's parsed fine
1697 if ($parser->parse($utf8_data, 'UTF-8'))
1699 $this->data
= $parser->get_data();
1700 if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE
)
1702 if (isset($headers))
1704 $this->data
['headers'] = $headers;
1706 $this->data
['build'] = SIMPLEPIE_BUILD
;
1708 // Cache the file if caching is enabled
1709 if ($cache && !$cache->save($this))
1711 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
);
1717 $this->error
= "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
1718 SimplePie_Misc
::error($this->error
, E_USER_NOTICE
, __FILE__
, __LINE__
);
1727 // We have an error, just set SimplePie_Misc::error to it and quit
1728 $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());
1732 $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.';
1735 SimplePie_Misc
::error($this->error
, E_USER_NOTICE
, __FILE__
, __LINE__
);
1739 elseif (!empty($this->multifeed_url
))
1743 $this->multifeed_objects
= array();
1744 foreach ($this->multifeed_url
as $url)
1746 $this->multifeed_objects
[$i] = clone $this;
1747 $this->multifeed_objects
[$i]->set_feed_url($url);
1748 $success |= $this->multifeed_objects
[$i]->init();
1751 return (bool) $success;
1760 * Return the error message for the occured error
1763 * @return string Error message
1765 public function error()
1767 return $this->error
;
1771 * Return the raw XML
1773 * This is the same as setting `$xml_dump = true;`, but returns
1774 * the data instead of printing it.
1776 * @return string|boolean Raw XML data, false if the cache is used
1778 public function get_raw_data()
1780 return $this->raw_data
;
1783 public function get_encoding()
1785 return $this->sanitize
->output_encoding
;
1788 public function handle_content_type($mime = 'text/html')
1790 if (!headers_sent())
1792 $header = "Content-type: $mime;";
1793 if ($this->get_encoding())
1795 $header .= ' charset=' . $this->get_encoding();
1799 $header .= ' charset=UTF-8';
1805 public function get_type()
1807 if (!isset($this->data
['type']))
1809 $this->data
['type'] = SIMPLEPIE_TYPE_ALL
;
1810 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed']))
1812 $this->data
['type'] &= SIMPLEPIE_TYPE_ATOM_10
;
1814 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed']))
1816 $this->data
['type'] &= SIMPLEPIE_TYPE_ATOM_03
;
1818 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF']))
1820 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['channel'])
1821 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['image'])
1822 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['item'])
1823 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10
]['textinput']))
1825 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_10
;
1827 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['channel'])
1828 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['image'])
1829 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['item'])
1830 || isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090
]['textinput']))
1832 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_090
;
1835 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss']))
1837 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_ALL
;
1838 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['attribs']['']['version']))
1840 switch (trim($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['attribs']['']['version']))
1843 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_091
;
1844 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['skiphours']['hour'][0]['data']))
1846 switch (trim($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['skiphours']['hour'][0]['data']))
1849 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE
;
1853 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND
;
1860 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_092
;
1864 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_093
;
1868 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_094
;
1872 $this->data
['type'] &= SIMPLEPIE_TYPE_RSS_20
;
1879 $this->data
['type'] = SIMPLEPIE_TYPE_NONE
;
1882 return $this->data
['type'];
1886 * @todo If we have a perm redirect we should return the new URL
1887 * @todo When we make the above change, let's support <itunes:new-feed-url> as well
1888 * @todo Also, |atom:link|@rel=self
1890 public function subscribe_url()
1892 if ($this->feed_url
!== null)
1894 return $this->sanitize($this->feed_url
, SIMPLEPIE_CONSTRUCT_IRI
);
1902 public function get_feed_tags($namespace, $tag)
1904 $type = $this->get_type();
1905 if ($type & SIMPLEPIE_TYPE_ATOM_10
)
1907 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['child'][$namespace][$tag]))
1909 return $this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['child'][$namespace][$tag];
1912 if ($type & SIMPLEPIE_TYPE_ATOM_03
)
1914 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['child'][$namespace][$tag]))
1916 return $this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['child'][$namespace][$tag];
1919 if ($type & SIMPLEPIE_TYPE_RSS_RDF
)
1921 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][$namespace][$tag]))
1923 return $this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['child'][$namespace][$tag];
1926 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION
)
1928 if (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][$namespace][$tag]))
1930 return $this->data
['child'][SIMPLEPIE_NAMESPACE_RSS_20
]['rss'][0]['child'][$namespace][$tag];
1936 public function get_channel_tags($namespace, $tag)
1938 $type = $this->get_type();
1939 if ($type & SIMPLEPIE_TYPE_ATOM_ALL
)
1941 if ($return = $this->get_feed_tags($namespace, $tag))
1946 if ($type & SIMPLEPIE_TYPE_RSS_10
)
1948 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'channel'))
1950 if (isset($channel[0]['child'][$namespace][$tag]))
1952 return $channel[0]['child'][$namespace][$tag];
1956 if ($type & SIMPLEPIE_TYPE_RSS_090
)
1958 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'channel'))
1960 if (isset($channel[0]['child'][$namespace][$tag]))
1962 return $channel[0]['child'][$namespace][$tag];
1966 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION
)
1968 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'channel'))
1970 if (isset($channel[0]['child'][$namespace][$tag]))
1972 return $channel[0]['child'][$namespace][$tag];
1979 public function get_image_tags($namespace, $tag)
1981 $type = $this->get_type();
1982 if ($type & SIMPLEPIE_TYPE_RSS_10
)
1984 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'image'))
1986 if (isset($image[0]['child'][$namespace][$tag]))
1988 return $image[0]['child'][$namespace][$tag];
1992 if ($type & SIMPLEPIE_TYPE_RSS_090
)
1994 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'image'))
1996 if (isset($image[0]['child'][$namespace][$tag]))
1998 return $image[0]['child'][$namespace][$tag];
2002 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION
)
2004 if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'image'))
2006 if (isset($image[0]['child'][$namespace][$tag]))
2008 return $image[0]['child'][$namespace][$tag];
2015 public function get_base($element = array())
2017 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION
) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
2019 return $element['xml_base'];
2021 elseif ($this->get_link() !== null)
2023 return $this->get_link();
2027 return $this->subscribe_url();
2031 public function sanitize($data, $type, $base = '')
2033 return $this->sanitize
->sanitize($data, $type, $base);
2036 public function get_title()
2038 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'title'))
2040 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
2042 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'title'))
2044 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
2046 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'title'))
2048 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2050 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'title'))
2052 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2054 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'title'))
2056 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2058 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'title'))
2060 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2062 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'title'))
2064 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2072 public function get_category($key = 0)
2074 $categories = $this->get_categories();
2075 if (isset($categories[$key]))
2077 return $categories[$key];
2085 public function get_categories()
2087 $categories = array();
2089 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'category') as $category)
2094 if (isset($category['attribs']['']['term']))
2096 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT
);
2098 if (isset($category['attribs']['']['scheme']))
2100 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT
);
2102 if (isset($category['attribs']['']['label']))
2104 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT
);
2106 $categories[] = new $this->category_class($term, $scheme, $label);
2108 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'category') as $category)
2110 // This is really the label, but keep this as the term also for BC.
2111 // Label will also work on retrieving because that falls back to term.
2112 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2113 if (isset($category['attribs']['']['domain']))
2115 $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT
);
2121 $categories[] = new $this->category_class($term, $scheme, null);
2123 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'subject') as $category)
2125 $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
2127 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'subject') as $category)
2129 $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
2132 if (!empty($categories))
2134 return SimplePie_Misc
::array_unique($categories);
2142 public function get_author($key = 0)
2144 $authors = $this->get_authors();
2145 if (isset($authors[$key]))
2147 return $authors[$key];
2155 public function get_authors()
2158 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'author') as $author)
2163 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data']))
2165 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2167 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['uri'][0]['data']))
2169 $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]));
2171 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data']))
2173 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2175 if ($name !== null || $email !== null || $uri !== null)
2177 $authors[] = new $this->author_class($name, $uri, $email);
2180 if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'author'))
2185 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data']))
2187 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2189 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['url'][0]['data']))
2191 $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]));
2193 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data']))
2195 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2197 if ($name !== null || $email !== null || $url !== null)
2199 $authors[] = new $this->author_class($name, $url, $email);
2202 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'creator') as $author)
2204 $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
2206 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'creator') as $author)
2208 $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
2210 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'author') as $author)
2212 $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT
), null, null);
2215 if (!empty($authors))
2217 return SimplePie_Misc
::array_unique($authors);
2225 public function get_contributor($key = 0)
2227 $contributors = $this->get_contributors();
2228 if (isset($contributors[$key]))
2230 return $contributors[$key];
2238 public function get_contributors()
2240 $contributors = array();
2241 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'contributor') as $contributor)
2246 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data']))
2248 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2250 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['uri'][0]['data']))
2252 $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]));
2254 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data']))
2256 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2258 if ($name !== null || $email !== null || $uri !== null)
2260 $contributors[] = new $this->author_class($name, $uri, $email);
2263 foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'contributor') as $contributor)
2268 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data']))
2270 $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2272 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['url'][0]['data']))
2274 $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]));
2276 if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data']))
2278 $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2280 if ($name !== null || $email !== null || $url !== null)
2282 $contributors[] = new $this->author_class($name, $url, $email);
2286 if (!empty($contributors))
2288 return SimplePie_Misc
::array_unique($contributors);
2296 public function get_link($key = 0, $rel = 'alternate')
2298 $links = $this->get_links($rel);
2299 if (isset($links[$key]))
2301 return $links[$key];
2310 * Added for parity between the parent-level and the item/entry-level.
2312 public function get_permalink()
2314 return $this->get_link(0);
2317 public function get_links($rel = 'alternate')
2319 if (!isset($this->data
['links']))
2321 $this->data
['links'] = array();
2322 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'link'))
2324 foreach ($links as $link)
2326 if (isset($link['attribs']['']['href']))
2328 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
2329 $this->data
['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($link));
2333 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, '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));
2345 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'link'))
2347 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
2349 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'link'))
2351 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
2353 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'link'))
2355 $this->data
['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($links[0]));
2358 $keys = array_keys($this->data
['links']);
2359 foreach ($keys as $key)
2361 if (SimplePie_Misc
::is_isegment_nz_nc($key))
2363 if (isset($this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key]))
2365 $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key] = array_merge($this->data
['links'][$key], $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key]);
2366 $this->data
['links'][$key] =& $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key];
2370 $this->data
['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
. $key] =& $this->data
['links'][$key];
2373 elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY
)
2375 $this->data
['links'][substr($key, 41)] =& $this->data
['links'][$key];
2377 $this->data
['links'][$key] = array_unique($this->data
['links'][$key]);
2381 if (isset($this->data
['links'][$rel]))
2383 return $this->data
['links'][$rel];
2391 public function get_all_discovered_feeds()
2393 return $this->all_discovered_feeds
;
2396 public function get_description()
2398 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'subtitle'))
2400 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
2402 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'tagline'))
2404 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
2406 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'description'))
2408 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2410 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'description'))
2412 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML
, $this->get_base($return[0]));
2414 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'description'))
2416 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
2418 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'description'))
2420 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2422 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'description'))
2424 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2426 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'summary'))
2428 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
2430 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'subtitle'))
2432 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML
, $this->get_base($return[0]));
2440 public function get_copyright()
2442 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'rights'))
2444 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
2446 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'copyright'))
2448 return $this->sanitize($return[0]['data'], SimplePie_Misc
::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
2450 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'copyright'))
2452 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2454 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'rights'))
2456 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2458 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'rights'))
2460 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2468 public function get_language()
2470 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'language'))
2472 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2474 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'language'))
2476 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2478 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'language'))
2480 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2482 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['xml_lang']))
2484 return $this->sanitize($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_10
]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2486 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['xml_lang']))
2488 return $this->sanitize($this->data
['child'][SIMPLEPIE_NAMESPACE_ATOM_03
]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2490 elseif (isset($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['xml_lang']))
2492 return $this->sanitize($this->data
['child'][SIMPLEPIE_NAMESPACE_RDF
]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT
);
2494 elseif (isset($this->data
['headers']['content-language']))
2496 return $this->sanitize($this->data
['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT
);
2504 public function get_latitude()
2507 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'lat'))
2509 return (float) $return[0]['data'];
2511 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))
2513 return (float) $match[1];
2521 public function get_longitude()
2523 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'long'))
2525 return (float) $return[0]['data'];
2527 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO
, 'lon'))
2529 return (float) $return[0]['data'];
2531 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))
2533 return (float) $match[2];
2541 public function get_image_title()
2543 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'title'))
2545 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2547 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'title'))
2549 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2551 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'title'))
2553 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2555 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11
, 'title'))
2557 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2559 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10
, 'title'))
2561 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT
);
2569 public function get_image_url()
2571 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES
, 'image'))
2573 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI
);
2575 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'logo'))
2577 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2579 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'icon'))
2581 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2583 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'url'))
2585 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2587 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'url'))
2589 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2591 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'url'))
2593 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2601 public function get_image_link()
2603 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'link'))
2605 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2607 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'link'))
2609 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2611 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'link'))
2613 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI
, $this->get_base($return[0]));
2621 public function get_image_width()
2623 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'width'))
2625 return round($return[0]['data']);
2627 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION
&& $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'url'))
2637 public function get_image_height()
2639 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'height'))
2641 return round($return[0]['data']);
2643 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION
&& $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'url'))
2653 public function get_item_quantity($max = 0)
2656 $qty = count($this->get_items());
2663 return ($qty > $max) ? $max : $qty;
2667 public function get_item($key = 0)
2669 $items = $this->get_items();
2670 if (isset($items[$key]))
2672 return $items[$key];
2680 public function get_items($start = 0, $end = 0)
2682 if (!isset($this->data
['items']))
2684 if (!empty($this->multifeed_objects
))
2686 $this->data
['items'] = SimplePie
::merge_items($this->multifeed_objects
, $start, $end, $this->item_limit
);
2690 $this->data
['items'] = array();
2691 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10
, 'entry'))
2693 $keys = array_keys($items);
2694 foreach ($keys as $key)
2696 $this->data
['items'][] = new $this->item_class($this, $items[$key]);
2699 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03
, 'entry'))
2701 $keys = array_keys($items);
2702 foreach ($keys as $key)
2704 $this->data
['items'][] = new $this->item_class($this, $items[$key]);
2707 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10
, 'item'))
2709 $keys = array_keys($items);
2710 foreach ($keys as $key)
2712 $this->data
['items'][] = new $this->item_class($this, $items[$key]);
2715 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090
, 'item'))
2717 $keys = array_keys($items);
2718 foreach ($keys as $key)
2720 $this->data
['items'][] = new $this->item_class($this, $items[$key]);
2723 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20
, 'item'))
2725 $keys = array_keys($items);
2726 foreach ($keys as $key)
2728 $this->data
['items'][] = new $this->item_class($this, $items[$key]);
2734 if (!empty($this->data
['items']))
2736 // If we want to order it by date, check if all items have a date, and then sort it
2737 if ($this->order_by_date
&& empty($this->multifeed_objects
))
2739 if (!isset($this->data
['ordered_items']))
2742 foreach ($this->data
['items'] as $item)
2744 if (!$item->get_date('U'))
2751 $this->data
['ordered_items'] = $this->data
['items'];
2754 usort($this->data
['ordered_items'], array(&$this, 'sort_items'));
2757 $items = $this->data
['ordered_items'];
2761 $items = $this->data
['items'];
2764 // Slice the data as desired
2767 return array_slice($items, $start);
2771 return array_slice($items, $start, $end);
2783 public function sort_items($a, $b)
2785 return $a->get_date('U') <= $b->get_date('U');
2791 public function merge_items($urls, $start = 0, $end = 0, $limit = 0)
2793 if (is_array($urls) && sizeof($urls) > 0)
2796 foreach ($urls as $arg)
2798 if (is_a($arg, 'SimplePie'))
2800 $items = array_merge($items, $arg->get_items(0, $limit));
2804 trigger_error('Arguments must be SimplePie objects', E_USER_WARNING
);
2809 foreach ($items as $item)
2811 if (!$item->get_date('U'))
2820 usort($items, array('SimplePie', 'sort_items'));
2825 return array_slice($items, $start);
2829 return array_slice($items, $start, $end);
2834 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING
);