You are here

function slick_get_media_switch in Slick Carousel 7.2

Returns the media switch: colorbox/photobox, content, excluding iframe.

1 call to slick_get_media_switch()
slick_get_image in includes/slick.global.inc
Returns the image/video/audio either using Picture mapping, or lazyload.

File

includes/slick.global.inc, line 109
Global functions across Slick field formatters and Views.

Code

function slick_get_media_switch(&$image = array(), $file = array(), $settings = array()) {
  $item = $image['#item'];
  $switch = str_replace('-switch', '', $settings['media_switch']);

  // Provide relevant file URL if it is a lightbox.
  if (!empty($settings['lightbox']) && !empty($settings['lightbox_ready'])) {
    $json = array(
      'type' => $item['type'],
    );
    if (!empty($item['embed_url'])) {
      $url = $item['embed_url'];
      $json['scheme'] = $item['scheme'];

      // Force autoplay for media URL on lightboxes, saving another click.
      if ($json['scheme'] == 'soundcloud') {
        if (strpos($url, 'auto_play') === FALSE || strpos($url, 'auto_play=false') !== FALSE) {
          $url = strpos($url, '?') === FALSE ? $url . '?auto_play=true' : $url . '&auto_play=true';
        }
      }
      elseif (strpos($url, 'autoplay') === FALSE || strpos($url, 'autoplay=0') !== FALSE) {
        $url = strpos($url, '?') === FALSE ? $url . '?autoplay=1' : $url . '&autoplay=1';
      }
    }
    else {
      $url = !empty($settings['box_style']) ? image_style_url($settings['box_style'], $item['uri']) : file_create_url($item['uri']);
    }
    $classes = array(
      'slick__' . $switch,
      'litebox',
    );
    if ($switch == 'colorbox' && $settings['count'] > 1) {
      $json['rel'] = $settings['id'];
    }
    elseif ($switch == 'photobox' && !empty($item['embed_url'])) {
      $image['#url_attributes']['rel'] = 'video';
    }
    elseif ($switch == 'slickbox') {
      $classes = array(
        'slick__box',
        'litebox',
      );
      $json['entity_id'] = $settings['entity_id'];
      if (!empty($settings['entity_uri']) && !empty($settings['use_ajax'])) {
        $url = $settings['entity_uri'];
        $json['ajax'] = TRUE;
      }
    }

    // Video/audio has special attributes for JS interaction.
    if ($item['type'] != 'image') {
      $json['player'] = TRUE;
      $json['height'] = empty($settings['box_height']) ? $item['height'] : $settings['box_height'];
      $json['width'] = empty($settings['box_width']) ? $item['width'] : $settings['box_width'];
    }
    $image['#url'] = $url;
    $image['#url_attributes']['class'] = $classes;
    $image['#url_attributes']['data-media'] = drupal_json_encode($json);
    if (!empty($settings['box_caption'])) {
      $image['#captions']['lightbox'] = slick_build_captions($item, $file, $settings);
    }
  }
  elseif ($switch == 'content' && !empty($settings['entity_uri'])) {
    $image['#url'] = $settings['entity_uri'];
  }
}