class BotchaRecipeUsingJsAbstract in BOTCHA Spam Prevention 6.3
Same name and namespace in other branches
- 6.2 controller/botcha_recipe.controller.inc \BotchaRecipeUsingJsAbstract
- 7.2 controller/botcha_recipe.controller.inc \BotchaRecipeUsingJsAbstract
- 7.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeUsingJsAbstract
Hierarchy
- class \BotchaRecipe
- class \BotchaRecipeUsingJsAbstract
Expanded class hierarchy of BotchaRecipeUsingJsAbstract
File
- controller/
recipe/ botcha.recipe.controller.inc, line 469 - Controller layer of the BotchaRecipe objects.
View source
class BotchaRecipeUsingJsAbstract extends BotchaRecipe {
public function getInfo() {
parent::getInfo();
$this->error_text .= '<br />' . t('Please enable Javascript to use this form.');
}
protected function getFieldCount() {
return 1;
}
public function generateFormElements() {
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
$js = $this
->getProperty($this->settings['js'], 'getJs');
$form_elements = array(
$fields[0]['name'] => array(
'#type' => 'textfield',
'#title' => t('Enter your name'),
// Leave the bot enough hints for it to guess it is a good name field
'#default_value' => $fields[0]['default_value'],
// Store part of secure_token
'#description' => t('Your first name.'),
// This is for human users without CSS.
'#prefix' => '<div class="' . $fields[0]['class'] . '">' . '<span class="description"> (' . t('If you\'re a human, don\'t change the following field') . ')</span>',
// @todo Move it to constant since it is also used in error_text.
// @see?
'#suffix' => '</div>' . '<noscript>' . t('Please enable Javascript to use this form.') . '</noscript>',
// @todo Abstract it.
'#attributes' => array(
'class' => $fields[0]['class'],
'autocomplete' => 'off',
),
//'#attributes' => array('class' => array($fields[0]['class']), 'autocomplete' => 'off'),
'#weight' => -20,
'!valid_token' => $js['secure_token'],
),
);
$js_value = $this
->getProperty($this->settings['js']['value'], 'getJsValue');
if (!empty($js_value)) {
// @todo Abstract it.
drupal_add_js($js_value, 'inline');
//drupal_add_js($js_value, array('type' => 'inline', 'preprocess' => FALSE));
}
return array_merge(parent::generateFormElements(), $form_elements);
}
protected function getField($delta) {
return array_merge(parent::getField($delta), array(
'default_value' => $this
->getProperty($this->settings['fields'][$delta]['default_value'], 'getFieldDefault', $delta),
));
}
/**
* What server sends to JS in the field.
*
* @return string
*/
protected function getFieldDefault($delta) {
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
$js = $this
->getProperty($this->settings['js'], 'getJs');
$field_prefix = $fields[$delta]['prefix'];
$chops_positions = array_keys($js['chops']);
$secure_token = $js['secure_token'];
return $field_prefix . substr($secure_token, $chops_positions[0], $chops_positions[1]);
}
public function getCss() {
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
return 'div.' . $fields[0]['class'] . ' { display: none; visibility: hidden; }';
}
public function getJs() {
// JS has to reconstruct the token from tok1, part of field_dflt, tok2.
return array(
'name' => $this
->getProperty($this->settings['js']['name'], 'getJsName'),
'pos' => $this
->getProperty($this->settings['js']['pos'], 'getJsPos'),
'match' => $this
->getProperty($this->settings['js']['match'], 'getJsMatch'),
'secure_token' => $this
->getProperty($this->settings['js']['secure_token'], 'getJsSecureToken'),
'chops' => $this
->getProperty($this->settings['js']['chops'], 'getJsChops'),
);
}
/**
* Get name of JS-script, attached to field.
*/
protected function getJsName() {
// Must start with a literal.
return 'a' . substr($this->secret, 0, 10) . substr($this
->getProperty($this->seed, 'getSeed'), 6, 8);
}
/**
* What position is the part of the token.
*/
protected function getJsPos() {
return strlen($this
->getProperty($this->settings['fields'][0]['prefix'], 'getFieldPrefix'));
}
/**
* What JS matches in the field.
*/
protected function getJsMatch() {
$chop_positions = array_keys($this
->getProperty($this->settings['js']['chops'], 'getJsChops'));
return substr($this
->getFieldDefault(0), 0, $this
->getJsPos() + mt_rand(2, $chop_positions[1]));
}
protected function getJsChops() {
$secure_token = $this
->getProperty($this->settings['js']['secure_token'], 'getJsSecureToken');
// Chop the token in 3 parts.
$js_chops = array();
$chop1 = 2;
$js_chops[$chop1] = substr($secure_token, 0, $chop1);
$chop2 = mt_rand(5, 8);
$js_chops[$chop2] = substr($secure_token, $chop1 + $chop2);
return $js_chops;
}
protected function getJsSecureToken() {
return substr($this
->getProperty($this->seed, 'getSeed'), 4, -2) . '_form';
}
}
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 | 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 the 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 | function | 1 | |
BotchaRecipe:: |
public | function | Used to get default recipe data structure. @todo ?Do we need it? | |
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
protected | function | ||
BotchaRecipe:: |
protected | function | 3 | |
BotchaRecipe:: |
protected | function | ||
BotchaRecipe:: |
protected | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
protected | 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 | function | ||
BotchaRecipe:: |
protected | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | Handle form depending on the result of spam check. | 1 |
BotchaRecipe:: |
public | function | Spam check. | 4 |
BotchaRecipe:: |
protected | function | 1 | |
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
public | function | Magic method __construct. | |
BotchaRecipeUsingJsAbstract:: |
public | function |
Used to get information about the recipe.
Must be overridden with calling to parent::generateFormElements.
@todo Switch from indexed array to associative.
@see? Overrides BotchaRecipe:: |
2 |
BotchaRecipeUsingJsAbstract:: |
public | function |
Should be overridden. Overrides BotchaRecipe:: |
|
BotchaRecipeUsingJsAbstract:: |
protected | function |
Overrides BotchaRecipe:: |
|
BotchaRecipeUsingJsAbstract:: |
protected | function | 1 | |
BotchaRecipeUsingJsAbstract:: |
protected | function | What server sends to JS in the field. | |
BotchaRecipeUsingJsAbstract:: |
public | function |
Used to get information about the recipe.
Must be overridden. Overrides BotchaRecipe:: |
2 |
BotchaRecipeUsingJsAbstract:: |
public | function |
Should be overridden. Overrides BotchaRecipe:: |
|
BotchaRecipeUsingJsAbstract:: |
protected | function | ||
BotchaRecipeUsingJsAbstract:: |
protected | function | What JS matches in the field. | |
BotchaRecipeUsingJsAbstract:: |
protected | function | Get name of JS-script, attached to field. | |
BotchaRecipeUsingJsAbstract:: |
protected | function | What position is the part of the token. | |
BotchaRecipeUsingJsAbstract:: |
protected | function |