You are here

function video_filter_youtube in Video Filter 7.3

Same name and namespace in other branches
  1. 5.2 video_filter.codecs.inc \video_filter_youtube()
  2. 5 video_filter.codecs.inc \video_filter_youtube()
  3. 6.3 video_filter.codecs.inc \video_filter_youtube()
  4. 6 video_filter.codecs.inc \video_filter_youtube()
  5. 6.2 video_filter.codecs.inc \video_filter_youtube()

Callback for YouTube codec.

See also

video_filter_codec_info()

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

File

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

Code

function video_filter_youtube($video) {
  $attributes = array(
    'modestbranding' => !empty($video['modestbranding']) ? 'modestbranding=1' : 'modestbranding=0',
    'rel' => !empty($video['related']) ? 'rel=1' : 'rel=0',
    'autoplay' => !empty($video['autoplay']) ? 'autoplay=1' : 'autoplay=0',
    'fs' => 'fs=1',
    'loop' => !empty($video['loop']) ? 'loop=1' : 'loop=0',
    'controls' => !empty($video['controls']) ? 'controls=1' : (!isset($video['controls']) ? 'controls=1' : 'controls=0'),
    'autohide' => !empty($video['autohide']) ? 'autohide=1' : 'autohide=0',
    'showinfo' => !empty($video['showinfo']) ? 'showinfo=1' : 'showinfo=0',
    'theme' => !empty($video['theme']) ? 'theme=' . $video['theme'] : 'theme=dark',
    'color' => !empty($video['color']) ? 'color=' . $video['color'] : 'color=red',
    'enablejsapi' => !empty($video['enablejsapi']) ? 'enablejsapi=' . (int) $video['enablejsapi'] : 'enablejsapi=0',
  );
  if (!empty($video['loop'])) {
    $attributes['playlist'] = 'playlist=' . $video['codec']['matches'][1];
  }
  if (preg_match('/[\\?|&]t=((?<minutes>\\d+m)?(?<seconds>\\d+s?)?)/', $video['source'], $matches)) {
    $attributes['start'] = 'start=' . (preg_replace("/[^0-9]/", "", $matches['minutes']) * 60 + preg_replace("/[^0-9]/", "", $matches['seconds']));
  }
  if (!empty($video['start'])) {
    if (preg_match('/((?<minutes>\\d+m)?(?<seconds>\\d+s?)?)/', $video['start'], $matches)) {
      $attributes['start'] = 'start=' . (preg_replace("/[^0-9]/", "", $matches['minutes']) * 60 + preg_replace("/[^0-9]/", "", $matches['seconds']));
    }
  }
  $video['source'] = '//www.youtube.com/embed/' . $video['codec']['matches'][1] . '?' . implode('&amp;', $attributes);
  $params['wmode'] = 'opaque';
  return video_filter_flash($video, $params);
}