You are here

function rate_bots_is_blocked in Rate 7

Check if the current user is blocked.

This function will first check if the user is already known to be a bot. If not, it will check if we have valid reasons to assume the user is a bot.

Return value

bool

1 call to rate_bots_is_blocked()
rate_save_vote in ./rate.module
Save a vote to the database.

File

./rate.bots.inc, line 30

Code

function rate_bots_is_blocked() {
  $ip = ip_address();
  $agent = $_SERVER['HTTP_USER_AGENT'];
  if (rate_bots_is_local($ip)) {

    // The IP-address is a local IP-address. This is probably because of
    // misconfigured proxy servers. Do only the user agent check.
    return rate_bots_check_agent($agent);
  }
  if (rate_bots_check_ip($ip)) {
    return TRUE;
  }
  if (rate_bots_check_agent($agent)) {

    // Identified as a bot by its user agent. Register this bot by IP-address
    // as well, in case this bots uses multiple agent strings.
    rate_bots_register_bot($ip);
    return TRUE;
  }
  $threshold = variable_get(RATE_VAR_BOT_MINUTE_THRESHOLD, 25);
  if ($threshold && rate_bots_check_threshold($ip, 60) > $threshold) {
    rate_bots_register_bot($ip);
    return TRUE;
  }
  $threshold = variable_get(RATE_VAR_BOT_HOUR_THRESHOLD, 250);

  // Always count, even if threshold is disabled. This is to determine if we
  // can skip the BotScout check.
  $count = rate_bots_check_threshold($ip, 3600);
  if ($threshold && $count > $threshold) {
    rate_bots_register_bot($ip);
    return TRUE;
  }
  if (!$count && rate_bots_check_botscout($ip)) {
    rate_bots_register_bot($ip);
    return TRUE;
  }
  return FALSE;
}