You are here

class BotchaRecipeTimegate in BOTCHA Spam Prevention 7.2

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.3 controller/recipe/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/botcha_recipe.controller.inc, line 847
Controller layer of the BotchaRecipe objects.

View source
class BotchaRecipeTimegate extends BotchaRecipe {
  protected $time;
  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.');
  }
  function getFieldCount() {
    return 1;
  }
  function getFieldName($delta) {
    switch ($delta) {
      case 0:
      default:
        return 'timegate';
        break;
    }
  }
  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(),
      ),
    ));
  }

  /* !!-{
    function applyRecipe(&$form, &$form_state) {
      // Save the timestamp of form creation
      // to compare it with time() during validation.
      switch ($this->method) {
        case 'build_id':
          $this->time = time();
          break;
        case 'build_id_submit':
          $this->time = $form_state['input']['timegate'];
          break;
      }
      parent::applyRecipe($form, $form_state);
    }
   * !!-}
   */
  function isSpam($form, $form_state) {
    $isSpam = parent::isSpam($form, $form_state);
    $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 @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::applyRecipe public function 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::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::handle function Handle form depending on the result of spam check. 1
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.
BotchaRecipeTimegate::$time protected property
BotchaRecipeTimegate::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. Overrides BotchaRecipe::generateFormElements
BotchaRecipeTimegate::getFieldCount function
BotchaRecipeTimegate::getFieldName function Overrides BotchaRecipe::getFieldName
BotchaRecipeTimegate::getInfo function Used to get information about the recipe. Must be overridden. Overrides BotchaRecipe::getInfo
BotchaRecipeTimegate::isSpam function Spam check. Overrides BotchaRecipe::isSpam