You are here

function filemime_settings_submit in File MIME 6

Set the mime_extension_mapping array based on the mime.types file and/or string.

1 string reference to 'filemime_settings_submit'
filemime_settings in ./filemime.admin.inc
Form builder function for admin settings.

File

./filemime.admin.inc, line 26

Code

function filemime_settings_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  if ($op == t('Reset to defaults')) {
    variable_del('mime_extension_mapping');
  }
  else {
    $file = $form_state['values']['filemime_file'];
    $mappings = array_merge(is_readable($file) ? file($file) : array(), preg_split('/[\\n\\r]+/', $form_state['values']['filemime_types'], -1, PREG_SPLIT_NO_EMPTY));
    foreach ($mappings as $mapping) {
      $types = preg_split('/[\\s]+/', $mapping, -1, PREG_SPLIT_NO_EMPTY);
      foreach ($types as $index => $type) {
        if (substr($type, 0, 1) == '#') {
          break;
        }
        if ($index) {
          $mime_types[$type] = $types[0];
        }
      }
    }
    if (isset($mime_types)) {
      variable_set('mime_extension_mapping', $mime_types);
      drupal_set_message(t('Detected @count.  Overriding default mapping.', array(
        '@count' => format_plural(count($mime_types), '1 custom mapping', '@count custom mappings'),
      )));
    }
    else {
      variable_del('mime_extension_mapping');
      drupal_set_message(t('No custom mappings detected. Using default mapping.'));
    }
  }
}