private function extractOpenGraph($html, $baseUrl)
{
if ('' === trim($html)) {
return array();
}
libxml_use_internal_errors(true);
$doc = new \DomDocument();
$doc->loadHTML($html);
libxml_use_internal_errors(false);
$xpath = new \DOMXPath($doc);
$query = '//*/meta[starts-with(@property, \'og:\')]';
$metas = $xpath->query($query);
$rmetas = array();
foreach ($metas as $meta) {
$property = str_replace(':', '_', $meta->getAttribute('property'));
// avoid image data:uri to avoid sending too much data
if ('og_image' === $property) {
if (0 === stripos($meta->getAttribute('content'), 'data:image')) {
continue;
}
$rmetas[$property] = $this->makeAbsoluteStr($baseUrl, $meta->getAttribute('content'));
continue;
}
$rmetas[$property] = $meta->getAttribute('content');
}
return $rmetas;
}