@@ -22,342 +22,342 @@ |
||
22 | 22 | class EED_Recaptcha_Invisible extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Registration_Config $config |
|
27 | - */ |
|
28 | - private static $config; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array $localized_vars |
|
32 | - */ |
|
33 | - private static $localized_vars; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return EED_Module|EED_Recaptcha |
|
38 | - */ |
|
39 | - public static function instance() |
|
40 | - { |
|
41 | - return parent::get_instance(__CLASS__); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return void |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidArgumentException |
|
50 | - */ |
|
51 | - public static function set_hooks() |
|
52 | - { |
|
53 | - EED_Recaptcha_Invisible::setProperties(); |
|
54 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
55 | - // ticket selection |
|
56 | - add_filter( |
|
57 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
58 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
59 | - 10, 2 |
|
60 | - ); |
|
61 | - add_action( |
|
62 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
63 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
64 | - ); |
|
65 | - // checkout |
|
66 | - add_action( |
|
67 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
68 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
69 | - ); |
|
70 | - add_filter( |
|
71 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
72 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
73 | - 10, 2 |
|
74 | - ); |
|
75 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'setLocalizedVars')); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return void |
|
82 | - * @throws InvalidInterfaceException |
|
83 | - * @throws InvalidDataTypeException |
|
84 | - * @throws InvalidArgumentException |
|
85 | - */ |
|
86 | - public static function set_hooks_admin() |
|
87 | - { |
|
88 | - // admin settings |
|
89 | - add_action( |
|
90 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
91 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
92 | - ); |
|
93 | - add_filter( |
|
94 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
95 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return void |
|
102 | - * @throws InvalidInterfaceException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws InvalidArgumentException |
|
105 | - */ |
|
106 | - public static function setProperties() |
|
107 | - { |
|
108 | - |
|
109 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
110 | - EED_Recaptcha_Invisible::$localized_vars = array( |
|
111 | - 'siteKey' => EED_Recaptcha_Invisible::$config->recaptcha_publickey, |
|
112 | - 'recaptcha_passed' => EED_Recaptcha_Invisible::recaptchaPassed(), |
|
113 | - 'wp_debug' => WP_DEBUG, |
|
114 | - 'mer_active' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return boolean |
|
121 | - */ |
|
122 | - public static function useInvisibleRecaptcha() |
|
123 | - { |
|
124 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
125 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public static function setLocalizedVars() |
|
134 | - { |
|
135 | - wp_localize_script( |
|
136 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
137 | - 'eeRecaptcha', |
|
138 | - apply_filters( |
|
139 | - 'FHEE__EED_Recaptcha_Invisible__setLocalizedVars__localized_vars', |
|
140 | - EED_Recaptcha_Invisible::$localized_vars |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public static function assetsUrl() |
|
150 | - { |
|
151 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param \WP $WP |
|
157 | - */ |
|
158 | - public function run($WP) |
|
159 | - { |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @return boolean |
|
165 | - * @throws InvalidInterfaceException |
|
166 | - * @throws InvalidDataTypeException |
|
167 | - * @throws InvalidArgumentException |
|
168 | - */ |
|
169 | - public static function recaptchaPassed() |
|
170 | - { |
|
171 | - static $recaptcha_passed = null; |
|
172 | - if($recaptcha_passed !== null) { |
|
173 | - return $recaptcha_passed; |
|
174 | - } |
|
175 | - // logged in means you have already passed a turing test of sorts |
|
176 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
177 | - $recaptcha_passed = true; |
|
178 | - return $recaptcha_passed; |
|
179 | - } |
|
180 | - // was test already passed? |
|
181 | - $recaptcha_passed = filter_var( |
|
182 | - EE_Registry::instance()->SSN->get_session_data( |
|
183 | - InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
184 | - ), |
|
185 | - FILTER_VALIDATE_BOOLEAN |
|
186 | - ); |
|
187 | - return $recaptcha_passed; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param EE_Request $request |
|
193 | - * @return bool |
|
194 | - * @throws InvalidArgumentException |
|
195 | - * @throws InvalidDataTypeException |
|
196 | - * @throws InvalidInterfaceException |
|
197 | - * @throws RuntimeException |
|
198 | - */ |
|
199 | - public static function verifyToken(EE_Request $request) |
|
200 | - { |
|
201 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
202 | - if ($invisible_recaptcha->verifyToken($request)) { |
|
203 | - add_action('shutdown', array('EED_Recaptcha_Invisible', 'setSessionData')); |
|
204 | - return true; |
|
205 | - } |
|
206 | - return false; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param EE_Form_Section_Proper $reg_form |
|
212 | - * @return void |
|
213 | - * @throws EE_Error |
|
214 | - * @throws InvalidArgumentException |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws InvalidInterfaceException |
|
217 | - */ |
|
218 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
219 | - { |
|
220 | - // do nothing if form isn't for a reg step or test has already been passed |
|
221 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
222 | - return; |
|
223 | - } |
|
224 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
225 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
226 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
227 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * @param EE_Form_Section_Proper $reg_form |
|
234 | - * @return bool |
|
235 | - * @throws InvalidDataTypeException |
|
236 | - * @throws InvalidInterfaceException |
|
237 | - * @throws EE_Error |
|
238 | - * @throws InvalidArgumentException |
|
239 | - */ |
|
240 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
241 | - { |
|
242 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
243 | - || ! EED_Recaptcha_Invisible::recaptchaPassed(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param array|null $req_data |
|
249 | - * @param EE_Form_Section_Proper $reg_form |
|
250 | - * @return array |
|
251 | - * @throws EE_Error |
|
252 | - * @throws InvalidArgumentException |
|
253 | - * @throws InvalidDataTypeException |
|
254 | - * @throws InvalidInterfaceException |
|
255 | - * @throws RuntimeException |
|
256 | - */ |
|
257 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
258 | - { |
|
259 | - // do nothing if form isn't for a reg step or test has already been passed |
|
260 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
261 | - return $req_data; |
|
262 | - } |
|
263 | - /** @var EE_Request $request */ |
|
264 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
265 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
266 | - if ($request->isAjax()) { |
|
267 | - $json_response = new EE_SPCO_JSON_Response(); |
|
268 | - $json_response->echoAndExit(); |
|
269 | - } |
|
270 | - EEH_URL::safeRedirectAndExit( |
|
271 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
272 | - ); |
|
273 | - } |
|
274 | - return $req_data; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * @param string $html |
|
280 | - * @param EE_Event $event |
|
281 | - * @return string |
|
282 | - * @throws InvalidArgumentException |
|
283 | - * @throws InvalidDataTypeException |
|
284 | - * @throws InvalidInterfaceException |
|
285 | - * @throws EE_Error |
|
286 | - */ |
|
287 | - public static function ticketSelectorForm($html = '', EE_Event $event) |
|
288 | - { |
|
289 | - // do nothing if test has already been passed |
|
290 | - if (EED_Recaptcha_Invisible::recaptchaPassed()) { |
|
291 | - return $html; |
|
292 | - } |
|
293 | - $html .= RecaptchaFactory::create()->getInputHtml( |
|
294 | - array('recaptcha_id' => $event->ID()) |
|
295 | - ); |
|
296 | - return $html; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * @return void |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidInterfaceException |
|
304 | - * @throws InvalidDataTypeException |
|
305 | - * @throws RuntimeException |
|
306 | - */ |
|
307 | - public static function processTicketSelectorForm() |
|
308 | - { |
|
309 | - // do nothing if test has already been passed |
|
310 | - if (EED_Recaptcha_Invisible::recaptchaPassed()) { |
|
311 | - return; |
|
312 | - } |
|
313 | - /** @var EE_Request $request */ |
|
314 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
315 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
316 | - $event_id = $request->get('tkt-slctr-event-id'); |
|
317 | - $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
318 | - ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
319 | - : get_permalink($event_id); |
|
320 | - EEH_URL::safeRedirectAndExit($return_url); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @throws InvalidArgumentException |
|
327 | - * @throws InvalidDataTypeException |
|
328 | - * @throws InvalidInterfaceException |
|
329 | - */ |
|
330 | - public static function setSessionData() |
|
331 | - { |
|
332 | - EE_Registry::instance()->SSN->set_session_data( |
|
333 | - array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
334 | - ); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @throws EE_Error |
|
340 | - * @throws InvalidArgumentException |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidInterfaceException |
|
343 | - */ |
|
344 | - public static function adminSettings() |
|
345 | - { |
|
346 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * @param EE_Registration_Config $EE_Registration_Config |
|
352 | - * @return EE_Registration_Config |
|
353 | - * @throws EE_Error |
|
354 | - * @throws InvalidArgumentException |
|
355 | - * @throws InvalidDataTypeException |
|
356 | - * @throws InvalidInterfaceException |
|
357 | - * @throws ReflectionException |
|
358 | - */ |
|
359 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
360 | - { |
|
361 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
362 | - } |
|
25 | + /** |
|
26 | + * @var EE_Registration_Config $config |
|
27 | + */ |
|
28 | + private static $config; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array $localized_vars |
|
32 | + */ |
|
33 | + private static $localized_vars; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return EED_Module|EED_Recaptcha |
|
38 | + */ |
|
39 | + public static function instance() |
|
40 | + { |
|
41 | + return parent::get_instance(__CLASS__); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return void |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidArgumentException |
|
50 | + */ |
|
51 | + public static function set_hooks() |
|
52 | + { |
|
53 | + EED_Recaptcha_Invisible::setProperties(); |
|
54 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
55 | + // ticket selection |
|
56 | + add_filter( |
|
57 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
58 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
59 | + 10, 2 |
|
60 | + ); |
|
61 | + add_action( |
|
62 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
63 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
64 | + ); |
|
65 | + // checkout |
|
66 | + add_action( |
|
67 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
68 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
69 | + ); |
|
70 | + add_filter( |
|
71 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
72 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
73 | + 10, 2 |
|
74 | + ); |
|
75 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'setLocalizedVars')); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return void |
|
82 | + * @throws InvalidInterfaceException |
|
83 | + * @throws InvalidDataTypeException |
|
84 | + * @throws InvalidArgumentException |
|
85 | + */ |
|
86 | + public static function set_hooks_admin() |
|
87 | + { |
|
88 | + // admin settings |
|
89 | + add_action( |
|
90 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
91 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
92 | + ); |
|
93 | + add_filter( |
|
94 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
95 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return void |
|
102 | + * @throws InvalidInterfaceException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws InvalidArgumentException |
|
105 | + */ |
|
106 | + public static function setProperties() |
|
107 | + { |
|
108 | + |
|
109 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
110 | + EED_Recaptcha_Invisible::$localized_vars = array( |
|
111 | + 'siteKey' => EED_Recaptcha_Invisible::$config->recaptcha_publickey, |
|
112 | + 'recaptcha_passed' => EED_Recaptcha_Invisible::recaptchaPassed(), |
|
113 | + 'wp_debug' => WP_DEBUG, |
|
114 | + 'mer_active' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return boolean |
|
121 | + */ |
|
122 | + public static function useInvisibleRecaptcha() |
|
123 | + { |
|
124 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
125 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public static function setLocalizedVars() |
|
134 | + { |
|
135 | + wp_localize_script( |
|
136 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
137 | + 'eeRecaptcha', |
|
138 | + apply_filters( |
|
139 | + 'FHEE__EED_Recaptcha_Invisible__setLocalizedVars__localized_vars', |
|
140 | + EED_Recaptcha_Invisible::$localized_vars |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public static function assetsUrl() |
|
150 | + { |
|
151 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param \WP $WP |
|
157 | + */ |
|
158 | + public function run($WP) |
|
159 | + { |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @return boolean |
|
165 | + * @throws InvalidInterfaceException |
|
166 | + * @throws InvalidDataTypeException |
|
167 | + * @throws InvalidArgumentException |
|
168 | + */ |
|
169 | + public static function recaptchaPassed() |
|
170 | + { |
|
171 | + static $recaptcha_passed = null; |
|
172 | + if($recaptcha_passed !== null) { |
|
173 | + return $recaptcha_passed; |
|
174 | + } |
|
175 | + // logged in means you have already passed a turing test of sorts |
|
176 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
177 | + $recaptcha_passed = true; |
|
178 | + return $recaptcha_passed; |
|
179 | + } |
|
180 | + // was test already passed? |
|
181 | + $recaptcha_passed = filter_var( |
|
182 | + EE_Registry::instance()->SSN->get_session_data( |
|
183 | + InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
184 | + ), |
|
185 | + FILTER_VALIDATE_BOOLEAN |
|
186 | + ); |
|
187 | + return $recaptcha_passed; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param EE_Request $request |
|
193 | + * @return bool |
|
194 | + * @throws InvalidArgumentException |
|
195 | + * @throws InvalidDataTypeException |
|
196 | + * @throws InvalidInterfaceException |
|
197 | + * @throws RuntimeException |
|
198 | + */ |
|
199 | + public static function verifyToken(EE_Request $request) |
|
200 | + { |
|
201 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
202 | + if ($invisible_recaptcha->verifyToken($request)) { |
|
203 | + add_action('shutdown', array('EED_Recaptcha_Invisible', 'setSessionData')); |
|
204 | + return true; |
|
205 | + } |
|
206 | + return false; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param EE_Form_Section_Proper $reg_form |
|
212 | + * @return void |
|
213 | + * @throws EE_Error |
|
214 | + * @throws InvalidArgumentException |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws InvalidInterfaceException |
|
217 | + */ |
|
218 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
219 | + { |
|
220 | + // do nothing if form isn't for a reg step or test has already been passed |
|
221 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
222 | + return; |
|
223 | + } |
|
224 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
225 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
226 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
227 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * @param EE_Form_Section_Proper $reg_form |
|
234 | + * @return bool |
|
235 | + * @throws InvalidDataTypeException |
|
236 | + * @throws InvalidInterfaceException |
|
237 | + * @throws EE_Error |
|
238 | + * @throws InvalidArgumentException |
|
239 | + */ |
|
240 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
241 | + { |
|
242 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
243 | + || ! EED_Recaptcha_Invisible::recaptchaPassed(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param array|null $req_data |
|
249 | + * @param EE_Form_Section_Proper $reg_form |
|
250 | + * @return array |
|
251 | + * @throws EE_Error |
|
252 | + * @throws InvalidArgumentException |
|
253 | + * @throws InvalidDataTypeException |
|
254 | + * @throws InvalidInterfaceException |
|
255 | + * @throws RuntimeException |
|
256 | + */ |
|
257 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
258 | + { |
|
259 | + // do nothing if form isn't for a reg step or test has already been passed |
|
260 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
261 | + return $req_data; |
|
262 | + } |
|
263 | + /** @var EE_Request $request */ |
|
264 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
265 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
266 | + if ($request->isAjax()) { |
|
267 | + $json_response = new EE_SPCO_JSON_Response(); |
|
268 | + $json_response->echoAndExit(); |
|
269 | + } |
|
270 | + EEH_URL::safeRedirectAndExit( |
|
271 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
272 | + ); |
|
273 | + } |
|
274 | + return $req_data; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * @param string $html |
|
280 | + * @param EE_Event $event |
|
281 | + * @return string |
|
282 | + * @throws InvalidArgumentException |
|
283 | + * @throws InvalidDataTypeException |
|
284 | + * @throws InvalidInterfaceException |
|
285 | + * @throws EE_Error |
|
286 | + */ |
|
287 | + public static function ticketSelectorForm($html = '', EE_Event $event) |
|
288 | + { |
|
289 | + // do nothing if test has already been passed |
|
290 | + if (EED_Recaptcha_Invisible::recaptchaPassed()) { |
|
291 | + return $html; |
|
292 | + } |
|
293 | + $html .= RecaptchaFactory::create()->getInputHtml( |
|
294 | + array('recaptcha_id' => $event->ID()) |
|
295 | + ); |
|
296 | + return $html; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * @return void |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidInterfaceException |
|
304 | + * @throws InvalidDataTypeException |
|
305 | + * @throws RuntimeException |
|
306 | + */ |
|
307 | + public static function processTicketSelectorForm() |
|
308 | + { |
|
309 | + // do nothing if test has already been passed |
|
310 | + if (EED_Recaptcha_Invisible::recaptchaPassed()) { |
|
311 | + return; |
|
312 | + } |
|
313 | + /** @var EE_Request $request */ |
|
314 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
315 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
316 | + $event_id = $request->get('tkt-slctr-event-id'); |
|
317 | + $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
318 | + ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
319 | + : get_permalink($event_id); |
|
320 | + EEH_URL::safeRedirectAndExit($return_url); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @throws InvalidArgumentException |
|
327 | + * @throws InvalidDataTypeException |
|
328 | + * @throws InvalidInterfaceException |
|
329 | + */ |
|
330 | + public static function setSessionData() |
|
331 | + { |
|
332 | + EE_Registry::instance()->SSN->set_session_data( |
|
333 | + array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
334 | + ); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @throws EE_Error |
|
340 | + * @throws InvalidArgumentException |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidInterfaceException |
|
343 | + */ |
|
344 | + public static function adminSettings() |
|
345 | + { |
|
346 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * @param EE_Registration_Config $EE_Registration_Config |
|
352 | + * @return EE_Registration_Config |
|
353 | + * @throws EE_Error |
|
354 | + * @throws InvalidArgumentException |
|
355 | + * @throws InvalidDataTypeException |
|
356 | + * @throws InvalidInterfaceException |
|
357 | + * @throws ReflectionException |
|
358 | + */ |
|
359 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
360 | + { |
|
361 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
362 | + } |
|
363 | 363 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | public static function assetsUrl() |
150 | 150 | { |
151 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
151 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | public static function recaptchaPassed() |
170 | 170 | { |
171 | 171 | static $recaptcha_passed = null; |
172 | - if($recaptcha_passed !== null) { |
|
172 | + if ($recaptcha_passed !== null) { |
|
173 | 173 | return $recaptcha_passed; |
174 | 174 | } |
175 | 175 | // logged in means you have already passed a turing test of sorts |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
219 | 219 | { |
220 | 220 | // do nothing if form isn't for a reg step or test has already been passed |
221 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
221 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
258 | 258 | { |
259 | 259 | // do nothing if form isn't for a reg step or test has already been passed |
260 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
260 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
261 | 261 | return $req_data; |
262 | 262 | } |
263 | 263 | /** @var EE_Request $request */ |
264 | 264 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
265 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
265 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
266 | 266 | if ($request->isAjax()) { |
267 | 267 | $json_response = new EE_SPCO_JSON_Response(); |
268 | 268 | $json_response->echoAndExit(); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | } |
313 | 313 | /** @var EE_Request $request */ |
314 | 314 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
315 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
316 | 316 | $event_id = $request->get('tkt-slctr-event-id'); |
317 | 317 | $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
318 | 318 | ? $request->get("tkt-slctr-return-url-{$event_id}") |
@@ -19,160 +19,160 @@ |
||
19 | 19 | class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base |
20 | 20 | { |
21 | 21 | |
22 | - const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
23 | - |
|
24 | - const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var EE_Registration_Config $config |
|
28 | - */ |
|
29 | - private $config; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $recaptcha_id |
|
33 | - */ |
|
34 | - private $recaptcha_id; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $submit_button_id |
|
38 | - */ |
|
39 | - private $submit_button_id; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param array $input_settings |
|
44 | - * @param EE_Registration_Config $registration_config |
|
45 | - * @throws InvalidArgumentException |
|
46 | - * @throws InvalidDataTypeException |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - */ |
|
49 | - public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
50 | - { |
|
51 | - $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
52 | - parent::__construct($input_settings); |
|
53 | - $registration_config = $registration_config instanceof EE_Registration_Config |
|
54 | - ? $registration_config |
|
55 | - : EE_Registry::instance()->CFG->registration; |
|
56 | - $this->config = $registration_config; |
|
57 | - $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
58 | - ? $input_settings['recaptcha_id'] |
|
59 | - : substr(spl_object_hash($this), 8, 8); |
|
60 | - $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
61 | - ? $input_settings['submit_button_id'] |
|
62 | - : ''; |
|
63 | - $this->registerScripts(); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function useCaptcha() |
|
71 | - { |
|
72 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function language() |
|
80 | - { |
|
81 | - return $this->config->recaptcha_language; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function siteKey() |
|
89 | - { |
|
90 | - return $this->config->recaptcha_publickey; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function secretKey() |
|
98 | - { |
|
99 | - return $this->config->recaptcha_privatekey; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function recaptchaId() |
|
107 | - { |
|
108 | - return $this->recaptcha_id; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function submitButtonId() |
|
116 | - { |
|
117 | - return $this->submit_button_id; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function registerScripts() |
|
125 | - { |
|
126 | - if (! $this->useCaptcha()) { |
|
127 | - return; |
|
128 | - } |
|
129 | - add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
130 | - wp_register_script( |
|
131 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
132 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
133 | - array('espresso_core'), |
|
134 | - EVENT_ESPRESSO_VERSION, |
|
135 | - true |
|
136 | - ); |
|
137 | - wp_register_script( |
|
138 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
139 | - add_query_arg( |
|
140 | - array( |
|
141 | - 'onload' => 'espressoLoadRecaptcha', |
|
142 | - 'render' => 'explicit', |
|
143 | - 'hl' => $this->language(), |
|
144 | - ), |
|
145 | - 'https://www.google.com/recaptcha/api.js?' |
|
146 | - ), |
|
147 | - array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
148 | - false, |
|
149 | - true |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param string $tag |
|
156 | - * @param string $handle |
|
157 | - * @return string |
|
158 | - */ |
|
159 | - public function addScriptAttributes($tag, $handle) |
|
160 | - { |
|
161 | - if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
162 | - $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
163 | - } |
|
164 | - return $tag; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Gets the HTML for displaying the label for this form input |
|
170 | - * according to the form section's layout strategy |
|
171 | - * |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function get_html_for_label() |
|
175 | - { |
|
176 | - return ''; |
|
177 | - } |
|
22 | + const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
23 | + |
|
24 | + const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var EE_Registration_Config $config |
|
28 | + */ |
|
29 | + private $config; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $recaptcha_id |
|
33 | + */ |
|
34 | + private $recaptcha_id; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $submit_button_id |
|
38 | + */ |
|
39 | + private $submit_button_id; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param array $input_settings |
|
44 | + * @param EE_Registration_Config $registration_config |
|
45 | + * @throws InvalidArgumentException |
|
46 | + * @throws InvalidDataTypeException |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + */ |
|
49 | + public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
50 | + { |
|
51 | + $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
52 | + parent::__construct($input_settings); |
|
53 | + $registration_config = $registration_config instanceof EE_Registration_Config |
|
54 | + ? $registration_config |
|
55 | + : EE_Registry::instance()->CFG->registration; |
|
56 | + $this->config = $registration_config; |
|
57 | + $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
58 | + ? $input_settings['recaptcha_id'] |
|
59 | + : substr(spl_object_hash($this), 8, 8); |
|
60 | + $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
61 | + ? $input_settings['submit_button_id'] |
|
62 | + : ''; |
|
63 | + $this->registerScripts(); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function useCaptcha() |
|
71 | + { |
|
72 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function language() |
|
80 | + { |
|
81 | + return $this->config->recaptcha_language; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function siteKey() |
|
89 | + { |
|
90 | + return $this->config->recaptcha_publickey; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function secretKey() |
|
98 | + { |
|
99 | + return $this->config->recaptcha_privatekey; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function recaptchaId() |
|
107 | + { |
|
108 | + return $this->recaptcha_id; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function submitButtonId() |
|
116 | + { |
|
117 | + return $this->submit_button_id; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function registerScripts() |
|
125 | + { |
|
126 | + if (! $this->useCaptcha()) { |
|
127 | + return; |
|
128 | + } |
|
129 | + add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
130 | + wp_register_script( |
|
131 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
132 | + EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
133 | + array('espresso_core'), |
|
134 | + EVENT_ESPRESSO_VERSION, |
|
135 | + true |
|
136 | + ); |
|
137 | + wp_register_script( |
|
138 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
139 | + add_query_arg( |
|
140 | + array( |
|
141 | + 'onload' => 'espressoLoadRecaptcha', |
|
142 | + 'render' => 'explicit', |
|
143 | + 'hl' => $this->language(), |
|
144 | + ), |
|
145 | + 'https://www.google.com/recaptcha/api.js?' |
|
146 | + ), |
|
147 | + array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
148 | + false, |
|
149 | + true |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param string $tag |
|
156 | + * @param string $handle |
|
157 | + * @return string |
|
158 | + */ |
|
159 | + public function addScriptAttributes($tag, $handle) |
|
160 | + { |
|
161 | + if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
162 | + $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
163 | + } |
|
164 | + return $tag; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Gets the HTML for displaying the label for this form input |
|
170 | + * according to the form section's layout strategy |
|
171 | + * |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function get_html_for_label() |
|
175 | + { |
|
176 | + return ''; |
|
177 | + } |
|
178 | 178 | } |