You are here

function clamav_form_alter in ClamAV 6

Implementation of hook_form_alter(). Validation of CCK filefield and imagefield is applied here.

File

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

Code

function clamav_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {

    // Check for CCK integration and handle supported CCK fields.
    if (module_exists('content')) {
      $type = content_types($form['#node']->type);
      if (!empty($type['fields'])) {
        foreach ($type['fields'] as $field_name => $field) {
          $function = 'clamav_' . $field['widget']['type'] . '_alter';
          if (function_exists($function)) {
            $function($form[$field_name]);
          }
        }
      }
    }
    if (isset($form['attachments'])) {

      // Replace upload.module submission handler with a custom one that can
      // refuse to attach files containing viruses
      foreach ($form['#submit'] as $key => $handler) {
        if ($handler == 'upload_node_form_submit') {
          $form['#submit'][$key] = 'clamav_upload_node_form_submit';
        }
      }

      // Override default upload/js callback to add clamav validation
      $form['attachments']['wrapper']['new']['attach']['#ahah']['path'] = 'clamav/upload/js';
    }
  }
}