import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -27,9 +27,9 @@ require_once 'Zend/Service/ReCaptcha.php';
|
||||
|
||||
/**
|
||||
* ReCaptcha adapter
|
||||
*
|
||||
*
|
||||
* Allows to insert captchas driven by ReCaptcha service
|
||||
*
|
||||
*
|
||||
* @see http://recaptcha.net/apidocs/captcha/
|
||||
*
|
||||
* @category Zend
|
||||
@ -37,32 +37,18 @@ require_once 'Zend/Service/ReCaptcha.php';
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: $
|
||||
* @version $Id: ReCaptcha.php 16127 2009-06-18 01:12:54Z stas $
|
||||
*/
|
||||
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
|
||||
*/
|
||||
protected $_CHALLENGE = 'recaptcha_challenge_field';
|
||||
protected $_RESPONSE = 'recaptcha_response_field';
|
||||
/**@-*/
|
||||
|
||||
|
||||
/**
|
||||
* Recaptcha service object
|
||||
*
|
||||
@ -72,7 +58,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
|
||||
/**
|
||||
* Parameters defined by the service
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_serviceParams = array();
|
||||
@ -95,64 +81,64 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
self::ERR_CAPTCHA => 'Failed to validate captcha',
|
||||
self::BAD_CAPTCHA => 'Captcha value is wrong: %value%',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve ReCaptcha Private key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrivkey()
|
||||
public function getPrivkey()
|
||||
{
|
||||
return $this->_privkey;
|
||||
return $this->getService()->getPrivateKey();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve ReCaptcha Public key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPubkey()
|
||||
public function getPubkey()
|
||||
{
|
||||
return $this->_pubkey;
|
||||
return $this->getService()->getPublicKey();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set ReCaptcha Private key
|
||||
*
|
||||
* @param string $_privkey
|
||||
* @param string $privkey
|
||||
* @return Zend_Captcha_ReCaptcha
|
||||
*/
|
||||
public function setPrivkey($privkey)
|
||||
public function setPrivkey($privkey)
|
||||
{
|
||||
$this->_privkey = $privkey;
|
||||
$this->getService()->setPrivateKey($privkey);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set ReCaptcha public key
|
||||
*
|
||||
* @param string $_pubkey
|
||||
* @param string $pubkey
|
||||
* @return Zend_Captcha_ReCaptcha
|
||||
*/
|
||||
public function setPubkey($pubkey)
|
||||
public function setPubkey($pubkey)
|
||||
{
|
||||
$this->_pubkey = $pubkey;
|
||||
$this->getService()->setPublicKey($pubkey);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
* @param array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
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();
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
}
|
||||
@ -163,8 +149,8 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
|
||||
/**
|
||||
* Set service object
|
||||
*
|
||||
* @param Zend_Service_ReCaptcha $service
|
||||
*
|
||||
* @param Zend_Service_ReCaptcha $service
|
||||
* @return Zend_Captcha_ReCaptcha
|
||||
*/
|
||||
public function setService(Zend_Service_ReCaptcha $service)
|
||||
@ -175,7 +161,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
|
||||
/**
|
||||
* Retrieve ReCaptcha service object
|
||||
*
|
||||
*
|
||||
* @return Zend_Service_ReCaptcha
|
||||
*/
|
||||
public function getService()
|
||||
@ -187,9 +173,9 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
* Set option
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public function setOption($key, $value)
|
||||
@ -201,7 +187,7 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
}
|
||||
return parent::setOption($key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate captcha
|
||||
*
|
||||
@ -222,20 +208,29 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
*/
|
||||
public function isValid($value, $context = null)
|
||||
{
|
||||
if (empty($context[$this->_CHALLENGE]) || empty($context[$this->_RESPONSE])) {
|
||||
if (!is_array($value) && !is_array($context)) {
|
||||
$this->_error(self::MISSING_VALUE);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($value) && is_array($context)) {
|
||||
$value = $context;
|
||||
}
|
||||
|
||||
if (empty($value[$this->_CHALLENGE]) || empty($value[$this->_RESPONSE])) {
|
||||
$this->_error(self::MISSING_VALUE);
|
||||
return false;
|
||||
}
|
||||
|
||||
$service = $this->getService();
|
||||
|
||||
$res = $service->verify($context[$this->_CHALLENGE], $context[$this->_RESPONSE]);
|
||||
|
||||
|
||||
$res = $service->verify($value[$this->_CHALLENGE], $value[$this->_RESPONSE]);
|
||||
|
||||
if (!$res) {
|
||||
$this->_error(self::ERR_CAPTCHA);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!$res->isValid()) {
|
||||
$this->_error(self::BAD_CAPTCHA, $res->getErrorCode());
|
||||
$service->setParam('error', $res->getErrorCode());
|
||||
@ -244,15 +239,15 @@ class Zend_Captcha_ReCaptcha extends Zend_Captcha_Base
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render captcha
|
||||
*
|
||||
* @param Zend_View $view
|
||||
* @param mixed $element
|
||||
*
|
||||
* @param Zend_View_Interface $view
|
||||
* @param mixed $element
|
||||
* @return string
|
||||
*/
|
||||
public function render(Zend_View_Interface $view, $element = null)
|
||||
public function render(Zend_View_Interface $view = null, $element = null)
|
||||
{
|
||||
return $this->getService()->getHTML();
|
||||
}
|
||||
|
Reference in New Issue
Block a user