You are here

function node_gallery_upload_limits_form_validate in Node Gallery 6.2

1 call to node_gallery_upload_limits_form_validate()
node_gallery_config_form_validate in ./node_gallery.admin.inc
1 string reference to 'node_gallery_upload_limits_form_validate'
node_gallery_upload_limits_form in ./node_gallery.admin.inc
gallery upload limitation settings. seperate from upload module for more flexibility.

File

./node_gallery.admin.inc, line 516
Node gallery admin page file

Code

function node_gallery_upload_limits_form_validate($form, &$form_state) {
  $has_error = FALSE;
  if ($form_state['values']['step'] == 2) {
    $upload_limit_values = $form_state['values']['config']['upload_limits'];
    $default_file_max_size = $upload_limit_values['general']['file_max_size'];
    $default_user_max_size = $upload_limit_values['general']['user_max_size'];
    $exceed_max_msg = t('Your PHP settings limit the maximum file size per upload to %size.', array(
      '%size' => format_size(file_upload_max_size()),
    )) . '<br/>';
    $more_info = t("Depending on your server environment, these settings may be changed in the system-wide php.ini file, a php.ini file in your Drupal root directory, in your Drupal site's settings.php file, or in the .htaccess file in your Drupal root directory.");
    foreach ($upload_limit_values as $role_key => $role_values) {
      foreach ($role_values as $key => $value) {
        switch ($key) {
          case 'file_resolution':
            if ($value != '0') {
              if (!preg_match('/^[0-9]+x[0-9]+$/', $value)) {
                form_set_error('file_resolution', t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
                $has_error = TRUE;
              }
            }
            break;
          case 'file_max_size':
            if (!is_numeric($value) || $value <= 0) {
              form_set_error('file_max_size', t('The %role file size limit must be a number and greater than zero.', array(
                '%role' => $role_key == 'general' ? t('default') : $role_values['role_name'],
              )));
              $has_error = TRUE;
            }
            if ($value * 1024 * 1024 > file_upload_max_size()) {
              form_set_error('file_max_size', $exceed_max_msg . $more_info);
              $has_error = TRUE;
            }
            if ($value > $role_values['user_max_size']) {
              form_set_error('file_max_size', t('The %role maximum file size per upload is greater than the total file size allowed per user', array(
                '%role' => $role_key == 'general' ? t('default') : $role_values['role_name'],
              )));
              $has_error = TRUE;
            }
            break;
          case 'user_max_size':
            if (!is_numeric($value) || $value <= 0) {
              form_set_error('user_max_size', t('The %role maximum file size limit must be a number and greater than zero.', array(
                '%role' => $role_key == 'general' ? t('default') : $role_values['role_name'],
              )));
              $has_error = TRUE;
            }
            if ($value < $role_values['file_max_size']) {
              form_set_error('user_max_size', t('The %role file size per upload is greater than the total file size allowed per user', array(
                '%role' => $role_key == 'general' ? t('default') : $role_values['role_name'],
              )));
              $has_error = TRUE;
            }
            break;
        }
      }
    }
    if ($has_error) {
      $form_state['values']['step']--;
    }
  }
}