You are here

function theme_emvideo_youtube_flash in Embedded Media Field 6

The embedded flash displaying the youtube video.

2 theme calls to theme_emvideo_youtube_flash()
emvideo_youtube_preview in contrib/emvideo/providers/youtube.inc
hook emvideo_PROVIDER_video this actually displays the preview-sized video we want, commonly for the teaser
emvideo_youtube_video in contrib/emvideo/providers/youtube.inc
hook emvideo_PROVIDER_video this actually displays the full/normal-sized video we want, usually on the default page view

File

contrib/emvideo/providers/youtube.inc, line 386
This include processes youtube.com media files for use by emfield.module.

Code

function theme_emvideo_youtube_flash($code, $width, $height, $autoplay, $options = array()) {
  static $count;
  $output = '';
  if ($code = check_plain($code)) {

    // Set the height and width.
    $width = intval($width);
    $height = intval($height);

    // Set the Full Screen option; if TRUE, then allow it.
    $fullscreen = isset($options['fullscreen']) ? $options['fullscreen'] : variable_get('emvideo_youtube_full_screen', 1);
    $fullscreen_value = $fullscreen ? "true" : "false";
    $fs = $fullscreen ? "&fs={$fullscreen}" : "";

    // Set the 'related videos' youtube option.
    $related = isset($options['related']) ? $options['related'] : variable_get('emvideo_youtube_show_related_videos', 0);
    $related = "rel={$related}";

    // Set the Autoplay option.
    $autoplay = isset($options['autoplay']) ? $options['autoplay'] : $autoplay;
    $autoplay_value = $autoplay ? '&autoplay=1' : '';

    // Set the custom colors.
    $show_colors = isset($options['show_colors']) ? $options['show_colors'] : variable_get('emvideo_youtube_show_colors', FALSE);
    $colors = '';
    if ($show_colors) {
      $color1 = isset($options['color1']) ? $options['color1'] : variable_get('emvideo_youtube_colors_color1', emvideo_YOUTUBE_COLOR1_DEFAULT);
      $color2 = isset($options['color2']) ? $options['color2'] : variable_get('emvideo_youtube_colors_color2', emvideo_YOUTUBE_COLOR2_DEFAULT);
      $colors = '&color1=0x' . emvideo_youtube_convert_color($color1) . '&color2=0x' . emvideo_youtube_convert_color($color2);
    }

    // Set the custom border; if TRUE, then display a big border.
    $border = isset($options['border']) ? $options['border'] : variable_get('emvideo_youtube_show_border', FALSE);
    $border = $border ? '&border=1' : '';

    // Enable JS for playback control.
    $enablejsapi = isset($options['enablejsapi']) ? $options['enablejsapi'] : variable_get('emvideo_youtube_enablejsapi', TRUE);
    $enablejsapi = $enablejsapi ? '&enablejsapi=1&playerapiid=ytplayer' : '';

    // Set the div ID for CSS.
    $id = check_plain(isset($options['id']) ? $options['id'] : 'emvideo-youtube-flash-' . ++$count);
    $div_id = check_plain(isset($options['div_id']) ? $options['div_id'] : 'emvideo-youtube-flash-wrapper-' . $count);

    // Whether to allow high quality videos or not.
    $high_quality = isset($options['high_quality']) ? $options['high_quality'] : variable_get('emvideo_youtube_high_quality', FALSE);
    $high_quality = $high_quality ? '&hd=1' : '';

    // Whether to display the video's info from YouTube in the player.
    $display_info = isset($options['display_info']) ? $options['display_info'] : variable_get('emvideo_youtube_display_info', FALSE);
    $display_info = $display_info ? '&showinfo=0' : '';

    // Create a URL from our options.
    if ($options['item']['data']['playlist']) {
      $code = substr($code, 9);
      $url = check_plain("http://www.youtube.com/p/{$code}&{$related}{$autoplay_value}{$colors}{$border}{$high_quality}{$display_info}{$enablejsapi}{$fs}");
    }
    else {
      $url = check_plain("http://www.youtube.com/v/{$code}&{$related}{$autoplay_value}{$colors}{$border}{$high_quality}{$display_info}{$enablejsapi}{$fs}");
    }

    // Find the path to the JW FLV Media Player.
    $path = emfield_flvmediaplayer_url();

    // If the JW FLV Player has been installed, the yt.swf file is in the same
    // folder, and the server has been configured to use it for YouTube videos,
    // then we'll do so now.
    $use_flv = isset($options['use_flv']) ? $options['use_flv'] : variable_get('emvideo_youtube_use_jw_flv', FALSE);

    // Set up the FLV Media Player options, assuming we're supposed to,
    // and the player is actually installed on the system.
    if ($use_flv && ($flv_path = emfield_flvmediaplayer_url()) && _emvideo_youtube_check_flv_player_setup()) {
      global $base_path;

      // Build the Thumbnail image for the player.
      $tn_options = array(
        'width' => $width,
        'height' => $height,
        'return_url' => TRUE,
      );
      $flashvars = array();

      // Grab the thumbnail for this video and tell JW FLV Player about it.
      $flashvars['image'] = theme('emvideo_video_thumbnail', NULL, $options['item'], 'emvideo_thumbnail', $options['node'], TRUE, $tn_options);

      // Tell the FLV Player we're sending a YouTube video.
      $flashvars['type'] = 'youtube';

      // We need to set the file to the original YouTube video.
      $flashvars['file'] = $url;

      // The JW FLV Player uses its own autoplay flashvar.
      $flashvars['autostart'] = $autoplay ? 'true' : 'false';

      // The URL will now be the JW FLV Player.
      $url = $base_path . $flv_path;
    }
    else {

      // We don't have access to FLV Media Player, so reset the option.
      $use_flv = FALSE;
    }
    if ($use_flv && module_exists('flvmediaplayer')) {

      // If we are using the JW FLV Player, defer to the flvmediaplayer module
      // for display.
      $params['width'] = $width;
      $params['height'] = $height;
      $params['div_id'] = $id;
      $params['allowFullScreen'] = $fullscreen_value;

      // If we have been told to use a specific FLV Player Option from
      // that module, then use it here.
      $flv_profile = isset($options['flv_profile']) ? $options['flv_profile'] : variable_get('emfield_flv_profile', '');
      if ($flv_profile) {

        // Get the configuration data for this profile.
        $data = flvmediaplayer_build_player_data($options['node'], $flv_profile, array(
          'file' => $flashvars['file'],
        ));
        $data['params']['width'] = $width;
        $data['params']['height'] = $height;
        $data['flashvars']['autostart'] = $flashvars['autostart'];
        $data['params']['allowFullScreen'] = $fullscreen_value;
        $data['params']['wmode'] = 'transparent';
        $data['flashvars']['image'] = $flashvars['image'];
        $output = theme('flvmediaplayer_render_player', $url, $data['params'], $data['flashvars']);
      }
      else {

        // Just display the default jw flv media player.
        $output = theme('flvmediaplayer_render_player', $url, $params, $flashvars);
      }
    }
    else {
      if (variable_get('emfield_swfobject', FALSE) && (module_exists('swfobject_api') || variable_get('emfield_swfobject_location', ''))) {

        // Use SWFObject API module if it's installed.
        // Note that we're going to try to send the Flv Media player as well,
        // assuming it's been set up and the flvmediaplayer module has not.
        $params['width'] = $width;
        $params['height'] = $height;
        $params['div_id'] = $id;
        $params['allowFullScreen'] = $fullscreen_value;
        $params['wmode'] = 'transparent';
        $output = theme('emfield_swfobject', $url, $params, $flashvars, $id);
      }
      else {
        if ($use_flv) {

          // We need to grab the thumbnail again for the NOEMBED option,
          // for accessibility compliance.
          // See http://www.w3.org/TR/WCAG10-HTML-TECHS/#text-equivs-multimedia.
          unset($tn_options['return_url']);
          $noembed = theme('emvideo_video_thumbnail', NULL, $options['item'], 'emvideo_thumbnail', $options['node'], TRUE, $tn_options);
          $flv_path = url($flv_path);
          $flashvars = check_plain(drupal_query_string_encode($flashvars));

          // Use object tags rather than embed.
          // See http://www.alistapart.com/articles/flashsatay
          $output = <<<FLV
        <div id="{<span class="php-variable">$div_id</span>}">
          <object
            type="application/x-shockwave-flash" data="{<span class="php-variable">$flv_path</span>}"
            width="{<span class="php-variable">$width</span>}" height="{<span class="php-variable">$height</span>}" id="{<span class="php-variable">$id</span>}">
            <param name="movie" value="{<span class="php-variable">$flv_path</span>}" />
            <param name="flashvars" value="{<span class="php-variable">$flashvars</span>}" />
            <param name="wmode" value="transparent" />
            {<span class="php-variable">$noembed</span>}
          </object>
        </div>
FLV;
        }
        else {

          // The fallback is to display plain old vanilla youtube.
          $flashvars = check_plain(drupal_query_string_encode(array(
            'playerMode' => 'embedded',
          )));
          $output = theme('emvideo_youtube_default_external', $height, $width, $url, $id, $div_id, $fullscreen_value, $flashvars);
        }
      }
    }
  }
  return '<div class="emfield-emvideo emfield-emvideo-youtube">' . $output . '</div>';
}