@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | public $headers; |
95 | 95 | |
96 | 96 | /** |
97 | - * Start the curl object |
|
98 | - * - allow for user override values |
|
99 | - * |
|
100 | - * @param array $options An array of cURL options |
|
101 | - * @param int $max_redirect Maximum number of redirects |
|
102 | - */ |
|
97 | + * Start the curl object |
|
98 | + * - allow for user override values |
|
99 | + * |
|
100 | + * @param array $options An array of cURL options |
|
101 | + * @param int $max_redirect Maximum number of redirects |
|
102 | + */ |
|
103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
104 | 104 | { |
105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Main calling function, |
|
112 | - * - will request the page data from a given $url |
|
113 | - * - optionally will post data to the page form if post data is supplied |
|
114 | - * - passed arrays will be converted to a post string joined with &'s |
|
115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
116 | - * |
|
117 | - * @param string $url the site we are going to fetch |
|
118 | - * @param array $post_data any post data as form name => value |
|
119 | - * @return object An instance of the curl_fetch_web_data class |
|
120 | - */ |
|
111 | + * Main calling function, |
|
112 | + * - will request the page data from a given $url |
|
113 | + * - optionally will post data to the page form if post data is supplied |
|
114 | + * - passed arrays will be converted to a post string joined with &'s |
|
115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
116 | + * |
|
117 | + * @param string $url the site we are going to fetch |
|
118 | + * @param array $post_data any post data as form name => value |
|
119 | + * @return object An instance of the curl_fetch_web_data class |
|
120 | + */ |
|
121 | 121 | public function get_url_data($url, $post_data = array()) |
122 | 122 | { |
123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
137 | - * Makes the actual cURL call |
|
138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
140 | - * |
|
141 | - * @param string $url The site to fetch |
|
142 | - * @param bool $redirect Whether or not this was a redirect request |
|
143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
144 | - */ |
|
137 | + * Makes the actual cURL call |
|
138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
140 | + * |
|
141 | + * @param string $url The site to fetch |
|
142 | + * @param bool $redirect Whether or not this was a redirect request |
|
143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
144 | + */ |
|
145 | 145 | private function curl_request($url, $redirect = false) |
146 | 146 | { |
147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Used if being redirected to ensure we have a fully qualified address |
|
197 | - * |
|
198 | - * @param string $last_url The URL we went to |
|
199 | - * @param string $new_url The URL we were redirected to |
|
200 | - * @return string The new URL that was in the HTTP header |
|
201 | - */ |
|
196 | + * Used if being redirected to ensure we have a fully qualified address |
|
197 | + * |
|
198 | + * @param string $last_url The URL we went to |
|
199 | + * @param string $new_url The URL we were redirected to |
|
200 | + * @return string The new URL that was in the HTTP header |
|
201 | + */ |
|
202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
203 | 203 | { |
204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Used to return the results to the calling program |
|
220 | - * - called as ->result() will return the full final array |
|
221 | - * - called as ->result('body') to just return the page source of the result |
|
222 | - * |
|
223 | - * @param string $area Used to return an area such as body, header, error |
|
224 | - * @return string The response |
|
225 | - */ |
|
219 | + * Used to return the results to the calling program |
|
220 | + * - called as ->result() will return the full final array |
|
221 | + * - called as ->result('body') to just return the page source of the result |
|
222 | + * |
|
223 | + * @param string $area Used to return an area such as body, header, error |
|
224 | + * @return string The response |
|
225 | + */ |
|
226 | 226 | public function result($area = '') |
227 | 227 | { |
228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | - * Will return all results from all loops (redirects) |
|
239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
240 | - * - Call as ->result_raw() for everything. |
|
241 | - * |
|
242 | - * @param string $response_number Which response we want to get |
|
243 | - * @return array|string The entire response array or just the specified response |
|
244 | - */ |
|
238 | + * Will return all results from all loops (redirects) |
|
239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
240 | + * - Call as ->result_raw() for everything. |
|
241 | + * |
|
242 | + * @param string $response_number Which response we want to get |
|
243 | + * @return array|string The entire response array or just the specified response |
|
244 | + */ |
|
245 | 245 | public function result_raw($response_number = '') |
246 | 246 | { |
247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
257 | - * Takes supplied POST data and url encodes it |
|
258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
260 | - * |
|
261 | - * @param array|string $post_data The raw POST data |
|
262 | - * @return string A string of post data |
|
263 | - */ |
|
257 | + * Takes supplied POST data and url encodes it |
|
258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
260 | + * |
|
261 | + * @param array|string $post_data The raw POST data |
|
262 | + * @return string A string of post data |
|
263 | + */ |
|
264 | 264 | private function build_post_data($post_data) |
265 | 265 | { |
266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * Sets the final cURL options for the current call |
|
283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
284 | - * - sets the callback function now that $this is existing |
|
285 | - * @return void |
|
286 | - */ |
|
282 | + * Sets the final cURL options for the current call |
|
283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
284 | + * - sets the callback function now that $this is existing |
|
285 | + * @return void |
|
286 | + */ |
|
287 | 287 | private function set_options() |
288 | 288 | { |
289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
313 | - * |
|
314 | - * @param string $target_url The URL we want to redirect to |
|
315 | - * @param string $referer_url The URL that we're redirecting from |
|
316 | - */ |
|
311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
313 | + * |
|
314 | + * @param string $target_url The URL we want to redirect to |
|
315 | + * @param string $referer_url The URL that we're redirecting from |
|
316 | + */ |
|
317 | 317 | private function redirect($target_url, $referer_url) |
318 | 318 | { |
319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -31,67 +31,67 @@ |
||
31 | 31 | */ |
32 | 32 | class ReCaptcha |
33 | 33 | { |
34 | - /** |
|
35 | - * Version of this client library. |
|
36 | - * @const string |
|
37 | - */ |
|
38 | - const VERSION = 'php_1.1.2'; |
|
34 | + /** |
|
35 | + * Version of this client library. |
|
36 | + * @const string |
|
37 | + */ |
|
38 | + const VERSION = 'php_1.1.2'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Shared secret for the site. |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - private $secret; |
|
40 | + /** |
|
41 | + * Shared secret for the site. |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + private $secret; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Method used to communicate with service. Defaults to POST request. |
|
48 | - * @var RequestMethod |
|
49 | - */ |
|
50 | - private $requestMethod; |
|
46 | + /** |
|
47 | + * Method used to communicate with service. Defaults to POST request. |
|
48 | + * @var RequestMethod |
|
49 | + */ |
|
50 | + private $requestMethod; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Create a configured instance to use the reCAPTCHA service. |
|
54 | - * |
|
55 | - * @param string $secret shared secret between site and reCAPTCHA server. |
|
56 | - * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
57 | - */ |
|
58 | - public function __construct($secret, RequestMethod $requestMethod = null) |
|
59 | - { |
|
60 | - if (empty($secret)) { |
|
61 | - throw new \RuntimeException('No secret provided'); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Create a configured instance to use the reCAPTCHA service. |
|
54 | + * |
|
55 | + * @param string $secret shared secret between site and reCAPTCHA server. |
|
56 | + * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
57 | + */ |
|
58 | + public function __construct($secret, RequestMethod $requestMethod = null) |
|
59 | + { |
|
60 | + if (empty($secret)) { |
|
61 | + throw new \RuntimeException('No secret provided'); |
|
62 | + } |
|
63 | 63 | |
64 | - if (!is_string($secret)) { |
|
65 | - throw new \RuntimeException('The provided secret must be a string'); |
|
66 | - } |
|
64 | + if (!is_string($secret)) { |
|
65 | + throw new \RuntimeException('The provided secret must be a string'); |
|
66 | + } |
|
67 | 67 | |
68 | - $this->secret = $secret; |
|
68 | + $this->secret = $secret; |
|
69 | 69 | |
70 | - if (!is_null($requestMethod)) { |
|
71 | - $this->requestMethod = $requestMethod; |
|
72 | - } else { |
|
73 | - $this->requestMethod = new RequestMethod\Post(); |
|
74 | - } |
|
75 | - } |
|
70 | + if (!is_null($requestMethod)) { |
|
71 | + $this->requestMethod = $requestMethod; |
|
72 | + } else { |
|
73 | + $this->requestMethod = new RequestMethod\Post(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
79 | - * CAPTCHA test. |
|
80 | - * |
|
81 | - * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
82 | - * @param string $remoteIp The end user's IP address. |
|
83 | - * @return Response Response from the service. |
|
84 | - */ |
|
85 | - public function verify($response, $remoteIp = null) |
|
86 | - { |
|
87 | - // Discard empty solution submissions |
|
88 | - if (empty($response)) { |
|
89 | - $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
90 | - return $recaptchaResponse; |
|
91 | - } |
|
77 | + /** |
|
78 | + * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
79 | + * CAPTCHA test. |
|
80 | + * |
|
81 | + * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
82 | + * @param string $remoteIp The end user's IP address. |
|
83 | + * @return Response Response from the service. |
|
84 | + */ |
|
85 | + public function verify($response, $remoteIp = null) |
|
86 | + { |
|
87 | + // Discard empty solution submissions |
|
88 | + if (empty($response)) { |
|
89 | + $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
90 | + return $recaptchaResponse; |
|
91 | + } |
|
92 | 92 | |
93 | - $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
94 | - $rawResponse = $this->requestMethod->submit($params); |
|
95 | - return Response::fromJson($rawResponse); |
|
96 | - } |
|
93 | + $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
94 | + $rawResponse = $this->requestMethod->submit($params); |
|
95 | + return Response::fromJson($rawResponse); |
|
96 | + } |
|
97 | 97 | } |