SimplePie: PHP-based RSS and Atom feed handling
 
  • Overview
  • Demo
  • Blog
  • Download
  • Documentation
  • API Docs
  • Support
  • Issue Tracker
  • FAQ
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated

Packages

  • SimplePie
    • API
    • Caching
    • HTTP
    • Parsing

Classes

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

Show some love! Wishlists for Geoffrey, Ryan P., and Ryan M.

SimplePie is © 2004–2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue and contributors. Licensed under the BSD License. Hosted thanks to Matt Mullenweg, API documentation generated by ApiGen 2.6.1. Variation on the Feed Icon by Wolfgang Bartelme.