You are here

function video_filter_wistia_html5 in Video Filter 6.3

Same name and namespace in other branches
  1. 7.3 video_filter.codecs.inc \video_filter_wistia_html5()

Callback for Wistia codec.

Adapted from the media_wistia module.

See also

video_filter_codec_info()

1 string reference to 'video_filter_wistia_html5'
video_filter_codec_info in ./video_filter.codecs.inc
Implements hook_codec_info().

File

./video_filter.codecs.inc, line 534
This file contains all codecs provided by Video Filter.

Code

function video_filter_wistia_html5($video) {
  $video_code = $video['codec']['matches'][7];
  $matches = $video['codec']['matches'];
  $embed_type = $matches[4] == 'projects' || $matches[6] == 'playlists' ? 'playlists' : 'iframe';

  // Get embed code via oEmbed.
  $endpoint = 'http://fast.wistia.com/oembed';
  $options = array(
    'url' => "http://fast.wistia.com/embed/{$embed_type}/{$video_code}",
    'width' => $video['width'],
    'height' => $video['height'],
  );
  $data = video_filter_oembed_request($endpoint, $options);
  $html = $data['html'];

  // See if the video source is already an iframe src.
  $pattern = '@https?://fast.wistia.(com|net)/embed/(iframe|playlists)/[a-zA-Z0-9]+\\?+.+@';
  $matches = array();
  if (preg_match($pattern, $video['source'], $matches)) {

    // Replace the oEmbed iframe src with that provided in the token, in order
    // to support embed builder URLs.
    $pattern = '@https?://fast.wistia.(com|net)/embed/(iframe|playlists)/[a-zA-Z0-9]+\\?[^"]+@';
    $replacement = $matches[0];
    $html = preg_replace($pattern, $replacement, $html);
  }
  return $html;
}