From 6dfc4ad844d57ba4289df175d325f058c12025ef Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 28 Apr 2021 20:52:50 +0200 Subject: Prevent some of the favicon fetching errors change user agent for fetching the feeds log to 'NextCloud-News/1.0' check if logo in feed is just an empty string remove path of url before searching for a favicon check if file was actually downloaded Ignore http errors when fetching favicons Add feed to integration tests that doesn't have a logo Co-authored-by: Alec Kojaev Signed-off-by: Benjamin Brahmer --- lib/Fetcher/FeedFetcher.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 134abb264..a7c4192e2 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -327,28 +327,36 @@ class FeedFetcher implements IFeedFetcher { $favicon = $feed->getLogo(); - // check if feed has a logo - if (is_null($favicon)) { - return $this->faviconFactory->get($url); + ini_set('user_agent', 'NextCloud-News/1.0'); + + $base_url = new Net_URL2($url); + $base_url->setPath(""); + $base_url = $base_url->getNormalizedURL(); + + // check if feed has a logo entry + if (is_null($favicon) || trim($favicon) === '') { + return $this->faviconFactory->get($base_url); } $favicon_path = join("/", [$this->ITempManager->getTempBaseDir(), basename($favicon)]); - copy( + + $downloaded = copy( $favicon, - $favicon_path + $favicon_path, + stream_context_create([ 'http' => [ 'ignore_errors' => true ] ]) ); - $is_image = substr(mime_content_type($favicon_path), 0, 5) === "image"; + $is_image = $downloaded && substr(mime_content_type($favicon_path), 0, 5) === "image"; // check if file is actually an image if (!$is_image) { - return $this->faviconFactory->get($url); + return $this->faviconFactory->get($base_url); } list($width, $height, $type, $attr) = getimagesize($favicon_path); // check if image is square else fall back to favicon if ($width !== $height) { - return $this->faviconFactory->get($url); + return $this->faviconFactory->get($base_url); } return $favicon; -- cgit v1.2.3