You are here

function honeypot_get_time_limit in Honeypot 6

Same name and namespace in other branches
  1. 8 honeypot.module \honeypot_get_time_limit()
  2. 7 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 262
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);

    // Get value from {honeypot_user} table for authenticated users.
    if ($user->uid) {
      $number = db_result(db_query("SELECT COUNT(*) FROM {honeypot_user} WHERE uid = %d AND timestamp > %d", $user->uid, time() - $expire_time));
    }
    else {
      $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", 'honeypot', ip_address(), time() - $expire_time));
    }

    // Don't add more than 30 days' worth of extra time.
    $honeypot_time_limit = (int) min($honeypot_time_limit + exp($number) - 1, 2592000);
    $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;
}