Skip to content
Snippets Groups Projects
Commit 600da9f8 authored by catch's avatar catch
Browse files

Issue #3008712 by phjou, s.abbott, msuthars, Sam152, chr.fritsch,...

Issue #3008712 by phjou, s.abbott, msuthars, Sam152, chr.fritsch, phenaproxima: oEmbed URL resolution does not take multiple endpoints into account
parent 10b44563
No related branches found
No related tags found
No related merge requests found
......@@ -158,10 +158,8 @@ public function getResourceUrl($url, $max_width = NULL, $max_height = NULL) {
}
$provider = $this->getProviderByUrl($url);
$endpoints = $provider->getEndpoints();
$endpoint = reset($endpoints);
$resource_url = $endpoint->buildResourceUrl($url);
$resource_url = $this->getEndpointMatchingUrl($url, $provider);
$parsed_url = UrlHelper::parse($resource_url);
if ($max_width) {
$parsed_url['query']['maxwidth'] = $max_width;
......@@ -181,4 +179,27 @@ public function getResourceUrl($url, $max_width = NULL, $max_height = NULL) {
return $resource_url;
}
/**
* For the given media item URL find an endpoint with schemes that match.
*
* @param string $url
* The media URL used to lookup the matching endpoint.
* @param \Drupal\media\OEmbed\Provider $provider
* The oEmbed provider for the asset.
*
* @return string
* The resource url.
*/
protected function getEndpointMatchingUrl($url, Provider $provider) {
$endpoints = $provider->getEndpoints();
$resource_url = reset($endpoints)->buildResourceUrl($url);
foreach ($endpoints as $endpoint) {
if ($endpoint->matchUrl($url)) {
$resource_url = $endpoint->buildResourceUrl($url);
break;
}
}
return $resource_url ?? reset($endpoints)->buildResourceUrl($url);
}
}
......@@ -72,5 +72,35 @@
"discovery": true
}
]
},
{
"provider_name": "Facebook",
"provider_url": "https:\/\/www.facebook.com\/",
"endpoints": [
{
"schemes": [
"https:\/\/www.facebook.com\/*\/posts\/*",
"https:\/\/www.facebook.com\/photos\/*",
"https:\/\/www.facebook.com\/*\/photos\/*",
"https:\/\/www.facebook.com\/photo.php*",
"https:\/\/www.facebook.com\/photo.php",
"https:\/\/www.facebook.com\/*\/activity\/*",
"https:\/\/www.facebook.com\/permalink.php",
"https:\/\/www.facebook.com\/media\/set?set=*",
"https:\/\/www.facebook.com\/questions\/*",
"https:\/\/www.facebook.com\/notes\/*\/*\/*"
],
"url": "https:\/\/www.facebook.com\/plugins\/post\/oembed.json",
"discovery": true
},
{
"schemes": [
"https:\/\/www.facebook.com\/*\/videos\/*",
"https:\/\/www.facebook.com\/video.php"
],
"url": "https:\/\/www.facebook.com\/plugins\/video\/oembed.json",
"discovery": true
}
]
}
]
......@@ -50,6 +50,10 @@ public function providerEndpointMatching() {
'http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime',
'http://www.collegehumor.com/oembed.json?url=http://www.collegehumor.com/video/40002870/lets-not-get-a-drink-sometime',
],
'match by endpoint: Facebook' => [
'https://www.facebook.com/facebook/videos/10153231379946729/',
'https://www.facebook.com/plugins/video/oembed.json?url=https://www.facebook.com/facebook/videos/10153231379946729/',
],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment