Skip to content

Commit 2c73fb7

Browse files
committed
improved oembed detection
1 parent e623b6b commit 2c73fb7

File tree

10 files changed

+23
-12
lines changed

10 files changed

+23
-12
lines changed

src/Providers/OEmbed/Deviantart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getEndPoint()
1919
{
2020
return Url::create(static::$endPoint)
2121
->withQueryParameters([
22-
'url' => (string) $this->response->getUrl(),
22+
'url' => (string) $this->getUrl(),
2323
'format' => 'json',
2424
'for' => 'embed',
2525
]);

src/Providers/OEmbed/Embedly.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getEndPoint()
4242
{
4343
return Url::create('http://api.embed.ly/1/oembed')
4444
->withQueryParameters([
45-
'url' => (string) $this->response->getUrl(),
45+
'url' => (string) $this->getUrl(),
4646
'format' => 'json',
4747
'key' => $this->key,
4848
]);

src/Providers/OEmbed/EndPoint.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
abstract class EndPoint
1313
{
1414
protected $response;
15+
protected $url;
1516
protected static $pattern;
1617
protected static $endPoint;
1718

@@ -25,16 +26,21 @@ public static function create(Adapter $adapter)
2526
if ($response->getUrl()->match(static::$pattern)) {
2627
return new static($response);
2728
}
29+
30+
if ($response->getStartingUrl()->match(static::$pattern)) {
31+
return new static($response, $response->getStartingUrl());
32+
}
2833
}
2934

3035
/**
3136
* Constructor.
3237
*
3338
* @param Response $response
3439
*/
35-
protected function __construct(Response $response)
40+
protected function __construct(Response $response, Url $url = null)
3641
{
3742
$this->response = $response;
43+
$this->url = $url;
3844
}
3945

4046
/**
@@ -44,8 +50,13 @@ public function getEndPoint()
4450
{
4551
return Url::create(static::$endPoint)
4652
->withQueryParameters([
47-
'url' => (string) $this->response->getUrl(),
53+
'url' => (string) $this->getUrl(),
4854
'format' => 'json',
4955
]);
5056
}
57+
58+
public function getUrl()
59+
{
60+
return $this->url ?: $this->response->getUrl();
61+
}
5162
}

src/Providers/OEmbed/Facebook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class Facebook extends EndPoint implements EndPointInterface
1313
*/
1414
public function getEndPoint()
1515
{
16-
if ($this->response->getUrl()->match(['*/videos/*', '/video.php'])) {
16+
if ($this->getUrl()->match(['*/videos/*', '/video.php'])) {
1717
$endPoint = Url::create('https://www.facebook.com/plugins/video/oembed.json');
1818
} else {
1919
$endPoint = Url::create('https://www.facebook.com/plugins/post/oembed.json');
2020
}
2121

2222
return $endPoint->withQueryParameters([
23-
'url' => (string) $this->response->getUrl(),
23+
'url' => (string) $this->getUrl(),
2424
'format' => 'json',
2525
]);
2626
}

src/Providers/OEmbed/Iframely.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getEndPoint()
4242
{
4343
return Url::create('http://open.iframe.ly/api/oembed')
4444
->withQueryParameters([
45-
'url' => (string) $this->response->getUrl(),
45+
'url' => (string) $this->getUrl(),
4646
'format' => 'json',
4747
'api_key' => $this->key,
4848
]);

src/Providers/OEmbed/Infogram.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Infogram extends EndPoint implements EndPointInterface
1717
*/
1818
public function getEndPoint()
1919
{
20-
$url = $this->response->getUrl()->withScheme('https');
20+
$url = $this->getUrl()->withScheme('https');
2121

2222
return Url::create(static::$endPoint)
2323
->withQueryParameters([

src/Providers/OEmbed/Instagram.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Instagram extends EndPoint implements EndPointInterface
1717
*/
1818
public function getEndPoint()
1919
{
20-
$url = $this->response->getUrl()->withScheme('http');
20+
$url = $this->getUrl()->withScheme('http');
2121

2222
return Url::create(static::$endPoint)
2323
->withQueryParameters([

src/Providers/OEmbed/Jsbin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Jsbin extends EndPoint implements EndPointInterface
1414
*/
1515
public function getEndPoint()
1616
{
17-
$url = $this->response->getUrl()->withDirectoryPosition(2, 'embed');
17+
$url = $this->getUrl()->withDirectoryPosition(2, 'embed');
1818

1919
return Url::create(static::$endPoint)
2020
->withQueryParameters([

src/Providers/OEmbed/Scribd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Scribd extends EndPoint implements EndPointInterface
1717
*/
1818
public function getEndPoint()
1919
{
20-
$url = $this->response->getUrl()->withDirectoryPosition(0, 'doc');
20+
$url = $this->getUrl()->withDirectoryPosition(0, 'doc');
2121

2222
return Url::create(static::$endPoint)
2323
->withQueryParameters([

src/Providers/OEmbed/Spotify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getEndPoint()
1616
{
1717
return Url::create(static::$endPoint)
1818
->withQueryParameters([
19-
'url' => (string) $this->response->getUrl()->withQueryParameters([]),
19+
'url' => (string) $this->getUrl()->withQueryParameters([]),
2020
'format' => 'json'
2121
]);
2222
}

0 commit comments

Comments
 (0)