You are here

function mimedetect_settings in MimeDetect 7

Same name and namespace in other branches
  1. 5 mimedetect.module \mimedetect_settings()
  2. 6 mimedetect.admin.inc \mimedetect_settings()

Form builder; configure mimedetect settings.

See also

system_settings_form()

1 string reference to 'mimedetect_settings'
mimedetect_menu in ./mimedetect.module
Implements hook_menu().

File

./mimedetect.admin.inc, line 14
Admin page callbacks for the mimedetect module.

Code

function mimedetect_settings() {

  // Mime detection engines.
  $form['engines'] = array(
    '#type' => 'fieldset',
    '#title' => t('MIME detection engines'),
  );

  // PHP Fileinfo.
  $form['engines']['mimedetect_enable_file_info'] = array(
    '#type' => 'checkbox',
    '#title' => t('PHP fileinfo'),
    '#default_value' => variable_get('mimedetect_enable_file_info', TRUE),
    '#description' => t('Use the <a href="@url">PHP file information extension</a>. This is the preferred method.', array(
      '@url' => 'http://php.net/manual/en/book.fileinfo.php',
    )),
  );

  // Disable fileinfo option if extension not present.
  if (!extension_loaded('fileinfo')) {
    $form['engines']['mimedetect_enable_file_info']['#disabled'] = TRUE;
    $form['engines']['mimedetect_enable_file_info']['#default_value'] = FALSE;
  }

  // UNIX file command.
  $form['engines']['mimedetect_enable_file_binary'] = array(
    '#type' => 'checkbox',
    '#title' => t('UNIX file'),
    '#default_value' => variable_get('mimedetect_enable_file_binary', FALSE),
    '#description' => t('System call to the file command. Used when PHP fileinfo fails or is not available.'),
  );
  $form['engines']['mimedetect_file_binary'] = array(
    '#type' => 'textfield',
    '#title' => t("Path to the 'file' command"),
    '#default_value' => variable_get('mimedetect_file_binary', '/usr/bin/file'),
    '#description' => t("The path to the executable 'file' binary."),
    '#states' => array(
      'visible' => array(
        ':input[name="mimedetect_enable_file_binary"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['engines']['mimedetect_enable_file_extension'] = array(
    '#type' => 'checkbox',
    '#title' => t('File extension'),
    '#default_value' => TRUE,
    '#disabled' => TRUE,
    '#description' => t('MIME detection based on filename extension. This is the system default method, used as fall back when all others fail or are not available.'),
  );

  // Custom MIME 'magic' file.
  $form['mimedetect_magic'] = array(
    '#type' => 'textfield',
    '#title' => t("Custom 'magic' file path"),
    '#default_value' => variable_get('mimedetect_magic', ''),
    '#description' => t("Used by any magic based engine. Leave blank to rely on system magic file or PHP internal info."),
    '#states' => array(
      'enabled' => array(
        array(
          ':input[name="mimedetect_enable_file_info"]' => array(
            'checked' => TRUE,
          ),
        ),
        array(
          ':input[name="mimedetect_enable_file_binary"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    ),
  );
  return system_settings_form($form);
}