You are here

function custom_admin_settings in Spam 5.3

Adminsitrative interface for configuring custom spam filter rules.

1 string reference to 'custom_admin_settings'
custom_menu in filters/custom/custom.module
Drupal _menu() hook.

File

filters/custom/custom.module, line 110

Code

function custom_admin_settings() {
  $form = array();
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array();
  foreach (module_invoke_all('spam_custom_operations') as $operation => $op) {
    $options[$operation] = $op['label'];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'scan',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Execute'),
  );
  $rows = array();
  $result = pager_query('SELECT * FROM {spam_custom} ORDER BY weight ASC');
  while ($custom = db_fetch_object($result)) {
    $all[$custom->cid] = '';

    // The filter text.
    $form['filter'][$custom->cid] = array(
      '#value' => $custom->filter,
    );

    // What style of filter.
    if ($custom->style == SPAM_CUSTOM_STYLE_PLAIN) {
      $form['style'][$custom->cid] = array(
        '#value' => t('Plain text'),
      );
    }
    else {
      if ($custom->style == SPAM_CUSTOM_STYLE_REGEX) {
        $form['style'][$custom->cid] = array(
          '#value' => t('Regular expression'),
        );
      }
    }

    // What to scan.
    $scan = array();
    if ($custom->scan & SPAM_CUSTOM_SCAN_CONTENT) {
      $scan[] = t('Content');
    }
    if ($custom->scan & SPAM_CUSTOM_SCAN_REFERRER) {
      $scan[] = t('Referrer');
    }
    if ($custom->scan & SPAM_CUSTOM_SCAN_USERAGENT) {
      $scan[] = t('User agent');
    }
    $form['scan'][$custom->cid] = array(
      '#value' => implode(', ', $scan),
    );

    // What status to apply.
    switch ($custom->status) {
      case SPAM_CUSTOM_STATUS_NOTSPAM:
        $status = t('Mark as not spam');
        break;
      case SPAM_CUSTOM_STATUS_PROBABLYNOT:
        $status = t('Mark as probably not spam');
        break;
      case SPAM_CUSTOM_STATUS_DISABLED:
        $status = t('Disabled');
        break;
      case SPAM_CUSTOM_STATUS_PROBABLY:
        $status = t('Mark as probably spam');
        break;
      case SPAM_CUSTOM_STATUS_SPAM:
        $status = t('Mark as spam');
        break;
      default:
        $status = t('Unknown');
        break;
    }
    $form['status'][$custom->cid] = array(
      '#value' => $status,
    );

    // How many times this filter has been matched.
    $form['matches'][$custom->cid] = array(
      '#value' => $custom->matches,
    );

    // The last time this filter was matched.
    $last = $custom->last ? t('@time ago', array(
      '@time' => format_interval(time() - $custom->last),
    )) : t('Never');
    $form['last'][$custom->cid] = array(
      '#value' => $last,
    );

    // Link to edit the filter.
    $form['edit'][$custom->cid] = array(
      '#value' => l(t('edit'), "admin/settings/spam/filters/custom/{$custom->cid}/edit"),
    );
    $rows[] = $row;
  }
  $form['create2'] = array(
    '#value' => '[' . l(t('create custom filter'), 'admin/settings/spam/filters/custom/create') . ']',
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $form['custom'] = array(
    '#type' => 'checkboxes',
    '#options' => $all,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}