You are here

class BotchaRecipeTimegate in BOTCHA Spam Prevention 7.3

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

Hierarchy

Expanded class hierarchy of BotchaRecipeTimegate

1 string reference to 'BotchaRecipeTimegate'
botcha_update_7200 in ./botcha.install
Create flexible relationships between recipe books and recipes and between recipe books and forms.

File

controller/recipe/botcha.recipe.controller.inc, line 936
Controller layer of the BotchaRecipe objects.

View source
class BotchaRecipeTimegate extends BotchaRecipe {
  protected $time;
  public function getInfo() {
    parent::getInfo();
    $this->description = t('Check time spended for submitting a form.') . ' ' . t('Bots submit form too fast.') . ' ' . t('Form is marked with timestamp which is checked during submit.');
    $this->error_text .= '<br />' . t('Form is submitted too fast.') . '<br />' . t('Please spend more time filling in the form.');
  }
  protected function getFieldCount() {
    return 1;
  }
  protected function getFieldName($delta) {
    switch ($delta) {
      case 0:
      default:
        return 'timegate';
        break;
    }
  }
  public function generateFormElements() {
    $fields = $this
      ->getProperty($this->settings['fields'], 'getFields');
    return array_merge(parent::generateFormElements(), array(
      $fields[0]['name'] => array(
        '#type' => 'hidden',
        '#title' => 'Timegate',
        '#weight' => 5,
        '#required' => FALSE,
        '#default_value' => time(),
      ),
    ));
  }
  public function isSpam($form, $form_state) {
    $isSpam = parent::isSpam($form, $form_state);

    // Timegate method validation.
    $absence = empty($form['timegate']);
    $minimal_delay = variable_get('botcha_timegate', 5);
    $form_generated = !empty($form_state['botcha_submit_values']['timegate']) ? $form_state['botcha_submit_values']['timegate'] : NULL;
    $form_submitted = !empty($form_state['values']['timegate']) ? $form_state['values']['timegate'] : NULL;
    if ($absence || (int) $form_submitted < (int) $form_generated + (int) $minimal_delay) {
      $isSpam = TRUE;
    }
    return $isSpam;
  }

}

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 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::apply public function 1
BotchaRecipe::getCss public function Should be overridden. 1
BotchaRecipe::getDefaultSettings public function Used to get default recipe data structure. @todo ?Do we need it?
BotchaRecipe::getDescription public function
BotchaRecipe::getField protected function 1
BotchaRecipe::getFieldClass protected function
BotchaRecipe::getFieldPrefix protected function
BotchaRecipe::getFields protected function
BotchaRecipe::getJs public function Should be overridden. 1
BotchaRecipe::getMethod public function
BotchaRecipe::getProperty 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::getSecret public function
BotchaRecipe::getSeed protected function
BotchaRecipe::getSetting public function
BotchaRecipe::getTitle public function
BotchaRecipe::handle public function Handle form depending on the result of spam check. 1
BotchaRecipe::prepare protected function 1
BotchaRecipe::setDescription public function
BotchaRecipe::setMethod public function
BotchaRecipe::setRecipebook public function
BotchaRecipe::setSecret public function
BotchaRecipe::setSetting public function
BotchaRecipe::setTitle public function
BotchaRecipe::__construct public function Magic method __construct.
BotchaRecipeTimegate::$time protected property
BotchaRecipeTimegate::generateFormElements 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::generateFormElements
BotchaRecipeTimegate::getFieldCount protected function
BotchaRecipeTimegate::getFieldName protected function Overrides BotchaRecipe::getFieldName
BotchaRecipeTimegate::getInfo public function Used to get information about the recipe. Must be overridden. Overrides BotchaRecipe::getInfo
BotchaRecipeTimegate::isSpam public function Spam check. Overrides BotchaRecipe::isSpam