You are here

function spambot_report_account in Spambot 6.3

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

Reports an account as a spammer. Requires ip address and evidence of a single incident

Parameters

$account: Account to report

$ip: IP address to report

$evidence: Evidence to report

Return value

TRUE if successful, FALSE if error

1 call to spambot_report_account()
spambot_user_spam_admin_form_submit in ./spambot.pages.inc

File

./spambot.module, line 406

Code

function spambot_report_account($account, $ip, $evidence) {
  $success = FALSE;
  $key = variable_get('spambot_sfs_api_key', FALSE);
  if ($key) {
    $query['api_key'] = $key;
    $query['email'] = $account->mail;
    $query['username'] = $account->name;
    $query['ip_addr'] = $ip;
    $query['evidence'] = mb_strimwidth($evidence, 0, SPAMBOT_MAX_EVIDENCE_LENGTH);

    // Change to use http_build_query() once PHP 4.x can be dropped
    $params = array();
    foreach ($query as $key => $value) {
      $params[] = $key . '=' . urlencode($value);
    }
    $url = 'http://www.stopforumspam.com/add.php';
    $result = drupal_http_request($url, array(
      'Content-type' => 'application/x-www-form-urlencoded',
    ), 'POST', join('&', $params));
    if (!empty($result->code) && $result->code == 200 && !empty($result->data) && stripos($result->data, 'data submitted successfully') !== FALSE) {
      $success = TRUE;
    }
    else {
      if (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', t("Error reporting account: @url <pre>\n@dump</pre>", array(
          '@url' => $url,
          '@dump' => print_r($result, TRUE),
        )));
      }
    }
  }
  return $success;
}