diff options
author | Benjamin Brahmer <info@b-brahmer.de> | 2021-04-28 20:52:50 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2021-05-03 09:28:00 +0200 |
commit | 6dfc4ad844d57ba4289df175d325f058c12025ef (patch) | |
tree | 8ff2fb47dc9cfa32488f0e2e833f8ecf65417630 /lib | |
parent | ccc7153a7282e1820101f9b8e12602a8f3da2557 (diff) |
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 <alec.kojaev@gmail.com>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Fetcher/FeedFetcher.php | 24 |
1 files changed, 16 insertions, 8 deletions
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; |