You are here

function video_embed_field_handle_youtube in Video Embed Field 7

Same name and namespace in other branches
  1. 7.2 video_embed_field.handlers.inc \video_embed_field_handle_youtube()

handler for youtube videos

1 string reference to 'video_embed_field_handle_youtube'
video_embed_field_video_embed_handler_info in ./video_embed_field.module
Implementation of hook_video_embed_handler_info

File

./video_embed_field.module, line 417

Code

function video_embed_field_handle_youtube($url, $settings, $type = 'video', $image_size = 'small') {

  //figure out the id of the video they want to play from the url

  //strip off the http
  if (stristr($url, 'http://')) {
    $url = substr($url, 7);
  }
  else {
    if (stristr($url, 'https://')) {
      $url = substr($url, 8);
    }
  }
  $pos = strripos($url, 'v=');
  if ($pos !== FALSE) {
    $pos += 2;
    $pos2 = stripos($url, '&', $pos);
  }
  else {
    $pos = strripos($url, '/');
    if ($pos !== FALSE) {
      $pos++;
      $pos2 = stripos($url, '?', $pos);
    }
  }
  if ($pos === FALSE) {

    //we can't figure out the url - just return the url as a link
    return l($url, $url);
  }
  else {
    if ($pos2 > 0) {
      $id = substr($url, $pos, $pos2 - $pos);
    }
    else {
      $id = substr($url, $pos);
    }
  }
  if ($type == 'image') {
    if ($image_size == 'large') {
      return '<img src="' . 'http://img.youtube.com/vi/' . $id . '/0.jpg' . '" />';

      // large
    }
    else {

      // small and medium have same size for youtube
      return '<img src="' . 'http://img.youtube.com/vi/' . $id . '/2.jpg' . '" />';

      // small
    }
  }
  else {

    //get settings
    $teaser = $type == 'teaser';
    $height = $teaser ? $settings['teaser_height'] : $settings['height'];
    $width = $teaser ? $settings['teaser_width'] : $settings['width'];
    $hd = $settings['hd'];
    $rel = $settings['rel'];
    $autoplay = $settings['autoplay'];
    $autohide = $settings['autohide'];
    $showinfo = $settings['showinfo'];
    $theme = $settings['theme'];
    $template_start = '<iframe width="' . $width . '" height="' . $height . '" src="';
    $template_end = '?hd=' . $hd . '&amp;rel=' . $rel . '&amp;wmode=opaque&amp;autoplay=' . $autoplay . '&amp;theme=' . $theme . '&amp;autohide=' . $autohide . '&amp;showinfo=' . $showinfo . '" frameborder="0" allowfullscreen></iframe>';
    $url_temp = 'http://www.youtube.com/embed/';
    return $template_start . $url_temp . $id . $template_end;
  }
}