- $entries = $xpath->query("//link[@type='application/json+oembed']");
- foreach ($entries as $e) {
- $href = $e->getAttributeNode('href')->nodeValue;
- $json_string = HTTPRequest::fetchUrl($href . '&maxwidth=' . $a->videowidth);
- break;
- }
-
- $entries = $xpath->query("//link[@type='text/json+oembed']");
- foreach ($entries as $e) {
- $href = $e->getAttributeNode('href')->nodeValue;
- $json_string = HTTPRequest::fetchUrl($href . '&maxwidth=' . $a->videowidth);
- break;
+ foreach (
+ $xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']")
+ as $link)
+ {
+ $href = $link->getAttributeNode('href')->nodeValue;
+ // Both Youtube and Vimeo output OEmbed endpoint URL with HTTP
+ // but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
+ $href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'],
+ ['https://www.youtube.com/', 'https://player.vimeo.com/'], $href);
+ $result = DI::httpClient()->fetchFull($href . '&maxwidth=' . $a->getThemeInfoValue('videowidth'));
+ if ($result->getReturnCode() === 200) {
+ $json_string = $result->getBody();
+ break;
+ }