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 10:19:23 +0200 |
commit | 56ebffbf76d26609388b16a716a68c2ef26e9162 (patch) | |
tree | c75310897171a67dbe85ec9b1aad39a0de7a532c /lib/Fetcher/FeedFetcher.php | |
parent | 11aad33a23a4c16dd128f67898250c9791b25aa8 (diff) |
[Backport] Prevent some of the favicon fetching errors
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib/Fetcher/FeedFetcher.php')
-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 f3d4e0f27..ef232eece 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; |