You are here

function video_widget_element_settings in Video 6.4

Same name and namespace in other branches
  1. 6.5 video_widget.inc \video_widget_element_settings()
  2. 7 video.module \video_widget_element_settings()

Process elements loads on settings

Parameters

array $element:

2 calls to video_widget_element_settings()
uploadfield_widget_process in types/uploadfield/uploadfield_widget.inc
Element #process callback function.
videoftp_widget_process in types/videoftp/videoftp_widget.inc
Process an individual element.

File

./video_widget.inc, line 11
Common widget functions

Code

function video_widget_element_settings(&$element) {
  $file = $element['#value'];
  $delta = $element['#delta'];
  $field = content_fields($element['#field_name'], $element['#type_name']);

  // Check if using the default width and replace tokens.
  $default_dimensions = user_access('override player dimensions');
  $description = t('Set your video dimensions.  This will create your player with these dimensions.');

  //setup our default dimensions.
  $dimensions = $field['widget']['default_dimensions'];
  $player_dimensions = $field['widget']['default_player_dimensions'];

  // Lets figure out our dimensions for our video and add astericks next to our options.
  $options = video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions()));
  if ($field['widget']['autoconversion'] && isset($element['preview']) && $file['fid'] != 0 && $default_dimensions) {
    $video_info = _video_dimensions_options($options, $file['filepath']);
    $description = t('Set your video dimensions. This will create your player and transcode your video with these dimensions.');
    if (!empty($video_info)) {
      $description .= t('Your video size is !size, if you choose a higher resolution, this could cause video distortion. You are shown dimensions that match your aspect ratio, if you choose dimensions that do not match your ratio, we will pad your video by adding black bars on either the top or bottom while maintaining your videos original aspect ratio.', array(
        '!size' => $video_info['width'] . 'x' . $video_info['height'],
      ));
    }

    //setup our default display of dimensions.

    //lets go through our options looking for a matching resolution
    foreach ($options as $key => $value) {
      if (stristr($value, t('(Matches Resolution)')) == TRUE) {
        $dimensions = $key;
        break;
      }
    }
  }

  // Override our dimensions to the user selected.
  if (isset($file['data']['dimensions']) && !empty($file['data']['dimensions'])) {
    $dimensions = $file['data']['dimensions'];
  }

  // Override our player dimensions to the user selected.
  if (isset($file['data']['player_dimensions']) && !empty($file['data']['player_dimensions'])) {
    $player_dimensions = $file['data']['player_dimensions'];
  }
  $element['data']['dimensions'] = array(
    '#type' => 'select',
    '#title' => t('Dimensions for Video Transcoding'),
    '#default_value' => $dimensions,
    '#description' => $description,
    '#options' => $options,
  );
  $element['data']['player_dimensions'] = array(
    '#type' => 'select',
    '#title' => t('Dimensions for Video Player'),
    '#default_value' => $player_dimensions,
    '#description' => t('WxH of your video player.'),
    '#options' => $options,
  );

  // If users cannot change the default dimensions, lets change this to a value.
  if (!$default_dimensions) {
    $element['data']['dimensions']['#type'] = 'value';
    $element['data']['dimensions']['#value'] = $dimensions;
    $element['data']['player_dimensions']['#type'] = 'value';
    $element['data']['player_dimensions']['#value'] = $player_dimensions;
  }

  // only in preview mode and then create thumbnails
  if ($field['widget']['autoconversion']) {
    $bypass = isset($file['data']['bypass_autoconversion']) ? $file['data']['bypass_autoconversion'] : variable_get('video_bypass_conversion', FALSE);
    if (user_access('bypass conversion video')) {
      $element['data']['bypass_autoconversion'] = array(
        '#type' => 'checkbox',
        '#title' => t('Bypass auto conversion'),
        '#default_value' => $bypass,
        '#description' => t('This will bypass your auto conversion of videos.'),
        '#attributes' => array(
          'class' => 'video-bypass-auto-conversion',
        ),
      );
      if ($file['status'] == FILE_STATUS_TEMPORARY) {

        // Checkbox #default_value does not work when the checkbox is inserted using AHAH
        $element['data']['bypass_autoconversion']['#value'] = $bypass;
      }
    }
    else {
      $element['data']['bypass_autoconversion'] = array(
        '#type' => 'value',
        '#value' => $bypass,
      );
    }
    $convert = isset($file['data']['convert_video_on_save']) ? $file['data']['convert_video_on_save'] : variable_get('video_convert_on_save', FALSE);
    if (user_access('convert on submission')) {
      $element['data']['convert_video_on_save'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert video on save'),
        '#default_value' => $convert,
        '#description' => t('This will convert your video to flv format when you save, instead of scheduling it for cron.'),
        '#attributes' => array(
          'class' => 'video-convert-video-on-save',
        ),
      );
      if ($file['status'] == FILE_STATUS_TEMPORARY) {

        // Checkbox #default_value does not work when the checkbox is inserted using AHAH
        $element['data']['convert_video_on_save']['#value'] = $convert;
      }
    }
    else {
      $element['data']['convert_video_on_save'] = array(
        '#type' => 'value',
        '#value' => $convert,
      );
    }
    $default_thumb = isset($file['data']['use_default_video_thumb']) ? $file['data']['use_default_video_thumb'] : variable_get('video_use_default_thumb', FALSE);
    if (user_access('use default thumb')) {
      $element['data']['use_default_video_thumb'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use the default thumbnail for this video?'),
        '#default_value' => $default_thumb,
        '#description' => t('This will set a flag for this video to use the default video thumbnail when outputed..'),
        '#attributes' => array(
          'class' => 'video-use-default-video-thumb',
        ),
      );
      if ($file['status'] == FILE_STATUS_TEMPORARY) {

        // Checkbox #default_value does not work when the checkbox is inserted using AHAH
        $element['data']['use_default_video_thumb']['#value'] = $default_thumb;
      }
    }
    else {
      $element['data']['use_default_video_thumb'] = array(
        '#type' => 'value',
        '#value' => $default_thumb,
      );
    }
  }
}