diff --git a/_config.php b/_config.php index 0e41915..a590f29 100644 --- a/_config.php +++ b/_config.php @@ -2,3 +2,6 @@ /** * @package recaptcha */ +// Ensure compatibility with PHP 7.2 ("object" is a reserved word), +// with SilverStripe 3.6 (using Object) and SilverStripe 3.7 (using SS_Object) +if (!class_exists('SS_Object')) class_alias('Object', 'SS_Object'); diff --git a/code/RecaptchaField.php b/code/RecaptchaField.php index 52442e1..d886c1b 100644 --- a/code/RecaptchaField.php +++ b/code/RecaptchaField.php @@ -158,14 +158,14 @@ public function Field($properties = array()) */ public function validate($validator) { - /** @var array $request */ + /** @var array $postVars */ if(SapphireTest::is_running_test()) { - $request = $_REQUEST; + $postVars = $_REQUEST; } else { - $request = Controller::curr()->getRequest(); + $postVars = Controller::curr()->getRequest()->postVars(); } // don't bother querying the recaptcha-service if fields were empty - if (!array_key_exists('g-recaptcha-response', $request) || empty($request['g-recaptcha-response'])) { + if (!array_key_exists('g-recaptcha-response', $postVars) || empty($postVars['g-recaptcha-response'])) { $validator->validationError( $this->name, _t( @@ -181,7 +181,7 @@ public function validate($validator) return false; } - $response = $this->recaptchaHTTPPost($_REQUEST['g-recaptcha-response']); + $response = $this->recaptchaHTTPPost($postVars['g-recaptcha-response']); if (!$response) { $validator->validationError( @@ -288,10 +288,12 @@ class RecaptchaField_HTTPClient extends Object public function post($url, $postVars) { $ch = curl_init($url); - if (!empty(RecaptchaField::$proxy_server)) { - curl_setopt($ch, CURLOPT_PROXY, RecaptchaField::$proxy_server); - if (!empty(RecaptchaField::$proxy_auth)) { - curl_setopt($ch, CURLOPT_PROXYUSERPWD, RecaptchaField::$proxy_auth); + $proxyServer = Config::inst()->get('RecaptchaField', 'proxy_server'); + if (!empty($proxyServer)) { + curl_setopt($ch, CURLOPT_PROXY, $proxyServer); + $proxyAuth = Config::inst()->get('RecaptchaField', 'proxy_auth'); + if (!empty($proxyAuth)) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth); } }