/** * Test if an item is already cached and if its cache is still valid * * This may check if a cache exists for the item and if it seems always valid ; validity * may be tested for a static duration time (a `max_cache_time`) and could be checked * comparing the creation time of the cache entry and the last modification time of the * source if it is possible. * * @return bool */ public function isCached() { $cache_lifetime = Helper::getOption('cache_lifetime', 0); if ($cache_lifetime > 0) { return @file_exists($this->getCacheKey()) && filemtime($this->getCacheKey()) + $cache_lifetime > time(); } else { return @file_exists($this->getCacheKey()); } }
public function read() { $proxy = Helper::getOption('proxy'); if (is_null($proxy)) { $protocol = substr($this->getFeedUrl(), 0, 5) == 'https' ? 'https' : 'http'; $proxy = Helper::getOption('proxy_' . $protocol); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->getFeedUrl()); if (!is_null($proxy)) { curl_setopt($ch, CURLOPT_PROXY, $proxy); } curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_HEADER, 1); $result = curl_exec($ch); curl_close($ch); if (!empty($result)) { $this->_init($result)->parse(); } }
public function forceRefresh($feed_url) { $cachable = Helper::getOption('use_cache', false); $index = $this->getFeedItemIndex($feed_url); if ($index) { $this->feeds_registry[$i] = $cachable ? new FeedCachable($this->offsetGet($index), $index) : new Feed($this->offsetGet($index), $index); } }