You are here

public function OpenGraphMeta::extractImageFields in Open Graph meta tags 7.2

Harvest images from node's image fields.

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

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

File

./opengraph_meta.common.inc, line 75

Class

OpenGraphMeta

Code

public function extractImageFields($fields) {
  $result = [];
  if (is_array($fields)) {
    if (!empty($fields['filemime']) && FALSE !== stripos($fields['filemime'], 'image') && !empty($fields['uri'])) {
      $url = $fields['uri'];
      $thumb_url = image_style_url($this->thumbnailStyle, $fields['uri']);
      $result[$url] = array(
        'title' => !empty($fields['title']) ? $fields['title'] : $url,
        'alt' => !empty($fields['alt']) ? $fields['alt'] : $url,
        'url' => $thumb_url,
      );
    }
    else {
      foreach ($fields as $cv) {
        $result += $this
          ->extractImageFields($cv);
      }
    }
  }
  return $result;
}