Index: video/plugins/video_upload/video_upload.module =================================================================== --- video.orig/plugins/video_upload/video_upload.module 2006-09-20 13:43:31.000000000 -0700 +++ video/plugins/video_upload/video_upload.module 2006-09-20 13:55:33.000000000 -0700 @@ -21,50 +21,6 @@ /** - * Implementation of hook_menu(). - */ -function video_upload_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/content/video/upload', - 'title' => t('video upload settings'), - 'description' => t('administer video_upload module settings'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('video_upload_settings'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); - } - return $items; -} - - -/** - * 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() { @@ -113,48 +69,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); } } } @@ -197,8 +111,12 @@ unset($_SESSION['video_upload_file']); } + if (isset($node->_file)) + $upload_file = $node->_file; + else + $upload_file = 'video_upload_file'; - if ($file = file_check_upload('video_upload_file')) { + if ($file = file_check_upload($upload_file)) { $temppath = file_directory_temp() . '/video/'; file_check_directory($temppath, TRUE); $node->video_upload_file = file_save_upload($file, $temppath .'/'. $file->filename, FILE_EXISTS_REPLACE); @@ -259,6 +177,8 @@ $form = array(); + $form['#attributes'] = array('enctype' => 'multipart/form-data'); + $form['size'] = array('#type' => 'hidden', '#default_value' => $node->size); $form['video_upload_file'] = array( '#type' => 'file', '#title' => t('Upload video file'), @@ -346,3 +266,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; +} Index: video/video.module =================================================================== --- video.orig/video.module 2006-09-20 13:51:38.000000000 -0700 +++ video/video.module 2006-09-20 13:53:10.000000000 -0700 @@ -100,6 +100,16 @@ 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); + $video_types = _video_get_types(); + 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))) { @@ -249,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', @@ -409,71 +431,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; } @@ -795,6 +759,8 @@ case 'mp4': case '3gp': case '3g2': + case 'mpg': + case 'avi': return theme('video_play_quicktime', $node); case 'rm': return theme('video_play_realmedia', $node); @@ -1491,3 +1457,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; +} +