Completed
Branch TASK-9118-extensions-page (04eaec)
by
unknown
856:31 queued 840:33
created

General_Settings_Admin_Page   F

Complexity

Total Complexity 162

Size/Duplication

Total Lines 938
Duplicated Lines 3.94 %

Coupling/Cohesion

Components 5
Dependencies 19

Importance

Changes 0
Metric Value
dl 37
loc 938
rs 1.263
c 0
b 0
f 0
wmc 162
lcom 5
cbo 19

33 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _init_page_props() 0 6 1
A _ajax_hooks() 0 6 1
A _define_page_props() 0 6 1
A _set_page_routes() 0 64 1
A _set_page_config() 0 63 1
A _add_screen_options() 0 1 1
A _add_feature_pointers() 0 1 1
A load_scripts_styles() 0 6 1
A admin_init() 0 7 2
A admin_notices() 0 1 1
A admin_footer_scripts() 0 1 1
A load_scripts_styles_default() 0 14 1
A load_scripts_styles_country_settings() 8 8 1
F _espresso_page_settings() 0 28 9
C _update_espresso_page_settings() 0 42 7
F _your_organization_settings() 0 75 25
F _update_your_organization_settings() 0 32 22
B _admin_option_settings() 0 17 8
B _update_admin_option_settings() 0 17 8
B _country_settings() 0 39 3
B display_country_settings() 7 44 4
C display_country_states() 7 50 7
F add_new_state() 7 40 9
C delete_state() 8 22 7
F _update_country_settings() 0 61 24
A country_form_field_label_wrap() 0 7 1
A country_form_field_input__wrap() 0 7 1
A state_form_field_label_wrap() 0 3 1
A state_form_field_input__wrap() 0 7 1
A edit_view_links() 0 6 1
B page_and_shortcode_status() 0 23 5
A page_settings_dropdown() 0 19 4

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like General_Settings_Admin_Page 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 General_Settings_Admin_Page, and based on these observations, apply Extract Interface, too.

1
<?php
2
if (!defined('EVENT_ESPRESSO_VERSION') )
3
	exit('NO direct script access allowed');
4
5
/**
6
 * Event Espresso
7
 *
8
 * Event Registration and Management Plugin for Wordpress
9
 *
10
 * @package		Event Espresso
11
 * @author		Seth Shoultes
12
 * @copyright	(c)2009-2012 Event Espresso All Rights Reserved.
13
 * @license		http://eventespresso.com/support/terms-conditions/  ** see Plugin Licensing **
14
 * @link		http://www.eventespresso.com
15
 * @version		4.0
16
 *
17
 * ------------------------------------------------------------------------
18
 *
19
 * General_Settings_Admin_Page
20
 *
21
 * This contains the logic for setting up the Custom General_Settings related pages.  Any methods without phpdoc comments have inline docs with parent class.
22
 *
23
 * NOTE:  TODO: This is a straight conversion from the legacy 3.1 settings page.  It is NOT optimized and will need modification to fully use the new system (and also will need adjusted when Questions and Questions groups model is implemented)
24
 *
25
 * @package		General_Settings_Admin_Page
26
 * @subpackage	includes/core/admin/general_settings/General_Settings_Admin_Page.core.php
27
 * @author			Brent Christensen
28
 *
29
 * ------------------------------------------------------------------------
30
 */
31
class General_Settings_Admin_Page extends EE_Admin_Page {
32
33
34
	/**
35
	 * _question_group
36
	 * holds the specific question group object for the question group details screen
37
	 * @var object
38
	 */
39
	protected $_question_group;
40
41
42
43
	public function __construct( $routing = TRUE ) {
44
		parent::__construct( $routing );
45
	}
46
47
48
49
	protected function _init_page_props() {
50
		$this->page_slug = GEN_SET_PG_SLUG;
51
		$this->page_label = GEN_SET_LABEL;
52
		$this->_admin_base_url = GEN_SET_ADMIN_URL;
53
		$this->_admin_base_path = GEN_SET_ADMIN;
54
	}
55
56
57
58
59
	protected function _ajax_hooks() {
60
		add_action('wp_ajax_espresso_display_country_settings', array( $this, 'display_country_settings'));
61
		add_action('wp_ajax_espresso_display_country_states', array( $this, 'display_country_states'));
62
		add_action('wp_ajax_espresso_delete_state', array( $this, 'delete_state'), 10, 3 );
63
		add_action('wp_ajax_espresso_add_new_state', array( $this, 'add_new_state'));
64
	}
65
66
67
68
69
70
	protected function _define_page_props() {
71
		$this->_admin_page_title = GEN_SET_LABEL;
72
		$this->_labels = array(
73
			'publishbox' => __('Update Settings', 'event_espresso')
74
		);
75
	}
76
77
78
79
80
	protected function _set_page_routes() {
81
		$this->_page_routes = array(
82
83
			'critical_pages' => array(
84
				'func' => '_espresso_page_settings',
85
				'capability' => 'manage_options'
86
				),
87
			'update_espresso_page_settings' => array(
88
				'func' => '_update_espresso_page_settings',
89
				'capability' => 'manage_options',
90
				'noheader' => TRUE,
91
				),
92
			'default' => array(
93
				'func' => '_your_organization_settings',
94
				'capability' => 'manage_options',
95
				),
96
97
			'update_your_organization_settings' => array(
98
				'func' => '_update_your_organization_settings',
99
				'capability' => 'manage_options',
100
				'noheader' => TRUE,
101
				),
102
103
			'admin_option_settings' => array(
104
				'func' => '_admin_option_settings',
105
				'capability' => 'manage_options',
106
				),
107
108
			'update_admin_option_settings' => array(
109
				'func' => '_update_admin_option_settings',
110
				'capability' => 'manage_options',
111
				'noheader' => TRUE,
112
				),
113
114
			'country_settings' => array(
115
				'func' => '_country_settings',
116
				'capability' => 'manage_options'
117
				),
118
119
			'update_country_settings' => array(
120
				'func' => '_update_country_settings',
121
				'capability' => 'manage_options',
122
				'noheader' => TRUE,
123
				),
124
125
			'display_country_settings' => array(
126
				'func' => 'display_country_settings',
127
				'capability' => 'manage_options',
128
				'noheader' => TRUE,
129
				),
130
131
			'add_new_state' => array(
132
				'func' => 'add_new_state',
133
				'capability' => 'manage_options',
134
				'noheader' => TRUE,
135
				),
136
137
			'delete_state' => array(
138
				'func' => 'delete_state',
139
				'capability' => 'manage_options',
140
				'noheader' => TRUE,
141
				)
142
			);
143
	}
144
145
146
147
148
149
	protected function _set_page_config() {
150
		$this->_page_config = array(
151
			'critical_pages' => array(
152
				'nav' => array(
153
					'label' => __('Critical Pages', 'event_espresso'),
154
					'order' => 50
155
					),
156
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ),
157
               			'help_tabs' => array(
158
					'general_settings_critical_pages_help_tab' => array(
159
						'title' => __('Critical Pages', 'event_espresso'),
160
						'filename' => 'general_settings_critical_pages'
161
						)
162
					),
163
				'help_tour' => array( 'Critical_Pages_Help_Tour' ),
164
				'require_nonce' => FALSE
165
				),
166
			'default' => array(
167
				'nav' => array(
168
					'label' => __('Your Organization', 'event_espresso'),
169
					'order' => 20
170
				),
171
                			'help_tabs' => array(
172
					'general_settings_your_organization_help_tab' => array(
173
						'title' => __('Your Organization', 'event_espresso'),
174
						'filename' => 'general_settings_your_organization'
175
						)
176
					),
177
				'help_tour' => array( 'Your_Organization_Help_Tour' ),
178
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ),
179
				'require_nonce' => FALSE
180
				),
181
			'admin_option_settings' => array(
182
				'nav' => array(
183
					'label' => __('Admin Options', 'event_espresso'),
184
					'order' => 60
185
					),
186
				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ),
187
                			'help_tabs' => array(
188
					'general_settings_admin_options_help_tab' => array(
189
						'title' => __('Admin Options', 'event_espresso'),
190
						'filename' => 'general_settings_admin_options'
191
						)
192
					),
193
				'help_tour' => array( 'Admin_Options_Help_Tour' ),
194
				'require_nonce' => FALSE
195
				),
196
			'country_settings' => array(
197
				'nav' => array(
198
					'label' => __('Countries', 'event_espresso'),
199
					'order' => 70
200
					),
201
                'help_tabs' => array(
202
					'general_settings_countries_help_tab' => array(
203
						'title' => __('Countries', 'event_espresso'),
204
						'filename' => 'general_settings_countries'
205
						)
206
					),
207
				'help_tour' => array( 'Countries_Help_Tour' ),
208
				'require_nonce' => FALSE
209
				)
210
			);
211
	}
212
213
214
	protected function _add_screen_options() {}
215
216
	protected function _add_feature_pointers() {}
217
	public function load_scripts_styles() {
218
		//styles
219
		wp_enqueue_style('espresso-ui-theme');
220
		//scripts
221
		wp_enqueue_script('ee_admin_js');
222
	}
223
224
	public function admin_init() {
225
		EE_Registry::$i18n_js_strings[ 'invalid_server_response' ] = __( 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', 'event_espresso' );
226
		EE_Registry::$i18n_js_strings[ 'error_occurred' ] = __( 'An error occurred! Please refresh the page and try again.', 'event_espresso' );
227
		EE_Registry::$i18n_js_strings[ 'confirm_delete_state' ] = __( 'Are you sure you want to delete this State / Province?', 'event_espresso' );
228
		$protocol = isset( $_SERVER[ 'HTTPS' ] ) ? 'https://' : 'http://';
229
		EE_Registry::$i18n_js_strings[ 'ajax_url' ] = admin_url( 'admin-ajax.php?page=espresso_general_settings', $protocol );
230
	}
231
232
	public function admin_notices() {}
233
	public function admin_footer_scripts() {}
234
235
236
	public function load_scripts_styles_default() {
237
		//styles
238
		wp_enqueue_style('thickbox');
239
		//scripts
240
		wp_enqueue_script('media-upload');
241
		wp_enqueue_script('thickbox');
242
		wp_register_script( 'organization_settings', GEN_SET_ASSETS_URL . 'your_organization_settings.js', array( 'jquery','media-upload','thickbox' ), EVENT_ESPRESSO_VERSION, TRUE );
243
		wp_register_style( 'organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION );
244
		wp_enqueue_script( 'organization_settings' );
245
		wp_enqueue_style( 'organization-css' );
246
		$confirm_image_delete = array( 'text' => __('Do you really want to delete this image? Please remember to save your settings to complete the removal.', 'event_espresso'));
247
		wp_localize_script( 'organization_settings', 'confirm_image_delete', $confirm_image_delete );
248
249
	}
250
251 View Code Duplication
	public function load_scripts_styles_country_settings() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
		//scripts
253
		wp_register_script( 'gen_settings_countries', GEN_SET_ASSETS_URL . 'gen_settings_countries.js', array( 'ee_admin_js' ), EVENT_ESPRESSO_VERSION, TRUE );
254
		wp_register_style( 'organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION );
255
		wp_enqueue_script( 'gen_settings_countries' );
256
		wp_enqueue_style( 'organization-css' );
257
258
	}
259
260
261
	/*************		Espresso Pages 		*************/
262
263
264
	protected function _espresso_page_settings() {
265
266
		// Check to make sure all of the main pages are setup properly,
267
		// if not create the default pages and display an admin notice
268
		EE_Registry::instance()->load_helper( 'Activation' );
269
		EEH_Activation::verify_default_pages_exist();
270
271
		$this->_transient_garbage_collection();
272
		$this->_template_args['values'] = $this->_yes_no_values;
273
274
		$this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id ) ?EE_Registry::instance()->CFG->core->reg_page_id : NULL;
275
		$this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id ) ? get_page(EE_Registry::instance()->CFG->core->reg_page_id ) : FALSE;
276
277
		$this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) ?EE_Registry::instance()->CFG->core->txn_page_id : NULL;
278
		$this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id ) ? get_page(EE_Registry::instance()->CFG->core->txn_page_id ) : FALSE;
279
280
		$this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id ) ?EE_Registry::instance()->CFG->core->thank_you_page_id : NULL;
281
		$this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id ) ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id ) : FALSE;
282
283
		$this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id ) ?EE_Registry::instance()->CFG->core->cancel_page_id : NULL;
284
		$this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id ) ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id ) : FALSE;
285
286
		$this->_set_add_edit_form_tags( 'update_espresso_page_settings' );
287
		$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
288
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', $this->_template_args, TRUE );
289
		$this->display_admin_page_with_sidebar();
290
291
	}
292
293
	protected function _update_espresso_page_settings() {
294
		// capture incoming request data
295
		$reg_page_id = isset( $this->_req_data['reg_page_id'] ) ? absint( $this->_req_data['reg_page_id'] ) : EE_Registry::instance()->CFG->core->reg_page_id;
296
		$txn_page_id = isset( $this->_req_data['txn_page_id'] ) ? absint( $this->_req_data['txn_page_id'] ) : EE_Registry::instance()->CFG->core->txn_page_id;
297
		$thank_you_page_id = isset( $this->_req_data['thank_you_page_id'] ) ? absint( $this->_req_data['thank_you_page_id'] ) : EE_Registry::instance()->CFG->core->thank_you_page_id;
298
		$cancel_page_id = isset( $this->_req_data['cancel_page_id'] ) ? absint( $this->_req_data['cancel_page_id'] ) : EE_Registry::instance()->CFG->core->cancel_page_id;
299
		// pack critical_pages into an array
300
		$critical_pages = array(
301
			'reg_page_id' 				=> $reg_page_id,
302
			'txn_page_id' 				=> $txn_page_id,
303
			'thank_you_page_id' 	=> $thank_you_page_id,
304
			'cancel_page_id' 		=> $cancel_page_id
305
		);
306
		foreach ( $critical_pages as $critical_page_name => $critical_page_id ) {
307
			// has the page changed ?
308
			if ( EE_Registry::instance()->CFG->core->$critical_page_name != $critical_page_id ) {
309
				// grab post object for old page
310
				$post = get_post( EE_Registry::instance()->CFG->core->$critical_page_name );
311
				// update post shortcodes for old page
312
				EE_Admin::parse_post_content_on_save( $critical_page_id, $post );
313
				// grab post object for new page
314
				$post = get_post( $critical_page_id );
315
				// update post shortcodes for new page
316
				EE_Admin::parse_post_content_on_save( $critical_page_id, $post );
317
			}
318
		}
319
		// set page IDs
320
		EE_Registry::instance()->CFG->core->reg_page_id = $reg_page_id;
321
		EE_Registry::instance()->CFG->core->txn_page_id = $txn_page_id;
322
		EE_Registry::instance()->CFG->core->thank_you_page_id = $thank_you_page_id;
323
		EE_Registry::instance()->CFG->core->cancel_page_id = $cancel_page_id;
324
325
		EE_Registry::instance()->CFG->core = apply_filters( 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', EE_Registry::instance()->CFG->core, $this->_req_data );
326
327
		$what = __('Critical Pages & Shortcodes', 'event_espresso');
328
		$success = $this->_update_espresso_configuration( $what, EE_Registry::instance()->CFG->core, __FILE__, __FUNCTION__, __LINE__ );
0 ignored issues
show
Unused Code introduced by
$success is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
329
		$query_args = array(
330
			'action' => 'critical_pages'
331
			);
332
		$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE );
333
334
	}
335
336
337
338
339
340
341
342
	/*************		Your Organization 		*************/
343
344
345
	protected function _your_organization_settings() {
346
347
		$this->_template_args['site_license_key'] = isset( EE_Registry::instance()->NET_CFG->core->site_license_key ) ? EE_Registry::instance()->NET_CFG->core->get_pretty( 'site_license_key' ) : '';
348
		$this->_template_args['organization_name'] = isset( EE_Registry::instance()->CFG->organization->name ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'name' ) : '';
349
		$this->_template_args['organization_address_1'] = isset( EE_Registry::instance()->CFG->organization->address_1 ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'address_1' ) : '';
350
		$this->_template_args['organization_address_2'] = isset( EE_Registry::instance()->CFG->organization->address_2 ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'address_2' ) : '';
351
		$this->_template_args['organization_city'] = isset( EE_Registry::instance()->CFG->organization->city ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'city' ) : '';
352
		$this->_template_args['organization_zip'] = isset( EE_Registry::instance()->CFG->organization->zip ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'zip' ) : '';
353
		$this->_template_args['organization_email'] = isset( EE_Registry::instance()->CFG->organization->email ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) : '';
354
		$this->_template_args['organization_phone'] = isset( EE_Registry::instance()->CFG->organization->phone ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'phone' ) : '';
355
		$this->_template_args['organization_vat'] = isset( EE_Registry::instance()->CFG->organization->vat ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'vat' ) : '';
356
		$this->_template_args['currency_sign'] = isset( EE_Registry::instance()->CFG->currency->sign ) ? EE_Registry::instance()->CFG->currency->get_pretty( 'sign' ) : '$';
357
		$this->_template_args['organization_logo_url'] = isset( EE_Registry::instance()->CFG->organization->logo_url ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ) : FALSE;
358
		$this->_template_args['organization_facebook'] = isset( EE_Registry::instance()->CFG->organization->facebook ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ) : '';
359
		$this->_template_args['organization_twitter'] = isset( EE_Registry::instance()->CFG->organization->twitter ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ) : '';
360
		$this->_template_args['organization_linkedin'] = isset( EE_Registry::instance()->CFG->organization->linkedin ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ) : '';
361
		$this->_template_args['organization_pinterest'] = isset( EE_Registry::instance()->CFG->organization->pinterest ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ) : '';
362
		$this->_template_args['organization_google'] = isset( EE_Registry::instance()->CFG->organization->google ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'google' ) : '';
363
		$this->_template_args['organization_instagram'] = isset( EE_Registry::instance()->CFG->organization->instagram ) ? EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ) : '';
364
		//UXIP settings
365
		$this->_template_args['ee_ueip_optin'] = isset( EE_Registry::instance()->CFG->core->ee_ueip_optin ) ? EE_Registry::instance()->CFG->core->get_pretty( 'ee_ueip_optin' ) : TRUE;
366
367
		EE_Registry::instance()->load_helper( 'Form_Fields' );
368
		$STA_ID = isset( EE_Registry::instance()->CFG->organization->STA_ID ) ? EE_Registry::instance()->CFG->organization->STA_ID : 4;
369
		$this->_template_args['states'] = new EE_Question_Form_Input(
370
				EE_Question::new_instance ( array(
371
					'QST_ID'=> 0,
372
					'QST_display_text'=> __('State/Province', 'event_espresso'),
373
					'QST_system'=>'admin-state'
374
				)),
375
				EE_Answer::new_instance ( array(
376
					'ANS_ID' => 0,
377
					'ANS_value' => $STA_ID
378
				)),
379
				array(
380
					'input_id' => 'organization_state',
381
					'input_name' => 'organization_state',
382
					'input_prefix' => '',
383
					'append_qstn_id' => FALSE
384
				)
385
			);
386
387
		$CNT_ISO = isset( EE_Registry::instance()->CFG->organization->CNT_ISO ) ? EE_Registry::instance()->CFG->organization->CNT_ISO : 'US';
388
		$this->_template_args['countries'] = new EE_Question_Form_Input(
389
				EE_Question::new_instance ( array(
390
					'QST_ID'=> 0,
391
					'QST_display_text'=> __('Country', 'event_espresso'),
392
					'QST_system'=>'admin-country'
393
				)),
394
				EE_Answer::new_instance ( array(
395
					'ANS_ID' => 0,
396
					'ANS_value' => $CNT_ISO
397
				)),
398
				array(
399
					'input_id' => 'organization_country',
400
					'input_name' => 'organization_country',
401
					'input_prefix' => '',
402
					'append_qstn_id' => FALSE
403
				)
404
			);
405
406
		add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $this, 'country_form_field_label_wrap' ), 10, 2 );
407
		add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $this, 'country_form_field_input__wrap' ), 10, 2 );
408
409
		//PUE verification stuff
410
		$ver_option_key = 'puvererr_' . basename( EE_PLUGIN_BASENAME );
411
		$verify_fail = get_option( $ver_option_key );
412
		$this->_template_args['site_license_key_verified'] = $verify_fail || !empty( $verify_fail ) || ( empty( $this->_template_args['site_license_key'] ) && empty( $verify_fail ) )? '<span class="dashicons dashicons-admin-network ee-icon-color-ee-red ee-icon-size-20"></span>' : '<span class="dashicons dashicons-admin-network ee-icon-color-ee-green ee-icon-size-20"></span>';
413
414
		$this->_set_add_edit_form_tags( 'update_your_organization_settings' );
415
		$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
416
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( GEN_SET_TEMPLATE_PATH . 'your_organization_settings.template.php', $this->_template_args, TRUE );
417
418
		$this->display_admin_page_with_sidebar();
419
	}
420
421
	protected function _update_your_organization_settings() {
422
		if ( is_main_site() )
423
			EE_Registry::instance()->NET_CFG->core->site_license_key = isset( $this->_req_data['site_license_key'] ) ? sanitize_text_field( $this->_req_data['site_license_key'] ) : EE_Registry::instance()->NET_CFG->core->site_license_key;
424
		EE_Registry::instance()->CFG->organization->name = isset( $this->_req_data['organization_name'] ) ? sanitize_text_field( $this->_req_data['organization_name'] ) : EE_Registry::instance()->CFG->organization->name;
425
		EE_Registry::instance()->CFG->organization->address_1 = isset( $this->_req_data['organization_address_1'] ) ? sanitize_text_field( $this->_req_data['organization_address_1'] ) : EE_Registry::instance()->CFG->organization->address_1;
426
		EE_Registry::instance()->CFG->organization->address_2 = isset( $this->_req_data['organization_address_2'] ) ? sanitize_text_field( $this->_req_data['organization_address_2'] ) : EE_Registry::instance()->CFG->organization->address_2;
427
		EE_Registry::instance()->CFG->organization->city = isset( $this->_req_data['organization_city'] ) ? sanitize_text_field( $this->_req_data['organization_city'] ) : EE_Registry::instance()->CFG->organization->city;
428
		EE_Registry::instance()->CFG->organization->STA_ID = isset( $this->_req_data['organization_state'] ) ? absint( $this->_req_data['organization_state'] ) : EE_Registry::instance()->CFG->organization->STA_ID;
429
		EE_Registry::instance()->CFG->organization->CNT_ISO = isset( $this->_req_data['organization_country'] ) ? sanitize_text_field( $this->_req_data['organization_country'] ) : EE_Registry::instance()->CFG->organization->CNT_ISO;
430
		EE_Registry::instance()->CFG->organization->zip = isset( $this->_req_data['organization_zip'] ) ? sanitize_text_field( $this->_req_data['organization_zip'] ) : EE_Registry::instance()->CFG->organization->zip;
431
		EE_Registry::instance()->CFG->organization->email = isset( $this->_req_data['organization_email'] ) ? sanitize_email( $this->_req_data['organization_email'] ) : EE_Registry::instance()->CFG->organization->email;
432
		EE_Registry::instance()->CFG->organization->vat = isset( $this->_req_data['organization_vat'] ) ? sanitize_text_field( $this->_req_data['organization_vat'] ) : EE_Registry::instance()->CFG->organization->vat;
433
		EE_Registry::instance()->CFG->organization->phone = isset( $this->_req_data['organization_phone'] ) ? sanitize_text_field( $this->_req_data['organization_phone'] ) : EE_Registry::instance()->CFG->organization->phone;
434
		EE_Registry::instance()->CFG->organization->logo_url = isset( $this->_req_data['organization_logo_url'] ) ? esc_url_raw( $this->_req_data['organization_logo_url'] ) : EE_Registry::instance()->CFG->organization->logo_url;
435
		EE_Registry::instance()->CFG->organization->facebook = isset( $this->_req_data['organization_facebook'] ) ? esc_url_raw( $this->_req_data['organization_facebook'] ) : EE_Registry::instance()->CFG->organization->facebook;
436
		EE_Registry::instance()->CFG->organization->twitter = isset( $this->_req_data['organization_twitter'] ) ? esc_url_raw( $this->_req_data['organization_twitter'] ) : EE_Registry::instance()->CFG->organization->twitter;
437
		EE_Registry::instance()->CFG->organization->linkedin = isset( $this->_req_data['organization_linkedin'] ) ? esc_url_raw( $this->_req_data['organization_linkedin'] ) : EE_Registry::instance()->CFG->organization->linkedin;
438
		EE_Registry::instance()->CFG->organization->pinterest = isset( $this->_req_data['organization_pinterest'] ) ? esc_url_raw( $this->_req_data['organization_pinterest'] ) : EE_Registry::instance()->CFG->organization->pinterest;
439
		EE_Registry::instance()->CFG->organization->google = isset( $this->_req_data['organization_google'] ) ? esc_url_raw( $this->_req_data['organization_google'] ) : EE_Registry::instance()->CFG->organization->google;
440
		EE_Registry::instance()->CFG->organization->instagram = isset( $this->_req_data['organization_instagram'] ) ? esc_url_raw( $this->_req_data['organization_instagram'] ) : EE_Registry::instance()->CFG->organization->instagram;
441
		EE_Registry::instance()->CFG->core->ee_ueip_optin = isset( $this->_req_data['ueip_optin'] ) && !empty( $this->_req_data['ueip_optin'] ) ? $this->_req_data['ueip_optin'] : EE_Registry::instance()->CFG->core->ee_ueip_optin;
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($this->_req_data['...FG->core->ee_ueip_optin can also be of type string. However, the property $ee_ueip_optin is declared as type false. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
442
443
		EE_Registry::instance()->CFG->currency = new EE_Currency_Config( EE_Registry::instance()->CFG->organization->CNT_ISO );
444
445
		EE_Registry::instance()->CFG = apply_filters( 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', EE_Registry::instance()->CFG );
446
447
		$what = 'Your Organization Settings';
448
		$success = $this->_update_espresso_configuration( $what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__ );
449
450
		$this->_redirect_after_action( $success, $what, 'updated', array( 'action' => 'default' ) );
0 ignored issues
show
Documentation introduced by
$success is of type boolean, but the function expects a false|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
451
452
	}
453
454
455
	/*************		Admin Options 		*************/
456
457
458
	protected function _admin_option_settings() {
459
460
		$this->_template_args['values'] = $this->_yes_no_values;
461
		$this->_template_args['use_personnel_manager'] = isset( EE_Registry::instance()->CFG->admin->use_personnel_manager ) ? absint( EE_Registry::instance()->CFG->admin->use_personnel_manager ) : FALSE;
462
		$this->_template_args['use_dashboard_widget'] = isset( EE_Registry::instance()->CFG->admin->use_dashboard_widget ) ? absint( EE_Registry::instance()->CFG->admin->use_dashboard_widget ) : TRUE;
463
		$this->_template_args['events_in_dashboard'] = isset( EE_Registry::instance()->CFG->admin->events_in_dashboard ) ? absint( EE_Registry::instance()->CFG->admin->events_in_dashboard ) : 30;
464
		$this->_template_args['use_event_timezones'] = isset( EE_Registry::instance()->CFG->admin->use_event_timezones ) ? absint( EE_Registry::instance()->CFG->admin->use_event_timezones ) : FALSE;
465
		$this->_template_args['show_reg_footer'] = isset( EE_Registry::instance()->CFG->admin->show_reg_footer ) ? absint( EE_Registry::instance()->CFG->admin->show_reg_footer ) : TRUE;
466
		$this->_template_args['affiliate_id'] = isset( EE_Registry::instance()->CFG->admin->affiliate_id ) ? EE_Registry::instance()->CFG->admin->get_pretty('affiliate_id') : '';
467
		$this->_template_args['help_tour_activation'] = isset( EE_Registry::instance()->CFG->admin->help_tour_activation ) ? absint( EE_Registry::instance()->CFG->admin->help_tour_activation ): 1;
468
469
		$this->_set_add_edit_form_tags( 'update_admin_option_settings' );
470
		$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
471
		$this->_template_args['template_args'] = $this->_template_args;
472
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( GEN_SET_TEMPLATE_PATH . 'admin_option_settings.template.php', $this->_template_args, TRUE );
473
		$this->display_admin_page_with_sidebar();
474
	}
475
476
	protected function _update_admin_option_settings() {
477
		EE_Registry::instance()->CFG->admin->use_personnel_manager = isset( $this->_req_data['use_personnel_manager'] ) ? absint( $this->_req_data['use_personnel_manager'] ) : EE_Registry::instance()->CFG->admin->use_personnel_manager;
478
		EE_Registry::instance()->CFG->admin->use_dashboard_widget = isset( $this->_req_data['use_dashboard_widget'] ) ? absint( $this->_req_data['use_dashboard_widget'] ) : EE_Registry::instance()->CFG->admin->use_dashboard_widget;
479
		EE_Registry::instance()->CFG->admin->events_in_dashboard = isset( $this->_req_data['events_in_dashboard'] ) ? absint( $this->_req_data['events_in_dashboard'] ) : EE_Registry::instance()->CFG->admin->events_in_dashboard;
480
		EE_Registry::instance()->CFG->admin->use_event_timezones = isset( $this->_req_data['use_event_timezones'] ) ? absint( $this->_req_data['use_event_timezones'] ) : EE_Registry::instance()->CFG->admin->use_event_timezones;
481
		EE_Registry::instance()->CFG->admin->show_reg_footer = isset( $this->_req_data['show_reg_footer'] ) ? absint( $this->_req_data['show_reg_footer'] ) : EE_Registry::instance()->CFG->admin->show_reg_footer;
482
		EE_Registry::instance()->CFG->admin->affiliate_id = isset( $this->_req_data['affiliate_id'] ) ? sanitize_text_field( $this->_req_data['affiliate_id'] ) : EE_Registry::instance()->CFG->admin->affiliate_id;
483
		EE_Registry::instance()->CFG->admin->help_tour_activation = isset( $this->_req_data['help_tour_activation'] ) ? absint( $this->_req_data['help_tour_activation'] ) : EE_Registry::instance()->CFG->admin->help_tour_activation;
484
485
		EE_Registry::instance()->CFG->admin = apply_filters( 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', EE_Registry::instance()->CFG->admin );
486
487
		$what = 'Admin Options';
488
		$success = $this->_update_espresso_configuration( $what, EE_Registry::instance()->CFG->admin, __FILE__, __FUNCTION__, __LINE__ );
489
		$success = apply_filters( 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', $success );
490
		$this->_redirect_after_action( $success, $what, 'updated', array( 'action' => 'admin_option_settings' ) );
491
492
	}
493
494
495
496
497
498
	/*************		Countries 		*************/
499
500
501
	protected function _country_settings() {
502
503
		$CNT_ISO = isset( EE_Registry::instance()->CFG->organization->CNT_ISO ) ? EE_Registry::instance()->CFG->organization->CNT_ISO : 'US';
504
		$CNT_ISO = isset( $this->_req_data['country'] ) ? strtoupper( sanitize_text_field( $this->_req_data['country'] )) : $CNT_ISO;
505
506
		//load field generator helper
507
		EE_Registry::instance()->load_helper( 'Form_Fields' );
508
509
		$this->_template_args['values'] = $this->_yes_no_values;
510
511
		$this->_template_args['countries'] = new EE_Question_Form_Input(
512
				EE_Question::new_instance ( array(
513
					'QST_ID'=> 0,
514
					'QST_display_text'=> __('Select Country', 'event_espresso'),
515
					'QST_system'=>'admin-country'
516
				)),
517
				EE_Answer::new_instance ( array(
518
					'ANS_ID' => 0,
519
					'ANS_value' => $CNT_ISO
520
				)),
521
				array(
522
					'input_id' => 'country',
523
					'input_name' => 'country',
524
					'input_prefix' => '',
525
					'append_qstn_id' => FALSE
526
				)
527
			);
528
//		EEH_Debug_Tools::printr( $this->_template_args['countries'], 'countries  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
529
530
		add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $this, 'country_form_field_label_wrap' ), 10, 2 );
531
		add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $this, 'country_form_field_input__wrap' ), 10, 2 );
532
		$this->_template_args['country_details_settings'] = $this->display_country_settings();
533
		$this->_template_args['country_states_settings'] = $this->display_country_states();
534
535
		$this->_set_add_edit_form_tags( 'update_country_settings' );
536
		$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
537
		$this->_template_args['admin_page_content'] = EEH_Template::display_template( GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', $this->_template_args, TRUE );
538
		$this->display_admin_page_with_no_sidebar();
539
	}
540
541
542
543
	/**
544
	 * 		display_country_settings
545
	 *
546
	 * 		@access 	public
547
	 * 		@param 	string 		$CNT_ISO
548
	 * 		@return 		mixed		string | array
549
	 */
550
	public function display_country_settings( $CNT_ISO = '' ) {
551
552
		$CNT_ISO = isset( $this->_req_data['country'] ) ? strtoupper( sanitize_text_field( $this->_req_data['country'] )) : $CNT_ISO;
553
		if ( ! $CNT_ISO ) {
554
			return '';
555
		}
556
557
		// for ajax
558
		EE_Registry::instance()->load_helper( 'Form_Fields' );
559
		remove_all_filters( 'FHEE__EEH_Form_Fields__label_html' );
560
		remove_all_filters( 'FHEE__EEH_Form_Fields__input_html' );
561
		add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $this, 'country_form_field_label_wrap' ), 10, 2 );
562
		add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $this, 'country_form_field_input__wrap' ), 10, 2 );
563
		$country = EEM_Country::instance()->get_one_by_ID( $CNT_ISO );
564
		//EEH_Debug_Tools::printr( $country, '$country  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
565
		$country_input_types = array(
566
			'CNT_active' => array( 'type' => 'RADIO_BTN', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => '', 'options' => $this->_yes_no_values, 'use_desc_4_label' => TRUE  ),
567
			'CNT_ISO' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'small-text' ),
568
			'CNT_ISO3' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'small-text' ),
569
			'RGN_ID' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'small-text' ),
570
			'CNT_name' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'regular-text' ),
571
			'CNT_cur_code' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'small-text' ),
572
			'CNT_cur_single' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'medium-text' ),
573
			'CNT_cur_plural' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'medium-text' ),
574
			'CNT_cur_sign' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'small-text', 'htmlentities' => FALSE ),
575
			'CNT_cur_sign_b4' => array( 'type' => 'RADIO_BTN', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => '', 'options' => $this->_yes_no_values, 'use_desc_4_label' => TRUE ),
576
			'CNT_cur_dec_plc' => array( 'type' => 'RADIO_BTN', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => '', 'options' => array( array( 'id' => 0, 'text' => '' ), array( 'id' => 1, 'text' => '' ), array( 'id' => 2, 'text' => '' ), array( 'id' => 3, 'text' => '' ))),
577
			'CNT_cur_dec_mrk' => array( 'type' => 'RADIO_BTN', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => '', 'options' => array( array( 'id' => ',', 'text' => __(', (comma)', 'event_espresso')), array( 'id' => '.', 'text' => __('. (decimal)', 'event_espresso'))), 'use_desc_4_label' => TRUE ),
578
			'CNT_cur_thsnds' => array( 'type' => 'RADIO_BTN', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => '', 'options' => array( array( 'id' => ',', 'text' => __(', (comma)', 'event_espresso')), array( 'id' => '.', 'text' => __('. (decimal)', 'event_espresso'))), 'use_desc_4_label' => TRUE ),
579
			'CNT_tel_code' => array( 'type' => 'TEXT', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => 'small-text' ),
580
			'CNT_is_EU' => array( 'type' => 'RADIO_BTN', 'input_name' => 'cntry[' . $CNT_ISO . ']', 'class' => '', 'options' => $this->_yes_no_values, 'use_desc_4_label' => TRUE  )
581
		);
582
		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( $country, $country_input_types );
0 ignored issues
show
Bug introduced by
It seems like $country defined by \EEM_Country::instance()->get_one_by_ID($CNT_ISO) on line 563 can be null; however, EE_Question_Form_Input::...orm_inputs_for_object() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
583
		$country_details_settings = EEH_Template::display_template( GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', $this->_template_args, TRUE );
584
585 View Code Duplication
		if ( defined( 'DOING_AJAX' )) {
586
			$notices = EE_Error::get_notices( FALSE, FALSE, FALSE );
587
			echo json_encode( array( 'return_data' => $country_details_settings, 'success' => $notices['success'], 'errors' => $notices['errors'] ));
588
			die();
589
		} else {
590
			return $country_details_settings;
591
		}
592
593
	}
594
595
596
597
598
	/**
599
	 * 		display_country_states
600
	 *
601
	 * 		@access 	public
602
	 * 		@param 	string 		$CNT_ISO
603
	 * 		@return 		string
604
	 */
605
	public function display_country_states( $CNT_ISO = '' ) {
606
607
		$CNT_ISO = isset( $this->_req_data['country'] ) ? sanitize_text_field( $this->_req_data['country'] ) : $CNT_ISO;
608
609
		if ( ! $CNT_ISO ) {
610
			return '';
611
		}
612
		// for ajax
613
		EE_Registry::instance()->load_helper( 'Form_Fields' );
614
		remove_all_filters( 'FHEE__EEH_Form_Fields__label_html' );
615
		remove_all_filters( 'FHEE__EEH_Form_Fields__input_html' );
616
		add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $this, 'state_form_field_label_wrap' ), 10, 2 );
617
		add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $this, 'state_form_field_input__wrap' ), 10, 2 );
618
		$states = EEM_State::instance()->get_all_states_for_these_countries( array( $CNT_ISO => $CNT_ISO ));
619
620
//			echo '<h4>$CNT_ISO : ' . $CNT_ISO . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
621
//			global $wpdb;
622
//			echo '<h4>' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
623
//			EEH_Debug_Tools::printr( $states, '$states  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
624
		if ( $states ) {
625
			foreach ( $states as $STA_ID => $state ) {
626
				if ( $state instanceof EE_State ) {
627
					//STA_abbrev 	STA_name 	STA_active
628
					$state_input_types = array(
629
						'STA_abbrev' => array( 'type' => 'TEXT', 'input_name' => 'states[' . $STA_ID . ']', 'class' => 'mid-text' ),
630
						'STA_name'   => array( 'type'       => 'TEXT', 'input_name' => 'states[' . $STA_ID . ']', 'class' => 'regular-text' ),
631
						'STA_active' => array( 'type' => 'RADIO_BTN', 'input_name' => 'states[' . $STA_ID . ']', 'options' => $this->_yes_no_values, 'use_desc_4_label' => true )
632
					);
633
					$this->_template_args[ 'states' ][ $STA_ID ][ 'inputs' ] = EE_Question_Form_Input::generate_question_form_inputs_for_object( $state, $state_input_types );
634
					$query_args = array( 'action'     => 'delete_state', 'STA_ID' => $STA_ID, 'CNT_ISO' => $CNT_ISO, 'STA_abbrev' => $state->abbrev() );
635
					$this->_template_args[ 'states' ][ $STA_ID ][ 'delete_state_url' ] = EE_Admin_Page::add_query_args_and_nonce( $query_args, GEN_SET_ADMIN_URL );
636
				}
637
			}
638
		} else {
639
			$this->_template_args['states'] = FALSE;
640
		}
641
//		EEH_Debug_Tools::printr( $this->_template_args['states'], 'states  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
642
		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'add_new_state' ),  GEN_SET_ADMIN_URL );
643
644
		$state_details_settings = EEH_Template::display_template( GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', $this->_template_args, TRUE );
645
646 View Code Duplication
		if ( defined( 'DOING_AJAX' )) {
647
			$notices = EE_Error::get_notices( FALSE, FALSE, FALSE );
648
			echo json_encode( array( 'return_data' => $state_details_settings, 'success' => $notices['success'], 'errors' => $notices['errors'] ));
649
			die();
650
		} else {
651
			return $state_details_settings;
652
		}
653
654
	}
655
656
657
658
659
	/**
660
	 * 		add_new_state
661
	 *
662
	 * 		@access 	public
663
	 * 		@return 		void
664
	 */
665
	public function add_new_state() {
666
667
		$success = TRUE;
668
669
		$CNT_ISO = isset( $this->_req_data['CNT_ISO'] ) ? strtoupper( sanitize_text_field( $this->_req_data['CNT_ISO'] )) : FALSE;
670
		if ( ! $CNT_ISO ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $CNT_ISO of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
671
			EE_Error::add_error( __( 'No Country ISO code or an invalid Country ISO code was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
672
			$success = FALSE;
673
		}
674
		$STA_abbrev = isset( $this->_req_data['STA_abbrev'] ) ? sanitize_text_field( $this->_req_data['STA_abbrev'] ) : FALSE;
675
		if ( ! $STA_abbrev ) {
676
			EE_Error::add_error( __( 'No State ISO code or an invalid State ISO code was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
677
			$success = FALSE;
678
		}
679
		$STA_name = isset( $this->_req_data['STA_name'] ) ?  sanitize_text_field( $this->_req_data['STA_name'] ) :
680
			FALSE;
681
		if ( ! $STA_name ) {
682
			EE_Error::add_error( __( 'No State name or an invalid State name was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
683
			$success = FALSE;
684
		}
685
686
		if ( $success ) {
687
			$cols_n_values = array(
688
				'CNT_ISO' => $CNT_ISO,
689
				'STA_abbrev' => $STA_abbrev,
690
				'STA_name' => $STA_name,
691
				'STA_active' => TRUE
692
			);
693
			$success = EEM_State::instance()->insert ( $cols_n_values );
694
			EE_Error::add_success( __( 'The State was added successfully.', 'event_espresso' ) );
695
		}
696
697 View Code Duplication
		if ( defined( 'DOING_AJAX' )) {
698
			$notices = EE_Error::get_notices( FALSE, FALSE, FALSE );
699
			echo json_encode( array_merge( $notices, array( 'return_data' => $CNT_ISO ) ) );
700
			die();
701
		} else {
702
			$this->_redirect_after_action( $success, 'State', 'added', array( 'action' => 'country_settings' ) );
0 ignored issues
show
Bug introduced by
It seems like $success defined by TRUE on line 667 can also be of type boolean; however, EE_Admin_Page::_redirect_after_action() does only seem to accept false|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
703
		}
704
	}
705
706
707
708
	/**
709
	 * 		delete_state
710
	 *
711
	 * 		@access 	public
712
	 * 		@return 		boolean | void
713
	 */
714
	public function delete_state() {
715
		$CNT_ISO = isset( $this->_req_data['CNT_ISO'] ) ? strtoupper( sanitize_text_field( $this->_req_data['CNT_ISO'] )) : FALSE;
716
		$STA_ID = isset( $this->_req_data['STA_ID'] ) ? sanitize_text_field( $this->_req_data['STA_ID'] ) : FALSE;
717
		$STA_abbrev = isset( $this->_req_data['STA_abbrev'] ) ? sanitize_text_field( $this->_req_data['STA_abbrev'] ) : FALSE;
718
		if ( ! $STA_ID ) {
719
			EE_Error::add_error( __( 'No State ID or an invalid State ID was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
720
			return FALSE;
721
		}
722
		$success = EEM_State::instance()->delete_by_ID( $STA_ID );
723
		if ( $success !== FALSE ) {
724
			do_action( 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', $CNT_ISO, $STA_ID, array( 'STA_abbrev' => $STA_abbrev ));
725
			EE_Error::add_success( __( 'The State was deleted successfully.', 'event_espresso' ));
726
		}
727 View Code Duplication
		if ( defined( 'DOING_AJAX' )) {
728
			$notices = EE_Error::get_notices( FALSE, FALSE );
729
			$notices['return_data'] = TRUE;
730
			echo json_encode( $notices );
731
			die();
732
		} else {
733
			$this->_redirect_after_action( $success, 'State', 'deleted', array( 'action' => 'country_settings' ) );
0 ignored issues
show
Documentation introduced by
$success is of type boolean, but the function expects a false|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
734
		}
735
	}
736
737
738
739
740
	/**
741
	 * 		_update_country_settings
742
	 *
743
	 * 		@access 	protected
744
	 * 		@return 		void
745
	 */
746
	protected function _update_country_settings() {
747
//		EEH_Debug_Tools::printr( $this->_req_data, '$this->_req_data  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
748
		// grab the country ISO code
749
		$CNT_ISO = isset( $this->_req_data['country'] ) ? strtoupper( sanitize_text_field( $this->_req_data['country'] )) : FALSE;
750
		if ( ! $CNT_ISO ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $CNT_ISO of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
751
			EE_Error::add_error( __( 'No Country ISO code or an invalid Country ISO code was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
752
			return;
753
		}
754
		$cols_n_values = array();
755
		$cols_n_values['CNT_ISO3'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'] ) ? strtoupper( sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'] )) : FALSE;
756
		$cols_n_values['RGN_ID'] = isset( $this->_req_data['cntry'][$CNT_ISO]['RGN_ID'] ) ? absint( $this->_req_data['cntry'][$CNT_ISO]['RGN_ID'] ) : NULL;
757
		$cols_n_values['CNT_name'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_name'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_name'] ) : NULL;
758
		$cols_n_values['CNT_cur_code'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'] ) ? strtoupper( sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'] )) : 'USD';
759
		$cols_n_values['CNT_cur_single'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'] ) : 'dollar';
760
		$cols_n_values['CNT_cur_plural'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'] ) : 'dollars';
761
		$cols_n_values['CNT_cur_sign'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'] ) : '$';
762
		$cols_n_values['CNT_cur_sign_b4'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'] ) ? absint( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'] ) : TRUE;
763
		$cols_n_values['CNT_cur_dec_plc'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'] ) ? absint( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'] ) : 2;
764
		$cols_n_values['CNT_cur_dec_mrk'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'] ) : '.';
765
		$cols_n_values['CNT_cur_thsnds'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'] ) : ',';
766
		$cols_n_values['CNT_tel_code'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'] ) ? sanitize_text_field( $this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'] ) : NULL;
767
		$cols_n_values['CNT_is_EU'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'] ) ? absint( $this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'] ) : FALSE;
768
		$cols_n_values['CNT_active'] = isset( $this->_req_data['cntry'][$CNT_ISO]['CNT_active'] ) ? absint( $this->_req_data['cntry'][$CNT_ISO]['CNT_active'] ) : FALSE;
769
		// allow filtering of country data
770
		$cols_n_values = apply_filters( 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', $cols_n_values );
771
		//EEH_Debug_Tools::printr( $cols_n_values, '$cols_n_values  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
772
		// where values
773
		$where_cols_n_values = array( array( 'CNT_ISO' => $CNT_ISO ));
774
		// run the update
775
		$success = EEM_Country::instance()->update( $cols_n_values, $where_cols_n_values );
776
//		global $wpdb;
777
//		echo '<h4>' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
778
//		echo '<h4>$success : ' . $success . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
779
		if ( isset( $this->_req_data['states'] ) && is_array( $this->_req_data['states'] ) && $success !== FALSE ) {
780
			// allow filtering of states data
781
			$states = apply_filters( 'FHEE__General_Settings_Admin_Page___update_country_settings__states', $this->_req_data['states'] );
782
//			EEH_Debug_Tools::printr( $states, '$states  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
783
			// loop thru state data ( looks like : states[75][STA_name] )
784
			foreach( $states as $STA_ID => $state ) {
785
				$cols_n_values = array(
786
					'CNT_ISO' 		=> $CNT_ISO,
787
					'STA_abbrev' => sanitize_text_field( $state['STA_abbrev'] ),
788
					'STA_name' 	=> sanitize_text_field( $state['STA_name'] ),
789
					'STA_active' 	=> (bool)absint( $state['STA_active'] )
790
				);
791
				// where values
792
				$where_cols_n_values = array( array( 'STA_ID' => $STA_ID ));
793
				// run the update
794
				$success = EEM_State::instance()->update( $cols_n_values, $where_cols_n_values );
795
				if ( $success !== FALSE ) {
796
					do_action( 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', $CNT_ISO, $STA_ID, $cols_n_values );
797
				}
798
			}
799
		}
800
		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
801
		if ( isset( EE_Registry::instance()->CFG->organization->CNT_ISO ) && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO ) {
802
			EE_Registry::instance()->CFG->currency = new EE_Currency_Config( $CNT_ISO );
803
			EE_Registry::instance()->CFG->update_espresso_config();
804
		}
805
		$this->_redirect_after_action( $success, 'Countries', 'updated', array( 'action' => 'country_settings', 'country' => $CNT_ISO ));
806
	}
807
808
809
810
811
812
	/**
813
	 * 		form_form_field_label_wrap
814
	 *
815
	 * 		@access 		public
816
	 * 		@param 		string 		$label
817
	 * 		@return 		string
818
	 */
819
	public function country_form_field_label_wrap( $label, $required_text ) {
0 ignored issues
show
Unused Code introduced by
The parameter $required_text is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
820
		return '
821
			<tr>
822
				<th>
823
					' . $label  . '
824
				</th>';
825
	}
826
827
828
829
830
	/**
831
	 * 		form_form_field_input__wrap
832
	 *
833
	 * 		@access 		public
834
	 * 		@param 		string 		$label
835
	 * 		@return 		string
836
	 */
837
	public function country_form_field_input__wrap( $input, $label ) {
0 ignored issues
show
Unused Code introduced by
The parameter $label is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
838
		return '
839
				<td class="general-settings-country-input-td">
840
					' . $input . '
841
				</td>
842
			</tr>';
843
	}
844
845
846
847
848
	/**
849
	 * 		form_form_field_label_wrap
850
	 *
851
	 * 		@access 		public
852
	 * 		@param 		string 		$label
853
	 * 		@param 		string 		$required_text
854
	 * 		@return 		string
855
	 */
856
	public function state_form_field_label_wrap( $label, $required_text  ) {
857
		return $required_text;
858
	}
859
860
861
862
863
	/**
864
	 * 		form_form_field_input__wrap
865
	 *
866
	 * 		@access 		public
867
	 * 		@param 		string 		$label
868
	 * 		@return 		string
869
	 */
870
	public function state_form_field_input__wrap( $input, $label ) {
0 ignored issues
show
Unused Code introduced by
The parameter $label is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
871
		return '
872
				<td class="general-settings-country-state-input-td">
873
					' . $input . '
874
				</td>';
875
876
	}
877
878
879
880
881
882
883
	/***********/
884
885
886
887
888
889
	/**
890
	 * displays edit and view links for critical EE pages
891
	 *
892
	 * @access public
893
	 * @param int $ee_page_id
894
	 * @return string
895
	 */
896
	public static function edit_view_links( $ee_page_id ) {
897
		$links = '<a href="' . add_query_arg( array( 'post' => $ee_page_id, 'action' => 'edit' ),  admin_url( 'post.php' )) . '" >' . __('Edit', 'event_espresso') . '</a>';
898
		$links .= ' &nbsp;|&nbsp; ';
899
		$links .= '<a href="' . get_permalink( $ee_page_id ) . '" >' . __('View', 'event_espresso') . '</a>';
900
		return $links;
901
	}
902
903
904
905
906
	/**
907
	 * displays page and shortcode status for critical EE pages
908
	 *
909
	 * @param WP page object $ee_page
910
	 * @return string
911
	 */
912
	public static function page_and_shortcode_status( $ee_page, $shortcode ) {
913
914
		// page status
915
		if ( isset( $ee_page->post_status ) && $ee_page->post_status == 'publish') {
916
			$pg_colour = 'green';
917
			$pg_status = sprintf( __('Page%sStatus%sOK', 'event_espresso'), '&nbsp;' , '&nbsp;' );
918
		 } else {
919
			$pg_colour = 'red';
920
			$pg_status = sprintf( __('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;'  );
921
		}
922
923
		// shortcode status
924
		if ( isset( $ee_page->post_content ) && strpos( $ee_page->post_content, $shortcode ) !== FALSE ) {
925
			$sc_colour = 'green';
926
			$sc_status = sprintf( __('Shortcode%sOK', 'event_espresso'), '&nbsp;' );
927
		 } else {
928
			$sc_colour = 'red';
929
			$sc_status = sprintf( __('Shortcode%sProblem', 'event_espresso'), '&nbsp;' );
930
		}
931
932
		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' . $pg_status . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
933
934
	}
935
936
937
938
939
	/**
940
	 * generates a dropdown of all parent pages - copied from WP core
941
	 *
942
	 * @param unknown_type $default
943
	 * @param unknown_type $parent
944
	 * @param unknown_type $level
945
	 * @return unknown
946
	 */
947
	public static function page_settings_dropdown( $default = 0, $parent = 0, $level = 0 ) {
948
		global $wpdb;
949
		$items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", $parent) );
950
951
		if ( $items ) {
952
			foreach ( $items as $item ) {
953
				$pad = str_repeat( '&nbsp;', $level * 3 );
954
				if ( $item->ID == $default)
955
					$current = ' selected="selected"';
956
				else
957
					$current = '';
958
959
				echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
960
				parent_dropdown( $default, $item->ID, $level +1 );
961
			}
962
		} else {
963
			return false;
964
		}
965
	}
966
967
968
} //ends Forms_Admin_Page class
969