| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
class sfReCaptchaValidator extends sfValidator |
|---|
| 12 |
{ |
|---|
| 13 |
|
|---|
| 14 |
* Execute this validator. |
|---|
| 15 |
* |
|---|
| 16 |
* @param mixed A file or parameter value/array |
|---|
| 17 |
* @param error An error message reference |
|---|
| 18 |
* |
|---|
| 19 |
* @return bool true, if this validator executes successfully, otherwise false |
|---|
| 20 |
*/ |
|---|
| 21 |
public function execute(&$value, &$error) |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
$challenge = $this->getContext()->getRequest()->getParameter('recaptcha_challenge_field'); |
|---|
| 25 |
$response = $this->getContext()->getRequest()->getParameter('recaptcha_response_field'); |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
$resp = recaptcha_check_answer (sfConfig::get('app_sf_re_captcha_plugin_privatekey'), |
|---|
| 29 |
$_SERVER["REMOTE_ADDR"], |
|---|
| 30 |
$challenge, |
|---|
| 31 |
$response); |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
if (!$resp->is_valid) |
|---|
| 35 |
{ |
|---|
| 36 |
$error = $resp->error; |
|---|
| 37 |
|
|---|
| 38 |
return false; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
return true; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
* Initializes the validator. |
|---|
| 46 |
* |
|---|
| 47 |
* @param sfContext The current application context |
|---|
| 48 |
* @param array An associative array of initialization parameters |
|---|
| 49 |
* |
|---|
| 50 |
* @return bool true, if initialization completes successfully, otherwise false |
|---|
| 51 |
*/ |
|---|
| 52 |
public function initialize($context, $parameters = null) |
|---|
| 53 |
{ |
|---|
| 54 |
require ('recaptchalib.php'); |
|---|
| 55 |
|
|---|
| 56 |
parent::initialize($context); |
|---|
| 57 |
|
|---|
| 58 |
return true; |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|