You are here

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

Same name and namespace in other branches
  1. 7 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 547

Class

OpenGraphMetaDrupalLayer
Drupal compatibility layer.

Code

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