Skip to content

Commit

Permalink
Fallback to use image_src if ogp::image isn't set
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
MitchellMcKenna committed Feb 18, 2013
1 parent 8137872 commit 155c2f4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 155c2f4

Please sign in to comment.