You are here

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

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

File

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

Class

CleanTalkSFW
Cleantalk Spam FireWall class

Code

public static function sfw_update($ct_key) {
  $data = array(
    'auth_key' => $ct_key,
    'method_name' => '2s_blacklists_db',
  );
  $result = sendRawRequest('https://api.cleantalk.org/2.1', $data, false);
  $result = json_decode($result, true);
  if (isset($result['data'])) {
    if (count($result['data']) > 30) {
      db_truncate('cleantalk_sfw')
        ->execute();
      $result = $result['data'];
      $query = "INSERT INTO `cleantalk_sfw` VALUES ";
      for ($i = 0; $i < sizeof($result); $i++) {
        if ($i == sizeof($result) - 1) {
          $query .= "(" . $result[$i][0] . "," . $result[$i][1] . ");";
        }
        else {
          $query .= "(" . $result[$i][0] . "," . $result[$i][1] . "), ";
        }
      }
      $result = db_query($query);
    }
    variable_set('ct_sfw_last_updated', time());
  }
}