You are here

function anonymous_publishing_cl_admin_spam_submit in Anonymous Publishing 7

Submit for the notify_admin_spam form.

File

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

Code

function anonymous_publishing_cl_admin_spam_submit($form, &$form_state) {
  if ($form_state['values']['reset']['box']) {
    $stats = array(
      'start' => REQUEST_TIME,
      'smart' => 0,
      'stupid' => 0,
    );
    variable_set('anonymous_publishing_cl_stats', $stats);
    drupal_set_message(t('Spambot counter reset to !date.', array(
      '!date' => format_date($stats['start'], 'short'),
    )), 'status');
    if (!array_key_exists('bots', $form_state['values'])) {
      return;
    }
  }
  if (!array_key_exists('bots', $form_state['values'])) {
    drupal_set_message(t('No bots.'), 'error');
    return;
  }
  $moved = 0;
  foreach ($form_state['values']['bots'] as $settings) {
    if ($settings['block']) {
      $existp = db_query("SELECT ip FROM {blocked_ips} WHERE ip = :ip", array(
        ':ip' => $settings['ip2'],
      ))
        ->fetchAssoc();
      if (FALSE == $existp) {
        $res = db_insert('blocked_ips')
          ->fields(array(
          'ip' => $settings['ip2'],
        ))
          ->execute();
      }
      else {
        $res = TRUE;
      }
      if ($res) {
        $res = db_delete('anonymous_publishing_bots')
          ->condition('ip', $settings['ip2'])
          ->execute();
        $moved++;
      }
    }
  }
  if ($moved) {
    drupal_set_message(t('IP-adresses moved to <code>{blocked_ips}</code>.'));
  }
}