Skip to content

Commit 61f0117

Browse files
author
Ricardo Fiorani
committed
now youtube adapter keeps the querystring
1 parent 2948b36 commit 61f0117

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/Adapter/AbstractServiceAdapter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,17 @@ public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecu
131131
}
132132

133133
/**
134-
* Switches the protocol scheme between http and https
134+
* Switches the protocol scheme between http and https in case you want to force https
135135
*
136136
* @param bool|false $forceSecure
137137
* @return string
138138
*/
139139
public function getScheme($forceSecure = false)
140140
{
141-
return ($forceSecure ? 'https' : 'http');
141+
if ($forceSecure) {
142+
return 'https';
143+
}
144+
145+
return parse_url($this->rawUrl, PHP_URL_SCHEME);
142146
}
143147
}

src/Adapter/Youtube/YoutubeServiceAdapter.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Date: 29/08/2015
66
* Time: 14:53.
77
*/
8+
89
namespace RicardoFiorani\Adapter\Youtube;
910

1011
use RicardoFiorani\Adapter\AbstractServiceAdapter;
@@ -94,7 +95,14 @@ public function getThumbNailSizes()
9495
*/
9596
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
9697
{
97-
return $this->getScheme($forceSecure) . '://www.youtube.com/embed/' . $this->getVideoId() . ($forceAutoplay ? '?amp&autoplay=1' : '');
98+
$queryString = $this->generateQuerystring($forceAutoplay);
99+
100+
return sprintf(
101+
'%s://www.youtube.com/embed/%s?%s',
102+
$this->getScheme($forceSecure),
103+
$this->getVideoId(),
104+
http_build_query($queryString)
105+
);
98106
}
99107

100108
/**
@@ -144,4 +152,20 @@ public function isEmbeddable()
144152
{
145153
return true;
146154
}
155+
156+
/**
157+
* @param bool $forceAutoplay
158+
* @return array
159+
*/
160+
private function generateQuerystring($forceAutoplay = false)
161+
{
162+
parse_str(parse_url($this->rawUrl, PHP_URL_QUERY), $queryString);
163+
unset($queryString['v']);
164+
165+
if ($forceAutoplay) {
166+
$queryString['autoplay'] = (int) $forceAutoplay;
167+
}
168+
169+
return $queryString;
170+
}
147171
}

0 commit comments

Comments
 (0)