Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/lib/recaptchalib.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + *
4 + * Note: The class names have been prefixed with pmpro_ to avoid conflicts with other plugins.
5 + *
6 + * This is a PHP library that handles calling reCAPTCHA.
7 + * - Documentation and latest version
8 + * https://developers.google.com/recaptcha/docs/php
9 + * - Get a reCAPTCHA API Key
10 + * https://www.google.com/recaptcha/admin/create
11 + * - Discussion group
12 + * http://groups.google.com/group/recaptcha
13 + *
14 + * @copyright Copyright (c) 2014, Google Inc.
15 + * @link http://www.google.com/recaptcha
16 + *
17 + * Permission is hereby granted, free of charge, to any person obtaining a copy
18 + * of this software and associated documentation files (the "Software"), to deal
19 + * in the Software without restriction, including without limitation the rights
20 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 + * copies of the Software, and to permit persons to whom the Software is
22 + * furnished to do so, subject to the following conditions:
23 + *
24 + * The above copyright notice and this permission notice shall be included in
25 + * all copies or substantial portions of the Software.
26 + *
27 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 + * THE SOFTWARE.
34 + */
35 +
36 + /**
37 + * A ReCaptchaResponse is returned from checkAnswer().
38 + */
39 + class pmpro_ReCaptchaResponse
40 + {
41 + public $success;
42 + public $errorCodes;
43 + }
44 +
45 + class pmpro_ReCaptcha
46 + {
47 + private static $_signupUrl = "https://www.google.com/recaptcha/admin";
48 + private static $_siteVerifyUrl =
49 + "https://www.google.com/recaptcha/api/siteverify?";
50 + private $_secret;
51 + private static $_version = "php_1.0";
52 +
53 + /**
54 + * Constructor.
55 + *
56 + * @param string $secret shared secret between site and ReCAPTCHA server.
57 + */
58 + function __construct($secret)
59 + {
60 + if ($secret == null || $secret == "") {
61 + die("To use reCAPTCHA you must get an API key from <a href='"
62 + . self::$_signupUrl . "'>" . self::$_signupUrl . "</a>");
63 + }
64 + $this->_secret=$secret;
65 + }
66 +
67 + /**
68 + * Submits an HTTP POST to a reCAPTCHA server.
69 + *
70 + * @param string $path url path to recaptcha server.
71 + * @param array $data array of parameters to be sent.
72 + *
73 + * @return string response
74 + */
75 + private function _submitHTTPPost($path, $data)
76 + {
77 + $response = wp_remote_post($path, [
78 + 'method' => 'POST',
79 + 'body' => $data,
80 + ])['body'];
81 +
82 + return $response;
83 + }
84 +
85 + /**
86 + * Calls the reCAPTCHA siteverify API to verify whether the user passes
87 + * CAPTCHA test.
88 + *
89 + * @param string $remoteIp IP address of end user.
90 + * @param string $response response string from recaptcha verification.
91 + *
92 + * @return object recaptchaResponse
93 + */
94 + public function verifyResponse($remoteIp, $response)
95 + {
96 + // Discard empty solution submissions
97 + if ($response == null || strlen($response) == 0) {
98 + $recaptchaResponse = new pmpro_ReCaptchaResponse();
99 + $recaptchaResponse->success = false;
100 + $recaptchaResponse->errorCodes = 'missing-input';
101 + return $recaptchaResponse;
102 + }
103 +
104 + $getResponse = $this->_submitHttpPost(
105 + self::$_siteVerifyUrl,
106 + array (
107 + 'secret' => $this->_secret,
108 + 'remoteip' => $remoteIp,
109 + 'v' => self::$_version,
110 + 'response' => $response
111 + )
112 + );
113 + $answers = json_decode($getResponse, true);
114 + $recaptchaResponse = new pmpro_ReCaptchaResponse();
115 +
116 + if ((bool)$answers['success'] == true) {
117 + $recaptchaResponse->success = true;
118 + } else {
119 + $recaptchaResponse->success = false;
120 + if (!empty($answers['error-codes'])) {
121 + switch ($answers['error-codes'][0]) {
122 + case 'timeout-or-duplicate':
123 + $recaptchaResponse->errorCodes = 'Duplicate or expired reCAPTCHA used';
124 + break;
125 + case 'missing-input-response':
126 + case 'invalid-input-response':
127 + $recaptchaResponse->errorCodes = 'Bad reCAPTCHA result';
128 + break;
129 + case 'missing-input-secret':
130 + case 'invalid-input-secret':
131 + case 'bad-request':
132 + $recaptchaResponse->errorCodes = 'Internal error';
133 + break;
134 + default:
135 + $recaptchaResponse->errorCodes = 'Unknown error';
136 + break;
137 + }
138 + }
139 + }
140 +
141 + return $recaptchaResponse;
142 + }
143 + }
144 + ?>