function video_thumb_process in Video 6.5
Same name and namespace in other branches
- 6.4 video_widget.inc \video_thumb_process()
- 7 video.module \video_thumb_process()
Adds a preview of thumbnails for you to select when uploading videos.
2 calls to video_thumb_process()
- uploadfield_widget_process in types/
uploadfield/ uploadfield_widget.inc - Element #process callback function.
- videoftp_widget_process in types/
videoftp/ videoftp_widget.inc - Process an individual element.
File
- ./
video_widget.inc, line 511 - Common Video module widget functions
Code
function video_thumb_process(&$element) {
$file = $element['#value'];
$fid = intval($file['fid']);
$field = content_fields($element['#field_name'], $element['#type_name']);
$gen_fail = FALSE;
if (isset($element['preview']) && $fid != 0) {
if (in_array($field['widget']['autothumbnail'], array(
'auto',
'auto_fallback',
))) {
$transcoder = video_get_transcoder();
$video = new stdClass();
$video->fid = $fid;
$video->filepath = $file['filepath'];
$video->filename = $file['filepath'];
$thumbs = $transcoder
->generate_thumbnails($video);
if (!empty($thumbs)) {
drupal_add_js(drupal_get_path('module', 'video') . '/js/video.admin.js');
$thumbss = array();
foreach ($thumbs as $img) {
$thumbss[$img->filepath] = theme('video_thumbnails', $img, '', '', array(
'width' => '50',
), FALSE);
}
if (!empty($file['data']['video_thumb']) && isset($thumbss[$file['data']['video_thumb']])) {
$currentthumb = $file['data']['video_thumb'];
}
else {
$currentthumb = array_rand($thumbss);
}
$element['data']['video_thumb'] = array(
'#type' => 'radios',
'#title' => t('Video thumbnail'),
'#options' => $thumbss,
'#default_value' => $currentthumb,
'#weight' => 10,
'#attributes' => array(
'class' => 'video-thumbnails',
'onchange' => 'videoftp_thumbnail_change()',
'rel' => 'video_large_thumbnail-' . $fid,
),
);
}
else {
$gen_fail = TRUE;
}
}
if (!empty($gen_fail) && $field['widget']['autothumbnail'] == 'auto_fallback' || $field['widget']['autothumbnail'] == 'manual_upload') {
$element['data']['video_thumb_file'] = array(
'#name' => 'files[' . $element['#field_name'] . '_' . $element['#delta'] . '_thumbs]',
'#type' => 'file',
'#size' => '40',
'#title' => !empty($file['data']['video_thumb']) ? t('Replace the video thumbnail') : t('Upload a video thumbnail'),
'#description' => t('This thumbnail will be uploaded when the node is saved.'),
);
$element['data']['video_thumb'] = array(
'#type' => 'value',
'#value' => isset($file['data']['video_thumb']) ? $file['data']['video_thumb'] : FALSE,
);
}
// Setup our large thumbnail that is on the left.
// @todo Add smaller video preview instead of thumbnail?
if (!empty($currentthumb)) {
$large_thumb = array(
'filepath' => $currentthumb,
);
}
elseif (!empty($file['data']['video_thumb'])) {
$large_thumb = array(
'filepath' => $file['data']['video_thumb'],
);
}
elseif (!empty($field['widget']['default_video_thumb'])) {
$large_thumb = $field['widget']['default_video_thumb'];
}
if (!empty($large_thumb)) {
// @todo Integrate the thumbnails with imagecache.
$element['preview']['#suffix'] = '<div class="video_large_thumbnail-' . $fid . '">' . theme('video_thumbnails', $large_thumb, '', '', array(
'width' => 150,
), FALSE) . '</div>';
}
}
}