You are here

protected function JuiceboxGalleryDrupal::styleImage in Juicebox HTML5 Responsive Image Galleries 7.2

Utility to style an individual image/file field item for use in a Juicebox gallery.

This method can detect if the passed item is incompatible with Juicebox. If so it styles the output as a mimetype image icon representing the file type. Otherwise the item is styled normally with the passed image style.

Parameters

array $item: An associative array of file field item data to append Juicebox styled image data to.

string $style: The Drupal image style to apply to the item.

boolean $check_compatible: Whether-or-not to detect if the item is compatible with Juicebox, and if so, substitute a mimetype icon for its output.

1 call to JuiceboxGalleryDrupal::styleImage()
JuiceboxGalleryDrupal::styleImageSrcData in includes/JuiceboxGalleryDrupal.inc
Utility to extract image source data in an array structure that can be used when adding a new image to the gallery.

File

includes/JuiceboxGalleryDrupal.inc, line 212
Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.

Class

JuiceboxGalleryDrupal
Class to extend a JuiceboxGalleryDecorator object with Drupal-specific logic and structures.

Code

protected function styleImage(&$item, $style, $check_compatible = TRUE) {
  $item['juicebox_compatible'] = TRUE;

  // Set the normal, unstyled, url for reference.
  $item['unstyled_src'] = file_create_url($item['uri']);

  // Check compatibility if configured and if the library info contains
  // mimetype compatibitly information.
  if ($check_compatible && !empty($this->library['compatible_mimetypes']) && !in_array($item['filemime'], $this->library['compatible_mimetypes'])) {

    // If the item is not compatible, find the substitute mimetype icon.
    $item['juicebox_compatible'] = FALSE;
    $icon_dir = drupal_get_path('module', 'juicebox') . '/images/mimetypes';
    $icon_path = file_icon_path((object) $item, $icon_dir);
    if ($icon_path) {
      $item['juicebox_src_data']['image_url'] = file_create_url($icon_path);
    }
    else {
      $item['juicebox_src_data']['image_url'] = file_create_url($icon_dir . '/image-x-generic.png');
    }
  }
  else {
    $sizes = array(
      'image_url' => $style,
    );

    // The "juicebox_multisize" style is special, and actually consists of 3
    // individual styles configured globally.
    if ($style == 'juicebox_multisize') {
      $sizes = array(
        'image_url_small' => variable_get('juicebox_multisize_small', 'juicebox_small'),
        'image_url' => variable_get('juicebox_multisize_medium', 'juicebox_medium'),
        'image_url_large' => variable_get('juicebox_multisize_large', 'juicebox_large'),
      );
    }
    foreach ($sizes as $size => $style_each) {
      if (!empty($style_each)) {
        $item['juicebox_src_data'][$size] = image_style_url($style_each, $item['uri']);
      }
      else {
        $item['juicebox_src_data'][$size] = $item['unstyled_src'];
      }
    }
  }
}