media_vimeo.module 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * @file media_vimeo/media_vimeo.module
  4. *
  5. * Media: Vimeo provides a stream wrapper and formatters for videos provided
  6. * by Vimeo, available at http://vimeo.com/.
  7. *
  8. * @TODO:
  9. * Tie in Vimeo API.
  10. * Allow editors to search for videos to display on the browser.
  11. * Allow editors to put in a vimeo username to display on the browser.
  12. * Allow editors to log in w/ their credentials.
  13. * Allow editors to upload videos to Vimeo.
  14. */
  15. // A registry of variable_get defaults.
  16. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_vimeo') . '/includes/media_vimeo.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_vimeo') . '/includes/media_vimeo.styles.inc';
  22. // Hooks and callbacks for integrating with File Entity module for display.
  23. include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_vimeo') . '/includes/media_vimeo.formatters.inc';
  24. /**
  25. * Implements hook_media_internet_providers().
  26. */
  27. function media_vimeo_media_internet_providers() {
  28. $path = drupal_get_path('module', 'media_vimeo');
  29. return array(
  30. 'MediaInternetVimeoHandler' => array(
  31. 'title' => 'vimeo',
  32. 'image' => $path . '/images/stream-vimeo.png'
  33. ),
  34. );
  35. }
  36. /**
  37. * Implements hook_stream_wrappers().
  38. */
  39. function media_vimeo_stream_wrappers() {
  40. return array(
  41. 'vimeo' => array(
  42. 'name' => t('Vimeo videos'),
  43. 'class' => 'MediaVimeoStreamWrapper',
  44. 'description' => t('Videos provided by Vimeo.'),
  45. 'type' => STREAM_WRAPPERS_READ_VISIBLE,
  46. ),
  47. );
  48. }
  49. /**
  50. * Implements hook_theme().
  51. */
  52. function media_vimeo_theme($existing, $type, $theme, $path) {
  53. return array(
  54. 'media_vimeo_preview_style' => array(
  55. 'variables' => array('style_name' => NULL),
  56. 'file' => 'media_vimeo.theme.inc',
  57. 'path' => $path . '/includes/themes',
  58. ),
  59. 'media_vimeo_field_formatter_styles' => array(
  60. 'variables' => array('element' => NULL, 'style' => NULL),
  61. 'file' => 'media_vimeo.theme.inc',
  62. 'path' => $path . '/includes/themes',
  63. ),
  64. 'media_vimeo_video' => array(
  65. 'variables' => array('uri' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL, 'fullscreen' => NULL),
  66. 'file' => 'media_vimeo.theme.inc',
  67. 'path' => $path . '/includes/themes',
  68. 'template' => 'media-vimeo-video',
  69. ),
  70. 'media_vimeo_embed' => array(
  71. 'variables' => array('style_name' => NULL, 'uri' => NULL, 'alt' => NULL, 'title' => NULL),
  72. 'file' => 'media_vimeo.theme.inc',
  73. 'path' => $path . '/includes/themes',
  74. ),
  75. 'media_vimeo_styles' => array(
  76. 'variables' => array('element' => NULL, 'style' => NULL),
  77. 'file' => 'media_vimeo.theme.inc',
  78. 'path' => $path . '/includes/themes',
  79. ),
  80. );
  81. }
  82. /**
  83. * Implements hook_media_parse().
  84. *
  85. * @todo This hook should be deprecated. Refactor Media module to not call it
  86. * any more, since media_internet should be able to automatically route to the
  87. * appropriate handler.
  88. */
  89. function media_vimeo_media_parse($embed_code) {
  90. $handler = new MediaInternetVimeoHandler($embed_code);
  91. return $handler->parse($embed_code);
  92. }
  93. /**
  94. * Implements hook_media_format_form_prepare_alter().
  95. */
  96. function media_vimeo_media_format_form_prepare_alter(&$form, &$form_state, $media) {
  97. $settings = array('autosubmit' => ($media->type == "video"));
  98. drupal_add_js(array('media_format_form' => $settings), 'setting');
  99. }
  100. /**
  101. * Implements hook_ctools_plugin_api().
  102. */
  103. function media_vimeo_ctools_plugin_api($owner, $api) {
  104. static $api_versions = array(
  105. 'file_entity' => array(
  106. 'file_default_displays' => 1,
  107. ),
  108. );
  109. if (isset($api_versions[$owner][$api])) {
  110. return array('version' => $api_versions[$owner][$api]);
  111. }
  112. }