Completed
Branch Gutenberg/event-attendees-bloc... (c8d45d)
by
unknown
76:01 queued 62:31
created
modules/ical/EED_Ical.module.php 1 patch
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * @return EED_Ical|EED_Module
20 20
 	 */
21 21
 	public static function instance() {
22
-		return parent::get_instance( __CLASS__ );
22
+		return parent::get_instance(__CLASS__);
23 23
 	}
24 24
 
25 25
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 		// create download buttons
35 35
 		add_filter(
36 36
 		    'FHEE__espresso_list_of_event_dates__datetime_html',
37
-            array( 'EED_Ical', 'generate_add_to_iCal_button' ),
37
+            array('EED_Ical', 'generate_add_to_iCal_button'),
38 38
             10,
39 39
             2
40 40
         );
41 41
 		 // process ics download request
42
-		EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' );
42
+		EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
43 43
 	}
44 44
 
45 45
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param    WP $WP
63 63
 	 * @return    void
64 64
 	 */
65
-	public function run( $WP ) {}
65
+	public function run($WP) {}
66 66
 
67 67
 
68 68
 
@@ -75,35 +75,35 @@  discard block
 block discarded – undo
75 75
      * @return    string
76 76
      * @throws \EE_Error
77 77
      */
78
-	public static function generate_add_to_iCal_button( $html, $datetime ) {
78
+	public static function generate_add_to_iCal_button($html, $datetime) {
79 79
 		// first verify a proper datetime object has been received
80
-		if ( $datetime instanceof EE_Datetime ) {
80
+		if ($datetime instanceof EE_Datetime) {
81 81
 			// set whether a link or submit button is shown
82
-			$iCal_type = apply_filters( 'FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit' );
82
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
83 83
 			// generate a link to the route we registered in set_hooks()
84
-			$URL = add_query_arg( array( 'ee' => 'download_ics_file', 'ics_id' => $datetime->ID() ), site_url() );
84
+			$URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url());
85 85
 			// what type ?
86
-			switch ( $iCal_type ) {
86
+			switch ($iCal_type) {
87 87
 				// submit buttons appear as buttons and are very compatible with a theme's style
88 88
 				case 'submit' :
89
-					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
90
-					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
89
+					$html .= '<form id="download-iCal-frm-'.$datetime->ID();
90
+					$html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
91 91
 					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
92
-					$html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '"/>';
92
+					$html .= __('Add to iCal Calendar', 'event_espresso').'"/>';
93 93
 					$html .= '</form>';
94 94
 					break;
95 95
 				// buttons are just links that have been styled to appear as buttons,
96 96
                 // but may not be blend with a theme as well as submit buttons
97 97
 				case 'button' :
98
-					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99
-					$html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
98
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
99
+					$html .= '" title="'.__('Add to iCal Calendar', 'event_espresso').'">';
100 100
 					$html .= ' <span class="dashicons dashicons-calendar"></span>';
101 101
 					$html .= '</a>';
102 102
 					break;
103 103
 				// links are just links that use the calendar dashicon
104 104
 				case 'icon' :
105
-					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
106
-					$html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
105
+					$html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
106
+					$html .= __('Add to iCal Calendar', 'event_espresso').'">';
107 107
 					$html .= ' <span class="dashicons dashicons-calendar"></span>';
108 108
 					$html .= '</a>';
109 109
 					break;
@@ -122,29 +122,29 @@  discard block
 block discarded – undo
122 122
      * @throws \EE_Error
123 123
      */
124 124
 	public static function download_ics_file() {
125
-		if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) {
126
-			$DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' ));
127
-			$datetime = EE_Registry::instance()->load_model( 'Datetime' )->get_one_by_ID( $DTT_ID );
128
-			if ( $datetime instanceof EE_Datetime ) {
125
+		if (EE_Registry::instance()->REQ->is_set('ics_id')) {
126
+			$DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id'));
127
+			$datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID);
128
+			if ($datetime instanceof EE_Datetime) {
129 129
 				// get related event, venues, and event categories
130 130
 				$event = $datetime->event();
131 131
 				// get related category Term object and it's name
132 132
 				$category = $event->first_event_category();
133
-				if ( $category instanceof EE_Term ) {
133
+				if ($category instanceof EE_Term) {
134 134
 					$category = $category->name();
135 135
 				}
136 136
 				$location = '';
137 137
 				// get first related venue and convert to CSV string
138
-				$venue = $event->venues(array( 'limit'=>1 ));
139
-				if ( is_array( $venue ) && ! empty( $venue )) {
140
-					$venue = array_shift( $venue );
141
-					if ( $venue instanceof EE_Venue ) {
142
-						$location = espresso_venue_raw_address( 'inline', $venue->ID(), FALSE );
138
+				$venue = $event->venues(array('limit'=>1));
139
+				if (is_array($venue) && ! empty($venue)) {
140
+					$venue = array_shift($venue);
141
+					if ($venue instanceof EE_Venue) {
142
+						$location = espresso_venue_raw_address('inline', $venue->ID(), FALSE);
143 143
 					}
144 144
 				}
145 145
 
146 146
 				//Generate filename
147
-				$filename = $event->slug() . '-' . $datetime->start_date( 'Y-m-d' ) . '.ics';
147
+				$filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
148 148
 
149 149
 				//Check the datetime status has not been cancelled and set the ics value accordingly
150 150
 				$status = $datetime->get_active_status();
@@ -153,48 +153,48 @@  discard block
 block discarded – undo
153 153
 				// Create array of ics details, escape strings, convert timestamps to ics format, etc
154 154
 				$ics_data = array(
155 155
 					'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
156
-					'UID' => md5( $event->name() . $event->ID() . $datetime->ID() ),
156
+					'UID' => md5($event->name().$event->ID().$datetime->ID()),
157 157
 					'ORGANIZER' => EE_Registry::instance()->CFG->organization->email,
158
-					'DTSTAMP' => date( EED_Ical::iCal_datetime_format ),
158
+					'DTSTAMP' => date(EED_Ical::iCal_datetime_format),
159 159
 					'LOCATION' => $location,
160 160
 					'SUMMARY' => $event->name(),
161
-					'DESCRIPTION' => wp_strip_all_tags( $event->description() ),
161
+					'DESCRIPTION' => wp_strip_all_tags($event->description()),
162 162
 					'STATUS' => $status,
163 163
 					'CATEGORIES' => $category,
164
-					'URL;VALUE=URI' => get_permalink( $event->ID() ),
165
-					'DTSTART' => date( EED_Ical::iCal_datetime_format, $datetime->start() ),
166
-					'DTEND' => date( EED_Ical::iCal_datetime_format, $datetime->end() ),
164
+					'URL;VALUE=URI' => get_permalink($event->ID()),
165
+					'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()),
166
+					'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()),
167 167
 				);
168 168
 
169 169
 				//Filter the values used within the ics output.
170 170
 				//NOTE - all values within ics_data will be escaped automatically.
171
-				$ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime );
171
+				$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
172 172
 
173 173
 				//Escape all ics data
174
-				foreach( $ics_data as $key => $value ) {
174
+				foreach ($ics_data as $key => $value) {
175 175
 					//Description is escaped differently from all all values
176
-					if( $key === 'DESCRIPTION' ) {
177
-						$ics_data[$key] = EED_Ical::_escape_ICal_description( wp_strip_all_tags( $value ) );
176
+					if ($key === 'DESCRIPTION') {
177
+						$ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178 178
 					} else {
179
-						$ics_data[$key] = EED_Ical::_escape_ICal_data( $value );
179
+						$ics_data[$key] = EED_Ical::_escape_ICal_data($value);
180 180
 					}
181 181
 				}
182 182
 
183 183
 				//Pull the organizer name from ics_data and remove it from the array.
184
-				$organizer_name = isset( $ics_data['ORGANIZER_NAME'] ) ? $ics_data['ORGANIZER_NAME'] : '';
185
-				unset( $ics_data['ORGANIZER_NAME'] );
184
+				$organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
185
+				unset($ics_data['ORGANIZER_NAME']);
186 186
 
187 187
 				// set headers
188
-				header( 'Content-type: text/calendar; charset=utf-8' );
189
-				header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
190
-				header( 'Cache-Control: private, max-age=0, must-revalidate' );
191
-				header( 'Pragma: public' );
192
-				header( 'Content-Type: application/octet-stream' );
193
-				header( 'Content-Type: application/force-download' );
194
-				header( 'Cache-Control: no-cache, must-revalidate' );
195
-				header( 'Content-Transfer-Encoding: binary' );
196
-				header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date
197
-				ini_set( 'zlib.output_compression', '0' );
188
+				header('Content-type: text/calendar; charset=utf-8');
189
+				header('Content-Disposition: attachment; filename="'.$filename.'"');
190
+				header('Cache-Control: private, max-age=0, must-revalidate');
191
+				header('Pragma: public');
192
+				header('Content-Type: application/octet-stream');
193
+				header('Content-Type: application/force-download');
194
+				header('Cache-Control: no-cache, must-revalidate');
195
+				header('Content-Transfer-Encoding: binary');
196
+				header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
197
+				ini_set('zlib.output_compression', '0');
198 198
 				// echo the output
199 199
 				echo "BEGIN:VCALENDAR\r\n";
200 200
 				echo "VERSION:2.0\r\n";
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 				echo "BEGIN:VEVENT\r\n";
204 204
 				
205 205
 				//Output all remaining values from ics_data.
206
-				foreach( $ics_data as $key => $value ) {
207
-					echo $key . ':' . $value . "\r\n";
206
+				foreach ($ics_data as $key => $value) {
207
+					echo $key.':'.$value."\r\n";
208 208
 				}
209 209
 
210 210
 				echo "END:VEVENT\r\n";
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 *  	@param	string $string
224 224
 	 *  	@return	string
225 225
 	 */
226
-	private static function _escape_ICal_data( $string = '' ) {
227
-		return preg_replace( '/([\,;])/', '\\\$1', $string );
226
+	private static function _escape_ICal_data($string = '') {
227
+		return preg_replace('/([\,;])/', '\\\$1', $string);
228 228
 	}
229 229
 
230 230
 	/**
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 	 *  	@param	string $description
235 235
 	 *  	@return	string
236 236
 	 */
237
-	private static function _escape_ICal_description( $description = '' ) {
237
+	private static function _escape_ICal_description($description = '') {
238 238
 
239 239
 			//Escape special chars within the description
240
-			$description = EED_Ical::_escape_ICal_data( $description );
240
+			$description = EED_Ical::_escape_ICal_data($description);
241 241
 
242 242
 		    //Remove line breaks and output in iCal format
243
-		    $description = str_replace( array( "\r\n", "\n"), '\n', $description );
243
+		    $description = str_replace(array("\r\n", "\n"), '\n', $description);
244 244
 
245 245
 		return $description;
246 246
 	}
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Form_Input_Base.input.php 2 patches
Indentation   +1238 added lines, -1238 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,1241 +16,1241 @@  discard block
 block discarded – undo
16 16
 abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable
17 17
 {
18 18
 
19
-    /**
20
-     * the input's name attribute
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_html_name;
25
-
26
-    /**
27
-     * id for the html label tag
28
-     *
29
-     * @var string
30
-     */
31
-    protected $_html_label_id;
32
-
33
-    /**
34
-     * class for teh html label tag
35
-     *
36
-     * @var string
37
-     */
38
-    protected $_html_label_class;
39
-
40
-    /**
41
-     * any additional html attributes that you may want to add
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_html_other_attributes;
46
-
47
-    /**
48
-     * style for teh html label tag
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_html_label_style;
53
-
54
-    /**
55
-     * text to be placed in the html label
56
-     *
57
-     * @var string
58
-     */
59
-    protected $_html_label_text;
60
-
61
-    /**
62
-     * the full html label. If used, all other html_label_* properties are invalid
63
-     *
64
-     * @var string
65
-     */
66
-    protected $_html_label;
67
-
68
-    /**
69
-     * HTML to use for help text (normally placed below form input), in a span which normally
70
-     * has a class of 'description'
71
-     *
72
-     * @var string
73
-     */
74
-    protected $_html_help_text;
75
-
76
-    /**
77
-     * CSS classes for displaying the help span
78
-     *
79
-     * @var string
80
-     */
81
-    protected $_html_help_class = 'description';
82
-
83
-    /**
84
-     * CSS to put in the style attribute on the help span
85
-     *
86
-     * @var string
87
-     */
88
-    protected $_html_help_style;
89
-
90
-    /**
91
-     * Stores whether or not this input's response is required.
92
-     * Because certain styling elements may also want to know that this
93
-     * input is required etc.
94
-     *
95
-     * @var boolean
96
-     */
97
-    protected $_required;
98
-
99
-    /**
100
-     * css class added to required inputs
101
-     *
102
-     * @var string
103
-     */
104
-    protected $_required_css_class = 'ee-required';
105
-
106
-    /**
107
-     * css styles applied to button type inputs
108
-     *
109
-     * @var string
110
-     */
111
-    protected $_button_css_attributes;
112
-
113
-    /**
114
-     * The raw data submitted for this, like in the $_POST super global.
115
-     * Generally unsafe for usage in client code
116
-     *
117
-     * @var mixed string or array
118
-     */
119
-    protected $_raw_value;
120
-
121
-    /**
122
-     * Value normalized according to the input's normalization strategy.
123
-     * The normalization strategy dictates whether this is a string, int, float,
124
-     * boolean, or array of any of those.
125
-     *
126
-     * @var mixed
127
-     */
128
-    protected $_normalized_value;
129
-
130
-
131
-    /**
132
-     * Normalized default value either initially set on the input, or provided by calling
133
-     * set_default().
134
-     * @var mixed
135
-     */
136
-    protected $_default;
137
-
138
-    /**
139
-     * Strategy used for displaying this field.
140
-     * Child classes must use _get_display_strategy to access it.
141
-     *
142
-     * @var EE_Display_Strategy_Base
143
-     */
144
-    private $_display_strategy;
145
-
146
-    /**
147
-     * Gets all the validation strategies used on this field
148
-     *
149
-     * @var EE_Validation_Strategy_Base[]
150
-     */
151
-    private $_validation_strategies = array();
152
-
153
-    /**
154
-     * The normalization strategy for this field
155
-     *
156
-     * @var EE_Normalization_Strategy_Base
157
-     */
158
-    private $_normalization_strategy;
159
-
160
-    /**
161
-     * Strategy for removing sensitive data after we're done with the form input
162
-     *
163
-     * @var EE_Sensitive_Data_Removal_Base
164
-     */
165
-    protected $_sensitive_data_removal_strategy;
166
-
167
-    /**
168
-     * Whether this input has been disabled or not.
169
-     * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
170
-     * (Client-side code that wants to dynamically disable it must also add this hidden input).
171
-     * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored.
172
-     * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored.
173
-     *
174
-     * @var boolean
175
-     */
176
-    protected $disabled = false;
177
-
178
-
179
-
180
-    /**
181
-     * @param array                         $input_args       {
182
-     * @type string                         $html_name        the html name for the input
183
-     * @type string                         $html_label_id    the id attribute to give to the html label tag
184
-     * @type string                         $html_label_class the class attribute to give to the html label tag
185
-     * @type string                         $html_label_style the style attribute to give ot teh label tag
186
-     * @type string                         $html_label_text  the text to put in the label tag
187
-     * @type string                         $html_label       the full html label. If used,
188
-     *                                                        all other html_label_* args are invalid
189
-     * @type string                         $html_help_text   text to put in help element
190
-     * @type string                         $html_help_style  style attribute to give to teh help element
191
-     * @type string                         $html_help_class  class attribute to give to the help element
192
-     * @type string                         $default          default value NORMALIZED (eg, if providing the default
193
-     *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
194
-     * @type EE_Display_Strategy_Base       $display          strategy
195
-     * @type EE_Normalization_Strategy_Base $normalization_strategy
196
-     * @type EE_Validation_Strategy_Base[]  $validation_strategies
197
-     * @type boolean                        $ignore_input special argument which can be used to avoid adding any validation strategies,
198
-     *                                                    and sets the normalization strategy to the Null normalization. This is good
199
-     *                                                    when you want the input to be totally ignored server-side (like when using
200
-     *                                                    React.js form inputs)
201
-     *                                                        }
202
-     */
203
-    public function __construct($input_args = array())
204
-    {
205
-        $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
206
-        // the following properties must be cast as arrays
207
-        if (isset($input_args['validation_strategies'])) {
208
-            foreach ((array)$input_args['validation_strategies'] as $validation_strategy) {
209
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
210
-                    $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
211
-                }
212
-            }
213
-            unset($input_args['validation_strategies']);
214
-        }
215
-        if(isset($input_args['ignore_input'])) {
216
-            $this->_validation_strategies = array();
217
-        }
218
-        // loop thru incoming options
219
-        foreach ($input_args as $key => $value) {
220
-            // add underscore to $key to match property names
221
-            $_key = '_' . $key;
222
-            if (property_exists($this, $_key)) {
223
-                $this->{$_key} = $value;
224
-            }
225
-        }
226
-        // ensure that "required" is set correctly
227
-        $this->set_required(
228
-            $this->_required, isset($input_args['required_validation_error_message'])
229
-            ? $input_args['required_validation_error_message']
230
-            : null
231
-        );
232
-        //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
233
-        $this->_display_strategy->_construct_finalize($this);
234
-        foreach ($this->_validation_strategies as $validation_strategy) {
235
-            $validation_strategy->_construct_finalize($this);
236
-        }
237
-        if (isset($input_args['ignore_input'])) {
238
-            $this->_normalization_strategy = new EE_Null_Normalization();
239
-        }
240
-        if (! $this->_normalization_strategy) {
241
-                $this->_normalization_strategy = new EE_Text_Normalization();
242
-        }
243
-        $this->_normalization_strategy->_construct_finalize($this);
244
-        //at least we can use the normalization strategy to populate the default
245
-        if (isset($input_args['default'])) {
246
-            $this->set_default($input_args['default']);
247
-            unset($input_args['default']);
248
-        }
249
-        if (! $this->_sensitive_data_removal_strategy) {
250
-            $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
251
-        }
252
-        $this->_sensitive_data_removal_strategy->_construct_finalize($this);
253
-        parent::__construct($input_args);
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * Sets the html_name to its default value, if none was specified in teh constructor.
260
-     * Calculation involves using the name and the parent's html_name
261
-     *
262
-     * @throws \EE_Error
263
-     */
264
-    protected function _set_default_html_name_if_empty()
265
-    {
266
-        if (! $this->_html_name) {
267
-            $this->_html_name = $this->name();
268
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
269
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
270
-            }
271
-        }
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @param $parent_form_section
278
-     * @param $name
279
-     * @throws \EE_Error
280
-     */
281
-    public function _construct_finalize($parent_form_section, $name)
282
-    {
283
-        parent::_construct_finalize($parent_form_section, $name);
284
-        if ($this->_html_label === null && $this->_html_label_text === null) {
285
-            $this->_html_label_text = ucwords(str_replace("_", " ", $name));
286
-        }
287
-        do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * Returns the strategy for displaying this form input. If none is set, throws an exception.
294
-     *
295
-     * @return EE_Display_Strategy_Base
296
-     * @throws EE_Error
297
-     */
298
-    protected function _get_display_strategy()
299
-    {
300
-        $this->ensure_construct_finalized_called();
301
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
302
-            throw new EE_Error(
303
-                sprintf(
304
-                    __(
305
-                        "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
306
-                        "event_espresso"
307
-                    ),
308
-                    $this->html_name(),
309
-                    $this->html_id()
310
-                )
311
-            );
312
-        } else {
313
-            return $this->_display_strategy;
314
-        }
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * Sets the display strategy.
321
-     *
322
-     * @param EE_Display_Strategy_Base $strategy
323
-     */
324
-    protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
325
-    {
326
-        $this->_display_strategy = $strategy;
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     * Sets the sanitization strategy
333
-     *
334
-     * @param EE_Normalization_Strategy_Base $strategy
335
-     */
336
-    protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
337
-    {
338
-        $this->_normalization_strategy = $strategy;
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * Gets sensitive_data_removal_strategy
345
-     *
346
-     * @return EE_Sensitive_Data_Removal_Base
347
-     */
348
-    public function get_sensitive_data_removal_strategy()
349
-    {
350
-        return $this->_sensitive_data_removal_strategy;
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * Sets sensitive_data_removal_strategy
357
-     *
358
-     * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
359
-     * @return boolean
360
-     */
361
-    public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
362
-    {
363
-        $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * Gets the display strategy for this input
370
-     *
371
-     * @return EE_Display_Strategy_Base
372
-     */
373
-    public function get_display_strategy()
374
-    {
375
-        return $this->_display_strategy;
376
-    }
377
-
378
-
379
-
380
-    /**
381
-     * Overwrites the display strategy
382
-     *
383
-     * @param EE_Display_Strategy_Base $display_strategy
384
-     */
385
-    public function set_display_strategy($display_strategy)
386
-    {
387
-        $this->_display_strategy = $display_strategy;
388
-        $this->_display_strategy->_construct_finalize($this);
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * Gets the normalization strategy set on this input
395
-     *
396
-     * @return EE_Normalization_Strategy_Base
397
-     */
398
-    public function get_normalization_strategy()
399
-    {
400
-        return $this->_normalization_strategy;
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * Overwrites the normalization strategy
407
-     *
408
-     * @param EE_Normalization_Strategy_Base $normalization_strategy
409
-     */
410
-    public function set_normalization_strategy($normalization_strategy)
411
-    {
412
-        $this->_normalization_strategy = $normalization_strategy;
413
-        $this->_normalization_strategy->_construct_finalize($this);
414
-    }
415
-
416
-
417
-
418
-    /**
419
-     * Returns all teh validation strategies which apply to this field, numerically indexed
420
-     *
421
-     * @return EE_Validation_Strategy_Base[]
422
-     */
423
-    public function get_validation_strategies()
424
-    {
425
-        return $this->_validation_strategies;
426
-    }
427
-
428
-
429
-
430
-    /**
431
-     * Adds this strategy to the field so it will be used in both JS validation and server-side validation
432
-     *
433
-     * @param EE_Validation_Strategy_Base $validation_strategy
434
-     * @return void
435
-     */
436
-    protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
437
-    {
438
-        $validation_strategy->_construct_finalize($this);
439
-        $this->_validation_strategies[] = $validation_strategy;
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     * Adds a new validation strategy onto the form input
446
-     *
447
-     * @param EE_Validation_Strategy_Base $validation_strategy
448
-     * @return void
449
-     */
450
-    public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
451
-    {
452
-        $this->_add_validation_strategy($validation_strategy);
453
-    }
454
-
455
-
456
-
457
-    /**
458
-     * The classname of the validation strategy to remove
459
-     *
460
-     * @param string $validation_strategy_classname
461
-     */
462
-    public function remove_validation_strategy($validation_strategy_classname)
463
-    {
464
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
465
-            if (
466
-                $validation_strategy instanceof $validation_strategy_classname
467
-                || is_subclass_of($validation_strategy, $validation_strategy_classname)
468
-            ) {
469
-                unset($this->_validation_strategies[$key]);
470
-            }
471
-        }
472
-    }
473
-
474
-
475
-
476
-    /**
477
-     * returns true if input employs any of the validation strategy defined by the supplied array of classnames
478
-     *
479
-     * @param array $validation_strategy_classnames
480
-     * @return bool
481
-     */
482
-    public function has_validation_strategy($validation_strategy_classnames)
483
-    {
484
-        $validation_strategy_classnames = is_array($validation_strategy_classnames)
485
-            ? $validation_strategy_classnames
486
-            : array($validation_strategy_classnames);
487
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
488
-            if (in_array($key, $validation_strategy_classnames)) {
489
-                return true;
490
-            }
491
-        }
492
-        return false;
493
-    }
494
-
495
-
496
-
497
-    /**
498
-     * Gets the HTML
499
-     *
500
-     * @return string
501
-     */
502
-    public function get_html()
503
-    {
504
-        return $this->_parent_section->get_html_for_input($this);
505
-    }
506
-
507
-
508
-
509
-    /**
510
-     * Gets the HTML for the input itself (no label or errors) according to the
511
-     * input's display strategy
512
-     * Makes sure the JS and CSS are enqueued for it
513
-     *
514
-     * @return string
515
-     * @throws \EE_Error
516
-     */
517
-    public function get_html_for_input()
518
-    {
519
-        return $this->_form_html_filter
520
-            ? $this->_form_html_filter->filterHtml(
521
-                $this->_get_display_strategy()->display(),
522
-                $this
523
-            )
524
-            : $this->_get_display_strategy()->display();
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * @return string
531
-     */
532
-    public function html_other_attributes()
533
-    {
534
-        return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : '';
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * @param string $html_other_attributes
541
-     */
542
-    public function set_html_other_attributes($html_other_attributes)
543
-    {
544
-        $this->_html_other_attributes = $html_other_attributes;
545
-    }
546
-
547
-
548
-
549
-    /**
550
-     * Gets the HTML for displaying the label for this form input
551
-     * according to the form section's layout strategy
552
-     *
553
-     * @return string
554
-     */
555
-    public function get_html_for_label()
556
-    {
557
-        return $this->_parent_section->get_layout_strategy()->display_label($this);
558
-    }
559
-
560
-
561
-
562
-    /**
563
-     * Gets the HTML for displaying the errors section for this form input
564
-     * according to the form section's layout strategy
565
-     *
566
-     * @return string
567
-     */
568
-    public function get_html_for_errors()
569
-    {
570
-        return $this->_parent_section->get_layout_strategy()->display_errors($this);
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * Gets the HTML for displaying the help text for this form input
577
-     * according to the form section's layout strategy
578
-     *
579
-     * @return string
580
-     */
581
-    public function get_html_for_help()
582
-    {
583
-        return $this->_parent_section->get_layout_strategy()->display_help_text($this);
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * Validates the input's sanitized value (assumes _sanitize() has already been called)
590
-     * and returns whether or not the form input's submitted value is value
591
-     *
592
-     * @return boolean
593
-     */
594
-    protected function _validate()
595
-    {
596
-        if ($this->isDisabled()) {
597
-            return true;
598
-        }
599
-        foreach ($this->_validation_strategies as $validation_strategy) {
600
-            if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
601
-                try {
602
-                    $validation_strategy->validate($this->normalized_value());
603
-                } catch (EE_Validation_Error $e) {
604
-                    $this->add_validation_error($e);
605
-                }
606
-            }
607
-        }
608
-        if ($this->get_validation_errors()) {
609
-            return false;
610
-        } else {
611
-            return true;
612
-        }
613
-    }
614
-
615
-
616
-
617
-    /**
618
-     * Performs basic sanitization on this value. But what sanitization can be performed anyways?
619
-     * This value MIGHT be allowed to have tags, so we can't really remove them.
620
-     *
621
-     * @param string $value
622
-     * @return null|string
623
-     */
624
-    private function _sanitize($value)
625
-    {
626
-        return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
627
-    }
628
-
629
-
630
-
631
-    /**
632
-     * Picks out the form value that relates to this form input,
633
-     * and stores it as the sanitized value on the form input, and sets the normalized value.
634
-     * Returns whether or not any validation errors occurred
635
-     *
636
-     * @param array $req_data like $_POST
637
-     * @return boolean whether or not there was an error
638
-     * @throws \EE_Error
639
-     */
640
-    protected function _normalize($req_data)
641
-    {
642
-        //any existing validation errors don't apply so clear them
643
-        $this->_validation_errors = array();
644
-        //if the input is disabled, ignore whatever input was sent in
645
-        if($this->isDisabled()) {
646
-            $this->_set_raw_value(null);
647
-            $this->_set_normalized_value($this->get_default());
648
-            return false;
649
-        }
650
-        try {
651
-            $raw_input = $this->find_form_data_for_this_section($req_data);
652
-            //super simple sanitization for now
653
-            if (is_array($raw_input)) {
654
-                $raw_value = array();
655
-                foreach ($raw_input as $key => $value) {
656
-                    $raw_value[$key] = $this->_sanitize($value);
657
-                }
658
-                $this->_set_raw_value($raw_value);
659
-            } else {
660
-                $this->_set_raw_value($this->_sanitize($raw_input));
661
-            }
662
-            //we want to mostly leave the input alone in case we need to re-display it to the user
663
-            $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
664
-            return false;
665
-        } catch (EE_Validation_Error $e) {
666
-            $this->add_validation_error($e);
667
-            return true;
668
-        }
669
-    }
670
-
671
-
672
-
673
-    /**
674
-     * @return string
675
-     */
676
-    public function html_name()
677
-    {
678
-        $this->_set_default_html_name_if_empty();
679
-        return $this->_html_name;
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * @return string
686
-     */
687
-    public function html_label_id()
688
-    {
689
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * @return string
696
-     */
697
-    public function html_label_class()
698
-    {
699
-        return $this->_html_label_class;
700
-    }
701
-
702
-
703
-
704
-    /**
705
-     * @return string
706
-     */
707
-    public function html_label_style()
708
-    {
709
-        return $this->_html_label_style;
710
-    }
711
-
712
-
713
-
714
-    /**
715
-     * @return string
716
-     */
717
-    public function html_label_text()
718
-    {
719
-        return $this->_html_label_text;
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     * @return string
726
-     */
727
-    public function html_help_text()
728
-    {
729
-        return $this->_html_help_text;
730
-    }
731
-
732
-
733
-
734
-    /**
735
-     * @return string
736
-     */
737
-    public function html_help_class()
738
-    {
739
-        return $this->_html_help_class;
740
-    }
741
-
742
-
743
-
744
-    /**
745
-     * @return string
746
-     */
747
-    public function html_help_style()
748
-    {
749
-        return $this->_html_style;
750
-    }
751
-
752
-
753
-
754
-    /**
755
-     * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
756
-     * Please note that almost all client code should instead use the normalized_value;
757
-     * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
758
-     * mostly by escaping quotes)
759
-     * Note, we do not store the exact original value sent in the user's request because
760
-     * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
761
-     * in which case, we would have stored the malicious content to our database.
762
-     *
763
-     * @return string
764
-     */
765
-    public function raw_value()
766
-    {
767
-        return $this->_raw_value;
768
-    }
769
-
770
-
771
-
772
-    /**
773
-     * Returns a string safe to usage in form inputs when displaying, because
774
-     * it escapes all html entities
775
-     *
776
-     * @return string
777
-     */
778
-    public function raw_value_in_form()
779
-    {
780
-        return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
781
-    }
782
-
783
-
784
-
785
-    /**
786
-     * returns the value after it's been sanitized, and then converted into it's proper type
787
-     * in PHP. Eg, a string, an int, an array,
788
-     *
789
-     * @return mixed
790
-     */
791
-    public function normalized_value()
792
-    {
793
-        return $this->_normalized_value;
794
-    }
795
-
796
-
797
-
798
-    /**
799
-     * Returns the normalized value is a presentable way. By default this is just
800
-     * the normalized value by itself, but it can be overridden for when that's not
801
-     * the best thing to display
802
-     *
803
-     * @return string
804
-     */
805
-    public function pretty_value()
806
-    {
807
-        return $this->_normalized_value;
808
-    }
809
-
810
-
811
-
812
-    /**
813
-     * When generating the JS for the jquery validation rules like<br>
814
-     * <code>$( "#myform" ).validate({
815
-     * rules: {
816
-     * password: "required",
817
-     * password_again: {
818
-     * equalTo: "#password"
819
-     * }
820
-     * }
821
-     * });</code>
822
-     * if this field had the name 'password_again', it should return
823
-     * <br><code>password_again: {
824
-     * equalTo: "#password"
825
-     * }</code>
826
-     *
827
-     * @return array
828
-     */
829
-    public function get_jquery_validation_rules()
830
-    {
831
-        $jquery_validation_js = array();
832
-        $jquery_validation_rules = array();
833
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
834
-            $jquery_validation_rules = array_replace_recursive(
835
-                $jquery_validation_rules,
836
-                $validation_strategy->get_jquery_validation_rule_array()
837
-            );
838
-        }
839
-        if (! empty($jquery_validation_rules)) {
840
-            foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
841
-                $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
842
-            }
843
-        }
844
-        return $jquery_validation_js;
845
-    }
846
-
847
-
848
-
849
-    /**
850
-     * Sets the input's default value for use in displaying in the form. Note: value should be
851
-     * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
852
-     *
853
-     * @param mixed $value
854
-     * @return void
855
-     */
856
-    public function set_default($value)
857
-    {
858
-        $this->_default = $value;
859
-        $this->_set_normalized_value($value);
860
-        $this->_set_raw_value($value);
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * Sets the normalized value on this input
867
-     *
868
-     * @param mixed $value
869
-     */
870
-    protected function _set_normalized_value($value)
871
-    {
872
-        $this->_normalized_value = $value;
873
-    }
874
-
875
-
876
-
877
-    /**
878
-     * Sets the raw value on this input (ie, exactly as the user submitted it)
879
-     *
880
-     * @param mixed $value
881
-     */
882
-    protected function _set_raw_value($value)
883
-    {
884
-        $this->_raw_value = $this->_normalization_strategy->unnormalize($value);
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * Sets the HTML label text after it has already been defined
891
-     *
892
-     * @param string $label
893
-     * @return void
894
-     */
895
-    public function set_html_label_text($label)
896
-    {
897
-        $this->_html_label_text = $label;
898
-    }
899
-
900
-
901
-
902
-    /**
903
-     * Sets whether or not this field is required, and adjusts the validation strategy.
904
-     * If you want to use the EE_Conditionally_Required_Validation_Strategy,
905
-     * please add it as a validation strategy using add_validation_strategy as normal
906
-     *
907
-     * @param boolean $required boolean
908
-     * @param null    $required_text
909
-     */
910
-    public function set_required($required = true, $required_text = null)
911
-    {
912
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
913
-        //whether $required is a string or a boolean, we want to add a required validation strategy
914
-        if ($required) {
915
-            $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
916
-        } else {
917
-            $this->remove_validation_strategy('EE_Required_Validation_Strategy');
918
-        }
919
-        $this->_required = $required;
920
-    }
921
-
922
-
923
-
924
-    /**
925
-     * Returns whether or not this field is required
926
-     *
927
-     * @return boolean
928
-     */
929
-    public function required()
930
-    {
931
-        return $this->_required;
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * @param string $required_css_class
938
-     */
939
-    public function set_required_css_class($required_css_class)
940
-    {
941
-        $this->_required_css_class = $required_css_class;
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * @return string
948
-     */
949
-    public function required_css_class()
950
-    {
951
-        return $this->_required_css_class;
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * @param bool $add_required
958
-     * @return string
959
-     */
960
-    public function html_class($add_required = false)
961
-    {
962
-        return $add_required && $this->required()
963
-            ? $this->required_css_class() . ' ' . $this->_html_class
964
-            : $this->_html_class;
965
-    }
966
-
967
-
968
-    /**
969
-     * Sets the help text, in case
970
-     *
971
-     * @param string $text
972
-     */
973
-    public function set_html_help_text($text)
974
-    {
975
-        $this->_html_help_text = $text;
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * Uses the sensitive data removal strategy to remove the sensitive data from this
982
-     * input. If there is any kind of sensitive data removal on this input, we clear
983
-     * out the raw value completely
984
-     *
985
-     * @return void
986
-     */
987
-    public function clean_sensitive_data()
988
-    {
989
-        //if we do ANY kind of sensitive data removal on this, then just clear out the raw value
990
-        //if we need more logic than this we'll make a strategy for it
991
-        if ($this->_sensitive_data_removal_strategy
992
-            && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
993
-        ) {
994
-            $this->_set_raw_value(null);
995
-        }
996
-        //and clean the normalized value according to the appropriate strategy
997
-        $this->_set_normalized_value(
998
-            $this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
999
-                $this->_normalized_value
1000
-            )
1001
-        );
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * @param bool   $primary
1008
-     * @param string $button_size
1009
-     * @param string $other_attributes
1010
-     */
1011
-    public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1012
-    {
1013
-        $button_css_attributes = 'button';
1014
-        $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
1015
-        switch ($button_size) {
1016
-            case 'xs' :
1017
-            case 'extra-small' :
1018
-                $button_css_attributes .= ' button-xs';
1019
-                break;
1020
-            case 'sm' :
1021
-            case 'small' :
1022
-                $button_css_attributes .= ' button-sm';
1023
-                break;
1024
-            case 'lg' :
1025
-            case 'large' :
1026
-                $button_css_attributes .= ' button-lg';
1027
-                break;
1028
-            case 'block' :
1029
-                $button_css_attributes .= ' button-block';
1030
-                break;
1031
-            case 'md' :
1032
-            case 'medium' :
1033
-            default :
1034
-                $button_css_attributes .= '';
1035
-        }
1036
-        $this->_button_css_attributes .= ! empty($other_attributes)
1037
-            ? $button_css_attributes . ' ' . $other_attributes
1038
-            : $button_css_attributes;
1039
-    }
1040
-
1041
-
1042
-
1043
-    /**
1044
-     * @return string
1045
-     */
1046
-    public function button_css_attributes()
1047
-    {
1048
-        if (empty($this->_button_css_attributes)) {
1049
-            $this->set_button_css_attributes();
1050
-        }
1051
-        return $this->_button_css_attributes;
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     * find_form_data_for_this_section
1058
-     * using this section's name and its parents, finds the value of the form data that corresponds to it.
1059
-     * For example, if this form section's HTML name is my_form[subform][form_input_1],
1060
-     * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1061
-     * (If that doesn't exist, we also check for this subsection's name
1062
-     * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1063
-     * This function finds its value in the form.
1064
-     *
1065
-     * @param array $req_data
1066
-     * @return mixed whatever the raw value of this form section is in the request data
1067
-     * @throws \EE_Error
1068
-     */
1069
-    public function find_form_data_for_this_section($req_data)
1070
-    {
1071
-        $name_parts = $this->getInputNameParts();
1072
-        // now get the value for the input
1073
-        $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1074
-        // check if this thing's name is at the TOP level of the request data
1075
-        if ($value === null && isset($req_data[$this->name()])) {
1076
-            $value = $req_data[$this->name()];
1077
-        }
1078
-        return $value;
1079
-    }
1080
-
1081
-
1082
-
1083
-    /**
1084
-     * If this input's name is something like "foo[bar][baz]"
1085
-     * returns an array like `array('foo','bar',baz')`
1086
-     * @return array
1087
-     */
1088
-    protected function getInputNameParts()
1089
-    {
1090
-        // break up the html name by "[]"
1091
-        if (strpos($this->html_name(), '[') !== false) {
1092
-            $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1093
-        } else {
1094
-            $before_any_brackets = $this->html_name();
1095
-        }
1096
-        // grab all of the segments
1097
-        preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1098
-        if (isset($matches[1]) && is_array($matches[1])) {
1099
-            $name_parts = $matches[1];
1100
-            array_unshift($name_parts, $before_any_brackets);
1101
-        } else {
1102
-            $name_parts = array($before_any_brackets);
1103
-        }
1104
-        return $name_parts;
1105
-    }
1106
-
1107
-
1108
-
1109
-    /**
1110
-     * @param array $html_name_parts
1111
-     * @param array $req_data
1112
-     * @return array | NULL
1113
-     */
1114
-    public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1115
-    {
1116
-        $first_part_to_consider = array_shift($html_name_parts);
1117
-        if (isset($req_data[$first_part_to_consider])) {
1118
-            if (empty($html_name_parts)) {
1119
-                return $req_data[$first_part_to_consider];
1120
-            } else {
1121
-                return $this->findRequestForSectionUsingNameParts(
1122
-                    $html_name_parts,
1123
-                    $req_data[$first_part_to_consider]
1124
-                );
1125
-            }
1126
-        } else {
1127
-            return null;
1128
-        }
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     * Checks if this form input's data is in the request data
1135
-     *
1136
-     * @param array $req_data like $_POST
1137
-     * @return boolean
1138
-     * @throws \EE_Error
1139
-     */
1140
-    public function form_data_present_in($req_data = null)
1141
-    {
1142
-        if ($req_data === null) {
1143
-            $req_data = $_POST;
1144
-        }
1145
-        $checked_value = $this->find_form_data_for_this_section($req_data);
1146
-        if ($checked_value !== null) {
1147
-            return true;
1148
-        } else {
1149
-            return false;
1150
-        }
1151
-    }
1152
-
1153
-
1154
-
1155
-    /**
1156
-     * Overrides parent to add js data from validation and display strategies
1157
-     *
1158
-     * @param array $form_other_js_data
1159
-     * @return array
1160
-     */
1161
-    public function get_other_js_data($form_other_js_data = array())
1162
-    {
1163
-        $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1164
-        return $form_other_js_data;
1165
-    }
1166
-
1167
-
1168
-
1169
-    /**
1170
-     * Gets other JS data for localization from this input's strategies, like
1171
-     * the validation strategies and the display strategy
1172
-     *
1173
-     * @param array $form_other_js_data
1174
-     * @return array
1175
-     */
1176
-    public function get_other_js_data_from_strategies($form_other_js_data = array())
1177
-    {
1178
-        $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1179
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1180
-            $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1181
-        }
1182
-        return $form_other_js_data;
1183
-    }
1184
-
1185
-
1186
-
1187
-    /**
1188
-     * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1189
-     *
1190
-     * @return void
1191
-     */
1192
-    public function enqueue_js()
1193
-    {
1194
-        //ask our display strategy and validation strategies if they have js to enqueue
1195
-        $this->enqueue_js_from_strategies();
1196
-    }
1197
-
1198
-
1199
-
1200
-    /**
1201
-     * Tells strategies when its ok to enqueue their js and css
1202
-     *
1203
-     * @return void
1204
-     */
1205
-    public function enqueue_js_from_strategies()
1206
-    {
1207
-        $this->get_display_strategy()->enqueue_js();
1208
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1209
-            $validation_strategy->enqueue_js();
1210
-        }
1211
-    }
1212
-
1213
-
1214
-
1215
-    /**
1216
-     * Gets the default value set on the input (not the current value, which may have been
1217
-     * changed because of a form submission). If no default was set, this us null.
1218
-     * @return mixed
1219
-     */
1220
-    public function get_default()
1221
-    {
1222
-        return $this->_default;
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1229
-     * and server-side if any input was received it will be ignored
1230
-     */
1231
-    public function disable($disable = true)
1232
-    {
1233
-        $disabled_attribute = ' disabled="disabled"';
1234
-        $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1235
-        if($this->disabled) {
1236
-            if (strpos($this->_other_html_attributes,$disabled_attribute) === false){
1237
-                $this->_other_html_attributes .= $disabled_attribute;
1238
-            }
1239
-            $this->_set_normalized_value($this->get_default());
1240
-        } else {
1241
-            $this->_other_html_attributes = str_replace($disabled_attribute,'', $this->_other_html_attributes);
1242
-        }
1243
-
1244
-    }
1245
-
1246
-
1247
-
1248
-    /**
1249
-     * Returns whether or not this input is currently disabled.
1250
-     * @return bool
1251
-     */
1252
-    public function isDisabled()
1253
-    {
1254
-        return $this->disabled;
1255
-    }
19
+	/**
20
+	 * the input's name attribute
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_html_name;
25
+
26
+	/**
27
+	 * id for the html label tag
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $_html_label_id;
32
+
33
+	/**
34
+	 * class for teh html label tag
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $_html_label_class;
39
+
40
+	/**
41
+	 * any additional html attributes that you may want to add
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_html_other_attributes;
46
+
47
+	/**
48
+	 * style for teh html label tag
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_html_label_style;
53
+
54
+	/**
55
+	 * text to be placed in the html label
56
+	 *
57
+	 * @var string
58
+	 */
59
+	protected $_html_label_text;
60
+
61
+	/**
62
+	 * the full html label. If used, all other html_label_* properties are invalid
63
+	 *
64
+	 * @var string
65
+	 */
66
+	protected $_html_label;
67
+
68
+	/**
69
+	 * HTML to use for help text (normally placed below form input), in a span which normally
70
+	 * has a class of 'description'
71
+	 *
72
+	 * @var string
73
+	 */
74
+	protected $_html_help_text;
75
+
76
+	/**
77
+	 * CSS classes for displaying the help span
78
+	 *
79
+	 * @var string
80
+	 */
81
+	protected $_html_help_class = 'description';
82
+
83
+	/**
84
+	 * CSS to put in the style attribute on the help span
85
+	 *
86
+	 * @var string
87
+	 */
88
+	protected $_html_help_style;
89
+
90
+	/**
91
+	 * Stores whether or not this input's response is required.
92
+	 * Because certain styling elements may also want to know that this
93
+	 * input is required etc.
94
+	 *
95
+	 * @var boolean
96
+	 */
97
+	protected $_required;
98
+
99
+	/**
100
+	 * css class added to required inputs
101
+	 *
102
+	 * @var string
103
+	 */
104
+	protected $_required_css_class = 'ee-required';
105
+
106
+	/**
107
+	 * css styles applied to button type inputs
108
+	 *
109
+	 * @var string
110
+	 */
111
+	protected $_button_css_attributes;
112
+
113
+	/**
114
+	 * The raw data submitted for this, like in the $_POST super global.
115
+	 * Generally unsafe for usage in client code
116
+	 *
117
+	 * @var mixed string or array
118
+	 */
119
+	protected $_raw_value;
120
+
121
+	/**
122
+	 * Value normalized according to the input's normalization strategy.
123
+	 * The normalization strategy dictates whether this is a string, int, float,
124
+	 * boolean, or array of any of those.
125
+	 *
126
+	 * @var mixed
127
+	 */
128
+	protected $_normalized_value;
129
+
130
+
131
+	/**
132
+	 * Normalized default value either initially set on the input, or provided by calling
133
+	 * set_default().
134
+	 * @var mixed
135
+	 */
136
+	protected $_default;
137
+
138
+	/**
139
+	 * Strategy used for displaying this field.
140
+	 * Child classes must use _get_display_strategy to access it.
141
+	 *
142
+	 * @var EE_Display_Strategy_Base
143
+	 */
144
+	private $_display_strategy;
145
+
146
+	/**
147
+	 * Gets all the validation strategies used on this field
148
+	 *
149
+	 * @var EE_Validation_Strategy_Base[]
150
+	 */
151
+	private $_validation_strategies = array();
152
+
153
+	/**
154
+	 * The normalization strategy for this field
155
+	 *
156
+	 * @var EE_Normalization_Strategy_Base
157
+	 */
158
+	private $_normalization_strategy;
159
+
160
+	/**
161
+	 * Strategy for removing sensitive data after we're done with the form input
162
+	 *
163
+	 * @var EE_Sensitive_Data_Removal_Base
164
+	 */
165
+	protected $_sensitive_data_removal_strategy;
166
+
167
+	/**
168
+	 * Whether this input has been disabled or not.
169
+	 * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
170
+	 * (Client-side code that wants to dynamically disable it must also add this hidden input).
171
+	 * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored.
172
+	 * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored.
173
+	 *
174
+	 * @var boolean
175
+	 */
176
+	protected $disabled = false;
177
+
178
+
179
+
180
+	/**
181
+	 * @param array                         $input_args       {
182
+	 * @type string                         $html_name        the html name for the input
183
+	 * @type string                         $html_label_id    the id attribute to give to the html label tag
184
+	 * @type string                         $html_label_class the class attribute to give to the html label tag
185
+	 * @type string                         $html_label_style the style attribute to give ot teh label tag
186
+	 * @type string                         $html_label_text  the text to put in the label tag
187
+	 * @type string                         $html_label       the full html label. If used,
188
+	 *                                                        all other html_label_* args are invalid
189
+	 * @type string                         $html_help_text   text to put in help element
190
+	 * @type string                         $html_help_style  style attribute to give to teh help element
191
+	 * @type string                         $html_help_class  class attribute to give to the help element
192
+	 * @type string                         $default          default value NORMALIZED (eg, if providing the default
193
+	 *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
194
+	 * @type EE_Display_Strategy_Base       $display          strategy
195
+	 * @type EE_Normalization_Strategy_Base $normalization_strategy
196
+	 * @type EE_Validation_Strategy_Base[]  $validation_strategies
197
+	 * @type boolean                        $ignore_input special argument which can be used to avoid adding any validation strategies,
198
+	 *                                                    and sets the normalization strategy to the Null normalization. This is good
199
+	 *                                                    when you want the input to be totally ignored server-side (like when using
200
+	 *                                                    React.js form inputs)
201
+	 *                                                        }
202
+	 */
203
+	public function __construct($input_args = array())
204
+	{
205
+		$input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
206
+		// the following properties must be cast as arrays
207
+		if (isset($input_args['validation_strategies'])) {
208
+			foreach ((array)$input_args['validation_strategies'] as $validation_strategy) {
209
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
210
+					$this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
211
+				}
212
+			}
213
+			unset($input_args['validation_strategies']);
214
+		}
215
+		if(isset($input_args['ignore_input'])) {
216
+			$this->_validation_strategies = array();
217
+		}
218
+		// loop thru incoming options
219
+		foreach ($input_args as $key => $value) {
220
+			// add underscore to $key to match property names
221
+			$_key = '_' . $key;
222
+			if (property_exists($this, $_key)) {
223
+				$this->{$_key} = $value;
224
+			}
225
+		}
226
+		// ensure that "required" is set correctly
227
+		$this->set_required(
228
+			$this->_required, isset($input_args['required_validation_error_message'])
229
+			? $input_args['required_validation_error_message']
230
+			: null
231
+		);
232
+		//$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
233
+		$this->_display_strategy->_construct_finalize($this);
234
+		foreach ($this->_validation_strategies as $validation_strategy) {
235
+			$validation_strategy->_construct_finalize($this);
236
+		}
237
+		if (isset($input_args['ignore_input'])) {
238
+			$this->_normalization_strategy = new EE_Null_Normalization();
239
+		}
240
+		if (! $this->_normalization_strategy) {
241
+				$this->_normalization_strategy = new EE_Text_Normalization();
242
+		}
243
+		$this->_normalization_strategy->_construct_finalize($this);
244
+		//at least we can use the normalization strategy to populate the default
245
+		if (isset($input_args['default'])) {
246
+			$this->set_default($input_args['default']);
247
+			unset($input_args['default']);
248
+		}
249
+		if (! $this->_sensitive_data_removal_strategy) {
250
+			$this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
251
+		}
252
+		$this->_sensitive_data_removal_strategy->_construct_finalize($this);
253
+		parent::__construct($input_args);
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * Sets the html_name to its default value, if none was specified in teh constructor.
260
+	 * Calculation involves using the name and the parent's html_name
261
+	 *
262
+	 * @throws \EE_Error
263
+	 */
264
+	protected function _set_default_html_name_if_empty()
265
+	{
266
+		if (! $this->_html_name) {
267
+			$this->_html_name = $this->name();
268
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
269
+				$this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
270
+			}
271
+		}
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @param $parent_form_section
278
+	 * @param $name
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function _construct_finalize($parent_form_section, $name)
282
+	{
283
+		parent::_construct_finalize($parent_form_section, $name);
284
+		if ($this->_html_label === null && $this->_html_label_text === null) {
285
+			$this->_html_label_text = ucwords(str_replace("_", " ", $name));
286
+		}
287
+		do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * Returns the strategy for displaying this form input. If none is set, throws an exception.
294
+	 *
295
+	 * @return EE_Display_Strategy_Base
296
+	 * @throws EE_Error
297
+	 */
298
+	protected function _get_display_strategy()
299
+	{
300
+		$this->ensure_construct_finalized_called();
301
+		if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
302
+			throw new EE_Error(
303
+				sprintf(
304
+					__(
305
+						"Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
306
+						"event_espresso"
307
+					),
308
+					$this->html_name(),
309
+					$this->html_id()
310
+				)
311
+			);
312
+		} else {
313
+			return $this->_display_strategy;
314
+		}
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * Sets the display strategy.
321
+	 *
322
+	 * @param EE_Display_Strategy_Base $strategy
323
+	 */
324
+	protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
325
+	{
326
+		$this->_display_strategy = $strategy;
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 * Sets the sanitization strategy
333
+	 *
334
+	 * @param EE_Normalization_Strategy_Base $strategy
335
+	 */
336
+	protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
337
+	{
338
+		$this->_normalization_strategy = $strategy;
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * Gets sensitive_data_removal_strategy
345
+	 *
346
+	 * @return EE_Sensitive_Data_Removal_Base
347
+	 */
348
+	public function get_sensitive_data_removal_strategy()
349
+	{
350
+		return $this->_sensitive_data_removal_strategy;
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * Sets sensitive_data_removal_strategy
357
+	 *
358
+	 * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
359
+	 * @return boolean
360
+	 */
361
+	public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
362
+	{
363
+		$this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * Gets the display strategy for this input
370
+	 *
371
+	 * @return EE_Display_Strategy_Base
372
+	 */
373
+	public function get_display_strategy()
374
+	{
375
+		return $this->_display_strategy;
376
+	}
377
+
378
+
379
+
380
+	/**
381
+	 * Overwrites the display strategy
382
+	 *
383
+	 * @param EE_Display_Strategy_Base $display_strategy
384
+	 */
385
+	public function set_display_strategy($display_strategy)
386
+	{
387
+		$this->_display_strategy = $display_strategy;
388
+		$this->_display_strategy->_construct_finalize($this);
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * Gets the normalization strategy set on this input
395
+	 *
396
+	 * @return EE_Normalization_Strategy_Base
397
+	 */
398
+	public function get_normalization_strategy()
399
+	{
400
+		return $this->_normalization_strategy;
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * Overwrites the normalization strategy
407
+	 *
408
+	 * @param EE_Normalization_Strategy_Base $normalization_strategy
409
+	 */
410
+	public function set_normalization_strategy($normalization_strategy)
411
+	{
412
+		$this->_normalization_strategy = $normalization_strategy;
413
+		$this->_normalization_strategy->_construct_finalize($this);
414
+	}
415
+
416
+
417
+
418
+	/**
419
+	 * Returns all teh validation strategies which apply to this field, numerically indexed
420
+	 *
421
+	 * @return EE_Validation_Strategy_Base[]
422
+	 */
423
+	public function get_validation_strategies()
424
+	{
425
+		return $this->_validation_strategies;
426
+	}
427
+
428
+
429
+
430
+	/**
431
+	 * Adds this strategy to the field so it will be used in both JS validation and server-side validation
432
+	 *
433
+	 * @param EE_Validation_Strategy_Base $validation_strategy
434
+	 * @return void
435
+	 */
436
+	protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
437
+	{
438
+		$validation_strategy->_construct_finalize($this);
439
+		$this->_validation_strategies[] = $validation_strategy;
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 * Adds a new validation strategy onto the form input
446
+	 *
447
+	 * @param EE_Validation_Strategy_Base $validation_strategy
448
+	 * @return void
449
+	 */
450
+	public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
451
+	{
452
+		$this->_add_validation_strategy($validation_strategy);
453
+	}
454
+
455
+
456
+
457
+	/**
458
+	 * The classname of the validation strategy to remove
459
+	 *
460
+	 * @param string $validation_strategy_classname
461
+	 */
462
+	public function remove_validation_strategy($validation_strategy_classname)
463
+	{
464
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
465
+			if (
466
+				$validation_strategy instanceof $validation_strategy_classname
467
+				|| is_subclass_of($validation_strategy, $validation_strategy_classname)
468
+			) {
469
+				unset($this->_validation_strategies[$key]);
470
+			}
471
+		}
472
+	}
473
+
474
+
475
+
476
+	/**
477
+	 * returns true if input employs any of the validation strategy defined by the supplied array of classnames
478
+	 *
479
+	 * @param array $validation_strategy_classnames
480
+	 * @return bool
481
+	 */
482
+	public function has_validation_strategy($validation_strategy_classnames)
483
+	{
484
+		$validation_strategy_classnames = is_array($validation_strategy_classnames)
485
+			? $validation_strategy_classnames
486
+			: array($validation_strategy_classnames);
487
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
488
+			if (in_array($key, $validation_strategy_classnames)) {
489
+				return true;
490
+			}
491
+		}
492
+		return false;
493
+	}
494
+
495
+
496
+
497
+	/**
498
+	 * Gets the HTML
499
+	 *
500
+	 * @return string
501
+	 */
502
+	public function get_html()
503
+	{
504
+		return $this->_parent_section->get_html_for_input($this);
505
+	}
506
+
507
+
508
+
509
+	/**
510
+	 * Gets the HTML for the input itself (no label or errors) according to the
511
+	 * input's display strategy
512
+	 * Makes sure the JS and CSS are enqueued for it
513
+	 *
514
+	 * @return string
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function get_html_for_input()
518
+	{
519
+		return $this->_form_html_filter
520
+			? $this->_form_html_filter->filterHtml(
521
+				$this->_get_display_strategy()->display(),
522
+				$this
523
+			)
524
+			: $this->_get_display_strategy()->display();
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * @return string
531
+	 */
532
+	public function html_other_attributes()
533
+	{
534
+		return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : '';
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * @param string $html_other_attributes
541
+	 */
542
+	public function set_html_other_attributes($html_other_attributes)
543
+	{
544
+		$this->_html_other_attributes = $html_other_attributes;
545
+	}
546
+
547
+
548
+
549
+	/**
550
+	 * Gets the HTML for displaying the label for this form input
551
+	 * according to the form section's layout strategy
552
+	 *
553
+	 * @return string
554
+	 */
555
+	public function get_html_for_label()
556
+	{
557
+		return $this->_parent_section->get_layout_strategy()->display_label($this);
558
+	}
559
+
560
+
561
+
562
+	/**
563
+	 * Gets the HTML for displaying the errors section for this form input
564
+	 * according to the form section's layout strategy
565
+	 *
566
+	 * @return string
567
+	 */
568
+	public function get_html_for_errors()
569
+	{
570
+		return $this->_parent_section->get_layout_strategy()->display_errors($this);
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * Gets the HTML for displaying the help text for this form input
577
+	 * according to the form section's layout strategy
578
+	 *
579
+	 * @return string
580
+	 */
581
+	public function get_html_for_help()
582
+	{
583
+		return $this->_parent_section->get_layout_strategy()->display_help_text($this);
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * Validates the input's sanitized value (assumes _sanitize() has already been called)
590
+	 * and returns whether or not the form input's submitted value is value
591
+	 *
592
+	 * @return boolean
593
+	 */
594
+	protected function _validate()
595
+	{
596
+		if ($this->isDisabled()) {
597
+			return true;
598
+		}
599
+		foreach ($this->_validation_strategies as $validation_strategy) {
600
+			if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
601
+				try {
602
+					$validation_strategy->validate($this->normalized_value());
603
+				} catch (EE_Validation_Error $e) {
604
+					$this->add_validation_error($e);
605
+				}
606
+			}
607
+		}
608
+		if ($this->get_validation_errors()) {
609
+			return false;
610
+		} else {
611
+			return true;
612
+		}
613
+	}
614
+
615
+
616
+
617
+	/**
618
+	 * Performs basic sanitization on this value. But what sanitization can be performed anyways?
619
+	 * This value MIGHT be allowed to have tags, so we can't really remove them.
620
+	 *
621
+	 * @param string $value
622
+	 * @return null|string
623
+	 */
624
+	private function _sanitize($value)
625
+	{
626
+		return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
627
+	}
628
+
629
+
630
+
631
+	/**
632
+	 * Picks out the form value that relates to this form input,
633
+	 * and stores it as the sanitized value on the form input, and sets the normalized value.
634
+	 * Returns whether or not any validation errors occurred
635
+	 *
636
+	 * @param array $req_data like $_POST
637
+	 * @return boolean whether or not there was an error
638
+	 * @throws \EE_Error
639
+	 */
640
+	protected function _normalize($req_data)
641
+	{
642
+		//any existing validation errors don't apply so clear them
643
+		$this->_validation_errors = array();
644
+		//if the input is disabled, ignore whatever input was sent in
645
+		if($this->isDisabled()) {
646
+			$this->_set_raw_value(null);
647
+			$this->_set_normalized_value($this->get_default());
648
+			return false;
649
+		}
650
+		try {
651
+			$raw_input = $this->find_form_data_for_this_section($req_data);
652
+			//super simple sanitization for now
653
+			if (is_array($raw_input)) {
654
+				$raw_value = array();
655
+				foreach ($raw_input as $key => $value) {
656
+					$raw_value[$key] = $this->_sanitize($value);
657
+				}
658
+				$this->_set_raw_value($raw_value);
659
+			} else {
660
+				$this->_set_raw_value($this->_sanitize($raw_input));
661
+			}
662
+			//we want to mostly leave the input alone in case we need to re-display it to the user
663
+			$this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
664
+			return false;
665
+		} catch (EE_Validation_Error $e) {
666
+			$this->add_validation_error($e);
667
+			return true;
668
+		}
669
+	}
670
+
671
+
672
+
673
+	/**
674
+	 * @return string
675
+	 */
676
+	public function html_name()
677
+	{
678
+		$this->_set_default_html_name_if_empty();
679
+		return $this->_html_name;
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * @return string
686
+	 */
687
+	public function html_label_id()
688
+	{
689
+		return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * @return string
696
+	 */
697
+	public function html_label_class()
698
+	{
699
+		return $this->_html_label_class;
700
+	}
701
+
702
+
703
+
704
+	/**
705
+	 * @return string
706
+	 */
707
+	public function html_label_style()
708
+	{
709
+		return $this->_html_label_style;
710
+	}
711
+
712
+
713
+
714
+	/**
715
+	 * @return string
716
+	 */
717
+	public function html_label_text()
718
+	{
719
+		return $this->_html_label_text;
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 * @return string
726
+	 */
727
+	public function html_help_text()
728
+	{
729
+		return $this->_html_help_text;
730
+	}
731
+
732
+
733
+
734
+	/**
735
+	 * @return string
736
+	 */
737
+	public function html_help_class()
738
+	{
739
+		return $this->_html_help_class;
740
+	}
741
+
742
+
743
+
744
+	/**
745
+	 * @return string
746
+	 */
747
+	public function html_help_style()
748
+	{
749
+		return $this->_html_style;
750
+	}
751
+
752
+
753
+
754
+	/**
755
+	 * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
756
+	 * Please note that almost all client code should instead use the normalized_value;
757
+	 * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
758
+	 * mostly by escaping quotes)
759
+	 * Note, we do not store the exact original value sent in the user's request because
760
+	 * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
761
+	 * in which case, we would have stored the malicious content to our database.
762
+	 *
763
+	 * @return string
764
+	 */
765
+	public function raw_value()
766
+	{
767
+		return $this->_raw_value;
768
+	}
769
+
770
+
771
+
772
+	/**
773
+	 * Returns a string safe to usage in form inputs when displaying, because
774
+	 * it escapes all html entities
775
+	 *
776
+	 * @return string
777
+	 */
778
+	public function raw_value_in_form()
779
+	{
780
+		return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
781
+	}
782
+
783
+
784
+
785
+	/**
786
+	 * returns the value after it's been sanitized, and then converted into it's proper type
787
+	 * in PHP. Eg, a string, an int, an array,
788
+	 *
789
+	 * @return mixed
790
+	 */
791
+	public function normalized_value()
792
+	{
793
+		return $this->_normalized_value;
794
+	}
795
+
796
+
797
+
798
+	/**
799
+	 * Returns the normalized value is a presentable way. By default this is just
800
+	 * the normalized value by itself, but it can be overridden for when that's not
801
+	 * the best thing to display
802
+	 *
803
+	 * @return string
804
+	 */
805
+	public function pretty_value()
806
+	{
807
+		return $this->_normalized_value;
808
+	}
809
+
810
+
811
+
812
+	/**
813
+	 * When generating the JS for the jquery validation rules like<br>
814
+	 * <code>$( "#myform" ).validate({
815
+	 * rules: {
816
+	 * password: "required",
817
+	 * password_again: {
818
+	 * equalTo: "#password"
819
+	 * }
820
+	 * }
821
+	 * });</code>
822
+	 * if this field had the name 'password_again', it should return
823
+	 * <br><code>password_again: {
824
+	 * equalTo: "#password"
825
+	 * }</code>
826
+	 *
827
+	 * @return array
828
+	 */
829
+	public function get_jquery_validation_rules()
830
+	{
831
+		$jquery_validation_js = array();
832
+		$jquery_validation_rules = array();
833
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
834
+			$jquery_validation_rules = array_replace_recursive(
835
+				$jquery_validation_rules,
836
+				$validation_strategy->get_jquery_validation_rule_array()
837
+			);
838
+		}
839
+		if (! empty($jquery_validation_rules)) {
840
+			foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
841
+				$jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
842
+			}
843
+		}
844
+		return $jquery_validation_js;
845
+	}
846
+
847
+
848
+
849
+	/**
850
+	 * Sets the input's default value for use in displaying in the form. Note: value should be
851
+	 * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
852
+	 *
853
+	 * @param mixed $value
854
+	 * @return void
855
+	 */
856
+	public function set_default($value)
857
+	{
858
+		$this->_default = $value;
859
+		$this->_set_normalized_value($value);
860
+		$this->_set_raw_value($value);
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * Sets the normalized value on this input
867
+	 *
868
+	 * @param mixed $value
869
+	 */
870
+	protected function _set_normalized_value($value)
871
+	{
872
+		$this->_normalized_value = $value;
873
+	}
874
+
875
+
876
+
877
+	/**
878
+	 * Sets the raw value on this input (ie, exactly as the user submitted it)
879
+	 *
880
+	 * @param mixed $value
881
+	 */
882
+	protected function _set_raw_value($value)
883
+	{
884
+		$this->_raw_value = $this->_normalization_strategy->unnormalize($value);
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * Sets the HTML label text after it has already been defined
891
+	 *
892
+	 * @param string $label
893
+	 * @return void
894
+	 */
895
+	public function set_html_label_text($label)
896
+	{
897
+		$this->_html_label_text = $label;
898
+	}
899
+
900
+
901
+
902
+	/**
903
+	 * Sets whether or not this field is required, and adjusts the validation strategy.
904
+	 * If you want to use the EE_Conditionally_Required_Validation_Strategy,
905
+	 * please add it as a validation strategy using add_validation_strategy as normal
906
+	 *
907
+	 * @param boolean $required boolean
908
+	 * @param null    $required_text
909
+	 */
910
+	public function set_required($required = true, $required_text = null)
911
+	{
912
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
913
+		//whether $required is a string or a boolean, we want to add a required validation strategy
914
+		if ($required) {
915
+			$this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
916
+		} else {
917
+			$this->remove_validation_strategy('EE_Required_Validation_Strategy');
918
+		}
919
+		$this->_required = $required;
920
+	}
921
+
922
+
923
+
924
+	/**
925
+	 * Returns whether or not this field is required
926
+	 *
927
+	 * @return boolean
928
+	 */
929
+	public function required()
930
+	{
931
+		return $this->_required;
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * @param string $required_css_class
938
+	 */
939
+	public function set_required_css_class($required_css_class)
940
+	{
941
+		$this->_required_css_class = $required_css_class;
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * @return string
948
+	 */
949
+	public function required_css_class()
950
+	{
951
+		return $this->_required_css_class;
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * @param bool $add_required
958
+	 * @return string
959
+	 */
960
+	public function html_class($add_required = false)
961
+	{
962
+		return $add_required && $this->required()
963
+			? $this->required_css_class() . ' ' . $this->_html_class
964
+			: $this->_html_class;
965
+	}
966
+
967
+
968
+	/**
969
+	 * Sets the help text, in case
970
+	 *
971
+	 * @param string $text
972
+	 */
973
+	public function set_html_help_text($text)
974
+	{
975
+		$this->_html_help_text = $text;
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * Uses the sensitive data removal strategy to remove the sensitive data from this
982
+	 * input. If there is any kind of sensitive data removal on this input, we clear
983
+	 * out the raw value completely
984
+	 *
985
+	 * @return void
986
+	 */
987
+	public function clean_sensitive_data()
988
+	{
989
+		//if we do ANY kind of sensitive data removal on this, then just clear out the raw value
990
+		//if we need more logic than this we'll make a strategy for it
991
+		if ($this->_sensitive_data_removal_strategy
992
+			&& ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
993
+		) {
994
+			$this->_set_raw_value(null);
995
+		}
996
+		//and clean the normalized value according to the appropriate strategy
997
+		$this->_set_normalized_value(
998
+			$this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
999
+				$this->_normalized_value
1000
+			)
1001
+		);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * @param bool   $primary
1008
+	 * @param string $button_size
1009
+	 * @param string $other_attributes
1010
+	 */
1011
+	public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1012
+	{
1013
+		$button_css_attributes = 'button';
1014
+		$button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
1015
+		switch ($button_size) {
1016
+			case 'xs' :
1017
+			case 'extra-small' :
1018
+				$button_css_attributes .= ' button-xs';
1019
+				break;
1020
+			case 'sm' :
1021
+			case 'small' :
1022
+				$button_css_attributes .= ' button-sm';
1023
+				break;
1024
+			case 'lg' :
1025
+			case 'large' :
1026
+				$button_css_attributes .= ' button-lg';
1027
+				break;
1028
+			case 'block' :
1029
+				$button_css_attributes .= ' button-block';
1030
+				break;
1031
+			case 'md' :
1032
+			case 'medium' :
1033
+			default :
1034
+				$button_css_attributes .= '';
1035
+		}
1036
+		$this->_button_css_attributes .= ! empty($other_attributes)
1037
+			? $button_css_attributes . ' ' . $other_attributes
1038
+			: $button_css_attributes;
1039
+	}
1040
+
1041
+
1042
+
1043
+	/**
1044
+	 * @return string
1045
+	 */
1046
+	public function button_css_attributes()
1047
+	{
1048
+		if (empty($this->_button_css_attributes)) {
1049
+			$this->set_button_css_attributes();
1050
+		}
1051
+		return $this->_button_css_attributes;
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 * find_form_data_for_this_section
1058
+	 * using this section's name and its parents, finds the value of the form data that corresponds to it.
1059
+	 * For example, if this form section's HTML name is my_form[subform][form_input_1],
1060
+	 * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1061
+	 * (If that doesn't exist, we also check for this subsection's name
1062
+	 * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1063
+	 * This function finds its value in the form.
1064
+	 *
1065
+	 * @param array $req_data
1066
+	 * @return mixed whatever the raw value of this form section is in the request data
1067
+	 * @throws \EE_Error
1068
+	 */
1069
+	public function find_form_data_for_this_section($req_data)
1070
+	{
1071
+		$name_parts = $this->getInputNameParts();
1072
+		// now get the value for the input
1073
+		$value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1074
+		// check if this thing's name is at the TOP level of the request data
1075
+		if ($value === null && isset($req_data[$this->name()])) {
1076
+			$value = $req_data[$this->name()];
1077
+		}
1078
+		return $value;
1079
+	}
1080
+
1081
+
1082
+
1083
+	/**
1084
+	 * If this input's name is something like "foo[bar][baz]"
1085
+	 * returns an array like `array('foo','bar',baz')`
1086
+	 * @return array
1087
+	 */
1088
+	protected function getInputNameParts()
1089
+	{
1090
+		// break up the html name by "[]"
1091
+		if (strpos($this->html_name(), '[') !== false) {
1092
+			$before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1093
+		} else {
1094
+			$before_any_brackets = $this->html_name();
1095
+		}
1096
+		// grab all of the segments
1097
+		preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1098
+		if (isset($matches[1]) && is_array($matches[1])) {
1099
+			$name_parts = $matches[1];
1100
+			array_unshift($name_parts, $before_any_brackets);
1101
+		} else {
1102
+			$name_parts = array($before_any_brackets);
1103
+		}
1104
+		return $name_parts;
1105
+	}
1106
+
1107
+
1108
+
1109
+	/**
1110
+	 * @param array $html_name_parts
1111
+	 * @param array $req_data
1112
+	 * @return array | NULL
1113
+	 */
1114
+	public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1115
+	{
1116
+		$first_part_to_consider = array_shift($html_name_parts);
1117
+		if (isset($req_data[$first_part_to_consider])) {
1118
+			if (empty($html_name_parts)) {
1119
+				return $req_data[$first_part_to_consider];
1120
+			} else {
1121
+				return $this->findRequestForSectionUsingNameParts(
1122
+					$html_name_parts,
1123
+					$req_data[$first_part_to_consider]
1124
+				);
1125
+			}
1126
+		} else {
1127
+			return null;
1128
+		}
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 * Checks if this form input's data is in the request data
1135
+	 *
1136
+	 * @param array $req_data like $_POST
1137
+	 * @return boolean
1138
+	 * @throws \EE_Error
1139
+	 */
1140
+	public function form_data_present_in($req_data = null)
1141
+	{
1142
+		if ($req_data === null) {
1143
+			$req_data = $_POST;
1144
+		}
1145
+		$checked_value = $this->find_form_data_for_this_section($req_data);
1146
+		if ($checked_value !== null) {
1147
+			return true;
1148
+		} else {
1149
+			return false;
1150
+		}
1151
+	}
1152
+
1153
+
1154
+
1155
+	/**
1156
+	 * Overrides parent to add js data from validation and display strategies
1157
+	 *
1158
+	 * @param array $form_other_js_data
1159
+	 * @return array
1160
+	 */
1161
+	public function get_other_js_data($form_other_js_data = array())
1162
+	{
1163
+		$form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1164
+		return $form_other_js_data;
1165
+	}
1166
+
1167
+
1168
+
1169
+	/**
1170
+	 * Gets other JS data for localization from this input's strategies, like
1171
+	 * the validation strategies and the display strategy
1172
+	 *
1173
+	 * @param array $form_other_js_data
1174
+	 * @return array
1175
+	 */
1176
+	public function get_other_js_data_from_strategies($form_other_js_data = array())
1177
+	{
1178
+		$form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1179
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1180
+			$form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1181
+		}
1182
+		return $form_other_js_data;
1183
+	}
1184
+
1185
+
1186
+
1187
+	/**
1188
+	 * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1189
+	 *
1190
+	 * @return void
1191
+	 */
1192
+	public function enqueue_js()
1193
+	{
1194
+		//ask our display strategy and validation strategies if they have js to enqueue
1195
+		$this->enqueue_js_from_strategies();
1196
+	}
1197
+
1198
+
1199
+
1200
+	/**
1201
+	 * Tells strategies when its ok to enqueue their js and css
1202
+	 *
1203
+	 * @return void
1204
+	 */
1205
+	public function enqueue_js_from_strategies()
1206
+	{
1207
+		$this->get_display_strategy()->enqueue_js();
1208
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1209
+			$validation_strategy->enqueue_js();
1210
+		}
1211
+	}
1212
+
1213
+
1214
+
1215
+	/**
1216
+	 * Gets the default value set on the input (not the current value, which may have been
1217
+	 * changed because of a form submission). If no default was set, this us null.
1218
+	 * @return mixed
1219
+	 */
1220
+	public function get_default()
1221
+	{
1222
+		return $this->_default;
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1229
+	 * and server-side if any input was received it will be ignored
1230
+	 */
1231
+	public function disable($disable = true)
1232
+	{
1233
+		$disabled_attribute = ' disabled="disabled"';
1234
+		$this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1235
+		if($this->disabled) {
1236
+			if (strpos($this->_other_html_attributes,$disabled_attribute) === false){
1237
+				$this->_other_html_attributes .= $disabled_attribute;
1238
+			}
1239
+			$this->_set_normalized_value($this->get_default());
1240
+		} else {
1241
+			$this->_other_html_attributes = str_replace($disabled_attribute,'', $this->_other_html_attributes);
1242
+		}
1243
+
1244
+	}
1245
+
1246
+
1247
+
1248
+	/**
1249
+	 * Returns whether or not this input is currently disabled.
1250
+	 * @return bool
1251
+	 */
1252
+	public function isDisabled()
1253
+	{
1254
+		return $this->disabled;
1255
+	}
1256 1256
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -202,23 +202,23 @@  discard block
 block discarded – undo
202 202
      */
203 203
     public function __construct($input_args = array())
204 204
     {
205
-        $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
205
+        $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
206 206
         // the following properties must be cast as arrays
207 207
         if (isset($input_args['validation_strategies'])) {
208
-            foreach ((array)$input_args['validation_strategies'] as $validation_strategy) {
208
+            foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
209 209
                 if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
210 210
                     $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
211 211
                 }
212 212
             }
213 213
             unset($input_args['validation_strategies']);
214 214
         }
215
-        if(isset($input_args['ignore_input'])) {
215
+        if (isset($input_args['ignore_input'])) {
216 216
             $this->_validation_strategies = array();
217 217
         }
218 218
         // loop thru incoming options
219 219
         foreach ($input_args as $key => $value) {
220 220
             // add underscore to $key to match property names
221
-            $_key = '_' . $key;
221
+            $_key = '_'.$key;
222 222
             if (property_exists($this, $_key)) {
223 223
                 $this->{$_key} = $value;
224 224
             }
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
         if (isset($input_args['ignore_input'])) {
238 238
             $this->_normalization_strategy = new EE_Null_Normalization();
239 239
         }
240
-        if (! $this->_normalization_strategy) {
240
+        if ( ! $this->_normalization_strategy) {
241 241
                 $this->_normalization_strategy = new EE_Text_Normalization();
242 242
         }
243 243
         $this->_normalization_strategy->_construct_finalize($this);
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
             $this->set_default($input_args['default']);
247 247
             unset($input_args['default']);
248 248
         }
249
-        if (! $this->_sensitive_data_removal_strategy) {
249
+        if ( ! $this->_sensitive_data_removal_strategy) {
250 250
             $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
251 251
         }
252 252
         $this->_sensitive_data_removal_strategy->_construct_finalize($this);
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
      */
264 264
     protected function _set_default_html_name_if_empty()
265 265
     {
266
-        if (! $this->_html_name) {
266
+        if ( ! $this->_html_name) {
267 267
             $this->_html_name = $this->name();
268 268
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
269
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
269
+                $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]";
270 270
             }
271 271
         }
272 272
     }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     protected function _get_display_strategy()
299 299
     {
300 300
         $this->ensure_construct_finalized_called();
301
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
301
+        if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
302 302
             throw new EE_Error(
303 303
                 sprintf(
304 304
                     __(
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      */
532 532
     public function html_other_attributes()
533 533
     {
534
-        return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : '';
534
+        return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : '';
535 535
     }
536 536
 
537 537
 
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
         //any existing validation errors don't apply so clear them
643 643
         $this->_validation_errors = array();
644 644
         //if the input is disabled, ignore whatever input was sent in
645
-        if($this->isDisabled()) {
645
+        if ($this->isDisabled()) {
646 646
             $this->_set_raw_value(null);
647 647
             $this->_set_normalized_value($this->get_default());
648 648
             return false;
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
      */
687 687
     public function html_label_id()
688 688
     {
689
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
689
+        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl';
690 690
     }
691 691
 
692 692
 
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
                 $validation_strategy->get_jquery_validation_rule_array()
837 837
             );
838 838
         }
839
-        if (! empty($jquery_validation_rules)) {
839
+        if ( ! empty($jquery_validation_rules)) {
840 840
             foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
841 841
                 $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
842 842
             }
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
     public function html_class($add_required = false)
961 961
     {
962 962
         return $add_required && $this->required()
963
-            ? $this->required_css_class() . ' ' . $this->_html_class
963
+            ? $this->required_css_class().' '.$this->_html_class
964 964
             : $this->_html_class;
965 965
     }
966 966
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
                 $button_css_attributes .= '';
1035 1035
         }
1036 1036
         $this->_button_css_attributes .= ! empty($other_attributes)
1037
-            ? $button_css_attributes . ' ' . $other_attributes
1037
+            ? $button_css_attributes.' '.$other_attributes
1038 1038
             : $button_css_attributes;
1039 1039
     }
1040 1040
 
@@ -1232,13 +1232,13 @@  discard block
 block discarded – undo
1232 1232
     {
1233 1233
         $disabled_attribute = ' disabled="disabled"';
1234 1234
         $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1235
-        if($this->disabled) {
1236
-            if (strpos($this->_other_html_attributes,$disabled_attribute) === false){
1235
+        if ($this->disabled) {
1236
+            if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1237 1237
                 $this->_other_html_attributes .= $disabled_attribute;
1238 1238
             }
1239 1239
             $this->_set_normalized_value($this->get_default());
1240 1240
         } else {
1241
-            $this->_other_html_attributes = str_replace($disabled_attribute,'', $this->_other_html_attributes);
1241
+            $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1242 1242
         }
1243 1243
 
1244 1244
     }
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3092 added lines, -3092 removed lines patch added patch discarded remove patch
@@ -17,2474 +17,2474 @@  discard block
 block discarded – undo
17 17
 final class EE_Config implements ResettableInterface
18 18
 {
19 19
 
20
-    const OPTION_NAME        = 'ee_config';
20
+	const OPTION_NAME        = 'ee_config';
21
+
22
+	const LOG_NAME           = 'ee_config_log';
23
+
24
+	const LOG_LENGTH         = 100;
25
+
26
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
+
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+
146
+	/**
147
+	 * @singleton method used to instantiate class object
148
+	 * @access    public
149
+	 * @return EE_Config instance
150
+	 */
151
+	public static function instance()
152
+	{
153
+		// check if class object is instantiated, and instantiated properly
154
+		if (! self::$_instance instanceof EE_Config) {
155
+			self::$_instance = new self();
156
+		}
157
+		return self::$_instance;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Resets the config
164
+	 *
165
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
+	 *                               reflect its state in the database
168
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
+	 *                               site was put into maintenance mode)
172
+	 * @return EE_Config
173
+	 */
174
+	public static function reset($hard_reset = false, $reinstantiate = true)
175
+	{
176
+		if (self::$_instance instanceof EE_Config) {
177
+			if ($hard_reset) {
178
+				self::$_instance->legacy_shortcodes_manager = null;
179
+				self::$_instance->_addon_option_names = array();
180
+				self::$_instance->_initialize_config();
181
+				self::$_instance->update_espresso_config();
182
+			}
183
+			self::$_instance->update_addon_option_names();
184
+		}
185
+		self::$_instance = null;
186
+		//we don't need to reset the static properties imo because those should
187
+		//only change when a module is added or removed. Currently we don't
188
+		//support removing a module during a request when it previously existed
189
+		if ($reinstantiate) {
190
+			return self::instance();
191
+		} else {
192
+			return null;
193
+		}
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 *    class constructor
200
+	 *
201
+	 * @access    private
202
+	 */
203
+	private function __construct()
204
+	{
205
+		do_action('AHEE__EE_Config__construct__begin', $this);
206
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
+		// setup empty config classes
208
+		$this->_initialize_config();
209
+		// load existing EE site settings
210
+		$this->_load_core_config();
211
+		// confirm everything loaded correctly and set filtered defaults if not
212
+		$this->_verify_config();
213
+		//  register shortcodes and modules
214
+		add_action(
215
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
+			array($this, 'register_shortcodes_and_modules'),
217
+			999
218
+		);
219
+		//  initialize shortcodes and modules
220
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
+		// register widgets
222
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
223
+		// shutdown
224
+		add_action('shutdown', array($this, 'shutdown'), 10);
225
+		// construct__end hook
226
+		do_action('AHEE__EE_Config__construct__end', $this);
227
+		// hardcoded hack
228
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 */
236
+	public static function logging_enabled()
237
+	{
238
+		return self::$_logging_enabled;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * use to get the current theme if needed from static context
245
+	 *
246
+	 * @return string current theme set.
247
+	 */
248
+	public static function get_current_theme()
249
+	{
250
+		return isset(self::$_instance->template_settings->current_espresso_theme)
251
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *        _initialize_config
258
+	 *
259
+	 * @access private
260
+	 * @return void
261
+	 */
262
+	private function _initialize_config()
263
+	{
264
+		EE_Config::trim_log();
265
+		//set defaults
266
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
+		$this->addons = new stdClass();
268
+		// set _module_route_map
269
+		EE_Config::$_module_route_map = array();
270
+		// set _module_forward_map
271
+		EE_Config::$_module_forward_map = array();
272
+		// set _module_view_map
273
+		EE_Config::$_module_view_map = array();
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 *        load core plugin configuration
280
+	 *
281
+	 * @access private
282
+	 * @return void
283
+	 */
284
+	private function _load_core_config()
285
+	{
286
+		// load_core_config__start hook
287
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
288
+		$espresso_config = $this->get_espresso_config();
289
+		foreach ($espresso_config as $config => $settings) {
290
+			// load_core_config__start hook
291
+			$settings = apply_filters(
292
+				'FHEE__EE_Config___load_core_config__config_settings',
293
+				$settings,
294
+				$config,
295
+				$this
296
+			);
297
+			if (is_object($settings) && property_exists($this, $config)) {
298
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
+				//call configs populate method to ensure any defaults are set for empty values.
300
+				if (method_exists($settings, 'populate')) {
301
+					$this->{$config}->populate();
302
+				}
303
+				if (method_exists($settings, 'do_hooks')) {
304
+					$this->{$config}->do_hooks();
305
+				}
306
+			}
307
+		}
308
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
+			$this->update_espresso_config();
310
+		}
311
+		// load_core_config__end hook
312
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 *    _verify_config
319
+	 *
320
+	 * @access    protected
321
+	 * @return    void
322
+	 */
323
+	protected function _verify_config()
324
+	{
325
+		$this->core = $this->core instanceof EE_Core_Config
326
+			? $this->core
327
+			: new EE_Core_Config();
328
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
+		$this->organization = $this->organization instanceof EE_Organization_Config
330
+			? $this->organization
331
+			: new EE_Organization_Config();
332
+		$this->organization = apply_filters(
333
+			'FHEE__EE_Config___initialize_config__organization',
334
+			$this->organization
335
+		);
336
+		$this->currency = $this->currency instanceof EE_Currency_Config
337
+			? $this->currency
338
+			: new EE_Currency_Config();
339
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
+		$this->registration = $this->registration instanceof EE_Registration_Config
341
+			? $this->registration
342
+			: new EE_Registration_Config();
343
+		$this->registration = apply_filters(
344
+			'FHEE__EE_Config___initialize_config__registration',
345
+			$this->registration
346
+		);
347
+		$this->admin = $this->admin instanceof EE_Admin_Config
348
+			? $this->admin
349
+			: new EE_Admin_Config();
350
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
352
+			? $this->template_settings
353
+			: new EE_Template_Config();
354
+		$this->template_settings = apply_filters(
355
+			'FHEE__EE_Config___initialize_config__template_settings',
356
+			$this->template_settings
357
+		);
358
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
359
+			? $this->map_settings
360
+			: new EE_Map_Config();
361
+		$this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
+			$this->map_settings);
363
+		$this->environment = $this->environment instanceof EE_Environment_Config
364
+			? $this->environment
365
+			: new EE_Environment_Config();
366
+		$this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
+			$this->environment);
368
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
+			? $this->tax_settings
370
+			: new EE_Tax_Config();
371
+		$this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
+			$this->tax_settings);
373
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
+		$this->messages = $this->messages instanceof EE_Messages_Config
375
+			? $this->messages
376
+			: new EE_Messages_Config();
377
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
378
+			? $this->gateway
379
+			: new EE_Gateway_Config();
380
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
+		$this->legacy_shortcodes_manager = null;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    get_espresso_config
387
+	 *
388
+	 * @access    public
389
+	 * @return    array of espresso config stuff
390
+	 */
391
+	public function get_espresso_config()
392
+	{
393
+		// grab espresso configuration
394
+		return apply_filters(
395
+			'FHEE__EE_Config__get_espresso_config__CFG',
396
+			get_option(EE_Config::OPTION_NAME, array())
397
+		);
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 *    double_check_config_comparison
404
+	 *
405
+	 * @access    public
406
+	 * @param string $option
407
+	 * @param        $old_value
408
+	 * @param        $value
409
+	 */
410
+	public function double_check_config_comparison($option = '', $old_value, $value)
411
+	{
412
+		// make sure we're checking the ee config
413
+		if ($option === EE_Config::OPTION_NAME) {
414
+			// run a loose comparison of the old value against the new value for type and properties,
415
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
+			if ($value != $old_value) {
417
+				// if they are NOT the same, then remove the hook,
418
+				// which means the subsequent update results will be based solely on the update query results
419
+				// the reason we do this is because, as stated above,
420
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
421
+				// this happens PRIOR to serialization and any subsequent update.
422
+				// If values are found to match their previous old value,
423
+				// then WP bails before performing any update.
424
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
+				// it just pulled from the db, with the one being passed to it (which will not match).
426
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
427
+				// MySQL MAY ALSO NOT perform the update because
428
+				// the string it sees in the db looks the same as the new one it has been passed!!!
429
+				// This results in the query returning an "affected rows" value of ZERO,
430
+				// which gets returned immediately by WP update_option and looks like an error.
431
+				remove_action('update_option', array($this, 'check_config_updated'));
432
+			}
433
+		}
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    update_espresso_config
440
+	 *
441
+	 * @access   public
442
+	 */
443
+	protected function _reset_espresso_addon_config()
444
+	{
445
+		$this->_addon_option_names = array();
446
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
447
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
448
+			if ($addon_config_obj instanceof EE_Config_Base) {
449
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
450
+			}
451
+			$this->addons->{$addon_name} = null;
452
+		}
453
+	}
454
+
455
+
456
+
457
+	/**
458
+	 *    update_espresso_config
459
+	 *
460
+	 * @access   public
461
+	 * @param   bool $add_success
462
+	 * @param   bool $add_error
463
+	 * @return   bool
464
+	 */
465
+	public function update_espresso_config($add_success = false, $add_error = true)
466
+	{
467
+		// don't allow config updates during WP heartbeats
468
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
469
+			return false;
470
+		}
471
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
472
+		//$clone = clone( self::$_instance );
473
+		//self::$_instance = NULL;
474
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
475
+		$this->_reset_espresso_addon_config();
476
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
477
+		// but BEFORE the actual update occurs
478
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
479
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
480
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
481
+		$this->legacy_shortcodes_manager = null;
482
+		// now update "ee_config"
483
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
484
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
485
+		EE_Config::log(EE_Config::OPTION_NAME);
486
+		// if not saved... check if the hook we just added still exists;
487
+		// if it does, it means one of two things:
488
+		// 		that update_option bailed at the ( $value === $old_value ) conditional,
489
+		//		 or...
490
+		// 		the db update query returned 0 rows affected
491
+		// 		(probably because the data  value was the same from it's perspective)
492
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
493
+		// but just means no update occurred, so don't display an error to the user.
494
+		// BUT... if update_option returns FALSE, AND the hook is missing,
495
+		// then it means that something truly went wrong
496
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
497
+		// remove our action since we don't want it in the system anymore
498
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
499
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
500
+		//self::$_instance = $clone;
501
+		//unset( $clone );
502
+		// if config remains the same or was updated successfully
503
+		if ($saved) {
504
+			if ($add_success) {
505
+				EE_Error::add_success(
506
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return true;
513
+		} else {
514
+			if ($add_error) {
515
+				EE_Error::add_error(
516
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
517
+					__FILE__,
518
+					__FUNCTION__,
519
+					__LINE__
520
+				);
521
+			}
522
+			return false;
523
+		}
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 *    _verify_config_params
530
+	 *
531
+	 * @access    private
532
+	 * @param    string         $section
533
+	 * @param    string         $name
534
+	 * @param    string         $config_class
535
+	 * @param    EE_Config_Base $config_obj
536
+	 * @param    array          $tests_to_run
537
+	 * @param    bool           $display_errors
538
+	 * @return    bool    TRUE on success, FALSE on fail
539
+	 */
540
+	private function _verify_config_params(
541
+		$section = '',
542
+		$name = '',
543
+		$config_class = '',
544
+		$config_obj = null,
545
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
546
+		$display_errors = true
547
+	) {
548
+		try {
549
+			foreach ($tests_to_run as $test) {
550
+				switch ($test) {
551
+					// TEST #1 : check that section was set
552
+					case 1 :
553
+						if (empty($section)) {
554
+							if ($display_errors) {
555
+								throw new EE_Error(
556
+									sprintf(
557
+										__(
558
+											'No configuration section has been provided while attempting to save "%s".',
559
+											'event_espresso'
560
+										),
561
+										$config_class
562
+									)
563
+								);
564
+							}
565
+							return false;
566
+						}
567
+						break;
568
+					// TEST #2 : check that settings section exists
569
+					case 2 :
570
+						if (! isset($this->{$section})) {
571
+							if ($display_errors) {
572
+								throw new EE_Error(
573
+									sprintf(
574
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
575
+										$section
576
+									)
577
+								);
578
+							}
579
+							return false;
580
+						}
581
+						break;
582
+					// TEST #3 : check that section is the proper format
583
+					case 3 :
584
+						if (
585
+						! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
586
+						) {
587
+							if ($display_errors) {
588
+								throw new EE_Error(
589
+									sprintf(
590
+										__(
591
+											'The "%s" configuration settings have not been formatted correctly.',
592
+											'event_espresso'
593
+										),
594
+										$section
595
+									)
596
+								);
597
+							}
598
+							return false;
599
+						}
600
+						break;
601
+					// TEST #4 : check that config section name has been set
602
+					case 4 :
603
+						if (empty($name)) {
604
+							if ($display_errors) {
605
+								throw new EE_Error(
606
+									__(
607
+										'No name has been provided for the specific configuration section.',
608
+										'event_espresso'
609
+									)
610
+								);
611
+							}
612
+							return false;
613
+						}
614
+						break;
615
+					// TEST #5 : check that a config class name has been set
616
+					case 5 :
617
+						if (empty($config_class)) {
618
+							if ($display_errors) {
619
+								throw new EE_Error(
620
+									__(
621
+										'No class name has been provided for the specific configuration section.',
622
+										'event_espresso'
623
+									)
624
+								);
625
+							}
626
+							return false;
627
+						}
628
+						break;
629
+					// TEST #6 : verify config class is accessible
630
+					case 6 :
631
+						if (! class_exists($config_class)) {
632
+							if ($display_errors) {
633
+								throw new EE_Error(
634
+									sprintf(
635
+										__(
636
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
637
+											'event_espresso'
638
+										),
639
+										$config_class
640
+									)
641
+								);
642
+							}
643
+							return false;
644
+						}
645
+						break;
646
+					// TEST #7 : check that config has even been set
647
+					case 7 :
648
+						if (! isset($this->{$section}->{$name})) {
649
+							if ($display_errors) {
650
+								throw new EE_Error(
651
+									sprintf(
652
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
653
+										$section,
654
+										$name
655
+									)
656
+								);
657
+							}
658
+							return false;
659
+						} else {
660
+							// and make sure it's not serialized
661
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
662
+						}
663
+						break;
664
+					// TEST #8 : check that config is the requested type
665
+					case 8 :
666
+						if (! $this->{$section}->{$name} instanceof $config_class) {
667
+							if ($display_errors) {
668
+								throw new EE_Error(
669
+									sprintf(
670
+										__(
671
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
672
+											'event_espresso'
673
+										),
674
+										$section,
675
+										$name,
676
+										$config_class
677
+									)
678
+								);
679
+							}
680
+							return false;
681
+						}
682
+						break;
683
+					// TEST #9 : verify config object
684
+					case 9 :
685
+						if (! $config_obj instanceof EE_Config_Base) {
686
+							if ($display_errors) {
687
+								throw new EE_Error(
688
+									sprintf(
689
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
690
+										print_r($config_obj, true)
691
+									)
692
+								);
693
+							}
694
+							return false;
695
+						}
696
+						break;
697
+				}
698
+			}
699
+		} catch (EE_Error $e) {
700
+			$e->get_error();
701
+		}
702
+		// you have successfully run the gauntlet
703
+		return true;
704
+	}
705
+
706
+
707
+
708
+	/**
709
+	 *    _generate_config_option_name
710
+	 *
711
+	 * @access        protected
712
+	 * @param        string $section
713
+	 * @param        string $name
714
+	 * @return        string
715
+	 */
716
+	private function _generate_config_option_name($section = '', $name = '')
717
+	{
718
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 *    _set_config_class
725
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
726
+	 *
727
+	 * @access    private
728
+	 * @param    string $config_class
729
+	 * @param    string $name
730
+	 * @return    string
731
+	 */
732
+	private function _set_config_class($config_class = '', $name = '')
733
+	{
734
+		return ! empty($config_class)
735
+			? $config_class
736
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
737
+	}
738
+
739
+
740
+
741
+	/**
742
+	 *    set_config
743
+	 *
744
+	 * @access    protected
745
+	 * @param    string         $section
746
+	 * @param    string         $name
747
+	 * @param    string         $config_class
748
+	 * @param    EE_Config_Base $config_obj
749
+	 * @return    EE_Config_Base
750
+	 */
751
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
752
+	{
753
+		// ensure config class is set to something
754
+		$config_class = $this->_set_config_class($config_class, $name);
755
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
756
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
757
+			return null;
758
+		}
759
+		$config_option_name = $this->_generate_config_option_name($section, $name);
760
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
761
+		if (! isset($this->_addon_option_names[$config_option_name])) {
762
+			$this->_addon_option_names[$config_option_name] = $config_class;
763
+			$this->update_addon_option_names();
764
+		}
765
+		// verify the incoming config object but suppress errors
766
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
767
+			$config_obj = new $config_class();
768
+		}
769
+		if (get_option($config_option_name)) {
770
+			EE_Config::log($config_option_name);
771
+			update_option($config_option_name, $config_obj);
772
+			$this->{$section}->{$name} = $config_obj;
773
+			return $this->{$section}->{$name};
774
+		} else {
775
+			// create a wp-option for this config
776
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
777
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
778
+				return $this->{$section}->{$name};
779
+			} else {
780
+				EE_Error::add_error(
781
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
782
+					__FILE__,
783
+					__FUNCTION__,
784
+					__LINE__
785
+				);
786
+				return null;
787
+			}
788
+		}
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 *    update_config
795
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
796
+	 *
797
+	 * @access    public
798
+	 * @param    string                $section
799
+	 * @param    string                $name
800
+	 * @param    EE_Config_Base|string $config_obj
801
+	 * @param    bool                  $throw_errors
802
+	 * @return    bool
803
+	 */
804
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
805
+	{
806
+		// don't allow config updates during WP heartbeats
807
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
808
+			return false;
809
+		}
810
+		$config_obj = maybe_unserialize($config_obj);
811
+		// get class name of the incoming object
812
+		$config_class = get_class($config_obj);
813
+		// run tests 1-5 and 9 to verify config
814
+		if (! $this->_verify_config_params(
815
+			$section,
816
+			$name,
817
+			$config_class,
818
+			$config_obj,
819
+			array(1, 2, 3, 4, 7, 9)
820
+		)
821
+		) {
822
+			return false;
823
+		}
824
+		$config_option_name = $this->_generate_config_option_name($section, $name);
825
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
826
+		if (! isset($this->_addon_option_names[$config_option_name])) {
827
+			// save new config to db
828
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
829
+				return true;
830
+			}
831
+		} else {
832
+			// first check if the record already exists
833
+			$existing_config = get_option($config_option_name);
834
+			$config_obj = serialize($config_obj);
835
+			// just return if db record is already up to date (NOT type safe comparison)
836
+			if ($existing_config == $config_obj) {
837
+				$this->{$section}->{$name} = $config_obj;
838
+				return true;
839
+			} else if (update_option($config_option_name, $config_obj)) {
840
+				EE_Config::log($config_option_name);
841
+				// update wp-option for this config class
842
+				$this->{$section}->{$name} = $config_obj;
843
+				return true;
844
+			} elseif ($throw_errors) {
845
+				EE_Error::add_error(
846
+					sprintf(
847
+						__(
848
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
849
+							'event_espresso'
850
+						),
851
+						$config_class,
852
+						'EE_Config->' . $section . '->' . $name
853
+					),
854
+					__FILE__,
855
+					__FUNCTION__,
856
+					__LINE__
857
+				);
858
+			}
859
+		}
860
+		return false;
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 *    get_config
867
+	 *
868
+	 * @access    public
869
+	 * @param    string $section
870
+	 * @param    string $name
871
+	 * @param    string $config_class
872
+	 * @return    mixed EE_Config_Base | NULL
873
+	 */
874
+	public function get_config($section = '', $name = '', $config_class = '')
875
+	{
876
+		// ensure config class is set to something
877
+		$config_class = $this->_set_config_class($config_class, $name);
878
+		// run tests 1-4, 6 and 7 to verify that all params have been set
879
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
880
+			return null;
881
+		}
882
+		// now test if the requested config object exists, but suppress errors
883
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
884
+			// config already exists, so pass it back
885
+			return $this->{$section}->{$name};
886
+		}
887
+		// load config option from db if it exists
888
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
889
+		// verify the newly retrieved config object, but suppress errors
890
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
891
+			// config is good, so set it and pass it back
892
+			$this->{$section}->{$name} = $config_obj;
893
+			return $this->{$section}->{$name};
894
+		}
895
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
896
+		$config_obj = $this->set_config($section, $name, $config_class);
897
+		// verify the newly created config object
898
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
899
+			return $this->{$section}->{$name};
900
+		} else {
901
+			EE_Error::add_error(
902
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
903
+				__FILE__,
904
+				__FUNCTION__,
905
+				__LINE__
906
+			);
907
+		}
908
+		return null;
909
+	}
910
+
911
+
912
+
913
+	/**
914
+	 *    get_config_option
915
+	 *
916
+	 * @access    public
917
+	 * @param    string $config_option_name
918
+	 * @return    mixed EE_Config_Base | FALSE
919
+	 */
920
+	public function get_config_option($config_option_name = '')
921
+	{
922
+		// retrieve the wp-option for this config class.
923
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
924
+		if (empty($config_option)) {
925
+			EE_Config::log($config_option_name . '-NOT-FOUND');
926
+		}
927
+		return $config_option;
928
+	}
929
+
930
+
931
+
932
+	/**
933
+	 * log
934
+	 *
935
+	 * @param string $config_option_name
936
+	 */
937
+	public static function log($config_option_name = '')
938
+	{
939
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
940
+			$config_log = get_option(EE_Config::LOG_NAME, array());
941
+			//copy incoming $_REQUEST and sanitize it so we can save it
942
+			$_request = $_REQUEST;
943
+			array_walk_recursive($_request, 'sanitize_text_field');
944
+			$config_log[(string)microtime(true)] = array(
945
+				'config_name' => $config_option_name,
946
+				'request'     => $_request,
947
+			);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * trim_log
956
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
957
+	 */
958
+	public static function trim_log()
959
+	{
960
+		if (! EE_Config::logging_enabled()) {
961
+			return;
962
+		}
963
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
964
+		$log_length = count($config_log);
965
+		if ($log_length > EE_Config::LOG_LENGTH) {
966
+			ksort($config_log);
967
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
968
+			update_option(EE_Config::LOG_NAME, $config_log);
969
+		}
970
+	}
971
+
972
+
973
+
974
+	/**
975
+	 *    get_page_for_posts
976
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
977
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
978
+	 *
979
+	 * @access    public
980
+	 * @return    string
981
+	 */
982
+	public static function get_page_for_posts()
983
+	{
984
+		$page_for_posts = get_option('page_for_posts');
985
+		if (! $page_for_posts) {
986
+			return 'posts';
987
+		}
988
+		/** @type WPDB $wpdb */
989
+		global $wpdb;
990
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
991
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 *    register_shortcodes_and_modules.
998
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
999
+	 *    In fact, this is where we give modules a chance to let core know they exist
1000
+	 *    so they can help trigger maintenance mode if it's needed
1001
+	 *
1002
+	 * @access    public
1003
+	 * @return    void
1004
+	 */
1005
+	public function register_shortcodes_and_modules()
1006
+	{
1007
+		// allow modules to set hooks for the rest of the system
1008
+		EE_Registry::instance()->modules = $this->_register_modules();
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 *    initialize_shortcodes_and_modules
1015
+	 *    meaning they can start adding their hooks to get stuff done
1016
+	 *
1017
+	 * @access    public
1018
+	 * @return    void
1019
+	 */
1020
+	public function initialize_shortcodes_and_modules()
1021
+	{
1022
+		// allow modules to set hooks for the rest of the system
1023
+		$this->_initialize_modules();
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 *    widgets_init
1030
+	 *
1031
+	 * @access private
1032
+	 * @return void
1033
+	 */
1034
+	public function widgets_init()
1035
+	{
1036
+		//only init widgets on admin pages when not in complete maintenance, and
1037
+		//on frontend when not in any maintenance mode
1038
+		if (
1039
+			! EE_Maintenance_Mode::instance()->level()
1040
+			|| (
1041
+				is_admin()
1042
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1043
+			)
1044
+		) {
1045
+			// grab list of installed widgets
1046
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1047
+			// filter list of modules to register
1048
+			$widgets_to_register = apply_filters(
1049
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1050
+				$widgets_to_register
1051
+			);
1052
+			if (! empty($widgets_to_register)) {
1053
+				// cycle thru widget folders
1054
+				foreach ($widgets_to_register as $widget_path) {
1055
+					// add to list of installed widget modules
1056
+					EE_Config::register_ee_widget($widget_path);
1057
+				}
1058
+			}
1059
+			// filter list of installed modules
1060
+			EE_Registry::instance()->widgets = apply_filters(
1061
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1062
+				EE_Registry::instance()->widgets
1063
+			);
1064
+		}
1065
+	}
1066
+
1067
+
1068
+
1069
+	/**
1070
+	 *    register_ee_widget - makes core aware of this widget
1071
+	 *
1072
+	 * @access    public
1073
+	 * @param    string $widget_path - full path up to and including widget folder
1074
+	 * @return    void
1075
+	 */
1076
+	public static function register_ee_widget($widget_path = null)
1077
+	{
1078
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1079
+		$widget_ext = '.widget.php';
1080
+		// make all separators match
1081
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1082
+		// does the file path INCLUDE the actual file name as part of the path ?
1083
+		if (strpos($widget_path, $widget_ext) !== false) {
1084
+			// grab and shortcode file name from directory name and break apart at dots
1085
+			$file_name = explode('.', basename($widget_path));
1086
+			// take first segment from file name pieces and remove class prefix if it exists
1087
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1088
+			// sanitize shortcode directory name
1089
+			$widget = sanitize_key($widget);
1090
+			// now we need to rebuild the shortcode path
1091
+			$widget_path = explode(DS, $widget_path);
1092
+			// remove last segment
1093
+			array_pop($widget_path);
1094
+			// glue it back together
1095
+			$widget_path = implode(DS, $widget_path);
1096
+		} else {
1097
+			// grab and sanitize widget directory name
1098
+			$widget = sanitize_key(basename($widget_path));
1099
+		}
1100
+		// create classname from widget directory name
1101
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1102
+		// add class prefix
1103
+		$widget_class = 'EEW_' . $widget;
1104
+		// does the widget exist ?
1105
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1106
+			$msg = sprintf(
1107
+				__(
1108
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1109
+					'event_espresso'
1110
+				),
1111
+				$widget_class,
1112
+				$widget_path . DS . $widget_class . $widget_ext
1113
+			);
1114
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1115
+			return;
1116
+		}
1117
+		// load the widget class file
1118
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1119
+		// verify that class exists
1120
+		if (! class_exists($widget_class)) {
1121
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1122
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1123
+			return;
1124
+		}
1125
+		register_widget($widget_class);
1126
+		// add to array of registered widgets
1127
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 *        _register_modules
1134
+	 *
1135
+	 * @access private
1136
+	 * @return array
1137
+	 */
1138
+	private function _register_modules()
1139
+	{
1140
+		// grab list of installed modules
1141
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1142
+		// filter list of modules to register
1143
+		$modules_to_register = apply_filters(
1144
+			'FHEE__EE_Config__register_modules__modules_to_register',
1145
+			$modules_to_register
1146
+		);
1147
+		if (! empty($modules_to_register)) {
1148
+			// loop through folders
1149
+			foreach ($modules_to_register as $module_path) {
1150
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1151
+				if (
1152
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1153
+					&& $module_path !== EE_MODULES . 'gateways'
1154
+				) {
1155
+					// add to list of installed modules
1156
+					EE_Config::register_module($module_path);
1157
+				}
1158
+			}
1159
+		}
1160
+		// filter list of installed modules
1161
+		return apply_filters(
1162
+			'FHEE__EE_Config___register_modules__installed_modules',
1163
+			EE_Registry::instance()->modules
1164
+		);
1165
+	}
1166
+
1167
+
1168
+
1169
+	/**
1170
+	 *    register_module - makes core aware of this module
1171
+	 *
1172
+	 * @access    public
1173
+	 * @param    string $module_path - full path up to and including module folder
1174
+	 * @return    bool
1175
+	 */
1176
+	public static function register_module($module_path = null)
1177
+	{
1178
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1179
+		$module_ext = '.module.php';
1180
+		// make all separators match
1181
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1182
+		// does the file path INCLUDE the actual file name as part of the path ?
1183
+		if (strpos($module_path, $module_ext) !== false) {
1184
+			// grab and shortcode file name from directory name and break apart at dots
1185
+			$module_file = explode('.', basename($module_path));
1186
+			// now we need to rebuild the shortcode path
1187
+			$module_path = explode(DS, $module_path);
1188
+			// remove last segment
1189
+			array_pop($module_path);
1190
+			// glue it back together
1191
+			$module_path = implode(DS, $module_path) . DS;
1192
+			// take first segment from file name pieces and sanitize it
1193
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1194
+			// ensure class prefix is added
1195
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1196
+		} else {
1197
+			// we need to generate the filename based off of the folder name
1198
+			// grab and sanitize module name
1199
+			$module = strtolower(basename($module_path));
1200
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1201
+			// like trailingslashit()
1202
+			$module_path = rtrim($module_path, DS) . DS;
1203
+			// create classname from module directory name
1204
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1205
+			// add class prefix
1206
+			$module_class = 'EED_' . $module;
1207
+		}
1208
+		// does the module exist ?
1209
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1210
+			$msg = sprintf(
1211
+				__(
1212
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1213
+					'event_espresso'
1214
+				),
1215
+				$module
1216
+			);
1217
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1218
+			return false;
1219
+		}
1220
+		// load the module class file
1221
+		require_once($module_path . $module_class . $module_ext);
1222
+		// verify that class exists
1223
+		if (! class_exists($module_class)) {
1224
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1225
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1226
+			return false;
1227
+		}
1228
+		// add to array of registered modules
1229
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1230
+		do_action(
1231
+			'AHEE__EE_Config__register_module__complete',
1232
+			$module_class,
1233
+			EE_Registry::instance()->modules->{$module_class}
1234
+		);
1235
+		return true;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 *    _initialize_modules
1242
+	 *    allow modules to set hooks for the rest of the system
1243
+	 *
1244
+	 * @access private
1245
+	 * @return void
1246
+	 */
1247
+	private function _initialize_modules()
1248
+	{
1249
+		// cycle thru shortcode folders
1250
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1251
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1252
+			// which set hooks ?
1253
+			if (is_admin()) {
1254
+				// fire immediately
1255
+				call_user_func(array($module_class, 'set_hooks_admin'));
1256
+			} else {
1257
+				// delay until other systems are online
1258
+				add_action(
1259
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1260
+					array($module_class, 'set_hooks')
1261
+				);
1262
+			}
1263
+		}
1264
+	}
1265
+
1266
+
1267
+
1268
+	/**
1269
+	 *    register_route - adds module method routes to route_map
1270
+	 *
1271
+	 * @access    public
1272
+	 * @param    string $route       - "pretty" public alias for module method
1273
+	 * @param    string $module      - module name (classname without EED_ prefix)
1274
+	 * @param    string $method_name - the actual module method to be routed to
1275
+	 * @param    string $key         - url param key indicating a route is being called
1276
+	 * @return    bool
1277
+	 */
1278
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1279
+	{
1280
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1281
+		$module = str_replace('EED_', '', $module);
1282
+		$module_class = 'EED_' . $module;
1283
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1284
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1285
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1286
+			return false;
1287
+		}
1288
+		if (empty($route)) {
1289
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1290
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1291
+			return false;
1292
+		}
1293
+		if (! method_exists('EED_' . $module, $method_name)) {
1294
+			$msg = sprintf(
1295
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1296
+				$route
1297
+			);
1298
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1299
+			return false;
1300
+		}
1301
+		EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1302
+		return true;
1303
+	}
1304
+
1305
+
1306
+
1307
+	/**
1308
+	 *    get_route - get module method route
1309
+	 *
1310
+	 * @access    public
1311
+	 * @param    string $route - "pretty" public alias for module method
1312
+	 * @param    string $key   - url param key indicating a route is being called
1313
+	 * @return    string
1314
+	 */
1315
+	public static function get_route($route = null, $key = 'ee')
1316
+	{
1317
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1318
+		$route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1319
+		if (isset(EE_Config::$_module_route_map[$key][$route])) {
1320
+			return EE_Config::$_module_route_map[$key][$route];
1321
+		}
1322
+		return null;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 *    get_routes - get ALL module method routes
1329
+	 *
1330
+	 * @access    public
1331
+	 * @return    array
1332
+	 */
1333
+	public static function get_routes()
1334
+	{
1335
+		return EE_Config::$_module_route_map;
1336
+	}
1337
+
1338
+
1339
+
1340
+	/**
1341
+	 *    register_forward - allows modules to forward request to another module for further processing
1342
+	 *
1343
+	 * @access    public
1344
+	 * @param    string       $route   - "pretty" public alias for module method
1345
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1346
+	 *                                 class, allows different forwards to be served based on status
1347
+	 * @param    array|string $forward - function name or array( class, method )
1348
+	 * @param    string       $key     - url param key indicating a route is being called
1349
+	 * @return    bool
1350
+	 */
1351
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1352
+	{
1353
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1354
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1355
+			$msg = sprintf(
1356
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1357
+				$route
1358
+			);
1359
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
+			return false;
1361
+		}
1362
+		if (empty($forward)) {
1363
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1364
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
+			return false;
1366
+		}
1367
+		if (is_array($forward)) {
1368
+			if (! isset($forward[1])) {
1369
+				$msg = sprintf(
1370
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1371
+					$route
1372
+				);
1373
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1374
+				return false;
1375
+			}
1376
+			if (! method_exists($forward[0], $forward[1])) {
1377
+				$msg = sprintf(
1378
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1379
+					$forward[1],
1380
+					$route
1381
+				);
1382
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1383
+				return false;
1384
+			}
1385
+		} else if (! function_exists($forward)) {
1386
+			$msg = sprintf(
1387
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1388
+				$forward,
1389
+				$route
1390
+			);
1391
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1392
+			return false;
1393
+		}
1394
+		EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1395
+		return true;
1396
+	}
1397
+
1398
+
1399
+
1400
+	/**
1401
+	 *    get_forward - get forwarding route
1402
+	 *
1403
+	 * @access    public
1404
+	 * @param    string  $route  - "pretty" public alias for module method
1405
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1406
+	 *                           allows different forwards to be served based on status
1407
+	 * @param    string  $key    - url param key indicating a route is being called
1408
+	 * @return    string
1409
+	 */
1410
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1411
+	{
1412
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1413
+		if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1414
+			return apply_filters(
1415
+				'FHEE__EE_Config__get_forward',
1416
+				EE_Config::$_module_forward_map[$key][$route][$status],
1417
+				$route,
1418
+				$status
1419
+			);
1420
+		}
1421
+		return null;
1422
+	}
1423
+
1424
+
1425
+
1426
+	/**
1427
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1428
+	 *    results
1429
+	 *
1430
+	 * @access    public
1431
+	 * @param    string  $route  - "pretty" public alias for module method
1432
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1433
+	 *                           allows different views to be served based on status
1434
+	 * @param    string  $view
1435
+	 * @param    string  $key    - url param key indicating a route is being called
1436
+	 * @return    bool
1437
+	 */
1438
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1439
+	{
1440
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1441
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1442
+			$msg = sprintf(
1443
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1444
+				$route
1445
+			);
1446
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1447
+			return false;
1448
+		}
1449
+		if (! is_readable($view)) {
1450
+			$msg = sprintf(
1451
+				__(
1452
+					'The %s view file could not be found or is not readable due to file permissions.',
1453
+					'event_espresso'
1454
+				),
1455
+				$view
1456
+			);
1457
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1458
+			return false;
1459
+		}
1460
+		EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1461
+		return true;
1462
+	}
1463
+
1464
+
1465
+
1466
+	/**
1467
+	 *    get_view - get view for route and status
1468
+	 *
1469
+	 * @access    public
1470
+	 * @param    string  $route  - "pretty" public alias for module method
1471
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1472
+	 *                           allows different views to be served based on status
1473
+	 * @param    string  $key    - url param key indicating a route is being called
1474
+	 * @return    string
1475
+	 */
1476
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1477
+	{
1478
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1479
+		if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1480
+			return apply_filters(
1481
+				'FHEE__EE_Config__get_view',
1482
+				EE_Config::$_module_view_map[$key][$route][$status],
1483
+				$route,
1484
+				$status
1485
+			);
1486
+		}
1487
+		return null;
1488
+	}
1489
+
1490
+
1491
+
1492
+	public function update_addon_option_names()
1493
+	{
1494
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1495
+	}
1496
+
1497
+
1498
+
1499
+	public function shutdown()
1500
+	{
1501
+		$this->update_addon_option_names();
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * @return LegacyShortcodesManager
1508
+	 */
1509
+	public static function getLegacyShortcodesManager()
1510
+	{
1511
+
1512
+		if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1513
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1514
+				EE_Registry::instance()
1515
+			);
1516
+		}
1517
+		return EE_Config::instance()->legacy_shortcodes_manager;
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * register_shortcode - makes core aware of this shortcode
1524
+	 *
1525
+	 * @deprecated 4.9.26
1526
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1527
+	 * @return    bool
1528
+	 */
1529
+	public static function register_shortcode($shortcode_path = null)
1530
+	{
1531
+		EE_Error::doing_it_wrong(
1532
+			__METHOD__,
1533
+			__(
1534
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1535
+				'event_espresso'
1536
+			),
1537
+			'4.9.26'
1538
+		);
1539
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1540
+	}
21 1541
 
22
-    const LOG_NAME           = 'ee_config_log';
23 1542
 
24
-    const LOG_LENGTH         = 100;
25 1543
 
26
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
-
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-
146
-    /**
147
-     * @singleton method used to instantiate class object
148
-     * @access    public
149
-     * @return EE_Config instance
150
-     */
151
-    public static function instance()
152
-    {
153
-        // check if class object is instantiated, and instantiated properly
154
-        if (! self::$_instance instanceof EE_Config) {
155
-            self::$_instance = new self();
156
-        }
157
-        return self::$_instance;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Resets the config
164
-     *
165
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
-     *                               reflect its state in the database
168
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
-     *                               site was put into maintenance mode)
172
-     * @return EE_Config
173
-     */
174
-    public static function reset($hard_reset = false, $reinstantiate = true)
175
-    {
176
-        if (self::$_instance instanceof EE_Config) {
177
-            if ($hard_reset) {
178
-                self::$_instance->legacy_shortcodes_manager = null;
179
-                self::$_instance->_addon_option_names = array();
180
-                self::$_instance->_initialize_config();
181
-                self::$_instance->update_espresso_config();
182
-            }
183
-            self::$_instance->update_addon_option_names();
184
-        }
185
-        self::$_instance = null;
186
-        //we don't need to reset the static properties imo because those should
187
-        //only change when a module is added or removed. Currently we don't
188
-        //support removing a module during a request when it previously existed
189
-        if ($reinstantiate) {
190
-            return self::instance();
191
-        } else {
192
-            return null;
193
-        }
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     *    class constructor
200
-     *
201
-     * @access    private
202
-     */
203
-    private function __construct()
204
-    {
205
-        do_action('AHEE__EE_Config__construct__begin', $this);
206
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
-        // setup empty config classes
208
-        $this->_initialize_config();
209
-        // load existing EE site settings
210
-        $this->_load_core_config();
211
-        // confirm everything loaded correctly and set filtered defaults if not
212
-        $this->_verify_config();
213
-        //  register shortcodes and modules
214
-        add_action(
215
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
-            array($this, 'register_shortcodes_and_modules'),
217
-            999
218
-        );
219
-        //  initialize shortcodes and modules
220
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
-        // register widgets
222
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
223
-        // shutdown
224
-        add_action('shutdown', array($this, 'shutdown'), 10);
225
-        // construct__end hook
226
-        do_action('AHEE__EE_Config__construct__end', $this);
227
-        // hardcoded hack
228
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     */
236
-    public static function logging_enabled()
237
-    {
238
-        return self::$_logging_enabled;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * use to get the current theme if needed from static context
245
-     *
246
-     * @return string current theme set.
247
-     */
248
-    public static function get_current_theme()
249
-    {
250
-        return isset(self::$_instance->template_settings->current_espresso_theme)
251
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *        _initialize_config
258
-     *
259
-     * @access private
260
-     * @return void
261
-     */
262
-    private function _initialize_config()
263
-    {
264
-        EE_Config::trim_log();
265
-        //set defaults
266
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
-        $this->addons = new stdClass();
268
-        // set _module_route_map
269
-        EE_Config::$_module_route_map = array();
270
-        // set _module_forward_map
271
-        EE_Config::$_module_forward_map = array();
272
-        // set _module_view_map
273
-        EE_Config::$_module_view_map = array();
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     *        load core plugin configuration
280
-     *
281
-     * @access private
282
-     * @return void
283
-     */
284
-    private function _load_core_config()
285
-    {
286
-        // load_core_config__start hook
287
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
288
-        $espresso_config = $this->get_espresso_config();
289
-        foreach ($espresso_config as $config => $settings) {
290
-            // load_core_config__start hook
291
-            $settings = apply_filters(
292
-                'FHEE__EE_Config___load_core_config__config_settings',
293
-                $settings,
294
-                $config,
295
-                $this
296
-            );
297
-            if (is_object($settings) && property_exists($this, $config)) {
298
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
-                //call configs populate method to ensure any defaults are set for empty values.
300
-                if (method_exists($settings, 'populate')) {
301
-                    $this->{$config}->populate();
302
-                }
303
-                if (method_exists($settings, 'do_hooks')) {
304
-                    $this->{$config}->do_hooks();
305
-                }
306
-            }
307
-        }
308
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
-            $this->update_espresso_config();
310
-        }
311
-        // load_core_config__end hook
312
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     *    _verify_config
319
-     *
320
-     * @access    protected
321
-     * @return    void
322
-     */
323
-    protected function _verify_config()
324
-    {
325
-        $this->core = $this->core instanceof EE_Core_Config
326
-            ? $this->core
327
-            : new EE_Core_Config();
328
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
-        $this->organization = $this->organization instanceof EE_Organization_Config
330
-            ? $this->organization
331
-            : new EE_Organization_Config();
332
-        $this->organization = apply_filters(
333
-            'FHEE__EE_Config___initialize_config__organization',
334
-            $this->organization
335
-        );
336
-        $this->currency = $this->currency instanceof EE_Currency_Config
337
-            ? $this->currency
338
-            : new EE_Currency_Config();
339
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
-        $this->registration = $this->registration instanceof EE_Registration_Config
341
-            ? $this->registration
342
-            : new EE_Registration_Config();
343
-        $this->registration = apply_filters(
344
-            'FHEE__EE_Config___initialize_config__registration',
345
-            $this->registration
346
-        );
347
-        $this->admin = $this->admin instanceof EE_Admin_Config
348
-            ? $this->admin
349
-            : new EE_Admin_Config();
350
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
352
-            ? $this->template_settings
353
-            : new EE_Template_Config();
354
-        $this->template_settings = apply_filters(
355
-            'FHEE__EE_Config___initialize_config__template_settings',
356
-            $this->template_settings
357
-        );
358
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
359
-            ? $this->map_settings
360
-            : new EE_Map_Config();
361
-        $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
-            $this->map_settings);
363
-        $this->environment = $this->environment instanceof EE_Environment_Config
364
-            ? $this->environment
365
-            : new EE_Environment_Config();
366
-        $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
-            $this->environment);
368
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
-            ? $this->tax_settings
370
-            : new EE_Tax_Config();
371
-        $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
-            $this->tax_settings);
373
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
-        $this->messages = $this->messages instanceof EE_Messages_Config
375
-            ? $this->messages
376
-            : new EE_Messages_Config();
377
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
378
-            ? $this->gateway
379
-            : new EE_Gateway_Config();
380
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
-        $this->legacy_shortcodes_manager = null;
382
-    }
383
-
384
-
385
-    /**
386
-     *    get_espresso_config
387
-     *
388
-     * @access    public
389
-     * @return    array of espresso config stuff
390
-     */
391
-    public function get_espresso_config()
392
-    {
393
-        // grab espresso configuration
394
-        return apply_filters(
395
-            'FHEE__EE_Config__get_espresso_config__CFG',
396
-            get_option(EE_Config::OPTION_NAME, array())
397
-        );
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     *    double_check_config_comparison
404
-     *
405
-     * @access    public
406
-     * @param string $option
407
-     * @param        $old_value
408
-     * @param        $value
409
-     */
410
-    public function double_check_config_comparison($option = '', $old_value, $value)
411
-    {
412
-        // make sure we're checking the ee config
413
-        if ($option === EE_Config::OPTION_NAME) {
414
-            // run a loose comparison of the old value against the new value for type and properties,
415
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
-            if ($value != $old_value) {
417
-                // if they are NOT the same, then remove the hook,
418
-                // which means the subsequent update results will be based solely on the update query results
419
-                // the reason we do this is because, as stated above,
420
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
421
-                // this happens PRIOR to serialization and any subsequent update.
422
-                // If values are found to match their previous old value,
423
-                // then WP bails before performing any update.
424
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
-                // it just pulled from the db, with the one being passed to it (which will not match).
426
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
427
-                // MySQL MAY ALSO NOT perform the update because
428
-                // the string it sees in the db looks the same as the new one it has been passed!!!
429
-                // This results in the query returning an "affected rows" value of ZERO,
430
-                // which gets returned immediately by WP update_option and looks like an error.
431
-                remove_action('update_option', array($this, 'check_config_updated'));
432
-            }
433
-        }
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    update_espresso_config
440
-     *
441
-     * @access   public
442
-     */
443
-    protected function _reset_espresso_addon_config()
444
-    {
445
-        $this->_addon_option_names = array();
446
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
447
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
448
-            if ($addon_config_obj instanceof EE_Config_Base) {
449
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
450
-            }
451
-            $this->addons->{$addon_name} = null;
452
-        }
453
-    }
454
-
455
-
456
-
457
-    /**
458
-     *    update_espresso_config
459
-     *
460
-     * @access   public
461
-     * @param   bool $add_success
462
-     * @param   bool $add_error
463
-     * @return   bool
464
-     */
465
-    public function update_espresso_config($add_success = false, $add_error = true)
466
-    {
467
-        // don't allow config updates during WP heartbeats
468
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
469
-            return false;
470
-        }
471
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
472
-        //$clone = clone( self::$_instance );
473
-        //self::$_instance = NULL;
474
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
475
-        $this->_reset_espresso_addon_config();
476
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
477
-        // but BEFORE the actual update occurs
478
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
479
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
480
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
481
-        $this->legacy_shortcodes_manager = null;
482
-        // now update "ee_config"
483
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
484
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
485
-        EE_Config::log(EE_Config::OPTION_NAME);
486
-        // if not saved... check if the hook we just added still exists;
487
-        // if it does, it means one of two things:
488
-        // 		that update_option bailed at the ( $value === $old_value ) conditional,
489
-        //		 or...
490
-        // 		the db update query returned 0 rows affected
491
-        // 		(probably because the data  value was the same from it's perspective)
492
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
493
-        // but just means no update occurred, so don't display an error to the user.
494
-        // BUT... if update_option returns FALSE, AND the hook is missing,
495
-        // then it means that something truly went wrong
496
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
497
-        // remove our action since we don't want it in the system anymore
498
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
499
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
500
-        //self::$_instance = $clone;
501
-        //unset( $clone );
502
-        // if config remains the same or was updated successfully
503
-        if ($saved) {
504
-            if ($add_success) {
505
-                EE_Error::add_success(
506
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return true;
513
-        } else {
514
-            if ($add_error) {
515
-                EE_Error::add_error(
516
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
517
-                    __FILE__,
518
-                    __FUNCTION__,
519
-                    __LINE__
520
-                );
521
-            }
522
-            return false;
523
-        }
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     *    _verify_config_params
530
-     *
531
-     * @access    private
532
-     * @param    string         $section
533
-     * @param    string         $name
534
-     * @param    string         $config_class
535
-     * @param    EE_Config_Base $config_obj
536
-     * @param    array          $tests_to_run
537
-     * @param    bool           $display_errors
538
-     * @return    bool    TRUE on success, FALSE on fail
539
-     */
540
-    private function _verify_config_params(
541
-        $section = '',
542
-        $name = '',
543
-        $config_class = '',
544
-        $config_obj = null,
545
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
546
-        $display_errors = true
547
-    ) {
548
-        try {
549
-            foreach ($tests_to_run as $test) {
550
-                switch ($test) {
551
-                    // TEST #1 : check that section was set
552
-                    case 1 :
553
-                        if (empty($section)) {
554
-                            if ($display_errors) {
555
-                                throw new EE_Error(
556
-                                    sprintf(
557
-                                        __(
558
-                                            'No configuration section has been provided while attempting to save "%s".',
559
-                                            'event_espresso'
560
-                                        ),
561
-                                        $config_class
562
-                                    )
563
-                                );
564
-                            }
565
-                            return false;
566
-                        }
567
-                        break;
568
-                    // TEST #2 : check that settings section exists
569
-                    case 2 :
570
-                        if (! isset($this->{$section})) {
571
-                            if ($display_errors) {
572
-                                throw new EE_Error(
573
-                                    sprintf(
574
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
575
-                                        $section
576
-                                    )
577
-                                );
578
-                            }
579
-                            return false;
580
-                        }
581
-                        break;
582
-                    // TEST #3 : check that section is the proper format
583
-                    case 3 :
584
-                        if (
585
-                        ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
586
-                        ) {
587
-                            if ($display_errors) {
588
-                                throw new EE_Error(
589
-                                    sprintf(
590
-                                        __(
591
-                                            'The "%s" configuration settings have not been formatted correctly.',
592
-                                            'event_espresso'
593
-                                        ),
594
-                                        $section
595
-                                    )
596
-                                );
597
-                            }
598
-                            return false;
599
-                        }
600
-                        break;
601
-                    // TEST #4 : check that config section name has been set
602
-                    case 4 :
603
-                        if (empty($name)) {
604
-                            if ($display_errors) {
605
-                                throw new EE_Error(
606
-                                    __(
607
-                                        'No name has been provided for the specific configuration section.',
608
-                                        'event_espresso'
609
-                                    )
610
-                                );
611
-                            }
612
-                            return false;
613
-                        }
614
-                        break;
615
-                    // TEST #5 : check that a config class name has been set
616
-                    case 5 :
617
-                        if (empty($config_class)) {
618
-                            if ($display_errors) {
619
-                                throw new EE_Error(
620
-                                    __(
621
-                                        'No class name has been provided for the specific configuration section.',
622
-                                        'event_espresso'
623
-                                    )
624
-                                );
625
-                            }
626
-                            return false;
627
-                        }
628
-                        break;
629
-                    // TEST #6 : verify config class is accessible
630
-                    case 6 :
631
-                        if (! class_exists($config_class)) {
632
-                            if ($display_errors) {
633
-                                throw new EE_Error(
634
-                                    sprintf(
635
-                                        __(
636
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
637
-                                            'event_espresso'
638
-                                        ),
639
-                                        $config_class
640
-                                    )
641
-                                );
642
-                            }
643
-                            return false;
644
-                        }
645
-                        break;
646
-                    // TEST #7 : check that config has even been set
647
-                    case 7 :
648
-                        if (! isset($this->{$section}->{$name})) {
649
-                            if ($display_errors) {
650
-                                throw new EE_Error(
651
-                                    sprintf(
652
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
653
-                                        $section,
654
-                                        $name
655
-                                    )
656
-                                );
657
-                            }
658
-                            return false;
659
-                        } else {
660
-                            // and make sure it's not serialized
661
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
662
-                        }
663
-                        break;
664
-                    // TEST #8 : check that config is the requested type
665
-                    case 8 :
666
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
667
-                            if ($display_errors) {
668
-                                throw new EE_Error(
669
-                                    sprintf(
670
-                                        __(
671
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
672
-                                            'event_espresso'
673
-                                        ),
674
-                                        $section,
675
-                                        $name,
676
-                                        $config_class
677
-                                    )
678
-                                );
679
-                            }
680
-                            return false;
681
-                        }
682
-                        break;
683
-                    // TEST #9 : verify config object
684
-                    case 9 :
685
-                        if (! $config_obj instanceof EE_Config_Base) {
686
-                            if ($display_errors) {
687
-                                throw new EE_Error(
688
-                                    sprintf(
689
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
690
-                                        print_r($config_obj, true)
691
-                                    )
692
-                                );
693
-                            }
694
-                            return false;
695
-                        }
696
-                        break;
697
-                }
698
-            }
699
-        } catch (EE_Error $e) {
700
-            $e->get_error();
701
-        }
702
-        // you have successfully run the gauntlet
703
-        return true;
704
-    }
705
-
706
-
707
-
708
-    /**
709
-     *    _generate_config_option_name
710
-     *
711
-     * @access        protected
712
-     * @param        string $section
713
-     * @param        string $name
714
-     * @return        string
715
-     */
716
-    private function _generate_config_option_name($section = '', $name = '')
717
-    {
718
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     *    _set_config_class
725
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
726
-     *
727
-     * @access    private
728
-     * @param    string $config_class
729
-     * @param    string $name
730
-     * @return    string
731
-     */
732
-    private function _set_config_class($config_class = '', $name = '')
733
-    {
734
-        return ! empty($config_class)
735
-            ? $config_class
736
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
737
-    }
738
-
739
-
740
-
741
-    /**
742
-     *    set_config
743
-     *
744
-     * @access    protected
745
-     * @param    string         $section
746
-     * @param    string         $name
747
-     * @param    string         $config_class
748
-     * @param    EE_Config_Base $config_obj
749
-     * @return    EE_Config_Base
750
-     */
751
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
752
-    {
753
-        // ensure config class is set to something
754
-        $config_class = $this->_set_config_class($config_class, $name);
755
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
756
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
757
-            return null;
758
-        }
759
-        $config_option_name = $this->_generate_config_option_name($section, $name);
760
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
761
-        if (! isset($this->_addon_option_names[$config_option_name])) {
762
-            $this->_addon_option_names[$config_option_name] = $config_class;
763
-            $this->update_addon_option_names();
764
-        }
765
-        // verify the incoming config object but suppress errors
766
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
767
-            $config_obj = new $config_class();
768
-        }
769
-        if (get_option($config_option_name)) {
770
-            EE_Config::log($config_option_name);
771
-            update_option($config_option_name, $config_obj);
772
-            $this->{$section}->{$name} = $config_obj;
773
-            return $this->{$section}->{$name};
774
-        } else {
775
-            // create a wp-option for this config
776
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
777
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
778
-                return $this->{$section}->{$name};
779
-            } else {
780
-                EE_Error::add_error(
781
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
782
-                    __FILE__,
783
-                    __FUNCTION__,
784
-                    __LINE__
785
-                );
786
-                return null;
787
-            }
788
-        }
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     *    update_config
795
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
796
-     *
797
-     * @access    public
798
-     * @param    string                $section
799
-     * @param    string                $name
800
-     * @param    EE_Config_Base|string $config_obj
801
-     * @param    bool                  $throw_errors
802
-     * @return    bool
803
-     */
804
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
805
-    {
806
-        // don't allow config updates during WP heartbeats
807
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
808
-            return false;
809
-        }
810
-        $config_obj = maybe_unserialize($config_obj);
811
-        // get class name of the incoming object
812
-        $config_class = get_class($config_obj);
813
-        // run tests 1-5 and 9 to verify config
814
-        if (! $this->_verify_config_params(
815
-            $section,
816
-            $name,
817
-            $config_class,
818
-            $config_obj,
819
-            array(1, 2, 3, 4, 7, 9)
820
-        )
821
-        ) {
822
-            return false;
823
-        }
824
-        $config_option_name = $this->_generate_config_option_name($section, $name);
825
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
826
-        if (! isset($this->_addon_option_names[$config_option_name])) {
827
-            // save new config to db
828
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
829
-                return true;
830
-            }
831
-        } else {
832
-            // first check if the record already exists
833
-            $existing_config = get_option($config_option_name);
834
-            $config_obj = serialize($config_obj);
835
-            // just return if db record is already up to date (NOT type safe comparison)
836
-            if ($existing_config == $config_obj) {
837
-                $this->{$section}->{$name} = $config_obj;
838
-                return true;
839
-            } else if (update_option($config_option_name, $config_obj)) {
840
-                EE_Config::log($config_option_name);
841
-                // update wp-option for this config class
842
-                $this->{$section}->{$name} = $config_obj;
843
-                return true;
844
-            } elseif ($throw_errors) {
845
-                EE_Error::add_error(
846
-                    sprintf(
847
-                        __(
848
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
849
-                            'event_espresso'
850
-                        ),
851
-                        $config_class,
852
-                        'EE_Config->' . $section . '->' . $name
853
-                    ),
854
-                    __FILE__,
855
-                    __FUNCTION__,
856
-                    __LINE__
857
-                );
858
-            }
859
-        }
860
-        return false;
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     *    get_config
867
-     *
868
-     * @access    public
869
-     * @param    string $section
870
-     * @param    string $name
871
-     * @param    string $config_class
872
-     * @return    mixed EE_Config_Base | NULL
873
-     */
874
-    public function get_config($section = '', $name = '', $config_class = '')
875
-    {
876
-        // ensure config class is set to something
877
-        $config_class = $this->_set_config_class($config_class, $name);
878
-        // run tests 1-4, 6 and 7 to verify that all params have been set
879
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
880
-            return null;
881
-        }
882
-        // now test if the requested config object exists, but suppress errors
883
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
884
-            // config already exists, so pass it back
885
-            return $this->{$section}->{$name};
886
-        }
887
-        // load config option from db if it exists
888
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
889
-        // verify the newly retrieved config object, but suppress errors
890
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
891
-            // config is good, so set it and pass it back
892
-            $this->{$section}->{$name} = $config_obj;
893
-            return $this->{$section}->{$name};
894
-        }
895
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
896
-        $config_obj = $this->set_config($section, $name, $config_class);
897
-        // verify the newly created config object
898
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
899
-            return $this->{$section}->{$name};
900
-        } else {
901
-            EE_Error::add_error(
902
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
903
-                __FILE__,
904
-                __FUNCTION__,
905
-                __LINE__
906
-            );
907
-        }
908
-        return null;
909
-    }
910
-
911
-
912
-
913
-    /**
914
-     *    get_config_option
915
-     *
916
-     * @access    public
917
-     * @param    string $config_option_name
918
-     * @return    mixed EE_Config_Base | FALSE
919
-     */
920
-    public function get_config_option($config_option_name = '')
921
-    {
922
-        // retrieve the wp-option for this config class.
923
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
924
-        if (empty($config_option)) {
925
-            EE_Config::log($config_option_name . '-NOT-FOUND');
926
-        }
927
-        return $config_option;
928
-    }
929
-
930
-
931
-
932
-    /**
933
-     * log
934
-     *
935
-     * @param string $config_option_name
936
-     */
937
-    public static function log($config_option_name = '')
938
-    {
939
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
940
-            $config_log = get_option(EE_Config::LOG_NAME, array());
941
-            //copy incoming $_REQUEST and sanitize it so we can save it
942
-            $_request = $_REQUEST;
943
-            array_walk_recursive($_request, 'sanitize_text_field');
944
-            $config_log[(string)microtime(true)] = array(
945
-                'config_name' => $config_option_name,
946
-                'request'     => $_request,
947
-            );
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * trim_log
956
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
957
-     */
958
-    public static function trim_log()
959
-    {
960
-        if (! EE_Config::logging_enabled()) {
961
-            return;
962
-        }
963
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
964
-        $log_length = count($config_log);
965
-        if ($log_length > EE_Config::LOG_LENGTH) {
966
-            ksort($config_log);
967
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
968
-            update_option(EE_Config::LOG_NAME, $config_log);
969
-        }
970
-    }
971
-
972
-
973
-
974
-    /**
975
-     *    get_page_for_posts
976
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
977
-     *    wp-option "page_for_posts", or "posts" if no page is selected
978
-     *
979
-     * @access    public
980
-     * @return    string
981
-     */
982
-    public static function get_page_for_posts()
983
-    {
984
-        $page_for_posts = get_option('page_for_posts');
985
-        if (! $page_for_posts) {
986
-            return 'posts';
987
-        }
988
-        /** @type WPDB $wpdb */
989
-        global $wpdb;
990
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
991
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     *    register_shortcodes_and_modules.
998
-     *    At this point, it's too early to tell if we're maintenance mode or not.
999
-     *    In fact, this is where we give modules a chance to let core know they exist
1000
-     *    so they can help trigger maintenance mode if it's needed
1001
-     *
1002
-     * @access    public
1003
-     * @return    void
1004
-     */
1005
-    public function register_shortcodes_and_modules()
1006
-    {
1007
-        // allow modules to set hooks for the rest of the system
1008
-        EE_Registry::instance()->modules = $this->_register_modules();
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     *    initialize_shortcodes_and_modules
1015
-     *    meaning they can start adding their hooks to get stuff done
1016
-     *
1017
-     * @access    public
1018
-     * @return    void
1019
-     */
1020
-    public function initialize_shortcodes_and_modules()
1021
-    {
1022
-        // allow modules to set hooks for the rest of the system
1023
-        $this->_initialize_modules();
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     *    widgets_init
1030
-     *
1031
-     * @access private
1032
-     * @return void
1033
-     */
1034
-    public function widgets_init()
1035
-    {
1036
-        //only init widgets on admin pages when not in complete maintenance, and
1037
-        //on frontend when not in any maintenance mode
1038
-        if (
1039
-            ! EE_Maintenance_Mode::instance()->level()
1040
-            || (
1041
-                is_admin()
1042
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1043
-            )
1044
-        ) {
1045
-            // grab list of installed widgets
1046
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1047
-            // filter list of modules to register
1048
-            $widgets_to_register = apply_filters(
1049
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1050
-                $widgets_to_register
1051
-            );
1052
-            if (! empty($widgets_to_register)) {
1053
-                // cycle thru widget folders
1054
-                foreach ($widgets_to_register as $widget_path) {
1055
-                    // add to list of installed widget modules
1056
-                    EE_Config::register_ee_widget($widget_path);
1057
-                }
1058
-            }
1059
-            // filter list of installed modules
1060
-            EE_Registry::instance()->widgets = apply_filters(
1061
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1062
-                EE_Registry::instance()->widgets
1063
-            );
1064
-        }
1065
-    }
1066
-
1067
-
1068
-
1069
-    /**
1070
-     *    register_ee_widget - makes core aware of this widget
1071
-     *
1072
-     * @access    public
1073
-     * @param    string $widget_path - full path up to and including widget folder
1074
-     * @return    void
1075
-     */
1076
-    public static function register_ee_widget($widget_path = null)
1077
-    {
1078
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1079
-        $widget_ext = '.widget.php';
1080
-        // make all separators match
1081
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1082
-        // does the file path INCLUDE the actual file name as part of the path ?
1083
-        if (strpos($widget_path, $widget_ext) !== false) {
1084
-            // grab and shortcode file name from directory name and break apart at dots
1085
-            $file_name = explode('.', basename($widget_path));
1086
-            // take first segment from file name pieces and remove class prefix if it exists
1087
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1088
-            // sanitize shortcode directory name
1089
-            $widget = sanitize_key($widget);
1090
-            // now we need to rebuild the shortcode path
1091
-            $widget_path = explode(DS, $widget_path);
1092
-            // remove last segment
1093
-            array_pop($widget_path);
1094
-            // glue it back together
1095
-            $widget_path = implode(DS, $widget_path);
1096
-        } else {
1097
-            // grab and sanitize widget directory name
1098
-            $widget = sanitize_key(basename($widget_path));
1099
-        }
1100
-        // create classname from widget directory name
1101
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1102
-        // add class prefix
1103
-        $widget_class = 'EEW_' . $widget;
1104
-        // does the widget exist ?
1105
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1106
-            $msg = sprintf(
1107
-                __(
1108
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1109
-                    'event_espresso'
1110
-                ),
1111
-                $widget_class,
1112
-                $widget_path . DS . $widget_class . $widget_ext
1113
-            );
1114
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1115
-            return;
1116
-        }
1117
-        // load the widget class file
1118
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1119
-        // verify that class exists
1120
-        if (! class_exists($widget_class)) {
1121
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1122
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1123
-            return;
1124
-        }
1125
-        register_widget($widget_class);
1126
-        // add to array of registered widgets
1127
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     *        _register_modules
1134
-     *
1135
-     * @access private
1136
-     * @return array
1137
-     */
1138
-    private function _register_modules()
1139
-    {
1140
-        // grab list of installed modules
1141
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1142
-        // filter list of modules to register
1143
-        $modules_to_register = apply_filters(
1144
-            'FHEE__EE_Config__register_modules__modules_to_register',
1145
-            $modules_to_register
1146
-        );
1147
-        if (! empty($modules_to_register)) {
1148
-            // loop through folders
1149
-            foreach ($modules_to_register as $module_path) {
1150
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1151
-                if (
1152
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1153
-                    && $module_path !== EE_MODULES . 'gateways'
1154
-                ) {
1155
-                    // add to list of installed modules
1156
-                    EE_Config::register_module($module_path);
1157
-                }
1158
-            }
1159
-        }
1160
-        // filter list of installed modules
1161
-        return apply_filters(
1162
-            'FHEE__EE_Config___register_modules__installed_modules',
1163
-            EE_Registry::instance()->modules
1164
-        );
1165
-    }
1166
-
1167
-
1168
-
1169
-    /**
1170
-     *    register_module - makes core aware of this module
1171
-     *
1172
-     * @access    public
1173
-     * @param    string $module_path - full path up to and including module folder
1174
-     * @return    bool
1175
-     */
1176
-    public static function register_module($module_path = null)
1177
-    {
1178
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1179
-        $module_ext = '.module.php';
1180
-        // make all separators match
1181
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1182
-        // does the file path INCLUDE the actual file name as part of the path ?
1183
-        if (strpos($module_path, $module_ext) !== false) {
1184
-            // grab and shortcode file name from directory name and break apart at dots
1185
-            $module_file = explode('.', basename($module_path));
1186
-            // now we need to rebuild the shortcode path
1187
-            $module_path = explode(DS, $module_path);
1188
-            // remove last segment
1189
-            array_pop($module_path);
1190
-            // glue it back together
1191
-            $module_path = implode(DS, $module_path) . DS;
1192
-            // take first segment from file name pieces and sanitize it
1193
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1194
-            // ensure class prefix is added
1195
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1196
-        } else {
1197
-            // we need to generate the filename based off of the folder name
1198
-            // grab and sanitize module name
1199
-            $module = strtolower(basename($module_path));
1200
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1201
-            // like trailingslashit()
1202
-            $module_path = rtrim($module_path, DS) . DS;
1203
-            // create classname from module directory name
1204
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1205
-            // add class prefix
1206
-            $module_class = 'EED_' . $module;
1207
-        }
1208
-        // does the module exist ?
1209
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1210
-            $msg = sprintf(
1211
-                __(
1212
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1213
-                    'event_espresso'
1214
-                ),
1215
-                $module
1216
-            );
1217
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1218
-            return false;
1219
-        }
1220
-        // load the module class file
1221
-        require_once($module_path . $module_class . $module_ext);
1222
-        // verify that class exists
1223
-        if (! class_exists($module_class)) {
1224
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1225
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1226
-            return false;
1227
-        }
1228
-        // add to array of registered modules
1229
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1230
-        do_action(
1231
-            'AHEE__EE_Config__register_module__complete',
1232
-            $module_class,
1233
-            EE_Registry::instance()->modules->{$module_class}
1234
-        );
1235
-        return true;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     *    _initialize_modules
1242
-     *    allow modules to set hooks for the rest of the system
1243
-     *
1244
-     * @access private
1245
-     * @return void
1246
-     */
1247
-    private function _initialize_modules()
1248
-    {
1249
-        // cycle thru shortcode folders
1250
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1251
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1252
-            // which set hooks ?
1253
-            if (is_admin()) {
1254
-                // fire immediately
1255
-                call_user_func(array($module_class, 'set_hooks_admin'));
1256
-            } else {
1257
-                // delay until other systems are online
1258
-                add_action(
1259
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1260
-                    array($module_class, 'set_hooks')
1261
-                );
1262
-            }
1263
-        }
1264
-    }
1265
-
1266
-
1267
-
1268
-    /**
1269
-     *    register_route - adds module method routes to route_map
1270
-     *
1271
-     * @access    public
1272
-     * @param    string $route       - "pretty" public alias for module method
1273
-     * @param    string $module      - module name (classname without EED_ prefix)
1274
-     * @param    string $method_name - the actual module method to be routed to
1275
-     * @param    string $key         - url param key indicating a route is being called
1276
-     * @return    bool
1277
-     */
1278
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1279
-    {
1280
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1281
-        $module = str_replace('EED_', '', $module);
1282
-        $module_class = 'EED_' . $module;
1283
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1284
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1285
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1286
-            return false;
1287
-        }
1288
-        if (empty($route)) {
1289
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1290
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1291
-            return false;
1292
-        }
1293
-        if (! method_exists('EED_' . $module, $method_name)) {
1294
-            $msg = sprintf(
1295
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1296
-                $route
1297
-            );
1298
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1299
-            return false;
1300
-        }
1301
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1302
-        return true;
1303
-    }
1304
-
1305
-
1306
-
1307
-    /**
1308
-     *    get_route - get module method route
1309
-     *
1310
-     * @access    public
1311
-     * @param    string $route - "pretty" public alias for module method
1312
-     * @param    string $key   - url param key indicating a route is being called
1313
-     * @return    string
1314
-     */
1315
-    public static function get_route($route = null, $key = 'ee')
1316
-    {
1317
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1318
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1319
-        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1320
-            return EE_Config::$_module_route_map[$key][$route];
1321
-        }
1322
-        return null;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     *    get_routes - get ALL module method routes
1329
-     *
1330
-     * @access    public
1331
-     * @return    array
1332
-     */
1333
-    public static function get_routes()
1334
-    {
1335
-        return EE_Config::$_module_route_map;
1336
-    }
1337
-
1338
-
1339
-
1340
-    /**
1341
-     *    register_forward - allows modules to forward request to another module for further processing
1342
-     *
1343
-     * @access    public
1344
-     * @param    string       $route   - "pretty" public alias for module method
1345
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1346
-     *                                 class, allows different forwards to be served based on status
1347
-     * @param    array|string $forward - function name or array( class, method )
1348
-     * @param    string       $key     - url param key indicating a route is being called
1349
-     * @return    bool
1350
-     */
1351
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1352
-    {
1353
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1354
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1355
-            $msg = sprintf(
1356
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1357
-                $route
1358
-            );
1359
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
-            return false;
1361
-        }
1362
-        if (empty($forward)) {
1363
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1364
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
-            return false;
1366
-        }
1367
-        if (is_array($forward)) {
1368
-            if (! isset($forward[1])) {
1369
-                $msg = sprintf(
1370
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1371
-                    $route
1372
-                );
1373
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1374
-                return false;
1375
-            }
1376
-            if (! method_exists($forward[0], $forward[1])) {
1377
-                $msg = sprintf(
1378
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1379
-                    $forward[1],
1380
-                    $route
1381
-                );
1382
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1383
-                return false;
1384
-            }
1385
-        } else if (! function_exists($forward)) {
1386
-            $msg = sprintf(
1387
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1388
-                $forward,
1389
-                $route
1390
-            );
1391
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1392
-            return false;
1393
-        }
1394
-        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1395
-        return true;
1396
-    }
1397
-
1398
-
1399
-
1400
-    /**
1401
-     *    get_forward - get forwarding route
1402
-     *
1403
-     * @access    public
1404
-     * @param    string  $route  - "pretty" public alias for module method
1405
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1406
-     *                           allows different forwards to be served based on status
1407
-     * @param    string  $key    - url param key indicating a route is being called
1408
-     * @return    string
1409
-     */
1410
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1411
-    {
1412
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1413
-        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1414
-            return apply_filters(
1415
-                'FHEE__EE_Config__get_forward',
1416
-                EE_Config::$_module_forward_map[$key][$route][$status],
1417
-                $route,
1418
-                $status
1419
-            );
1420
-        }
1421
-        return null;
1422
-    }
1423
-
1424
-
1425
-
1426
-    /**
1427
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1428
-     *    results
1429
-     *
1430
-     * @access    public
1431
-     * @param    string  $route  - "pretty" public alias for module method
1432
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1433
-     *                           allows different views to be served based on status
1434
-     * @param    string  $view
1435
-     * @param    string  $key    - url param key indicating a route is being called
1436
-     * @return    bool
1437
-     */
1438
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1439
-    {
1440
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1441
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1442
-            $msg = sprintf(
1443
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1444
-                $route
1445
-            );
1446
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1447
-            return false;
1448
-        }
1449
-        if (! is_readable($view)) {
1450
-            $msg = sprintf(
1451
-                __(
1452
-                    'The %s view file could not be found or is not readable due to file permissions.',
1453
-                    'event_espresso'
1454
-                ),
1455
-                $view
1456
-            );
1457
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1458
-            return false;
1459
-        }
1460
-        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1461
-        return true;
1462
-    }
1463
-
1464
-
1465
-
1466
-    /**
1467
-     *    get_view - get view for route and status
1468
-     *
1469
-     * @access    public
1470
-     * @param    string  $route  - "pretty" public alias for module method
1471
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1472
-     *                           allows different views to be served based on status
1473
-     * @param    string  $key    - url param key indicating a route is being called
1474
-     * @return    string
1475
-     */
1476
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1477
-    {
1478
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1479
-        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1480
-            return apply_filters(
1481
-                'FHEE__EE_Config__get_view',
1482
-                EE_Config::$_module_view_map[$key][$route][$status],
1483
-                $route,
1484
-                $status
1485
-            );
1486
-        }
1487
-        return null;
1488
-    }
1489
-
1490
-
1491
-
1492
-    public function update_addon_option_names()
1493
-    {
1494
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1495
-    }
1496
-
1497
-
1498
-
1499
-    public function shutdown()
1500
-    {
1501
-        $this->update_addon_option_names();
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * @return LegacyShortcodesManager
1508
-     */
1509
-    public static function getLegacyShortcodesManager()
1510
-    {
1511
-
1512
-        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1513
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1514
-                EE_Registry::instance()
1515
-            );
1516
-        }
1517
-        return EE_Config::instance()->legacy_shortcodes_manager;
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * register_shortcode - makes core aware of this shortcode
1524
-     *
1525
-     * @deprecated 4.9.26
1526
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1527
-     * @return    bool
1528
-     */
1529
-    public static function register_shortcode($shortcode_path = null)
1530
-    {
1531
-        EE_Error::doing_it_wrong(
1532
-            __METHOD__,
1533
-            __(
1534
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1535
-                'event_espresso'
1536
-            ),
1537
-            '4.9.26'
1538
-        );
1539
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1540
-    }
1541
-
1542
-
1543
-
1544
-}
1545
-
1546
-
1547
-
1548
-/**
1549
- * Base class used for config classes. These classes should generally not have
1550
- * magic functions in use, except we'll allow them to magically set and get stuff...
1551
- * basically, they should just be well-defined stdClasses
1552
- */
1553
-class EE_Config_Base
1554
-{
1555
-
1556
-    /**
1557
-     * Utility function for escaping the value of a property and returning.
1558
-     *
1559
-     * @param string $property property name (checks to see if exists).
1560
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1561
-     * @throws \EE_Error
1562
-     */
1563
-    public function get_pretty($property)
1564
-    {
1565
-        if (! property_exists($this, $property)) {
1566
-            throw new EE_Error(
1567
-                sprintf(
1568
-                    __(
1569
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1570
-                        'event_espresso'
1571
-                    ),
1572
-                    get_class($this),
1573
-                    $property
1574
-                )
1575
-            );
1576
-        }
1577
-        //just handling escaping of strings for now.
1578
-        if (is_string($this->{$property})) {
1579
-            return stripslashes($this->{$property});
1580
-        }
1581
-        return $this->{$property};
1582
-    }
1583
-
1584
-
1585
-
1586
-    public function populate()
1587
-    {
1588
-        //grab defaults via a new instance of this class.
1589
-        $class_name = get_class($this);
1590
-        $defaults = new $class_name;
1591
-        //loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1592
-        //default from our $defaults object.
1593
-        foreach (get_object_vars($defaults) as $property => $value) {
1594
-            if ($this->{$property} === null) {
1595
-                $this->{$property} = $value;
1596
-            }
1597
-        }
1598
-        //cleanup
1599
-        unset($defaults);
1600
-    }
1601
-
1602
-
1603
-
1604
-    /**
1605
-     *        __isset
1606
-     *
1607
-     * @param $a
1608
-     * @return bool
1609
-     */
1610
-    public function __isset($a)
1611
-    {
1612
-        return false;
1613
-    }
1614
-
1615
-
1616
-
1617
-    /**
1618
-     *        __unset
1619
-     *
1620
-     * @param $a
1621
-     * @return bool
1622
-     */
1623
-    public function __unset($a)
1624
-    {
1625
-        return false;
1626
-    }
1627
-
1628
-
1629
-
1630
-    /**
1631
-     *        __clone
1632
-     */
1633
-    public function __clone()
1634
-    {
1635
-    }
1636
-
1637
-
1638
-
1639
-    /**
1640
-     *        __wakeup
1641
-     */
1642
-    public function __wakeup()
1643
-    {
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     *        __destruct
1650
-     */
1651
-    public function __destruct()
1652
-    {
1653
-    }
1654
-}
1655
-
1656
-
1657
-
1658
-/**
1659
- * Class for defining what's in the EE_Config relating to registration settings
1660
- */
1661
-class EE_Core_Config extends EE_Config_Base
1662
-{
1663
-
1664
-    public $current_blog_id;
1665
-
1666
-    public $ee_ueip_optin;
1667
-
1668
-    public $ee_ueip_has_notified;
1669
-
1670
-    /**
1671
-     * Not to be confused with the 4 critical page variables (See
1672
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1673
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1674
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1675
-     *
1676
-     * @var array
1677
-     */
1678
-    public $post_shortcodes;
1679
-
1680
-    public $module_route_map;
1681
-
1682
-    public $module_forward_map;
1683
-
1684
-    public $module_view_map;
1685
-
1686
-    /**
1687
-     * The next 4 vars are the IDs of critical EE pages.
1688
-     *
1689
-     * @var int
1690
-     */
1691
-    public $reg_page_id;
1692
-
1693
-    public $txn_page_id;
1694
-
1695
-    public $thank_you_page_id;
1696
-
1697
-    public $cancel_page_id;
1698
-
1699
-    /**
1700
-     * The next 4 vars are the URLs of critical EE pages.
1701
-     *
1702
-     * @var int
1703
-     */
1704
-    public $reg_page_url;
1705
-
1706
-    public $txn_page_url;
1707
-
1708
-    public $thank_you_page_url;
1709
-
1710
-    public $cancel_page_url;
1711
-
1712
-    /**
1713
-     * The next vars relate to the custom slugs for EE CPT routes
1714
-     */
1715
-    public $event_cpt_slug;
1716
-
1717
-
1718
-    /**
1719
-     * This caches the _ee_ueip_option in case this config is reset in the same
1720
-     * request across blog switches in a multisite context.
1721
-     * Avoids extra queries to the db for this option.
1722
-     *
1723
-     * @var bool
1724
-     */
1725
-    public static $ee_ueip_option;
1726
-
1727
-
1728
-
1729
-    /**
1730
-     *    class constructor
1731
-     *
1732
-     * @access    public
1733
-     */
1734
-    public function __construct()
1735
-    {
1736
-        // set default organization settings
1737
-        $this->current_blog_id = get_current_blog_id();
1738
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1739
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1740
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1741
-        $this->post_shortcodes = array();
1742
-        $this->module_route_map = array();
1743
-        $this->module_forward_map = array();
1744
-        $this->module_view_map = array();
1745
-        // critical EE page IDs
1746
-        $this->reg_page_id = 0;
1747
-        $this->txn_page_id = 0;
1748
-        $this->thank_you_page_id = 0;
1749
-        $this->cancel_page_id = 0;
1750
-        // critical EE page URLs
1751
-        $this->reg_page_url = '';
1752
-        $this->txn_page_url = '';
1753
-        $this->thank_you_page_url = '';
1754
-        $this->cancel_page_url = '';
1755
-        //cpt slugs
1756
-        $this->event_cpt_slug = __('events', 'event_espresso');
1757
-        //ueip constant check
1758
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1759
-            $this->ee_ueip_optin = false;
1760
-            $this->ee_ueip_has_notified = true;
1761
-        }
1762
-    }
1763
-
1764
-
1765
-
1766
-    /**
1767
-     * @return array
1768
-     */
1769
-    public function get_critical_pages_array()
1770
-    {
1771
-        return array(
1772
-            $this->reg_page_id,
1773
-            $this->txn_page_id,
1774
-            $this->thank_you_page_id,
1775
-            $this->cancel_page_id,
1776
-        );
1777
-    }
1778
-
1779
-
1780
-
1781
-    /**
1782
-     * @return array
1783
-     */
1784
-    public function get_critical_pages_shortcodes_array()
1785
-    {
1786
-        return array(
1787
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1788
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1789
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1790
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1791
-        );
1792
-    }
1793
-
1794
-
1795
-
1796
-    /**
1797
-     *  gets/returns URL for EE reg_page
1798
-     *
1799
-     * @access    public
1800
-     * @return    string
1801
-     */
1802
-    public function reg_page_url()
1803
-    {
1804
-        if (! $this->reg_page_url) {
1805
-            $this->reg_page_url = add_query_arg(
1806
-                                      array('uts' => time()),
1807
-                                      get_permalink($this->reg_page_id)
1808
-                                  ) . '#checkout';
1809
-        }
1810
-        return $this->reg_page_url;
1811
-    }
1812
-
1813
-
1814
-
1815
-    /**
1816
-     *  gets/returns URL for EE txn_page
1817
-     *
1818
-     * @param array $query_args like what gets passed to
1819
-     *                          add_query_arg() as the first argument
1820
-     * @access    public
1821
-     * @return    string
1822
-     */
1823
-    public function txn_page_url($query_args = array())
1824
-    {
1825
-        if (! $this->txn_page_url) {
1826
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1827
-        }
1828
-        if ($query_args) {
1829
-            return add_query_arg($query_args, $this->txn_page_url);
1830
-        } else {
1831
-            return $this->txn_page_url;
1832
-        }
1833
-    }
1834
-
1835
-
1836
-
1837
-    /**
1838
-     *  gets/returns URL for EE thank_you_page
1839
-     *
1840
-     * @param array $query_args like what gets passed to
1841
-     *                          add_query_arg() as the first argument
1842
-     * @access    public
1843
-     * @return    string
1844
-     */
1845
-    public function thank_you_page_url($query_args = array())
1846
-    {
1847
-        if (! $this->thank_you_page_url) {
1848
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1849
-        }
1850
-        if ($query_args) {
1851
-            return add_query_arg($query_args, $this->thank_you_page_url);
1852
-        } else {
1853
-            return $this->thank_you_page_url;
1854
-        }
1855
-    }
1856
-
1857
-
1858
-
1859
-    /**
1860
-     *  gets/returns URL for EE cancel_page
1861
-     *
1862
-     * @access    public
1863
-     * @return    string
1864
-     */
1865
-    public function cancel_page_url()
1866
-    {
1867
-        if (! $this->cancel_page_url) {
1868
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1869
-        }
1870
-        return $this->cancel_page_url;
1871
-    }
1872
-
1873
-
1874
-
1875
-    /**
1876
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
-     *
1878
-     * @since 4.7.5
1879
-     */
1880
-    protected function _reset_urls()
1881
-    {
1882
-        $this->reg_page_url = '';
1883
-        $this->txn_page_url = '';
1884
-        $this->cancel_page_url = '';
1885
-        $this->thank_you_page_url = '';
1886
-    }
1887
-
1888
-
1889
-
1890
-    /**
1891
-     * Used to return what the optin value is set for the EE User Experience Program.
1892
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1893
-     * on the main site only.
1894
-     *
1895
-     * @return mixed|void
1896
-     */
1897
-    protected function _get_main_ee_ueip_optin()
1898
-    {
1899
-        //if this is the main site then we can just bypass our direct query.
1900
-        if (is_main_site()) {
1901
-            return get_option('ee_ueip_optin', false);
1902
-        }
1903
-        //is this already cached for this request?  If so use it.
1904
-        if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1905
-            return EE_Core_Config::$ee_ueip_option;
1906
-        }
1907
-        global $wpdb;
1908
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1909
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1910
-        $option = 'ee_ueip_optin';
1911
-        //set correct table for query
1912
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1913
-        //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1914
-        //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1915
-        //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1916
-        //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1917
-        //for the purpose of caching.
1918
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1919
-        if (false !== $pre) {
1920
-            EE_Core_Config::$ee_ueip_option = $pre;
1921
-            return EE_Core_Config::$ee_ueip_option;
1922
-        }
1923
-        $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1924
-            $option));
1925
-        if (is_object($row)) {
1926
-            $value = $row->option_value;
1927
-        } else { //option does not exist so use default.
1928
-            return apply_filters('default_option_' . $option, false, $option);
1929
-        }
1930
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1931
-        return EE_Core_Config::$ee_ueip_option;
1932
-    }
1933
-
1934
-    /**
1935
-     * Utility function for escaping the value of a property and returning.
1936
-     *
1937
-     * @param string $property property name (checks to see if exists).
1938
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1939
-     * @throws \EE_Error
1940
-     */
1941
-    public function get_pretty($property)
1942
-    {
1943
-        if ($property === 'ee_ueip_optin') {
1944
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1945
-        }
1946
-        return parent::get_pretty($property);
1947
-    }
1948
-
1949
-
1950
-    /**
1951
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1952
-     * on the object.
1953
-     *
1954
-     * @return array
1955
-     */
1956
-    public function __sleep()
1957
-    {
1958
-        //reset all url properties
1959
-        $this->_reset_urls();
1960
-        //return what to save to db
1961
-        return array_keys(get_object_vars($this));
1962
-    }
1963
-
1964
-}
1965
-
1966
-
1967
-
1968
-/**
1969
- * Config class for storing info on the Organization
1970
- */
1971
-class EE_Organization_Config extends EE_Config_Base
1972
-{
1973
-
1974
-    /**
1975
-     * @var string $name
1976
-     * eg EE4.1
1977
-     */
1978
-    public $name;
1979
-
1980
-    /**
1981
-     * @var string $address_1
1982
-     * eg 123 Onna Road
1983
-     */
1984
-    public $address_1;
1985
-
1986
-    /**
1987
-     * @var string $address_2
1988
-     * eg PO Box 123
1989
-     */
1990
-    public $address_2;
1991
-
1992
-    /**
1993
-     * @var string $city
1994
-     * eg Inna City
1995
-     */
1996
-    public $city;
1997
-
1998
-    /**
1999
-     * @var int $STA_ID
2000
-     * eg 4
2001
-     */
2002
-    public $STA_ID;
2003
-
2004
-    /**
2005
-     * @var string $CNT_ISO
2006
-     * eg US
2007
-     */
2008
-    public $CNT_ISO;
2009
-
2010
-    /**
2011
-     * @var string $zip
2012
-     * eg 12345  or V1A 2B3
2013
-     */
2014
-    public $zip;
2015
-
2016
-    /**
2017
-     * @var string $email
2018
-     * eg [email protected]
2019
-     */
2020
-    public $email;
2021
-
2022
-
2023
-    /**
2024
-     * @var string $phone
2025
-     * eg. 111-111-1111
2026
-     */
2027
-    public $phone;
2028
-
2029
-
2030
-    /**
2031
-     * @var string $vat
2032
-     * VAT/Tax Number
2033
-     */
2034
-    public $vat;
2035
-
2036
-    /**
2037
-     * @var string $logo_url
2038
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2039
-     */
2040
-    public $logo_url;
2041
-
2042
-
2043
-    /**
2044
-     * The below are all various properties for holding links to organization social network profiles
2045
-     *
2046
-     * @var string
2047
-     */
2048
-    /**
2049
-     * facebook (facebook.com/profile.name)
2050
-     *
2051
-     * @var string
2052
-     */
2053
-    public $facebook;
2054
-
2055
-
2056
-    /**
2057
-     * twitter (twitter.com/twitter_handle)
2058
-     *
2059
-     * @var string
2060
-     */
2061
-    public $twitter;
2062
-
2063
-
2064
-    /**
2065
-     * linkedin (linkedin.com/in/profile_name)
2066
-     *
2067
-     * @var string
2068
-     */
2069
-    public $linkedin;
2070
-
2071
-
2072
-    /**
2073
-     * pinterest (www.pinterest.com/profile_name)
2074
-     *
2075
-     * @var string
2076
-     */
2077
-    public $pinterest;
2078
-
2079
-
2080
-    /**
2081
-     * google+ (google.com/+profileName)
2082
-     *
2083
-     * @var string
2084
-     */
2085
-    public $google;
2086
-
2087
-
2088
-    /**
2089
-     * instagram (instagram.com/handle)
2090
-     *
2091
-     * @var string
2092
-     */
2093
-    public $instagram;
2094
-
2095
-
2096
-
2097
-    /**
2098
-     *    class constructor
2099
-     *
2100
-     * @access    public
2101
-     */
2102
-    public function __construct()
2103
-    {
2104
-        // set default organization settings
2105
-        //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2106
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2107
-        $this->address_1 = '123 Onna Road';
2108
-        $this->address_2 = 'PO Box 123';
2109
-        $this->city = 'Inna City';
2110
-        $this->STA_ID = 4;
2111
-        $this->CNT_ISO = 'US';
2112
-        $this->zip = '12345';
2113
-        $this->email = get_bloginfo('admin_email');
2114
-        $this->phone = '';
2115
-        $this->vat = '123456789';
2116
-        $this->logo_url = '';
2117
-        $this->facebook = '';
2118
-        $this->twitter = '';
2119
-        $this->linkedin = '';
2120
-        $this->pinterest = '';
2121
-        $this->google = '';
2122
-        $this->instagram = '';
2123
-    }
2124
-
2125
-}
2126
-
2127
-
2128
-
2129
-/**
2130
- * Class for defining what's in the EE_Config relating to currency
2131
- */
2132
-class EE_Currency_Config extends EE_Config_Base
2133
-{
2134
-
2135
-    /**
2136
-     * @var string $code
2137
-     * eg 'US'
2138
-     */
2139
-    public $code;
2140
-
2141
-    /**
2142
-     * @var string $name
2143
-     * eg 'Dollar'
2144
-     */
2145
-    public $name;
2146
-
2147
-    /**
2148
-     * plural name
2149
-     *
2150
-     * @var string $plural
2151
-     * eg 'Dollars'
2152
-     */
2153
-    public $plural;
2154
-
2155
-    /**
2156
-     * currency sign
2157
-     *
2158
-     * @var string $sign
2159
-     * eg '$'
2160
-     */
2161
-    public $sign;
2162
-
2163
-    /**
2164
-     * Whether the currency sign should come before the number or not
2165
-     *
2166
-     * @var boolean $sign_b4
2167
-     */
2168
-    public $sign_b4;
2169
-
2170
-    /**
2171
-     * How many digits should come after the decimal place
2172
-     *
2173
-     * @var int $dec_plc
2174
-     */
2175
-    public $dec_plc;
2176
-
2177
-    /**
2178
-     * Symbol to use for decimal mark
2179
-     *
2180
-     * @var string $dec_mrk
2181
-     * eg '.'
2182
-     */
2183
-    public $dec_mrk;
2184
-
2185
-    /**
2186
-     * Symbol to use for thousands
2187
-     *
2188
-     * @var string $thsnds
2189
-     * eg ','
2190
-     */
2191
-    public $thsnds;
2192
-
2193
-
2194
-
2195
-    /**
2196
-     *    class constructor
2197
-     *
2198
-     * @access    public
2199
-     * @param string $CNT_ISO
2200
-     * @throws \EE_Error
2201
-     */
2202
-    public function __construct($CNT_ISO = '')
2203
-    {
2204
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2205
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2206
-        // get country code from organization settings or use default
2207
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2208
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2209
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2210
-            : '';
2211
-        // but override if requested
2212
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2213
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2214
-        if (
2215
-            ! empty($CNT_ISO)
2216
-            && EE_Maintenance_Mode::instance()->models_can_query()
2217
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2218
-        ) {
2219
-            // retrieve the country settings from the db, just in case they have been customized
2220
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2221
-            if ($country instanceof EE_Country) {
2222
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2223
-                $this->name = $country->currency_name_single();    // Dollar
2224
-                $this->plural = $country->currency_name_plural();    // Dollars
2225
-                $this->sign = $country->currency_sign();            // currency sign: $
2226
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2227
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2228
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2229
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2230
-            }
2231
-        }
2232
-        // fallback to hardcoded defaults, in case the above failed
2233
-        if (empty($this->code)) {
2234
-            // set default currency settings
2235
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2236
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2237
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2238
-            $this->sign = '$';    // currency sign: $
2239
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2240
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2241
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2242
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2243
-        }
2244
-    }
2245
-}
2246
-
2247
-
2248
-
2249
-/**
2250
- * Class for defining what's in the EE_Config relating to registration settings
2251
- */
2252
-class EE_Registration_Config extends EE_Config_Base
2253
-{
2254
-
2255
-    /**
2256
-     * Default registration status
2257
-     *
2258
-     * @var string $default_STS_ID
2259
-     * eg 'RPP'
2260
-     */
2261
-    public $default_STS_ID;
2262
-
2263
-
2264
-    /**
2265
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2266
-     * registrations)
2267
-     * @var int
2268
-     */
2269
-    public $default_maximum_number_of_tickets;
2270
-
2271
-
2272
-    /**
2273
-     * level of validation to apply to email addresses
2274
-     *
2275
-     * @var string $email_validation_level
2276
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2277
-     */
2278
-    public $email_validation_level;
2279
-
2280
-    /**
2281
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2282
-     *
2283
-     * @var boolean $show_pending_payment_options
2284
-     */
2285
-    public $show_pending_payment_options;
2286
-
2287
-    /**
2288
-     * Whether to skip the registration confirmation page
2289
-     *
2290
-     * @var boolean $skip_reg_confirmation
2291
-     */
2292
-    public $skip_reg_confirmation;
2293
-
2294
-    /**
2295
-     * an array of SPCO reg steps where:
2296
-     *        the keys denotes the reg step order
2297
-     *        each element consists of an array with the following elements:
2298
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2299
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2300
-     *            "slug" => the URL param used to trigger the reg step
2301
-     *
2302
-     * @var array $reg_steps
2303
-     */
2304
-    public $reg_steps;
2305
-
2306
-    /**
2307
-     * Whether registration confirmation should be the last page of SPCO
2308
-     *
2309
-     * @var boolean $reg_confirmation_last
2310
-     */
2311
-    public $reg_confirmation_last;
2312
-
2313
-    /**
2314
-     * Whether or not to enable the EE Bot Trap
2315
-     *
2316
-     * @var boolean $use_bot_trap
2317
-     */
2318
-    public $use_bot_trap;
2319
-
2320
-    /**
2321
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2322
-     *
2323
-     * @var boolean $use_encryption
2324
-     */
2325
-    public $use_encryption;
2326
-
2327
-    /**
2328
-     * Whether or not to use ReCaptcha
2329
-     *
2330
-     * @var boolean $use_captcha
2331
-     */
2332
-    public $use_captcha;
2333
-
2334
-    /**
2335
-     * ReCaptcha Theme
2336
-     *
2337
-     * @var string $recaptcha_theme
2338
-     *    options: 'dark', 'light', 'invisible'
2339
-     */
2340
-    public $recaptcha_theme;
1544
+}
2341 1545
 
2342
-    /**
2343
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2344
-     *
2345
-     * @var string $recaptcha_badge
2346
-     *    options: 'bottomright', 'bottomleft', 'inline'
2347
-     */
2348
-    public $recaptcha_badge;
2349 1546
 
2350
-    /**
2351
-     * ReCaptcha Type
2352
-     *
2353
-     * @var string $recaptcha_type
2354
-     *    options: 'audio', 'image'
2355
-     */
2356
-    public $recaptcha_type;
2357 1547
 
2358
-    /**
2359
-     * ReCaptcha language
2360
-     *
2361
-     * @var string $recaptcha_language
2362
-     * eg 'en'
2363
-     */
2364
-    public $recaptcha_language;
1548
+/**
1549
+ * Base class used for config classes. These classes should generally not have
1550
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1551
+ * basically, they should just be well-defined stdClasses
1552
+ */
1553
+class EE_Config_Base
1554
+{
2365 1555
 
2366
-    /**
2367
-     * ReCaptcha public key
2368
-     *
2369
-     * @var string $recaptcha_publickey
2370
-     */
2371
-    public $recaptcha_publickey;
1556
+	/**
1557
+	 * Utility function for escaping the value of a property and returning.
1558
+	 *
1559
+	 * @param string $property property name (checks to see if exists).
1560
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1561
+	 * @throws \EE_Error
1562
+	 */
1563
+	public function get_pretty($property)
1564
+	{
1565
+		if (! property_exists($this, $property)) {
1566
+			throw new EE_Error(
1567
+				sprintf(
1568
+					__(
1569
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1570
+						'event_espresso'
1571
+					),
1572
+					get_class($this),
1573
+					$property
1574
+				)
1575
+			);
1576
+		}
1577
+		//just handling escaping of strings for now.
1578
+		if (is_string($this->{$property})) {
1579
+			return stripslashes($this->{$property});
1580
+		}
1581
+		return $this->{$property};
1582
+	}
1583
+
1584
+
1585
+
1586
+	public function populate()
1587
+	{
1588
+		//grab defaults via a new instance of this class.
1589
+		$class_name = get_class($this);
1590
+		$defaults = new $class_name;
1591
+		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1592
+		//default from our $defaults object.
1593
+		foreach (get_object_vars($defaults) as $property => $value) {
1594
+			if ($this->{$property} === null) {
1595
+				$this->{$property} = $value;
1596
+			}
1597
+		}
1598
+		//cleanup
1599
+		unset($defaults);
1600
+	}
1601
+
1602
+
1603
+
1604
+	/**
1605
+	 *        __isset
1606
+	 *
1607
+	 * @param $a
1608
+	 * @return bool
1609
+	 */
1610
+	public function __isset($a)
1611
+	{
1612
+		return false;
1613
+	}
1614
+
1615
+
1616
+
1617
+	/**
1618
+	 *        __unset
1619
+	 *
1620
+	 * @param $a
1621
+	 * @return bool
1622
+	 */
1623
+	public function __unset($a)
1624
+	{
1625
+		return false;
1626
+	}
1627
+
1628
+
1629
+
1630
+	/**
1631
+	 *        __clone
1632
+	 */
1633
+	public function __clone()
1634
+	{
1635
+	}
1636
+
1637
+
1638
+
1639
+	/**
1640
+	 *        __wakeup
1641
+	 */
1642
+	public function __wakeup()
1643
+	{
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 *        __destruct
1650
+	 */
1651
+	public function __destruct()
1652
+	{
1653
+	}
1654
+}
2372 1655
 
2373
-    /**
2374
-     * ReCaptcha private key
2375
-     *
2376
-     * @var string $recaptcha_privatekey
2377
-     */
2378
-    public $recaptcha_privatekey;
2379 1656
 
2380
-    /**
2381
-     * array of form names protected by ReCaptcha
2382
-     *
2383
-     * @var array $recaptcha_protected_forms
2384
-     */
2385
-    public $recaptcha_protected_forms;
2386 1657
 
2387
-    /**
2388
-     * ReCaptcha width
2389
-     *
2390
-     * @var int $recaptcha_width
2391
-     * @deprecated
2392
-     */
2393
-    public $recaptcha_width;
1658
+/**
1659
+ * Class for defining what's in the EE_Config relating to registration settings
1660
+ */
1661
+class EE_Core_Config extends EE_Config_Base
1662
+{
2394 1663
 
2395
-    /**
2396
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2397
-     *
2398
-     * @var boolean $track_invalid_checkout_access
2399
-     */
2400
-    protected $track_invalid_checkout_access = true;
1664
+	public $current_blog_id;
1665
+
1666
+	public $ee_ueip_optin;
1667
+
1668
+	public $ee_ueip_has_notified;
1669
+
1670
+	/**
1671
+	 * Not to be confused with the 4 critical page variables (See
1672
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1673
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1674
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1675
+	 *
1676
+	 * @var array
1677
+	 */
1678
+	public $post_shortcodes;
1679
+
1680
+	public $module_route_map;
1681
+
1682
+	public $module_forward_map;
1683
+
1684
+	public $module_view_map;
1685
+
1686
+	/**
1687
+	 * The next 4 vars are the IDs of critical EE pages.
1688
+	 *
1689
+	 * @var int
1690
+	 */
1691
+	public $reg_page_id;
1692
+
1693
+	public $txn_page_id;
1694
+
1695
+	public $thank_you_page_id;
1696
+
1697
+	public $cancel_page_id;
1698
+
1699
+	/**
1700
+	 * The next 4 vars are the URLs of critical EE pages.
1701
+	 *
1702
+	 * @var int
1703
+	 */
1704
+	public $reg_page_url;
1705
+
1706
+	public $txn_page_url;
1707
+
1708
+	public $thank_you_page_url;
1709
+
1710
+	public $cancel_page_url;
1711
+
1712
+	/**
1713
+	 * The next vars relate to the custom slugs for EE CPT routes
1714
+	 */
1715
+	public $event_cpt_slug;
1716
+
1717
+
1718
+	/**
1719
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1720
+	 * request across blog switches in a multisite context.
1721
+	 * Avoids extra queries to the db for this option.
1722
+	 *
1723
+	 * @var bool
1724
+	 */
1725
+	public static $ee_ueip_option;
1726
+
1727
+
1728
+
1729
+	/**
1730
+	 *    class constructor
1731
+	 *
1732
+	 * @access    public
1733
+	 */
1734
+	public function __construct()
1735
+	{
1736
+		// set default organization settings
1737
+		$this->current_blog_id = get_current_blog_id();
1738
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1739
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1740
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1741
+		$this->post_shortcodes = array();
1742
+		$this->module_route_map = array();
1743
+		$this->module_forward_map = array();
1744
+		$this->module_view_map = array();
1745
+		// critical EE page IDs
1746
+		$this->reg_page_id = 0;
1747
+		$this->txn_page_id = 0;
1748
+		$this->thank_you_page_id = 0;
1749
+		$this->cancel_page_id = 0;
1750
+		// critical EE page URLs
1751
+		$this->reg_page_url = '';
1752
+		$this->txn_page_url = '';
1753
+		$this->thank_you_page_url = '';
1754
+		$this->cancel_page_url = '';
1755
+		//cpt slugs
1756
+		$this->event_cpt_slug = __('events', 'event_espresso');
1757
+		//ueip constant check
1758
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1759
+			$this->ee_ueip_optin = false;
1760
+			$this->ee_ueip_has_notified = true;
1761
+		}
1762
+	}
1763
+
1764
+
1765
+
1766
+	/**
1767
+	 * @return array
1768
+	 */
1769
+	public function get_critical_pages_array()
1770
+	{
1771
+		return array(
1772
+			$this->reg_page_id,
1773
+			$this->txn_page_id,
1774
+			$this->thank_you_page_id,
1775
+			$this->cancel_page_id,
1776
+		);
1777
+	}
1778
+
1779
+
1780
+
1781
+	/**
1782
+	 * @return array
1783
+	 */
1784
+	public function get_critical_pages_shortcodes_array()
1785
+	{
1786
+		return array(
1787
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1788
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1789
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1790
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1791
+		);
1792
+	}
1793
+
1794
+
1795
+
1796
+	/**
1797
+	 *  gets/returns URL for EE reg_page
1798
+	 *
1799
+	 * @access    public
1800
+	 * @return    string
1801
+	 */
1802
+	public function reg_page_url()
1803
+	{
1804
+		if (! $this->reg_page_url) {
1805
+			$this->reg_page_url = add_query_arg(
1806
+									  array('uts' => time()),
1807
+									  get_permalink($this->reg_page_id)
1808
+								  ) . '#checkout';
1809
+		}
1810
+		return $this->reg_page_url;
1811
+	}
1812
+
1813
+
1814
+
1815
+	/**
1816
+	 *  gets/returns URL for EE txn_page
1817
+	 *
1818
+	 * @param array $query_args like what gets passed to
1819
+	 *                          add_query_arg() as the first argument
1820
+	 * @access    public
1821
+	 * @return    string
1822
+	 */
1823
+	public function txn_page_url($query_args = array())
1824
+	{
1825
+		if (! $this->txn_page_url) {
1826
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1827
+		}
1828
+		if ($query_args) {
1829
+			return add_query_arg($query_args, $this->txn_page_url);
1830
+		} else {
1831
+			return $this->txn_page_url;
1832
+		}
1833
+	}
1834
+
1835
+
1836
+
1837
+	/**
1838
+	 *  gets/returns URL for EE thank_you_page
1839
+	 *
1840
+	 * @param array $query_args like what gets passed to
1841
+	 *                          add_query_arg() as the first argument
1842
+	 * @access    public
1843
+	 * @return    string
1844
+	 */
1845
+	public function thank_you_page_url($query_args = array())
1846
+	{
1847
+		if (! $this->thank_you_page_url) {
1848
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1849
+		}
1850
+		if ($query_args) {
1851
+			return add_query_arg($query_args, $this->thank_you_page_url);
1852
+		} else {
1853
+			return $this->thank_you_page_url;
1854
+		}
1855
+	}
1856
+
1857
+
1858
+
1859
+	/**
1860
+	 *  gets/returns URL for EE cancel_page
1861
+	 *
1862
+	 * @access    public
1863
+	 * @return    string
1864
+	 */
1865
+	public function cancel_page_url()
1866
+	{
1867
+		if (! $this->cancel_page_url) {
1868
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1869
+		}
1870
+		return $this->cancel_page_url;
1871
+	}
1872
+
1873
+
1874
+
1875
+	/**
1876
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
+	 *
1878
+	 * @since 4.7.5
1879
+	 */
1880
+	protected function _reset_urls()
1881
+	{
1882
+		$this->reg_page_url = '';
1883
+		$this->txn_page_url = '';
1884
+		$this->cancel_page_url = '';
1885
+		$this->thank_you_page_url = '';
1886
+	}
1887
+
1888
+
1889
+
1890
+	/**
1891
+	 * Used to return what the optin value is set for the EE User Experience Program.
1892
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1893
+	 * on the main site only.
1894
+	 *
1895
+	 * @return mixed|void
1896
+	 */
1897
+	protected function _get_main_ee_ueip_optin()
1898
+	{
1899
+		//if this is the main site then we can just bypass our direct query.
1900
+		if (is_main_site()) {
1901
+			return get_option('ee_ueip_optin', false);
1902
+		}
1903
+		//is this already cached for this request?  If so use it.
1904
+		if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1905
+			return EE_Core_Config::$ee_ueip_option;
1906
+		}
1907
+		global $wpdb;
1908
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1909
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1910
+		$option = 'ee_ueip_optin';
1911
+		//set correct table for query
1912
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1913
+		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1914
+		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1915
+		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1916
+		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1917
+		//for the purpose of caching.
1918
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1919
+		if (false !== $pre) {
1920
+			EE_Core_Config::$ee_ueip_option = $pre;
1921
+			return EE_Core_Config::$ee_ueip_option;
1922
+		}
1923
+		$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1924
+			$option));
1925
+		if (is_object($row)) {
1926
+			$value = $row->option_value;
1927
+		} else { //option does not exist so use default.
1928
+			return apply_filters('default_option_' . $option, false, $option);
1929
+		}
1930
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1931
+		return EE_Core_Config::$ee_ueip_option;
1932
+	}
1933
+
1934
+	/**
1935
+	 * Utility function for escaping the value of a property and returning.
1936
+	 *
1937
+	 * @param string $property property name (checks to see if exists).
1938
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1939
+	 * @throws \EE_Error
1940
+	 */
1941
+	public function get_pretty($property)
1942
+	{
1943
+		if ($property === 'ee_ueip_optin') {
1944
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1945
+		}
1946
+		return parent::get_pretty($property);
1947
+	}
1948
+
1949
+
1950
+	/**
1951
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1952
+	 * on the object.
1953
+	 *
1954
+	 * @return array
1955
+	 */
1956
+	public function __sleep()
1957
+	{
1958
+		//reset all url properties
1959
+		$this->_reset_urls();
1960
+		//return what to save to db
1961
+		return array_keys(get_object_vars($this));
1962
+	}
2401 1963
 
1964
+}
2402 1965
 
2403 1966
 
2404
-    /**
2405
-     *    class constructor
2406
-     *
2407
-     * @access    public
2408
-     */
2409
-    public function __construct()
2410
-    {
2411
-        // set default registration settings
2412
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2413
-        $this->email_validation_level = 'wp_default';
2414
-        $this->show_pending_payment_options = true;
2415
-        $this->skip_reg_confirmation = true;
2416
-        $this->reg_steps = array();
2417
-        $this->reg_confirmation_last = false;
2418
-        $this->use_bot_trap = true;
2419
-        $this->use_encryption = true;
2420
-        $this->use_captcha = false;
2421
-        $this->recaptcha_theme = 'light';
2422
-        $this->recaptcha_badge = 'bottomleft';
2423
-        $this->recaptcha_type = 'image';
2424
-        $this->recaptcha_language = 'en';
2425
-        $this->recaptcha_publickey = null;
2426
-        $this->recaptcha_privatekey = null;
2427
-        $this->recaptcha_protected_forms = array();
2428
-        $this->recaptcha_width = 500;
2429
-        $this->default_maximum_number_of_tickets = 10;
2430
-    }
2431
-
2432
-
2433
-
2434
-    /**
2435
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2436
-     *
2437
-     * @since 4.8.8.rc.019
2438
-     */
2439
-    public function do_hooks()
2440
-    {
2441
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2442
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2443
-    }
2444 1967
 
1968
+/**
1969
+ * Config class for storing info on the Organization
1970
+ */
1971
+class EE_Organization_Config extends EE_Config_Base
1972
+{
2445 1973
 
1974
+	/**
1975
+	 * @var string $name
1976
+	 * eg EE4.1
1977
+	 */
1978
+	public $name;
1979
+
1980
+	/**
1981
+	 * @var string $address_1
1982
+	 * eg 123 Onna Road
1983
+	 */
1984
+	public $address_1;
1985
+
1986
+	/**
1987
+	 * @var string $address_2
1988
+	 * eg PO Box 123
1989
+	 */
1990
+	public $address_2;
1991
+
1992
+	/**
1993
+	 * @var string $city
1994
+	 * eg Inna City
1995
+	 */
1996
+	public $city;
1997
+
1998
+	/**
1999
+	 * @var int $STA_ID
2000
+	 * eg 4
2001
+	 */
2002
+	public $STA_ID;
2003
+
2004
+	/**
2005
+	 * @var string $CNT_ISO
2006
+	 * eg US
2007
+	 */
2008
+	public $CNT_ISO;
2009
+
2010
+	/**
2011
+	 * @var string $zip
2012
+	 * eg 12345  or V1A 2B3
2013
+	 */
2014
+	public $zip;
2015
+
2016
+	/**
2017
+	 * @var string $email
2018
+	 * eg [email protected]
2019
+	 */
2020
+	public $email;
2021
+
2022
+
2023
+	/**
2024
+	 * @var string $phone
2025
+	 * eg. 111-111-1111
2026
+	 */
2027
+	public $phone;
2028
+
2029
+
2030
+	/**
2031
+	 * @var string $vat
2032
+	 * VAT/Tax Number
2033
+	 */
2034
+	public $vat;
2035
+
2036
+	/**
2037
+	 * @var string $logo_url
2038
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2039
+	 */
2040
+	public $logo_url;
2041
+
2042
+
2043
+	/**
2044
+	 * The below are all various properties for holding links to organization social network profiles
2045
+	 *
2046
+	 * @var string
2047
+	 */
2048
+	/**
2049
+	 * facebook (facebook.com/profile.name)
2050
+	 *
2051
+	 * @var string
2052
+	 */
2053
+	public $facebook;
2054
+
2055
+
2056
+	/**
2057
+	 * twitter (twitter.com/twitter_handle)
2058
+	 *
2059
+	 * @var string
2060
+	 */
2061
+	public $twitter;
2062
+
2063
+
2064
+	/**
2065
+	 * linkedin (linkedin.com/in/profile_name)
2066
+	 *
2067
+	 * @var string
2068
+	 */
2069
+	public $linkedin;
2070
+
2071
+
2072
+	/**
2073
+	 * pinterest (www.pinterest.com/profile_name)
2074
+	 *
2075
+	 * @var string
2076
+	 */
2077
+	public $pinterest;
2078
+
2079
+
2080
+	/**
2081
+	 * google+ (google.com/+profileName)
2082
+	 *
2083
+	 * @var string
2084
+	 */
2085
+	public $google;
2086
+
2087
+
2088
+	/**
2089
+	 * instagram (instagram.com/handle)
2090
+	 *
2091
+	 * @var string
2092
+	 */
2093
+	public $instagram;
2094
+
2095
+
2096
+
2097
+	/**
2098
+	 *    class constructor
2099
+	 *
2100
+	 * @access    public
2101
+	 */
2102
+	public function __construct()
2103
+	{
2104
+		// set default organization settings
2105
+		//decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2106
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2107
+		$this->address_1 = '123 Onna Road';
2108
+		$this->address_2 = 'PO Box 123';
2109
+		$this->city = 'Inna City';
2110
+		$this->STA_ID = 4;
2111
+		$this->CNT_ISO = 'US';
2112
+		$this->zip = '12345';
2113
+		$this->email = get_bloginfo('admin_email');
2114
+		$this->phone = '';
2115
+		$this->vat = '123456789';
2116
+		$this->logo_url = '';
2117
+		$this->facebook = '';
2118
+		$this->twitter = '';
2119
+		$this->linkedin = '';
2120
+		$this->pinterest = '';
2121
+		$this->google = '';
2122
+		$this->instagram = '';
2123
+	}
2446 2124
 
2447
-    /**
2448
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2449
-     * field matches the config setting for default_STS_ID.
2450
-     */
2451
-    public function set_default_reg_status_on_EEM_Event()
2452
-    {
2453
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2454
-    }
2125
+}
2455 2126
 
2456 2127
 
2457
-    /**
2458
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2459
-     * for Events matches the config setting for default_maximum_number_of_tickets
2460
-     */
2461
-    public function set_default_max_ticket_on_EEM_Event()
2462
-    {
2463
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2464
-    }
2465 2128
 
2129
+/**
2130
+ * Class for defining what's in the EE_Config relating to currency
2131
+ */
2132
+class EE_Currency_Config extends EE_Config_Base
2133
+{
2466 2134
 
2135
+	/**
2136
+	 * @var string $code
2137
+	 * eg 'US'
2138
+	 */
2139
+	public $code;
2140
+
2141
+	/**
2142
+	 * @var string $name
2143
+	 * eg 'Dollar'
2144
+	 */
2145
+	public $name;
2146
+
2147
+	/**
2148
+	 * plural name
2149
+	 *
2150
+	 * @var string $plural
2151
+	 * eg 'Dollars'
2152
+	 */
2153
+	public $plural;
2154
+
2155
+	/**
2156
+	 * currency sign
2157
+	 *
2158
+	 * @var string $sign
2159
+	 * eg '$'
2160
+	 */
2161
+	public $sign;
2162
+
2163
+	/**
2164
+	 * Whether the currency sign should come before the number or not
2165
+	 *
2166
+	 * @var boolean $sign_b4
2167
+	 */
2168
+	public $sign_b4;
2169
+
2170
+	/**
2171
+	 * How many digits should come after the decimal place
2172
+	 *
2173
+	 * @var int $dec_plc
2174
+	 */
2175
+	public $dec_plc;
2176
+
2177
+	/**
2178
+	 * Symbol to use for decimal mark
2179
+	 *
2180
+	 * @var string $dec_mrk
2181
+	 * eg '.'
2182
+	 */
2183
+	public $dec_mrk;
2184
+
2185
+	/**
2186
+	 * Symbol to use for thousands
2187
+	 *
2188
+	 * @var string $thsnds
2189
+	 * eg ','
2190
+	 */
2191
+	public $thsnds;
2192
+
2193
+
2194
+
2195
+	/**
2196
+	 *    class constructor
2197
+	 *
2198
+	 * @access    public
2199
+	 * @param string $CNT_ISO
2200
+	 * @throws \EE_Error
2201
+	 */
2202
+	public function __construct($CNT_ISO = '')
2203
+	{
2204
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2205
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2206
+		// get country code from organization settings or use default
2207
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2208
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2209
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2210
+			: '';
2211
+		// but override if requested
2212
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2213
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2214
+		if (
2215
+			! empty($CNT_ISO)
2216
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2217
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2218
+		) {
2219
+			// retrieve the country settings from the db, just in case they have been customized
2220
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2221
+			if ($country instanceof EE_Country) {
2222
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2223
+				$this->name = $country->currency_name_single();    // Dollar
2224
+				$this->plural = $country->currency_name_plural();    // Dollars
2225
+				$this->sign = $country->currency_sign();            // currency sign: $
2226
+				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2227
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2228
+				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2229
+				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2230
+			}
2231
+		}
2232
+		// fallback to hardcoded defaults, in case the above failed
2233
+		if (empty($this->code)) {
2234
+			// set default currency settings
2235
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2236
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2237
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2238
+			$this->sign = '$';    // currency sign: $
2239
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2240
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2241
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2242
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2243
+		}
2244
+	}
2245
+}
2467 2246
 
2468
-    /**
2469
-     * @return boolean
2470
-     */
2471
-    public function track_invalid_checkout_access()
2472
-    {
2473
-        return $this->track_invalid_checkout_access;
2474
-    }
2475 2247
 
2476 2248
 
2249
+/**
2250
+ * Class for defining what's in the EE_Config relating to registration settings
2251
+ */
2252
+class EE_Registration_Config extends EE_Config_Base
2253
+{
2477 2254
 
2478
-    /**
2479
-     * @param boolean $track_invalid_checkout_access
2480
-     */
2481
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2482
-    {
2483
-        $this->track_invalid_checkout_access = filter_var(
2484
-            $track_invalid_checkout_access,
2485
-            FILTER_VALIDATE_BOOLEAN
2486
-        );
2487
-    }
2255
+	/**
2256
+	 * Default registration status
2257
+	 *
2258
+	 * @var string $default_STS_ID
2259
+	 * eg 'RPP'
2260
+	 */
2261
+	public $default_STS_ID;
2262
+
2263
+
2264
+	/**
2265
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2266
+	 * registrations)
2267
+	 * @var int
2268
+	 */
2269
+	public $default_maximum_number_of_tickets;
2270
+
2271
+
2272
+	/**
2273
+	 * level of validation to apply to email addresses
2274
+	 *
2275
+	 * @var string $email_validation_level
2276
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2277
+	 */
2278
+	public $email_validation_level;
2279
+
2280
+	/**
2281
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2282
+	 *
2283
+	 * @var boolean $show_pending_payment_options
2284
+	 */
2285
+	public $show_pending_payment_options;
2286
+
2287
+	/**
2288
+	 * Whether to skip the registration confirmation page
2289
+	 *
2290
+	 * @var boolean $skip_reg_confirmation
2291
+	 */
2292
+	public $skip_reg_confirmation;
2293
+
2294
+	/**
2295
+	 * an array of SPCO reg steps where:
2296
+	 *        the keys denotes the reg step order
2297
+	 *        each element consists of an array with the following elements:
2298
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2299
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2300
+	 *            "slug" => the URL param used to trigger the reg step
2301
+	 *
2302
+	 * @var array $reg_steps
2303
+	 */
2304
+	public $reg_steps;
2305
+
2306
+	/**
2307
+	 * Whether registration confirmation should be the last page of SPCO
2308
+	 *
2309
+	 * @var boolean $reg_confirmation_last
2310
+	 */
2311
+	public $reg_confirmation_last;
2312
+
2313
+	/**
2314
+	 * Whether or not to enable the EE Bot Trap
2315
+	 *
2316
+	 * @var boolean $use_bot_trap
2317
+	 */
2318
+	public $use_bot_trap;
2319
+
2320
+	/**
2321
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2322
+	 *
2323
+	 * @var boolean $use_encryption
2324
+	 */
2325
+	public $use_encryption;
2326
+
2327
+	/**
2328
+	 * Whether or not to use ReCaptcha
2329
+	 *
2330
+	 * @var boolean $use_captcha
2331
+	 */
2332
+	public $use_captcha;
2333
+
2334
+	/**
2335
+	 * ReCaptcha Theme
2336
+	 *
2337
+	 * @var string $recaptcha_theme
2338
+	 *    options: 'dark', 'light', 'invisible'
2339
+	 */
2340
+	public $recaptcha_theme;
2341
+
2342
+	/**
2343
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2344
+	 *
2345
+	 * @var string $recaptcha_badge
2346
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2347
+	 */
2348
+	public $recaptcha_badge;
2349
+
2350
+	/**
2351
+	 * ReCaptcha Type
2352
+	 *
2353
+	 * @var string $recaptcha_type
2354
+	 *    options: 'audio', 'image'
2355
+	 */
2356
+	public $recaptcha_type;
2357
+
2358
+	/**
2359
+	 * ReCaptcha language
2360
+	 *
2361
+	 * @var string $recaptcha_language
2362
+	 * eg 'en'
2363
+	 */
2364
+	public $recaptcha_language;
2365
+
2366
+	/**
2367
+	 * ReCaptcha public key
2368
+	 *
2369
+	 * @var string $recaptcha_publickey
2370
+	 */
2371
+	public $recaptcha_publickey;
2372
+
2373
+	/**
2374
+	 * ReCaptcha private key
2375
+	 *
2376
+	 * @var string $recaptcha_privatekey
2377
+	 */
2378
+	public $recaptcha_privatekey;
2379
+
2380
+	/**
2381
+	 * array of form names protected by ReCaptcha
2382
+	 *
2383
+	 * @var array $recaptcha_protected_forms
2384
+	 */
2385
+	public $recaptcha_protected_forms;
2386
+
2387
+	/**
2388
+	 * ReCaptcha width
2389
+	 *
2390
+	 * @var int $recaptcha_width
2391
+	 * @deprecated
2392
+	 */
2393
+	public $recaptcha_width;
2394
+
2395
+	/**
2396
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2397
+	 *
2398
+	 * @var boolean $track_invalid_checkout_access
2399
+	 */
2400
+	protected $track_invalid_checkout_access = true;
2401
+
2402
+
2403
+
2404
+	/**
2405
+	 *    class constructor
2406
+	 *
2407
+	 * @access    public
2408
+	 */
2409
+	public function __construct()
2410
+	{
2411
+		// set default registration settings
2412
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2413
+		$this->email_validation_level = 'wp_default';
2414
+		$this->show_pending_payment_options = true;
2415
+		$this->skip_reg_confirmation = true;
2416
+		$this->reg_steps = array();
2417
+		$this->reg_confirmation_last = false;
2418
+		$this->use_bot_trap = true;
2419
+		$this->use_encryption = true;
2420
+		$this->use_captcha = false;
2421
+		$this->recaptcha_theme = 'light';
2422
+		$this->recaptcha_badge = 'bottomleft';
2423
+		$this->recaptcha_type = 'image';
2424
+		$this->recaptcha_language = 'en';
2425
+		$this->recaptcha_publickey = null;
2426
+		$this->recaptcha_privatekey = null;
2427
+		$this->recaptcha_protected_forms = array();
2428
+		$this->recaptcha_width = 500;
2429
+		$this->default_maximum_number_of_tickets = 10;
2430
+	}
2431
+
2432
+
2433
+
2434
+	/**
2435
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2436
+	 *
2437
+	 * @since 4.8.8.rc.019
2438
+	 */
2439
+	public function do_hooks()
2440
+	{
2441
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2442
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2443
+	}
2444
+
2445
+
2446
+
2447
+	/**
2448
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2449
+	 * field matches the config setting for default_STS_ID.
2450
+	 */
2451
+	public function set_default_reg_status_on_EEM_Event()
2452
+	{
2453
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2454
+	}
2455
+
2456
+
2457
+	/**
2458
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2459
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2460
+	 */
2461
+	public function set_default_max_ticket_on_EEM_Event()
2462
+	{
2463
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2464
+	}
2465
+
2466
+
2467
+
2468
+	/**
2469
+	 * @return boolean
2470
+	 */
2471
+	public function track_invalid_checkout_access()
2472
+	{
2473
+		return $this->track_invalid_checkout_access;
2474
+	}
2475
+
2476
+
2477
+
2478
+	/**
2479
+	 * @param boolean $track_invalid_checkout_access
2480
+	 */
2481
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2482
+	{
2483
+		$this->track_invalid_checkout_access = filter_var(
2484
+			$track_invalid_checkout_access,
2485
+			FILTER_VALIDATE_BOOLEAN
2486
+		);
2487
+	}
2488 2488
 
2489 2489
 
2490 2490
 
@@ -2498,160 +2498,160 @@  discard block
 block discarded – undo
2498 2498
 class EE_Admin_Config extends EE_Config_Base
2499 2499
 {
2500 2500
 
2501
-    /**
2502
-     * @var boolean $use_personnel_manager
2503
-     */
2504
-    public $use_personnel_manager;
2505
-
2506
-    /**
2507
-     * @var boolean $use_dashboard_widget
2508
-     */
2509
-    public $use_dashboard_widget;
2510
-
2511
-    /**
2512
-     * @var int $events_in_dashboard
2513
-     */
2514
-    public $events_in_dashboard;
2515
-
2516
-    /**
2517
-     * @var boolean $use_event_timezones
2518
-     */
2519
-    public $use_event_timezones;
2520
-
2521
-    /**
2522
-     * @var boolean $use_full_logging
2523
-     */
2524
-    public $use_full_logging;
2525
-
2526
-    /**
2527
-     * @var string $log_file_name
2528
-     */
2529
-    public $log_file_name;
2530
-
2531
-    /**
2532
-     * @var string $debug_file_name
2533
-     */
2534
-    public $debug_file_name;
2535
-
2536
-    /**
2537
-     * @var boolean $use_remote_logging
2538
-     */
2539
-    public $use_remote_logging;
2540
-
2541
-    /**
2542
-     * @var string $remote_logging_url
2543
-     */
2544
-    public $remote_logging_url;
2545
-
2546
-    /**
2547
-     * @var boolean $show_reg_footer
2548
-     */
2549
-    public $show_reg_footer;
2550
-
2551
-    /**
2552
-     * @var string $affiliate_id
2553
-     */
2554
-    public $affiliate_id;
2555
-
2556
-    /**
2557
-     * help tours on or off (global setting)
2558
-     *
2559
-     * @var boolean
2560
-     */
2561
-    public $help_tour_activation;
2562
-
2563
-    /**
2564
-     * adds extra layer of encoding to session data to prevent serialization errors
2565
-     * but is incompatible with some server configuration errors
2566
-     * if you get "500 internal server errors" during registration, try turning this on
2567
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2568
-     *
2569
-     * @var boolean $encode_session_data
2570
-     */
2571
-    private $encode_session_data = false;
2572
-
2573
-
2574
-
2575
-    /**
2576
-     *    class constructor
2577
-     *
2578
-     * @access    public
2579
-     */
2580
-    public function __construct()
2581
-    {
2582
-        // set default general admin settings
2583
-        $this->use_personnel_manager = true;
2584
-        $this->use_dashboard_widget = true;
2585
-        $this->events_in_dashboard = 30;
2586
-        $this->use_event_timezones = false;
2587
-        $this->use_full_logging = false;
2588
-        $this->use_remote_logging = false;
2589
-        $this->remote_logging_url = null;
2590
-        $this->show_reg_footer = true;
2591
-        $this->affiliate_id = 'default';
2592
-        $this->help_tour_activation = true;
2593
-        $this->encode_session_data = false;
2594
-    }
2595
-
2596
-
2597
-
2598
-    /**
2599
-     * @param bool $reset
2600
-     * @return string
2601
-     */
2602
-    public function log_file_name($reset = false)
2603
-    {
2604
-        if (empty($this->log_file_name) || $reset) {
2605
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2606
-            EE_Config::instance()->update_espresso_config(false, false);
2607
-        }
2608
-        return $this->log_file_name;
2609
-    }
2610
-
2611
-
2612
-
2613
-    /**
2614
-     * @param bool $reset
2615
-     * @return string
2616
-     */
2617
-    public function debug_file_name($reset = false)
2618
-    {
2619
-        if (empty($this->debug_file_name) || $reset) {
2620
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2621
-            EE_Config::instance()->update_espresso_config(false, false);
2622
-        }
2623
-        return $this->debug_file_name;
2624
-    }
2625
-
2626
-
2627
-
2628
-    /**
2629
-     * @return string
2630
-     */
2631
-    public function affiliate_id()
2632
-    {
2633
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2634
-    }
2635
-
2636
-
2637
-
2638
-    /**
2639
-     * @return boolean
2640
-     */
2641
-    public function encode_session_data()
2642
-    {
2643
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2644
-    }
2645
-
2646
-
2647
-
2648
-    /**
2649
-     * @param boolean $encode_session_data
2650
-     */
2651
-    public function set_encode_session_data($encode_session_data)
2652
-    {
2653
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2654
-    }
2501
+	/**
2502
+	 * @var boolean $use_personnel_manager
2503
+	 */
2504
+	public $use_personnel_manager;
2505
+
2506
+	/**
2507
+	 * @var boolean $use_dashboard_widget
2508
+	 */
2509
+	public $use_dashboard_widget;
2510
+
2511
+	/**
2512
+	 * @var int $events_in_dashboard
2513
+	 */
2514
+	public $events_in_dashboard;
2515
+
2516
+	/**
2517
+	 * @var boolean $use_event_timezones
2518
+	 */
2519
+	public $use_event_timezones;
2520
+
2521
+	/**
2522
+	 * @var boolean $use_full_logging
2523
+	 */
2524
+	public $use_full_logging;
2525
+
2526
+	/**
2527
+	 * @var string $log_file_name
2528
+	 */
2529
+	public $log_file_name;
2530
+
2531
+	/**
2532
+	 * @var string $debug_file_name
2533
+	 */
2534
+	public $debug_file_name;
2535
+
2536
+	/**
2537
+	 * @var boolean $use_remote_logging
2538
+	 */
2539
+	public $use_remote_logging;
2540
+
2541
+	/**
2542
+	 * @var string $remote_logging_url
2543
+	 */
2544
+	public $remote_logging_url;
2545
+
2546
+	/**
2547
+	 * @var boolean $show_reg_footer
2548
+	 */
2549
+	public $show_reg_footer;
2550
+
2551
+	/**
2552
+	 * @var string $affiliate_id
2553
+	 */
2554
+	public $affiliate_id;
2555
+
2556
+	/**
2557
+	 * help tours on or off (global setting)
2558
+	 *
2559
+	 * @var boolean
2560
+	 */
2561
+	public $help_tour_activation;
2562
+
2563
+	/**
2564
+	 * adds extra layer of encoding to session data to prevent serialization errors
2565
+	 * but is incompatible with some server configuration errors
2566
+	 * if you get "500 internal server errors" during registration, try turning this on
2567
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2568
+	 *
2569
+	 * @var boolean $encode_session_data
2570
+	 */
2571
+	private $encode_session_data = false;
2572
+
2573
+
2574
+
2575
+	/**
2576
+	 *    class constructor
2577
+	 *
2578
+	 * @access    public
2579
+	 */
2580
+	public function __construct()
2581
+	{
2582
+		// set default general admin settings
2583
+		$this->use_personnel_manager = true;
2584
+		$this->use_dashboard_widget = true;
2585
+		$this->events_in_dashboard = 30;
2586
+		$this->use_event_timezones = false;
2587
+		$this->use_full_logging = false;
2588
+		$this->use_remote_logging = false;
2589
+		$this->remote_logging_url = null;
2590
+		$this->show_reg_footer = true;
2591
+		$this->affiliate_id = 'default';
2592
+		$this->help_tour_activation = true;
2593
+		$this->encode_session_data = false;
2594
+	}
2595
+
2596
+
2597
+
2598
+	/**
2599
+	 * @param bool $reset
2600
+	 * @return string
2601
+	 */
2602
+	public function log_file_name($reset = false)
2603
+	{
2604
+		if (empty($this->log_file_name) || $reset) {
2605
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2606
+			EE_Config::instance()->update_espresso_config(false, false);
2607
+		}
2608
+		return $this->log_file_name;
2609
+	}
2610
+
2611
+
2612
+
2613
+	/**
2614
+	 * @param bool $reset
2615
+	 * @return string
2616
+	 */
2617
+	public function debug_file_name($reset = false)
2618
+	{
2619
+		if (empty($this->debug_file_name) || $reset) {
2620
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2621
+			EE_Config::instance()->update_espresso_config(false, false);
2622
+		}
2623
+		return $this->debug_file_name;
2624
+	}
2625
+
2626
+
2627
+
2628
+	/**
2629
+	 * @return string
2630
+	 */
2631
+	public function affiliate_id()
2632
+	{
2633
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2634
+	}
2635
+
2636
+
2637
+
2638
+	/**
2639
+	 * @return boolean
2640
+	 */
2641
+	public function encode_session_data()
2642
+	{
2643
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2644
+	}
2645
+
2646
+
2647
+
2648
+	/**
2649
+	 * @param boolean $encode_session_data
2650
+	 */
2651
+	public function set_encode_session_data($encode_session_data)
2652
+	{
2653
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2654
+	}
2655 2655
 
2656 2656
 
2657 2657
 
@@ -2665,71 +2665,71 @@  discard block
 block discarded – undo
2665 2665
 class EE_Template_Config extends EE_Config_Base
2666 2666
 {
2667 2667
 
2668
-    /**
2669
-     * @var boolean $enable_default_style
2670
-     */
2671
-    public $enable_default_style;
2672
-
2673
-    /**
2674
-     * @var string $custom_style_sheet
2675
-     */
2676
-    public $custom_style_sheet;
2677
-
2678
-    /**
2679
-     * @var boolean $display_address_in_regform
2680
-     */
2681
-    public $display_address_in_regform;
2682
-
2683
-    /**
2684
-     * @var int $display_description_on_multi_reg_page
2685
-     */
2686
-    public $display_description_on_multi_reg_page;
2687
-
2688
-    /**
2689
-     * @var boolean $use_custom_templates
2690
-     */
2691
-    public $use_custom_templates;
2692
-
2693
-    /**
2694
-     * @var string $current_espresso_theme
2695
-     */
2696
-    public $current_espresso_theme;
2697
-
2698
-    /**
2699
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2700
-     */
2701
-    public $EED_Ticket_Selector;
2702
-
2703
-    /**
2704
-     * @var EE_Event_Single_Config $EED_Event_Single
2705
-     */
2706
-    public $EED_Event_Single;
2707
-
2708
-    /**
2709
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2710
-     */
2711
-    public $EED_Events_Archive;
2712
-
2713
-
2714
-
2715
-    /**
2716
-     *    class constructor
2717
-     *
2718
-     * @access    public
2719
-     */
2720
-    public function __construct()
2721
-    {
2722
-        // set default template settings
2723
-        $this->enable_default_style = true;
2724
-        $this->custom_style_sheet = null;
2725
-        $this->display_address_in_regform = true;
2726
-        $this->display_description_on_multi_reg_page = false;
2727
-        $this->use_custom_templates = false;
2728
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2729
-        $this->EED_Event_Single = null;
2730
-        $this->EED_Events_Archive = null;
2731
-        $this->EED_Ticket_Selector = null;
2732
-    }
2668
+	/**
2669
+	 * @var boolean $enable_default_style
2670
+	 */
2671
+	public $enable_default_style;
2672
+
2673
+	/**
2674
+	 * @var string $custom_style_sheet
2675
+	 */
2676
+	public $custom_style_sheet;
2677
+
2678
+	/**
2679
+	 * @var boolean $display_address_in_regform
2680
+	 */
2681
+	public $display_address_in_regform;
2682
+
2683
+	/**
2684
+	 * @var int $display_description_on_multi_reg_page
2685
+	 */
2686
+	public $display_description_on_multi_reg_page;
2687
+
2688
+	/**
2689
+	 * @var boolean $use_custom_templates
2690
+	 */
2691
+	public $use_custom_templates;
2692
+
2693
+	/**
2694
+	 * @var string $current_espresso_theme
2695
+	 */
2696
+	public $current_espresso_theme;
2697
+
2698
+	/**
2699
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2700
+	 */
2701
+	public $EED_Ticket_Selector;
2702
+
2703
+	/**
2704
+	 * @var EE_Event_Single_Config $EED_Event_Single
2705
+	 */
2706
+	public $EED_Event_Single;
2707
+
2708
+	/**
2709
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2710
+	 */
2711
+	public $EED_Events_Archive;
2712
+
2713
+
2714
+
2715
+	/**
2716
+	 *    class constructor
2717
+	 *
2718
+	 * @access    public
2719
+	 */
2720
+	public function __construct()
2721
+	{
2722
+		// set default template settings
2723
+		$this->enable_default_style = true;
2724
+		$this->custom_style_sheet = null;
2725
+		$this->display_address_in_regform = true;
2726
+		$this->display_description_on_multi_reg_page = false;
2727
+		$this->use_custom_templates = false;
2728
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2729
+		$this->EED_Event_Single = null;
2730
+		$this->EED_Events_Archive = null;
2731
+		$this->EED_Ticket_Selector = null;
2732
+	}
2733 2733
 
2734 2734
 }
2735 2735
 
@@ -2741,115 +2741,115 @@  discard block
 block discarded – undo
2741 2741
 class EE_Map_Config extends EE_Config_Base
2742 2742
 {
2743 2743
 
2744
-    /**
2745
-     * @var boolean $use_google_maps
2746
-     */
2747
-    public $use_google_maps;
2748
-
2749
-    /**
2750
-     * @var string $api_key
2751
-     */
2752
-    public $google_map_api_key;
2753
-
2754
-    /**
2755
-     * @var int $event_details_map_width
2756
-     */
2757
-    public $event_details_map_width;
2758
-
2759
-    /**
2760
-     * @var int $event_details_map_height
2761
-     */
2762
-    public $event_details_map_height;
2763
-
2764
-    /**
2765
-     * @var int $event_details_map_zoom
2766
-     */
2767
-    public $event_details_map_zoom;
2768
-
2769
-    /**
2770
-     * @var boolean $event_details_display_nav
2771
-     */
2772
-    public $event_details_display_nav;
2773
-
2774
-    /**
2775
-     * @var boolean $event_details_nav_size
2776
-     */
2777
-    public $event_details_nav_size;
2778
-
2779
-    /**
2780
-     * @var string $event_details_control_type
2781
-     */
2782
-    public $event_details_control_type;
2783
-
2784
-    /**
2785
-     * @var string $event_details_map_align
2786
-     */
2787
-    public $event_details_map_align;
2788
-
2789
-    /**
2790
-     * @var int $event_list_map_width
2791
-     */
2792
-    public $event_list_map_width;
2793
-
2794
-    /**
2795
-     * @var int $event_list_map_height
2796
-     */
2797
-    public $event_list_map_height;
2798
-
2799
-    /**
2800
-     * @var int $event_list_map_zoom
2801
-     */
2802
-    public $event_list_map_zoom;
2803
-
2804
-    /**
2805
-     * @var boolean $event_list_display_nav
2806
-     */
2807
-    public $event_list_display_nav;
2808
-
2809
-    /**
2810
-     * @var boolean $event_list_nav_size
2811
-     */
2812
-    public $event_list_nav_size;
2813
-
2814
-    /**
2815
-     * @var string $event_list_control_type
2816
-     */
2817
-    public $event_list_control_type;
2818
-
2819
-    /**
2820
-     * @var string $event_list_map_align
2821
-     */
2822
-    public $event_list_map_align;
2823
-
2824
-
2825
-
2826
-    /**
2827
-     *    class constructor
2828
-     *
2829
-     * @access    public
2830
-     */
2831
-    public function __construct()
2832
-    {
2833
-        // set default map settings
2834
-        $this->use_google_maps = true;
2835
-        $this->google_map_api_key = '';
2836
-        // for event details pages (reg page)
2837
-        $this->event_details_map_width = 585;            // ee_map_width_single
2838
-        $this->event_details_map_height = 362;            // ee_map_height_single
2839
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2840
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2841
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2842
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2843
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2844
-        // for event list pages
2845
-        $this->event_list_map_width = 300;            // ee_map_width
2846
-        $this->event_list_map_height = 185;        // ee_map_height
2847
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2848
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2849
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2850
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2851
-        $this->event_list_map_align = 'center';            // ee_map_align
2852
-    }
2744
+	/**
2745
+	 * @var boolean $use_google_maps
2746
+	 */
2747
+	public $use_google_maps;
2748
+
2749
+	/**
2750
+	 * @var string $api_key
2751
+	 */
2752
+	public $google_map_api_key;
2753
+
2754
+	/**
2755
+	 * @var int $event_details_map_width
2756
+	 */
2757
+	public $event_details_map_width;
2758
+
2759
+	/**
2760
+	 * @var int $event_details_map_height
2761
+	 */
2762
+	public $event_details_map_height;
2763
+
2764
+	/**
2765
+	 * @var int $event_details_map_zoom
2766
+	 */
2767
+	public $event_details_map_zoom;
2768
+
2769
+	/**
2770
+	 * @var boolean $event_details_display_nav
2771
+	 */
2772
+	public $event_details_display_nav;
2773
+
2774
+	/**
2775
+	 * @var boolean $event_details_nav_size
2776
+	 */
2777
+	public $event_details_nav_size;
2778
+
2779
+	/**
2780
+	 * @var string $event_details_control_type
2781
+	 */
2782
+	public $event_details_control_type;
2783
+
2784
+	/**
2785
+	 * @var string $event_details_map_align
2786
+	 */
2787
+	public $event_details_map_align;
2788
+
2789
+	/**
2790
+	 * @var int $event_list_map_width
2791
+	 */
2792
+	public $event_list_map_width;
2793
+
2794
+	/**
2795
+	 * @var int $event_list_map_height
2796
+	 */
2797
+	public $event_list_map_height;
2798
+
2799
+	/**
2800
+	 * @var int $event_list_map_zoom
2801
+	 */
2802
+	public $event_list_map_zoom;
2803
+
2804
+	/**
2805
+	 * @var boolean $event_list_display_nav
2806
+	 */
2807
+	public $event_list_display_nav;
2808
+
2809
+	/**
2810
+	 * @var boolean $event_list_nav_size
2811
+	 */
2812
+	public $event_list_nav_size;
2813
+
2814
+	/**
2815
+	 * @var string $event_list_control_type
2816
+	 */
2817
+	public $event_list_control_type;
2818
+
2819
+	/**
2820
+	 * @var string $event_list_map_align
2821
+	 */
2822
+	public $event_list_map_align;
2823
+
2824
+
2825
+
2826
+	/**
2827
+	 *    class constructor
2828
+	 *
2829
+	 * @access    public
2830
+	 */
2831
+	public function __construct()
2832
+	{
2833
+		// set default map settings
2834
+		$this->use_google_maps = true;
2835
+		$this->google_map_api_key = '';
2836
+		// for event details pages (reg page)
2837
+		$this->event_details_map_width = 585;            // ee_map_width_single
2838
+		$this->event_details_map_height = 362;            // ee_map_height_single
2839
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2840
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2841
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2842
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2843
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2844
+		// for event list pages
2845
+		$this->event_list_map_width = 300;            // ee_map_width
2846
+		$this->event_list_map_height = 185;        // ee_map_height
2847
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2848
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2849
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2850
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2851
+		$this->event_list_map_align = 'center';            // ee_map_align
2852
+	}
2853 2853
 
2854 2854
 }
2855 2855
 
@@ -2861,47 +2861,47 @@  discard block
 block discarded – undo
2861 2861
 class EE_Events_Archive_Config extends EE_Config_Base
2862 2862
 {
2863 2863
 
2864
-    public $display_status_banner;
2864
+	public $display_status_banner;
2865 2865
 
2866
-    public $display_description;
2866
+	public $display_description;
2867 2867
 
2868
-    public $display_ticket_selector;
2868
+	public $display_ticket_selector;
2869 2869
 
2870
-    public $display_datetimes;
2870
+	public $display_datetimes;
2871 2871
 
2872
-    public $display_venue;
2872
+	public $display_venue;
2873 2873
 
2874
-    public $display_expired_events;
2874
+	public $display_expired_events;
2875 2875
 
2876
-    public $use_sortable_display_order;
2876
+	public $use_sortable_display_order;
2877 2877
 
2878
-    public $display_order_tickets;
2878
+	public $display_order_tickets;
2879 2879
 
2880
-    public $display_order_datetimes;
2880
+	public $display_order_datetimes;
2881 2881
 
2882
-    public $display_order_event;
2882
+	public $display_order_event;
2883 2883
 
2884
-    public $display_order_venue;
2884
+	public $display_order_venue;
2885 2885
 
2886 2886
 
2887 2887
 
2888
-    /**
2889
-     *    class constructor
2890
-     */
2891
-    public function __construct()
2892
-    {
2893
-        $this->display_status_banner = 0;
2894
-        $this->display_description = 1;
2895
-        $this->display_ticket_selector = 0;
2896
-        $this->display_datetimes = 1;
2897
-        $this->display_venue = 0;
2898
-        $this->display_expired_events = 0;
2899
-        $this->use_sortable_display_order = false;
2900
-        $this->display_order_tickets = 100;
2901
-        $this->display_order_datetimes = 110;
2902
-        $this->display_order_event = 120;
2903
-        $this->display_order_venue = 130;
2904
-    }
2888
+	/**
2889
+	 *    class constructor
2890
+	 */
2891
+	public function __construct()
2892
+	{
2893
+		$this->display_status_banner = 0;
2894
+		$this->display_description = 1;
2895
+		$this->display_ticket_selector = 0;
2896
+		$this->display_datetimes = 1;
2897
+		$this->display_venue = 0;
2898
+		$this->display_expired_events = 0;
2899
+		$this->use_sortable_display_order = false;
2900
+		$this->display_order_tickets = 100;
2901
+		$this->display_order_datetimes = 110;
2902
+		$this->display_order_event = 120;
2903
+		$this->display_order_venue = 130;
2904
+	}
2905 2905
 }
2906 2906
 
2907 2907
 
@@ -2912,35 +2912,35 @@  discard block
 block discarded – undo
2912 2912
 class EE_Event_Single_Config extends EE_Config_Base
2913 2913
 {
2914 2914
 
2915
-    public $display_status_banner_single;
2915
+	public $display_status_banner_single;
2916 2916
 
2917
-    public $display_venue;
2917
+	public $display_venue;
2918 2918
 
2919
-    public $use_sortable_display_order;
2919
+	public $use_sortable_display_order;
2920 2920
 
2921
-    public $display_order_tickets;
2921
+	public $display_order_tickets;
2922 2922
 
2923
-    public $display_order_datetimes;
2923
+	public $display_order_datetimes;
2924 2924
 
2925
-    public $display_order_event;
2925
+	public $display_order_event;
2926 2926
 
2927
-    public $display_order_venue;
2927
+	public $display_order_venue;
2928 2928
 
2929 2929
 
2930 2930
 
2931
-    /**
2932
-     *    class constructor
2933
-     */
2934
-    public function __construct()
2935
-    {
2936
-        $this->display_status_banner_single = 0;
2937
-        $this->display_venue = 1;
2938
-        $this->use_sortable_display_order = false;
2939
-        $this->display_order_tickets = 100;
2940
-        $this->display_order_datetimes = 110;
2941
-        $this->display_order_event = 120;
2942
-        $this->display_order_venue = 130;
2943
-    }
2931
+	/**
2932
+	 *    class constructor
2933
+	 */
2934
+	public function __construct()
2935
+	{
2936
+		$this->display_status_banner_single = 0;
2937
+		$this->display_venue = 1;
2938
+		$this->use_sortable_display_order = false;
2939
+		$this->display_order_tickets = 100;
2940
+		$this->display_order_datetimes = 110;
2941
+		$this->display_order_event = 120;
2942
+		$this->display_order_venue = 130;
2943
+	}
2944 2944
 }
2945 2945
 
2946 2946
 
@@ -2951,152 +2951,152 @@  discard block
 block discarded – undo
2951 2951
 class EE_Ticket_Selector_Config extends EE_Config_Base
2952 2952
 {
2953 2953
 
2954
-    /**
2955
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2956
-     */
2957
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2958
-
2959
-    /**
2960
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2961
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2962
-     */
2963
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2964
-
2965
-    /**
2966
-     * @var boolean $show_ticket_sale_columns
2967
-     */
2968
-    public $show_ticket_sale_columns;
2969
-
2970
-    /**
2971
-     * @var boolean $show_ticket_details
2972
-     */
2973
-    public $show_ticket_details;
2974
-
2975
-    /**
2976
-     * @var boolean $show_expired_tickets
2977
-     */
2978
-    public $show_expired_tickets;
2979
-
2980
-    /**
2981
-     * whether or not to display a dropdown box populated with event datetimes
2982
-     * that toggles which tickets are displayed for a ticket selector.
2983
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2984
-     *
2985
-     * @var string $show_datetime_selector
2986
-     */
2987
-    private $show_datetime_selector = 'no_datetime_selector';
2988
-
2989
-    /**
2990
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2991
-     *
2992
-     * @var int $datetime_selector_threshold
2993
-     */
2994
-    private $datetime_selector_threshold = 3;
2995
-
2996
-
2997
-
2998
-    /**
2999
-     *    class constructor
3000
-     */
3001
-    public function __construct()
3002
-    {
3003
-        $this->show_ticket_sale_columns = true;
3004
-        $this->show_ticket_details = true;
3005
-        $this->show_expired_tickets = true;
3006
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3007
-        $this->datetime_selector_threshold = 3;
3008
-    }
3009
-
3010
-
3011
-
3012
-    /**
3013
-     * returns true if a datetime selector should be displayed
3014
-     *
3015
-     * @param array $datetimes
3016
-     * @return bool
3017
-     */
3018
-    public function showDatetimeSelector(array $datetimes)
3019
-    {
3020
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3021
-        return ! (
3022
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3023
-            || (
3024
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3025
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3026
-            )
3027
-        );
3028
-    }
3029
-
3030
-
3031
-
3032
-    /**
3033
-     * @return string
3034
-     */
3035
-    public function getShowDatetimeSelector()
3036
-    {
3037
-        return $this->show_datetime_selector;
3038
-    }
3039
-
3040
-
3041
-
3042
-    /**
3043
-     * @param bool $keys_only
3044
-     * @return array
3045
-     */
3046
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3047
-    {
3048
-        return $keys_only
3049
-            ? array(
3050
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3051
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3052
-            )
3053
-            : array(
3054
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3055
-                    'Do not show date & time filter', 'event_espresso'
3056
-                ),
3057
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3058
-                    'Maybe show date & time filter', 'event_espresso'
3059
-                ),
3060
-            );
3061
-    }
3062
-
3063
-
3064
-
3065
-    /**
3066
-     * @param string $show_datetime_selector
3067
-     */
3068
-    public function setShowDatetimeSelector($show_datetime_selector)
3069
-    {
3070
-        $this->show_datetime_selector = in_array(
3071
-            $show_datetime_selector,
3072
-            $this->getShowDatetimeSelectorOptions(),
3073
-            true
3074
-        )
3075
-            ? $show_datetime_selector
3076
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3077
-    }
3078
-
3079
-
3080
-
3081
-    /**
3082
-     * @return int
3083
-     */
3084
-    public function getDatetimeSelectorThreshold()
3085
-    {
3086
-        return $this->datetime_selector_threshold;
3087
-    }
3088
-
3089
-
3090
-
3091
-
3092
-    /**
3093
-     * @param int $datetime_selector_threshold
3094
-     */
3095
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3096
-    {
3097
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3098
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3099
-    }
2954
+	/**
2955
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2956
+	 */
2957
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2958
+
2959
+	/**
2960
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2961
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2962
+	 */
2963
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2964
+
2965
+	/**
2966
+	 * @var boolean $show_ticket_sale_columns
2967
+	 */
2968
+	public $show_ticket_sale_columns;
2969
+
2970
+	/**
2971
+	 * @var boolean $show_ticket_details
2972
+	 */
2973
+	public $show_ticket_details;
2974
+
2975
+	/**
2976
+	 * @var boolean $show_expired_tickets
2977
+	 */
2978
+	public $show_expired_tickets;
2979
+
2980
+	/**
2981
+	 * whether or not to display a dropdown box populated with event datetimes
2982
+	 * that toggles which tickets are displayed for a ticket selector.
2983
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2984
+	 *
2985
+	 * @var string $show_datetime_selector
2986
+	 */
2987
+	private $show_datetime_selector = 'no_datetime_selector';
2988
+
2989
+	/**
2990
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2991
+	 *
2992
+	 * @var int $datetime_selector_threshold
2993
+	 */
2994
+	private $datetime_selector_threshold = 3;
2995
+
2996
+
2997
+
2998
+	/**
2999
+	 *    class constructor
3000
+	 */
3001
+	public function __construct()
3002
+	{
3003
+		$this->show_ticket_sale_columns = true;
3004
+		$this->show_ticket_details = true;
3005
+		$this->show_expired_tickets = true;
3006
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3007
+		$this->datetime_selector_threshold = 3;
3008
+	}
3009
+
3010
+
3011
+
3012
+	/**
3013
+	 * returns true if a datetime selector should be displayed
3014
+	 *
3015
+	 * @param array $datetimes
3016
+	 * @return bool
3017
+	 */
3018
+	public function showDatetimeSelector(array $datetimes)
3019
+	{
3020
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3021
+		return ! (
3022
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3023
+			|| (
3024
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3025
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3026
+			)
3027
+		);
3028
+	}
3029
+
3030
+
3031
+
3032
+	/**
3033
+	 * @return string
3034
+	 */
3035
+	public function getShowDatetimeSelector()
3036
+	{
3037
+		return $this->show_datetime_selector;
3038
+	}
3039
+
3040
+
3041
+
3042
+	/**
3043
+	 * @param bool $keys_only
3044
+	 * @return array
3045
+	 */
3046
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3047
+	{
3048
+		return $keys_only
3049
+			? array(
3050
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3051
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3052
+			)
3053
+			: array(
3054
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3055
+					'Do not show date & time filter', 'event_espresso'
3056
+				),
3057
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3058
+					'Maybe show date & time filter', 'event_espresso'
3059
+				),
3060
+			);
3061
+	}
3062
+
3063
+
3064
+
3065
+	/**
3066
+	 * @param string $show_datetime_selector
3067
+	 */
3068
+	public function setShowDatetimeSelector($show_datetime_selector)
3069
+	{
3070
+		$this->show_datetime_selector = in_array(
3071
+			$show_datetime_selector,
3072
+			$this->getShowDatetimeSelectorOptions(),
3073
+			true
3074
+		)
3075
+			? $show_datetime_selector
3076
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3077
+	}
3078
+
3079
+
3080
+
3081
+	/**
3082
+	 * @return int
3083
+	 */
3084
+	public function getDatetimeSelectorThreshold()
3085
+	{
3086
+		return $this->datetime_selector_threshold;
3087
+	}
3088
+
3089
+
3090
+
3091
+
3092
+	/**
3093
+	 * @param int $datetime_selector_threshold
3094
+	 */
3095
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3096
+	{
3097
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3098
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3099
+	}
3100 3100
 
3101 3101
 
3102 3102
 
@@ -3114,85 +3114,85 @@  discard block
 block discarded – undo
3114 3114
 class EE_Environment_Config extends EE_Config_Base
3115 3115
 {
3116 3116
 
3117
-    /**
3118
-     * Hold any php environment variables that we want to track.
3119
-     *
3120
-     * @var stdClass;
3121
-     */
3122
-    public $php;
3123
-
3124
-
3125
-
3126
-    /**
3127
-     *    constructor
3128
-     */
3129
-    public function __construct()
3130
-    {
3131
-        $this->php = new stdClass();
3132
-        $this->_set_php_values();
3133
-    }
3134
-
3135
-
3136
-
3137
-    /**
3138
-     * This sets the php environment variables.
3139
-     *
3140
-     * @since 4.4.0
3141
-     * @return void
3142
-     */
3143
-    protected function _set_php_values()
3144
-    {
3145
-        $this->php->max_input_vars = ini_get('max_input_vars');
3146
-        $this->php->version = phpversion();
3147
-    }
3148
-
3149
-
3150
-
3151
-    /**
3152
-     * helper method for determining whether input_count is
3153
-     * reaching the potential maximum the server can handle
3154
-     * according to max_input_vars
3155
-     *
3156
-     * @param int   $input_count the count of input vars.
3157
-     * @return array {
3158
-     *                           An array that represents whether available space and if no available space the error
3159
-     *                           message.
3160
-     * @type bool   $has_space   whether more inputs can be added.
3161
-     * @type string $msg         Any message to be displayed.
3162
-     *                           }
3163
-     */
3164
-    public function max_input_vars_limit_check($input_count = 0)
3165
-    {
3166
-        if (! empty($this->php->max_input_vars)
3167
-            && ($input_count >= $this->php->max_input_vars)
3168
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3169
-        ) {
3170
-            return sprintf(
3171
-                __(
3172
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3173
-                    'event_espresso'
3174
-                ),
3175
-                '<br>',
3176
-                $input_count,
3177
-                $this->php->max_input_vars
3178
-            );
3179
-        } else {
3180
-            return '';
3181
-        }
3182
-    }
3183
-
3184
-
3185
-
3186
-    /**
3187
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3188
-     *
3189
-     * @since 4.4.1
3190
-     * @return void
3191
-     */
3192
-    public function recheck_values()
3193
-    {
3194
-        $this->_set_php_values();
3195
-    }
3117
+	/**
3118
+	 * Hold any php environment variables that we want to track.
3119
+	 *
3120
+	 * @var stdClass;
3121
+	 */
3122
+	public $php;
3123
+
3124
+
3125
+
3126
+	/**
3127
+	 *    constructor
3128
+	 */
3129
+	public function __construct()
3130
+	{
3131
+		$this->php = new stdClass();
3132
+		$this->_set_php_values();
3133
+	}
3134
+
3135
+
3136
+
3137
+	/**
3138
+	 * This sets the php environment variables.
3139
+	 *
3140
+	 * @since 4.4.0
3141
+	 * @return void
3142
+	 */
3143
+	protected function _set_php_values()
3144
+	{
3145
+		$this->php->max_input_vars = ini_get('max_input_vars');
3146
+		$this->php->version = phpversion();
3147
+	}
3148
+
3149
+
3150
+
3151
+	/**
3152
+	 * helper method for determining whether input_count is
3153
+	 * reaching the potential maximum the server can handle
3154
+	 * according to max_input_vars
3155
+	 *
3156
+	 * @param int   $input_count the count of input vars.
3157
+	 * @return array {
3158
+	 *                           An array that represents whether available space and if no available space the error
3159
+	 *                           message.
3160
+	 * @type bool   $has_space   whether more inputs can be added.
3161
+	 * @type string $msg         Any message to be displayed.
3162
+	 *                           }
3163
+	 */
3164
+	public function max_input_vars_limit_check($input_count = 0)
3165
+	{
3166
+		if (! empty($this->php->max_input_vars)
3167
+			&& ($input_count >= $this->php->max_input_vars)
3168
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3169
+		) {
3170
+			return sprintf(
3171
+				__(
3172
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3173
+					'event_espresso'
3174
+				),
3175
+				'<br>',
3176
+				$input_count,
3177
+				$this->php->max_input_vars
3178
+			);
3179
+		} else {
3180
+			return '';
3181
+		}
3182
+	}
3183
+
3184
+
3185
+
3186
+	/**
3187
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3188
+	 *
3189
+	 * @since 4.4.1
3190
+	 * @return void
3191
+	 */
3192
+	public function recheck_values()
3193
+	{
3194
+		$this->_set_php_values();
3195
+	}
3196 3196
 
3197 3197
 
3198 3198
 
@@ -3210,22 +3210,22 @@  discard block
 block discarded – undo
3210 3210
 class EE_Tax_Config extends EE_Config_Base
3211 3211
 {
3212 3212
 
3213
-    /*
3213
+	/*
3214 3214
      * flag to indicate whether or not to display ticket prices with the taxes included
3215 3215
      *
3216 3216
      * @var boolean $prices_displayed_including_taxes
3217 3217
      */
3218
-    public $prices_displayed_including_taxes;
3218
+	public $prices_displayed_including_taxes;
3219 3219
 
3220 3220
 
3221 3221
 
3222
-    /**
3223
-     *    class constructor
3224
-     */
3225
-    public function __construct()
3226
-    {
3227
-        $this->prices_displayed_including_taxes = true;
3228
-    }
3222
+	/**
3223
+	 *    class constructor
3224
+	 */
3225
+	public function __construct()
3226
+	{
3227
+		$this->prices_displayed_including_taxes = true;
3228
+	}
3229 3229
 }
3230 3230
 
3231 3231
 
@@ -3240,17 +3240,17 @@  discard block
 block discarded – undo
3240 3240
 class EE_Messages_Config extends EE_Config_Base
3241 3241
 {
3242 3242
 
3243
-    /**
3244
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3245
-     * A value of 0 represents never deleting.  Default is 0.
3246
-     *
3247
-     * @var integer
3248
-     */
3249
-    public $delete_threshold;
3250
-
3251
-    public function __construct() {
3252
-        $this->delete_threshold = 0;
3253
-    }
3243
+	/**
3244
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3245
+	 * A value of 0 represents never deleting.  Default is 0.
3246
+	 *
3247
+	 * @var integer
3248
+	 */
3249
+	public $delete_threshold;
3250
+
3251
+	public function __construct() {
3252
+		$this->delete_threshold = 0;
3253
+	}
3254 3254
 }
3255 3255
 
3256 3256
 
@@ -3262,34 +3262,34 @@  discard block
 block discarded – undo
3262 3262
 class EE_Gateway_Config extends EE_Config_Base
3263 3263
 {
3264 3264
 
3265
-    /**
3266
-     * Array with keys that are payment gateways slugs, and values are arrays
3267
-     * with any config info the gateway wants to store
3268
-     *
3269
-     * @var array
3270
-     */
3271
-    public $payment_settings;
3272
-
3273
-    /**
3274
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3275
-     * the gateway is stored in the uploads directory
3276
-     *
3277
-     * @var array
3278
-     */
3279
-    public $active_gateways;
3280
-
3281
-
3282
-
3283
-    /**
3284
-     *    class constructor
3285
-     *
3286
-     * @deprecated
3287
-     */
3288
-    public function __construct()
3289
-    {
3290
-        $this->payment_settings = array();
3291
-        $this->active_gateways = array('Invoice' => false);
3292
-    }
3265
+	/**
3266
+	 * Array with keys that are payment gateways slugs, and values are arrays
3267
+	 * with any config info the gateway wants to store
3268
+	 *
3269
+	 * @var array
3270
+	 */
3271
+	public $payment_settings;
3272
+
3273
+	/**
3274
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3275
+	 * the gateway is stored in the uploads directory
3276
+	 *
3277
+	 * @var array
3278
+	 */
3279
+	public $active_gateways;
3280
+
3281
+
3282
+
3283
+	/**
3284
+	 *    class constructor
3285
+	 *
3286
+	 * @deprecated
3287
+	 */
3288
+	public function __construct()
3289
+	{
3290
+		$this->payment_settings = array();
3291
+		$this->active_gateways = array('Invoice' => false);
3292
+	}
3293 3293
 }
3294 3294
 
3295 3295
 // End of file EE_Config.core.php
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +1836 added lines, -1836 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\exceptions\InvalidInterfaceException;
7 7
 
8 8
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 
12 12
 
@@ -21,1841 +21,1841 @@  discard block
 block discarded – undo
21 21
 class EED_Single_Page_Checkout extends EED_Module
22 22
 {
23 23
 
24
-    /**
25
-     * $_initialized - has the SPCO controller already been initialized ?
26
-     *
27
-     * @access private
28
-     * @var bool $_initialized
29
-     */
30
-    private static $_initialized = false;
31
-
32
-
33
-    /**
34
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
35
-     *
36
-     * @access private
37
-     * @var bool $_valid_checkout
38
-     */
39
-    private static $_checkout_verified = true;
40
-
41
-    /**
42
-     *    $_reg_steps_array - holds initial array of reg steps
43
-     *
44
-     * @access private
45
-     * @var array $_reg_steps_array
46
-     */
47
-    private static $_reg_steps_array = array();
48
-
49
-    /**
50
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
51
-     *
52
-     * @access public
53
-     * @var EE_Checkout $checkout
54
-     */
55
-    public $checkout;
56
-
57
-
58
-
59
-    /**
60
-     * @return EED_Module|EED_Single_Page_Checkout
61
-     */
62
-    public static function instance()
63
-    {
64
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
-        return parent::get_instance(__CLASS__);
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * @return EE_CART
72
-     */
73
-    public function cart()
74
-    {
75
-        return $this->checkout->cart;
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * @return EE_Transaction
82
-     */
83
-    public function transaction()
84
-    {
85
-        return $this->checkout->transaction;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     *    set_hooks - for hooking into EE Core, other modules, etc
92
-     *
93
-     * @access    public
94
-     * @return    void
95
-     * @throws EE_Error
96
-     */
97
-    public static function set_hooks()
98
-    {
99
-        EED_Single_Page_Checkout::set_definitions();
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     * @throws EE_Error
110
-     */
111
-    public static function set_hooks_admin()
112
-    {
113
-        EED_Single_Page_Checkout::set_definitions();
114
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
115
-            return;
116
-        }
117
-        // going to start an output buffer in case anything gets accidentally output
118
-        // that might disrupt our JSON response
119
-        ob_start();
120
-        EED_Single_Page_Checkout::load_request_handler();
121
-        EED_Single_Page_Checkout::load_reg_steps();
122
-        // set ajax hooks
123
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
125
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
127
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     *    process ajax request
135
-     *
136
-     * @param string $ajax_action
137
-     * @throws EE_Error
138
-     */
139
-    public static function process_ajax_request($ajax_action)
140
-    {
141
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
142
-        EED_Single_Page_Checkout::instance()->_initialize();
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     *    ajax display registration step
149
-     *
150
-     * @throws EE_Error
151
-     */
152
-    public static function display_reg_step()
153
-    {
154
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     *    ajax process registration step
161
-     *
162
-     * @throws EE_Error
163
-     */
164
-    public static function process_reg_step()
165
-    {
166
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     *    ajax process registration step
173
-     *
174
-     * @throws EE_Error
175
-     */
176
-    public static function update_reg_step()
177
-    {
178
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     *   update_checkout
185
-     *
186
-     * @access public
187
-     * @return void
188
-     * @throws EE_Error
189
-     */
190
-    public static function update_checkout()
191
-    {
192
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     *    load_request_handler
199
-     *
200
-     * @access    public
201
-     * @return    void
202
-     */
203
-    public static function load_request_handler()
204
-    {
205
-        // load core Request_Handler class
206
-        if (EE_Registry::instance()->REQ !== null) {
207
-            EE_Registry::instance()->load_core('Request_Handler');
208
-        }
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     *    set_definitions
215
-     *
216
-     * @access    public
217
-     * @return    void
218
-     * @throws EE_Error
219
-     */
220
-    public static function set_definitions()
221
-    {
222
-        if(defined('SPCO_BASE_PATH')) {
223
-            return;
224
-        }
225
-        define(
226
-            'SPCO_BASE_PATH',
227
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
228
-        );
229
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
230
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
231
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
232
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
233
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
234
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
235
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
236
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * load_reg_steps
243
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
244
-     *
245
-     * @access    private
246
-     * @throws EE_Error
247
-     */
248
-    public static function load_reg_steps()
249
-    {
250
-        static $reg_steps_loaded = false;
251
-        if ($reg_steps_loaded) {
252
-            return;
253
-        }
254
-        // filter list of reg_steps
255
-        $reg_steps_to_load = (array)apply_filters(
256
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
257
-            EED_Single_Page_Checkout::get_reg_steps()
258
-        );
259
-        // sort by key (order)
260
-        ksort($reg_steps_to_load);
261
-        // loop through folders
262
-        foreach ($reg_steps_to_load as $order => $reg_step) {
263
-            // we need a
264
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
265
-                // copy over to the reg_steps_array
266
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
267
-                // register custom key route for each reg step
268
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
269
-                EE_Config::register_route(
270
-                    $reg_step['slug'],
271
-                    'EED_Single_Page_Checkout',
272
-                    'run',
273
-                    'step'
274
-                );
275
-                // add AJAX or other hooks
276
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
277
-                    // setup autoloaders if necessary
278
-                    if ( ! class_exists($reg_step['class_name'])) {
279
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
280
-                            $reg_step['file_path'],
281
-                            true
282
-                        );
283
-                    }
284
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
285
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
286
-                    }
287
-                }
288
-            }
289
-        }
290
-        $reg_steps_loaded = true;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     *    get_reg_steps
297
-     *
298
-     * @access    public
299
-     * @return    array
300
-     */
301
-    public static function get_reg_steps()
302
-    {
303
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
304
-        if (empty($reg_steps)) {
305
-            $reg_steps = array(
306
-                10  => array(
307
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
308
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
309
-                    'slug'       => 'attendee_information',
310
-                    'has_hooks'  => false,
311
-                ),
312
-                30  => array(
313
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
314
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
315
-                    'slug'       => 'payment_options',
316
-                    'has_hooks'  => true,
317
-                ),
318
-                999 => array(
319
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
320
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
321
-                    'slug'       => 'finalize_registration',
322
-                    'has_hooks'  => false,
323
-                ),
324
-            );
325
-        }
326
-        return $reg_steps;
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     *    registration_checkout_for_admin
333
-     *
334
-     * @access    public
335
-     * @return    string
336
-     * @throws EE_Error
337
-     */
338
-    public static function registration_checkout_for_admin()
339
-    {
340
-        EED_Single_Page_Checkout::load_request_handler();
341
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
342
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
343
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
344
-        EED_Single_Page_Checkout::instance()->_initialize();
345
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
346
-        return EE_Registry::instance()->REQ->get_output();
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * process_registration_from_admin
353
-     *
354
-     * @access public
355
-     * @return \EE_Transaction
356
-     * @throws EE_Error
357
-     */
358
-    public static function process_registration_from_admin()
359
-    {
360
-        EED_Single_Page_Checkout::load_request_handler();
361
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
362
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
363
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
364
-        EED_Single_Page_Checkout::instance()->_initialize();
365
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
366
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
367
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
368
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
369
-                if ($final_reg_step->process_reg_step()) {
370
-                    $final_reg_step->set_completed();
371
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
372
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
373
-                }
374
-            }
375
-        }
376
-        return null;
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     *    run
383
-     *
384
-     * @access    public
385
-     * @param WP_Query $WP_Query
386
-     * @return    void
387
-     * @throws EE_Error
388
-     */
389
-    public function run($WP_Query)
390
-    {
391
-        if (
392
-            $WP_Query instanceof WP_Query
393
-            && $WP_Query->is_main_query()
394
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
395
-            && $this->_is_reg_checkout()
396
-        ) {
397
-            $this->_initialize();
398
-        }
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * determines whether current url matches reg page url
405
-     *
406
-     * @return bool
407
-     */
408
-    protected function _is_reg_checkout()
409
-    {
410
-        // get current permalink for reg page without any extra query args
411
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
412
-        // get request URI for current request, but without the scheme or host
413
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
414
-        $current_request_uri = html_entity_decode($current_request_uri);
415
-        // get array of query args from the current request URI
416
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
417
-        // grab page id if it is set
418
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
419
-        // and remove the page id from the query args (we will re-add it later)
420
-        unset($query_args['page_id']);
421
-        // now strip all query args from current request URI
422
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
423
-        // and re-add the page id if it was set
424
-        if ($page_id) {
425
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
426
-        }
427
-        // remove slashes and ?
428
-        $current_request_uri = trim($current_request_uri, '?/');
429
-        // is current request URI part of the known full reg page URL ?
430
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * @param WP_Query $wp_query
437
-     * @return    void
438
-     * @throws EE_Error
439
-     */
440
-    public static function init($wp_query)
441
-    {
442
-        EED_Single_Page_Checkout::instance()->run($wp_query);
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     *    _initialize - initial module setup
449
-     *
450
-     * @access    private
451
-     * @throws EE_Error
452
-     * @return    void
453
-     */
454
-    private function _initialize()
455
-    {
456
-        // ensure SPCO doesn't run twice
457
-        if (EED_Single_Page_Checkout::$_initialized) {
458
-            return;
459
-        }
460
-        try {
461
-            EED_Single_Page_Checkout::load_reg_steps();
462
-            $this->_verify_session();
463
-            // setup the EE_Checkout object
464
-            $this->checkout = $this->_initialize_checkout();
465
-            // filter checkout
466
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
467
-            // get the $_GET
468
-            $this->_get_request_vars();
469
-            if ($this->_block_bots()) {
470
-                return;
471
-            }
472
-            // filter continue_reg
473
-            $this->checkout->continue_reg = apply_filters(
474
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
475
-                true,
476
-                $this->checkout
477
-            );
478
-            // load the reg steps array
479
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
480
-                EED_Single_Page_Checkout::$_initialized = true;
481
-                return;
482
-            }
483
-            // set the current step
484
-            $this->checkout->set_current_step($this->checkout->step);
485
-            // and the next step
486
-            $this->checkout->set_next_step();
487
-            // verify that everything has been setup correctly
488
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
489
-                EED_Single_Page_Checkout::$_initialized = true;
490
-                return;
491
-            }
492
-            // lock the transaction
493
-            $this->checkout->transaction->lock();
494
-            // make sure all of our cached objects are added to their respective model entity mappers
495
-            $this->checkout->refresh_all_entities();
496
-            // set amount owing
497
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
498
-            // initialize each reg step, which gives them the chance to potentially alter the process
499
-            $this->_initialize_reg_steps();
500
-            // DEBUG LOG
501
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
502
-            // get reg form
503
-            if( ! $this->_check_form_submission()) {
504
-                EED_Single_Page_Checkout::$_initialized = true;
505
-                return;
506
-            }
507
-            // checkout the action!!!
508
-            $this->_process_form_action();
509
-            // add some style and make it dance
510
-            $this->add_styles_and_scripts();
511
-            // kk... SPCO has successfully run
512
-            EED_Single_Page_Checkout::$_initialized = true;
513
-            // set no cache headers and constants
514
-            EE_System::do_not_cache();
515
-            // add anchor
516
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
517
-            // remove transaction lock
518
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
519
-        } catch (Exception $e) {
520
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
521
-        }
522
-    }
523
-
524
-
525
-
526
-    /**
527
-     *    _verify_session
528
-     * checks that the session is valid and not expired
529
-     *
530
-     * @access    private
531
-     * @throws EE_Error
532
-     */
533
-    private function _verify_session()
534
-    {
535
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
536
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
537
-        }
538
-        $clear_session_requested = filter_var(
539
-            EE_Registry::instance()->REQ->get('clear_session', false),
540
-            FILTER_VALIDATE_BOOLEAN
541
-        );
542
-        // is session still valid ?
543
-        if ($clear_session_requested
544
-            || ( EE_Registry::instance()->SSN->expired()
545
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
546
-            )
547
-        ) {
548
-            $this->checkout = new EE_Checkout();
549
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
550
-            // EE_Registry::instance()->SSN->reset_cart();
551
-            // EE_Registry::instance()->SSN->reset_checkout();
552
-            // EE_Registry::instance()->SSN->reset_transaction();
553
-            if (! $clear_session_requested) {
554
-                EE_Error::add_attention(
555
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
556
-                    __FILE__, __FUNCTION__, __LINE__
557
-                );
558
-            }
559
-            // EE_Registry::instance()->SSN->reset_expired();
560
-        }
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     *    _initialize_checkout
567
-     * loads and instantiates EE_Checkout
568
-     *
569
-     * @access    private
570
-     * @throws EE_Error
571
-     * @return EE_Checkout
572
-     */
573
-    private function _initialize_checkout()
574
-    {
575
-        // look in session for existing checkout
576
-        /** @type EE_Checkout $checkout */
577
-        $checkout = EE_Registry::instance()->SSN->checkout();
578
-        // verify
579
-        if ( ! $checkout instanceof EE_Checkout) {
580
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
581
-            $checkout = EE_Registry::instance()->load_file(
582
-                SPCO_INC_PATH,
583
-                'EE_Checkout',
584
-                'class', array(),
585
-                false
586
-            );
587
-        } else {
588
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
589
-                $this->unlock_transaction();
590
-                wp_safe_redirect($checkout->redirect_url);
591
-                exit();
592
-            }
593
-        }
594
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
595
-        // verify again
596
-        if ( ! $checkout instanceof EE_Checkout) {
597
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
598
-        }
599
-        // reset anything that needs a clean slate for each request
600
-        $checkout->reset_for_current_request();
601
-        return $checkout;
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     *    _get_request_vars
608
-     *
609
-     * @access    private
610
-     * @return    void
611
-     * @throws EE_Error
612
-     */
613
-    private function _get_request_vars()
614
-    {
615
-        // load classes
616
-        EED_Single_Page_Checkout::load_request_handler();
617
-        //make sure this request is marked as belonging to EE
618
-        EE_Registry::instance()->REQ->set_espresso_page(true);
619
-        // which step is being requested ?
620
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
621
-        // which step is being edited ?
622
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
623
-        // and what we're doing on the current step
624
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
625
-        // timestamp
626
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
627
-        // returning to edit ?
628
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
629
-        // add reg url link to registration query params
630
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
631
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
632
-        }
633
-        // or some other kind of revisit ?
634
-        $this->checkout->revisit = filter_var(
635
-            EE_Registry::instance()->REQ->get('revisit', false),
636
-            FILTER_VALIDATE_BOOLEAN
637
-        );
638
-        // and whether or not to generate a reg form for this request
639
-        $this->checkout->generate_reg_form = filter_var(
640
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to process a reg form submission for this request
644
-        $this->checkout->process_form_submission = filter_var(
645
-            EE_Registry::instance()->REQ->get(
646
-                'process_form_submission',
647
-                $this->checkout->action === 'process_reg_step'
648
-            ),
649
-            FILTER_VALIDATE_BOOLEAN
650
-        );
651
-        $this->checkout->process_form_submission = filter_var(
652
-            $this->checkout->action !== 'display_spco_reg_step'
653
-                ? $this->checkout->process_form_submission
654
-                : false,
655
-            FILTER_VALIDATE_BOOLEAN
656
-        );
657
-        // $this->_display_request_vars();
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     *  _display_request_vars
664
-     *
665
-     * @access    protected
666
-     * @return    void
667
-     */
668
-    protected function _display_request_vars()
669
-    {
670
-        if ( ! WP_DEBUG) {
671
-            return;
672
-        }
673
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
674
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
675
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
676
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
677
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
678
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * _block_bots
687
-     * checks that the incoming request has either of the following set:
688
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
689
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
690
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
691
-     * then where you coming from man?
692
-     *
693
-     * @return boolean
694
-     */
695
-    private function _block_bots()
696
-    {
697
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
698
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
699
-            return true;
700
-        }
701
-        return false;
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     *    _get_first_step
708
-     *  gets slug for first step in $_reg_steps_array
709
-     *
710
-     * @access    private
711
-     * @throws EE_Error
712
-     * @return    string
713
-     */
714
-    private function _get_first_step()
715
-    {
716
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
717
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
718
-    }
719
-
720
-
721
-    /**
722
-     * instantiates each reg step based on the loaded reg_steps array
723
-     *
724
-     * @return    bool
725
-     * @throws EE_Error
726
-     * @throws InvalidArgumentException
727
-     * @throws InvalidDataTypeException
728
-     * @throws InvalidInterfaceException
729
-     */
730
-    private function _load_and_instantiate_reg_steps()
731
-    {
732
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
733
-        // have reg_steps already been instantiated ?
734
-        if (
735
-            empty($this->checkout->reg_steps)
736
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
737
-        ) {
738
-            // if not, then loop through raw reg steps array
739
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
740
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
741
-                    return false;
742
-                }
743
-            }
744
-            if(isset($this->checkout->reg_steps['registration_confirmation'])){
745
-                // skip the registration_confirmation page ?
746
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
747
-                    // just remove it from the reg steps array
748
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
749
-                } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
750
-                ) {
751
-                    // set the order to something big like 100
752
-                    $this->checkout->set_reg_step_order('registration_confirmation', 100);
753
-                }
754
-            }
755
-            // filter the array for good luck
756
-            $this->checkout->reg_steps = apply_filters(
757
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
758
-                $this->checkout->reg_steps
759
-            );
760
-            // finally re-sort based on the reg step class order properties
761
-            $this->checkout->sort_reg_steps();
762
-        } else {
763
-            foreach ($this->checkout->reg_steps as $reg_step) {
764
-                // set all current step stati to FALSE
765
-                $reg_step->set_is_current_step(false);
766
-            }
767
-        }
768
-        if (empty($this->checkout->reg_steps)) {
769
-            EE_Error::add_error(
770
-                __('No Reg Steps were loaded..', 'event_espresso'),
771
-                __FILE__, __FUNCTION__, __LINE__
772
-            );
773
-            return false;
774
-        }
775
-        // make reg step details available to JS
776
-        $this->checkout->set_reg_step_JSON_info();
777
-        return true;
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     *     _load_and_instantiate_reg_step
784
-     *
785
-     * @access    private
786
-     * @param array $reg_step
787
-     * @param int   $order
788
-     * @return bool
789
-     */
790
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
791
-    {
792
-        // we need a file_path, class_name, and slug to add a reg step
793
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
794
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
795
-            if (
796
-                $this->checkout->reg_url_link
797
-                && $this->checkout->step !== $reg_step['slug']
798
-                && $reg_step['slug'] !== 'finalize_registration'
799
-                // normally at this point we would NOT load the reg step, but this filter can change that
800
-                && apply_filters(
801
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
802
-                    true,
803
-                    $reg_step,
804
-                    $this->checkout
805
-                )
806
-            ) {
807
-                return true;
808
-            }
809
-            // instantiate step class using file path and class name
810
-            $reg_step_obj = EE_Registry::instance()->load_file(
811
-                $reg_step['file_path'],
812
-                $reg_step['class_name'],
813
-                'class',
814
-                $this->checkout,
815
-                false
816
-            );
817
-            // did we gets the goods ?
818
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
819
-                // set reg step order based on config
820
-                $reg_step_obj->set_order($order);
821
-                // add instantiated reg step object to the master reg steps array
822
-                $this->checkout->add_reg_step($reg_step_obj);
823
-            } else {
824
-                EE_Error::add_error(
825
-                    __('The current step could not be set.', 'event_espresso'),
826
-                    __FILE__, __FUNCTION__, __LINE__
827
-                );
828
-                return false;
829
-            }
830
-        } else {
831
-            if (WP_DEBUG) {
832
-                EE_Error::add_error(
833
-                    sprintf(
834
-                        __(
835
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
836
-                            'event_espresso'
837
-                        ),
838
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
839
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
840
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
841
-                        '<ul>',
842
-                        '<li>',
843
-                        '</li>',
844
-                        '</ul>'
845
-                    ),
846
-                    __FILE__, __FUNCTION__, __LINE__
847
-                );
848
-            }
849
-            return false;
850
-        }
851
-        return true;
852
-    }
853
-
854
-
855
-    /**
856
-     * _verify_transaction_and_get_registrations
857
-     *
858
-     * @access private
859
-     * @return bool
860
-     * @throws InvalidDataTypeException
861
-     * @throws InvalidEntityException
862
-     * @throws EE_Error
863
-     */
864
-    private function _verify_transaction_and_get_registrations()
865
-    {
866
-        // was there already a valid transaction in the checkout from the session ?
867
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
868
-            // get transaction from db or session
869
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
870
-                ? $this->_get_transaction_and_cart_for_previous_visit()
871
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
872
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
873
-                EE_Error::add_error(
874
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
875
-                        'event_espresso'),
876
-                    __FILE__, __FUNCTION__, __LINE__
877
-                );
878
-                $this->checkout->transaction = EE_Transaction::new_instance();
879
-                // add some style and make it dance
880
-                $this->add_styles_and_scripts();
881
-                EED_Single_Page_Checkout::$_initialized = true;
882
-                return false;
883
-            }
884
-            // and the registrations for the transaction
885
-            $this->_get_registrations($this->checkout->transaction);
886
-        }
887
-        return true;
888
-    }
889
-
890
-
891
-
892
-    /**
893
-     * _get_transaction_and_cart_for_previous_visit
894
-     *
895
-     * @access private
896
-     * @return mixed EE_Transaction|NULL
897
-     */
898
-    private function _get_transaction_and_cart_for_previous_visit()
899
-    {
900
-        /** @var $TXN_model EEM_Transaction */
901
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
902
-        // because the reg_url_link is present in the request,
903
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
904
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
905
-        // verify transaction
906
-        if ($transaction instanceof EE_Transaction) {
907
-            // and get the cart that was used for that transaction
908
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
909
-            return $transaction;
910
-        }
911
-        EE_Error::add_error(
912
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
913
-            __FILE__, __FUNCTION__, __LINE__
914
-        );
915
-        return null;
916
-
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * _get_cart_for_transaction
923
-     *
924
-     * @access private
925
-     * @param EE_Transaction $transaction
926
-     * @return EE_Cart
927
-     */
928
-    private function _get_cart_for_transaction($transaction)
929
-    {
930
-        return $this->checkout->get_cart_for_transaction($transaction);
931
-    }
932
-
933
-
934
-
935
-    /**
936
-     * get_cart_for_transaction
937
-     *
938
-     * @access public
939
-     * @param EE_Transaction $transaction
940
-     * @return EE_Cart
941
-     */
942
-    public function get_cart_for_transaction(EE_Transaction $transaction)
943
-    {
944
-        return $this->checkout->get_cart_for_transaction($transaction);
945
-    }
946
-
947
-
948
-
949
-    /**
950
-     * _get_transaction_and_cart_for_current_session
951
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
952
-     *
953
-     * @access private
954
-     * @return EE_Transaction
955
-     * @throws EE_Error
956
-     */
957
-    private function _get_cart_for_current_session_and_setup_new_transaction()
958
-    {
959
-        //  if there's no transaction, then this is the FIRST visit to SPCO
960
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
961
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
962
-        // and then create a new transaction
963
-        $transaction = $this->_initialize_transaction();
964
-        // verify transaction
965
-        if ($transaction instanceof EE_Transaction) {
966
-            // save it so that we have an ID for other objects to use
967
-            $transaction->save();
968
-            // and save TXN data to the cart
969
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
970
-        } else {
971
-            EE_Error::add_error(
972
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
973
-                __FILE__, __FUNCTION__, __LINE__
974
-            );
975
-        }
976
-        return $transaction;
977
-    }
978
-
979
-
980
-
981
-    /**
982
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
983
-     *
984
-     * @access private
985
-     * @return mixed EE_Transaction|NULL
986
-     */
987
-    private function _initialize_transaction()
988
-    {
989
-        try {
990
-            // ensure cart totals have been calculated
991
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
992
-            // grab the cart grand total
993
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
994
-            // create new TXN
995
-            $transaction = EE_Transaction::new_instance(
996
-                array(
997
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
998
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
999
-                    'TXN_paid'      => 0,
1000
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1001
-                )
1002
-            );
1003
-            // save it so that we have an ID for other objects to use
1004
-            $transaction->save();
1005
-            // set cron job for following up on TXNs after their session has expired
1006
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1007
-                EE_Registry::instance()->SSN->expiration() + 1,
1008
-                $transaction->ID()
1009
-            );
1010
-            return $transaction;
1011
-        } catch (Exception $e) {
1012
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1013
-        }
1014
-        return null;
1015
-    }
1016
-
1017
-
1018
-    /**
1019
-     * _get_registrations
1020
-     *
1021
-     * @access private
1022
-     * @param EE_Transaction $transaction
1023
-     * @return void
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidEntityException
1026
-     * @throws EE_Error
1027
-     */
1028
-    private function _get_registrations(EE_Transaction $transaction)
1029
-    {
1030
-        // first step: grab the registrants  { : o
1031
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1032
-        $this->checkout->total_ticket_count = count($registrations);
1033
-        // verify registrations have been set
1034
-        if (empty($registrations)) {
1035
-            // if no cached registrations, then check the db
1036
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1037
-            // still nothing ? well as long as this isn't a revisit
1038
-            if (empty($registrations) && ! $this->checkout->revisit) {
1039
-                // generate new registrations from scratch
1040
-                $registrations = $this->_initialize_registrations($transaction);
1041
-            }
1042
-        }
1043
-        // sort by their original registration order
1044
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1045
-        // then loop thru the array
1046
-        foreach ($registrations as $registration) {
1047
-            // verify each registration
1048
-            if ($registration instanceof EE_Registration) {
1049
-                // we display all attendee info for the primary registrant
1050
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1051
-                    && $registration->is_primary_registrant()
1052
-                ) {
1053
-                    $this->checkout->primary_revisit = true;
1054
-                    break;
1055
-                }
1056
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1057
-                    // but hide info if it doesn't belong to you
1058
-                    $transaction->clear_cache('Registration', $registration->ID());
1059
-                    $this->checkout->total_ticket_count--;
1060
-                }
1061
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1062
-            }
1063
-        }
1064
-    }
1065
-
1066
-
1067
-    /**
1068
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1069
-     *
1070
-     * @access private
1071
-     * @param EE_Transaction $transaction
1072
-     * @return    array
1073
-     * @throws InvalidDataTypeException
1074
-     * @throws InvalidEntityException
1075
-     * @throws EE_Error
1076
-     */
1077
-    private function _initialize_registrations(EE_Transaction $transaction)
1078
-    {
1079
-        $att_nmbr = 0;
1080
-        $registrations = array();
1081
-        if ($transaction instanceof EE_Transaction) {
1082
-            /** @type EE_Registration_Processor $registration_processor */
1083
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1084
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1085
-            // now let's add the cart items to the $transaction
1086
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1087
-                //do the following for each ticket of this type they selected
1088
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1089
-                    $att_nmbr++;
1090
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1091
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1092
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1093
-                        array(
1094
-                            $transaction,
1095
-                            $line_item,
1096
-                            $att_nmbr,
1097
-                            $this->checkout->total_ticket_count,
1098
-                        )
1099
-                    );
1100
-                    // override capabilities for frontend registrations
1101
-                    if ( ! is_admin()) {
1102
-                        $CreateRegistrationCommand->setCapCheck(
1103
-                            new PublicCapabilities('', 'create_new_registration')
1104
-                        );
1105
-                    }
1106
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1107
-                    if ( ! $registration instanceof EE_Registration) {
1108
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1109
-                    }
1110
-                    $registrations[ $registration->ID() ] = $registration;
1111
-                }
1112
-            }
1113
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1114
-        }
1115
-        return $registrations;
1116
-    }
1117
-
1118
-
1119
-
1120
-    /**
1121
-     * sorts registrations by REG_count
1122
-     *
1123
-     * @access public
1124
-     * @param EE_Registration $reg_A
1125
-     * @param EE_Registration $reg_B
1126
-     * @return int
1127
-     */
1128
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1129
-    {
1130
-        // this shouldn't ever happen within the same TXN, but oh well
1131
-        if ($reg_A->count() === $reg_B->count()) {
1132
-            return 0;
1133
-        }
1134
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1135
-    }
1136
-
1137
-
1138
-
1139
-    /**
1140
-     *    _final_verifications
1141
-     * just makes sure that everything is set up correctly before proceeding
1142
-     *
1143
-     * @access    private
1144
-     * @return    bool
1145
-     * @throws EE_Error
1146
-     */
1147
-    private function _final_verifications()
1148
-    {
1149
-        // filter checkout
1150
-        $this->checkout = apply_filters(
1151
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1152
-            $this->checkout
1153
-        );
1154
-        //verify that current step is still set correctly
1155
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1156
-            EE_Error::add_error(
1157
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1158
-                __FILE__,
1159
-                __FUNCTION__,
1160
-                __LINE__
1161
-            );
1162
-            return false;
1163
-        }
1164
-        // if returning to SPCO, then verify that primary registrant is set
1165
-        if ( ! empty($this->checkout->reg_url_link)) {
1166
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1167
-            if ( ! $valid_registrant instanceof EE_Registration) {
1168
-                EE_Error::add_error(
1169
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1170
-                    __FILE__,
1171
-                    __FUNCTION__,
1172
-                    __LINE__
1173
-                );
1174
-                return false;
1175
-            }
1176
-            $valid_registrant = null;
1177
-            foreach (
1178
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1179
-            ) {
1180
-                if (
1181
-                    $registration instanceof EE_Registration
1182
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1183
-                ) {
1184
-                    $valid_registrant = $registration;
1185
-                }
1186
-            }
1187
-            if ( ! $valid_registrant instanceof EE_Registration) {
1188
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1189
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1190
-                    // clear the session, mark the checkout as unverified, and try again
1191
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1192
-                    EED_Single_Page_Checkout::$_initialized = false;
1193
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1194
-                    $this->_initialize();
1195
-                    EE_Error::reset_notices();
1196
-                    return false;
1197
-                }
1198
-                EE_Error::add_error(
1199
-                    __(
1200
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1201
-                        'event_espresso'
1202
-                    ),
1203
-                    __FILE__,
1204
-                    __FUNCTION__,
1205
-                    __LINE__
1206
-                );
1207
-                return false;
1208
-            }
1209
-        }
1210
-        // now that things have been kinda sufficiently verified,
1211
-        // let's add the checkout to the session so that it's available to other systems
1212
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1213
-        return true;
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     *    _initialize_reg_steps
1220
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1221
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1222
-     *
1223
-     * @access    private
1224
-     * @param bool $reinitializing
1225
-     * @throws EE_Error
1226
-     */
1227
-    private function _initialize_reg_steps($reinitializing = false)
1228
-    {
1229
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1230
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1231
-        foreach ($this->checkout->reg_steps as $reg_step) {
1232
-            if ( ! $reg_step->initialize_reg_step()) {
1233
-                // if not initialized then maybe this step is being removed...
1234
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1235
-                    // if it was the current step, then we need to start over here
1236
-                    $this->_initialize_reg_steps(true);
1237
-                    return;
1238
-                }
1239
-                continue;
1240
-            }
1241
-            // add css and JS for current step
1242
-            $reg_step->enqueue_styles_and_scripts();
1243
-            // i18n
1244
-            $reg_step->translate_js_strings();
1245
-            if ($reg_step->is_current_step()) {
1246
-                // the text that appears on the reg step form submit button
1247
-                $reg_step->set_submit_button_text();
1248
-            }
1249
-        }
1250
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1251
-        do_action(
1252
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1253
-            $this->checkout->current_step
1254
-        );
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * _check_form_submission
1261
-     *
1262
-     * @access private
1263
-     * @return boolean
1264
-     */
1265
-    private function _check_form_submission()
1266
-    {
1267
-        //does this request require the reg form to be generated ?
1268
-        if ($this->checkout->generate_reg_form) {
1269
-            // ever heard that song by Blue Rodeo ?
1270
-            try {
1271
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1272
-                // if not displaying a form, then check for form submission
1273
-                if (
1274
-                    $this->checkout->process_form_submission
1275
-                    && $this->checkout->current_step->reg_form->was_submitted()
1276
-                ) {
1277
-                    // clear out any old data in case this step is being run again
1278
-                    $this->checkout->current_step->set_valid_data(array());
1279
-                    // capture submitted form data
1280
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1281
-                        apply_filters(
1282
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1283
-                            EE_Registry::instance()->REQ->params(),
1284
-                            $this->checkout
1285
-                        )
1286
-                    );
1287
-                    // validate submitted form data
1288
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1289
-                        // thou shall not pass !!!
1290
-                        $this->checkout->continue_reg = false;
1291
-                        // any form validation errors?
1292
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1293
-                            EE_Error::add_error(
1294
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1295
-                                __FILE__, __FUNCTION__, __LINE__
1296
-                            );
1297
-                        }
1298
-                        // well not really... what will happen is
1299
-                        // we'll just get redirected back to redo the current step
1300
-                        $this->go_to_next_step();
1301
-                        return false;
1302
-                    }
1303
-                }
1304
-            } catch (EE_Error $e) {
1305
-                $e->get_error();
1306
-            }
1307
-        }
1308
-        return true;
1309
-    }
1310
-
1311
-
1312
-
1313
-    /**
1314
-     * _process_action
1315
-     *
1316
-     * @access private
1317
-     * @return void
1318
-     * @throws EE_Error
1319
-     */
1320
-    private function _process_form_action()
1321
-    {
1322
-        // what cha wanna do?
1323
-        switch ($this->checkout->action) {
1324
-            // AJAX next step reg form
1325
-            case 'display_spco_reg_step' :
1326
-                $this->checkout->redirect = false;
1327
-                if (EE_Registry::instance()->REQ->ajax) {
1328
-                    $this->checkout->json_response->set_reg_step_html(
1329
-                        $this->checkout->current_step->display_reg_form()
1330
-                    );
1331
-                }
1332
-                break;
1333
-            default :
1334
-                // meh... do one of those other steps first
1335
-                if (
1336
-                    ! empty($this->checkout->action)
1337
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1338
-                ) {
1339
-                    // dynamically creates hook point like:
1340
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1341
-                    do_action(
1342
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1343
-                        $this->checkout->current_step
1344
-                    );
1345
-                    // call action on current step
1346
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1347
-                        // good registrant, you get to proceed
1348
-                        if (
1349
-                            $this->checkout->current_step->success_message() !== ''
1350
-                            && apply_filters(
1351
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1352
-                                false
1353
-                            )
1354
-                        ) {
1355
-                            EE_Error::add_success(
1356
-                                $this->checkout->current_step->success_message()
1357
-                                . '<br />' . $this->checkout->next_step->_instructions()
1358
-                            );
1359
-                        }
1360
-                        // pack it up, pack it in...
1361
-                        $this->_setup_redirect();
1362
-                    }
1363
-                    // dynamically creates hook point like:
1364
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1365
-                    do_action(
1366
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1367
-                        $this->checkout->current_step
1368
-                    );
1369
-                } else {
1370
-                    EE_Error::add_error(
1371
-                        sprintf(
1372
-                            __(
1373
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1374
-                                'event_espresso'
1375
-                            ),
1376
-                            $this->checkout->action,
1377
-                            $this->checkout->current_step->name()
1378
-                        ),
1379
-                        __FILE__,
1380
-                        __FUNCTION__,
1381
-                        __LINE__
1382
-                    );
1383
-                }
1384
-            // end default
1385
-        }
1386
-        // store our progress so far
1387
-        $this->checkout->stash_transaction_and_checkout();
1388
-        // advance to the next step! If you pass GO, collect $200
1389
-        $this->go_to_next_step();
1390
-    }
1391
-
1392
-
1393
-
1394
-    /**
1395
-     *        add_styles_and_scripts
1396
-     *
1397
-     * @access        public
1398
-     * @return        void
1399
-     */
1400
-    public function add_styles_and_scripts()
1401
-    {
1402
-        // i18n
1403
-        $this->translate_js_strings();
1404
-        if ($this->checkout->admin_request) {
1405
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1406
-        } else {
1407
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1408
-        }
1409
-    }
1410
-
1411
-
1412
-
1413
-    /**
1414
-     *        translate_js_strings
1415
-     *
1416
-     * @access        public
1417
-     * @return        void
1418
-     */
1419
-    public function translate_js_strings()
1420
-    {
1421
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1422
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1423
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1424
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1425
-            'event_espresso'
1426
-        );
1427
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1428
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1429
-            'event_espresso'
1430
-        );
1431
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1432
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1433
-            'event_espresso'
1434
-        );
1435
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1436
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1437
-            'event_espresso'
1438
-        );
1439
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1440
-            'This registration step could not be completed. Please refresh the page and try again.',
1441
-            'event_espresso'
1442
-        );
1443
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1444
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1445
-            'event_espresso'
1446
-        );
1447
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1448
-            __(
1449
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1450
-                'event_espresso'
1451
-            ),
1452
-            '<br/>',
1453
-            '<br/>'
1454
-        );
1455
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1456
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1457
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1458
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1459
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1460
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1461
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1462
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1463
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1464
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1465
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1466
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1467
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1468
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1469
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1470
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1471
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1472
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1473
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1474
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1475
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1476
-            true
1477
-        );
1478
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1479
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1480
-        );
1481
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1482
-            'M d, Y H:i:s',
1483
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1484
-        );
1485
-    }
1486
-
1487
-
1488
-
1489
-    /**
1490
-     *    enqueue_styles_and_scripts
1491
-     *
1492
-     * @access        public
1493
-     * @return        void
1494
-     * @throws EE_Error
1495
-     */
1496
-    public function enqueue_styles_and_scripts()
1497
-    {
1498
-        // load css
1499
-        wp_register_style(
1500
-            'single_page_checkout',
1501
-            SPCO_CSS_URL . 'single_page_checkout.css',
1502
-            array('espresso_default'),
1503
-            EVENT_ESPRESSO_VERSION
1504
-        );
1505
-        wp_enqueue_style('single_page_checkout');
1506
-        // load JS
1507
-        wp_register_script(
1508
-            'jquery_plugin',
1509
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1510
-            array('jquery'),
1511
-            '1.0.1',
1512
-            true
1513
-        );
1514
-        wp_register_script(
1515
-            'jquery_countdown',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1517
-            array('jquery_plugin'),
1518
-            '2.0.2',
1519
-            true
1520
-        );
1521
-        wp_register_script(
1522
-            'single_page_checkout',
1523
-            SPCO_JS_URL . 'single_page_checkout.js',
1524
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1525
-            EVENT_ESPRESSO_VERSION,
1526
-            true
1527
-        );
1528
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1529
-            $this->checkout->registration_form->enqueue_js();
1530
-        }
1531
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1532
-            $this->checkout->current_step->reg_form->enqueue_js();
1533
-        }
1534
-        wp_enqueue_script('single_page_checkout');
1535
-        /**
1536
-         * global action hook for enqueueing styles and scripts with
1537
-         * spco calls.
1538
-         */
1539
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1540
-        /**
1541
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1542
-         * The hook will end up being something like:
1543
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1544
-         */
1545
-        do_action(
1546
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1547
-            $this
1548
-        );
1549
-    }
1550
-
1551
-
1552
-
1553
-    /**
1554
-     *    display the Registration Single Page Checkout Form
1555
-     *
1556
-     * @access    private
1557
-     * @return    void
1558
-     * @throws EE_Error
1559
-     */
1560
-    private function _display_spco_reg_form()
1561
-    {
1562
-        // if registering via the admin, just display the reg form for the current step
1563
-        if ($this->checkout->admin_request) {
1564
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1565
-        } else {
1566
-            // add powered by EE msg
1567
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1568
-            $empty_cart = count(
1569
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1570
-            ) < 1;
1571
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1572
-            $cookies_not_set_msg = '';
1573
-            if ($empty_cart) {
1574
-                $cookies_not_set_msg = apply_filters(
1575
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1576
-                    sprintf(
1577
-                        __(
1578
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1579
-                            'event_espresso'
1580
-                        ),
1581
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1582
-                        '</div>',
1583
-                        '<h6 class="important-notice">',
1584
-                        '</h6>',
1585
-                        '<p>',
1586
-                        '</p>',
1587
-                        '<br />',
1588
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1589
-                        '</a>'
1590
-                    )
1591
-                );
1592
-            }
1593
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1594
-                array(
1595
-                    'name'            => 'single-page-checkout',
1596
-                    'html_id'         => 'ee-single-page-checkout-dv',
1597
-                    'layout_strategy' =>
1598
-                        new EE_Template_Layout(
1599
-                            array(
1600
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1601
-                                'template_args'        => array(
1602
-                                    'empty_cart'              => $empty_cart,
1603
-                                    'revisit'                 => $this->checkout->revisit,
1604
-                                    'reg_steps'               => $this->checkout->reg_steps,
1605
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1606
-                                        ? $this->checkout->next_step->slug()
1607
-                                        : '',
1608
-                                    'empty_msg'               => apply_filters(
1609
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1610
-                                        sprintf(
1611
-                                            __(
1612
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1613
-                                                'event_espresso'
1614
-                                            ),
1615
-                                            '<a href="'
1616
-                                            . get_post_type_archive_link('espresso_events')
1617
-                                            . '" title="',
1618
-                                            '">',
1619
-                                            '</a>'
1620
-                                        )
1621
-                                    ),
1622
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1623
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1624
-                                    'session_expiration'      => gmdate(
1625
-                                        'M d, Y H:i:s',
1626
-                                        EE_Registry::instance()->SSN->expiration()
1627
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1628
-                                    ),
1629
-                                ),
1630
-                            )
1631
-                        ),
1632
-                )
1633
-            );
1634
-            // load template and add to output sent that gets filtered into the_content()
1635
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1636
-        }
1637
-    }
1638
-
1639
-
1640
-
1641
-    /**
1642
-     *    add_extra_finalize_registration_inputs
1643
-     *
1644
-     * @access    public
1645
-     * @param $next_step
1646
-     * @internal  param string $label
1647
-     * @return void
1648
-     */
1649
-    public function add_extra_finalize_registration_inputs($next_step)
1650
-    {
1651
-        if ($next_step === 'finalize_registration') {
1652
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1653
-        }
1654
-    }
1655
-
1656
-
1657
-
1658
-    /**
1659
-     *    display_registration_footer
1660
-     *
1661
-     * @access    public
1662
-     * @return    string
1663
-     */
1664
-    public static function display_registration_footer()
1665
-    {
1666
-        if (
1667
-        apply_filters(
1668
-            'FHEE__EE_Front__Controller__show_reg_footer',
1669
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1670
-        )
1671
-        ) {
1672
-            add_filter(
1673
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1674
-                function ($url) {
1675
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1676
-                }
1677
-            );
1678
-            echo apply_filters(
1679
-                'FHEE__EE_Front_Controller__display_registration_footer',
1680
-                \EEH_Template::powered_by_event_espresso(
1681
-                    '',
1682
-                    'espresso-registration-footer-dv',
1683
-                    array('utm_content' => 'registration_checkout')
1684
-                )
1685
-            );
1686
-        }
1687
-        return '';
1688
-    }
1689
-
1690
-
1691
-
1692
-    /**
1693
-     *    unlock_transaction
1694
-     *
1695
-     * @access    public
1696
-     * @return    void
1697
-     * @throws EE_Error
1698
-     */
1699
-    public function unlock_transaction()
1700
-    {
1701
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1702
-            $this->checkout->transaction->unlock();
1703
-        }
1704
-    }
1705
-
1706
-
1707
-
1708
-    /**
1709
-     *        _setup_redirect
1710
-     *
1711
-     * @access    private
1712
-     * @return void
1713
-     */
1714
-    private function _setup_redirect()
1715
-    {
1716
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1717
-            $this->checkout->redirect = true;
1718
-            if (empty($this->checkout->redirect_url)) {
1719
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1720
-            }
1721
-            $this->checkout->redirect_url = apply_filters(
1722
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1723
-                $this->checkout->redirect_url,
1724
-                $this->checkout
1725
-            );
1726
-        }
1727
-    }
1728
-
1729
-
1730
-
1731
-    /**
1732
-     *   handle ajax message responses and redirects
1733
-     *
1734
-     * @access public
1735
-     * @return void
1736
-     * @throws EE_Error
1737
-     */
1738
-    public function go_to_next_step()
1739
-    {
1740
-        if (EE_Registry::instance()->REQ->ajax) {
1741
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1742
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1743
-        }
1744
-        $this->unlock_transaction();
1745
-        // just return for these conditions
1746
-        if (
1747
-            $this->checkout->admin_request
1748
-            || $this->checkout->action === 'redirect_form'
1749
-            || $this->checkout->action === 'update_checkout'
1750
-        ) {
1751
-            return;
1752
-        }
1753
-        // AJAX response
1754
-        $this->_handle_json_response();
1755
-        // redirect to next step or the Thank You page
1756
-        $this->_handle_html_redirects();
1757
-        // hmmm... must be something wrong, so let's just display the form again !
1758
-        $this->_display_spco_reg_form();
1759
-    }
1760
-
1761
-
1762
-
1763
-    /**
1764
-     *   _handle_json_response
1765
-     *
1766
-     * @access protected
1767
-     * @return void
1768
-     */
1769
-    protected function _handle_json_response()
1770
-    {
1771
-        // if this is an ajax request
1772
-        if (EE_Registry::instance()->REQ->ajax) {
1773
-            // DEBUG LOG
1774
-            //$this->checkout->log(
1775
-            //	__CLASS__, __FUNCTION__, __LINE__,
1776
-            //	array(
1777
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1778
-            //		'redirect'                   => $this->checkout->redirect,
1779
-            //		'continue_reg'               => $this->checkout->continue_reg,
1780
-            //	)
1781
-            //);
1782
-            $this->checkout->json_response->set_registration_time_limit(
1783
-                $this->checkout->get_registration_time_limit()
1784
-            );
1785
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1786
-            // just send the ajax (
1787
-            $json_response = apply_filters(
1788
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1789
-                $this->checkout->json_response
1790
-            );
1791
-            echo $json_response;
1792
-            exit();
1793
-        }
1794
-    }
1795
-
1796
-
1797
-
1798
-    /**
1799
-     *   _handle_redirects
1800
-     *
1801
-     * @access protected
1802
-     * @return void
1803
-     */
1804
-    protected function _handle_html_redirects()
1805
-    {
1806
-        // going somewhere ?
1807
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1808
-            // store notices in a transient
1809
-            EE_Error::get_notices(false, true, true);
1810
-            // DEBUG LOG
1811
-            //$this->checkout->log(
1812
-            //	__CLASS__, __FUNCTION__, __LINE__,
1813
-            //	array(
1814
-            //		'headers_sent' => headers_sent(),
1815
-            //		'redirect_url'     => $this->checkout->redirect_url,
1816
-            //		'headers_list'    => headers_list(),
1817
-            //	)
1818
-            //);
1819
-            wp_safe_redirect($this->checkout->redirect_url);
1820
-            exit();
1821
-        }
1822
-    }
1823
-
1824
-
1825
-
1826
-    /**
1827
-     *   set_checkout_anchor
1828
-     *
1829
-     * @access public
1830
-     * @return void
1831
-     */
1832
-    public function set_checkout_anchor()
1833
-    {
1834
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1835
-    }
1836
-
1837
-    /**
1838
-     *    getRegistrationExpirationNotice
1839
-     *
1840
-     * @since 4.9.59.p
1841
-     * @access    public
1842
-     * @return    string
1843
-     */
1844
-    public static function getRegistrationExpirationNotice()
1845
-    {
1846
-        return sprintf(
1847
-            __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1848
-                'event_espresso'),
1849
-            '<h4 class="important-notice">',
1850
-            '</h4>',
1851
-            '<br />',
1852
-            '<p>',
1853
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1854
-            '">',
1855
-            '</a>',
1856
-            '</p>'
1857
-        );
1858
-    }
24
+	/**
25
+	 * $_initialized - has the SPCO controller already been initialized ?
26
+	 *
27
+	 * @access private
28
+	 * @var bool $_initialized
29
+	 */
30
+	private static $_initialized = false;
31
+
32
+
33
+	/**
34
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
35
+	 *
36
+	 * @access private
37
+	 * @var bool $_valid_checkout
38
+	 */
39
+	private static $_checkout_verified = true;
40
+
41
+	/**
42
+	 *    $_reg_steps_array - holds initial array of reg steps
43
+	 *
44
+	 * @access private
45
+	 * @var array $_reg_steps_array
46
+	 */
47
+	private static $_reg_steps_array = array();
48
+
49
+	/**
50
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
51
+	 *
52
+	 * @access public
53
+	 * @var EE_Checkout $checkout
54
+	 */
55
+	public $checkout;
56
+
57
+
58
+
59
+	/**
60
+	 * @return EED_Module|EED_Single_Page_Checkout
61
+	 */
62
+	public static function instance()
63
+	{
64
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
+		return parent::get_instance(__CLASS__);
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * @return EE_CART
72
+	 */
73
+	public function cart()
74
+	{
75
+		return $this->checkout->cart;
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * @return EE_Transaction
82
+	 */
83
+	public function transaction()
84
+	{
85
+		return $this->checkout->transaction;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 *    set_hooks - for hooking into EE Core, other modules, etc
92
+	 *
93
+	 * @access    public
94
+	 * @return    void
95
+	 * @throws EE_Error
96
+	 */
97
+	public static function set_hooks()
98
+	{
99
+		EED_Single_Page_Checkout::set_definitions();
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 * @throws EE_Error
110
+	 */
111
+	public static function set_hooks_admin()
112
+	{
113
+		EED_Single_Page_Checkout::set_definitions();
114
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
115
+			return;
116
+		}
117
+		// going to start an output buffer in case anything gets accidentally output
118
+		// that might disrupt our JSON response
119
+		ob_start();
120
+		EED_Single_Page_Checkout::load_request_handler();
121
+		EED_Single_Page_Checkout::load_reg_steps();
122
+		// set ajax hooks
123
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
125
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
127
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 *    process ajax request
135
+	 *
136
+	 * @param string $ajax_action
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function process_ajax_request($ajax_action)
140
+	{
141
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
142
+		EED_Single_Page_Checkout::instance()->_initialize();
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 *    ajax display registration step
149
+	 *
150
+	 * @throws EE_Error
151
+	 */
152
+	public static function display_reg_step()
153
+	{
154
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 *    ajax process registration step
161
+	 *
162
+	 * @throws EE_Error
163
+	 */
164
+	public static function process_reg_step()
165
+	{
166
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 *    ajax process registration step
173
+	 *
174
+	 * @throws EE_Error
175
+	 */
176
+	public static function update_reg_step()
177
+	{
178
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 *   update_checkout
185
+	 *
186
+	 * @access public
187
+	 * @return void
188
+	 * @throws EE_Error
189
+	 */
190
+	public static function update_checkout()
191
+	{
192
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 *    load_request_handler
199
+	 *
200
+	 * @access    public
201
+	 * @return    void
202
+	 */
203
+	public static function load_request_handler()
204
+	{
205
+		// load core Request_Handler class
206
+		if (EE_Registry::instance()->REQ !== null) {
207
+			EE_Registry::instance()->load_core('Request_Handler');
208
+		}
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 *    set_definitions
215
+	 *
216
+	 * @access    public
217
+	 * @return    void
218
+	 * @throws EE_Error
219
+	 */
220
+	public static function set_definitions()
221
+	{
222
+		if(defined('SPCO_BASE_PATH')) {
223
+			return;
224
+		}
225
+		define(
226
+			'SPCO_BASE_PATH',
227
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
228
+		);
229
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
230
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
231
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
232
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
233
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
234
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
235
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
236
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * load_reg_steps
243
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
244
+	 *
245
+	 * @access    private
246
+	 * @throws EE_Error
247
+	 */
248
+	public static function load_reg_steps()
249
+	{
250
+		static $reg_steps_loaded = false;
251
+		if ($reg_steps_loaded) {
252
+			return;
253
+		}
254
+		// filter list of reg_steps
255
+		$reg_steps_to_load = (array)apply_filters(
256
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
257
+			EED_Single_Page_Checkout::get_reg_steps()
258
+		);
259
+		// sort by key (order)
260
+		ksort($reg_steps_to_load);
261
+		// loop through folders
262
+		foreach ($reg_steps_to_load as $order => $reg_step) {
263
+			// we need a
264
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
265
+				// copy over to the reg_steps_array
266
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
267
+				// register custom key route for each reg step
268
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
269
+				EE_Config::register_route(
270
+					$reg_step['slug'],
271
+					'EED_Single_Page_Checkout',
272
+					'run',
273
+					'step'
274
+				);
275
+				// add AJAX or other hooks
276
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
277
+					// setup autoloaders if necessary
278
+					if ( ! class_exists($reg_step['class_name'])) {
279
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
280
+							$reg_step['file_path'],
281
+							true
282
+						);
283
+					}
284
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
285
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
286
+					}
287
+				}
288
+			}
289
+		}
290
+		$reg_steps_loaded = true;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 *    get_reg_steps
297
+	 *
298
+	 * @access    public
299
+	 * @return    array
300
+	 */
301
+	public static function get_reg_steps()
302
+	{
303
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
304
+		if (empty($reg_steps)) {
305
+			$reg_steps = array(
306
+				10  => array(
307
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
308
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
309
+					'slug'       => 'attendee_information',
310
+					'has_hooks'  => false,
311
+				),
312
+				30  => array(
313
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
314
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
315
+					'slug'       => 'payment_options',
316
+					'has_hooks'  => true,
317
+				),
318
+				999 => array(
319
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
320
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
321
+					'slug'       => 'finalize_registration',
322
+					'has_hooks'  => false,
323
+				),
324
+			);
325
+		}
326
+		return $reg_steps;
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 *    registration_checkout_for_admin
333
+	 *
334
+	 * @access    public
335
+	 * @return    string
336
+	 * @throws EE_Error
337
+	 */
338
+	public static function registration_checkout_for_admin()
339
+	{
340
+		EED_Single_Page_Checkout::load_request_handler();
341
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
342
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
343
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
344
+		EED_Single_Page_Checkout::instance()->_initialize();
345
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
346
+		return EE_Registry::instance()->REQ->get_output();
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * process_registration_from_admin
353
+	 *
354
+	 * @access public
355
+	 * @return \EE_Transaction
356
+	 * @throws EE_Error
357
+	 */
358
+	public static function process_registration_from_admin()
359
+	{
360
+		EED_Single_Page_Checkout::load_request_handler();
361
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
362
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
363
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
364
+		EED_Single_Page_Checkout::instance()->_initialize();
365
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
366
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
367
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
368
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
369
+				if ($final_reg_step->process_reg_step()) {
370
+					$final_reg_step->set_completed();
371
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
372
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
373
+				}
374
+			}
375
+		}
376
+		return null;
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 *    run
383
+	 *
384
+	 * @access    public
385
+	 * @param WP_Query $WP_Query
386
+	 * @return    void
387
+	 * @throws EE_Error
388
+	 */
389
+	public function run($WP_Query)
390
+	{
391
+		if (
392
+			$WP_Query instanceof WP_Query
393
+			&& $WP_Query->is_main_query()
394
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
395
+			&& $this->_is_reg_checkout()
396
+		) {
397
+			$this->_initialize();
398
+		}
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * determines whether current url matches reg page url
405
+	 *
406
+	 * @return bool
407
+	 */
408
+	protected function _is_reg_checkout()
409
+	{
410
+		// get current permalink for reg page without any extra query args
411
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
412
+		// get request URI for current request, but without the scheme or host
413
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
414
+		$current_request_uri = html_entity_decode($current_request_uri);
415
+		// get array of query args from the current request URI
416
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
417
+		// grab page id if it is set
418
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
419
+		// and remove the page id from the query args (we will re-add it later)
420
+		unset($query_args['page_id']);
421
+		// now strip all query args from current request URI
422
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
423
+		// and re-add the page id if it was set
424
+		if ($page_id) {
425
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
426
+		}
427
+		// remove slashes and ?
428
+		$current_request_uri = trim($current_request_uri, '?/');
429
+		// is current request URI part of the known full reg page URL ?
430
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * @param WP_Query $wp_query
437
+	 * @return    void
438
+	 * @throws EE_Error
439
+	 */
440
+	public static function init($wp_query)
441
+	{
442
+		EED_Single_Page_Checkout::instance()->run($wp_query);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 *    _initialize - initial module setup
449
+	 *
450
+	 * @access    private
451
+	 * @throws EE_Error
452
+	 * @return    void
453
+	 */
454
+	private function _initialize()
455
+	{
456
+		// ensure SPCO doesn't run twice
457
+		if (EED_Single_Page_Checkout::$_initialized) {
458
+			return;
459
+		}
460
+		try {
461
+			EED_Single_Page_Checkout::load_reg_steps();
462
+			$this->_verify_session();
463
+			// setup the EE_Checkout object
464
+			$this->checkout = $this->_initialize_checkout();
465
+			// filter checkout
466
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
467
+			// get the $_GET
468
+			$this->_get_request_vars();
469
+			if ($this->_block_bots()) {
470
+				return;
471
+			}
472
+			// filter continue_reg
473
+			$this->checkout->continue_reg = apply_filters(
474
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
475
+				true,
476
+				$this->checkout
477
+			);
478
+			// load the reg steps array
479
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
480
+				EED_Single_Page_Checkout::$_initialized = true;
481
+				return;
482
+			}
483
+			// set the current step
484
+			$this->checkout->set_current_step($this->checkout->step);
485
+			// and the next step
486
+			$this->checkout->set_next_step();
487
+			// verify that everything has been setup correctly
488
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
489
+				EED_Single_Page_Checkout::$_initialized = true;
490
+				return;
491
+			}
492
+			// lock the transaction
493
+			$this->checkout->transaction->lock();
494
+			// make sure all of our cached objects are added to their respective model entity mappers
495
+			$this->checkout->refresh_all_entities();
496
+			// set amount owing
497
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
498
+			// initialize each reg step, which gives them the chance to potentially alter the process
499
+			$this->_initialize_reg_steps();
500
+			// DEBUG LOG
501
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
502
+			// get reg form
503
+			if( ! $this->_check_form_submission()) {
504
+				EED_Single_Page_Checkout::$_initialized = true;
505
+				return;
506
+			}
507
+			// checkout the action!!!
508
+			$this->_process_form_action();
509
+			// add some style and make it dance
510
+			$this->add_styles_and_scripts();
511
+			// kk... SPCO has successfully run
512
+			EED_Single_Page_Checkout::$_initialized = true;
513
+			// set no cache headers and constants
514
+			EE_System::do_not_cache();
515
+			// add anchor
516
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
517
+			// remove transaction lock
518
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
519
+		} catch (Exception $e) {
520
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
521
+		}
522
+	}
523
+
524
+
525
+
526
+	/**
527
+	 *    _verify_session
528
+	 * checks that the session is valid and not expired
529
+	 *
530
+	 * @access    private
531
+	 * @throws EE_Error
532
+	 */
533
+	private function _verify_session()
534
+	{
535
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
536
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
537
+		}
538
+		$clear_session_requested = filter_var(
539
+			EE_Registry::instance()->REQ->get('clear_session', false),
540
+			FILTER_VALIDATE_BOOLEAN
541
+		);
542
+		// is session still valid ?
543
+		if ($clear_session_requested
544
+			|| ( EE_Registry::instance()->SSN->expired()
545
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
546
+			)
547
+		) {
548
+			$this->checkout = new EE_Checkout();
549
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
550
+			// EE_Registry::instance()->SSN->reset_cart();
551
+			// EE_Registry::instance()->SSN->reset_checkout();
552
+			// EE_Registry::instance()->SSN->reset_transaction();
553
+			if (! $clear_session_requested) {
554
+				EE_Error::add_attention(
555
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
556
+					__FILE__, __FUNCTION__, __LINE__
557
+				);
558
+			}
559
+			// EE_Registry::instance()->SSN->reset_expired();
560
+		}
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 *    _initialize_checkout
567
+	 * loads and instantiates EE_Checkout
568
+	 *
569
+	 * @access    private
570
+	 * @throws EE_Error
571
+	 * @return EE_Checkout
572
+	 */
573
+	private function _initialize_checkout()
574
+	{
575
+		// look in session for existing checkout
576
+		/** @type EE_Checkout $checkout */
577
+		$checkout = EE_Registry::instance()->SSN->checkout();
578
+		// verify
579
+		if ( ! $checkout instanceof EE_Checkout) {
580
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
581
+			$checkout = EE_Registry::instance()->load_file(
582
+				SPCO_INC_PATH,
583
+				'EE_Checkout',
584
+				'class', array(),
585
+				false
586
+			);
587
+		} else {
588
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
589
+				$this->unlock_transaction();
590
+				wp_safe_redirect($checkout->redirect_url);
591
+				exit();
592
+			}
593
+		}
594
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
595
+		// verify again
596
+		if ( ! $checkout instanceof EE_Checkout) {
597
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
598
+		}
599
+		// reset anything that needs a clean slate for each request
600
+		$checkout->reset_for_current_request();
601
+		return $checkout;
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 *    _get_request_vars
608
+	 *
609
+	 * @access    private
610
+	 * @return    void
611
+	 * @throws EE_Error
612
+	 */
613
+	private function _get_request_vars()
614
+	{
615
+		// load classes
616
+		EED_Single_Page_Checkout::load_request_handler();
617
+		//make sure this request is marked as belonging to EE
618
+		EE_Registry::instance()->REQ->set_espresso_page(true);
619
+		// which step is being requested ?
620
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
621
+		// which step is being edited ?
622
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
623
+		// and what we're doing on the current step
624
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
625
+		// timestamp
626
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
627
+		// returning to edit ?
628
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
629
+		// add reg url link to registration query params
630
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
631
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
632
+		}
633
+		// or some other kind of revisit ?
634
+		$this->checkout->revisit = filter_var(
635
+			EE_Registry::instance()->REQ->get('revisit', false),
636
+			FILTER_VALIDATE_BOOLEAN
637
+		);
638
+		// and whether or not to generate a reg form for this request
639
+		$this->checkout->generate_reg_form = filter_var(
640
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to process a reg form submission for this request
644
+		$this->checkout->process_form_submission = filter_var(
645
+			EE_Registry::instance()->REQ->get(
646
+				'process_form_submission',
647
+				$this->checkout->action === 'process_reg_step'
648
+			),
649
+			FILTER_VALIDATE_BOOLEAN
650
+		);
651
+		$this->checkout->process_form_submission = filter_var(
652
+			$this->checkout->action !== 'display_spco_reg_step'
653
+				? $this->checkout->process_form_submission
654
+				: false,
655
+			FILTER_VALIDATE_BOOLEAN
656
+		);
657
+		// $this->_display_request_vars();
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 *  _display_request_vars
664
+	 *
665
+	 * @access    protected
666
+	 * @return    void
667
+	 */
668
+	protected function _display_request_vars()
669
+	{
670
+		if ( ! WP_DEBUG) {
671
+			return;
672
+		}
673
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
674
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
675
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
676
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
677
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
678
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * _block_bots
687
+	 * checks that the incoming request has either of the following set:
688
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
689
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
690
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
691
+	 * then where you coming from man?
692
+	 *
693
+	 * @return boolean
694
+	 */
695
+	private function _block_bots()
696
+	{
697
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
698
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
699
+			return true;
700
+		}
701
+		return false;
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 *    _get_first_step
708
+	 *  gets slug for first step in $_reg_steps_array
709
+	 *
710
+	 * @access    private
711
+	 * @throws EE_Error
712
+	 * @return    string
713
+	 */
714
+	private function _get_first_step()
715
+	{
716
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
717
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
718
+	}
719
+
720
+
721
+	/**
722
+	 * instantiates each reg step based on the loaded reg_steps array
723
+	 *
724
+	 * @return    bool
725
+	 * @throws EE_Error
726
+	 * @throws InvalidArgumentException
727
+	 * @throws InvalidDataTypeException
728
+	 * @throws InvalidInterfaceException
729
+	 */
730
+	private function _load_and_instantiate_reg_steps()
731
+	{
732
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
733
+		// have reg_steps already been instantiated ?
734
+		if (
735
+			empty($this->checkout->reg_steps)
736
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
737
+		) {
738
+			// if not, then loop through raw reg steps array
739
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
740
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
741
+					return false;
742
+				}
743
+			}
744
+			if(isset($this->checkout->reg_steps['registration_confirmation'])){
745
+				// skip the registration_confirmation page ?
746
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
747
+					// just remove it from the reg steps array
748
+					$this->checkout->remove_reg_step('registration_confirmation', false);
749
+				} elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
750
+				) {
751
+					// set the order to something big like 100
752
+					$this->checkout->set_reg_step_order('registration_confirmation', 100);
753
+				}
754
+			}
755
+			// filter the array for good luck
756
+			$this->checkout->reg_steps = apply_filters(
757
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
758
+				$this->checkout->reg_steps
759
+			);
760
+			// finally re-sort based on the reg step class order properties
761
+			$this->checkout->sort_reg_steps();
762
+		} else {
763
+			foreach ($this->checkout->reg_steps as $reg_step) {
764
+				// set all current step stati to FALSE
765
+				$reg_step->set_is_current_step(false);
766
+			}
767
+		}
768
+		if (empty($this->checkout->reg_steps)) {
769
+			EE_Error::add_error(
770
+				__('No Reg Steps were loaded..', 'event_espresso'),
771
+				__FILE__, __FUNCTION__, __LINE__
772
+			);
773
+			return false;
774
+		}
775
+		// make reg step details available to JS
776
+		$this->checkout->set_reg_step_JSON_info();
777
+		return true;
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 *     _load_and_instantiate_reg_step
784
+	 *
785
+	 * @access    private
786
+	 * @param array $reg_step
787
+	 * @param int   $order
788
+	 * @return bool
789
+	 */
790
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
791
+	{
792
+		// we need a file_path, class_name, and slug to add a reg step
793
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
794
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
795
+			if (
796
+				$this->checkout->reg_url_link
797
+				&& $this->checkout->step !== $reg_step['slug']
798
+				&& $reg_step['slug'] !== 'finalize_registration'
799
+				// normally at this point we would NOT load the reg step, but this filter can change that
800
+				&& apply_filters(
801
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
802
+					true,
803
+					$reg_step,
804
+					$this->checkout
805
+				)
806
+			) {
807
+				return true;
808
+			}
809
+			// instantiate step class using file path and class name
810
+			$reg_step_obj = EE_Registry::instance()->load_file(
811
+				$reg_step['file_path'],
812
+				$reg_step['class_name'],
813
+				'class',
814
+				$this->checkout,
815
+				false
816
+			);
817
+			// did we gets the goods ?
818
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
819
+				// set reg step order based on config
820
+				$reg_step_obj->set_order($order);
821
+				// add instantiated reg step object to the master reg steps array
822
+				$this->checkout->add_reg_step($reg_step_obj);
823
+			} else {
824
+				EE_Error::add_error(
825
+					__('The current step could not be set.', 'event_espresso'),
826
+					__FILE__, __FUNCTION__, __LINE__
827
+				);
828
+				return false;
829
+			}
830
+		} else {
831
+			if (WP_DEBUG) {
832
+				EE_Error::add_error(
833
+					sprintf(
834
+						__(
835
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
836
+							'event_espresso'
837
+						),
838
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
839
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
840
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
841
+						'<ul>',
842
+						'<li>',
843
+						'</li>',
844
+						'</ul>'
845
+					),
846
+					__FILE__, __FUNCTION__, __LINE__
847
+				);
848
+			}
849
+			return false;
850
+		}
851
+		return true;
852
+	}
853
+
854
+
855
+	/**
856
+	 * _verify_transaction_and_get_registrations
857
+	 *
858
+	 * @access private
859
+	 * @return bool
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws InvalidEntityException
862
+	 * @throws EE_Error
863
+	 */
864
+	private function _verify_transaction_and_get_registrations()
865
+	{
866
+		// was there already a valid transaction in the checkout from the session ?
867
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
868
+			// get transaction from db or session
869
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
870
+				? $this->_get_transaction_and_cart_for_previous_visit()
871
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
872
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
873
+				EE_Error::add_error(
874
+					__('Your Registration and Transaction information could not be retrieved from the db.',
875
+						'event_espresso'),
876
+					__FILE__, __FUNCTION__, __LINE__
877
+				);
878
+				$this->checkout->transaction = EE_Transaction::new_instance();
879
+				// add some style and make it dance
880
+				$this->add_styles_and_scripts();
881
+				EED_Single_Page_Checkout::$_initialized = true;
882
+				return false;
883
+			}
884
+			// and the registrations for the transaction
885
+			$this->_get_registrations($this->checkout->transaction);
886
+		}
887
+		return true;
888
+	}
889
+
890
+
891
+
892
+	/**
893
+	 * _get_transaction_and_cart_for_previous_visit
894
+	 *
895
+	 * @access private
896
+	 * @return mixed EE_Transaction|NULL
897
+	 */
898
+	private function _get_transaction_and_cart_for_previous_visit()
899
+	{
900
+		/** @var $TXN_model EEM_Transaction */
901
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
902
+		// because the reg_url_link is present in the request,
903
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
904
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
905
+		// verify transaction
906
+		if ($transaction instanceof EE_Transaction) {
907
+			// and get the cart that was used for that transaction
908
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
909
+			return $transaction;
910
+		}
911
+		EE_Error::add_error(
912
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
913
+			__FILE__, __FUNCTION__, __LINE__
914
+		);
915
+		return null;
916
+
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * _get_cart_for_transaction
923
+	 *
924
+	 * @access private
925
+	 * @param EE_Transaction $transaction
926
+	 * @return EE_Cart
927
+	 */
928
+	private function _get_cart_for_transaction($transaction)
929
+	{
930
+		return $this->checkout->get_cart_for_transaction($transaction);
931
+	}
932
+
933
+
934
+
935
+	/**
936
+	 * get_cart_for_transaction
937
+	 *
938
+	 * @access public
939
+	 * @param EE_Transaction $transaction
940
+	 * @return EE_Cart
941
+	 */
942
+	public function get_cart_for_transaction(EE_Transaction $transaction)
943
+	{
944
+		return $this->checkout->get_cart_for_transaction($transaction);
945
+	}
946
+
947
+
948
+
949
+	/**
950
+	 * _get_transaction_and_cart_for_current_session
951
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
952
+	 *
953
+	 * @access private
954
+	 * @return EE_Transaction
955
+	 * @throws EE_Error
956
+	 */
957
+	private function _get_cart_for_current_session_and_setup_new_transaction()
958
+	{
959
+		//  if there's no transaction, then this is the FIRST visit to SPCO
960
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
961
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
962
+		// and then create a new transaction
963
+		$transaction = $this->_initialize_transaction();
964
+		// verify transaction
965
+		if ($transaction instanceof EE_Transaction) {
966
+			// save it so that we have an ID for other objects to use
967
+			$transaction->save();
968
+			// and save TXN data to the cart
969
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
970
+		} else {
971
+			EE_Error::add_error(
972
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
973
+				__FILE__, __FUNCTION__, __LINE__
974
+			);
975
+		}
976
+		return $transaction;
977
+	}
978
+
979
+
980
+
981
+	/**
982
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
983
+	 *
984
+	 * @access private
985
+	 * @return mixed EE_Transaction|NULL
986
+	 */
987
+	private function _initialize_transaction()
988
+	{
989
+		try {
990
+			// ensure cart totals have been calculated
991
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
992
+			// grab the cart grand total
993
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
994
+			// create new TXN
995
+			$transaction = EE_Transaction::new_instance(
996
+				array(
997
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
998
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
999
+					'TXN_paid'      => 0,
1000
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1001
+				)
1002
+			);
1003
+			// save it so that we have an ID for other objects to use
1004
+			$transaction->save();
1005
+			// set cron job for following up on TXNs after their session has expired
1006
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1007
+				EE_Registry::instance()->SSN->expiration() + 1,
1008
+				$transaction->ID()
1009
+			);
1010
+			return $transaction;
1011
+		} catch (Exception $e) {
1012
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1013
+		}
1014
+		return null;
1015
+	}
1016
+
1017
+
1018
+	/**
1019
+	 * _get_registrations
1020
+	 *
1021
+	 * @access private
1022
+	 * @param EE_Transaction $transaction
1023
+	 * @return void
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidEntityException
1026
+	 * @throws EE_Error
1027
+	 */
1028
+	private function _get_registrations(EE_Transaction $transaction)
1029
+	{
1030
+		// first step: grab the registrants  { : o
1031
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1032
+		$this->checkout->total_ticket_count = count($registrations);
1033
+		// verify registrations have been set
1034
+		if (empty($registrations)) {
1035
+			// if no cached registrations, then check the db
1036
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1037
+			// still nothing ? well as long as this isn't a revisit
1038
+			if (empty($registrations) && ! $this->checkout->revisit) {
1039
+				// generate new registrations from scratch
1040
+				$registrations = $this->_initialize_registrations($transaction);
1041
+			}
1042
+		}
1043
+		// sort by their original registration order
1044
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1045
+		// then loop thru the array
1046
+		foreach ($registrations as $registration) {
1047
+			// verify each registration
1048
+			if ($registration instanceof EE_Registration) {
1049
+				// we display all attendee info for the primary registrant
1050
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1051
+					&& $registration->is_primary_registrant()
1052
+				) {
1053
+					$this->checkout->primary_revisit = true;
1054
+					break;
1055
+				}
1056
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1057
+					// but hide info if it doesn't belong to you
1058
+					$transaction->clear_cache('Registration', $registration->ID());
1059
+					$this->checkout->total_ticket_count--;
1060
+				}
1061
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1062
+			}
1063
+		}
1064
+	}
1065
+
1066
+
1067
+	/**
1068
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1069
+	 *
1070
+	 * @access private
1071
+	 * @param EE_Transaction $transaction
1072
+	 * @return    array
1073
+	 * @throws InvalidDataTypeException
1074
+	 * @throws InvalidEntityException
1075
+	 * @throws EE_Error
1076
+	 */
1077
+	private function _initialize_registrations(EE_Transaction $transaction)
1078
+	{
1079
+		$att_nmbr = 0;
1080
+		$registrations = array();
1081
+		if ($transaction instanceof EE_Transaction) {
1082
+			/** @type EE_Registration_Processor $registration_processor */
1083
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1084
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1085
+			// now let's add the cart items to the $transaction
1086
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1087
+				//do the following for each ticket of this type they selected
1088
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1089
+					$att_nmbr++;
1090
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1091
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1092
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1093
+						array(
1094
+							$transaction,
1095
+							$line_item,
1096
+							$att_nmbr,
1097
+							$this->checkout->total_ticket_count,
1098
+						)
1099
+					);
1100
+					// override capabilities for frontend registrations
1101
+					if ( ! is_admin()) {
1102
+						$CreateRegistrationCommand->setCapCheck(
1103
+							new PublicCapabilities('', 'create_new_registration')
1104
+						);
1105
+					}
1106
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1107
+					if ( ! $registration instanceof EE_Registration) {
1108
+						throw new InvalidEntityException($registration, 'EE_Registration');
1109
+					}
1110
+					$registrations[ $registration->ID() ] = $registration;
1111
+				}
1112
+			}
1113
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1114
+		}
1115
+		return $registrations;
1116
+	}
1117
+
1118
+
1119
+
1120
+	/**
1121
+	 * sorts registrations by REG_count
1122
+	 *
1123
+	 * @access public
1124
+	 * @param EE_Registration $reg_A
1125
+	 * @param EE_Registration $reg_B
1126
+	 * @return int
1127
+	 */
1128
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1129
+	{
1130
+		// this shouldn't ever happen within the same TXN, but oh well
1131
+		if ($reg_A->count() === $reg_B->count()) {
1132
+			return 0;
1133
+		}
1134
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1135
+	}
1136
+
1137
+
1138
+
1139
+	/**
1140
+	 *    _final_verifications
1141
+	 * just makes sure that everything is set up correctly before proceeding
1142
+	 *
1143
+	 * @access    private
1144
+	 * @return    bool
1145
+	 * @throws EE_Error
1146
+	 */
1147
+	private function _final_verifications()
1148
+	{
1149
+		// filter checkout
1150
+		$this->checkout = apply_filters(
1151
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1152
+			$this->checkout
1153
+		);
1154
+		//verify that current step is still set correctly
1155
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1156
+			EE_Error::add_error(
1157
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1158
+				__FILE__,
1159
+				__FUNCTION__,
1160
+				__LINE__
1161
+			);
1162
+			return false;
1163
+		}
1164
+		// if returning to SPCO, then verify that primary registrant is set
1165
+		if ( ! empty($this->checkout->reg_url_link)) {
1166
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1167
+			if ( ! $valid_registrant instanceof EE_Registration) {
1168
+				EE_Error::add_error(
1169
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1170
+					__FILE__,
1171
+					__FUNCTION__,
1172
+					__LINE__
1173
+				);
1174
+				return false;
1175
+			}
1176
+			$valid_registrant = null;
1177
+			foreach (
1178
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1179
+			) {
1180
+				if (
1181
+					$registration instanceof EE_Registration
1182
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1183
+				) {
1184
+					$valid_registrant = $registration;
1185
+				}
1186
+			}
1187
+			if ( ! $valid_registrant instanceof EE_Registration) {
1188
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1189
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1190
+					// clear the session, mark the checkout as unverified, and try again
1191
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1192
+					EED_Single_Page_Checkout::$_initialized = false;
1193
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1194
+					$this->_initialize();
1195
+					EE_Error::reset_notices();
1196
+					return false;
1197
+				}
1198
+				EE_Error::add_error(
1199
+					__(
1200
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1201
+						'event_espresso'
1202
+					),
1203
+					__FILE__,
1204
+					__FUNCTION__,
1205
+					__LINE__
1206
+				);
1207
+				return false;
1208
+			}
1209
+		}
1210
+		// now that things have been kinda sufficiently verified,
1211
+		// let's add the checkout to the session so that it's available to other systems
1212
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1213
+		return true;
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 *    _initialize_reg_steps
1220
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1221
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1222
+	 *
1223
+	 * @access    private
1224
+	 * @param bool $reinitializing
1225
+	 * @throws EE_Error
1226
+	 */
1227
+	private function _initialize_reg_steps($reinitializing = false)
1228
+	{
1229
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1230
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1231
+		foreach ($this->checkout->reg_steps as $reg_step) {
1232
+			if ( ! $reg_step->initialize_reg_step()) {
1233
+				// if not initialized then maybe this step is being removed...
1234
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1235
+					// if it was the current step, then we need to start over here
1236
+					$this->_initialize_reg_steps(true);
1237
+					return;
1238
+				}
1239
+				continue;
1240
+			}
1241
+			// add css and JS for current step
1242
+			$reg_step->enqueue_styles_and_scripts();
1243
+			// i18n
1244
+			$reg_step->translate_js_strings();
1245
+			if ($reg_step->is_current_step()) {
1246
+				// the text that appears on the reg step form submit button
1247
+				$reg_step->set_submit_button_text();
1248
+			}
1249
+		}
1250
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1251
+		do_action(
1252
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1253
+			$this->checkout->current_step
1254
+		);
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * _check_form_submission
1261
+	 *
1262
+	 * @access private
1263
+	 * @return boolean
1264
+	 */
1265
+	private function _check_form_submission()
1266
+	{
1267
+		//does this request require the reg form to be generated ?
1268
+		if ($this->checkout->generate_reg_form) {
1269
+			// ever heard that song by Blue Rodeo ?
1270
+			try {
1271
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1272
+				// if not displaying a form, then check for form submission
1273
+				if (
1274
+					$this->checkout->process_form_submission
1275
+					&& $this->checkout->current_step->reg_form->was_submitted()
1276
+				) {
1277
+					// clear out any old data in case this step is being run again
1278
+					$this->checkout->current_step->set_valid_data(array());
1279
+					// capture submitted form data
1280
+					$this->checkout->current_step->reg_form->receive_form_submission(
1281
+						apply_filters(
1282
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1283
+							EE_Registry::instance()->REQ->params(),
1284
+							$this->checkout
1285
+						)
1286
+					);
1287
+					// validate submitted form data
1288
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1289
+						// thou shall not pass !!!
1290
+						$this->checkout->continue_reg = false;
1291
+						// any form validation errors?
1292
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1293
+							EE_Error::add_error(
1294
+								$this->checkout->current_step->reg_form->submission_error_message(),
1295
+								__FILE__, __FUNCTION__, __LINE__
1296
+							);
1297
+						}
1298
+						// well not really... what will happen is
1299
+						// we'll just get redirected back to redo the current step
1300
+						$this->go_to_next_step();
1301
+						return false;
1302
+					}
1303
+				}
1304
+			} catch (EE_Error $e) {
1305
+				$e->get_error();
1306
+			}
1307
+		}
1308
+		return true;
1309
+	}
1310
+
1311
+
1312
+
1313
+	/**
1314
+	 * _process_action
1315
+	 *
1316
+	 * @access private
1317
+	 * @return void
1318
+	 * @throws EE_Error
1319
+	 */
1320
+	private function _process_form_action()
1321
+	{
1322
+		// what cha wanna do?
1323
+		switch ($this->checkout->action) {
1324
+			// AJAX next step reg form
1325
+			case 'display_spco_reg_step' :
1326
+				$this->checkout->redirect = false;
1327
+				if (EE_Registry::instance()->REQ->ajax) {
1328
+					$this->checkout->json_response->set_reg_step_html(
1329
+						$this->checkout->current_step->display_reg_form()
1330
+					);
1331
+				}
1332
+				break;
1333
+			default :
1334
+				// meh... do one of those other steps first
1335
+				if (
1336
+					! empty($this->checkout->action)
1337
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1338
+				) {
1339
+					// dynamically creates hook point like:
1340
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1341
+					do_action(
1342
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1343
+						$this->checkout->current_step
1344
+					);
1345
+					// call action on current step
1346
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1347
+						// good registrant, you get to proceed
1348
+						if (
1349
+							$this->checkout->current_step->success_message() !== ''
1350
+							&& apply_filters(
1351
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1352
+								false
1353
+							)
1354
+						) {
1355
+							EE_Error::add_success(
1356
+								$this->checkout->current_step->success_message()
1357
+								. '<br />' . $this->checkout->next_step->_instructions()
1358
+							);
1359
+						}
1360
+						// pack it up, pack it in...
1361
+						$this->_setup_redirect();
1362
+					}
1363
+					// dynamically creates hook point like:
1364
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1365
+					do_action(
1366
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1367
+						$this->checkout->current_step
1368
+					);
1369
+				} else {
1370
+					EE_Error::add_error(
1371
+						sprintf(
1372
+							__(
1373
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1374
+								'event_espresso'
1375
+							),
1376
+							$this->checkout->action,
1377
+							$this->checkout->current_step->name()
1378
+						),
1379
+						__FILE__,
1380
+						__FUNCTION__,
1381
+						__LINE__
1382
+					);
1383
+				}
1384
+			// end default
1385
+		}
1386
+		// store our progress so far
1387
+		$this->checkout->stash_transaction_and_checkout();
1388
+		// advance to the next step! If you pass GO, collect $200
1389
+		$this->go_to_next_step();
1390
+	}
1391
+
1392
+
1393
+
1394
+	/**
1395
+	 *        add_styles_and_scripts
1396
+	 *
1397
+	 * @access        public
1398
+	 * @return        void
1399
+	 */
1400
+	public function add_styles_and_scripts()
1401
+	{
1402
+		// i18n
1403
+		$this->translate_js_strings();
1404
+		if ($this->checkout->admin_request) {
1405
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1406
+		} else {
1407
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1408
+		}
1409
+	}
1410
+
1411
+
1412
+
1413
+	/**
1414
+	 *        translate_js_strings
1415
+	 *
1416
+	 * @access        public
1417
+	 * @return        void
1418
+	 */
1419
+	public function translate_js_strings()
1420
+	{
1421
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1422
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1423
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1424
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1425
+			'event_espresso'
1426
+		);
1427
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1428
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1429
+			'event_espresso'
1430
+		);
1431
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1432
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1433
+			'event_espresso'
1434
+		);
1435
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1436
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1437
+			'event_espresso'
1438
+		);
1439
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1440
+			'This registration step could not be completed. Please refresh the page and try again.',
1441
+			'event_espresso'
1442
+		);
1443
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1444
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1445
+			'event_espresso'
1446
+		);
1447
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1448
+			__(
1449
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1450
+				'event_espresso'
1451
+			),
1452
+			'<br/>',
1453
+			'<br/>'
1454
+		);
1455
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1456
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1457
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1458
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1459
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1460
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1461
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1462
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1463
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1464
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1465
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1466
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1467
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1468
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1469
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1470
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1471
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1472
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1473
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1474
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1475
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1476
+			true
1477
+		);
1478
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1479
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1480
+		);
1481
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1482
+			'M d, Y H:i:s',
1483
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1484
+		);
1485
+	}
1486
+
1487
+
1488
+
1489
+	/**
1490
+	 *    enqueue_styles_and_scripts
1491
+	 *
1492
+	 * @access        public
1493
+	 * @return        void
1494
+	 * @throws EE_Error
1495
+	 */
1496
+	public function enqueue_styles_and_scripts()
1497
+	{
1498
+		// load css
1499
+		wp_register_style(
1500
+			'single_page_checkout',
1501
+			SPCO_CSS_URL . 'single_page_checkout.css',
1502
+			array('espresso_default'),
1503
+			EVENT_ESPRESSO_VERSION
1504
+		);
1505
+		wp_enqueue_style('single_page_checkout');
1506
+		// load JS
1507
+		wp_register_script(
1508
+			'jquery_plugin',
1509
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1510
+			array('jquery'),
1511
+			'1.0.1',
1512
+			true
1513
+		);
1514
+		wp_register_script(
1515
+			'jquery_countdown',
1516
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1517
+			array('jquery_plugin'),
1518
+			'2.0.2',
1519
+			true
1520
+		);
1521
+		wp_register_script(
1522
+			'single_page_checkout',
1523
+			SPCO_JS_URL . 'single_page_checkout.js',
1524
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1525
+			EVENT_ESPRESSO_VERSION,
1526
+			true
1527
+		);
1528
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1529
+			$this->checkout->registration_form->enqueue_js();
1530
+		}
1531
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1532
+			$this->checkout->current_step->reg_form->enqueue_js();
1533
+		}
1534
+		wp_enqueue_script('single_page_checkout');
1535
+		/**
1536
+		 * global action hook for enqueueing styles and scripts with
1537
+		 * spco calls.
1538
+		 */
1539
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1540
+		/**
1541
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1542
+		 * The hook will end up being something like:
1543
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1544
+		 */
1545
+		do_action(
1546
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1547
+			$this
1548
+		);
1549
+	}
1550
+
1551
+
1552
+
1553
+	/**
1554
+	 *    display the Registration Single Page Checkout Form
1555
+	 *
1556
+	 * @access    private
1557
+	 * @return    void
1558
+	 * @throws EE_Error
1559
+	 */
1560
+	private function _display_spco_reg_form()
1561
+	{
1562
+		// if registering via the admin, just display the reg form for the current step
1563
+		if ($this->checkout->admin_request) {
1564
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1565
+		} else {
1566
+			// add powered by EE msg
1567
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1568
+			$empty_cart = count(
1569
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1570
+			) < 1;
1571
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1572
+			$cookies_not_set_msg = '';
1573
+			if ($empty_cart) {
1574
+				$cookies_not_set_msg = apply_filters(
1575
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1576
+					sprintf(
1577
+						__(
1578
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1579
+							'event_espresso'
1580
+						),
1581
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1582
+						'</div>',
1583
+						'<h6 class="important-notice">',
1584
+						'</h6>',
1585
+						'<p>',
1586
+						'</p>',
1587
+						'<br />',
1588
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1589
+						'</a>'
1590
+					)
1591
+				);
1592
+			}
1593
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1594
+				array(
1595
+					'name'            => 'single-page-checkout',
1596
+					'html_id'         => 'ee-single-page-checkout-dv',
1597
+					'layout_strategy' =>
1598
+						new EE_Template_Layout(
1599
+							array(
1600
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1601
+								'template_args'        => array(
1602
+									'empty_cart'              => $empty_cart,
1603
+									'revisit'                 => $this->checkout->revisit,
1604
+									'reg_steps'               => $this->checkout->reg_steps,
1605
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1606
+										? $this->checkout->next_step->slug()
1607
+										: '',
1608
+									'empty_msg'               => apply_filters(
1609
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1610
+										sprintf(
1611
+											__(
1612
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1613
+												'event_espresso'
1614
+											),
1615
+											'<a href="'
1616
+											. get_post_type_archive_link('espresso_events')
1617
+											. '" title="',
1618
+											'">',
1619
+											'</a>'
1620
+										)
1621
+									),
1622
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1623
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1624
+									'session_expiration'      => gmdate(
1625
+										'M d, Y H:i:s',
1626
+										EE_Registry::instance()->SSN->expiration()
1627
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1628
+									),
1629
+								),
1630
+							)
1631
+						),
1632
+				)
1633
+			);
1634
+			// load template and add to output sent that gets filtered into the_content()
1635
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1636
+		}
1637
+	}
1638
+
1639
+
1640
+
1641
+	/**
1642
+	 *    add_extra_finalize_registration_inputs
1643
+	 *
1644
+	 * @access    public
1645
+	 * @param $next_step
1646
+	 * @internal  param string $label
1647
+	 * @return void
1648
+	 */
1649
+	public function add_extra_finalize_registration_inputs($next_step)
1650
+	{
1651
+		if ($next_step === 'finalize_registration') {
1652
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1653
+		}
1654
+	}
1655
+
1656
+
1657
+
1658
+	/**
1659
+	 *    display_registration_footer
1660
+	 *
1661
+	 * @access    public
1662
+	 * @return    string
1663
+	 */
1664
+	public static function display_registration_footer()
1665
+	{
1666
+		if (
1667
+		apply_filters(
1668
+			'FHEE__EE_Front__Controller__show_reg_footer',
1669
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1670
+		)
1671
+		) {
1672
+			add_filter(
1673
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1674
+				function ($url) {
1675
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1676
+				}
1677
+			);
1678
+			echo apply_filters(
1679
+				'FHEE__EE_Front_Controller__display_registration_footer',
1680
+				\EEH_Template::powered_by_event_espresso(
1681
+					'',
1682
+					'espresso-registration-footer-dv',
1683
+					array('utm_content' => 'registration_checkout')
1684
+				)
1685
+			);
1686
+		}
1687
+		return '';
1688
+	}
1689
+
1690
+
1691
+
1692
+	/**
1693
+	 *    unlock_transaction
1694
+	 *
1695
+	 * @access    public
1696
+	 * @return    void
1697
+	 * @throws EE_Error
1698
+	 */
1699
+	public function unlock_transaction()
1700
+	{
1701
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1702
+			$this->checkout->transaction->unlock();
1703
+		}
1704
+	}
1705
+
1706
+
1707
+
1708
+	/**
1709
+	 *        _setup_redirect
1710
+	 *
1711
+	 * @access    private
1712
+	 * @return void
1713
+	 */
1714
+	private function _setup_redirect()
1715
+	{
1716
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1717
+			$this->checkout->redirect = true;
1718
+			if (empty($this->checkout->redirect_url)) {
1719
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1720
+			}
1721
+			$this->checkout->redirect_url = apply_filters(
1722
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1723
+				$this->checkout->redirect_url,
1724
+				$this->checkout
1725
+			);
1726
+		}
1727
+	}
1728
+
1729
+
1730
+
1731
+	/**
1732
+	 *   handle ajax message responses and redirects
1733
+	 *
1734
+	 * @access public
1735
+	 * @return void
1736
+	 * @throws EE_Error
1737
+	 */
1738
+	public function go_to_next_step()
1739
+	{
1740
+		if (EE_Registry::instance()->REQ->ajax) {
1741
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1742
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1743
+		}
1744
+		$this->unlock_transaction();
1745
+		// just return for these conditions
1746
+		if (
1747
+			$this->checkout->admin_request
1748
+			|| $this->checkout->action === 'redirect_form'
1749
+			|| $this->checkout->action === 'update_checkout'
1750
+		) {
1751
+			return;
1752
+		}
1753
+		// AJAX response
1754
+		$this->_handle_json_response();
1755
+		// redirect to next step or the Thank You page
1756
+		$this->_handle_html_redirects();
1757
+		// hmmm... must be something wrong, so let's just display the form again !
1758
+		$this->_display_spco_reg_form();
1759
+	}
1760
+
1761
+
1762
+
1763
+	/**
1764
+	 *   _handle_json_response
1765
+	 *
1766
+	 * @access protected
1767
+	 * @return void
1768
+	 */
1769
+	protected function _handle_json_response()
1770
+	{
1771
+		// if this is an ajax request
1772
+		if (EE_Registry::instance()->REQ->ajax) {
1773
+			// DEBUG LOG
1774
+			//$this->checkout->log(
1775
+			//	__CLASS__, __FUNCTION__, __LINE__,
1776
+			//	array(
1777
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1778
+			//		'redirect'                   => $this->checkout->redirect,
1779
+			//		'continue_reg'               => $this->checkout->continue_reg,
1780
+			//	)
1781
+			//);
1782
+			$this->checkout->json_response->set_registration_time_limit(
1783
+				$this->checkout->get_registration_time_limit()
1784
+			);
1785
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1786
+			// just send the ajax (
1787
+			$json_response = apply_filters(
1788
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1789
+				$this->checkout->json_response
1790
+			);
1791
+			echo $json_response;
1792
+			exit();
1793
+		}
1794
+	}
1795
+
1796
+
1797
+
1798
+	/**
1799
+	 *   _handle_redirects
1800
+	 *
1801
+	 * @access protected
1802
+	 * @return void
1803
+	 */
1804
+	protected function _handle_html_redirects()
1805
+	{
1806
+		// going somewhere ?
1807
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1808
+			// store notices in a transient
1809
+			EE_Error::get_notices(false, true, true);
1810
+			// DEBUG LOG
1811
+			//$this->checkout->log(
1812
+			//	__CLASS__, __FUNCTION__, __LINE__,
1813
+			//	array(
1814
+			//		'headers_sent' => headers_sent(),
1815
+			//		'redirect_url'     => $this->checkout->redirect_url,
1816
+			//		'headers_list'    => headers_list(),
1817
+			//	)
1818
+			//);
1819
+			wp_safe_redirect($this->checkout->redirect_url);
1820
+			exit();
1821
+		}
1822
+	}
1823
+
1824
+
1825
+
1826
+	/**
1827
+	 *   set_checkout_anchor
1828
+	 *
1829
+	 * @access public
1830
+	 * @return void
1831
+	 */
1832
+	public function set_checkout_anchor()
1833
+	{
1834
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1835
+	}
1836
+
1837
+	/**
1838
+	 *    getRegistrationExpirationNotice
1839
+	 *
1840
+	 * @since 4.9.59.p
1841
+	 * @access    public
1842
+	 * @return    string
1843
+	 */
1844
+	public static function getRegistrationExpirationNotice()
1845
+	{
1846
+		return sprintf(
1847
+			__('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1848
+				'event_espresso'),
1849
+			'<h4 class="important-notice">',
1850
+			'</h4>',
1851
+			'<br />',
1852
+			'<p>',
1853
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1854
+			'">',
1855
+			'</a>',
1856
+			'</p>'
1857
+		);
1858
+	}
1859 1859
 
1860 1860
 }
1861 1861
 // End of file EED_Single_Page_Checkout.module.php
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
      */
220 220
     public static function set_definitions()
221 221
     {
222
-        if(defined('SPCO_BASE_PATH')) {
222
+        if (defined('SPCO_BASE_PATH')) {
223 223
             return;
224 224
         }
225 225
         define(
226 226
             'SPCO_BASE_PATH',
227
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
228 228
         );
229
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
230
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
231
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
232
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
233
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
234
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
229
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
230
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
231
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
232
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
233
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
234
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
235 235
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
236 236
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
237 237
     }
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             return;
253 253
         }
254 254
         // filter list of reg_steps
255
-        $reg_steps_to_load = (array)apply_filters(
255
+        $reg_steps_to_load = (array) apply_filters(
256 256
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
257 257
             EED_Single_Page_Checkout::get_reg_steps()
258 258
         );
@@ -304,19 +304,19 @@  discard block
 block discarded – undo
304 304
         if (empty($reg_steps)) {
305 305
             $reg_steps = array(
306 306
                 10  => array(
307
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
308 308
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
309 309
                     'slug'       => 'attendee_information',
310 310
                     'has_hooks'  => false,
311 311
                 ),
312 312
                 30  => array(
313
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
313
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
314 314
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
315 315
                     'slug'       => 'payment_options',
316 316
                     'has_hooks'  => true,
317 317
                 ),
318 318
                 999 => array(
319
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
319
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
320 320
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
321 321
                     'slug'       => 'finalize_registration',
322 322
                     'has_hooks'  => false,
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
             // DEBUG LOG
501 501
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
502 502
             // get reg form
503
-            if( ! $this->_check_form_submission()) {
503
+            if ( ! $this->_check_form_submission()) {
504 504
                 EED_Single_Page_Checkout::$_initialized = true;
505 505
                 return;
506 506
             }
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         );
542 542
         // is session still valid ?
543 543
         if ($clear_session_requested
544
-            || ( EE_Registry::instance()->SSN->expired()
544
+            || (EE_Registry::instance()->SSN->expired()
545 545
               && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
546 546
             )
547 547
         ) {
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
             // EE_Registry::instance()->SSN->reset_cart();
551 551
             // EE_Registry::instance()->SSN->reset_checkout();
552 552
             // EE_Registry::instance()->SSN->reset_transaction();
553
-            if (! $clear_session_requested) {
553
+            if ( ! $clear_session_requested) {
554 554
                 EE_Error::add_attention(
555 555
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
556 556
                     __FILE__, __FUNCTION__, __LINE__
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
                     return false;
742 742
                 }
743 743
             }
744
-            if(isset($this->checkout->reg_steps['registration_confirmation'])){
744
+            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
745 745
                 // skip the registration_confirmation page ?
746 746
                 if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
747 747
                     // just remove it from the reg steps array
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
                     if ( ! $registration instanceof EE_Registration) {
1108 1108
                         throw new InvalidEntityException($registration, 'EE_Registration');
1109 1109
                     }
1110
-                    $registrations[ $registration->ID() ] = $registration;
1110
+                    $registrations[$registration->ID()] = $registration;
1111 1111
                 }
1112 1112
             }
1113 1113
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
                         ) {
1355 1355
                             EE_Error::add_success(
1356 1356
                                 $this->checkout->current_step->success_message()
1357
-                                . '<br />' . $this->checkout->next_step->_instructions()
1357
+                                . '<br />'.$this->checkout->next_step->_instructions()
1358 1358
                             );
1359 1359
                         }
1360 1360
                         // pack it up, pack it in...
@@ -1498,7 +1498,7 @@  discard block
 block discarded – undo
1498 1498
         // load css
1499 1499
         wp_register_style(
1500 1500
             'single_page_checkout',
1501
-            SPCO_CSS_URL . 'single_page_checkout.css',
1501
+            SPCO_CSS_URL.'single_page_checkout.css',
1502 1502
             array('espresso_default'),
1503 1503
             EVENT_ESPRESSO_VERSION
1504 1504
         );
@@ -1506,21 +1506,21 @@  discard block
 block discarded – undo
1506 1506
         // load JS
1507 1507
         wp_register_script(
1508 1508
             'jquery_plugin',
1509
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1509
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1510 1510
             array('jquery'),
1511 1511
             '1.0.1',
1512 1512
             true
1513 1513
         );
1514 1514
         wp_register_script(
1515 1515
             'jquery_countdown',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1516
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1517 1517
             array('jquery_plugin'),
1518 1518
             '2.0.2',
1519 1519
             true
1520 1520
         );
1521 1521
         wp_register_script(
1522 1522
             'single_page_checkout',
1523
-            SPCO_JS_URL . 'single_page_checkout.js',
1523
+            SPCO_JS_URL.'single_page_checkout.js',
1524 1524
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1525 1525
             EVENT_ESPRESSO_VERSION,
1526 1526
             true
@@ -1543,7 +1543,7 @@  discard block
 block discarded – undo
1543 1543
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1544 1544
          */
1545 1545
         do_action(
1546
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1546
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1547 1547
             $this
1548 1548
         );
1549 1549
     }
@@ -1597,7 +1597,7 @@  discard block
 block discarded – undo
1597 1597
                     'layout_strategy' =>
1598 1598
                         new EE_Template_Layout(
1599 1599
                             array(
1600
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1600
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1601 1601
                                 'template_args'        => array(
1602 1602
                                     'empty_cart'              => $empty_cart,
1603 1603
                                     'revisit'                 => $this->checkout->revisit,
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
         ) {
1672 1672
             add_filter(
1673 1673
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1674
-                function ($url) {
1674
+                function($url) {
1675 1675
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1676 1676
                 }
1677 1677
             );
@@ -1850,7 +1850,7 @@  discard block
 block discarded – undo
1850 1850
             '</h4>',
1851 1851
             '<br />',
1852 1852
             '<p>',
1853
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1853
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1854 1854
             '">',
1855 1855
             '</a>',
1856 1856
             '</p>'
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.024');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.024');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.