From 155c2f4ca8780f90adc5006523b518dae30c5a87 Mon Sep 17 00:00:00 2001 From: Mitchell McKenna Date: Sun, 17 Feb 2013 22:12:17 -0800 Subject: [PATCH] Fallback to use image_src if ogp::image isn't set - Some websites (eg. imgur.com) don't have OGP tags but they do indicated an image associated with the page using image_src. Facebook's oEmbed falls back on this if OGP data isn't avalable. --- OpenGraph.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/OpenGraph.php b/OpenGraph.php index af26618..0ec72c3 100644 --- a/OpenGraph.php +++ b/OpenGraph.php @@ -107,6 +107,20 @@ static private function _parse($HTML) { $page->_values['description'] = $nonOgDescription; } + //Fallback to use image_src if ogp::image isn't set. + if (!isset($page->values['image'])) { + $domxpath = new DOMXPath($doc); + $elements = $domxpath->query("//link[@rel='image_src']"); + + if ($elements->length > 0) { + $domattr = $elements->item(0)->attributes->getNamedItem('href'); + if ($domattr) { + $page->_values['image'] = $domattr->value; + $page->_values['image_src'] = $domattr->value; + } + } + } + if (empty($page->_values)) { return false; } return $page;