public function BotchaRecipebook::handle in BOTCHA Spam Prevention 6.3
Same name and namespace in other branches
- 7.3 controller/recipebook/botcha.recipebook.controller.inc \BotchaRecipebook::handle()
Handle form depending on the result of spam check.
_state
Parameters
string $result: This parameter is string and not boolean to have a chance to easily implement new results of spam check (such as 'postponed', 'suspected' or other).
array $form:
array $is_spam:
File
- controller/
recipebook/ botcha.recipebook.controller.inc, line 217 - Controller layer of the BotchaRecipebook objects.
Class
Code
public function handle($result, $form, $form_state, $is_spam) {
$recipes_spam = array_intersect($is_spam, array_fill_keys(array_keys($is_spam), TRUE));
$recipes_spam_count = count($recipes_spam);
$recipes_success = array_intersect($is_spam, array_fill_keys(array_keys($is_spam), FALSE));
$recipes_success_count = count($recipes_success);
// !!~ @todo Recipebook handle Reduce code duplication.
switch ($result) {
case 'success':
variable_set('botcha_form_passed_counter', $recipes_success_count);
// Show good submissions in log.
if (BOTCHA_LOGLEVEL >= 3) {
watchdog(BOTCHA_LOG, '!form_id post approved by BOTCHA.!more', array(
'!form_id' => $form['form_id']['#value'],
'!more' => '' . (BOTCHA_LOGLEVEL >= 3 ? ' Checked ' . count($this
->getRecipes()) . ' botchas (' . join(', ', $this
->getRecipes()) . ').' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . 'POST=<pre>' . print_r(_botcha_filter_form_values_log($_POST), 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . 'GET=<pre>' . print_r(_botcha_filter_form_values_log($_GET), 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . 'SERVER=<pre>' . print_r($_SERVER, 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . ' form=<pre>' . print_r(_botcha_filter_form_log($form), 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . ' values=<pre>' . print_r(_botcha_filter_form_values_log($form_state['values']), 1) . '</pre>' : ''),
), WATCHDOG_INFO);
}
$rules_event_name = 'botcha_form_approved';
break;
case 'spam':
default:
variable_set('botcha_form_blocked_counter', $recipes_spam_count);
// Show blocked submissions in log.
// @todo Turn logging into a Rules action.
if (BOTCHA_LOGLEVEL >= 1) {
watchdog(BOTCHA_LOG, '!form_id post blocked by BOTCHA: submission looks like from a spambot.!more', array(
'!form_id' => $form['form_id']['#value'],
'!more' => '' . (BOTCHA_LOGLEVEL >= 2 ? '<br /><br />' . 'Failed ' . $recipes_spam_count . ' of ' . count($this
->getRecipes()) . ' recipes [' . implode(', ', array_keys($recipes_spam)) . '] from "' . $this->id . '" recipe book.' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . 'POST=<pre>' . print_r(_botcha_filter_form_values_log($_POST), 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . 'GET=<pre>' . print_r(_botcha_filter_form_values_log($_GET), 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . 'SERVER=<pre>' . print_r($_SERVER, 1) . '</pre>' : '') . (BOTCHA_LOGLEVEL >= 5 ? '<br /><br />' . ' values=<pre>' . print_r(_botcha_filter_form_values_log($form_state['values']), 1) . '</pre>' : ''),
), WATCHDOG_WARNING);
}
$rules_event_name = 'botcha_form_rejected';
break;
}
// Invoke rules event.
if (module_exists('rules')) {
$arguments = array(
// 'form' => &$form,
// 'form_state' => &$form_state,
'form_id' => $form['form_id']['#value'],
'total_recipes' => count($this
->getRecipes()),
'passed_recipes' => $recipes_success_count,
'passed_recipes_names' => join(', ', array_keys($recipes_success)),
// !!~ @todo Add last recipe name.
//'last_recipe_name' => $recipe->name,
// !!~ @todo Add a reason of fail to rules event invokation.
//'fail' => $fail,
'fail' => 'FAIL',
'failed_field' => 'mail',
);
// !!? Do we need per recipe rules event invoking?
rules_invoke_event($rules_event_name, $arguments);
}
}