1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
<?php
class FormFieldConstraintAntiFlood extends AbstractFormFieldConstraint
{
private $content_management_config;
private $last_posted_timestamp;
private $anti_flood_duration;
public function __construct($last_posted_timestamp, $anti_flood_duration = '', $error_message = '')
{
$this->content_management_config = ContentManagementConfig::load();
$this->last_posted_timestamp = $last_posted_timestamp;
if (empty($anti_flood_duration))
{
$anti_flood_duration = $this->content_management_config->get_anti_flood_duration();
}
$this->anti_flood_duration = $anti_flood_duration;
if (empty($error_message))
{
$error_message = LangLoader::get_message('e_flood', 'errors');
}
$this->set_validation_error_message($error_message);
}
public function validate(FormField $field)
{
if ($this->content_management_config->is_anti_flood_enabled())
{
return !$this->flooding($field);
}
return true;
}
public function get_js_validation(FormField $field)
{
return '';
}
public function flooding($field)
{
if ($this->last_posted_timestamp >= (time() - $this->anti_flood_duration))
{
return true;
}
return false;
}
}
?>