public function OpenGraphMeta::harvest_images_from_node in Open Graph meta tags 7
Same name and namespace in other branches
- 6 opengraph_meta.common.inc \OpenGraphMeta::harvest_images_from_node()
Harvest all images from the given node.
Return value
array(array('title' => , 'alt' => , 'url' =>))
1 call to OpenGraphMeta::harvest_images_from_node()
- OpenGraphMeta::get_og_tag_defaults in ./
opengraph_meta.common.inc - Get default values for all meta tags (including optional ones).
File
- ./
opengraph_meta.common.inc, line 294
Class
Code
public function harvest_images_from_node($node) {
// extract image fields
$ret = array();
OpenGraphMetaDrupalLayer::extract_image_fields((array) $node, $ret);
// extract all images from body content
$body = OpenGraphMetaDrupalLayer::get_node_body($node);
if (!empty($body)) {
libxml_use_internal_errors(TRUE);
// turn off libxml errors for now
$doc = new DOMDocument();
$doc
->loadHTML($body);
$list = $doc
->getElementsByTagName('img');
for ($i = 0; $list->length > $i; ++$i) {
$item = $list
->item($i);
if ($item
->hasAttribute('src')) {
$url = $item
->getAttribute('src');
if (!empty($url)) {
$ret[$url] = array(
'title' => $url,
'alt' => $url,
'url' => $url,
);
}
}
}
libxml_use_internal_errors(FALSE);
// turn libxml errors back on
}
return $ret;
}