You are here

function mimedetect_requirements in MimeDetect 6

Same name and namespace in other branches
  1. 8 mimedetect.install \mimedetect_requirements()
  2. 5 mimedetect.module \mimedetect_requirements()
  3. 7 mimedetect.install \mimedetect_requirements()

Implementation of hook_requirements().

File

./mimedetect.install, line 20

Code

function mimedetect_requirements($phase) {
  $requirements = array();
  $t = get_t();
  $requirement = array(
    'title' => $t('Mime type detection'),
  );
  if (extension_loaded('fileinfo')) {
    $requirement['value'] = $t('PHP Fileinfo Extension');
    if (!($finfo = @finfo_open(FILEINFO_MIME, variable_get('mimedetect_magic', drupal_get_path('module', 'mimedetect') . '/magic')))) {
      $requirement['description'] = $t('Fileinfo could not load the magic file. It could be corrupted. Try reinstalling the magic file distributed with the MimeDetect module.');
      $requirement['severity'] = REQUIREMENT_ERROR;
    }
  }
  else {
    if (variable_get('mimedetect_enable_file_binary', FALSE)) {
      $binary = variable_get('mimedetect_file_binary', '/usr/bin/file');
      $requirement['value'] = $t("UNIX 'file' Command");
      if (!is_executable($binary)) {
        if (!file_exists($binary)) {
          $requirement['description'] = $t("The file %path does not exist or is not readable by your webserver. ", array(
            '%path' => $binary,
          ));
        }
        else {
          $requirement['description'] = $t("The file %path is not executable by your webserver.", array(
            '%path' => $binary,
          ));
        }
        $requirement['severity'] = REQUIREMENT_ERROR;
      }
    }
    else {
      $requirement['value'] = $t('File Extension');
      $requirement['description'] = $t("MimeDetect is using the browser supplied filename for file extension lookups. It is strongly recommended that you install and configure the PHP Fileinfo Extension or the UNIX 'file' command to provide more accurate sever-side mime type detection.");
      $requirement['severity'] = REQUIREMENT_WARNING;
    }
  }
  return array(
    'mimedetect' => $requirement,
  );
}