aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeshan Wanigasooriya <heshanmw@gmail.com>2011-02-04 05:38:29 +0000
committerHeshan Wanigasooriya <heshanmw@gmail.com>2011-02-04 05:38:29 +0000
commit972258223885132cc38dbcdbc9e0efce8dd7afc5 (patch)
treeb070d91a64ed4ffee6a3b87ceb13ba791bb7eeca
parent90ae392eadddfad417ed4ac752134e3eca70066c (diff)
downloadvideo-972258223885132cc38dbcdbc9e0efce8dd7afc5.tar.gz
video-972258223885132cc38dbcdbc9e0efce8dd7afc5.tar.bz2
Updating the video module with thumbnail support with default thumbnail.
-rw-r--r--includes/video_helper.inc52
-rw-r--r--video.field.inc34
-rw-r--r--video.module24
-rw-r--r--video_formatter.inc86
4 files changed, 101 insertions, 95 deletions
diff --git a/includes/video_helper.inc b/includes/video_helper.inc
index 2307f87..54d1ed8 100644
--- a/includes/video_helper.inc
+++ b/includes/video_helper.inc
@@ -10,21 +10,21 @@
class video_helper {
- public function video_object($element) {
- $field_settings = $element['field']['settings'];
- $instance_settings = $element['instance']['settings'];
+ public function video_object($variables) {
+ $field_settings = $variables['field']['settings'];
+ $instance_settings = $variables['instance']['settings'];
//setup our width x height
- $player_dimensions = explode("x", $element['item']['player_dimensions']);
+ $player_dimensions = explode("x", $variables['item']['player_dimensions']);
// set the video dimentions
- if (!isset($element['item']['dimensions'])) {
+ if (!isset($variables['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']);
+ $dimensions = explode("x", $variables['item']['dimensions']);
if (!isset($player_dimensions[0]) || !isset($player_dimensions[1])) {
$player_dimensions = explode("x", $instance_settings['default_player_dimensions']);
@@ -35,12 +35,12 @@ 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']['filename'], PATHINFO_FILENAME) . '.' . $extension;
- $video->files->{$extension}->filepath = $element['item']['uri'];
- $video->files->{$extension}->url = file_create_url($element['item']['uri']);
+ $video->fid = $variables['item']['fid'];
+ $video->original = $variables['item'];
+ $extension = strtolower(pathinfo($variables['item']['filename'], PATHINFO_EXTENSION));
+ $video->files->{$extension}->filename = pathinfo($variables['item']['filename'], PATHINFO_FILENAME) . '.' . $extension;
+ $video->files->{$extension}->filepath = $variables['item']['uri'];
+ $video->files->{$extension}->url = file_create_url($variables['item']['uri']);
$video->files->{$extension}->extension = $extension;
// set the player to play
$video->player = $extension;
@@ -49,14 +49,14 @@ class video_helper {
$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->thumbnail = $this->thumbnail_object($variables);
+// $video->formatter = $variables['#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_settings['autoconversion']) && $field_settings['autoconversion']
- && !$element['item']['bypass_autoconversion']) {
+ && !$variables['item']['bypass_autoconversion']) {
// discard all existing file data
$video->files = new stdClass();
module_load_include('inc', 'video', '/includes/conversion');
@@ -81,9 +81,9 @@ class video_helper {
return $video;
}
- public function thumbnail_object($element) {
- $field_settings = $element['field']['settings'];
- $instance_settings = $element['instance']['settings'];
+ public function thumbnail_object($variables) {
+ $field_settings = $variables['field']['settings'];
+ $instance_settings = $variables['instance']['settings'];
// Build our thumbnail object
$thumbnail = new stdClass();
$thumbnail->filepath = '';
@@ -95,24 +95,18 @@ class video_helper {
// Setup our thumbnail path.
$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;
+ $use_default_img = isset($variables['item']['use_default_video_thumb']) ? $variables['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']);
+ } elseif (isset($variables['item']['video_thumb']) ? $variables['item']['video_thumb'] : false) {
+ $thumbnail_load = file_load($variables['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
- $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);
- }
+
+ $thumbnail->url = file_create_url($thumbnail->filepath);
//swftools appends sites/default/files to the front of our path...
//@todo Is this a setting? Need to figure this out.
diff --git a/video.field.inc b/video.field.inc
index b530537..cdb1e25 100644
--- a/video.field.inc
+++ b/video.field.inc
@@ -303,13 +303,13 @@ function video_field_widget_process($element, &$form_state, $form) {
*/
function video_field_formatter_info() {
$formatters = array(
- 'video_plain' => array(
+ 'video' => array(
'label' => t('Video'),
'field types' => array('video'),
- 'settings' => array('video_style' => '', 'video_link' => ''),
+// 'settings' => array('video_style' => '', 'video_link' => ''),
),
- 'video_nodelink' => array(
- 'label' => t('Video Thumbnail linked to node'),
+ 'video_thumbnail' => array(
+ 'label' => t('Video thumbnail'),
'field types' => array('video'),
'settings' => array('video_style' => '', 'video_link' => ''),
),
@@ -324,18 +324,6 @@ function video_field_formatter_info() {
// 'description' => t('Displays the video by using jmedia javascript.'),
// ),
);
- //setup our imagecache presets
- //we need formatters for each of our thumbnails.
- $thumb_types = array('video_nodelink'); //array('video_colorbox', 'video_nodelink');
- foreach ($thumb_types as $types) {
- foreach (image_styles () as $preset) {
- $formatters[$preset['name'] . '__' . $types] = array(
- 'label' => t('[Video] @preset of @label', array('@preset' => $preset['name'], '@label' => $formatters[$types]['label'])),
- 'field types' => array('video'),
- 'settings' => array('video_style' => '', 'video_link' => ''),
- );
- }
- }
return $formatters;
}
@@ -348,10 +336,10 @@ function video_field_formatter_settings_form($field, $instance, $view_mode, $for
$image_styles = image_style_options(FALSE);
$element['video_style'] = array(
- '#title' => t('Image style'),
+ '#title' => t('Video thumbnail style'),
'#type' => 'select',
'#default_value' => $settings['video_style'],
- '#empty_option' => t('None (original video/video thumbnail)'),
+ '#empty_option' => t('None (original video thumbnail)'),
'#options' => $image_styles,
);
@@ -360,7 +348,7 @@ function video_field_formatter_settings_form($field, $instance, $view_mode, $for
'file' => t('File'),
);
$element['video_link'] = array(
- '#title' => t('Link video or vide thumbanil to'),
+ '#title' => t('Link video or video thumbanil to'),
'#type' => 'select',
'#default_value' => $settings['video_link'],
'#empty_option' => t('Nothing'),
@@ -387,12 +375,12 @@ function video_field_formatter_settings_summary($field, $instance, $view_mode) {
if (isset($image_styles[$settings['video_style']])) {
$summary[] = t('Video thumbnail style: @style', array('@style' => $image_styles[$settings['video_style']]));
} else {
- $summary[] = t('Original video/video thumbnail');
+ $summary[] = t('Original video thumbnail');
}
$link_types = array(
'content' => t('Linked to content'),
- 'file' => t('Linked to file'),
+ 'file' => t('Linked to video file'),
);
// Display this setting only if image is linked.
if (isset($link_types[$settings['video_link']])) {
@@ -415,6 +403,8 @@ function video_field_formatter_view($entity_type, $entity, $field, $instance, $l
$link_file = TRUE;
}
+ // set the display
+ $theme = $display['type'];
foreach ($items as $delta => $item) {
if (isset($link_file)) {
$uri = array(
@@ -423,7 +413,7 @@ function video_field_formatter_view($entity_type, $entity, $field, $instance, $l
);
}
$element[$delta] = array(
- '#theme' => 'video_formatter',
+ '#theme' => $theme,
'#item' => $item,
'#video_style' => $display['settings']['video_style'],
'#path' => isset($uri) ? $uri : '',
diff --git a/video.module b/video.module
index 6a03d75..385b334 100644
--- a/video.module
+++ b/video.module
@@ -138,6 +138,15 @@ function video_menu() {
*/
function video_theme() {
$theme = array();
+ $theme['video'] = array(
+ 'variables' => array('item' => NULL, 'path' => NULL, 'video_style' => NULL, 'entity' => NULL, 'field' => NULL, 'instance' => NULL),
+ 'file' => 'video_formatter.inc',
+ );
+ $theme['video_thumbnail'] = array(
+ 'variables' => array('item' => NULL, 'path' => NULL, 'video_style' => NULL, 'entity' => NULL, 'field' => NULL, 'instance' => NULL),
+ 'file' => 'video_formatter.inc',
+ );
+
$theme['video_thumbnails'] = array(
'variables' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE),
'file' => 'video.theme.inc',
@@ -158,14 +167,7 @@ function video_theme() {
'variables' => array('item' => TRUE),
'file' => 'video.theme.inc',
);
- $theme['video_formatter_video_plain'] = array(
- 'variables' => array('element' => NULL),
- 'file' => 'video_formatter.inc',
- );
- $theme['video_formatter_video_nodelink'] = array(
- 'variables' => array('element' => NULL, 'imagecache' => NULL),
- 'file' => 'video_formatter.inc',
- );
+
//$theme['video_formatter_video_colorbox'] = array(
// 'arguments' => array('element' => NULL, 'imagecache' => NULL),
// 'file' => 'video_formatter.inc',
@@ -781,13 +783,13 @@ function video_video_flv_players() {
/**
* Get the object for the suitable player for the parameter resource
*/
-function video_get_player($element) {
+function video_get_player($variables) {
// Setup our node object to be passed along with the player.
-// $node = $element['entity'];
+// $node = $variables['entity'];
// Setup our video object
module_load_include('inc', 'video', '/includes/video_helper');
$video_helper = new video_helper;
- $video = $video_helper->video_object($element);
+ $video = $video_helper->video_object($variables);
// Lets spit out our theme based on the extension
$defaults = video_video_extensions();
$theme_function = variable_get('video_extension_' . $video->player, $defaults[$video->player]);
diff --git a/video_formatter.inc b/video_formatter.inc
index a9451d4..dead10e 100644
--- a/video_formatter.inc
+++ b/video_formatter.inc
@@ -10,43 +10,63 @@
* Default video cck formatter. Makes sure the video being displayed exists, has been converted (if in que).
* If not or the video is processed, then it will get the default player for the specific video type for output.
*/
-function theme_video_formatter_video_plain($element) {
- if (empty($element['#item']['fid']))
- return '';
- // Get our field information to determine if we are checking conversion
- $field = content_fields($element['#field_name'], $element['#type_name']);
- if (!empty($field['list_field']) && !$element['#item']['list'])
+function theme_video($variables) {
+ if (empty($variables['item']['fid']))
return '';
+ $field_settings = $variables['field']['settings'];
+ $instance_settings = $variables['instance']['settings'];
// Only needs to be ran if they are converting videos
- if (isset($field['widget']['autoconversion']) && $field['widget']['autoconversion'] && !$element['#item']['data']['bypass_autoconversion']) {
+ if (isset($field_settings['autoconversion']) && $field_settings['autoconversion'] && !$variables['item']['bypass_autoconversion']) {
module_load_include('inc', 'video', '/includes/conversion');
$conversion = new video_conversion;
- $video = $conversion->load_job($element['#item']['fid']);
+ $video = $conversion->load_job($variables['item']['fid']);
if ($video->video_status == VIDEO_RENDERING_ACTIVE || $video->video_status == VIDEO_RENDERING_PENDING) {
return theme('video_inprogress');
} else if ($video->video_status == VIDEO_RENDERING_FAILED) {
return theme('video_encoding_failed');
}
}
- return video_get_player($element);
+ return video_get_player($variables);
}
/*
* Renders the video thumbnail as a link to the node page.
*/
-function theme_video_formatter_video_nodelink($element, $imagecache = FALSE) {
- // Inside a view $element may contain null data. In that case, just return.
- if (empty($element['#item']['fid']))
+function theme_video_thumbnail($variables) {
+ // Inside a view $variables may contain null data. In that case, just return.
+ if (empty($variables['item']['fid']))
return '';
//setup our thumbnail object
module_load_include('inc', 'video', '/includes/video_helper');
$video_helper = new video_helper;
- $thumbnail = $video_helper->thumbnail_object($element);
- //get our themed image
- $image = theme('video_image', $thumbnail, $thumbnail->alt, $thumbnail->title, '', TRUE, $imagecache);
- $class = 'popups video video-nodelink video-' . $element['#field_name'];
- return l($image, 'node/' . $element['#node']->nid, array('attributes' => array('class' => $class), 'html' => TRUE));
+ // @TODO : change the object to an array
+ $thumbnail = (array) $video_helper->thumbnail_object($variables);
+ $image = array(
+ 'path' => $thumbnail['filepath'],
+ 'alt' => $thumbnail['alt'],
+ );
+ // Do not output an empty 'title' attribute.
+ if (drupal_strlen($thumbnail['title']) > 0) {
+ $image['title'] = $thumbnail['title'];
+ }
+
+ if ($variables['video_style']) {
+ $image['style_name'] = $variables['video_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;
}
/*
@@ -57,15 +77,15 @@ function theme_video_formatter_video_nodelink($element, $imagecache = FALSE) {
* used. We are also using jmedia for all other filetypes.
*/
-function theme_video_formatter_video_colorbox($element, $imagecache = FALSE) {
+function theme_video_colorbox($variables, $imagecache = FALSE) {
global $base_path;
if (!module_exists('colorbox')) {
drupal_set_message(t('You must download and enable !colorbox for this formatter.', array('!colorbox' => l(t('Colorbox'), 'http://www.drupal.org/project/colorbox'))), 'error');
- return theme('video_formatter_video_nodelink', $element);
+ return theme('video_formatter_video_nodelink', $variables);
}
- // Inside a view $element may contain null data. In that case, just return.
- if (empty($element['#item']['fid']))
+ // Inside a view $variables may contain null data. In that case, just return.
+ if (empty($variables['#item']['fid']))
return '';
//load up our media plugins
@@ -76,7 +96,7 @@ function theme_video_formatter_video_colorbox($element, $imagecache = FALSE) {
//setup our video object
module_load_include('inc', 'video', '/includes/video_helper');
$video_helper = new video_helper;
- $video = $video_helper->video_object($element);
+ $video = $video_helper->video_object($variables);
$action = swftools_get_action($video->filepath);
$player = swftools_get_player($action);
@@ -94,7 +114,7 @@ function theme_video_formatter_video_colorbox($element, $imagecache = FALSE) {
));
drupal_add_js($settings, 'setting');
$image = theme('video_image', $video->thumbnail, $video->thumbnail->alt, $video->thumbnail->title, '', TRUE, $imagecache);
- $class = 'video-box video-' . $element['#field_name'] . '{width:\'' . $video->player_width . 'px\', height:\'' . $video->player_height . 'px\', player:\'' . $player . '\'}';
+ $class = 'video-box video-' . $variables['#field_name'] . '{width:\'' . $video->player_width . 'px\', height:\'' . $video->player_height . 'px\', player:\'' . $player . '\'}';
return l($image, $video->files->{$video->player}->url, array('attributes' => array('class' => $class), 'html' => TRUE));
}
@@ -107,10 +127,10 @@ function theme_video_formatter_video_colorbox($element, $imagecache = FALSE) {
* We are outputing an anchor to the videofile. The jMedia functions will overtake this anchor and setup our object/embed tags.
*/
-function theme_video_formatter_video_media_js($element) {
+function theme_video_media_js($variables) {
//#913928
- $field = content_fields($element['#field_name'], $element['#type_name']);
- if (!empty($field['list_field']) && !$element['#item']['list'])
+ $field = content_fields($variables['#field_name'], $variables['#type_name']);
+ if (!empty($field['list_field']) && !$variables['#item']['list'])
return '';
drupal_add_js(drupal_get_path('module', 'video') . '/js/jquery.media.js');
@@ -118,7 +138,7 @@ function theme_video_formatter_video_media_js($element) {
//setup our video object
module_load_include('inc', 'video', '/includes/video_helper');
$video_helper = new video_helper;
- $video = $video_helper->video_object($element);
+ $video = $video_helper->video_object($variables);
//lets output the link to be overtaken by jmedia
$link = l($video->filename, $video->files->{$video->player}->url, array('attributes' => array('class' => 'jmedia {width: ' . $video->player_width . ', height: ' . $video->player_height . ', autoplay: ' . $video->autoplay . '}')));
return $link;
@@ -181,19 +201,19 @@ function theme_video_flv($video, $node) {
return theme('video_play_flv', $video, $node, $themed_output);
}
-function theme_video_formatter_imagecache($element) {
- // Inside a view $element may contain NULL data. In that case, just return.
- if (empty($element['#item']['fid'])) {
+function theme_video_formatter_imagecache($variables) {
+ // Inside a view $variables may contain NULL data. In that case, just return.
+ if (empty($variables['#item']['fid'])) {
return '';
}
// Extract the preset name from the formatter name.
- list($namespace, $theme_function) = explode('__', $element['#formatter'], 2);
+ list($namespace, $theme_function) = explode('__', $variables['#formatter'], 2);
if ($preset = imagecache_preset_by_name($namespace)) {
- $element['imagecache_preset'] = $namespace;
+ $variables['imagecache_preset'] = $namespace;
}
//return $theme_function;
- return theme('video_formatter_' . $theme_function, $element, TRUE);
+ return theme('video_formatter_' . $theme_function, $variables, TRUE);
}
/**