Make WordPress Core

Ticket #11585: 11585.2.diff

File 11585.2.diff, 6.9 KB (added by peterchester, 12 years ago)
  • wp-includes/class-simplepie.php

     
    557557        public $cache_duration = 3600;
    558558
    559559        /**
     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        /**
    560567         * @var int Auto-discovery cache duration (in seconds)
    561568         * @see SimplePie::set_autodiscovery_cache_duration()
    562569         * @access private
     
    877884        }
    878885
    879886        /**
     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        /**
    880898         * Set the length of time (in seconds) that the autodiscovered feed URL will
    881899         * be cached
    882900         *
     
    14701488                                        $cache->unlink();
    14711489                                        $this->data = array();
    14721490                                }
     1491
    14731492                                // If we've hit a collision just rerun it with caching disabled
    14741493                                elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
    14751494                                {
    14761495                                        $cache = false;
    14771496                                        $this->data = array();
    14781497                                }
     1498
    14791499                                // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
    14801500                                elseif (isset($this->data['feed_url']))
    14811501                                {
     
    14931513                                                $this->data = array();
    14941514                                        }
    14951515                                }
     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
    14961524                                // Check if the cache has been updated
    14971525                                elseif ($cache->mtime() + $this->cache_duration < time())
    14981526                                {
     
    15271555                                                }
    15281556                                        }
    15291557                                }
     1558
    15301559                                // If the cache is still valid, just return true
    15311560                                else
    15321561                                {
     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                                        }
    15331567                                        $this->raw_data = false;
    15341568                                        return true;
    15351569                                }
    15361570                        }
     1571
    15371572                        // If the cache is empty, delete it
    15381573                        else
    15391574                        {
     
    15411576                                $this->data = array();
    15421577                        }
    15431578                }
     1579
    15441580                // 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.
    15451581                if (!isset($file))
    15461582                {
     
    15531589                                $headers = array(
    15541590                                        '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',
    15551591                                );
     1592
    15561593                                $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
    15571594                        }
    15581595                }
     
    15601597                if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
    15611598                {
    15621599                        $this->error = $file->error;
     1600                        $this->cache_results( $cache, $this->feed_url );
    15631601                        return !empty($this->data);
    15641602                }
    15651603
     
    15781616                                        {
    15791617                                                $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.";
    15801618                                                $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
     1619                                                $this->cache_results( $cache, $this->feed_url );
    15811620                                                return false;
    15821621                                        }
    15831622                                }
     
    15861625                                        // This is usually because DOMDocument doesn't exist
    15871626                                        $this->error = $e->getMessage();
    15881627                                        $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
     1628                                        $this->cache_results( $cache, $this->feed_url );
    15891629                                        return false;
    15901630                                }
    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 );
    16001633                                $this->feed_url = $file->url;
    16011634                        }
    16021635                        $locate = null;
     
    16111644                return array($headers, $sniffed);
    16121645        }
    16131646
     1647
    16141648        /**
     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        /**
    16151680         * Get the error message for the occured error
    16161681         *
    16171682         * @return string|array Error message, or array of messages for multifeeds
  • wp-includes/default-widgets.php

     
    833833
    834834        if ( is_wp_error($rss) ) {
    835835                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>';
    837837                return;
    838838        }
    839839
  • wp-includes/feed.php

     
    541541
    542542        $feed->set_feed_url( $url );
    543543        $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 ) );
    544545        do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
    545546        $feed->init();
    546547        $feed->handle_content_type();