[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/simplepie/simplepie/library/ -> SimplePie.php (source)

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