From f804c5913e46299bc52f97ce7905bc00c162db81 Mon Sep 17 00:00:00 2001 From: Heshan Date: Mon, 7 Mar 2011 14:40:10 +0530 Subject: Creating new module Video UI to manage Video module configurations ie. Preset management --- includes/preset.inc | 1 + includes/video.features.inc | 50 --- includes/video.field.inc | 424 -------------------- includes/video.preset.inc | 790 -------------------------------------- modules/video_ui/video.admin.inc | 174 +++++++++ modules/video_ui/video.preset.inc | 790 ++++++++++++++++++++++++++++++++++++++ modules/video_ui/video_ui.info | 7 + modules/video_ui/video_ui.module | 188 +++++++++ video.admin.inc | 174 --------- video.css | 0 video.features.inc | 50 +++ video.field.inc | 424 ++++++++++++++++++++ video.info | 10 +- video.module | 222 +---------- 14 files changed, 1637 insertions(+), 1667 deletions(-) delete mode 100644 includes/video.features.inc delete mode 100644 includes/video.field.inc delete mode 100644 includes/video.preset.inc create mode 100644 modules/video_ui/video.admin.inc create mode 100644 modules/video_ui/video.preset.inc create mode 100644 modules/video_ui/video_ui.info create mode 100644 modules/video_ui/video_ui.module delete mode 100644 video.admin.inc delete mode 100644 video.css create mode 100644 video.features.inc create mode 100644 video.field.inc diff --git a/includes/preset.inc b/includes/preset.inc index 52d814b..f1c14b8 100644 --- a/includes/preset.inc +++ b/includes/preset.inc @@ -22,6 +22,7 @@ class video_preset { */ public function admin_settings() { $form = array(); + module_load_include('inc', 'video_ui', 'video.preset'); $presets = video_preset_get_presets(); if (count($presets) == 0) { $form['video_preset'] = array( diff --git a/includes/video.features.inc b/includes/video.features.inc deleted file mode 100644 index 10fbc9d..0000000 --- a/includes/video.features.inc +++ /dev/null @@ -1,50 +0,0 @@ - $code); -} - -/** - * Implementation of hook_features_revert(). - */ -function video_features_revert($module) { - if ($default_presets = features_get_default('video', $module)) { - foreach (array_keys($default_presets) as $default_preset) { - video_preset_delete($default_preset); - } - } -} diff --git a/includes/video.field.inc b/includes/video.field.inc deleted file mode 100644 index a342bc4..0000000 --- a/includes/video.field.inc +++ /dev/null @@ -1,424 +0,0 @@ - array( - 'label' => t('Video'), - 'description' => t('This field stores the ID of an video file as an integer value.'), - 'settings' => array( - 'uri_scheme' => variable_get('file_default_scheme', 'public'), - 'autoconversion' => 0, - 'autothumbnail' => 'no', - 'default_video_thumbnail' => 0, - 'preview_video_thumb_style' => 'thumbnail', - ), - 'instance_settings' => array( - 'file_extensions' => 'mp4 ogg avi mov wmv flv', - 'file_directory' => 'videos/original', - 'max_filesize' => '', - 'default_dimensions' => '640x350', - 'default_player_dimensions' => '640x350' - ), - 'default_widget' => 'video_upload', - 'default_formatter' => 'video', - ), - ); -} - -/** - * Implements hook_field_settings_form(). - */ -function video_field_settings_form($field, $instance) { - $defaults = field_info_field_settings($field['type']); - $settings = array_merge($defaults, $field['settings']); - $scheme_options = array(); - foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { - $scheme_options[$scheme] = $stream_wrapper['name']; - } - $form['uri_scheme'] = array( - '#type' => 'radios', - '#title' => t('Upload destination'), - '#options' => $scheme_options, - '#default_value' => $settings['uri_scheme'], - '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), - ); - $form = $form + video_default_field_settings($settings); - return $form; -} - -/** - * Element specific validation for video default value. - * - */ -function video_field_default_thumbnail_validate($element, &$form_state) { - $settings = $form_state['values']['field']['settings']; - // Make the file permanent and store it in the form. - if (!empty($settings['default_video_thumbnail']['fid'])) { - $file = file_load($settings['default_video_thumbnail']['fid']); - $file->status |= FILE_STATUS_PERMANENT; - $file = file_save($file); - $form_state['values']['field']['settings']['default_video_thumbnail'] = (array) $file; - } -} - -/** - * Implements hook_field_instance_settings_form(). - */ -function video_field_instance_settings_form($field, $instance) { - $widget = $instance['widget']; - $instance_settings = $instance['settings']; - $settings = $instance['settings']; - // Use the file field instance settings form as a basis. - $form = file_field_instance_settings_form($field, $instance); - // Remove the description option. - unset($form['description_field']); - // add settings by widget type - switch ($instance['widget']['type']) { - case 'video_upload': - break; - case 'video_ftp': - $form['ftp_path'] = array( - '#type' => 'textfield', - '#title' => t('FTP Filepath'), - '#default_value' => !empty($widget['ftp_path']) ? $widget['ftp_path'] : 'ftpvideos', - '#description' => t('The subdirectory within the "files/" directory where you have upload the videos for attachment. Once the video is attached it will be moved from this directory to the main files directory.'), - '#required' => TRUE, - '#weight' => 3, - ); - break; - } - //default settings - $default = video_default_instance_settings($settings); - $form = $default + $form; - return $form; -} - -/** - * Implements hook_field_load(). - */ -function video_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { - file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age); -} - -/** - * Implements hook_field_prepare_view(). - */ -function video_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { - // If there are no files specified at all, use the default. - foreach ($entities as $id => $entity) { - if (empty($items[$id]) && $field['settings']['default_video_thumbnail']) { - if ($file = file_load($field['settings']['default_video_thumbnail'])) { - $items[$id][0] = (array) $file + array( - 'is_default' => TRUE, - ); - } - } - } -} - -/** - * Implements hook_field_presave(). - */ -function video_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_presave($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_insert(). - */ -function video_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_update(). - */ -function video_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_update($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_delete(). - */ -function video_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_delete($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_delete_revision(). - */ -function video_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_is_empty(). - */ -function video_field_is_empty($item, $field) { - return file_field_is_empty($item, $field); -} - -/** - * Implements hook_field_widget_info(). - */ -function video_field_widget_info() { - return array( - 'video_upload' => array( - 'label' => t('Video Upload'), - 'field types' => array('video'), - 'settings' => array( - 'progress_indicator' => 'throbber', - ), - 'behaviors' => array( - 'multiple values' => FIELD_BEHAVIOR_CUSTOM, - 'default value' => FIELD_BEHAVIOR_NONE, - ), - ), - 'video_ftp' => array( - 'label' => t('Video FTP'), - 'field types' => array('video'), - 'settings' => array( - 'progress_indicator' => 'throbber', - ), - 'behaviors' => array( - 'multiple values' => FIELD_BEHAVIOR_CUSTOM, - 'default value' => FIELD_BEHAVIOR_NONE, - ), - ), - ); -} - -/** - * Implements hook_field_widget_settings_form(). - */ -function video_field_widget_settings_form($field, $instance) { - // Use the file widget settings form. - $form = file_field_widget_settings_form($field, $instance); - - return $form; -} - -/** - * Implements hook_field_widget_form(). - */ -function video_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { -// return; - // Add display_field setting to field because file_field_widget_form() assumes it is set. - $field['settings']['display_field'] = 0; - - $elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element); - $settings = $instance['settings']; - foreach (element_children($elements) as $delta) { - - // If not using custom extension validation, ensure this is an image. - $supported_extensions = array('mp4', 'ogg', 'avi', 'mov', 'wmv', 'flv'); - $extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions); - $extensions = array_intersect(explode(' ', $extensions), $supported_extensions); - $elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions); - - // Add all extra functionality provided by the image widget. - $elements[$delta]['#process'][] = 'video_field_widget_process'; - } - - if ($field['cardinality'] == 1) { - // If there's only one field, return it as delta 0. - if (empty($elements[0]['#default_value']['fid'])) { - $elements[0]['#description'] = theme('file_upload_help', array('description' => $instance['description'], 'upload_validators' => $elements[0]['#upload_validators'])); - } - } else { - $elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators'])); - } - return $elements; -} - -/** - * An element #process callback for the image_image field type. - * - * Expands the image_image type to include the alt and title fields. - */ -function video_field_widget_process($element, &$form_state, $form) { - $item = $element['#value']; - $item['fid'] = $element['fid']['#value']; - $field = field_widget_field($element, $form_state); - $instance = field_widget_instance($element, $form_state); - $settings = $field['settings']; - $element['#theme'] = 'video_widget'; - $element['#attached']['css'][] = drupal_get_path('module', 'video') . '/css/video.css'; - $element['preview'] = array(); - // preview the video thumbnail -// if (isset($element['preview']) && $element['#value']['fid'] != 0) { -// $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); -// } - // Add the image preview. - if ($settings['default_video_thumbnail'] && $element['#value']['fid'] != 0) { - $default_thumbnail = file_load($settings['default_video_thumbnail']); -// $element['preview'] = array( -// '#type' => 'markup', -// '#markup' => theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)), -// ); - } - // Title is not necessary for each individual field. - if ($field['cardinality'] != 1) { - unset($element['#title']); - } - // add file elements by widget type - switch ($instance['widget']['type']) { - case 'video_upload': - break; - case 'video_ftp': - break; - } - // Create our thumbnails - video_thumb_process($element, $form_state); - - - // Add our extra fields if in preview mode - if (!empty($item['fid'])) { - video_widget_element_settings($element, $form_state); - } - - // Lets use the clicked_button #submit[0] value here instead and see how that works out for now... - if ($form_state['submitted'] == 1) { - video_widget_process($element, $form_state); - } - return $element; -} - -/** - * Formatters - */ - -/** - * Implementation of CCK's hook_field_formatter_info(). - */ -function video_field_formatter_info() { - $formatters = array( - 'video' => array( - 'label' => t('Video'), - 'field types' => array('video'), - 'settings' => array('video_style' => '', 'video_link' => ''), - ), - 'video_thumbnail' => array( - 'label' => t('Video thumbnail'), - 'field types' => array('video'), - 'settings' => array('video_style' => '', 'video_link' => ''), - ), - //'video_colorbox' => array( - // 'label' => t('Video Thumbnail to Colorbox'), - // 'field types' => array('filefield'), - // 'description' => t('Displays the video thumbnail and adds colorbox support.'), - //), -// 'video_media_js' => array( -// 'label' => t('Video inject with jMedia'), -// 'field types' => array('video'), -// 'description' => t('Displays the video by using jmedia javascript.'), -// ), - ); - return $formatters; -} - -/** - * Implements hook_field_formatter_settings_form(). - */ -function video_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $image_styles = image_style_options(FALSE); - $element['video_style'] = array( - '#title' => t('Video thumbnail style'), - '#type' => 'select', - '#default_value' => $settings['video_style'], - '#empty_option' => t('None (original video thumbnail)'), - '#options' => $image_styles, - ); - - $link_types = array( - 'content' => t('Content'), - 'file' => t('File'), - ); - $element['video_link'] = array( - '#title' => t('Link video or video thumbanil to'), - '#type' => 'select', - '#default_value' => $settings['video_link'], - '#empty_option' => t('Nothing'), - '#options' => $link_types, - ); - - return $element; -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function video_field_formatter_settings_summary($field, $instance, $view_mode) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $summary = array(); - - $image_styles = image_style_options(FALSE); - // Unset possible 'No defined styles' option. - unset($image_styles['']); - // Styles could be lost because of enabled/disabled modules that defines - // their styles in code. - if (isset($image_styles[$settings['video_style']])) { - $summary[] = t('Video thumbnail style: @style', array('@style' => $image_styles[$settings['video_style']])); - } else { - $summary[] = t('Original video thumbnail'); - } - - $link_types = array( - 'content' => t('Linked to content'), - 'file' => t('Linked to video file'), - ); - // Display this setting only if image is linked. - if (isset($link_types[$settings['video_link']])) { - $summary[] = $link_types[$settings['video_link']]; - } - - return implode('
', $summary); -} - -/** - * Implements hook_field_formatter_view(). - */ -function video_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $element = array(); - - // Check if the formatter involves a link. - if ($display['settings']['video_link'] == 'content') { - $uri = entity_uri($entity_type, $entity); - } elseif ($display['settings']['video_link'] == 'file') { - $link_file = TRUE; - } - - // set the display - $theme = $display['type']; - foreach ($items as $delta => $item) { - if (isset($link_file)) { - $uri = array( - 'path' => file_create_url($item['uri']), - 'options' => array(), - ); - } - $element[$delta] = array( - '#theme' => $theme, - '#item' => $item, - '#video_style' => $display['settings']['video_style'], - '#path' => isset($uri) ? $uri : '', - '#entity' => $entity, - '#field' => $field, - '#instance' => $instance - ); - } - return $element; -} \ No newline at end of file diff --git a/includes/video.preset.inc b/includes/video.preset.inc deleted file mode 100644 index 4036c82..0000000 --- a/includes/video.preset.inc +++ /dev/null @@ -1,790 +0,0 @@ - - The preset object. - * @return - The additional form settings that you would like to add to your preset. - */ -function video_preset_default_form($form, &$form_state, $preset) { - $form = array(); - $form['settings']['device_profile'] = array( - '#type' => 'fieldset', - '#title' => t('Output parameter'), - '#description' => t('All output settings are optional. We choose sensible defaults for web and iPhone playback.'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['device_profile']['device_profile'] = array( - '#type' => 'select', - '#title' => t('Device profile'), - '#description' => t('A profile for your target device.'), - '#options' => array( - '0' => 'None', - 'mobile/advanced' => 'mobile/advanced', - 'mobile/baseline' => 'mobile/baseline', - 'mobile/legacy' => 'mobile/legacy', - 'v1/mobile/advanced' => 'v1/mobile/advanced', - 'v1/mobile/baseline' => 'v1/mobile/baseline', - 'v1/mobile/legacy' => 'v1/mobile/legacy', - 'v2/mobile/legacy' => 'v2/mobile/legacy' - ), - '#default_value' => (!empty($preset['settings']['device_profile'])) ? $preset['settings']['device_profile'] : 0 - ); - // video settings - $form['settings']['video'] = array( - '#type' => 'fieldset', - '#title' => t('Video settings'), - '#collapsible' => TRUE, - '#collapsed' => FALSE - ); - $form['settings']['video']['video_codec'] = array( - '#type' => 'select', - '#title' => t('Video codec'), - '#description' => t('The video codec used in the video file can affect the ability to play the video on certain devices. The default codec used is H.264.'), - '#options' => array( - 'h264' => 'H.264 (default)', - 'vp8' => 'VP8', - 'theora' => 'Theora', - 'vp6' => 'VP6', - 'mpeg4' => 'MPEG-4', - 'wmv' => 'WMV' - ), - '#default_value' => (!empty($preset['settings']['video_codec'])) ? $preset['settings']['video_codec'] : 'h264' - ); - $form['settings']['video']['video_quality'] = array( - '#type' => 'select', - '#title' => t('Video quality'), - '#description' => t('A target video quality. Affects bitrate and file size.'), - '#options' => array( - '1 - Poor quality (smaller file)', - '2', - '3 (default)', - '4', - '5 - High quality (larger file)' - ), - '#default_value' => (!empty($preset['settings']['video_quality'])) ? $preset['settings']['video_quality'] : 2 - ); - $form['settings']['video']['video_speed'] = array( - '#type' => 'select', - '#title' => t('Video speed'), - '#description' => t('Speed of encoding. Affects compression.'), - '#options' => array( - '1 - Slow (better compression)', - '2', - '3 (default)', - '4', - '5 - Fast (worse compression)' - ), - '#default_value' => (!empty($preset['settings']['video_speed'])) ? $preset['settings']['video_speed'] : 2 - ); - $form['settings']['video']['width'] = array( - '#type' => 'textfield', - '#title' => t('Width'), - '#description' => t('The maximum width of the output video (in pixels).'), - '#default_value' => !empty($preset['settings']['width']) ? $preset['settings']['width'] : '' - ); - $form['settings']['video']['height'] = array( - '#type' => 'textfield', - '#title' => t('Height'), - '#description' => t('The maximum height of the output video (in pixels).'), - '#default_value' => !empty($preset['settings']['height']) ? $preset['settings']['height'] : '' - ); - $form['settings']['video']['video_aspectmode'] = array( - '#type' => 'select', - '#title' => t('Aspect mode'), - '#description' => t('What to do when aspect ratio of input file does not match the target width/height aspect ratio.'), - '#options' => array( - 'preserve' => 'Preserve aspect ratio (default)', - 'crop' => 'Crop to fit output aspect ratio', - 'pad' => 'Pad (letterbox) to fit output aspect ratio', - 'stretch' => 'Stretch (distort) to output aspect ratio' - ), - '#default_value' => (!empty($preset['settings']['video_aspectmode'])) ? $preset['settings']['video_aspectmode'] : 'preserve' - ); - $form['settings']['video']['video_upscale'] = array( - '#type' => 'checkbox', - '#title' => t('Upscale'), - '#description' => t('If the input file is smaller than the target output, should the file be upscaled to the target size?'), - '#default_value' => !empty($preset['settings']['video_upscale']) ? $preset['settings']['video_upscale'] : '' - ); - // audio settings - $form['settings']['audio'] = array( - '#type' => 'fieldset', - '#title' => t('Audio settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['audio']['audio_codec'] = array( - '#type' => 'select', - '#title' => t('Audio codec'), - '#description' => t('The audio codec to be used.'), - '#options' => array( - 'aac' => 'AAC (default for most cases)', - 'mp3' => 'MP3', - 'vorbis' => 'Vorbis (default for VP8 and Theora)', - 'wma' => 'WMA' - ), - '#default_value' => (!empty($preset['settings']['audio_codec'])) ? $preset['settings']['audio_codec'] : 'h264' - ); - $form['settings']['audio']['audio_quality'] = array( - '#type' => 'select', - '#title' => t('Audio quality'), - '#description' => t('A target audio quality. Affects bitrate and file size.'), - '#options' => array( - '1 - Poor quality (smaller file)', - '2', - '3 (default)', - '4', - '5 - High quality (larger file)' - ), - '#default_value' => (!empty($preset['settings']['audio_quality'])) ? $preset['settings']['audio_quality'] : 2 - ); - // advanced video settings - $form['settings']['adv_video'] = array( - '#type' => 'fieldset', - '#title' => t('Advanced video settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['adv_video']['deinterlace'] = array( - '#type' => 'select', - '#title' => t('Deinterlace'), - '#description' => t('Note that detect mode will auto-detect and deinterlace interlaced content.'), - '#options' => array( - 'detect' => 'Detect (default)', - 'on' => 'On (reduces quality of non-interlaced content)', - 'off' => 'Off' - ), - '#default_value' => (!empty($preset['settings']['deinterlace'])) ? $preset['settings']['deinterlace'] : 'detect' - ); - $form['settings']['adv_video']['max_frame_rate'] = array( - '#type' => 'textfield', - '#title' => t('Maximum frame rate'), - '#description' => t('A maximum frame rate cap (in frames per second).'), - '#default_value' => !empty($preset['settings']['max_frame_rate']) ? $preset['settings']['max_frame_rate'] : '' - ); - $form['settings']['adv_video']['frame_rate'] = array( - '#type' => 'textfield', - '#title' => t('Frame rate'), - '#description' => t('Force a specific output frame rate (in frames per second). For best quality, do not use this setting.'), - '#default_value' => !empty($preset['settings']['frame_rate']) ? $preset['settings']['frame_rate'] : '' - ); - $form['settings']['adv_video']['frame_rate'] = array( - '#type' => 'textfield', - '#title' => t('Frame rate'), - '#description' => t('Force a specific output frame rate (in frames per second). For best quality, do not use this setting.'), - '#default_value' => !empty($preset['settings']['frame_rate']) ? $preset['settings']['frame_rate'] : '' - ); - $form['settings']['adv_video']['video_bitrate'] = array( - '#type' => 'textfield', - '#title' => t('Video bitrate'), - '#description' => t('A target bitrate in kbps. Not necessary if you select a Video Quality setting, unless you want to target a specific bitrate.'), - '#default_value' => !empty($preset['settings']['video_bitrate']) ? $preset['settings']['video_bitrate'] : '' - ); - $form['settings']['adv_video']['bitrate_cap'] = array( - '#type' => 'textfield', - '#title' => t('Bitrate cap'), - '#description' => t('A bitrate cap in kbps, used for streaming servers.'), - '#default_value' => !empty($preset['settings']['bitrate_cap']) ? $preset['settings']['bitrate_cap'] : '' - ); - $form['settings']['adv_video']['buffer_size'] = array( - '#type' => 'textfield', - '#title' => t('Buffer size'), - '#description' => t('The buffer size for the bitrate cap in kbps.'), - '#default_value' => !empty($preset['settings']['buffer_size']) ? $preset['settings']['buffer_size'] : '' - ); - $form['settings']['adv_video']['one_pass'] = array( - '#type' => 'checkbox', - '#title' => t('One pass'), - '#description' => t('Force one-pass encoding when targeting a specific video_bitrate. True or False.'), - '#default_value' => !empty($preset['settings']['one_pass']) ? $preset['settings']['one_pass'] : '' - ); - $form['settings']['adv_video']['skip_video'] = array( - '#type' => 'checkbox', - '#title' => t('Skip video'), - '#description' => t('The video track will be omitted from the output. You can still specify a video format, however, no video track will be present in the resulting file.'), - '#default_value' => !empty($preset['settings']['skip_video']) ? $preset['settings']['skip_video'] : '' - ); - // advanced audio settings - $form['settings']['adv_audio'] = array( - '#type' => 'fieldset', - '#title' => t('Advanced audio settings'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['adv_audio']['audio_bitrate'] = array( - '#type' => 'textfield', - '#title' => t('Audio bitrate'), - '#description' => t('The overall audio bitrate specified as kilobits per second (kbps, e.g. 96 or 160). This value can\'t exceed 160 kbps per channel. 96-160 is usually a good range for stereo output.'), - '#default_value' => !empty($preset['settings']['audio_bitrate']) ? $preset['settings']['audio_bitrate'] : '' - ); - $form['settings']['adv_audio']['audio_channels'] = array( - '#type' => 'select', - '#title' => t('Audio channels'), - '#description' => t('By default we will choose the lesser of the number of audio channels in the input file or 2 (stereo).'), - '#options' => array( - 1 => '1 - Mono', - 2 => '2 - Stereo (default)' - ), - '#default_value' => (!empty($preset['settings']['audio_channels'])) ? $preset['settings']['audio_channels'] : 2 - ); - $form['settings']['adv_audio']['audio_sample_rate'] = array( - '#type' => 'textfield', - '#title' => t('Audio sample rate'), - '#description' => t('The sample rate of the audio in hertz. Manually setting this may cause problems, depending on the selected bitrate and number of channels.'), - '#default_value' => !empty($preset['settings']['audio_sample_rate']) ? $preset['settings']['audio_sample_rate'] : '' - ); - $form['settings']['adv_audio']['skip_audio'] = array( - '#type' => 'checkbox', - '#title' => t('Skip audio'), - '#description' => t('The audio track will be omitted from the output. You must specify a video format and no audio track will be present in the resulting file.'), - '#default_value' => !empty($preset['settings']['skip_audio']) ? $preset['settings']['skip_audio'] : '' - ); - // video optimizations - $form['settings']['vid_optimization'] = array( - '#type' => 'fieldset', - '#title' => t('Video Optimization'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['vid_optimization']['autolevels'] = array( - '#type' => 'checkbox', - '#title' => t('Autolevels'), - '#description' => t('Automatic brightness / contrast correction.'), - '#default_value' => !empty($preset['settings']['autolevels']) ? $preset['settings']['autolevels'] : '' - ); - $form['settings']['vid_optimization']['deblock'] = array( - '#type' => 'checkbox', - '#title' => t('Deblock'), - '#description' => t('Apply deblocking filter. Useful for highly compressed or blocky input videos.'), - '#default_value' => !empty($preset['settings']['deblock']) ? $preset['settings']['deblock'] : '' - ); - $form['settings']['vid_optimization']['denoise'] = array( - '#type' => 'select', - '#title' => t('Denoise'), - '#description' => t('Apply denoise filter. Generally results in slightly better compression, and slightly slower encoding. Beware of any value higher than "Weak" (unless you\'re encoding animation).'), - '#options' => array( - 0 => 'None', - 'weak' => 'Weak - usually OK for general use', - 'medium' => 'Medium', - 'strong' => 'Strong - beware', - 'strongest' => 'Strongest - beware, except for Anime' - ), - '#default_value' => (!empty($preset['settings']['denoise'])) ? $preset['settings']['denoise'] : 2 - ); - // Segmented Streaming - $form['settings']['segmented_streaming'] = array( - '#type' => 'fieldset', - '#title' => t('Segmented Streaming'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['segmented_streaming']['segmented_type'] = array( - '#type' => 'select', - '#title' => t('Type'), - '#description' => t('Set to segmented for HTTP Live Streaming.'), - '#options' => array( - 0 => 'Standard', - 'segmented' => 'segmented' - ), - '#default_value' => (!empty($preset['settings']['segmented_type'])) ? $preset['settings']['segmented_type'] : 0 - ); - $form['settings']['segmented_streaming']['segmented_seconds'] = array( - '#type' => 'textfield', - '#title' => t('Segment Seconds'), - '#description' => t('The maximum duration of each segment in segmented outputs.'), - '#default_value' => !empty($preset['settings']['segmented_seconds']) ? $preset['settings']['segmented_seconds'] : '' - ); - // Create clip - $form['settings']['create_clip'] = array( - '#type' => 'fieldset', - '#title' => t('Create Clip'), - '#collapsible' => TRUE, - '#collapsed' => TRUE - ); - $form['settings']['create_clip']['clip_start'] = array( - '#type' => 'textfield', - '#title' => t('Start clip'), - '#description' => t('The starting point of a subclip (in timecode or number of seconds).'), - '#default_value' => !empty($preset['settings']['clip_start']) ? $preset['settings']['clip_start'] : '' - ); - $form['settings']['create_clip']['clip_length'] = array( - '#type' => 'textfield', - '#title' => t('Clip length '), - '#description' => t('The length of the subclip (in timecode or number of seconds).'), - '#default_value' => !empty($preset['settings']['clip_length']) ? $preset['settings']['clip_length'] : '' - ); - // Command line parameters - $form['settings']['command_line'] = array( - '#type' => 'fieldset', - '#title' => t('Command line options'), - '#collapsible' => TRUE, - '#collapsed' => FALSE - ); - $tokes = array( - '!cmd_path - Path to transcoder', - '!videofile - Input video file', - '!convertfile - Output video file', - '!width - Width of output video', - '!height - Height of output video' - ); - $form['settings']['command_line']['cli_code'] = array( - '#type' => 'textarea', - '#title' => t('Command line codes to run'), - '#description' => t('Please add command line codes each to run separated by a new line.') . theme('item_list', array('items' => $tokes, 'title' => 'Available Tokes')), - '#default_value' => !empty($preset['settings']['cli_code']) ? $preset['settings']['cli_code'] : '!cmd_path -i !videofile -s !widthx!height -r 15 -b 250 -ar 22050 -ab 48 !convertfile' - ); - return $form; -} - -/** - * Menu callback: video Module administration. - */ -function video_presets_overview() { - $presets = video_preset_get_presets(); - - if (count($presets) > 0) { - $header = array(t('Preset Name'), t('Description'), array('data' => t('Operations'), 'colspan' => '3')); - $rows = array(); - foreach ($presets as $pid => $preset) { - $row = array(); - $row[] = check_plain($preset['name']); - $row[] = array('data' => filter_xss_admin($preset['description']), 'class' => 'description'); - $row[] = array('data' => l(t('edit'), 'admin/config/media/video/presets/preset/' . $preset['name'])); - - if (!isset($preset['default'])) { - $row[] = array('data' => l(t('delete'), 'admin/config/media/video/presets/preset/' . $preset['name'] . '/delete')); - } - - $row[] = array('data' => l(t('export'), 'admin/config/media/video/presets/preset/' . $preset['name'] . '/export')); - $rows[] = $row; - } - return theme('table', array('header' => $header, 'rows' => $rows)); - } else { - return t('No Preset were found. Please use the !create_link link to create - a new video preset, or upload an existing Feature to your modules directory.', - array('!create_link' => l(t('Create Video Preset'), 'admin/config/media/video/presets/add'))); - } -} - -/** - * Preset form - * @param $form - * @param $form_state - * @param $preset - * @return string - */ -function video_preset_form($form, &$form_state, $preset = false) { - $form = array(); - // basic preset details - $form['preset'] = array( - '#type' => 'fieldset', - '#title' => t('Preset information'), - '#weight' => -10, - ); - if (isset($preset['pid'])) { - $form['preset']['pid'] = array( - '#type' => 'value', - '#value' => $preset['pid'], - ); - } elseif (video_is_default_preset($preset['name'])) { - $form['preset']['default'] = array( - '#type' => 'value', - '#value' => TRUE, - ); - } - $form['preset']['name'] = array( - '#type' => 'textfield', - '#title' => t('Preset name'), - '#maxlength' => VIDEO_PRESET_MAX_LENGTH, - '#description' => t('Spaces are NOT allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), - '#required' => TRUE, - '#weight' => -10, - '#element_validate' => array('_video_preset_name_validate'), - '#default_value' => !empty($preset['name']) ? $preset['name'] : '' - ); - - $form['preset']['description'] = array( - '#type' => 'textfield', - '#title' => t('Description'), - '#description' => t('Add a brief description to your preset name.'), - '#weight' => -9, - '#default_value' => !empty($preset['description']) ? $preset['description'] : '' - ); - - // Preset settings - $form += video_preset_default_form($form, $form_state, $preset); - - // Buttons - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Save Preset'), - '#weight' => 30, - ); - - $form['delete'] = array( - '#type' => 'submit', - '#value' => t('Delete'), - '#weight' => 40, - '#submit' => array('video_preset_delete_submit'), - ); - - // Add the form submit handler. - $form['#submit'][] = 'video_preset_submit'; - $form['#validate'][] = 'video_preset_validate'; - return $form; -} - -/** - * Validation for the preset form. - */ -function video_preset_validate($form, &$form_state) { - -} - -/** - * Flatten the settings array. - * - * @param $array - * @param $return - * @return - */ -function video_preset_array_flatten($array, $return=array()) { - foreach ($array as $key => $value) { - if (is_array($value)) { - $return = video_preset_array_flatten($value, $return); - } else { - $return[$key] = $value; - } - } - return $return; -} - -/** - * Submit handler for the preset form. - */ -function video_preset_submit($form, &$form_state) { - $preset = array(); - if (isset($form_state['values']['pid'])) { - $preset['pid'] = $form_state['values']['pid']; - } - $preset['name'] = $form_state['values']['name']; - $preset['description'] = $form_state['values']['description']; - // unset unwanted values saved to database - unset($form_state['values']['pid'], $form_state['values']['name'], - $form_state['values']['description'], $form_state['values']['submit'], - $form_state['values']['delete'], $form_state['values']['form_build_id'], - $form_state['values']['form_token'], $form_state['values']['form_id'], - $form_state['values']['op']); - $preset['settings'] = video_preset_array_flatten($form_state['values']); - - // Save this preset. - video_preset_save($preset); - drupal_set_message(t('Preset !preset successfully saved.', array('!preset' => $preset['name']))); - $form_state['redirect'] = 'admin/config/media/video/presets'; -} - -/** - * Button sumit function: handle the 'Delete' button on the preset form. - */ -function video_preset_delete_submit($form, &$form_state) { - $preset['name'] = $form_state['values']['name']; - $form_state['redirect'] = 'admin/config/media/video/presets/preset/' . $preset['name'] . '/delete'; -} - -/** - * Menu callback; delete a single preset. - */ -function video_preset_delete_confirm($form, &$form_state, $preset) { - $form['name'] = array('#type' => 'value', '#value' => $preset['name']); - $message = t('Are you sure you want to delete the preset %name?', array('%name' => $preset['name'])); - $caption = '

' . t('This action cannot be undone.') . '

'; - return confirm_form($form, $message, 'admin/config/media/video/presets', $caption, t('Delete')); -} - -/** - * Execute preset deletion - */ -function video_preset_delete_confirm_submit($form, &$form_state) { - if ($form_state['values']['confirm']) { - video_preset_delete($form_state['values']['name']); - } - - $form_state['redirect'] = 'admin/config/media/video/presets'; -} - -/** - * Validation for the preset form. - */ -function _video_preset_name_validate($element, &$form_state) { - $error = video_validate_preset_name($form_state['values']['name']); - if ($error && !isset($form_state['values']['pid']) && !isset ($form_state['values']['default'])) { - form_set_error('name', $error); - } -} - -/** - * Import's a preset. - */ -function video_preset_import_form($form, &$form_state) { - $form['preset'] = array( - '#title' => t('Preset Code'), - '#type' => 'textarea', - '#rows' => 10, - '#description' => t('Copy the export text and paste it into this text field to import a new preset.'), - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Import Preset'), - '#weight' => 30, - ); - - $form['#submit'][] = 'video_preset_import_submit'; - $form['#validate'][] = 'video_preset_import_validate'; - - return $form; -} - -/** - * Validation for the preset import form. - */ -function video_preset_import_validate($form, &$form_state) { - $preset = ''; - - // Get the preset that they declared in the text field. - ob_start(); - eval($form_state['values']['preset']); - ob_end_clean(); - - if (is_array($preset)) { - $name = isset($preset['name']) ? $preset['name'] : ''; - if ($error = video_validate_preset_name($name)) { - form_set_error('name', $error); - } - } else { - form_set_error('name', 'Invalid preset import.'); - } - - $form_state['preset'] = &$preset; -} - -/** - * Submit handler for the preset import form. - */ -function video_preset_import_submit($form, &$form_state) { - $preset = $form_state['preset']; - video_preset_save($preset); - $form_state['redirect'] = 'admin/config/media/video/presets/preset/' . $preset['name']; -} - -/** - * The preset export form. - */ -function video_preset_export_form($form, &$form_state, $preset) { - // Unset the unnecessary elements. - unset($preset['pid']); - unset($preset['default']); - - // Get the code string representation. - $code = var_export($preset, true); - - // Make sure to format the arrays like drupal. - $code = str_replace("=> \n ", '=> ', $code); - - // Add the preset variable. - $code = '$preset = ' . $code . ';'; - - $lines = substr_count($code, "\n"); - $form['export'] = array( - '#title' => t('Export Preset'), - '#type' => 'textarea', - '#value' => $code, - '#rows' => $lines, - '#description' => t('Copy the export text and paste it into another preset using the import function.'), - ); - - // Return the form. - return $form; -} - -/** - * Get's the player settings for the given player. - */ -function video_player_settings_form($preset) { - $settings_form = $preset['player'] . '_player_settings_form'; - if (function_exists($settings_form)) { - return $settings_form($preset); - } - return array(); -} - -/** - * Title callback for a preset. - */ -function video_preset_page_title($preset) { - return $preset['name']; -} - -/** - * Saves a new preset. - */ -function video_preset_save($preset) { - // If they provide the pid, then this needs to be an update. - $pid = (isset($preset['pid']) && $preset['pid']) ? array('pid') : array(); - - // Save or update a preset. - drupal_write_record('video_preset', $preset, $pid); -} - -/** - * Returns the default presets. - * - * @return - */ -function video_preset_get_default_presets() { - $default_presets = module_invoke_all('video_default_presets'); - drupal_alter('video_default_presets', $default_presets); - return $default_presets; -} - -/** - * Gets a list of all presets. - */ -function video_preset_get_presets() { - $presets = array(); - $normal_presets = array(); - - // Get all the presets from the database. - $result = db_select('video_preset', 'p') - ->fields('p') - ->orderBy('p.name', 'ASC') - ->execute(); - - // Iterate through all the presets and structure them in an array. - foreach ($result as $preset) { - $preset = (array) $preset; - $preset['settings'] = $preset['settings'] ? unserialize($preset['settings']) : array(); - $presets[$preset['pid']] = $preset; - $normal_presets[$preset['name']] = $preset['pid']; - } - - // Now allow other modules to add their default presets. - foreach (video_preset_get_default_presets () as $preset) { - // adding default TRUE - $preset['default'] = TRUE; - if (!empty($preset['name']) && !isset($normal_presets[$preset['name']])) { - $presets[$preset['name']] = $preset; - } - } - - return $presets; -} - -/** - * Get's the preset. - */ -function video_get_preset($preset_name) { - // Get the preset from the database. - $preset = db_select('video_preset', 'p') - ->fields('p') - ->condition('p.name', $preset_name) - ->execute() - ->fetchAssoc(); - if ($preset) { - $preset['settings'] = $preset['settings'] ? unserialize($preset['settings']) : array(); - } else { - // Get all of the default presets. - $default_presets = video_preset_get_default_presets(); - - // Check to see if this preset exists. - if (isset($default_presets[$preset_name])) { - // Make this our preset - $preset = $default_presets[$preset_name]; - } - } - - // Return the preset. - return $preset; -} - -/** - * Deletes a preset - */ -function video_preset_delete($preset_name) { - // Delete the preset. - db_delete('video_preset') - ->condition('name', $preset_name) - ->execute(); - - // Rebuild Theme Registry - drupal_theme_rebuild(); -} - -/** - * Checks to see if another preset is already taken. - */ -function video_preset_name_exists($preset_name) { - - // Get the default presets. - $default_presets = video_preset_get_default_presets(); - - // See if there is a default preset name. - if ($default_presets && isset($default_presets[$preset_name])) { - return true; - } else { - return (bool) db_select('video_preset', 'p') - ->fields('p') - ->condition('p.name', $preset_name) - ->range(0, 1) - ->execute() - ->fetchField(); - } -} - -/** - * Verify the syntax of the given prefix name. - * - * Borrowed from the user.module. :) - */ -function video_validate_preset_name($name) { - if (!$name) { - return t('You must enter a preset.'); - } - if (video_preset_name_exists($name)) { - return t('The preset name %name is already taken.', array('%name' => $name)); - } - if (strpos($name, ' ') !== FALSE) { - return t('The preset name cannot contain a space.'); - } - if (is_numeric($name[0])) { - return t('The preset name cannot begin with a number.'); - } - if (preg_match('/[^a-z0-9_]/i', $name)) { - return t('The preset name contains an illegal character.'); - } - if (drupal_strlen($name) > VIDEO_PRESET_MAX_LENGTH) { - return t('The preset name %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => VIDEO_PRESET_MAX_LENGTH)); - } -} - -/** - * Check for default preset - * @param $preset_name - * @return - */ -function video_is_default_preset($preset_name) { - // Get the default presets. - $default_presets = video_preset_get_default_presets(); - - // See if there is a default preset name. - if ($default_presets && isset($default_presets[$preset_name])) - return TRUE; - else - return FALSE; -} diff --git a/modules/video_ui/video.admin.inc b/modules/video_ui/video.admin.inc new file mode 100644 index 0000000..0f55dea --- /dev/null +++ b/modules/video_ui/video.admin.inc @@ -0,0 +1,174 @@ + + */ +function video_transcoder_admin_settings() { + $transcoder = new video_transcoder; + $form = $transcoder->admin_settings(); + return system_settings_form($form); +} + +/** + * Form API callback to validate the upload settings form. + */ +function video_transcoder_admin_settings_validate($form, &$form_state) { + // check ffmpeg_wrapper module installed or not + if ($form_state['values']['video_convertor'] == 'video_ffmpeg_wrapper' && !module_exists('ffmpeg_wrapper')) { + form_set_error('video_convertor', t('You need to download and install the !ffmpeg_wrapper module to enable this option.', array('!ffmpeg_wrapper' => l(t('FFMPEG Wrapper'), 'http://drupal.org/project/ffmpeg_wrapper')))); + } + + // add vallidations by trnacoder interface + $transcoder = $form_state['values']['video_convertor']; + $transcoder = new video_transcoder($transcoder); + $transcoder->admin_settings_validate($form, $form_state); +} + +/** + * Video preset admin settings + * @return + */ +function video_preset_admin_settings() { + $preset = new video_preset(); + $form = $preset->admin_settings(); + return system_settings_form($form); +} + +/** + * Video general admin settings + * @return + */ +function video_general_admin_settings() { + $form = array(); + $form['video_autoplay'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically start video on page load'), + '#default_value' => variable_get('video_autoplay', FALSE), + '#description' => t('Start the video when the page and video loads') + ); + $form['video_autobuffering'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically start video buffering'), + '#default_value' => variable_get('video_autobuffering', TRUE), + '#description' => t('Start buffering video when the page and video loads') + ); + $form['video_bypass_conversion'] = array( + '#type' => 'checkbox', + '#title' => t('Bypass Video Conversion'), + '#default_value' => variable_get('video_bypass_conversion', FALSE), + '#description' => t('Bypass video conversion when creating videos.') + ); + $form['video_convert_on_save'] = array( + '#type' => 'checkbox', + '#title' => t('Video Convert on Node Submit'), + '#default_value' => variable_get('video_convert_on_save', FALSE), + '#description' => t('Convert videos on node submit.') + ); + $form['video_use_default_thumb'] = array( + '#type' => 'checkbox', + '#title' => t('Override Auto Thumbnails with Default'), + '#default_value' => variable_get('video_use_default_thumb', FALSE), + '#description' => t('Override auto thumbnails with default thumbnail.') + ); + return system_settings_form($form); +} + +/** + * Video player admin settings + * @return + */ +function video_players_admin_settings() { + $form = array(); + $form['extensions'] = array( + '#type' => 'fieldset', + '#title' => t('Video Extensions'), + '#description' => t('Here you can map specific players to each video extension type.'), + ); + //lets get all our supported extensions and players. + $extensions = video_video_extensions(); + $players = video_video_players(); + $flv_players = video_video_flv_players(); + + foreach ($extensions as $ext => $player) { + $form['extensions']['video_extension_' . $ext] = array( + '#type' => 'select', + '#title' => t('Extension:') . ' ' . $ext, + '#default_value' => variable_get('video_extension_' . $ext, $player), + '#options' => $players, + '#prefix' => '
', + '#suffix' => '
', + ); + + $form['extensions']['video_extension_' . $ext . '_flash_player'] = array( + '#type' => !empty($flv_players) ? 'radios' : 'markup', + '#title' => t('Flash Player for') . ' ' . $ext, + '#value' => !empty($flv_players) ? '' : t('No flash players detected.
You need to install !swf_tools or !flowplayer.', array('!swf_tools' => l(t('SWF Tools'), 'http://www.drupal.org/project/swftools'), '!flowplayer' => l(t('Flowplayer'), 'http://www.drupal.org/project/flowplayer'))), + '#options' => $flv_players, + '#default_value' => variable_get('video_extension_' . $ext . '_flash_player', ''), + '#prefix' => '
', + '#suffix' => '
', + ); + } + return system_settings_form($form); +} + +/** + * Video Metadata admin settings + * @return + */ +function video_metadata_admin_settings() { + $metadata = new video_metadata; + $form = $metadata->admin_settings(); + return system_settings_form($form); +} + +function video_metadata_admin_settings_validate($form, &$form_state) { + // add vallidations by metadata interface + $metadata = $form_state['values']['video_metadata']; + $metadata = new video_metadata($metadata); + $metadata->admin_settings_validate($form, $form_state); +} + +/** + * Video cron admin settings + * @return + */ +function video_cron_admin_settings() { + $form = array(); + $form['video_cron'] = array( + '#type' => 'checkbox', + '#title' => t('Use Drupals built in cron.'), + '#default_value' => variable_get('video_cron', TRUE), + '#description' => t('If you would like to use Drupals built in cron hook, check this box. Please be warned that transcoding videos is very resource intensive. If you use poor mans cron, I highly discourage this option. I also suggest you setup your cron to call this function through CLI instead of WGET.'), + ); + $form['video_ffmpeg_instances'] = array( + '#type' => 'textfield', + '#title' => t('Total videos to convert during each cron process.'), + '#default_value' => variable_get('video_ffmpeg_instances', 5), + '#description' => t('How many videos do you want to process on each cron run? Either through hook_cron or the video_scheduler.php.'), + ); + return system_settings_form($form); +} + +/** + * File system admin settings + * @return + */ +function video_filesystem_admin_settings() { + $filesystem = new video_filesystem; + $form = $filesystem->admin_settings(); + return system_settings_form($form); +} + +function video_filesystem_admin_settings_validate($form, &$form_state) { + // add vallidations by metadata interface + $filesystem = $form_state['values']['video_filesystem']; + $filesystem = new video_filesystem($filesystem); + $filesystem->admin_settings_validate($form, $form_state); +} \ No newline at end of file diff --git a/modules/video_ui/video.preset.inc b/modules/video_ui/video.preset.inc new file mode 100644 index 0000000..4036c82 --- /dev/null +++ b/modules/video_ui/video.preset.inc @@ -0,0 +1,790 @@ + - The preset object. + * @return - The additional form settings that you would like to add to your preset. + */ +function video_preset_default_form($form, &$form_state, $preset) { + $form = array(); + $form['settings']['device_profile'] = array( + '#type' => 'fieldset', + '#title' => t('Output parameter'), + '#description' => t('All output settings are optional. We choose sensible defaults for web and iPhone playback.'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['device_profile']['device_profile'] = array( + '#type' => 'select', + '#title' => t('Device profile'), + '#description' => t('A profile for your target device.'), + '#options' => array( + '0' => 'None', + 'mobile/advanced' => 'mobile/advanced', + 'mobile/baseline' => 'mobile/baseline', + 'mobile/legacy' => 'mobile/legacy', + 'v1/mobile/advanced' => 'v1/mobile/advanced', + 'v1/mobile/baseline' => 'v1/mobile/baseline', + 'v1/mobile/legacy' => 'v1/mobile/legacy', + 'v2/mobile/legacy' => 'v2/mobile/legacy' + ), + '#default_value' => (!empty($preset['settings']['device_profile'])) ? $preset['settings']['device_profile'] : 0 + ); + // video settings + $form['settings']['video'] = array( + '#type' => 'fieldset', + '#title' => t('Video settings'), + '#collapsible' => TRUE, + '#collapsed' => FALSE + ); + $form['settings']['video']['video_codec'] = array( + '#type' => 'select', + '#title' => t('Video codec'), + '#description' => t('The video codec used in the video file can affect the ability to play the video on certain devices. The default codec used is H.264.'), + '#options' => array( + 'h264' => 'H.264 (default)', + 'vp8' => 'VP8', + 'theora' => 'Theora', + 'vp6' => 'VP6', + 'mpeg4' => 'MPEG-4', + 'wmv' => 'WMV' + ), + '#default_value' => (!empty($preset['settings']['video_codec'])) ? $preset['settings']['video_codec'] : 'h264' + ); + $form['settings']['video']['video_quality'] = array( + '#type' => 'select', + '#title' => t('Video quality'), + '#description' => t('A target video quality. Affects bitrate and file size.'), + '#options' => array( + '1 - Poor quality (smaller file)', + '2', + '3 (default)', + '4', + '5 - High quality (larger file)' + ), + '#default_value' => (!empty($preset['settings']['video_quality'])) ? $preset['settings']['video_quality'] : 2 + ); + $form['settings']['video']['video_speed'] = array( + '#type' => 'select', + '#title' => t('Video speed'), + '#description' => t('Speed of encoding. Affects compression.'), + '#options' => array( + '1 - Slow (better compression)', + '2', + '3 (default)', + '4', + '5 - Fast (worse compression)' + ), + '#default_value' => (!empty($preset['settings']['video_speed'])) ? $preset['settings']['video_speed'] : 2 + ); + $form['settings']['video']['width'] = array( + '#type' => 'textfield', + '#title' => t('Width'), + '#description' => t('The maximum width of the output video (in pixels).'), + '#default_value' => !empty($preset['settings']['width']) ? $preset['settings']['width'] : '' + ); + $form['settings']['video']['height'] = array( + '#type' => 'textfield', + '#title' => t('Height'), + '#description' => t('The maximum height of the output video (in pixels).'), + '#default_value' => !empty($preset['settings']['height']) ? $preset['settings']['height'] : '' + ); + $form['settings']['video']['video_aspectmode'] = array( + '#type' => 'select', + '#title' => t('Aspect mode'), + '#description' => t('What to do when aspect ratio of input file does not match the target width/height aspect ratio.'), + '#options' => array( + 'preserve' => 'Preserve aspect ratio (default)', + 'crop' => 'Crop to fit output aspect ratio', + 'pad' => 'Pad (letterbox) to fit output aspect ratio', + 'stretch' => 'Stretch (distort) to output aspect ratio' + ), + '#default_value' => (!empty($preset['settings']['video_aspectmode'])) ? $preset['settings']['video_aspectmode'] : 'preserve' + ); + $form['settings']['video']['video_upscale'] = array( + '#type' => 'checkbox', + '#title' => t('Upscale'), + '#description' => t('If the input file is smaller than the target output, should the file be upscaled to the target size?'), + '#default_value' => !empty($preset['settings']['video_upscale']) ? $preset['settings']['video_upscale'] : '' + ); + // audio settings + $form['settings']['audio'] = array( + '#type' => 'fieldset', + '#title' => t('Audio settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['audio']['audio_codec'] = array( + '#type' => 'select', + '#title' => t('Audio codec'), + '#description' => t('The audio codec to be used.'), + '#options' => array( + 'aac' => 'AAC (default for most cases)', + 'mp3' => 'MP3', + 'vorbis' => 'Vorbis (default for VP8 and Theora)', + 'wma' => 'WMA' + ), + '#default_value' => (!empty($preset['settings']['audio_codec'])) ? $preset['settings']['audio_codec'] : 'h264' + ); + $form['settings']['audio']['audio_quality'] = array( + '#type' => 'select', + '#title' => t('Audio quality'), + '#description' => t('A target audio quality. Affects bitrate and file size.'), + '#options' => array( + '1 - Poor quality (smaller file)', + '2', + '3 (default)', + '4', + '5 - High quality (larger file)' + ), + '#default_value' => (!empty($preset['settings']['audio_quality'])) ? $preset['settings']['audio_quality'] : 2 + ); + // advanced video settings + $form['settings']['adv_video'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced video settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['adv_video']['deinterlace'] = array( + '#type' => 'select', + '#title' => t('Deinterlace'), + '#description' => t('Note that detect mode will auto-detect and deinterlace interlaced content.'), + '#options' => array( + 'detect' => 'Detect (default)', + 'on' => 'On (reduces quality of non-interlaced content)', + 'off' => 'Off' + ), + '#default_value' => (!empty($preset['settings']['deinterlace'])) ? $preset['settings']['deinterlace'] : 'detect' + ); + $form['settings']['adv_video']['max_frame_rate'] = array( + '#type' => 'textfield', + '#title' => t('Maximum frame rate'), + '#description' => t('A maximum frame rate cap (in frames per second).'), + '#default_value' => !empty($preset['settings']['max_frame_rate']) ? $preset['settings']['max_frame_rate'] : '' + ); + $form['settings']['adv_video']['frame_rate'] = array( + '#type' => 'textfield', + '#title' => t('Frame rate'), + '#description' => t('Force a specific output frame rate (in frames per second). For best quality, do not use this setting.'), + '#default_value' => !empty($preset['settings']['frame_rate']) ? $preset['settings']['frame_rate'] : '' + ); + $form['settings']['adv_video']['frame_rate'] = array( + '#type' => 'textfield', + '#title' => t('Frame rate'), + '#description' => t('Force a specific output frame rate (in frames per second). For best quality, do not use this setting.'), + '#default_value' => !empty($preset['settings']['frame_rate']) ? $preset['settings']['frame_rate'] : '' + ); + $form['settings']['adv_video']['video_bitrate'] = array( + '#type' => 'textfield', + '#title' => t('Video bitrate'), + '#description' => t('A target bitrate in kbps. Not necessary if you select a Video Quality setting, unless you want to target a specific bitrate.'), + '#default_value' => !empty($preset['settings']['video_bitrate']) ? $preset['settings']['video_bitrate'] : '' + ); + $form['settings']['adv_video']['bitrate_cap'] = array( + '#type' => 'textfield', + '#title' => t('Bitrate cap'), + '#description' => t('A bitrate cap in kbps, used for streaming servers.'), + '#default_value' => !empty($preset['settings']['bitrate_cap']) ? $preset['settings']['bitrate_cap'] : '' + ); + $form['settings']['adv_video']['buffer_size'] = array( + '#type' => 'textfield', + '#title' => t('Buffer size'), + '#description' => t('The buffer size for the bitrate cap in kbps.'), + '#default_value' => !empty($preset['settings']['buffer_size']) ? $preset['settings']['buffer_size'] : '' + ); + $form['settings']['adv_video']['one_pass'] = array( + '#type' => 'checkbox', + '#title' => t('One pass'), + '#description' => t('Force one-pass encoding when targeting a specific video_bitrate. True or False.'), + '#default_value' => !empty($preset['settings']['one_pass']) ? $preset['settings']['one_pass'] : '' + ); + $form['settings']['adv_video']['skip_video'] = array( + '#type' => 'checkbox', + '#title' => t('Skip video'), + '#description' => t('The video track will be omitted from the output. You can still specify a video format, however, no video track will be present in the resulting file.'), + '#default_value' => !empty($preset['settings']['skip_video']) ? $preset['settings']['skip_video'] : '' + ); + // advanced audio settings + $form['settings']['adv_audio'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced audio settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['adv_audio']['audio_bitrate'] = array( + '#type' => 'textfield', + '#title' => t('Audio bitrate'), + '#description' => t('The overall audio bitrate specified as kilobits per second (kbps, e.g. 96 or 160). This value can\'t exceed 160 kbps per channel. 96-160 is usually a good range for stereo output.'), + '#default_value' => !empty($preset['settings']['audio_bitrate']) ? $preset['settings']['audio_bitrate'] : '' + ); + $form['settings']['adv_audio']['audio_channels'] = array( + '#type' => 'select', + '#title' => t('Audio channels'), + '#description' => t('By default we will choose the lesser of the number of audio channels in the input file or 2 (stereo).'), + '#options' => array( + 1 => '1 - Mono', + 2 => '2 - Stereo (default)' + ), + '#default_value' => (!empty($preset['settings']['audio_channels'])) ? $preset['settings']['audio_channels'] : 2 + ); + $form['settings']['adv_audio']['audio_sample_rate'] = array( + '#type' => 'textfield', + '#title' => t('Audio sample rate'), + '#description' => t('The sample rate of the audio in hertz. Manually setting this may cause problems, depending on the selected bitrate and number of channels.'), + '#default_value' => !empty($preset['settings']['audio_sample_rate']) ? $preset['settings']['audio_sample_rate'] : '' + ); + $form['settings']['adv_audio']['skip_audio'] = array( + '#type' => 'checkbox', + '#title' => t('Skip audio'), + '#description' => t('The audio track will be omitted from the output. You must specify a video format and no audio track will be present in the resulting file.'), + '#default_value' => !empty($preset['settings']['skip_audio']) ? $preset['settings']['skip_audio'] : '' + ); + // video optimizations + $form['settings']['vid_optimization'] = array( + '#type' => 'fieldset', + '#title' => t('Video Optimization'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['vid_optimization']['autolevels'] = array( + '#type' => 'checkbox', + '#title' => t('Autolevels'), + '#description' => t('Automatic brightness / contrast correction.'), + '#default_value' => !empty($preset['settings']['autolevels']) ? $preset['settings']['autolevels'] : '' + ); + $form['settings']['vid_optimization']['deblock'] = array( + '#type' => 'checkbox', + '#title' => t('Deblock'), + '#description' => t('Apply deblocking filter. Useful for highly compressed or blocky input videos.'), + '#default_value' => !empty($preset['settings']['deblock']) ? $preset['settings']['deblock'] : '' + ); + $form['settings']['vid_optimization']['denoise'] = array( + '#type' => 'select', + '#title' => t('Denoise'), + '#description' => t('Apply denoise filter. Generally results in slightly better compression, and slightly slower encoding. Beware of any value higher than "Weak" (unless you\'re encoding animation).'), + '#options' => array( + 0 => 'None', + 'weak' => 'Weak - usually OK for general use', + 'medium' => 'Medium', + 'strong' => 'Strong - beware', + 'strongest' => 'Strongest - beware, except for Anime' + ), + '#default_value' => (!empty($preset['settings']['denoise'])) ? $preset['settings']['denoise'] : 2 + ); + // Segmented Streaming + $form['settings']['segmented_streaming'] = array( + '#type' => 'fieldset', + '#title' => t('Segmented Streaming'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['segmented_streaming']['segmented_type'] = array( + '#type' => 'select', + '#title' => t('Type'), + '#description' => t('Set to segmented for HTTP Live Streaming.'), + '#options' => array( + 0 => 'Standard', + 'segmented' => 'segmented' + ), + '#default_value' => (!empty($preset['settings']['segmented_type'])) ? $preset['settings']['segmented_type'] : 0 + ); + $form['settings']['segmented_streaming']['segmented_seconds'] = array( + '#type' => 'textfield', + '#title' => t('Segment Seconds'), + '#description' => t('The maximum duration of each segment in segmented outputs.'), + '#default_value' => !empty($preset['settings']['segmented_seconds']) ? $preset['settings']['segmented_seconds'] : '' + ); + // Create clip + $form['settings']['create_clip'] = array( + '#type' => 'fieldset', + '#title' => t('Create Clip'), + '#collapsible' => TRUE, + '#collapsed' => TRUE + ); + $form['settings']['create_clip']['clip_start'] = array( + '#type' => 'textfield', + '#title' => t('Start clip'), + '#description' => t('The starting point of a subclip (in timecode or number of seconds).'), + '#default_value' => !empty($preset['settings']['clip_start']) ? $preset['settings']['clip_start'] : '' + ); + $form['settings']['create_clip']['clip_length'] = array( + '#type' => 'textfield', + '#title' => t('Clip length '), + '#description' => t('The length of the subclip (in timecode or number of seconds).'), + '#default_value' => !empty($preset['settings']['clip_length']) ? $preset['settings']['clip_length'] : '' + ); + // Command line parameters + $form['settings']['command_line'] = array( + '#type' => 'fieldset', + '#title' => t('Command line options'), + '#collapsible' => TRUE, + '#collapsed' => FALSE + ); + $tokes = array( + '!cmd_path - Path to transcoder', + '!videofile - Input video file', + '!convertfile - Output video file', + '!width - Width of output video', + '!height - Height of output video' + ); + $form['settings']['command_line']['cli_code'] = array( + '#type' => 'textarea', + '#title' => t('Command line codes to run'), + '#description' => t('Please add command line codes each to run separated by a new line.') . theme('item_list', array('items' => $tokes, 'title' => 'Available Tokes')), + '#default_value' => !empty($preset['settings']['cli_code']) ? $preset['settings']['cli_code'] : '!cmd_path -i !videofile -s !widthx!height -r 15 -b 250 -ar 22050 -ab 48 !convertfile' + ); + return $form; +} + +/** + * Menu callback: video Module administration. + */ +function video_presets_overview() { + $presets = video_preset_get_presets(); + + if (count($presets) > 0) { + $header = array(t('Preset Name'), t('Description'), array('data' => t('Operations'), 'colspan' => '3')); + $rows = array(); + foreach ($presets as $pid => $preset) { + $row = array(); + $row[] = check_plain($preset['name']); + $row[] = array('data' => filter_xss_admin($preset['description']), 'class' => 'description'); + $row[] = array('data' => l(t('edit'), 'admin/config/media/video/presets/preset/' . $preset['name'])); + + if (!isset($preset['default'])) { + $row[] = array('data' => l(t('delete'), 'admin/config/media/video/presets/preset/' . $preset['name'] . '/delete')); + } + + $row[] = array('data' => l(t('export'), 'admin/config/media/video/presets/preset/' . $preset['name'] . '/export')); + $rows[] = $row; + } + return theme('table', array('header' => $header, 'rows' => $rows)); + } else { + return t('No Preset were found. Please use the !create_link link to create + a new video preset, or upload an existing Feature to your modules directory.', + array('!create_link' => l(t('Create Video Preset'), 'admin/config/media/video/presets/add'))); + } +} + +/** + * Preset form + * @param $form + * @param $form_state + * @param $preset + * @return string + */ +function video_preset_form($form, &$form_state, $preset = false) { + $form = array(); + // basic preset details + $form['preset'] = array( + '#type' => 'fieldset', + '#title' => t('Preset information'), + '#weight' => -10, + ); + if (isset($preset['pid'])) { + $form['preset']['pid'] = array( + '#type' => 'value', + '#value' => $preset['pid'], + ); + } elseif (video_is_default_preset($preset['name'])) { + $form['preset']['default'] = array( + '#type' => 'value', + '#value' => TRUE, + ); + } + $form['preset']['name'] = array( + '#type' => 'textfield', + '#title' => t('Preset name'), + '#maxlength' => VIDEO_PRESET_MAX_LENGTH, + '#description' => t('Spaces are NOT allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'), + '#required' => TRUE, + '#weight' => -10, + '#element_validate' => array('_video_preset_name_validate'), + '#default_value' => !empty($preset['name']) ? $preset['name'] : '' + ); + + $form['preset']['description'] = array( + '#type' => 'textfield', + '#title' => t('Description'), + '#description' => t('Add a brief description to your preset name.'), + '#weight' => -9, + '#default_value' => !empty($preset['description']) ? $preset['description'] : '' + ); + + // Preset settings + $form += video_preset_default_form($form, $form_state, $preset); + + // Buttons + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save Preset'), + '#weight' => 30, + ); + + $form['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + '#weight' => 40, + '#submit' => array('video_preset_delete_submit'), + ); + + // Add the form submit handler. + $form['#submit'][] = 'video_preset_submit'; + $form['#validate'][] = 'video_preset_validate'; + return $form; +} + +/** + * Validation for the preset form. + */ +function video_preset_validate($form, &$form_state) { + +} + +/** + * Flatten the settings array. + * + * @param $array + * @param $return + * @return + */ +function video_preset_array_flatten($array, $return=array()) { + foreach ($array as $key => $value) { + if (is_array($value)) { + $return = video_preset_array_flatten($value, $return); + } else { + $return[$key] = $value; + } + } + return $return; +} + +/** + * Submit handler for the preset form. + */ +function video_preset_submit($form, &$form_state) { + $preset = array(); + if (isset($form_state['values']['pid'])) { + $preset['pid'] = $form_state['values']['pid']; + } + $preset['name'] = $form_state['values']['name']; + $preset['description'] = $form_state['values']['description']; + // unset unwanted values saved to database + unset($form_state['values']['pid'], $form_state['values']['name'], + $form_state['values']['description'], $form_state['values']['submit'], + $form_state['values']['delete'], $form_state['values']['form_build_id'], + $form_state['values']['form_token'], $form_state['values']['form_id'], + $form_state['values']['op']); + $preset['settings'] = video_preset_array_flatten($form_state['values']); + + // Save this preset. + video_preset_save($preset); + drupal_set_message(t('Preset !preset successfully saved.', array('!preset' => $preset['name']))); + $form_state['redirect'] = 'admin/config/media/video/presets'; +} + +/** + * Button sumit function: handle the 'Delete' button on the preset form. + */ +function video_preset_delete_submit($form, &$form_state) { + $preset['name'] = $form_state['values']['name']; + $form_state['redirect'] = 'admin/config/media/video/presets/preset/' . $preset['name'] . '/delete'; +} + +/** + * Menu callback; delete a single preset. + */ +function video_preset_delete_confirm($form, &$form_state, $preset) { + $form['name'] = array('#type' => 'value', '#value' => $preset['name']); + $message = t('Are you sure you want to delete the preset %name?', array('%name' => $preset['name'])); + $caption = '

' . t('This action cannot be undone.') . '

'; + return confirm_form($form, $message, 'admin/config/media/video/presets', $caption, t('Delete')); +} + +/** + * Execute preset deletion + */ +function video_preset_delete_confirm_submit($form, &$form_state) { + if ($form_state['values']['confirm']) { + video_preset_delete($form_state['values']['name']); + } + + $form_state['redirect'] = 'admin/config/media/video/presets'; +} + +/** + * Validation for the preset form. + */ +function _video_preset_name_validate($element, &$form_state) { + $error = video_validate_preset_name($form_state['values']['name']); + if ($error && !isset($form_state['values']['pid']) && !isset ($form_state['values']['default'])) { + form_set_error('name', $error); + } +} + +/** + * Import's a preset. + */ +function video_preset_import_form($form, &$form_state) { + $form['preset'] = array( + '#title' => t('Preset Code'), + '#type' => 'textarea', + '#rows' => 10, + '#description' => t('Copy the export text and paste it into this text field to import a new preset.'), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Import Preset'), + '#weight' => 30, + ); + + $form['#submit'][] = 'video_preset_import_submit'; + $form['#validate'][] = 'video_preset_import_validate'; + + return $form; +} + +/** + * Validation for the preset import form. + */ +function video_preset_import_validate($form, &$form_state) { + $preset = ''; + + // Get the preset that they declared in the text field. + ob_start(); + eval($form_state['values']['preset']); + ob_end_clean(); + + if (is_array($preset)) { + $name = isset($preset['name']) ? $preset['name'] : ''; + if ($error = video_validate_preset_name($name)) { + form_set_error('name', $error); + } + } else { + form_set_error('name', 'Invalid preset import.'); + } + + $form_state['preset'] = &$preset; +} + +/** + * Submit handler for the preset import form. + */ +function video_preset_import_submit($form, &$form_state) { + $preset = $form_state['preset']; + video_preset_save($preset); + $form_state['redirect'] = 'admin/config/media/video/presets/preset/' . $preset['name']; +} + +/** + * The preset export form. + */ +function video_preset_export_form($form, &$form_state, $preset) { + // Unset the unnecessary elements. + unset($preset['pid']); + unset($preset['default']); + + // Get the code string representation. + $code = var_export($preset, true); + + // Make sure to format the arrays like drupal. + $code = str_replace("=> \n ", '=> ', $code); + + // Add the preset variable. + $code = '$preset = ' . $code . ';'; + + $lines = substr_count($code, "\n"); + $form['export'] = array( + '#title' => t('Export Preset'), + '#type' => 'textarea', + '#value' => $code, + '#rows' => $lines, + '#description' => t('Copy the export text and paste it into another preset using the import function.'), + ); + + // Return the form. + return $form; +} + +/** + * Get's the player settings for the given player. + */ +function video_player_settings_form($preset) { + $settings_form = $preset['player'] . '_player_settings_form'; + if (function_exists($settings_form)) { + return $settings_form($preset); + } + return array(); +} + +/** + * Title callback for a preset. + */ +function video_preset_page_title($preset) { + return $preset['name']; +} + +/** + * Saves a new preset. + */ +function video_preset_save($preset) { + // If they provide the pid, then this needs to be an update. + $pid = (isset($preset['pid']) && $preset['pid']) ? array('pid') : array(); + + // Save or update a preset. + drupal_write_record('video_preset', $preset, $pid); +} + +/** + * Returns the default presets. + * + * @return + */ +function video_preset_get_default_presets() { + $default_presets = module_invoke_all('video_default_presets'); + drupal_alter('video_default_presets', $default_presets); + return $default_presets; +} + +/** + * Gets a list of all presets. + */ +function video_preset_get_presets() { + $presets = array(); + $normal_presets = array(); + + // Get all the presets from the database. + $result = db_select('video_preset', 'p') + ->fields('p') + ->orderBy('p.name', 'ASC') + ->execute(); + + // Iterate through all the presets and structure them in an array. + foreach ($result as $preset) { + $preset = (array) $preset; + $preset['settings'] = $preset['settings'] ? unserialize($preset['settings']) : array(); + $presets[$preset['pid']] = $preset; + $normal_presets[$preset['name']] = $preset['pid']; + } + + // Now allow other modules to add their default presets. + foreach (video_preset_get_default_presets () as $preset) { + // adding default TRUE + $preset['default'] = TRUE; + if (!empty($preset['name']) && !isset($normal_presets[$preset['name']])) { + $presets[$preset['name']] = $preset; + } + } + + return $presets; +} + +/** + * Get's the preset. + */ +function video_get_preset($preset_name) { + // Get the preset from the database. + $preset = db_select('video_preset', 'p') + ->fields('p') + ->condition('p.name', $preset_name) + ->execute() + ->fetchAssoc(); + if ($preset) { + $preset['settings'] = $preset['settings'] ? unserialize($preset['settings']) : array(); + } else { + // Get all of the default presets. + $default_presets = video_preset_get_default_presets(); + + // Check to see if this preset exists. + if (isset($default_presets[$preset_name])) { + // Make this our preset + $preset = $default_presets[$preset_name]; + } + } + + // Return the preset. + return $preset; +} + +/** + * Deletes a preset + */ +function video_preset_delete($preset_name) { + // Delete the preset. + db_delete('video_preset') + ->condition('name', $preset_name) + ->execute(); + + // Rebuild Theme Registry + drupal_theme_rebuild(); +} + +/** + * Checks to see if another preset is already taken. + */ +function video_preset_name_exists($preset_name) { + + // Get the default presets. + $default_presets = video_preset_get_default_presets(); + + // See if there is a default preset name. + if ($default_presets && isset($default_presets[$preset_name])) { + return true; + } else { + return (bool) db_select('video_preset', 'p') + ->fields('p') + ->condition('p.name', $preset_name) + ->range(0, 1) + ->execute() + ->fetchField(); + } +} + +/** + * Verify the syntax of the given prefix name. + * + * Borrowed from the user.module. :) + */ +function video_validate_preset_name($name) { + if (!$name) { + return t('You must enter a preset.'); + } + if (video_preset_name_exists($name)) { + return t('The preset name %name is already taken.', array('%name' => $name)); + } + if (strpos($name, ' ') !== FALSE) { + return t('The preset name cannot contain a space.'); + } + if (is_numeric($name[0])) { + return t('The preset name cannot begin with a number.'); + } + if (preg_match('/[^a-z0-9_]/i', $name)) { + return t('The preset name contains an illegal character.'); + } + if (drupal_strlen($name) > VIDEO_PRESET_MAX_LENGTH) { + return t('The preset name %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => VIDEO_PRESET_MAX_LENGTH)); + } +} + +/** + * Check for default preset + * @param $preset_name + * @return + */ +function video_is_default_preset($preset_name) { + // Get the default presets. + $default_presets = video_preset_get_default_presets(); + + // See if there is a default preset name. + if ($default_presets && isset($default_presets[$preset_name])) + return TRUE; + else + return FALSE; +} diff --git a/modules/video_ui/video_ui.info b/modules/video_ui/video_ui.info new file mode 100644 index 0000000..a03febd --- /dev/null +++ b/modules/video_ui/video_ui.info @@ -0,0 +1,7 @@ +name = Video UI +description = Administrative interface to Video. Without this module you cannot configure the video module. +package = Video +core = 7.x +configure = admin/config/media/video +dependencies[] = video +files[] = video_ui.module \ No newline at end of file diff --git a/modules/video_ui/video_ui.module b/modules/video_ui/video_ui.module new file mode 100644 index 0000000..d2edb9e --- /dev/null +++ b/modules/video_ui/video_ui.module @@ -0,0 +1,188 @@ + 'Video', + 'description' => 'Configure different aspects of the video module and its plugins', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_general_admin_settings'), + 'file' => 'video.admin.inc', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + $items['admin/config/media/video/general'] = array( + 'title' => 'General', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 0, + ); + // Player settings + $items['admin/config/media/video/players'] = array( + 'title' => 'Players', + 'description' => 'Configure your player settings for each video extension.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_players_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 1, + ); + // Transcoder settings + $items['admin/config/media/video/transcoders'] = array( + 'title' => 'Transcoders', + 'description' => 'Configure your transcoder to convert your videos or extra thumbnails.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_transcoder_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + ); + // Preset settings + $items['admin/config/media/video/presets'] = array( + 'title' => 'Manage Preset', + 'description' => 'Configure your transcoder presets to convert your videos.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 3, + ); + +// $items['admin/structure/video'] = array( +// 'title' => 'Video Presets', +// 'file' => 'includes/video.preset.inc', +// 'description' => 'Manage and configure the presets for Video.', +// 'page callback' => 'video_presets_overview', +// 'access arguments' => array('administer video presets') +// ); + $items['admin/config/media/video/presets/all'] = array( + 'title' => 'Presets', + 'description' => 'Configure your transcoder presets to convert your videos.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + $items['admin/config/media/video/presets/list'] = array( + 'title' => 'List', + 'file' => 'video.preset.inc', + 'description' => 'Manage and configure the presets for Video.', + 'page callback' => 'video_presets_overview', + 'access arguments' => array('administer video presets'), + 'type' => MENU_LOCAL_TASK, + 'weight' => -9, + ); + $items['admin/config/media/video/presets/add'] = array( + 'title' => 'Add preset', + 'file' => 'video.preset.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_form'), + 'access arguments' => array('administer video presets'), + 'type' => MENU_LOCAL_TASK + ); + $items['admin/config/media/video/presets/import'] = array( + 'title' => t('Import preset'), + 'file' => 'video.preset.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_import_form'), + 'access arguments' => array('administer video presets'), + 'type' => MENU_LOCAL_TASK + ); + + $items['admin/config/media/video/presets/preset/%video_preset'] = array( + 'title' => 'Edit video preset', + 'title callback' => 'video_preset_page_title', + 'title arguments' => array(6), + 'file' => 'video.preset.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_form', 6), + 'access arguments' => array('administer video presets') + ); + $items['admin/config/media/video/presets/preset/%video_preset/edit'] = array( + 'title' => 'Edit', + 'file' => 'video.preset.inc', + 'page arguments' => array(6), + 'access arguments' => array('administer video presets'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + $items['admin/config/media/video/presets/preset/%video_preset/delete'] = array( + 'title' => 'Delete', + 'file' => 'video.preset.inc', + 'page arguments' => array('video_preset_delete_confirm', 6), + 'access arguments' => array('administer video presets'), + 'type' => MENU_CALLBACK + ); + $items['admin/config/media/video/presets/preset/%video_preset/export'] = array( + 'title' => t('Export'), + 'file' => 'video.preset.inc', + 'title callback' => 'video_preset_page_title', + 'title arguments' => array(6), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_export_form', 6), + 'access arguments' => array('administer video presets'), + 'type' => MENU_CALLBACK + ); + // Metadata settings + $items['admin/config/media/video/metadata'] = array( + 'title' => 'Metadata', + 'description' => 'Configure your metadata settings.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_metadata_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 4, + ); + // Filesystem settings + $items['admin/config/media/video/filesystem'] = array( + 'title' => 'Filesystem', + 'description' => 'Configure your filesystem settings.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_filesystem_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 5, + ); + // Cron settings + $items['admin/config/media/video/cron'] = array( + 'title' => 'Cron Settings', + 'description' => 'Configure your cron settings.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_cron_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 6, + ); + + + return $items; +} + +/** + * Implementing the special "auto-loader" for menu %video_preset. + * + * @param $preset_name + * @return $preset + */ +function video_preset_load($preset_name) { + module_load_include('inc', 'video_ui', 'video.preset'); + return video_get_preset($preset_name); +} diff --git a/video.admin.inc b/video.admin.inc deleted file mode 100644 index 0f55dea..0000000 --- a/video.admin.inc +++ /dev/null @@ -1,174 +0,0 @@ - - */ -function video_transcoder_admin_settings() { - $transcoder = new video_transcoder; - $form = $transcoder->admin_settings(); - return system_settings_form($form); -} - -/** - * Form API callback to validate the upload settings form. - */ -function video_transcoder_admin_settings_validate($form, &$form_state) { - // check ffmpeg_wrapper module installed or not - if ($form_state['values']['video_convertor'] == 'video_ffmpeg_wrapper' && !module_exists('ffmpeg_wrapper')) { - form_set_error('video_convertor', t('You need to download and install the !ffmpeg_wrapper module to enable this option.', array('!ffmpeg_wrapper' => l(t('FFMPEG Wrapper'), 'http://drupal.org/project/ffmpeg_wrapper')))); - } - - // add vallidations by trnacoder interface - $transcoder = $form_state['values']['video_convertor']; - $transcoder = new video_transcoder($transcoder); - $transcoder->admin_settings_validate($form, $form_state); -} - -/** - * Video preset admin settings - * @return - */ -function video_preset_admin_settings() { - $preset = new video_preset(); - $form = $preset->admin_settings(); - return system_settings_form($form); -} - -/** - * Video general admin settings - * @return - */ -function video_general_admin_settings() { - $form = array(); - $form['video_autoplay'] = array( - '#type' => 'checkbox', - '#title' => t('Automatically start video on page load'), - '#default_value' => variable_get('video_autoplay', FALSE), - '#description' => t('Start the video when the page and video loads') - ); - $form['video_autobuffering'] = array( - '#type' => 'checkbox', - '#title' => t('Automatically start video buffering'), - '#default_value' => variable_get('video_autobuffering', TRUE), - '#description' => t('Start buffering video when the page and video loads') - ); - $form['video_bypass_conversion'] = array( - '#type' => 'checkbox', - '#title' => t('Bypass Video Conversion'), - '#default_value' => variable_get('video_bypass_conversion', FALSE), - '#description' => t('Bypass video conversion when creating videos.') - ); - $form['video_convert_on_save'] = array( - '#type' => 'checkbox', - '#title' => t('Video Convert on Node Submit'), - '#default_value' => variable_get('video_convert_on_save', FALSE), - '#description' => t('Convert videos on node submit.') - ); - $form['video_use_default_thumb'] = array( - '#type' => 'checkbox', - '#title' => t('Override Auto Thumbnails with Default'), - '#default_value' => variable_get('video_use_default_thumb', FALSE), - '#description' => t('Override auto thumbnails with default thumbnail.') - ); - return system_settings_form($form); -} - -/** - * Video player admin settings - * @return - */ -function video_players_admin_settings() { - $form = array(); - $form['extensions'] = array( - '#type' => 'fieldset', - '#title' => t('Video Extensions'), - '#description' => t('Here you can map specific players to each video extension type.'), - ); - //lets get all our supported extensions and players. - $extensions = video_video_extensions(); - $players = video_video_players(); - $flv_players = video_video_flv_players(); - - foreach ($extensions as $ext => $player) { - $form['extensions']['video_extension_' . $ext] = array( - '#type' => 'select', - '#title' => t('Extension:') . ' ' . $ext, - '#default_value' => variable_get('video_extension_' . $ext, $player), - '#options' => $players, - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['extensions']['video_extension_' . $ext . '_flash_player'] = array( - '#type' => !empty($flv_players) ? 'radios' : 'markup', - '#title' => t('Flash Player for') . ' ' . $ext, - '#value' => !empty($flv_players) ? '' : t('No flash players detected.
You need to install !swf_tools or !flowplayer.', array('!swf_tools' => l(t('SWF Tools'), 'http://www.drupal.org/project/swftools'), '!flowplayer' => l(t('Flowplayer'), 'http://www.drupal.org/project/flowplayer'))), - '#options' => $flv_players, - '#default_value' => variable_get('video_extension_' . $ext . '_flash_player', ''), - '#prefix' => '
', - '#suffix' => '
', - ); - } - return system_settings_form($form); -} - -/** - * Video Metadata admin settings - * @return - */ -function video_metadata_admin_settings() { - $metadata = new video_metadata; - $form = $metadata->admin_settings(); - return system_settings_form($form); -} - -function video_metadata_admin_settings_validate($form, &$form_state) { - // add vallidations by metadata interface - $metadata = $form_state['values']['video_metadata']; - $metadata = new video_metadata($metadata); - $metadata->admin_settings_validate($form, $form_state); -} - -/** - * Video cron admin settings - * @return - */ -function video_cron_admin_settings() { - $form = array(); - $form['video_cron'] = array( - '#type' => 'checkbox', - '#title' => t('Use Drupals built in cron.'), - '#default_value' => variable_get('video_cron', TRUE), - '#description' => t('If you would like to use Drupals built in cron hook, check this box. Please be warned that transcoding videos is very resource intensive. If you use poor mans cron, I highly discourage this option. I also suggest you setup your cron to call this function through CLI instead of WGET.'), - ); - $form['video_ffmpeg_instances'] = array( - '#type' => 'textfield', - '#title' => t('Total videos to convert during each cron process.'), - '#default_value' => variable_get('video_ffmpeg_instances', 5), - '#description' => t('How many videos do you want to process on each cron run? Either through hook_cron or the video_scheduler.php.'), - ); - return system_settings_form($form); -} - -/** - * File system admin settings - * @return - */ -function video_filesystem_admin_settings() { - $filesystem = new video_filesystem; - $form = $filesystem->admin_settings(); - return system_settings_form($form); -} - -function video_filesystem_admin_settings_validate($form, &$form_state) { - // add vallidations by metadata interface - $filesystem = $form_state['values']['video_filesystem']; - $filesystem = new video_filesystem($filesystem); - $filesystem->admin_settings_validate($form, $form_state); -} \ No newline at end of file diff --git a/video.css b/video.css deleted file mode 100644 index e69de29..0000000 diff --git a/video.features.inc b/video.features.inc new file mode 100644 index 0000000..10fbc9d --- /dev/null +++ b/video.features.inc @@ -0,0 +1,50 @@ + $code); +} + +/** + * Implementation of hook_features_revert(). + */ +function video_features_revert($module) { + if ($default_presets = features_get_default('video', $module)) { + foreach (array_keys($default_presets) as $default_preset) { + video_preset_delete($default_preset); + } + } +} diff --git a/video.field.inc b/video.field.inc new file mode 100644 index 0000000..a342bc4 --- /dev/null +++ b/video.field.inc @@ -0,0 +1,424 @@ + array( + 'label' => t('Video'), + 'description' => t('This field stores the ID of an video file as an integer value.'), + 'settings' => array( + 'uri_scheme' => variable_get('file_default_scheme', 'public'), + 'autoconversion' => 0, + 'autothumbnail' => 'no', + 'default_video_thumbnail' => 0, + 'preview_video_thumb_style' => 'thumbnail', + ), + 'instance_settings' => array( + 'file_extensions' => 'mp4 ogg avi mov wmv flv', + 'file_directory' => 'videos/original', + 'max_filesize' => '', + 'default_dimensions' => '640x350', + 'default_player_dimensions' => '640x350' + ), + 'default_widget' => 'video_upload', + 'default_formatter' => 'video', + ), + ); +} + +/** + * Implements hook_field_settings_form(). + */ +function video_field_settings_form($field, $instance) { + $defaults = field_info_field_settings($field['type']); + $settings = array_merge($defaults, $field['settings']); + $scheme_options = array(); + foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { + $scheme_options[$scheme] = $stream_wrapper['name']; + } + $form['uri_scheme'] = array( + '#type' => 'radios', + '#title' => t('Upload destination'), + '#options' => $scheme_options, + '#default_value' => $settings['uri_scheme'], + '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), + ); + $form = $form + video_default_field_settings($settings); + return $form; +} + +/** + * Element specific validation for video default value. + * + */ +function video_field_default_thumbnail_validate($element, &$form_state) { + $settings = $form_state['values']['field']['settings']; + // Make the file permanent and store it in the form. + if (!empty($settings['default_video_thumbnail']['fid'])) { + $file = file_load($settings['default_video_thumbnail']['fid']); + $file->status |= FILE_STATUS_PERMANENT; + $file = file_save($file); + $form_state['values']['field']['settings']['default_video_thumbnail'] = (array) $file; + } +} + +/** + * Implements hook_field_instance_settings_form(). + */ +function video_field_instance_settings_form($field, $instance) { + $widget = $instance['widget']; + $instance_settings = $instance['settings']; + $settings = $instance['settings']; + // Use the file field instance settings form as a basis. + $form = file_field_instance_settings_form($field, $instance); + // Remove the description option. + unset($form['description_field']); + // add settings by widget type + switch ($instance['widget']['type']) { + case 'video_upload': + break; + case 'video_ftp': + $form['ftp_path'] = array( + '#type' => 'textfield', + '#title' => t('FTP Filepath'), + '#default_value' => !empty($widget['ftp_path']) ? $widget['ftp_path'] : 'ftpvideos', + '#description' => t('The subdirectory within the "files/" directory where you have upload the videos for attachment. Once the video is attached it will be moved from this directory to the main files directory.'), + '#required' => TRUE, + '#weight' => 3, + ); + break; + } + //default settings + $default = video_default_instance_settings($settings); + $form = $default + $form; + return $form; +} + +/** + * Implements hook_field_load(). + */ +function video_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { + file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age); +} + +/** + * Implements hook_field_prepare_view(). + */ +function video_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { + // If there are no files specified at all, use the default. + foreach ($entities as $id => $entity) { + if (empty($items[$id]) && $field['settings']['default_video_thumbnail']) { + if ($file = file_load($field['settings']['default_video_thumbnail'])) { + $items[$id][0] = (array) $file + array( + 'is_default' => TRUE, + ); + } + } + } +} + +/** + * Implements hook_field_presave(). + */ +function video_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_presave($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_insert(). + */ +function video_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_update(). + */ +function video_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_update($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_delete(). + */ +function video_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_delete($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_delete_revision(). + */ +function video_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_is_empty(). + */ +function video_field_is_empty($item, $field) { + return file_field_is_empty($item, $field); +} + +/** + * Implements hook_field_widget_info(). + */ +function video_field_widget_info() { + return array( + 'video_upload' => array( + 'label' => t('Video Upload'), + 'field types' => array('video'), + 'settings' => array( + 'progress_indicator' => 'throbber', + ), + 'behaviors' => array( + 'multiple values' => FIELD_BEHAVIOR_CUSTOM, + 'default value' => FIELD_BEHAVIOR_NONE, + ), + ), + 'video_ftp' => array( + 'label' => t('Video FTP'), + 'field types' => array('video'), + 'settings' => array( + 'progress_indicator' => 'throbber', + ), + 'behaviors' => array( + 'multiple values' => FIELD_BEHAVIOR_CUSTOM, + 'default value' => FIELD_BEHAVIOR_NONE, + ), + ), + ); +} + +/** + * Implements hook_field_widget_settings_form(). + */ +function video_field_widget_settings_form($field, $instance) { + // Use the file widget settings form. + $form = file_field_widget_settings_form($field, $instance); + + return $form; +} + +/** + * Implements hook_field_widget_form(). + */ +function video_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { +// return; + // Add display_field setting to field because file_field_widget_form() assumes it is set. + $field['settings']['display_field'] = 0; + + $elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element); + $settings = $instance['settings']; + foreach (element_children($elements) as $delta) { + + // If not using custom extension validation, ensure this is an image. + $supported_extensions = array('mp4', 'ogg', 'avi', 'mov', 'wmv', 'flv'); + $extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions); + $extensions = array_intersect(explode(' ', $extensions), $supported_extensions); + $elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions); + + // Add all extra functionality provided by the image widget. + $elements[$delta]['#process'][] = 'video_field_widget_process'; + } + + if ($field['cardinality'] == 1) { + // If there's only one field, return it as delta 0. + if (empty($elements[0]['#default_value']['fid'])) { + $elements[0]['#description'] = theme('file_upload_help', array('description' => $instance['description'], 'upload_validators' => $elements[0]['#upload_validators'])); + } + } else { + $elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators'])); + } + return $elements; +} + +/** + * An element #process callback for the image_image field type. + * + * Expands the image_image type to include the alt and title fields. + */ +function video_field_widget_process($element, &$form_state, $form) { + $item = $element['#value']; + $item['fid'] = $element['fid']['#value']; + $field = field_widget_field($element, $form_state); + $instance = field_widget_instance($element, $form_state); + $settings = $field['settings']; + $element['#theme'] = 'video_widget'; + $element['#attached']['css'][] = drupal_get_path('module', 'video') . '/css/video.css'; + $element['preview'] = array(); + // preview the video thumbnail +// if (isset($element['preview']) && $element['#value']['fid'] != 0) { +// $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); +// } + // Add the image preview. + if ($settings['default_video_thumbnail'] && $element['#value']['fid'] != 0) { + $default_thumbnail = file_load($settings['default_video_thumbnail']); +// $element['preview'] = array( +// '#type' => 'markup', +// '#markup' => theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)), +// ); + } + // Title is not necessary for each individual field. + if ($field['cardinality'] != 1) { + unset($element['#title']); + } + // add file elements by widget type + switch ($instance['widget']['type']) { + case 'video_upload': + break; + case 'video_ftp': + break; + } + // Create our thumbnails + video_thumb_process($element, $form_state); + + + // Add our extra fields if in preview mode + if (!empty($item['fid'])) { + video_widget_element_settings($element, $form_state); + } + + // Lets use the clicked_button #submit[0] value here instead and see how that works out for now... + if ($form_state['submitted'] == 1) { + video_widget_process($element, $form_state); + } + return $element; +} + +/** + * Formatters + */ + +/** + * Implementation of CCK's hook_field_formatter_info(). + */ +function video_field_formatter_info() { + $formatters = array( + 'video' => array( + 'label' => t('Video'), + 'field types' => array('video'), + 'settings' => array('video_style' => '', 'video_link' => ''), + ), + 'video_thumbnail' => array( + 'label' => t('Video thumbnail'), + 'field types' => array('video'), + 'settings' => array('video_style' => '', 'video_link' => ''), + ), + //'video_colorbox' => array( + // 'label' => t('Video Thumbnail to Colorbox'), + // 'field types' => array('filefield'), + // 'description' => t('Displays the video thumbnail and adds colorbox support.'), + //), +// 'video_media_js' => array( +// 'label' => t('Video inject with jMedia'), +// 'field types' => array('video'), +// 'description' => t('Displays the video by using jmedia javascript.'), +// ), + ); + return $formatters; +} + +/** + * Implements hook_field_formatter_settings_form(). + */ +function video_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $image_styles = image_style_options(FALSE); + $element['video_style'] = array( + '#title' => t('Video thumbnail style'), + '#type' => 'select', + '#default_value' => $settings['video_style'], + '#empty_option' => t('None (original video thumbnail)'), + '#options' => $image_styles, + ); + + $link_types = array( + 'content' => t('Content'), + 'file' => t('File'), + ); + $element['video_link'] = array( + '#title' => t('Link video or video thumbanil to'), + '#type' => 'select', + '#default_value' => $settings['video_link'], + '#empty_option' => t('Nothing'), + '#options' => $link_types, + ); + + return $element; +} + +/** + * Implements hook_field_formatter_settings_summary(). + */ +function video_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $summary = array(); + + $image_styles = image_style_options(FALSE); + // Unset possible 'No defined styles' option. + unset($image_styles['']); + // Styles could be lost because of enabled/disabled modules that defines + // their styles in code. + if (isset($image_styles[$settings['video_style']])) { + $summary[] = t('Video thumbnail style: @style', array('@style' => $image_styles[$settings['video_style']])); + } else { + $summary[] = t('Original video thumbnail'); + } + + $link_types = array( + 'content' => t('Linked to content'), + 'file' => t('Linked to video file'), + ); + // Display this setting only if image is linked. + if (isset($link_types[$settings['video_link']])) { + $summary[] = $link_types[$settings['video_link']]; + } + + return implode('
', $summary); +} + +/** + * Implements hook_field_formatter_view(). + */ +function video_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + $element = array(); + + // Check if the formatter involves a link. + if ($display['settings']['video_link'] == 'content') { + $uri = entity_uri($entity_type, $entity); + } elseif ($display['settings']['video_link'] == 'file') { + $link_file = TRUE; + } + + // set the display + $theme = $display['type']; + foreach ($items as $delta => $item) { + if (isset($link_file)) { + $uri = array( + 'path' => file_create_url($item['uri']), + 'options' => array(), + ); + } + $element[$delta] = array( + '#theme' => $theme, + '#item' => $item, + '#video_style' => $display['settings']['video_style'], + '#path' => isset($uri) ? $uri : '', + '#entity' => $entity, + '#field' => $field, + '#instance' => $instance + ); + } + return $element; +} \ No newline at end of file diff --git a/video.info b/video.info index ac24b81..be1c5a8 100644 --- a/video.info +++ b/video.info @@ -1,18 +1,10 @@ name = Video -description = Implementation of a video field +description = Upload and manage video content with Drupal package = Video core = 7.x -configure = admin/config/media/video dependencies[] = file dependencies[] = image files[] = video.module -files[] = video.admin.inc -files[] = video.drush.inc -files[] = video.theme.inc -files[] = video_formatter.inc -files[] = video_schedular.inc -files[] = video.field.inc -files[] = includes/video.preset.inc # Including class files to lazyload files[] = includes/conversion.inc files[] = includes/filesystem.inc diff --git a/video.module b/video.module index 9c59ecf..92a362d 100644 --- a/video.module +++ b/video.module @@ -6,8 +6,8 @@ * */ // include the field element -module_load_include('inc', 'video', 'includes/video.field'); -module_load_include('inc', 'video', 'includes/video.features'); +module_load_include('inc', 'video', 'video.field'); +module_load_include('inc', 'video', 'video.features'); /* * Implementation of hook_init(). @@ -46,183 +46,6 @@ function video_permission() { return $perms; } -/** - * Implementation of hook_menu(). - */ -function video_menu() { - $items = array(); - // General settings - $items['admin/config/media/video'] = array( - 'title' => 'Video', - 'description' => 'Configure different aspects of the video module and its plugins', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_general_admin_settings'), - 'file' => 'video.admin.inc', - 'access arguments' => array('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); - $items['admin/config/media/video/general'] = array( - 'title' => 'General', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 0, - ); - // Player settings - $items['admin/config/media/video/players'] = array( - 'title' => 'Players', - 'description' => 'Configure your player settings for each video extension.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_players_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 1, - ); - // Transcoder settings - $items['admin/config/media/video/transcoders'] = array( - 'title' => 'Transcoders', - 'description' => 'Configure your transcoder to convert your videos or extra thumbnails.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_transcoder_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - ); - // Preset settings - $items['admin/config/media/video/presets'] = array( - 'title' => 'Manage Preset', - 'description' => 'Configure your transcoder presets to convert your videos.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 3, - ); - -// $items['admin/structure/video'] = array( -// 'title' => 'Video Presets', -// 'file' => 'includes/video.preset.inc', -// 'description' => 'Manage and configure the presets for Video.', -// 'page callback' => 'video_presets_overview', -// 'access arguments' => array('administer video presets') -// ); - $items['admin/config/media/video/presets/all'] = array( - 'title' => 'Presets', - 'description' => 'Configure your transcoder presets to convert your videos.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, - ); - $items['admin/config/media/video/presets/list'] = array( - 'title' => 'List', - 'file' => 'includes/video.preset.inc', - 'description' => 'Manage and configure the presets for Video.', - 'page callback' => 'video_presets_overview', - 'access arguments' => array('administer video presets'), - 'type' => MENU_LOCAL_TASK, - 'weight' => -9, - ); - $items['admin/config/media/video/presets/add'] = array( - 'title' => 'Add preset', - 'file' => 'includes/video.preset.inc', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_form'), - 'access arguments' => array('administer video presets'), - 'type' => MENU_LOCAL_TASK - ); - $items['admin/config/media/video/presets/import'] = array( - 'title' => t('Import preset'), - 'file' => 'includes/video.preset.inc', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_import_form'), - 'access arguments' => array('administer video presets'), - 'type' => MENU_LOCAL_TASK - ); - - $items['admin/config/media/video/presets/preset/%video_preset'] = array( - 'title' => 'Edit video preset', - 'title callback' => 'video_preset_page_title', - 'title arguments' => array(6), - 'file' => 'includes/video.preset.inc', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_form', 6), - 'access arguments' => array('administer video presets') - ); - $items['admin/config/media/video/presets/preset/%video_preset/edit'] = array( - 'title' => 'Edit', - 'file' => 'includes/video.preset.inc', - 'page arguments' => array(6), - 'access arguments' => array('administer video presets'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - ); - $items['admin/config/media/video/presets/preset/%video_preset/delete'] = array( - 'title' => 'Delete', - 'file' => 'includes/video.preset.inc', - 'page arguments' => array('video_preset_delete_confirm', 6), - 'access arguments' => array('administer video presets'), - 'type' => MENU_CALLBACK - ); - $items['admin/config/media/video/presets/preset/%video_preset/export'] = array( - 'title' => t('Export'), - 'file' => 'includes/video.preset.inc', - 'title callback' => 'video_preset_page_title', - 'title arguments' => array(6), - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_export_form', 6), - 'access arguments' => array('administer video presets'), - 'type' => MENU_CALLBACK - ); - // Metadata settings - $items['admin/config/media/video/metadata'] = array( - 'title' => 'Metadata', - 'description' => 'Configure your metadata settings.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_metadata_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 4, - ); - // Filesystem settings - $items['admin/config/media/video/filesystem'] = array( - 'title' => 'Filesystem', - 'description' => 'Configure your filesystem settings.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_filesystem_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 5, - ); - // Cron settings - $items['admin/config/media/video/cron'] = array( - 'title' => 'Cron Settings', - 'description' => 'Configure your cron settings.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_cron_admin_settings'), - 'access arguments' => array('administer site configuration'), - 'file' => 'video.admin.inc', - 'type' => MENU_LOCAL_TASK, - 'weight' => 6, - ); - - - return $items; -} - -/** - * Used for the menu item to load a preset. - * - * @param $preset_name - */ -function video_preset_load($preset_name) { - module_load_include('inc', 'video', 'includes/video.preset'); - return video_get_preset($preset_name); -} /** * Implementation of hook_theme(). @@ -993,45 +816,4 @@ function rmdirr($dir) { } } @rmdir($dir); -} - -/** - * The hook that tells the preset module that your module should be added to the Preset Management. - * - * @return - * title - The title that you would like to show in the preset manager. - * - * description - The description of your preset when it is shown in the preset manager. - * - * permissions - The permission that you would like to add for the management of your preset. - * - * default_settings - The default settings for your preset. This can also be passed in as a string, - * which is then interpreted as a function callback that has the following signature... - * - * function mymodule_default_settings( $preset ) { - * return array( - * 'param1' => 1, - * 'param2' => 2 - * ); - * } - * - * file - The external file that will hold the form hooks (seen below) for your preset. - */ -function video_preset_info() { - return array( - 'title' => t('Video Preset'), - 'description' => t('Video module transcoding presets.'), - 'permissions' => array( - 'name' => 'administer video preset', - 'title' => t('Administer Video Preset'), - 'description' => t('Administer video preset settings for the video conversions.') - ), - 'default_settings' => array( - 'param1' => 0, - 'param2' => 1, - 'param3' => 3, - 'param4' => 4 - ), - 'file' => drupal_get_path('module', 'video') . '/includes/video.preset.inc' - ); } \ No newline at end of file -- cgit v1.2.3