You are here

function _botcha_recipes in BOTCHA Spam Prevention 6

Same name and namespace in other branches
  1. 7 botcha.botcha.inc \_botcha_recipes()
1 call to _botcha_recipes()
botcha_form_alter_botcha in ./botcha.botcha.inc
Main BOTCHA worker - process the form and apply BOTCHA protection

File

./botcha.botcha.inc, line 442
Implementation of botcha form logic.

Code

function _botcha_recipes($form, $botcha, $secret) {

  // Caching
  static $recipes_cache = array();
  $cache_id = $form['#build_id'] . '_' . $botcha . '_' . $secret;
  if (isset($recipes_cache[$cache_id])) {
    if (BOTCHA_LOGLEVEL >= 6) {
      watchdog(BOTCHA_LOG, 'Found cached recipes book for %cache_id', array(
        '%cache_id' => $cache_id,
      ), WATCHDOG_INFO);
    }
    return $recipes_cache[$cache_id];
  }
  if (BOTCHA_LOGLEVEL >= 6) {
    watchdog(BOTCHA_LOG, 'Built new recipes book for %cache_id', array(
      '%cache_id' => $cache_id,
    ), WATCHDOG_INFO);
  }
  if ($botcha == 'test') {
    $recipe_book = array(
      '_botcha_recipe_test1',
      '_botcha_recipe1',
    );
  }
  else {
    $recipe_book = array(
      '_botcha_recipe1',
      '_botcha_recipe2',
      '_botcha_recipe3',
    );
    if ($botcha == '') {
      $botcha = 'default';
    }
    elseif ($botcha != 'default') {
      $botcha = split(',', $botcha);
    }
  }
  $error_field = _botcha_pick_patsy_field($form, 'mail');
  $recipes = array();
  foreach ($recipe_book as $recipe_page) {
    if (!function_exists($recipe_page)) {
      continue;
    }
    $recipe = $recipe_page($form, $secret, $error_field);
    if (!is_array($botcha) || isset($recipe->name) && isset($botcha[$recipe->name])) {
      $recipe->source = $recipe_page;
      $recipe->secret = $secret;
      $recipes[] = $recipe;
    }
  }
  if ($cache_id) {
    $recipes_cache[$cache_id] = $recipes;
  }
  return $recipes;
}