Ticket #11585: 11585.2.diff
File 11585.2.diff, 6.9 KB (added by , 12 years ago) |
---|
-
wp-includes/class-simplepie.php
557 557 public $cache_duration = 3600; 558 558 559 559 /** 560 * @var int Error cache duration (in seconds) 561 * @see SimplePie::set_error_cache_duration() 562 * @access private 563 */ 564 public $error_cache_duration = 3600; 565 566 /** 560 567 * @var int Auto-discovery cache duration (in seconds) 561 568 * @see SimplePie::set_autodiscovery_cache_duration() 562 569 * @access private … … 877 884 } 878 885 879 886 /** 887 * Set the length of time (in seconds) that the errors for failed feed loads 888 * will be cached 889 * 890 * @param int $seconds The feed error cache duration 891 */ 892 public function set_error_cache_duration($seconds = 3600) 893 { 894 $this->error_cache_duration = (int) $seconds; 895 } 896 897 /** 880 898 * Set the length of time (in seconds) that the autodiscovered feed URL will 881 899 * be cached 882 900 * … … 1470 1488 $cache->unlink(); 1471 1489 $this->data = array(); 1472 1490 } 1491 1473 1492 // If we've hit a collision just rerun it with caching disabled 1474 1493 elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) 1475 1494 { 1476 1495 $cache = false; 1477 1496 $this->data = array(); 1478 1497 } 1498 1479 1499 // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL. 1480 1500 elseif (isset($this->data['feed_url'])) 1481 1501 { … … 1493 1513 $this->data = array(); 1494 1514 } 1495 1515 } 1516 1517 // Check if the error cache has been updated 1518 elseif ($cache->mtime() + $this->error_cache_duration < time() && isset($this->data['error'])) 1519 { 1520 $cache->unlink(); 1521 $this->data = array(); 1522 } 1523 1496 1524 // Check if the cache has been updated 1497 1525 elseif ($cache->mtime() + $this->cache_duration < time()) 1498 1526 { … … 1527 1555 } 1528 1556 } 1529 1557 } 1558 1530 1559 // If the cache is still valid, just return true 1531 1560 else 1532 1561 { 1562 // If we're caching an error, pull it back out from the cache payload for persistent error response. 1563 if (!empty($this->data['error'])) 1564 { 1565 $this->error = $this->data['error']; 1566 } 1533 1567 $this->raw_data = false; 1534 1568 return true; 1535 1569 } 1536 1570 } 1571 1537 1572 // If the cache is empty, delete it 1538 1573 else 1539 1574 { … … 1541 1576 $this->data = array(); 1542 1577 } 1543 1578 } 1579 1544 1580 // 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. 1545 1581 if (!isset($file)) 1546 1582 { … … 1553 1589 $headers = array( 1554 1590 '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', 1555 1591 ); 1592 1556 1593 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen)); 1557 1594 } 1558 1595 } … … 1560 1597 if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) 1561 1598 { 1562 1599 $this->error = $file->error; 1600 $this->cache_results( $cache, $this->feed_url ); 1563 1601 return !empty($this->data); 1564 1602 } 1565 1603 … … 1578 1616 { 1579 1617 $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."; 1580 1618 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 1619 $this->cache_results( $cache, $this->feed_url ); 1581 1620 return false; 1582 1621 } 1583 1622 } … … 1586 1625 // This is usually because DOMDocument doesn't exist 1587 1626 $this->error = $e->getMessage(); 1588 1627 $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine())); 1628 $this->cache_results( $cache, $this->feed_url ); 1589 1629 return false; 1590 1630 } 1591 if ($cache) 1592 { 1593 $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); 1594 if (!$cache->save($this)) 1595 { 1596 trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); 1597 } 1598 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc')); 1599 } 1631 1632 $this->cache_results( $cache, $file->url ); 1600 1633 $this->feed_url = $file->url; 1601 1634 } 1602 1635 $locate = null; … … 1611 1644 return array($headers, $sniffed); 1612 1645 } 1613 1646 1647 1614 1648 /** 1649 * Cache the results of the feed request. 1650 * 1651 * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache 1652 * @param string $feedurl 1653 */ 1654 public function cache_results( &$cache, $feedurl ) 1655 { 1656 if ($cache) 1657 { 1658 $this->data = array('url' => $this->feed_url, 'build' => SIMPLEPIE_BUILD); 1659 1660 // A weird little hack to ensure that we cache errors. 1661 if (!empty($this->error)) 1662 { 1663 $this->data['error'] = $this->error; 1664 } 1665 // For some reason feed_url in the cache payload should only be set if there are no errors. 1666 else { 1667 $this->data['feed_url'] = $feedurl; 1668 } 1669 1670 if (!$cache->save($this)) 1671 { 1672 trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); 1673 } 1674 1675 $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $feedurl), 'spc')); 1676 } 1677 } 1678 1679 /** 1615 1680 * Get the error message for the occured error 1616 1681 * 1617 1682 * @return string|array Error message, or array of messages for multifeeds -
wp-includes/default-widgets.php
833 833 834 834 if ( is_wp_error($rss) ) { 835 835 if ( is_admin() || current_user_can('manage_options') ) 836 echo '<p >' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';836 echo '<p class="error">' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>'; 837 837 return; 838 838 } 839 839 -
wp-includes/feed.php
541 541 542 542 $feed->set_feed_url( $url ); 543 543 $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); 544 $feed->set_error_cache_duration( apply_filters( 'wp_feed_error_cache_transient_lifetime', 15 * MINUTE_IN_SECONDS, $url ) ); 544 545 do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) ); 545 546 $feed->init(); 546 547 $feed->handle_content_type();