Completed
Branch FET-9576-iframes (6f13fd)
by
unknown
72:43 queued 55:40
created

EED_Recaptcha   F

Complexity

Total Complexity 62

Size/Duplication

Total Lines 623
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 20

Importance

Changes 0
Metric Value
dl 0
loc 623
rs 2.0576
c 0
b 0
f 0
wmc 62
lcom 2
cbo 20

21 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 3 1
A bypass_recaptcha_for_spco_load_payment_method() 0 7 1
B recaptcha_passed() 0 18 5
A recaptcha_response() 0 9 2
B _bypass_recaptcha() 0 15 5
A _get_recaptcha_response() 0 3 1
B _process_recaptcha_response() 0 27 6
A admin_settings() 0 3 1
B set_hooks() 0 34 4
B set_hooks_admin() 0 20 5
A set_definitions() 0 7 2
A set_late_hooks() 0 6 1
A enqueue_styles_and_scripts() 0 7 1
A run() 0 2 1
A not_a_robot() 0 5 2
A display_recaptcha() 0 21 4
A _recaptcha_settings_form() 0 22 1
B _recaptcha_main_settings() 0 41 4
B _recaptcha_appearance_settings() 0 94 4
A _recaptcha_example() 0 20 1
D update_admin_settings() 0 40 10

How to fix   Complexity   

Complex Class

Complex classes like EED_Recaptcha often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EED_Recaptcha, and based on these observations, apply Extract Interface, too.

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
            && EE_Registry::instance()->REQ->get( 'step', '' ) !== ''
106
            && ! (
107
				EE_Registry::instance()->REQ->get( 'step', '' ) === 'payment_options'
108
				&& (boolean) EE_Registry::instance()->REQ->get( 'revisit', false ) === true
109
			)
110
		) {
111
			EED_Recaptcha::enqueue_styles_and_scripts();
112
			add_filter( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', array( 'EED_Recaptcha', 'not_a_robot' ), 10 );
113
			add_filter( 'FHEE__EE_SPCO_Reg_Step__set_completed___completed', array( 'EED_Recaptcha', 'not_a_robot' ), 10 );
114
			add_filter( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', array( 'EED_Recaptcha', 'recaptcha_response' ), 10, 1 );
115
		}
116
		// admin settings
117
		add_action( 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', array( 'EED_Recaptcha', 'admin_settings' ), 10, 1 );
118
		add_filter( 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', array( 'EED_Recaptcha', 'update_admin_settings' ), 10, 1 );
119
	}
120
121
122
123
	/**
124
	 * 	set_definitions
125
	 *
126
	 *  @access 	public
127
	 *  @return 	void
128
	 */
129
	public static function set_definitions() {
130
		if ( is_user_logged_in() ) {
131
			EED_Recaptcha::$_not_a_robot = true;
132
		}
133
		define( 'RECAPTCHA_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS );
134
		define( 'RECAPTCHA_BASE_URL', plugin_dir_url( __FILE__ ));
135
	}
136
137
138
139
	/**
140
	 * set_late_hooks
141
	 *
142
	 * @access    public
143
	 * @return    void
144
	 */
145
	public static function set_late_hooks() {
146
		add_filter(
147
			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
148
			array( 'EED_Recaptcha', 'not_a_robot' )
149
		);
150
	}
151
152
153
154
	/**
155
	 * 	enqueue_styles_and_scripts
156
	 *
157
	 *  @access 	public
158
	 *  @return 	void
159
	 */
160
	public static function enqueue_styles_and_scripts() {
161
		wp_register_script( 'espresso_recaptcha', RECAPTCHA_BASE_URL . 'scripts' . DS . 'espresso_recaptcha.js', array( 'single_page_checkout' ), EVENT_ESPRESSO_VERSION, TRUE );
162
		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 );
163
		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' );
164
		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' );
165
		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __( 'Please complete the anti-spam test before proceeding.', 'event_espresso' );
166
	}
167
168
169
170
	/**
171
	 *    run
172
	 *
173
	 * @access    public
174
	 * @param \WP $WP
175
	 */
176
	public function run( $WP ) {
177
	}
178
179
180
181
	/**
182
	 * not_a_robot
183
	 *  @return boolean
184
	 */
185
	public static function not_a_robot() {
186
		$not_a_robot = is_bool( EED_Recaptcha::$_not_a_robot ) ? EED_Recaptcha::$_not_a_robot :
187
			EED_Recaptcha::recaptcha_passed();
188
		return $not_a_robot;
189
	}
190
191
192
193
194
195
	/**
196
	 * display_recaptcha
197
	 *
198
	 * @access public
199
	 * @return void
200
	 */
201
	public static function display_recaptcha() {
202
		// logged in means you have already passed a turing test of sorts
203
		if ( is_user_logged_in() ) {
204
			return;
205
		}
206
		// don't display if not using recaptcha or user is logged in
207
		if ( EE_Registry::instance()->CFG->registration->use_captcha ) {
208
			// only display if they have NOT passed the test yet
209
			if ( ! EED_Recaptcha::$_not_a_robot ) {
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();
0 ignored issues
show
Deprecated Code introduced by
The method EE_Form_Section_Proper::get_html_and_js() has been deprecated with message: since 4.9.0. You should instead call enqueue_js during the "wp_enqueue_scripts" and get_html when you are about to display the form.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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
389
		return new EE_Form_Section_Proper(
390
			array(
391
				'name' 					=> 'recaptcha_settings_form',
392
				'html_id' 					=> 'recaptcha_settings_form',
393
				'layout_strategy'		=> new EE_Div_Per_Section_Layout(),
394
				'subsections' 			=> apply_filters(
395
					'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
396
					array(
397
						'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' ))),
398
						'main_settings' 						=> EED_Recaptcha::_recaptcha_main_settings(),
399
						'appearance_settings_hdr' 	=> new EE_Form_Section_HTML( EEH_HTML::h2( __( 'reCAPTCHA Appearance', 'event_espresso' ) )),
400
						'appearance_settings' 			=> EED_Recaptcha::_recaptcha_appearance_settings(),
401
						// 'recaptcha_example' 				=> new EE_Form_Section_HTML( EED_Recaptcha::display_recaptcha() ),
402
						'required_fields_note' 			=> new EE_Form_Section_HTML( EEH_HTML::p( __( 'All fields marked with a * are required fields', 'event_espresso' ), '', 'grey-text' ))
403
					)
404
				)
405
			)
406
		);
407
	}
408
409
410
411
	/**
412
	 * _recaptcha_main_settings
413
	 *
414
	 * @access protected
415
	 * @return EE_Form_Section_Proper
416
	 */
417
	protected static function _recaptcha_main_settings() {
418
		return new EE_Form_Section_Proper(
419
			array(
420
				'name' 					=> 'recaptcha_settings_tbl',
421
				'html_id' 					=> 'recaptcha_settings_tbl',
422
				'html_class' 			=> 'form-table',
423
				'layout_strategy'		=> new EE_Admin_Two_Column_Layout(),
424
				'subsections' 			=> apply_filters(
425
					'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections',
426
					array(
427
						'use_captcha' 				=> new EE_Yes_No_Input(
428
							array(
429
								'html_label_text'	 	=> __( 'Use reCAPTCHA', 'event_espresso' ),
430
								'html_help_text' 		=> sprintf(
431
									__( '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' ),
432
									'<a href="https://www.google.com/recaptcha/intro/index.html">',
433
									'</a>'
434
								),
435
								'default' 								=> isset( EE_Registry::instance()->CFG->registration->use_captcha ) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE,
436
								'display_html_label_text' 	=> FALSE
437
							)
438
						),
439
						'recaptcha_publickey' 		=> new EE_Text_Input(
440
							array(
441
								'html_label_text'	 	=> __( 'Site Key', 'event_espresso' ),
442
								'html_help_text' 		=> __( 'The site key is used to display the widget on your site.', 'event_espresso' ),
443
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) : ''
444
							)
445
						),
446
						'recaptcha_privatekey' 		=> new EE_Text_Input(
447
							array(
448
								'html_label_text'	 	=> __( 'Secret Key', 'event_espresso' ),
449
								'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' ),
450
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) : ''
451
							)
452
						)
453
					)
454
				)
455
			)
456
		);
457
	}
458
459
460
461
462
463
464
	/**
465
	 * _recaptcha_appearance_settings
466
	 *
467
	 * @access protected
468
	 * @return EE_Form_Section_Proper
469
	 */
470
	protected static function _recaptcha_appearance_settings() {
471
		return new EE_Form_Section_Proper(
472
			array(
473
				'name' 					=> 'recaptcha_appearance_settings_tbl',
474
				'html_id' 					=> 'recaptcha_appearance_settings_tbl',
475
				'html_class' 			=> 'form-table',
476
				'layout_strategy'		=> new EE_Admin_Two_Column_Layout(),
477
				'subsections' 			=> apply_filters(
478
					'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections',
479
					array(
480
						'recaptcha_theme' 		=> new EE_Radio_Button_Input(
481
							array(
482
								'light' => __( 'Light', 'event_espresso' ),
483
								'dark' => __( 'Dark', 'event_espresso' )
484
							),
485
							array(
486
								'html_label_text'	 	=> __( 'Theme', 'event_espresso' ),
487
								'html_help_text' 		=> __( 'The color theme of the widget.', 'event_espresso' ),
488
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_theme ) ? EE_Registry::instance()->CFG->registration->recaptcha_theme : 'light',
489
								'display_html_label_text' => FALSE
490
							)
491
						),
492
						'recaptcha_type' 		=> new EE_Radio_Button_Input(
493
							array(
494
								'image' => __( 'Image', 'event_espresso' ),
495
								'audio' => __( 'Audio', 'event_espresso' )
496
							),
497
							array(
498
								'html_label_text'	 	=> __( 'Type', 'event_espresso' ),
499
								'html_help_text' 		=> __( 'The type of CAPTCHA to serve.', 'event_espresso' ),
500
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_type ) ? EE_Registry::instance()->CFG->registration->recaptcha_type : 'image',
501
								'display_html_label_text' =>FALSE
502
							)
503
						),
504
						'recaptcha_language' 		=> new EE_Select_Input(
505
							array(
506
								 'ar' 			=> __( 'Arabic', 'event_espresso' ),
507
								 'bg' 		=> __( 'Bulgarian', 'event_espresso' ),
508
								 'ca' 			=> __( 'Catalan', 'event_espresso' ),
509
								 'zh-CN' 	=>  __( 'Chinese (Simplified)', 'event_espresso' ),
510
								 'zh-TW' 	=>  __( 'Chinese (Traditional)	', 'event_espresso' ),
511
								 'hr' 			=> __( 'Croatian', 'event_espresso' ),
512
								 'cs' 			=> __( 'Czech', 'event_espresso' ),
513
								 'da' 			=> __( 'Danish', 'event_espresso' ),
514
								 'nl' 			=> __( 'Dutch', 'event_espresso' ),
515
								 'en-GB' 	=>  __( 'English (UK)', 'event_espresso' ),
516
								 'en' 			=> __( 'English (US)', 'event_espresso' ),
517
								 'fil' 			=> __( 'Filipino', 'event_espresso' ),
518
								 'fi' 			=> __( 'Finnish', 'event_espresso' ),
519
								 'fr' 			=> __( 'French', 'event_espresso' ),
520
								 'fr-CA' 	=>  __( 'French (Canadian)', 'event_espresso' ),
521
								 'de' 			=> __( 'German', 'event_espresso' ),
522
								 'de-AT' 	=>  __( 'German (Austria)', 'event_espresso' ),
523
								 'de-CH' 	=>  __( 'German (Switzerland)', 'event_espresso' ),
524
								 'el' 			=> __( 'Greek', 'event_espresso' ),
525
								 'iw' 			=> __( 'Hebrew', 'event_espresso' ),
526
								 'hi' 			=> __( 'Hindi', 'event_espresso' ),
527
								 'hu' 		=> __( 'Hungarian', 'event_espresso' ),
528
								 'id' 			=> __( 'Indonesian', 'event_espresso' ),
529
								 'it' 			=> __( 'Italian', 'event_espresso' ),
530
								 'ja' 			=> __( 'Japanese', 'event_espresso' ),
531
								 'ko' 			=> __( 'Korean', 'event_espresso' ),
532
								 'lv' 			=> __( 'Latvian', 'event_espresso' ),
533
								 'lt' 			=> __( 'Lithuanian', 'event_espresso' ),
534
								 'no' 		=> __( 'Norwegian', 'event_espresso' ),
535
								 'fa' 			=> __( 'Persian', 'event_espresso' ),
536
								 'pl' 			=> __( 'Polish', 'event_espresso' ),
537
								 'pt' 			=> __( 'Portuguese', 'event_espresso' ),
538
								 'pt-BR' 	=>  __( 'Portuguese (Brazil)', 'event_espresso' ),
539
								 'pt-PT' 	=>  __( 'Portuguese (Portugal)', 'event_espresso' ),
540
								 'ro' 			=> __( 'Romanian', 'event_espresso' ),
541
								 'ru' 			=> __( 'Russian', 'event_espresso' ),
542
								 'sr' 			=> __( 'Serbian', 'event_espresso' ),
543
								 'sk' 			=> __( 'Slovak', 'event_espresso' ),
544
								 'sl' 			=> __( 'Slovenian', 'event_espresso' ),
545
								 'es' 			=> __( 'Spanish', 'event_espresso' ),
546
								 'es-419' 	=>  __( 'Spanish (Latin America)', 'event_espresso' ),
547
								 'sv' 			=> __( 'Swedish', 'event_espresso' ),
548
								 'th' 			=> __( 'Thai', 'event_espresso' ),
549
								 'tr' 			=> __( 'Turkish', 'event_espresso' ),
550
								 'uk' 			=> __( 'Ukrainian', 'event_espresso' ),
551
								 'vi' 			=> __( 'Vietnamese', 'event_espresso')
552
							),
553
							array(
554
								'html_label_text'	 	=> __( 'Language', 'event_espresso' ),
555
								'html_help_text' 		=> __( 'Forces the widget to render in a specific language.', 'event_espresso' ),
556
								'default' 					=> isset( EE_Registry::instance()->CFG->registration->recaptcha_language ) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en'
557
							)
558
						)
559
					)
560
				)
561
			)
562
		);
563
	}
564
565
566
567
568
569
	/**
570
	 * _recaptcha_example
571
	 *
572
	 * @access protected
573
	 * @return EE_Form_Section_Proper
574
	 */
575
	protected static function _recaptcha_example() {
576
		//		 if ( !empty( $recaptcha_example ) ) { ?>
577
		<!--		-->
578
		<!--			<h2 class="ee-admin-settings-hdr admin-recaptcha-settings-hdr">-->
579
		<!--				--><?php //_e('reCAPTCHA Example', 'event_espresso'); ?>
580
		<!--			</h2>-->
581
		<!--			<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>-->
582
		<!--			<table class="form-table">-->
583
		<!--				<tbody>-->
584
		<!--		-->
585
		<!--					<tr class="admin-recaptcha-settings-tr">-->
586
		<!--						<td>-->
587
		<!--							--><?php //echo $recaptcha_example; ?>
588
		<!--						</td>-->
589
		<!--					</tr>-->
590
		<!--		-->
591
		<!--				</tbody>-->
592
		<!--			</table>-->
593
		<!--		--><?php //}
594
	}
595
596
597
	/**
598
	 * admin_settings_template
599
	 *
600
	 * @access public
601
	 * @param EE_Registration_Config $EE_Registration_Config
602
	 * @return array
603
	 */
604
	public static function update_admin_settings( EE_Registration_Config $EE_Registration_Config ) {
605
		try {
606
			$recaptcha_settings_form = EED_Recaptcha::_recaptcha_settings_form();
607
			// if not displaying a form, then check for form submission
608
			if ( $recaptcha_settings_form->was_submitted() ) {
609
				// capture form data
610
				$recaptcha_settings_form->receive_form_submission();
611
				// validate form data
612
				if ( $recaptcha_settings_form->is_valid() ) {
613
					// grab validated data from form
614
					$valid_data = $recaptcha_settings_form->valid_data();
615
					// 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.
616
					if (
617
						apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys', TRUE, $EE_Registration_Config )
618
						&& $valid_data['main_settings']['use_captcha']
619
						&& ( ! $EE_Registration_Config->use_captcha && ( empty( $valid_data['main_settings']['recaptcha_publickey'] ) || empty( $valid_data['main_settings']['recaptcha_privatekey'] )))
620
					) {
621
						$valid_data['main_settings']['use_captcha'] = FALSE;
622
						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__ );
623
					}
624
					$EE_Registration_Config->use_captcha = $valid_data['main_settings']['use_captcha'];
625
					$EE_Registration_Config->recaptcha_publickey = $valid_data['main_settings']['recaptcha_publickey'];
626
					$EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey'];
627
					$EE_Registration_Config->recaptcha_type = $valid_data['appearance_settings']['recaptcha_type'];
628
					$EE_Registration_Config->recaptcha_theme = $valid_data['appearance_settings']['recaptcha_theme'];
629
					$EE_Registration_Config->recaptcha_language = $valid_data['appearance_settings']['recaptcha_language'];
630
				} else {
631
					if ( $recaptcha_settings_form->submission_error_message() != '' ) {
632
						EE_Error::add_error( $recaptcha_settings_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ );
633
					}
634
				}
635
			}
636
		} catch( EE_Error $e ) {
637
			$e->get_error();
638
		}
639
640
//		d( $EE_Registration_Config );
641
//		die();
642
		return $EE_Registration_Config;
643
	}
644
645
646
}
647
// End of file EED_Recaptcha.module.php
648
// Location: /modules/recaptcha/EED_Recaptcha.module.php
649