scottmac / opengraph

Helper class for accessing the OpenGraph Protocol
463 stars 151 forks source link

Google+ image #14

Open nerg4l opened 11 years ago

nerg4l commented 11 years ago

Google+ uses the to get a thumbnail from sites and facebook also added to their code so it would be great to use this meta tag also. And most of the site stopped using the link rel='image_src' (The New York Times too) so now I think it's unnecessary.

I changed that part to this:

    if (!isset($page->values['image'])) {
        $domxpath = new DOMXPath($doc);
        $elements = $domxpath->query("//meta[@itemprop='image']");

        if ($elements->length > 0) {
            $domattr = $elements->item(0)->attributes->getNamedItem('content');
            if ($domattr) {
                $page->_values['image'] = $domattr->value;
                $page->_values['image_src'] = $domattr->value;
            }
        }
    }

I also tried to creat an automatic image finder but I got in truble with that.