You are here

function googtube_youtube in Googtube 7.2

Same name and namespace in other branches
  1. 5 googtube.module \googtube_youtube()
  2. 6.2 googtube.module \googtube_youtube()
  3. 6 googtube.module \googtube_youtube()
  4. 7 googtube.module \googtube_youtube()
1 call to googtube_youtube()
_googtube_process in ./googtube.module

File

./googtube.module, line 153

Code

function googtube_youtube($match, $filter) {

  // extract id from complete url
  $parsed_url = parse_url(check_url($match));
  parse_str($parsed_url['query'], $parsed_query);
  $youtube_id = $parsed_query['v'];
  $headers = get_headers("http://gdata.youtube.com/feeds/api/videos/" . $youtube_id);

  // existing video?
  if (preg_match('/^HTTP\\/\\d\\.\\d\\s+(200|301|302)/', $headers[0])) {

    // existing video
    // load info about video in xml format
    $xmlData = simplexml_load_file("http://gdata.youtube.com/feeds/api/videos/" . $youtube_id);

    // parse video entry
    $video = new stdClass();

    // get nodes in media: namespace for media information
    $media = $xmlData
      ->children('http://search.yahoo.com/mrss/');

    // get video title
    $video->title = $media->group->title;

    // get video description
    $video->description = $media->group->description;

    // get video thumbnail
    $attrs = $media->group->thumbnail[2]
      ->attributes();
    $video->thumbnailURL = $attrs['url'];

    // these variables include the video information
    $videos["title"] = strip_tags(stripslashes($video->title));
    $videos["description"] = strip_tags(str_replace('"', '\'', stripslashes($video->description)));
    $videos["thumbnail"] = stripslashes($video->thumbnailURL);
  }
  else {

    // non-existing video
    // show removed videos?
    if ($filter->settings['googtube_removed']) {

      // fill variables with Not available message
      $videos["title"] = t('Not available.');
      $videos["description"] = t('This video has been removed.');
      $videos["thumbnail"] = '/' . drupal_get_path('module', 'googtube') . '/default.jpg';
    }
    else {

      // don't show removed video
      return;
    }
  }

  // construct html for each method
  switch ($filter->settings['googtube_method']) {
    case 'embedded':
      return '<object width="' . $filter->settings['googtube_width'] . '" height="' . $filter->settings['googtube_height'] . '"><param name="movie" value="http://www.youtube.com/v/' . $youtube_id . '?version=3&fs=' . $filter->settings['googtube_fs'] . '&autoplay=' . $filter->settings['googtube_autoplay'] . '&rel=' . $filter->settings['googtube_rel'] . '"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $youtube_id . '?version=3&fs=' . $filter->settings['googtube_fs'] . '&autoplay=' . $filter->settings['googtube_autoplay'] . '&rel=' . $filter->settings['googtube_rel'] . '" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="' . $filter->settings['googtube_width'] . '" height="' . $filter->settings['googtube_height'] . '"></embed></object>';
      break;
    case 'iframe':
      return '<iframe class="youtube-video" width="' . $filter->settings['googtube_width'] . '" height="' . $filter->settings['googtube_height'] . '" src="http://www.youtube.com/embed/' . $youtube_id . '?fs=' . $filter->settings['googtube_fs'] . '&autoplay=' . $filter->settings['googtube_autoplay'] . '&rel=' . $filter->settings['googtube_rel'] . '" frameborder="0" allowfullscreen></iframe>';
      break;
    case 'floatbox':
      return '<a href="http://www.youtube.com/embed/' . $youtube_id . '?fs=' . $filter->settings['googtube_fs'] . '&rel=' . $filter->settings['googtube_rel'] . '&hd=1&autoplay=' . $filter->settings['googtube_autoplay'] . '" class="floatbox youtube-video" data-fb-options="width:' . $filter->settings['googtube_width'] . ' height:' . $filter->settings['googtube_height'] . ' autoFitMedia:true"><img title="' . $videos["title"] . ': ' . $videos["description"] . ' ' . t('[CLICK TO PLAY VIDEO]') . '" src="' . $videos["thumbnail"] . '" /></a>';
      break;
    case 'colorbox':
      return '<a class="colorbox-load youtube-video" href="http://www.youtube.com/embed/' . $youtube_id . '?fs=' . $filter->settings['googtube_fs'] . '&rel=' . $filter->settings['googtube_rel'] . '&hd=1&autoplay=' . $filter->settings['googtube_autoplay'] . '&amp;width=' . $filter->settings['googtube_width'] . '&amp;height=' . $filter->settings['googtube_height'] . '&amp;iframe=true&amp;wmode=transparent" title="' . $videos["title"] . ': ' . $videos["description"] . '"><img title="' . $videos["title"] . ': ' . $videos["description"] . ' ' . t('[CLICK TO PLAY VIDEO]') . '" src="' . $videos["thumbnail"] . '" /></a>';
      break;
  }
}