@@ -18,332 +18,332 @@ |
||
18 | 18 | class EED_Recaptcha_Invisible extends EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Registration_Config $config |
|
23 | - */ |
|
24 | - private static $config; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @return EED_Module|EED_Recaptcha |
|
29 | - */ |
|
30 | - public static function instance() |
|
31 | - { |
|
32 | - return parent::get_instance(__CLASS__); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return void |
|
38 | - * @throws InvalidInterfaceException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public static function set_hooks() |
|
43 | - { |
|
44 | - EED_Recaptcha_Invisible::setProperties(); |
|
45 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
46 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
47 | - // ticket selection |
|
48 | - add_filter( |
|
49 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
50 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
51 | - 10, |
|
52 | - 3 |
|
53 | - ); |
|
54 | - add_action( |
|
55 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
56 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
57 | - ); |
|
58 | - } |
|
59 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
60 | - // checkout |
|
61 | - add_action( |
|
62 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
63 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
64 | - ); |
|
65 | - add_filter( |
|
66 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
67 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
68 | - 10, |
|
69 | - 2 |
|
70 | - ); |
|
71 | - } |
|
72 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - */ |
|
83 | - public static function set_hooks_admin() |
|
84 | - { |
|
85 | - EED_Recaptcha_Invisible::setProperties(); |
|
86 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
87 | - add_action( |
|
88 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
89 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
90 | - ); |
|
91 | - } |
|
92 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
93 | - add_filter( |
|
94 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
95 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
96 | - 10, |
|
97 | - 2 |
|
98 | - ); |
|
99 | - } |
|
100 | - // admin settings |
|
101 | - add_action( |
|
102 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | - ); |
|
105 | - add_filter( |
|
106 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidArgumentException |
|
117 | - */ |
|
118 | - public static function setProperties() |
|
119 | - { |
|
120 | - |
|
121 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return boolean |
|
127 | - */ |
|
128 | - public static function useInvisibleRecaptcha() |
|
129 | - { |
|
130 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
131 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param string $form |
|
137 | - * @return boolean |
|
138 | - */ |
|
139 | - public static function protectForm($form) |
|
140 | - { |
|
141 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
142 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return void |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidArgumentException |
|
151 | - */ |
|
152 | - public static function localizeScriptVars() |
|
153 | - { |
|
154 | - /** @var \EventEspresso\core\services\request\Request $request */ |
|
155 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
156 | - // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
157 | - // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
158 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | - return; |
|
160 | - } |
|
161 | - wp_localize_script( |
|
162 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
163 | - 'eeRecaptcha', |
|
164 | - RecaptchaFactory::create()->getLocalizedVars() |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public static function assetsUrl() |
|
173 | - { |
|
174 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param \WP $WP |
|
180 | - */ |
|
181 | - public function run($WP) |
|
182 | - { |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param RequestInterface $request |
|
188 | - * @return bool |
|
189 | - * @throws InvalidArgumentException |
|
190 | - * @throws InvalidDataTypeException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - * @throws RuntimeException |
|
193 | - */ |
|
194 | - public static function verifyToken(RequestInterface $request) |
|
195 | - { |
|
196 | - return RecaptchaFactory::create()->verifyToken($request); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param EE_Form_Section_Proper $reg_form |
|
202 | - * @return void |
|
203 | - * @throws EE_Error |
|
204 | - * @throws InvalidArgumentException |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws InvalidInterfaceException |
|
207 | - * @throws DomainException |
|
208 | - */ |
|
209 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
210 | - { |
|
211 | - // do nothing if form isn't for a reg step or test has already been passed |
|
212 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | - return; |
|
214 | - } |
|
215 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
216 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
217 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
218 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @param EE_Form_Section_Proper $reg_form |
|
225 | - * @return bool |
|
226 | - * @throws InvalidDataTypeException |
|
227 | - * @throws InvalidInterfaceException |
|
228 | - * @throws EE_Error |
|
229 | - * @throws InvalidArgumentException |
|
230 | - */ |
|
231 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
232 | - { |
|
233 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
234 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array|null $req_data |
|
240 | - * @param EE_Form_Section_Proper $reg_form |
|
241 | - * @return array |
|
242 | - * @throws EE_Error |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - * @throws RuntimeException |
|
247 | - */ |
|
248 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
249 | - { |
|
250 | - // do nothing if form isn't for a reg step or test has already been passed |
|
251 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | - return $req_data; |
|
253 | - } |
|
254 | - /** @var RequestInterface $request */ |
|
255 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
256 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | - if ($request->isAjax()) { |
|
258 | - $json_response = new EE_SPCO_JSON_Response(); |
|
259 | - $json_response->echoAndExit(); |
|
260 | - } |
|
261 | - EEH_URL::safeRedirectAndExit( |
|
262 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
263 | - ); |
|
264 | - } |
|
265 | - return $req_data; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $html |
|
271 | - * @param EE_Event $event |
|
272 | - * @param bool $iframe |
|
273 | - * @return string |
|
274 | - * @throws EE_Error |
|
275 | - * @throws InvalidArgumentException |
|
276 | - * @throws InvalidDataTypeException |
|
277 | - * @throws InvalidInterfaceException |
|
278 | - * @throws ReflectionException |
|
279 | - * @throws DomainException |
|
280 | - */ |
|
281 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
282 | - { |
|
283 | - $recaptcha = RecaptchaFactory::create(); |
|
284 | - // do nothing if test has already been passed |
|
285 | - if ($recaptcha->recaptchaPassed()) { |
|
286 | - return $html; |
|
287 | - } |
|
288 | - $html .= $recaptcha->getInputHtml( |
|
289 | - array( |
|
290 | - 'recaptcha_id' => $event->ID(), |
|
291 | - 'iframe' => $iframe, |
|
292 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
293 | - ) |
|
294 | - ); |
|
295 | - return $html; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return void |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidInterfaceException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws RuntimeException |
|
305 | - */ |
|
306 | - public static function processTicketSelectorForm() |
|
307 | - { |
|
308 | - // do nothing if test has already been passed |
|
309 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
310 | - return; |
|
311 | - } |
|
312 | - /** @var RequestInterface $request */ |
|
313 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
314 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | - $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
|
316 | - $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
|
317 | - ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
|
318 | - : get_permalink($event_id); |
|
319 | - EEH_URL::safeRedirectAndExit($return_url); |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @throws EE_Error |
|
326 | - * @throws InvalidArgumentException |
|
327 | - * @throws InvalidDataTypeException |
|
328 | - * @throws InvalidInterfaceException |
|
329 | - */ |
|
330 | - public static function adminSettings() |
|
331 | - { |
|
332 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param EE_Registration_Config $EE_Registration_Config |
|
338 | - * @return EE_Registration_Config |
|
339 | - * @throws EE_Error |
|
340 | - * @throws InvalidArgumentException |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidInterfaceException |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
346 | - { |
|
347 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
348 | - } |
|
21 | + /** |
|
22 | + * @var EE_Registration_Config $config |
|
23 | + */ |
|
24 | + private static $config; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @return EED_Module|EED_Recaptcha |
|
29 | + */ |
|
30 | + public static function instance() |
|
31 | + { |
|
32 | + return parent::get_instance(__CLASS__); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + * @throws InvalidInterfaceException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public static function set_hooks() |
|
43 | + { |
|
44 | + EED_Recaptcha_Invisible::setProperties(); |
|
45 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
46 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
47 | + // ticket selection |
|
48 | + add_filter( |
|
49 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
50 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
51 | + 10, |
|
52 | + 3 |
|
53 | + ); |
|
54 | + add_action( |
|
55 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
56 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
57 | + ); |
|
58 | + } |
|
59 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
60 | + // checkout |
|
61 | + add_action( |
|
62 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
63 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
64 | + ); |
|
65 | + add_filter( |
|
66 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
67 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
68 | + 10, |
|
69 | + 2 |
|
70 | + ); |
|
71 | + } |
|
72 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + */ |
|
83 | + public static function set_hooks_admin() |
|
84 | + { |
|
85 | + EED_Recaptcha_Invisible::setProperties(); |
|
86 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
87 | + add_action( |
|
88 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
89 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
90 | + ); |
|
91 | + } |
|
92 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
93 | + add_filter( |
|
94 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
95 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
96 | + 10, |
|
97 | + 2 |
|
98 | + ); |
|
99 | + } |
|
100 | + // admin settings |
|
101 | + add_action( |
|
102 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | + ); |
|
105 | + add_filter( |
|
106 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidArgumentException |
|
117 | + */ |
|
118 | + public static function setProperties() |
|
119 | + { |
|
120 | + |
|
121 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | + public static function useInvisibleRecaptcha() |
|
129 | + { |
|
130 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
131 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param string $form |
|
137 | + * @return boolean |
|
138 | + */ |
|
139 | + public static function protectForm($form) |
|
140 | + { |
|
141 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
142 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return void |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidArgumentException |
|
151 | + */ |
|
152 | + public static function localizeScriptVars() |
|
153 | + { |
|
154 | + /** @var \EventEspresso\core\services\request\Request $request */ |
|
155 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
156 | + // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
157 | + // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
158 | + if (! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | + return; |
|
160 | + } |
|
161 | + wp_localize_script( |
|
162 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
163 | + 'eeRecaptcha', |
|
164 | + RecaptchaFactory::create()->getLocalizedVars() |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public static function assetsUrl() |
|
173 | + { |
|
174 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param \WP $WP |
|
180 | + */ |
|
181 | + public function run($WP) |
|
182 | + { |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param RequestInterface $request |
|
188 | + * @return bool |
|
189 | + * @throws InvalidArgumentException |
|
190 | + * @throws InvalidDataTypeException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + * @throws RuntimeException |
|
193 | + */ |
|
194 | + public static function verifyToken(RequestInterface $request) |
|
195 | + { |
|
196 | + return RecaptchaFactory::create()->verifyToken($request); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param EE_Form_Section_Proper $reg_form |
|
202 | + * @return void |
|
203 | + * @throws EE_Error |
|
204 | + * @throws InvalidArgumentException |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws InvalidInterfaceException |
|
207 | + * @throws DomainException |
|
208 | + */ |
|
209 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
210 | + { |
|
211 | + // do nothing if form isn't for a reg step or test has already been passed |
|
212 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | + return; |
|
214 | + } |
|
215 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
216 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
217 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
218 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @param EE_Form_Section_Proper $reg_form |
|
225 | + * @return bool |
|
226 | + * @throws InvalidDataTypeException |
|
227 | + * @throws InvalidInterfaceException |
|
228 | + * @throws EE_Error |
|
229 | + * @throws InvalidArgumentException |
|
230 | + */ |
|
231 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
232 | + { |
|
233 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
234 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array|null $req_data |
|
240 | + * @param EE_Form_Section_Proper $reg_form |
|
241 | + * @return array |
|
242 | + * @throws EE_Error |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + * @throws RuntimeException |
|
247 | + */ |
|
248 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
249 | + { |
|
250 | + // do nothing if form isn't for a reg step or test has already been passed |
|
251 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | + return $req_data; |
|
253 | + } |
|
254 | + /** @var RequestInterface $request */ |
|
255 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
256 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | + if ($request->isAjax()) { |
|
258 | + $json_response = new EE_SPCO_JSON_Response(); |
|
259 | + $json_response->echoAndExit(); |
|
260 | + } |
|
261 | + EEH_URL::safeRedirectAndExit( |
|
262 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
263 | + ); |
|
264 | + } |
|
265 | + return $req_data; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $html |
|
271 | + * @param EE_Event $event |
|
272 | + * @param bool $iframe |
|
273 | + * @return string |
|
274 | + * @throws EE_Error |
|
275 | + * @throws InvalidArgumentException |
|
276 | + * @throws InvalidDataTypeException |
|
277 | + * @throws InvalidInterfaceException |
|
278 | + * @throws ReflectionException |
|
279 | + * @throws DomainException |
|
280 | + */ |
|
281 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
282 | + { |
|
283 | + $recaptcha = RecaptchaFactory::create(); |
|
284 | + // do nothing if test has already been passed |
|
285 | + if ($recaptcha->recaptchaPassed()) { |
|
286 | + return $html; |
|
287 | + } |
|
288 | + $html .= $recaptcha->getInputHtml( |
|
289 | + array( |
|
290 | + 'recaptcha_id' => $event->ID(), |
|
291 | + 'iframe' => $iframe, |
|
292 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
293 | + ) |
|
294 | + ); |
|
295 | + return $html; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return void |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidInterfaceException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws RuntimeException |
|
305 | + */ |
|
306 | + public static function processTicketSelectorForm() |
|
307 | + { |
|
308 | + // do nothing if test has already been passed |
|
309 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
310 | + return; |
|
311 | + } |
|
312 | + /** @var RequestInterface $request */ |
|
313 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
314 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | + $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
|
316 | + $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
|
317 | + ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
|
318 | + : get_permalink($event_id); |
|
319 | + EEH_URL::safeRedirectAndExit($return_url); |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @throws EE_Error |
|
326 | + * @throws InvalidArgumentException |
|
327 | + * @throws InvalidDataTypeException |
|
328 | + * @throws InvalidInterfaceException |
|
329 | + */ |
|
330 | + public static function adminSettings() |
|
331 | + { |
|
332 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param EE_Registration_Config $EE_Registration_Config |
|
338 | + * @return EE_Registration_Config |
|
339 | + * @throws EE_Error |
|
340 | + * @throws InvalidArgumentException |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidInterfaceException |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
346 | + { |
|
347 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
348 | + } |
|
349 | 349 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
156 | 156 | // Invisible Recaptcha is ONLY ever required for the frontend and admin |
157 | 157 | // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
158 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | + if ( ! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | wp_localize_script( |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public static function assetsUrl() |
173 | 173 | { |
174 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
174 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
210 | 210 | { |
211 | 211 | // do nothing if form isn't for a reg step or test has already been passed |
212 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -248,12 +248,12 @@ discard block |
||
248 | 248 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
249 | 249 | { |
250 | 250 | // do nothing if form isn't for a reg step or test has already been passed |
251 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | 252 | return $req_data; |
253 | 253 | } |
254 | 254 | /** @var RequestInterface $request */ |
255 | 255 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
256 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | 257 | if ($request->isAjax()) { |
258 | 258 | $json_response = new EE_SPCO_JSON_Response(); |
259 | 259 | $json_response->echoAndExit(); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | /** @var RequestInterface $request */ |
313 | 313 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
314 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | 315 | $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
316 | 316 | $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
317 | 317 | ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
@@ -27,258 +27,258 @@ |
||
27 | 27 | class InvisibleRecaptcha |
28 | 28 | { |
29 | 29 | |
30 | - const URL_GOOGLE_RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'; |
|
30 | + const URL_GOOGLE_RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'; |
|
31 | 31 | |
32 | - const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed'; |
|
32 | + const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var EE_Registration_Config $config |
|
36 | - */ |
|
37 | - private $config; |
|
34 | + /** |
|
35 | + * @var EE_Registration_Config $config |
|
36 | + */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var EE_Session $session |
|
41 | - */ |
|
42 | - private $session; |
|
39 | + /** |
|
40 | + * @var EE_Session $session |
|
41 | + */ |
|
42 | + private $session; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var boolean $recaptcha_passed |
|
46 | - */ |
|
47 | - private $recaptcha_passed; |
|
44 | + /** |
|
45 | + * @var boolean $recaptcha_passed |
|
46 | + */ |
|
47 | + private $recaptcha_passed; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * InvisibleRecaptcha constructor. |
|
52 | - * |
|
53 | - * @param EE_Registration_Config $registration_config |
|
54 | - * @param EE_Session $session |
|
55 | - */ |
|
56 | - public function __construct(EE_Registration_Config $registration_config, EE_Session $session) |
|
57 | - { |
|
58 | - $this->config = $registration_config; |
|
59 | - $this->session = $session; |
|
60 | - } |
|
50 | + /** |
|
51 | + * InvisibleRecaptcha constructor. |
|
52 | + * |
|
53 | + * @param EE_Registration_Config $registration_config |
|
54 | + * @param EE_Session $session |
|
55 | + */ |
|
56 | + public function __construct(EE_Registration_Config $registration_config, EE_Session $session) |
|
57 | + { |
|
58 | + $this->config = $registration_config; |
|
59 | + $this->session = $session; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @return boolean |
|
65 | - */ |
|
66 | - public function useInvisibleRecaptcha() |
|
67 | - { |
|
68 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
69 | - } |
|
63 | + /** |
|
64 | + * @return boolean |
|
65 | + */ |
|
66 | + public function useInvisibleRecaptcha() |
|
67 | + { |
|
68 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * @param array $input_settings |
|
74 | - * @return EE_Invisible_Recaptcha_Input |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws InvalidArgumentException |
|
78 | - * @throws DomainException |
|
79 | - */ |
|
80 | - public function getInput(array $input_settings = array()) |
|
81 | - { |
|
82 | - return new EE_Invisible_Recaptcha_Input( |
|
83 | - $input_settings, |
|
84 | - $this->config |
|
85 | - ); |
|
86 | - } |
|
72 | + /** |
|
73 | + * @param array $input_settings |
|
74 | + * @return EE_Invisible_Recaptcha_Input |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws InvalidArgumentException |
|
78 | + * @throws DomainException |
|
79 | + */ |
|
80 | + public function getInput(array $input_settings = array()) |
|
81 | + { |
|
82 | + return new EE_Invisible_Recaptcha_Input( |
|
83 | + $input_settings, |
|
84 | + $this->config |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param array $input_settings |
|
91 | - * @return string |
|
92 | - * @throws EE_Error |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws InvalidArgumentException |
|
96 | - * @throws DomainException |
|
97 | - */ |
|
98 | - public function getInputHtml(array $input_settings = array()) |
|
99 | - { |
|
100 | - return $this->getInput($input_settings)->get_html_for_input(); |
|
101 | - } |
|
89 | + /** |
|
90 | + * @param array $input_settings |
|
91 | + * @return string |
|
92 | + * @throws EE_Error |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws InvalidArgumentException |
|
96 | + * @throws DomainException |
|
97 | + */ |
|
98 | + public function getInputHtml(array $input_settings = array()) |
|
99 | + { |
|
100 | + return $this->getInput($input_settings)->get_html_for_input(); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @param EE_Form_Section_Proper $form |
|
106 | - * @param array $input_settings |
|
107 | - * @throws EE_Error |
|
108 | - * @throws InvalidArgumentException |
|
109 | - * @throws InvalidDataTypeException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - * @throws DomainException |
|
112 | - */ |
|
113 | - public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array()) |
|
114 | - { |
|
115 | - $form->add_subsections( |
|
116 | - array( |
|
117 | - 'espresso_recaptcha' => $this->getInput($input_settings), |
|
118 | - ), |
|
119 | - null, |
|
120 | - false |
|
121 | - ); |
|
122 | - } |
|
104 | + /** |
|
105 | + * @param EE_Form_Section_Proper $form |
|
106 | + * @param array $input_settings |
|
107 | + * @throws EE_Error |
|
108 | + * @throws InvalidArgumentException |
|
109 | + * @throws InvalidDataTypeException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + * @throws DomainException |
|
112 | + */ |
|
113 | + public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array()) |
|
114 | + { |
|
115 | + $form->add_subsections( |
|
116 | + array( |
|
117 | + 'espresso_recaptcha' => $this->getInput($input_settings), |
|
118 | + ), |
|
119 | + null, |
|
120 | + false |
|
121 | + ); |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - /** |
|
126 | - * @param RequestInterface $request |
|
127 | - * @return boolean |
|
128 | - * @throws InvalidArgumentException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - * @throws InvalidInterfaceException |
|
131 | - * @throws RuntimeException |
|
132 | - */ |
|
133 | - public function verifyToken(RequestInterface $request) |
|
134 | - { |
|
135 | - static $previous_recaptcha_response = array(); |
|
136 | - $grecaptcha_response = $request->getRequestParam('g-recaptcha-response'); |
|
137 | - if ($grecaptcha_response === null) { |
|
138 | - $this->generateError( |
|
139 | - sprintf( |
|
140 | - esc_html__( |
|
141 | - 'The "%1$s" parameter is missing.', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - 'g-recaptcha-response' |
|
145 | - ), |
|
146 | - true |
|
147 | - ); |
|
148 | - return false; |
|
149 | - } |
|
150 | - // if this token has already been verified, then return previous response |
|
151 | - if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
152 | - return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
153 | - } |
|
154 | - // will update to true if everything passes |
|
155 | - $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
156 | - $response = wp_safe_remote_post( |
|
157 | - InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
|
158 | - array( |
|
159 | - 'body' => array( |
|
160 | - 'secret' => $this->config->recaptcha_privatekey, |
|
161 | - 'response' => $grecaptcha_response, |
|
162 | - 'remoteip' => $request->ipAddress(), |
|
163 | - ), |
|
164 | - ) |
|
165 | - ); |
|
166 | - if ($response instanceof WP_Error) { |
|
167 | - $this->generateError($response->get_error_messages()); |
|
168 | - return false; |
|
169 | - } |
|
170 | - $results = json_decode(wp_remote_retrieve_body($response), true); |
|
171 | - if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
|
172 | - $errors = array_map( |
|
173 | - array($this, 'getErrorCode'), |
|
174 | - $results['error-codes'] |
|
175 | - ); |
|
176 | - if (isset($results['challenge_ts'])) { |
|
177 | - $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
178 | - } |
|
179 | - $this->generateError(implode(' ', $errors), true); |
|
180 | - } |
|
181 | - $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
182 | - add_action('shutdown', array($this, 'setSessionData')); |
|
183 | - return true; |
|
184 | - } |
|
125 | + /** |
|
126 | + * @param RequestInterface $request |
|
127 | + * @return boolean |
|
128 | + * @throws InvalidArgumentException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + * @throws InvalidInterfaceException |
|
131 | + * @throws RuntimeException |
|
132 | + */ |
|
133 | + public function verifyToken(RequestInterface $request) |
|
134 | + { |
|
135 | + static $previous_recaptcha_response = array(); |
|
136 | + $grecaptcha_response = $request->getRequestParam('g-recaptcha-response'); |
|
137 | + if ($grecaptcha_response === null) { |
|
138 | + $this->generateError( |
|
139 | + sprintf( |
|
140 | + esc_html__( |
|
141 | + 'The "%1$s" parameter is missing.', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + 'g-recaptcha-response' |
|
145 | + ), |
|
146 | + true |
|
147 | + ); |
|
148 | + return false; |
|
149 | + } |
|
150 | + // if this token has already been verified, then return previous response |
|
151 | + if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
152 | + return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
153 | + } |
|
154 | + // will update to true if everything passes |
|
155 | + $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
156 | + $response = wp_safe_remote_post( |
|
157 | + InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
|
158 | + array( |
|
159 | + 'body' => array( |
|
160 | + 'secret' => $this->config->recaptcha_privatekey, |
|
161 | + 'response' => $grecaptcha_response, |
|
162 | + 'remoteip' => $request->ipAddress(), |
|
163 | + ), |
|
164 | + ) |
|
165 | + ); |
|
166 | + if ($response instanceof WP_Error) { |
|
167 | + $this->generateError($response->get_error_messages()); |
|
168 | + return false; |
|
169 | + } |
|
170 | + $results = json_decode(wp_remote_retrieve_body($response), true); |
|
171 | + if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
|
172 | + $errors = array_map( |
|
173 | + array($this, 'getErrorCode'), |
|
174 | + $results['error-codes'] |
|
175 | + ); |
|
176 | + if (isset($results['challenge_ts'])) { |
|
177 | + $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
178 | + } |
|
179 | + $this->generateError(implode(' ', $errors), true); |
|
180 | + } |
|
181 | + $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
182 | + add_action('shutdown', array($this, 'setSessionData')); |
|
183 | + return true; |
|
184 | + } |
|
185 | 185 | |
186 | 186 | |
187 | - /** |
|
188 | - * @param string $error_response |
|
189 | - * @param bool $show_errors |
|
190 | - * @return void |
|
191 | - * @throws RuntimeException |
|
192 | - */ |
|
193 | - public function generateError($error_response = '', $show_errors = false) |
|
194 | - { |
|
195 | - throw new RuntimeException( |
|
196 | - sprintf( |
|
197 | - esc_html__( |
|
198 | - 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - '<br />', |
|
202 | - $show_errors || current_user_can('manage_options') ? $error_response : '' |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
187 | + /** |
|
188 | + * @param string $error_response |
|
189 | + * @param bool $show_errors |
|
190 | + * @return void |
|
191 | + * @throws RuntimeException |
|
192 | + */ |
|
193 | + public function generateError($error_response = '', $show_errors = false) |
|
194 | + { |
|
195 | + throw new RuntimeException( |
|
196 | + sprintf( |
|
197 | + esc_html__( |
|
198 | + 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + '<br />', |
|
202 | + $show_errors || current_user_can('manage_options') ? $error_response : '' |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | 206 | |
207 | 207 | |
208 | - /** |
|
209 | - * @param string $error_code |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function getErrorCode(&$error_code) |
|
213 | - { |
|
214 | - $error_codes = array( |
|
215 | - 'missing-input-secret' => 'The secret parameter is missing.', |
|
216 | - 'invalid-input-secret' => 'The secret parameter is invalid or malformed.', |
|
217 | - 'missing-input-response' => 'The response parameter is missing.', |
|
218 | - 'invalid-input-response' => 'The response parameter is invalid or malformed.', |
|
219 | - 'bad-request' => 'The request is invalid or malformed.', |
|
220 | - 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
|
221 | - ); |
|
222 | - return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
223 | - } |
|
208 | + /** |
|
209 | + * @param string $error_code |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function getErrorCode(&$error_code) |
|
213 | + { |
|
214 | + $error_codes = array( |
|
215 | + 'missing-input-secret' => 'The secret parameter is missing.', |
|
216 | + 'invalid-input-secret' => 'The secret parameter is invalid or malformed.', |
|
217 | + 'missing-input-response' => 'The response parameter is missing.', |
|
218 | + 'invalid-input-response' => 'The response parameter is invalid or malformed.', |
|
219 | + 'bad-request' => 'The request is invalid or malformed.', |
|
220 | + 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
|
221 | + ); |
|
222 | + return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * @return array |
|
228 | - * @throws InvalidInterfaceException |
|
229 | - * @throws InvalidDataTypeException |
|
230 | - * @throws InvalidArgumentException |
|
231 | - */ |
|
232 | - public function getLocalizedVars() |
|
233 | - { |
|
234 | - return (array) apply_filters( |
|
235 | - 'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars', |
|
236 | - array( |
|
237 | - 'siteKey' => $this->config->recaptcha_publickey, |
|
238 | - 'recaptcha_passed' => $this->recaptchaPassed(), |
|
239 | - 'wp_debug' => WP_DEBUG, |
|
240 | - 'disable_submit' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
241 | - ) |
|
242 | - ); |
|
243 | - } |
|
226 | + /** |
|
227 | + * @return array |
|
228 | + * @throws InvalidInterfaceException |
|
229 | + * @throws InvalidDataTypeException |
|
230 | + * @throws InvalidArgumentException |
|
231 | + */ |
|
232 | + public function getLocalizedVars() |
|
233 | + { |
|
234 | + return (array) apply_filters( |
|
235 | + 'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars', |
|
236 | + array( |
|
237 | + 'siteKey' => $this->config->recaptcha_publickey, |
|
238 | + 'recaptcha_passed' => $this->recaptchaPassed(), |
|
239 | + 'wp_debug' => WP_DEBUG, |
|
240 | + 'disable_submit' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
241 | + ) |
|
242 | + ); |
|
243 | + } |
|
244 | 244 | |
245 | 245 | |
246 | - /** |
|
247 | - * @return boolean |
|
248 | - * @throws InvalidInterfaceException |
|
249 | - * @throws InvalidDataTypeException |
|
250 | - * @throws InvalidArgumentException |
|
251 | - */ |
|
252 | - public function recaptchaPassed() |
|
253 | - { |
|
254 | - if ($this->recaptcha_passed !== null) { |
|
255 | - return $this->recaptcha_passed; |
|
256 | - } |
|
257 | - // logged in means you have already passed a turing test of sorts |
|
258 | - if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
259 | - $this->recaptcha_passed = true; |
|
260 | - return $this->recaptcha_passed; |
|
261 | - } |
|
262 | - // was test already passed? |
|
263 | - $this->recaptcha_passed = filter_var( |
|
264 | - $this->session->get_session_data( |
|
265 | - InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
266 | - ), |
|
267 | - FILTER_VALIDATE_BOOLEAN |
|
268 | - ); |
|
269 | - return $this->recaptcha_passed; |
|
270 | - } |
|
246 | + /** |
|
247 | + * @return boolean |
|
248 | + * @throws InvalidInterfaceException |
|
249 | + * @throws InvalidDataTypeException |
|
250 | + * @throws InvalidArgumentException |
|
251 | + */ |
|
252 | + public function recaptchaPassed() |
|
253 | + { |
|
254 | + if ($this->recaptcha_passed !== null) { |
|
255 | + return $this->recaptcha_passed; |
|
256 | + } |
|
257 | + // logged in means you have already passed a turing test of sorts |
|
258 | + if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
259 | + $this->recaptcha_passed = true; |
|
260 | + return $this->recaptcha_passed; |
|
261 | + } |
|
262 | + // was test already passed? |
|
263 | + $this->recaptcha_passed = filter_var( |
|
264 | + $this->session->get_session_data( |
|
265 | + InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
266 | + ), |
|
267 | + FILTER_VALIDATE_BOOLEAN |
|
268 | + ); |
|
269 | + return $this->recaptcha_passed; |
|
270 | + } |
|
271 | 271 | |
272 | 272 | |
273 | - /** |
|
274 | - * @throws InvalidArgumentException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - */ |
|
278 | - public function setSessionData() |
|
279 | - { |
|
280 | - $this->session->set_session_data( |
|
281 | - array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
282 | - ); |
|
283 | - } |
|
273 | + /** |
|
274 | + * @throws InvalidArgumentException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + */ |
|
278 | + public function setSessionData() |
|
279 | + { |
|
280 | + $this->session->set_session_data( |
|
281 | + array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
282 | + ); |
|
283 | + } |
|
284 | 284 | } |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | // if this token has already been verified, then return previous response |
151 | - if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
152 | - return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
151 | + if (isset($previous_recaptcha_response[$grecaptcha_response])) { |
|
152 | + return $previous_recaptcha_response[$grecaptcha_response]; |
|
153 | 153 | } |
154 | 154 | // will update to true if everything passes |
155 | - $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
155 | + $previous_recaptcha_response[$grecaptcha_response] = false; |
|
156 | 156 | $response = wp_safe_remote_post( |
157 | 157 | InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
158 | 158 | array( |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | } |
170 | 170 | $results = json_decode(wp_remote_retrieve_body($response), true); |
171 | 171 | if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
172 | - $errors = array_map( |
|
172 | + $errors = array_map( |
|
173 | 173 | array($this, 'getErrorCode'), |
174 | 174 | $results['error-codes'] |
175 | 175 | ); |
176 | 176 | if (isset($results['challenge_ts'])) { |
177 | - $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
177 | + $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.'; |
|
178 | 178 | } |
179 | 179 | $this->generateError(implode(' ', $errors), true); |
180 | 180 | } |
181 | - $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
181 | + $previous_recaptcha_response[$grecaptcha_response] = true; |
|
182 | 182 | add_action('shutdown', array($this, 'setSessionData')); |
183 | 183 | return true; |
184 | 184 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | 'bad-request' => 'The request is invalid or malformed.', |
220 | 220 | 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
221 | 221 | ); |
222 | - return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
222 | + return isset($error_codes[$error_code]) ? $error_codes[$error_code] : ''; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 |