media_vimeo.theme.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * @file media_vimeo/includes/themes/media_vimeo.theme.inc
  4. *
  5. * Theme and preprocess functions for Media: Vimeo.
  6. */
  7. /**
  8. * Preprocess function for theme('media_vimeo_video').
  9. */
  10. function media_vimeo_preprocess_media_vimeo_video(&$variables) {
  11. // Build the URL for display.
  12. $uri = $variables['uri'];
  13. $wrapper = file_stream_wrapper_get_instance_by_uri($uri);
  14. $parts = $wrapper->get_parameters();
  15. $variables['video_id'] = check_plain($parts['v']);
  16. $variables['width'] = isset($variables['width']) ? $variables['width'] : media_vimeo_variable_get('width');
  17. $variables['height'] = isset($variables['height']) ? $variables['height'] : media_vimeo_variable_get('height');
  18. $variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_vimeo_variable_get('autoplay');
  19. $variables['fullscreen'] = isset($variables['fullscreen']) ? $variables['fullscreen'] : media_vimeo_variable_get('fullscreen');
  20. $variables['autoplay'] = $variables['autoplay'] ? 1 : 0;
  21. $variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
  22. $variables['wrapper_id'] = 'media_vimeo_' . $variables['video_id'] . '_' . $variables['id'];
  23. // For users with JavaScript, these object and embed tags will be replaced
  24. // by an iframe, so that we can support users without Flash.
  25. $variables['output'] = <<<OUTPUT
  26. <object width="{$variables['width']}" height="{$variables['height']}">
  27. <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}">
  28. <param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
  29. <param name="wmode" value="transparent" />
  30. <embed src="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}"></embed>
  31. </object>
  32. OUTPUT;
  33. // Pass the settings to replace the object tag with an iframe.
  34. $settings = array(
  35. 'media_vimeo' => array(
  36. $variables['wrapper_id'] => array(
  37. 'width' => $variables['width'],
  38. 'height' => $variables['height'],
  39. 'video_id' => $variables['video_id'],
  40. 'fullscreen' => $variables['fullscreen'],
  41. 'id' => $variables['wrapper_id'] .'_iframe',
  42. ),
  43. ),
  44. );
  45. if ($variables['autoplay']) {
  46. $settings['media_vimeo'][$variables['wrapper_id']]['options'] = array(
  47. 'autoplay' => $variables['autoplay'],
  48. );
  49. }
  50. drupal_add_js($settings, 'setting');
  51. drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/media_vimeo.js');
  52. drupal_add_css(drupal_get_path('module', 'media_vimeo') . '/css/media_vimeo.css');
  53. drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/flash_detect_min.js');
  54. }
  55. function theme_media_vimeo_field_formatter_styles($variables) {
  56. $element = $variables['element'];
  57. $style = $variables['style'];
  58. $variables['file'] = $element['#item'];
  59. $variables['uri'] = $variables['file']['uri'];
  60. $variables['style_name'] = $style['name'];
  61. return theme('media_vimeo_embed', $variables);
  62. }
  63. /**
  64. * Preview for Styles UI.
  65. */
  66. function theme_media_vimeo_preview_style($variables) {
  67. $variables['uri'] = media_vimeo_variable_get('preview_uri');
  68. $variables['field_type'] = 'file';
  69. $variables['object'] = file_uri_to_object($variables['uri']);
  70. return theme('styles', $variables);
  71. }
  72. /**
  73. * NOTE: Deprecated with Styles version 2.
  74. */
  75. function theme_media_vimeo_styles($variables) {
  76. $style = $variables['style'];
  77. $variables['file'] = $variables['object'];
  78. $variables['uri'] = $variables['object']->uri;
  79. $variables['style_name'] = $style['name'];
  80. return theme('media_vimeo_embed', $variables);
  81. }
  82. /**
  83. * @todo: get this working
  84. *
  85. * This code is for embedding videos in WYSIYWG areas, not currently working.
  86. * NOTE: Deprecated with Styles version 2.
  87. */
  88. function theme_media_vimeo_embed($variables) {
  89. $preset_name = $variables['preset_name'];
  90. $preset = styles_containers_available_styles('file', 'media_vimeo', $preset_name);
  91. $output = '';
  92. if (!empty($preset)) {
  93. // Build the URL for display.
  94. $uri = $variables['uri'];
  95. $wrapper = file_stream_wrapper_get_instance_by_uri($uri);
  96. $parts = $wrapper->get_parameters();
  97. $fullscreen_value = $autoplay = 'false';
  98. $in_browser = $thumbnail = FALSE;
  99. foreach ($preset['effects'] as $effect) {
  100. switch ($effect['name']) {
  101. case 'autoplay':
  102. $autoplay = $effect['data']['autoplay'] ? 'true' : 'false';
  103. break;
  104. case 'resize':
  105. $width = $effect['data']['width'];
  106. $height = $effect['data']['height'];
  107. break;
  108. case 'fullscreen':
  109. $fullscreen_value = $effect['data']['fullscreen'] ? 'true' : 'false';
  110. break;
  111. case 'thumbnail':
  112. $thumbnail = $effect['data']['thumbnail'];
  113. }
  114. }
  115. if (isset($variables['object']->override)) {
  116. $override = $variables['object']->override;
  117. if (isset($override['width'])) {
  118. $width = $override['width'];
  119. }
  120. if (isset($override['height'])) {
  121. $height = $override['height'];
  122. }
  123. if (isset($override['wysiwyg'])) {
  124. $thumbnail = TRUE;
  125. }
  126. if (isset($override['browser']) && $override['browser']) {
  127. $in_browser = TRUE;
  128. $thumbnail = TRUE;
  129. }
  130. }
  131. $width = isset($width) ? $width : media_vimeo_variable_get('width');
  132. $height = isset($height) ? $height : media_vimeo_variable_get('height');
  133. $video_id = check_plain($parts['v']);
  134. if ($thumbnail) {
  135. // @todo Clean this up.
  136. $image_variables = array(
  137. 'path' => $wrapper->getOriginalThumbnailPath(),
  138. 'alt' => $variables['alt'],
  139. 'title' => $variables['title'],
  140. 'getsize' => FALSE,
  141. );
  142. if (isset($preset['image_style'])) {
  143. $image_variables['path'] = $wrapper->getLocalThumbnailPath();
  144. $image_variables['style_name'] = $preset['image_style'];
  145. $output = theme('image_style', $image_variables);
  146. }
  147. else {
  148. // We need to add this style attribute here so that it doesn't get lost
  149. // If you resize a video in a node, save it, edit it, but don't adjust
  150. // the sizing of the video while editing, the size will revert to the
  151. // default. Adding the specific size here retains the original resizing
  152. $WYSIWYG = isset($variables['object']->override['style']) ? $variables['object']->override['style'] : '';
  153. $image_variables['attributes'] = array('width' => $width, 'height' => $height, 'style' => $WYSIWYG);
  154. $output = theme('image', $image_variables);
  155. }
  156. if ($in_browser) {
  157. // Add an overlay that says 'Vimeo' to media library browser thumbnails.
  158. $output .= '<span />';
  159. }
  160. }
  161. else {
  162. $output = theme('media_vimeo_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL)));
  163. }
  164. }
  165. return $output;
  166. }