Completed
Branch BETA-4.9-message-activity (25b3d1)
by
unknown
30:52 queued 13:07
created

EED_Recaptcha::recaptcha_passed()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 8.8571
cc 5
eloc 12
nc 3
nop 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * Event Espresso
4
 *
5
 * Event Registration and Management Plugin for WordPress
6
 *
7
 * @ package			Event Espresso
8
 * @ author			Seth Shoultes
9
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
10
 * @ license			http://eventespresso.com/support/terms-conditions/   * see Plugin Licensing *
11
 * @ link					http://www.eventespresso.com
12
 * @ version		 	4.0
13
 *
14
 * ------------------------------------------------------------------------
15
 *
16
 * EED_Recaptcha
17
 *
18
 * @package		Event Espresso
19
 * @subpackage	/modules/recaptcha/
20
 * @author		Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
class EED_Recaptcha  extends EED_Module {
25
26
27
28
	/**
29
	 * @type bool $_not_a_robot
30
	 */
31
	private static $_not_a_robot;
32
33
34
35
	/**
36
	 * @type string $_recaptcha_response
37
	 */
38
	private static $_recaptcha_response;
39
40
41
42
	/**
43
	 * @return EED_Recaptcha
44
	 */
45
	public static function instance() {
46
		return parent::get_instance( __CLASS__ );
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (get_instance() instead of instance()). Are you sure this is correct? If so, you might want to change this to $this->get_instance().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
47
	}
48
49
50
51
	/**
52
	 * 	set_hooks - for hooking into EE Core, other modules, etc
53
	 *
54
	 *  @access 	public
55
	 *  @return 	void
56
	 */
57
	public static function set_hooks() {
58
		// use_captcha ?
59
		if (
60
			EE_Registry::instance()->CFG->registration->use_captcha
61
			&& ! (
62
				EE_Registry::instance()->REQ->get( 'step', '' ) === 'payment_options'
63
				&& (boolean) EE_Registry::instance()->REQ->get( 'revisit', false ) === true
64
			)
65
		) {
66
			EED_Recaptcha::set_definitions();
67
			EED_Recaptcha::enqueue_styles_and_scripts();
68
			add_action( 'wp', array( 'EED_Recaptcha', 'set_late_hooks' ), 1, 0 );
69
			add_action(
70
				'AHEE__before_spco_whats_next_buttons',
71
				array( 'EED_Recaptcha', 'display_recaptcha' ), 10, 0
72
			);
73
			add_filter(
74
				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
75
				array( 'EED_Recaptcha', 'not_a_robot' ), 10
76
			);
77
			add_filter(
78
				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
79
				array( 'EED_Recaptcha', 'not_a_robot' ), 10
80
			);
81
			add_filter(
82
				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
83
				array( 'EED_Recaptcha', 'recaptcha_response' ), 10, 1
84
			);
85
			add_filter(
86
				'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
87
				array( 'EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method' ), 10, 1
88
			);
89
		}
90
	}
91
92
93
94
	/**
95
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
96
	 *
97
	 *  @access 	public
98
	 *  @return 	void
99
	 */
100
	public static function set_hooks_admin() {
101
		EED_Recaptcha::set_definitions();
102
		// use_captcha ?
103
		if (
104
			EE_Registry::instance()->CFG->registration->use_captcha
105
			&& ! (
106
				EE_Registry::instance()->REQ->get( 'step', '' ) === 'payment_options'
107
				&& (boolean) EE_Registry::instance()->REQ->get( 'revisit', false ) === true
108
			)
109
		) {
110
			EED_Recaptcha::enqueue_styles_and_scripts();
111
			add_filter( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', array( 'EED_Recaptcha', 'not_a_robot' ), 10 );
112
			add_filter( 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', array( 'EED_Recaptcha', 'not_a_robot' ), 10 );
113
			add_filter( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', array( 'EED_Recaptcha', 'recaptcha_response' ), 10, 1 );
114
		}
115
		// admin settings
116
		add_action( 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', array( 'EED_Recaptcha', 'admin_settings' ), 10, 1 );
117
		add_filter( 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', array( 'EED_Recaptcha', 'update_admin_settings' ), 10, 1 );
118
	}
119
120
121
122
	/**
123
	 * 	set_definitions
124
	 *
125
	 *  @access 	public
126
	 *  @return 	void
127
	 */
128
	public static function set_definitions() {
129
		if ( is_user_logged_in() ) {
130
			EED_Recaptcha::$_not_a_robot = true;
131
		}
132
		define( 'RECAPTCHA_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS );
133
		define( 'RECAPTCHA_BASE_URL', plugin_dir_url( __FILE__ ));
134
	}
135
136
137
138
	/**
139
	 * set_late_hooks
140
	 *
141
	 * @access    public
142
	 * @return    void
143
	 */
144
	public static function set_late_hooks() {
145
		add_filter(
146
			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
147
			array( 'EED_Recaptcha', 'not_a_robot' )
148
		);
149
	}
150
151
152
153
	/**
154
	 * 	enqueue_styles_and_scripts
155
	 *
156
	 *  @access 	public
157
	 *  @return 	void
158
	 */
159
	public static function enqueue_styles_and_scripts() {
160
		wp_register_script( 'espresso_recaptcha', RECAPTCHA_BASE_URL . 'scripts' . DS . 'espresso_recaptcha.js', array( 'single_page_checkout' ), EVENT_ESPRESSO_VERSION, TRUE );
161
		wp_register_script( 'google_recaptcha', 'https://www.google.com/recaptcha/api.js?hl=' . EE_Registry::instance()->CFG->registration->recaptcha_language, array( 'espresso_recaptcha' ), EVENT_ESPRESSO_VERSION, TRUE );
162
		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __( 'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.', 'event_espresso' );
163
		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __( 'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.', 'event_espresso' );
164
		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( 'Please complete the anti-spam test before proceeding.', 'event_espresso' );
165
	}
166
167
168
169
	/**
170
	 *    run
171
	 *
172
	 * @access    public
173
	 * @param \WP $WP
174
	 */
175
	public function run( $WP ) {
176
	}
177
178
179
180
	/**
181
	 * not_a_robot
182
	 *  @return boolean
183
	 */
184
	public static function not_a_robot() {
185
		$not_a_robot = is_bool( EED_Recaptcha::$_not_a_robot ) ? EED_Recaptcha::$_not_a_robot :
186
			EED_Recaptcha::recaptcha_passed();
187
		return $not_a_robot;
188
	}
189
190
191
192
193
194
	/**
195
	 * display_recaptcha
196
	 *
197
	 * @access public
198
	 * @return void
199
	 */
200
	public static function display_recaptcha() {
201
		// logged in means you have already passed a turing test of sorts
202
		if ( is_user_logged_in() ) {
203
			return;
204
		}
205
		// don't display if not using recaptcha or user is logged in
206
		if ( EE_Registry::instance()->CFG->registration->use_captcha ) {
207
			// only display if they have NOT passed the test yet
208
			if ( ! EED_Recaptcha::$_not_a_robot ) {
209
				EE_Registry::instance()->load_helper( 'Template' );
210
				EEH_Template::display_template(
211
					RECAPTCHA_BASE_PATH . DS . 'templates' . DS . 'recaptcha.template.php',
212
					array(
213
						'recaptcha_publickey' 	=> EE_Registry::instance()->CFG->registration->recaptcha_publickey,
214
						'recaptcha_theme' 		=> EE_Registry::instance()->CFG->registration->recaptcha_theme,
215
						'recaptcha_type' 			=> EE_Registry::instance()->CFG->registration->recaptcha_type
216
					)
217
				);
218
				wp_enqueue_script( 'google_recaptcha' );
219
			}
220
		}
221
	}
222
223
224
225
	/**
226
	 * bypass_recaptcha_for_spco_load_payment_method
227
	 *
228
	 * @access public
229
	 * @return string
230
	 */
231
	public static function bypass_recaptcha_for_spco_load_payment_method() {
232
		return array(
233
			'EESID' 		=> EE_Registry::instance()->SSN->id(),
234
			'step' 		=> 'payment_options',
235
			'action' 	=> 'switch_spco_billing_form'
236
		);
237
	}
238
239
240
241
	/**
242
	 * recaptcha_passed
243
	 *
244
	 * @access public
245
	 * @return boolean
246
	 */
247
	public static function recaptcha_passed() {
248
		// logged in means you have already passed a turing test of sorts
249
		if ( is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha() ) {
250
			return TRUE;
251
		}
252
		// was test already passed?
253
		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data( 'recaptcha_passed' );
254
		$recaptcha_passed = filter_var( $recaptcha_passed, FILTER_VALIDATE_BOOLEAN );
255
		// verify recaptcha
256
		EED_Recaptcha::_get_recaptcha_response();
257
		if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response ) {
258
			$recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
259
			EE_Registry::instance()->SSN->set_session_data( array( 'recaptcha_passed' => $recaptcha_passed ));
260
			EE_Registry::instance()->SSN->update();
261
		}
262
		EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
263
		return $recaptcha_passed;
264
	}
265
266
267
268
	/**
269
	 * recaptcha_response
270
	 *
271
	 * @access public
272
	 * @param array $recaptcha_response
273
	 * @return boolean
274
	 */
275
	public static function recaptcha_response( $recaptcha_response = array() ) {
276
		if ( EED_Recaptcha::_bypass_recaptcha() ) {
277
			$recaptcha_response['bypass_recaptcha'] = TRUE;
278
			$recaptcha_response['recaptcha_passed'] = TRUE;
279
		} else {
280
			$recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
281
		}
282
		return $recaptcha_response;
283
	}
284
285
286
287
288
	/**
289
	 * 	_bypass_recaptcha
290
	 *
291
	 * 	@access private
292
	 * 	@return 	boolean
293
	 */
294
	private static function _bypass_recaptcha() {
295
		// an array of key value pairs that must match exactly with the incoming request, in order to bypass recaptcha for the current request ONLY
296
		$bypass_request_params_array = apply_filters( 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', array() );
297
		// does $bypass_request_params_array have any values ?
298
		if ( empty( $bypass_request_params_array )) {
299
			return FALSE;
300
		}
301
		// initially set bypass to TRUE
302
		$bypass_recaptcha = TRUE;
303
		foreach ( $bypass_request_params_array as $key => $value ) {
304
			// if $key is not found or value doesn't match exactly, then toggle bypass to FALSE, otherwise carry over it's value. This way, one missed setting results in no bypass
305
			$bypass_recaptcha = isset( $_REQUEST[ $key ] ) && $_REQUEST[ $key ] === $value ? $bypass_recaptcha : FALSE;
306
		}
307
		return $bypass_recaptcha;
308
	}
309
310
311
312
313
	/**
314
	 * 	process_recaptcha
315
	 *
316
	 * 	@access private
317
	 * 	@return 	boolean
318
	 */
319
	private static function _get_recaptcha_response() {
320
		EED_Recaptcha::$_recaptcha_response = EE_Registry::instance()->REQ->get( 'g-recaptcha-response', false );
321
	}
322
323
324
325
326
	/**
327
	 * 	process_recaptcha
328
	 *
329
	 * 	@access private
330
	 * 	@return 	boolean
331
	 */
332
	private static function _process_recaptcha_response() {
333
		// verify library is loaded
334
		if ( ! class_exists( '\\ReCaptcha\\ReCaptcha' )) {
335
			require_once( RECAPTCHA_BASE_PATH . DS . 'autoload.php' );
336
		}
337
		// The response from reCAPTCHA
338
		EED_Recaptcha::_get_recaptcha_response();
339
		$recaptcha_response = EED_Recaptcha::$_recaptcha_response;
340
		// Was there a reCAPTCHA response?
341
		if ( $recaptcha_response ) {
342
			// if allow_url_fopen is Off, then set a different request method
343
			$request_method = ! ini_get( 'allow_url_fopen' ) ? new \ReCaptcha\RequestMethod\SocketPost() : null;
344
			$recaptcha = new \ReCaptcha\ReCaptcha(
345
				EE_Registry::instance()->CFG->registration->recaptcha_privatekey,
346
				$request_method
347
			);
348
			$recaptcha_response = $recaptcha->verify(
349
				EED_Recaptcha::$_recaptcha_response,
350
				$_SERVER[ 'REMOTE_ADDR' ]
351
			);
352
		}
353
		if ( $recaptcha_response instanceof \ReCaptcha\Response && $recaptcha_response->isSuccess() ) {
354
			return TRUE;
355
		}
356
		// sorry... it appears you can't don't know what soup or hamburgers are !!!
357
		return FALSE;
358
	}
359
360
361
362
363
364
	/***************************************		reCAPTCHA ADMIN SETTINGS 		***************************************/
365
366
367
368
	/**
369
	 * admin_settings
370
	 *
371
	 * @access public
372
	 * @return array
373
	 */
374
	public static function admin_settings() {
375
		echo EED_Recaptcha::_recaptcha_settings_form()->get_html_and_js();
376
	}
377
378
379
380
	/**
381
	 * _recaptcha_main_settings
382
	 *
383
	 * @access protected
384
	 * @return EE_Form_Section_Proper
385
	 */
386
	protected static function _recaptcha_settings_form() {
387
388
		EE_Registry::instance()->load_helper( 'HTML' );
389
		EE_Registry::instance()->load_helper( 'Template' );
390
391
		return new EE_Form_Section_Proper(
392
			array(
393
				'name' 					=> 'recaptcha_settings_form',
394
				'html_id' 					=> 'recaptcha_settings_form',
395
				'layout_strategy'		=> new EE_Div_Per_Section_Layout(),
396
				'subsections' 			=> apply_filters(
397
					'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
398
					array(
399
						'main_settings_hdr' 				=> new EE_Form_Section_HTML( EEH_HTML::h2( __( 'reCAPTCHA Anti-spam Settings', 'event_espresso' ) . EEH_Template::get_help_tab_link( 'recaptcha_info' ))),
400
						'main_settings' 						=> EED_Recaptcha::_recaptcha_main_settings(),
401
						'appearance_settings_hdr' 	=> new EE_Form_Section_HTML( EEH_HTML::h2( __( 'reCAPTCHA Appearance', 'event_espresso' ) )),
402
						'appearance_settings' 			=> EED_Recaptcha::_recaptcha_appearance_settings(),
403
						// 'recaptcha_example' 				=> new EE_Form_Section_HTML( EED_Recaptcha::display_recaptcha() ),
404
						'required_fields_note' 			=> new EE_Form_Section_HTML( EEH_HTML::p( __( 'All fields marked with a * are required fields', 'event_espresso' ), '', 'grey-text' ))
405
					)
406
				)
407
			)
408
		);
409
	}
410
411
412
413
	/**
414
	 * _recaptcha_main_settings
415
	 *
416
	 * @access protected
417
	 * @return EE_Form_Section_Proper
418
	 */
419
	protected static function _recaptcha_main_settings() {
420
		return new EE_Form_Section_Proper(
421
			array(
422
				'name' 					=> 'recaptcha_settings_tbl',
423
				'html_id' 					=> 'recaptcha_settings_tbl',
424
				'html_class' 			=> 'form-table',
425
				'layout_strategy'		=> new EE_Admin_Two_Column_Layout(),
426
				'subsections' 			=> apply_filters(
427
					'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections',
428
					array(
429
						'use_captcha' 				=> new EE_Yes_No_Input(
430
							array(
431
								'html_label_text'	 	=> __( 'Use reCAPTCHA', 'event_espresso' ),
432
								'html_help_text' 		=> sprintf(
433
									__( 'reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.', 'event_espresso' ),
434
									'<a href="https://www.google.com/recaptcha/intro/index.html">',
435
									'</a>'
436
								),
437
								'default' 								=> isset( EE_Registry::instance()->CFG->registration->use_captcha ) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE,
438
								'display_html_label_text' 	=> FALSE
439
							)
440
						),
441
						'recaptcha_publickey' 		=> new EE_Text_Input(
442
							array(
443
								'html_label_text'	 	=> __( 'Site Key', 'event_espresso' ),
444
								'html_help_text' 		=> __( 'The site key is used to display the widget on your site.', 'event_espresso' ),
445
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) : ''
446
							)
447
						),
448
						'recaptcha_privatekey' 		=> new EE_Text_Input(
449
							array(
450
								'html_label_text'	 	=> __( 'Secret Key', 'event_espresso' ),
451
								'html_help_text' 		=> __( 'The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.', 'event_espresso' ),
452
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) : ''
453
							)
454
						)
455
					)
456
				)
457
			)
458
		);
459
	}
460
461
462
463
464
465
466
	/**
467
	 * _recaptcha_appearance_settings
468
	 *
469
	 * @access protected
470
	 * @return EE_Form_Section_Proper
471
	 */
472
	protected static function _recaptcha_appearance_settings() {
473
		return new EE_Form_Section_Proper(
474
			array(
475
				'name' 					=> 'recaptcha_appearance_settings_tbl',
476
				'html_id' 					=> 'recaptcha_appearance_settings_tbl',
477
				'html_class' 			=> 'form-table',
478
				'layout_strategy'		=> new EE_Admin_Two_Column_Layout(),
479
				'subsections' 			=> apply_filters(
480
					'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections',
481
					array(
482
						'recaptcha_theme' 		=> new EE_Radio_Button_Input(
483
							array(
484
								'light' => __( 'Light', 'event_espresso' ),
485
								'dark' => __( 'Dark', 'event_espresso' )
486
							),
487
							array(
488
								'html_label_text'	 	=> __( 'Theme', 'event_espresso' ),
489
								'html_help_text' 		=> __( 'The color theme of the widget.', 'event_espresso' ),
490
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_theme ) ? EE_Registry::instance()->CFG->registration->recaptcha_theme : 'light',
491
								'display_html_label_text' => FALSE
492
							)
493
						),
494
						'recaptcha_type' 		=> new EE_Radio_Button_Input(
495
							array(
496
								'image' => __( 'Image', 'event_espresso' ),
497
								'audio' => __( 'Audio', 'event_espresso' )
498
							),
499
							array(
500
								'html_label_text'	 	=> __( 'Type', 'event_espresso' ),
501
								'html_help_text' 		=> __( 'The type of CAPTCHA to serve.', 'event_espresso' ),
502
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_type ) ? EE_Registry::instance()->CFG->registration->recaptcha_type : 'image',
503
								'display_html_label_text' =>FALSE
504
							)
505
						),
506
						'recaptcha_language' 		=> new EE_Select_Input(
507
							array(
508
								 'ar' 			=> __( 'Arabic', 'event_espresso' ),
509
								 'bg' 		=> __( 'Bulgarian', 'event_espresso' ),
510
								 'ca' 			=> __( 'Catalan', 'event_espresso' ),
511
								 'zh-CN' 	=>  __( 'Chinese (Simplified)', 'event_espresso' ),
512
								 'zh-TW' 	=>  __( 'Chinese (Traditional)	', 'event_espresso' ),
513
								 'hr' 			=> __( 'Croatian', 'event_espresso' ),
514
								 'cs' 			=> __( 'Czech', 'event_espresso' ),
515
								 'da' 			=> __( 'Danish', 'event_espresso' ),
516
								 'nl' 			=> __( 'Dutch', 'event_espresso' ),
517
								 'en-GB' 	=>  __( 'English (UK)', 'event_espresso' ),
518
								 'en' 			=> __( 'English (US)', 'event_espresso' ),
519
								 'fil' 			=> __( 'Filipino', 'event_espresso' ),
520
								 'fi' 			=> __( 'Finnish', 'event_espresso' ),
521
								 'fr' 			=> __( 'French', 'event_espresso' ),
522
								 'fr-CA' 	=>  __( 'French (Canadian)', 'event_espresso' ),
523
								 'de' 			=> __( 'German', 'event_espresso' ),
524
								 'de-AT' 	=>  __( 'German (Austria)', 'event_espresso' ),
525
								 'de-CH' 	=>  __( 'German (Switzerland)', 'event_espresso' ),
526
								 'el' 			=> __( 'Greek', 'event_espresso' ),
527
								 'iw' 			=> __( 'Hebrew', 'event_espresso' ),
528
								 'hi' 			=> __( 'Hindi', 'event_espresso' ),
529
								 'hu' 		=> __( 'Hungarian', 'event_espresso' ),
530
								 'id' 			=> __( 'Indonesian', 'event_espresso' ),
531
								 'it' 			=> __( 'Italian', 'event_espresso' ),
532
								 'ja' 			=> __( 'Japanese', 'event_espresso' ),
533
								 'ko' 			=> __( 'Korean', 'event_espresso' ),
534
								 'lv' 			=> __( 'Latvian', 'event_espresso' ),
535
								 'lt' 			=> __( 'Lithuanian', 'event_espresso' ),
536
								 'no' 		=> __( 'Norwegian', 'event_espresso' ),
537
								 'fa' 			=> __( 'Persian', 'event_espresso' ),
538
								 'pl' 			=> __( 'Polish', 'event_espresso' ),
539
								 'pt' 			=> __( 'Portuguese', 'event_espresso' ),
540
								 'pt-BR' 	=>  __( 'Portuguese (Brazil)', 'event_espresso' ),
541
								 'pt-PT' 	=>  __( 'Portuguese (Portugal)', 'event_espresso' ),
542
								 'ro' 			=> __( 'Romanian', 'event_espresso' ),
543
								 'ru' 			=> __( 'Russian', 'event_espresso' ),
544
								 'sr' 			=> __( 'Serbian', 'event_espresso' ),
545
								 'sk' 			=> __( 'Slovak', 'event_espresso' ),
546
								 'sl' 			=> __( 'Slovenian', 'event_espresso' ),
547
								 'es' 			=> __( 'Spanish', 'event_espresso' ),
548
								 'es-419' 	=>  __( 'Spanish (Latin America)', 'event_espresso' ),
549
								 'sv' 			=> __( 'Swedish', 'event_espresso' ),
550
								 'th' 			=> __( 'Thai', 'event_espresso' ),
551
								 'tr' 			=> __( 'Turkish', 'event_espresso' ),
552
								 'uk' 			=> __( 'Ukrainian', 'event_espresso' ),
553
								 'vi' 			=> __( 'Vietnamese', 'event_espresso')
554
							),
555
							array(
556
								'html_label_text'	 	=> __( 'Language', 'event_espresso' ),
557
								'html_help_text' 		=> __( 'Forces the widget to render in a specific language.', 'event_espresso' ),
558
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_language ) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en'
559
							)
560
						)
561
					)
562
				)
563
			)
564
		);
565
	}
566
567
568
569
570
571
	/**
572
	 * _recaptcha_example
573
	 *
574
	 * @access protected
575
	 * @return EE_Form_Section_Proper
576
	 */
577
	protected static function _recaptcha_example() {
578
		//		 if ( !empty( $recaptcha_example ) ) { ?>
579
		<!--		-->
580
		<!--			<h2 class="ee-admin-settings-hdr admin-recaptcha-settings-hdr">-->
581
		<!--				--><?php //_e('reCAPTCHA Example', 'event_espresso'); ?>
582
		<!--			</h2>-->
583
		<!--			<p class="description">--><?php //_e('A reCAPTCHA displaying here means that you have a valid public key entered for the reCAPTCHA settings and this is how the reCAPTCHA will look with the currently set appearance settings.  If you do not see a reCAPTCHA then please doublecheck the key you entered for a public key.', 'event_espresso'); ?><!--</p>-->
584
		<!--			<table class="form-table">-->
585
		<!--				<tbody>-->
586
		<!--		-->
587
		<!--					<tr class="admin-recaptcha-settings-tr">-->
588
		<!--						<td>-->
589
		<!--							--><?php //echo $recaptcha_example; ?>
590
		<!--						</td>-->
591
		<!--					</tr>-->
592
		<!--		-->
593
		<!--				</tbody>-->
594
		<!--			</table>-->
595
		<!--		--><?php //}
596
	}
597
598
599
	/**
600
	 * admin_settings_template
601
	 *
602
	 * @access public
603
	 * @param EE_Registration_Config $EE_Registration_Config
604
	 * @return array
605
	 */
606
	public static function update_admin_settings( EE_Registration_Config $EE_Registration_Config ) {
607
		try {
608
			$recaptcha_settings_form = EED_Recaptcha::_recaptcha_settings_form();
609
			// if not displaying a form, then check for form submission
610
			if ( $recaptcha_settings_form->was_submitted() ) {
611
				// capture form data
612
				$recaptcha_settings_form->receive_form_submission();
613
				// validate form data
614
				if ( $recaptcha_settings_form->is_valid() ) {
615
					// grab validated data from form
616
					$valid_data = $recaptcha_settings_form->valid_data();
617
					// user proofing recaptcha:  If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message.
618
					if (
619
						apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', TRUE, $EE_Registration_Config )
620
						&& $valid_data['main_settings']['use_captcha']
621
						&& ( ! $EE_Registration_Config->use_captcha && ( empty( $valid_data['main_settings']['recaptcha_publickey'] ) || empty( $valid_data['main_settings']['recaptcha_privatekey'] )))
622
					) {
623
						$valid_data['main_settings']['use_captcha'] = FALSE;
624
						EE_Error::add_error( __('The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
625
					}
626
					$EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha'];
627
					$EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey'];
628
					$EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey'];
629
					$EE_Registration_Config->recaptcha_type = $valid_data['appearance_settings']['recaptcha_type'];
630
					$EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme'];
631
					$EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language'];
632
				} else {
633
					if ( $recaptcha_settings_form->submission_error_message() != '' ) {
634
						EE_Error::add_error( $recaptcha_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ );
635
					}
636
				}
637
			}
638
		} catch( EE_Error $e ) {
639
			$e->get_error();
640
		}
641
642
//		d( $EE_Registration_Config );
643
//		die();
644
		return $EE_Registration_Config;
645
	}
646
647
648
}
649
// End of file EED_Recaptcha.module.php
650
// Location: /modules/recaptcha/EED_Recaptcha.module.php
651