Harden OEmbed link discovery
- Check OEmbed call return code before storing response - Stop at first successful OEmbed response
This commit is contained in:
parent
5354a2d5d0
commit
0927bb5f2c
|
@ -98,21 +98,19 @@ class OEmbed
|
||||||
// try oembed autodiscovery
|
// try oembed autodiscovery
|
||||||
$html_text = DI::httpRequest()->fetch($embedurl, 15, 'text/*');
|
$html_text = DI::httpRequest()->fetch($embedurl, 15, 'text/*');
|
||||||
if ($html_text) {
|
if ($html_text) {
|
||||||
$dom = @DOMDocument::loadHTML($html_text);
|
$dom = new DOMDocument();
|
||||||
if ($dom) {
|
if ($dom->loadHTML($html_text)) {
|
||||||
$xpath = new DOMXPath($dom);
|
$xpath = new DOMXPath($dom);
|
||||||
$entries = $xpath->query("//link[@type='application/json+oembed']");
|
foreach (
|
||||||
foreach ($entries as $e) {
|
$xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']")
|
||||||
$href = $e->getAttributeNode('href')->nodeValue;
|
as $link)
|
||||||
$json_string = DI::httpRequest()->fetch($href . '&maxwidth=' . $a->videowidth);
|
{
|
||||||
break;
|
$href = $link->getAttributeNode('href')->nodeValue;
|
||||||
}
|
$result = DI::httpRequest()->fetchFull($href . '&maxwidth=' . $a->videowidth);
|
||||||
|
if ($result->getReturnCode() === 200) {
|
||||||
$entries = $xpath->query("//link[@type='text/json+oembed']");
|
$json_string = $result->getBody();
|
||||||
foreach ($entries as $e) {
|
break;
|
||||||
$href = $e->getAttributeNode('href')->nodeValue;
|
}
|
||||||
$json_string = DI::httpRequest()->fetch($href . '&maxwidth=' . $a->videowidth);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue