Changeset 4851 for OpenPNE/trunk
- Timestamp:
- Dec 26, 2007, 4:22:30 PM (15 years ago)
- Location:
- OpenPNE/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE/trunk/lib/include/simplepie.inc
r1857 r4851 1 1 <?php 2 /**************************************************** 3 SIMPLEPIE 4 A PHP-Based RSS and Atom Feed Framework 5 Takes the hard work out of managing a complete RSS/Atom solution. 6 7 Version: "Lemon Meringue" 8 Updated: 24 November 2006 9 Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon 10 http://simplepie.org 11 12 ***************************************************** 13 LICENSE: 14 15 GNU Lesser General Public License 2.1 (LGPL) 16 http://creativecommons.org/licenses/LGPL/2.1/ 17 18 ***************************************************** 19 Please submit all bug reports and feature requests to the SimplePie forums. 20 http://simplepie.org/support/ 21 22 ****************************************************/ 23 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-2007, Ryan Parman and Geoffrey Sneddon 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 "Razzleberry" 37 * @copyright 2004-2007 Ryan Parman, Geoffrey Sneddon 38 * @author Ryan Parman 39 * @author Geoffrey Sneddon 40 * @link http://simplepie.org/ SimplePie 41 * @link http://simplepie.org/support/ Please submit all bug reports and feature requests to the SimplePie forums 42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 43 * @todo phpDoc comments 44 */ 45 46 /** 47 * SimplePie Name 48 */ 49 define('SIMPLEPIE_NAME', 'SimplePie'); 50 51 /** 52 * SimplePie Version 53 */ 54 define('SIMPLEPIE_VERSION', '1.0.1'); 55 56 /** 57 * SimplePie Build 58 * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::parse_date() only every load of simplepie.inc) 59 */ 60 define('SIMPLEPIE_BUILD', 20070719221955); 61 62 /** 63 * SimplePie Website URL 64 */ 65 define('SIMPLEPIE_URL', 'http://simplepie.org/'); 66 67 /** 68 * SimplePie Useragent 69 * @see SimplePie::set_useragent() 70 */ 71 define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD); 72 73 /** 74 * SimplePie Linkback 75 */ 76 define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>'); 77 78 /** 79 * No Autodiscovery 80 * @see SimplePie::set_autodiscovery_level() 81 */ 82 define('SIMPLEPIE_LOCATOR_NONE', 0); 83 84 /** 85 * Feed Link Element Autodiscovery 86 * @see SimplePie::set_autodiscovery_level() 87 */ 88 define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1); 89 90 /** 91 * Local Feed Extension Autodiscovery 92 * @see SimplePie::set_autodiscovery_level() 93 */ 94 define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2); 95 96 /** 97 * Local Feed Body Autodiscovery 98 * @see SimplePie::set_autodiscovery_level() 99 */ 100 define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4); 101 102 /** 103 * Remote Feed Extension Autodiscovery 104 * @see SimplePie::set_autodiscovery_level() 105 */ 106 define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8); 107 108 /** 109 * Remote Feed Body Autodiscovery 110 * @see SimplePie::set_autodiscovery_level() 111 */ 112 define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16); 113 114 /** 115 * All Feed Autodiscovery 116 * @see SimplePie::set_autodiscovery_level() 117 */ 118 define('SIMPLEPIE_LOCATOR_ALL', 31); 119 120 /** 121 * No known feed type 122 */ 123 define('SIMPLEPIE_TYPE_NONE', 0); 124 125 /** 126 * RSS 0.90 127 */ 128 define('SIMPLEPIE_TYPE_RSS_090', 1); 129 130 /** 131 * RSS 0.91 (Netscape) 132 */ 133 define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2); 134 135 /** 136 * RSS 0.91 (Userland) 137 */ 138 define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4); 139 140 /** 141 * RSS 0.91 (both Netscape and Userland) 142 */ 143 define('SIMPLEPIE_TYPE_RSS_091', 6); 144 145 /** 146 * RSS 0.92 147 */ 148 define('SIMPLEPIE_TYPE_RSS_092', 8); 149 150 /** 151 * RSS 0.93 152 */ 153 define('SIMPLEPIE_TYPE_RSS_093', 16); 154 155 /** 156 * RSS 0.94 157 */ 158 define('SIMPLEPIE_TYPE_RSS_094', 32); 159 160 /** 161 * RSS 1.0 162 */ 163 define('SIMPLEPIE_TYPE_RSS_10', 64); 164 165 /** 166 * RSS 2.0 167 */ 168 define('SIMPLEPIE_TYPE_RSS_20', 128); 169 170 /** 171 * RDF-based RSS 172 */ 173 define('SIMPLEPIE_TYPE_RSS_RDF', 65); 174 175 /** 176 * Non-RDF-based RSS (truly intended as syndication format) 177 */ 178 define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190); 179 180 /** 181 * All RSS 182 */ 183 define('SIMPLEPIE_TYPE_RSS_ALL', 255); 184 185 /** 186 * Atom 0.3 187 */ 188 define('SIMPLEPIE_TYPE_ATOM_03', 256); 189 190 /** 191 * Atom 1.0 192 */ 193 define('SIMPLEPIE_TYPE_ATOM_10', 512); 194 195 /** 196 * All Atom 197 */ 198 define('SIMPLEPIE_TYPE_ATOM_ALL', 768); 199 200 /** 201 * All feed types 202 */ 203 define('SIMPLEPIE_TYPE_ALL', 1023); 204 205 /** 206 * No construct 207 */ 208 define('SIMPLEPIE_CONSTRUCT_NONE', 0); 209 210 /** 211 * Text construct 212 */ 213 define('SIMPLEPIE_CONSTRUCT_TEXT', 1); 214 215 /** 216 * HTML construct 217 */ 218 define('SIMPLEPIE_CONSTRUCT_HTML', 2); 219 220 /** 221 * XHTML construct 222 */ 223 define('SIMPLEPIE_CONSTRUCT_XHTML', 4); 224 225 /** 226 * base64-encoded construct 227 */ 228 define('SIMPLEPIE_CONSTRUCT_BASE64', 8); 229 230 /** 231 * IRI construct 232 */ 233 define('SIMPLEPIE_CONSTRUCT_IRI', 16); 234 235 /** 236 * A construct that might be HTML 237 */ 238 define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32); 239 240 /** 241 * All constructs 242 */ 243 define('SIMPLEPIE_CONSTRUCT_ALL', 63); 244 245 /** 246 * PCRE for HTML attributes 247 */ 248 define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[a-z0-9\-._:]*)))?)*)\s*'); 249 250 /** 251 * PCRE for XML attributes 252 */ 253 define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*'); 254 255 /** 256 * XML Namespace 257 */ 258 define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace'); 259 260 /** 261 * Atom 1.0 Namespace 262 */ 263 define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom'); 264 265 /** 266 * Atom 0.3 Namespace 267 */ 268 define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#'); 269 270 /** 271 * RDF Namespace 272 */ 273 define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); 274 275 /** 276 * RSS 0.90 Namespace 277 */ 278 define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/'); 279 280 /** 281 * RSS 1.0 Namespace 282 */ 283 define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/'); 284 285 /** 286 * RSS 1.0 Content Module Namespace 287 */ 288 define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/'); 289 290 /** 291 * DC 1.0 Namespace 292 */ 293 define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/'); 294 295 /** 296 * DC 1.1 Namespace 297 */ 298 define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/'); 299 300 /** 301 * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace 302 */ 303 define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#'); 304 305 /** 306 * GeoRSS Namespace 307 */ 308 define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss'); 309 310 /** 311 * Media RSS Namespace 312 */ 313 define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/'); 314 315 /** 316 * iTunes RSS Namespace 317 */ 318 define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd'); 319 320 /** 321 * XHTML Namespace 322 */ 323 define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml'); 324 325 /** 326 * IANA Link Relations Registry 327 */ 328 define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/'); 329 330 /** 331 * Whether we're running on PHP5 332 */ 333 define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>=')); 334 335 /** 336 * SimplePie 337 * 338 * @package SimplePie 339 * @version "Razzleberry" 340 * @copyright 2004-2007 Ryan Parman, Geoffrey Sneddon 341 * @author Ryan Parman 342 * @author Geoffrey Sneddon 343 * @todo Option for type of fetching (cache, not modified header, fetch, etc.) 344 */ 24 345 class SimplePie 25 346 { 26 // SimplePie Info 27 var $name = 'SimplePie'; 28 var $version = '1.0 b3.2'; 29 var $build = '20061124'; 30 var $url = 'http://simplepie.org/'; 31 var $useragent; 32 var $linkback; 33 34 // Other objects, instances created here so we can set options on them 347 /** 348 * @var array Raw data 349 * @access private 350 */ 351 var $data = array(); 352 353 /** 354 * @var mixed Error string 355 * @access private 356 */ 357 var $error; 358 359 /** 360 * @var object Instance of SimplePie_Sanitize (or other class) 361 * @see SimplePie::set_sanitize_class() 362 * @access private 363 */ 35 364 var $sanitize; 36 37 // Options 38 var $rss_url; 365 366 /** 367 * @var string SimplePie Useragent 368 * @see SimplePie::set_useragent() 369 * @access private 370 */ 371 var $useragent = SIMPLEPIE_USERAGENT; 372 373 /** 374 * @var string Feed URL 375 * @see SimplePie::set_feed_url() 376 * @access private 377 */ 378 var $feed_url; 379 380 /** 381 * @var object Instance of SimplePie_File to use as a feed 382 * @see SimplePie::set_file() 383 * @access private 384 */ 39 385 var $file; 386 387 /** 388 * @var string Raw feed data 389 * @see SimplePie::set_raw_data() 390 * @access private 391 */ 392 var $raw_data; 393 394 /** 395 * @var int Timeout for fetching remote files 396 * @see SimplePie::set_timeout() 397 * @access private 398 */ 40 399 var $timeout = 10; 400 401 /** 402 * @var bool Forces fsockopen() to be used for remote files instead 403 * of cURL, even if a new enough version is installed 404 * @see SimplePie::force_fsockopen() 405 * @access private 406 */ 407 var $force_fsockopen = false; 408 409 /** 410 * @var bool Enable/Disable XML dump 411 * @see SimplePie::enable_xml_dump() 412 * @access private 413 */ 41 414 var $xml_dump = false; 42 var $enable_cache = true; 43 var $max_minutes = 60; 415 416 /** 417 * @var bool Enable/Disable Caching 418 * @see SimplePie::enable_cache() 419 * @access private 420 */ 421 var $cache = true; 422 423 /** 424 * @var int Cache duration (in seconds) 425 * @see SimplePie::set_cache_duration() 426 * @access private 427 */ 428 var $cache_duration = 3600; 429 430 /** 431 * @var int Auto-discovery cache duration (in seconds) 432 * @see SimplePie::set_autodiscovery_cache_duration() 433 * @access private 434 */ 435 var $autodiscovery_cache_duration = 604800; // 7 Days. 436 437 /** 438 * @var string Cache location (relative to executing script) 439 * @see SimplePie::set_cache_location() 440 * @access private 441 */ 44 442 var $cache_location = './cache'; 443 444 /** 445 * @var string Function that creates the cache filename 446 * @see SimplePie::set_cache_name_function() 447 * @access private 448 */ 449 var $cache_name_function = 'md5'; 450 451 /** 452 * @var bool Reorder feed by date descending 453 * @see SimplePie::enable_order_by_date() 454 * @access private 455 */ 45 456 var $order_by_date = true; 457 458 /** 459 * @var mixed Force input encoding to be set to the follow value 460 * (false, or anything type-cast to false, disables this feature) 461 * @see SimplePie::set_input_encoding() 462 * @access private 463 */ 46 464 var $input_encoding = false; 465 466 /** 467 * @var int Feed Autodiscovery Level 468 * @see SimplePie::set_autodiscovery_level() 469 * @access private 470 */ 471 var $autodiscovery = SIMPLEPIE_LOCATOR_ALL; 472 473 /** 474 * @var string Class used for caching feeds 475 * @see SimplePie::set_cache_class() 476 * @access private 477 */ 47 478 var $cache_class = 'SimplePie_Cache'; 479 480 /** 481 * @var string Class used for locating feeds 482 * @see SimplePie::set_locator_class() 483 * @access private 484 */ 48 485 var $locator_class = 'SimplePie_Locator'; 486 487 /** 488 * @var string Class used for parsing feeds 489 * @see SimplePie::set_parser_class() 490 * @access private 491 */ 49 492 var $parser_class = 'SimplePie_Parser'; 493 494 /** 495 * @var string Class used for fetching feeds 496 * @see SimplePie::set_file_class() 497 * @access private 498 */ 50 499 var $file_class = 'SimplePie_File'; 51 var $force_fsockopen = false; 52 var $cache_name_type = 'sha1'; 53 54 // Misc. variables 55 var $data; 56 var $error; 57 58 function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null) 59 { 60 // Couple of variables built up from other variables 61 $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build; 62 $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>'; 63 500 501 /** 502 * @var string Class used for items 503 * @see SimplePie::set_item_class() 504 * @access private 505 */ 506 var $item_class = 'SimplePie_Item'; 507 508 /** 509 * @var string Class used for authors 510 * @see SimplePie::set_author_class() 511 * @access private 512 */ 513 var $author_class = 'SimplePie_Author'; 514 515 /** 516 * @var string Class used for categories 517 * @see SimplePie::set_category_class() 518 * @access private 519 */ 520 var $category_class = 'SimplePie_Category'; 521 522 /** 523 * @var string Class used for enclosures 524 * @see SimplePie::set_enclosures_class() 525 * @access private 526 */ 527 var $enclosure_class = 'SimplePie_Enclosure'; 528 529 /** 530 * @var string Class used for Media RSS <media:text> captions 531 * @see SimplePie::set_caption_class() 532 * @access private 533 */ 534 var $caption_class = 'SimplePie_Caption'; 535 536 /** 537 * @var string Class used for Media RSS <media:copyright> 538 * @see SimplePie::set_copyright_class() 539 * @access private 540 */ 541 var $copyright_class = 'SimplePie_Copyright'; 542 543 /** 544 * @var string Class used for Media RSS <media:credit> 545 * @see SimplePie::set_credit_class() 546 * @access private 547 */ 548 var $credit_class = 'SimplePie_Credit'; 549 550 /** 551 * @var string Class used for Media RSS <media:rating> 552 * @see SimplePie::set_rating_class() 553 * @access private 554 */ 555 var $rating_class = 'SimplePie_Rating'; 556 557 /** 558 * @var string Class used for Media RSS <media:restriction> 559 * @see SimplePie::set_restriction_class() 560 * @access private 561 */ 562 var $restriction_class = 'SimplePie_Restriction'; 563 564 /** 565 * @var mixed Set javascript query string parameter (false, or 566 * anything type-cast to false, disables this feature) 567 * @see SimplePie::set_javascript() 568 * @access private 569 */ 570 var $javascript = 'js'; 571 572 /** 573 * @var int Maximum number of feeds to check with autodiscovery 574 * @see SimplePie::set_max_checked_feeds() 575 * @access private 576 */ 577 var $max_checked_feeds = 10; 578 579 /** 580 * @var string Web-accessible path to the handler_favicon.php file. 581 * @see SimplePie::set_favicon_handler() 582 * @access private 583 */ 584 var $favicon_handler = ''; 585 586 /** 587 * @var string Web-accessible path to the handler_image.php file. 588 * @see SimplePie::set_image_handler() 589 * @access private 590 */ 591 var $image_handler = ''; 592 593 /** 594 * @var array Stores the URLs when multiple feeds are being initialized. 595 * @see SimplePie::set_feed_url() 596 * @access private 597 */ 598 var $multifeed_url = array(); 599 600 /** 601 * @var array Stores SimplePie objects when multiple feeds initialized. 602 * @access private 603 */ 604 var $multifeed_objects = array(); 605 606 /** 607 * @var array Stores the get_object_vars() array for use with multifeeds. 608 * @see SimplePie::set_feed_url() 609 * @access private 610 */ 611 var $config_settings = null; 612 613 /** 614 * @var array Stores the default attributes to be stripped by strip_attributes(). 615 * @see SimplePie::strip_attributes() 616 * @access private 617 */ 618 var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); 619 620 /** 621 * @var array Stores the default tags to be stripped by strip_htmltags(). 622 * @see SimplePie::strip_htmltags() 623 * @access private 624 */ 625 var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); 626 627 /** 628 * The SimplePie class contains feed level data and options 629 * 630 * There are two ways that you can create a new SimplePie object. The first 631 * is by passing a feed URL as a parameter to the SimplePie constructor 632 * (as well as optionally setting the cache location and cache expiry). This 633 * will initialise the whole feed with all of the default settings, and you 634 * can begin accessing methods and properties immediately. 635 * 636 * The second way is to create the SimplePie object with no parameters 637 * at all. This will enable you to set configuration options. After setting 638 * them, you must initialise the feed using $feed->init(). At that point the 639 * object's methods and properties will be available to you. This format is 640 * what is used throughout this documentation. 641 * 642 * @access public 643 * @since 1.0 Preview Release 644 * @param string $feed_url This is the URL you want to parse. 645 * @param string $cache_location This is where you want the cache to be stored. 646 * @param int $cache_duration This is the number of seconds that you want to store the cache file for. 647 */ 648 function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null) 649 { 64 650 // Other objects, instances created here so we can set options on them 65 $this->sanitize = new SimplePie_Sanitize;66 651 $this->sanitize =& new SimplePie_Sanitize; 652 67 653 // Set options if they're passed to the constructor 68 if (!is_null($feed_url)) 69 { 70 $this->feed_url($feed_url); 71 } 72 73 if (!is_null($cache_location)) 74 { 75 $this->cache_location($cache_location); 76 } 77 78 if (!is_null($cache_max_minutes)) 79 { 80 $this->cache_max_minutes($cache_max_minutes); 81 } 82 83 // If we've passed an xmldump variable in the URL, snap into XMLdump mode 84 if (isset($_GET['xmldump'])) 85 { 86 $this->enable_xmldump(true); 87 } 88 654 if ($cache_location !== null) 655 { 656 $this->set_cache_location($cache_location); 657 } 658 659 if ($cache_duration !== null) 660 { 661 $this->set_cache_duration($cache_duration); 662 } 663 89 664 // Only init the script if we're passed a feed URL 90 if (!is_null($feed_url)) 91 { 92 return $this->init(); 93 } 94 } 95 96 function feed_url($url) 97 { 98 $this->rss_url = SimplePie_Misc::fix_protocol($url, 1); 99 } 100 665 if ($feed_url !== null) 666 { 667 $this->set_feed_url($feed_url); 668 $this->init(); 669 } 670 } 671 672 /** 673 * Used for converting object to a string 674 */ 675 function __toString() 676 { 677 return md5(serialize($this->data)); 678 } 679 680 /** 681 * This is the URL of the feed you want to parse. 682 * 683 * This allows you to enter the URL of the feed you want to parse, or the 684 * website you want to try to use auto-discovery on. This takes priority 685 * over any set raw data. 686 * 687 * You can set multiple feeds to mash together by passing an array instead 688 * of a string for the $url. Remember that with each additional feed comes 689 * additional processing and resources. 690 * 691 * @access public 692 * @since 1.0 Preview Release 693 * @param mixed $url This is the URL (or array of URLs) that you want to parse. 694 * @see SimplePie::set_raw_data() 695 */ 696 function set_feed_url($url) 697 { 698 if (is_array($url)) 699 { 700 $this->multifeed_url = array(); 701 foreach ($url as $value) 702 { 703 $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1); 704 } 705 } 706 else 707 { 708 $this->feed_url = SimplePie_Misc::fix_protocol($url, 1); 709 } 710 } 711 712 /** 713 * Provides an instance of SimplePie_File to use as a feed 714 * 715 * @access public 716 * @param object &$file Instance of SimplePie_File (or subclass) 717 * @return bool True on success, false on failure 718 */ 101 719 function set_file(&$file) 102 720 { 103 if ( is_a($file, 'SimplePie_File'))104 { 105 $this-> rss_url = $file->url;721 if (SimplePie_Misc::is_a($file, 'SimplePie_File')) 722 { 723 $this->feed_url = $file->url; 106 724 $this->file =& $file; 107 } 108 } 109 725 return true; 726 } 727 return false; 728 } 729 730 /** 731 * Allows you to use a string of RSS/Atom data instead of a remote feed. 732 * 733 * If you have a feed available as a string in PHP, you can tell SimplePie 734 * to parse that data string instead of a remote feed. Any set feed URL 735 * takes precedence. 736 * 737 * @access public 738 * @since 1.0 Beta 3 739 * @param string $data RSS or Atom data as a string. 740 * @see SimplePie::set_feed_url() 741 */ 742 function set_raw_data($data) 743 { 744 $this->raw_data = trim($data); 745 } 746 747 /** 748 * Allows you to override the default timeout for fetching remote feeds. 749 * 750 * This allows you to change the maximum time the feed's server to respond 751 * and send the feed back. 752 * 753 * @access public 754 * @since 1.0 Beta 3 755 * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed. 756 */ 110 757 function set_timeout($timeout = 10) 111 758 { 112 759 $this->timeout = (int) $timeout; 113 760 } 114 115 function set_raw_data($data) 116 { 117 $this->raw_data = trim((string) $data); 118 } 119 120 function enable_xmldump($enable = false) 761 762 /** 763 * Forces SimplePie to use fsockopen() instead of the preferred cURL 764 * functions. 765 * 766 * @access public 767 * @since 1.0 Beta 3 768 * @param bool $enable Force fsockopen() to be used 769 */ 770 function force_fsockopen($enable = false) 771 { 772 $this->force_fsockopen = (bool) $enable; 773 } 774 775 /** 776 * Outputs the raw XML content of the feed, after it has gone through 777 * SimplePie's filters. 778 * 779 * Used only for debugging, this function will output the XML content as 780 * text/xml. When SimplePie reads in a feed, it does a bit of cleaning up 781 * before trying to parse it. Many parts of the feed are re-written in 782 * memory, and in the end, you have a parsable feed. XML dump shows you the 783 * actual XML that SimplePie tries to parse, which may or may not be very 784 * different from the original feed. 785 * 786 * @access public 787 * @since 1.0 Preview Release 788 * @param bool $enable Enable XML dump 789 */ 790 function enable_xml_dump($enable = false) 121 791 { 122 792 $this->xml_dump = (bool) $enable; 123 793 } 124 125 function enable_caching($enable = true) 126 { 127 $this->enable_cache = (bool) $enable; 128 } 129 130 function cache_max_minutes($minutes = 60) 131 { 132 $this->max_minutes = (float) $minutes; 133 } 134 135 function cache_location($location = './cache') 794 795 /** 796 * Enables/disables caching in SimplePie. 797 * 798 * This option allows you to disable caching all-together in SimplePie. 799 * However, disabling the cache can lead to longer load times. 800 * 801 * @access public 802 * @since 1.0 Preview Release 803 * @param bool $enable Enable caching 804 */ 805 function enable_cache($enable = true) 806 { 807 $this->cache = (bool) $enable; 808 } 809 810 /** 811 * Set the length of time (in seconds) that the contents of a feed 812 * will be cached. 813 * 814 * @access public 815 * @param int $seconds The feed content cache duration. 816 */ 817 function set_cache_duration($seconds = 3600) 818 { 819 $this->cache_duration = (int) $seconds; 820 } 821 822 /** 823 * Set the length of time (in seconds) that the autodiscovered feed 824 * URL will be cached. 825 * 826 * @access public 827 * @param int $seconds The autodiscovered feed URL cache duration. 828 */ 829 function set_autodiscovery_cache_duration($seconds = 604800) 830 { 831 $this->autodiscovery_cache_duration = (int) $seconds; 832 } 833 834 /** 835 * Set the file system location where the cached files should be stored. 836 * 837 * @access public 838 * @param string $location The file system location. 839 */ 840 function set_cache_location($location = './cache') 136 841 { 137 842 $this->cache_location = (string) $location; 138 843 } 139 140 function order_by_date($enable = true) 844 845 /** 846 * Determines whether feed items should be sorted into reverse chronological order. 847 * 848 * @access public 849 * @param bool $enable Sort as reverse chronological order. 850 */ 851 function enable_order_by_date($enable = true) 141 852 { 142 853 $this->order_by_date = (bool) $enable; 143 854 } 144 145 function input_encoding($encoding = false) 855 856 /** 857 * Allows you to override the character encoding reported by the feed. 858 * 859 * @access public 860 * @param string $encoding Character encoding. 861 */ 862 function set_input_encoding($encoding = false) 146 863 { 147 864 if ($encoding) … … 154 871 } 155 872 } 156 873 874 /** 875 * Set how much feed autodiscovery to do 876 * 877 * @access public 878 * @see SIMPLEPIE_LOCATOR_NONE 879 * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY 880 * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION 881 * @see SIMPLEPIE_LOCATOR_LOCAL_BODY 882 * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION 883 * @see SIMPLEPIE_LOCATOR_REMOTE_BODY 884 * @see SIMPLEPIE_LOCATOR_ALL 885 * @param int $level Feed Autodiscovery Level (level can be a 886 * combination of the above constants, see bitwise OR operator) 887 */ 888 function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL) 889 { 890 $this->autodiscovery = (int) $level; 891 } 892 893 /** 894 * Allows you to change which class SimplePie uses for caching. 895 * Useful when you are overloading or extending SimplePie's default classes. 896 * 897 * @access public 898 * @param string $class Name of custom class. 899 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 900 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 901 */ 157 902 function set_cache_class($class = 'SimplePie_Cache') 158 903 { 159 if (SimplePie_Misc::is_ a_class($class, 'SimplePie_Cache'))904 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Cache')) 160 905 { 161 906 $this->cache_class = $class; … … 164 909 return false; 165 910 } 166 911 912 /** 913 * Allows you to change which class SimplePie uses for auto-discovery. 914 * Useful when you are overloading or extending SimplePie's default classes. 915 * 916 * @access public 917 * @param string $class Name of custom class. 918 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 919 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 920 */ 167 921 function set_locator_class($class = 'SimplePie_Locator') 168 922 { 169 if (SimplePie_Misc::is_ a_class($class, 'SimplePie_Locator'))923 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Locator')) 170 924 { 171 925 $this->locator_class = $class; … … 174 928 return false; 175 929 } 176 930 931 /** 932 * Allows you to change which class SimplePie uses for XML parsing. 933 * Useful when you are overloading or extending SimplePie's default classes. 934 * 935 * @access public 936 * @param string $class Name of custom class. 937 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 938 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 939 */ 177 940 function set_parser_class($class = 'SimplePie_Parser') 178 941 { 179 if (SimplePie_Misc::is_ a_class($class, 'SimplePie_Parser'))942 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Parser')) 180 943 { 181 944 $this->parser_class = $class; … … 184 947 return false; 185 948 } 186 949 950 /** 951 * Allows you to change which class SimplePie uses for remote file fetching. 952 * Useful when you are overloading or extending SimplePie's default classes. 953 * 954 * @access public 955 * @param string $class Name of custom class. 956 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 957 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 958 */ 187 959 function set_file_class($class = 'SimplePie_File') 188 960 { 189 if (SimplePie_Misc::is_ a_class($class, 'SimplePie_File'))961 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_File')) 190 962 { 191 963 $this->file_class = $class; … … 194 966 return false; 195 967 } 196 197 function set_sanitize_class($object = 'SimplePie_Sanitize') 198 { 199 if (class_exists($object)) 200 { 201 $this->sanitize = new $object; 968 969 /** 970 * Allows you to change which class SimplePie uses for data sanitization. 971 * Useful when you are overloading or extending SimplePie's default classes. 972 * 973 * @access public 974 * @param string $class Name of custom class. 975 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 976 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 977 */ 978 function set_sanitize_class($class = 'SimplePie_Sanitize') 979 { 980 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Sanitize')) 981 { 982 $this->sanitize =& new $class; 202 983 return true; 203 984 } 204 985 return false; 205 986 } 206 207 function set_useragent($ua) 987 988 /** 989 * Allows you to change which class SimplePie uses for handling feed items. 990 * Useful when you are overloading or extending SimplePie's default classes. 991 * 992 * @access public 993 * @param string $class Name of custom class. 994 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 995 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 996 */ 997 function set_item_class($class = 'SimplePie_Item') 998 { 999 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Item')) 1000 { 1001 $this->item_class = $class; 1002 return true; 1003 } 1004 return false; 1005 } 1006 1007 /** 1008 * Allows you to change which class SimplePie uses for handling author data. 1009 * Useful when you are overloading or extending SimplePie's default classes. 1010 * 1011 * @access public 1012 * @param string $class Name of custom class. 1013 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1014 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1015 */ 1016 function set_author_class($class = 'SimplePie_Author') 1017 { 1018 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Author')) 1019 { 1020 $this->author_class = $class; 1021 return true; 1022 } 1023 return false; 1024 } 1025 1026 /** 1027 * Allows you to change which class SimplePie uses for handling category data. 1028 * Useful when you are overloading or extending SimplePie's default classes. 1029 * 1030 * @access public 1031 * @param string $class Name of custom class. 1032 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1033 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1034 */ 1035 function set_category_class($class = 'SimplePie_Category') 1036 { 1037 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Category')) 1038 { 1039 $this->category_class = $class; 1040 return true; 1041 } 1042 return false; 1043 } 1044 1045 /** 1046 * Allows you to change which class SimplePie uses for feed enclosures. 1047 * Useful when you are overloading or extending SimplePie's default classes. 1048 * 1049 * @access public 1050 * @param string $class Name of custom class. 1051 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1052 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1053 */ 1054 function set_enclosure_class($class = 'SimplePie_Enclosure') 1055 { 1056 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Enclosure')) 1057 { 1058 $this->enclosure_class = $class; 1059 return true; 1060 } 1061 return false; 1062 } 1063 1064 /** 1065 * Allows you to change which class SimplePie uses for <media:text> captions 1066 * Useful when you are overloading or extending SimplePie's default classes. 1067 * 1068 * @access public 1069 * @param string $class Name of custom class. 1070 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1071 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1072 */ 1073 function set_caption_class($class = 'SimplePie_Caption') 1074 { 1075 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Caption')) 1076 { 1077 $this->caption_class = $class; 1078 return true; 1079 } 1080 return false; 1081 } 1082 1083 /** 1084 * Allows you to change which class SimplePie uses for <media:copyright> 1085 * Useful when you are overloading or extending SimplePie's default classes. 1086 * 1087 * @access public 1088 * @param string $class Name of custom class. 1089 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1090 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1091 */ 1092 function set_copyright_class($class = 'SimplePie_Copyright') 1093 { 1094 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Copyright')) 1095 { 1096 $this->copyright_class = $class; 1097 return true; 1098 } 1099 return false; 1100 } 1101 1102 /** 1103 * Allows you to change which class SimplePie uses for <media:credit> 1104 * Useful when you are overloading or extending SimplePie's default classes. 1105 * 1106 * @access public 1107 * @param string $class Name of custom class. 1108 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1109 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1110 */ 1111 function set_credit_class($class = 'SimplePie_Credit') 1112 { 1113 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Credit')) 1114 { 1115 $this->credit_class = $class; 1116 return true; 1117 } 1118 return false; 1119 } 1120 1121 /** 1122 * Allows you to change which class SimplePie uses for <media:rating> 1123 * Useful when you are overloading or extending SimplePie's default classes. 1124 * 1125 * @access public 1126 * @param string $class Name of custom class. 1127 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1128 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1129 */ 1130 function set_rating_class($class = 'SimplePie_Rating') 1131 { 1132 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Rating')) 1133 { 1134 $this->rating_class = $class; 1135 return true; 1136 } 1137 return false; 1138 } 1139 1140 /** 1141 * Allows you to change which class SimplePie uses for <media:restriction> 1142 * Useful when you are overloading or extending SimplePie's default classes. 1143 * 1144 * @access public 1145 * @param string $class Name of custom class. 1146 * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation 1147 * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 1148 */ 1149 function set_restriction_class($class = 'SimplePie_Restriction') 1150 { 1151 if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Restriction')) 1152 { 1153 $this->restriction_class = $class; 1154 return true; 1155 } 1156 return false; 1157 } 1158 1159 /** 1160 * Allows you to override the default user agent string. 1161 * 1162 * @access public 1163 * @param string $ua New user agent string. 1164 */ 1165 function set_useragent($ua = SIMPLEPIE_USERAGENT) 208 1166 { 209 1167 $this->useragent = (string) $ua; 210 1168 } 211 212 function force_fsockopen($enable = false) 213 { 214 $this->force_fsockopen = (bool) $enable; 215 } 216 217 function set_cache_name_type($type = 'sha1') 218 { 219 $type = strtolower(trim($type)); 220 switch ($type) 221 { 222 case 'crc32': 223 $this->cache_name_type = 'crc32'; 224 break; 225 226 case 'md5': 227 $this->cache_name_type = 'md5'; 228 break; 229 230 case 'rawurlencode': 231 $this->cache_name_type = 'rawurlencode'; 232 break; 233 234 case 'urlencode': 235 $this->cache_name_type = 'urlencode'; 236 break; 237 238 default: 239 $this->cache_name_type = 'sha1'; 240 break; 241 } 242 } 243 244 function bypass_image_hotlink($get = false) 245 { 246 $this->sanitize->bypass_image_hotlink($get); 247 } 248 249 function bypass_image_hotlink_page($page = false) 250 { 251 $this->sanitize->bypass_image_hotlink_page($page); 252 } 253 254 function replace_headers($enable = false) 255 { 256 $this->sanitize->replace_headers($enable); 257 } 258 1169 1170 /** 1171 * Set callback function to create cache filename with 1172 * 1173 * @access public 1174 * @param mixed $function Callback function 1175 */ 1176 function set_cache_name_function($function = 'md5') 1177 { 1178 if (is_callable($function)) 1179 { 1180 $this->cache_name_function = $function; 1181 } 1182 } 1183 1184 /** 1185 * Set javascript query string parameter 1186 * 1187 * @access public 1188 * @param mixed $get Javascript query string parameter 1189 */ 1190 function set_javascript($get = 'js') 1191 { 1192 if ($get) 1193 { 1194 $this->javascript = (string) $get; 1195 } 1196 else 1197 { 1198 $this->javascript = false; 1199 } 1200 } 1201 1202 /** 1203 * Set options to make SP as fast as possible. Forgoes a 1204 * substantial amount of data sanitization in favor of speed. 1205 * 1206 * @access public 1207 * @param bool $set Whether to set them or not 1208 */ 1209 function set_stupidly_fast($set = false) 1210 { 1211 if ($set) 1212 { 1213 $this->enable_order_by_date(false); 1214 $this->remove_div(false); 1215 $this->strip_comments(false); 1216 $this->strip_htmltags(false); 1217 $this->strip_attributes(false); 1218 $this->set_image_handler(false); 1219 } 1220 } 1221 1222 /** 1223 * Set maximum number of feeds to check with autodiscovery 1224 * 1225 * @access public 1226 * @param int $max Maximum number of feeds to check 1227 */ 1228 function set_max_checked_feeds($max = 10) 1229 { 1230 $this->max_checked_feeds = (int) $max; 1231 } 1232 259 1233 function remove_div($enable = true) 260 1234 { 261 1235 $this->sanitize->remove_div($enable); 262 1236 } 263 264 function strip_ads($enable = false) 265 { 266 $this->sanitize->strip_ads($enable); 267 } 268 269 function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null) 270 { 1237 1238 function strip_htmltags($tags = '', $encode = null) 1239 { 1240 if ($tags === '') 1241 { 1242 $tags = $this->strip_htmltags; 1243 } 271 1244 $this->sanitize->strip_htmltags($tags); 272 if ( !is_null($encode))1245 if ($encode !== null) 273 1246 { 274 1247 $this->sanitize->encode_instead_of_strip($tags); 275 1248 } 276 1249 } 277 1250 278 1251 function encode_instead_of_strip($enable = true) 279 1252 { 280 1253 $this->sanitize->encode_instead_of_strip($enable); 281 1254 } 282 283 function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur')) 284 { 1255 1256 function strip_attributes($attribs = '') 1257 { 1258 if ($attribs === '') 1259 { 1260 $attribs = $this->strip_attributes; 1261 } 285 1262 $this->sanitize->strip_attributes($attribs); 286 1263 } 287 288 function output_encoding($encoding = 'UTF-8') 289 { 290 $this->sanitize->output_encoding($encoding); 291 } 292 293 function set_item_class($class = 'SimplePie_Item') 294 { 295 return $this->sanitize->set_item_class($class); 296 } 297 298 function set_author_class($class = 'SimplePie_Author') 299 { 300 return $this->sanitize->set_author_class($class); 301 } 302 303 function set_enclosure_class($class = 'SimplePie_Enclosure') 304 { 305 return $this->sanitize->set_enclosure_class($class); 306 } 307 1264 1265 function set_output_encoding($encoding = 'UTF-8') 1266 { 1267 $this->sanitize->set_output_encoding($encoding); 1268 } 1269 1270 function strip_comments($strip = false) 1271 { 1272 $this->sanitize->strip_comments($strip); 1273 } 1274 1275 /** 1276 * Set element/attribute key/value pairs of HTML attributes 1277 * containing URLs that need to be resolved relative to the feed 1278 * 1279 * @access public 1280 * @since 1.0 1281 * @param array $element_attribute Element/attribute key/value pairs 1282 */ 1283 function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite')) 1284 { 1285 $this->sanitize->set_url_replacements($element_attribute); 1286 } 1287 1288 /** 1289 * Set the handler to enable the display of cached favicons. 1290 * 1291 * @access public 1292 * @param str $page Web-accessible path to the handler_favicon.php file. 1293 * @param str $qs The query string that the value should be passed to. 1294 */ 1295 function set_favicon_handler($page = false, $qs = 'i') 1296 { 1297 if ($page != false) 1298 { 1299 $this->favicon_handler = $page . '?' . $qs . '='; 1300 } 1301 else 1302 { 1303 $this->favicon_handler = ''; 1304 } 1305 } 1306 1307 /** 1308 * Set the handler to enable the display of cached images. 1309 * 1310 * @access public 1311 * @param str $page Web-accessible path to the handler_image.php file. 1312 * @param str $qs The query string that the value should be passed to. 1313 */ 1314 function set_image_handler($page = false, $qs = 'i') 1315 { 1316 if ($page != false) 1317 { 1318 $this->sanitize->set_image_handler($page . '?' . $qs . '='); 1319 } 1320 else 1321 { 1322 $this->image_handler = ''; 1323 } 1324 } 1325 308 1326 function init() 309 1327 { 310 if ( !(function_exists('version_compare') && ((version_compare(phpversion(), '4.3.2', '>=') && version_compare(phpversion(), '5', '<')) || version_compare(phpversion(), '5.0.3', '>='))) || !extension_loaded('xml') || !extension_loaded('pcre'))1328 if ((function_exists('version_compare') && version_compare(PHP_VERSION, '4.1.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre')) 311 1329 { 312 1330 return false; 313 1331 } 314 if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink])) 315 { 316 if (get_magic_quotes_gpc()) 317 { 318 $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]); 319 } 320 SimplePie_Misc::display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent); 321 } 322 323 if (isset($_GET['js'])) 324 { 325 $embed = <<<EOT 1332 if (isset($_GET[$this->javascript])) 1333 { 1334 if (function_exists('ob_gzhandler')) 1335 { 1336 ob_start('ob_gzhandler'); 1337 } 1338 header('Content-type: text/javascript; charset: UTF-8'); 1339 header('Cache-Control: must-revalidate'); 1340 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days 1341 ?> 326 1342 function embed_odeo(link) { 327 1343 document.writeln('<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed>'); … … 338 1354 339 1355 function embed_flash(bgcolor, width, height, link, loop, type) { 340 document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>'); 1356 document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>'); 1357 } 1358 1359 function embed_flv(width, height, link, placeholder, loop, player) { 1360 document.writeln('<embed src="'+player+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" flashvars="file='+link+'&autostart=false&repeat='+loop+'&showdigits=true&showfsbutton=false"></embed>'); 341 1361 } 342 1362 … … 344 1364 document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>'); 345 1365 } 346 EOT; 347 348 if (function_exists('ob_gzhandler')) 349 { 350 ob_start('ob_gzhandler'); 351 } 352 header('Content-type: text/javascript; charset: UTF-8'); 353 header('Cache-Control: must-revalidate'); 354 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT'); 355 echo $embed; 1366 <?php 356 1367 exit; 357 1368 } 358 359 if (!empty($this->rss_url) || !empty($this->raw_data)) 1369 1370 // Pass whatever was set with config options over to the sanitizer. 1371 $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->cache_class); 1372 $this->sanitize->pass_file_data($this->file_class, $this->timeout, $this->useragent, $this->force_fsockopen); 1373 1374 if ($this->feed_url !== null || $this->raw_data !== null) 360 1375 { 361 1376 $this->data = array(); 1377 $this->multifeed_objects = array(); 362 1378 $cache = false; 363 364 if (!empty($this->rss_url)) 365 { 1379 1380 if ($this->feed_url !== null) 1381 { 1382 $parsed_feed_url = SimplePie_Misc::parse_url($this->feed_url); 366 1383 // Decide whether to enable caching 367 if ($this-> enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url))368 { 369 $cache = new $this->cache_class($this->cache_location, call_user_func($this->cache_name_type, $this->rss_url), 'spc');1384 if ($this->cache && $parsed_feed_url['scheme'] !== '') 1385 { 1386 $cache =& new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'); 370 1387 } 371 1388 // If it's enabled and we don't want an XML dump, use the cache … … 376 1393 if (!empty($this->data)) 377 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 } 378 1401 // If we've hit a collision just rerun it with caching disabled 379 if (isset($this->data['url']) && $this->data['url'] != $this->rss_url)1402 elseif (isset($this->data['url']) && $this->data['url'] != $this->feed_url) 380 1403 { 381 1404 $cache = false; 382 } 383 // If we've got a feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL 384 else if (!empty($this->data['feed_url'])) 385 { 386 if ($this->data['feed_url'] == $this->data['url']) 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()) 387 1412 { 388 $cache->unlink(); 1413 // Do not need to do feed autodiscovery yet. 1414 if ($this->data['feed_url'] == $this->data['url']) 1415 { 1416 $cache->unlink(); 1417 $this->data = array(); 1418 } 1419 else 1420 { 1421 $this->set_feed_url($this->data['feed_url']); 1422 return $this->init(); 1423 } 389 1424 } 390 else 391 { 392 $this->feed_url($this->data['feed_url']); 393 return $this->init(); 394 } 395 } 396 // If the cache is new enough 397 else if ($cache->mtime() + $this->max_minutes * 60 < time()) 1425 } 1426 // Check if the cache has been updated 1427 elseif ($cache->mtime() + $this->cache_duration < time()) 398 1428 { 399 1429 // If we have last-modified and/or etag set 400 if ( !empty($this->data['last-modified']) || !empty($this->data['etag']))1430 if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) 401 1431 { 402 1432 $headers = array(); 403 if ( !empty($this->data['last-modified']))1433 if (isset($this->data['headers']['last-modified'])) 404 1434 { 405 $headers['if-modified-since'] = $this->data[' last-modified'];1435 $headers['if-modified-since'] = $this->data['headers']['last-modified']; 406 1436 } 407 if ( !empty($this->data['etag']))1437 if (isset($this->data['headers']['etag'])) 408 1438 { 409 $headers['if-none-match'] = $this->data[' etag'];1439 $headers['if-none-match'] = $this->data['headers']['etag']; 410 1440 } 411 $file = new $this->file_class($this->rss_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);1441 $file =& new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen); 412 1442 if ($file->success) 413 1443 { 414 $headers = $file->headers(); 415 if ($headers['status']['code'] == 304) 1444 if ($file->status_code == 304) 416 1445 { 417 1446 $cache->touch(); 418 1447 return true; 1448 } 1449 else 1450 { 1451 $headers = $file->headers; 419 1452 } 420 1453 } … … 424 1457 } 425 1458 } 426 // If we don't have last-modified or etag set, just clear the cache427 else428 {429 $cache->unlink();430 }431 1459 } 432 1460 // If the cache is still valid, just return true … … 440 1468 { 441 1469 $cache->unlink(); 442 }443 }444 $this->data = array();1470 $this->data = array(); 1471 } 1472 } 445 1473 // 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. 446 1474 if (!isset($file)) 447 1475 { 448 if ( is_a($this->file, 'SimplePie_File') && $this->file->url == $this->rss_url)1476 if (SimplePie_Misc::is_a($this->file, 'SimplePie_File') && $this->file->url == $this->feed_url) 449 1477 { 450 1478 $file =& $this->file; … … 452 1480 else 453 1481 { 454 $file = new $this->file_class($this->rss_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);1482 $file =& new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen); 455 1483 } 456 1484 } … … 459 1487 { 460 1488 $this->error = $file->error; 461 return false; 462 } 463 1489 if (!empty($this->data)) 1490 { 1491 return true; 1492 } 1493 else 1494 { 1495 return false; 1496 } 1497 } 1498 464 1499 // Check if the supplied URL is a feed, if it isn't, look for it. 465 $locate = new $this->locator_class($file, $this->timeout, $this->useragent);1500 $locate =& new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds); 466 1501 if (!$locate->is_feed($file)) 467 1502 { 468 $feed = $locate->find(); 469 if ($feed) 470 { 471 if ($cache && !$cache->save(array('url' => $this->rss_url, 'feed_url' => $feed))) 472 { 473 $this->error = "$cache->name is not writeable"; 474 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__); 475 } 476 $this->rss_url = $feed; 477 return $this->init(); 1503 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched 1504 unset($file); 1505 if ($file = $locate->find($this->autodiscovery)) 1506 { 1507 if ($cache) 1508 { 1509 if (!$cache->save(array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD))) 1510 { 1511 trigger_error("$cache->name is not writeable", E_USER_WARNING); 1512 } 1513 $cache =& new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'); 1514 } 1515 $this->feed_url = $file->url; 478 1516 } 479 1517 else 480 1518 { 481 $this->error = "A feed could not be found at $this-> rss_url";482 SimplePie_Misc::error($this->error, E_USER_ WARNING, __FILE__, __LINE__);1519 $this->error = "A feed could not be found at $this->feed_url"; 1520 SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__); 483 1521 return false; 484 1522 } 485 1523 } 486 487 $headers = $file->headers(); 488 $ data = trim($file->body());489 $ file->close();1524 $locate = null; 1525 1526 $headers = $file->headers; 1527 $data = trim($file->body); 490 1528 unset($file); 491 1529 } … … 494 1532 $data = $this->raw_data; 495 1533 } 496 1534 497 1535 // First check to see if input has been overridden. 498 if ( !empty($this->input_encoding))1536 if ($this->input_encoding !== false) 499 1537 { 500 1538 $encoding = $this->input_encoding; 501 1539 } 502 1540 // Second try HTTP headers 503 else if (!empty($headers['content-type']) && preg_match('/charset\s*=\s*([^;]*)/i', $headers['content-type'], $charset))1541 elseif (isset($headers['content-type']) && preg_match('/;[\x09\x20]*charset=([^;]*)/i', $headers['content-type'], $charset)) 504 1542 { 505 1543 $encoding = $charset[1]; 506 1544 } 507 1545 // Then prolog, if at the very start of the document 508 else if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*("([^"]*)"|\'([^\']*)\')/Ui', $prolog[1], $encoding))509 { 510 $encoding = substr($ encoding[1], 1, -1);1546 elseif (preg_match("/^<\?xml[\x20\x9\xD\xA]+version([\x20\x9\xD\xA]+)?=([\x20\x9\xD\xA]+)?(\"1.0\"|'1.0'|\"1.1\"|'1.1')[\x20\x9\xD\xA]+encoding([\x20\x9\xD\xA]+)?=([\x20\x9\xD\xA]+)?(\"[A-Za-z][A-Za-z0-9._\-]*\"|'[A-Za-z][A-Za-z0-9._\-]*')([\x20\x9\xD\xA]+standalone([\x20\x9\xD\xA]+)?=([\x20\x9\xD\xA]+)?(\"(yes|no)\"|'(yes|no)'))?([\x20\x9\xD\xA]+)?\?>/", $data, $prolog)) 1547 { 1548 $encoding = substr($prolog[6], 1, -1); 511 1549 } 512 1550 // UTF-32 Big Endian BOM 513 else if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)1551 elseif (strpos($data, "\x0\x0\xFE\xFF") === 0) 514 1552 { 515 1553 $encoding = 'UTF-32be'; 516 1554 } 517 1555 // UTF-32 Little Endian BOM 518 else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)1556 elseif (strpos($data, "\xFF\xFE\x0\x0") === 0) 519 1557 { 520 1558 $encoding = 'UTF-32'; 521 1559 } 522 1560 // UTF-16 Big Endian BOM 523 else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)1561 elseif (strpos($data, "\xFE\xFF") === 0) 524 1562 { 525 1563 $encoding = 'UTF-16be'; 526 1564 } 527 1565 // UTF-16 Little Endian BOM 528 else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)1566 elseif (strpos($data, "\xFF\xFE") === 0) 529 1567 { 530 1568 $encoding = 'UTF-16le'; 531 1569 } 532 1570 // UTF-8 BOM 533 else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)1571 elseif (strpos($data, "\xEF\xBB\xBF") === 0) 534 1572 { 535 1573 $encoding = 'UTF-8'; 536 1574 } 537 // Fallback to the default 1575 // Fallback to the default (US-ASCII for text/xml, ISO-8859-1 for text/* MIME types, UTF-8 otherwise) 1576 elseif (isset($headers['content-type']) && strtolower(SimplePie_Misc::parse_mime($headers['content-type'])) == 'text/xml') 1577 { 1578 $encoding = 'US-ASCII'; 1579 } 1580 elseif (isset($headers['content-type']) && SimplePie_Misc::stripos(SimplePie_Misc::parse_mime($headers['content-type']), 'text/') === 0) 1581 { 1582 $encoding = 'ISO-8859-1'; 1583 } 538 1584 else 539 1585 { 540 $encoding = null;541 } 542 1586 $encoding = 'UTF-8'; 1587 } 1588 543 1589 // Change the encoding to UTF-8 (as we always use UTF-8 internally) 544 $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8'); 545 546 // Strip illegal characters (if on less than PHP5, as on PHP5 expat can manage fine) 547 if (version_compare(phpversion(), '5', '<')) 548 { 549 if (function_exists('iconv')) 550 { 551 $data = iconv('UTF-8', 'UTF-8//IGNORE', $data); 552 } 553 else if (function_exists('mb_convert_encoding')) 554 { 555 $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8'); 556 } 557 else 558 { 559 $data = SimplePie_Misc::utf8_bad_replace($data); 560 } 561 } 562 563 // Start parsing 564 $data = new $this->parser_class($data, 'UTF-8', $this->xml_dump); 1590 if ($encoding != 'UTF-8') 1591 { 1592 $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8'); 1593 } 1594 1595 // Strip illegal characters 1596 $data = SimplePie_Misc::utf8_bad_replace($data); 1597 1598 $parser =& new $this->parser_class(); 1599 $parser->pre_process($data, 'UTF-8'); 565 1600 // If we want the XML, just output that and quit 566 1601 if ($this->xml_dump) 567 1602 { 568 1603 header('Content-type: text/xml; charset=UTF-8'); 569 echo $data ->data;1604 echo $data; 570 1605 exit; 571 1606 } 572 1607 // If it's parsed fine 573 else if (!$data->error_code) 574 { 575 // Parse the data, and make it sane 576 $this->sanitize->parse_data_array($data->data, $this->rss_url); 1608 elseif ($parser->parse($data)) 1609 { 577 1610 unset($data); 578 // Get the sane data 579 $this->data['feedinfo'] = $this->sanitize->feedinfo; 580 unset($this->sanitize->feedinfo); 581 $this->data['info'] = $this->sanitize->info; 582 unset($this->sanitize->info); 583 $this->data['items'] = $this->sanitize->items; 584 unset($this->sanitize->items); 585 $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding; 586 $this->data['url'] = $this->rss_url; 587 588 // Store the headers that we need 589 if (!empty($headers['last-modified'])) 590 { 591 $this->data['last-modified'] = $headers['last-modified']; 592 } 593 if (!empty($headers['etag'])) 594 { 595 $this->data['etag'] = $headers['etag']; 596 } 597 598 // If we want to order it by date, check if all items have a date, and then sort it 599 if ($this->order_by_date && !empty($this->data['items'])) 1611 $this->data = $parser->get_data(); 1612 if (isset($this->data['child'])) 1613 { 1614 if (isset($headers)) 1615 { 1616 $this->data['headers'] = $headers; 1617 } 1618 $this->data['build'] = SIMPLEPIE_BUILD; 1619 1620 // Cache the file if caching is enabled 1621 if ($cache && !$cache->save($this->data)) 1622 { 1623 trigger_error("$cache->name is not writeable", E_USER_WARNING); 1624 } 1625 return true; 1626 } 1627 else 1628 { 1629 $this->error = "A feed could not be found at $this->feed_url"; 1630 SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__); 1631 return false; 1632 } 1633 } 1634 // If we have an error, just set SimplePie::error to it and quit 1635 else 1636 { 1637 $this->error = sprintf('XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column()); 1638 SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__); 1639 return false; 1640 } 1641 } 1642 elseif (!empty($this->multifeed_url)) 1643 { 1644 $i = 0; 1645 $success = 0; 1646 $this->multifeed_objects = array(); 1647 foreach ($this->multifeed_url as $url) 1648 { 1649 if (SIMPLEPIE_PHP5) 1650 { 1651 // This keyword needs to defy coding standards for PHP4 compatibility 1652 $this->multifeed_objects[$i] = clone($this); 1653 } 1654 else 1655 { 1656 $this->multifeed_objects[$i] = $this; 1657 } 1658 $this->multifeed_objects[$i]->set_feed_url($url); 1659 $success |= $this->multifeed_objects[$i]->init(); 1660 $i++; 1661 } 1662 return (bool) $success; 1663 } 1664 else 1665 { 1666 return false; 1667 } 1668 } 1669 1670 /** 1671 * Return the error message for the occured error 1672 * 1673 * @access public 1674 * @return string Error message 1675 */ 1676 function error() 1677 { 1678 return $this->error; 1679 } 1680 1681 function get_encoding() 1682 { 1683 return $this->sanitize->output_encoding; 1684 } 1685 1686 function handle_content_type($mime = 'text/html') 1687 { 1688 if (!headers_sent()) 1689 { 1690 $header = "Content-type: $mime;"; 1691 if ($this->get_encoding()) 1692 { 1693 $header .= ' charset=' . $this->get_encoding(); 1694 } 1695 else 1696 { 1697 $header .= ' charset=UTF-8'; 1698 } 1699 header($header); 1700 } 1701 } 1702 1703 function get_type() 1704 { 1705 if (!isset($this->data['type'])) 1706 { 1707 $this->data['type'] = SIMPLEPIE_TYPE_ALL; 1708 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) 1709 { 1710 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10; 1711 } 1712 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) 1713 { 1714 $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03; 1715 } 1716 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) 1717 { 1718 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) 1719 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) 1720 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']) 1721 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput'])) 1722 { 1723 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10; 1724 } 1725 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel']) 1726 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image']) 1727 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']) 1728 || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput'])) 1729 { 1730 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090; 1731 } 1732 } 1733 elseif (isset($this->data['child']['']['rss'])) 1734 { 1735 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL; 1736 if (isset($this->data['child']['']['rss'][0]['attribs']['']['version'])) 1737 { 1738 switch (trim($this->data['child']['']['rss'][0]['attribs']['']['version'])) 1739 { 1740 case '0.91': 1741 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091; 1742 if (isset($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data'])) 1743 { 1744 switch (trim($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data'])) 1745 { 1746 case '0': 1747 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE; 1748 break; 1749 1750 case '24': 1751 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND; 1752 break; 1753 } 1754 } 1755 break; 1756 1757 case '0.92': 1758 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092; 1759 break; 1760 1761 case '0.93': 1762 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093; 1763 break; 1764 1765 case '0.94': 1766 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094; 1767 break; 1768 1769 case '2.0': 1770 $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20; 1771 break; 1772 } 1773 } 1774 } 1775 else 1776 { 1777 $this->data['type'] = SIMPLEPIE_TYPE_NONE; 1778 } 1779 } 1780 return $this->data['type']; 1781 } 1782 1783 /** 1784 * Returns the URL for the favicon of the feed's website. 1785 * 1786 * @access public 1787 * @since 1.0 1788 */ 1789 function get_favicon() 1790 { 1791 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 1792 { 1793 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 1794 } 1795 elseif (($url = $this->get_link()) !== null && preg_match('/^http(s)?:\/\//i', $url)) 1796 { 1797 $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $url); 1798 1799 if ($this->cache && $this->favicon_handler) 1800 { 1801 $cache =& new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $favicon), 'spi'); 1802 1803 if ($cache->load()) 1804 { 1805 return $this->sanitize($this->favicon_handler . rawurlencode($favicon), SIMPLEPIE_CONSTRUCT_IRI); 1806 } 1807 else 1808 { 1809 $file =& new $this->file_class($favicon, $this->timeout / 10, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen); 1810 1811 if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)) && strlen($file->body) > 0) 1812 { 1813 if ($cache->save(array('headers' => $file->headers, 'body' => $file->body))) 1814 { 1815 return $this->sanitize($this->favicon_handler . rawurlencode($favicon), SIMPLEPIE_CONSTRUCT_IRI); 1816 } 1817 else 1818 { 1819 trigger_error("$cache->name is not writeable", E_USER_WARNING); 1820 return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI); 1821 } 1822 } 1823 } 1824 } 1825 else 1826 { 1827 return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI); 1828 } 1829 } 1830 return false; 1831 } 1832 1833 /** 1834 * @todo If we have a perm redirect we should return the new URL 1835 * @todo When we make the above change, let's support <itunes:new-feed-url> as well 1836 * @todo Also, |atom:link|@rel=self 1837 */ 1838 function subscribe_url() 1839 { 1840 if ($this->feed_url !== null) 1841 { 1842 return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); 1843 } 1844 else 1845 { 1846 return null; 1847 } 1848 } 1849 1850 function subscribe_feed() 1851 { 1852 if ($this->feed_url !== null) 1853 { 1854 return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI); 1855 } 1856 else 1857 { 1858 return null; 1859 } 1860 } 1861 1862 function subscribe_outlook() 1863 { 1864 if ($this->feed_url !== null) 1865 { 1866 return 'outlook' . $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI); 1867 } 1868 else 1869 { 1870 return null; 1871 } 1872 } 1873 1874 function subscribe_podcast() 1875 { 1876 if ($this->feed_url !== null) 1877 { 1878 return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 3), SIMPLEPIE_CONSTRUCT_IRI); 1879 } 1880 else 1881 { 1882 return null; 1883 } 1884 } 1885 1886 function subscribe_itunes() 1887 { 1888 if ($this->feed_url !== null) 1889 { 1890 return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 4), SIMPLEPIE_CONSTRUCT_IRI); 1891 } 1892 else 1893 { 1894 return null; 1895 } 1896 } 1897 1898 /** 1899 * Creates the subscribe_* methods' return data 1900 * 1901 * @access private 1902 * @param string $feed_url String to prefix to the feed URL 1903 * @param string $site_url String to prefix to the site URL (and 1904 * suffix to the feed URL) 1905 * @return mixed URL if feed exists, false otherwise 1906 */ 1907 function subscribe_service($feed_url, $site_url = null) 1908 { 1909 if ($this->subscribe_url()) 1910 { 1911 $return = $this->sanitize($feed_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->subscribe_url()); 1912 if ($site_url !== null && $this->get_link() !== null) 1913 { 1914 $return .= $this->sanitize($site_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_link()); 1915 } 1916 return $return; 1917 } 1918 else 1919 { 1920 return null; 1921 } 1922 } 1923 1924 function subscribe_aol() 1925 { 1926 return $this->subscribe_service('http://feeds.my.aol.com/add.jsp?url='); 1927 } 1928 1929 function subscribe_bloglines() 1930 { 1931 return urldecode($this->subscribe_service('http://www.bloglines.com/sub/')); 1932 } 1933 1934 function subscribe_eskobo() 1935 { 1936 return $this->subscribe_service('http://www.eskobo.com/?AddToMyPage='); 1937 } 1938 1939 function subscribe_feedfeeds() 1940 { 1941 return $this->subscribe_service('http://www.feedfeeds.com/add?feed='); 1942 } 1943 1944 function subscribe_feedster() 1945 { 1946 return $this->subscribe_service('http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl='); 1947 } 1948 1949 function subscribe_google() 1950 { 1951 return $this->subscribe_service('http://fusion.google.com/add?feedurl='); 1952 } 1953 1954 function subscribe_gritwire() 1955 { 1956 return $this->subscribe_service('http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl='); 1957 } 1958 1959 function subscribe_msn() 1960 { 1961 return $this->subscribe_service('http://my.msn.com/addtomymsn.armx?id=rss&ut=', '&ru='); 1962 } 1963 1964 function subscribe_netvibes() 1965 { 1966 return $this->subscribe_service('http://www.netvibes.com/subscribe.php?url='); 1967 } 1968 1969 function subscribe_newsburst() 1970 { 1971 return $this->subscribe_service('http://www.newsburst.com/Source/?add='); 1972 } 1973 1974 function subscribe_newsgator() 1975 { 1976 return $this->subscribe_service('http://www.newsgator.com/ngs/subscriber/subext.aspx?url='); 1977 } 1978 1979 function subscribe_odeo() 1980 { 1981 return $this->subscribe_service('http://www.odeo.com/listen/subscribe?feed='); 1982 } 1983 1984 function subscribe_podnova() 1985 { 1986 return $this->subscribe_service('http://www.podnova.com/index_your_podcasts.srf?action=add&url='); 1987 } 1988 1989 function subscribe_rojo() 1990 { 1991 return $this->subscribe_service('http://www.rojo.com/add-subscription?resource='); 1992 } 1993 1994 function subscribe_yahoo() 1995 { 1996 return $this->subscribe_service('http://add.my.yahoo.com/rss?url='); 1997 } 1998 1999 function get_feed_tags($namespace, $tag) 2000 { 2001 $type = $this->get_type(); 2002 if ($type & SIMPLEPIE_TYPE_ATOM_10) 2003 { 2004 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag])) 2005 { 2006 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]; 2007 } 2008 } 2009 if ($type & SIMPLEPIE_TYPE_ATOM_03) 2010 { 2011 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag])) 2012 { 2013 return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]; 2014 } 2015 } 2016 if ($type & SIMPLEPIE_TYPE_RSS_RDF) 2017 { 2018 if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag])) 2019 { 2020 return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]; 2021 } 2022 } 2023 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 2024 { 2025 if (isset($this->data['child']['']['rss'][0]['child'][$namespace][$tag])) 2026 { 2027 return $this->data['child']['']['rss'][0]['child'][$namespace][$tag]; 2028 } 2029 } 2030 return null; 2031 } 2032 2033 function get_channel_tags($namespace, $tag) 2034 { 2035 $type = $this->get_type(); 2036 if ($type & SIMPLEPIE_TYPE_ATOM_ALL) 2037 { 2038 if ($return = $this->get_feed_tags($namespace, $tag)) 2039 { 2040 return $return; 2041 } 2042 } 2043 if ($type & SIMPLEPIE_TYPE_RSS_10) 2044 { 2045 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel')) 2046 { 2047 if (isset($channel[0]['child'][$namespace][$tag])) 2048 { 2049 return $channel[0]['child'][$namespace][$tag]; 2050 } 2051 } 2052 } 2053 if ($type & SIMPLEPIE_TYPE_RSS_090) 2054 { 2055 if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel')) 2056 { 2057 if (isset($channel[0]['child'][$namespace][$tag])) 2058 { 2059 return $channel[0]['child'][$namespace][$tag]; 2060 } 2061 } 2062 } 2063 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 2064 { 2065 if ($channel = $this->get_feed_tags('', 'channel')) 2066 { 2067 if (isset($channel[0]['child'][$namespace][$tag])) 2068 { 2069 return $channel[0]['child'][$namespace][$tag]; 2070 } 2071 } 2072 } 2073 return null; 2074 } 2075 2076 function get_image_tags($namespace, $tag) 2077 { 2078 $type = $this->get_type(); 2079 if ($type & SIMPLEPIE_TYPE_RSS_10) 2080 { 2081 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image')) 2082 { 2083 if (isset($image[0]['child'][$namespace][$tag])) 2084 { 2085 return $image[0]['child'][$namespace][$tag]; 2086 } 2087 } 2088 } 2089 if ($type & SIMPLEPIE_TYPE_RSS_090) 2090 { 2091 if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image')) 2092 { 2093 if (isset($image[0]['child'][$namespace][$tag])) 2094 { 2095 return $image[0]['child'][$namespace][$tag]; 2096 } 2097 } 2098 } 2099 if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 2100 { 2101 if ($image = $this->get_channel_tags('', 'image')) 2102 { 2103 if (isset($image[0]['child'][$namespace][$tag])) 2104 { 2105 return $image[0]['child'][$namespace][$tag]; 2106 } 2107 } 2108 } 2109 return null; 2110 } 2111 2112 function get_base($element = array()) 2113 { 2114 if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) 2115 { 2116 return $element['xml_base']; 2117 } 2118 elseif ($this->get_link() !== null) 2119 { 2120 return $this->get_link(); 2121 } 2122 elseif (isset($this->data['headers']['content-location'])) 2123 { 2124 return SimplePie_Misc::absolutize_url($this->data['headers']['content-location'], $this->subscribe_url()); 2125 } 2126 else 2127 { 2128 return $this->subscribe_url(); 2129 } 2130 } 2131 2132 function sanitize($data, $type, $base = '') 2133 { 2134 return $this->sanitize->sanitize($data, $type, $base); 2135 } 2136 2137 function get_title() 2138 { 2139 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 2140 { 2141 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2142 } 2143 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 2144 { 2145 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2146 } 2147 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 2148 { 2149 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2150 } 2151 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 2152 { 2153 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2154 } 2155 elseif ($return = $this->get_channel_tags('', 'title')) 2156 { 2157 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2158 } 2159 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 2160 { 2161 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2162 } 2163 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 2164 { 2165 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2166 } 2167 else 2168 { 2169 return null; 2170 } 2171 } 2172 2173 function get_link($key = 0, $rel = 'alternate') 2174 { 2175 $links = $this->get_links($rel); 2176 if (isset($links[$key])) 2177 { 2178 return $links[$key]; 2179 } 2180 else 2181 { 2182 return null; 2183 } 2184 } 2185 2186 /** 2187 * Added for parity between the parent-level and the item/entry-level. 2188 */ 2189 function get_permalink() 2190 { 2191 return $this->get_link(0); 2192 } 2193 2194 function get_links($rel = 'alternate') 2195 { 2196 if (!isset($this->data['links'])) 2197 { 2198 $this->data['links'] = array(); 2199 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) 2200 { 2201 foreach ($links as $link) 2202 { 2203 if (isset($link['attribs']['']['href'])) 2204 { 2205 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 2206 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 2207 } 2208 } 2209 } 2210 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) 2211 { 2212 foreach ($links as $link) 2213 { 2214 if (isset($link['attribs']['']['href'])) 2215 { 2216 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 2217 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 2218 2219 } 2220 } 2221 } 2222 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 2223 { 2224 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 2225 } 2226 if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 2227 { 2228 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 2229 } 2230 if ($links = $this->get_channel_tags('', 'link')) 2231 { 2232 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 2233 } 2234 2235 $keys = array_keys($this->data['links']); 2236 foreach ($keys as $key) 2237 { 2238 if (SimplePie_Misc::is_isegment_nz_nc($key)) 2239 { 2240 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 2241 { 2242 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 2243 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 2244 } 2245 else 2246 { 2247 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 2248 } 2249 } 2250 elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 2251 { 2252 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 2253 } 2254 $this->data['links'][$key] = array_unique($this->data['links'][$key]); 2255 } 2256 } 2257 2258 if (isset($this->data['links'][$rel])) 2259 { 2260 return $this->data['links'][$rel]; 2261 } 2262 else 2263 { 2264 return null; 2265 } 2266 } 2267 2268 function get_description() 2269 { 2270 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) 2271 { 2272 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2273 } 2274 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) 2275 { 2276 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2277 } 2278 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 2279 { 2280 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2281 } 2282 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 2283 { 2284 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2285 } 2286 elseif ($return = $this->get_channel_tags('', 'description')) 2287 { 2288 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2289 } 2290 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 2291 { 2292 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2293 } 2294 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 2295 { 2296 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2297 } 2298 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 2299 { 2300 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 2301 } 2302 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 2303 { 2304 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 2305 } 2306 else 2307 { 2308 return null; 2309 } 2310 } 2311 2312 function get_copyright() 2313 { 2314 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 2315 { 2316 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2317 } 2318 elseif ($return = $this->get_channel_tags('', 'copyright')) 2319 { 2320 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2321 } 2322 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 2323 { 2324 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2325 } 2326 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 2327 { 2328 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2329 } 2330 else 2331 { 2332 return null; 2333 } 2334 } 2335 2336 function get_language() 2337 { 2338 if ($return = $this->get_channel_tags('', 'language')) 2339 { 2340 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2341 } 2342 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) 2343 { 2344 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2345 } 2346 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) 2347 { 2348 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2349 } 2350 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) 2351 { 2352 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 2353 } 2354 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) 2355 { 2356 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 2357 } 2358 elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) 2359 { 2360 return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 2361 } 2362 elseif (isset($this->data['headers']['content-language'])) 2363 { 2364 return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); 2365 } 2366 else 2367 { 2368 return null; 2369 } 2370 } 2371 2372 function get_latitude() 2373 { 2374 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 2375 { 2376 return (float) $return[0]['data']; 2377 } 2378 elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match)) 2379 { 2380 return (float) $match[1]; 2381 } 2382 else 2383 { 2384 return null; 2385 } 2386 } 2387 2388 function get_longitude() 2389 { 2390 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 2391 { 2392 return (float) $return[0]['data']; 2393 } 2394 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 2395 { 2396 return (float) $return[0]['data']; 2397 } 2398 elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match)) 2399 { 2400 return (float) $match[2]; 2401 } 2402 else 2403 { 2404 return null; 2405 } 2406 } 2407 2408 function get_image_title() 2409 { 2410 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 2411 { 2412 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2413 } 2414 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 2415 { 2416 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2417 } 2418 elseif ($return = $this->get_image_tags('', 'title')) 2419 { 2420 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2421 } 2422 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 2423 { 2424 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2425 } 2426 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 2427 { 2428 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2429 } 2430 else 2431 { 2432 return null; 2433 } 2434 } 2435 2436 function get_image_url() 2437 { 2438 if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) 2439 { 2440 return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); 2441 } 2442 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) 2443 { 2444 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2445 } 2446 elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 2447 { 2448 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2449 } 2450 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) 2451 { 2452 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2453 } 2454 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) 2455 { 2456 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2457 } 2458 elseif ($return = $this->get_image_tags('', 'url')) 2459 { 2460 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2461 } 2462 else 2463 { 2464 return null; 2465 } 2466 } 2467 2468 function get_image_link() 2469 { 2470 if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 2471 { 2472 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2473 } 2474 elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 2475 { 2476 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2477 } 2478 elseif ($return = $this->get_image_tags('', 'link')) 2479 { 2480 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2481 } 2482 else 2483 { 2484 return null; 2485 } 2486 } 2487 2488 function get_image_width() 2489 { 2490 if ($return = $this->get_image_tags('', 'width')) 2491 { 2492 return round($return[0]['data']); 2493 } 2494 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags('', 'url')) 2495 { 2496 return 88.0; 2497 } 2498 else 2499 { 2500 return null; 2501 } 2502 } 2503 2504 function get_image_height() 2505 { 2506 if ($return = $this->get_image_tags('', 'height')) 2507 { 2508 return round($return[0]['data']); 2509 } 2510 elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags('', 'url')) 2511 { 2512 return 31.0; 2513 } 2514 else 2515 { 2516 return null; 2517 } 2518 } 2519 2520 function get_item_quantity($max = 0) 2521 { 2522 $qty = count($this->get_items()); 2523 if ($max == 0) 2524 { 2525 return $qty; 2526 } 2527 else 2528 { 2529 return ($qty > $max) ? $max : $qty; 2530 } 2531 } 2532 2533 function get_item($key = 0) 2534 { 2535 $items = $this->get_items(); 2536 if (isset($items[$key])) 2537 { 2538 return $items[$key]; 2539 } 2540 else 2541 { 2542 return null; 2543 } 2544 } 2545 2546 function get_items($start = 0, $end = 0) 2547 { 2548 if (!empty($this->multifeed_objects)) 2549 { 2550 return SimplePie::merge_items($this->multifeed_objects, $start, $end); 2551 } 2552 elseif (!isset($this->data['items'])) 2553 { 2554 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) 2555 { 2556 $keys = array_keys($items); 2557 foreach ($keys as $key) 2558 { 2559 $this->data['items'][] =& new $this->item_class($this, $items[$key]); 2560 } 2561 } 2562 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) 2563 { 2564 $keys = array_keys($items); 2565 foreach ($keys as $key) 2566 { 2567 $this->data['items'][] =& new $this->item_class($this, $items[$key]); 2568 } 2569 } 2570 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) 2571 { 2572 $keys = array_keys($items); 2573 foreach ($keys as $key) 2574 { 2575 $this->data['items'][] =& new $this->item_class($this, $items[$key]); 2576 } 2577 } 2578 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) 2579 { 2580 $keys = array_keys($items); 2581 foreach ($keys as $key) 2582 { 2583 $this->data['items'][] =& new $this->item_class($this, $items[$key]); 2584 } 2585 } 2586 if ($items = $this->get_channel_tags('', 'item')) 2587 { 2588 $keys = array_keys($items); 2589 foreach ($keys as $key) 2590 { 2591 $this->data['items'][] =& new $this->item_class($this, $items[$key]); 2592 } 2593 } 2594 } 2595 2596 if (!empty($this->data['items'])) 2597 { 2598 // If we want to order it by date, check if all items have a date, and then sort it 2599 if ($this->order_by_date) 2600 { 2601 if (!isset($this->data['ordered_items'])) 600 2602 { 601 2603 $do_sort = true; … … 608 2610 } 609 2611 } 2612 $item = null; 2613 $this->data['ordered_items'] = $this->data['items']; 610 2614 if ($do_sort) 611 2615 { 612 usort($this->data['items'], create_function('$a, $b', 'if ($a->get_date(\'U\') == $b->get_date(\'U\')) return 1; return ($a->get_date(\'U\') < $b->get_date(\'U\')) ? 1 : -1;')); 613 } 614 } 615 616 // Cache the file if caching is enabled 617 if ($cache && !$cache->save($this->data)) 618 { 619 $this->error = "$cache->name is not writeable"; 620 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__); 621 } 622 return true; 623 } 624 // If we have an error, just set SimplePie::error to it and quit 2616 usort($this->data['ordered_items'], array(&$this, 'sort_items')); 2617 } 2618 } 2619 $items = $this->data['ordered_items']; 2620 } 625 2621 else 626 2622 { 627 $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column"; 628 SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__); 629 return false; 630 } 631 } 632 } 633 634 function get_encoding() 635 { 636 if (!empty($this->data['feedinfo']['encoding'])) 637 { 638 return $this->data['feedinfo']['encoding']; 639 } 640 else 641 { 642 return false; 643 } 644 } 645 646 function handle_content_type($mime = 'text/html') 647 { 648 if (!headers_sent()) 649 { 650 $header = "Content-type: $mime;"; 651 if ($this->get_encoding()) 652 { 653 $header .= ' charset=' . $this->get_encoding(); 2623 $items = $this->data['items']; 2624 } 2625 2626 // Slice the data as desired 2627 if ($end == 0) 2628 { 2629 return array_slice($items, $start); 654 2630 } 655 2631 else 656 2632 { 657 $header .= ' charset=UTF-8'; 658 } 659 header($header); 660 } 661 } 662 663 function get_type() 664 { 665 if (!empty($this->data['feedinfo']['type'])) 666 { 667 return $this->data['feedinfo']['type']; 668 } 669 else 670 { 671 return false; 672 } 673 } 674 675 function get_version() 676 { 677 if (!empty($this->data['feedinfo']['version'])) 678 { 679 return $this->data['feedinfo']['version']; 680 } 681 else 682 { 683 return false; 684 } 685 } 686 687 function get_favicon($check = false, $alternate = null) 688 { 689 if (!empty($this->data['info']['link']['alternate'][0])) 690 { 691 $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $this->get_feed_link()); 692 693 if ($check) 694 { 695 $file = new $this->file_class($favicon, $this->timeout/10, 5, null, $this->useragent, $this->force_fsockopen); 696 $headers = $file->headers(); 697 $file->close(); 698 699 if ($headers['status']['code'] == 200) 700 { 701 return $favicon; 702 } 2633 return array_slice($items, $start, $end); 2634 } 2635 } 2636 else 2637 { 2638 return array(); 2639 } 2640 } 2641 2642 function sort_items($a, $b) 2643 { 2644 return $a->get_date('U') <= $b->get_date('U'); 2645 } 2646 2647 function merge_items($urls, $start = 0, $end = 0) 2648 { 2649 if (is_array($urls) && sizeof($urls) > 0) 2650 { 2651 $items = array(); 2652 foreach ($urls as $arg) 2653 { 2654 if (SimplePie_Misc::is_a($arg, 'SimplePie')) 2655 { 2656 $items = array_merge($items, $arg->get_items()); 2657 } 2658 else 2659 { 2660 trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); 2661 } 2662 } 2663 2664 $do_sort = true; 2665 foreach ($items as $item) 2666 { 2667 if (!$item->get_date('U')) 2668 { 2669 $do_sort = false; 2670 break; 2671 } 2672 } 2673 $item = null; 2674 if ($do_sort) 2675 { 2676 usort($items, array('SimplePie', 'sort_items')); 2677 } 2678 2679 if ($end == 0) 2680 { 2681 return array_slice($items, $start); 703 2682 } 704 2683 else 705 2684 { 706 return $favicon; 707 } 708 } 709 if (!is_null($alternate)) 710 { 711 return $alternate; 712 } 713 else 714 { 715 return false; 716 } 717 } 718 719 function subscribe_url() 720 { 721 if (!empty($this->rss_url)) 722 { 723 return $this->rss_url; 724 } 725 else 726 { 727 return false; 728 } 729 } 730 731 function subscribe_feed() 732 { 733 if (!empty($this->rss_url)) 734 { 735 return SimplePie_Misc::fix_protocol($this->rss_url, 2); 736 } 737 else 738 { 739 return false; 740 } 741 } 742 743 function subscribe_outlook() 744 { 745 if (!empty($this->rss_url)) 746 { 747 return 'outlook' . SimplePie_Misc::fix_protocol($this->rss_url, 2); 748 } 749 else 750 { 751 return false; 752 } 753 } 754 755 function subscribe_podcast() 756 { 757 if (!empty($this->rss_url)) 758 { 759 return SimplePie_Misc::fix_protocol($this->rss_url, 3); 760 } 761 else 762 { 763 return false; 764 } 765 } 766 767 function subscribe_aol() 768 { 769 if ($this->subscribe_url()) 770 { 771 return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url()); 772 } 773 else 774 { 775 return false; 776 } 777 } 778 779 function subscribe_bloglines() 780 { 781 if ($this->subscribe_url()) 782 { 783 return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url()); 784 } 785 else 786 { 787 return false; 788 } 789 } 790 791 function subscribe_eskobo() 792 { 793 if ($this->subscribe_url()) 794 { 795 return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url()); 796 } 797 else 798 { 799 return false; 800 } 801 } 802 803 function subscribe_feedfeeds() 804 { 805 if ($this->subscribe_url()) 806 { 807 return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url()); 808 } 809 else 810 { 811 return false; 812 } 813 } 814 815 function subscribe_feedlounge() 816 { 817 if ($this->subscribe_url()) 818 { 819 return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url()); 820 } 821 else 822 { 823 return false; 824 } 825 } 826 827 function subscribe_feedster() 828 { 829 if ($this->subscribe_url()) 830 { 831 return 'http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=' . rawurlencode($this->subscribe_url()); 832 } 833 else 834 { 835 return false; 836 } 837 } 838 839 function subscribe_google() 840 { 841 if ($this->subscribe_url()) 842 { 843 return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url()); 844 } 845 else 846 { 847 return false; 848 } 849 } 850 851 function subscribe_gritwire() 852 { 853 if ($this->subscribe_url()) 854 { 855 return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url()); 856 } 857 else 858 { 859 return false; 860 } 861 } 862 863 function subscribe_msn() 864 { 865 if ($this->subscribe_url()) 866 { 867 $url = 'http://my.msn.com/addtomymsn.armx?id=rss&ut=' . rawurlencode($this->subscribe_url()); 868 if ($this->get_feed_link()) 869 { 870 $url .= '&ru=' . rawurlencode($this->get_feed_link()); 871 } 872 return $url; 873 } 874 else 875 { 876 return false; 877 } 878 } 879 880 function subscribe_netvibes() 881 { 882 if ($this->subscribe_url()) 883 { 884 return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url()); 885 } 886 else 887 { 888 return false; 889 } 890 } 891 892 function subscribe_newsburst() 893 { 894 if ($this->subscribe_url()) 895 { 896 return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url()); 897 } 898 else 899 { 900 return false; 901 } 902 } 903 904 function subscribe_newsgator() 905 { 906 if ($this->subscribe_url()) 907 { 908 return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url()); 909 } 910 else 911 { 912 return false; 913 } 914 } 915 916 function subscribe_odeo() 917 { 918 if ($this->subscribe_url()) 919 { 920 return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url()); 921 } 922 else 923 { 924 return false; 925 } 926 } 927 928 function subscribe_pluck() 929 { 930 if ($this->subscribe_url()) 931 { 932 return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&a=' . rawurlencode($this->subscribe_url()); 933 } 934 else 935 { 936 return false; 937 } 938 } 939 940 function subscribe_podnova() 941 { 942 if ($this->subscribe_url()) 943 { 944 return 'http://www.podnova.com/index_your_podcasts.srf?action=add&url=' . rawurlencode($this->subscribe_url()); 945 } 946 else 947 { 948 return false; 949 } 950 } 951 952 function subscribe_rojo() 953 { 954 if ($this->subscribe_url()) 955 { 956 return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url()); 957 } 958 else 959 { 960 return false; 961 } 962 } 963 964 function subscribe_yahoo() 965 { 966 if ($this->subscribe_url()) 967 { 968 return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url()); 969 } 970 else 971 { 972 return false; 973 } 974 } 975 976 function get_feed_title() 977 { 978 if (!empty($this->data['info']['title'])) 979 { 980 return $this->data['info']['title']; 981 } 982 else 983 { 984 return false; 985 } 986 } 987 988 function get_feed_link() 989 { 990 if (!empty($this->data['info']['link']['alternate'][0])) 991 { 992 return $this->data['info']['link']['alternate'][0]; 993 } 994 else 995 { 996 return false; 997 } 998 } 999 1000 function get_feed_links() 1001 { 1002 if (!empty($this->data['info']['link'])) 1003 { 1004 return $this->data['info']['link']; 1005 } 1006 else 1007 { 1008 return false; 1009 } 1010 } 1011 1012 function get_feed_description() 1013 { 1014 if (!empty($this->data['info']['description'])) 1015 { 1016 return $this->data['info']['description']; 1017 } 1018 else if (!empty($this->data['info']['dc:description'])) 1019 { 1020 return $this->data['info']['dc:description']; 1021 } 1022 else if (!empty($this->data['info']['tagline'])) 1023 { 1024 return $this->data['info']['tagline']; 1025 } 1026 else if (!empty($this->data['info']['subtitle'])) 1027 { 1028 return $this->data['info']['subtitle']; 1029 } 1030 else 1031 { 1032 return false; 1033 } 1034 } 1035 1036 function get_feed_copyright() 1037 { 1038 if (!empty($this->data['info']['copyright'])) 1039 { 1040 return $this->data['info']['copyright']; 1041 } 1042 else 1043 { 1044 return false; 1045 } 1046 } 1047 1048 function get_feed_language() 1049 { 1050 if (!empty($this->data['info']['language'])) 1051 { 1052 return $this->data['info']['language']; 1053 } 1054 else if (!empty($this->data['info']['xml:lang'])) 1055 { 1056 return $this->data['info']['xml:lang']; 1057 } 1058 else 1059 { 1060 return false; 1061 } 1062 } 1063 1064 function get_image_exist() 1065 { 1066 if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo'])) 1067 { 1068 return true; 1069 } 1070 else 1071 { 1072 return false; 1073 } 1074 } 1075 1076 function get_image_title() 1077 { 1078 if (!empty($this->data['info']['image']['title'])) 1079 { 1080 return $this->data['info']['image']['title']; 1081 } 1082 else 1083 { 1084 return false; 1085 } 1086 } 1087 1088 function get_image_url() 1089 { 1090 if (!empty($this->data['info']['image']['url'])) 1091 { 1092 return $this->data['info']['image']['url']; 1093 } 1094 else if (!empty($this->data['info']['image']['logo'])) 1095 { 1096 return $this->data['info']['image']['logo']; 1097 } 1098 else 1099 { 1100 return false; 1101 } 1102 } 1103 1104 function get_image_link() 1105 { 1106 if (!empty($this->data['info']['image']['link'])) 1107 { 1108 return $this->data['info']['image']['link']; 1109 } 1110 else 1111 { 1112 return false; 1113 } 1114 } 1115 1116 function get_image_width() 1117 { 1118 if (!empty($this->data['info']['image']['width'])) 1119 { 1120 return $this->data['info']['image']['width']; 1121 } 1122 else 1123 { 1124 return false; 1125 } 1126 } 1127 1128 function get_image_height() 1129 { 1130 if (!empty($this->data['info']['image']['height'])) 1131 { 1132 return $this->data['info']['image']['height']; 1133 } 1134 else 1135 { 1136 return false; 1137 } 1138 } 1139 1140 function get_item_quantity($max = 0) 1141 { 1142 if (!empty($this->data['items'])) 1143 { 1144 $qty = sizeof($this->data['items']); 1145 } 1146 else 1147 { 1148 $qty = 0; 1149 } 1150 if ($max == 0) 1151 { 1152 return $qty; 1153 } 1154 else 1155 { 1156 return ($qty > $max) ? $max : $qty; 1157 } 1158 } 1159 1160 function get_item($key = 0) 1161 { 1162 if (!empty($this->data['items'][$key])) 1163 { 1164 return $this->data['items'][$key]; 1165 } 1166 else 1167 { 1168 return false; 1169 } 1170 } 1171 1172 function get_items($start = 0, $end = 0) 1173 { 1174 if ($this->get_item_quantity() > 0) 1175 { 1176 if ($end == 0) 1177 { 1178 return array_slice($this->data['items'], $start); 1179 } 1180 else 1181 { 1182 return array_slice($this->data['items'], $start, $end); 1183 } 1184 } 1185 else 1186 { 1187 return false; 2685 return array_slice($items, $start, $end); 2686 } 2687 } 2688 else 2689 { 2690 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); 2691 return array(); 1188 2692 } 1189 2693 } … … 1192 2696 class SimplePie_Item 1193 2697 { 1194 var $data; 1195 1196 function SimplePie_Item($data) 1197 { 1198 $this->data =& $data; 1199 } 1200 1201 function get_id() 1202 { 1203 if (!empty($this->data['guid']['data'])) 1204 { 1205 return $this->data['guid']['data']; 1206 } 1207 else if (!empty($this->data['id'])) 1208 { 1209 return $this->data['id']; 1210 } 1211 else 1212 { 1213 return false; 1214 } 1215 } 1216 2698 var $feed; 2699 var $data = array(); 2700 2701 function SimplePie_Item($feed, $data) 2702 { 2703 $this->feed = $feed; 2704 $this->data = $data; 2705 } 2706 2707 function __toString() 2708 { 2709 return md5(serialize($this->data)); 2710 } 2711 2712 function get_item_tags($namespace, $tag) 2713 { 2714 if (isset($this->data['child'][$namespace][$tag])) 2715 { 2716 return $this->data['child'][$namespace][$tag]; 2717 } 2718 else 2719 { 2720 return null; 2721 } 2722 } 2723 2724 function get_base($element = array()) 2725 { 2726 return $this->feed->get_base($element); 2727 } 2728 2729 function sanitize($data, $type, $base = '') 2730 { 2731 return $this->feed->sanitize($data, $type, $base); 2732 } 2733 2734 function get_feed() 2735 { 2736 return $this->feed; 2737 } 2738 2739 function get_id($hash = false) 2740 { 2741 if ($hash) 2742 { 2743 return $this->__toString(); 2744 } 2745 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id')) 2746 { 2747 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2748 } 2749 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id')) 2750 { 2751 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2752 } 2753 elseif ($return = $this->get_item_tags('', 'guid')) 2754 { 2755 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2756 } 2757 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier')) 2758 { 2759 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2760 } 2761 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier')) 2762 { 2763 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2764 } 2765 elseif (($return = $this->get_permalink()) !== null) 2766 { 2767 return $return; 2768 } 2769 elseif (($return = $this->get_title()) !== null) 2770 { 2771 return $return; 2772 } 2773 else 2774 { 2775 return $this->__toString(); 2776 } 2777 } 2778 1217 2779 function get_title() 1218 2780 { 1219 if (!empty($this->data['title'])) 1220 { 1221 return $this->data['title']; 1222 } 1223 else if (!empty($this->data['dc:title'])) 1224 { 1225 return $this->data['dc:title']; 1226 } 1227 else 1228 { 1229 return false; 1230 } 1231 } 1232 1233 function get_description() 1234 { 1235 if (!empty($this->data['content'])) 1236 { 1237 return $this->data['content']; 1238 } 1239 else if (!empty($this->data['encoded'])) 1240 { 1241 return $this->data['encoded']; 1242 } 1243 else if (!empty($this->data['summary'])) 1244 { 1245 return $this->data['summary']; 1246 } 1247 else if (!empty($this->data['description'])) 1248 { 1249 return $this->data['description']; 1250 } 1251 else if (!empty($this->data['dc:description'])) 1252 { 1253 return $this->data['dc:description']; 1254 } 1255 else if (!empty($this->data['longdesc'])) 1256 { 1257 return $this->data['longdesc']; 1258 } 1259 else 1260 { 1261 return false; 1262 } 1263 } 1264 2781 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 2782 { 2783 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2784 } 2785 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 2786 { 2787 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2788 } 2789 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 2790 { 2791 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2792 } 2793 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 2794 { 2795 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2796 } 2797 elseif ($return = $this->get_item_tags('', 'title')) 2798 { 2799 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2800 } 2801 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 2802 { 2803 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2804 } 2805 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 2806 { 2807 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2808 } 2809 else 2810 { 2811 return null; 2812 } 2813 } 2814 2815 function get_description($description_only = false) 2816 { 2817 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) 2818 { 2819 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2820 } 2821 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) 2822 { 2823 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2824 } 2825 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 2826 { 2827 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 2828 } 2829 elseif ($return = $this->get_item_tags('', 'description')) 2830 { 2831 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 2832 } 2833 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 2834 { 2835 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2836 } 2837 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 2838 { 2839 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2840 } 2841 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 2842 { 2843 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 2844 } 2845 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 2846 { 2847 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2848 } 2849 elseif (!$description_only) 2850 { 2851 return $this->get_content(true); 2852 } 2853 else 2854 { 2855 return null; 2856 } 2857 } 2858 2859 function get_content($content_only = false) 2860 { 2861 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) 2862 { 2863 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_content_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2864 } 2865 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) 2866 { 2867 return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0])); 2868 } 2869 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) 2870 { 2871 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 2872 } 2873 elseif (!$content_only) 2874 { 2875 return $this->get_description(true); 2876 } 2877 else 2878 { 2879 return null; 2880 } 2881 } 2882 1265 2883 function get_category($key = 0) 1266 2884 { 1267 2885 $categories = $this->get_categories(); 1268 if ( !empty($categories[$key]))2886 if (isset($categories[$key])) 1269 2887 { 1270 2888 return $categories[$key]; … … 1272 2890 else 1273 2891 { 1274 return false;1275 } 1276 } 1277 2892 return null; 2893 } 2894 } 2895 1278 2896 function get_categories() 1279 2897 { 1280 2898 $categories = array(); 1281 if (!empty($this->data['category'])) 1282 { 1283 $categories = array_merge($categories, $this->data['category']); 1284 } 1285 if (!empty($this->data['subject'])) 1286 { 1287 $categories = array_merge($categories, $this->data['subject']); 1288 } 1289 if (!empty($this->data['term'])) 1290 { 1291 $categories = array_merge($categories, $this->data['term']); 1292 } 2899 2900 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 2901 { 2902 $term = null; 2903 $scheme = null; 2904 $label = null; 2905 if (isset($category['attribs']['']['term'])) 2906 { 2907 $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 2908 } 2909 if (isset($category['attribs']['']['scheme'])) 2910 { 2911 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 2912 } 2913 if (isset($category['attribs']['']['label'])) 2914 { 2915 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 2916 } 2917 $categories[] =& new $this->feed->category_class($term, $scheme, $label); 2918 } 2919 foreach ((array) $this->get_item_tags('', 'category') as $category) 2920 { 2921 $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 2922 } 2923 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 2924 { 2925 $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 2926 } 2927 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 2928 { 2929 $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 2930 } 2931 1293 2932 if (!empty($categories)) 1294 2933 { 1295 return array_unique($categories);1296 } 1297 else 1298 { 1299 return false;1300 } 1301 } 1302 2934 return SimplePie_Misc::array_unique($categories); 2935 } 2936 else 2937 { 2938 return null; 2939 } 2940 } 2941 1303 2942 function get_author($key = 0) 1304 2943 { 1305 2944 $authors = $this->get_authors(); 1306 if ( !empty($authors[$key]))2945 if (isset($authors[$key])) 1307 2946 { 1308 2947 return $authors[$key]; … … 1310 2949 else 1311 2950 { 1312 return false; 1313 } 1314 } 1315 2951 return null; 2952 } 2953 } 2954 2955 /** 2956 * @todo Atom inheritance (item author, source author, feed author) 2957 */ 1316 2958 function get_authors() 1317 2959 { 1318 2960 $authors = array(); 1319 if (!empty($this->data['author'])) 1320 { 1321 $authors = array_merge($authors, $this->data['author']); 1322 } 1323 if (!empty($this->data['creator'])) 1324 { 1325 $authors = array_merge($authors, $this->data['creator']); 1326 } 2961 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 2962 { 2963 $name = null; 2964 $uri = null; 2965 $email = null; 2966 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 2967 { 2968 $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2969 } 2970 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 2971 { 2972 $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])); 2973 } 2974 if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 2975 { 2976 $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2977 } 2978 if ($name !== null || $email !== null || $uri !== null) 2979 { 2980 $authors[] =& new $this->feed->author_class($name, $uri, $email); 2981 } 2982 } 2983 if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 2984 { 2985 $name = null; 2986 $url = null; 2987 $email = null; 2988 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 2989 { 2990 $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2991 } 2992 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 2993 { 2994 $uri = $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])); 2995 } 2996 if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 2997 { 2998 $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2999 } 3000 if ($name !== null || $email !== null || $uri !== null) 3001 { 3002 $authors[] =& new $this->feed->author_class($name, $url, $email); 3003 } 3004 } 3005 if ($author = $this->get_item_tags('', 'author')) 3006 { 3007 $authors[] =& new $this->feed->author_class(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 3008 } 3009 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 3010 { 3011 $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 3012 } 3013 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 3014 { 3015 $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 3016 } 3017 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 3018 { 3019 $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null); 3020 } 3021 1327 3022 if (!empty($authors)) 1328 3023 { 1329 return array_unique($authors);1330 } 1331 else 1332 { 1333 return false;1334 } 1335 } 1336 3024 return SimplePie_Misc::array_unique($authors); 3025 } 3026 else 3027 { 3028 return null; 3029 } 3030 } 3031 1337 3032 function get_date($date_format = 'j F Y, g:i a') 1338 3033 { 1339 if (!empty($this->data['pubdate'])) 1340 { 1341 return date($date_format, $this->data['pubdate']); 1342 } 1343 else if (!empty($this->data['dc:date'])) 1344 { 1345 return date($date_format, $this->data['dc:date']); 1346 } 1347 else if (!empty($this->data['issued'])) 1348 { 1349 return date($date_format, $this->data['issued']); 1350 } 1351 else if (!empty($this->data['published'])) 1352 { 1353 return date($date_format, $this->data['published']); 1354 } 1355 else if (!empty($this->data['modified'])) 1356 { 1357 return date($date_format, $this->data['modified']); 1358 } 1359 else if (!empty($this->data['updated'])) 1360 { 1361 return date($date_format, $this->data['updated']); 1362 } 1363 else 1364 { 1365 return false; 1366 } 1367 } 1368 3034 if (!isset($this->data['date'])) 3035 { 3036 if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published')) 3037 { 3038 $this->data['date']['raw'] = $return[0]['data']; 3039 } 3040 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated')) 3041 { 3042 $this->data['date']['raw'] = $return[0]['data']; 3043 } 3044 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued')) 3045 { 3046 $this->data['date']['raw'] = $return[0]['data']; 3047 } 3048 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created')) 3049 { 3050 $this->data['date']['raw'] = $return[0]['data']; 3051 } 3052 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified')) 3053 { 3054 $this->data['date']['raw'] = $return[0]['data']; 3055 } 3056 elseif ($return = $this->get_item_tags('', 'pubDate')) 3057 { 3058 $this->data['date']['raw'] = $return[0]['data']; 3059 } 3060 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date')) 3061 { 3062 $this->data['date']['raw'] = $return[0]['data']; 3063 } 3064 elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date')) 3065 { 3066 $this->data['date']['raw'] = $return[0]['data']; 3067 } 3068 3069 if (!empty($this->data['date']['raw'])) 3070 { 3071 $this->data['date']['parsed'] = SimplePie_Misc::parse_date($this->data['date']['raw']); 3072 } 3073 else 3074 { 3075 $this->data['date'] = null; 3076 } 3077 } 3078 if ($this->data['date']) 3079 { 3080 $date_format = (string) $date_format; 3081 switch ($date_format) 3082 { 3083 case '': 3084 return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT); 3085 3086 case 'U': 3087 return $this->data['date']['parsed']; 3088 3089 default: 3090 return date($date_format, $this->data['date']['parsed']); 3091 } 3092 } 3093 else 3094 { 3095 return null; 3096 } 3097 } 3098 3099 function get_local_date($date_format = '%c') 3100 { 3101 if (!$date_format) 3102 { 3103 return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT); 3104 } 3105 elseif (($date = $this->get_date('U')) !== null) 3106 { 3107 return strftime($date_format, $date); 3108 } 3109 else 3110 { 3111 return null; 3112 } 3113 } 3114 1369 3115 function get_permalink() 1370 3116 { 1371 $link = $this->get_link( 0);3117 $link = $this->get_link(); 1372 3118 $enclosure = $this->get_enclosure(0); 1373 if ( !empty($link))3119 if ($link !== null) 1374 3120 { 1375 3121 return $link; 1376 3122 } 1377 else if (!empty($enclosure))3123 elseif ($enclosure !== null) 1378 3124 { 1379 3125 return $enclosure->get_link(); … … 1381 3127 else 1382 3128 { 1383 return false;1384 } 1385 } 1386 3129 return null; 3130 } 3131 } 3132 1387 3133 function get_link($key = 0, $rel = 'alternate') 1388 3134 { 1389 3135 $links = $this->get_links($rel); 1390 if ( !empty($links[$key]))3136 if ($links[$key] !== null) 1391 3137 { 1392 3138 return $links[$key]; … … 1394 3140 else 1395 3141 { 1396 return false;1397 } 1398 } 1399 3142 return null; 3143 } 3144 } 3145 1400 3146 function get_links($rel = 'alternate') 1401 3147 { 1402 if ($rel == 'alternate') 1403 { 1404 $links = array(); 1405 if (!empty($this->data['link'][$rel])) 1406 { 1407 $links = $this->data['link'][$rel]; 1408 } 1409 if (!empty($this->data['guid']['data']) && $this->data['guid']['permalink'] == true) 1410 { 1411 $links[] = $this->data['guid']['data']; 1412 } 1413 return $links; 1414 } 1415 else if (!empty($this->data['link'][$rel])) 1416 { 1417 return $this->data['link'][$rel]; 1418 } 1419 else 1420 { 1421 return false; 1422 } 1423 } 1424 1425 function get_enclosure($key = 0) 3148 if (!isset($this->data['links'])) 3149 { 3150 $this->data['links'] = array(); 3151 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link) 3152 { 3153 if (isset($link['attribs']['']['href'])) 3154 { 3155 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 3156 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 3157 3158 } 3159 } 3160 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link) 3161 { 3162 if (isset($link['attribs']['']['href'])) 3163 { 3164 $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 3165 $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 3166 } 3167 } 3168 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 3169 { 3170 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 3171 } 3172 if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 3173 { 3174 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 3175 } 3176 if ($links = $this->get_item_tags('', 'link')) 3177 { 3178 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 3179 } 3180 if ($links = $this->get_item_tags('', 'guid')) 3181 { 3182 if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) == 'true') 3183 { 3184 $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 3185 } 3186 } 3187 3188 $keys = array_keys($this->data['links']); 3189 foreach ($keys as $key) 3190 { 3191 if (SimplePie_Misc::is_isegment_nz_nc($key)) 3192 { 3193 if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 3194 { 3195 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 3196 $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 3197 } 3198 else 3199 { 3200 $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 3201 } 3202 } 3203 elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 3204 { 3205 $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 3206 } 3207 $this->data['links'][$key] = array_unique($this->data['links'][$key]); 3208 } 3209 } 3210 if (isset($this->data['links'][$rel])) 3211 { 3212 return $this->data['links'][$rel]; 3213 } 3214 else 3215 { 3216 return null; 3217 } 3218 } 3219 3220 /** 3221 * @todo Add ability to prefer one type of content over another (in a media group). 3222 */ 3223 function get_enclosure($key = 0, $prefer = null) 1426 3224 { 1427 3225 $enclosures = $this->get_enclosures(); 1428 if ( !empty($enclosures[$key]))3226 if (isset($enclosures[$key])) 1429 3227 { 1430 3228 return $enclosures[$key]; … … 1432 3230 else 1433 3231 { 1434 return false; 1435 } 1436 } 1437 3232 return null; 3233 } 3234 } 3235 3236 /** 3237 * Grabs all available enclosures (podcasts, etc.) 3238 * 3239 * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS. 3240 * 3241 * At this point, we're pretty much assuming that all enclosures for an item are the same content. Anything else is too complicated to properly support. 3242 * 3243 * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4). 3244 * @todo Add support for itunes: tags. These should be relatively simple compared to media:. 3245 * @todo If an element exists at a level, but it's value is empty, we should fall back to the value from the parent (if it exists). 3246 */ 1438 3247 function get_enclosures() 1439 3248 { 1440 $enclosures = array(); 1441 $links = $this->get_links('enclosure'); 3249 if (!isset($this->data['enclosures'])) 3250 { 3251 $this->data['enclosures'] = array(); 3252 3253 // Elements 3254 $captions_parent = null; 3255 $categories_parent = null; 3256 $copyrights_parent = null; 3257 $credits_parent = null; 3258 $description_parent = null; 3259 $duration_parent = null; 3260 $hashes_parent = null; 3261 $keywords_parent = null; 3262 $player_parent = null; 3263 $ratings_parent = null; 3264 $restrictions_parent = null; 3265 $thumbnails_parent = null; 3266 $title_parent = null; 3267 3268 // Let's do the channel and item-level ones first, and just re-use them if we need to. 3269 $parent = $this->get_feed(); 3270 3271 // CAPTIONS 3272 if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text')) 3273 { 3274 foreach ($captions as $caption) 3275 { 3276 $caption_type = null; 3277 $caption_lang = null; 3278 $caption_startTime = null; 3279 $caption_endTime = null; 3280 $caption_text = null; 3281 if (isset($caption['attribs']['']['type'])) 3282 { 3283 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 3284 } 3285 if (isset($caption['attribs']['']['lang'])) 3286 { 3287 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 3288 } 3289 if (isset($caption['attribs']['']['start'])) 3290 { 3291 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 3292 } 3293 if (isset($caption['attribs']['']['end'])) 3294 { 3295 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 3296 } 3297 if (isset($caption['data'])) 3298 { 3299 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3300 } 3301 $captions_parent[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 3302 } 3303 } 3304 elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text')) 3305 { 3306 foreach ($captions as $caption) 3307 { 3308 $caption_type = null; 3309 $caption_lang = null; 3310 $caption_startTime = null; 3311 $caption_endTime = null; 3312 $caption_text = null; 3313 if (isset($caption['attribs']['']['type'])) 3314 { 3315 $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 3316 } 3317 if (isset($caption['attribs']['']['lang'])) 3318 { 3319 $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT); 3320 } 3321 if (isset($caption['attribs']['']['start'])) 3322 { 3323 $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT); 3324 } 3325 if (isset($caption['attribs']['']['end'])) 3326 { 3327 $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT); 3328 } 3329 if (isset($caption['data'])) 3330 { 3331 $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3332 } 3333 $captions_parent[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text); 3334 } 3335 } 3336 if (is_array($captions_parent)) 3337 { 3338 $captions_parent = array_values(SimplePie_Misc::array_unique($captions_parent)); 3339 } 3340 3341 // CATEGORIES 3342 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category) 3343 { 3344 $term = null; 3345 $scheme = null; 3346 $label = null; 3347 if (isset($category['data'])) 3348 { 3349 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3350 } 3351 if (isset($category['attribs']['']['scheme'])) 3352 { 3353 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 3354 } 3355 else 3356 { 3357 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 3358 } 3359 if (isset($category['attribs']['']['label'])) 3360 { 3361 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 3362 } 3363 $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label); 3364 } 3365 foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category) 3366 { 3367 $term = null; 3368 $scheme = null; 3369 $label = null; 3370 if (isset($category['data'])) 3371 { 3372 $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3373 } 3374 if (isset($category['attribs']['']['scheme'])) 3375 { 3376 $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 3377 } 3378 else 3379 { 3380 $scheme = 'http://search.yahoo.com/mrss/category_schema'; 3381 } 3382 if (isset($category['attribs']['']['label'])) 3383 { 3384 $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 3385 } 3386 $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label); 3387 } 3388 foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category) 3389 { 3390 $term = null; 3391 $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; 3392 $label = null; 3393 if (isset($category['attribs']['']['text'])) 3394 { 3395 $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT); 3396 } 3397 $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label); 3398 3399 if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'])) 3400 { 3401 foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory) 3402 { 3403 if (isset($subcategory['attribs']['']['text'])) 3404 { 3405 $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT); 3406 } 3407 $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label); 3408 } 3409 } 3410 } 3411 if (is_array($categories_parent)) 3412 { 3413 $categories_parent = array_values(SimplePie_Misc::array_unique($categories_parent)); 3414 } 3415 3416 // COPYRIGHT 3417 if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright')) 3418 { 3419 $copyright_url = null; 3420 $copyright_label = null; 3421 if (isset($copyright[0]['attribs']['']['url'])) 3422 { 3423 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 3424 } 3425 if (isset($copyright[0]['data'])) 3426 { 3427 $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3428 } 3429 $copyrights_parent =& new $this->feed->copyright_class($copyright_url, $copyright_label); 3430 } 3431 elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright')) 3432 { 3433 $copyright_url = null; 3434 $copyright_label = null; 3435 if (isset($copyright[0]['attribs']['']['url'])) 3436 { 3437 $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT); 3438 } 3439 if (isset($copyright[0]['data'])) 3440 { 3441 $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3442 } 3443 $copyrights_parent =& new $this->feed->copyright_class($copyright_url, $copyright_label); 3444 } 3445 3446 // CREDITS 3447 if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit')) 3448 { 3449 foreach ($credits as $credit) 3450 { 3451 $credit_role = null; 3452 $credit_scheme = null; 3453 $credit_name = null; 3454 if (isset($credit['attribs']['']['role'])) 3455 { 3456 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 3457 } 3458 if (isset($credit['attribs']['']['scheme'])) 3459 { 3460 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 3461 } 3462 else 3463 { 3464 $credit_scheme = 'urn:ebu'; 3465 } 3466 if (isset($credit['data'])) 3467 { 3468 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3469 } 3470 $credits_parent[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 3471 } 3472 } 3473 elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit')) 3474 { 3475 foreach ($credits as $credit) 3476 { 3477 $credit_role = null; 3478 $credit_scheme = null; 3479 $credit_name = null; 3480 if (isset($credit['attribs']['']['role'])) 3481 { 3482 $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT); 3483 } 3484 if (isset($credit['attribs']['']['scheme'])) 3485 { 3486 $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 3487 } 3488 else 3489 { 3490 $credit_scheme = 'urn:ebu'; 3491 } 3492 if (isset($credit['data'])) 3493 { 3494 $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3495 } 3496 $credits_parent[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name); 3497 } 3498 } 3499 if (is_array($credits_parent)) 3500 { 3501 $credits_parent = array_values(SimplePie_Misc::array_unique($credits_parent)); 3502 } 3503 3504 // DESCRIPTION 3505 if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description')) 3506 { 3507 if (isset($description_parent[0]['data'])) 3508 { 3509 $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3510 } 3511 } 3512 elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description')) 3513 { 3514 if (isset($description_parent[0]['data'])) 3515 { 3516 $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3517 } 3518 } 3519 3520 // DURATION 3521 if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration')) 3522 { 3523 $seconds = null; 3524 $minutes = null; 3525 $hours = null; 3526 if (isset($duration_parent[0]['data'])) 3527 { 3528 $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 3529 if (sizeof($temp) > 0) 3530 { 3531 (int) $seconds = array_pop($temp); 3532 } 3533 if (sizeof($temp) > 0) 3534 { 3535 (int) $minutes = array_pop($temp); 3536 $seconds += $minutes * 60; 3537 } 3538 if (sizeof($temp) > 0) 3539 { 3540 (int) $hours = array_pop($temp); 3541 $seconds += $hours * 3600; 3542 } 3543 unset($temp); 3544 $duration_parent = $seconds; 3545 } 3546 } 3547 3548 // HASHES 3549 if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash')) 3550 { 3551 foreach ($hashes_iterator as $hash) 3552 { 3553 $value = null; 3554 $algo = null; 3555 if (isset($hash['data'])) 3556 { 3557 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3558 } 3559 if (isset($hash['attribs']['']['algo'])) 3560 { 3561 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 3562 } 3563 else 3564 { 3565 $algo = 'md5'; 3566 } 3567 $hashes_parent[] = $algo.':'.$value; 3568 } 3569 } 3570 elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash')) 3571 { 3572 foreach ($hashes_iterator as $hash) 3573 { 3574 $value = null; 3575 $algo = null; 3576 if (isset($hash['data'])) 3577 { 3578 $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3579 } 3580 if (isset($hash['attribs']['']['algo'])) 3581 { 3582 $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT); 3583 } 3584 else 3585 { 3586 $algo = 'md5'; 3587 } 3588 $hashes_parent[] = $algo.':'.$value; 3589 } 3590 } 3591 if (is_array($hashes_parent)) 3592 { 3593 $hashes_parent = array_values(SimplePie_Misc::array_unique($hashes_parent)); 3594 } 3595 3596 // KEYWORDS 3597 if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords')) 3598 { 3599 if (isset($keywords[0]['data'])) 3600 { 3601 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 3602 foreach ($temp as $word) 3603 { 3604 $keywords_parent[] = trim($word); 3605 } 3606 } 3607 unset($temp); 3608 } 3609 elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords')) 3610 { 3611 if (isset($keywords[0]['data'])) 3612 { 3613 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 3614 foreach ($temp as $word) 3615 { 3616 $keywords_parent[] = trim($word); 3617 } 3618 } 3619 unset($temp); 3620 } 3621 elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords')) 3622 { 3623 if (isset($keywords[0]['data'])) 3624 { 3625 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 3626 foreach ($temp as $word) 3627 { 3628 $keywords_parent[] = trim($word); 3629 } 3630 } 3631 unset($temp); 3632 } 3633 elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords')) 3634 { 3635 if (isset($keywords[0]['data'])) 3636 { 3637 $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)); 3638 foreach ($temp as $word) 3639 { 3640 $keywords_parent[] = trim($word); 3641 } 3642 } 3643 unset($temp); 3644 } 3645 if (is_array($keywords_parent)) 3646 { 3647 $keywords_parent = array_values(SimplePie_Misc::array_unique($keywords_parent)); 3648 } 3649 3650 // PLAYER 3651 if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player')) 3652 { 3653 if (isset($player_parent[0]['attribs']['']['url'])) 3654 { 3655 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 3656 } 3657 } 3658 elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player')) 3659 { 3660 if (isset($player_parent[0]['attribs']['']['url'])) 3661 { 3662 $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 3663 } 3664 } 3665 3666 // RATINGS 3667 if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating')) 3668 { 3669 foreach ($ratings as $rating) 3670 { 3671 $rating_scheme = null; 3672 $rating_value = null; 3673 if (isset($rating['attribs']['']['scheme'])) 3674 { 3675 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 3676 } 3677 else 3678 { 3679 $rating_scheme = 'urn:simple'; 3680 } 3681 if (isset($rating['data'])) 3682 { 3683 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3684 } 3685 $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value); 3686 } 3687 } 3688 elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit')) 3689 { 3690 foreach ($ratings as $rating) 3691 { 3692 $rating_scheme = 'urn:itunes'; 3693 $rating_value = null; 3694 if (isset($rating['data'])) 3695 { 3696 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3697 } 3698 $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value); 3699 } 3700 } 3701 elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating')) 3702 { 3703 foreach ($ratings as $rating) 3704 { 3705 $rating_scheme = null; 3706 $rating_value = null; 3707 if (isset($rating['attribs']['']['scheme'])) 3708 { 3709 $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 3710 } 3711 else 3712 { 3713 $rating_scheme = 'urn:simple'; 3714 } 3715 if (isset($rating['data'])) 3716 { 3717 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3718 } 3719 $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value); 3720 } 3721 } 3722 elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit')) 3723 { 3724 foreach ($ratings as $rating) 3725 { 3726 $rating_scheme = 'urn:itunes'; 3727 $rating_value = null; 3728 if (isset($rating['data'])) 3729 { 3730 $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3731 } 3732 $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value); 3733 } 3734 } 3735 if (is_array($ratings_parent)) 3736 { 3737 $ratings_parent = array_values(SimplePie_Misc::array_unique($ratings_parent)); 3738 } 3739 3740 // RESTRICTIONS 3741 if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction')) 3742 { 3743 foreach ($restrictions as $restriction) 3744 { 3745 $restriction_relationship = null; 3746 $restriction_type = null; 3747 $restriction_value = null; 3748 if (isset($restriction['attribs']['']['relationship'])) 3749 { 3750 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 3751 } 3752 if (isset($restriction['attribs']['']['type'])) 3753 { 3754 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 3755 } 3756 if (isset($restriction['data'])) 3757 { 3758 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3759 } 3760 $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 3761 } 3762 } 3763 elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block')) 3764 { 3765 foreach ($restrictions as $restriction) 3766 { 3767 $restriction_relationship = 'allow'; 3768 $restriction_type = null; 3769 $restriction_value = 'itunes'; 3770 if (isset($restriction['data']) && strtolower($restriction['data']) == 'yes') 3771 { 3772 $restriction_relationship = 'deny'; 3773 } 3774 $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 3775 } 3776 } 3777 elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction')) 3778 { 3779 foreach ($restrictions as $restriction) 3780 { 3781 $restriction_relationship = null; 3782 $restriction_type = null; 3783 $restriction_value = null; 3784 if (isset($restriction['attribs']['']['relationship'])) 3785 { 3786 $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT); 3787 } 3788 if (isset($restriction['attribs']['']['type'])) 3789 { 3790 $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); 3791 } 3792 if (isset($restriction['data'])) 3793 { 3794 $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3795 } 3796 $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 3797 } 3798 } 3799 elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block')) 3800 { 3801 foreach ($restrictions as $restriction) 3802 { 3803 $restriction_relationship = 'allow'; 3804 $restriction_type = null; 3805 $restriction_value = 'itunes'; 3806 if (isset($restriction['data']) && strtolower($restriction['data']) == 'yes') 3807 { 3808 $restriction_relationship = 'deny'; 3809 } 3810 $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value); 3811 } 3812 } 3813 if (is_array($restrictions_parent)) 3814 { 3815 $restrictions_parent = array_values(SimplePie_Misc::array_unique($restrictions_parent)); 3816 } 3817 3818 // THUMBNAILS 3819 if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) 3820 { 3821 foreach ($thumbnails as $thumbnail) 3822 { 3823 if (isset($thumbnail['attribs']['']['url'])) 3824 { 3825 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 3826 } 3827 } 3828 } 3829 elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail')) 3830 { 3831 foreach ($thumbnails as $thumbnail) 3832 { 3833 if (isset($thumbnail['attribs']['']['url'])) 3834 { 3835 $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI); 3836 } 3837 } 3838 } 3839 3840 // TITLES 3841 if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title')) 3842 { 3843 if (isset($title_parent[0]['data'])) 3844 { 3845 $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3846 } 3847 } 3848 elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title')) 3849 { 3850 if (isset($title_parent[0]['data'])) 3851 { 3852 $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 3853 } 3854 } 3855 3856 // Clear the memory 3857 unset($parent); 3858 3859 // If we have media:group tags, loop through them. 3860 foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group) 3861 { 3862 // If we have media:content tags, loop through them. 3863 foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content) 3864 { 3865 if (isset($content['attribs']['']['url'])) 3866 { 3867 // Attributes 3868 $bitrate = null; 3869 $channels = null; 3870 $duration = null; 3871 $expression = null; 3872 $framerate = null; 3873 $height = null; 3874 $javascript = null; 3875 $lang = null; 3876 $length = null; 3877 $medium = null; 3878 $samplingrate = null; 3879 $type = null; 3880 $url = null; 3881 $width = null; 3882 3883 // Elements 3884 $captions = null; 3885 $categories = null; 3886 $copyrights = null; 3887 $credits = null; 3888 $description = null; 3889 &