public function video_transcoder::generate_thumbnails in Video 7
Same name and namespace in other branches
- 6.5 video.lib.inc \video_transcoder::generate_thumbnails()
- 6.4 includes/transcoder.inc \video_transcoder::generate_thumbnails()
File
- includes/
transcoder.inc, line 57
Class
Code
public function generate_thumbnails($video) {
// Save thiumnails to the vide_thumbnails table
$thumbnails = array();
$vid = $video['fid'];
$thumbs = $this->transcoder
->generate_thumbnails($video);
foreach ($thumbs as $file) {
// media module is altering file_manged table with type, so if we do not consider about is then we might get entity load issue.
// #1015580
// if media module exists add type as an image
if (module_exists('media')) {
$file->type = 'image';
}
if (variable_get('video_thumb_save_all', FALSE)) {
$file->status = FILE_STATUS_PERMANENT;
}
$existing_file = file_load_multiple(array(), array(
'uri' => $file->uri,
));
if ($existing_file) {
// check thumbnail file exists
$file = (array) $existing_file;
}
else {
// create new file entries for thumbnails
drupal_write_record('file_managed', $file);
$file = file_load_multiple(array(), array(
'uri' => $file->uri,
));
}
if (!empty($file)) {
$thumbnails = array_merge($file, $thumbnails);
}
}
$exists = db_query('SELECT 1 FROM {video_thumbnails} WHERE vid = :vid', array(
':vid' => $vid,
))
->fetchField();
if ($exists == FALSE) {
// returns TRUE is there is a record.
$insertquery = db_insert('video_thumbnails')
->fields(array(
'vid' => $vid,
'thumbnails' => serialize($thumbnails),
))
->execute();
}
else {
$updatequery = db_update('video_thumbnails')
->fields(array(
'thumbnails' => serialize($thumbnails),
))
->condition('vid', $vid)
->execute();
}
return unserialize(db_query('SELECT thumbnails FROM {video_thumbnails} WHERE vid = :vid', array(
':vid' => $vid,
))
->fetchField());
}