class BotchaRecipeTimegate in BOTCHA Spam Prevention 6.2
Same name and namespace in other branches
- 6.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeTimegate
- 7.2 controller/botcha_recipe.controller.inc \BotchaRecipeTimegate
- 7.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeTimegate
Hierarchy
- class \BotchaRecipe
- class \BotchaRecipeTimegate
Expanded class hierarchy of BotchaRecipeTimegate
1 string reference to 'BotchaRecipeTimegate'
- botcha_update_6200 in ./
botcha.install - Implementation of hook_update_N(). Create flexible relationships between recipe books and recipes and between recipe books and forms.
File
- controller/
botcha_recipe.controller.inc, line 846 - Controller layer of the BotchaRecipe objects.
View source
class BotchaRecipeTimegate extends BotchaRecipe {
protected $time;
function getInfo() {
parent::getInfo();
$this->description = t('Check time spended for submitting a form.') . ' ' . t('Bots submit form too fast.') . ' ' . t('Form is marked with timestamp which is checked during submit.');
$this->error_text .= '<br />' . t('Form is submitted too fast.') . '<br />' . t('Please spend more time filling in the form.');
}
function getFieldCount() {
return 1;
}
function getFieldName($delta) {
switch ($delta) {
case 0:
default:
return 'timegate';
break;
}
}
function generateFormElements() {
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
return array_merge(parent::generateFormElements(), array(
$fields[0]['name'] => array(
'#type' => 'hidden',
'#title' => 'Timegate',
'#weight' => 5,
'#required' => FALSE,
'#default_value' => time(),
),
));
}
/* !!-{
function applyRecipe(&$form, &$form_state) {
// Save the timestamp of form creation
// to compare it with time() during validation.
switch ($this->method) {
case 'build_id':
$this->time = time();
break;
case 'build_id_submit':
$this->time = $form_state['input']['timegate'];
break;
}
parent::applyRecipe($form, $form_state);
}
* !!-}
*/
function isSpam($form, $form_state) {
$isSpam = parent::isSpam($form, $form_state);
// Timegate method validation.
$absence = empty($form['timegate']);
$minimal_delay = variable_get('botcha_timegate', 5);
$form_generated = !empty($form_state['botcha_submit_values']['timegate']) ? $form_state['botcha_submit_values']['timegate'] : NULL;
$form_submitted = !empty($form_state['values']['timegate']) ? $form_state['values']['timegate'] : NULL;
if ($absence || (int) $form_submitted < (int) $form_generated + (int) $minimal_delay) {
$isSpam = TRUE;
}
return $isSpam;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BotchaRecipe:: |
protected | property | CSS to add to the page. | |
BotchaRecipe:: |
protected | property | Brief description of the recipe. It should contain explanation of how bots would fail with it and what the recipe exactly does. | |
BotchaRecipe:: |
public | property | @todo Do we really need it? Probably the best way is to provide mail field always - it hides our fields. Name of the field in the form to use in error messages (to mask botcha fields). | |
BotchaRecipe:: |
public | property | Text to give users if botcha recipe blocks submission. It should give some help to real human users in cases of disabled Javascript or CSS. | |
BotchaRecipe:: |
public | property | Identifier of recipe. | |
BotchaRecipe:: |
protected | property | Javascript to add to the page. | |
BotchaRecipe:: |
protected | property | Method of recipe genration. | |
BotchaRecipe:: |
protected | property | ||
BotchaRecipe:: |
protected | property | Secret. | |
BotchaRecipe:: |
protected | property | Options that received as parameters turned into settings by merging with default values. | |
BotchaRecipe:: |
public | property | Status of the spam check. | |
BotchaRecipe:: |
public | function | 2 | |
BotchaRecipe:: |
public | function | Should be overridden. | 1 |
BotchaRecipe:: |
function | Used to get default recipe data structure. | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | 1 | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
public | function | Should be overridden. | 1 |
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | Universal getter. Wrapper getProperty is used to let class methods be used not only in getting default settings. It gives flexibility to make calls to the class methods in any order: the first of them will always calculate the property value and set… | ||
BotchaRecipe:: |
public static | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | Handle form depending on the result of spam check. | 1 | |
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | Magic method __construct. | ||
BotchaRecipeTimegate:: |
protected | property | ||
BotchaRecipeTimegate:: |
function |
Used to get information about the recipe.
Must be overridden with calling to parent::generateFormElements.
@todo Switch from indexed array to associative. Overrides BotchaRecipe:: |
||
BotchaRecipeTimegate:: |
function | |||
BotchaRecipeTimegate:: |
function |
Overrides BotchaRecipe:: |
||
BotchaRecipeTimegate:: |
function |
Used to get information about the recipe.
Must be overridden. Overrides BotchaRecipe:: |
||
BotchaRecipeTimegate:: |
function |
Spam check. Overrides BotchaRecipe:: |