You are here

filelog.install in File Log 6

File

filelog.install
View source
<?php

/**
 * Implementation of hook_requirements().
 */
function filelog_requirements($phase) {
  drupal_load('module', 'filelog');
  $f = _filelog_get_conf();
  $mode = isset($f['dir']) ? FILE_MODIFY_PERMISSIONS : ($phase == 'install' ? FILE_CREATE_DIRECTORY : FILE_MODIFY_PERMISSIONS);
  $dir = filelog_directory(FALSE, TRUE);
  $exists = file_check_directory($dir, $mode);
  $requirements = array();
  $t = get_t();
  $requirements['filelog_directory'] = array(
    'title' => $t('Log directory'),
    'value' => $dir,
    'severity' => $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    'description' => $exists ? $t('Directory exists and writable.') : $t('Directory does not exist or writable.'),
  );
  if ($exists) {
    $htaccess = "{$dir}/.htaccess";
    $htaccess_lines = "Order Allow,Deny\nDeny from all\n";
    if ($phase == 'install') {
      if (($fp = fopen($htaccess, 'wb')) && fwrite($fp, $htaccess_lines)) {
        fclose($fp);
        chmod($dir . '/.htaccess', 0664);
        $htaccess = FALSE;
      }
    }
    else {
      $htaccess = !file_exists($htaccess);
    }
    $requirements['filelog_protection'] = array(
      'title' => $t('Log directory protection'),
      'value' => $htaccess ? $t('NOT PROTECTED') : $t('Protected'),
      'severity' => $htaccess ? REQUIREMENT_WARNING : REQUIREMENT_OK,
    );
    if ($htaccess) {
      $variables = array(
        '%directory' => $dir,
        '!htaccess' => '<br />' . nl2br(check_plain($htaccess_lines)),
      );
      $requirements['filelog_protection']['description'] = $t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables);
    }
  }
  return $requirements;
}

/**
 * Implementation of hook_uninstall().
 */
function filelog_uninstall() {
  drupal_load('module', 'filelog');
  file_scan_directory(filelog_directory(FALSE), '.+', array(
    '.',
    '..',
    'CVS',
  ), 'file_delete');
}

Functions

Namesort descending Description
filelog_requirements Implementation of hook_requirements().
filelog_uninstall Implementation of hook_uninstall().