Move HTTPS exception for YouTube and Vimeo to OEmbed::fetchUrl

- Both Youtube and Vimeo output OEmbed endpoint URL with HTTP but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
This commit is contained in:
Hypolite Petovan 2021-02-08 02:06:24 -05:00
parent 0927bb5f2c
commit 4a57ed1a31

View file

@ -106,6 +106,10 @@ class OEmbed
as $link) as $link)
{ {
$href = $link->getAttributeNode('href')->nodeValue; $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::httpRequest()->fetchFull($href . '&maxwidth=' . $a->videowidth); $result = DI::httpRequest()->fetchFull($href . '&maxwidth=' . $a->videowidth);
if ($result->getReturnCode() === 200) { if ($result->getReturnCode() === 200) {
$json_string = $result->getBody(); $json_string = $result->getBody();
@ -335,10 +339,6 @@ class OEmbed
public static function getHTML($url, $title = null) public static function getHTML($url, $title = null)
{ {
// Always embed the SSL version
$url = str_replace(["http://www.youtube.com/", "http://player.vimeo.com/"],
["https://www.youtube.com/", "https://player.vimeo.com/"], $url);
$o = self::fetchURL($url, !self::isAllowedURL($url)); $o = self::fetchURL($url, !self::isAllowedURL($url));
if (!is_object($o) || property_exists($o, 'type') && $o->type == 'error') { if (!is_object($o) || property_exists($o, 'type') && $o->type == 'error') {