media_youtube.module 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @file media_youtube/media_youtube.module
  4. *
  5. * Media: YouTube provides a stream wrapper and formatters for videos provided
  6. * by YouTube, available at http://youtube.com/.
  7. *
  8. * @TODO:
  9. * Tie in YouTube API.
  10. * Allow editors to search for videos to display on the browser.
  11. * Allow editors to put in a youtube username to display on the browser.
  12. * Allow editors to log in w/ their credentials.
  13. * Allow editors to upload videos to YouTube.
  14. */
  15. // A registry of variable_get defaults.
  16. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.variables.inc';
  17. // Hooks and callbacks for integrating with Styles module for display.
  18. // @todo Can save a little overhead for people without Styles module by wrapping
  19. // this inside a module_exists('styles'). However, is that safe to do in
  20. // global context? If not, is there any down side to doing it in hook_init()?
  21. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.styles.inc';
  22. // Hooks and callbacks for integrating with File Entity module for display.
  23. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/media_youtube.formatters.inc';
  24. /**
  25. * Implements hook_media_internet_providers().
  26. */
  27. function media_youtube_media_internet_providers() {
  28. $path = drupal_get_path('module', 'media_youtube');
  29. return array(
  30. 'MediaInternetYouTubeHandler' => array(
  31. 'title' => 'youtube',
  32. 'image' => $path . '/images/stream-youtube.png'
  33. ),
  34. );
  35. }
  36. /**
  37. * Implements hook_stream_wrappers().
  38. */
  39. function media_youtube_stream_wrappers() {
  40. return array(
  41. 'youtube' => array(
  42. 'name' => t('YouTube videos'),
  43. 'class' => 'MediaYouTubeStreamWrapper',
  44. 'description' => t('Videos provided by YouTube.'),
  45. 'type' => STREAM_WRAPPERS_READ_VISIBLE,
  46. ),
  47. );
  48. }
  49. /**
  50. * Implements hook_theme().
  51. */
  52. function media_youtube_theme($existing, $type, $theme, $path) {
  53. return array(
  54. 'media_youtube_preview_style' => array(
  55. 'variables' => array('style_name' => NULL),
  56. 'file' => 'media_youtube.theme.inc',
  57. 'path' => $path . '/includes/themes',
  58. ),
  59. 'media_youtube_field_formatter_styles' => array(
  60. 'variables' => array('element' => NULL, 'style' => NULL),
  61. 'file' => 'media_youtube.theme.inc',
  62. 'path' => $path . '/includes/themes',
  63. ),
  64. // Note that all the variables after options are now deprecated.
  65. 'media_youtube_video' => array(
  66. 'variables' => array('uri' => NULL, 'options' => array(), 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'fullscreen' => NULL, 'related' => NULL),
  67. 'file' => 'media_youtube.theme.inc',
  68. 'path' => $path . '/includes/themes',
  69. 'template' => 'media-youtube-video',
  70. ),
  71. 'media_youtube_embed' => array(
  72. 'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL),
  73. 'file' => 'media_youtube.theme.inc',
  74. 'path' => $path . '/includes/themes',
  75. ),
  76. 'media_youtube_styles' => array(
  77. 'variables' => array('element' => NULL, 'style' => NULL),
  78. 'file' => 'media_youtube.theme.inc',
  79. 'path' => $path . '/includes/themes',
  80. ),
  81. );
  82. }
  83. /**
  84. * Implements hook_media_parse().
  85. *
  86. * @todo This hook should be deprecated. Refactor Media module to not call it
  87. * any more, since media_internet should be able to automatically route to the
  88. * appropriate handler.
  89. */
  90. function media_youtube_media_parse($embed_code) {
  91. $handler = new MediaInternetYouTubeHandler($embed_code);
  92. return $handler->parse($embed_code);
  93. }
  94. /**
  95. * Implements hook_media_format_form_prepare_alter().
  96. */
  97. function media_youtube_media_format_form_prepare_alter(&$form, &$form_state, $media) {
  98. $settings = array('autosubmit' => ($media->type == "video"));
  99. drupal_add_js(array('media_format_form' => $settings), 'setting');
  100. }
  101. /**
  102. * Implements hook_ctools_plugin_api().
  103. */
  104. function media_youtube_ctools_plugin_api($owner, $api) {
  105. static $api_versions = array(
  106. 'file_entity' => array(
  107. 'file_default_displays' => 1,
  108. ),
  109. );
  110. if (isset($api_versions[$owner][$api])) {
  111. return array('version' => $api_versions[$owner][$api]);
  112. }
  113. }