You are here

function honeypot_get_time_limit in Honeypot 7

Same name and namespace in other branches
  1. 8 honeypot.module \honeypot_get_time_limit()
  2. 6 honeypot.module \honeypot_get_time_limit()
  3. 2.0.x honeypot.module \honeypot_get_time_limit()

Look up the time limit for the current user.

Parameters

array $form_values: Array of form values (optional).

1 call to honeypot_get_time_limit()
_honeypot_time_restriction_validate in ./honeypot.module
Validate honeypot's time restriction field.

File

./honeypot.module, line 424
Honeypot module, for deterring spam bots from completing Drupal forms.

Code

function honeypot_get_time_limit($form_values = array()) {
  global $user;
  $honeypot_time_limit = variable_get('honeypot_time_limit', 5);

  // Only calculate time limit if honeypot_time_limit has a value > 0.
  if ($honeypot_time_limit) {
    $expire_time = variable_get('honeypot_expire', 300);

    // Query the {honeypot_user} table to determine the number of failed
    // submissions for the current user.
    $query = db_select('honeypot_user', 'hs')
      ->condition('uid', $user->uid)
      ->condition('timestamp', REQUEST_TIME - $expire_time, '>');

    // For anonymous users, take the hostname into account.
    if ($user->uid === 0) {
      $query
        ->condition('hostname', ip_address());
    }
    $number = $query
      ->countQuery()
      ->execute()
      ->fetchField();

    // Don't add more time than the expiration window.
    $honeypot_time_limit = (int) min($honeypot_time_limit + exp($number) - 1, $expire_time);
    $additions = module_invoke_all('honeypot_time_limit', $honeypot_time_limit, $form_values, $number);
    if (count($additions)) {
      $honeypot_time_limit += array_sum($additions);
    }
  }
  return $honeypot_time_limit;
}