root / drupal7 / sites / all / modules / recaptcha / src / ReCaptcha / RequestMethod / Drupal7Post.php @ be58a50c
1 |
<?php
|
---|---|
2 |
|
3 |
/**
|
4 |
* @file
|
5 |
* Custom Drupal 7 RequestMehod class for Google reCAPTCHA library.
|
6 |
*/
|
7 |
|
8 |
namespace ReCaptcha\RequestMethod; |
9 |
|
10 |
use ReCaptcha\RequestMethod; |
11 |
use ReCaptcha\RequestParameters; |
12 |
|
13 |
/**
|
14 |
* Sends POST requests to the reCAPTCHA service.
|
15 |
*/
|
16 |
class Drupal7Post implements RequestMethod { |
17 |
|
18 |
/**
|
19 |
* URL to which requests are POSTed.
|
20 |
* @const string
|
21 |
*/
|
22 |
const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
23 |
|
24 |
/**
|
25 |
* Submit the POST request with the specified parameters.
|
26 |
*
|
27 |
* @param RequestParameters $params Request parameters
|
28 |
* @return string Body of the reCAPTCHA response
|
29 |
*/
|
30 |
public function submit(RequestParameters $params) { |
31 |
|
32 |
$options = array( |
33 |
'headers' => array( |
34 |
'Content-type' => 'application/x-www-form-urlencoded', |
35 |
), |
36 |
'method' => 'POST', |
37 |
'data' => $params->toQueryString(), |
38 |
); |
39 |
$response = drupal_http_request(self::SITE_VERIFY_URL, $options); |
40 |
|
41 |
return isset($response->data) ? $response->data : ''; |
42 |
} |
43 |
} |