You are here

public function CleantalkSFW::sfw_update in Anti Spam by CleanTalk 7.4

Same name and namespace in other branches
  1. 7.5 src/CleantalkSFW.php \CleantalkSFW::sfw_update()
  2. 7.2 cleantalk.module \CleanTalkSFW::sfw_update()

File

src/CleantalkSFW.php, line 106

Class

CleantalkSFW

Code

public function sfw_update($ct_key) {
  $result = self::api_method__get_2s_blacklists_db($ct_key);
  if (empty($result['error'])) {
    db_truncate('cleantalk_sfw')
      ->execute();

    // Cast result to int
    foreach ($result as $value) {
      $value[0] = intval($value[0]);
      $value[1] = intval($value[1]);
    }
    unset($value);
    $values = array();
    for ($i = 0, $arr_count = count($result); $i < $arr_count; $i++) {
      $values[] = array(
        'network' => $result[$i][0],
        'mask' => $result[$i][1],
      );
    }
    if (count($values) > 0) {
      $query = db_insert('cleantalk_sfw')
        ->fields([
        'network',
        'mask',
      ]);
      foreach ($values as $record) {
        $query
          ->values($record);
      }
      $query
        ->execute();
    }
    return true;
  }
  else {
    return $result;
  }
}