class BotchaRecipeHoneypot in BOTCHA Spam Prevention 7.2
Same name and namespace in other branches
- 6.2 controller/botcha_recipe.controller.inc \BotchaRecipeHoneypot
- 6.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeHoneypot
- 7.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeHoneypot
Hierarchy
- class \BotchaRecipe
- class \BotchaRecipeUsingJsAbstract
- class \BotchaRecipeHoneypot
- class \BotchaRecipeUsingJsAbstract
Expanded class hierarchy of BotchaRecipeHoneypot
1 string reference to 'BotchaRecipeHoneypot'
- botcha_update_7200 in ./
botcha.install - Create flexible relationships between recipe books and recipes and between recipe books and forms.
File
- controller/
botcha_recipe.controller.inc, line 605 - Controller layer of the BotchaRecipe objects.
View source
class BotchaRecipeHoneypot extends BotchaRecipeUsingJsAbstract {
function getInfo() {
parent::getInfo();
$this->description = t('Insert JS+CSS+honeypot field.') . ' ' . t('Bots will not run JS or will mess with the field') . ' ' . t('%parts are added to the form.', array(
'%parts' => t('Honeypot field') . ', CSS , JS',
)) . ' ' . t('CSS hides the input field.') . ' ' . t('JS enters key value into the field.');
}
function getJsValue() {
// Just ensure that parameters are set.
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
$js = $this
->getProperty($this->settings['js'], 'getJs');
$js_tok1 = reset($js['chops']);
$js_tok2 = next($js['chops']);
return <<<END
(function (\$) {
Drupal.behaviors.{<span class="php-variable">$js</span>[<span class="php-string">'name'</span>]} = {
attach: function (context, settings) {
\$("input.{<span class="php-variable">$fields</span>[<span class="php-constant">0</span>][<span class="php-string">'class'</span>]}").each(function() {
f=\$(this)[0];
if (f.value.indexOf("{<span class="php-variable">$js</span>[<span class="php-string">'match'</span>]}")==0){f.value="{<span class="php-variable">$js_tok1</span>}"+f.value.substring({<span class="php-variable">$js</span>[<span class="php-string">'pos'</span>]})+"{<span class="php-variable">$js_tok2</span>}";}
});
}
};
})(jQuery);
END;
}
function isSpam($form, $form_state) {
$isSpam = parent::isSpam($form, $form_state);
foreach ($this
->generateFormElements() as $field_name => $formElement) {
if (isset($formElement['!valid_token']) && isset($form_state['botcha_submit_values'][$field_name]) && $form_state['botcha_submit_values'][$field_name] !== $formElement['!valid_token']) {
$isSpam = TRUE;
break;
}
}
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 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:: |
public | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
public | function | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | Magic method __construct. | ||
BotchaRecipeHoneypot:: |
function |
Used to get information about the recipe.
Must be overridden. Overrides BotchaRecipeUsingJsAbstract:: |
||
BotchaRecipeHoneypot:: |
function |
Overrides BotchaRecipeUsingJsAbstract:: |
1 | |
BotchaRecipeHoneypot:: |
function |
Spam check. Overrides BotchaRecipe:: |
||
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:: |
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 |