|
@@ -27,9 +27,9 @@ require_once 'Zend/Service/ReCaptcha.php';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* ReCaptcha adapter
|
|
* ReCaptcha adapter
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* Allows to insert captchas driven by ReCaptcha service
|
|
* Allows to insert captchas driven by ReCaptcha service
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @see http://recaptcha.net/apidocs/captcha/
|
|
* @see http://recaptcha.net/apidocs/captcha/
|
|
|
*
|
|
*
|
|
|
* @category Zend
|
|
* @category Zend
|
|
@@ -39,30 +39,16 @@ require_once 'Zend/Service/ReCaptcha.php';
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
* @version $Id: $
|
|
* @version $Id: $
|
|
|
*/
|
|
*/
|
|
|
-class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
|
|
|
|
+class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
{
|
|
{
|
|
|
- /**
|
|
|
|
|
- * Recaptcha public key
|
|
|
|
|
- *
|
|
|
|
|
- * @var string
|
|
|
|
|
- */
|
|
|
|
|
- protected $_pubkey;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Recaptcha private key
|
|
|
|
|
- *
|
|
|
|
|
- * @var string
|
|
|
|
|
- */
|
|
|
|
|
- protected $_privkey;
|
|
|
|
|
-
|
|
|
|
|
/**@+
|
|
/**@+
|
|
|
- * ReCaptcha Field names
|
|
|
|
|
|
|
+ * ReCaptcha Field names
|
|
|
* @var string
|
|
* @var string
|
|
|
*/
|
|
*/
|
|
|
protected $_CHALLENGE = 'recaptcha_challenge_field';
|
|
protected $_CHALLENGE = 'recaptcha_challenge_field';
|
|
|
protected $_RESPONSE = 'recaptcha_response_field';
|
|
protected $_RESPONSE = 'recaptcha_response_field';
|
|
|
/**@-*/
|
|
/**@-*/
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Recaptcha service object
|
|
* Recaptcha service object
|
|
|
*
|
|
*
|
|
@@ -72,7 +58,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Parameters defined by the service
|
|
* Parameters defined by the service
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @var array
|
|
* @var array
|
|
|
*/
|
|
*/
|
|
|
protected $_serviceParams = array();
|
|
protected $_serviceParams = array();
|
|
@@ -95,64 +81,64 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
self::ERR_CAPTCHA => 'Failed to validate captcha',
|
|
self::ERR_CAPTCHA => 'Failed to validate captcha',
|
|
|
self::BAD_CAPTCHA => 'Captcha value is wrong: %value%',
|
|
self::BAD_CAPTCHA => 'Captcha value is wrong: %value%',
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Retrieve ReCaptcha Private key
|
|
* Retrieve ReCaptcha Private key
|
|
|
*
|
|
*
|
|
|
* @return string
|
|
* @return string
|
|
|
*/
|
|
*/
|
|
|
- public function getPrivkey()
|
|
|
|
|
|
|
+ public function getPrivkey()
|
|
|
{
|
|
{
|
|
|
- return $this->_privkey;
|
|
|
|
|
|
|
+ return $this->getService()->getPrivateKey();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Retrieve ReCaptcha Public key
|
|
* Retrieve ReCaptcha Public key
|
|
|
*
|
|
*
|
|
|
* @return string
|
|
* @return string
|
|
|
*/
|
|
*/
|
|
|
- public function getPubkey()
|
|
|
|
|
|
|
+ public function getPubkey()
|
|
|
{
|
|
{
|
|
|
- return $this->_pubkey;
|
|
|
|
|
|
|
+ return $this->getService()->getPublicKey();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Set ReCaptcha Private key
|
|
* Set ReCaptcha Private key
|
|
|
*
|
|
*
|
|
|
- * @param string $_privkey
|
|
|
|
|
|
|
+ * @param string $privkey
|
|
|
* @return Zend_Captcha_ReCaptcha
|
|
* @return Zend_Captcha_ReCaptcha
|
|
|
*/
|
|
*/
|
|
|
- public function setPrivkey($privkey)
|
|
|
|
|
|
|
+ public function setPrivkey($privkey)
|
|
|
{
|
|
{
|
|
|
- $this->_privkey = $privkey;
|
|
|
|
|
|
|
+ $this->getService()->setPrivateKey($privkey);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Set ReCaptcha public key
|
|
* Set ReCaptcha public key
|
|
|
*
|
|
*
|
|
|
- * @param string $_pubkey
|
|
|
|
|
|
|
+ * @param string $pubkey
|
|
|
* @return Zend_Captcha_ReCaptcha
|
|
* @return Zend_Captcha_ReCaptcha
|
|
|
*/
|
|
*/
|
|
|
- public function setPubkey($pubkey)
|
|
|
|
|
|
|
+ public function setPubkey($pubkey)
|
|
|
{
|
|
{
|
|
|
- $this->_pubkey = $pubkey;
|
|
|
|
|
|
|
+ $this->getService()->setPublicKey($pubkey);
|
|
|
return $this;
|
|
return $this;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Constructor
|
|
* Constructor
|
|
|
*
|
|
*
|
|
|
- * @param array|Zend_Config $options
|
|
|
|
|
|
|
+ * @param array|Zend_Config $options
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
public function __construct($options = null)
|
|
public function __construct($options = null)
|
|
|
{
|
|
{
|
|
|
- parent::__construct($options);
|
|
|
|
|
-
|
|
|
|
|
- $this->setService(new Zend_Service_ReCaptcha($this->getPubKey(), $this->getPrivKey()));
|
|
|
|
|
|
|
+ $this->setService(new Zend_Service_ReCaptcha());
|
|
|
$this->_serviceParams = $this->getService()->getParams();
|
|
$this->_serviceParams = $this->getService()->getParams();
|
|
|
|
|
|
|
|
|
|
+ parent::__construct($options);
|
|
|
|
|
+
|
|
|
if ($options instanceof Zend_Config) {
|
|
if ($options instanceof Zend_Config) {
|
|
|
$options = $options->toArray();
|
|
$options = $options->toArray();
|
|
|
}
|
|
}
|
|
@@ -163,8 +149,8 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Set service object
|
|
* Set service object
|
|
|
- *
|
|
|
|
|
- * @param Zend_Service_ReCaptcha $service
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param Zend_Service_ReCaptcha $service
|
|
|
* @return Zend_Captcha_ReCaptcha
|
|
* @return Zend_Captcha_ReCaptcha
|
|
|
*/
|
|
*/
|
|
|
public function setService(Zend_Service_ReCaptcha $service)
|
|
public function setService(Zend_Service_ReCaptcha $service)
|
|
@@ -175,7 +161,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Retrieve ReCaptcha service object
|
|
* Retrieve ReCaptcha service object
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @return Zend_Service_ReCaptcha
|
|
* @return Zend_Service_ReCaptcha
|
|
|
*/
|
|
*/
|
|
|
public function getService()
|
|
public function getService()
|
|
@@ -187,9 +173,9 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
* Set option
|
|
* Set option
|
|
|
*
|
|
*
|
|
|
* If option is a service parameter, proxies to the service.
|
|
* If option is a service parameter, proxies to the service.
|
|
|
- *
|
|
|
|
|
- * @param string $key
|
|
|
|
|
- * @param mixed $value
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $key
|
|
|
|
|
+ * @param mixed $value
|
|
|
* @return Zend_Captcha_ReCaptcha
|
|
* @return Zend_Captcha_ReCaptcha
|
|
|
*/
|
|
*/
|
|
|
public function setOption($key, $value)
|
|
public function setOption($key, $value)
|
|
@@ -201,7 +187,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
}
|
|
}
|
|
|
return parent::setOption($key, $value);
|
|
return parent::setOption($key, $value);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Generate captcha
|
|
* Generate captcha
|
|
|
*
|
|
*
|
|
@@ -226,6 +212,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
$this->_error(self::MISSING_VALUE);
|
|
$this->_error(self::MISSING_VALUE);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (!is_array($value) && is_array($context)) {
|
|
if (!is_array($value) && is_array($context)) {
|
|
|
$value = $context;
|
|
$value = $context;
|
|
|
}
|
|
}
|
|
@@ -236,14 +223,14 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$service = $this->getService();
|
|
$service = $this->getService();
|
|
|
-
|
|
|
|
|
- $res = $service->verify($value[$this->_CHALLENGE], $value[$this->_RESPONSE]);
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $res = $service->verify($value[$this->_CHALLENGE], $value[$this->_RESPONSE]);
|
|
|
|
|
+
|
|
|
if (!$res) {
|
|
if (!$res) {
|
|
|
$this->_error(self::ERR_CAPTCHA);
|
|
$this->_error(self::ERR_CAPTCHA);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (!$res->isValid()) {
|
|
if (!$res->isValid()) {
|
|
|
$this->_error(self::BAD_CAPTCHA, $res->getErrorCode());
|
|
$this->_error(self::BAD_CAPTCHA, $res->getErrorCode());
|
|
|
$service->setParam('error', $res->getErrorCode());
|
|
$service->setParam('error', $res->getErrorCode());
|
|
@@ -252,12 +239,12 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Render captcha
|
|
* Render captcha
|
|
|
- *
|
|
|
|
|
- * @param Zend_View_Interface $view
|
|
|
|
|
- * @param mixed $element
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param Zend_View_Interface $view
|
|
|
|
|
+ * @param mixed $element
|
|
|
* @return string
|
|
* @return string
|
|
|
*/
|
|
*/
|
|
|
public function render(Zend_View_Interface $view, $element = null)
|
|
public function render(Zend_View_Interface $view, $element = null)
|