+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
* pattern and cache the instance in this variable
*
* @var object
- * @static
*/
static private $_singleton = NULL;
/**
- * Singleton function used to manage this object
+ * Singleton function used to manage this object.
*
- * @param string the key to permit session scope's
*
* @return object
- * @static
- *
*/
- static function &singleton() {
+ public static function &singleton() {
if (self::$_singleton === NULL) {
self::$_singleton = new CRM_Utils_ReCAPTCHA();
}
}
/**
- *
*/
- function __construct() {}
+ public function __construct() {
+ }
/**
- * Add element to form
- *
+ * Add element to form.
*/
- static function add(&$form) {
- $error = NULL;
+ public static function add(&$form) {
+ $error = NULL;
$config = CRM_Core_Config::singleton();
$useSSL = FALSE;
- if ( !function_exists( 'recaptcha_get_html' ) ) {
+ if (!function_exists('recaptcha_get_html')) {
require_once 'packages/recaptcha/recaptchalib.php';
}
$form->assign('recaptchaOptions', $config->recaptchaOptions);
$form->add(
'text',
- 'recaptcha_challenge_field',
- NULL,
+ 'g-recaptcha-response',
+ 'reCaptcha',
NULL,
TRUE
);
- $form->add(
- 'hidden',
- 'recaptcha_response_field',
- 'manual_challenge'
- );
-
$form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA');
- $form->addRule(
- 'recaptcha_challenge_field',
- ts('Input text must match the phrase in the image. Please review the image and re-enter matching text.'),
- 'recaptcha',
- $form
- );
+ if ($form->isSubmitted() && empty($form->_submitValues['g-recaptcha-response'])) {
+ $form->setElementError(
+ 'g-recaptcha-response',
+ ts('Input text must match the phrase in the image. Please review the image and re-enter matching text.')
+ );
+ }
}
- /**
- * @param $value
- * @param CRM_Core_Form $form
- *
- * @return mixed
- */
- static function validate($value, $form) {
- $config = CRM_Core_Config::singleton();
-
- $resp = recaptcha_check_answer($config->recaptchaPrivateKey,
- $_SERVER['REMOTE_ADDR'],
- $_POST["recaptcha_challenge_field"],
- $_POST["recaptcha_response_field"]
- );
- return $resp->is_valid;
- }
}
-