You are here

function spambot_report_account in Spambot 7

Same name and namespace in other branches
  1. 8 spambot.module \spambot_report_account()
  2. 6.3 spambot.module \spambot_report_account()

Reports an account as a spammer.

Requires ip address and evidence of a single incident.

Parameters

object $account: Account to report.

string $ip: IP address to report.

string $evidence: Evidence to report.

Return value

bool TRUE if successful, FALSE if error

1 call to spambot_report_account()
_spambot_user_spam_admin_form_submit_action in ./spambot.pages.inc
Take action under this user account.

File

./spambot.module, line 613
Main module file.

Code

function spambot_report_account($account, $ip, $evidence) {
  $success = FALSE;
  if ($key = variable_get('spambot_sfs_api_key', FALSE)) {
    $query['api_key'] = $key;
    $query['email'] = $account->mail;
    $query['username'] = $account->name;
    $query['ip_addr'] = $ip;
    $query['evidence'] = truncate_utf8($evidence, SPAMBOT_MAX_EVIDENCE_LENGTH);
    $url = 'http://www.stopforumspam.com/add.php';
    $options = array(
      'headers' => array(
        'Content-type' => 'application/x-www-form-urlencoded',
      ),
      'method' => 'POST',
      'data' => http_build_query($query, '', '&'),
    );
    $result = drupal_http_request($url, $options);
    if (!empty($result->code) && $result->code == 200 && !empty($result->data) && stripos($result->data, 'data submitted successfully') !== FALSE) {
      $success = TRUE;
    }
    elseif (stripos($result->data, 'duplicate') !== FALSE) {

      // www.stopforumspam.com can return a 503 code
      // with data = '<p>recent duplicate entry</p>'
      // which we will treat as successful.
      $success = TRUE;
    }
    else {
      watchdog('spambot', "Error reporting account: %url <pre>\n@dump</pre>", array(
        '%url' => $url,
        '@dump' => print_r($result, TRUE),
      ));
    }
  }
  return $success;
}