You are here

function honeypot_get_protected_forms in Honeypot 6

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

Build an array of all the protected forms on the site, by form_id.

@todo - Add in API call/hook to allow modules to add to this array.

1 call to honeypot_get_protected_forms()
honeypot_form_alter in ./honeypot.module
Implementation of hook_form_alter().

File

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

Code

function honeypot_get_protected_forms() {
  static $forms;

  // If the data isn't already in memory, get from cache or look it up fresh.
  if (!isset($forms)) {
    if (($cache = cache_get('honeypot_protected_forms')) && !empty($cache->data)) {
      $forms = unserialize($cache->data);
    }
    else {
      $forms = array();

      // Look up all the honeypot forms in the variables table.
      $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'honeypot_form_%'");

      // Add each form that's enabled to the $forms array.
      while ($variable = db_fetch_array($result)) {
        if (variable_get($variable['name'], 0)) {
          $forms[] = substr($variable['name'], 14);
        }
      }

      // Save the cached data.
      cache_set('honeypot_protected_forms', serialize($forms), 'cache');
    }
  }
  return $forms;
}