From 23348d9bc9a704d4a1a58c9580d03737ee52f8a3 Mon Sep 17 00:00:00 2001 From: Heshan Wanigasooriya Date: Sat, 25 Apr 2009 00:30:48 +0000 Subject: Cmmiting Drupal 6 core capability version --- FILE_TYPES.txt | 4 +- README.txt | 8 +- TODO.txt | 4 +- hooks.php | 31 +- video.css | 10 +- video.info | 2 +- video.install | 290 +++++++--- video.js | 3 + video.module | 1607 +++++++++++++++++++++++-------------------------------- views_video.inc | 42 +- 10 files changed, 962 insertions(+), 1039 deletions(-) diff --git a/FILE_TYPES.txt b/FILE_TYPES.txt index be0d2fb..fbfc94f 100644 --- a/FILE_TYPES.txt +++ b/FILE_TYPES.txt @@ -5,7 +5,7 @@ FILE TYPE INFORMATIONS Video.module for Drupal 4.7 supports multiple video formats. -.mov, .wmv, .rm, .3gp, .mp4, .swf, .dir, .dcr +.mov, .wmv, .asf, .rm, .3gp, .mp4, .swf, .dir, .dcr These files type are supported out the box. To play these file types you need to enter in the path to the file. If your video is on the same webserver as drupal, you can use a path relative @@ -42,7 +42,7 @@ Google Video support Then set the Flash player file name to use on the Flash settings in video module configuration page. .ogg - Ogg Theora videos, video.module uses the java applet cortado to display Ogg Theora files, + Ogg Theora videos, video.module uses the java applet cortado to display Ogg Theora files, you can find the latest version of cortado at http://www.flumotion.net//jar/cortado/ get http://www.flumotion.net//jar/cortado/cortado-ovt-stripped-0.2.0.jar and put it into your Drupal folder as cortado.jar diff --git a/README.txt b/README.txt index 8ee2642..f679ef2 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ VIDEO MODULE ----- This module add the possibility to create -video nodes wich are containers to embed +video nodes which are containers to embed videos into drupal pages. For installation and upgrade instructions see INSTALL.txt @@ -20,4 +20,8 @@ Please submit bugs/features/support requests at: Maintainers: Fabio Varesano: fvaresano at yahoo dot it David Norman: deekayen (at) deekayen [dot-} net - Luke Last: luke [at] lukelast dot com \ No newline at end of file + Luke Last: luke [at] lukelast dot com + Vernon Mauery: vernon at mauery dot com + +Porting to Drupal 6 +Heshan Wanigasooriya :heshan@heidisoft.com,heshanmw@gmail.com diff --git a/TODO.txt b/TODO.txt index d13c350..ec7c780 100644 --- a/TODO.txt +++ b/TODO.txt @@ -8,6 +8,4 @@ TODO LIST - Thumbnails - http://drupal.org/node/31784 - Work on XHTML compliance - http://drupal.org/node/30953 - Director/Flash (.dcr/.dir and .swf) - http://drupal.org/node/30100 -- Your suggestions here - - -http://drupal.org/node/add/project_issue/video \ No newline at end of file +- Your suggestions here - http://drupal.org/node/add/project_issue/video diff --git a/hooks.php b/hooks.php index a534c1d..af33b82 100644 --- a/hooks.php +++ b/hooks.php @@ -1,10 +1,8 @@ - + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo */ +//TODO: When we will release a stable version we have to document all the APIs +// the video module have + + +function hook_v_info() {}; + + +/** + * This hook is called by the video_image plugins once + * TODO: better documentation +*/ +function hook_v_autothumbnail($node) { + ; +} + /** The hook_v_get_params is used by plugins to write an html param inside inside video generated object tag during the play. @@ -33,3 +49,6 @@ inside video generated object tag during the play. function hook_v_get_params(&$node) { return array('flashVars' => 'autostart=true&url=false'); } + + + diff --git a/video.css b/video.css index 487151a..3036c08 100644 --- a/video.css +++ b/video.css @@ -1,10 +1,11 @@ -/* $Id$ /* - /** * @file * Contains css theming rules for video module and plugins * * @author Fabio Varesano + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo */ .video_image_teaser { @@ -19,3 +20,8 @@ br.video_image_clear { .video_image_view { /* inser here rules for node page image */ } + +.video-ffmpeg-helper-inprogress { + border: 1px solid red; + padding: .5em; +} diff --git a/video.info b/video.info index ebacdf4..72f2934 100644 --- a/video.info +++ b/video.info @@ -1,4 +1,4 @@ -; $Id$ name = Video description = Allows video nodes. package = "Video" +core = 6.x \ No newline at end of file diff --git a/video.install b/video.install index a8e4c6f..b640bc9 100644 --- a/video.install +++ b/video.install @@ -1,5 +1,173 @@ t('TODO'), + 'fields' => array( + 'vid' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'nid' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'vtype' => array( + 'description' => t('TODO'), + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), + 'vidfile' => array( + 'description' => t('TODO'), + 'type' => 'text', + 'not null' => TRUE, + 'default' => '', + ), + 'videox' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'size' => 'small', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'videoy' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'size' => 'small', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'size' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'size' => 'big', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), + 'download_counter' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'play_counter' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'video_bitrate' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), + 'audio_bitrate' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), + 'audio_sampling_rate' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), + 'audio_channels' => array( + 'description' => t('TODO'), + 'type' => 'unknown', + 'not null' => FALSE, + ), + 'playtime_seconds' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => FALSE, + ), + 'download_folder' => array( + 'description' => t('TODO'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'disable_multidownload' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'use_play_folder' => array( + 'description' => t('TODO'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'custom_field_1' => array( + 'description' => t('TODO'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'custom_field_2' => array( + 'description' => t('TODO'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'custom_field_3' => array( + 'description' => t('TODO'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'custom_field_4' => array( + 'description' => t('TODO'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => FALSE, + ), + 'custom_field_5' => array( + 'description' => t('TODO'), + 'type' => 'text', + 'not null' => FALSE, + ), + 'custom_field_6' => array( + 'description' => t('TODO'), + 'type' => 'text', + 'not null' => FALSE, + ), + 'serialized_data' => array( + 'description' => t('TODO'), + 'type' => 'text', + 'not null' => FALSE, + ), + ), + 'primary key' => array('vid'), + ); + + return $schema; +} + +// ex: set syntax=php tabstop=2 expandtab shiftwidth=2 softtabstop=2: function video_install() { switch ($GLOBALS['db_type']) { @@ -8,6 +176,7 @@ function video_install() { db_query("CREATE TABLE {video} ( vid int(10) unsigned NOT NULL default '0', nid int(10) unsigned NOT NULL default '0', + vtype varchar(32) NOT NULL default '', vidfile text NOT NULL default '', videox smallint(4) unsigned NOT NULL default '0', videoy smallint(4) unsigned NOT NULL default '0', @@ -36,6 +205,7 @@ function video_install() { db_query("CREATE TABLE {video} ( vid integer NOT NULL default '0', nid integer NOT NULL default '0', + vtype varchar(32) NOT NULL default '', vidfile text NOT NULL default '', videox smallint NOT NULL default '0', videoy smallint NOT NULL default '0', @@ -61,6 +231,12 @@ function video_install() { );"); } + + // default values for some variables use for resolution stuff + variable_set('video_resolution_1_name', '4:3 - Television'); + variable_set('video_resolution_1_value', '400x300'); + variable_set('video_resolution_2_name', '16:9 - Widescreen'); + variable_set('video_resolution_2_value', '400x226'); } /** @@ -68,91 +244,63 @@ function video_install() { * * @return array */ -function video_update_1() { - $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("ALTER TABLE {video} CHANGE videox videox smallint(4) NOT NULL default '0'"); - $ret[] = update_sql("ALTER TABLE {video} CHANGE videoy videoy smallint(4) NOT NULL default '0'"); - $ret[] = update_sql('ALTER TABLE {video} CHANGE size size bigint(13) default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD video_bitrate int(11) default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD audio_bitrate int(11) default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD audio_sampling_rate int(11) default NULL'); - $ret[] = update_sql("ALTER TABLE {video} ADD audio_channels enum('','stereo','mono') default NULL"); - $ret[] = update_sql('ALTER TABLE {video} ADD playtime_seconds int(11) default NULL'); - } - return $ret; -} - /** * Rename counter, add custom fields, for video.module version 1.9 * * @return array */ -function video_update_2() { - $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("ALTER TABLE {video} CHANGE clicks download_counter int(10) unsigned NOT NULL default '0'"); - $ret[] = update_sql("ALTER TABLE {video} ADD play_counter int(10) unsigned NOT NULL default '0' AFTER download_counter"); - $ret[] = update_sql("ALTER TABLE {video} CHANGE audio_channels audio_channels enum('','5.1','stereo','mono') default NULL"); - $ret[] = update_sql('ALTER TABLE {video} ADD download_folder varchar(255) NULL default NULL'); - $ret[] = update_sql("ALTER TABLE {video} ADD disable_multidownload tinyint(1) NOT NULL default '0'"); - $ret[] = update_sql("ALTER TABLE {video} ADD use_play_folder tinyint(1) NOT NULL default '0'"); - $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_1 varchar(255) NULL default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_2 varchar(255) NULL default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_3 varchar(255) NULL default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_4 varchar(255) NULL default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_5 text NULL default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD custom_field_6 text NULL default NULL'); - } - return $ret; -} - /** * Add unsigned to all int fields * * @return array */ -function video_update_3() { - $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("ALTER TABLE {video} CHANGE videox videox smallint(4) unsigned NOT NULL default '0'"); - $ret[] = update_sql("ALTER TABLE {video} CHANGE videoy videoy smallint(4) unsigned NOT NULL default '0'"); - $ret[] = update_sql('ALTER TABLE {video} CHANGE size size bigint(13) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE video_bitrate video_bitrate int(11) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_bitrate audio_bitrate int(11) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_sampling_rate audio_sampling_rate int(11) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE playtime_seconds playtime_seconds int(11) unsigned default NULL'); - $ret[] = update_sql("ALTER TABLE {video} CHANGE disable_multidownload disable_multidownload tinyint(1) unsigned NOT NULL default '0'"); - $ret[] = update_sql("ALTER TABLE {video} CHANGE use_play_folder use_play_folder tinyint(1) unsigned NOT NULL default '0'"); - } - return $ret; -} - /** * Start of Drupal 4.7 support in video.module issue #40005, version 1.25 * updated revisions, db schema, forms api, form validation, permissions, added .swf and image support * * @return array */ -function video_update_4() { - $ret = array(); - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("ALTER TABLE {video} ADD vid int(10) unsigned NOT NULL default '0' FIRST"); - $ret[] = update_sql('UPDATE {video} SET vid = nid'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE video_bitrate video_bitrate int(10) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_bitrate audio_bitrate int(10) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE audio_sampling_rate audio_sampling_rate int(10) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} CHANGE playtime_seconds playtime_seconds int(10) unsigned default NULL'); - $ret[] = update_sql('ALTER TABLE {video} ADD serialized_data text NULL default NULL'); - $ret[] = update_sql('ALTER TABLE {video} DROP PRIMARY KEY, ADD PRIMARY KEY ( `vid` )'); +/** + * Add the vtype field for video module subtypes + * + * @return array + */ +function _video_update_6_get_vtype($node) { + $file_type = ''; + $vidfile = $node->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 = 'google'; + } + else if(db_result(db_query("SELECT count(fid) FROM {files} WHERE nid=%d", $node->nid)) > 0) { + $file_type = 'upload'; } - return $ret; + else if ($vidfile != '' ) { // enable absolute urls and relative paths + $file_type = 'url'; + } + else { + drupal_set_message(t('Could not determine video type of node %nid', array('%nid' => $node->nid)), 'error'); + } + return $file_type; } + +/** + * Set vtype for all the videos +*/ +/** + * Set default values of resolutions +*/ +/** + * Video_upload changes from relying on files table to locate + * video file to saving it in serialized_data as video_fid +*/ +/** + * Update the vidfile for youtube videos so they will work again + */ +/** + * Update vidfile for google videos -- they play, but they are not editable + * in the current form because validation fails upon submit + */ diff --git a/video.js b/video.js index 00ab0f3..7022907 100644 --- a/video.js +++ b/video.js @@ -8,6 +8,9 @@ * file for more informations. * * @author Fabio Varesano + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo */ //We do this code only on Internet Explorer. diff --git a/video.module b/video.module index 8b2fd01..8276d82 100644 --- a/video.module +++ b/video.module @@ -1,15 +1,20 @@ - * @author David Norman - * @author Luke Last + * @contributor Vernon Mauery + * porting to Drupal 6 + * @author Heshan Wanigasooriya + * @todo */ +/** + * Let's include views logic if views module is enabled +*/ +if (module_exists('views')) { + module_load_include('inc', 'video', 'views_video'); +} /******************************************************************** * General Hooks @@ -24,45 +29,6 @@ * @return * string of help information */ -function video_help($section = 'admin/help#video') { - switch ($section) { - case 'admin/help#video': - $output = '

' . t('The video module (4.7 or with backport patch to 4.6) allows users to post video content to their site. The emergence of portable phones with video capture capabilities has made video capture ubiquitous. Video logging, or vlogging as a medium for personal video broadcasting has proven to be popular and is following the blogging, and podcasting phenomena\'s. Videos are useful for creative collaboration among community members. If community members can not meet in person videos of meetings are valuable for enhancing the interaction between community members.', array('%elink-en-wikipedia-org' => 'http://en.wikipedia.org/wiki/Vlog')) . '

'; - $output .= '

' . t('The video module can be administered to flash player settings. There are a number of page and menu links which can be added to play and download video content on the site. Other configurable options include play and download counters. Multi-file downloads can also be configured under settings. There are also up to six custom fields and a group name which can be added.') . '

'; - $output .= t('

You can:

- -', array('%admin-block' => url('admin/settings/block'), '%node-add-video' => url('node/add/video'), '%admin-settings-video' => url('admin/content/video'))); - $output .= '

'. t('For more information please read the configuration and customization handbook Video page.', array('%video' => 'http://www.drupal.org/handbook/modules/video/')) .'

'; - return $output; - case 'admin/settings/modules#description': - return t('Allows video nodes.'); - case 'node/add#video': - return t('Allows you to insert videos as nodes.'); - case 'video/help': - $help = ''; - $help .= '

' . t('Video File Field') . '

'; - $help .= '

' . t('This is the field where you enter the video file information. The Video module currently supports these file types:') . '

'; - $help .= '
  • ' . t('.mov, .wmv, .rm, .flv, .swf, .dir, .dcr') . '
    • ' . t('To play these file types you need to enter in the path to the file. If your video is on the same webserver as drupal, you can use a path relative to the drupal directory, like "downloads/video.mov". If your video is on another server you can enter the URI to the video like "http://www.example.com/videos/my-video.mov".') . '

  • '; - $help .= '
  • ' . t('YouTube.com support') . '
    • ' . t('You can host videos on youtube.com and put them on your site. To do this, after you upload the video on youtube.com enter the video ID into the "Video File" field. If the URI youtube.com gives you for the video is "http://www.youtube.com/watch.php?v=XM4QYXPf-s8" you would enter "XM4QYXPf-s8".') . '

  • '; - $help .= '
  • ' . t('Google Video support') . '
    • ' . t('You can host videos on video.google.com and put them on your site. - To do this, after you upload the video on Google video enter get the - the embed code. In this code you will find an attribute like - src="http://video.google.com/googleplayer.swf?docId=-1591729516923874694" . - You will need the -1591729516923874694 like number just after docId= . - Then use "google:-1591729516923874694" as video file value.') . '
'; - $help .= '

' . t('Multi-file Dowload Help') . '

'; - $help .= '

' . t('If enabled, this group holds all the settings for multi-file downloads. Multi-file downloads allows you to have a list of any number of files on the download page. These files are usually scanned from a folder. This allows the listing of multiple sizes and video types for visitors to choose from, you can even zip the files up.') . '

'; - $help .= '
  • ' . t('Disable multi-file downloads') . '
    • ' . t('This checkbox will disable multi-file downloads for this video. This means the download tab and link will send visitors straight to download the same video as is set to play. Use this option if you only have one version of your video.') . '

  • '; - $help .= '
  • ' . t('Multi-file download folder') . '
    • ' . t('Allows you to specify a folder on the local server containing the files you wish to show up on the download tab. This folder should be relative to the drupal root directory, so if the absolute path is "C:\inetpub\drupal\videos\projectfolder\" or "/usr/htdocs/drupal/videos/projectfolder/" then you would enter "videos/projectfolder/".') . '

  • '; - $help .= '
  • ' . t('Show files in "play" folder') . '
    • ' . t('This option will list all the files in the same folder is the "play" file listed in the "Video File" field above. You can use this option in addition to the download folder to list the videos in both folders.') . '
'; - return $help; - } -} - /** * Implementation of hook_menu(). * @@ -72,63 +38,55 @@ function video_help($section = 'admin/help#video') { * @return * array of menu information */ -function video_menu($may_cache) { +function video_menu() { + global $user; + $items = array(); + $may_cache=true; if ($may_cache) { - $items[] = array( - 'path' => 'video', - 'title' => t('videos'), - 'callback' => 'video_page', - 'access' => user_access('access video'), + $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[] = array( - 'path' => 'video/feed', - 'title' => t('videos feed'), - 'callback' => 'video_feed', - 'access' => user_access('access video'), + + $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[] = array( - 'path' => 'node/add/video', - 'title' => t('Video'), - 'access' => user_access('create video')); - $items[] = array( - 'path' => 'admin/content/video', - 'title' => t('Video settings'), - 'description' => t('Configure different aspects of the video module and its plugins'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('video_settings_form'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); + + + $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, + ); } else { //If $may_cache is false. if (arg(0) == 'node' && is_numeric(arg(1))) { if ($node = node_load(arg(1)) and $node->type == 'video') { - if (variable_get('video_displayplaymenutab', 1) == 1) { - $menu_type = MENU_LOCAL_TASK; - } - else { - $menu_type = MENU_CALLBACK; - } - $items[] = array('path' => 'node/'. arg(1) .'/play', - 'title' => t('play'), - 'callback' => 'video_play', - 'access' => user_access('play video'), - 'weight' => 3, - 'type' => $menu_type); - - //If the video is of type youtube and multi-file downloads aren't turned on don't show the download tab. - if (_video_get_filetype($node->vidfile) != 'youtube' and _video_get_filetype($node->vidfile) != 'googlevideo') { - if (variable_get('video_displayplaymenutab', 1) == 1) { - $menu_type = MENU_LOCAL_TASK; - } - else { - $menu_type = MENU_CALLBACK; - } - $items[] = array('path' => 'node/'.arg(1).'/download', - 'title' => t('download'), - 'callback' => 'video_download', - 'access' => user_access('access 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); } @@ -139,17 +97,6 @@ function video_menu($may_cache) { } -/** - * Implementation of hook_init() - * Currently just does a check for whether the views module exists and, - * if it does loads the video views module. - */ -function video_init() { - if (module_exists('views')) { - include(drupal_get_path('module', 'video') .'/views_video.inc'); - } -} - /** * Internal Drupal links hook * @@ -164,52 +111,28 @@ function video_init() { */ 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_get_filetype($node->vidfile) == 'youtube' || _video_get_filetype($node->vidfile) == 'googlevideo') && $node->disable_multidownload == 1) { + if (!video_support_download($node) || $node->disable_multidownload == 1) { $display_download_link = 0; } else { $display_download_link = variable_get('video_displaydownloadlink', 1); } - if (variable_get('video_displayplaylink', 1)) { - if (user_access('play video')) { - $link['video_play'] = array( - 'title' => t('play'), - 'href' => "node/$node->nid/play", - 'attributes' => array( - 'class' => 'outgoing', - 'title' => t('play %link', array('%link' => $node->title)), - ), - ); - } - else { - $text .= l(t('login'), "user/login", array('class' => 'outgoing', 'title' => t('login to your account'))); - $text .= ' ' . t('or') . ' '; - $text .= l(t('register'), "user/register", array('class' => 'outgoing', 'title' => t('create a new account'))); - $text .= t(' to play video'); - - $link['video_play'] = array( - 'title' => $text, - 'html' => TRUE, - ); - - } - } 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)), + 'title' => t('download @link', array('@link' => $node->title)), ), ); } - if (variable_get('video_displayplaytime', 1)) { + 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), ); @@ -224,7 +147,7 @@ function video_link($type, $node = NULL) { 'title' => format_plural($node->play_counter, '1 play', '@count plays'), ); } - if (variable_get('video_downloadcounter', 1) && user_access('view download counter')) { + 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'), ); @@ -271,7 +194,7 @@ 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', NULL, NULL, TRUE) + 'link' => url('video', array('absolute' => TRUE)) ); $result = db_query('SELECT n.nid FROM {node} n WHERE n.type = "video" AND n.status = 1 ORDER BY n.created DESC'); @@ -285,7 +208,7 @@ function video_feed() { * 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'); + $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; } @@ -296,90 +219,168 @@ function video_perm() { * string of form content or error message */ function video_settings_form() { - global $base_url; - - //Must have "administer site configuration" and "administer video" privilages. - if (!user_access('administer video')) { - drupal_access_denied(); - } - $options = array(1 => 'Yes', 0 => 'No'); + global $base_url; + $form = array(); - $form['tabs'] = array('#type' => 'fieldset', '#title' => t('Tab menu options'), '#collapsible' => TRUE, '#collapsed' => TRUE); - $form['tabs']['video_playinbody'] = array( - '#type' => 'radios', - '#title' => t('Play in node'), - '#options' => $options, - '#default_value' => variable_get('video_playinbody', 1), - '#description' => t('Toggle display of video in the body of the node.')); - $form['tabs']['video_displayplaymenutab'] = array( - '#type' => 'radios', - '#title' => t('Display play menu tab'), - '#options' => $options, - '#default_value' => variable_get('video_displayplaymenutab', 1), - '#description' => t('Toggle display of menu link to play video from the node page. If you have chosen to display the video in the body of the node, then this is redundant and must be set to "No."')); - $form['tabs']['video_displaydownloadmenutab'] = array( - '#type' => 'radios', + + $form['menu'] = array( + '#type' => 'fieldset', + '#title' => t('General behavior'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $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'), - '#options' => $options, '#default_value' => variable_get('video_displaydownloadmenutab', 1), - '#description' => t('Toggle display of menu link to download video from the node page.')); - - $form['flash'] = array('#type' => 'fieldset', '#title' => t('Flash settings'), '#collapsible' => TRUE, '#collapsed' => TRUE); - $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.')); - $form['ogg'] = array('#type' => 'fieldset', '#title' => t('Ogg Theora settings'), '#collapsible' => TRUE, '#collapsed' => TRUE); - $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.')); - $form['menu'] = array('#type' => 'fieldset', '#title' => t('Items to display in the node menu'), '#weight' => -5, '#collapsible' => TRUE, '#collapsed' => TRUE); - $form['menu']['video_displayplaylink'] = array( - '#type' => 'radios', - '#title' => t('Display play link'), - '#options' => $options, - '#default_value' => variable_get('video_displayplaylink', 1), - '#description' => t('Toggle display of "play" link (below the node content in most themes). If you choose to display the video in the body of the node, then this is redundant and must be set to "No."')); + '#description' => t('Toggle display of menu tab to download video from the node page.') + ); $form['menu']['video_displaydownloadlink'] = array( - '#type' => 'radios', + '#type' => 'checkbox', '#title' => t('Display download link'), - '#options' => $options, '#default_value' => variable_get('video_displaydownloadlink', 1), - '#description' => t('Toggle display of "download" link (below the node content in most themes).')); + '#description' => t('Toggle display of "download" link (below the node content in most themes).') + ); $form['menu']['video_displayplaytime'] = array( - '#type' => 'radios', + '#type' => 'checkbox', '#title' => t('Display playtime'), - '#options' => $options, '#default_value' => variable_get('video_displayplaytime', 1), - '#description' => t('Toggle the display of the playtime for a video.')); + '#description' => t('Toggle the display of the playtime for a video.') + ); $form['menu']['video_displayfilesize'] = array( - '#type' => 'radios', + '#type' => 'checkbox', '#title' => t('Display filesize'), - '#options' => $options, '#default_value' => variable_get('video_displayfilesize', 1), - '#description' => t('Toggle the display of the filesize for a video.')); - - $form['counters'] = array('#type' => 'fieldset', '#title' => t('Statistics counters'), '#description' => t('To allow users to view counters visit: ') . l(t('access control'), 'admin/access'), '#collapsible' => TRUE, '#collapsed' => TRUE); + '#description' => t('Toggle the display of the filesize for a video.') + ); + + $form['resolutions'] = array( + '#type' => 'fieldset', + '#title' => t('Video resolutions'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + + $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') + ); + + $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/access'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); $form['counters']['video_playcounter'] = array( - '#type' => 'radios', + '#type' => 'checkbox', '#title' => t('Count play hits'), - '#options' => $options, '#default_value' => variable_get('video_playcounter', 1), - '#description' => t('Counts a hit everytime someone views the play page.')); + '#description' => t('Counts a hit everytime someone views the play page.') + ); $form['counters']['video_downloadcounter'] = array( - '#type' => 'radios', + '#type' => 'checkbox', '#title' => t('Count downloads'), - '#options' => $options, '#default_value' => variable_get('video_downloadcounter', 1), - '#description' => t('Counts a hit everytime someone downloads a video.')); + '#description' => t('Counts a hit everytime someone downloads a video.') + ); + + $form['flash'] = array( + '#type' => 'fieldset', + '#title' => t('Flash settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $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.') + ); + $form['ogg'] = array( + '#type' => 'fieldset', + '#title' => t('Ogg Theora settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $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.') + ); 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 ******************************************************************************/ @@ -402,17 +403,15 @@ function video_node_info() { /** * access hook */ -function video_access($op, $node) { - global $user; +function video_access($op, $node, $account) { - switch($op) { - case 'view': - return $node->status; // see book.module for reference - case 'create': - return user_access('create video'); - case 'update': - case 'delete': - return user_access('edit own video') && ($user->uid == $node->uid); + + if ($op == 'create') { + return user_access('create video', $account); + } + + if ($op == 'update' || $op == 'delete') { + return (user_access('edit own video', $account) && ($account->uid == $node->uid)) || user_access('edit all video nodes', $account); } } @@ -424,23 +423,174 @@ 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']; - $media['fileSize'] = $attributes['length']; - $media['type'] = $attributes['type']; - return array(array('key' => 'enclosure', 'attributes' => $attributes), array('key' => 'media', 'value' => '', 'attributes' => $media)); + 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; + } } + return array($enclosure, $mrss); + case 'revision delete': db_query('DELETE FROM {video} WHERE vid = %d', $node->vid); break; } } + +/** + * Create video submission page. Let the user select the actived video types + * or display the video form for the selected video type +*/ +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(); + //print_r($vtypes); + // exit; + 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); + //print_r($node); + //exit; + $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); + //print_r($output); + //exit; + 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(); + } + //$output ="
Prefs :test
";; + //print_r($output); + //exit; + 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 = '
'. /* TODO + Please manually fix the parameters on the l() or url() function on the next line. + Typically, this was not changed because of a function call inside an array call like + array('title' => t('View user profile.')).*/ +l($infos['#name'], "node/add/video/$vtype", array('title' => t('Add a !s.', array('!s' => $infos['#name'])))) .'
'; + $out .= '
'. $infos['#description'] .'
'; + $items[$vtype] = $out; + } + // let's order by type name + ksort($items); + return t('Choose from the following available video types:') .'
'. implode('', $items) .'
'; + } +} + + +/** + * 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'); + } + 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 +*/ +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. * @@ -452,130 +602,145 @@ function video_nodeapi($node, $op, $arg) { */ function video_form($node) { //We must unserialize the array for display in the forms. - $node->serial_data = unserialize($node->serialized_data); + if($node->serial_data) { + $node->serial_data = unserialize($node->serialized_data); + } $form = array(); - $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), - '#size' => 60, '#maxlength' => 128, '#required' => TRUE, - '#default_value' => $node->title, '#weight' => -20); - $form['body_filter']['body'] = array('#type' => 'textarea', - '#title' => t('Body'), '#default_value' => $node->body, - '#required' => FALSE, '#rows' => 10, '#weight' => -15); - $form['body_filter']['filter'] = filter_form($node->format); - $form['log'] = array('#type' => 'fieldset', '#title' => t('Log message'), - '#collapsible' => TRUE, '#collapsed' => TRUE); - $form['log']['message'] = array( - '#type' => 'textarea', '#default_value' => $node->log, '#rows' => 5, - '#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.') - ); + + // default node stuff + $type = node_get_types('type', $node); - $form['video'] = array('#type' => 'fieldset', '#title' => t('Video File'), '#weight' => -19); - $form['video']['vidfile'] = array( + $form['title'] = array( '#type' => 'textfield', - '#title' => t('Video File'), - '#default_value' => $node->vidfile, - '#maxlength' => 700, + '#title' => check_plain($type->title_label), + '#size' => 60, + '#maxlength' => 128, '#required' => TRUE, - '#weight' => -20, - '#description' => t('Put here the video file path. You can use either relative to the drupal root directory (something/video.mov) or absolute (http://www.example.com/videos/videos.mov). Windows Media currently requires a fully qualified URL to function. Flash movies may not play with spaces in the path or filename. To add youtube.com videos enter the video ID. If your video was at (http://www.youtube.com/watch.php?v=aBM4QYXPf-s) you would enter (aBM4QYXPf-s). To add Google videos you will need the docId values available on the embed code google provide with "google:" as heading. ') . l(t('More information.'), 'video/help', NULL, NULL, 'videofile')); - $form['video']['videox'] = array( - '#type' => 'textfield', - '#title' => t('Video Size Width (x)'), - '#required' => TRUE, - '#length' => 4, - '#maxlength' => 4, - '#default_value' => $node->videox, - '#description' => t('Horizontal video pixel size.')); - $form['video']['videoy'] = array( - '#type' => 'textfield', - '#title' => t('Video Size Height (y)'), - '#required' => TRUE, - '#length' => 4, - '#maxlength' => 4, - '#default_value' => $node->videoy, - '#description' => t('Vertical video pixel size.')); + '#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 + ); - $form['video']['filesize'] = array('#type' => 'fieldset', '#title' => t('Filesize')); - $form['video']['filesize']['size'] = array( - '#type' => 'textfield', - '#title' => t('Size'), - '#required' => FALSE, - '#length' => 12, - '#maxlength' => 12, - '#default_value' => $node->size, - '#description' => t('If the video is on the local server the size will be set automatically. Otherwise enter a value. Entering 0 will turn the display off. Must be less than 2GB.')); - $form['video']['filesize']['size_format'] = array( - '#type' => 'select', - '#title' => t('size units'), - '#options' => array('B' => t('bytes'), 'Kb' => t('Kilobits'), 'KB' => t('KiloBytes'), 'Mb' => t('Megabits'), 'MB' => t('MegaBytes'), 'Gb' => t('Gigabits'), 'GB' => t('GigaBytes')), - '#default_value' => 'B'); - - $form['video']['playtime'] = array('#type' => 'fieldset', '#title' => t('Playtime'), '#description' => t('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'), - '#length' => 11, - '#maxlength' => 11, - '#default_value' => $playtime['hours'], - '#description' => t('Integer of hours.')); - $form['video']['playtime']['playtime_minutes'] = array( - '#type' => 'textfield', - '#title' => t('Minutes'), - '#length' => 11, - '#maxlength' => 11, - '#default_value' => $playtime['minutes'], - '#description' => t('Integer of minutes.')); - $form['video']['playtime']['playtime_seconds'] = array( - '#type' => 'textfield', - '#title' => t('Seconds'), - '#required' => TRUE, - '#length' => 11, - '#maxlength' => 11, - '#default_value' => $playtime['seconds'], - '#description' => t('Integer of seconds.')); + $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.
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, + ); + } + + 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.
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'], + ); + } + + // Get the video-type-specific bits. + $form = module_invoke('video_' . $node->vtype, 'v_form', $node, $form); return $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 - * + * Implementation of hook_validate */ -function video_settings_form_validate($form_id, $form_values){ - // If the user has selected to play videos in the body - // and also has the play tab or the play link on - // report back that this is redundant and throw an error. - if($form_values['video_playinbody'] == 1){ - if($form_values['video_displayplaylink'] == 1){ - form_set_error('video_displayplaylink', t('You cannot have the play link turned on if you are playing videos in the node body.')); - } - if($form_values['video_displayplaymenutab'] == 1){ - form_set_error('video_displayplaymenutab', t('You cannot have the play tab turned on if you are playing videos in the node body.')); +function video_validate($node) { + + 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", '') == '') { + } } - if($form_values['video_playinbody'] == 0 && $form_values['video_displayplaylink'] == 0 && $form_values['video_displayplaymenutab'] == 0){ - drupal_set_message(t('You have NOT selected a method to display videos. Please choose at least one play option below. If you only want users to download videos, you can ignore this message, but usually you will want at least one option turned on. The current possible options are: Display play link, Display in node, and Display play menu tab.')); - } + + module_invoke('video_'.$node->vtype, 'v_validate', $node); + + } + /** * Implementation of hook submit */ function video_submit(&$node) { - _video_db_preprocess($node); //Make changes to data before updating DB. + + if(video_support_autoresolution($node)) { // vtype support autoresolution getting + $xy = module_invoke('video_' . $form_state['values']['vtype'], 'v_auto_resolution', $node); + if ($xy) { + $form_state['values']['videox'] = $xy[0]; + $form_state['values']['videoy'] = $xy[1]; + } + } + else { + // we should have a good value (checked by Form API) + if($form_state['values']['vresolution']) { + $res = explode('x', variable_get('video_resolution_' . $form_state['values']['vresolution'] . '_value', '')); + $form_state['values']['videox'] = $res[0]; + $form_state['values']['videoy'] = $res[1]; + } + } + + if(video_support_autoplaytime($node)) { // vtype support auto playtime + $form_state['values']['playtime_seconds'] = module_invoke('video_' . $form_state['values']['vtype'], 'v_auto_playtime', $node); + } + else { // vtype does not support auto_playtime + $form_state['values']['playtime_seconds'] += ($form_state['values']['playtime_hours'] * 3600) + ($form_state['values']['playtime_minutes'] * 60); + } + } /** - * Hook: Create video record in video table + * Implementation of hook_insert. + * Create video record in the video table * * @return * TRUE on success, FALSE on error @@ -584,8 +749,8 @@ function video_insert($node) { $node->serialized_data = serialize($node->serial_data); //Serialize the data for insertion into the database. - return db_query("INSERT INTO {video} (vid, nid, vidfile, size, videox, videoy, video_bitrate, audio_bitrate, audio_sampling_rate, audio_channels, playtime_seconds, disable_multidownload, download_folder, use_play_folder, custom_field_1, custom_field_2, custom_field_3, custom_field_4, custom_field_5, custom_field_6, serialized_data) VALUES (%d, %d, '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", - $node->vid, $node->nid, $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->custom_field_1, $node->custom_field_2, $node->custom_field_3, $node->custom_field_4, $node->custom_field_5, $node->custom_field_6, $node->serialized_data); + 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, custom_field_1, custom_field_2, custom_field_3, custom_field_4, custom_field_5, custom_field_6, serialized_data) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%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->custom_field_1, $node->custom_field_2, $node->custom_field_3, $node->custom_field_4, $node->custom_field_5, $node->custom_field_6, $node->serialized_data); } @@ -600,7 +765,6 @@ function video_update($node) { return video_insert($node); } else { - $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, custom_field_1='%s', custom_field_2='%s', custom_field_3='%s', custom_field_4='%s', custom_field_5='%s', custom_field_6='%s', serialized_data='%s' WHERE vid = %d", @@ -608,72 +772,16 @@ function video_update($node) { } } -/** - * This function makes changes to node data before it is put into the database. - * - * @param $node - * object a reference to a $node object to modify. - * - * @return - * nothing - */ -function _video_db_preprocess(&$node) { - - //Calculate the time in seconds. - $node->playtime_seconds += ($node->playtime_hours * 3600) + ($node->playtime_minutes * 60); - - //If video type is youtube or googlevideo, don't attempt to get filesize (googlevideo filenames are too long to stat) - if (_video_get_filetype($node->vidfile) != 'youtube' and _video_get_filetype($node->vidfile) != 'googlevideo') { - //If file is on the local server get size, otherwise get size from function. - $path = getcwd() . '/' . $node->vidfile; //Local path to video file. - $path_for_size = $path; // file_check_file will make $path unusable for filesize() - if (file_check_path($path) && is_file($path_for_size)) { //If file exists locally set size. - $node->size = filesize($path_for_size); - } - else { - $node->size = _video_size2bytes($node); //Change the size to be correctly shown in bytes. - } - } -} + /** - * Hook - * - * @param $node - * object + * Implementation of hook_delete */ function video_delete($node) { db_query("DELETE FROM {video} WHERE nid = %d", $node->nid); } -/** - * Hook to see if every video field has been filled - * and contains a valid value. - * - * @param $node - * object - */ -function video_validate($node) { - if (_video_get_filetype($node->vidfile) != 'youtube' and _video_get_filetype($node->vidfile) != 'googlevideo') { //If video is of type youtube don't check size. - if (isset($node->videox) && $node->videox <= 0) { - form_set_error('videox', t('You have to insert a valid horizontal pixel size for this video')); - } - if (isset($node->videoy) && $node->videoy <= 0) { - form_set_error('videoy', t('You have to insert a valid vertical pixel size for this video')); - } - } - //Make sure file size is valid. - $path = getcwd() . '/' . $node->vidfile; //Local path to video file. - if ((!isset($node->size) || !is_numeric($node->size) || $node->size < 0) && !$_SESSION['video_upload_file']) { //If the file is not local or not a valid number then set error. $_SESSION check needed for video_upload functionality - form_set_error('size', t('You have to insert a valid file size for this video.')); - } - - //Makes sure the total playtime is greater than 0. - $time = $node->playtime_seconds + $node->playtime_minutes + $node->playtime_hours; - if ((isset($node->playtime_minutes) and isset($node->playtime_hours) and isset($node->playtime_seconds)) and $time == 0) { - form_set_error('playtime_seconds', t('Please enter valid playtime information for this video.')); - } -} + /** * Implementation of hook_load() @@ -696,37 +804,33 @@ function video_load($node) { /** * Implementation of hook_view(). - * In addition to standard uses, it adds the 6 custom fields to the body of the node. - * - * @return - * Nothing, modifies $node which is passed by reference. */ function video_view(&$node, $teaser = FALSE, $page = FALSE) { - $node = node_prepare($node, $teaser); //Run the body through the standard filters. - + // include the video css file drupal_add_css(drupal_get_path('module', 'video').'/video.css'); - $node->content['body'] = array('#value' => $node->body); - + + //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 (variable_get('video_playinbody', 0)) { - if (user_access('play video')) { - $output .= theme('video_player', $node); - } - 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'); - } - } - $output .= theme('video_view', $node, $teaser, $page); - $node->content['body'] = array('#value' => $output); + if (user_access('play video')) { + $node->content['video_player'] = array('#value' => theme('video_player', $node), '#weight' => -1); + } + 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); + } } return $node; @@ -862,10 +966,13 @@ function video_block_list($delta = 0) { /** * Redirects to download the video file. */ -function video_download() { - if ($node = node_load(arg(1))) { - if (_video_get_filetype($node->vidfile) != 'youtube' and _video_get_filetype($node->vidfile) != 'googlevideo') { //Make sure the video type is not youtube before downloading. - _video_download_goto($node->vidfile, $node->vid); +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); } 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'); @@ -877,36 +984,30 @@ function video_download() { } } + /** - * Implements play callback function from node menu - */ -function video_play() { - if ($node = node_load(arg(1))) { - drupal_set_title(t('Playing') . ' ' . theme('placeholder', $node->title)); - $output = theme('video_player', $node); - if($output == ''){ - drupal_goto("node/$node->nid"); - } - return $output; - } - else { - drupal_not_found(); - } + * Return true if the video is downloadable, false otherwise +*/ +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; } + /** * 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 + * @param $teaser * Whether we are to generate a "teaser" or summary of the node, rather than display the whole thing. - * @param $page + * @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 */ @@ -917,14 +1018,14 @@ function theme_video_teaser($node, $teaser = FALSE, $page = FALSE) { /** * 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 + * @param $teaser * Whether we are to generate a "teaser" or summary of the node, rather than display the whole thing. - * @param $page + * @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 */ @@ -934,504 +1035,27 @@ function theme_video_view($node, $teaser = FALSE, $page = FALSE) { /** * theme function to control which player is presented -* +* * @param $node * node object -* +* * @return * html */ function theme_video_player($node) { // include video.js file for Internet Explorer fixes - theme('video_get_script'); - drupal_set_title(t('Playing') . ' ' . theme('placeholder', $node->title)); + //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. } - - switch (_video_get_filetype($node->vidfile)) { - case 'divx': - return theme('video_play_divx', $node); - case 'mov': - case 'mp4': - case '3gp': - case '3g2': - return theme('video_play_quicktime', $node); - case 'rm': - return theme('video_play_realmedia', $node); - case 'flv': - return theme('video_play_flash', $node); - case 'swf': - return theme('video_play_swf', $node); - case 'dir': - case 'dcr': - return theme('video_play_dcr', $node); - case 'wmv': - return theme('video_play_windowsmedia', $node); - case 'ogg': - return theme('video_play_ogg_theora', $node); - case 'youtube': - return theme('video_play_youtube', $node); - case 'googlevideo': - return theme('video_play_googlevideo', $node); - default: - drupal_set_message('Video type not supported', 'error'); - drupal_goto("node/$node->nid"); - break; - } -} - -/********************************************************************* - * Themeable functions for playing videos. They print a page with a player embedded. - *********************************************************************/ - -/** - * Play videos from in FLV Flash video format - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_flash($node) { - $loader_location = variable_get('video_flvplayerloader', 'FlowPlayer.swf'); - - $url = _video_get_fileurl($node->vidfile); - $file = basename($url); - $base_url = substr($url, 0, strrpos($url, '/')); - - $height = $node->videoy + 24; // add commands height - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= ' - - - ' . "\n" - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; - - $output = _theme_video_format_play($output, t('http://www.macromedia.com/go/getflashplayer'), - t('Link to Macromedia Flash Player Download Page'), - t('Download latest Flash Player')); - return $output; -} - -/** - * Play Flash .swf files. - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_swf($node) { - - $url = _video_get_fileurl($node->vidfile); - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= '' . "\n" - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; - - $output = _theme_video_format_play($output, t('http://www.macromedia.com/go/getflashplayer'), t('Link to Flash player download'), t('Download the latest Flash player')); - return $output; -} - - - -/** - * Play Director .dcr/.dir files. - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ - -function theme_video_play_dcr($node) { - - $url = _video_get_fileurl($node->vidfile); - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - -// params will be passed to both IE or not IE browsers - $output .= '' . "\n" - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; - - $output = _theme_video_format_play($output, t('http://www.macromedia.com/shockwave/download/'), - t('Link to Macromedia Shockwave Player Download Page'), - t('Download latest Shockwave Player')); - return $output; -} - -/** - * Play videos from in DivX format - * - * @see http://developer.apple.com/internet/ieembedprep.html - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_divx($node) { - //Increase the height to accommodate the player controls on the bottom. - $height = $node->videoy + 20; - $url = _video_get_fileurl($node->vidfile); + _video_scale_video($node); + $output = module_invoke('video_'.$node->vtype, 'v_play', $node); - $output = ' - - '. "\n"; - // this will be executed by not Internet Explorer browsers - $output = ' - - '."\n"; - - $output .= ''."\n"; - $output .= ''."\n"; - $output .= ''; - $output = _theme_video_format_play($output,t('http://www.divx.com/divx/webplayer/'), - t('Link to DivX Download Page'), - t('Download latest DivX Web Player')); return $output; } -/** - * Play videos from in Quicktime format - * - * @see http://developer.apple.com/internet/ieembedprep.html - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_quicktime($node) { - //Increase the height to accommodate the player controls on the bottom. - $height = $node->videoy + 16; - - $url = _video_get_fileurl($node->vidfile); - - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= ' - - ' . "\n" - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; // only one
needed becouse only one opening tag has been parsed by browsers - - - /* - $output = ''; - */ - - - $output = _theme_video_format_play($output, t('http://www.apple.com/quicktime/download'), - t('Link to QuickTime Download Page'), - t('Download latest Quicktime Player')); - return $output; -} - -/** - * Play videos from in Realmedia format - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_realmedia($node) { - // Real's embeded player includes the controls - // in the height - $node->videoy += 40; - - $url = _video_get_fileurl($node->vidfile); - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= ' - - - - - - - - - - - - - ' - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; // only one needed becouse only one opening tag has been parsed by browsers - - - $output = _theme_video_format_play($output, t('http://www.real.com/'), - t('Link to Real'), - t('Download latest Realmedia Player')); - return $output; -} - -/** - * Play videos from in WindowsMediaVideo format - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_windowsmedia($node) { - // Windows Media's embeded player includes the controls in the height - $node->videoy += 68; - $url = _video_get_fileurl($node->vidfile); - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= ' - - - - - - ' - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; // only one needed becouse only one opening tag has been parsed by browsers - - - $output = _theme_video_format_play($output, t('http://windowsupdate.microsoft.com/'), - t('Link to Windows Update'), - t('Download latest Windows Media Player')); - return $output; -} - -/** - * Play videos hosted on youtube.com - * Allows users to host videos on youtube.com and then use the video ID to post it in the module. - * In the future it could also use the youtube developer API to get info and comments of the video. - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_youtube($node) { - $width = ($node->videox ? $node->videox : '425'); - $height = ($node->videoy ? $node->videoy : '350'); - - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= '' . "\n" - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; - - - $output = _theme_video_format_play($output, t('http://www.youtube.com/t/help_center'), t('Link to youtube.com'), t('youtube.com')); - return $output; -} - -/** - * Play videos hosted on video.google.com - * Allows users to host videos on video.google.com and then use the video ID to post it in the module. - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_googlevideo($node) { - $width = ($node->videox ? $node->videox : '425'); - $height = ($node->videoy ? $node->videoy : '350'); - // Strip heading "google:" - $videoid = substr($node->vidfile, 7); - - // this will be executed by not Internet Explorer browsers - $output = ' - - ' . "\n"; - - // this will be executed by Internet Explorer - $output .= '' . "\n"; - - // params will be passed to both IE or not IE browsers - $output .= '' . "\n"; - // following a list of params simply copied from old embed tag params. I don't know if this are really needed. - $output .= ' - - - - - - ' - . _video_get_parameters($node) . - '

'. t('Your browser is not able to display this multimedia content.') .'

-
'; - - - $output = _theme_video_format_play($output, t('http://video.google.com/support'), t('Link to video.google.com'), t('video.google.com')); - return $output; -} - -/** - * Play Ogg Theora videos with Cortado Applet - * - * @param $node - * object with node information - * - * @return - * string of content to display - */ -function theme_video_play_ogg_theora($node) { - global $base_url; - $cortado_location = variable_get('video_cortado', $base_url . '/cortado.jar'); - $url = _video_get_fileurl($node->vidfile); - - $width = ($node->videox ? $node->videox : '425'); - $height = ($node->videoy ? $node->videoy : '350'); - - $output = ' - - - - - - - - - - - - - - - - - - - - This browser does not have a Java Plug-in.
- - Get the latest Java Plug-in here. - -
-
- '; - - $output = _theme_video_format_play($output, - t('http://java.com/download/'), t('Link to java.com'), t('Download Java')); - return $output; -} /** * Cut down on redundant link text @@ -1448,11 +1072,11 @@ function theme_video_play_ogg_theora($node) { * @return * string HTML link */ -function _theme_video_format_play($output, $url, $title, $link_text) { +function theme_video_format_play($output, $url, $title, $link_text) { $output = "\n
\n" . $output; $output .= "

\n". t('Problems viewing videos?'); $output .= "
\n"; - $output .= l($link_text, $url, array('title' => $title), NULL, NULL, TRUE); + $output .= l($link_text, $url, array('attributes' => array('title' => $title), 'absolute' => TRUE)); return $output ."\n

\n
\n"; } @@ -1481,8 +1105,8 @@ function theme_video_fields($fields) { /** * Import the video.js script */ -function theme_video_get_script() { - drupal_set_html_head(''); +function theme_video_get_scripvt() { + drupal_add_js(drupal_get_path('module', 'video') . '/video.js'); } /****************************************************************************** @@ -1501,48 +1125,41 @@ function theme_video_get_script() { * string value of file type or boolean FALSE on error */ 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 = substr($vidfile, strrpos($vidfile, '.') + 1); - } - else { - $file_type = FALSE; - } - return $file_type; + //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)); + } + else { + $file_type = FALSE; + } + + return strtolower($file_type); } /** * Forward user directly to the file for downloading * - * @param $input_url - * string should be either a base64 encoded absolute URL, relative URL, or absolute URL. - * - * @param $vid - * integer node version ID of the node to have it's download counter updated. - * - * @return - * Nothing */ -function _video_download_goto($input_url, $vid) { +function _video_download_goto($node) { if (user_access('download video')) { - - $url = _video_get_fileurl($input_url); - + if (variable_get('video_downloadcounter', 1)) { - db_query("UPDATE {video} SET download_counter = download_counter + 1 where vid = %d", $vid); //Increment download counter. + db_query("UPDATE {video} SET download_counter = download_counter + 1 where vid = %d", $node->vid); //Increment download counter. } - header("Location: $url"); //Redirect to the video files URL. + + // 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'); - $node = node_load(array('vid' => $vid)); //Load a node with the $vid so we can get the nid. - drupal_goto("node/$node->nid"); //Use the nid we just loaded to go back to the node page. + drupal_goto("node/".$node->nid); //Use the nid we just loaded to go back to the node page. } } @@ -1585,6 +1202,7 @@ function _video_size2bytes($node) { } } + /** * Convert seconds to hours, minutes, and seconds. * Derived from h:m:s example by Jon Haworth @@ -1623,7 +1241,7 @@ function _video_sec2hms($sec = 0) { */ 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); @@ -1641,12 +1259,19 @@ 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': @@ -1687,3 +1312,105 @@ function _video_get_parameters(&$node) { } 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']; +} + + +/** + * 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']; +} + + +/** + * Get the resolution options array to use on the video form +*/ +function _video_get_resolution_options() { + + $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', ''); + } + $i++; + } + return $options; +} + + +/** + * Get the selected resolution id from the videox and videoy fields +*/ +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++; + } +} + +/** + * Scale a video to match the desired width +*/ +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++; + } + $node->video_scaled_x = $def_width; + $node->video_scaled_y = $height; +} + +/** + * Implementation of hook_theme(). + */ +function video_theme() { + return 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), + ), + ); +} diff --git a/views_video.inc b/views_video.inc index 6bbed4d..26ece40 100644 --- a/views_video.inc +++ b/views_video.inc @@ -1,12 +1,14 @@ +* @todo **/ + function video_views_tables() { $tables['video'] = array( 'name' => 'video', @@ -63,6 +65,20 @@ function video_views_tables() { 'help' => t('This will display the height (y) of the video'), ), ), + 'sorts' => array( + 'play_counter' => array( + 'name' => t('Video: Play count'), + 'help' => t('Sort by the number of video plays.'), + ), + 'download_counter' => array( + 'name' => t('Video: Download count'), + 'help' => t('Sort by the number of video downloads.'), + ), + 'playtime_seconds' => array( + 'name' => t('Video: Length'), + 'help' => t('Sort by the video length.'), + ) + ) ); // Add video_image support only if the video_image module is enabled @@ -75,7 +91,7 @@ function video_views_tables() { 'help' => t('This will display the thumbnail image for the video.'), ); } - + return $tables; } @@ -88,7 +104,7 @@ function video_views_tables() { **/ function video_views_default_views() { $views = array(); - + // recent video node activity view $view = new stdClass(); $view->name = 'video_tracker'; @@ -157,7 +173,7 @@ function video_views_default_views() { $view->exposed_filter = array (); $view->requires = array(node, users, video); $views[$view->name] = $view; - + return $views; } @@ -167,7 +183,7 @@ function video_views_default_views() { **/ function video_views_handler_field_download($fieldinfo, $fielddata, $value, $data) { $nid = $data->nid; - return l(t('Download'), "node/$nid/download", NULL); + return l(t('Download'), "node/$nid/download", array()); } @@ -176,7 +192,7 @@ function video_views_handler_field_download($fieldinfo, $fielddata, $value, $dat **/ function video_views_handler_field_play($fieldinfo, $fielddata, $value, $data) { $nid = $data->nid; - return l(t('Play'), "node/$nid/play", NULL); + return l(t('Play'), "node/$nid/play", array()); } @@ -186,29 +202,31 @@ function video_views_handler_field_play($fieldinfo, $fielddata, $value, $data) { function video_views_handler_field_playtime_seconds($fieldinfo, $fielddata, $value, $data) { $seconds = $value; $hms = _video_sec2hms($seconds); - + // Pad the minutes / seconds with a leading "0", if // necessary if ($hms['hours'] > 0) { $hms['minutes'] = str_pad($hms['minutes'], 2, '0', STR_PAD_LEFT); } $hms['seconds'] = str_pad($hms['seconds'], 2, '0', STR_PAD_LEFT); - + $out = ''; if ($hms['hours'] > 0) { $out .= $hms['hours'].":"; } $out .= $hms['minutes'].":".$hms['seconds']; - + return t($out); } /** -* Handler to to render the preview image associated with a video +* Handler to render the preview image associated with a video **/ function video_views_handler_field_video_image($fieldinfo, $fielddata, $value, $data) { $node = node_load($data->nid); - $output = theme_video_image_body($node); + if($node->iid && $image = node_load($node->iid)) { + $output = theme('video_image_teaser', $image, $node); + } return $output; } -- cgit v1.2.3