You are here

function clamav_upload_node_form_submit in ClamAV 6

Validator for upload.module attachments.

Nearly an exact copy of upload_node_form_submit() in upload.module

1 call to clamav_upload_node_form_submit()
clamav_upload_js in ./clamav.module
Menu-callback for JavaScript-based uploads.
1 string reference to 'clamav_upload_node_form_submit'
clamav_form_alter in ./clamav.module
Implementation of hook_form_alter(). Validation of CCK filefield and imagefield is applied here.

File

./clamav.module, line 181
Integrate ClamAV to allow uploaded files to be scanned for viruses.

Code

function clamav_upload_node_form_submit(&$form, &$form_state) {
  global $user;
  $limits = _upload_file_limits($user);
  $validators = array(
    'clamav_elements_filefield_validate' => array(),
    'file_validate_extensions' => array(
      $limits['extensions'],
    ),
    'file_validate_image_resolution' => array(
      $limits['resolution'],
    ),
    'file_validate_size' => array(
      $limits['file_size'],
      $limits['user_size'],
    ),
  );

  // Save new file uploads.
  if (user_access('upload files') && ($file = file_save_upload('upload', $validators, file_directory_path()))) {
    $file->list = variable_get('upload_list_default', 1);
    $file->description = $file->filename;
    $file->weight = 0;
    $file->new = TRUE;
    $form['#node']->files[$file->fid] = $file;
    $form_state['values']['files'][$file->fid] = (array) $file;
  }
  if (isset($form_state['values']['files'])) {
    foreach ($form_state['values']['files'] as $fid => $file) {

      // If the node was previewed prior to saving, $form['#node']->files[$fid]
      // is an array instead of an object. Convert file to object for compatibility.
      $form['#node']->files[$fid] = (object) $form['#node']->files[$fid];
      $form_state['values']['files'][$fid]['new'] = !empty($form['#node']->files[$fid]->new);
    }
  }

  // Order the form according to the set file weight values.
  if (!empty($form_state['values']['files'])) {
    $microweight = 0.001;
    foreach ($form_state['values']['files'] as $fid => $file) {
      if (is_numeric($fid)) {
        $form_state['values']['files'][$fid]['#weight'] = $file['weight'] + $microweight;
        $microweight += 0.001;
      }
    }
    uasort($form_state['values']['files'], 'element_sort');
  }
}