function get_content_by_parsing($url, $path) { require_once LIB_PATH . '/lib_phpQuery.php'; Minz_Log::notice('FreshRSS GET ' . url_remove_credentials($url)); $html = file_get_contents($url); if ($html) { $doc = phpQuery::newDocument($html); $content = $doc->find($path); return sanitizeHTML($content->__toString(), $url); } else { throw new Exception(); } }
public function load($loadDetails = false) { if ($this->url !== null) { if (CACHE_PATH === false) { throw new Minz_FileNotExistException('CACHE_PATH', Minz_Exception::ERROR); } else { $url = htmlspecialchars_decode($this->url, ENT_QUOTES); if ($this->httpAuth != '') { $url = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url); } $feed = customSimplePie(); if (substr($url, -11) === '#force_feed') { $feed->force_feed(true); $url = substr($url, 0, -11); } $feed->set_feed_url($url); if (!$loadDetails) { //Only activates auto-discovery when adding a new feed $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); } $mtime = $feed->init(); if (!$mtime || $feed->error()) { $errorMessage = $feed->error(); throw new FreshRSS_Feed_Exception(($errorMessage == '' ? 'Feed error' : $errorMessage) . ' [' . $url . ']'); } if ($loadDetails) { // si on a utilisé l'auto-discover, notre url va avoir changé $subscribe_url = $feed->subscribe_url(false); $title = strtr(html_only_entity_decode($feed->get_title()), array('<' => '<', '>' => '>', '"' => '"')); //HTML to HTML-PRE //ENT_COMPAT except & $this->_name($title == '' ? $url : $title); $this->_website(html_only_entity_decode($feed->get_link())); $this->_description(html_only_entity_decode($feed->get_description())); } else { //The case of HTTP 301 Moved Permanently $subscribe_url = $feed->subscribe_url(true); } $clean_url = url_remove_credentials($subscribe_url); if ($subscribe_url !== null && $subscribe_url !== $url) { $this->_url($clean_url); } if ($mtime === true || $mtime > $this->lastUpdate) { Minz_Log::notice('FreshRSS no cache ' . $mtime . ' > ' . $this->lastUpdate . ' for ' . $clean_url); $this->loadEntries($feed); // et on charge les articles du flux } else { Minz_Log::notice('FreshRSS use cache for ' . $clean_url); $this->entries = array(); } $feed->__destruct(); //http://simplepie.org/wiki/faq/i_m_getting_memory_leaks unset($feed); } } }