@@ -32,11 +32,11 @@ |
||
32 | 32 | interface RequestMethod |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Submit the request with the specified parameters. |
|
37 | - * |
|
38 | - * @param RequestParameters $params Request parameters |
|
39 | - * @return string Body of the reCAPTCHA response |
|
40 | - */ |
|
41 | - public function submit(RequestParameters $params); |
|
35 | + /** |
|
36 | + * Submit the request with the specified parameters. |
|
37 | + * |
|
38 | + * @param RequestParameters $params Request parameters |
|
39 | + * @return string Body of the reCAPTCHA response |
|
40 | + */ |
|
41 | + public function submit(RequestParameters $params); |
|
42 | 42 | } |
@@ -36,53 +36,53 @@ |
||
36 | 36 | */ |
37 | 37 | class CurlPost implements RequestMethod |
38 | 38 | { |
39 | - /** |
|
40 | - * URL to which requests are sent via cURL. |
|
41 | - * @const string |
|
42 | - */ |
|
43 | - const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
39 | + /** |
|
40 | + * URL to which requests are sent via cURL. |
|
41 | + * @const string |
|
42 | + */ |
|
43 | + const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Curl connection to the reCAPTCHA service |
|
47 | - * @var Curl |
|
48 | - */ |
|
49 | - private $curl; |
|
45 | + /** |
|
46 | + * Curl connection to the reCAPTCHA service |
|
47 | + * @var Curl |
|
48 | + */ |
|
49 | + private $curl; |
|
50 | 50 | |
51 | - public function __construct(Curl $curl = null) |
|
52 | - { |
|
53 | - if (!is_null($curl)) { |
|
54 | - $this->curl = $curl; |
|
55 | - } else { |
|
56 | - $this->curl = new Curl(); |
|
57 | - } |
|
58 | - } |
|
51 | + public function __construct(Curl $curl = null) |
|
52 | + { |
|
53 | + if (!is_null($curl)) { |
|
54 | + $this->curl = $curl; |
|
55 | + } else { |
|
56 | + $this->curl = new Curl(); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Submit the cURL request with the specified parameters. |
|
62 | - * |
|
63 | - * @param RequestParameters $params Request parameters |
|
64 | - * @return string Body of the reCAPTCHA response |
|
65 | - */ |
|
66 | - public function submit(RequestParameters $params) |
|
67 | - { |
|
68 | - $handle = $this->curl->init(self::SITE_VERIFY_URL); |
|
60 | + /** |
|
61 | + * Submit the cURL request with the specified parameters. |
|
62 | + * |
|
63 | + * @param RequestParameters $params Request parameters |
|
64 | + * @return string Body of the reCAPTCHA response |
|
65 | + */ |
|
66 | + public function submit(RequestParameters $params) |
|
67 | + { |
|
68 | + $handle = $this->curl->init(self::SITE_VERIFY_URL); |
|
69 | 69 | |
70 | - $options = array( |
|
71 | - CURLOPT_POST => true, |
|
72 | - CURLOPT_POSTFIELDS => $params->toQueryString(), |
|
73 | - CURLOPT_HTTPHEADER => array( |
|
74 | - 'Content-Type: application/x-www-form-urlencoded' |
|
75 | - ), |
|
76 | - CURLINFO_HEADER_OUT => false, |
|
77 | - CURLOPT_HEADER => false, |
|
78 | - CURLOPT_RETURNTRANSFER => true, |
|
79 | - CURLOPT_SSL_VERIFYPEER => true |
|
80 | - ); |
|
81 | - $this->curl->setoptArray($handle, $options); |
|
70 | + $options = array( |
|
71 | + CURLOPT_POST => true, |
|
72 | + CURLOPT_POSTFIELDS => $params->toQueryString(), |
|
73 | + CURLOPT_HTTPHEADER => array( |
|
74 | + 'Content-Type: application/x-www-form-urlencoded' |
|
75 | + ), |
|
76 | + CURLINFO_HEADER_OUT => false, |
|
77 | + CURLOPT_HEADER => false, |
|
78 | + CURLOPT_RETURNTRANSFER => true, |
|
79 | + CURLOPT_SSL_VERIFYPEER => true |
|
80 | + ); |
|
81 | + $this->curl->setoptArray($handle, $options); |
|
82 | 82 | |
83 | - $response = $this->curl->exec($handle); |
|
84 | - $this->curl->close($handle); |
|
83 | + $response = $this->curl->exec($handle); |
|
84 | + $this->curl->close($handle); |
|
85 | 85 | |
86 | - return $response; |
|
87 | - } |
|
86 | + return $response; |
|
87 | + } |
|
88 | 88 | } |
@@ -34,37 +34,37 @@ |
||
34 | 34 | */ |
35 | 35 | class Post implements RequestMethod |
36 | 36 | { |
37 | - /** |
|
38 | - * URL to which requests are POSTed. |
|
39 | - * @const string |
|
40 | - */ |
|
41 | - const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
37 | + /** |
|
38 | + * URL to which requests are POSTed. |
|
39 | + * @const string |
|
40 | + */ |
|
41 | + const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Submit the POST request with the specified parameters. |
|
45 | - * |
|
46 | - * @param RequestParameters $params Request parameters |
|
47 | - * @return string Body of the reCAPTCHA response |
|
48 | - */ |
|
49 | - public function submit(RequestParameters $params) |
|
50 | - { |
|
51 | - /** |
|
52 | - * PHP 5.6.0 changed the way you specify the peer name for SSL context options. |
|
53 | - * Using "CN_name" will still work, but it will raise deprecated errors. |
|
54 | - */ |
|
55 | - $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; |
|
56 | - $options = array( |
|
57 | - 'http' => array( |
|
58 | - 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
59 | - 'method' => 'POST', |
|
60 | - 'content' => $params->toQueryString(), |
|
61 | - // Force the peer to validate (not needed in 5.6.0+, but still works |
|
62 | - 'verify_peer' => true, |
|
63 | - // Force the peer validation to use www.google.com |
|
64 | - $peer_key => 'www.google.com', |
|
65 | - ), |
|
66 | - ); |
|
67 | - $context = stream_context_create($options); |
|
68 | - return file_get_contents(self::SITE_VERIFY_URL, false, $context); |
|
69 | - } |
|
43 | + /** |
|
44 | + * Submit the POST request with the specified parameters. |
|
45 | + * |
|
46 | + * @param RequestParameters $params Request parameters |
|
47 | + * @return string Body of the reCAPTCHA response |
|
48 | + */ |
|
49 | + public function submit(RequestParameters $params) |
|
50 | + { |
|
51 | + /** |
|
52 | + * PHP 5.6.0 changed the way you specify the peer name for SSL context options. |
|
53 | + * Using "CN_name" will still work, but it will raise deprecated errors. |
|
54 | + */ |
|
55 | + $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; |
|
56 | + $options = array( |
|
57 | + 'http' => array( |
|
58 | + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", |
|
59 | + 'method' => 'POST', |
|
60 | + 'content' => $params->toQueryString(), |
|
61 | + // Force the peer to validate (not needed in 5.6.0+, but still works |
|
62 | + 'verify_peer' => true, |
|
63 | + // Force the peer validation to use www.google.com |
|
64 | + $peer_key => 'www.google.com', |
|
65 | + ), |
|
66 | + ); |
|
67 | + $context = stream_context_create($options); |
|
68 | + return file_get_contents(self::SITE_VERIFY_URL, false, $context); |
|
69 | + } |
|
70 | 70 | } |
@@ -36,86 +36,86 @@ |
||
36 | 36 | */ |
37 | 37 | class SocketPost implements RequestMethod |
38 | 38 | { |
39 | - /** |
|
40 | - * reCAPTCHA service host. |
|
41 | - * @const string |
|
42 | - */ |
|
43 | - const RECAPTCHA_HOST = 'www.google.com'; |
|
44 | - |
|
45 | - /** |
|
46 | - * @const string reCAPTCHA service path |
|
47 | - */ |
|
48 | - const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
49 | - |
|
50 | - /** |
|
51 | - * @const string Bad request error |
|
52 | - */ |
|
53 | - const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
54 | - |
|
55 | - /** |
|
56 | - * @const string Bad response error |
|
57 | - */ |
|
58 | - const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Socket to the reCAPTCHA service |
|
62 | - * @var Socket |
|
63 | - */ |
|
64 | - private $socket; |
|
65 | - |
|
66 | - /** |
|
67 | - * Constructor |
|
68 | - * |
|
69 | - * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
70 | - */ |
|
71 | - public function __construct(Socket $socket = null) |
|
72 | - { |
|
73 | - if (!is_null($socket)) { |
|
74 | - $this->socket = $socket; |
|
75 | - } else { |
|
76 | - $this->socket = new Socket(); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Submit the POST request with the specified parameters. |
|
82 | - * |
|
83 | - * @param RequestParameters $params Request parameters |
|
84 | - * @return string Body of the reCAPTCHA response |
|
85 | - */ |
|
86 | - public function submit(RequestParameters $params) |
|
87 | - { |
|
88 | - $errno = 0; |
|
89 | - $errstr = ''; |
|
90 | - |
|
91 | - if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) { |
|
92 | - return self::BAD_REQUEST; |
|
93 | - } |
|
94 | - |
|
95 | - $content = $params->toQueryString(); |
|
96 | - |
|
97 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
98 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
99 | - $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
100 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
101 | - $request .= "Connection: close\r\n\r\n"; |
|
102 | - $request .= $content . "\r\n\r\n"; |
|
103 | - |
|
104 | - $this->socket->fwrite($request); |
|
105 | - $response = ''; |
|
106 | - |
|
107 | - while (!$this->socket->feof()) { |
|
108 | - $response .= $this->socket->fgets(4096); |
|
109 | - } |
|
110 | - |
|
111 | - $this->socket->fclose(); |
|
112 | - |
|
113 | - if (0 !== strpos($response, 'HTTP/1.1 200 OK')) { |
|
114 | - return self::BAD_RESPONSE; |
|
115 | - } |
|
116 | - |
|
117 | - $parts = preg_split("#\n\s*\n#Uis", $response); |
|
118 | - |
|
119 | - return $parts[1]; |
|
120 | - } |
|
39 | + /** |
|
40 | + * reCAPTCHA service host. |
|
41 | + * @const string |
|
42 | + */ |
|
43 | + const RECAPTCHA_HOST = 'www.google.com'; |
|
44 | + |
|
45 | + /** |
|
46 | + * @const string reCAPTCHA service path |
|
47 | + */ |
|
48 | + const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @const string Bad request error |
|
52 | + */ |
|
53 | + const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
54 | + |
|
55 | + /** |
|
56 | + * @const string Bad response error |
|
57 | + */ |
|
58 | + const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Socket to the reCAPTCHA service |
|
62 | + * @var Socket |
|
63 | + */ |
|
64 | + private $socket; |
|
65 | + |
|
66 | + /** |
|
67 | + * Constructor |
|
68 | + * |
|
69 | + * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
70 | + */ |
|
71 | + public function __construct(Socket $socket = null) |
|
72 | + { |
|
73 | + if (!is_null($socket)) { |
|
74 | + $this->socket = $socket; |
|
75 | + } else { |
|
76 | + $this->socket = new Socket(); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Submit the POST request with the specified parameters. |
|
82 | + * |
|
83 | + * @param RequestParameters $params Request parameters |
|
84 | + * @return string Body of the reCAPTCHA response |
|
85 | + */ |
|
86 | + public function submit(RequestParameters $params) |
|
87 | + { |
|
88 | + $errno = 0; |
|
89 | + $errstr = ''; |
|
90 | + |
|
91 | + if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) { |
|
92 | + return self::BAD_REQUEST; |
|
93 | + } |
|
94 | + |
|
95 | + $content = $params->toQueryString(); |
|
96 | + |
|
97 | + $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
98 | + $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
99 | + $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
100 | + $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
101 | + $request .= "Connection: close\r\n\r\n"; |
|
102 | + $request .= $content . "\r\n\r\n"; |
|
103 | + |
|
104 | + $this->socket->fwrite($request); |
|
105 | + $response = ''; |
|
106 | + |
|
107 | + while (!$this->socket->feof()) { |
|
108 | + $response .= $this->socket->fgets(4096); |
|
109 | + } |
|
110 | + |
|
111 | + $this->socket->fclose(); |
|
112 | + |
|
113 | + if (0 !== strpos($response, 'HTTP/1.1 200 OK')) { |
|
114 | + return self::BAD_RESPONSE; |
|
115 | + } |
|
116 | + |
|
117 | + $parts = preg_split("#\n\s*\n#Uis", $response); |
|
118 | + |
|
119 | + return $parts[1]; |
|
120 | + } |
|
121 | 121 | } |
@@ -31,72 +31,72 @@ |
||
31 | 31 | */ |
32 | 32 | class Response |
33 | 33 | { |
34 | - /** |
|
35 | - * Succes or failure. |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - private $success = false; |
|
34 | + /** |
|
35 | + * Succes or failure. |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + private $success = false; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Error code strings. |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $errorCodes = array(); |
|
40 | + /** |
|
41 | + * Error code strings. |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $errorCodes = array(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Build the response from the expected JSON returned by the service. |
|
48 | - * |
|
49 | - * @param string $json |
|
50 | - * @return \ReCaptcha\Response |
|
51 | - */ |
|
52 | - public static function fromJson($json) |
|
53 | - { |
|
54 | - $responseData = json_decode($json, true); |
|
46 | + /** |
|
47 | + * Build the response from the expected JSON returned by the service. |
|
48 | + * |
|
49 | + * @param string $json |
|
50 | + * @return \ReCaptcha\Response |
|
51 | + */ |
|
52 | + public static function fromJson($json) |
|
53 | + { |
|
54 | + $responseData = json_decode($json, true); |
|
55 | 55 | |
56 | - if (!$responseData) { |
|
57 | - return new Response(false, array('invalid-json')); |
|
58 | - } |
|
56 | + if (!$responseData) { |
|
57 | + return new Response(false, array('invalid-json')); |
|
58 | + } |
|
59 | 59 | |
60 | - if (isset($responseData['success']) && $responseData['success'] == true) { |
|
61 | - return new Response(true); |
|
62 | - } |
|
60 | + if (isset($responseData['success']) && $responseData['success'] == true) { |
|
61 | + return new Response(true); |
|
62 | + } |
|
63 | 63 | |
64 | - if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
|
65 | - return new Response(false, $responseData['error-codes']); |
|
66 | - } |
|
64 | + if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) { |
|
65 | + return new Response(false, $responseData['error-codes']); |
|
66 | + } |
|
67 | 67 | |
68 | - return new Response(false); |
|
69 | - } |
|
68 | + return new Response(false); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Constructor. |
|
73 | - * |
|
74 | - * @param boolean $success |
|
75 | - * @param array $errorCodes |
|
76 | - */ |
|
77 | - public function __construct($success, array $errorCodes = array()) |
|
78 | - { |
|
79 | - $this->success = $success; |
|
80 | - $this->errorCodes = $errorCodes; |
|
81 | - } |
|
71 | + /** |
|
72 | + * Constructor. |
|
73 | + * |
|
74 | + * @param boolean $success |
|
75 | + * @param array $errorCodes |
|
76 | + */ |
|
77 | + public function __construct($success, array $errorCodes = array()) |
|
78 | + { |
|
79 | + $this->success = $success; |
|
80 | + $this->errorCodes = $errorCodes; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Is success? |
|
85 | - * |
|
86 | - * @return boolean |
|
87 | - */ |
|
88 | - public function isSuccess() |
|
89 | - { |
|
90 | - return $this->success; |
|
91 | - } |
|
83 | + /** |
|
84 | + * Is success? |
|
85 | + * |
|
86 | + * @return boolean |
|
87 | + */ |
|
88 | + public function isSuccess() |
|
89 | + { |
|
90 | + return $this->success; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get error codes. |
|
95 | - * |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function getErrorCodes() |
|
99 | - { |
|
100 | - return $this->errorCodes; |
|
101 | - } |
|
93 | + /** |
|
94 | + * Get error codes. |
|
95 | + * |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function getErrorCodes() |
|
99 | + { |
|
100 | + return $this->errorCodes; |
|
101 | + } |
|
102 | 102 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | class EventNew_Notify_Background extends SMF_BackgroundTask |
21 | 21 | { |
22 | 22 | /** |
23 | - * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
23 | + * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
24 | 24 | * @return bool Always returns true |
25 | 25 | */ |
26 | 26 | public function execute() |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'content_action' => empty($this->_details['sender_id']) ? 'new_guest' : 'new', |
82 | 82 | 'is_read' => 0, |
83 | 83 | 'extra' => json_encode( |
84 | - array( |
|
85 | - "event_id" => $this->_details['event_id'], |
|
84 | + array( |
|
85 | + "event_id" => $this->_details['event_id'], |
|
86 | 86 | "event_title" => $this->_details['event_title'] |
87 | 87 | ) |
88 | 88 | ), |
@@ -82,7 +82,7 @@ |
||
82 | 82 | |
83 | 83 | // The helper is crucial. Include it first thing. |
84 | 84 | if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
85 | - die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
|
85 | + die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
|
86 | 86 | |
87 | 87 | require_once($upgrade_path . '/upgrade-helper.php'); |
88 | 88 |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | { |
838 | 838 | uasort($loaded_attachments, function($a, $b) { |
839 | 839 | if ($a['filesize'] == $b['filesize']) |
840 | - return 0; |
|
840 | + return 0; |
|
841 | 841 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
842 | 842 | }); |
843 | 843 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
1242 | 1242 | { |
1243 | 1243 | uasort($loaded_attachments, function($a, $b) { |
1244 | 1244 | if ($a['filesize'] == $b['filesize']) |
1245 | - return 0; |
|
1245 | + return 0; |
|
1246 | 1246 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1247 | 1247 | }); |
1248 | 1248 | } |
@@ -437,9 +437,9 @@ discard block |
||
437 | 437 | { |
438 | 438 | // Sort events by start time (all day events will be listed first) |
439 | 439 | uasort($day['events'], function($a, $b) { |
440 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
441 | - return 0; |
|
442 | - return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
440 | + if ($a['start_timestamp'] == $b['start_timestamp']) |
|
441 | + return 0; |
|
442 | + return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
443 | 443 | }); |
444 | 444 | |
445 | 445 | echo ' |
@@ -619,9 +619,9 @@ discard block |
||
619 | 619 | { |
620 | 620 | // Sort events by start time (all day events will be listed first) |
621 | 621 | uasort($day['events'], function($a, $b) { |
622 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
623 | - return 0; |
|
624 | - return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
622 | + if ($a['start_timestamp'] == $b['start_timestamp']) |
|
623 | + return 0; |
|
624 | + return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
625 | 625 | }); |
626 | 626 | |
627 | 627 | foreach ($day['events'] as $event) |