Make WordPress Core

Ticket #11585: 11585.diff

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

     
    15411541                                $this->data = array();
    15421542                        }
    15431543                }
     1544
    15441545                // 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.
    15451546                if (!isset($file))
    15461547                {
     
    15531554                                $headers = array(
    15541555                                        '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',
    15551556                                );
     1557
    15561558                                $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
    15571559                        }
    15581560                }
     
    15601562                if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
    15611563                {
    15621564                        $this->error = $file->error;
     1565                        $this->cache_results( $cache, $this->feed_url );
    15631566                        return !empty($this->data);
    15641567                }
    15651568
     
    15781581                                        {
    15791582                                                $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.";
    15801583                                                $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
     1584                                                $this->cache_results( $cache, $this->feed_url );
    15811585                                                return false;
    15821586                                        }
    15831587                                }
     
    15861590                                        // This is usually because DOMDocument doesn't exist
    15871591                                        $this->error = $e->getMessage();
    15881592                                        $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
     1593                                        $this->cache_results( $cache, $this->feed_url );
    15891594                                        return false;
    15901595                                }
    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                                 }
     1596
     1597                                $this->cache_results( $cache, $file->url );
    16001598                                $this->feed_url = $file->url;
    16011599                        }
    16021600                        $locate = null;
     
    16111609                return array($headers, $sniffed);
    16121610        }
    16131611
     1612
    16141613        /**
     1614         * Cache the results of the feed request.
     1615         *
     1616         * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache
     1617         * @param string $feedurl
     1618         */
     1619        public function cache_results( &$cache, $feedurl )
     1620        {
     1621                if ($cache)
     1622                {
     1623                        $this->data = array('url' => $this->feed_url, 'build' => SIMPLEPIE_BUILD);
     1624
     1625                        // A weird little hack to ensure that we cache errors.
     1626                        if (empty($this->error))
     1627                        {
     1628                                $this->data['feed_url'] = $feedurl;
     1629                        }
     1630
     1631                        if (!$cache->save($this))
     1632                        {
     1633                                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);
     1634                        }
     1635
     1636                        $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $feedurl), 'spc'));
     1637                }
     1638        }
     1639
     1640        /**
    16151641         * Get the error message for the occured error
    16161642         *
    16171643         * @return string|array Error message, or array of messages for multifeeds