You are here

function slick_extract_media_data in Slick Carousel 7.2

Gets a media URL from the rendered iframe already containing all the params.

3 calls to slick_extract_media_data()
slick_format_media in includes/slick.media.inc
Formats image/media file data.
slick_get_media_url in includes/slick.extras.inc
Gets a media URL from the rendered iframe already containing all the params.
_slick_build_fc_overlay in includes/slick.field_collection.inc
Build the managed overlays: image, video, audio or nested slicks.

File

includes/slick.extras.inc, line 115
Contains optional functions called by frontend Media, or Field collection.

Code

function slick_extract_media_data(array &$settings, array &$media, $file = NULL) {

  // If a file has an invalid type, allow file_view_file() to work.
  if (!file_type_is_enabled($file->type)) {
    $file->type = file_get_type($file);
  }
  $media['type'] = $file->type;
  $media['scheme'] = file_uri_scheme($file->uri);
  $media['media_uri'] = $file->uri;

  // Needed settings: type scheme image_style uri view_mode.
  if (!slick_is_media($media['scheme'])) {
    return;
  }
  $renderables = file_view_file($file, $settings['view_mode']);

  // Only do the hard work if we do have a misconfigured file view mode.
  // This is a fallback for the failing expected output when all weights are 0,
  // and the non-supported schemes may screw up file_view_file().
  if (!isset($renderables['#uri'])) {
    $formatter = 'media_' . $media['scheme'] . '_' . $media['type'];
    $renderables = array(
      '#theme' => $formatter,
      '#uri' => $file->uri,
      '#options' => slick_load_media_settings($media['type'], $settings['view_mode'], $formatter),
    );
  }

  // Are we dealing with INLINE or LIGHTBOX audio/video dimensions?
  // LIGHTBOX videos need the actual video dimensions independent from images,
  // hence we put them into box_height and box_width taken from the active file
  // entity view mode as no custom settings for lightbox video dimensions, yet.
  $media['box_height'] = $renderables['#options']['height'];
  $media['box_width'] = $renderables['#options']['width'];

  // On the contrary, allows various INLINE iframe dimensions based on the given
  // image_style, good to re-use a single file view mode for various file host
  // entity view modes, and a mix of image and media with consistent dimensions.
  if (!empty($settings['image_style'])) {
    $settings['content_attributes']['width'] = $media['width'];
    $settings['content_attributes']['height'] = $media['height'];
  }
  $rendered_media = drupal_render($renderables);
  if (!empty($rendered_media) && strpos($rendered_media, 'src') !== FALSE) {
    $dom = new DOMDocument();
    libxml_use_internal_errors(TRUE);
    $dom
      ->loadHTML($rendered_media);
    $url = $dom
      ->getElementsByTagName('iframe')
      ->item(0)
      ->getAttribute('src');
    $media['embed_url'] = $url;
  }

  // Get audio/video thumbnail uri as opposed to the actual video uri.
  if ($media_image_uri = slick_get_media_thumbnail($settings, $media)) {
    $media['uri'] = $media_image_uri;
  }
}