diff options
author | Heshan Wanigasooriya <heshanmw@gmail.com> | 2011-02-03 08:51:55 +0000 |
---|---|---|
committer | Heshan Wanigasooriya <heshanmw@gmail.com> | 2011-02-03 08:51:55 +0000 |
commit | 90ae392eadddfad417ed4ac752134e3eca70066c (patch) | |
tree | 32b457adc2c2bdc2a47f1d6afbcfcef4dc632a78 | |
parent | 0e7283722f6ed7b6a8ace7c4683c7c260ff7a7e4 (diff) | |
download | video-90ae392eadddfad417ed4ac752134e3eca70066c.tar.gz video-90ae392eadddfad417ed4ac752134e3eca70066c.tar.bz2 |
Updating the video players with the D7 theme registry preprocess functions.
-rw-r--r-- | includes/video_helper.inc | 64 | ||||
-rw-r--r-- | theme/video-play-quicktime.tpl.php | 14 | ||||
-rw-r--r-- | video.field.inc | 82 | ||||
-rw-r--r-- | video.module | 41 | ||||
-rw-r--r-- | video_formatter.inc | 109 |
5 files changed, 197 insertions, 113 deletions
diff --git a/includes/video_helper.inc b/includes/video_helper.inc index 63f3e5a..2307f87 100644 --- a/includes/video_helper.inc +++ b/includes/video_helper.inc @@ -11,18 +11,23 @@ class video_helper { public function video_object($element) { - $field = content_fields($element['#field_name'], $element['#type_name']); + $field_settings = $element['field']['settings']; + $instance_settings = $element['instance']['settings']; //setup our width x height - $dimensions = explode("x", $element['#item']['data']['dimensions']); - $player_dimensions = explode("x", $element['#item']['data']['player_dimensions']); - if (!isset($dimensions[0]) || !isset($dimensions[1])) { - $dimensions = explode("x", $field['widget']['default_dimensions']); + + $player_dimensions = explode("x", $element['item']['player_dimensions']); + // set the video dimentions + if (!isset($element['item']['dimensions'])) { + $dimensions = explode("x", $instance_settings['default_dimensions']); if (!isset($dimensions[0]) || !isset($dimensions[1])) { drupal_set_message(t('Something is wrong with your dimensions. Make sure you enter dimensions in the form of WxH.'), 'error'); } } + else + $dimensions = explode("x", $element['item']['dimensions']); + if (!isset($player_dimensions[0]) || !isset($player_dimensions[1])) { - $player_dimensions = explode("x", $field['widget']['default_player_dimensions']); + $player_dimensions = explode("x", $instance_settings['default_player_dimensions']); if (!isset($player_dimensions[0]) || !isset($player_dimensions[1])) { drupal_set_message(t('Something is wrong with your player dimensions. Make sure you enter the player dimensions in the form of WxH.'), 'error'); } @@ -30,35 +35,34 @@ class video_helper { // Build our video object for all types. $video = new stdClass(); - $video->fid = $element['#item']['fid']; - $video->original = $element['#item']; - $extension = strtolower(pathinfo($element['#item']['filename'], PATHINFO_EXTENSION)); - $video->files->{$extension}->filename = pathinfo($element['#item']['filepath'], PATHINFO_FILENAME) . '.' . $extension; - $video->files->{$extension}->filepath = $element['#item']['filepath']; - $video->files->{$extension}->url = file_create_url($element['#item']['filepath']); + $video->fid = $element['item']['fid']; + $video->original = $element['item']; + $extension = strtolower(pathinfo($element['item']['filename'], PATHINFO_EXTENSION)); + $video->files->{$extension}->filename = pathinfo($element['item']['filename'], PATHINFO_FILENAME) . '.' . $extension; + $video->files->{$extension}->filepath = $element['item']['uri']; + $video->files->{$extension}->url = file_create_url($element['item']['uri']); $video->files->{$extension}->extension = $extension; - $video->player = strtolower(pathinfo($element['#item']['filename'], PATHINFO_EXTENSION)); + // set the player to play + $video->player = $extension; $video->width = trim($dimensions[0]); $video->height = trim($dimensions[1]); $video->player_width = trim($player_dimensions[0]); $video->player_height = trim($player_dimensions[1]); + // load thumbnail object $video->thumbnail = $this->thumbnail_object($element); - $video->formatter = $element['#formatter']; +// $video->formatter = $element['#formatter']; $video->autoplay = variable_get('video_autoplay', TRUE); $video->autobuffering = variable_get('video_autobuffering', TRUE); $video->theora_player = variable_get('video_ogg_player', 'http://theora.org/cortado.jar'); // lets find out if we have transcoded this file and update our paths. - if (isset($field['widget']['autoconversion']) && $field['widget']['autoconversion'] - && !$element['#item']['data']['bypass_autoconversion']) { + if (isset($field_settings['autoconversion']) && $field_settings['autoconversion'] + && !$element['item']['bypass_autoconversion']) { // discard all existing file data $video->files = new stdClass(); module_load_include('inc', 'video', '/includes/conversion'); $conversion = new video_conversion; $conversion->load_completed_job($video); } -// echo '<pre>'; -// print_r($video); -// die(); // Let othere module to load the video files by referance // Lets find out if we have pushed this file to the cdn if enabled. // @TODO : add correct filesystem load to this @@ -78,7 +82,8 @@ class video_helper { } public function thumbnail_object($element) { - $field = content_fields($element['#field_name'], $element['#type_name']); + $field_settings = $element['field']['settings']; + $instance_settings = $element['instance']['settings']; // Build our thumbnail object $thumbnail = new stdClass(); $thumbnail->filepath = ''; @@ -89,19 +94,22 @@ class video_helper { $thumbnail->description = ''; // Setup our thumbnail path. - $use_default_img = isset($element['#item']['data']['use_default_video_thumb']) ? $element['#item']['data']['use_default_video_thumb'] : false; - if ($use_default_img && !empty($field['widget']['default_video_thumb']['filepath'])) { - $thumbnail->filepath = $field['widget']['default_video_thumb']['filepath']; - } elseif (isset($element['#item']['data']['video_thumb']) ? $element['#item']['data']['video_thumb'] : false) { - $thumbnail->filepath = $element['#item']['data']['video_thumb']; + $default_thumbnail = file_load($field_settings['default_video_thumbnail']); + $use_default_img = isset($element['item']['use_default_video_thumb']) ? $element['item']['use_default_video_thumb'] : false; + if ($use_default_img && !empty($field_settings['default_video_thumbnail'])) { + $thumbnail->filepath = $default_thumbnail->uri; + } elseif (isset($element['item']['video_thumb']) ? $element['item']['video_thumb'] : false) { + $thumbnail_load = file_load($element['item']['video_thumb']); + $thumbnail->filepath = $thumbnail_load->uri; } else { //need some type of default if nothing is present //drupal_set_message(t('No thumbnail has been configured for the video.'), 'error'); } //lets check for an imagecache preset - if (isset($element['imagecache_preset'])) { - $thumbnail->url = imagecache_create_url($element['imagecache_preset'], $thumbnail->filepath); - $thumbnail->filepath = imagecache_create_path($element['imagecache_preset'], $thumbnail->filepath); + $style_name = $field_settings['preview_video_thumb_style']; + $style_path = image_style_path($style_name, $thumbnail->filepath); + if (!file_exists($style_path)) { + $style_path = image_style_url($style_name, $thumbnail->filepath); } else { $thumbnail->url = file_create_url($thumbnail->filepath); } diff --git a/theme/video-play-quicktime.tpl.php b/theme/video-play-quicktime.tpl.php index a69ce26..d234130 100644 --- a/theme/video-play-quicktime.tpl.php +++ b/theme/video-play-quicktime.tpl.php @@ -1,4 +1,4 @@ -<?php +<?php //$Id$ /* * @file @@ -22,11 +22,11 @@ <param name="autoplay" value="<?php print $video->autoplay ? 'true' : 'false'; ?>" /> <param name="pluginurl" value="http://www.apple.com/quicktime/download/" /> <embed src="<?php print $video->files->{$video->player}->url; ?>" - type="video/quicktime" - pluginspage="http://www.apple.com/quicktime/download/" - width="<?php print $video->player_width; ?>" - height="<?php print $video->player_height; ?>" - autostart="<?php print $video->autoplay ? 'true' : 'false'; ?>" - controller="true" > + type="video/quicktime" + pluginspage="http://www.apple.com/quicktime/download/" + width="<?php print $video->player_width; ?>" + height="<?php print $video->player_height; ?>" + autostart="<?php print $video->autoplay ? 'true' : 'false'; ?>" + controller="true" > </embed> </object>
\ No newline at end of file diff --git a/video.field.inc b/video.field.inc index 1f9a863..b530537 100644 --- a/video.field.inc +++ b/video.field.inc @@ -306,12 +306,12 @@ function video_field_formatter_info() { 'video_plain' => array( 'label' => t('Video'), 'field types' => array('video'), - 'settings' => array('image_style' => '', 'image_link' => ''), + 'settings' => array('video_style' => '', 'video_link' => ''), ), 'video_nodelink' => array( 'label' => t('Video Thumbnail linked to node'), 'field types' => array('video'), - 'settings' => array('image_style' => '', 'image_link' => ''), + 'settings' => array('video_style' => '', 'video_link' => ''), ), //'video_colorbox' => array( // 'label' => t('Video Thumbnail to Colorbox'), @@ -330,9 +330,9 @@ function video_field_formatter_info() { foreach ($thumb_types as $types) { foreach (image_styles () as $preset) { $formatters[$preset['name'] . '__' . $types] = array( - 'label' => t('[Video] @preset @label', array('@preset' => $preset['name'], '@label' => $formatters[$types]['label'])), + 'label' => t('[Video] @preset of @label', array('@preset' => $preset['name'], '@label' => $formatters[$types]['label'])), 'field types' => array('video'), - 'settings' => array('image_style' => '', 'image_link' => ''), + 'settings' => array('video_style' => '', 'video_link' => ''), ); } } @@ -347,11 +347,11 @@ function video_field_formatter_settings_form($field, $instance, $view_mode, $for $settings = $display['settings']; $image_styles = image_style_options(FALSE); - $element['image_style'] = array( + $element['video_style'] = array( '#title' => t('Image style'), '#type' => 'select', - '#default_value' => $settings['image_style'], - '#empty_option' => t('None (original image)'), + '#default_value' => $settings['video_style'], + '#empty_option' => t('None (original video/video thumbnail)'), '#options' => $image_styles, ); @@ -359,10 +359,10 @@ function video_field_formatter_settings_form($field, $instance, $view_mode, $for 'content' => t('Content'), 'file' => t('File'), ); - $element['image_link'] = array( - '#title' => t('Link image to'), + $element['video_link'] = array( + '#title' => t('Link video or vide thumbanil to'), '#type' => 'select', - '#default_value' => $settings['image_link'], + '#default_value' => $settings['video_link'], '#empty_option' => t('Nothing'), '#options' => $link_types, ); @@ -384,10 +384,10 @@ function video_field_formatter_settings_summary($field, $instance, $view_mode) { unset($image_styles['']); // Styles could be lost because of enabled/disabled modules that defines // their styles in code. - if (isset($image_styles[$settings['image_style']])) { - $summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']])); + if (isset($image_styles[$settings['video_style']])) { + $summary[] = t('Video thumbnail style: @style', array('@style' => $image_styles[$settings['video_style']])); } else { - $summary[] = t('Original image'); + $summary[] = t('Original video/video thumbnail'); } $link_types = array( @@ -395,8 +395,8 @@ function video_field_formatter_settings_summary($field, $instance, $view_mode) { 'file' => t('Linked to file'), ); // Display this setting only if image is linked. - if (isset($link_types[$settings['image_link']])) { - $summary[] = $link_types[$settings['image_link']]; + if (isset($link_types[$settings['video_link']])) { + $summary[] = $link_types[$settings['video_link']]; } return implode('<br />', $summary); @@ -409,9 +409,9 @@ function video_field_formatter_view($entity_type, $entity, $field, $instance, $l $element = array(); // Check if the formatter involves a link. - if ($display['settings']['image_link'] == 'content') { + if ($display['settings']['video_link'] == 'content') { $uri = entity_uri($entity_type, $entity); - } elseif ($display['settings']['image_link'] == 'file') { + } elseif ($display['settings']['video_link'] == 'file') { $link_file = TRUE; } @@ -423,52 +423,14 @@ function video_field_formatter_view($entity_type, $entity, $field, $instance, $l ); } $element[$delta] = array( - '#theme' => 'image_formatter', + '#theme' => 'video_formatter', '#item' => $item, - '#image_style' => $display['settings']['image_style'], + '#video_style' => $display['settings']['video_style'], '#path' => isset($uri) ? $uri : '', + '#entity' => $entity, + '#field' => $field, + '#instance' => $instance ); } - return $element; -} - -/** - * Returns HTML for an image field formatter. - * - * @param $variables - * An associative array containing: - * - item: An array of image data. - * - image_style: An optional image style. - * - path: An array containing the link 'path' and link 'options'. - * - * @ingroup themeable - */ -function theme_video_formatter($variables) { - $item = $variables['item']; - $image = array( - 'path' => $item['uri'], - 'alt' => $item['alt'], - ); - // Do not output an empty 'title' attribute. - if (drupal_strlen($item['title']) > 0) { - $image['title'] = $item['title']; - } - - if ($variables['image_style']) { - $image['style_name'] = $variables['image_style']; - $output = theme('image_style', $image); - } else { - $output = theme('image', $image); - } - - if ($variables['path']) { - $path = $variables['path']['path']; - $options = $variables['path']['options']; - // When displaying an image inside a link, the html option must be TRUE. - $options['html'] = TRUE; - $output = l($output, $path, $options); - } - - return $output; }
\ No newline at end of file diff --git a/video.module b/video.module index d16a38b..6a03d75 100644 --- a/video.module +++ b/video.module @@ -139,7 +139,7 @@ function video_menu() { function video_theme() { $theme = array(); $theme['video_thumbnails'] = array( - 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), + 'variables' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), 'file' => 'video.theme.inc', ); $theme['video_widget'] = array( @@ -147,23 +147,23 @@ function video_theme() { 'file' => 'video.theme.inc', ); $theme['video_widget_preview'] = array( - 'arguments' => array('item' => TRUE), + 'variables' => array('item' => TRUE), 'file' => 'video.theme.inc', ); $theme['video_image'] = array( - 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE, 'imagecache' => NULL), + 'variables' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE, 'imagecache' => NULL), 'file' => 'video.theme.inc', ); $theme['video_widget_video_thumb'] = array( - 'arguments' => array('item' => TRUE), + 'variables' => array('item' => TRUE), 'file' => 'video.theme.inc', ); $theme['video_formatter_video_plain'] = array( - 'arguments' => array('element' => NULL), + 'variables' => array('element' => NULL), 'file' => 'video_formatter.inc', ); $theme['video_formatter_video_nodelink'] = array( - 'arguments' => array('element' => NULL, 'imagecache' => NULL), + 'variables' => array('element' => NULL, 'imagecache' => NULL), 'file' => 'video_formatter.inc', ); //$theme['video_formatter_video_colorbox'] = array( @@ -171,15 +171,15 @@ function video_theme() { // 'file' => 'video_formatter.inc', //); $theme['video_formatter_video_media_js'] = array( - 'arguments' => array('element' => NULL), + 'variables' => array('element' => NULL), 'file' => 'video_formatter.inc', ); $theme['video_encoding_failed'] = array( - 'arguments' => array(), + 'variables' => array(), 'file' => 'video_formatter.inc', ); $theme['video_inprogress'] = array( - 'arguments' => array(), + 'variables' => array(), 'file' => 'video_formatter.inc', ); @@ -188,9 +188,7 @@ function video_theme() { $players = video_video_players(); foreach ($players as $tpl => $value) { $theme[$tpl] = array( - 'arguments' => array('video' => NULL, 'node' => NULL, 'themed_output' => NULL), - //#843368 fix -// 'file' => 'video_formatter.inc', + 'variables' => array('video' => NULL, 'themed_output' => NULL), 'template' => str_replace('_', '-', $tpl), 'path' => $path, ); @@ -198,7 +196,7 @@ function video_theme() { //We need to add an flv theme buffer to allow users to override in their own module to add in extra parameters before //calling our flv template file. $theme['video_flv'] = array( - 'arguments' => array('video' => NULL, 'node' => NULL), + 'variables' => array('video' => NULL, 'node' => NULL), 'file' => 'video_formatter.inc' ); @@ -210,13 +208,18 @@ function video_theme() { foreach ($thumb_types as $types) { foreach (imagecache_presets () as $preset) { $theme['video_formatter_' . $preset['presetname'] . '__' . $types] = array( - 'arguments' => array('element' => NULL), + 'variables' => array('element' => NULL), 'function' => 'theme_video_formatter_imagecache', 'file' => 'video_formatter.inc' ); } } } + // @TODO : check is there any other optimal way to do this? + $theme['video_formatter'] = array( + 'variables' => array('item' => NULL, 'path' => NULL, 'video_style' => NULL, 'entity' => NULL, 'field' => NULL, 'instance' => NULL), + 'file' => 'video_formatter.inc' + ); return $theme; } @@ -334,7 +337,8 @@ function video_thumb_process(&$element, &$form_state) { // print_r($field['settings']['default_video_thumbnail']); $default_thumbnail = file_load($field['settings']['default_video_thumbnail']); // @todo Integrate the thumbnails with imagecache. - $element['preview']['#suffix'] = '<div class="video_large_thumbnail-' . $delta . '">' . theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)) . '</div>'; + if (!empty($default_thumbnail)) + $element['preview']['#suffix'] = '<div class="video_large_thumbnail-' . $delta . '">' . theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)) . '</div>'; } } @@ -779,7 +783,7 @@ function video_video_flv_players() { */ function video_get_player($element) { // Setup our node object to be passed along with the player. - $node = $element['#node']; +// $node = $element['entity']; // Setup our video object module_load_include('inc', 'video', '/includes/video_helper'); $video_helper = new video_helper; @@ -787,11 +791,12 @@ function video_get_player($element) { // Lets spit out our theme based on the extension $defaults = video_video_extensions(); $theme_function = variable_get('video_extension_' . $video->player, $defaults[$video->player]); + // Lets do some special handling for our flv files to accomdate multiple players. if ($theme_function == 'video_play_flv') { - return theme('video_flv', $video, $node); + return theme('video_flv', (array) $video); } else { - return theme($theme_function, $video, $node); + return theme($theme_function, (array) $video); } } diff --git a/video_formatter.inc b/video_formatter.inc index bcda04f..a9451d4 100644 --- a/video_formatter.inc +++ b/video_formatter.inc @@ -211,4 +211,113 @@ function theme_video_formatter_imagecache($element) { */ function theme_video_formatter($variables) { return video_get_player($variables); +} + +/** + * Process variables for video-play-quicktime.tpl.php. + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-quicktime.tpl.php + */ +function template_preprocess_video_play_quicktime(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-dcr.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-dcr.tpl.php + */ +function template_preprocess_video_play_dcr(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-divx.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-divx.tpl.php + */ +function template_preprocess_video_play_divx(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-flash.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-flash.tpl.php + */ +function template_preprocess_video_play_flash(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-flv.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-flv.tpl.php + */ +function template_preprocess_video_play_flv(&$variables) { + $variables['video'] = (object) $variables; + $variables['themed_output'] = (object) $variables; +} + +/** + * Process variables for video-play-html5.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-html5.tpl.php + */ +function template_preprocess_video_play_html5(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-realmedia.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-realmedia.tpl.php + */ +function template_preprocess_video_play_realmedia(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-theora.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-theora.tpl.php + */ +function template_preprocess_video_play_theora(&$variables) { + $variables['video'] = (object) $variables; +} + +/** + * Process variables for video-play-windowsmedia.tpl.php + * + * The $variables array contains the following arguments: + * - $video + * + * @see video-play-windowsmedia.tpl.php + */ +function template_preprocess_video_play_windowsmedia(&$variables) { + $variables['video'] = (object) $variables; }
\ No newline at end of file |