aboutsummaryrefslogtreecommitdiff
path: root/video.module
diff options
context:
space:
mode:
authorMohamed Mujahid <muja_dd@494418.no-reply.drupal.org>2010-07-06 17:04:02 +0000
committerMohamed Mujahid <muja_dd@494418.no-reply.drupal.org>2010-07-06 17:04:02 +0000
commit0c8e7ae689eed6291bb2061c9c75e3057b230339 (patch)
treef0a8ef699214db00367763ba5f30c748d106fd69 /video.module
parent8041073c8d74e5d24e3b9f10143f3e4bd04db2de (diff)
downloadvideo-0c8e7ae689eed6291bb2061c9c75e3057b230339.tar.gz
video-0c8e7ae689eed6291bb2061c9c75e3057b230339.tar.bz2
merging changes from DRUPAL-6--4
Diffstat (limited to 'video.module')
-rw-r--r--video.module1977
1 files changed, 656 insertions, 1321 deletions
diff --git a/video.module b/video.module
index 3dc7f0d..1576bee 100644
--- a/video.module
+++ b/video.module
@@ -1,1488 +1,823 @@
<?php
//$Id$
/**
- * @file video.module
*
- * @author Heshan Wanigasooriya <heshan at heidisoft dot com>
- * <heshanmw at gmail dot com>
- * @author Glen Marianko Twitter@demoforum <glenm at demoforum dot com>
- * @todo
- */
-
-/** GMM: Views 2
- * Implementation of hook_views_api()
- */
-function video_views_api() {
- return array(
- 'api' => 2,
- 'path' => drupal_get_path('module', 'video').'/includes',
- );
-}
-
-/**
- * Implementation of hook_views_handlers()
- */
-function video_views_handlers() {
- return array(
- 'info' => array(
- 'path' => drupal_get_path('module', 'video').'/includes',
- ),
- 'handlers' => array(
- 'video_views_handler_field_playtime_seconds' => array('parent' => 'views_handler_field'),
- 'video_views_handler_field_download' => array('parent' => 'views_handler_field'),
- 'video_views_handler_field_play' => array('parent' => 'views_handler_field'),
- 'video_views_handler_field_image' => array('parent' => 'views_handler_field'),
-
- ),
- );
-}
-/********************************************************************
- * General Hooks
- ********************************************************************/
-
-/**
- * Help hook
- * Implementation of hook_help
- * @param $section
- * string of the area of Drupal where help was requested
- *
- * @return
- * string of help information
- */
-
-function video_help($path, $arg) {
- switch ($path) {
- case 'admin/help#video':
- $output = '<p>'. t('The Video Module is used to create and administrator Video nodes for Drupal') .'</p>';
- return $output;
- }
-}
-
-/**
- * Implementation of hook_menu().
- *
- * @param $may_cache
- * boolean indicating whether cacheable menu items should be returned
- *
- * @return
- * array of menu information
- */
-function video_menu() {
- global $user;
- $items = array();
-
- $items['video'] = array(
- 'title' => 'videos',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('video_page'),
- 'access arguments' => array('access video'),
- 'type' => MENU_SUGGESTED_ITEM);
-
- $items['video/feed'] = array(
- 'title' => 'videos feed',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('video_feed'),
- 'access arguments' => array('access video'),
- 'type' => MENU_CALLBACK);
-
-
- $items["node/add/video"] = array(
- 'title' => 'Video',
- 'description' => 'Allow a variety of video formats to be posted as nodes in your site',
- 'page callback' => 'video_add',
- 'access arguments' => array('create video'));
-
- $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_settings_form'),
- 'access arguments' => array('administer video'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- if (arg(0) == 'node' && is_numeric(arg(1))) {
- if ($node = node_load(arg(1)) and $node->type == 'video') {
-
- //enable the download tab only if it is supported
- if (video_support_download($node)) {
-
- $menu_type = (variable_get('video_displaydownloadmenutab', 1)) ? MENU_LOCAL_TASK : MENU_CALLBACK;
- $items['node/'.$node->nid.'/download'] = array(
- 'title' => 'Download',
- 'page callback' => 'video_download',
- 'page arguments' => array($node),
- 'access arguments' => array('access video') && node_access('view', $node, $user->uid),
- 'weight' => 5,
- 'type' => $menu_type);
- }
- }
- }
- return $items;
-}
-
-
-/**
- * Internal Drupal links hook
- *
- * @param $type
- * string type of link to show
- *
- * @param $node
- * object of node information
+ * @file video.module
*
- * @return
- * array of link information
*/
-function video_link($type, $node = NULL) {
- $link = array();
- // Node links for a video
- if ($type == 'node' && $node->type == 'video' && $node->vidfile && user_access('access video')) {
- //If the video is of type youtube and multi-file downloads aren't turned on don't show the download link.
- if (!video_support_download($node) || $node->disable_multidownload == 1) {
- $display_download_link = 0;
- }
- else {
- $display_download_link = variable_get('video_displaydownloadlink', 1);
- }
-
- if ($display_download_link == 1) {
- $link['video_download'] = array(
- 'title' => t('download'),
- 'href' => "node/$node->nid/download",
- 'attributes' => array(
- 'class' => 'outgoing',
- 'title' => t('download @link', array('@link' => $node->title)),
- ),
- );
- }
- if (variable_get('video_displayplaytime', 1) && $node->playtime_seconds > 0) { // hide the duration if the admin hided it or we don't have playtime informations
- $link['playtime'] = array(
- 'title' => format_interval($node->playtime_seconds),
- );
- }
- if (variable_get('video_displayfilesize', 1) && $node->size != 0) {
- $link['size'] = array(
- 'title' => format_size($node->size),
- );
- }
- if (variable_get('video_playcounter', 1) && user_access('view play counter')) {
- $link['play_counter'] = array(
- 'title' => format_plural($node->play_counter, '1 play', '@count plays'),
- );
- }
- if (variable_get('video_downloadcounter', 1) && user_access('view download counter') && video_support_download($node)) {
- $link['download_counter'] = array(
- 'title' => format_plural($node->download_counter, '1 download', '@count downloads'),
- );
- }
-
- return $link;
- }
- return array();
-}
-/**
- * Displays a Drupal page containing recently added videos
- *
- * @return
- * string HTML output
- */
-function video_page() {
- theme('video_page', NULL);
+/*
+ * Implementation of hook_init().
+*/
+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');
}
/**
- * Displays a Drupal page containing recently added videos
+ * Invokes hook_video_*action*() in every module.
+ * Eg :
+ * hook_video_submit()
+ * hook_video_insert()
+ * hook_video_preview()
+ * hook_video_delete()
+ * hook_video_load()
+ * hook_video_form() - to show values once upload is completed eg. Resolution, and Convert on Save etc
*
- * @return
- * string HTML output
+ * We cannot use module_invoke() for this, because the arguments need to
+ * be passed by reference.
*/
-function theme_video_page() {
- $output = '';
- if (arg(1) != 'help') { //We are not reading help so output a list of recent video nodes.
- $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'video' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
- while ($node = db_fetch_object($result)) {
- $output .= node_view(node_load($node->nid), 1);
+function video_module_invoke($action, &$array, &$video, $other = NULL) {
+ foreach (module_list() as $module) {
+ $function = $module . '_video_' . $action;
+ if (function_exists($function)) {
+ $function($array, $video, $other);
}
- $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
- // adds feed icon and link
- drupal_add_link(array('rel' => 'alternate',
- 'type' => 'application/rss+xml',
- 'title' => variable_get('site_name', 'drupal') . ' ' . t('videos'),
- 'href' => url('video/feed/')));
-
- $output .= '<br />' . theme('feed_icon', url('video/feed'), t('Syndicate'));
}
- return $output;
}
/**
- * Generate an RSS feed for videos
- *
- * @return
- * feed
+ * Implementation of hook_perm().
*/
-function video_feed() {
- $channel = array(
- 'title' => variable_get('site_name', 'drupal') . ' ' . t('videos'),
- 'description' => t('Latest videos on') . ' ' . variable_get('site_name', 'drupal'),
- 'link' => url('video', array('absolute' => TRUE))
- );
-
- $result = db_fetch_object(db_query('SELECT n.nid FROM {node} n WHERE n.type = "video" AND n.status = 1 ORDER BY n.created DESC'));
- node_feed($result, $channel);
-}
-/**
- * Permissions hook
- *
- * @return
- * array of permissions
- */
function video_perm() {
- $array = array('create video', 'access video', 'administer video', 'play video', 'download video', 'view play counter', 'view download counter', 'edit own video', 'edit all video nodes');
- return $array;
+ return array('bypass conversion video', 'convert on submission', 'override player dimensions', 'use default thumb');
}
/**
- * Settings Hook
- *
- * @return
- * string of form content or error message
+ * Implementation of hook_menu().
*/
-function video_settings_form() {
- global $base_url;
-
- $form = array();
-
- $form['menu'] = array(
- '#type' => 'fieldset',
- '#title' => t('General behavior'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
+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,
);
-
- $vtypes = video_get_types_infos();
-
- if ($vtypes) { // no vtype available
- $video_types = array();
- foreach ($vtypes as $vtype => $info) {
- $video_types[$vtype] = $info['#name'];
- }
- $video_types[0] = t('No default type');
- $form['menu']['video_default_video_type'] = array(
- '#type' => 'select',
- '#title' => t('Choose default video type'),
- '#default_value' => variable_get('video_default_video_type', 0),
- '#description' => t('For installations that have more than one video type available, this sets the default video type when a user visits node/add/video'),
- '#options' => $video_types,
- );
- }
-
- $form['menu']['video_displaydownloadmenutab'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display download menu tab'),
- '#default_value' => variable_get('video_displaydownloadmenutab', 1),
- '#description' => t('Toggle display of menu tab to download video from the node page.')
+ $items['admin/settings/video/general'] = array(
+ 'title' => 'General',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 0,
);
- $form['menu']['video_displaydownloadlink'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display download link'),
- '#default_value' => variable_get('video_displaydownloadlink', 1),
- '#description' => t('Toggle display of "download" link (below the node content in most themes).')
+ $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,
);
- $form['menu']['video_displayplaytime'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display playtime'),
- '#default_value' => variable_get('video_displayplaytime', 1),
- '#description' => t('Toggle the display of the playtime for a video.')
+ $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,
);
- $form['menu']['video_displayfilesize'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display filesize'),
- '#default_value' => variable_get('video_displayfilesize', 1),
- '#description' => t('Toggle the display of the filesize for a video.')
+ $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' => 3,
);
- $form['menu']['video_autoplay'] = array(
- '#type' => 'checkbox',
- '#title' => t('Automatically start video on page load'),
- '#default_value' => variable_get('video_autoplay', TRUE),
- '#description' => t('Start the video when the page and video loads')
+ $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' => 4,
);
+ return $items;
+}
- $form['resolutions'] = array(
- '#type' => 'fieldset',
- '#title' => t('Video resolutions'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
+/**
+ * Implementation of hook_theme().
+ */
+function video_theme() {
+ $theme = array();
+ $theme['video_thumbnails'] = array(
+ 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE),
+ 'file' => 'video.theme.inc',
);
-
- $form['resolutions']["video_resolution_width"] = array(
- '#type' => 'textfield',
- '#title' => t("Default width"),
- '#default_value' => variable_get("video_resolution_width", 400),
- '#description' => t('The width which will be used to scale video during playing. This let all videos on the website look the same')
+ $theme['video_widget_preview'] = array(
+ 'arguments' => array('item' => TRUE),
+ 'file' => 'video.theme.inc',
);
-
- $i = 1;
- while($i <= 4) {
- $form['resolutions']["video_resolution_{$i}_name"] = array(
- '#type' => 'textfield',
- '#title' => t("Resolution {$i} name"),
- '#default_value' => variable_get("video_resolution_{$i}_name", ''),
- );
- $form['resolutions']["video_resolution_{$i}_value"] = array(
- '#type' => 'textfield',
- '#title' => t("Resolution {$i} value"),
- '#default_value' => variable_get("video_resolution_{$i}_value", ''),
- '#description' => t('The resolution: two numbers representing width and height separated by an "x"'),
- );
- $i++;
- }
-
- // statistics stuff
- $form['counters'] = array(
- '#type' => 'fieldset',
- '#title' => t('Statistics counters'),
- '#description' => t('To allow users to view counters visit: ') . l(t('access control'), 'admin/user/permissions'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
+ $theme['video_image'] = array(
+ 'arguments' => array('file' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE, 'imagecache' => NULL),
+ 'file' => 'video.theme.inc',
);
- $form['counters']['video_playcounter'] = array(
- '#type' => 'checkbox',
- '#title' => t('Count play hits'),
- '#default_value' => variable_get('video_playcounter', 1),
- '#description' => t('Counts a hit everytime someone views the play page.')
+ $theme['video_widget_video_thumb'] = array(
+ 'arguments' => array('item' => TRUE),
+ 'file' => 'video.theme.inc',
);
- $form['counters']['video_downloadcounter'] = array(
- '#type' => 'checkbox',
- '#title' => t('Count downloads'),
- '#default_value' => variable_get('video_downloadcounter', 1),
- '#description' => t('Counts a hit everytime someone downloads a video.')
+ $theme['video_formatter_video_plain'] = array(
+ 'arguments' => array('element' => NULL),
+ 'file' => 'video_formatter.inc',
);
-
- $form['flash'] = array(
- '#type' => 'fieldset',
- '#title' => t('Flash settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
+ $theme['video_formatter_video_nodelink'] = array(
+ 'arguments' => array('element' => NULL, 'imagecache' => NULL),
+ 'file' => 'video_formatter.inc',
);
- $form['flash']['video_flvplayerloader'] = array(
- '#type' => 'textfield',
- '#title' => t('Filename of Flash loader'),
- '#default_value' => variable_get('video_flvplayerloader', 'FlowPlayer.swf'),
- '#description' => t('The name of the Shockwave file that manages loading the FLV movie. This is relative to the website root.')
+ //$theme['video_formatter_video_colorbox'] = 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',
);
- $form['ogg'] = array(
- '#type' => 'fieldset',
- '#title' => t('Ogg Theora settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE
+ $theme['video_encoding_failed'] = array(
+ 'arguments' => array(),
+ 'file' => 'video_formatter.inc',
);
- $form['ogg']['video_cortado'] = array(
- '#type' => 'textfield',
- '#title' => t('Filename of Cortado Java Applet'),
- '#default_value' => variable_get('video_cortado', $base_url . '/cortado.jar'),
- '#description' => t('The path to the Cortado Applet to play Ogg Theora Files.')
+ $theme['video_inprogress'] = array(
+ 'arguments' => array(),
+ 'file' => 'video_formatter.inc',
);
- return system_settings_form($form);
-}
-
-
-/**
- * Form API callback to validate the upload settings form.
- *
- * Keeps the use from showing the play tab or the play link
- * if they have chosen to display the video in the node body.
- *
- * @param $form_id
- * The identifier of the form
- *
- * @param $form_values
- * form values from the settings page
- *
- */
-function video_settings_form_validate($form, &$form_state){
- //print_r($form_state['values']); die;
-
- // if admin set a name for a resolution he also have to set its value
- while($i <= 4) {
- if($form_state['values']["video_resolution_{$i}_name"] != '' && $form_state['values']["video_resolution_{$i}_value"] == '') {
- form_set_error("video_resolution_{$i}_value", t('You have to set a value for resolution %res_num if you want to enable it.', array('%res_num' => $i)));
- }
- if($form_state['values']["video_resolution_{$i}_value"] != '' && !preg_match('/^[0-9]{2,4}x[0-9]{2,4}$/',$form_state['values']["video_resolution_{$i}_value"])) { // check valid resolution value
- form_set_error("video_resolution_{$i}_value", t('You have to set valid value for resolution %res_num if you want to enable it. A valid value is 400x300', array('%res_num' => $i)));
- }
-
- $i++;
- }
- ; // for future use
-}
-
-
-/******************************************************************************
- * Node Hooks
- ******************************************************************************/
-
-/**
- * Implementation of _node_info().
- *
- * @return
- * array
- */
-function video_node_info() {
- return array('video' => array(
- 'name' => t('Video'),
- 'module' => 'video',
- 'description' => t('Allow a variety of video formats to be posted as nodes in your site'),
- )
+ $path = drupal_get_path('module', 'video'). '/theme';
+ //Lets setup our themes for our players
+ $players = video_video_players();
+ foreach($players as $tpl => $value) {
+ $theme[$tpl] = array(
+ 'arguments' => array('video' => NULL, 'node' => NULL, 'themed_output' => NULL),
+ 'file' => 'video_formatter.inc',
+ 'template' => str_replace('_', '-', $tpl),
+ 'path' => $path,
);
-}
-
-/**
- * access hook
- */
-function video_access($op, $node, $account) {
-
-
- if ($op == 'create') {
- return user_access('create video', $account);
}
+ //We need to add an flv theme buffer to allow users to override in their own module to add in extra parameters before
+ //calling our flv template file.
+ $theme['video_flv'] = array(
+ 'arguments' => array('video' => NULL, 'node' => NULL),
+ 'file' => 'video_formatter.inc'
+ );
- if ($op == 'update' || $op == 'delete') {
- return (user_access('edit own video', $account) && ($account->uid == $node->uid)) || user_access('edit all video nodes', $account);
+ //setup our imagecache presets
+ if(module_exists('imagecache')) {
+ //we need formatters for each of our thumbnails.
+ //@todo create a function to check for our colorbox module and only add theme elements that could be used.
+ $thumb_types = array('video_nodelink'); //array('video_colorbox', 'video_nodelink');
+ 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;
}
/**
- * Implementation of hook_nodeapi().
- * We use this to append <enclosure> tags to the RSS feeds Drupal generates.
+ * Implementation of CCK's hook_field_formatter_info().
*/
-function video_nodeapi($node, $op, $arg) {
- switch ($op) {
- case 'rss item':
- if ($node->type == 'video') {
- // RSS Enclosure http://cyber.law.harvard.edu/rss/rss.html#ltenclosuregtSubelementOfLtitemgt
- $attributes['url'] = _video_get_fileurl($node->vidfile);
- $attributes['length'] = $node->size;
- $mime_type = _video_get_mime_type($node);
- if ($mime_type) {
- $attributes['type'] = $mime_type;
- $enclosure = array('key' => 'enclosure', 'attributes' => $attributes);
- }
-
- // MRSS media:content http://search.yahoo.com/mrss
- $media['url'] = $attributes['url'];
- if ($attributes['length'] > 1) {
- $media['fileSize'] = $attributes['length'];
- }
- if ($mime_type) {
- $media['type'] = $mime_type;
- }
- if (isset($node->playtime_seconds) && $node->playtime_seconds > 0) {
- $media['duration'] = $node->playtime_seconds;
- }
- if (isset($node->video_bitrate) && $node->video_bitrate > 0) {
- $media['bitrate'] = $node->video_bitrate;
- }
- if (isset($node->videox) && isset($node->videoy) && $node->videox > 0) {
- $media['width'] = $node->videox;
- $media['height'] = $node->videoy;
- }
- if (isset($node->audio_sampling_rate) && $node->audio_sampling_rate > 0) {
- $media['samplingrate'] = $node->audio_sampling_rate;
- }
- $mrss = array('key' => 'media:content', 'attributes' => $media);
-
- // work around for http://drupal.org/node/157709
- static $been_here = FALSE;
- if (! $been_here) {
- $mrss['namespace'] = array('xmlns:media="http://search.yahoo.com/mrss/"');
- $been_here = TRUE;
- }
+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_colorbox' => array(
+ // 'label' => t('Video Thumbnail to Colorbox'),
+ // 'field types' => array('filefield'),
+ // 'description' => t('Displays the video thumbnail and adds colorbox support.'),
+ //),
+ 'video_media_js' => array(
+ 'label' => t('Video inject with jMedia'),
+ 'field types' => array('filefield'),
+ 'description' => t('Displays the video by using jmedia javascript.'),
+ ),
+ );
+ //setup our imagecache presets
+ if(module_exists('imagecache')) {
+ //we need formatters for each of our thumbnails.
+ $thumb_types = array('video_nodelink'); //array('video_colorbox', 'video_nodelink');
+ 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 array($enclosure, $mrss);
-
- case 'revision delete':
- db_query('DELETE FROM {video} WHERE vid = %d', $node->vid);
- break;
+ }
}
+ return $formatters;
}
-
-/**
- * Create video submission page. Let the user select the actived video types
- * or display the video form for the selected video type
+/*
+ * Implmentation of hook_cron().
*/
-function video_add() {
- global $user;
-
- $edit = isset($_POST['edit']) ? $_POST['edit'] : '';
-
- // If a video type has been specified, validate its existence.
-
- $vtypes = video_get_types();
-
- if (arg(3) && in_array(arg(3), $vtypes)) { // is a valid video type
- $type = arg(3);
-
- // Initialize settings:
- module_load_include('inc', 'node', 'node.pages');
- $node = (object) array('uid' => $user->uid, 'name' => $user->name, 'type' => 'video', 'vtype' => $type);
- $output = drupal_get_form('video_node_form', $node);
- drupal_set_title(t('Submit %name video', array('%name' => $type)));
- }
- else if (count($vtypes) == 1) { // only one vtype active. redirect the user to the active type form
- // Initialize settings:
- $node = (object) array('uid' => $user->uid, 'name' => $user->name, 'type' => 'video', 'vtype' => $vtypes[0]);
- module_load_include('inc', 'node', 'node.pages');
- $output = drupal_get_form('video_node_form', $node);
- drupal_set_title(t('Submit %name video', array('%name' => $vtypes[0])));
- }
- else if ($vtype = variable_get('video_default_video_type', 0)) {
- // Initialize settings:
- $node = (object) array('uid' => $user->uid, 'name' => $user->name, 'type' => 'video', 'vtype' => $vtype);
- module_load_include('inc', 'node', 'node.pages');
- $output = drupal_get_form('video_node_form', $node);
- drupal_set_title(t('Submit %name video', array('%name' => $vtype)));
- }
- else {
- $output = video_types_page();
+function video_cron() {
+ if (variable_get('video_cron', FALSE)) {
+ module_load_include('inc', 'video', '/includes/conversion');
+ $video_conversion = new video_conversion;
+ $video_conversion->run_queue();
}
- return $output;
}
-
-/**
- * Display a video types selection page
-*/
-function video_types_page() {
-
- drupal_set_title(t('Submit Video')); // we have to set a titl ebecause the node module will not do it for us as we are using a callback video_add()
-
- $vtypes = video_get_types_infos();
- if(!$vtypes) { // no vtype available
- return t('There are no Video types enabled.');
- }
- else {
- $items = array();
- foreach ($vtypes as $vtype => $infos) {
- $out = '<dt>'. l($infos['#name'], "node/add/video/$vtype", array('HTML'=>TRUE, 'attributes' => array('title' => 'Add a '. $infos['#name']))) .'</dt>';
- $out .= '<dd>'. $infos['#description'] .'</dd>';
- $items[$vtype] = $out;
- }
- // let's order by type name
- ksort($items);
- return t('Choose from the following available video types:') .'<dl>'. implode('', $items) .'</dl>';
+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';
}
}
-
-/**
- * Return an array containing enabled Video Types
- */
-function video_get_types(){
- return array_keys(video_get_types_infos());
-}
-
-
-/**
- * Return an array containing informations on enabled Video Types
- */
-function video_get_types_infos(){
- static $infos = NULL;
-
- if(!is_array($infos)) {
- $infos = module_invoke_all('v_info');
+function video_node_update_submit($form, &$form_state) {
+ //lets update our video rending table to include the node id created
+ 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) {
+ //lets update our table to include the nid
+ db_query("UPDATE {video_files} SET nid=%d WHERE fid=%d", $form_state['nid'], $fid);
+ }
}
- return $infos;
-}
-
-
-/**
- * Return the informations for a given video type
-*/
-function video_get_type_info($type) {
- return module_invoke('video_'.$type, 'v_info');
}
-
-/**
- * Return true if a given video type is downloadable
+/*
+ * Utility function that will add a preview of thumbnails for you to select when uploading videos.
*/
-function video_support_download($node) {
- $info = video_get_type_info($node->vtype);
- return $info[$node->vtype]['#downloadable'];
-}
-
-
-
-/**
- * Hook, displays the contents of the node form page for creating and editing nodes.
- *
- * @param $node
- * object
- *
- * @return
- * string value of form content
- */
-function video_form($node) {
- //We must unserialize the array for display in the forms.
- if($node->serial_data) {
- $node->serial_data = unserialize($node->serialized_data);
- }
- $form = array();
-
- // default node stuff
- $type = node_get_types('type', $node);
-
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#size' => 60,
- '#maxlength' => 128,
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#weight' => -20
- );
-
- if ($type->has_body) {
- $form['body_filter']['body'] = array(
- '#type' => 'textarea',
- '#title' => check_plain($type->body_label),
- '#required' => ($type->min_word_count > 0),
- '#rows' => 10,
- '#default_value' => $node->body,
- );
- $form['body_filter']['format'] = filter_form($node->format);
- }
-
- // set an hidden field to store video type
- $form['vtype'] = array(
- '#type' => 'hidden',
- '#value' => $node->vtype
- );
-
- // kjh: set an hidden field to store encoded fid
- if ($node->serial_data && isset($node->serial_data['video_encoded_fid'])) {
- $form['video_encoded_fid'] = array(
- '#type' => 'hidden',
- '#value' => $node->serial_data['video_encoded_fid']
- );
- }
+function video_thumb_process(&$element) {
+ // Developed for ffmpeg support
+ $file = $element['#value'];
+ $delta = $file['fid'];
+ if (isset($element['preview']) && $file['fid'] != 0) {
+ module_load_include('inc', 'video', '/includes/transcoder');
+ $transcoder = new video_transcoder;
+ if($thumbs = $transcoder->generate_thumbnails($file)) {
+ $default_thumb = '';
+ $rnd_img = rand(0, variable_get('no_of_video_thumbs', 5) - 1);
+ $default_thumb = $thumbs[$rnd_img]->filepath;
+
+ if(is_array($thumbs)) {
+ foreach($thumbs as $fid => $img) {
+ $thumbss[$img->filepath] = theme('video_thumbnails', $img, '', '', array('width' => '50'), FALSE);
+ }
+ }
+ }
- $form['video'] = array('#type' => 'fieldset', '#title' => t('Video Information'), '#weight' => -19);
-
- if(!video_support_autoresolution($node)) { // this vtype doesn't support autoresolution
- // let's display the resolution selection
- $form['video']['vresolution'] = array(
- '#type' => 'select',
- '#title' => t('Resolution'),
- '#description' => t("Select the approriate resolution (aspect ratio) for your video.<br />If you don't know what to choose then the default value will probably be ok for you."),
- '#options' => _video_get_resolution_options(),
- '#default_value' => _video_get_resolution_selected_option($node),
- '#required' => true,
- );
- }
- else {
- // set an hidden field to store video resolution
- $form['hvresolution'] = array(
- '#type' => 'hidden',
- '#value' => $node->videox . 'x' . $node->videoy
+ $element['data']['video_thumb'] = array(
+ '#type' => 'radios',
+ '#title' => t('Video Thumbnails'),
+ '#options' => $thumbss,
+ '#default_value' => !empty($file['data']['video_thumb']) ? $file['data']['video_thumb'] : $default_thumb,
+ '#weight' => 10,
+ '#attributes' => array('class' => 'video-thumbnails', 'onchange' => 'videoftp_thumbnail_change()', 'rel' => 'video_large_thumbnail-'.$delta),
);
- }
-
- if(!video_support_autoplaytime($node)) { // this vtype doesn't support autoplaytime
- $form['video']['playtime'] = array(
- '#type' => 'fieldset',
- '#title' => t('Playtime'),
- '#collapsible' => true,
- '#collapsed' => ($node->playtime_seconds) ? false : true, // display expanded if we have values inserted by the user
- '#description' => t('Insert here the duration of the video.<br />Values may be entered in excess of their normal "clock maximum" (the seconds field may be 3600 to represent 1 hour), however each value will be summed for a total of all three.'));
- $playtime = _video_sec2hms($node->playtime_seconds);
- $form['video']['playtime']['playtime_hours'] = array(
- '#type' => 'textfield',
- '#title' => t('Hours'),
- '#size' => 11,
- '#maxlength' => 11,
- '#default_value' => $playtime['hours'],
- );
- $form['video']['playtime']['playtime_minutes'] = array(
- '#type' => 'textfield',
- '#title' => t('Minutes'),
- '#size' => 11,
- '#maxlength' => 11,
- '#default_value' => $playtime['minutes'],
- );
- $form['video']['playtime']['playtime_seconds'] = array(
- '#type' => 'textfield',
- '#title' => t('Seconds'),
- '#required' => FALSE,
- '#size' => 11,
- '#maxlength' => 11,
- '#default_value' => $playtime['seconds'],
- );
- }
- else {
- // set an hidden field to store video length
- $form['playtime_seconds'] = array(
- '#type' => 'hidden',
- '#value' => $node->playtime_seconds
- );
- // we need to store file size too
- $form['hsize'] = array(
- '#type' => 'hidden',
- '#value' => $node->size
- );
- }
-
- // Get the video-type-specific bits.
- $form = module_invoke('video_' . $node->vtype, 'v_form', $node, $form);
-
- return $form;
-}
-
-
-/**
- * Implementation of hook_validate
- */
-function video_validate($node, $form = array()) {
- if(!video_support_autoresolution($node) || $node->vresolution) { // we have some resolution value
- // form api checked for good values of vresolution
- if(variable_get("video_{$node->vresolution}_value", '') == '') {
+ // Setup our large thumbnail that is on the left.
+ // @todo Add smaller video preview instead of thumbnail?
+ if (isset($file['data']['video_thumb']) && !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'];
}
+ else {
+ $large_thumb = array('filepath' => $default_thumb);
+ }
+ // @todo Integrate the thumbnails with imagecache.
+ $element['preview']['#suffix'] = '<div class="video_large_thumbnail-'.$delta.'">'. theme('video_thumbnails', $large_thumb, '', '', array('width' => '150'), FALSE) .'</div>';
}
-
- module_invoke('video_'.$node->vtype, 'v_validate', $node);
-
}
-
/**
- * Implementation of hook submit
+ * Adds a video to the video rendering table.
+ *
+ * If auto converting, it will convert your video to flv right now. We are passing the element by reference
+ * just in case we ever want to add more to the element during this process.
+ *
+ * @param $element
+ * Form element to get the video file from.
*/
-function video_presave(&$node) {
- if(video_support_autoresolution($node) && ($node->new_video_upload_file_fid)) { // vtype support autoresolution getting
- $xy = module_invoke('video_' . $node->vtype, 'v_auto_resolution', $node);
- if ($xy) {
- $node->videox = $xy[0];
- $node->videoy = $xy[1];
- }
+function video_convert_process(&$element) {
+ $file = $element['#value'];
+ // Add default dimensions from our default_value if needed
+ if(!isset($file['data']['dimensions'])) {
+ $file['data']['dimensions'] = $element['data']['dimensions']['#value'];
}
- else {
- // if you have a existing value from hidden field
- if($node->hvresolution) {
- $res = explode('x', $node->hvresolution);
- $node->videox = $res[0];
- $node->videoy = $res[1];
- $node->size = $node->hsize;
+ $convert = false;
+ //we need to check if this fid has already been added to the database AND that there is in fact a fid
+ if (is_array($file) && isset($file['fid']) && !empty($file['fid']) && !$file['data']['bypass_autoconversion']) {
+ $fid = $file['fid'];
+ //setup our conversion class and check for the fid existence.
+ module_load_include('inc', 'video', '/includes/conversion');
+ $video_conversion = new video_conversion;
+ // Lets verify that we haven't added this video already. Multiple validation fails will cause this to be ran more than once
+ if(!$video = $video_conversion->load_video($fid)) {
+ // Video has not been added to the queue yet so lets add it.
+ db_query("INSERT INTO {video_files} (fid, status, dimensions) VALUES (%d, %d, '%s')", $fid, VIDEO_RENDERING_PENDING, $file['data']['dimensions']);
+ $convert = true;
+ //lets queue our node status to unpublished.
+ $element['#unpublish'] = true;
}
- // we should have a good value (checked by Form API)
- else {
- $res = explode('x', variable_get('video_resolution_' . $node->vresolution . '_value', ''));
- $node->videox = $res[0];
- $node->videoy = $res[1];
+ elseif($video->video_status != VIDEO_RENDERING_COMPLETE) {
+ //lets queue our node status to unpublished.
+ $element['#unpublish'] = true;
}
- }
- if(video_support_autoplaytime($node) && ($node->new_video_upload_file_fid)) { // vtype support auto playtime
- $node->playtime_seconds = module_invoke('video_' . $node->vtype, 'v_auto_playtime', $node);
- }
- else { // vtype does not support auto_playtime
- $node->playtime_seconds += ($node->playtime_hours * 3600) + ($node->playtime_minutes * 60);
+ // Our video should be in the database pending, lets see if we need to convert it now.
+ // Check if we are going from unselected to selected or if this is a new video and we have checked the checkbox
+ if (((!isset($element['#default_value']['data']['convert_video_on_save']) || !$element['#default_value']['data']['convert_video_on_save']) && $file['data']['convert_video_on_save']) || ($convert && $file['data']['convert_video_on_save'])) {
+ $return = $video_conversion->process($fid);
+ if ($return === FALSE) {
+ drupal_set_message(t('Something went wrong with your video conversion. Please check your recent log entries for further debugging.'), 'error');
+ }
+ elseif($return === TRUE) {
+ //we are always unpublished until we are converted.
+ unset($element['#unpublish']);
+ drupal_set_message(t('Successfully converted your video.'));
+ }
+ }
+ elseif ($convert) {
+ drupal_set_message(t('Video submission queued for processing. Please wait: our servers are preparing your video for display.'));
+ }
}
}
/**
- * Implementation of hook_insert.
- * Create video record in the video table
- *
- * @return
- * TRUE on success, FALSE on error
+ * Implementation of hook_file_delete().
*/
-function video_insert($node) {
- // set the required properties of the video node
- video_presave($node);
- $node->serialized_data = serialize($node->serial_data); //Serialize the data for insertion into the database.
-
- return db_query("INSERT INTO {video} (vid, nid, vtype, vidfile, size, videox, videoy, video_bitrate, audio_bitrate, audio_sampling_rate, audio_channels, playtime_seconds, disable_multidownload, download_folder, use_play_folder, serialized_data) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s')",
- $node->vid, $node->nid, $node->vtype, $node->vidfile, $node->size, $node->videox, $node->videoy, $node->video_bitrate, $node->audio_bitrate, $node->audio_sampling_rate, $node->audio_channels, $node->playtime_seconds, $node->disable_multidownload, $node->download_folder, $node->use_play_folder, $node->serialized_data);
+function video_file_delete($file) {
+ //lets get all our videos and unlink them
+ $sql = db_query("SELECT filepath FROM {video_files} WHERE fid=%d", $file->fid);
+ //we loop here as future development will include multiple video types (HTML 5)
+ while($row = db_fetch_object($sql)) {
+ if(file_exists($row->filepath)) unlink($row->filepath);
+ }
+ //now delete our rows.
+ db_query('DELETE FROM {video_files} WHERE fid = %d', $file->fid);
+ //now lets delete our video thumbnails and folder.
+ $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs');
+ $thumb_folder = file_directory_path(). '/' . $video_thumb_path . '/' . $file->fid;
+ // Recursively delete our folder and files
+ rmdirr($thumb_folder);
}
-
/**
- * Hook
- *
- * @return
- * TRUE on success, FALSE on error
+ * Compares passed extensions with normal video web extensions.
*/
-function video_update($node) {
- if ($node->revision) { //If a new node revision is being added then insert a new row.
- return video_insert($node);
- }
- else {
- // set the required properties of the video node
- video_presave($node);
-
- // GMM: make sure to save the encoded_fid
- if (!isset($node->serial_data['video_encoded_fid']) && $node->video_encoded_fid) {
- $node->serial_data['video_encoded_fid'] = $node->video_encoded_fid;
- }
-
- $node->serialized_data = serialize($node->serial_data); //Serialize the data for insertion into the database.
-
- return db_query("UPDATE {video} SET vidfile='%s', size=%d, videox=%d, videoy=%d, video_bitrate=%d, audio_bitrate=%d, audio_sampling_rate=%d, audio_channels='%s', playtime_seconds=%d, disable_multidownload=%d, download_folder='%s', use_play_folder=%d, serialized_data='%s' WHERE vid = %d",
- $node->vidfile, $node->size, $node->videox, $node->videoy, $node->video_bitrate, $node->audio_bitrate, $node->audio_sampling_rate, $node->audio_channels, $node->playtime_seconds, $node->disable_multidownload, $node->download_folder, $node->use_play_folder, $node->serialized_data, $node->vid);
+function video_web_extensions($ext) {
+ $extensions = array_filter(explode(' ', $ext));
+ $web_extensions = array(
+ 'mov', 'mp4', '3gp', '3g2', 'mpg', 'mpeg', // quicktime
+ 'divx', //divx
+ 'rm', // realplayer
+ 'flv', 'f4v', //flash player
+ 'swf', // swf player
+ 'dir', 'dcr', // dcr player
+ 'asf', 'wmv', 'avi', 'mpg', 'mpeg', // windows media
+ 'ogg',
+ 'ogv', // ogg/ogv theora
+ );
+ if (count(array_diff($extensions, $web_extensions))) {
+ return FALSE;
}
+ return TRUE;
}
-
-
/**
- * Implementation of hook_delete
+ * Implementation of hook_views_api().
*/
-function video_delete($node) {
- db_query("DELETE FROM {video} WHERE nid = %d", $node->nid);
+function video_views_api() {
+ return array(
+ 'api' => 2.0,
+ 'path' => drupal_get_path('module', 'video') . '/views',
+ );
}
-
-
/**
- * Implementation of hook_load()
- *
- * @param $node
- * object or boolean FALSE on error
- */
-function video_load($node) {
-
- if (is_numeric($node->vid)) {
- $node = db_fetch_object(db_query("SELECT * FROM {video} WHERE vid = %d", $node->vid));
-
- // load serialized data for plug-ins
- $node->serial_data = unserialize($node->serialized_data);
-
- return $node;
+ * Process elements loads on settings
+ * @param <type> $element
+ */
+function video_widget_element_settings(&$element) {
+ $file = $element['#value'];
+ $delta = $element['#delta'];
+ $field = content_fields($element['#field_name'], $element['#type_name']);
+ // Check if using the default width and replace tokens.
+ $default_dimensions = user_access('override player dimensions');
+ $description = t('Set your video dimensions. This will create your player with these dimensions.');
+ //setup our default dimensions.
+ $dimensions = $field['widget']['default_dimensions'];
+ $player_dimensions = $field['widget']['default_player_dimensions'];
+ // Lets figure out our dimensions for our video and add astericks next to our options.
+ $options = video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions()));
+ if ($field['widget']['autoconversion'] && isset($element['preview']) && $file['fid'] != 0 && $default_dimensions) {
+ $video_info = _video_dimensions_options($options, $file['filepath']);
+ $description = t('Set your video dimensions. This will create your player and transcode your video with these dimensions. Your video size is !size, if you choose a higher resolution, this could cause video distortion. You are shown dimensions that match your aspect ratio, if you choose dimensions that do not match your ratio, we will pad your video by adding black bars on either the top or bottom while maintaining your videos original aspect ratio.', array('!size' => $video_info['width'] .'x'. $video_info['height']));
+ //setup our default display of dimensions.
+ //lets go through our options looking for a matching resolution
+ foreach($options as $key => $value) {
+ if(stristr($value, t('(Matches Resolution)')) == TRUE) {
+ $dimensions = $key;
+ break;
+ }
+ }
}
- else {
- return false;
+ // Override our dimensions to the user selected.
+ if (isset($file['data']['dimensions']) && !empty($file['data']['dimensions'])) {
+ $dimensions = $file['data']['dimensions'];
}
-}
-/**
- * Implementation of hook_view().
- */
-function video_view(&$node, $teaser = FALSE, $page = FALSE) {
+ // Override our player dimensions to the user selected.
+ if (isset($file['data']['player_dimensions']) && !empty($file['data']['player_dimensions'])) {
+ $player_dimensions = $file['data']['player_dimensions'];
+ }
- // include the video css file
- drupal_add_css(drupal_get_path('module', 'video').'/video.css');
+ $element['data']['dimensions'] = array(
+ '#type' => 'select',
+ '#title' => t('Dimensions for Video Transcoding'),
+ '#default_value' => $dimensions,
+ '#description' => $description,
+ '#options' => $options,
+ );
+ $element['data']['player_dimensions'] = array(
+ '#type' => 'select',
+ '#title' => t('Dimensions for Video Player'),
+ '#default_value' => $player_dimensions,
+ '#description' => t('WxH of your video player.'),
+ '#options' => $options,
+ );
+ // If users cannot change the default dimensions, lets change this to a value.
+ if (!$default_dimensions) {
+ $element['data']['dimensions']['#type'] = 'value';
+ $element['data']['dimensions']['#value'] = $dimensions;
+ $element['data']['player_dimensions']['#type'] = 'value';
+ $element['data']['player_dimensions']['#value'] = $player_dimensions;
+ }
- //Run the body through the standard filters.
- $node = node_prepare($node, $teaser);
- //print_r($node);
- //exit;
- // theme the teaser
- $node->teaser = theme('video_teaser', $node, $teaser, $page);
-
- // if we are viewing the page, run the body through the theme
- if ($page) {
- $output = '';
- if (user_access('play video')) {
- $node->content['video_player'] = array('#value' => theme('video_player', $node), '#weight' => -1);
+ // only in preview mode and then create thumbnails
+ if ($field['widget']['autoconversion']) {
+ if (user_access('bypass conversion video')) {
+ $element['data']['bypass_autoconversion'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Bypass auto conversion'),
+ '#default_value' => isset($file['data']['bypass_autoconversion']) ? $file['data']['bypass_autoconversion'] : variable_get('video_bypass_conversion', FALSE),
+ '#description' => t('This will bypass your auto conversion of videos.'),
+ '#attributes' => array('class' => 'video-bypass-auto-conversion'),
+ );
}
- else {
- $output .= l(t('login'), "user/login", array('class' => 'outgoing', 'title' => t('login to your account')));
- $output .= ' ' . t('or') . ' ';
- $output .= l(t('register'), "user/register", array('class' => 'outgoing', 'title' => t('create a new account')));
- $output .= ' ' . t('to play video');
-
- $node->content['video_player'] = array('#value' => $output, '#weight' => -1);
+ $convert_on_submission = user_access('convert on submission');
+ $element['data']['convert_video_on_save'] = array(
+ '#type' => $convert_on_submission ? 'checkbox' : 'value',
+ '#title' => t('Convert video on save'),
+ '#default_value' => isset($file['data']['convert_video_on_save']) ? $file['data']['convert_video_on_save'] : variable_get('video_convert_on_save', FALSE),
+ '#description' => t('This will convert your video to flv format when you save, instead of scheduling it for cron.'),
+ '#attributes' => array('class' => 'video-convert-video-on-save'),
+ );
+ $use_default_thumb = user_access('use default thumb');
+ if ($use_default_thumb) {
+ $element['data']['use_default_video_thumb'] = array(
+ '#type' => $use_default_thumb ? 'checkbox' : 'value',
+ '#title' => t('Use the default thumbnail for this video?'),
+ '#default_value' => isset($file['data']['use_default_video_thumb']) ? $file['data']['use_default_video_thumb'] : variable_get('video_use_default_thumb', FALSE),
+ '#description' => t('This will set a flag for this video to use the default video thumbnail when outputed..'),
+ '#attributes' => array('class' => 'video-use-default-video-thumb'),
+ );
}
}
-
- return $node;
}
-/********************************************************************
- * Block display functions
- ********************************************************************/
/**
- * Hook block. Does all the interaction with the drupal block system. Uses video_block_list() for DB queries.
- *
- * @param $op
- * string type of block
- *
- * @param $delta
- * integer 0 for latest, 1 for played+downloaded, 2 for most played, 3 for most downloaded.
- *
- * @param $edit
- * array holds the data submitted by the configure forms.
- *
- * @return
- * array
- */
-function video_block($op = 'list', $delta = 0, $edit = array()) {
- if ($op == 'list') {
- $blocks[0]['info'] = t('Latest videos');
- $blocks[1]['info'] = t('Top videos');
- $blocks[2]['info'] = t('Most played videos');
- $blocks[3]['info'] = t('Most downloaded');
- $blocks[4]['info'] = t('Random video');
- return $blocks;
- }
- else if ($op == 'view') {
- switch ($delta) {
- case 0:
- return array(
- 'subject' => variable_get('video_block_title_0', t('Latest videos')),
- 'content' => video_block_list($delta)
- );
- case 1:
- return array(
- 'subject' => variable_get('video_block_title_1', t('Top videos')),
- 'content' => video_block_list($delta)
- );
- case 2:
- return array(
- 'subject' => variable_get('video_block_title_2', t('Most played videos')),
- 'content' => video_block_list($delta)
- );
- case 3:
- return array(
- 'subject' => variable_get('video_block_title_3', t('Most downloaded')),
- 'content' => video_block_list($delta)
- );
- case 4:
- return array(
- 'subject' => variable_get('video_block_title_4', t('Random video')),
- 'content' => video_block_list($delta)
- );
- }
- }
- else if ($op == 'configure') {
- switch ($delta) { //Get the default title of the block incase the variable is not set yet.
- case 0:
- $default_title = t('Latest videos');
- break;
- case 1:
- $default_title = t('Top videos');
- break;
- case 2:
- $default_title = t('Most played videos');
- break;
- case 3:
- $default_title = t('Most downloaded');
- break;
- case 4:
- $default_title = t('Random video');
- }
- $form['video_block_title'] = array(
- '#type' => 'textfield',
- '#title' => t('Block display title'),
- '#default_value' => variable_get("video_block_title_$delta", $default_title));
- $form['video_block_limit'] = array(
- '#type' => 'select',
- '#title' => t('Number of videos to list in block'),
- '#default_value' => variable_get("video_block_limit_$delta", 10),
- '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)));
- return $form;
- }
- else if ($op == 'save') {
- variable_set("video_block_title_$delta", $edit['video_block_title']);
- variable_set("video_block_limit_$delta", $edit['video_block_limit']);
- }
-}
-
-/**
- * Query DB for block content
- *
- * @param $delta
- * int 0, 1, 2, or 3. Determines which type of block is being accessed.
- *
- * @return
- * string HTML content for a block
+ * Video_widgi_process for API handlers for any video types.
+ * @param <type> $element
+ * @param <type> $form_state
*/
-function video_block_list($delta = 0) {
- $count = variable_get("video_block_limit_$delta", 10);
- switch ($delta) {
- case 0:
- $orderby = 'n.created';
- break;
- case 1:
- $orderby = 'v.download_counter + v.play_counter';
- break;
- case 2:
- $orderby = 'v.play_counter';
+function video_widget_process($element, &$form_state) {
+ $item = $element['#value'];
+ switch($form_state['clicked_button']['#submit'][0]) {
+ case 'node_form_submit':
+ // Auto convert our video file
+ if($field['widget']['autoconversion']) {
+ video_convert_process($element);
+ //lets set our node status to unpublished if our video is not converted.
+ if ($element['#unpublish']) {
+ //unpublish the node
+ $form_state['values']['status'] = 0;
+ }
+ }
+ // Call hook_video_submit API
+ video_module_invoke('submit', $element, $form_state);
+ //
+ //queue up the file id to update the node id in the video rendering / cdn tables.
+ $form_state['values']['video_id'][] = $item['fid'];
break;
- case 3:
- $orderby = 'v.download_counter';
+ case 'node_form_build_preview':
+ // Call hook_video_preview API
+ video_module_invoke('preview', &$element, &$form_state);
break;
- case 4:
- $count = 1;
- $orderby = 'RAND()';
+ case 'node_form_delete_submit':
+ //moved to hook_file_delete in video module.
break;
}
- return node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, $orderby FROM {node} n INNER JOIN {video} v ON n.vid = v.vid WHERE n.type = 'video' AND n.status = 1 AND n.moderate = 0 ORDER BY $orderby DESC"),0, $count));
}
-/****************************************************
- * Menu callback functions
- ****************************************************/
-
-/**
- * Redirects to download the video file.
- */
-function video_download($node) {
- // $node as been loaded by video_menu
- print_r($node);
- exit;
- if ($node) {
- if (video_support_download($node) && _video_allow_download($node)) { //Make sure the video type is not youtube before downloading.
- _video_download_goto($node);
+/*
+ * Function updates our options list to show matching aspect ratios and if we have a matching resolution.
+ *
+ * We will update the options array by reference and return the aspect ratio of the file.
+*/
+function _video_dimensions_options(&$options, $video) {
+ $aspect_ratio = _video_aspect_ratio($video);
+ //loop through our options and find matching ratio's and also the exact width/height
+ foreach($options as $key => $value) {
+ $wxh = explode('x', $value);
+ //lets check our width and height first
+ if($aspect_ratio['width'] == $wxh[0] && $aspect_ratio['height'] == $wxh[1]) {
+ $options[$key] = $value .' '.t('(Matches Resolution)');
}
- else { //If video is type youtube then it can't be downloaded.
- drupal_set_message(t('There are no files to download for this video.'), 'error');
- print theme('page', '');
+ else {
+ //now lets check our ratio's
+ $ratio = number_format($wxh[0] / $wxh[1], 4);
+ if($ratio == $aspect_ratio['ratio']) {
+ $options[$key] = $value .' '.t('(Matches Ratio)');
+ }
}
}
- else {
- drupal_not_found();
- }
+ return $aspect_ratio;
}
-
-/**
- * Return true if the video is downloadable, false otherwise
+/*
+ * Returns the width/height and aspect ratio of the video
+ *
+ * @todo: move this to the transcoder class instead?
*/
-function _video_allow_download($node) {
- // TODO: now videos are downloadable by default. why not implementing a feature to let users choose if they want their videos to be downloadable?
-
- return true;
+function _video_aspect_ratio($video) {
+ //lets get our video dimensions from the file
+ module_load_include('inc', 'video', '/includes/transcoder');
+ $transcoder = new video_transcoder;
+ $wxh = $transcoder->get_dimensions($video);
+ $width = $wxh['width'];
+ $height = $wxh['height'];
+
+ if(!$width || !$height) {
+ //no width and height found just return.
+ watchdog('video_conversion', 'We could not determine the height and width of the video: '.$video, array(), WATCHDOG_DEBUG);
+ drupal_set_message(t('The system counld not determine the width and height of your video: !video. If transcoding, the system could have problems.', array('!video' => $video)));
+ return;
+ }
+
+ //now lets get aspect ratio and compare our options in the select dropdown then add an asterick if any to each option representing a matching aspect ratio.
+ $ratio = number_format($width / $height, 4);
+ $aspect_ratio = array(
+ 'width' => $width,
+ 'height' => $height,
+ 'ratio' => $ratio,
+ );
+ return $aspect_ratio;
}
-
-/**
- * Theme the teaser
- *
- * This is just in place for site admins and theme developers
- * who need to adjust how the teaser is themed.
- *
- * @param $node
- * The node to be displayed.
- * @param $teaser
- * Whether we are to generate a "teaser" or summary of the node, rather than display the whole thing.
- * @param $page
- * Whether the node is being displayed as a standalone page. If this is TRUE, the node title should not be displayed, as it will be printed automatically by the theme system. Also, the module may choose to alter the default breadcrumb trail in this case.
- *
- * @return
- * html
- */
-function theme_video_teaser($node, $teaser = FALSE, $page = FALSE) {
- return $node->teaser;
+/*
+ * Return our list of video extensions and their associated player.
+*/
+function video_video_extensions() {
+ $extensions = array(
+ 'divx' => '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',
+ );
+ return $extensions;
}
-/**
- * theme the view of the page to include the video
- * assumes that body was put through prepare in hook_view
- *
- * @param $node
- * The node to be displayed.
- * @param $teaser
- * Whether we are to generate a "teaser" or summary of the node, rather than display the whole thing.
- * @param $page
- * Whether the node is being displayed as a standalone page. If this is TRUE, the node title should not be displayed, as it will be printed automatically by the theme system. Also, the module may choose to alter the default breadcrumb trail in this case.
- *
- * @return
- * html
- */
-function theme_video_view($node, $teaser = FALSE, $page = FALSE) {
- return '<div id="video_body">'. $node->body .'</div>';
+/*
+ * Return our supported video players.
+*/
+function video_video_players() {
+ $players = array(
+ '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'),
+ );
+ return $players;
}
-/**
-* theme function to control which player is presented
-*
-* @param $node
-* node object
-*
-* @return
-* html
+/*
+ * Return our possible flash players.
*/
-function theme_video_player($node) {
- // include video.js file for Internet Explorer fixes
- //theme('video_get_script');
- drupal_add_js(drupal_get_path('module', 'video') . '/video.js');
- if (variable_get('video_playcounter', 1)) {
- db_query("UPDATE {video} SET play_counter = play_counter + 1 where vid = %d", $node->vid); //Increment play counter.
+function video_video_flv_players() {
+ $options = array();
+ if(module_exists('swftools')) {
+ $options['swftools'] = t('SWF Tools');
}
-
- _video_scale_video($node);
- $output = module_invoke('video_'.$node->vtype, 'v_play', $node);
-
- return $output;
-}
-
-
-/**
- * Cut down on redundant link text
- *
- * @param $url
- * string URL to link to
- *
- * @param $title
- * string title of link to show on mouseover
- *
- * @param $link_text
- * string text of the link
- *
- * @return
- * string HTML link
- */
-function theme_video_format_play($output, $url, $title, $link_text) {
- $output = "\n<div id=\"video-player\">\n" . $output;
- $output .= "<p>\n". t('Problems viewing videos?');
- $output .= "<br />\n";
- $output .= l($link_text, $url, array('attributes' => array('title' => $title), 'absolute' => TRUE));
- return $output ."\n</p> \n </div>\n";
-}
-
-
-/**
- * Takes an associative array of $fields with 'title' and 'body' keys and outputs the HTML.
- * This theme function allows the same HTML code to generate all the custom and metadata fields.
- *
- * @param $fields
- * array with 'title' and 'body' keys
- *
- * @return
- * string of content to display
- */
-function theme_video_fields($fields) {
- $output = '';
- $odd_even = 'odd';
- foreach ($fields as $field) {
- $output .= "<div class=\"$odd_even\"><b>" . check_plain($field['title']) . '</b> ' . check_plain($field['body']) . "</div>\n";
- $odd_even = ($odd_even == 'odd') ? 'even' : 'odd'; //Always switch its value.
+ if(module_exists('flowplayer')) {
+ $options['flowplayer'] = t('Flowplayer');
}
- return $output;
-}
-
-
-/**
- * Import the video.js script
- */
-function theme_video_get_scripvt() {
- drupal_add_js(drupal_get_path('module', 'video') . '/video.js');
+ return $options;
}
-/******************************************************************************
- * End theme functions
- ******************************************************************************
- * Start private functions created for this module.
- ******************************************************************************/
-
/**
- * Pull the file extension from a filename
- *
- * @param $vidfile
- * string filename to get the filetype from.
- *
- * @return
- * string value of file type or boolean FALSE on error
+ * Get the object for the suitable player for the parameter resource
*/
-function _video_get_filetype($vidfile) {
- //If the filename doesn't contain a ".", "/", or "\" and is exactly 11 characters then consider it a youtube video ID.
- if (!strpos($vidfile, '.') and !strpos($vidfile, '/') and !strpos($vidfile, '\\') and strlen($vidfile) == 11) {
- $file_type = 'youtube';
- }
- else if (strpos($vidfile, 'google:') === 0) {
- $file_type = 'googlevideo';
- }
- else if (strstr($vidfile, '.')) { //If file contains a "." then get the file extension after the "."
-
- $file_type = end(explode('.', $vidfile));
+function video_get_player($element) {
+ // Setup our node object to be passed along with the player.
+ $node = $element['#node'];
+ // Setup our video object
+ module_load_include('inc', 'video', '/includes/video_helper');
+ $video_helper = new video_helper;
+ $video = $video_helper->video_object($element);
+ // Lets spit out our theme based on the extension
+ $defaults = video_video_extensions();
+ $theme_function = variable_get('video_extension_'. $video->extension, $defaults[$video->extension]);
+ // Lets do some special handling for our flv files to accomdate multiple players.
+ if($theme_function == 'video_play_flv') {
+ return theme('video_flv', $video, $node);
}
else {
- $file_type = FALSE;
+ return theme($theme_function, $video, $node);
}
-
- return strtolower($file_type);
}
-/**
- * Forward user directly to the file for downloading
- *
- */
-function _video_download_goto($node) {
- if (user_access('download video')) {
-
- if (variable_get('video_downloadcounter', 1)) {
- db_query("UPDATE {video} SET download_counter = download_counter + 1 where vid = %d", $node->vid); //Increment download counter.
- }
-
- // let the submodule handle the real download logic
- module_invoke('video_'.$node->vtype, 'v_download', $node);
- }
- else { //If the user does not have access to download videos.
- drupal_set_message(t('You do not have permission to download videos.'), 'error');
- drupal_goto("node/".$node->nid); //Use the nid we just loaded to go back to the node page.
+function video_default_widget_settings($widget) {
+ $form = array();
+ // Default video settings.
+ $form['plugins'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Video Advanced Settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#weight' => 10
+ );
+ $form['plugins']['default_dimensions'] = array(
+ '#type' => 'select',
+ '#title' => t('Default Video Resolution Dimensions'),
+ '#default_value' => !empty($widget['default_dimensions']) ? $widget['default_dimensions'] : '',
+ '#options' => video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions())),
+ '#description' => t('Default transcoding resolution WIDTHxHEIGHT, in px, that FFMPEG will use to transcode your video files.')
+ );
+ $form['plugins']['default_player_dimensions'] = array(
+ '#type' => 'select',
+ '#title' => t('Default Video Player Dimensions'),
+ '#default_value' => !empty($widget['default_player_dimensions']) ? $widget['default_player_dimensions'] : '',
+ '#options' => video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions())),
+ '#description' => t('Default player WIDTHxHEIGHT in px. This is your actual player dimensions that your video will be playing in.')
+ );
+ $form['plugins']['autoconversion'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable video conversion.'),
+ '#description' => t('Use ffmpeg(Default) to automatically convert videos to web compatible types eg. FLV, Please make sure to configure your transcoder settings.'),
+ '#default_value' => $widget['autoconversion'],
+ );
+ $form['plugins']['autothumbnail'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable thumbnail creation.'),
+ '#description' => t('Use ffmpeg(Default) to create thumbnails, Please make sure to configure your transcoder settings.'),
+ '#default_value' => $widget['autothumbnail'],
+ );
+ // Default thumbnail settings.
+ $form['default'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Video Thumbnail Settings'),
+ '#element_validate' => array('video_default_widget_settings_validate'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#weight' => 11
+ );
+ // @TODO: Move this to the actual upload/attach when creating a node to allow the user to upload their own thumbnail for each video.
+ // Present a video image of the current default image.
+ if (!empty($widget['default_video_thumb'])) {
+ $form['default']['default_video_thumbnail'] = array(
+ '#type' => 'markup',
+ '#value' => theme('video_image', $widget['default_video_thumb'], '', '', array('width' => '150'), FALSE),
+ '#prefix' => '<div class="video_thumbnail">',
+ '#suffix' => '</div>'
+ );
}
+ $form['default']['default_video_thumb_upload'] = array(
+ '#type' => 'file',
+ '#title' => empty($widget['default_video_thumb']) ? t('Upload default video thumbnail') : t('Replace default video thumbnail with'),
+ '#description' => t('Choose a image that will be used as video thumbnail when you don\'t have video thumbnails for videos.'),
+ );
+ // We set this value on 'validate' so we can get CCK to add it
+ // as a standard field setting.
+ $form['default_video_thumb'] = array(
+ '#type' => 'value',
+ '#value' => $widget['default_video_thumb'],
+ );
+ return $form;
}
-
-
/**
- * Convert filesize to bytes
+ * Element specific validation for video default value.
*
- * @return
- * integer bytes
*/
-function _video_size2bytes($node) {
- if (!empty($node->size)) {
- switch ($node->size_format) {
- case 'Kb': // KiloBits
- return intval($node->size * 128);
- break;
- case 'KB': // KiloBytes
- return intval($node->size * 1024);
- break;
- case 'Mb': // MegaBits
- return intval($node->size * 131072);
- break;
- case 'MB': // MegaBytes
- return intval($node->size * 1048576);
- break;
- case 'Gb': // GigaBits
- return intval($node->size * 134217728);
- break;
- case 'GB': // GigaBytes
- return intval($node->size * 1073741824);
- break;
- default:
- return (int)$node->size;
- break;
- }
- }
- else {
- return 0;
+function video_default_widget_settings_validate($element, &$form_state) {
+ // Verify the destination exists
+ $destination = file_directory_path() .'/video_thumbs';
+ if (!field_file_check_directory($destination, FILE_CREATE_DIRECTORY)) {
+ form_set_error('default_video_thumb', t('The default image could not be uploaded. The destination %destination does not exist or is not writable by the server.', array('%destination' => dirname($destination))));
+ return;
}
-}
-
-
-/**
- * Convert seconds to hours, minutes, and seconds.
- * Derived from h:m:s example by Jon Haworth
- *
- * @link
- * http://www.laughing-buddha.net/jon/php/sec2hms/
- *
- * @param $sec
- * integer value of seconds.
- *
- * @return
- * array associative with key values of hours, minutes, and seconds.
- */
-function _video_sec2hms($sec = 0) {
- $hms = array();
- // 3600 seconds in an hour and trash remainder
- $hms['hours'] = intval(intval($sec) / 3600);
- // dividing the total seconds by 60 will give us
- // the number of minutes, but we're interested in
- // minutes past the hour: to get that, we need to
- // divide by 60 again and keep the remainder
- $hms['minutes'] = intval(($sec / 60) % 60);
- $hms['seconds'] = intval($sec % 60); //keep the remainder.
- return $hms;
-}
-
-/**
- * Returns an absolute url which references
- * to the video file
- *
- * @param $video_file
- * string containing absolute or relative URL to video.
- *
- * @return
- * string containing absolute URL path to video file.
- */
-function _video_get_fileurl($video_file) {
- global $base_url;
- //creation of absolute url
- if (preg_match("/^(http|ftp|mm|rstp)(s?):\/\//", $video_file)) { //If path is absolute
- return check_plain($video_file);
- }
- else { // path is relative to drupal install
- return check_plain($base_url . '/' . $video_file);
- }
-}
+ $validators = array (
+ 'file_validate_is_image' => array(),
+ );
-/**
- * Returns the correct mime-type for the video. Returns false if the
- * mime-type cannot be detected.
- */
-function _video_get_mime_type($node) {
- switch (_video_get_filetype($node->vidfile)) {
- case 'mov':
- return 'video/quicktime';
- case 'avi' : // Added
- return 'video/x-msvideo';
- case 'mpg' : // Added
- case 'mpeg' : // Added
- return 'video/mpeg'; // Added
- case 'divx':
- return 'video/vnd.divx';
- case 'rm':
- return 'application/vnd.rn-realmedia';
- case 'flv':
- return 'flv-application/octet-stream';
- case 'asf':
- return 'video/x-ms-asf';
- case 'wmv':
- return 'video/x-ms-wmv';
- case '3gp':
- return 'video/3gpp';
- case 'mp4':
- return 'video/mp4';
- case 'dir':
- case 'dcr':
- return 'application/x-director';
- // We can't support this sources properly, so return false.
- case 'youtube':
- case 'googlevideo':
- return false;
- case 'ogg':
- return 'application/ogg';
- default:
- // We couldn't detect the mime-type, so return false.
- return false;
+ // We save the upload here because we can't know the correct path until the file is saved.
+ if (!$file = file_save_upload('default_video_thumb_upload', $validators, $destination)) {
+ // No upload to save we hope... or file_save_upload() reported an error on its own.
+ return;
}
-}
-/**
- * Generates the HTML for any object parameters in an embedded video.
- *
- * @param $node the node which is being played
- *
- * @return
- * string with the parameters in HTML form.
- */
-function _video_get_parameters(&$node) {
-
- // call hook_v_get_params
- $param_value = module_invoke_all('v_get_params', $node);
-
- $output = '';
- foreach ($param_value as $param => $value) {
- $output .= '<param name="' . check_plain($param) . '" value="' . check_plain($value) . '" />\n';
+ // Remove old image (if any) & clean up database.
+ $old_default = $form_state['values']['default_video_thumb'];
+ if (!empty($old_default['fid'])) {
+ if (file_delete(file_create_path($old_default['filepath']))) {
+ db_query('DELETE FROM {files} WHERE fid=%d', $old_default['fid']);
+ }
}
- return $output;
-}
-
-/**
- * Return true if the video support auto resolution
-*/
-function video_support_autoresolution($node) {
- $info = video_get_type_info($node->vtype);
- $has_hook = module_hook('video_' . $node->vtype, 'v_auto_resolution');
- return $has_hook && isset($info[$node->vtype]['#autoresolution']) && $info[$node->vtype]['#autoresolution'];
+ // Make the file permanent and store it in the form.
+ file_set_status($file, FILE_STATUS_PERMANENT);
+ $file->timestamp = time();
+ $form_state['values']['default_video_thumb'] = (array)$file;
}
-
-/**
- * Return true if the video support auto playtime
-*/
-function video_support_autoplaytime($node) {
- $info = video_get_type_info($node->vtype);
- $has_hook = module_hook('video_' . $node->vtype, 'v_auto_playtime');
- return $has_hook && isset($info[$node->vtype]['#autoplaytime']) && $info[$node->vtype]['#autoplaytime'];
+function video_widget_settings_file_path_validate($element, &$form_state) {
+ //lets prepend our video folder to the path settings. first truncate videos/ off the end if it exists.
+ $form_state['values']['file_path'] = 'videos/'. $form_state['values']['file_path'];
}
-
-/**
- * Get the resolution options array to use on the video form
+/*
+ * #options helper function to set our key=value for the form api.
*/
-function _video_get_resolution_options() {
-
+function video_explode($delimeter, $dimensions) {
$options = array();
-
- $i = 1;
- while($i <= 4) {
- if(variable_get('video_resolution_'.$i.'_value', '') != '') { // only if we have a value
- $options[$i] = variable_get('video_resolution_'.$i.'_name', '');
+ $values = explode($delimeter, $dimensions);
+ foreach($values as $value) {
+ //lets check we have a value and its in the right format
+ if(!empty($value) && video_format_right($value)) {
+ $options[trim($value)] = trim($value);
}
- $i++;
}
return $options;
}
+function video_format_right($value) {
+ $format = explode("x", $value);
+ if(!isset($format[0]) || !is_numeric(trim($format[0]))) return false;
+ if(!isset($format[1]) || !is_numeric(trim($format[1]))) return false;
+ return true;
+}
-/**
- * Get the selected resolution id from the videox and videoy fields
+/*
+ * Default video dimensions.
*/
-function _video_get_resolution_selected_option($node) {
- $value = $node->videox . "x" . $node->videoy;
-
- $i = 1;
- while($i <= 4) {
- if(variable_get('video_resolution_'.$i.'_value', '') == $value) {
- return $i;
- }
-
- $i++;
- }
+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";
}
-/**
- * Scale a video to match the desired width
+/*
+ * Utility function to remove all files and directories recursively.
*/
-function _video_scale_video(&$node) {
- $def_width = (int) variable_get("video_resolution_width", 400);
-
- if (!$node->videox || !$node->videoy) {
- $height = $def_width * 3 / 4;
- } else {
- $height = $def_width * ($node->videoy / $node->videox); // do you remember proportions?? :-)
- }
-
- $height = round($height);
- // add one if odd
- if($height % 2) {
- $height++;
+function rmdirr($dir) {
+ if($objs = glob($dir."/*")) {
+ foreach($objs as $obj) {
+ is_dir($obj)? rmdirr($obj) : unlink($obj);
+ }
}
- $node->video_scaled_x = $def_width;
- $node->video_scaled_y = $height;
-}
-
-/**
- * Implementation of hook_theme().
- */
-function video_theme() {
- return array(
- 'video_page' => array(
- 'arguments' => array(),
- ),
- 'video_fields' => array(
- 'arguments' => array('fields' => NULL),
- ),
- 'video_format_play' => array(
- 'arguments' => array('output' => NULL,'url' => NULL,'title' => NULL,'link_text' => NULL),
- ),
- 'video_get_scripvt' => array(
- 'arguments' => array(),
- ),
- 'video_player' => array(
- 'arguments' => array('node' => NULL),
- ),
- 'video_teaser' => array(
- 'arguments' => array('node' => NULL,'teaser' => NULL,'page' => NULL),
- ),
- 'video_view' => array(
- 'arguments' => array('node' => NULL,'teaser' => NULL,'page' => NULL),
- ),
- );
-}
+ @rmdir($dir);
+} \ No newline at end of file