You are here

public function video_zencoder::preset_settings_validate in Video 6.5

Overrides video_transcoder::preset_settings_validate

File

plugins/video_zencoder/transcoders/video_zencoder.inc, line 357
Transcoder class file to handle Zencoder settings and conversions.

Class

video_zencoder

Code

public function preset_settings_validate($form, &$form_state) {
  $v =& $form_state['values'];
  foreach (array(
    'frame_rate',
    'max_frame_rate',
  ) as $k) {
    if (!empty($v[$k]) && !preg_match('#^\\d+(\\.\\d+)?$#', $v[$k])) {
      form_error($form[$k], t('The value of the %setting setting must be a floating point number.', array(
        '%setting' => $form[$k]['#title'],
      )));
    }
  }
  foreach (array(
    'video_bitrate',
    'audio_bitrate',
    'audio_sample_rate',
    'audio_channels',
  ) as $k) {
    if (!empty($v[$k])) {
      if (!preg_match('#^\\d+$#', $v[$k])) {
        form_error($form[$k], t('The value of the %setting setting must be a positive integer.', array(
          '%setting' => $form[$k]['#title'],
        )));
      }
      else {
        $v[$k] = intval($v[$k]);
      }
    }
  }
  if (!empty($v['additional_settings'])) {

    // Remove unnecessary new lines
    $asstr = trim($v['additional_settings']);
    $asstr = preg_replace('#[\\r\\n]+#', "\n", $asstr);

    // Parse the lines into a structure
    $lines = explode("\n", $asstr);
    $as = array();
    $stack = array();
    array_unshift($stack, &$as);
    foreach ($lines as $lineno => $line) {
      $parts = explode(':', $line, 2);
      if (count($parts) != 2) {
        continue;
      }
      $key = rtrim($parts[0]);
      $value = trim($parts[1]);
      if ($value != '') {

        // Check the spaces of the key
        $level = strspn($key, ' ') / 2;
        if ($level != abs($level)) {
          continue;
        }

        // Check if we should go one level lower
        if ($level == count($stack) - 2) {
          array_shift($stack);
        }
        if ($level == count($stack) - 1) {

          // Add a value to the current stack top
          $stack[0][ltrim($key)] = $value;
        }
      }
      else {
        $stack[0][$key] = array();
        array_unshift($stack, &$stack[0][$key]);
      }
      $lines[$lineno] = $key . ': ' . $value;
    }
    $v['additional_settings'] = $as;
  }
}