You are here

function access_filter_overview_filters in Access Filter 7

Form builder to list and manage filters.

See also

access_filter_overview_filters_submit()

theme_access_filter_overview_filters()

1 string reference to 'access_filter_overview_filters'
access_filter_menu in ./access_filter.module
Implements hook_menu().

File

./access_filter.admin.inc, line 15
Administration pages for access filters.

Code

function access_filter_overview_filters($form) {
  global $conf, $_access_filter_fast_mode_enabled;
  if (!empty($conf['access_filter_disabled'])) {
    drupal_set_message(t('Access filter module is disabled in settings.php.', 'warning'));
    return;
  }
  $process_types = array(
    ACCESS_FILTER_PROCESS_TYPE_DENY => t('Deny from'),
    ACCESS_FILTER_PROCESS_TYPE_ALLOW => t('Allow from'),
  );
  $action_types = array(
    ACCESS_FILTER_DENY_ACTION_403 => t('Error') . ': 403 Forbidden',
    ACCESS_FILTER_DENY_ACTION_404 => t('Error') . ': 404 Not Found',
    ACCESS_FILTER_DENY_ACTION_301 => t('Redirect') . ': 301 Moved Permanently',
    ACCESS_FILTER_DENY_ACTION_302 => t('Redirect') . ': 302 Moved Temporarily',
    ACCESS_FILTER_DENY_ACTION_200 => '200 OK',
  );
  $form['#tree'] = TRUE;
  $filters = access_filter_load_all();
  foreach ($filters as $filter) {
    $form[$filter->fid]['#filter'] = $filter;
    $form[$filter->fid]['enabled'] = array(
      '#markup' => check_plain($filter->status >= ACCESS_FILTER_STATUS_ENABLED) ? 'o' : 'x',
    );
    $form[$filter->fid]['name'] = array(
      '#markup' => check_plain($filter->name),
    );
    $paths_markup = '<ul>';
    foreach ($filter->parsed_paths as $parsed) {
      $type_text = $parsed->is_uri ? t('Request uri') : t('Drupal path');
      $modifier_texts = array();
      if ($parsed->is_regex) {
        $modifier_texts[] = t('regex');
      }
      if ($parsed->is_blind) {
        $modifier_texts[] = t('blind');
      }
      if (!empty($modifier_texts)) {
        $type_text .= ' (' . implode(', ', $modifier_texts) . ')';
      }
      $paths_markup .= '<li>' . check_plain($parsed->pattern) . ' <i>#' . check_plain($type_text) . '</i></li>';
    }
    $paths_markup .= '</ul>';
    $form[$filter->fid]['paths'] = array(
      '#markup' => $paths_markup,
    );
    $rules_markup = '<ol>';
    foreach (explode("\n", $filter->rules) as $line) {
      $line = trim($line);
      if (strlen($line)) {
        list($type, $ip) = explode(':', $line, 2);
        $rules_markup .= '<li>' . check_plain($process_types[$type] . ' ' . $ip) . '</li>';
      }
    }
    $rules_markup .= '</ol>';
    $form[$filter->fid]['rules'] = array(
      '#markup' => $rules_markup,
    );
    $deny_action_markup = '<ul>';
    if ($filter->deny_action_settings->type == ACCESS_FILTER_DENY_ACTION_301 || $filter->deny_action_settings->type == ACCESS_FILTER_DENY_ACTION_302) {
      $deny_action_markup .= '<li>' . $action_types[$filter->deny_action_settings->type] . '<br />' . $filter->deny_action_settings->redirect_destination . '</li>';
    }
    else {
      $deny_action_markup .= '<li>' . $action_types[$filter->deny_action_settings->type] . '</li>';
    }
    if ($filter->deny_action_settings->force_logout) {
      $deny_action_markup .= '<li>' . t('Force logout') . '</li>';
    }
    $deny_action_markup .= '</ul>';
    $form[$filter->fid]['action'] = array(
      '#markup' => $deny_action_markup,
    );
    $form[$filter->fid]['weight'] = array(
      '#type' => 'textfield',
      '#title' => t('Weight for @title', array(
        '@title' => $filter->name,
      )),
      '#title_display' => 'invisible',
      '#delta' => 10,
      '#size' => 3,
      '#default_value' => $filter->weight,
    );
    $form[$filter->fid]['edit'] = array(
      '#type' => 'link',
      '#title' => t('edit'),
      '#href' => "admin/config/people/access_filter/{$filter->fid}/edit",
    );
    $form[$filter->fid]['delete'] = array(
      '#type' => 'link',
      '#title' => t('delete'),
      '#href' => "admin/config/people/access_filter/{$filter->fid}/delete",
    );
  }
  if (count($filters) > 1) {
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
  }
  elseif (isset($filter)) {
    unset($form[$filter->fid]['weight']);
  }
  if ($_access_filter_fast_mode_enabled) {
    if ($conf['access_filter_fast'] != access_filter_build_fast($filters)) {
      drupal_set_message('Fast mode is enabled and some filter(s) are changed. Changes does not apply until modify settings.php.', 'warning');
    }
    else {
      drupal_set_message('Fast mode is enabled. Changes does not apply until modify settings.php.', 'warning');
    }
  }
  return $form;
}