You are here

public static function CleanTalkSFW::send_logs in Anti Spam by CleanTalk 7.2

Same name and namespace in other branches
  1. 7.5 src/CleantalkSFW.php \CleantalkSFW::send_logs()
  2. 7.4 src/CleantalkSFW.php \CleantalkSFW::send_logs()
2 calls to CleanTalkSFW::send_logs()
cleantalk_boot in ./cleantalk.module
Implements hook_boot()
cleantalk_init in ./cleantalk.module
Implements hook_init()

File

./cleantalk.module, line 158
Main CleanTalk integration module functions.

Class

CleanTalkSFW
Cleantalk Spam FireWall class

Code

public static function send_logs($ct_key) {

  //Getting logs
  $tmp = db_query("SELECT * FROM `cleantalk_sfw_logs`");
  $result = $tmp
    ->fetchAll(PDO::FETCH_ASSOC);
  if (!empty($result)) {

    //Compile logs
    $data = array();
    foreach ($result as $key => $value) {
      $data[] = array(
        trim($value['ip']),
        $value['all'],
        $value['blocked'],
        $value['timestamp'],
      );
    }
    unset($key, $value, $result);

    //Final compile
    $qdata = array(
      'data' => json_encode($data),
      'rows' => count($data),
      'timestamp' => time(),
    );

    //Sendings request
    $result = sendRawRequest('https://api.cleantalk.org/?method_name=sfw_logs&auth_key=' . $ct_key, $qdata, false);
    $result = json_decode($result);

    //Checking answer and truncate table, reset counter
    if (isset($result->data) && isset($result->data->rows)) {
      if ($result->data->rows == count($data)) {
        db_query("TRUNCATE TABLE `cleantalk_sfw_logs`");
        variable_set('ct_sfw_last_logs_sent', time());
      }
    }
  }
}