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: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95:
<?php
class FormFieldCaptcha extends AbstractFormField
{
private $captcha = '';
public function __construct($id = 'captcha')
{
$this->captcha = AppContext::get_captcha_service()->get_default_factory();
$field_options = $this->is_enabled() && $this->captcha->is_visible() ? array('required' => true) : array();
parent::__construct($id, LangLoader::get_message('form.captcha', 'common'), false, $field_options);
}
public function retrieve_value()
{
$this->captcha->set_html_id($this->get_html_id());
if ($this->is_enabled())
{
$this->set_value($this->captcha->is_valid());
}
else
{
$this->set_value(true);
}
}
public function display()
{
$this->captcha->set_html_id($this->get_html_id());
$this->captcha->set_form_id($this->get_form_id());
$template = $this->get_template_to_use();
$this->assign_common_template_variables($template);
$template->put_all(array(
'C_IS_ENABLED' => $this->is_enabled(),
'C_IS_VISIBLE' => $this->captcha->is_visible(),
'CAPTCHA' => $this->captcha->display(),
));
return $template;
}
public function validate()
{
$this->retrieve_value();
$result = $this->get_value();
if (!$result)
{
$this->set_validation_error_message(LangLoader::get_message('captcha.validation_error', 'status-messages-common'));
}
return $result;
}
private function is_enabled()
{
return !AppContext::get_current_user()->check_level(User::MEMBER_LEVEL) && $this->captcha->is_available();
}
protected function get_default_template()
{
return new FileTemplate('framework/builder/form/FormFieldCaptcha.tpl');
}
}
?>