Changeset 47733 for trunk/src/wp-includes/class-simplepie.php
- Timestamp:
- 05/01/2020 02:24:42 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-simplepie.php
r47198 r47733 41 41 * Takes the hard work out of managing a complete RSS/Atom solution. 42 42 * 43 * Copyright (c) 2004-201 2, Ryan Parman, GeoffreySneddon, Ryan McCue, and contributors43 * Copyright (c) 2004-2017, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 44 44 * All rights reserved. 45 45 * … … 69 69 * 70 70 * @package SimplePie 71 * @version 1. 3.172 * @copyright 2004-201 2 Ryan Parman, GeoffreySneddon, Ryan McCue71 * @version 1.5.5 72 * @copyright 2004-2017 Ryan Parman, Sam Sneddon, Ryan McCue 73 73 * @author Ryan Parman 74 * @author GeoffreySneddon74 * @author Sam Sneddon 75 75 * @author Ryan McCue 76 76 * @link http://simplepie.org/ SimplePie … … 86 86 * SimplePie Version 87 87 */ 88 define('SIMPLEPIE_VERSION', '1. 3.1');88 define('SIMPLEPIE_VERSION', '1.5.5'); 89 89 90 90 /** … … 482 482 483 483 /** 484 * @var string Original feed URL, or new feed URL iff HTTP 301 Moved Permanently 485 * @see SimplePie::subscribe_url() 486 * @access private 487 */ 488 public $permanent_url = null; 489 490 /** 484 491 * @var object Instance of SimplePie_File to use as a feed 485 492 * @see SimplePie::set_file() … … 501 508 */ 502 509 public $timeout = 10; 510 511 /** 512 * @var array Custom curl options 513 * @see SimplePie::set_curl_options() 514 * @access private 515 */ 516 public $curl_options = array(); 503 517 504 518 /** … … 526 540 527 541 /** 542 * @var bool Force SimplePie to fallback to expired cache, if enabled, 543 * when feed is unavailable. 544 * @see SimplePie::force_cache_fallback() 545 * @access private 546 */ 547 public $force_cache_fallback = false; 548 549 /** 528 550 * @var int Cache duration (in seconds) 529 551 * @see SimplePie::set_cache_duration() … … 631 653 632 654 /** 655 * @var bool Stores if last-modified and/or etag headers were sent with the 656 * request when checking a feed. 657 */ 658 public $check_modified = false; 659 660 /** 633 661 * @var array Stores the default attributes to be stripped by strip_attributes(). 634 662 * @see SimplePie::strip_attributes() … … 638 666 639 667 /** 668 * @var array Stores the default attributes to add to different tags by add_attributes(). 669 * @see SimplePie::add_attributes() 670 * @access private 671 */ 672 public $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none')); 673 674 /** 640 675 * @var array Stores the default tags to be stripped by strip_htmltags(). 641 676 * @see SimplePie::strip_htmltags() … … 643 678 */ 644 679 public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); 680 681 /** 682 * @var bool Should we throw exceptions, or use the old-style error property? 683 * @access private 684 */ 685 public $enable_exceptions = false; 645 686 646 687 /** … … 660 701 public function __construct() 661 702 { 662 if (version_compare(PHP_VERSION, '5. 2', '<'))663 { 664 trigger_error('P HP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2or newer.');703 if (version_compare(PHP_VERSION, '5.6', '<')) 704 { 705 trigger_error('Please upgrade to PHP 5.6 or newer.'); 665 706 die(); 666 707 } … … 673 714 { 674 715 $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 675 trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_ location() directly.', $level);716 trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', $level); 676 717 677 718 $args = func_get_args(); … … 701 742 public function __destruct() 702 743 { 703 if ( (version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))744 if (!gc_enabled()) 704 745 { 705 746 if (!empty($this->data['items'])) … … 764 805 { 765 806 $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1)); 807 $this->permanent_url = $this->feed_url; 766 808 } 767 809 } … … 778 820 { 779 821 $this->feed_url = $file->url; 822 $this->permanent_url = $this->feed_url; 780 823 $this->file =& $file; 781 824 return true; … … 803 846 804 847 /** 805 * Set the thedefault timeout for fetching remote feeds848 * Set the default timeout for fetching remote feeds 806 849 * 807 850 * This allows you to change the maximum time the feed's server to respond … … 817 860 818 861 /** 862 * Set custom curl options 863 * 864 * This allows you to change default curl options 865 * 866 * @since 1.0 Beta 3 867 * @param array $curl_options Curl options to add to default settings 868 */ 869 public function set_curl_options(array $curl_options = array()) 870 { 871 $this->curl_options = $curl_options; 872 } 873 874 /** 819 875 * Force SimplePie to use fsockopen() instead of cURL 820 876 * … … 839 895 { 840 896 $this->cache = (bool) $enable; 897 } 898 899 /** 900 * SimplePie to continue to fall back to expired cache, if enabled, when 901 * feed is unavailable. 902 * 903 * This tells SimplePie to ignore any file errors and fall back to cache 904 * instead. This only works if caching is enabled and cached content 905 * still exists. 906 907 * @param bool $enable Force use of cache on fail. 908 */ 909 public function force_cache_fallback($enable = false) 910 { 911 $this->force_cache_fallback= (bool) $enable; 841 912 } 842 913 … … 1109 1180 $this->strip_htmltags(false); 1110 1181 $this->strip_attributes(false); 1182 $this->add_attributes(false); 1111 1183 $this->set_image_handler(false); 1112 1184 } … … 1155 1227 } 1156 1228 1229 public function add_attributes($attribs = '') 1230 { 1231 if ($attribs === '') 1232 { 1233 $attribs = $this->add_attributes; 1234 } 1235 $this->sanitize->add_attributes($attribs); 1236 } 1237 1157 1238 /** 1158 1239 * Set the output encoding … … 1160 1241 * Allows you to override SimplePie's output to match that of your webpage. 1161 1242 * This is useful for times when your webpages are not being served as 1162 * UTF-8. 1243 * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and 1163 1244 * is similar to {@see set_input_encoding()}. 1164 1245 * 1165 1246 * It should be noted, however, that not all character encodings can support 1166 * all characters. 1247 * all characters. If your page is being served as ISO-8859-1 and you try 1167 1248 * to display a Japanese feed, you'll likely see garbled characters. 1168 1249 * Because of this, it is highly recommended to ensure that your webpages … … 1206 1287 * Set the handler to enable the display of cached images. 1207 1288 * 1208 * @param str $page Web-accessible path to the handler_image.php file.1209 * @param str $qs The query string that the value should be passed to.1289 * @param string $page Web-accessible path to the handler_image.php file. 1290 * @param string $qs The query string that the value should be passed to. 1210 1291 */ 1211 1292 public function set_image_handler($page = false, $qs = 'i') … … 1232 1313 1233 1314 /** 1315 * Enable throwing exceptions 1316 * 1317 * @param boolean $enable Should we throw exceptions, or use the old-style error property? 1318 */ 1319 public function enable_exceptions($enable = true) 1320 { 1321 $this->enable_exceptions = $enable; 1322 } 1323 1324 /** 1234 1325 * Initialize the feed object 1235 1326 * 1236 * This is what makes everything happen. Period.This is where all of the1327 * This is what makes everything happen. Period. This is where all of the 1237 1328 * configuration options get processed, feeds are fetched, cached, and 1238 1329 * parsed, and all of that other good stuff. … … 1245 1336 if (!extension_loaded('xml') || !extension_loaded('pcre')) 1246 1337 { 1338 $this->error = 'XML or PCRE extensions not loaded!'; 1247 1339 return false; 1248 1340 } … … 1264 1356 } 1265 1357 1358 // The default sanitize class gets set in the constructor, check if it has 1359 // changed. 1360 if ($this->registry->get_class('Sanitize') !== 'SimplePie_Sanitize') { 1361 $this->sanitize = $this->registry->create('Sanitize'); 1362 } 1266 1363 if (method_exists($this->sanitize, 'set_registry')) 1267 1364 { … … 1272 1369 // Pass the classes in for legacy support; new classes should use the registry instead 1273 1370 $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache')); 1274 $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen );1371 $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options); 1275 1372 1276 1373 if (!empty($this->multifeed_url)) … … 1301 1398 $this->error = null; 1302 1399 $this->data = array(); 1400 $this->check_modified = false; 1303 1401 $this->multifeed_objects = array(); 1304 1402 $cache = false; … … 1311 1409 if ($this->cache && $parsed_feed_url['scheme'] !== '') 1312 1410 { 1313 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc')); 1411 $url = $this->feed_url . ($this->force_feed ? '#force_feed' : ''); 1412 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $url), 'spc')); 1314 1413 } 1315 1414 … … 1326 1425 } 1327 1426 1427 // Empty response check 1428 if(empty($this->raw_data)){ 1429 $this->error = "A feed could not be found at `$this->feed_url`. Empty body."; 1430 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 1431 return false; 1432 } 1433 1328 1434 // Set up array of possible encodings 1329 1435 $encodings = array(); … … 1332 1438 if ($this->input_encoding !== false) 1333 1439 { 1334 $encodings[] = $this->input_encoding;1440 $encodings[] = strtoupper($this->input_encoding); 1335 1441 } 1336 1442 … … 1354 1460 if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 1355 1461 { 1356 $encodings[] = $charset[1];1462 $encodings[] = strtoupper($charset[1]); 1357 1463 } 1358 1464 $encodings[] = 'US-ASCII'; … … 1361 1467 elseif (substr($sniffed, 0, 5) === 'text/') 1362 1468 { 1363 $encodings[] = 'U S-ASCII';1469 $encodings[] = 'UTF-8'; 1364 1470 } 1365 1471 } … … 1383 1489 1384 1490 // If it's parsed fine 1385 if ($parser->parse($utf8_data, 'UTF-8' ))1491 if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url)) 1386 1492 { 1387 1493 $this->data = $parser->get_data(); 1388 1494 if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) 1389 1495 { 1390 $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";1496 $this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed."; 1391 1497 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 1392 1498 return false; … … 1402 1508 if ($cache && !$cache->save($this)) 1403 1509 { 1404 trigger_error("$this->cache_location is not writ eable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);1510 trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); 1405 1511 } 1406 1512 return true; … … 1412 1518 { 1413 1519 // We have an error, just set SimplePie_Misc::error to it and quit 1414 $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column()); 1520 $this->error = $this->feed_url; 1521 $this->error .= sprintf(' is invalid XML, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column()); 1415 1522 } 1416 1523 else 1417 1524 { 1418 $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.'; 1525 $this->error = 'The data could not be converted to UTF-8.'; 1526 if (!extension_loaded('mbstring') && !extension_loaded('iconv') && !class_exists('\UConverter')) { 1527 $this->error .= ' You MUST have either the iconv, mbstring or intl (PHP 5.5+) extension installed and enabled.'; 1528 } else { 1529 $missingExtensions = array(); 1530 if (!extension_loaded('iconv')) { 1531 $missingExtensions[] = 'iconv'; 1532 } 1533 if (!extension_loaded('mbstring')) { 1534 $missingExtensions[] = 'mbstring'; 1535 } 1536 if (!class_exists('\UConverter')) { 1537 $missingExtensions[] = 'intl (PHP 5.5+)'; 1538 } 1539 $this->error .= ' Try installing/enabling the ' . implode(' or ', $missingExtensions) . ' extension.'; 1540 } 1419 1541 } 1420 1542 … … 1472 1594 elseif ($cache->mtime() + $this->cache_duration < time()) 1473 1595 { 1474 // If we have last-modified and/or etag set 1596 // Want to know if we tried to send last-modified and/or etag headers 1597 // when requesting this file. (Note that it's up to the file to 1598 // support this, but we don't always send the headers either.) 1599 $this->check_modified = true; 1475 1600 if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) 1476 1601 { … … 1487 1612 } 1488 1613 1489 $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen ));1614 $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); 1490 1615 1491 1616 if ($file->success) … … 1493 1618 if ($file->status_code === 304) 1494 1619 { 1620 // Set raw_data to false here too, to signify that the cache 1621 // is still valid. 1622 $this->raw_data = false; 1495 1623 $cache->touch(); 1496 1624 return true; … … 1499 1627 else 1500 1628 { 1629 $this->check_modified = false; 1630 if($this->force_cache_fallback) 1631 { 1632 $cache->touch(); 1633 return true; 1634 } 1635 1501 1636 unset($file); 1502 1637 } … … 1529 1664 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', 1530 1665 ); 1531 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen ));1666 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); 1532 1667 } 1533 1668 } … … 1542 1677 { 1543 1678 // Check if the supplied URL is a feed, if it isn't, look for it. 1544 $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds ));1679 $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds, $this->force_fsockopen, $this->curl_options)); 1545 1680 1546 1681 if (!$locate->is_feed($file)) 1547 1682 { 1548 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched1549 unset($file);1683 $copyStatusCode = $file->status_code; 1684 $copyContentType = $file->headers['content-type']; 1550 1685 try 1551 1686 { 1552 if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) 1687 $microformats = false; 1688 if (class_exists('DOMXpath') && function_exists('Mf2\parse')) { 1689 $doc = new DOMDocument(); 1690 @$doc->loadHTML($file->body); 1691 $xpath = new DOMXpath($doc); 1692 // Check for both h-feed and h-entry, as both a feed with no entries 1693 // and a list of entries without an h-feed wrapper are both valid. 1694 $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '. 1695 'contains(concat(" ", @class, " "), " h-entry ")]'; 1696 $result = $xpath->query($query); 1697 $microformats = $result->length !== 0; 1698 } 1699 // Now also do feed discovery, but if microformats were found don't 1700 // overwrite the current value of file. 1701 $discovered = $locate->find($this->autodiscovery, 1702 $this->all_discovered_feeds); 1703 if ($microformats) 1553 1704 { 1554 $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."; 1555 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 1556 return false; 1705 if ($hub = $locate->get_rel_link('hub')) 1706 { 1707 $self = $locate->get_rel_link('self'); 1708 $this->store_links($file, $hub, $self); 1709 } 1710 // Push the current file onto all_discovered feeds so the user can 1711 // be shown this as one of the options. 1712 if (isset($this->all_discovered_feeds)) { 1713 $this->all_discovered_feeds[] = $file; 1714 } 1557 1715 } 1716 else 1717 { 1718 if ($discovered) 1719 { 1720 $file = $discovered; 1721 } 1722 else 1723 { 1724 // We need to unset this so that if SimplePie::set_file() has 1725 // been called that object is untouched 1726 unset($file); 1727 $this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`"; 1728 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 1729 return false; 1730 } 1731 } 1558 1732 } 1559 1733 catch (SimplePie_Exception $e) 1560 1734 { 1735 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched 1736 unset($file); 1561 1737 // This is usually because DOMDocument doesn't exist 1562 1738 $this->error = $e->getMessage(); … … 1569 1745 if (!$cache->save($this)) 1570 1746 { 1571 trigger_error("$this->cache_location is not writ eable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);1747 trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); 1572 1748 } 1573 1749 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc')); 1574 1750 } 1575 $this->feed_url = $file->url;1576 }1751 } 1752 $this->feed_url = $file->url; 1577 1753 $locate = null; 1578 1754 } 1579 1755 1580 1756 $this->raw_data = $file->body; 1581 1757 $this->permanent_url = $file->permanent_url; 1582 1758 $headers = $file->headers; 1583 1759 $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file)); … … 1588 1764 1589 1765 /** 1590 * Get the error message for the occur red error.1766 * Get the error message for the occured error 1591 1767 * 1592 1768 * @return string|array Error message, or array of messages for multifeeds … … 1766 1942 * Get the URL for the feed 1767 1943 * 1768 * May or may not be different from the URL passed to {@see set_feed_url()}, 1769 * depending on whether auto-discovery was used. 1944 * When the 'permanent' mode is enabled, returns the original feed URL, 1945 * except in the case of an `HTTP 301 Moved Permanently` status response, 1946 * in which case the location of the first redirection is returned. 1947 * 1948 * When the 'permanent' mode is disabled (default), 1949 * may or may not be different from the URL passed to {@see set_feed_url()}, 1950 * depending on whether auto-discovery was used, and whether there were 1951 * any redirects along the way. 1770 1952 * 1771 1953 * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.) 1772 * @todo If we have a perm redirect we should return the new URL 1773 * @todo When we make the above change, let's support <itunes:new-feed-url> as well 1954 * @todo Support <itunes:new-feed-url> 1774 1955 * @todo Also, |atom:link|@rel=self 1956 * @param bool $permanent Permanent mode to return only the original URL or the first redirection 1957 * iff it is a 301 redirection 1775 1958 * @return string|null 1776 1959 */ 1777 public function subscribe_url() 1778 { 1779 if ($this->feed_url !== null) 1780 { 1781 return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); 1960 public function subscribe_url($permanent = false) 1961 { 1962 if ($permanent) 1963 { 1964 if ($this->permanent_url !== null) 1965 { 1966 // sanitize encodes ampersands which are required when used in a url. 1967 return str_replace('&', '&', 1968 $this->sanitize($this->permanent_url, 1969 SIMPLEPIE_CONSTRUCT_IRI)); 1970 } 1782 1971 } 1783 1972 else 1784 1973 { 1785 return null; 1786 } 1974 if ($this->feed_url !== null) 1975 { 1976 return str_replace('&', '&', 1977 $this->sanitize($this->feed_url, 1978 SIMPLEPIE_CONSTRUCT_IRI)); 1979 } 1980 } 1981 return null; 1787 1982 } 1788 1983 … … 1981 2176 return $this->get_link(); 1982 2177 } 1983 else 1984 { 1985 return $this->subscribe_url(); 1986 } 2178 2179 return $this->subscribe_url(); 1987 2180 } 1988 2181 … … 1999 2192 public function sanitize($data, $type, $base = '') 2000 2193 { 2001 return $this->sanitize->sanitize($data, $type, $base); 2194 try 2195 { 2196 return $this->sanitize->sanitize($data, $type, $base); 2197 } 2198 catch (SimplePie_Exception $e) 2199 { 2200 if (!$this->enable_exceptions) 2201 { 2202 $this->error = $e->getMessage(); 2203 $this->registry->call('Misc', 'error', array($this->error, E_USER_WARNING, $e->getFile(), $e->getLine())); 2204 return ''; 2205 } 2206 2207 throw $e; 2208 } 2002 2209 } 2003 2210 … … 2040 2247 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2041 2248 } 2042 else 2043 { 2044 return null; 2045 } 2249 2250 return null; 2046 2251 } 2047 2252 … … 2050 2255 * 2051 2256 * @since Unknown 2052 * @param int $key The category that you want to return. 2257 * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1 2053 2258 * @return SimplePie_Category|null 2054 2259 */ … … 2060 2265 return $categories[$key]; 2061 2266 } 2062 else 2063 { 2064 return null; 2065 } 2267 2268 return null; 2066 2269 } 2067 2270 … … 2125 2328 return array_unique($categories); 2126 2329 } 2127 else 2128 { 2129 return null; 2130 } 2330 2331 return null; 2131 2332 } 2132 2333 … … 2135 2336 * 2136 2337 * @since 1.1 2137 * @param int $key The author that you want to return. 2338 * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1 2138 2339 * @return SimplePie_Author|null 2139 2340 */ … … 2145 2346 return $authors[$key]; 2146 2347 } 2147 else 2148 { 2149 return null; 2150 } 2348 2349 return null; 2151 2350 } 2152 2351 … … 2223 2422 return array_unique($authors); 2224 2423 } 2225 else 2226 { 2227 return null; 2228 } 2424 2425 return null; 2229 2426 } 2230 2427 … … 2233 2430 * 2234 2431 * @since 1.1 2235 * @param int $key The contrbutor that you want to return. 2432 * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1 2236 2433 * @return SimplePie_Author|null 2237 2434 */ … … 2243 2440 return $contributors[$key]; 2244 2441 } 2245 else 2246 { 2247 return null; 2248 } 2442 2443 return null; 2249 2444 } 2250 2445 … … 2309 2504 return array_unique($contributors); 2310 2505 } 2311 else 2312 { 2313 return null; 2314 } 2506 2507 return null; 2315 2508 } 2316 2509 … … 2319 2512 * 2320 2513 * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8) 2321 * @param int $key The link that you want to return. 2514 * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1 2322 2515 * @param string $rel The relationship of the link to return 2323 2516 * @return string|null Link URL … … 2330 2523 return $links[$key]; 2331 2524 } 2332 else 2333 { 2334 return null; 2335 } 2525 2526 return null; 2336 2527 } 2337 2528 … … 2425 2616 } 2426 2617 2427 if (isset($this->data['links'][$rel])) 2618 if (isset($this->data['headers']['link']) && 2619 preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/', 2620 $this->data['headers']['link'], $match)) 2621 { 2622 return array($match[1]); 2623 } 2624 else if (isset($this->data['links'][$rel])) 2428 2625 { 2429 2626 return $this->data['links'][$rel]; 2430 2627 } 2431 else 2432 { 2433 return null; 2434 } 2628 2629 return null; 2435 2630 } 2436 2631 … … 2487 2682 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 2488 2683 } 2489 else 2490 { 2491 return null; 2492 } 2684 2685 return null; 2493 2686 } 2494 2687 … … 2523 2716 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2524 2717 } 2525 else 2526 { 2527 return null; 2528 } 2718 2719 return null; 2529 2720 } 2530 2721 … … 2567 2758 return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); 2568 2759 } 2569 else 2570 { 2571 return null; 2572 } 2760 2761 return null; 2573 2762 } 2574 2763 … … 2596 2785 return (float) $match[1]; 2597 2786 } 2598 else 2599 { 2600 return null; 2601 } 2787 2788 return null; 2602 2789 } 2603 2790 … … 2628 2815 return (float) $match[2]; 2629 2816 } 2630 else 2631 { 2632 return null; 2633 } 2817 2818 return null; 2634 2819 } 2635 2820 … … 2665 2850 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 2666 2851 } 2667 else 2668 { 2669 return null; 2670 } 2852 2853 return null; 2671 2854 } 2672 2855 … … 2708 2891 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2709 2892 } 2710 else 2711 { 2712 return null; 2713 } 2893 2894 return null; 2714 2895 } 2715 2896 … … 2740 2921 return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 2741 2922 } 2742 else 2743 { 2744 return null; 2745 } 2923 2924 return null; 2746 2925 } 2747 2926 … … 2766 2945 return 88.0; 2767 2946 } 2768 else 2769 { 2770 return null; 2771 } 2947 2948 return null; 2772 2949 } 2773 2950 … … 2792 2969 return 31.0; 2793 2970 } 2794 else 2795 { 2796 return null; 2797 } 2971 2972 return null; 2798 2973 } 2799 2974 … … 2815 2990 return $qty; 2816 2991 } 2817 else 2818 { 2819 return ($qty > $max) ? $max : $qty; 2820 } 2992 2993 return ($qty > $max) ? $max : $qty; 2821 2994 } 2822 2995 … … 2830 3003 * @see get_item_quantity() 2831 3004 * @since Beta 2 2832 * @param int $key The item that you want to return. 3005 * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1 2833 3006 * @return SimplePie_Item|null 2834 3007 */ … … 2840 3013 return $items[$key]; 2841 3014 } 2842 else 2843 { 2844 return null; 2845 } 3015 3016 return null; 2846 3017 } 2847 3018 … … 2857 3028 * @param int $start Index to start at 2858 3029 * @param int $end Number of items to return. 0 for all items after `$start` 2859 * @return array|null List of {@see SimplePie_Item} objects3030 * @return SimplePie_Item[]|null List of {@see SimplePie_Item} objects 2860 3031 */ 2861 3032 public function get_items($start = 0, $end = 0) … … 2866 3037 { 2867 3038 $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); 2868 } 2869 else 2870 { 2871 $this->data['items'] = array(); 2872 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) 2873 { 2874 $keys = array_keys($items); 2875 foreach ($keys as $key) 2876 { 2877 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 2878 } 2879 } 2880 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) 2881 { 2882 $keys = array_keys($items); 2883 foreach ($keys as $key) 2884 { 2885 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 2886 } 2887 } 2888 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) 2889 { 2890 $keys = array_keys($items); 2891 foreach ($keys as $key) 2892 { 2893 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 2894 } 2895 } 2896 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) 2897 { 2898 $keys = array_keys($items); 2899 foreach ($keys as $key) 2900 { 2901 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 2902 } 2903 } 2904 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) 2905 { 2906 $keys = array_keys($items); 2907 foreach ($keys as $key) 2908 { 2909 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 2910 } 2911 } 2912 } 2913 } 2914 2915 if (!empty($this->data['items'])) 2916 { 2917 // If we want to order it by date, check if all items have a date, and then sort it 2918 if ($this->order_by_date && empty($this->multifeed_objects)) 2919 { 2920 if (!isset($this->data['ordered_items'])) 2921 { 2922 $do_sort = true; 2923 foreach ($this->data['items'] as $item) 2924 { 2925 if (!$item->get_date('U')) 2926 { 2927 $do_sort = false; 2928 break; 2929 } 2930 } 2931 $item = null; 2932 $this->data['ordered_items'] = $this->data['items']; 2933 if ($do_sort) 2934 { 2935 usort($this->data['ordered_items'], array(get_class($this), 'sort_items')); 2936 } 2937 } 2938 $items = $this->data['ordered_items']; 2939 } 2940 else 2941 { 2942 $items = $this->data['items']; 2943 } 2944 2945 // Slice the data as desired 2946 if ($end === 0) 2947 { 2948 return array_slice($items, $start); 2949 } 2950 else 2951 { 2952 return array_slice($items, $start, $end); 2953 } 3039 if (empty($this->data['items'])) 3040 { 3041 return array(); 3042 } 3043 return $this->data['items']; 3044 } 3045 $this->data['items'] = array(); 3046 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) 3047 { 3048 $keys = array_keys($items); 3049 foreach ($keys as $key) 3050 { 3051 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 3052 } 3053 } 3054 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) 3055 { 3056 $keys = array_keys($items); 3057 foreach ($keys as $key) 3058 { 3059 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 3060 } 3061 } 3062 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) 3063 { 3064 $keys = array_keys($items); 3065 foreach ($keys as $key) 3066 { 3067 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 3068 } 3069 } 3070 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) 3071 { 3072 $keys = array_keys($items); 3073 foreach ($keys as $key) 3074 { 3075 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 3076 } 3077 } 3078 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) 3079 { 3080 $keys = array_keys($items); 3081 foreach ($keys as $key) 3082 { 3083 $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 3084 } 3085 } 3086 } 3087 3088 if (empty($this->data['items'])) 3089 { 3090 return array(); 3091 } 3092 3093 if ($this->order_by_date) 3094 { 3095 if (!isset($this->data['ordered_items'])) 3096 { 3097 $this->data['ordered_items'] = $this->data['items']; 3098 usort($this->data['ordered_items'], array(get_class($this), 'sort_items')); 3099 } 3100 $items = $this->data['ordered_items']; 2954 3101 } 2955 3102 else 2956 3103 { 2957 return array(); 2958 } 3104 $items = $this->data['items']; 3105 } 3106 // Slice the data as desired 3107 if ($end === 0) 3108 { 3109 return array_slice($items, $start); 3110 } 3111 3112 return array_slice($items, $start, $end); 2959 3113 } 2960 3114 … … 2983 3137 if (($url = $this->get_link()) !== null) 2984 3138 { 2985 return 'http ://g.etfv.co/' . urlencode($url);3139 return 'https://www.google.com/s2/favicons?domain=' . urlencode($url); 2986 3140 } 2987 3141 … … 3028 3182 public static function sort_items($a, $b) 3029 3183 { 3030 return $a->get_date('U') <= $b->get_date('U'); 3184 $a_date = $a->get_date('U'); 3185 $b_date = $b->get_date('U'); 3186 if ($a_date && $b_date) { 3187 return $a_date > $b_date ? -1 : 1; 3188 } 3189 // Sort items without dates to the top. 3190 if ($a_date) { 3191 return 1; 3192 } 3193 if ($b_date) { 3194 return -1; 3195 } 3196 return 0; 3031 3197 } 3032 3198 … … 3061 3227 } 3062 3228 3063 $do_sort = true; 3064 foreach ($items as $item) 3065 { 3066 if (!$item->get_date('U')) 3067 { 3068 $do_sort = false; 3069 break; 3070 } 3071 } 3072 $item = null; 3073 if ($do_sort) 3074 { 3075 usort($items, array(get_class($urls[0]), 'sort_items')); 3076 } 3229 usort($items, array(get_class($urls[0]), 'sort_items')); 3077 3230 3078 3231 if ($end === 0) … … 3080 3233 return array_slice($items, $start); 3081 3234 } 3235 3236 return array_slice($items, $start, $end); 3237 } 3238 3239 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); 3240 return array(); 3241 } 3242 3243 /** 3244 * Store PubSubHubbub links as headers 3245 * 3246 * There is no way to find PuSH links in the body of a microformats feed, 3247 * so they are added to the headers when found, to be used later by get_links. 3248 * @param SimplePie_File $file 3249 * @param string $hub 3250 * @param string $self 3251 */ 3252 private function store_links(&$file, $hub, $self) { 3253 if (isset($file->headers['link']['hub']) || 3254 (isset($file->headers['link']) && 3255 preg_match('/rel=hub/', $file->headers['link']))) 3256 { 3257 return; 3258 } 3259 3260 if ($hub) 3261 { 3262 if (isset($file->headers['link'])) 3263 { 3264 if ($file->headers['link'] !== '') 3265 { 3266 $file->headers['link'] = ', '; 3267 } 3268 } 3082 3269 else 3083 3270 { 3084 return array_slice($items, $start, $end);3085 } 3086 }3087 else3088 {3089 trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);3090 return array();3271 $file->headers['link'] = ''; 3272 } 3273 $file->headers['link'] .= '<'.$hub.'>; rel=hub'; 3274 if ($self) 3275 { 3276 $file->headers['link'] .= ', <'.$self.'>; rel=self'; 3277 } 3091 3278 } 3092 3279 }
Note: See TracChangeset
for help on using the changeset viewer.