From 5c4479bd42842497d8e7523009b30e2f8d907724 Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Mon, 11 Oct 2021 13:27:13 +0100 Subject: [PATCH 1/5] Added favicon size to google provider Added favicon_size to config file --- config/favicon-extractor.php | 11 +++++++++++ src/Provider/GoogleProvider.php | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config/favicon-extractor.php b/config/favicon-extractor.php index 81ccc4d..f3f8778 100644 --- a/config/favicon-extractor.php +++ b/config/favicon-extractor.php @@ -1,6 +1,17 @@ 32, + /* |-------------------------------------------------------------------------- | Favicon Provider diff --git a/src/Provider/GoogleProvider.php b/src/Provider/GoogleProvider.php index c0b05ac..64a7e8f 100644 --- a/src/Provider/GoogleProvider.php +++ b/src/Provider/GoogleProvider.php @@ -18,6 +18,8 @@ public function fetchFromUrl(string $url): string private function getUrl(string $url): string { - return 'https://www.google.com/s2/favicons?domain='.urlencode($url); + $favicon_size = config('favicon-extractor.favicon_size', 32); + $size_query = '&sz='.$favicon_size; + return 'https://www.google.com/s2/favicons?domain='.urlencode($url).$size_query; } } From 0e95e00e2a2cb7183c1c7a2c9e82bc0772606dfa Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Mon, 11 Oct 2021 15:23:03 +0100 Subject: [PATCH 2/5] Add storage disk to `fetchAndSaveTo` --- config/favicon-extractor.php | 11 +++++++++++ src/FaviconExtractor.php | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/favicon-extractor.php b/config/favicon-extractor.php index f3f8778..7555264 100644 --- a/config/favicon-extractor.php +++ b/config/favicon-extractor.php @@ -12,6 +12,17 @@ 'favicon_size' => 32, + /* + |-------------------------------------------------------------------------- + | Favicon Provider + |-------------------------------------------------------------------------- + | + | This value is used for requesting a favicon of the given size (if supported by the given provider) + | + */ + + 'disk' => 'public', + /* |-------------------------------------------------------------------------- | Favicon Provider diff --git a/src/FaviconExtractor.php b/src/FaviconExtractor.php index 085b50b..d4bf08f 100644 --- a/src/FaviconExtractor.php +++ b/src/FaviconExtractor.php @@ -57,11 +57,12 @@ public function fetchAndSaveTo(string $path, string $filename = null): string $favicon = $this->fetchOnly(); $targetPath = $this->getTargetPath($path, $filename); - - if (!Storage::put($targetPath, $favicon->getContent())) { + $targetDisk = config('favicon-exractor.disk'); + if (!Storage::disk($targetDisk)->put($targetPath, $favicon->getContent())) { throw new FaviconCouldNotBeSavedException(sprintf( 'The favicon of %s could not be saved at path "%s" ', - $this->getUrl(), $targetPath + $this->getUrl(), + $targetPath )); } From 3a9c721d8d8512c170c42212258a7afb899b2777 Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Mon, 11 Oct 2021 15:57:08 +0100 Subject: [PATCH 3/5] set default disk --- src/FaviconExtractor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FaviconExtractor.php b/src/FaviconExtractor.php index d4bf08f..490ccce 100644 --- a/src/FaviconExtractor.php +++ b/src/FaviconExtractor.php @@ -57,7 +57,8 @@ public function fetchAndSaveTo(string $path, string $filename = null): string $favicon = $this->fetchOnly(); $targetPath = $this->getTargetPath($path, $filename); - $targetDisk = config('favicon-exractor.disk'); + $targetDisk = config('favicon-exractor.disk', 'public'); + if (!Storage::disk($targetDisk)->put($targetPath, $favicon->getContent())) { throw new FaviconCouldNotBeSavedException(sprintf( 'The favicon of %s could not be saved at path "%s" ', From 089220b198ecee1e6ee0436921419bae1e39ce28 Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Thu, 21 Oct 2021 17:28:05 +0100 Subject: [PATCH 4/5] Changed provider variables to camelCase Moved config variables between provider and generator --- config/favicon-extractor.php | 23 ++++++++++++----------- src/Provider/GoogleProvider.php | 6 +++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/config/favicon-extractor.php b/config/favicon-extractor.php index 7555264..38d2e50 100644 --- a/config/favicon-extractor.php +++ b/config/favicon-extractor.php @@ -6,37 +6,37 @@ | Favicon Provider |-------------------------------------------------------------------------- | - | This value is used for requesting a favicon of the given size (if supported by the given provider) + | This class is used for fetching favicons. You can swap it out easily if + | you like as long as you implement the ProviderInterface. + | + | \StefanBauer\LaravelFaviconExtractor\Provider\ProviderInterface | */ - 'favicon_size' => 32, + 'provider_class' => \StefanBauer\LaravelFaviconExtractor\Provider\GoogleProvider::class, /* |-------------------------------------------------------------------------- - | Favicon Provider + | Favicon Size |-------------------------------------------------------------------------- | | This value is used for requesting a favicon of the given size (if supported by the given provider) | */ - 'disk' => 'public', + 'favicon_size' => 32, /* |-------------------------------------------------------------------------- - | Favicon Provider + | Favicon Disk |-------------------------------------------------------------------------- | - | This class is used for fetching favicons. You can swap it out easily if - | you like as long as you implement the ProviderInterface. - | - | \StefanBauer\LaravelFaviconExtractor\Provider\ProviderInterface + | This value is used for providing a default disk for the favicon | */ - 'provider_class' => \StefanBauer\LaravelFaviconExtractor\Provider\GoogleProvider::class, - + 'disk' => 'public', + /* |-------------------------------------------------------------------------- | Filename Generator @@ -50,5 +50,6 @@ | \StefanBauer\LaravelFaviconExtractor\Generator\FilenameGeneratorInterface | */ + 'filename_generator_class' => \StefanBauer\LaravelFaviconExtractor\Generator\FilenameGenerator::class, ]; diff --git a/src/Provider/GoogleProvider.php b/src/Provider/GoogleProvider.php index 64a7e8f..c9901f4 100644 --- a/src/Provider/GoogleProvider.php +++ b/src/Provider/GoogleProvider.php @@ -18,8 +18,8 @@ public function fetchFromUrl(string $url): string private function getUrl(string $url): string { - $favicon_size = config('favicon-extractor.favicon_size', 32); - $size_query = '&sz='.$favicon_size; - return 'https://www.google.com/s2/favicons?domain='.urlencode($url).$size_query; + $faviconSize = config('favicon-extractor.favicon_size', 32); + $sizeQuery = '&sz='.$faviconSize; + return 'https://www.google.com/s2/favicons?domain='.urlencode($url).$sizeQuery; } } From fcda5f54c313ff33f899059ecd2c8aaf95d00329 Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Thu, 21 Oct 2021 17:30:04 +0100 Subject: [PATCH 5/5] Added new providers for Allesev, Unavatar and Yandex unavatar is interesting because it resolves a domain, username or email to image. --- src/Provider/AllesedvProvider.php | 25 +++++++++++++++++++++++++ src/Provider/UnavatarProvider.php | 24 ++++++++++++++++++++++++ src/Provider/YandexProvider.php | 26 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/Provider/AllesedvProvider.php create mode 100644 src/Provider/UnavatarProvider.php create mode 100644 src/Provider/YandexProvider.php diff --git a/src/Provider/AllesedvProvider.php b/src/Provider/AllesedvProvider.php new file mode 100644 index 0000000..042d7c3 --- /dev/null +++ b/src/Provider/AllesedvProvider.php @@ -0,0 +1,25 @@ +get($this->getUrl($url)); + + return $response->getBody()->getContents(); + } + + private function getUrl(string $url): string + { + $faviconSize = config('favicon-extractor.favicon_size', 32); + $sizeQuery = $faviconSize.'/'; + return 'https://f1.allesedv.com/'.$sizeQuery.urlencode($url); + } +} diff --git a/src/Provider/UnavatarProvider.php b/src/Provider/UnavatarProvider.php new file mode 100644 index 0000000..dce4ffc --- /dev/null +++ b/src/Provider/UnavatarProvider.php @@ -0,0 +1,24 @@ +get($this->getUrl($url)); + + return $response->getBody()->getContents(); + } + + private function getUrl(string $url): string + { + // accpts a domain, username or email, + return 'https://unavatar.io/'.urlencode($url); + } +} diff --git a/src/Provider/YandexProvider.php b/src/Provider/YandexProvider.php new file mode 100644 index 0000000..7b38e3d --- /dev/null +++ b/src/Provider/YandexProvider.php @@ -0,0 +1,26 @@ +get($this->getUrl($url)); + + return $response->getBody()->getContents(); + } + + private function getUrl(string $url): string + { + // size options are limited to 16 & 32 + $faviconSize = config('favicon-extractor.favicon_size', 32) > 16 ? 32 : 16; + $sizeQuery = '?size='.$faviconSize; + return 'https://favicon.yandex.net/favicon/'.urlencode($url).$sizeQuery; + } +}