You are here

public function SFW::send_logs in Anti Spam by CleanTalk 8.3

File

src/lib/Cleantalk/Antispam/SFW.php, line 256

Class

SFW

Namespace

Drupal\cleantalk\lib\Cleantalk\Antispam

Code

public function send_logs() {

  //Getting logs
  $query = "SELECT * FROM " . $this->table_prefix . "cleantalk_sfw_logs";
  $this
    ->universal_query($query);
  $result = $this
    ->universal_fetch_all();
  if ($result && is_array($result) && count($result)) {

    //Compile logs
    $data = array();
    foreach ($result as $key => $value) {
      $data[] = array(
        trim($value['ip']),
        $value['all_entries'],
        $value['all_entries'] - $value['blocked_entries'],
        $value['entries_timestamp'],
      );
    }
    unset($key, $value);

    //Sending the request
    $result = CleantalkAPI::method__sfw_logs($this->api_key, $data);

    //Checking answer and deleting all lines from the table
    if (empty($result['error'])) {
      if ($result['rows'] == count($data)) {
        $this
          ->universal_query("TRUNCATE TABLE " . $this->table_prefix . "cleantalk_sfw_logs");
        return true;
      }
    }
    else {
      return $result;
    }
  }
  else {
    return array(
      'error' => true,
      'error_string' => 'NO_LOGS_TO_SEND',
    );
  }
}