diff --git a/config/favicon-extractor.php b/config/favicon-extractor.php index 81ccc4d..38d2e50 100644 --- a/config/favicon-extractor.php +++ b/config/favicon-extractor.php @@ -15,6 +15,28 @@ 'provider_class' => \StefanBauer\LaravelFaviconExtractor\Provider\GoogleProvider::class, + /* + |-------------------------------------------------------------------------- + | Favicon Size + |-------------------------------------------------------------------------- + | + | This value is used for requesting a favicon of the given size (if supported by the given provider) + | + */ + + 'favicon_size' => 32, + + /* + |-------------------------------------------------------------------------- + | Favicon Disk + |-------------------------------------------------------------------------- + | + | This value is used for providing a default disk for the favicon + | + */ + + 'disk' => 'public', + /* |-------------------------------------------------------------------------- | Filename Generator @@ -28,5 +50,6 @@ | \StefanBauer\LaravelFaviconExtractor\Generator\FilenameGeneratorInterface | */ + 'filename_generator_class' => \StefanBauer\LaravelFaviconExtractor\Generator\FilenameGenerator::class, ]; diff --git a/src/FaviconExtractor.php b/src/FaviconExtractor.php index 085b50b..490ccce 100644 --- a/src/FaviconExtractor.php +++ b/src/FaviconExtractor.php @@ -57,11 +57,13 @@ public function fetchAndSaveTo(string $path, string $filename = null): string $favicon = $this->fetchOnly(); $targetPath = $this->getTargetPath($path, $filename); + $targetDisk = config('favicon-exractor.disk', 'public'); - if (!Storage::put($targetPath, $favicon->getContent())) { + 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 )); } 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/GoogleProvider.php b/src/Provider/GoogleProvider.php index c0b05ac..c9901f4 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); + $faviconSize = config('favicon-extractor.favicon_size', 32); + $sizeQuery = '&sz='.$faviconSize; + return 'https://www.google.com/s2/favicons?domain='.urlencode($url).$sizeQuery; } } 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; + } +}