You are here

function duplicate_init in Spam 5.3

If IP blacklisting and IP blocking are both enabled, perform a database query on each page load to see if the current visitor has been blacklisted.

File

filters/duplicate/duplicate.module, line 83

Code

function duplicate_init() {

  // Allow notification to blacklisted IP, if enabled.
  if (_duplicate_arg(0) == 'duplicate' && _duplicate_arg(1) == 'denied' && _duplicate_arg(2) == 'ip') {
    return;
  }

  // Only perform database queries if functionality is enabled.
  if (variable_get('duplicate_blacklist_action', DUPLICATE_BLACKLIST_NOTIFY) == DUPLICATE_BLACKLIST_BLOCK && variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST) > -1) {

    // Blacklisting and IP blocking enabled.
    $duplicate_ip = (int) db_query("SELECT COUNT(iid) FROM {spam_duplicate} WHERE hostname = '%s' AND spam = %d", $_SERVER['REMOTE_ADDR'], DUPLICATE_SPAM);
    if ($duplicate_ip >= variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST)) {
      if (user_access('bypass filters')) {
        spam_log(SPAM_DEBUG, 'duplicate_init', t('Found !count spam for IP !ip, ignoring because user !user (uid !uid) is configured to bypass filters', array(
          '!count' => $duplicate_ip,
          '!ip' => $_SERVER['REMOTE_ADDR'],
          '!user' => $user->name,
          'uid' => $user->uid,
        )), $type, $id);
        return;
      }
      drupal_goto("duplicate/denied/ip");
    }
  }
}