Graby\Graby::extractOpenGraph PHP Method

extractOpenGraph() private method

Extract OpenGraph data from the response.
See also: http://stackoverflow.com/a/7454737/569101
private extractOpenGraph ( string $html, string $baseUrl ) : array
$html string
$baseUrl string Used to make the og:image absolute
return array
    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;
    }