Index: video.module =================================================================== RCS file: /cvs/drupal/contributions/modules/video/video.module,v retrieving revision 1.51 diff -u -r1.51 video.module --- video.module 25 Aug 2006 23:43:28 -0000 1.51 +++ video.module 4 Sep 2006 21:34:09 -0000 @@ -75,6 +75,7 @@ function video_menu($may_cache) { $items = array(); if ($may_cache) { + $video_types = _video_get_types(); $items[] = array( 'path' => 'video', 'title' => t('videos'), @@ -91,6 +92,15 @@ 'path' => 'node/add/video', 'title' => t('video'), 'access' => user_access('create video')); + foreach ($video_types as $type) { + $items[] = array( + 'path' => "node/add/video/{$type['type']}", + 'title' => t('!type video', array('!type' => $type['title'])), + 'access' => user_access($type['access']), + 'type' => ($type['type'] == variable_get('video_default_type', 'remote') ? + MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK), + ); + } } else { //If $may_cache is false. if (arg(0) == 'node' && is_numeric(arg(1))) { @@ -250,8 +259,20 @@ drupal_access_denied(); } $options = array(1 => 'Yes', 0 => 'No'); + $video_types = array(); + foreach (_video_get_types() as $type) { + $video_types[$type['type']] = $type['title']; + } $form = array(); + $form['general'] = array('#type' => 'fieldset', '#title' => t('General video settings'), '#collapsible' => TRUE, '#collapsed' => TRUE); + $form['general']['video_default_type'] = array( + '#type' => 'radios', + '#title' => t('Default video type'), + '#options' => $video_types, + '#default_value' => variable_get('video_default_type', 'remote'), + '#description' => t("This is video type that the form at node/add/video will show. If there are more than one available video types (e.g. 'Remote hosted', 'Uploaded', etc.) they will show up in tabs as menu local tasks"), + ); $form['tabs'] = array('#type' => 'fieldset', '#title' => t('Tab menu options'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['tabs']['video_displayplaymenutab'] = array( '#type' => 'radios', @@ -406,71 +430,13 @@ '#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.') ); - $form['video'] = array('#type' => 'fieldset', '#title' => t('Video File'), '#weight' => -19); - $form['video']['vidfile'] = array( - '#type' => 'textfield', - '#title' => t('Video File'), - '#default_value' => $node->vidfile, - '#maxlength' => 700, - '#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.')); + $video_type = _video_type_from_path(); + if (!$video_type) + $video_type = variable_get('video_default_type', 'remote'); + $types = _video_get_types(); + $type_form = $types[$video_type]['form']; - $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 = array_merge($form, $type_form($node)); return $form; } @@ -574,7 +540,8 @@ } } } - if (_video_get_filetype($node->vidfile) != 'youtube' and _video_get_filetype($node->vidfile) != 'googlevideo') { //If video is of type youtube don't check size. + $video_type = _video_get_filetype($node->vidfile); + if ($video_type != 'youtube' && $video_type != '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')); } @@ -582,16 +549,17 @@ 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) { //If the file is not local or a number then set error. - form_set_error('size', t('You have to insert a valid file size for this video.')); + //Make sure file size is valid. No need to check for uploaded or server-local videos + if ($video_type == 'youtube' || $video_type == 'googlevideo') { + if (!isset($node->size) || !is_numeric($node->size) || $node->size < 0) { //If the file is not local or a number then set error. + 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.')); + if (isset($node->playtime_minutes) and isset($node->playtime_hours) and isset($node->playtime_seconds)) { + if ($node->playtime_seconds + $node->playtime_minutes + $node->playtime_hours == 0) + form_set_error('playtime_seconds', t('Please enter valid playtime information for this video.')); } } @@ -1486,3 +1456,102 @@ } return $output; } + +/** + * Returns video types (e.g. remote hosted, uploaded, local to server) + * + * @return + * array of options for video types (suitable for use in #options) + */ +function _video_get_types() { + static $types = NULL; + if (!$types) { + $types = module_invoke_all('video_type'); + $types['remote'] = array( + 'type' => 'remote', + 'title' => t('Remote hosted'), + 'access' => 'create video', + 'form' => '_video_remote_hosted_form', + ); + } + return $types; +} + +function _video_type_from_path() { + $q = explode('/', $_GET['q']); + $c = count($q); + if ($c == 4 && $q[0] == 'node' && $q[1] == 'add' && $q[2] == 'video') + return $q[3]; + return NULL; +} + +function _video_remote_hosted_form(&$node) { + $form = array(); + $form['video'] = array('#type' => 'fieldset', '#title' => t('Video File'), '#weight' => -19); + $form['video']['vidfile'] = array( + '#type' => 'textfield', + '#title' => t('Video File'), + '#default_value' => $node->vidfile, + '#maxlength' => 700, + '#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.')); + + $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.')); + return $form; +} + Index: plugins/video_upload/video_upload.module =================================================================== RCS file: /cvs/drupal/contributions/modules/video/plugins/video_upload/video_upload.module,v retrieving revision 1.8 diff -u -r1.8 video_upload.module --- plugins/video_upload/video_upload.module 16 Jul 2006 10:06:53 -0000 1.8 +++ plugins/video_upload/video_upload.module 4 Sep 2006 21:34:09 -0000 @@ -21,30 +21,6 @@ /** - * Settings Hook - * - * @return - * string of form content or error message - */ -function video_upload_settings() { - //Must have "administer site configuration" and "administer video" privilages. - if (!user_access('administer video')) { - drupal_access_denied(); - } - - $form = array(); - $form['video_upload_override_vidfile'] = array( - '#type' => 'checkbox', - '#title' => t('override video file'), - '#description' => t('Check this if your users must only submit videos through uploading. This disables path insertion.'), - '#default_value' => variable_get('video_upload_override_vidfile', false), - ); - - return $form; -} - - -/** * Implementation of hook_perm(). */ function video_upload_perm() { @@ -91,48 +68,6 @@ case 'delete revision': video_upload_delete_revision($node); break; - - - - } - } -} - - -/** - * Implementation of hook_form_alter() - * We use this to add a file upload field to the video creation form. - */ -function video_upload_form_alter($form_id, &$form) { - - if($form_id == 'video_node_form' && isset($form['video']) && user_access('upload video files')) { - - //get node object from form - $node = $form['#node']; - - // required for upload to work - $form['#attributes']['enctype'] = 'multipart/form-data'; - - if(variable_get('video_upload_override_vidfile', false)) { - // remove unnecessary fields - $form['video']['vidfile'] = NULL; - $form['video']['filesize'] = NULL; - $form['video'] += _video_upload_form($node); - } - else { - // vidfile field is no more required while upload is enabled. - $form['video']['vidfile']['#required'] = FALSE; - - $form['video']['vidfile']['#description'] .= '

' . t('If you want to upload a video simply ignore this field and select your video file at the "Upload video file" field.') . '

'; - $form['video']['video_upload'] = array( - '#type' => 'fieldset', - '#title' => t('Upload video'), - '#weight' => -19, - '#collapsible' => TRUE, - '#collapsed' => (isset($node->video_upload_file) ? TRUE : FALSE ), - ); - - $form['video']['video_upload'] += _video_upload_form($node); } } } @@ -231,6 +171,7 @@ $form = array(); + $form['#attributes'] = array('enctype' => 'multipart/form-data'); $form['video_upload_file'] = array( '#type' => 'file', '#title' => t('Upload video file'), @@ -318,3 +260,17 @@ return true; } + +/** + * Implementation of hook_video_type + */ +function video_upload_video_type() { + $type = array(); + $type['uploaded'] = array( + 'type' => 'uploaded', + 'title' => t('Uploaded'), + 'access' => 'upload video files', + 'form' => '_video_upload_form', + ); + return $type; +}