Skip to content

Commit

Permalink
Prevent accessing explode results when empty
Browse files Browse the repository at this point in the history
Related to Generate screenshots for links Kovah#18
  • Loading branch information
jeop10 committed Apr 17, 2021
1 parent 98567b8 commit 499a876
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/Helper/HtmlMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ protected static function buildLinkMeta(array $metaTags, string $url): array
?? null;

//Edge case of Youtube only (because of Youtube EU cookie consent)
if (str_contains($url, 'youtube')) {
if (is_null($thumbnail)) {
//Formula based on https://stackoverflow.com/a/2068371
$explode = explode('v=', $url);
//https://img.youtube.com/vi/[video-id]/mqdefault.jpg
$thumbnail = 'https://img.youtube.com/vi/'.$explode[1].'/mqdefault.jpg';
}
if (str_contains($url, 'youtube')
&& str_contains($url, 'v=')
&& is_null($thumbnail)
) {
//Formula based on https://stackoverflow.com/a/2068371
$explode = explode('v=', $url);
//https://img.youtube.com/vi/[video-id]/mqdefault.jpg
$thumbnail = 'https://img.youtube.com/vi/' . $explode[1] . '/mqdefault.jpg';
}

return [
Expand Down

0 comments on commit 499a876

Please sign in to comment.