You are here

class BotchaRecipeNoResubmit in BOTCHA Spam Prevention 7.2

Same name and namespace in other branches
  1. 6.2 controller/botcha_recipe.controller.inc \BotchaRecipeNoResubmit
  2. 6.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeNoResubmit
  3. 7.3 controller/recipe/botcha.recipe.controller.inc \BotchaRecipeNoResubmit

Hierarchy

Expanded class hierarchy of BotchaRecipeNoResubmit

1 string reference to 'BotchaRecipeNoResubmit'
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 346
Controller layer of the BotchaRecipe objects.

View source
class BotchaRecipeNoResubmit extends BotchaRecipe {
  function getInfo() {
    parent::getInfo();
    $this->description = t('Prevent form resubmission.' . ' Bots will try to resubmit old form prepared.' . ' Form is remembered, and only one submission is allowed.');
    $this->error_text .= '<br />' . t('Form session reuse detected.') . ' ' . t('An old form was submitted again, which may happen' . ' if it was retrieved from browser history using "Back" button.') . '<br />' . t('Please try again - fill all entries on this page' . ' without going "Back".');
  }
  function isSpam($form, $form_state) {

    // !!~ @todo Reduce code duplication.
    // @see BotchaRecipe.applyRecipe()
    $isSpam = TRUE;
    $build_id = isset($_POST['form_build_id']) ? $_POST['form_build_id'] : $form['#build_id'];
    if ($cached = cache_get("botcha_{$build_id}", 'cache_form')) {
      $data = $cached->data;
      if (isset($data['#cache_token']) && $data['#cache_token'] == $this
        ->getToken()) {
        $isSpam = FALSE;
      }
    }
    return $isSpam;
  }
  protected function getToken($value = '') {
    return drupal_get_token($value);
  }
  function applyRecipe(&$form, &$form_state) {
    parent::applyRecipe($form, $form_state);

    // Save build id.
    $build_id = $form['#build_id'];

    // !!~ @todo Reduce code duplication.
    // @see BotchaRecipebook.apply()
    $build_id_submit = isset($_POST['form_build_id']) ? $_POST['form_build_id'] : FALSE;

    // Issue the client a new build_id, make sure that the form has it set
    // in the hidden field.
    if ($build_id_submit != $build_id) {
      $form_state['post']['form_build_id'] = $build_id;
    }

    // 6 hours cache life time for forms should be plenty.
    // @todo Provide UI for controlling the botcha_cache_expiration_timeout parameter.
    $expire = variable_get('botcha_cache_expiration_timeout', 21600);
    $data = array();
    $data['#cache_token'] = $this
      ->getToken();

    // We use cache_form table.
    // Sneaky, but why build our own table since we are working side-by-side with form API?
    cache_set('botcha_' . $build_id, $data, 'cache_form', REQUEST_TIME + $expire);
  }
  function handle($mode, $form, $form_state) {
    parent::handle($mode, $form, $form_state);

    // !!~ @todo Reduce code duplication.
    // @see BotchaRecipe.applyRecipe()
    $build_id = isset($_POST['form_build_id']) ? $_POST['form_build_id'] : $form['#build_id'];

    // Invalidate cache so resubmit will not work.
    // Make it to expire immediately.
    $expire = 0;
    $data = array();
    cache_set('botcha_' . $build_id, $data, 'cache_form', REQUEST_TIME + $expire);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BotchaRecipe::$css protected property CSS to add to the page.
BotchaRecipe::$description 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::$error_field 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::$error_text 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::$id public property Identifier of the recipe.
BotchaRecipe::$js protected property Javascript to add to the page.
BotchaRecipe::$method protected property Method of recipe genration.
BotchaRecipe::$recipebooks protected property
BotchaRecipe::$secret protected property Secret.
BotchaRecipe::$settings protected property Options that received as parameters turned into settings by merging with default values.
BotchaRecipe::$status public property Status of the spam check.
BotchaRecipe::generateFormElements 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. 2
BotchaRecipe::getCss public function Should be overridden. 1
BotchaRecipe::getDefaultSettings function Used to get default recipe data structure.
BotchaRecipe::getDescription function
BotchaRecipe::getField function 1
BotchaRecipe::getFieldClass function
BotchaRecipe::getFieldName function 3
BotchaRecipe::getFieldPrefix function
BotchaRecipe::getFields function
BotchaRecipe::getJs public function Should be overridden. 1
BotchaRecipe::getMethod function
BotchaRecipe::getProperty 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::getRecipe public static function
BotchaRecipe::getSecret function
BotchaRecipe::getSeed function
BotchaRecipe::getSetting function
BotchaRecipe::getStatus function
BotchaRecipe::getTitle function
BotchaRecipe::save public function
BotchaRecipe::setDescription function
BotchaRecipe::setMethod function
BotchaRecipe::setRecipebook public function
BotchaRecipe::setSecret function
BotchaRecipe::setSetting function
BotchaRecipe::setStatus function
BotchaRecipe::setTitle function
BotchaRecipe::__construct function Magic method __construct.
BotchaRecipeNoResubmit::applyRecipe function Overrides BotchaRecipe::applyRecipe
BotchaRecipeNoResubmit::getInfo function Used to get information about the recipe. Must be overridden. Overrides BotchaRecipe::getInfo
BotchaRecipeNoResubmit::getToken protected function
BotchaRecipeNoResubmit::handle function Handle form depending on the result of spam check. Overrides BotchaRecipe::handle
BotchaRecipeNoResubmit::isSpam function Spam check. Overrides BotchaRecipe::isSpam