From 73f65c8fbadbdd2098448e77b6d3f0464ad8613e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 27 Jan 2015 09:29:09 +0100 Subject: update picofeed --- vendor/fguillot/picofeed | 1 + .../picofeed/lib/PicoFeed/Reader/Favicon.php | 208 -------------------- .../picofeed/lib/PicoFeed/Reader/Reader.php | 211 --------------------- .../lib/PicoFeed/Reader/ReaderException.php | 16 -- .../Reader/SubscriptionNotFoundException.php | 13 -- .../Reader/UnsupportedFeedFormatException.php | 13 -- 6 files changed, 1 insertion(+), 461 deletions(-) create mode 160000 vendor/fguillot/picofeed delete mode 100644 vendor/fguillot/picofeed/lib/PicoFeed/Reader/Favicon.php delete mode 100644 vendor/fguillot/picofeed/lib/PicoFeed/Reader/Reader.php delete mode 100644 vendor/fguillot/picofeed/lib/PicoFeed/Reader/ReaderException.php delete mode 100644 vendor/fguillot/picofeed/lib/PicoFeed/Reader/SubscriptionNotFoundException.php delete mode 100644 vendor/fguillot/picofeed/lib/PicoFeed/Reader/UnsupportedFeedFormatException.php (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Reader') diff --git a/vendor/fguillot/picofeed b/vendor/fguillot/picofeed new file mode 160000 index 000000000..0a1d0d395 --- /dev/null +++ b/vendor/fguillot/picofeed @@ -0,0 +1 @@ +Subproject commit 0a1d0d3950f7f047dc8fb1d80aa6296e15f306d0 diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Reader/Favicon.php b/vendor/fguillot/picofeed/lib/PicoFeed/Reader/Favicon.php deleted file mode 100644 index 1d9715143..000000000 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Reader/Favicon.php +++ /dev/null @@ -1,208 +0,0 @@ -config = $config ?: new Config; - } - - /** - * Get the icon file content (available only after the download) - * - * @access public - * @return string - */ - public function getContent() - { - return $this->content; - } - - /** - * Get the icon file type (available only after the download) - * - * @access public - * @return string - */ - public function getType() - { - return $this->content_type; - } - - /** - * Get data URI (http://en.wikipedia.org/wiki/Data_URI_scheme) - * - * @access public - * @return string - */ - public function getDataUri() - { - return sprintf( - 'data:%s;base64,%s', - $this->content_type, - base64_encode($this->content) - ); - } - - /** - * Download and check if a resource exists - * - * @access public - * @param string $url URL - * @return \PicoFeed\Client Client instance - */ - public function download($url) - { - $client = Client::getInstance(); - $client->setConfig($this->config); - - Logger::setMessage(get_called_class().' Download => '.$url); - - try { - $client->execute($url); - } - catch (ClientException $e) { - Logger::setMessage(get_called_class().' Download Failed => '.$e->getMessage()); - } - - return $client; - } - - /** - * Check if a remote file exists - * - * @access public - * @param string $url URL - * @return boolean - */ - public function exists($url) - { - return $this->download($url)->getContent() !== ''; - } - - /** - * Get the icon link for a website - * - * @access public - * @param string $website_link URL - * @return string - */ - public function find($website_link) - { - $website = new Url($website_link); - - $icons = $this->extract($this->download($website->getBaseUrl('/'))->getContent()); - $icons[] = $website->getBaseUrl('/favicon.ico'); - - foreach ($icons as $icon_link) { - - $icon_link = $this->convertLink($website, new Url($icon_link)); - $resource = $this->download($icon_link); - $this->content = $resource->getContent(); - $this->content_type = $resource->getContentType(); - - if ($this->content !== '') { - return $icon_link; - } - } - - return ''; - } - - /** - * Convert icon links to absolute url - * - * @access public - * @param \PicoFeed\Client\Url $website Website url - * @param \PicoFeed\Client\Url $icon Icon url - * @return string - */ - public function convertLink(Url $website, Url $icon) - { - $base_url = ''; - - if ($icon->isRelativeUrl()) { - $base_url = $website->getBaseUrl(); - } - else if ($icon->isProtocolRelative()) { - $icon->setScheme($website->getScheme()); - } - - return $icon->getAbsoluteUrl($base_url); - } - - /** - * Extract the icon links from the HTML - * - * @access public - * @param string $html HTML - * @return array - */ - public function extract($html) - { - $icons = array(); - - if (empty($html)) { - return $icons; - } - - $dom = XmlParser::getHtmlDocument($html); - - $xpath = new DOMXpath($dom); - $elements = $xpath->query("//link[contains(@rel, 'icon') and not(contains(@rel, 'apple'))]"); - - for ($i = 0; $i < $elements->length; $i++) { - $icons[] = $elements->item($i)->getAttribute('href'); - } - - return $icons; - } -} diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Reader/Reader.php b/vendor/fguillot/picofeed/lib/PicoFeed/Reader/Reader.php deleted file mode 100644 index fd629f094..000000000 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Reader/Reader.php +++ /dev/null @@ -1,211 +0,0 @@ - '//feed', - 'Rss20' => '//rss[@version="2.0"]', - 'Rss92' => '//rss[@version="0.92"]', - 'Rss91' => '//rss[@version="0.91"]', - 'Rss10' => '//rdf', - ); - - /** - * Config class instance - * - * @access private - * @var \PicoFeed\Config\Config - */ - private $config; - - /** - * Constructor - * - * @access public - * @param \PicoFeed\Config\Config $config Config class instance - */ - public function __construct(Config $config = null) - { - $this->config = $config ?: new Config; - Logger::setTimezone($this->config->getTimezone()); - } - - /** - * Download a feed (no discovery) - * - * @access public - * @param string $url Feed url - * @param string $last_modified Last modified HTTP header - * @param string $etag Etag HTTP header - * @return \PicoFeed\Client\Client - */ - public function download($url, $last_modified = '', $etag = '') - { - $url = $this->prependScheme($url); - - return Client::getInstance() - ->setConfig($this->config) - ->setLastModified($last_modified) - ->setEtag($etag) - ->execute($url); - } - - /** - * Discover and download a feed - * - * @access public - * @param string $url Feed or website url - * @param string $last_modified Last modified HTTP header - * @param string $etag Etag HTTP header - * @return \PicoFeed\Client\Client - */ - public function discover($url, $last_modified = '', $etag = '') - { - $client = $this->download($url, $last_modified, $etag); - - // It's already a feed or the feed was not modified - if (! $client->isModified() || $this->detectFormat($client->getContent())) { - return $client; - } - - // Try to find a subscription - $links = $this->find($client->getUrl(), $client->getContent()); - - if (empty($links)) { - throw new SubscriptionNotFoundException('Unable to find a subscription'); - } - - return $this->download($links[0], $last_modified, $etag); - } - - /** - * Find feed urls inside a HTML document - * - * @access public - * @param string $url Website url - * @param string $html HTML content - * @return array List of feed links - */ - public function find($url, $html) - { - Logger::setMessage(get_called_class().': Try to discover subscriptions'); - - $dom = XmlParser::getHtmlDocument($html); - $xpath = new DOMXPath($dom); - $links = array(); - - $queries = array( - '//link[@type="application/rss+xml"]', - '//link[@type="application/atom+xml"]', - ); - - foreach ($queries as $query) { - - $nodes = $xpath->query($query); - - foreach ($nodes as $node) { - - $link = $node->getAttribute('href'); - - if (! empty($link)) { - - $feedUrl = new Url($link); - $siteUrl = new Url($url); - - $links[] = $feedUrl->getAbsoluteUrl($feedUrl->isRelativeUrl() ? $siteUrl->getBaseUrl() : ''); - } - } - } - - Logger::setMessage(get_called_class().': '.implode(', ', $links)); - - return $links; - } - - /** - * Get a parser instance - * - * @access public - * @param string $url Site url - * @param string $content Feed content - * @param string $encoding HTTP encoding - * @return \PicoFeed\Parser\Parser - */ - public function getParser($url, $content, $encoding) - { - $format = $this->detectFormat($content); - - if (empty($format)) { - throw new UnsupportedFeedFormatException('Unable to detect feed format'); - } - - $className = '\PicoFeed\Parser\\'.$format; - - $parser = new $className($content, $encoding, $url); - $parser->setHashAlgo($this->config->getParserHashAlgo()); - $parser->setTimezone($this->config->getTimezone()); - $parser->setConfig($this->config); - - return $parser; - } - - /** - * Detect the feed format - * - * @access public - * @param string $content Feed content - * @return string - */ - public function detectFormat($content) - { - $dom = XmlParser::getHtmlDocument($content); - $xpath = new DOMXPath($dom); - - foreach ($this->formats as $parser_name => $query) { - $nodes = $xpath->query($query); - - if ($nodes->length === 1) { - return $parser_name; - } - } - - return ''; - } - - /** - * Add the prefix "http://" if the end-user just enter a domain name - * - * @access public - * @param string $url Url - * @retunr string - */ - public function prependScheme($url) - { - if (! preg_match('%^https?://%', $url)) { - $url = 'http://' . $url; - } - - return $url; - } -} diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Reader/ReaderException.php b/vendor/fguillot/picofeed/lib/PicoFeed/Reader/ReaderException.php deleted file mode 100644 index a8e973f8a..000000000 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Reader/ReaderException.php +++ /dev/null @@ -1,16 +0,0 @@ -