media_archive.theme.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * @file media_archive/includes/themes/media_archive.theme.inc
  4. *
  5. * Theme and preprocess functions for Media: Archive.
  6. */
  7. /**
  8. * Preprocess function for theme('media_archive_video').
  9. */
  10. function media_archive_preprocess_media_archive_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. //convert episode id from filepath to embed code
  17. $variables['embed_code'] = media_archive_embedcode_lookup($variables['video_id']);
  18. $variables['width'] = isset($variables['width']) ? $variables['width'] : media_archive_variable_get('width');
  19. $variables['height'] = isset($variables['height']) ? $variables['height'] : media_archive_variable_get('height');
  20. $variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_archive_variable_get('autoplay');
  21. $variables['fullscreen'] = isset($variables['fullscreen']) ? $variables['fullscreen'] : media_archive_variable_get('fullscreen');
  22. $variables['autoplay'] = $variables['autoplay'] ? 1 : 1;
  23. $variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
  24. $variables['wrapper_id'] = 'media_archive_' . $variables['video_id'] . '_' . $variables['id'];
  25. $mp4URL = 'http://www.archive.org/download/' . $variables['video_id'] . '/' . $variables['embed_code'] . '_512kb.mp4';
  26. $ogvURL = 'http://www.archive.org/download/' . $variables['video_id'] . '/' . $variables['embed_code'] . '.ogv';
  27. //Fix for IE!!
  28. //<object width="640" height="506" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param value="true" name="allowfullscreen"/><param value="always" name="allowscriptaccess"/><param value="high" name="quality"/><param value="true" name="cachebusting"/><param value="#000000" name="bgcolor"/><param name="movie" value="http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf" /><param value="config={'key':'#$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'Domino_Theory_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/bavc-77620-dominotheory/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']}" name="flashvars"/><embed src="http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf" type="application/x-shockwave-flash" width="640" height="506" allowfullscreen="true" allowscriptaccess="always" cachebusting="true" bgcolor="#000000" quality="high" flashvars="config={'key':'#$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'Domino_Theory_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/bavc-77620-dominotheory/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']}"> </embed></object>
  29. $variables['output'] = '<video width="' . $variables['width'] .'" height="' . $variables['height'] .'" controls>
  30. <source src="' . $mp4URL . '" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\'>
  31. <source src="' . $ogvURL . '" type=\'video/ogg; codecs="theora, vorbis"\'>
  32. </video>';
  33. // For users with JavaScript, these object and embed tags will be replaced
  34. // by an iframe, so that we can support users without Flash.
  35. /*
  36. $variables['output'] = '<object width="' . $variables['width'] . '" height="' . $variables['height'] . '">';
  37. $variables['output'] .= '<param value="true" name="allowfullscreen"/><param value="always" name="allowscriptaccess"/><param value="high" name="quality"/><param value="true" name="cachebusting"/><param value="#000000" name="bgcolor"/>';
  38. $variables['output'] .= '<param name="movie" value="http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf"></param>';
  39. $variables['output'] .= '<param name="allowFullScreen" value="' . $variables['fullscreen'] . '"></param>';
  40. $variables['output'] .= '<param name="wmode" value="transparent" />';
  41. $variables['output'] .= "<param value=\"config={'key':'#$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'" . $variables['embed_code'] . "_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/bavc-77620-dominotheory/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']}\" name=\"flashvars\"/>";
  42. $config = "'key':\'#$aa4baff94a9bdcafce8','playlist':['format=Thumbnail?.jpg',{'autoPlay':false,'url':'" . $variables['embed_code'] . "_512kb.mp4'}],'clip':{'autoPlay':true,'baseUrl':'http://www.archive.org/download/" . $variables['video_id'] . "/','scaling':'fit','provider':'h264streaming'},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'plugins':{'controls':{'playlist':false,'fullscreen':true,'height':26,'backgroundColor':'#000000','autoHide':{'fullscreenOnly':true}},'h264streaming':{'url':'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf'}},'contextMenu':[{},'-','Flowplayer v3.2.1']";
  43. $variables['output'] .= '<embed src="http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf" type="application/x-shockwave-flash" width="' . $variables['width'] . '" height="' . $variables['height'] . '" allowfullscreen="' . $variables['fullscreen'] . 'allowfullscreen="true" allowscriptaccess="always" cachebusting="true" bgcolor="#000000" quality="high" flashvars="config={' . $config . '}"></embed>';
  44. $variables['output'] .= '</object>';
  45. */
  46. /*
  47. $variables['output'] = <<<OUTPUT
  48. <object width="{$variables['width']}" height="{$variables['height']}">
  49. <param name="movie" value="http://www.archive.org/play/{$variables['embed_code']}"></param>
  50. <param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
  51. <param name="wmode" value="transparent" />
  52. <embed src="http://www.archive.org/play/{$variables['embed_code']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}"></embed>
  53. </object>
  54. OUTPUT;
  55. */
  56. // @todo Replace this inline JavaScript with at least calls to
  57. // drupal_add_js()/drupal_get_js(), and ideally, with a behavior. Keep
  58. // in mind that the solution needs to work when inside a colorbox or
  59. // otherwise in an AJAX response, but that should now be possible in D7.
  60. /*
  61. $iframe_id = drupal_json_encode($variables['wrapper_id'] .'_iframe');
  62. $wrapper_id = drupal_json_encode($variables['wrapper_id']);
  63. $JSObject = 'Drupal.settings.media_archive[' . $wrapper_id . ']';
  64. $variables['output'] .= <<<OUTPUT
  65. <script type="text/javascript">
  66. if (Drupal.settings && Drupal.media_archive) {
  67. Drupal.settings.media_archive = Drupal.settings.media_archive || {};
  68. $JSObject = {};
  69. $JSObject.width = {$variables['width']};
  70. $JSObject.height = {$variables['height']};
  71. $JSObject.video_id = "{$variables['video_id']}";
  72. $JSObject.fullscreen = {$variables['fullscreen']};
  73. $JSObject.id = $iframe_id;
  74. Drupal.media_archive.insertEmbed($wrapper_id);
  75. }
  76. </script>
  77. OUTPUT;
  78. */
  79. //drupal_add_js(drupal_get_path('module', 'media_archive') . '/js/media_archive.js');
  80. drupal_add_css(drupal_get_path('module', 'media_archive') . '/css/media_archive.css');
  81. drupal_add_js(drupal_get_path('module', 'media_archive') . '/js/flash_detect_min.js');
  82. }
  83. function theme_media_archive_field_formatter_styles($variables) {
  84. $element = $variables['element'];
  85. $style = $variables['style'];
  86. $variables['file'] = $element['#item'];
  87. $variables['uri'] = $variables['file']['uri'];
  88. $variables['style_name'] = $style['name'];
  89. return theme('media_archive_embed', $variables);
  90. }
  91. /**
  92. * Preview for Styles UI.
  93. */
  94. function theme_media_archive_preview_style($variables) {
  95. $variables['uri'] = media_archive_variable_get('preview_uri');
  96. $variables['field_type'] = 'file';
  97. $variables['object'] = file_uri_to_object($variables['uri']);
  98. return theme('styles', $variables);
  99. }
  100. /**
  101. * NOTE: Deprecated with Styles version 2.
  102. */
  103. function theme_media_archive_styles($variables) {
  104. $style = $variables['style'];
  105. $variables['file'] = $variables['object'];
  106. $variables['uri'] = $variables['object']->uri;
  107. $variables['style_name'] = $style['name'];
  108. return theme('media_archive_embed', $variables);
  109. }
  110. /**
  111. * @todo: get this working
  112. *
  113. * This code is for embedding videos in WYSIYWG areas, not currently working.
  114. * NOTE: Deprecated with Styles version 2.
  115. */
  116. function theme_media_archive_embed($variables) {
  117. $preset_name = $variables['preset_name'];
  118. $preset = styles_containers_available_styles('file', 'media_archive', $preset_name);
  119. $output = '';
  120. if (!empty($preset)) {
  121. // Build the URL for display.
  122. $uri = $variables['uri'];
  123. $wrapper = file_stream_wrapper_get_instance_by_uri($uri);
  124. $parts = $wrapper->get_parameters();
  125. $fullscreen_value = $autoplay = 'false';
  126. $in_browser = $thumbnail = FALSE;
  127. foreach ($preset['effects'] as $effect) {
  128. switch ($effect['name']) {
  129. case 'autoplay':
  130. $autoplay = $effect['data']['autoplay'] ? 'true' : 'false';
  131. break;
  132. case 'resize':
  133. $width = $effect['data']['width'];
  134. $height = $effect['data']['height'];
  135. break;
  136. case 'fullscreen':
  137. $fullscreen_value = $effect['data']['fullscreen'] ? 'true' : 'false';
  138. break;
  139. case 'thumbnail':
  140. $thumbnail = $effect['data']['thumbnail'];
  141. }
  142. }
  143. if (isset($variables['object']->override)) {
  144. $override = $variables['object']->override;
  145. if (isset($override['width'])) {
  146. $width = $override['width'];
  147. }
  148. if (isset($override['height'])) {
  149. $height = $override['height'];
  150. }
  151. if (isset($override['wysiwyg'])) {
  152. $thumbnail = TRUE;
  153. }
  154. if (isset($override['browser']) && $override['browser']) {
  155. $in_browser = TRUE;
  156. $thumbnail = TRUE;
  157. }
  158. }
  159. $width = isset($width) ? $width : media_archive_variable_get('width');
  160. $height = isset($height) ? $height : media_archive_variable_get('height');
  161. $video_id = check_plain($parts['v']);
  162. if ($thumbnail) {
  163. // @todo Clean this up.
  164. $image_variables = array(
  165. 'path' => $wrapper->getOriginalThumbnailPath(),
  166. 'alt' => $variables['alt'],
  167. 'title' => $variables['title'],
  168. 'getsize' => FALSE,
  169. );
  170. if (isset($preset['image_style'])) {
  171. $image_variables['path'] = $wrapper->getLocalThumbnailPath();
  172. $image_variables['style_name'] = $preset['image_style'];
  173. $output = theme('image_style', $image_variables);
  174. }
  175. else {
  176. // We need to add this style attribute here so that it doesn't get lost
  177. // If you resize a video in a node, save it, edit it, but don't adjust
  178. // the sizing of the video while editing, the size will revert to the
  179. // default. Adding the specific size here retains the original resizing
  180. $WYSIWYG = isset($variables['object']->override['style']) ? $variables['object']->override['style'] : '';
  181. $image_variables['attributes'] = array('width' => $width, 'height' => $height, 'style' => $WYSIWYG);
  182. $output = theme('image', $image_variables);
  183. }
  184. if ($in_browser) {
  185. // Add an overlay that says 'Archive' to media library browser thumbnails.
  186. $output .= '<span />';
  187. }
  188. }
  189. else {
  190. $output = theme('media_archive_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL)));
  191. }
  192. }
  193. return $output;
  194. }