Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added favicon size to google provider #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions config/favicon-extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,5 +50,6 @@
| \StefanBauer\LaravelFaviconExtractor\Generator\FilenameGeneratorInterface
|
*/

'filename_generator_class' => \StefanBauer\LaravelFaviconExtractor\Generator\FilenameGenerator::class,
];
6 changes: 4 additions & 2 deletions src/FaviconExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}

Expand Down
25 changes: 25 additions & 0 deletions src/Provider/AllesedvProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace StefanBauer\LaravelFaviconExtractor\Provider;

use GrahamCampbell\GuzzleFactory\GuzzleFactory;

class GoogleProvider implements ProviderInterface
{
public function fetchFromUrl(string $url): string
{
$client = GuzzleFactory::make();
$response = $client->get($this->getUrl($url));

return $response->getBody()->getContents();
}

private function getUrl(string $url): string
{
$faviconSize = config('favicon-extractor.favicon_size', 32);
$sizeQuery = $faviconSize.'/';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing line-break before return

return 'https://f1.allesedv.com/'.$sizeQuery.urlencode($url);
}
}
4 changes: 3 additions & 1 deletion src/Provider/GoogleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing line-break before return

return 'https://www.google.com/s2/favicons?domain='.urlencode($url).$sizeQuery;
}
}
24 changes: 24 additions & 0 deletions src/Provider/UnavatarProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace StefanBauer\LaravelFaviconExtractor\Provider;

use GrahamCampbell\GuzzleFactory\GuzzleFactory;

class GoogleProvider implements ProviderInterface
{
public function fetchFromUrl(string $url): string
{
$client = GuzzleFactory::make();
$response = $client->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);
}
}
26 changes: 26 additions & 0 deletions src/Provider/YandexProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace StefanBauer\LaravelFaviconExtractor\Provider;

use GrahamCampbell\GuzzleFactory\GuzzleFactory;

class GoogleProvider implements ProviderInterface
{
public function fetchFromUrl(string $url): string
{
$client = GuzzleFactory::make();
$response = $client->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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing line-break before return

}
}