View source
<?php
function video_init() {
drupal_add_css(drupal_get_path('module', 'video') . '/css/video.css');
drupal_add_js(drupal_get_path('module', 'video') . '/js/video.js');
}
function video_module_invoke($action, &$array, &$video = NULL, $other = NULL) {
foreach (module_list() as $module) {
$function = $module . '_video_' . $action;
if (function_exists($function)) {
$function($array, $video, $other);
}
}
}
function video_perm() {
return array(
'bypass conversion video',
'convert on submission',
'override player dimensions',
'use default thumb',
);
}
function video_menu() {
$items = array();
$items['admin/settings/video'] = array(
'title' => 'Video',
'description' => 'Configure different aspects of the video module and its plugins',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_general_admin_settings',
),
'file' => 'video.admin.inc',
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/video/general'] = array(
'title' => 'General',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/settings/video/players'] = array(
'title' => 'Players',
'description' => 'Configure your player settings for each video extension.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_players_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'video.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['admin/settings/video/transcoders'] = array(
'title' => 'Transcoders',
'description' => 'Configure your transcoder to convert your videos or extra thumbnails.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_transcoder_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'video.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
$items['admin/settings/video/presets'] = array(
'title' => 'Presets',
'description' => 'Configure your transcoder presets to convert your videos.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_preset_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'video.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items['admin/settings/video/metadata'] = array(
'title' => 'Metadata',
'description' => 'Configure your metadata settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_metadata_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'video.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
$items['admin/settings/video/filesystem'] = array(
'title' => 'File System',
'description' => 'Configure your file system settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_filesystem_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'video.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['admin/settings/video/cron'] = array(
'title' => 'Cron Settings',
'description' => 'Configure your cron settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'video_cron_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'file' => 'video.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 6,
);
return $items;
}
function video_theme() {
$theme = array();
$theme['video_thumbnails'] = array(
'arguments' => array(
'file' => NULL,
'alt' => '',
'title' => '',
'attributes' => NULL,
'getsize' => TRUE,
),
'file' => 'video.theme.inc',
);
$theme['video_widget_preview'] = array(
'arguments' => array(
'item' => TRUE,
),
'file' => 'video.theme.inc',
);
$theme['video_image'] = array(
'arguments' => array(
'file' => NULL,
'alt' => '',
'title' => '',
'attributes' => NULL,
'getsize' => TRUE,
'imagecache' => NULL,
),
'file' => 'video.theme.inc',
);
$theme['video_widget_video_thumb'] = array(
'arguments' => array(
'item' => TRUE,
),
'file' => 'video.theme.inc',
);
$theme['video_formatter_video_plain'] = array(
'arguments' => array(
'element' => NULL,
),
'file' => 'video_formatter.inc',
);
$theme['video_formatter_video_nodelink'] = array(
'arguments' => array(
'element' => NULL,
'imagecache' => NULL,
),
'file' => 'video_formatter.inc',
);
$theme['video_formatter_video_thumbnail'] = array(
'arguments' => array(
'element' => NULL,
'imagecache' => NULL,
),
'file' => 'video_formatter.inc',
);
$theme['video_formatter_video_nonodelink'] = array(
'arguments' => array(
'element' => NULL,
'imagecache' => NULL,
),
'file' => 'video_formatter.inc',
);
$theme['video_formatter_video_media_js'] = array(
'arguments' => array(
'element' => NULL,
),
'file' => 'video_formatter.inc',
);
$theme['video_encoding_failed'] = array(
'arguments' => array(),
'file' => 'video_formatter.inc',
);
$theme['video_inprogress'] = array(
'arguments' => array(),
'file' => 'video_formatter.inc',
);
$path = drupal_get_path('module', 'video') . '/theme';
$players = video_video_players();
foreach ($players as $tpl => $value) {
$theme[$tpl] = array(
'arguments' => array(
'video' => NULL,
'node' => NULL,
'themed_output' => NULL,
),
'template' => str_replace('_', '-', $tpl),
'path' => $path,
);
}
$theme['video_flv'] = array(
'arguments' => array(
'video' => NULL,
'node' => NULL,
),
'file' => 'video_formatter.inc',
);
$theme['video_html5'] = array(
'arguments' => array(
'video' => NULL,
'node' => NULL,
),
'file' => 'video_formatter.inc',
);
if (module_exists('imagecache')) {
$thumb_types = array(
'video_nodelink',
'video_thumbnail',
'video_nonodelink',
);
foreach ($thumb_types as $types) {
foreach (imagecache_presets() as $preset) {
$theme['video_formatter_' . $preset['presetname'] . '__' . $types] = array(
'arguments' => array(
'element' => NULL,
),
'function' => 'theme_video_formatter_imagecache',
'file' => 'video_formatter.inc',
);
}
}
}
return $theme;
}
function video_field_formatter_info() {
$formatters = array(
'video_plain' => array(
'label' => t('Video'),
'field types' => array(
'filefield',
),
'description' => t('Displays video files with player embedded.'),
),
'video_nodelink' => array(
'label' => t('Video Thumbnail linked to node'),
'field types' => array(
'filefield',
),
'description' => t('Displays the video thumbnail and links to the node.'),
),
'video_thumbnail' => array(
'label' => t('Video Thumbnail'),
'field types' => array(
'filefield',
),
'description' => t('Displays the video thumbnail.'),
),
'video_nonodelink' => array(
'label' => t('Video Thumbnail'),
'field types' => array(
'filefield',
),
'description' => t('Displays the video thumbnail (no link to node).'),
),
'video_media_js' => array(
'label' => t('Video inject with jMedia'),
'field types' => array(
'filefield',
),
'description' => t('Displays the video by using jmedia javascript.'),
),
);
if (module_exists('imagecache')) {
$thumb_types = array(
'video_nodelink',
'video_thumbnail',
'video_nonodelink',
);
foreach ($thumb_types as $types) {
foreach (imagecache_presets() as $preset) {
$formatters[$preset['presetname'] . '__' . $types] = array(
'label' => t('@preset @label', array(
'@preset' => $preset['presetname'],
'@label' => $formatters[$types]['label'],
)),
'field types' => array(
'filefield',
),
);
}
}
}
return $formatters;
}
function video_cron() {
if (variable_get('video_cron', TRUE)) {
$filesystem = variable_get('vid_filesystem', 'drupal');
$transcoder = variable_get('vid_convertor', 'video_ffmpeg');
if ($filesystem == 'video_s3' && $transcoder == 'video_zencoder') {
video_s3_cron();
}
module_load_include('inc', 'video', '/includes/conversion');
$video_conversion = new video_conversion();
$video_conversion
->run_queue();
}
}
function video_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$form['buttons']['submit']['#submit'][] = 'video_node_update_submit';
$form['#validate'][] = 'video_add_adminjs';
video_add_adminjs();
}
}
function video_node_update_submit($form, &$form_state) {
if (isset($form_state['nid']) && isset($form_state['values']['video_id']) && is_array($form_state['values']['video_id'])) {
foreach ($form_state['values']['video_id'] as $fid) {
module_load_include('inc', 'video', '/includes/transcoder');
$transcoder = new video_transcoder();
$video = array(
'nid' => $form_state['nid'],
'fid' => $fid,
);
$transcoder
->update_job($video);
video_module_invoke('update', $form, $form_state);
}
}
}
function video_file_delete($file) {
if (empty($file->fid)) {
watchdog('video', 'video_file_delete called with empty argument', array(), WATCHDOG_ERROR);
return;
}
video_module_invoke('delete', $file);
module_load_include('inc', 'video', '/includes/transcoder');
$transcoder = new video_transcoder();
$transcoder
->delete_job($file);
$video_thumb_path = variable_get('video_thumb_path', 'video_thumbs');
$thumb_folder = file_directory_path() . '/' . $video_thumb_path . '/' . $file->fid . '/';
if (is_dir($thumb_folder)) {
rmdirr($thumb_folder);
db_query('DELETE FROM {files} WHERE filepath LIKE "%b%%"', strtr(db_escape_string($thumb_folder), array(
'%' => '\\%',
'_' => '\\_',
)));
}
}
function video_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'video') . '/views',
);
}
function _video_aspect_ratio($video) {
module_load_include('inc', 'video', '/includes/transcoder');
$transcoder = new video_transcoder();
$wxh = $transcoder
->get_dimensions($video);
if (empty($wxh) || empty($wxh['width']) || empty($wxh['height'])) {
return null;
}
return array(
'width' => $wxh['width'],
'height' => $wxh['height'],
'ratio' => number_format($wxh['width'] / $wxh['height'], 4),
);
}
function video_default_dimensions() {
return "176x144\n352x288\n704x576\n1408x1152\n128x96\n160x120\n320x240\n640x480\n800x600\n1024x768\n1600x1200\n2048x1024\n1280x1024\n2560x2048\n5120x4096\n852x480\n1366x768\n1600x1024\n1920x1200\n2560x1600\n3200x2048\n3840x2400\n6400x4096\n7680x4800\n320x200\n640x350\n852x480\n1280x720\n1920x1080";
}
function video_video_extensions() {
return array(
'divx' => 'video_play_divx',
'mkv' => 'video_play_divx',
'mov' => 'video_play_quicktime',
'3gp' => 'video_play_quicktime',
'3g2' => 'video_play_quicktime',
'mp4' => 'video_play_quicktime',
'rm' => 'video_play_realmedia',
'f4v' => 'video_play_flv',
'flv' => 'video_play_flv',
'swf' => 'video_play_flash',
'dir' => 'video_play_dcr',
'dcr' => 'video_play_dcr',
'asf' => 'video_play_windowsmedia',
'wmv' => 'video_play_windowsmedia',
'avi' => 'video_play_windowsmedia',
'mpg' => 'video_play_windowsmedia',
'mpeg' => 'video_play_windowsmedia',
'ogg' => 'video_play_theora',
'ogv' => 'video_play_theora',
'webm' => 'video_play_theora',
);
}
function video_video_players() {
return array(
'video_play_html5' => t('HTML5 Player'),
'video_play_divx' => t('Divx Player'),
'video_play_quicktime' => t('Quicktime'),
'video_play_realmedia' => t('Real Media Player'),
'video_play_flv' => t('FLV Flash Players'),
'video_play_flash' => t('SWF Flash Player'),
'video_play_dcr' => t('Director/Shockwave'),
'video_play_windowsmedia' => t('Windows Media Player'),
'video_play_theora' => t('Theora Player'),
);
}
function rmdirr($dir) {
if ($objs = glob($dir . "/*")) {
foreach ($objs as $obj) {
is_dir($obj) ? rmdirr($obj) : unlink($obj);
}
}
@rmdir($dir);
}
function video_thumb_path($video = NULL, $checkexistence = TRUE) {
$dir = $basedir = file_directory_path() . '/' . variable_get('video_thumb_path', 'video_thumbs');
if (is_array($video)) {
$dir .= '/' . $video['fid'];
}
elseif (is_object($video)) {
$dir .= '/' . $video->fid;
}
elseif ($video > 0) {
$dir .= '/' . intval($video);
}
elseif ($video != NULL) {
return NULL;
}
if ($checkexistence) {
field_file_check_directory(file_directory_path(), FILE_CREATE_DIRECTORY);
field_file_check_directory($basedir, FILE_CREATE_DIRECTORY);
if ($dir != $basedir) {
field_file_check_directory($dir, FILE_CREATE_DIRECTORY);
}
}
return $dir;
}
function video_add_adminjs() {
drupal_add_js(drupal_get_path('module', 'video') . '/js/video.admin.js');
}
function _video_db_increase_timeout() {
global $db_type;
if ($db_type === 'mysqli' || $db_type === 'mysql') {
$timeout = 24 * 60 * 60;
db_query('SET SESSION wait_timeout = %d', $timeout);
}
}