View source
<?php
function theme_video_widget($variables) {
$element = $variables['element'];
$output = '';
$output .= '<div class="video-widget form-managed-file clearfix">';
if (isset($element['preview'])) {
$output .= '<div class="video-preview">';
$output .= drupal_render($element['preview']);
$output .= '</div>';
}
$output .= '<div class="video-widget-data">';
if ($element['fid']['#value'] != 0) {
$element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';
$output .= '</div>';
return $output;
}
function theme_video($variables) {
$themed_output = '';
if (empty($variables['item']['fid'])) {
return '';
}
$field_settings = $variables['field']['settings'];
$instance_settings = $variables['instance']['settings'];
if (isset($field_settings['autoconversion']) && $field_settings['autoconversion']) {
module_load_include('inc', 'video', '/includes/conversion');
$conversion = new video_conversion();
if ($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_conversion_failed');
}
}
}
}
module_load_include('inc', 'video', '/includes/video_helper');
$video_helper = new video_helper();
$video = $video_helper
->video_object($variables);
$defaults = video_video_extensions();
$theme_function = variable_get('video_extension_' . $video->player, $defaults[$video->player]);
switch ($theme_function) {
case 'video_play_flv':
return theme('video_flv', array(
'video' => $video,
'themed_output' => $themed_output,
));
break;
case 'video_play_html5':
return theme('video_html5', array(
'video' => $video,
'themed_output' => $themed_output,
));
break;
default:
return theme($theme_function, array(
'video' => $video,
'themed_output' => $themed_output,
));
break;
}
}
function theme_video_thumbnail($variables) {
if (empty($variables['item']['fid'])) {
return '<!-- File not found: ' . $variables['item']['fid'] . ' -->';
}
module_load_include('inc', 'video', '/includes/video_helper');
$video_helper = new video_helper();
$thumbnail = (array) $video_helper
->thumbnail_object($variables);
if (empty($thumbnail['filepath'])) {
watchdog('video', 'Unable to find the video thumbnail for the %node.', array(
'%node' => $variables['entity']->title,
), WATCHDOG_ERROR);
return '<!-- File not found: ' . $thumbnail['filepath'] . ' -->';
}
$image = array(
'path' => $thumbnail['filepath'],
'alt' => $thumbnail['alt'],
);
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'];
$options['html'] = TRUE;
$output = l($output, $path, $options);
}
return $output;
}
function theme_video_thumb_style($variables) {
$style_name = $variables['style_name'];
$path = $variables['path'];
$style_path = image_style_path($style_name, $path);
if (!file_exists($style_path)) {
$style_path = image_style_url($style_name, $path);
}
$variables['path'] = $style_path;
return theme('image', $variables);
}
function theme_video_inprogress() {
return '<div class="video-inprogress">' . t('This video is currently being processed. Please wait.') . '</div>';
}
function theme_video_conversion_failed() {
return '<div class="video-conversion-failed">' . t('The video conversion process has failed. You might want to submit a simpler video format like <em>mpeg</em> or <em>divx avi</em>.<br />If the problem persists please contact website administrators.') . '</div>';
}
function theme_video_flv($variables) {
$video = $variables['video'];
$video->flash_player = variable_get('video_extension_' . $video->player . '_flash_player', '');
switch ($video->flash_player) {
case 'swftools':
$options = array(
'params' => array(
'width' => $video->player_width,
'height' => $video->player_height,
),
'othervars' => array(
'image' => $video->thumbnail->swfthumb,
),
);
$themed_output = swf($video->files->{$video->player}->url, $options);
break;
case 'flowplayer':
if (isset($video->autoplay) && isset($video->thumbnail->url)) {
$options = array(
'playlist' => array(
$video->thumbnail->url,
array(
'url' => urlencode($video->files->{$video->player}->url),
'autoPlay' => $video->autoplay,
'autoBuffering' => $video->autobuffering,
),
),
);
}
else {
$options = array(
'clip' => array(
'url' => urlencode($video->files->{$video->player}->url),
'autoPlay' => $video->autoplay,
'autoBuffering' => $video->autobuffering,
),
);
}
$themed_output = theme('flowplayer', array(
'config' => $options,
'id' => 'flowplayer-' . $video->formatter,
'attributes' => array(
'style' => 'width:' . $video->player_width . 'px;height:' . ($video->player_height + 24) . 'px;',
),
));
break;
default:
$themed_output = t('No flash player has been setup. ' . l(t('Please select a player to play Flash videos.'), 'admin/settings/video/players'));
break;
}
return theme('video_play_flv', array(
'video' => $video,
'themed_output' => $themed_output,
));
}
function theme_video_html5($variables) {
$themed_output = NULL;
$video = $variables['video'];
$video->html5_player = variable_get('video_extension_' . $video->player . '_html5_player', '');
switch ($video->html5_player) {
case 'video':
return theme('video_play_html5', array(
'video' => $video,
'themed_output' => $themed_output,
));
break;
case 'videojs':
$items = _video_object_to_array($video->files);
$items += array(
'thumbnail' => (array) $video->thumbnail,
);
$attributes = array();
$attributes['width'] = $video->player_width;
$attributes['height'] = $video->player_height;
return theme('videojs', array(
'items' => $items,
'player_id' => 'video-' . $video->fid,
'attributes' => $attributes,
));
break;
}
}