You are here

function googtube_vimeo in Googtube 6.2

Same name and namespace in other branches
  1. 6 googtube.module \googtube_vimeo()
  2. 7.2 googtube.module \googtube_vimeo()
  3. 7 googtube.module \googtube_vimeo()
1 call to googtube_vimeo()
googtube_filter in ./googtube.module

File

./googtube.module, line 213

Code

function googtube_vimeo($match, $format) {

  // extract id from complete url
  $parsed_url = parse_url(check_url($match));
  $vimeo_id = substr($parsed_url['path'], strripos($parsed_url['path'], "/") + 1);
  $headers = get_headers("http://vimeo.com/api/v2/video/" . $vimeo_id . ".php");

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

    // existing video
    // load info about video
    $videodata = file_get_contents("http://vimeo.com/api/v2/video/" . $vimeo_id . ".php");

    // parse videodata
    $hash = unserialize($videodata);

    // replace incorrect double hyphens in description by single hyphens (found some video's with these)
    $vimeo_description = str_replace('"', '\'', $hash[0]['description']);

    // set height and width from videoinfo or from settings
    if (variable_get('googtube_info_hw', 1)) {
      $height = $hash[0]['height'];
      $width = $hash[0]['width'];
    }
    else {
      $height = variable_get('googtube_height');
      $width = variable_get('googtube_width');
    }
    $vimeo_title = $hash[0]['title'];
    $vimeo_thumbnail = $hash[0]['thumbnail_small'];
  }
  else {

    // non-existing video
    if (variable_get('googtube_removed', 1)) {

      // no: fill variables with Not available message
      $height = variable_get('googtube_height', '344');
      $width = variable_get('googtube_width', '425');
      $vimeo_title = t('Not available.');
      $vimeo_description = t('This video has been removed.');
      $vimeo_thumbnail = drupal_get_path('module', 'googtube') . '/default.jpg';
    }
    else {

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

  // construct html for each method
  switch (variable_get('googtube_method', 'embedded')) {
    case 'embedded':
      return '<object width="' . $width . '" height="' . $height . '"><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $vimeo_id . '&amp;server=vimeo.com&amp;show_byline=0&amp;show_portrait=0&amp;autoplay=' . variable_get('googtube_autoplay', 0) . '&amp;fullscreen=' . variable_get('googtube_fs', 0) . '" /></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://vimeo.com/moogaloop.swf?clip_id=' . $vimeo_id . '&amp;server=vimeo.com&amp;show_byline=0&amp;show_portrait=0&amp;fullscreen=' . variable_get('googtube_fs', 0) . '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' . $width . '" height="' . $height . '"></embed></object>';
      break;
    case 'iframe':
      return '<iframe class="vimeo-video" width="' . $width . '" height="' . $height . '" src="http://player.vimeo.com/video/' . $vimeo_id . '?fullscreen=' . variable_get('googtube_fs', 0) . '&autoplay=' . variable_get('googtube_autoplay', 0) . '&byline=0&portrait=0" frameborder="0" allowfullscreen></iframe>';
      break;
    case 'floatbox':
      return '<a href="http://player.vimeo.com/video/' . $vimeo_id . '?autoplay=' . variable_get('googtube_autoplay', 0) . '&amp;fullscreen=' . variable_get('googtube_fs', 0) . '&amp;byline=0&amp;portrait=0" class="floatbox vimeo-video" data-fb-options="width:' . $width . ' height:' . $height . ' autoFitMedia:true"><img title="' . $vimeo_title . ': ' . $vimeo_description . ' ' . t('[CLICK TO PLAY VIDEO]') . '"src="' . $vimeo_thumbnail . '" /></a>';
      break;
    case 'colorbox':
      return '<a class="colorbox-load" href="http://player.vimeo.com/video/' . $vimeo_id . '?autoplay=' . variable_get('googtube_autoplay', 0) . '&amp;fullscreen=' . variable_get('googtube_fs', 0) . '&amp;byline=0&amp;portrait=0&amp;width=' . $width . '&amp;height=' . $height . '&amp;iframe=true&amp;wmode=transparent" title="' . $vimeo_title . ': ' . $vimeo_description . '"><img title="' . $vimeo_title . ': ' . $vimeo_description . ' ' . t('[CLICK TO PLAY VIDEO]') . '"src="' . $vimeo_thumbnail . '" /></a>';
      break;
  }
}