You are here

media_youtube.module in Media: YouTube 7

media_youtube/media_youtube.module

Media: YouTube provides a stream wrapper and formatters for videos provided by YouTube, available at http://youtube.com/.

@TODO: Tie in YouTube API. Allow editors to search for videos to display on the browser. Allow editors to put in a youtube username to display on the browser. Allow editors to log in w/ their credentials. Allow editors to upload videos to YouTube.

File

media_youtube.module
View source
<?php

/**
 * @file media_youtube/media_youtube.module
 *
 * Media: YouTube provides a stream wrapper and formatters for videos provided
 * by YouTube, available at http://youtube.com/.
 *
 * @TODO:
 * Tie in YouTube API.
 * Allow editors to search for videos to display on the browser.
 * Allow editors to put in a youtube username to display on the browser.
 * Allow editors to log in w/ their credentials.
 * Allow editors to upload videos to YouTube.
 */

// A registry of variable_get defaults.
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.variables.inc';

// Hooks and callbacks for integrating with Styles module for display.
// @todo Can save a little overhead for people without Styles module by wrapping
//   this inside a module_exists('styles'). However, is that safe to do in
//   global context? If not, is there any down side to doing it in hook_init()?
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.styles.inc';

// Hooks and callbacks for integrating with File Entity module for display.
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.formatters.inc';

/**
 * Implements hook_media_internet_providers().
 */
function media_youtube_media_internet_providers() {
  $info['MediaInternetYouTubeHandler'] = array(
    'title' => t('YouTube'),
    'image' => drupal_get_path('module', 'media_youtube') . '/images/stream-youtube.png',
  );
  return $info;
}

/**
 * Implements hook_stream_wrappers().
 */
function media_youtube_stream_wrappers() {
  return array(
    'youtube' => array(
      'name' => t('YouTube videos'),
      'class' => 'MediaYouTubeStreamWrapper',
      'description' => t('Videos provided by YouTube.'),
      'type' => STREAM_WRAPPERS_READ_VISIBLE,
    ),
  );
}

/**
 * Implements hook_theme().
 */
function media_youtube_theme($existing, $type, $theme, $path) {
  return array(
    'media_youtube_preview_style' => array(
      'variables' => array(
        'style_name' => NULL,
      ),
      'file' => 'media_youtube.theme.inc',
      'path' => $path . '/includes/themes',
    ),
    'media_youtube_field_formatter_styles' => array(
      'variables' => array(
        'element' => NULL,
        'style' => NULL,
      ),
      'file' => 'media_youtube.theme.inc',
      'path' => $path . '/includes/themes',
    ),
    // Note that all the variables after options are now deprecated.
    'media_youtube_video' => array(
      'variables' => array(
        'uri' => NULL,
        'options' => array(),
        'width' => NULL,
        'height' => NULL,
        'autoplay' => NULL,
        'fullscreen' => NULL,
        'related' => NULL,
      ),
      'file' => 'media_youtube.theme.inc',
      'path' => $path . '/includes/themes',
      'template' => 'media-youtube-video',
    ),
    'media_youtube_embed' => array(
      'variables' => array(
        'style_name' => NULL,
        'uri' => NULL,
        'alt' => NULL,
        'title' => NULL,
      ),
      'file' => 'media_youtube.theme.inc',
      'path' => $path . '/includes/themes',
    ),
    'media_youtube_styles' => array(
      'variables' => array(
        'element' => NULL,
        'style' => NULL,
      ),
      'file' => 'media_youtube.theme.inc',
      'path' => $path . '/includes/themes',
    ),
  );
}

/**
 * Implements hook_media_parse().
 *
 * @todo This hook should be deprecated. Refactor Media module to not call it
 *   any more, since media_internet should be able to automatically route to the
 *   appropriate handler.
 */
function media_youtube_media_parse($embed_code) {
  $handler = new MediaInternetYouTubeHandler($embed_code);
  return $handler
    ->parse($embed_code);
}

/**
 * Implements hook_media_format_form_prepare_alter().
 */
function media_youtube_media_format_form_prepare_alter(&$form, &$form_state, $media) {
  $settings = array(
    'autosubmit' => $media->type == "video",
  );
  drupal_add_js(array(
    'media_format_form' => $settings,
  ), 'setting');
}

/**
 * Implements hook_ctools_plugin_api().
 */
function media_youtube_ctools_plugin_api($owner, $api) {
  static $api_versions = array(
    'file_entity' => array(
      'file_default_displays' => 1,
    ),
  );
  if (isset($api_versions[$owner][$api])) {
    return array(
      'version' => $api_versions[$owner][$api],
    );
  }
}