class BotchaRecipeUsingJsAbstract in BOTCHA Spam Prevention 7.2
Same name and namespace in other branches
- 6.2 controller/botcha_recipe.controller.inc \BotchaRecipeUsingJsAbstract
- 6.3 controller/recipe/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/
botcha_recipe.controller.inc, line 414 - Controller layer of the BotchaRecipe objects.
View source
class BotchaRecipeUsingJsAbstract extends BotchaRecipe {
function getInfo() {
parent::getInfo();
$this->error_text .= '<br />' . t('Please enable Javascript to use this form.');
}
function getFieldCount() {
return 1;
}
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.
'#suffix' => '</div>' . '<noscript>' . t('Please enable Javascript to use this form.') . '</noscript>',
'#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)) {
drupal_add_js($js_value, array(
'type' => 'inline',
'preprocess' => FALSE,
));
}
return array_merge(parent::generateFormElements(), $form_elements);
}
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
*/
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.
*/
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.
*/
function getJsPos() {
return strlen($this
->getProperty($this->settings['fields'][0]['prefix'], 'getFieldPrefix'));
}
/**
* What JS matches in the field.
*/
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]));
}
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;
}
function getJsSecureToken() {
return substr($this
->getProperty($this->seed, 'getSeed'), 4, -2) . '_form';
}
function getJsValue() {
}
}
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 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 | property | Status of the spam check. | |
BotchaRecipe:: |
public | function | 2 | |
BotchaRecipe:: |
function | Used to get default recipe data structure. | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | 3 | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
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:: |
function | Spam check. | 4 | |
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | Magic method __construct. | ||
BotchaRecipeUsingJsAbstract:: |
function |
Used to get information about the recipe.
Must be overridden with calling to parent::generateFormElements.
@todo BotchaRecipe generateFormElements Switch from indexed array to associative. Overrides BotchaRecipe:: |
1 | |
BotchaRecipeUsingJsAbstract:: |
public | function |
Should be overridden. Overrides BotchaRecipe:: |
1 |
BotchaRecipeUsingJsAbstract:: |
function |
Overrides BotchaRecipe:: |
||
BotchaRecipeUsingJsAbstract:: |
function | 1 | ||
BotchaRecipeUsingJsAbstract:: |
function | What server sends to JS in the field. | ||
BotchaRecipeUsingJsAbstract:: |
function |
Used to get information about the recipe.
Must be overridden. Overrides BotchaRecipe:: |
2 | |
BotchaRecipeUsingJsAbstract:: |
public | function |
Should be overridden. Overrides BotchaRecipe:: |
|
BotchaRecipeUsingJsAbstract:: |
function | |||
BotchaRecipeUsingJsAbstract:: |
function | What JS matches in the field. | ||
BotchaRecipeUsingJsAbstract:: |
function | Get name of JS-script, attached to field. | ||
BotchaRecipeUsingJsAbstract:: |
function | What position is the part of the token. | ||
BotchaRecipeUsingJsAbstract:: |
function | |||
BotchaRecipeUsingJsAbstract:: |
function | 2 |