Merge pull request #202 from jonnybarnes/errors-with-author-info

Use Laravel’s Array helper to ease accessing data in authorship array
This commit is contained in:
Jonny Barnes 2020-09-13 18:05:08 +01:00 committed by GitHub
commit a48a7eab3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Jonnybarnes\WebmentionsParser\Authorship;
use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
@ -19,8 +20,7 @@ class SaveProfileImage implements ShouldQueue
use Queueable;
use SerializesModels;
/** @var array */
protected $microformats;
protected array $microformats;
/**
* Create a new job instance.
@ -44,17 +44,18 @@ class SaveProfileImage implements ShouldQueue
} catch (AuthorshipParserException $e) {
return;
}
$photo = $author['properties']['photo'][0];
$home = $author['properties']['url'][0];
$photo = Arr::get($author, 'properties.photo.0');
$home = Arr::get($author, 'properties.url.0');
//dont save pbs.twimg.com links
if (
parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com'
$photo
&& parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com'
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com'
) {
$client = resolve(Client::class);
try {
$response = $client->get($photo);
$image = $response->getBody(true);
$image = $response->getBody();
} catch (RequestException $e) {
// we are opening and reading the default image so that
$default = public_path() . '/assets/profile-images/default-image';