You are here

function anonymous_publishing_cl_admin_spam in Anonymous Publishing 7

Menu callback: Form to manage spambot report.

Return value

array $form

1 string reference to 'anonymous_publishing_cl_admin_spam'
anonymous_publishing_cl_menu in modules/cl/anonymous_publishing_cl.admin.inc
Implements hook_menu().

File

modules/cl/anonymous_publishing_cl.admin.inc, line 599
Menu callbacks for the CL tabs on the module admin page.

Code

function anonymous_publishing_cl_admin_spam($form, &$form_state) {
  $form = array();
  $form['#tree'] = TRUE;
  $form['apu_info'] = array(
    '#markup' => t("<p>The following table shows the IP-addresses and the average hits per day generated by the ten most aggressive spambots hitting the site. To move the bot's IP-address to Drupal's <code>{blocked_ips}</code> table, check the box in the “ban IP” column and press “Submit”.</p><p>As an alternative to the Drupal <code>{blocked_ips}</code> table you may instead deny access to unwanted IP-addresses using the appropriate command in the web server access file.</p>"),
  );

  // Fetch first 10 bot reports.
  $rows = db_query_range('SELECT id, ip, visits, first, last
    FROM {anonymous_publishing_bots}
    ORDER BY visits DESC, last DESC', 0, 10)
    ->fetchAll(PDO::FETCH_ASSOC);
  $form['bots'] = array();
  foreach ($rows as $row) {
    $freq = $row['visits'] / ((REQUEST_TIME - $row['first']) / 86400);
    $freq = min(array(
      $freq,
      $row['visits'],
    ));
    $form['bots'][$row['id']] = array();
    $form['bots'][$row['id']]['id'] = array(
      '#markup' => $row['id'],
    );
    $form['bots'][$row['id']]['ip'] = array(
      '#markup' => $row['ip'],
    );
    $form['bots'][$row['id']]['first'] = array(
      '#markup' => format_interval(REQUEST_TIME - $row['first'], 1) . ' ' . t('ago'),
    );
    $form['bots'][$row['id']]['last'] = array(
      '#markup' => format_interval(REQUEST_TIME - $row['last'], 1) . ' ' . t('ago'),
    );
    $form['bots'][$row['id']]['visits'] = array(
      '#markup' => $row['visits'],
    );
    $form['bots'][$row['id']]['freq'] = array(
      '#markup' => round($freq),
    );
    $form['bots'][$row['id']]['block'] = array(
      '#type' => 'checkbox',
      '#default_value' => FALSE,
    );
    $form['bots'][$row['id']]['ip2'] = array(
      '#type' => 'hidden',
      '#value' => $row['ip'],
    );
  }
  $form['reset']['title'] = array(
    '#markup' => '<br />' . t('Tick box below before clicking “Submit” to reset the Anonymous Publishing spambot counter in the Status report.'),
  );
  $form['reset']['box'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reset spambot counter.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}