You are here

public static function OpenGraphMetaDrupalLayer::extract_image_fields in Open Graph meta tags 7

Same name and namespace in other branches
  1. 6 opengraph_meta.common.inc \OpenGraphMetaDrupalLayer::extract_image_fields()

Harvest images from node's image fields.

array_walk_recursive() doesn't give us enough flexibility so we do the recursion manually.

Parameters

$resultarray will hold results.:

1 call to OpenGraphMetaDrupalLayer::extract_image_fields()
OpenGraphMeta::harvest_images_from_node in ./opengraph_meta.common.inc
Harvest all images from the given node.

File

./opengraph_meta.common.inc, line 495

Class

OpenGraphMetaDrupalLayer
Drupal compatibility layer.

Code

public static function extract_image_fields($fields, array &$resultarray) {
  if (is_array($fields)) {
    if (!empty($fields['filemime']) && FALSE !== stripos($fields['filemime'], 'image') && !empty($fields['uri'])) {
      $url = $fields['uri'];
      $thumb_url = image_style_url('thumbnail', $fields['uri']);
      $resultarray[$url] = array(
        'title' => !empty($fields['title']) ? $fields['title'] : $url,
        'alt' => !empty($fields['alt']) ? $fields['alt'] : $url,
        'url' => $thumb_url,
      );
    }
    else {
      foreach ($fields as $cv) {
        self::extract_image_fields($cv, $resultarray);
      }
    }
  }
}