class BotchaRecipeObscureUrl in BOTCHA Spam Prevention 6.2
Same name and namespace in other branches
- 6.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeObscureUrl
- 7.2 controller/botcha_recipe.controller.inc \BotchaRecipeObscureUrl
- 7.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeObscureUrl
Hierarchy
- class \BotchaRecipe
- class \BotchaRecipeUsingJsAbstract
- class \BotchaRecipeObscureUrl
- class \BotchaRecipeUsingJsAbstract
Expanded class hierarchy of BotchaRecipeObscureUrl
1 string reference to 'BotchaRecipeObscureUrl'
- 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 711 - Controller layer of the BotchaRecipe objects.
View source
class BotchaRecipeObscureUrl extends BotchaRecipeUsingJsAbstract {
function getInfo() {
parent::getInfo();
$this->description = t('Insert a new field into form action URL.') . ' ' . t('Bots will not run JS and miss the field.') . ' ' . t('%parts is added to the form.', array(
'%parts' => 'JS',
)) . ' ' . t('JS enters key value into the field.');
}
function isSpam($form, $form_state) {
$isSpam = parent::isSpam($form, $form_state);
if (isset($this->url_elements)) {
foreach ($this->url_elements as $field => $value) {
$url_field = isset($_GET[$field]) ? $_GET[$field] : FALSE;
unset($_GET[$field]);
if (isset($value['!valid_token']) && $url_field !== $value['!valid_token']) {
$isSpam = TRUE;
break;
}
}
}
return $isSpam;
}
function applyRecipe(&$form, &$form_state) {
// Make some preparations dependent on form before applying.
$this
->setSetting('form_id', $form['form_id']['#value']);
$this
->setSetting('form_action', $form['#action']);
parent::applyRecipe($form, $form_state);
// @todo Merge url_elements with just fields.
$this->url_elements[$this->settings['fields'][2]['name']] = array(
// Describe URL field. JS will return token in URL field.
'#type' => 'textfield',
'#default_value' => '',
'!valid_token' => $this->settings['js']['secure_token'],
);
// @todo Refactor url_elements saving.
Botcha::setRecipe($this);
}
function getFieldCount() {
return 3;
}
function getFieldName($delta) {
switch ($delta) {
case 2:
return substr($this
->getProperty($this->seed, 'getSeed'), 1, 4) . '_name';
break;
case 1:
return parent::getFieldName($delta);
break;
case 0:
default:
// @todo Remove hardcode.
return 'botcha';
break;
}
}
function getJsValue() {
// Just ensure that parameters are set.
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
$js = $this
->getProperty($this->settings['js'], 'getJs');
$chops_positions = array_keys($js['chops']);
$field2_name = $fields[2]['name'];
$form_id = str_replace('_', '-', $this
->getSetting('form_id'));
$submit = _botcha_url($this
->getSetting('form_action'), array(
'query' => array(
$field2_name => '__replace__',
),
));
// Secure_token.
$submit = preg_replace('/__replace__/', $js['chops'][$chops_positions[0]] . '\'+v+\'' . $js['chops'][$chops_positions[1]], $submit);
// @todo Abstract it.
return <<<END
Drupal.behaviors.{<span class="php-variable">$js</span>[<span class="php-string">'name'</span>]} = function() {
\$("input.{<span class="php-variable">$fields</span>[<span class="php-constant">1</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){
v=f.value.substring({<span class="php-variable">$js</span>[<span class="php-string">'pos'</span>]});
\$("#{<span class="php-variable">$form_id</span>}").get(0).setAttribute('action', '{<span class="php-variable">$submit</span>}');
}
});
};
END;
}
function generateFormElements() {
$fields = $this
->getProperty($this->settings['fields'], 'getFields');
return array_merge(parent::generateFormElements(), array(
// Add hidden field to keep part of the token.
$fields[1]['name'] => array(
'#type' => 'hidden',
// Store part of secure_token.
'#default_value' => $fields[1]['default_value'],
// @todo Abstract it.
//'#attributes' => array('class' => array($fields[1]['class'])),
'#attributes' => array(
'class' => $fields[1]['class'],
),
'#weight' => 20,
),
));
}
}
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:: |
function | Used to get default recipe data structure. | ||
BotchaRecipe:: |
function | |||
BotchaRecipe:: |
function | |||
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. | ||
BotchaRecipeObscureUrl:: |
function |
Overrides BotchaRecipe:: |
||
BotchaRecipeObscureUrl:: |
function |
Used to get information about the recipe.
Must be overridden with calling to parent::generateFormElements.
@todo Switch from indexed array to associative. Overrides BotchaRecipeUsingJsAbstract:: |
||
BotchaRecipeObscureUrl:: |
function |
Overrides BotchaRecipeUsingJsAbstract:: |
||
BotchaRecipeObscureUrl:: |
function |
Overrides BotchaRecipe:: |
||
BotchaRecipeObscureUrl:: |
function |
Used to get information about the recipe.
Must be overridden. Overrides BotchaRecipeUsingJsAbstract:: |
||
BotchaRecipeObscureUrl:: |
function |
Overrides BotchaRecipeUsingJsAbstract:: |
||
BotchaRecipeObscureUrl:: |
function |
Spam check. Overrides BotchaRecipe:: |
||
BotchaRecipeUsingJsAbstract:: |
public | function |
Should be overridden. Overrides BotchaRecipe:: |
1 |
BotchaRecipeUsingJsAbstract:: |
function |
Overrides BotchaRecipe:: |
||
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 |