Skip to content

Commit

Permalink
Added the rel=0 parameter for the youtube provider
Browse files Browse the repository at this point in the history
  • Loading branch information
simba77 committed Sep 9, 2021
1 parent 8c8ee4c commit e08534a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Providers/Youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public function parse(string $content): string
if (! empty($url)) {
$params = $this->parseUrl($url);
if (isset($params['video_code'])) {
$urlParams = ['rel' => 0]; // Don't show recommended videos.
if (! empty($params['time'])) {
$urlParams['start'] = $params['time'];
}
$html_player = '<div' . $this->getStyles() . '>';
$html_player .= '<div class="' . $this->classes . '">';
$html_player .= '<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/' . $params['video_code'] . (! empty($params['time']) ? '?start=' . $params['time'] : '') . '"></iframe>';
$html_player .= '<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/' . $params['video_code'] . '?' . http_build_query($urlParams) . '"></iframe>';
$html_player .= '</div></div>';
$parent = $embed->parent();
if ($parent !== null) {
Expand Down
8 changes: 4 additions & 4 deletions test/Providers/YoutubeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public function testParse(): void
$content = $youtube->parse($this->html_string);
$this->assertEquals(
'<figure class="media"><div><div class="player_classes">' .
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y?start=75"></iframe></div></div></figure><figure class="media"><div><div class="player_classes">' .
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y"></iframe></div></div></figure>',
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y?rel=0&amp;start=75"></iframe></div></div></figure><figure class="media"><div><div class="player_classes">' .
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y?rel=0"></iframe></div></div></figure>',
$content
);

$youtube = new Youtube(['styles' => ['max-width' => '900px']]);
$content = $youtube->parse($this->html_string);
$this->assertEquals(
'<figure class="media"><div style="max-width:900px;"><div class="">' .
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y?start=75"></iframe></div></div></figure><figure class="media"><div style="max-width:900px;"><div class="">' .
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y"></iframe></div></div></figure>',
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y?rel=0&amp;start=75"></iframe></div></div></figure><figure class="media"><div style="max-width:900px;"><div class="">' .
'<iframe allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/8ZLSKEmbt0Y?rel=0"></iframe></div></div></figure>',
$content
);
}
Expand Down

0 comments on commit e08534a

Please sign in to comment.