video_helper.inc in Video 7
File
includes/video_helper.inc
View source
<?php
class video_helper {
public function video_object($variables) {
$field_settings = $variables['field']['settings'];
$instance_settings = $variables['instance']['settings'];
$player_dimensions = explode("x", $variables['item']['player_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", $variables['item']['dimensions']);
}
if (!isset($player_dimensions[0]) || !isset($player_dimensions[1])) {
$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');
}
}
$video = new stdClass();
$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}->uri = $variables['item']['uri'];
$video->files->{$extension}->extension = $extension;
$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]);
$video->thumbnail = $this
->thumbnail_object($variables);
$video->formatter = $variables['instance']['display']['default']['type'];
$video->autoplay = variable_get('video_autoplay', FALSE);
$video->autobuffering = variable_get('video_autobuffering', TRUE);
$video->theora_player = variable_get('video_ogg_player', 'http://theora.org/cortado.jar');
if (isset($field_settings['autoconversion']) && $field_settings['autoconversion']) {
module_load_include('inc', 'video', '/includes/conversion');
$conversion = new video_conversion();
if ($conversion
->load_job($variables['item']['fid'])) {
$video->files = new stdClass();
$conversion
->load_completed_job($video);
}
}
return $video;
}
public function thumbnail_object($variables) {
$field_settings = $variables['field']['settings'];
$instance_settings = $variables['instance']['settings'];
$thumbnail = new stdClass();
$thumbnail->filepath = '';
$thumbnail->url = '';
$thumbnail->alt = $variables['entity']->title;
$thumbnail->title = $variables['entity']->title;
$use_default_img = isset($variables['item']['use_default_video_thumb']) ? TRUE : FALSE;
if ($use_default_img && !empty($field_settings['default_video_thumbnail'])) {
$default_thumbnail = file_load($field_settings['default_video_thumbnail']['fid']);
$thumbnail->filepath = $default_thumbnail->uri;
}
elseif (isset($variables['item']['thumbnail']) ? TRUE : FALSE) {
$thumbnail_load = file_load($variables['item']['thumbnail']);
$thumbnail->filepath = $thumbnail_load->uri;
}
else {
return;
}
$thumbnail->url = file_create_url($thumbnail->filepath);
$thumbnail->uri = $thumbnail->filepath;
$thumbnail->filemime = file_get_mimetype($thumbnail->filepath);
$thumbnail->swfthumb = $thumbnail->filepath;
return $thumbnail;
}
}