Skip to content

Commit

Permalink
Merge pull request #9 from MitchellMcKenna/feature/image_src-fallback
Browse files Browse the repository at this point in the history
Fallback to use image_src if ogp::image isn't set
  • Loading branch information
scottmac committed Mar 18, 2013
2 parents 8043880 + 155c2f4 commit faba415
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 @@ -125,6 +125,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

3 comments on commit faba415

@AramZS
Copy link
Contributor

@AramZS AramZS commented on faba415 Jan 8, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch does not properly call the _value instead calling value, resulting in it always failing. This hits #29 #27 #7 #14 - Patch via PR incoming.

@AramZS
Copy link
Contributor

@AramZS AramZS commented on faba415 Jan 8, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pea
Copy link

@pea pea commented on faba415 Jul 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Please sign in to comment.