aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--types/video_google/video_google.info5
-rw-r--r--types/video_google/video_google.module248
-rw-r--r--types/video_upload/busy.gifbin0 -> 3873 bytes
-rw-r--r--types/video_upload/video_upload.info7
-rw-r--r--types/video_upload/video_upload.js44
-rw-r--r--types/video_upload/video_upload.module908
-rw-r--r--types/video_url/video_url.info5
-rw-r--r--types/video_url/video_url.module102
-rw-r--r--types/video_youtube/video_youtube.info5
-rw-r--r--types/video_youtube/video_youtube.module329
10 files changed, 1653 insertions, 0 deletions
diff --git a/types/video_google/video_google.info b/types/video_google/video_google.info
new file mode 100644
index 0000000..5226b71
--- /dev/null
+++ b/types/video_google/video_google.info
@@ -0,0 +1,5 @@
+name = Google Video
+description = Enable Google video support for Video module.
+dependencies[] = video
+package = "Video"
+core = 6.x \ No newline at end of file
diff --git a/types/video_google/video_google.module b/types/video_google/video_google.module
new file mode 100644
index 0000000..88e17c7
--- /dev/null
+++ b/types/video_google/video_google.module
@@ -0,0 +1,248 @@
+<?php
+/**
+ * @file
+ * Enable Google Video support for video module.
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ * porting to Drupal 6
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
+ * @todo
+ */
+
+
+/**
+ * Implementation of hook_menu
+*/
+function video_google_menu() {
+ $items = array();
+ $maycache=true;
+ if($maycache) {
+ $items['node/add/video/google'] = array(
+ 'title' => 'Google',
+ 'access arguments' => array('create video')
+ );
+ }
+ return $items;
+}
+
+
+/**
+ * Implementation of hook_v_help
+*/
+function video_google_v_help() {
+
+ $help = array();
+ $help['google']['data'] = '<b><a href="http://video.google.com" name="video_google">' . t('Google Video support') . '</a></b>';
+ $help['google']['children'] = array(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 you just have to get the URL of the video.'));
+
+ return $help;
+}
+
+
+/**
+ * Implementation of hook_v_info()
+*/
+function video_google_v_info() {
+ $info['google'] = array(
+ '#name' => 'Google Video',
+ '#description' => t('Post a video available on !link to this website.', array('!link' => l(t('Google Video'), 'http://video.google.com'), NULL, NULL, NULL, TRUE)),
+ '#autothumbable' => true,
+ '#autoresolution' => true,
+ '#autoplaytime' => false, // seems that thereisn't a video lenght field in the google video xml
+ );
+
+ return $info;
+}
+
+
+/**
+ * Implementation of hook_v_form()
+*/
+function video_google_v_form(&$node, &$form) {
+
+ $form['video']['vidfile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Google Video URL'),
+ '#default_value' => $node->vidfile,
+ '#maxlength' => 700,
+ '#required' => TRUE,
+ '#weight' => -20,
+ '#description' => t('Insert the URL to the google video. ') . l(t('More information.'), 'video/help', array('fragment' => 'videofile')));
+
+ return $form;
+}
+
+
+
+/**
+ * implementation of hook_v_validate
+*/
+function video_google_v_validate($node) {
+ // TODO: use youtube REST or XML-RPC to query youtube: check video available and embeddable
+ if(!preg_match("/^http:\/\/video\.google\.com\/videoplay\?docid=/", $node->vidfile)) {
+ form_set_error('vidfile', t('The Google Video URL field must be similar to <em>http://video.google.com/videoplay?docid=1806507480014945777</em>'));
+ }
+ else {
+ //get the video id
+ $id = _video_google_get_id($node->vidfile);
+
+ $response = _video_apiclient_google_request($id);
+ if(count($response) == 0) { // google video wasn't able to find the video
+ form_set_error('vidfile', t('The system was not able to find this video on Google Video. Please check the URL of your Google video.'));
+ }
+ }
+}
+
+
+/**
+ * Implementation of hook_v_play
+*/
+function video_google_v_play($node) {
+ return theme('video_google_play', $node);
+}
+
+
+
+/** AUTOTHUMBNAILING LOGIC */
+
+define('VIDEO_GOOGLE_XML', 'http://video.google.com/videofeed');
+
+function _video_apiclient_google_request($id, $cacheable = TRUE) {
+ $args = array('docid' => $id);
+ return _video_apiclient_request_xml('google', VIDEO_GOOGLE_XML, $args, $cacheable);
+}
+
+function _video_apiclient_google_get_thumbnail_url($id) {
+
+ $xml = _video_apiclient_google_request($id);
+
+ // we *should* be able to use media:thumbnail
+ // but unfortunately, that is stripped out from the request hook
+ // so instead, we'll parse it from the description, where it's repeated.
+ // TODO: look into how to fix this...
+ $desc = $xml['ITEM']['DESCRIPTION'][0];
+ $regex = '@<img src="([^"]*)"@';
+ if (preg_match($regex, $desc, $matches)) {
+ return $matches[1];
+ }
+ return null;
+}
+
+
+/**
+ * Implementation of hook_v_auto_thumbnail
+*/
+function video_google_v_auto_thumbnail($node) {
+ if (count($_POST)) {
+ if ($_POST['vidfile'] == $node->vidfile) {
+ _video_image_thumbnail_debug(t('No new video to thumbnail'));
+ return NULL;
+ }
+ if ($_POST['tempimage']['fids']['_original']) {
+ _video_image_thumbnail_debug(t('Video already thumbnailed'));
+ return NULL;
+ }
+ }
+ // let's include apiclient logic
+
+ //get the video id
+ if (!$node->vidfile && count($_POST)) {
+ $vidfile = $_POST['vidfile'];
+ } else {
+ $vidfile = $node->vidfile;
+ }
+ $id = _video_google_get_id($vidfile);
+ // get thumbnail url
+ $thumbnail_url = _video_apiclient_google_get_thumbnail_url($id);
+
+ return _video_image_get_thumb_file_object($thumbnail_url, $id);
+}
+
+
+/**
+ * Implementation of hook_v_auto_resolution
+*/
+function video_google_v_auto_resolution(&$node) {
+ // we set google videos to 400x326 by default
+ return array(400, 326);
+}
+
+
+
+/** THEMEABLE FUNCTIONS */
+
+/**
+ * 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_google_play($node) {
+ $width = ($node->video_scaled_x ? $node->video_scaled_x : '425');
+ $height = ($node->video_scaled_y ? $node->video_scaled_y : '350');
+ // Strip heading "google:"
+ $videoid = _video_google_get_id(check_plain($node->vidfile));
+ //$videoid = substr($node->vidfile, 7);
+
+ // this will be executed by not Internet Explorer browsers
+ $output = '<!--[if !IE]> <-->
+<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
+data="http://video.google.com/googleplayer.swf?docId='. check_plain($videoid) .'">
+<!--> <![endif]-->' . "\n";
+
+ // this will be executed by Internet Explorer
+ $output .= '<!--[if IE]>
+<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
+classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
+codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
+<![endif]-->' . "\n";
+
+ // params will be passed to both IE or not IE browsers
+ $output .= '<param name="movie" value="http://video.google.com/googleplayer.swf?docId=' . check_plain($videoid) . '" />' . "\n";
+ // following a list of params simply copied from old embed tag params. I don't know if this are really needed.
+ $output .= '<param name="quality" value="best" />
+ <param name="bgcolor" value="#ffffff" />
+ <param name="allowScriptAccess" value="sameDomain" />
+ <param name="scale" value="noScale" />
+ <param name="wmode" value="transparent" />
+ <param name="salign" value="TL" />
+ <param name="FlashVars" value="playerMode=embedded" />'
+ . _video_get_parameters($node) .
+ '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
+</object>';
+
+
+ $output = theme('video_format_play', $output, t('http://video.google.com/support'), t('Link to video.google.com'), t('video.google.com'));
+ return $output;
+}
+
+
+
+/** HELPER FUNCTIONS */
+
+/**
+ * Get the docid from an URL
+*/
+function _video_google_get_id($url) {
+ $pattern = '/-?[0-9]+/'; // maybe too weak? some id have a leading -
+ preg_match_all($pattern, $url, $matches, PREG_PATTERN_ORDER);
+ return $matches[0][0];
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function video_google_theme() {
+ return array(
+ 'video_google_play' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ );
+}
+
+module_load_include('inc', 'video', 'includes/apiclient');
diff --git a/types/video_upload/busy.gif b/types/video_upload/busy.gif
new file mode 100644
index 0000000..d45e5c2
--- /dev/null
+++ b/types/video_upload/busy.gif
Binary files differ
diff --git a/types/video_upload/video_upload.info b/types/video_upload/video_upload.info
new file mode 100644
index 0000000..10f6e66
--- /dev/null
+++ b/types/video_upload/video_upload.info
@@ -0,0 +1,7 @@
+name = Upload Video
+description = Enable Uploaded video support for Video module.
+dependencies[] = video
+dependencies[] = token
+dependencies[] = upload
+package = "Video"
+core = 6.x \ No newline at end of file
diff --git a/types/video_upload/video_upload.js b/types/video_upload/video_upload.js
new file mode 100644
index 0000000..0341f16
--- /dev/null
+++ b/types/video_upload/video_upload.js
@@ -0,0 +1,44 @@
+// $Id$
+/**
+ * @file
+ * Javascript functions for busy status on video uploads
+ *
+ * TODO: Support AJAX Uploads :-)
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ * porting to Drupal 6
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
+ * @todo
+*/
+
+/**
+ * Hide the node form and show the busy div
+*/
+Drupal.video_upload_hide = function () {
+ // hiding the form (using display: none) makes its file values empty in Konqueror (Possibly also Safari). So let's move the form away of the view of the browser
+
+ $('#node-form').css({ position: "absolute", top: "-4000px" });
+
+ $("#sending").show();
+ $("#video_upload_cancel_link").click(Drupal.video_upload_show);
+}
+
+Drupal.video_upload_show = function() {
+ $('#node-form').show();
+ $("#sending").hide();
+
+ //$("form").bind("submit", function() { return false; })
+ window.location = window.location;
+}
+
+/**
+ * Attaches the upload behaviour to the video upload form.
+ */
+Drupal.video_upload = function() {
+ $('#node-form').submit(Drupal.video_upload_hide);
+}
+
+// Global killswitch
+if (Drupal.jsEnabled) {
+ $(document).ready(Drupal.video_upload);
+}
diff --git a/types/video_upload/video_upload.module b/types/video_upload/video_upload.module
new file mode 100644
index 0000000..4dc0630
--- /dev/null
+++ b/types/video_upload/video_upload.module
@@ -0,0 +1,908 @@
+<?php
+
+/**
+ * @file
+ * Enable Uploaded videos support for video module.
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ * @contributor Vernon Mauery <vernon at mauery dot com>
+ * porting to Drupal 6
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
+ * @todo
+ */
+
+
+/**
+ * Implementation of hook_menu
+*/
+function video_upload_menu() {
+ $items = array();
+ $maycache = true;
+ if($maycache) {
+ $items['node/add/video/upload'] = array(
+ 'title' => 'Upload',
+ 'access arguments' => array('create video')
+ );
+ $items['admin/settings/video/upload'] = array(
+ 'title' => 'Upload',
+ 'description' => 'Configure various settings of the video upload plugin.',
+ 'access arguments' => array('administer site configuration'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('video_upload_admin_settings'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+ }
+
+ return $items;
+}
+
+
+/**
+ * Setting form for video_upload
+*/
+function video_upload_admin_settings() {
+ $form = array();
+
+ $form['video_upload_allowed_extensions'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed extensions'),
+ '#description' => t('A comma separated list of video extesions uploadable with the video upload feature. Do not insert any space.'),
+ '#default_value' => variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'),
+ );
+
+ $form['video_upload_path_prefix'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pattern for the file prefix'),
+ '#description' => t('Specify the pattern to prefix to file names uploaded with the video_upload module. It will be appended after the site files directory (e.g., files) but before the file name itself. Do not include a leading or trailing slash. Spaces will be converted to underscores to avoid file system issues.'),
+ '#default_value' => variable_get('video_upload_path_prefix', 'videos'),
+ );
+
+ $form['token_help'] = array(
+ '#title' => t('Replacement patterns'),
+ '#type' => 'fieldset',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
+ );
+ $form['token_help']['help'] = array(
+ '#value' => theme('token_help', 'node'),
+ );
+
+ return system_settings_form($form);
+}
+
+
+/**
+ * Implementation of hook_cron().
+ * Look for uploaded videos which have not been submitted (only previews) and
+ * delete them
+ */
+function video_upload_cron() {
+ /* look for crusty files */
+ $temppath = file_directory_temp() . '/video/';
+ $files = file_scan_directory(file_create_path($temppath), '.*');
+ foreach ($files as $file => $info) {
+ if (time() - filemtime($file) > 60*60*6) {
+ db_query("DELETE FROM {files} WHERE filename LIKE 'video_upload_temp.%' AND nid = 1 AND filepath = '%s'", $file);
+ file_delete($file);
+ }
+ }
+}
+
+
+
+
+/**
+ * Implementation of hook_v_help
+*/
+function video_upload_v_help() {
+
+ $help = array();
+ $help['upload']['data'] = '<b>' . t('Upload support') . '</b>';
+ $help['upload']['children'] = array(t('You can upload a video file from your computer to this website.'));
+
+ return $help;
+}
+
+
+/**
+ * Implementation of hook_v_info()
+*/
+function video_upload_v_info() {
+ $info['upload'] = array(
+ '#name' => 'Upload Video',
+ '#description' => t('Post a video available on your computer as a file to this website.'),
+ '#downloadable' => true,
+ '#autothumbable' => module_exists('video_ffmpeg_helper') && variable_get('video_image_auto_thumbnail', false),
+ '#autoresolution' => module_exists('video_ffmpeg_helper') && variable_get('video_ffmpeg_helper_auto_resolution', false),
+ '#autoplaytime' => module_exists('video_ffmpeg_helper') && variable_get('video_ffmpeg_helper_auto_playtime', false),
+ );
+
+ return $info;
+}
+
+
+/**
+ * Implements the hook_v_auto_thumnail
+*/
+function video_upload_v_auto_thumbnail(&$node) {
+ // as we rely on ffmpeg_helper, let's check if we have video_ffmpeg_helper_installed
+ if(module_exists('video_ffmpeg_helper')) {
+ return _video_ffmpeg_helper_auto_thumbnail($node);
+ }
+ return false;
+}
+
+
+/**
+ * Implements the hook_v_auto_resolution
+*/
+function video_upload_v_auto_resolution(&$node) {
+ // as we rely on ffmpeg_helper, let's check if we have video_ffmpeg_helper_installed
+ if(module_exists('video_ffmpeg_helper')) {
+ return _video_ffmpeg_helper_auto_resolution($node);
+ }
+ return false;
+}
+
+
+/**
+ * Implements the hook_v_auto_resolution
+*/
+function video_upload_v_auto_playtime(&$node) {
+ // as we rely on ffmpeg_helper, let's check if we have video_ffmpeg_helper_installed
+ if(module_exists('video_ffmpeg_helper')) {
+ return _video_ffmpeg_helper_auto_playtime($node);
+ }
+ return false;
+}
+
+
+/**
+ * Implements the hook_v_download
+*/
+function video_upload_v_download($node) {
+ // the code below comes from the audio.module
+
+ // The mime_header_encode function does not (yet) support
+ // quoted-string encoding of ASCII strings with special
+ // characters. See discussion at http://drupal.org/node/82614
+ $filename = basename($node->current_video_upload_file->filename);
+ // If the string contains non-ASCII characters, process it through
+ // the mime_header_encode function.
+ if (preg_match('/[^\x20-\x7E]/', $filename)) {
+ $filename = mime_header_encode($filename);
+ }
+ // Otherwise, if the string contains special characters (like
+ // space), perform quoted-string encoding.
+ elseif (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $filename)) {
+ $filename = '"'. str_replace('"', '\"', $filename) .'"';
+ }
+ $headers = array(
+ 'Content-Type: '. mime_header_encode($node->current_video_upload_file->filemime),
+ 'Content-Length: '. $node->current_video_upload_file->filesize,
+ 'Content-Disposition: attachment; filename='. $filename,
+ );
+ video_upload_file_transfer($node->current_video_upload_file->filepath, $headers);
+}
+
+
+/**
+ * Variation on Drupal's file_transfer() function. The only difference
+ * is that set_time_limit() is called to allow for large files.
+
+ * This code comes from audio module
+ *
+ * @param $source File to transfer.
+ * @param $headers An array of http headers to send along with file.
+ */
+function video_upload_file_transfer($source, $headers) {
+ ob_end_clean();
+
+ foreach ($headers as $header) {
+ // To prevent HTTP header injection, we delete new lines that are
+ // not followed by a space or a tab.
+ // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
+ $header = preg_replace('/\r?\n(?!\t| )/', '', $header);
+ header($header);
+ }
+
+ $source = file_create_path($source);
+
+ // Transfer file in 1024 byte chunks to save memory usage.
+ if ($fd = fopen($source, 'rb')) {
+ if (!ini_get('safe_mode')){
+ set_time_limit(0);
+ }
+ while (!feof($fd)) {
+ print fread($fd, 1024);
+ ob_flush();
+ flush();
+ }
+ fclose($fd);
+ }
+ else {
+ drupal_not_found();
+ }
+ exit();
+}
+
+
+/**
+ * Implementation of hook_v_form()
+*/
+function video_upload_v_form(&$node, &$form) {
+ //print 'form';
+
+ // add js stuff for the 'upload in progess' message
+ theme('video_upload_get_script');
+ // add hidden html used for the 'upload in progess' message
+ $form['#suffix'] = theme('video_upload_busy');
+
+ // required for upload to work
+ $form['#attributes']['enctype'] = 'multipart/form-data';
+
+ $form['video'] += _video_upload_form($node);
+
+ return $form;
+}
+
+
+
+/**
+ * Implementation of hook_nodeapi()
+ */
+function video_upload_nodeapi(&$node, $op) {
+
+ if($node->type == 'video' && $node->vtype == 'upload') {
+ switch ($op) {
+
+ case 'load':
+ //exit;
+ //print_r($node);
+ //exit;
+ return _video_upload_load($node);
+
+ case 'prepare':
+ //exit;
+ _video_upload_prepare($node);
+ break;
+
+ case 'validate':
+ //exit;
+ //_video_upload_validate($node);
+ break;
+
+ case 'presave':
+ //exit;
+ //_video_upload_submit($node);
+ break;
+
+ case 'submit':
+ // exit;
+
+ //_video_upload_submit($node);
+ break;
+
+ case 'insert':
+ //exit;
+ //print_r($node);
+ //exit;
+ //_video_upload_submit($node);
+ //_video_upload_insert($node);
+ _video_upload_validate($node);
+ break;
+
+ case 'update':
+ // exit;
+ _video_upload_update($node);
+ break;
+
+ case 'delete':
+ //exit;
+ _video_upload_delete($node);
+ break;
+
+ case 'delete revision':
+ //exit;
+ video_upload_delete_revision($node);
+ break;
+
+ case 'view':
+ // exit;
+ _video_upload_view($node);
+ }
+ }
+}
+
+
+
+function _video_upload_load(&$node) {
+ //print 'load';
+ //print_r($node);
+ //exit;
+ $fileBuf = db_fetch_object(db_query('SELECT fid FROM {upload} WHERE nid = %d', $node->nid));
+ $output = array();
+ $output['video_fid'] = $fileBuf->fid;
+ $file = _video_upload_get_file($output['video_fid']);
+ $output['current_video_upload_file'] = $file;
+ $output['vidfile'] = file_create_url($file->filepath);
+ // set the filesize
+ $output['size'] = $file->filesize;
+ //print_r($output);
+ return $output;
+}
+
+
+/*
+The following hooks implementation is pretty Drupal voodoo :-) .. you should be
+pretty confortable on drupal apis. See
+http://www.varesano.net/blog/fabio/understanding+drupal+hook+nodeapi+execution+order
+for some hints
+*/
+
+function _video_upload_prepare(&$node) {
+ //print 'prepare';
+ //exit;
+ if (!count($_POST))
+ return;
+ //print 'prepare';
+ //print_r($node);
+ //exit;
+ if (is_object($node->video_upload_file)) {
+ $file_field = $node->video_upload_file;
+ } else {
+ $file_field = 'video_upload_file';
+ }
+
+/* TODO Modify the validators array to suit your needs.
+ This array is used in the revised file_save_upload */
+ $validators = array(
+ 'file_validate_is_image' => array(),
+ 'file_validate_image_resolution' => array('85x85'),
+ 'file_validate_size' => array(30 * 1024),
+ );
+
+ if (count($_POST) && $file = file_save_upload($file_field , $validators) ){ // a file has been uploaded
+ // this is the temp directory to store files
+ $temppath = file_directory_temp() . '/video/';
+ // let's check that the directory is good
+ file_check_directory($temppath, TRUE);
+ // let's save the uploaded file to the temp directory
+ $file = file_save_upload($file, $temppath . '/' . $file->filename, FILE_EXISTS_REPLACE);
+
+ // let's store the temp file into the DB
+ $file->fid = db_last_insert_id('files','fid');
+ db_query("INSERT INTO {files} (fid, filename, filepath, filemime, filesize) VALUES (%d, '%s', '%s', '%s', %d)", $file->fid, 'video_upload_temp.'.$file->filename, $file->filepath, $file->filemime, $file->filesize);
+
+ // TODO: delete here the previous $node->new_video_upload_file
+
+ $node->new_video_upload_file = $file;
+ }
+ else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Submit') {
+ $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
+ }
+ else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Preview') {
+ $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
+
+ }
+}
+
+/**
+* Create video upload specific form fields
+*/
+function _video_upload_form(&$node) {
+ _video_upload_check_settings();
+
+ $form = array();
+
+ if($node->new_video_upload_file) { // there is a newly uploaded file (this has been initialized by _prepare())
+ $form['new_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => $node->new_video_upload_file->fid);
+ $form['new_video_upload_file_info'] = array('#type' => 'item', '#value' => theme('video_upload_file_info_form', $node->new_video_upload_file, $node), '#weight' => -10);
+
+ $we_have_video = true;
+ }
+ else {
+ $form['new_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => 0);
+ if($node->current_video_upload_file) { // we don't have a new file
+ $form['current_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => $node->current_video_upload_file->fid);
+ $form['current_video_upload_file_info'] = array('#type' => 'item', '#value' => theme('video_upload_file_info_form', $node->current_video_upload_file, $node), '#weight' => -10);
+
+ $we_have_video = true;
+ }
+ }
+ $form['video_upload_file'] = array(
+ '#type' => 'file',
+ '#title' => $we_have_video ? t('Replace with') : t('Upload video file'),
+ '#size' => 40,
+ '#weight' => -9,
+ '#description' => t('Choose a video file from your pc.<br /><b>NOTE:</b> The max upload size is') . ' ' . format_size(file_upload_max_size()) . '.',
+ // no need to set this as required as we do validation in the validate nodeapi hook
+ );
+
+ return $form;
+}
+
+
+/**
+ * Validate video file
+ */
+function _video_upload_validate(&$node) {
+ //print 'validate';
+ //print_r($node); die;
+ //##################### PREPARE ##########################
+
+ if (is_object($node->video_upload_file)) {
+ $file_field = $node->video_upload_file;
+ } else {
+ $file_field = 'video_upload_file';
+ }
+
+/* TODO Modify the validators array to suit your needs.
+ This array is used in the revised file_save_upload
+ $validators = array(
+ 'file_validate_is_image' => array(),
+ 'file_validate_image_resolution' => array('85x85'),
+ 'file_validate_size' => array(30 * 1024),
+ );
+*/
+ // get extention list
+ $extentions = explode(",",variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'));
+
+ $validators = array(
+ 'file_validate_extensions' => array(variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'))
+ );
+ // TODO : add file sixe validation
+ // 'file_validate_size' => array($limits['file_size'], $limits['user_size']),
+
+ if (count($_POST) && $file = file_save_upload($file_field , $validators) ){ // a file has been uploaded
+
+ // this is the temp directory to store files
+ //$temppath = file_directory_temp() . '/video/';
+ // let's check that the directory is good
+ //file_check_directory($temppath, TRUE);
+ // let's save the uploaded file to the temp directory
+ //$file = file_save_upload($file, $validators, $temppath . '/' . $file->filename, FILE_EXISTS_REPLACE);
+
+ //TODO : set status value
+ //$status=0;
+ // let's store the temp file into the DB
+ //$file->fid = db_last_insert_id('files','fid');
+ //db_query("INSERT INTO {files} (fid, filename, filepath, filemime, filesize,status) VALUES (%d, '%s', '%s', '%s', %d, %d)", $file->fid, 'video_upload_temp.'.$file->filename, $file->filepath, $file->filemime, $file->filesize, $file->status);
+
+ // TODO: delete here the previous $node->new_video_upload_file
+ //print_r($file);
+ //exit;
+ $node->new_video_upload_file = $file->fid;
+ $node->new_video_upload_file_fid = $file->fid;
+ }
+ else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Submit') {
+ $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
+ }
+ else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Preview') {
+ $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
+
+ }
+ //print_r($node);
+ //exit;
+ //#########################################################
+
+ if(!($node->new_file_uploaded || $node->new_video_upload_file_fid > 0 || $node->new_video_upload_file_fid > 0 || $node->current_video_upload_file_fid > 0)) { //
+ form_set_error('video_upload_file', t('You have not provided any video file. Please upload one.<br />If you uploaded a video but the system did not received it, please check that it is smaller than') . ' ' . format_size(file_upload_max_size()).'.');
+ }
+ else if($node->new_file_uploaded || $node->new_video_upload_file_fid > 0 || $node->new_video_upload_file_fid > 0){
+ if($node->new_file_uploaded) { // only if the user oploaded a new file
+ $file = $node->new_file_uploaded;
+ }
+ else {
+ $file = _video_upload_get_file($node->new_video_upload_file_fid);
+ }
+
+ // let's check file extension
+ $extensions = variable_get('video_upload_allowed_extensions', 'mov,flv,wmv');
+ $regex = '/\.('. ereg_replace(',+', '|', preg_quote($extensions)) .')$/i';
+ if (!preg_match($regex, $file->filename)) {
+ //set an error message and delete the the file
+ form_set_error('audio', t('The selected file %name can not be uploaded, because it is only possible to upload files with the following extensions: %files-allowed.', array('%name' => $file->filename, '%files-allowed' => $extensions)));
+ _video_upload_delete_file($file);
+ }
+ }
+ //call to submit function
+ //print_r($node);
+ //exit;
+ _video_upload_submit($file,$node);
+}
+
+
+function _video_upload_submit(&$file,&$node) {
+ //print 'submit';
+
+ //print_r($node); die;
+ if($node->new_video_upload_file_fid) {
+ $fid = $node->new_video_upload_file_fid;
+ }
+ else {
+ $fid = $node->current_video_upload_file_fid;
+ }
+ $node->serial_data['video_fid'] = $fid;
+ _video_upload_insert($file,$node);
+}
+
+function _video_upload_insert(&$file,&$node) {
+ // global $file;
+ //print 'insert';
+ //print_r($node); die;
+ // if($node->new_video_upload_file_fid && $file = _video_upload_get_file($node->new_video_upload_file_fid)) { // there is a new file uploaded (now stored on the temp path); need to store in the final directory
+ //print_r($node);
+ //exit;
+ _video_upload_store_file($file, $node);
+ //}
+}
+
+function _video_upload_update(&$node) {
+ //##################### PREPARE ##########################
+
+ if (is_object($node->video_upload_file)) {
+ $file_field = $node->video_upload_file;
+ } else {
+ $file_field = 'video_upload_file';
+ }
+
+/* TODO Modify the validators array to suit your needs.
+ This array is used in the revised file_save_upload
+ $validators = array(
+ 'file_validate_is_image' => array(),
+ 'file_validate_image_resolution' => array('85x85'),
+ 'file_validate_size' => array(30 * 1024),
+ );
+*/
+ // get extention list
+ $extentions = explode(",",variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'));
+
+ $validators = array(
+ 'file_validate_extensions' => array(variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'))
+ );
+ // TODO : add file sixe validation
+ // 'file_validate_size' => array($limits['file_size'], $limits['user_size']),
+
+ if (count($_POST) && $file = file_save_upload($file_field , $validators) ){ // a file has been uploaded
+
+ // this is the temp directory to store files
+ //$temppath = file_directory_temp() . '/video/';
+ // let's check that the directory is good
+ //file_check_directory($temppath, TRUE);
+ // let's save the uploaded file to the temp directory
+ //$file = file_save_upload($file, $validators, $temppath . '/' . $file->filename, FILE_EXISTS_REPLACE);
+
+ //TODO : set status value
+ //$status=0;
+ // let's store the temp file into the DB
+ //$file->fid = db_last_insert_id('files','fid');
+ //db_query("INSERT INTO {files} (fid, filename, filepath, filemime, filesize,status) VALUES (%d, '%s', '%s', '%s', %d, %d)", $file->fid, 'video_upload_temp.'.$file->filename, $file->filepath, $file->filemime, $file->filesize, $file->status);
+
+ // TODO: delete here the previous $node->new_video_upload_file
+ //print_r($file);
+ //exit;
+ $node->new_video_upload_file = $file->fid;
+ $node->new_video_upload_file_fid = $file->fid;
+ }
+ else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Submit') {
+ $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
+ }
+ else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Preview') {
+ $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
+
+ }
+ //print_r($node);
+ //exit;
+ //#########################################################
+
+
+ if($node->new_video_upload_file_fid && $file = _video_upload_get_file($node->new_video_upload_file_fid)) { // there is a new file uploaded (now stored on the temp path)
+ //need to store in the final directory
+ //exit;
+ _video_upload_store_file($file, $node);
+ ///print_r($node);
+ //exit;
+ //$node = _video_upload_load($node);
+ if($node->current_video_upload_file_fid) {
+ // let's delete the old video
+ _video_upload_delete_file($node->current_video_upload_file_fid);
+ }
+ }
+
+}
+
+/**
+ * Delete files associated to this video node
+ */
+function _video_upload_delete(&$node) {
+ //print 'delete';
+
+ // delete file
+ file_delete($node->current_video_upload_file->path);
+
+ // delete file information from database
+ db_query('DELETE FROM {upload} WHERE fid = %d', $node->current_video_upload_file->fid);
+ db_query('DELETE FROM {files} WHERE fid = %d', $node->current_video_upload_file->fid);
+}
+
+
+/**
+ *
+*/
+function _video_upload_view(&$node) {
+ //print 'view';
+}
+
+
+/**
+ * Move a temp file into the final directory associating it with the node
+*/
+function _video_upload_store_file(&$file, &$node) {
+ //global $file;
+ // $file->filename is video_upload_temp.realfile.ext : let's restore original filename
+//print_r($file);
+//exit;
+ $file->filename = _video_get_original_filename($file->filename);
+
+ _video_upload_get_path($file, $node);
+
+ if (file_move($file, file_directory_path())) { // file moved successfully
+
+ // update the file db entry
+ db_query("UPDATE {files} SET filename = '%s', filepath = '%s', filemime = '%s', filesize = %d WHERE fid = %d", $file->filename, $file->filepath, $file->filemime, $file->filesize, $file->fid);
+ // add an entry in the file_revisions table
+ db_query("INSERT INTO {upload} (fid, nid, vid, list, description) VALUES (%d, %d, %d, %d, '%s')", $file->fid, $node->nid, $node->vid, $file->list, $file->description);
+ // update the file db entry
+ //db_query("UPDATE {video} SET serialized_data = '%s' WHERE vid = %d", $file->filename, $file->filepath, $file->filemime, $file->filesize, $file->fid);
+
+ }
+ else {
+ drupal_set_message(t('An error occurred during file saving. Your video file has not been stored.'), 'error');
+ $rep = array(
+ '!path' => $file,
+ '!dest' => $dest_path,
+ );
+ watchdog('video_upload', 'moving file !path to !dest failed', $rep);
+ }
+}
+
+
+/**
+ * Gets the definitive path for stored videos
+*/
+function _video_upload_get_path(&$file, &$node) {
+ // this code is from uploadpath.module
+ $file_name = str_replace(array(' ', "\n", "\t"), '_', token_replace(variable_get('video_upload_path_prefix', 'videos') . '/', 'node', $node)) . $file->filename;
+
+ // Create the directory if it doesn't exist yet.
+ $dirs = explode('/', dirname($file_name));
+ $directory = file_directory_path();
+ while (count($dirs)) {
+ $directory .= '/' . array_shift($dirs);
+ file_check_directory($directory, FILE_CREATE_DIRECTORY);
+ }
+ $file->filename = $file_name;
+}
+
+
+/**
+ * Get the file object with the given $fid. This function cache its results
+*/
+function _video_upload_get_file($fid) {
+ static $files = array();
+
+ if (!$fid) {
+ return null;
+ }
+ if (!isset($files[$fid])) {
+ $files[$fid] = db_fetch_object(db_query('SELECT * from {files} WHERE fid = %d', $fid));
+ }
+ return $files[$fid];
+}
+
+
+/**
+ * Delete a file
+*/
+function _video_upload_delete_file($file) {
+
+ // delete file
+ file_delete($file->path);
+
+ // delete file information from database
+ db_query('DELETE FROM {upload} WHERE fid = %d', $file);
+ db_query('DELETE FROM {files} WHERE fid = %d', $file);
+}
+
+
+/**
+ * Display informations about already uploaded file
+ */
+function theme_video_upload_file_info_form($file, $node) {
+ // create array containing uploaded file informations
+ $items = array(
+ '<b>'. t('file name') .':</b> ' . _video_get_original_filename(basename($file->filename)), // do not display parent folders
+ '<b>'. t('file size') .':</b> ' . format_size($file->filesize),
+ );
+
+ // create information list
+ $output .= theme_item_list($items, t('uploaded video information:'));
+
+ return $output;
+}
+
+
+/**
+ * Return the original filename (without 'video_upload_temp.')
+*/
+function _video_get_original_filename($filename) {
+ if(strpos($filename, 'video_upload_temp.') === 0) {
+ return substr($filename, strlen('video_upload_temp.'));
+ }
+ return $filename;
+}
+
+
+/**
+ * Verify the video_upload module settings.
+ */
+function _video_upload_check_settings() {
+
+ /*
+ // File paths
+ $video_path = file_create_path(variable_get('video_upload_default_path', 'videos'));
+ $temp_path = rtrim($video_path, '/') . '/temp';
+
+ if (!file_check_directory($video_path, FILE_CREATE_DIRECTORY, 'video_upload_default_path')) {
+ return false;
+ }
+ if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY, 'video_upload_default_path')) {
+ return false;
+ }
+ */
+ return true;
+
+}
+
+
+
+/**
+ * Import the video_upload.js script
+ */
+function theme_video_upload_get_script() {
+ drupal_add_js(drupal_get_path('module', 'video_upload') . '/video_upload.js');
+}
+
+
+/**
+ * Renders a 'upload in progress' message
+*/
+function theme_video_upload_busy() {
+ return '<div id="sending" style="display: none;">
+ <h3>' . t('Sending video... please wait.') . '</h3>
+ <img src="'. base_path() . drupal_get_path('module', 'video_upload') . '/busy.gif'.'" alt="' . t('Sending video... please wait.') . '"/>
+ <p>'. t('Please wait while your video is uploading.') . '<br /><a href="#" id="video_upload_cancel_link">' . t('abort upload.') . '</a></p>
+ </div>';
+}
+
+
+/**
+ * Implementation of hook_v_play
+*/
+function video_upload_v_play($node) {
+ module_load_include('inc', 'video', '/includes/common');
+ return _video_common_get_player($node);
+}
+
+
+/**
+ * Function to other modules to use to create image nodes.
+ *
+ * @param $filepath
+ * String filepath of an image file. Note that this file will be moved into
+ * the image module's images directory.
+ * @param $title
+ * String to be used as the node's title. If this is ommitted the filename
+ * will be used.
+ * @param $body
+ * String to be used as the node's body.
+ * @param $taxonomy
+ * Taxonomy terms to assign to the node if the taxonomy.module is installed.
+ * @return
+ * A node object if the node is created successfully or FALSE on error.
+ */
+function video_upload_create_node_from($filepath, $title = NULL, $body = '', $taxonomy = NULL) {
+ global $user;
+
+ if (!user_access('create video')) {
+ drupal_access_denied();
+ }
+
+ if (!is_object($filepath)) {
+ $p = $filepath;
+ $filepath = new stdClass();
+ $filepath->filepath = $p;
+ $filepath->filename = basename($p);
+ $filepath->filesize = filesize($p);
+ }
+
+ // Ensure it's a valid video
+ //if (!$image_info = image_get_info($filepath)) {
+ // return FALSE;
+ //}
+
+ // Build the node.
+ $node = new stdClass();
+ $node->type = 'video';
+ $node->vtype = 'upload';
+ $node->uid = $user->uid;
+ $node->name = $user->name;
+ $node->title = isset($title) ? $title : basename($filepath);
+ $node->body = $body;
+
+ // Set the node's defaults... (copied this from node and comment.module)
+ $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
+ $node->status = in_array('status', $node_options);
+ $node->promote = in_array('promote', $node_options);
+ if (module_exists('comment')) {
+ $node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE);
+ }
+ if (module_exists('taxonomy')) {
+ $node->taxonomy = $taxonomy;
+ }
+ $node->video_upload_file = $filepath;
+ node_invoke_nodeapi($node, 'prepare');
+ $node->new_video_upload_file_fid = $node->new_video_upload_file->fid;
+
+ // Save the node.
+ $node = node_submit($node);
+ node_save($node);
+
+ // Remove the original image now that the import has completed.
+ file_delete($original_path);
+
+ return $node;
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function video_upload_theme() {
+ return array(
+ 'video_upload_busy' => array(
+ 'arguments' => array(),
+ ),
+ 'video_upload_file_info_form' => array(
+ 'arguments' => array('file' => NULL,'node' => NULL),
+ ),
+ 'video_upload_get_script' => array(
+ 'arguments' => array(),
+ ),
+ 'video_play_dcr' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_divx' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_flash' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_ogg_theora' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_quicktime' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_realmedia' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_swf' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'video_play_windowsmedia' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ );
+} \ No newline at end of file
diff --git a/types/video_url/video_url.info b/types/video_url/video_url.info
new file mode 100644
index 0000000..a45f8a6
--- /dev/null
+++ b/types/video_url/video_url.info
@@ -0,0 +1,5 @@
+name = URL Video
+description = Enable URL video support for Video module.
+dependencies[] = video
+package = "Video"
+core = 6.x \ No newline at end of file
diff --git a/types/video_url/video_url.module b/types/video_url/video_url.module
new file mode 100644
index 0000000..1eaae16
--- /dev/null
+++ b/types/video_url/video_url.module
@@ -0,0 +1,102 @@
+<?php
+/**
+ * @file
+ * Enable Path or URL support for video module.
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ * porting to Drupal 6
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
+ * @todo
+ */
+
+
+/**
+ * Implementation of hook_menu
+*/
+function video_url_menu() {
+ $items = array();
+ $maycache=true;
+ if($maycache) {
+ $items['node/add/video/url'] = array(
+ 'title' => 'URL',
+ 'access arguments' => array('create video')
+ );
+ }
+
+ return $items;
+}
+
+
+/**
+ * Implementation of hook_v_help
+*/
+function video_url_v_help() {
+
+ $help = array();
+ $help['url']['data'] = '<b>' . t('Url support') . '</b>';
+ $help['url']['children'] = array(t('You can link to any video file on the Internet.'));
+
+ return $help;
+}
+
+
+/**
+ * Implementation of hook_v_info()
+*/
+function video_url_v_info() {
+ $info['url'] = array(
+ '#name' => 'URL Video',
+ '#description' => t('Post a video available on the Internet to this website.'),
+ '#downloadable' => TRUE,
+ '#autothumbable' => FALSE,
+ '#autoresolution' => FALSE,
+ '#autoplaytime' => FALSE,
+ );
+
+ return $info;
+}
+
+
+/**
+ * Implementation of hook_v_form()
+*/
+function video_url_v_form(&$node, &$form) {
+
+ $form['video']['vidfile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('URL to the video'),
+ '#default_value' => $node->vidfile,
+ '#maxlength' => 700,
+ '#required' => TRUE,
+ '#weight' => -20,
+ '#description' => t('Insert the URL to the video file. This shuold be something similar to <em>http://www.example.com/videos/myvideo.flv</em>') . ' ' . l(t('More information.'), 'video/help', array('fragment' => 'videofile')));
+
+ return $form;
+}
+
+
+/**
+ * implementation of hook_v_validate
+*/
+function video_url_v_validate($node) {
+ // Can you suggest a validation?
+ // validation should allow URLs, relative paths but also streaming servers URLs
+}
+
+/**
+ * Implementation of hook_v_play
+*/
+function video_url_v_play($node) {
+ module_load_include('inc', 'video', 'includes/common');
+ return _video_common_get_player($node);
+}
+
+
+/**
+ * Implements the hook_v_download
+*/
+function video_url_v_download($node) {
+ $url = _video_get_fileurl($node->vidfile);
+
+ header("Location: $url"); //Redirect to the video file URL.
+}
diff --git a/types/video_youtube/video_youtube.info b/types/video_youtube/video_youtube.info
new file mode 100644
index 0000000..7fc5a2a
--- /dev/null
+++ b/types/video_youtube/video_youtube.info
@@ -0,0 +1,5 @@
+name = Youtube Video
+description = Enable Youtube videos support for Video module.
+dependencies[] = video
+package = "Video"
+core = 6.x \ No newline at end of file
diff --git a/types/video_youtube/video_youtube.module b/types/video_youtube/video_youtube.module
new file mode 100644
index 0000000..5d0a509
--- /dev/null
+++ b/types/video_youtube/video_youtube.module
@@ -0,0 +1,329 @@
+<?php
+/**
+ * @file
+ * Enable Youtube support for video module.
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ * porting to Drupal 6
+ * @author Heshan Wanigasooriya <heshan at heidisoft.com><heshanmw@gmail.com>
+ * @todo
+ */
+
+
+// let's include apiclient logic
+module_load_include('inc', 'video', 'includes/apiclient');
+
+/**
+ * Implementation of hook_menu
+*/
+function video_youtube_menu() {
+ $items = array();
+ $maycache=true;
+ if($maycache) {
+ $items['node/add/video/youtube'] = array(
+ 'title' => 'Youtube',
+ 'access arguments' => array('create video')
+ );
+
+ $items['admin/settings/video/youtube'] = array(
+ 'title' => 'Youtube',
+ 'description' => 'Configure various settings of the video Youtube plugin.',
+ 'access arguments' => array('administer site configuration'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('video_youtube_admin_settings'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+ }
+
+ return $items;
+}
+
+
+/**
+ * Setting form for video_upload
+*/
+function video_youtube_admin_settings() {
+ $form = array();
+
+ $form['video_youtube_auto_thumbnail'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable auto thumbnailing for youtube videos'),
+ '#default_value' => variable_get('video_youtube_auto_thumbnail', false)
+ );
+ $form['video_youtube_related'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable related videos'),
+ '#default_value' => variable_get('video_youtube_related', false),
+ '#description' => t('If you enable related videos the Youtube player will display a list of related videos once the video completes playing.'),
+ );
+ $form['video_youtube_validation'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable validation'),
+ '#default_value' => variable_get('video_youtube_validation', false),
+ '#description' => t('If you enable validation, on each youtube video submission, you web server will contact Youtube to check that the inserted video is available and embeddable.'),
+ );
+ $form['video_youtube_api_key'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Developer Key'),
+ '#description' => t('Insert here the developer Key. You can get one from <a href="http://www.youtube.com/my_profile_dev">Youtube Development pages</a>.'),
+ '#default_value' =>variable_get('video_youtube_api_key', ''),
+ );
+ // jlampton added: new youtube optional client id
+ $form['video_youtube_client_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Client ID'),
+ '#description' => t('Insert here the client ID. You can get one from <a href="http://www.youtube.com/my_profile_dev">Youtube Development pages</a>.'),
+ '#default_value' =>variable_get('video_youtube_client_id', ''),
+ );
+ return system_settings_form($form);
+}
+
+
+/**
+ * Validate settings
+*/
+function video_youtube_admin_settings_validate($form, &$form_state) {
+ if ($form_state['values']['video_youtube_auto_thumbnail']) { // autothumbnailing is active
+ // let's check we have a valid dev key
+ if($form_state['values']['video_youtube_api_key'] == '') {
+ form_set_error('video_youtube_api_key', t('You have to insert a valid Youtube Developer Key for auto thumbnailing to work'));
+ }
+ }
+}
+
+
+/**
+ * Implementation of hook_v_help
+*/
+function video_youtube_v_help() {
+
+ $help = array();
+ $help['youtube']['data'] = '<b><a href="http://www.youtube.com">' . t('YouTube.com support') . '</a></b>';
+ $help['youtube']['children'] = array(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 URL.'));
+
+ return $help;
+}
+
+
+/**
+ * Implementation of hook_v_info()
+*/
+function video_youtube_v_info() {
+ $info['youtube'] = array(
+ '#name' => 'Youtube Video',
+ '#description' => t('Post a video available on !link to this website.', array('!link' => l(t('Youtube'), 'http://www.youtube.com'), NULL, NULL, NULL, TRUE)),
+ '#autothumbable' => variable_get('video_youtube_auto_thumbnail', false),
+ '#autoresolution' => true,
+ '#autoplaytime' => true,
+ );
+
+ return $info;
+}
+
+
+/**
+ * Implementation of hook_v_form()
+*/
+function video_youtube_v_form(&$node, &$form) {
+
+ $form['video']['vidfile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Youtube Video URL'),
+ '#default_value' => $node->vidfile,
+ '#maxlength' => 700,
+ '#required' => TRUE,
+ '#weight' => -20,
+ '#description' => t('Insert the URL to the youtube video. ') . l(t('More information.'), 'video/help', array('fragment' => 'videofile')));
+
+ return $form;
+}
+
+
+/**
+ * implementation of hook_v_validate
+*/
+function video_youtube_v_validate($node) {
+ if(!preg_match("/^http:\/\/([a-z]{2,3}\.)?youtube\.com\/watch\?v=/", $node->vidfile)) {
+ form_set_error('vidfile', t('The Youtube Video URL field must be similar to <em>http://youtube.com/watch?v=IICWFx7sKmw</em>, <em>http://www.youtube.com/watch?v=IICWFx7sKmw</em> or <em>http://it.youtube.com/watch?v=IICWFx7sKmw</em>'));
+ }
+ else if(variable_get('video_youtube_validation', false)){
+ // we have a good URL. Let's check that the video is available on Youtube and that it is embeddable.
+ // the approach used here is to return errors only if Youtube explicitely says "an error has occurred"
+ $id = _video_youtube_get_id($node->vidfile);
+ // jlampton changed the youtube validation url
+ $response = _video_apiclient_youtube_request('gdata.youtube.com/feeds/api/videos', array('video_id' => $id));
+ if(isset($response['ERROR'])) {
+ form_set_error('vidfile', t('The Youtube Video URL validation has failed for some reason. Please check the URL and try again.<br />If the error persists please contact %site_name administrators.', array('%site_name' => variable_get('site_name', 'Drupal'))));
+ if(isset($response['ERROR']['DESCRIPTION'][0])) {
+ drupal_set_message(t('The Youtube validation service reported the following error: %error', array('%error'=>$response['ERROR']['DESCRIPTION'][0])), 'error');
+ }
+ }
+ else if(isset($response['VIDEO_DETAILS']['EMBED_STATUS'][0])
+ && $response['VIDEO_DETAILS']['EMBED_STATUS'][0] != 'ok') {
+ // embedding has been disabled. we let the video pass but we warn the user
+ drupal_set_message(t('The video authors have disabled embedding on Youtube. This means that this video will only be playable directly on Youtube.'));
+ }
+ else { // if youtube did not explicetely said "an error has occurred" we accept the video
+ ;
+ }
+ }
+}
+
+/**
+ * Implementation of hook_v_play
+*/
+function video_youtube_v_play($node) {
+ return theme('video_youtube_play', $node);
+}
+
+
+/** AUTOTHUMBNAILING LOGIC */
+
+define('VIDEO_YOUTUBE_API_INFO', 'http://youtube.com/dev');
+define('VIDEO_YOUTUBE_API_APPLICATION_URL', 'http://www.youtube.com/my_profile_dev');
+define('VIDEO_YOUTUBE_REST_ENDPOINT', 'http://www.youtube.com/api2_rest');
+
+
+/**
+* this is a wrapper for _video_apiclient_request_xml that includes youtube's api key
+*/
+function _video_apiclient_youtube_request($method, $args = array(), $cacheable = TRUE) {
+ $args['dev_id'] = trim(variable_get('video_youtube_api_key', ''));
+ $args['method'] = $method;
+
+ return _video_apiclient_request_xml('youtube', VIDEO_YOUTUBE_REST_ENDPOINT, $args, $cacheable);
+}
+
+/**
+* returns the external url for a thumbnail of a specific video
+* @param $id
+* the youtube id of the specific video
+* @return
+* a URL pointing to the thumbnail
+*/
+function _video_apiclient_youtube_get_thumbnail_url($id) {
+ $response = _video_apiclient_youtube_request('youtube.videos.get_details', array('video_id' => $id));
+
+ if(isset($response['THUMBNAIL_URL'][0]) && $response['THUMBNAIL_URL'][0] != '') {
+ return $response['THUMBNAIL_URL'][0];
+ }
+ return false;
+}
+
+
+/**
+ * Implementation of hook_v_auto_thumbnail
+*/
+function video_youtube_v_auto_thumbnail($node) {
+ if (count($_POST)) {
+ if ($_POST['vidfile'] == $node->vidfile) {
+ _video_image_thumbnail_debug(t('No new video to thumbnail'));
+ return NULL;
+ }
+ if ($_POST['tempimage']['fids']['_original']) {
+ _video_image_thumbnail_debug(t('Video already thumbnailed'));
+ return NULL;
+ }
+ $vidfile = $_POST['vidfile'];
+ } else {
+ $vidfile = $node->vidfile;
+ }
+
+ //get the video id
+ $id = _video_youtube_get_id($vidfile);
+ // get thumbnail url
+ $thumbnail_url = _video_apiclient_youtube_get_thumbnail_url($id);
+
+ return _video_image_get_thumb_file_object($thumbnail_url, $id);
+}
+
+
+/**
+ * Implementation of hook_v_auto_resolution
+*/
+function video_youtube_v_auto_resolution(&$node) {
+ // we set youtube videos to 425x350 by default
+ return array(425, 350);
+}
+
+
+/**
+ * Implementation of hook_v_auto_playtime
+*/
+function video_youtube_v_auto_playtime(&$node) {
+ $id = _video_youtube_get_id($node->vidfile);
+ $response = _video_apiclient_youtube_request('youtube.videos.get_details', array('video_id' => $id)); // NOTE: here we already passed validation so we expect a valid response
+
+ return $response['VIDEO_DETAILS']['LENGTH_SECONDS'][0]; // return the lenght in seconds
+}
+
+
+/** THEMEABLE FUNCTIONS */
+
+/**
+ * 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_youtube_play($node) {
+ $width = ($node->video_scaled_x ? $node->video_scaled_x : '425');
+ $height = ($node->video_scaled_y ? $node->video_scaled_y : '350');
+
+ $id = _video_youtube_get_id(check_plain($node->vidfile));
+
+ // related video setting
+ $rel = variable_get('video_youtube_related', false) ? '1' : '0';
+
+ // this will be executed by not Internet Explorer browsers
+ $output = '<!--[if !IE]> <-->
+<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
+data="http://www.youtube.com/v/' . $id . '&rel='.$rel.'">
+<!--> <![endif]-->' . "\n";
+
+ // this will be executed by Internet Explorer
+ $output .= '<!--[if IE]>
+<object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
+classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
+codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
+<![endif]-->' . "\n";
+
+ // params will be passed to both IE or not IE browsers
+ $output .= '<param name="movie" value="http://www.youtube.com/v/' . $id . '&rel='.$rel.'" />' . "\n"
+ . '<param name="wmode" value="transparent" />' . "\n"
+ . _video_get_parameters($node) .
+ '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
+</object>';
+
+
+ $output = theme('video_format_play', $output, t('http://www.google.com/support/youtube'), t('Link to youtube.com'), t('youtube.com'));
+ return $output;
+}
+
+
+/** HELPER FUNCTIONS */
+
+/**
+ * Get the id from an URL
+*/
+function _video_youtube_get_id($url) {
+ $parsed_url = parse_url($url);
+ parse_str($parsed_url['query'], $parsed_query);;
+ return $parsed_query['v'];
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function video_youtube_theme() {
+ return array(
+ 'video_youtube_play' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ );
+}