You are here

function _cloudflare_spam_api in CloudFlare 6

Same name and namespace in other branches
  1. 7 cloudflare.module \_cloudflare_spam_api()
1 call to _cloudflare_spam_api()
_cloudflare_spam_report in ./cloudflare.module

File

./cloudflare.module, line 385

Code

function _cloudflare_spam_api($cid) {

  // Retrieve the settings.
  $cf_settings = _cloudflare_settings();
  $cf_api_email = $cf_settings['cf_api_email'];
  $cf_api_key = $cf_settings['cf_api_key'];

  //$cf_ip_ranges = $cf_settings['cf_ip_ranges'];

  //$my_ip = $cf_settings['my_ip'];
  $comment = _comment_load($cid);
  $value = array(
    "a" => $comment->name,
    "am" => $comment->mail,
    "ip" => $comment->hostname,
    "con" => substr($comment->comment, 0, 350),
  );
  $postdata = http_build_query(array(
    'evnt_v' => json_encode($value),
    'u' => $cf_api_email,
    'tkn' => $cf_api_key,
    'evnt_t' => 'WP_SPAM',
  ), '', '&');
  $opts = array(
    'http' => array(
      'method' => 'POST',
      'header' => array(
        "Host: www.cloudflare.com",
        "Content-type: application/x-www-form-urlencoded",
        "Content-length: " . strlen($postdata),
        "Connection: Close",
      ),
      'content' => $postdata,
    ),
  );
  $context = stream_context_create($opts);
  $url = "/ajax/external-event.html";

  // Open the file using the HTTP headers set above
  $fc = file_get_contents($cf_settings['cf_api_https_host'] . $url, false, $context);
  $result = json_decode($fc);
  if ($result->result == 'error') {
    return array(
      "result" => $result,
      "options" => $opts,
    );
  }
  elseif ($result->result == 'success') {
    return array(
      "result" => $result,
      "value" => $value,
    );
  }
  else {
    return array(
      "result" => 'other',
      "fc" => $fc,
    );
  }
}