Completed
Branch BUG/11302/correct-error-messag... (694f28)
by
unknown
29:59 queued 17:10
created
core/EE_Front_Controller.core.php 2 patches
Indentation   +495 added lines, -495 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\widgets\EspressoWidget;
9 9
 
10 10
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 /**
@@ -31,401 +31,401 @@  discard block
 block discarded – undo
31 31
 final class EE_Front_Controller
32 32
 {
33 33
 
34
-    /**
35
-     * @var string $_template_path
36
-     */
37
-    private $_template_path;
38
-
39
-    /**
40
-     * @var string $_template
41
-     */
42
-    private $_template;
43
-
44
-    /**
45
-     * @type EE_Registry $Registry
46
-     */
47
-    protected $Registry;
48
-
49
-    /**
50
-     * @type EE_Request_Handler $Request_Handler
51
-     */
52
-    protected $Request_Handler;
53
-
54
-    /**
55
-     * @type EE_Module_Request_Router $Module_Request_Router
56
-     */
57
-    protected $Module_Request_Router;
58
-
59
-    /**
60
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
61
-     */
62
-    private $persistent_admin_notice_manager;
63
-
64
-
65
-    /**
66
-     *    class constructor
67
-     *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
68
-     *
69
-     * @access    public
70
-     * @param \EE_Registry              $Registry
71
-     * @param \EE_Request_Handler       $Request_Handler
72
-     * @param \EE_Module_Request_Router $Module_Request_Router
73
-     */
74
-    public function __construct(
75
-        EE_Registry $Registry,
76
-        EE_Request_Handler $Request_Handler,
77
-        EE_Module_Request_Router $Module_Request_Router
78
-    ) {
79
-        $this->Registry              = $Registry;
80
-        $this->Request_Handler       = $Request_Handler;
81
-        $this->Module_Request_Router = $Module_Request_Router;
82
-        // determine how to integrate WP_Query with the EE models
83
-        add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
84
-        // just in case any nag notices are created during the request
85
-        add_action('AHEE__EE_System__initialize_last', array($this, 'loadPersistentAdminNoticeManager'));
86
-        // load other resources and begin to actually run shortcodes and modules
87
-        add_action('wp_loaded', array($this, 'wp_loaded'), 5);
88
-        // analyse the incoming WP request
89
-        add_action('parse_request', array($this, 'get_request'), 1, 1);
90
-        // process request with module factory
91
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
92
-        // before headers sent
93
-        add_action('wp', array($this, 'wp'), 5);
94
-        // primarily used to process any content shortcodes
95
-        add_action('template_redirect', array($this, 'templateRedirect'), 999);
96
-        // header
97
-        add_action('wp_head', array($this, 'header_meta_tag'), 5);
98
-        add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
99
-        add_filter('template_include', array($this, 'template_include'), 1);
100
-        // display errors
101
-        add_action('loop_start', array($this, 'display_errors'), 2);
102
-        // the content
103
-        // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
104
-        //exclude our private cpt comments
105
-        add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
106
-        //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
107
-        add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
108
-        // action hook EE
109
-        do_action('AHEE__EE_Front_Controller__construct__done', $this);
110
-    }
111
-
112
-
113
-    /**
114
-     * @return EE_Request_Handler
115
-     */
116
-    public function Request_Handler()
117
-    {
118
-        return $this->Request_Handler;
119
-    }
120
-
121
-
122
-    /**
123
-     * @return EE_Module_Request_Router
124
-     */
125
-    public function Module_Request_Router()
126
-    {
127
-        return $this->Module_Request_Router;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return LegacyShortcodesManager
134
-     */
135
-    public function getLegacyShortcodesManager()
136
-    {
137
-        return EE_Config::getLegacyShortcodesManager();
138
-    }
139
-
140
-
141
-
142
-
143
-
144
-    /***********************************************        INIT ACTION HOOK         ***********************************************/
145
-
146
-
147
-
148
-    /**
149
-     * filter_wp_comments
150
-     * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
151
-     * widgets/queries done on frontend
152
-     *
153
-     * @param  array $clauses array of comment clauses setup by WP_Comment_Query
154
-     * @return array array of comment clauses with modifications.
155
-     */
156
-    public function filter_wp_comments($clauses)
157
-    {
158
-        global $wpdb;
159
-        if (strpos($clauses['join'], $wpdb->posts) !== false) {
160
-            $cpts = EE_Register_CPTs::get_private_CPTs();
161
-            foreach ($cpts as $cpt => $details) {
162
-                $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
163
-            }
164
-        }
165
-        return $clauses;
166
-    }
167
-
168
-
169
-    /**
170
-     * @return void
171
-     * @throws EE_Error
172
-     * @throws ReflectionException
173
-     */
174
-    public function employ_CPT_Strategy()
175
-    {
176
-        if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
177
-            $this->Registry->load_core('CPT_Strategy');
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * @return void
184
-     * @throws InvalidArgumentException
185
-     * @throws InvalidDataTypeException
186
-     * @throws InvalidInterfaceException
187
-     */
188
-    public function loadPersistentAdminNoticeManager()
189
-    {
190
-        $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
191
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
192
-        );
193
-    }
194
-
195
-
196
-    /**
197
-     * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
198
-     *
199
-     * @param  string $url incoming url
200
-     * @return string         final assembled url
201
-     */
202
-    public function maybe_force_admin_ajax_ssl($url)
203
-    {
204
-        if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
205
-            $url = str_replace('http://', 'https://', $url);
206
-        }
207
-        return $url;
208
-    }
34
+	/**
35
+	 * @var string $_template_path
36
+	 */
37
+	private $_template_path;
38
+
39
+	/**
40
+	 * @var string $_template
41
+	 */
42
+	private $_template;
43
+
44
+	/**
45
+	 * @type EE_Registry $Registry
46
+	 */
47
+	protected $Registry;
48
+
49
+	/**
50
+	 * @type EE_Request_Handler $Request_Handler
51
+	 */
52
+	protected $Request_Handler;
53
+
54
+	/**
55
+	 * @type EE_Module_Request_Router $Module_Request_Router
56
+	 */
57
+	protected $Module_Request_Router;
58
+
59
+	/**
60
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
61
+	 */
62
+	private $persistent_admin_notice_manager;
63
+
64
+
65
+	/**
66
+	 *    class constructor
67
+	 *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
68
+	 *
69
+	 * @access    public
70
+	 * @param \EE_Registry              $Registry
71
+	 * @param \EE_Request_Handler       $Request_Handler
72
+	 * @param \EE_Module_Request_Router $Module_Request_Router
73
+	 */
74
+	public function __construct(
75
+		EE_Registry $Registry,
76
+		EE_Request_Handler $Request_Handler,
77
+		EE_Module_Request_Router $Module_Request_Router
78
+	) {
79
+		$this->Registry              = $Registry;
80
+		$this->Request_Handler       = $Request_Handler;
81
+		$this->Module_Request_Router = $Module_Request_Router;
82
+		// determine how to integrate WP_Query with the EE models
83
+		add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy'));
84
+		// just in case any nag notices are created during the request
85
+		add_action('AHEE__EE_System__initialize_last', array($this, 'loadPersistentAdminNoticeManager'));
86
+		// load other resources and begin to actually run shortcodes and modules
87
+		add_action('wp_loaded', array($this, 'wp_loaded'), 5);
88
+		// analyse the incoming WP request
89
+		add_action('parse_request', array($this, 'get_request'), 1, 1);
90
+		// process request with module factory
91
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
92
+		// before headers sent
93
+		add_action('wp', array($this, 'wp'), 5);
94
+		// primarily used to process any content shortcodes
95
+		add_action('template_redirect', array($this, 'templateRedirect'), 999);
96
+		// header
97
+		add_action('wp_head', array($this, 'header_meta_tag'), 5);
98
+		add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
99
+		add_filter('template_include', array($this, 'template_include'), 1);
100
+		// display errors
101
+		add_action('loop_start', array($this, 'display_errors'), 2);
102
+		// the content
103
+		// add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
104
+		//exclude our private cpt comments
105
+		add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
106
+		//make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
107
+		add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
108
+		// action hook EE
109
+		do_action('AHEE__EE_Front_Controller__construct__done', $this);
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return EE_Request_Handler
115
+	 */
116
+	public function Request_Handler()
117
+	{
118
+		return $this->Request_Handler;
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return EE_Module_Request_Router
124
+	 */
125
+	public function Module_Request_Router()
126
+	{
127
+		return $this->Module_Request_Router;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return LegacyShortcodesManager
134
+	 */
135
+	public function getLegacyShortcodesManager()
136
+	{
137
+		return EE_Config::getLegacyShortcodesManager();
138
+	}
139
+
140
+
141
+
142
+
143
+
144
+	/***********************************************        INIT ACTION HOOK         ***********************************************/
145
+
146
+
147
+
148
+	/**
149
+	 * filter_wp_comments
150
+	 * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
151
+	 * widgets/queries done on frontend
152
+	 *
153
+	 * @param  array $clauses array of comment clauses setup by WP_Comment_Query
154
+	 * @return array array of comment clauses with modifications.
155
+	 */
156
+	public function filter_wp_comments($clauses)
157
+	{
158
+		global $wpdb;
159
+		if (strpos($clauses['join'], $wpdb->posts) !== false) {
160
+			$cpts = EE_Register_CPTs::get_private_CPTs();
161
+			foreach ($cpts as $cpt => $details) {
162
+				$clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
163
+			}
164
+		}
165
+		return $clauses;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return void
171
+	 * @throws EE_Error
172
+	 * @throws ReflectionException
173
+	 */
174
+	public function employ_CPT_Strategy()
175
+	{
176
+		if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) {
177
+			$this->Registry->load_core('CPT_Strategy');
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return void
184
+	 * @throws InvalidArgumentException
185
+	 * @throws InvalidDataTypeException
186
+	 * @throws InvalidInterfaceException
187
+	 */
188
+	public function loadPersistentAdminNoticeManager()
189
+	{
190
+		$this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
191
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
192
+		);
193
+	}
194
+
195
+
196
+	/**
197
+	 * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
198
+	 *
199
+	 * @param  string $url incoming url
200
+	 * @return string         final assembled url
201
+	 */
202
+	public function maybe_force_admin_ajax_ssl($url)
203
+	{
204
+		if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
205
+			$url = str_replace('http://', 'https://', $url);
206
+		}
207
+		return $url;
208
+	}
209 209
 
210 210
 
211 211
 
212
-
213
-
214
-
215
-    /***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
216
-
217
-
218
-    /**
219
-     *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
220
-     *    default priority init phases have run
221
-     *
222
-     * @access    public
223
-     * @return    void
224
-     */
225
-    public function wp_loaded()
226
-    {
227
-    }
228
-
229
-
230
-
231
-
232
-
233
-    /***********************************************        PARSE_REQUEST HOOK         ***********************************************/
234
-    /**
235
-     *    _get_request
236
-     *
237
-     * @access public
238
-     * @param WP $WP
239
-     * @return void
240
-     */
241
-    public function get_request(WP $WP)
242
-    {
243
-        do_action('AHEE__EE_Front_Controller__get_request__start');
244
-        $this->Request_Handler->parse_request($WP);
245
-        do_action('AHEE__EE_Front_Controller__get_request__complete');
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
252
-     *
253
-     * @access    public
254
-     * @param   WP_Query $WP_Query
255
-     * @return    void
256
-     */
257
-    public function pre_get_posts($WP_Query)
258
-    {
259
-        // only load Module_Request_Router if this is the main query
260
-        if (
261
-            $this->Module_Request_Router instanceof EE_Module_Request_Router
262
-            && $WP_Query->is_main_query()
263
-        ) {
264
-            // cycle thru module routes
265
-            while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
266
-                // determine module and method for route
267
-                $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
268
-                if ($module instanceof EED_Module) {
269
-                    // get registered view for route
270
-                    $this->_template_path = $this->Module_Request_Router->get_view($route);
271
-                    // grab module name
272
-                    $module_name = $module->module_name();
273
-                    // map the module to the module objects
274
-                    $this->Registry->modules->{$module_name} = $module;
275
-                }
276
-            }
277
-        }
278
-    }
279
-
280
-
281
-
282
-
283
-
284
-    /***********************************************        WP HOOK         ***********************************************/
285
-
286
-
287
-    /**
288
-     *    wp - basically last chance to do stuff before headers sent
289
-     *
290
-     * @access    public
291
-     * @return    void
292
-     */
293
-    public function wp()
294
-    {
295
-    }
296
-
297
-
298
-
299
-    /***********************     GET_HEADER && WP_HEAD HOOK     ***********************/
300
-
301
-
302
-
303
-    /**
304
-     * callback for the "template_redirect" hook point
305
-     * checks sidebars for EE widgets
306
-     * loads resources and assets accordingly
307
-     *
308
-     * @return void
309
-     */
310
-    public function templateRedirect()
311
-    {
312
-        global $wp_query;
313
-        if (empty($wp_query->posts)){
314
-            return;
315
-        }
316
-        // if we already know this is an espresso page, then load assets
317
-        $load_assets = $this->Request_Handler->is_espresso_page();
318
-        // if we are already loading assets then just move along, otherwise check for widgets
319
-        $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars();
320
-        if ( $load_assets){
321
-            add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
322
-            add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
323
-        }
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * builds list of active widgets then scans active sidebars looking for them
330
-     * returns true is an EE widget is found in an active sidebar
331
-     * Please Note: this does NOT mean that the sidebar or widget
332
-     * is actually in use in a given template, as that is unfortunately not known
333
-     * until a sidebar and it's widgets are actually loaded
334
-     *
335
-     * @return boolean
336
-     */
337
-    private function espresso_widgets_in_active_sidebars()
338
-    {
339
-        $espresso_widgets = array();
340
-        foreach ($this->Registry->widgets as $widget_class => $widget) {
341
-            $id_base = EspressoWidget::getIdBase($widget_class);
342
-            if (is_active_widget(false, false, $id_base)) {
343
-                $espresso_widgets[] = $id_base;
344
-            }
345
-        }
346
-        $all_sidebar_widgets = wp_get_sidebars_widgets();
347
-        foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) {
348
-            if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
349
-                foreach ($sidebar_widgets as $sidebar_widget) {
350
-                    foreach ($espresso_widgets as $espresso_widget) {
351
-                        if (strpos($sidebar_widget, $espresso_widget) !== false) {
352
-                            return true;
353
-                        }
354
-                    }
355
-                }
356
-            }
357
-        }
358
-        return false;
359
-    }
360
-
361
-
362
-
363
-
364
-    /**
365
-     *    header_meta_tag
366
-     *
367
-     * @access    public
368
-     * @return    void
369
-     */
370
-    public function header_meta_tag()
371
-    {
372
-        print(
373
-            apply_filters(
374
-                'FHEE__EE_Front_Controller__header_meta_tag',
375
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
376
-        );
377
-
378
-        //let's exclude all event type taxonomy term archive pages from search engine indexing
379
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
380
-        //also exclude all critical pages from indexing
381
-        if (
382
-            (
383
-                is_tax('espresso_event_type')
384
-                && get_option( 'blog_public' ) !== '0'
385
-            )
386
-            || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
387
-        ) {
388
-            print(
389
-                apply_filters(
390
-                    'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
391
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
392
-                )
393
-            );
394
-        }
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * wp_print_scripts
401
-     *
402
-     * @return void
403
-     */
404
-    public function wp_print_scripts()
405
-    {
406
-        global $post;
407
-        if (
408
-            isset($post->EE_Event)
409
-            && $post->EE_Event instanceof EE_Event
410
-            && get_post_type() === 'espresso_events'
411
-            && is_singular()
412
-        ) {
413
-            \EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
414
-        }
415
-    }
416
-
417
-
418
-
419
-    public function enqueueStyle()
420
-    {
421
-        wp_enqueue_style('espresso_default');
422
-        wp_enqueue_style('espresso_custom_css');
423
-    }
424
-
425
-
426
-
427
-
428
-    /***********************************************        THE_CONTENT FILTER HOOK         **********************************************
212
+
213
+
214
+
215
+	/***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
216
+
217
+
218
+	/**
219
+	 *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
220
+	 *    default priority init phases have run
221
+	 *
222
+	 * @access    public
223
+	 * @return    void
224
+	 */
225
+	public function wp_loaded()
226
+	{
227
+	}
228
+
229
+
230
+
231
+
232
+
233
+	/***********************************************        PARSE_REQUEST HOOK         ***********************************************/
234
+	/**
235
+	 *    _get_request
236
+	 *
237
+	 * @access public
238
+	 * @param WP $WP
239
+	 * @return void
240
+	 */
241
+	public function get_request(WP $WP)
242
+	{
243
+		do_action('AHEE__EE_Front_Controller__get_request__start');
244
+		$this->Request_Handler->parse_request($WP);
245
+		do_action('AHEE__EE_Front_Controller__get_request__complete');
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
252
+	 *
253
+	 * @access    public
254
+	 * @param   WP_Query $WP_Query
255
+	 * @return    void
256
+	 */
257
+	public function pre_get_posts($WP_Query)
258
+	{
259
+		// only load Module_Request_Router if this is the main query
260
+		if (
261
+			$this->Module_Request_Router instanceof EE_Module_Request_Router
262
+			&& $WP_Query->is_main_query()
263
+		) {
264
+			// cycle thru module routes
265
+			while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
266
+				// determine module and method for route
267
+				$module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
268
+				if ($module instanceof EED_Module) {
269
+					// get registered view for route
270
+					$this->_template_path = $this->Module_Request_Router->get_view($route);
271
+					// grab module name
272
+					$module_name = $module->module_name();
273
+					// map the module to the module objects
274
+					$this->Registry->modules->{$module_name} = $module;
275
+				}
276
+			}
277
+		}
278
+	}
279
+
280
+
281
+
282
+
283
+
284
+	/***********************************************        WP HOOK         ***********************************************/
285
+
286
+
287
+	/**
288
+	 *    wp - basically last chance to do stuff before headers sent
289
+	 *
290
+	 * @access    public
291
+	 * @return    void
292
+	 */
293
+	public function wp()
294
+	{
295
+	}
296
+
297
+
298
+
299
+	/***********************     GET_HEADER && WP_HEAD HOOK     ***********************/
300
+
301
+
302
+
303
+	/**
304
+	 * callback for the "template_redirect" hook point
305
+	 * checks sidebars for EE widgets
306
+	 * loads resources and assets accordingly
307
+	 *
308
+	 * @return void
309
+	 */
310
+	public function templateRedirect()
311
+	{
312
+		global $wp_query;
313
+		if (empty($wp_query->posts)){
314
+			return;
315
+		}
316
+		// if we already know this is an espresso page, then load assets
317
+		$load_assets = $this->Request_Handler->is_espresso_page();
318
+		// if we are already loading assets then just move along, otherwise check for widgets
319
+		$load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars();
320
+		if ( $load_assets){
321
+			add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
322
+			add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
323
+		}
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * builds list of active widgets then scans active sidebars looking for them
330
+	 * returns true is an EE widget is found in an active sidebar
331
+	 * Please Note: this does NOT mean that the sidebar or widget
332
+	 * is actually in use in a given template, as that is unfortunately not known
333
+	 * until a sidebar and it's widgets are actually loaded
334
+	 *
335
+	 * @return boolean
336
+	 */
337
+	private function espresso_widgets_in_active_sidebars()
338
+	{
339
+		$espresso_widgets = array();
340
+		foreach ($this->Registry->widgets as $widget_class => $widget) {
341
+			$id_base = EspressoWidget::getIdBase($widget_class);
342
+			if (is_active_widget(false, false, $id_base)) {
343
+				$espresso_widgets[] = $id_base;
344
+			}
345
+		}
346
+		$all_sidebar_widgets = wp_get_sidebars_widgets();
347
+		foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) {
348
+			if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
349
+				foreach ($sidebar_widgets as $sidebar_widget) {
350
+					foreach ($espresso_widgets as $espresso_widget) {
351
+						if (strpos($sidebar_widget, $espresso_widget) !== false) {
352
+							return true;
353
+						}
354
+					}
355
+				}
356
+			}
357
+		}
358
+		return false;
359
+	}
360
+
361
+
362
+
363
+
364
+	/**
365
+	 *    header_meta_tag
366
+	 *
367
+	 * @access    public
368
+	 * @return    void
369
+	 */
370
+	public function header_meta_tag()
371
+	{
372
+		print(
373
+			apply_filters(
374
+				'FHEE__EE_Front_Controller__header_meta_tag',
375
+				'<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
376
+		);
377
+
378
+		//let's exclude all event type taxonomy term archive pages from search engine indexing
379
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/10249
380
+		//also exclude all critical pages from indexing
381
+		if (
382
+			(
383
+				is_tax('espresso_event_type')
384
+				&& get_option( 'blog_public' ) !== '0'
385
+			)
386
+			|| is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
387
+		) {
388
+			print(
389
+				apply_filters(
390
+					'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
391
+					'<meta name="robots" content="noindex,follow" />' . "\n"
392
+				)
393
+			);
394
+		}
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * wp_print_scripts
401
+	 *
402
+	 * @return void
403
+	 */
404
+	public function wp_print_scripts()
405
+	{
406
+		global $post;
407
+		if (
408
+			isset($post->EE_Event)
409
+			&& $post->EE_Event instanceof EE_Event
410
+			&& get_post_type() === 'espresso_events'
411
+			&& is_singular()
412
+		) {
413
+			\EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
414
+		}
415
+	}
416
+
417
+
418
+
419
+	public function enqueueStyle()
420
+	{
421
+		wp_enqueue_style('espresso_default');
422
+		wp_enqueue_style('espresso_custom_css');
423
+	}
424
+
425
+
426
+
427
+
428
+	/***********************************************        THE_CONTENT FILTER HOOK         **********************************************
429 429
 
430 430
 
431 431
 
@@ -436,108 +436,108 @@  discard block
 block discarded – undo
436 436
     //  * @param   $the_content
437 437
     //  * @return    string
438 438
     //  */
439
-    // public function the_content( $the_content ) {
440
-    // 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
441
-    // 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
442
-    // 	}
443
-    // 	return $the_content;
444
-    // }
445
-
446
-
447
-
448
-    /***********************************************        WP_FOOTER         ***********************************************/
449
-
450
-
451
-
452
-    public function enqueueScripts()
453
-    {
454
-        wp_enqueue_script('espresso_core');
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * display_errors
461
-     *
462
-     * @access public
463
-     * @return void
464
-     * @throws DomainException
465
-     */
466
-    public function display_errors()
467
-    {
468
-        static $shown_already = false;
469
-        do_action('AHEE__EE_Front_Controller__display_errors__begin');
470
-        if (
471
-            ! $shown_already
472
-            && apply_filters('FHEE__EE_Front_Controller__display_errors', true)
473
-            && is_main_query()
474
-            && ! is_feed()
475
-            && in_the_loop()
476
-            && $this->Request_Handler->is_espresso_page()
477
-        ) {
478
-            echo EE_Error::get_notices();
479
-            $shown_already = true;
480
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
481
-        }
482
-        do_action('AHEE__EE_Front_Controller__display_errors__end');
483
-    }
484
-
485
-
486
-
487
-
488
-
489
-    /***********************************************        UTILITIES         ***********************************************/
490
-    /**
491
-     *    template_include
492
-     *
493
-     * @access    public
494
-     * @param   string $template_include_path
495
-     * @return    string
496
-     */
497
-    public function template_include($template_include_path = null)
498
-    {
499
-        if ($this->Request_Handler->is_espresso_page()) {
500
-            $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
501
-            $template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
502
-            $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
503
-            $this->_template      = basename($this->_template_path);
504
-            return $this->_template_path;
505
-        }
506
-        return $template_include_path;
507
-    }
508
-
509
-
510
-    /**
511
-     *    get_selected_template
512
-     *
513
-     * @access    public
514
-     * @param bool $with_path
515
-     * @return    string
516
-     */
517
-    public function get_selected_template($with_path = false)
518
-    {
519
-        return $with_path ? $this->_template_path : $this->_template;
520
-    }
521
-
522
-
523
-
524
-    /**
525
-     * @deprecated 4.9.26
526
-     * @param string $shortcode_class
527
-     * @param \WP    $wp
528
-     */
529
-    public function initialize_shortcode($shortcode_class = '', WP $wp = null)
530
-    {
531
-        \EE_Error::doing_it_wrong(
532
-            __METHOD__,
533
-            __(
534
-                'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
535
-                'event_espresso'
536
-            ),
537
-            '4.9.26'
538
-        );
539
-        $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
540
-    }
439
+	// public function the_content( $the_content ) {
440
+	// 	// nothing gets loaded at this point unless other systems turn this hookpoint on by using:  add_filter( 'FHEE_run_EE_the_content', '__return_true' );
441
+	// 	if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) {
442
+	// 	}
443
+	// 	return $the_content;
444
+	// }
445
+
446
+
447
+
448
+	/***********************************************        WP_FOOTER         ***********************************************/
449
+
450
+
451
+
452
+	public function enqueueScripts()
453
+	{
454
+		wp_enqueue_script('espresso_core');
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * display_errors
461
+	 *
462
+	 * @access public
463
+	 * @return void
464
+	 * @throws DomainException
465
+	 */
466
+	public function display_errors()
467
+	{
468
+		static $shown_already = false;
469
+		do_action('AHEE__EE_Front_Controller__display_errors__begin');
470
+		if (
471
+			! $shown_already
472
+			&& apply_filters('FHEE__EE_Front_Controller__display_errors', true)
473
+			&& is_main_query()
474
+			&& ! is_feed()
475
+			&& in_the_loop()
476
+			&& $this->Request_Handler->is_espresso_page()
477
+		) {
478
+			echo EE_Error::get_notices();
479
+			$shown_already = true;
480
+			EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
481
+		}
482
+		do_action('AHEE__EE_Front_Controller__display_errors__end');
483
+	}
484
+
485
+
486
+
487
+
488
+
489
+	/***********************************************        UTILITIES         ***********************************************/
490
+	/**
491
+	 *    template_include
492
+	 *
493
+	 * @access    public
494
+	 * @param   string $template_include_path
495
+	 * @return    string
496
+	 */
497
+	public function template_include($template_include_path = null)
498
+	{
499
+		if ($this->Request_Handler->is_espresso_page()) {
500
+			$this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
501
+			$template_path        = EEH_Template::locate_template($this->_template_path, array(), false);
502
+			$this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
503
+			$this->_template      = basename($this->_template_path);
504
+			return $this->_template_path;
505
+		}
506
+		return $template_include_path;
507
+	}
508
+
509
+
510
+	/**
511
+	 *    get_selected_template
512
+	 *
513
+	 * @access    public
514
+	 * @param bool $with_path
515
+	 * @return    string
516
+	 */
517
+	public function get_selected_template($with_path = false)
518
+	{
519
+		return $with_path ? $this->_template_path : $this->_template;
520
+	}
521
+
522
+
523
+
524
+	/**
525
+	 * @deprecated 4.9.26
526
+	 * @param string $shortcode_class
527
+	 * @param \WP    $wp
528
+	 */
529
+	public function initialize_shortcode($shortcode_class = '', WP $wp = null)
530
+	{
531
+		\EE_Error::doing_it_wrong(
532
+			__METHOD__,
533
+			__(
534
+				'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
535
+				'event_espresso'
536
+			),
537
+			'4.9.26'
538
+		);
539
+		$this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
540
+	}
541 541
 
542 542
 }
543 543
 // End of file EE_Front_Controller.core.php
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -310,14 +310,14 @@  discard block
 block discarded – undo
310 310
     public function templateRedirect()
311 311
     {
312 312
         global $wp_query;
313
-        if (empty($wp_query->posts)){
313
+        if (empty($wp_query->posts)) {
314 314
             return;
315 315
         }
316 316
         // if we already know this is an espresso page, then load assets
317 317
         $load_assets = $this->Request_Handler->is_espresso_page();
318 318
         // if we are already loading assets then just move along, otherwise check for widgets
319 319
         $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars();
320
-        if ( $load_assets){
320
+        if ($load_assets) {
321 321
             add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
322 322
             add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
323 323
         }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         print(
373 373
             apply_filters(
374 374
                 'FHEE__EE_Front_Controller__header_meta_tag',
375
-                '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n")
375
+                '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n")
376 376
         );
377 377
 
378 378
         //let's exclude all event type taxonomy term archive pages from search engine indexing
@@ -381,14 +381,14 @@  discard block
 block discarded – undo
381 381
         if (
382 382
             (
383 383
                 is_tax('espresso_event_type')
384
-                && get_option( 'blog_public' ) !== '0'
384
+                && get_option('blog_public') !== '0'
385 385
             )
386 386
             || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
387 387
         ) {
388 388
             print(
389 389
                 apply_filters(
390 390
                     'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
391
-                    '<meta name="robots" content="noindex,follow" />' . "\n"
391
+                    '<meta name="robots" content="noindex,follow" />'."\n"
392 392
                 )
393 393
             );
394 394
         }
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
         ) {
478 478
             echo EE_Error::get_notices();
479 479
             $shown_already = true;
480
-            EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
480
+            EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php');
481 481
         }
482 482
         do_action('AHEE__EE_Front_Controller__display_errors__end');
483 483
     }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 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.3.9');
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.3.9');
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.57.rc.004');
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.57.rc.004');
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');
118
-        /**
119
-         *    espresso_load_error_handling
120
-         *    this function loads EE's class for handling exceptions and errors
121
-         */
122
-        function espresso_load_error_handling()
123
-        {
124
-            static $error_handling_loaded = false;
125
-            if ($error_handling_loaded) {
126
-                return;
127
-            }
128
-            // load debugging tools
129
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
-                \EEH_Debug_Tools::instance();
132
-            }
133
-            // load error handling
134
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
-                require_once EE_CORE . 'EE_Error.core.php';
136
-            } else {
137
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
-            }
139
-            $error_handling_loaded = true;
140
-        }
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118
+		/**
119
+		 *    espresso_load_error_handling
120
+		 *    this function loads EE's class for handling exceptions and errors
121
+		 */
122
+		function espresso_load_error_handling()
123
+		{
124
+			static $error_handling_loaded = false;
125
+			if ($error_handling_loaded) {
126
+				return;
127
+			}
128
+			// load debugging tools
129
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
130
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
131
+				\EEH_Debug_Tools::instance();
132
+			}
133
+			// load error handling
134
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
135
+				require_once EE_CORE . 'EE_Error.core.php';
136
+			} else {
137
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
138
+			}
139
+			$error_handling_loaded = true;
140
+		}
141 141
 
142
-        /**
143
-         *    espresso_load_required
144
-         *    given a class name and path, this function will load that file or throw an exception
145
-         *
146
-         * @param    string $classname
147
-         * @param    string $full_path_to_file
148
-         * @throws    EE_Error
149
-         */
150
-        function espresso_load_required($classname, $full_path_to_file)
151
-        {
152
-            if (is_readable($full_path_to_file)) {
153
-                require_once $full_path_to_file;
154
-            } else {
155
-                throw new \EE_Error (
156
-                    sprintf(
157
-                        esc_html__(
158
-                            'The %s class file could not be located or is not readable due to file permissions.',
159
-                            'event_espresso'
160
-                        ),
161
-                        $classname
162
-                    )
163
-                );
164
-            }
165
-        }
142
+		/**
143
+		 *    espresso_load_required
144
+		 *    given a class name and path, this function will load that file or throw an exception
145
+		 *
146
+		 * @param    string $classname
147
+		 * @param    string $full_path_to_file
148
+		 * @throws    EE_Error
149
+		 */
150
+		function espresso_load_required($classname, $full_path_to_file)
151
+		{
152
+			if (is_readable($full_path_to_file)) {
153
+				require_once $full_path_to_file;
154
+			} else {
155
+				throw new \EE_Error (
156
+					sprintf(
157
+						esc_html__(
158
+							'The %s class file could not be located or is not readable due to file permissions.',
159
+							'event_espresso'
160
+						),
161
+						$classname
162
+					)
163
+				);
164
+			}
165
+		}
166 166
 
167
-        /**
168
-         * @since 4.9.27
169
-         * @throws \EE_Error
170
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
174
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
-         * @throws \OutOfBoundsException
178
-         */
179
-        function bootstrap_espresso()
180
-        {
181
-            require_once __DIR__ . '/core/espresso_definitions.php';
182
-            try {
183
-                espresso_load_error_handling();
184
-                espresso_load_required(
185
-                    'EEH_Base',
186
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
-                );
188
-                espresso_load_required(
189
-                    'EEH_File',
190
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
-                );
192
-                espresso_load_required(
193
-                    'EEH_File',
194
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
-                );
196
-                espresso_load_required(
197
-                    'EEH_Array',
198
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
-                );
200
-                // instantiate and configure PSR4 autoloader
201
-                espresso_load_required(
202
-                    'Psr4Autoloader',
203
-                    EE_CORE . 'Psr4Autoloader.php'
204
-                );
205
-                espresso_load_required(
206
-                    'EE_Psr4AutoloaderInit',
207
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
-                );
209
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
210
-                $AutoloaderInit->initializeAutoloader();
211
-                espresso_load_required(
212
-                    'EE_Request',
213
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
-                );
215
-                espresso_load_required(
216
-                    'EE_Response',
217
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
-                );
219
-                espresso_load_required(
220
-                    'EE_Bootstrap',
221
-                    EE_CORE . 'EE_Bootstrap.core.php'
222
-                );
223
-                // bootstrap EE and the request stack
224
-                new EE_Bootstrap(
225
-                    new EE_Request($_GET, $_POST, $_COOKIE),
226
-                    new EE_Response()
227
-                );
228
-            } catch (Exception $e) {
229
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
-            }
232
-        }
233
-        bootstrap_espresso();
234
-    }
167
+		/**
168
+		 * @since 4.9.27
169
+		 * @throws \EE_Error
170
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
171
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
175
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
177
+		 * @throws \OutOfBoundsException
178
+		 */
179
+		function bootstrap_espresso()
180
+		{
181
+			require_once __DIR__ . '/core/espresso_definitions.php';
182
+			try {
183
+				espresso_load_error_handling();
184
+				espresso_load_required(
185
+					'EEH_Base',
186
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
187
+				);
188
+				espresso_load_required(
189
+					'EEH_File',
190
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
191
+				);
192
+				espresso_load_required(
193
+					'EEH_File',
194
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
195
+				);
196
+				espresso_load_required(
197
+					'EEH_Array',
198
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
199
+				);
200
+				// instantiate and configure PSR4 autoloader
201
+				espresso_load_required(
202
+					'Psr4Autoloader',
203
+					EE_CORE . 'Psr4Autoloader.php'
204
+				);
205
+				espresso_load_required(
206
+					'EE_Psr4AutoloaderInit',
207
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
208
+				);
209
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
210
+				$AutoloaderInit->initializeAutoloader();
211
+				espresso_load_required(
212
+					'EE_Request',
213
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
214
+				);
215
+				espresso_load_required(
216
+					'EE_Response',
217
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
218
+				);
219
+				espresso_load_required(
220
+					'EE_Bootstrap',
221
+					EE_CORE . 'EE_Bootstrap.core.php'
222
+				);
223
+				// bootstrap EE and the request stack
224
+				new EE_Bootstrap(
225
+					new EE_Request($_GET, $_POST, $_COOKIE),
226
+					new EE_Response()
227
+				);
228
+			} catch (Exception $e) {
229
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
230
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
231
+			}
232
+		}
233
+		bootstrap_espresso();
234
+	}
235 235
 }
236 236
 if (! function_exists('espresso_deactivate_plugin')) {
237
-    /**
238
-     *    deactivate_plugin
239
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
-     *
241
-     * @access public
242
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
-     * @return    void
244
-     */
245
-    function espresso_deactivate_plugin($plugin_basename = '')
246
-    {
247
-        if (! function_exists('deactivate_plugins')) {
248
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
-        }
250
-        unset($_GET['activate'], $_REQUEST['activate']);
251
-        deactivate_plugins($plugin_basename);
252
-    }
237
+	/**
238
+	 *    deactivate_plugin
239
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
240
+	 *
241
+	 * @access public
242
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
243
+	 * @return    void
244
+	 */
245
+	function espresso_deactivate_plugin($plugin_basename = '')
246
+	{
247
+		if (! function_exists('deactivate_plugins')) {
248
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
249
+		}
250
+		unset($_GET['activate'], $_REQUEST['activate']);
251
+		deactivate_plugins($plugin_basename);
252
+	}
253 253
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Question_Group.class.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
 	 * @param array $props_n_values
33 33
 	 * @return EE_Question_Group|mixed
34 34
 	 */
35
-	public static function new_instance( $props_n_values = array() ) {
36
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__ );
37
-		return $has_object ? $has_object : new self( $props_n_values );
35
+	public static function new_instance($props_n_values = array()) {
36
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
37
+		return $has_object ? $has_object : new self($props_n_values);
38 38
 	}
39 39
 
40 40
 
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	 * @param array $props_n_values
44 44
 	 * @return EE_Question_Group
45 45
 	 */
46
-	public static function new_instance_from_db( $props_n_values = array() ) {
47
-		return new self( $props_n_values, TRUE );
46
+	public static function new_instance_from_db($props_n_values = array()) {
47
+		return new self($props_n_values, TRUE);
48 48
 	}
49 49
 
50 50
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
 	 * @param bool $pretty
56 56
 	 * @return string
57 57
 	 */
58
-	public function name( $pretty = FALSE ) {
59
-		return $pretty ? $this->get_pretty( 'QSG_name' ) : $this->get( 'QSG_name' );
58
+	public function name($pretty = FALSE) {
59
+		return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name');
60 60
 	}
61 61
 
62 62
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @return string
69 69
 	 */
70 70
 	public function identifier() {
71
-		return $this->get( 'QSG_identifier' );
71
+		return $this->get('QSG_identifier');
72 72
 	}
73 73
 
74 74
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 * @param bool $pretty
80 80
 	 * @return string
81 81
 	 */
82
-	public function desc( $pretty = FALSE ) {
83
-		return $pretty ? $this->get_pretty( 'QSG_desc' ) : $this->get( 'QSG_desc' );
82
+	public function desc($pretty = FALSE) {
83
+		return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc');
84 84
 	}
85 85
 
86 86
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @return int
93 93
 	 */
94 94
 	public function order() {
95
-		return $this->get( 'QSG_order' );
95
+		return $this->get('QSG_order');
96 96
 	}
97 97
 
98 98
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @return boolean
104 104
 	 */
105 105
 	public function show_group_name() {
106
-		return $this->get( 'QSG_show_group_name' );
106
+		return $this->get('QSG_show_group_name');
107 107
 	}
108 108
 
109 109
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return boolean
116 116
 	 */
117 117
 	public function show_group_desc() {
118
-		return $this->get( 'QSG_show_group_desc' );
118
+		return $this->get('QSG_show_group_desc');
119 119
 	}
120 120
 
121 121
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return int
129 129
 	 */
130 130
 	public function system_group() {
131
-		return $this->get( 'QSG_system' );
131
+		return $this->get('QSG_system');
132 132
 	}
133 133
 
134 134
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return boolean
154 154
 	 */
155 155
 	public function deleted() {
156
-		return $this->get( 'QST_deleted' );
156
+		return $this->get('QST_deleted');
157 157
 	}
158 158
 
159 159
 
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 	 */
165 165
 	public function questions_in_and_not_in_group() {
166 166
 		$questions_in_group = $this->questions();
167
-		$exclude_question_ids = ! empty( $questions_in_group ) ? array_keys( $questions_in_group ) : array();
168
-		$questions_not_in_group = $this->questions_not_in_group( $exclude_question_ids );
167
+		$exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array();
168
+		$questions_not_in_group = $this->questions_not_in_group($exclude_question_ids);
169 169
 		return $questions_in_group + $questions_not_in_group;
170 170
 	}
171 171
 
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 	 * @param array $query_params
177 177
 	 * @return EE_Question[]
178 178
 	 */
179
-	public function questions( $query_params = array() ) {
180
-		$query_params = ! empty( $query_params ) ? $query_params : array( 'order_by' => array( 'Question_Group_Question.QGQ_order' => 'ASC' ) );
181
-		return $this->ID() ? $this->get_many_related( 'Question', $query_params ) : array();
179
+	public function questions($query_params = array()) {
180
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC'));
181
+		return $this->ID() ? $this->get_many_related('Question', $query_params) : array();
182 182
 	}
183 183
 
184 184
 
@@ -188,14 +188,14 @@  discard block
 block discarded – undo
188 188
 	 * @param  mixed $question_IDS_in_group if empty array then all questions returned.  if FALSE then we first get questions in this group and exclude them from questions get all. IF empty array then we just return all questions.
189 189
 	 * @return EE_Question[]
190 190
 	 */
191
-	public function questions_not_in_group( $question_IDS_in_group = FALSE ) {
192
-		if ( $question_IDS_in_group === FALSE ) {
191
+	public function questions_not_in_group($question_IDS_in_group = FALSE) {
192
+		if ($question_IDS_in_group === FALSE) {
193 193
 			$questions = $this->questions();
194
-			$question_IDS_in_group = ! empty( $questions ) ? array_keys( $questions ) : array();
194
+			$question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array();
195 195
 		}
196
-		$_where = ! empty( $question_IDS_in_group ) ? array( 'QST_ID' => array( 'not_in', $question_IDS_in_group ) ) : array();
196
+		$_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group)) : array();
197 197
 
198
-		return EEM_Question::instance()->get_all( array( $_where, 'order_by' => array( 'QST_ID' => 'ASC' ) ) );
198
+		return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC')));
199 199
 	}
200 200
 
201 201
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * @return EE_Event[]
206 206
 	 */
207 207
 	public function events() {
208
-		return $this->get_many_related( 'Event' );
208
+		return $this->get_many_related('Event');
209 209
 	}
210 210
 
211 211
 
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param EE_Question || int $question object or ID
216 216
 	 * @return boolean if successful
217 217
 	 */
218
-	public function add_question( $questionObjectOrID ) {
219
-		return $this->_add_relation_to( $questionObjectOrID, 'Question' );
218
+	public function add_question($questionObjectOrID) {
219
+		return $this->_add_relation_to($questionObjectOrID, 'Question');
220 220
 	}
221 221
 
222 222
 
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param EE_Question || int $question object or ID
227 227
 	 * @return boolean of success
228 228
 	 */
229
-	public function remove_question( $questionObjectOrID ) {
230
-		return $this->_remove_relation_to( $questionObjectOrID, 'Question' );
229
+	public function remove_question($questionObjectOrID) {
230
+		return $this->_remove_relation_to($questionObjectOrID, 'Question');
231 231
 	}
232 232
 
233 233
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
 	 * @param $qst_order
238 238
 	 * @return int
239 239
 	 */
240
-	public function update_question_order( $questionObjectOrID, $qst_order ) {
241
-		$qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int)$questionObjectOrID;
242
-		return EEM_Question_Group_Question::instance()->update( array( 'QGQ_order' => $qst_order ), array( array( 'QST_ID' => $qst_ID, 'QSG_ID' => $this->ID() ) ) );
240
+	public function update_question_order($questionObjectOrID, $qst_order) {
241
+		$qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID;
242
+		return EEM_Question_Group_Question::instance()->update(array('QGQ_order' => $qst_order), array(array('QST_ID' => $qst_ID, 'QSG_ID' => $this->ID())));
243 243
 	}
244 244
 
245 245
 
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 	 */
251 251
 	public function has_questions_with_answers() {
252 252
 		$has_answers = FALSE;
253
-		$questions = $this->get_many_related( 'Question' );
254
-		foreach ( $questions as $question ) {
255
-			if ( $question->count_related( 'Answer' ) > 0 )
253
+		$questions = $this->get_many_related('Question');
254
+		foreach ($questions as $question) {
255
+			if ($question->count_related('Answer') > 0)
256 256
 				$has_answers = TRUE;
257 257
 		}
258 258
 		return $has_answers;
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 */
269 269
 	public function set_order_to_latest() {
270 270
 		$latest_order = $this->get_model()->get_latest_question_group_order();
271
-		$latest_order ++;
272
-		$this->set( 'QSG_order', $latest_order );
271
+		$latest_order++;
272
+		$this->set('QSG_order', $latest_order);
273 273
 	}
274 274
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 1 patch
Indentation   +1335 added lines, -1335 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\exceptions\UnexpectedEntityException;
5 5
 
6 6
 if (!defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -18,1339 +18,1339 @@  discard block
 block discarded – undo
18 18
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
19 19
 {
20 20
 
21
-    /**
22
-     * cached value for the the logical active status for the event
23
-     *
24
-     * @see get_active_status()
25
-     * @var string
26
-     */
27
-    protected $_active_status = '';
28
-
29
-    /**
30
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
31
-     *
32
-     * @var EE_Datetime
33
-     */
34
-    protected $_Primary_Datetime;
35
-
36
-    /**
37
-     * @var EventSpacesCalculator $available_spaces_calculator
38
-     */
39
-    protected $available_spaces_calculator;
40
-
41
-
42
-    /**
43
-     * @param array $props_n_values incoming values
44
-     * @param string $timezone incoming timezone (if not set the timezone set for the website will be
45
-     *                                        used.)
46
-     * @param array $date_formats incoming date_formats in an array where the first value is the
47
-     *                                        date_format and the second value is the time format
48
-     * @return EE_Event
49
-     * @throws EE_Error
50
-     */
51
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
52
-    {
53
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
54
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
55
-    }
56
-
57
-
58
-    /**
59
-     * @param array $props_n_values incoming values from the database
60
-     * @param string $timezone incoming timezone as set by the model.  If not set the timezone for
61
-     *                                the website will be used.
62
-     * @return EE_Event
63
-     * @throws EE_Error
64
-     */
65
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
66
-    {
67
-        return new self($props_n_values, true, $timezone);
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @return EventSpacesCalculator
74
-     * @throws \EE_Error
75
-     */
76
-    public function getAvailableSpacesCalculator()
77
-    {
78
-        if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){
79
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
80
-        }
81
-        return $this->available_spaces_calculator;
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
88
-     *
89
-     * @param string $field_name
90
-     * @param mixed $field_value
91
-     * @param bool $use_default
92
-     * @throws EE_Error
93
-     */
94
-    public function set($field_name, $field_value, $use_default = false)
95
-    {
96
-        switch ($field_name) {
97
-            case 'status' :
98
-                $this->set_status($field_value, $use_default);
99
-                break;
100
-            default :
101
-                parent::set($field_name, $field_value, $use_default);
102
-        }
103
-    }
104
-
105
-
106
-    /**
107
-     *    set_status
108
-     * Checks if event status is being changed to SOLD OUT
109
-     * and updates event meta data with previous event status
110
-     * so that we can revert things if/when the event is no longer sold out
111
-     *
112
-     * @access public
113
-     * @param string $new_status
114
-     * @param bool $use_default
115
-     * @return void
116
-     * @throws EE_Error
117
-     */
118
-    public function set_status($new_status = null, $use_default = false)
119
-    {
120
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
121
-        if (empty($new_status) && !$use_default) {
122
-            return;
123
-        }
124
-        // get current Event status
125
-        $old_status = $this->status();
126
-        // if status has changed
127
-        if ($old_status !== $new_status) {
128
-            // TO sold_out
129
-            if ($new_status === EEM_Event::sold_out) {
130
-                // save the previous event status so that we can revert if the event is no longer sold out
131
-                $this->add_post_meta('_previous_event_status', $old_status);
132
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
133
-                // OR FROM  sold_out
134
-            } else if ($old_status === EEM_Event::sold_out) {
135
-                $this->delete_post_meta('_previous_event_status');
136
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
137
-            }
138
-            //clear out the active status so that it gets reset the next time it is requested
139
-            $this->_active_status = null;
140
-            // update status
141
-            parent::set('status', $new_status, $use_default);
142
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
143
-            return;
144
-        }
145
-        // even though the old value matches the new value, it's still good to
146
-        // allow the parent set method to have a say
147
-        parent::set('status', $new_status, $use_default);
148
-    }
149
-
150
-
151
-    /**
152
-     * Gets all the datetimes for this event
153
-     *
154
-     * @param array $query_params like EEM_Base::get_all
155
-     * @return EE_Base_Class[]|EE_Datetime[]
156
-     * @throws EE_Error
157
-     */
158
-    public function datetimes($query_params = array())
159
-    {
160
-        return $this->get_many_related('Datetime', $query_params);
161
-    }
162
-
163
-
164
-    /**
165
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
166
-     *
167
-     * @return EE_Base_Class[]|EE_Datetime[]
168
-     * @throws EE_Error
169
-     */
170
-    public function datetimes_in_chronological_order()
171
-    {
172
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
173
-    }
174
-
175
-
176
-    /**
177
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
178
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
179
-     * after running our query, so that this timezone isn't set for EVERY query
180
-     * on EEM_Datetime for the rest of the request, no?
181
-     *
182
-     * @param boolean $show_expired whether or not to include expired events
183
-     * @param boolean $show_deleted whether or not to include deleted events
184
-     * @param null $limit
185
-     * @return EE_Datetime[]
186
-     * @throws EE_Error
187
-     */
188
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
189
-    {
190
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
191
-            $this->ID(),
192
-            $show_expired,
193
-            $show_deleted,
194
-            $limit
195
-        );
196
-    }
197
-
198
-
199
-    /**
200
-     * Returns one related datetime. Mostly only used by some legacy code.
201
-     *
202
-     * @return EE_Base_Class|EE_Datetime
203
-     * @throws EE_Error
204
-     */
205
-    public function first_datetime()
206
-    {
207
-        return $this->get_first_related('Datetime');
208
-    }
209
-
210
-
211
-    /**
212
-     * Returns the 'primary' datetime for the event
213
-     *
214
-     * @param bool $try_to_exclude_expired
215
-     * @param bool $try_to_exclude_deleted
216
-     * @return EE_Datetime
217
-     * @throws EE_Error
218
-     */
219
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
220
-    {
221
-        if (!empty ($this->_Primary_Datetime)) {
222
-            return $this->_Primary_Datetime;
223
-        }
224
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
225
-            $this->ID(),
226
-            $try_to_exclude_expired,
227
-            $try_to_exclude_deleted
228
-        );
229
-        return $this->_Primary_Datetime;
230
-    }
231
-
232
-
233
-    /**
234
-     * Gets all the tickets available for purchase of this event
235
-     *
236
-     * @param array $query_params like EEM_Base::get_all
237
-     * @return EE_Base_Class[]|EE_Ticket[]
238
-     * @throws EE_Error
239
-     */
240
-    public function tickets($query_params = array())
241
-    {
242
-        //first get all datetimes
243
-        $datetimes = $this->datetimes_ordered();
244
-        if (!$datetimes) {
245
-            return array();
246
-        }
247
-        $datetime_ids = array();
248
-        foreach ($datetimes as $datetime) {
249
-            $datetime_ids[] = $datetime->ID();
250
-        }
251
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
252
-        //if incoming $query_params has where conditions let's merge but not override existing.
253
-        if (is_array($query_params) && isset($query_params[0])) {
254
-            $where_params = array_merge($query_params[0], $where_params);
255
-            unset($query_params[0]);
256
-        }
257
-        //now add $where_params to $query_params
258
-        $query_params[0] = $where_params;
259
-        return EEM_Ticket::instance()->get_all($query_params);
260
-    }
261
-
262
-
263
-    /**
264
-     * get all unexpired untrashed tickets
265
-     *
266
-     * @return EE_Ticket[]
267
-     * @throws EE_Error
268
-     */
269
-    public function active_tickets()
270
-    {
271
-        return $this->tickets(array(
272
-            array(
273
-                'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
274
-                'TKT_deleted' => false,
275
-            ),
276
-        ));
277
-    }
278
-
279
-
280
-    /**
281
-     * @return bool
282
-     * @throws EE_Error
283
-     */
284
-    public function additional_limit()
285
-    {
286
-        return $this->get('EVT_additional_limit');
287
-    }
288
-
289
-
290
-    /**
291
-     * @return bool
292
-     * @throws EE_Error
293
-     */
294
-    public function allow_overflow()
295
-    {
296
-        return $this->get('EVT_allow_overflow');
297
-    }
298
-
299
-
300
-    /**
301
-     * @return bool
302
-     * @throws EE_Error
303
-     */
304
-    public function created()
305
-    {
306
-        return $this->get('EVT_created');
307
-    }
308
-
309
-
310
-    /**
311
-     * @return bool
312
-     * @throws EE_Error
313
-     */
314
-    public function description()
315
-    {
316
-        return $this->get('EVT_desc');
317
-    }
318
-
319
-
320
-    /**
321
-     * Runs do_shortcode and wpautop on the description
322
-     *
323
-     * @return string of html
324
-     * @throws EE_Error
325
-     */
326
-    public function description_filtered()
327
-    {
328
-        return $this->get_pretty('EVT_desc');
329
-    }
330
-
331
-
332
-    /**
333
-     * @return bool
334
-     * @throws EE_Error
335
-     */
336
-    public function display_description()
337
-    {
338
-        return $this->get('EVT_display_desc');
339
-    }
340
-
341
-
342
-    /**
343
-     * @return bool
344
-     * @throws EE_Error
345
-     */
346
-    public function display_ticket_selector()
347
-    {
348
-        return (bool)$this->get('EVT_display_ticket_selector');
349
-    }
350
-
351
-
352
-    /**
353
-     * @return bool
354
-     * @throws EE_Error
355
-     */
356
-    public function external_url()
357
-    {
358
-        return $this->get('EVT_external_URL');
359
-    }
360
-
361
-
362
-    /**
363
-     * @return bool
364
-     * @throws EE_Error
365
-     */
366
-    public function member_only()
367
-    {
368
-        return $this->get('EVT_member_only');
369
-    }
370
-
371
-
372
-    /**
373
-     * @return bool
374
-     * @throws EE_Error
375
-     */
376
-    public function phone()
377
-    {
378
-        return $this->get('EVT_phone');
379
-    }
380
-
381
-
382
-    /**
383
-     * @return bool
384
-     * @throws EE_Error
385
-     */
386
-    public function modified()
387
-    {
388
-        return $this->get('EVT_modified');
389
-    }
390
-
391
-
392
-    /**
393
-     * @return bool
394
-     * @throws EE_Error
395
-     */
396
-    public function name()
397
-    {
398
-        return $this->get('EVT_name');
399
-    }
400
-
401
-
402
-    /**
403
-     * @return bool
404
-     * @throws EE_Error
405
-     */
406
-    public function order()
407
-    {
408
-        return $this->get('EVT_order');
409
-    }
410
-
411
-
412
-    /**
413
-     * @return bool|string
414
-     * @throws EE_Error
415
-     */
416
-    public function default_registration_status()
417
-    {
418
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
419
-        return !empty($event_default_registration_status)
420
-            ? $event_default_registration_status
421
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
422
-    }
423
-
424
-
425
-    /**
426
-     * @param int $num_words
427
-     * @param null $more
428
-     * @param bool $not_full_desc
429
-     * @return bool|string
430
-     * @throws EE_Error
431
-     */
432
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
433
-    {
434
-        $short_desc = $this->get('EVT_short_desc');
435
-        if (!empty($short_desc) || $not_full_desc) {
436
-            return $short_desc;
437
-        }
438
-        $full_desc = $this->get('EVT_desc');
439
-        return wp_trim_words($full_desc, $num_words, $more);
440
-    }
441
-
442
-
443
-    /**
444
-     * @return bool
445
-     * @throws EE_Error
446
-     */
447
-    public function slug()
448
-    {
449
-        return $this->get('EVT_slug');
450
-    }
451
-
452
-
453
-    /**
454
-     * @return bool
455
-     * @throws EE_Error
456
-     */
457
-    public function timezone_string()
458
-    {
459
-        return $this->get('EVT_timezone_string');
460
-    }
461
-
462
-
463
-    /**
464
-     * @return bool
465
-     * @throws EE_Error
466
-     */
467
-    public function visible_on()
468
-    {
469
-        return $this->get('EVT_visible_on');
470
-    }
471
-
472
-
473
-    /**
474
-     * @return int
475
-     * @throws EE_Error
476
-     */
477
-    public function wp_user()
478
-    {
479
-        return $this->get('EVT_wp_user');
480
-    }
481
-
482
-
483
-    /**
484
-     * @return bool
485
-     * @throws EE_Error
486
-     */
487
-    public function donations()
488
-    {
489
-        return $this->get('EVT_donations');
490
-    }
491
-
492
-
493
-    /**
494
-     * @param $limit
495
-     * @throws EE_Error
496
-     */
497
-    public function set_additional_limit($limit)
498
-    {
499
-        $this->set('EVT_additional_limit', $limit);
500
-    }
501
-
502
-
503
-    /**
504
-     * @param $created
505
-     * @throws EE_Error
506
-     */
507
-    public function set_created($created)
508
-    {
509
-        $this->set('EVT_created', $created);
510
-    }
511
-
512
-
513
-    /**
514
-     * @param $desc
515
-     * @throws EE_Error
516
-     */
517
-    public function set_description($desc)
518
-    {
519
-        $this->set('EVT_desc', $desc);
520
-    }
521
-
522
-
523
-    /**
524
-     * @param $display_desc
525
-     * @throws EE_Error
526
-     */
527
-    public function set_display_description($display_desc)
528
-    {
529
-        $this->set('EVT_display_desc', $display_desc);
530
-    }
531
-
532
-
533
-    /**
534
-     * @param $display_ticket_selector
535
-     * @throws EE_Error
536
-     */
537
-    public function set_display_ticket_selector($display_ticket_selector)
538
-    {
539
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
540
-    }
541
-
542
-
543
-    /**
544
-     * @param $external_url
545
-     * @throws EE_Error
546
-     */
547
-    public function set_external_url($external_url)
548
-    {
549
-        $this->set('EVT_external_URL', $external_url);
550
-    }
551
-
552
-
553
-    /**
554
-     * @param $member_only
555
-     * @throws EE_Error
556
-     */
557
-    public function set_member_only($member_only)
558
-    {
559
-        $this->set('EVT_member_only', $member_only);
560
-    }
561
-
562
-
563
-    /**
564
-     * @param $event_phone
565
-     * @throws EE_Error
566
-     */
567
-    public function set_event_phone($event_phone)
568
-    {
569
-        $this->set('EVT_phone', $event_phone);
570
-    }
571
-
572
-
573
-    /**
574
-     * @param $modified
575
-     * @throws EE_Error
576
-     */
577
-    public function set_modified($modified)
578
-    {
579
-        $this->set('EVT_modified', $modified);
580
-    }
581
-
582
-
583
-    /**
584
-     * @param $name
585
-     * @throws EE_Error
586
-     */
587
-    public function set_name($name)
588
-    {
589
-        $this->set('EVT_name', $name);
590
-    }
591
-
592
-
593
-    /**
594
-     * @param $order
595
-     * @throws EE_Error
596
-     */
597
-    public function set_order($order)
598
-    {
599
-        $this->set('EVT_order', $order);
600
-    }
601
-
602
-
603
-    /**
604
-     * @param $short_desc
605
-     * @throws EE_Error
606
-     */
607
-    public function set_short_description($short_desc)
608
-    {
609
-        $this->set('EVT_short_desc', $short_desc);
610
-    }
611
-
612
-
613
-    /**
614
-     * @param $slug
615
-     * @throws EE_Error
616
-     */
617
-    public function set_slug($slug)
618
-    {
619
-        $this->set('EVT_slug', $slug);
620
-    }
621
-
622
-
623
-    /**
624
-     * @param $timezone_string
625
-     * @throws EE_Error
626
-     */
627
-    public function set_timezone_string($timezone_string)
628
-    {
629
-        $this->set('EVT_timezone_string', $timezone_string);
630
-    }
631
-
632
-
633
-    /**
634
-     * @param $visible_on
635
-     * @throws EE_Error
636
-     */
637
-    public function set_visible_on($visible_on)
638
-    {
639
-        $this->set('EVT_visible_on', $visible_on);
640
-    }
641
-
642
-
643
-    /**
644
-     * @param $wp_user
645
-     * @throws EE_Error
646
-     */
647
-    public function set_wp_user($wp_user)
648
-    {
649
-        $this->set('EVT_wp_user', $wp_user);
650
-    }
651
-
652
-
653
-    /**
654
-     * @param $default_registration_status
655
-     * @throws EE_Error
656
-     */
657
-    public function set_default_registration_status($default_registration_status)
658
-    {
659
-        $this->set('EVT_default_registration_status', $default_registration_status);
660
-    }
661
-
662
-
663
-    /**
664
-     * @param $donations
665
-     * @throws EE_Error
666
-     */
667
-    public function set_donations($donations)
668
-    {
669
-        $this->set('EVT_donations', $donations);
670
-    }
671
-
672
-
673
-    /**
674
-     * Adds a venue to this event
675
-     *
676
-     * @param EE_Venue /int $venue_id_or_obj
677
-     * @return EE_Base_Class|EE_Venue
678
-     * @throws EE_Error
679
-     */
680
-    public function add_venue($venue_id_or_obj)
681
-    {
682
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
683
-    }
684
-
685
-
686
-    /**
687
-     * Removes a venue from the event
688
-     *
689
-     * @param EE_Venue /int $venue_id_or_obj
690
-     * @return EE_Base_Class|EE_Venue
691
-     * @throws EE_Error
692
-     */
693
-    public function remove_venue($venue_id_or_obj)
694
-    {
695
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
696
-    }
697
-
698
-
699
-    /**
700
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
701
-     *
702
-     * @param array $query_params like EEM_Base::get_all's $query_params
703
-     * @return EE_Base_Class[]|EE_Venue[]
704
-     * @throws EE_Error
705
-     */
706
-    public function venues($query_params = array())
707
-    {
708
-        return $this->get_many_related('Venue', $query_params);
709
-    }
710
-
711
-
712
-    /**
713
-     * check if event id is present and if event is published
714
-     *
715
-     * @access public
716
-     * @return boolean true yes, false no
717
-     * @throws EE_Error
718
-     */
719
-    private function _has_ID_and_is_published()
720
-    {
721
-        // first check if event id is present and not NULL,
722
-        // then check if this event is published (or any of the equivalent "published" statuses)
723
-        return
724
-            $this->ID() && $this->ID() !== null
725
-            && (
726
-                $this->status() === 'publish'
727
-                || $this->status() === EEM_Event::sold_out
728
-                || $this->status() === EEM_Event::postponed
729
-                || $this->status() === EEM_Event::cancelled
730
-            );
731
-    }
732
-
733
-
734
-    /**
735
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
736
-     *
737
-     * @access public
738
-     * @return boolean true yes, false no
739
-     * @throws EE_Error
740
-     */
741
-    public function is_upcoming()
742
-    {
743
-        // check if event id is present and if this event is published
744
-        if ($this->is_inactive()) {
745
-            return false;
746
-        }
747
-        // set initial value
748
-        $upcoming = false;
749
-        //next let's get all datetimes and loop through them
750
-        $datetimes = $this->datetimes_in_chronological_order();
751
-        foreach ($datetimes as $datetime) {
752
-            if ($datetime instanceof EE_Datetime) {
753
-                //if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
754
-                if ($datetime->is_expired()) {
755
-                    continue;
756
-                }
757
-                //if this dtt is active then we return false.
758
-                if ($datetime->is_active()) {
759
-                    return false;
760
-                }
761
-                //otherwise let's check upcoming status
762
-                $upcoming = $datetime->is_upcoming();
763
-            }
764
-        }
765
-        return $upcoming;
766
-    }
767
-
768
-
769
-    /**
770
-     * @return bool
771
-     * @throws EE_Error
772
-     */
773
-    public function is_active()
774
-    {
775
-        // check if event id is present and if this event is published
776
-        if ($this->is_inactive()) {
777
-            return false;
778
-        }
779
-        // set initial value
780
-        $active = false;
781
-        //next let's get all datetimes and loop through them
782
-        $datetimes = $this->datetimes_in_chronological_order();
783
-        foreach ($datetimes as $datetime) {
784
-            if ($datetime instanceof EE_Datetime) {
785
-                //if this dtt is expired then we continue cause one of the other datetimes might be active.
786
-                if ($datetime->is_expired()) {
787
-                    continue;
788
-                }
789
-                //if this dtt is upcoming then we return false.
790
-                if ($datetime->is_upcoming()) {
791
-                    return false;
792
-                }
793
-                //otherwise let's check active status
794
-                $active = $datetime->is_active();
795
-            }
796
-        }
797
-        return $active;
798
-    }
799
-
800
-
801
-    /**
802
-     * @return bool
803
-     * @throws EE_Error
804
-     */
805
-    public function is_expired()
806
-    {
807
-        // check if event id is present and if this event is published
808
-        if ($this->is_inactive()) {
809
-            return false;
810
-        }
811
-        // set initial value
812
-        $expired = false;
813
-        //first let's get all datetimes and loop through them
814
-        $datetimes = $this->datetimes_in_chronological_order();
815
-        foreach ($datetimes as $datetime) {
816
-            if ($datetime instanceof EE_Datetime) {
817
-                //if this dtt is upcoming or active then we return false.
818
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
819
-                    return false;
820
-                }
821
-                //otherwise let's check active status
822
-                $expired = $datetime->is_expired();
823
-            }
824
-        }
825
-        return $expired;
826
-    }
827
-
828
-
829
-    /**
830
-     * @return bool
831
-     * @throws EE_Error
832
-     */
833
-    public function is_inactive()
834
-    {
835
-        // check if event id is present and if this event is published
836
-        if ($this->_has_ID_and_is_published()) {
837
-            return false;
838
-        }
839
-        return true;
840
-    }
841
-
842
-
843
-    /**
844
-     * calculate spaces remaining based on "saleable" tickets
845
-     *
846
-     * @param array $tickets
847
-     * @param bool $filtered
848
-     * @return int|float
849
-     * @throws EE_Error
850
-     * @throws DomainException
851
-     * @throws UnexpectedEntityException
852
-     */
853
-    public function spaces_remaining($tickets = array(), $filtered = true)
854
-    {
855
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
856
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
857
-        return $filtered
858
-            ? apply_filters(
859
-                'FHEE_EE_Event__spaces_remaining',
860
-                $spaces_remaining,
861
-                $this,
862
-                $tickets
863
-            )
864
-            : $spaces_remaining;
865
-    }
866
-
867
-
868
-    /**
869
-     *    perform_sold_out_status_check
870
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces available...
871
-     *    if NOT, then the event status will get toggled to 'sold_out'
872
-     *
873
-     * @return bool    return the ACTUAL sold out state.
874
-     * @throws EE_Error
875
-     * @throws DomainException
876
-     * @throws UnexpectedEntityException
877
-     */
878
-    public function perform_sold_out_status_check()
879
-    {
880
-        // get all unexpired untrashed tickets
881
-        $tickets = $this->tickets(
882
-            array(
883
-                array('TKT_deleted' => false),
884
-                'order_by' => array('TKT_qty' => 'ASC'),
885
-            )
886
-        );
887
-        $all_expired = true;
888
-        foreach ($tickets as $ticket) {
889
-            if(!$ticket->is_expired()){
890
-                $all_expired = false;
891
-                break;
892
-            }
893
-        }
894
-        // if all the tickets are just expired, then don't update the event status to sold out
895
-        if ($all_expired) {
896
-            return true;
897
-        }
898
-        $spaces_remaining = $this->spaces_remaining($tickets);
899
-        if ($spaces_remaining < 1) {
900
-            $this->set_status(EEM_Event::sold_out);
901
-            $this->save();
902
-            $sold_out = true;
903
-        } else {
904
-            $sold_out = false;
905
-            // was event previously marked as sold out ?
906
-            if ($this->status() === EEM_Event::sold_out) {
907
-                // revert status to previous value, if it was set
908
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
909
-                if ($previous_event_status) {
910
-                    $this->set_status($previous_event_status);
911
-                    $this->save();
912
-                }
913
-            }
914
-        }
915
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
916
-        return $sold_out;
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * This returns the total remaining spaces for sale on this event.
923
-     *
924
-     * @uses EE_Event::total_available_spaces()
925
-     * @return float|int
926
-     * @throws EE_Error
927
-     * @throws DomainException
928
-     * @throws UnexpectedEntityException
929
-     */
930
-    public function spaces_remaining_for_sale()
931
-    {
932
-        return $this->total_available_spaces(true);
933
-    }
934
-
935
-
936
-
937
-    /**
938
-     * This returns the total spaces available for an event
939
-     * while considering all the qtys on the tickets and the reg limits
940
-     * on the datetimes attached to this event.
941
-     *
942
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
943
-     *                              If this is false, then we return the most tickets that could ever be sold
944
-     *                              for this event with the datetime and tickets setup on the event under optimal
945
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
946
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
947
-     *                              may appear to equal remaining tickets.  However, the more tickets are
948
-     *                              sold out, the more accurate the "live" total is.
949
-     * @return float|int
950
-     * @throws EE_Error
951
-     * @throws DomainException
952
-     * @throws UnexpectedEntityException
953
-     */
954
-    public function total_available_spaces($consider_sold = false)
955
-    {
956
-        $spaces_available = $consider_sold
957
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
958
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
959
-        return apply_filters(
960
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
961
-            $spaces_available,
962
-            $this,
963
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
964
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
965
-        );
966
-    }
967
-
968
-
969
-    /**
970
-     * Checks if the event is set to sold out
971
-     *
972
-     * @param  bool $actual whether or not to perform calculations to not only figure the
973
-     *                      actual status but also to flip the status if necessary to sold
974
-     *                      out If false, we just check the existing status of the event
975
-     * @return boolean
976
-     * @throws EE_Error
977
-     */
978
-    public function is_sold_out($actual = false)
979
-    {
980
-        if (!$actual) {
981
-            return $this->status() === EEM_Event::sold_out;
982
-        }
983
-        return $this->perform_sold_out_status_check();
984
-    }
985
-
986
-
987
-    /**
988
-     * Checks if the event is marked as postponed
989
-     *
990
-     * @return boolean
991
-     */
992
-    public function is_postponed()
993
-    {
994
-        return $this->status() === EEM_Event::postponed;
995
-    }
996
-
997
-
998
-    /**
999
-     * Checks if the event is marked as cancelled
1000
-     *
1001
-     * @return boolean
1002
-     */
1003
-    public function is_cancelled()
1004
-    {
1005
-        return $this->status() === EEM_Event::cancelled;
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1011
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1012
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1013
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1014
-     * the event is considered expired.
1015
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a status
1016
-     * set on the EVENT when it is not published and thus is done
1017
-     *
1018
-     * @param bool $reset
1019
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1020
-     * @throws EE_Error
1021
-     */
1022
-    public function get_active_status($reset = false)
1023
-    {
1024
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1025
-        if (!empty($this->_active_status) && !$reset) {
1026
-            return $this->_active_status;
1027
-        }
1028
-        //first check if event id is present on this object
1029
-        if (!$this->ID()) {
1030
-            return false;
1031
-        }
1032
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1033
-        //if event is published:
1034
-        if ($this->status() === 'publish') {
1035
-            //active?
1036
-            if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) {
1037
-                $this->_active_status = EE_Datetime::active;
1038
-            } else {
1039
-                //upcoming?
1040
-                if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) {
1041
-                    $this->_active_status = EE_Datetime::upcoming;
1042
-                } else {
1043
-                    //expired?
1044
-                    if (
1045
-                        EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
1046
-                    ) {
1047
-                        $this->_active_status = EE_Datetime::expired;
1048
-                    } else {
1049
-                        //it would be odd if things make it this far because it basically means there are no datetime's
1050
-                        //attached to the event.  So in this case it will just be considered inactive.
1051
-                        $this->_active_status = EE_Datetime::inactive;
1052
-                    }
1053
-                }
1054
-            }
1055
-        } else {
1056
-            //the event is not published, so let's just set it's active status according to its' post status
1057
-            switch ($this->status()) {
1058
-                case EEM_Event::sold_out :
1059
-                    $this->_active_status = EE_Datetime::sold_out;
1060
-                    break;
1061
-                case EEM_Event::cancelled :
1062
-                    $this->_active_status = EE_Datetime::cancelled;
1063
-                    break;
1064
-                case EEM_Event::postponed :
1065
-                    $this->_active_status = EE_Datetime::postponed;
1066
-                    break;
1067
-                default :
1068
-                    $this->_active_status = EE_Datetime::inactive;
1069
-            }
1070
-        }
1071
-        return $this->_active_status;
1072
-    }
1073
-
1074
-
1075
-    /**
1076
-     *    pretty_active_status
1077
-     *
1078
-     * @access public
1079
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1080
-     * @return mixed void|string
1081
-     * @throws EE_Error
1082
-     */
1083
-    public function pretty_active_status($echo = true)
1084
-    {
1085
-        $active_status = $this->get_active_status();
1086
-        $status = '<span class="ee-status event-active-status-'
1087
-            . $active_status
1088
-            . '">'
1089
-            . EEH_Template::pretty_status($active_status, false, 'sentence')
1090
-            . '</span>';
1091
-        if ($echo) {
1092
-            echo $status;
1093
-            return '';
1094
-        }
1095
-        return $status;
1096
-    }
1097
-
1098
-
1099
-    /**
1100
-     * @return bool|int
1101
-     * @throws EE_Error
1102
-     */
1103
-    public function get_number_of_tickets_sold()
1104
-    {
1105
-        $tkt_sold = 0;
1106
-        if (!$this->ID()) {
1107
-            return 0;
1108
-        }
1109
-        $datetimes = $this->datetimes();
1110
-        foreach ($datetimes as $datetime) {
1111
-            if ($datetime instanceof EE_Datetime) {
1112
-                $tkt_sold += $datetime->sold();
1113
-            }
1114
-        }
1115
-        return $tkt_sold;
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * This just returns a count of all the registrations for this event
1121
-     *
1122
-     * @access  public
1123
-     * @return int
1124
-     * @throws EE_Error
1125
-     */
1126
-    public function get_count_of_all_registrations()
1127
-    {
1128
-        return EEM_Event::instance()->count_related($this, 'Registration');
1129
-    }
1130
-
1131
-
1132
-    /**
1133
-     * This returns the ticket with the earliest start time that is
1134
-     * available for this event (across all datetimes attached to the event)
1135
-     *
1136
-     * @return EE_Base_Class|EE_Ticket|null
1137
-     * @throws EE_Error
1138
-     */
1139
-    public function get_ticket_with_earliest_start_time()
1140
-    {
1141
-        $where['Datetime.EVT_ID'] = $this->ID();
1142
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1143
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1144
-    }
1145
-
1146
-
1147
-    /**
1148
-     * This returns the ticket with the latest end time that is available
1149
-     * for this event (across all datetimes attached to the event)
1150
-     *
1151
-     * @return EE_Base_Class|EE_Ticket|null
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function get_ticket_with_latest_end_time()
1155
-    {
1156
-        $where['Datetime.EVT_ID'] = $this->ID();
1157
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1158
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1159
-    }
1160
-
1161
-
1162
-    /**
1163
-     * This returns whether there are any tickets on sale for this event.
1164
-     *
1165
-     * @return bool true = YES tickets on sale.
1166
-     * @throws EE_Error
1167
-     */
1168
-    public function tickets_on_sale()
1169
-    {
1170
-        $earliest_ticket = $this->get_ticket_with_earliest_start_time();
1171
-        $latest_ticket = $this->get_ticket_with_latest_end_time();
1172
-        if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) {
1173
-            return false;
1174
-        }
1175
-        //check on sale for these two tickets.
1176
-        if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) {
1177
-            return true;
1178
-        }
1179
-        return false;
1180
-    }
1181
-
1182
-
1183
-    /**
1184
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1185
-     * to check for an external URL first
1186
-     *
1187
-     * @return string
1188
-     * @throws EE_Error
1189
-     */
1190
-    public function get_permalink()
1191
-    {
1192
-        if ($this->external_url()) {
1193
-            return $this->external_url();
1194
-        }
1195
-        return parent::get_permalink();
1196
-    }
1197
-
1198
-
1199
-    /**
1200
-     * Gets the first term for 'espresso_event_categories' we can find
1201
-     *
1202
-     * @param array $query_params like EEM_Base::get_all
1203
-     * @return EE_Base_Class|EE_Term|null
1204
-     * @throws EE_Error
1205
-     */
1206
-    public function first_event_category($query_params = array())
1207
-    {
1208
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1209
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1210
-        return EEM_Term::instance()->get_one($query_params);
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * Gets all terms for 'espresso_event_categories' we can find
1216
-     *
1217
-     * @param array $query_params
1218
-     * @return EE_Base_Class[]|EE_Term[]
1219
-     * @throws EE_Error
1220
-     */
1221
-    public function get_all_event_categories($query_params = array())
1222
-    {
1223
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1224
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1225
-        return EEM_Term::instance()->get_all($query_params);
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * Adds a question group to this event
1231
-     *
1232
-     * @param EE_Question_Group|int $question_group_id_or_obj
1233
-     * @param bool                  $for_primary if true, the question group will be added for the primary
1234
-     *                                           registrant, if false will be added for others. default: false
1235
-     * @return EE_Base_Class|EE_Question_Group
1236
-     * @throws EE_Error
1237
-     */
1238
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1239
-    {
1240
-        $extra = $for_primary
1241
-            ? array('EQG_primary' => 1)
1242
-            : array();
1243
-        return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra);
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * Removes a question group from the event
1249
-     *
1250
-     * @param EE_Question_Group|int $question_group_id_or_obj
1251
-     * @param bool                  $for_primary if true, the question group will be removed from the primary
1252
-     *                                           registrant, if false will be removed from others. default: false
1253
-     * @return EE_Base_Class|EE_Question_Group
1254
-     * @throws EE_Error
1255
-     */
1256
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1257
-    {
1258
-        $where = $for_primary
1259
-            ? array('EQG_primary' => 1)
1260
-            : array();
1261
-        return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where);
1262
-    }
1263
-
1264
-
1265
-    /**
1266
-     * Gets all the question groups, ordering them by QSG_order ascending
1267
-     *
1268
-     * @param array $query_params @see EEM_Base::get_all
1269
-     * @return EE_Base_Class[]|EE_Question_Group[]
1270
-     * @throws EE_Error
1271
-     */
1272
-    public function question_groups($query_params = array())
1273
-    {
1274
-        $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1275
-        return $this->get_many_related('Question_Group', $query_params);
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     * Implementation for EEI_Has_Icon interface method.
1281
-     *
1282
-     * @see EEI_Visual_Representation for comments
1283
-     * @return string
1284
-     */
1285
-    public function get_icon()
1286
-    {
1287
-        return '<span class="dashicons dashicons-flag"></span>';
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * Implementation for EEI_Admin_Links interface method.
1293
-     *
1294
-     * @see EEI_Admin_Links for comments
1295
-     * @return string
1296
-     * @throws EE_Error
1297
-     */
1298
-    public function get_admin_details_link()
1299
-    {
1300
-        return $this->get_admin_edit_link();
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * Implementation for EEI_Admin_Links interface method.
1306
-     *
1307
-     * @see EEI_Admin_Links for comments
1308
-     * @return string
1309
-     * @throws EE_Error
1310
-     */
1311
-    public function get_admin_edit_link()
1312
-    {
1313
-        return EEH_URL::add_query_args_and_nonce(array(
1314
-            'page' => 'espresso_events',
1315
-            'action' => 'edit',
1316
-            'post' => $this->ID(),
1317
-        ),
1318
-            admin_url('admin.php')
1319
-        );
1320
-    }
1321
-
1322
-
1323
-    /**
1324
-     * Implementation for EEI_Admin_Links interface method.
1325
-     *
1326
-     * @see EEI_Admin_Links for comments
1327
-     * @return string
1328
-     */
1329
-    public function get_admin_settings_link()
1330
-    {
1331
-        return EEH_URL::add_query_args_and_nonce(array(
1332
-            'page' => 'espresso_events',
1333
-            'action' => 'default_event_settings',
1334
-        ),
1335
-            admin_url('admin.php')
1336
-        );
1337
-    }
1338
-
1339
-
1340
-    /**
1341
-     * Implementation for EEI_Admin_Links interface method.
1342
-     *
1343
-     * @see EEI_Admin_Links for comments
1344
-     * @return string
1345
-     */
1346
-    public function get_admin_overview_link()
1347
-    {
1348
-        return EEH_URL::add_query_args_and_nonce(array(
1349
-            'page' => 'espresso_events',
1350
-            'action' => 'default',
1351
-        ),
1352
-            admin_url('admin.php')
1353
-        );
1354
-    }
21
+	/**
22
+	 * cached value for the the logical active status for the event
23
+	 *
24
+	 * @see get_active_status()
25
+	 * @var string
26
+	 */
27
+	protected $_active_status = '';
28
+
29
+	/**
30
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
31
+	 *
32
+	 * @var EE_Datetime
33
+	 */
34
+	protected $_Primary_Datetime;
35
+
36
+	/**
37
+	 * @var EventSpacesCalculator $available_spaces_calculator
38
+	 */
39
+	protected $available_spaces_calculator;
40
+
41
+
42
+	/**
43
+	 * @param array $props_n_values incoming values
44
+	 * @param string $timezone incoming timezone (if not set the timezone set for the website will be
45
+	 *                                        used.)
46
+	 * @param array $date_formats incoming date_formats in an array where the first value is the
47
+	 *                                        date_format and the second value is the time format
48
+	 * @return EE_Event
49
+	 * @throws EE_Error
50
+	 */
51
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
52
+	{
53
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
54
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
55
+	}
56
+
57
+
58
+	/**
59
+	 * @param array $props_n_values incoming values from the database
60
+	 * @param string $timezone incoming timezone as set by the model.  If not set the timezone for
61
+	 *                                the website will be used.
62
+	 * @return EE_Event
63
+	 * @throws EE_Error
64
+	 */
65
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
66
+	{
67
+		return new self($props_n_values, true, $timezone);
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @return EventSpacesCalculator
74
+	 * @throws \EE_Error
75
+	 */
76
+	public function getAvailableSpacesCalculator()
77
+	{
78
+		if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){
79
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
80
+		}
81
+		return $this->available_spaces_calculator;
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
88
+	 *
89
+	 * @param string $field_name
90
+	 * @param mixed $field_value
91
+	 * @param bool $use_default
92
+	 * @throws EE_Error
93
+	 */
94
+	public function set($field_name, $field_value, $use_default = false)
95
+	{
96
+		switch ($field_name) {
97
+			case 'status' :
98
+				$this->set_status($field_value, $use_default);
99
+				break;
100
+			default :
101
+				parent::set($field_name, $field_value, $use_default);
102
+		}
103
+	}
104
+
105
+
106
+	/**
107
+	 *    set_status
108
+	 * Checks if event status is being changed to SOLD OUT
109
+	 * and updates event meta data with previous event status
110
+	 * so that we can revert things if/when the event is no longer sold out
111
+	 *
112
+	 * @access public
113
+	 * @param string $new_status
114
+	 * @param bool $use_default
115
+	 * @return void
116
+	 * @throws EE_Error
117
+	 */
118
+	public function set_status($new_status = null, $use_default = false)
119
+	{
120
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
121
+		if (empty($new_status) && !$use_default) {
122
+			return;
123
+		}
124
+		// get current Event status
125
+		$old_status = $this->status();
126
+		// if status has changed
127
+		if ($old_status !== $new_status) {
128
+			// TO sold_out
129
+			if ($new_status === EEM_Event::sold_out) {
130
+				// save the previous event status so that we can revert if the event is no longer sold out
131
+				$this->add_post_meta('_previous_event_status', $old_status);
132
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
133
+				// OR FROM  sold_out
134
+			} else if ($old_status === EEM_Event::sold_out) {
135
+				$this->delete_post_meta('_previous_event_status');
136
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
137
+			}
138
+			//clear out the active status so that it gets reset the next time it is requested
139
+			$this->_active_status = null;
140
+			// update status
141
+			parent::set('status', $new_status, $use_default);
142
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
143
+			return;
144
+		}
145
+		// even though the old value matches the new value, it's still good to
146
+		// allow the parent set method to have a say
147
+		parent::set('status', $new_status, $use_default);
148
+	}
149
+
150
+
151
+	/**
152
+	 * Gets all the datetimes for this event
153
+	 *
154
+	 * @param array $query_params like EEM_Base::get_all
155
+	 * @return EE_Base_Class[]|EE_Datetime[]
156
+	 * @throws EE_Error
157
+	 */
158
+	public function datetimes($query_params = array())
159
+	{
160
+		return $this->get_many_related('Datetime', $query_params);
161
+	}
162
+
163
+
164
+	/**
165
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
166
+	 *
167
+	 * @return EE_Base_Class[]|EE_Datetime[]
168
+	 * @throws EE_Error
169
+	 */
170
+	public function datetimes_in_chronological_order()
171
+	{
172
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
173
+	}
174
+
175
+
176
+	/**
177
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
178
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
179
+	 * after running our query, so that this timezone isn't set for EVERY query
180
+	 * on EEM_Datetime for the rest of the request, no?
181
+	 *
182
+	 * @param boolean $show_expired whether or not to include expired events
183
+	 * @param boolean $show_deleted whether or not to include deleted events
184
+	 * @param null $limit
185
+	 * @return EE_Datetime[]
186
+	 * @throws EE_Error
187
+	 */
188
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
189
+	{
190
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
191
+			$this->ID(),
192
+			$show_expired,
193
+			$show_deleted,
194
+			$limit
195
+		);
196
+	}
197
+
198
+
199
+	/**
200
+	 * Returns one related datetime. Mostly only used by some legacy code.
201
+	 *
202
+	 * @return EE_Base_Class|EE_Datetime
203
+	 * @throws EE_Error
204
+	 */
205
+	public function first_datetime()
206
+	{
207
+		return $this->get_first_related('Datetime');
208
+	}
209
+
210
+
211
+	/**
212
+	 * Returns the 'primary' datetime for the event
213
+	 *
214
+	 * @param bool $try_to_exclude_expired
215
+	 * @param bool $try_to_exclude_deleted
216
+	 * @return EE_Datetime
217
+	 * @throws EE_Error
218
+	 */
219
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
220
+	{
221
+		if (!empty ($this->_Primary_Datetime)) {
222
+			return $this->_Primary_Datetime;
223
+		}
224
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
225
+			$this->ID(),
226
+			$try_to_exclude_expired,
227
+			$try_to_exclude_deleted
228
+		);
229
+		return $this->_Primary_Datetime;
230
+	}
231
+
232
+
233
+	/**
234
+	 * Gets all the tickets available for purchase of this event
235
+	 *
236
+	 * @param array $query_params like EEM_Base::get_all
237
+	 * @return EE_Base_Class[]|EE_Ticket[]
238
+	 * @throws EE_Error
239
+	 */
240
+	public function tickets($query_params = array())
241
+	{
242
+		//first get all datetimes
243
+		$datetimes = $this->datetimes_ordered();
244
+		if (!$datetimes) {
245
+			return array();
246
+		}
247
+		$datetime_ids = array();
248
+		foreach ($datetimes as $datetime) {
249
+			$datetime_ids[] = $datetime->ID();
250
+		}
251
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
252
+		//if incoming $query_params has where conditions let's merge but not override existing.
253
+		if (is_array($query_params) && isset($query_params[0])) {
254
+			$where_params = array_merge($query_params[0], $where_params);
255
+			unset($query_params[0]);
256
+		}
257
+		//now add $where_params to $query_params
258
+		$query_params[0] = $where_params;
259
+		return EEM_Ticket::instance()->get_all($query_params);
260
+	}
261
+
262
+
263
+	/**
264
+	 * get all unexpired untrashed tickets
265
+	 *
266
+	 * @return EE_Ticket[]
267
+	 * @throws EE_Error
268
+	 */
269
+	public function active_tickets()
270
+	{
271
+		return $this->tickets(array(
272
+			array(
273
+				'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
274
+				'TKT_deleted' => false,
275
+			),
276
+		));
277
+	}
278
+
279
+
280
+	/**
281
+	 * @return bool
282
+	 * @throws EE_Error
283
+	 */
284
+	public function additional_limit()
285
+	{
286
+		return $this->get('EVT_additional_limit');
287
+	}
288
+
289
+
290
+	/**
291
+	 * @return bool
292
+	 * @throws EE_Error
293
+	 */
294
+	public function allow_overflow()
295
+	{
296
+		return $this->get('EVT_allow_overflow');
297
+	}
298
+
299
+
300
+	/**
301
+	 * @return bool
302
+	 * @throws EE_Error
303
+	 */
304
+	public function created()
305
+	{
306
+		return $this->get('EVT_created');
307
+	}
308
+
309
+
310
+	/**
311
+	 * @return bool
312
+	 * @throws EE_Error
313
+	 */
314
+	public function description()
315
+	{
316
+		return $this->get('EVT_desc');
317
+	}
318
+
319
+
320
+	/**
321
+	 * Runs do_shortcode and wpautop on the description
322
+	 *
323
+	 * @return string of html
324
+	 * @throws EE_Error
325
+	 */
326
+	public function description_filtered()
327
+	{
328
+		return $this->get_pretty('EVT_desc');
329
+	}
330
+
331
+
332
+	/**
333
+	 * @return bool
334
+	 * @throws EE_Error
335
+	 */
336
+	public function display_description()
337
+	{
338
+		return $this->get('EVT_display_desc');
339
+	}
340
+
341
+
342
+	/**
343
+	 * @return bool
344
+	 * @throws EE_Error
345
+	 */
346
+	public function display_ticket_selector()
347
+	{
348
+		return (bool)$this->get('EVT_display_ticket_selector');
349
+	}
350
+
351
+
352
+	/**
353
+	 * @return bool
354
+	 * @throws EE_Error
355
+	 */
356
+	public function external_url()
357
+	{
358
+		return $this->get('EVT_external_URL');
359
+	}
360
+
361
+
362
+	/**
363
+	 * @return bool
364
+	 * @throws EE_Error
365
+	 */
366
+	public function member_only()
367
+	{
368
+		return $this->get('EVT_member_only');
369
+	}
370
+
371
+
372
+	/**
373
+	 * @return bool
374
+	 * @throws EE_Error
375
+	 */
376
+	public function phone()
377
+	{
378
+		return $this->get('EVT_phone');
379
+	}
380
+
381
+
382
+	/**
383
+	 * @return bool
384
+	 * @throws EE_Error
385
+	 */
386
+	public function modified()
387
+	{
388
+		return $this->get('EVT_modified');
389
+	}
390
+
391
+
392
+	/**
393
+	 * @return bool
394
+	 * @throws EE_Error
395
+	 */
396
+	public function name()
397
+	{
398
+		return $this->get('EVT_name');
399
+	}
400
+
401
+
402
+	/**
403
+	 * @return bool
404
+	 * @throws EE_Error
405
+	 */
406
+	public function order()
407
+	{
408
+		return $this->get('EVT_order');
409
+	}
410
+
411
+
412
+	/**
413
+	 * @return bool|string
414
+	 * @throws EE_Error
415
+	 */
416
+	public function default_registration_status()
417
+	{
418
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
419
+		return !empty($event_default_registration_status)
420
+			? $event_default_registration_status
421
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
422
+	}
423
+
424
+
425
+	/**
426
+	 * @param int $num_words
427
+	 * @param null $more
428
+	 * @param bool $not_full_desc
429
+	 * @return bool|string
430
+	 * @throws EE_Error
431
+	 */
432
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
433
+	{
434
+		$short_desc = $this->get('EVT_short_desc');
435
+		if (!empty($short_desc) || $not_full_desc) {
436
+			return $short_desc;
437
+		}
438
+		$full_desc = $this->get('EVT_desc');
439
+		return wp_trim_words($full_desc, $num_words, $more);
440
+	}
441
+
442
+
443
+	/**
444
+	 * @return bool
445
+	 * @throws EE_Error
446
+	 */
447
+	public function slug()
448
+	{
449
+		return $this->get('EVT_slug');
450
+	}
451
+
452
+
453
+	/**
454
+	 * @return bool
455
+	 * @throws EE_Error
456
+	 */
457
+	public function timezone_string()
458
+	{
459
+		return $this->get('EVT_timezone_string');
460
+	}
461
+
462
+
463
+	/**
464
+	 * @return bool
465
+	 * @throws EE_Error
466
+	 */
467
+	public function visible_on()
468
+	{
469
+		return $this->get('EVT_visible_on');
470
+	}
471
+
472
+
473
+	/**
474
+	 * @return int
475
+	 * @throws EE_Error
476
+	 */
477
+	public function wp_user()
478
+	{
479
+		return $this->get('EVT_wp_user');
480
+	}
481
+
482
+
483
+	/**
484
+	 * @return bool
485
+	 * @throws EE_Error
486
+	 */
487
+	public function donations()
488
+	{
489
+		return $this->get('EVT_donations');
490
+	}
491
+
492
+
493
+	/**
494
+	 * @param $limit
495
+	 * @throws EE_Error
496
+	 */
497
+	public function set_additional_limit($limit)
498
+	{
499
+		$this->set('EVT_additional_limit', $limit);
500
+	}
501
+
502
+
503
+	/**
504
+	 * @param $created
505
+	 * @throws EE_Error
506
+	 */
507
+	public function set_created($created)
508
+	{
509
+		$this->set('EVT_created', $created);
510
+	}
511
+
512
+
513
+	/**
514
+	 * @param $desc
515
+	 * @throws EE_Error
516
+	 */
517
+	public function set_description($desc)
518
+	{
519
+		$this->set('EVT_desc', $desc);
520
+	}
521
+
522
+
523
+	/**
524
+	 * @param $display_desc
525
+	 * @throws EE_Error
526
+	 */
527
+	public function set_display_description($display_desc)
528
+	{
529
+		$this->set('EVT_display_desc', $display_desc);
530
+	}
531
+
532
+
533
+	/**
534
+	 * @param $display_ticket_selector
535
+	 * @throws EE_Error
536
+	 */
537
+	public function set_display_ticket_selector($display_ticket_selector)
538
+	{
539
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
540
+	}
541
+
542
+
543
+	/**
544
+	 * @param $external_url
545
+	 * @throws EE_Error
546
+	 */
547
+	public function set_external_url($external_url)
548
+	{
549
+		$this->set('EVT_external_URL', $external_url);
550
+	}
551
+
552
+
553
+	/**
554
+	 * @param $member_only
555
+	 * @throws EE_Error
556
+	 */
557
+	public function set_member_only($member_only)
558
+	{
559
+		$this->set('EVT_member_only', $member_only);
560
+	}
561
+
562
+
563
+	/**
564
+	 * @param $event_phone
565
+	 * @throws EE_Error
566
+	 */
567
+	public function set_event_phone($event_phone)
568
+	{
569
+		$this->set('EVT_phone', $event_phone);
570
+	}
571
+
572
+
573
+	/**
574
+	 * @param $modified
575
+	 * @throws EE_Error
576
+	 */
577
+	public function set_modified($modified)
578
+	{
579
+		$this->set('EVT_modified', $modified);
580
+	}
581
+
582
+
583
+	/**
584
+	 * @param $name
585
+	 * @throws EE_Error
586
+	 */
587
+	public function set_name($name)
588
+	{
589
+		$this->set('EVT_name', $name);
590
+	}
591
+
592
+
593
+	/**
594
+	 * @param $order
595
+	 * @throws EE_Error
596
+	 */
597
+	public function set_order($order)
598
+	{
599
+		$this->set('EVT_order', $order);
600
+	}
601
+
602
+
603
+	/**
604
+	 * @param $short_desc
605
+	 * @throws EE_Error
606
+	 */
607
+	public function set_short_description($short_desc)
608
+	{
609
+		$this->set('EVT_short_desc', $short_desc);
610
+	}
611
+
612
+
613
+	/**
614
+	 * @param $slug
615
+	 * @throws EE_Error
616
+	 */
617
+	public function set_slug($slug)
618
+	{
619
+		$this->set('EVT_slug', $slug);
620
+	}
621
+
622
+
623
+	/**
624
+	 * @param $timezone_string
625
+	 * @throws EE_Error
626
+	 */
627
+	public function set_timezone_string($timezone_string)
628
+	{
629
+		$this->set('EVT_timezone_string', $timezone_string);
630
+	}
631
+
632
+
633
+	/**
634
+	 * @param $visible_on
635
+	 * @throws EE_Error
636
+	 */
637
+	public function set_visible_on($visible_on)
638
+	{
639
+		$this->set('EVT_visible_on', $visible_on);
640
+	}
641
+
642
+
643
+	/**
644
+	 * @param $wp_user
645
+	 * @throws EE_Error
646
+	 */
647
+	public function set_wp_user($wp_user)
648
+	{
649
+		$this->set('EVT_wp_user', $wp_user);
650
+	}
651
+
652
+
653
+	/**
654
+	 * @param $default_registration_status
655
+	 * @throws EE_Error
656
+	 */
657
+	public function set_default_registration_status($default_registration_status)
658
+	{
659
+		$this->set('EVT_default_registration_status', $default_registration_status);
660
+	}
661
+
662
+
663
+	/**
664
+	 * @param $donations
665
+	 * @throws EE_Error
666
+	 */
667
+	public function set_donations($donations)
668
+	{
669
+		$this->set('EVT_donations', $donations);
670
+	}
671
+
672
+
673
+	/**
674
+	 * Adds a venue to this event
675
+	 *
676
+	 * @param EE_Venue /int $venue_id_or_obj
677
+	 * @return EE_Base_Class|EE_Venue
678
+	 * @throws EE_Error
679
+	 */
680
+	public function add_venue($venue_id_or_obj)
681
+	{
682
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
683
+	}
684
+
685
+
686
+	/**
687
+	 * Removes a venue from the event
688
+	 *
689
+	 * @param EE_Venue /int $venue_id_or_obj
690
+	 * @return EE_Base_Class|EE_Venue
691
+	 * @throws EE_Error
692
+	 */
693
+	public function remove_venue($venue_id_or_obj)
694
+	{
695
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
696
+	}
697
+
698
+
699
+	/**
700
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
701
+	 *
702
+	 * @param array $query_params like EEM_Base::get_all's $query_params
703
+	 * @return EE_Base_Class[]|EE_Venue[]
704
+	 * @throws EE_Error
705
+	 */
706
+	public function venues($query_params = array())
707
+	{
708
+		return $this->get_many_related('Venue', $query_params);
709
+	}
710
+
711
+
712
+	/**
713
+	 * check if event id is present and if event is published
714
+	 *
715
+	 * @access public
716
+	 * @return boolean true yes, false no
717
+	 * @throws EE_Error
718
+	 */
719
+	private function _has_ID_and_is_published()
720
+	{
721
+		// first check if event id is present and not NULL,
722
+		// then check if this event is published (or any of the equivalent "published" statuses)
723
+		return
724
+			$this->ID() && $this->ID() !== null
725
+			&& (
726
+				$this->status() === 'publish'
727
+				|| $this->status() === EEM_Event::sold_out
728
+				|| $this->status() === EEM_Event::postponed
729
+				|| $this->status() === EEM_Event::cancelled
730
+			);
731
+	}
732
+
733
+
734
+	/**
735
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
736
+	 *
737
+	 * @access public
738
+	 * @return boolean true yes, false no
739
+	 * @throws EE_Error
740
+	 */
741
+	public function is_upcoming()
742
+	{
743
+		// check if event id is present and if this event is published
744
+		if ($this->is_inactive()) {
745
+			return false;
746
+		}
747
+		// set initial value
748
+		$upcoming = false;
749
+		//next let's get all datetimes and loop through them
750
+		$datetimes = $this->datetimes_in_chronological_order();
751
+		foreach ($datetimes as $datetime) {
752
+			if ($datetime instanceof EE_Datetime) {
753
+				//if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
754
+				if ($datetime->is_expired()) {
755
+					continue;
756
+				}
757
+				//if this dtt is active then we return false.
758
+				if ($datetime->is_active()) {
759
+					return false;
760
+				}
761
+				//otherwise let's check upcoming status
762
+				$upcoming = $datetime->is_upcoming();
763
+			}
764
+		}
765
+		return $upcoming;
766
+	}
767
+
768
+
769
+	/**
770
+	 * @return bool
771
+	 * @throws EE_Error
772
+	 */
773
+	public function is_active()
774
+	{
775
+		// check if event id is present and if this event is published
776
+		if ($this->is_inactive()) {
777
+			return false;
778
+		}
779
+		// set initial value
780
+		$active = false;
781
+		//next let's get all datetimes and loop through them
782
+		$datetimes = $this->datetimes_in_chronological_order();
783
+		foreach ($datetimes as $datetime) {
784
+			if ($datetime instanceof EE_Datetime) {
785
+				//if this dtt is expired then we continue cause one of the other datetimes might be active.
786
+				if ($datetime->is_expired()) {
787
+					continue;
788
+				}
789
+				//if this dtt is upcoming then we return false.
790
+				if ($datetime->is_upcoming()) {
791
+					return false;
792
+				}
793
+				//otherwise let's check active status
794
+				$active = $datetime->is_active();
795
+			}
796
+		}
797
+		return $active;
798
+	}
799
+
800
+
801
+	/**
802
+	 * @return bool
803
+	 * @throws EE_Error
804
+	 */
805
+	public function is_expired()
806
+	{
807
+		// check if event id is present and if this event is published
808
+		if ($this->is_inactive()) {
809
+			return false;
810
+		}
811
+		// set initial value
812
+		$expired = false;
813
+		//first let's get all datetimes and loop through them
814
+		$datetimes = $this->datetimes_in_chronological_order();
815
+		foreach ($datetimes as $datetime) {
816
+			if ($datetime instanceof EE_Datetime) {
817
+				//if this dtt is upcoming or active then we return false.
818
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
819
+					return false;
820
+				}
821
+				//otherwise let's check active status
822
+				$expired = $datetime->is_expired();
823
+			}
824
+		}
825
+		return $expired;
826
+	}
827
+
828
+
829
+	/**
830
+	 * @return bool
831
+	 * @throws EE_Error
832
+	 */
833
+	public function is_inactive()
834
+	{
835
+		// check if event id is present and if this event is published
836
+		if ($this->_has_ID_and_is_published()) {
837
+			return false;
838
+		}
839
+		return true;
840
+	}
841
+
842
+
843
+	/**
844
+	 * calculate spaces remaining based on "saleable" tickets
845
+	 *
846
+	 * @param array $tickets
847
+	 * @param bool $filtered
848
+	 * @return int|float
849
+	 * @throws EE_Error
850
+	 * @throws DomainException
851
+	 * @throws UnexpectedEntityException
852
+	 */
853
+	public function spaces_remaining($tickets = array(), $filtered = true)
854
+	{
855
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
856
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
857
+		return $filtered
858
+			? apply_filters(
859
+				'FHEE_EE_Event__spaces_remaining',
860
+				$spaces_remaining,
861
+				$this,
862
+				$tickets
863
+			)
864
+			: $spaces_remaining;
865
+	}
866
+
867
+
868
+	/**
869
+	 *    perform_sold_out_status_check
870
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces available...
871
+	 *    if NOT, then the event status will get toggled to 'sold_out'
872
+	 *
873
+	 * @return bool    return the ACTUAL sold out state.
874
+	 * @throws EE_Error
875
+	 * @throws DomainException
876
+	 * @throws UnexpectedEntityException
877
+	 */
878
+	public function perform_sold_out_status_check()
879
+	{
880
+		// get all unexpired untrashed tickets
881
+		$tickets = $this->tickets(
882
+			array(
883
+				array('TKT_deleted' => false),
884
+				'order_by' => array('TKT_qty' => 'ASC'),
885
+			)
886
+		);
887
+		$all_expired = true;
888
+		foreach ($tickets as $ticket) {
889
+			if(!$ticket->is_expired()){
890
+				$all_expired = false;
891
+				break;
892
+			}
893
+		}
894
+		// if all the tickets are just expired, then don't update the event status to sold out
895
+		if ($all_expired) {
896
+			return true;
897
+		}
898
+		$spaces_remaining = $this->spaces_remaining($tickets);
899
+		if ($spaces_remaining < 1) {
900
+			$this->set_status(EEM_Event::sold_out);
901
+			$this->save();
902
+			$sold_out = true;
903
+		} else {
904
+			$sold_out = false;
905
+			// was event previously marked as sold out ?
906
+			if ($this->status() === EEM_Event::sold_out) {
907
+				// revert status to previous value, if it was set
908
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
909
+				if ($previous_event_status) {
910
+					$this->set_status($previous_event_status);
911
+					$this->save();
912
+				}
913
+			}
914
+		}
915
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
916
+		return $sold_out;
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * This returns the total remaining spaces for sale on this event.
923
+	 *
924
+	 * @uses EE_Event::total_available_spaces()
925
+	 * @return float|int
926
+	 * @throws EE_Error
927
+	 * @throws DomainException
928
+	 * @throws UnexpectedEntityException
929
+	 */
930
+	public function spaces_remaining_for_sale()
931
+	{
932
+		return $this->total_available_spaces(true);
933
+	}
934
+
935
+
936
+
937
+	/**
938
+	 * This returns the total spaces available for an event
939
+	 * while considering all the qtys on the tickets and the reg limits
940
+	 * on the datetimes attached to this event.
941
+	 *
942
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
943
+	 *                              If this is false, then we return the most tickets that could ever be sold
944
+	 *                              for this event with the datetime and tickets setup on the event under optimal
945
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
946
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
947
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
948
+	 *                              sold out, the more accurate the "live" total is.
949
+	 * @return float|int
950
+	 * @throws EE_Error
951
+	 * @throws DomainException
952
+	 * @throws UnexpectedEntityException
953
+	 */
954
+	public function total_available_spaces($consider_sold = false)
955
+	{
956
+		$spaces_available = $consider_sold
957
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
958
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
959
+		return apply_filters(
960
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
961
+			$spaces_available,
962
+			$this,
963
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
964
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
965
+		);
966
+	}
967
+
968
+
969
+	/**
970
+	 * Checks if the event is set to sold out
971
+	 *
972
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
973
+	 *                      actual status but also to flip the status if necessary to sold
974
+	 *                      out If false, we just check the existing status of the event
975
+	 * @return boolean
976
+	 * @throws EE_Error
977
+	 */
978
+	public function is_sold_out($actual = false)
979
+	{
980
+		if (!$actual) {
981
+			return $this->status() === EEM_Event::sold_out;
982
+		}
983
+		return $this->perform_sold_out_status_check();
984
+	}
985
+
986
+
987
+	/**
988
+	 * Checks if the event is marked as postponed
989
+	 *
990
+	 * @return boolean
991
+	 */
992
+	public function is_postponed()
993
+	{
994
+		return $this->status() === EEM_Event::postponed;
995
+	}
996
+
997
+
998
+	/**
999
+	 * Checks if the event is marked as cancelled
1000
+	 *
1001
+	 * @return boolean
1002
+	 */
1003
+	public function is_cancelled()
1004
+	{
1005
+		return $this->status() === EEM_Event::cancelled;
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1011
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1012
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1013
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1014
+	 * the event is considered expired.
1015
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a status
1016
+	 * set on the EVENT when it is not published and thus is done
1017
+	 *
1018
+	 * @param bool $reset
1019
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1020
+	 * @throws EE_Error
1021
+	 */
1022
+	public function get_active_status($reset = false)
1023
+	{
1024
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1025
+		if (!empty($this->_active_status) && !$reset) {
1026
+			return $this->_active_status;
1027
+		}
1028
+		//first check if event id is present on this object
1029
+		if (!$this->ID()) {
1030
+			return false;
1031
+		}
1032
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1033
+		//if event is published:
1034
+		if ($this->status() === 'publish') {
1035
+			//active?
1036
+			if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) {
1037
+				$this->_active_status = EE_Datetime::active;
1038
+			} else {
1039
+				//upcoming?
1040
+				if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) {
1041
+					$this->_active_status = EE_Datetime::upcoming;
1042
+				} else {
1043
+					//expired?
1044
+					if (
1045
+						EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
1046
+					) {
1047
+						$this->_active_status = EE_Datetime::expired;
1048
+					} else {
1049
+						//it would be odd if things make it this far because it basically means there are no datetime's
1050
+						//attached to the event.  So in this case it will just be considered inactive.
1051
+						$this->_active_status = EE_Datetime::inactive;
1052
+					}
1053
+				}
1054
+			}
1055
+		} else {
1056
+			//the event is not published, so let's just set it's active status according to its' post status
1057
+			switch ($this->status()) {
1058
+				case EEM_Event::sold_out :
1059
+					$this->_active_status = EE_Datetime::sold_out;
1060
+					break;
1061
+				case EEM_Event::cancelled :
1062
+					$this->_active_status = EE_Datetime::cancelled;
1063
+					break;
1064
+				case EEM_Event::postponed :
1065
+					$this->_active_status = EE_Datetime::postponed;
1066
+					break;
1067
+				default :
1068
+					$this->_active_status = EE_Datetime::inactive;
1069
+			}
1070
+		}
1071
+		return $this->_active_status;
1072
+	}
1073
+
1074
+
1075
+	/**
1076
+	 *    pretty_active_status
1077
+	 *
1078
+	 * @access public
1079
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1080
+	 * @return mixed void|string
1081
+	 * @throws EE_Error
1082
+	 */
1083
+	public function pretty_active_status($echo = true)
1084
+	{
1085
+		$active_status = $this->get_active_status();
1086
+		$status = '<span class="ee-status event-active-status-'
1087
+			. $active_status
1088
+			. '">'
1089
+			. EEH_Template::pretty_status($active_status, false, 'sentence')
1090
+			. '</span>';
1091
+		if ($echo) {
1092
+			echo $status;
1093
+			return '';
1094
+		}
1095
+		return $status;
1096
+	}
1097
+
1098
+
1099
+	/**
1100
+	 * @return bool|int
1101
+	 * @throws EE_Error
1102
+	 */
1103
+	public function get_number_of_tickets_sold()
1104
+	{
1105
+		$tkt_sold = 0;
1106
+		if (!$this->ID()) {
1107
+			return 0;
1108
+		}
1109
+		$datetimes = $this->datetimes();
1110
+		foreach ($datetimes as $datetime) {
1111
+			if ($datetime instanceof EE_Datetime) {
1112
+				$tkt_sold += $datetime->sold();
1113
+			}
1114
+		}
1115
+		return $tkt_sold;
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * This just returns a count of all the registrations for this event
1121
+	 *
1122
+	 * @access  public
1123
+	 * @return int
1124
+	 * @throws EE_Error
1125
+	 */
1126
+	public function get_count_of_all_registrations()
1127
+	{
1128
+		return EEM_Event::instance()->count_related($this, 'Registration');
1129
+	}
1130
+
1131
+
1132
+	/**
1133
+	 * This returns the ticket with the earliest start time that is
1134
+	 * available for this event (across all datetimes attached to the event)
1135
+	 *
1136
+	 * @return EE_Base_Class|EE_Ticket|null
1137
+	 * @throws EE_Error
1138
+	 */
1139
+	public function get_ticket_with_earliest_start_time()
1140
+	{
1141
+		$where['Datetime.EVT_ID'] = $this->ID();
1142
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1143
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1144
+	}
1145
+
1146
+
1147
+	/**
1148
+	 * This returns the ticket with the latest end time that is available
1149
+	 * for this event (across all datetimes attached to the event)
1150
+	 *
1151
+	 * @return EE_Base_Class|EE_Ticket|null
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function get_ticket_with_latest_end_time()
1155
+	{
1156
+		$where['Datetime.EVT_ID'] = $this->ID();
1157
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1158
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1159
+	}
1160
+
1161
+
1162
+	/**
1163
+	 * This returns whether there are any tickets on sale for this event.
1164
+	 *
1165
+	 * @return bool true = YES tickets on sale.
1166
+	 * @throws EE_Error
1167
+	 */
1168
+	public function tickets_on_sale()
1169
+	{
1170
+		$earliest_ticket = $this->get_ticket_with_earliest_start_time();
1171
+		$latest_ticket = $this->get_ticket_with_latest_end_time();
1172
+		if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) {
1173
+			return false;
1174
+		}
1175
+		//check on sale for these two tickets.
1176
+		if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) {
1177
+			return true;
1178
+		}
1179
+		return false;
1180
+	}
1181
+
1182
+
1183
+	/**
1184
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1185
+	 * to check for an external URL first
1186
+	 *
1187
+	 * @return string
1188
+	 * @throws EE_Error
1189
+	 */
1190
+	public function get_permalink()
1191
+	{
1192
+		if ($this->external_url()) {
1193
+			return $this->external_url();
1194
+		}
1195
+		return parent::get_permalink();
1196
+	}
1197
+
1198
+
1199
+	/**
1200
+	 * Gets the first term for 'espresso_event_categories' we can find
1201
+	 *
1202
+	 * @param array $query_params like EEM_Base::get_all
1203
+	 * @return EE_Base_Class|EE_Term|null
1204
+	 * @throws EE_Error
1205
+	 */
1206
+	public function first_event_category($query_params = array())
1207
+	{
1208
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1209
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1210
+		return EEM_Term::instance()->get_one($query_params);
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * Gets all terms for 'espresso_event_categories' we can find
1216
+	 *
1217
+	 * @param array $query_params
1218
+	 * @return EE_Base_Class[]|EE_Term[]
1219
+	 * @throws EE_Error
1220
+	 */
1221
+	public function get_all_event_categories($query_params = array())
1222
+	{
1223
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1224
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1225
+		return EEM_Term::instance()->get_all($query_params);
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * Adds a question group to this event
1231
+	 *
1232
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1233
+	 * @param bool                  $for_primary if true, the question group will be added for the primary
1234
+	 *                                           registrant, if false will be added for others. default: false
1235
+	 * @return EE_Base_Class|EE_Question_Group
1236
+	 * @throws EE_Error
1237
+	 */
1238
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1239
+	{
1240
+		$extra = $for_primary
1241
+			? array('EQG_primary' => 1)
1242
+			: array();
1243
+		return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra);
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * Removes a question group from the event
1249
+	 *
1250
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1251
+	 * @param bool                  $for_primary if true, the question group will be removed from the primary
1252
+	 *                                           registrant, if false will be removed from others. default: false
1253
+	 * @return EE_Base_Class|EE_Question_Group
1254
+	 * @throws EE_Error
1255
+	 */
1256
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1257
+	{
1258
+		$where = $for_primary
1259
+			? array('EQG_primary' => 1)
1260
+			: array();
1261
+		return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where);
1262
+	}
1263
+
1264
+
1265
+	/**
1266
+	 * Gets all the question groups, ordering them by QSG_order ascending
1267
+	 *
1268
+	 * @param array $query_params @see EEM_Base::get_all
1269
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1270
+	 * @throws EE_Error
1271
+	 */
1272
+	public function question_groups($query_params = array())
1273
+	{
1274
+		$query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1275
+		return $this->get_many_related('Question_Group', $query_params);
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 * Implementation for EEI_Has_Icon interface method.
1281
+	 *
1282
+	 * @see EEI_Visual_Representation for comments
1283
+	 * @return string
1284
+	 */
1285
+	public function get_icon()
1286
+	{
1287
+		return '<span class="dashicons dashicons-flag"></span>';
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * Implementation for EEI_Admin_Links interface method.
1293
+	 *
1294
+	 * @see EEI_Admin_Links for comments
1295
+	 * @return string
1296
+	 * @throws EE_Error
1297
+	 */
1298
+	public function get_admin_details_link()
1299
+	{
1300
+		return $this->get_admin_edit_link();
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * Implementation for EEI_Admin_Links interface method.
1306
+	 *
1307
+	 * @see EEI_Admin_Links for comments
1308
+	 * @return string
1309
+	 * @throws EE_Error
1310
+	 */
1311
+	public function get_admin_edit_link()
1312
+	{
1313
+		return EEH_URL::add_query_args_and_nonce(array(
1314
+			'page' => 'espresso_events',
1315
+			'action' => 'edit',
1316
+			'post' => $this->ID(),
1317
+		),
1318
+			admin_url('admin.php')
1319
+		);
1320
+	}
1321
+
1322
+
1323
+	/**
1324
+	 * Implementation for EEI_Admin_Links interface method.
1325
+	 *
1326
+	 * @see EEI_Admin_Links for comments
1327
+	 * @return string
1328
+	 */
1329
+	public function get_admin_settings_link()
1330
+	{
1331
+		return EEH_URL::add_query_args_and_nonce(array(
1332
+			'page' => 'espresso_events',
1333
+			'action' => 'default_event_settings',
1334
+		),
1335
+			admin_url('admin.php')
1336
+		);
1337
+	}
1338
+
1339
+
1340
+	/**
1341
+	 * Implementation for EEI_Admin_Links interface method.
1342
+	 *
1343
+	 * @see EEI_Admin_Links for comments
1344
+	 * @return string
1345
+	 */
1346
+	public function get_admin_overview_link()
1347
+	{
1348
+		return EEH_URL::add_query_args_and_nonce(array(
1349
+			'page' => 'espresso_events',
1350
+			'action' => 'default',
1351
+		),
1352
+			admin_url('admin.php')
1353
+		);
1354
+	}
1355 1355
 
1356 1356
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1860 added lines, -1860 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1865 +20,1865 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
-            __('%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',
237
-                'event_espresso'),
238
-            '<h4 class="important-notice">',
239
-            '</h4>',
240
-            '<br />',
241
-            '<p>',
242
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
243
-            '">',
244
-            '</a>',
245
-            '</p>'
246
-        );
247
-    }
248
-
249
-
250
-
251
-    /**
252
-     * load_reg_steps
253
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
254
-     *
255
-     * @access    private
256
-     * @throws EE_Error
257
-     */
258
-    public static function load_reg_steps()
259
-    {
260
-        static $reg_steps_loaded = false;
261
-        if ($reg_steps_loaded) {
262
-            return;
263
-        }
264
-        // filter list of reg_steps
265
-        $reg_steps_to_load = (array)apply_filters(
266
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267
-            EED_Single_Page_Checkout::get_reg_steps()
268
-        );
269
-        // sort by key (order)
270
-        ksort($reg_steps_to_load);
271
-        // loop through folders
272
-        foreach ($reg_steps_to_load as $order => $reg_step) {
273
-            // we need a
274
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
275
-                // copy over to the reg_steps_array
276
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
277
-                // register custom key route for each reg step
278
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
279
-                EE_Config::register_route(
280
-                    $reg_step['slug'],
281
-                    'EED_Single_Page_Checkout',
282
-                    'run',
283
-                    'step'
284
-                );
285
-                // add AJAX or other hooks
286
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
287
-                    // setup autoloaders if necessary
288
-                    if ( ! class_exists($reg_step['class_name'])) {
289
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
290
-                            $reg_step['file_path'],
291
-                            true
292
-                        );
293
-                    }
294
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
295
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
296
-                    }
297
-                }
298
-            }
299
-        }
300
-        $reg_steps_loaded = true;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     *    get_reg_steps
307
-     *
308
-     * @access    public
309
-     * @return    array
310
-     */
311
-    public static function get_reg_steps()
312
-    {
313
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
314
-        if (empty($reg_steps)) {
315
-            $reg_steps = array(
316
-                10  => array(
317
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
318
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319
-                    'slug'       => 'attendee_information',
320
-                    'has_hooks'  => false,
321
-                ),
322
-                20  => array(
323
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
324
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325
-                    'slug'       => 'registration_confirmation',
326
-                    'has_hooks'  => false,
327
-                ),
328
-                30  => array(
329
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
330
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331
-                    'slug'       => 'payment_options',
332
-                    'has_hooks'  => true,
333
-                ),
334
-                999 => array(
335
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
336
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337
-                    'slug'       => 'finalize_registration',
338
-                    'has_hooks'  => false,
339
-                ),
340
-            );
341
-        }
342
-        return $reg_steps;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     *    registration_checkout_for_admin
349
-     *
350
-     * @access    public
351
-     * @return    string
352
-     * @throws EE_Error
353
-     */
354
-    public static function registration_checkout_for_admin()
355
-    {
356
-        EED_Single_Page_Checkout::load_request_handler();
357
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
358
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
359
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
360
-        EED_Single_Page_Checkout::instance()->_initialize();
361
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
362
-        return EE_Registry::instance()->REQ->get_output();
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     * process_registration_from_admin
369
-     *
370
-     * @access public
371
-     * @return \EE_Transaction
372
-     * @throws EE_Error
373
-     */
374
-    public static function process_registration_from_admin()
375
-    {
376
-        EED_Single_Page_Checkout::load_request_handler();
377
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
378
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
379
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
380
-        EED_Single_Page_Checkout::instance()->_initialize();
381
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
382
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
383
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
384
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
385
-                if ($final_reg_step->process_reg_step()) {
386
-                    $final_reg_step->set_completed();
387
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
388
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
389
-                }
390
-            }
391
-        }
392
-        return null;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     *    run
399
-     *
400
-     * @access    public
401
-     * @param WP_Query $WP_Query
402
-     * @return    void
403
-     * @throws EE_Error
404
-     */
405
-    public function run($WP_Query)
406
-    {
407
-        if (
408
-            $WP_Query instanceof WP_Query
409
-            && $WP_Query->is_main_query()
410
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
411
-            && $this->_is_reg_checkout()
412
-        ) {
413
-            $this->_initialize();
414
-        }
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * determines whether current url matches reg page url
421
-     *
422
-     * @return bool
423
-     */
424
-    protected function _is_reg_checkout()
425
-    {
426
-        // get current permalink for reg page without any extra query args
427
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
428
-        // get request URI for current request, but without the scheme or host
429
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
430
-        $current_request_uri = html_entity_decode($current_request_uri);
431
-        // get array of query args from the current request URI
432
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
433
-        // grab page id if it is set
434
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
435
-        // and remove the page id from the query args (we will re-add it later)
436
-        unset($query_args['page_id']);
437
-        // now strip all query args from current request URI
438
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
439
-        // and re-add the page id if it was set
440
-        if ($page_id) {
441
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
442
-        }
443
-        // remove slashes and ?
444
-        $current_request_uri = trim($current_request_uri, '?/');
445
-        // is current request URI part of the known full reg page URL ?
446
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * @param WP_Query $wp_query
453
-     * @return    void
454
-     * @throws EE_Error
455
-     */
456
-    public static function init($wp_query)
457
-    {
458
-        EED_Single_Page_Checkout::instance()->run($wp_query);
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     *    _initialize - initial module setup
465
-     *
466
-     * @access    private
467
-     * @throws EE_Error
468
-     * @return    void
469
-     */
470
-    private function _initialize()
471
-    {
472
-        // ensure SPCO doesn't run twice
473
-        if (EED_Single_Page_Checkout::$_initialized) {
474
-            return;
475
-        }
476
-        try {
477
-            EED_Single_Page_Checkout::load_reg_steps();
478
-            $this->_verify_session();
479
-            // setup the EE_Checkout object
480
-            $this->checkout = $this->_initialize_checkout();
481
-            // filter checkout
482
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
483
-            // get the $_GET
484
-            $this->_get_request_vars();
485
-            if ($this->_block_bots()) {
486
-                return;
487
-            }
488
-            // filter continue_reg
489
-            $this->checkout->continue_reg = apply_filters(
490
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
491
-                true,
492
-                $this->checkout
493
-            );
494
-            // load the reg steps array
495
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
496
-                EED_Single_Page_Checkout::$_initialized = true;
497
-                return;
498
-            }
499
-            // set the current step
500
-            $this->checkout->set_current_step($this->checkout->step);
501
-            // and the next step
502
-            $this->checkout->set_next_step();
503
-            // verify that everything has been setup correctly
504
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
505
-                EED_Single_Page_Checkout::$_initialized = true;
506
-                return;
507
-            }
508
-            // lock the transaction
509
-            $this->checkout->transaction->lock();
510
-            // make sure all of our cached objects are added to their respective model entity mappers
511
-            $this->checkout->refresh_all_entities();
512
-            // set amount owing
513
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
514
-            // initialize each reg step, which gives them the chance to potentially alter the process
515
-            $this->_initialize_reg_steps();
516
-            // DEBUG LOG
517
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518
-            // get reg form
519
-            if( ! $this->_check_form_submission()) {
520
-                EED_Single_Page_Checkout::$_initialized = true;
521
-                return;
522
-            }
523
-            // checkout the action!!!
524
-            $this->_process_form_action();
525
-            // add some style and make it dance
526
-            $this->add_styles_and_scripts();
527
-            // kk... SPCO has successfully run
528
-            EED_Single_Page_Checkout::$_initialized = true;
529
-            // set no cache headers and constants
530
-            EE_System::do_not_cache();
531
-            // add anchor
532
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
533
-            // remove transaction lock
534
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
535
-        } catch (Exception $e) {
536
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
-        }
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     *    _verify_session
544
-     * checks that the session is valid and not expired
545
-     *
546
-     * @access    private
547
-     * @throws EE_Error
548
-     */
549
-    private function _verify_session()
550
-    {
551
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
552
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
553
-        }
554
-        $clear_session_requested = filter_var(
555
-            EE_Registry::instance()->REQ->get('clear_session', false),
556
-            FILTER_VALIDATE_BOOLEAN
557
-        );
558
-        // is session still valid ?
559
-        if ($clear_session_requested
560
-            || ( EE_Registry::instance()->SSN->expired()
561
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
562
-            )
563
-        ) {
564
-            $this->checkout = new EE_Checkout();
565
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
566
-            // EE_Registry::instance()->SSN->reset_cart();
567
-            // EE_Registry::instance()->SSN->reset_checkout();
568
-            // EE_Registry::instance()->SSN->reset_transaction();
569
-            if (! $clear_session_requested) {
570
-                EE_Error::add_attention(
571
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
572
-                    __FILE__, __FUNCTION__, __LINE__
573
-                );
574
-            }
575
-            // EE_Registry::instance()->SSN->reset_expired();
576
-        }
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     *    _initialize_checkout
583
-     * loads and instantiates EE_Checkout
584
-     *
585
-     * @access    private
586
-     * @throws EE_Error
587
-     * @return EE_Checkout
588
-     */
589
-    private function _initialize_checkout()
590
-    {
591
-        // look in session for existing checkout
592
-        /** @type EE_Checkout $checkout */
593
-        $checkout = EE_Registry::instance()->SSN->checkout();
594
-        // verify
595
-        if ( ! $checkout instanceof EE_Checkout) {
596
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
597
-            $checkout = EE_Registry::instance()->load_file(
598
-                SPCO_INC_PATH,
599
-                'EE_Checkout',
600
-                'class', array(),
601
-                false
602
-            );
603
-        } else {
604
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
605
-                $this->unlock_transaction();
606
-                wp_safe_redirect($checkout->redirect_url);
607
-                exit();
608
-            }
609
-        }
610
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
611
-        // verify again
612
-        if ( ! $checkout instanceof EE_Checkout) {
613
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
614
-        }
615
-        // reset anything that needs a clean slate for each request
616
-        $checkout->reset_for_current_request();
617
-        return $checkout;
618
-    }
619
-
620
-
621
-
622
-    /**
623
-     *    _get_request_vars
624
-     *
625
-     * @access    private
626
-     * @return    void
627
-     * @throws EE_Error
628
-     */
629
-    private function _get_request_vars()
630
-    {
631
-        // load classes
632
-        EED_Single_Page_Checkout::load_request_handler();
633
-        //make sure this request is marked as belonging to EE
634
-        EE_Registry::instance()->REQ->set_espresso_page(true);
635
-        // which step is being requested ?
636
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
637
-        // which step is being edited ?
638
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
639
-        // and what we're doing on the current step
640
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
641
-        // timestamp
642
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
643
-        // returning to edit ?
644
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
645
-        // add reg url link to registration query params
646
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
647
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
648
-        }
649
-        // or some other kind of revisit ?
650
-        $this->checkout->revisit = filter_var(
651
-            EE_Registry::instance()->REQ->get('revisit', false),
652
-            FILTER_VALIDATE_BOOLEAN
653
-        );
654
-        // and whether or not to generate a reg form for this request
655
-        $this->checkout->generate_reg_form = filter_var(
656
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
657
-            FILTER_VALIDATE_BOOLEAN
658
-        );
659
-        // and whether or not to process a reg form submission for this request
660
-        $this->checkout->process_form_submission = filter_var(
661
-            EE_Registry::instance()->REQ->get(
662
-                'process_form_submission',
663
-                $this->checkout->action === 'process_reg_step'
664
-            ),
665
-            FILTER_VALIDATE_BOOLEAN
666
-        );
667
-        $this->checkout->process_form_submission = filter_var(
668
-            $this->checkout->action !== 'display_spco_reg_step'
669
-                ? $this->checkout->process_form_submission
670
-                : false,
671
-            FILTER_VALIDATE_BOOLEAN
672
-        );
673
-        // $this->_display_request_vars();
674
-    }
675
-
676
-
677
-
678
-    /**
679
-     *  _display_request_vars
680
-     *
681
-     * @access    protected
682
-     * @return    void
683
-     */
684
-    protected function _display_request_vars()
685
-    {
686
-        if ( ! WP_DEBUG) {
687
-            return;
688
-        }
689
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
690
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
691
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
692
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
693
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
694
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
695
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
696
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * _block_bots
703
-     * checks that the incoming request has either of the following set:
704
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
705
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
706
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
707
-     * then where you coming from man?
708
-     *
709
-     * @return boolean
710
-     */
711
-    private function _block_bots()
712
-    {
713
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
714
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
715
-            return true;
716
-        }
717
-        return false;
718
-    }
719
-
720
-
721
-
722
-    /**
723
-     *    _get_first_step
724
-     *  gets slug for first step in $_reg_steps_array
725
-     *
726
-     * @access    private
727
-     * @throws EE_Error
728
-     * @return    string
729
-     */
730
-    private function _get_first_step()
731
-    {
732
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
733
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     *    _load_and_instantiate_reg_steps
740
-     *  instantiates each reg step based on the loaded reg_steps array
741
-     *
742
-     * @access    private
743
-     * @throws EE_Error
744
-     * @return    bool
745
-     */
746
-    private function _load_and_instantiate_reg_steps()
747
-    {
748
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
749
-        // have reg_steps already been instantiated ?
750
-        if (
751
-            empty($this->checkout->reg_steps)
752
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
753
-        ) {
754
-            // if not, then loop through raw reg steps array
755
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
756
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
757
-                    return false;
758
-                }
759
-            }
760
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
761
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
762
-            // skip the registration_confirmation page ?
763
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
764
-                // just remove it from the reg steps array
765
-                $this->checkout->remove_reg_step('registration_confirmation', false);
766
-            } else if (
767
-                isset($this->checkout->reg_steps['registration_confirmation'])
768
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
769
-            ) {
770
-                // set the order to something big like 100
771
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
772
-            }
773
-            // filter the array for good luck
774
-            $this->checkout->reg_steps = apply_filters(
775
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
776
-                $this->checkout->reg_steps
777
-            );
778
-            // finally re-sort based on the reg step class order properties
779
-            $this->checkout->sort_reg_steps();
780
-        } else {
781
-            foreach ($this->checkout->reg_steps as $reg_step) {
782
-                // set all current step stati to FALSE
783
-                $reg_step->set_is_current_step(false);
784
-            }
785
-        }
786
-        if (empty($this->checkout->reg_steps)) {
787
-            EE_Error::add_error(
788
-                __('No Reg Steps were loaded..', 'event_espresso'),
789
-                __FILE__, __FUNCTION__, __LINE__
790
-            );
791
-            return false;
792
-        }
793
-        // make reg step details available to JS
794
-        $this->checkout->set_reg_step_JSON_info();
795
-        return true;
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     *     _load_and_instantiate_reg_step
802
-     *
803
-     * @access    private
804
-     * @param array $reg_step
805
-     * @param int   $order
806
-     * @return bool
807
-     */
808
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
809
-    {
810
-        // we need a file_path, class_name, and slug to add a reg step
811
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
812
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
813
-            if (
814
-                $this->checkout->reg_url_link
815
-                && $this->checkout->step !== $reg_step['slug']
816
-                && $reg_step['slug'] !== 'finalize_registration'
817
-                // normally at this point we would NOT load the reg step, but this filter can change that
818
-                && apply_filters(
819
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
820
-                    true,
821
-                    $reg_step,
822
-                    $this->checkout
823
-                )
824
-            ) {
825
-                return true;
826
-            }
827
-            // instantiate step class using file path and class name
828
-            $reg_step_obj = EE_Registry::instance()->load_file(
829
-                $reg_step['file_path'],
830
-                $reg_step['class_name'],
831
-                'class',
832
-                $this->checkout,
833
-                false
834
-            );
835
-            // did we gets the goods ?
836
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
837
-                // set reg step order based on config
838
-                $reg_step_obj->set_order($order);
839
-                // add instantiated reg step object to the master reg steps array
840
-                $this->checkout->add_reg_step($reg_step_obj);
841
-            } else {
842
-                EE_Error::add_error(
843
-                    __('The current step could not be set.', 'event_espresso'),
844
-                    __FILE__, __FUNCTION__, __LINE__
845
-                );
846
-                return false;
847
-            }
848
-        } else {
849
-            if (WP_DEBUG) {
850
-                EE_Error::add_error(
851
-                    sprintf(
852
-                        __(
853
-                            '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',
854
-                            'event_espresso'
855
-                        ),
856
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
857
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
858
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
859
-                        '<ul>',
860
-                        '<li>',
861
-                        '</li>',
862
-                        '</ul>'
863
-                    ),
864
-                    __FILE__, __FUNCTION__, __LINE__
865
-                );
866
-            }
867
-            return false;
868
-        }
869
-        return true;
870
-    }
871
-
872
-
873
-    /**
874
-     * _verify_transaction_and_get_registrations
875
-     *
876
-     * @access private
877
-     * @return bool
878
-     * @throws InvalidDataTypeException
879
-     * @throws InvalidEntityException
880
-     * @throws EE_Error
881
-     */
882
-    private function _verify_transaction_and_get_registrations()
883
-    {
884
-        // was there already a valid transaction in the checkout from the session ?
885
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
886
-            // get transaction from db or session
887
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
888
-                ? $this->_get_transaction_and_cart_for_previous_visit()
889
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
890
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
891
-                EE_Error::add_error(
892
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
893
-                        'event_espresso'),
894
-                    __FILE__, __FUNCTION__, __LINE__
895
-                );
896
-                $this->checkout->transaction = EE_Transaction::new_instance();
897
-                // add some style and make it dance
898
-                $this->add_styles_and_scripts();
899
-                EED_Single_Page_Checkout::$_initialized = true;
900
-                return false;
901
-            }
902
-            // and the registrations for the transaction
903
-            $this->_get_registrations($this->checkout->transaction);
904
-        }
905
-        return true;
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * _get_transaction_and_cart_for_previous_visit
912
-     *
913
-     * @access private
914
-     * @return mixed EE_Transaction|NULL
915
-     */
916
-    private function _get_transaction_and_cart_for_previous_visit()
917
-    {
918
-        /** @var $TXN_model EEM_Transaction */
919
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
920
-        // because the reg_url_link is present in the request,
921
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
922
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
923
-        // verify transaction
924
-        if ($transaction instanceof EE_Transaction) {
925
-            // and get the cart that was used for that transaction
926
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
927
-            return $transaction;
928
-        }
929
-        EE_Error::add_error(
930
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
931
-            __FILE__, __FUNCTION__, __LINE__
932
-        );
933
-        return null;
934
-
935
-    }
936
-
937
-
938
-
939
-    /**
940
-     * _get_cart_for_transaction
941
-     *
942
-     * @access private
943
-     * @param EE_Transaction $transaction
944
-     * @return EE_Cart
945
-     */
946
-    private function _get_cart_for_transaction($transaction)
947
-    {
948
-        return $this->checkout->get_cart_for_transaction($transaction);
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * get_cart_for_transaction
955
-     *
956
-     * @access public
957
-     * @param EE_Transaction $transaction
958
-     * @return EE_Cart
959
-     */
960
-    public function get_cart_for_transaction(EE_Transaction $transaction)
961
-    {
962
-        return $this->checkout->get_cart_for_transaction($transaction);
963
-    }
964
-
965
-
966
-
967
-    /**
968
-     * _get_transaction_and_cart_for_current_session
969
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
970
-     *
971
-     * @access private
972
-     * @return EE_Transaction
973
-     * @throws EE_Error
974
-     */
975
-    private function _get_cart_for_current_session_and_setup_new_transaction()
976
-    {
977
-        //  if there's no transaction, then this is the FIRST visit to SPCO
978
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
979
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
980
-        // and then create a new transaction
981
-        $transaction = $this->_initialize_transaction();
982
-        // verify transaction
983
-        if ($transaction instanceof EE_Transaction) {
984
-            // save it so that we have an ID for other objects to use
985
-            $transaction->save();
986
-            // and save TXN data to the cart
987
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
988
-        } else {
989
-            EE_Error::add_error(
990
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
991
-                __FILE__, __FUNCTION__, __LINE__
992
-            );
993
-        }
994
-        return $transaction;
995
-    }
996
-
997
-
998
-
999
-    /**
1000
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
1001
-     *
1002
-     * @access private
1003
-     * @return mixed EE_Transaction|NULL
1004
-     */
1005
-    private function _initialize_transaction()
1006
-    {
1007
-        try {
1008
-            // ensure cart totals have been calculated
1009
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
1010
-            // grab the cart grand total
1011
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1012
-            // create new TXN
1013
-            $transaction = EE_Transaction::new_instance(
1014
-                array(
1015
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1016
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1017
-                    'TXN_paid'      => 0,
1018
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1019
-                )
1020
-            );
1021
-            // save it so that we have an ID for other objects to use
1022
-            $transaction->save();
1023
-            // set cron job for following up on TXNs after their session has expired
1024
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1025
-                EE_Registry::instance()->SSN->expiration() + 1,
1026
-                $transaction->ID()
1027
-            );
1028
-            return $transaction;
1029
-        } catch (Exception $e) {
1030
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1031
-        }
1032
-        return null;
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * _get_registrations
1038
-     *
1039
-     * @access private
1040
-     * @param EE_Transaction $transaction
1041
-     * @return void
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidEntityException
1044
-     * @throws EE_Error
1045
-     */
1046
-    private function _get_registrations(EE_Transaction $transaction)
1047
-    {
1048
-        // first step: grab the registrants  { : o
1049
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1050
-        $this->checkout->total_ticket_count = count($registrations);
1051
-        // verify registrations have been set
1052
-        if (empty($registrations)) {
1053
-            // if no cached registrations, then check the db
1054
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1055
-            // still nothing ? well as long as this isn't a revisit
1056
-            if (empty($registrations) && ! $this->checkout->revisit) {
1057
-                // generate new registrations from scratch
1058
-                $registrations = $this->_initialize_registrations($transaction);
1059
-            }
1060
-        }
1061
-        // sort by their original registration order
1062
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1063
-        // then loop thru the array
1064
-        foreach ($registrations as $registration) {
1065
-            // verify each registration
1066
-            if ($registration instanceof EE_Registration) {
1067
-                // we display all attendee info for the primary registrant
1068
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1069
-                    && $registration->is_primary_registrant()
1070
-                ) {
1071
-                    $this->checkout->primary_revisit = true;
1072
-                    break;
1073
-                }
1074
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1075
-                    // but hide info if it doesn't belong to you
1076
-                    $transaction->clear_cache('Registration', $registration->ID());
1077
-                    $this->checkout->total_ticket_count--;
1078
-                }
1079
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1080
-            }
1081
-        }
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1087
-     *
1088
-     * @access private
1089
-     * @param EE_Transaction $transaction
1090
-     * @return    array
1091
-     * @throws InvalidDataTypeException
1092
-     * @throws InvalidEntityException
1093
-     * @throws EE_Error
1094
-     */
1095
-    private function _initialize_registrations(EE_Transaction $transaction)
1096
-    {
1097
-        $att_nmbr = 0;
1098
-        $registrations = array();
1099
-        if ($transaction instanceof EE_Transaction) {
1100
-            /** @type EE_Registration_Processor $registration_processor */
1101
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1102
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1103
-            // now let's add the cart items to the $transaction
1104
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1105
-                //do the following for each ticket of this type they selected
1106
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1107
-                    $att_nmbr++;
1108
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1109
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1110
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1111
-                        array(
1112
-                            $transaction,
1113
-                            $line_item,
1114
-                            $att_nmbr,
1115
-                            $this->checkout->total_ticket_count,
1116
-                        )
1117
-                    );
1118
-                    // override capabilities for frontend registrations
1119
-                    if ( ! is_admin()) {
1120
-                        $CreateRegistrationCommand->setCapCheck(
1121
-                            new PublicCapabilities('', 'create_new_registration')
1122
-                        );
1123
-                    }
1124
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1125
-                    if ( ! $registration instanceof EE_Registration) {
1126
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1127
-                    }
1128
-                    $registrations[ $registration->ID() ] = $registration;
1129
-                }
1130
-            }
1131
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1132
-        }
1133
-        return $registrations;
1134
-    }
1135
-
1136
-
1137
-
1138
-    /**
1139
-     * sorts registrations by REG_count
1140
-     *
1141
-     * @access public
1142
-     * @param EE_Registration $reg_A
1143
-     * @param EE_Registration $reg_B
1144
-     * @return int
1145
-     */
1146
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1147
-    {
1148
-        // this shouldn't ever happen within the same TXN, but oh well
1149
-        if ($reg_A->count() === $reg_B->count()) {
1150
-            return 0;
1151
-        }
1152
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     *    _final_verifications
1159
-     * just makes sure that everything is set up correctly before proceeding
1160
-     *
1161
-     * @access    private
1162
-     * @return    bool
1163
-     * @throws EE_Error
1164
-     */
1165
-    private function _final_verifications()
1166
-    {
1167
-        // filter checkout
1168
-        $this->checkout = apply_filters(
1169
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1170
-            $this->checkout
1171
-        );
1172
-        //verify that current step is still set correctly
1173
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1174
-            EE_Error::add_error(
1175
-                __('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'),
1176
-                __FILE__,
1177
-                __FUNCTION__,
1178
-                __LINE__
1179
-            );
1180
-            return false;
1181
-        }
1182
-        // if returning to SPCO, then verify that primary registrant is set
1183
-        if ( ! empty($this->checkout->reg_url_link)) {
1184
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1185
-            if ( ! $valid_registrant instanceof EE_Registration) {
1186
-                EE_Error::add_error(
1187
-                    __('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'),
1188
-                    __FILE__,
1189
-                    __FUNCTION__,
1190
-                    __LINE__
1191
-                );
1192
-                return false;
1193
-            }
1194
-            $valid_registrant = null;
1195
-            foreach (
1196
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1197
-            ) {
1198
-                if (
1199
-                    $registration instanceof EE_Registration
1200
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1201
-                ) {
1202
-                    $valid_registrant = $registration;
1203
-                }
1204
-            }
1205
-            if ( ! $valid_registrant instanceof EE_Registration) {
1206
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1207
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1208
-                    // clear the session, mark the checkout as unverified, and try again
1209
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1210
-                    EED_Single_Page_Checkout::$_initialized = false;
1211
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1212
-                    $this->_initialize();
1213
-                    EE_Error::reset_notices();
1214
-                    return false;
1215
-                }
1216
-                EE_Error::add_error(
1217
-                    __(
1218
-                        '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.',
1219
-                        'event_espresso'
1220
-                    ),
1221
-                    __FILE__,
1222
-                    __FUNCTION__,
1223
-                    __LINE__
1224
-                );
1225
-                return false;
1226
-            }
1227
-        }
1228
-        // now that things have been kinda sufficiently verified,
1229
-        // let's add the checkout to the session so that it's available to other systems
1230
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1231
-        return true;
1232
-    }
1233
-
1234
-
1235
-
1236
-    /**
1237
-     *    _initialize_reg_steps
1238
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1239
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1240
-     *
1241
-     * @access    private
1242
-     * @param bool $reinitializing
1243
-     * @throws EE_Error
1244
-     */
1245
-    private function _initialize_reg_steps($reinitializing = false)
1246
-    {
1247
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1248
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1249
-        foreach ($this->checkout->reg_steps as $reg_step) {
1250
-            if ( ! $reg_step->initialize_reg_step()) {
1251
-                // if not initialized then maybe this step is being removed...
1252
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1253
-                    // if it was the current step, then we need to start over here
1254
-                    $this->_initialize_reg_steps(true);
1255
-                    return;
1256
-                }
1257
-                continue;
1258
-            }
1259
-            // add css and JS for current step
1260
-            $reg_step->enqueue_styles_and_scripts();
1261
-            // i18n
1262
-            $reg_step->translate_js_strings();
1263
-            if ($reg_step->is_current_step()) {
1264
-                // the text that appears on the reg step form submit button
1265
-                $reg_step->set_submit_button_text();
1266
-            }
1267
-        }
1268
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1269
-        do_action(
1270
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1271
-            $this->checkout->current_step
1272
-        );
1273
-    }
1274
-
1275
-
1276
-
1277
-    /**
1278
-     * _check_form_submission
1279
-     *
1280
-     * @access private
1281
-     * @return boolean
1282
-     */
1283
-    private function _check_form_submission()
1284
-    {
1285
-        //does this request require the reg form to be generated ?
1286
-        if ($this->checkout->generate_reg_form) {
1287
-            // ever heard that song by Blue Rodeo ?
1288
-            try {
1289
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1290
-                // if not displaying a form, then check for form submission
1291
-                if (
1292
-                    $this->checkout->process_form_submission
1293
-                    && $this->checkout->current_step->reg_form->was_submitted()
1294
-                ) {
1295
-                    // clear out any old data in case this step is being run again
1296
-                    $this->checkout->current_step->set_valid_data(array());
1297
-                    // capture submitted form data
1298
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1299
-                        apply_filters(
1300
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1301
-                            EE_Registry::instance()->REQ->params(),
1302
-                            $this->checkout
1303
-                        )
1304
-                    );
1305
-                    // validate submitted form data
1306
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1307
-                        // thou shall not pass !!!
1308
-                        $this->checkout->continue_reg = false;
1309
-                        // any form validation errors?
1310
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1311
-                            $submission_error_messages = array();
1312
-                            // bad, bad, bad registrant
1313
-                            foreach (
1314
-                                $this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1315
-                                as $validation_error
1316
-                            ) {
1317
-                                if ($validation_error instanceof EE_Validation_Error) {
1318
-                                    $submission_error_messages[] = sprintf(
1319
-                                        __('%s : %s', 'event_espresso'),
1320
-                                        $validation_error->get_form_section()->html_label_text(),
1321
-                                        $validation_error->getMessage()
1322
-                                    );
1323
-                                }
1324
-                            }
1325
-                            EE_Error::add_error(
1326
-                                implode('<br />', $submission_error_messages),
1327
-                                __FILE__, __FUNCTION__, __LINE__
1328
-                            );
1329
-                        }
1330
-                        // well not really... what will happen is
1331
-                        // we'll just get redirected back to redo the current step
1332
-                        $this->go_to_next_step();
1333
-                        return false;
1334
-                    }
1335
-                }
1336
-            } catch (EE_Error $e) {
1337
-                $e->get_error();
1338
-            }
1339
-        }
1340
-        return true;
1341
-    }
1342
-
1343
-
1344
-
1345
-    /**
1346
-     * _process_action
1347
-     *
1348
-     * @access private
1349
-     * @return void
1350
-     * @throws EE_Error
1351
-     */
1352
-    private function _process_form_action()
1353
-    {
1354
-        // what cha wanna do?
1355
-        switch ($this->checkout->action) {
1356
-            // AJAX next step reg form
1357
-            case 'display_spco_reg_step' :
1358
-                $this->checkout->redirect = false;
1359
-                if (EE_Registry::instance()->REQ->ajax) {
1360
-                    $this->checkout->json_response->set_reg_step_html(
1361
-                        $this->checkout->current_step->display_reg_form()
1362
-                    );
1363
-                }
1364
-                break;
1365
-            default :
1366
-                // meh... do one of those other steps first
1367
-                if (
1368
-                    ! empty($this->checkout->action)
1369
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1370
-                ) {
1371
-                    // dynamically creates hook point like:
1372
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1373
-                    do_action(
1374
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1375
-                        $this->checkout->current_step
1376
-                    );
1377
-                    // call action on current step
1378
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1379
-                        // good registrant, you get to proceed
1380
-                        if (
1381
-                            $this->checkout->current_step->success_message() !== ''
1382
-                            && apply_filters(
1383
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1384
-                                false
1385
-                            )
1386
-                        ) {
1387
-                            EE_Error::add_success(
1388
-                                $this->checkout->current_step->success_message()
1389
-                                . '<br />' . $this->checkout->next_step->_instructions()
1390
-                            );
1391
-                        }
1392
-                        // pack it up, pack it in...
1393
-                        $this->_setup_redirect();
1394
-                    }
1395
-                    // dynamically creates hook point like:
1396
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1397
-                    do_action(
1398
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1399
-                        $this->checkout->current_step
1400
-                    );
1401
-                } else {
1402
-                    EE_Error::add_error(
1403
-                        sprintf(
1404
-                            __(
1405
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1406
-                                'event_espresso'
1407
-                            ),
1408
-                            $this->checkout->action,
1409
-                            $this->checkout->current_step->name()
1410
-                        ),
1411
-                        __FILE__,
1412
-                        __FUNCTION__,
1413
-                        __LINE__
1414
-                    );
1415
-                }
1416
-            // end default
1417
-        }
1418
-        // store our progress so far
1419
-        $this->checkout->stash_transaction_and_checkout();
1420
-        // advance to the next step! If you pass GO, collect $200
1421
-        $this->go_to_next_step();
1422
-    }
1423
-
1424
-
1425
-
1426
-    /**
1427
-     *        add_styles_and_scripts
1428
-     *
1429
-     * @access        public
1430
-     * @return        void
1431
-     */
1432
-    public function add_styles_and_scripts()
1433
-    {
1434
-        // i18n
1435
-        $this->translate_js_strings();
1436
-        if ($this->checkout->admin_request) {
1437
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1438
-        } else {
1439
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1440
-        }
1441
-    }
1442
-
1443
-
1444
-
1445
-    /**
1446
-     *        translate_js_strings
1447
-     *
1448
-     * @access        public
1449
-     * @return        void
1450
-     */
1451
-    public function translate_js_strings()
1452
-    {
1453
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1454
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1455
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1456
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1457
-            'event_espresso'
1458
-        );
1459
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1460
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1461
-            'event_espresso'
1462
-        );
1463
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1464
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1465
-            'event_espresso'
1466
-        );
1467
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1468
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1469
-            'event_espresso'
1470
-        );
1471
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1472
-            'This registration step could not be completed. Please refresh the page and try again.',
1473
-            'event_espresso'
1474
-        );
1475
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1476
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1477
-            'event_espresso'
1478
-        );
1479
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1480
-            __(
1481
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1482
-                'event_espresso'
1483
-            ),
1484
-            '<br/>',
1485
-            '<br/>'
1486
-        );
1487
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1488
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1489
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1490
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1491
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1492
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1493
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1494
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1495
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1496
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1497
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1498
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1499
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1500
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1501
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1502
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1503
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1504
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1505
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1506
-            __(
1507
-                '%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',
1508
-                'event_espresso'
1509
-            ),
1510
-            '<h4 class="important-notice">',
1511
-            '</h4>',
1512
-            '<br />',
1513
-            '<p>',
1514
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1515
-            '">',
1516
-            '</a>',
1517
-            '</p>'
1518
-        );
1519
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1520
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1521
-            true
1522
-        );
1523
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1524
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1525
-        );
1526
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1527
-            'M d, Y H:i:s',
1528
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1529
-        );
1530
-    }
1531
-
1532
-
1533
-
1534
-    /**
1535
-     *    enqueue_styles_and_scripts
1536
-     *
1537
-     * @access        public
1538
-     * @return        void
1539
-     * @throws EE_Error
1540
-     */
1541
-    public function enqueue_styles_and_scripts()
1542
-    {
1543
-        // load css
1544
-        wp_register_style(
1545
-            'single_page_checkout',
1546
-            SPCO_CSS_URL . 'single_page_checkout.css',
1547
-            array('espresso_default'),
1548
-            EVENT_ESPRESSO_VERSION
1549
-        );
1550
-        wp_enqueue_style('single_page_checkout');
1551
-        // load JS
1552
-        wp_register_script(
1553
-            'jquery_plugin',
1554
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1555
-            array('jquery'),
1556
-            '1.0.1',
1557
-            true
1558
-        );
1559
-        wp_register_script(
1560
-            'jquery_countdown',
1561
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1562
-            array('jquery_plugin'),
1563
-            '2.0.2',
1564
-            true
1565
-        );
1566
-        wp_register_script(
1567
-            'single_page_checkout',
1568
-            SPCO_JS_URL . 'single_page_checkout.js',
1569
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1570
-            EVENT_ESPRESSO_VERSION,
1571
-            true
1572
-        );
1573
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1574
-            $this->checkout->registration_form->enqueue_js();
1575
-        }
1576
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1577
-            $this->checkout->current_step->reg_form->enqueue_js();
1578
-        }
1579
-        wp_enqueue_script('single_page_checkout');
1580
-        /**
1581
-         * global action hook for enqueueing styles and scripts with
1582
-         * spco calls.
1583
-         */
1584
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1585
-        /**
1586
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1587
-         * The hook will end up being something like:
1588
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1589
-         */
1590
-        do_action(
1591
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1592
-            $this
1593
-        );
1594
-    }
1595
-
1596
-
1597
-
1598
-    /**
1599
-     *    display the Registration Single Page Checkout Form
1600
-     *
1601
-     * @access    private
1602
-     * @return    void
1603
-     * @throws EE_Error
1604
-     */
1605
-    private function _display_spco_reg_form()
1606
-    {
1607
-        // if registering via the admin, just display the reg form for the current step
1608
-        if ($this->checkout->admin_request) {
1609
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1610
-        } else {
1611
-            // add powered by EE msg
1612
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1613
-            $empty_cart = count(
1614
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1615
-            ) < 1;
1616
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1617
-            $cookies_not_set_msg = '';
1618
-            if ($empty_cart) {
1619
-                $cookies_not_set_msg = apply_filters(
1620
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1621
-                    sprintf(
1622
-                        __(
1623
-                            '%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',
1624
-                            'event_espresso'
1625
-                        ),
1626
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1627
-                        '</div>',
1628
-                        '<h6 class="important-notice">',
1629
-                        '</h6>',
1630
-                        '<p>',
1631
-                        '</p>',
1632
-                        '<br />',
1633
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1634
-                        '</a>'
1635
-                    )
1636
-                );
1637
-            }
1638
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1639
-                array(
1640
-                    'name'            => 'single-page-checkout',
1641
-                    'html_id'         => 'ee-single-page-checkout-dv',
1642
-                    'layout_strategy' =>
1643
-                        new EE_Template_Layout(
1644
-                            array(
1645
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1646
-                                'template_args'        => array(
1647
-                                    'empty_cart'              => $empty_cart,
1648
-                                    'revisit'                 => $this->checkout->revisit,
1649
-                                    'reg_steps'               => $this->checkout->reg_steps,
1650
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1651
-                                        ? $this->checkout->next_step->slug()
1652
-                                        : '',
1653
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1654
-                                    'empty_msg'               => apply_filters(
1655
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1656
-                                        sprintf(
1657
-                                            __(
1658
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1659
-                                                'event_espresso'
1660
-                                            ),
1661
-                                            '<a href="'
1662
-                                            . get_post_type_archive_link('espresso_events')
1663
-                                            . '" title="',
1664
-                                            '">',
1665
-                                            '</a>'
1666
-                                        )
1667
-                                    ),
1668
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1669
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1670
-                                    'session_expiration'      => gmdate(
1671
-                                        'M d, Y H:i:s',
1672
-                                        EE_Registry::instance()->SSN->expiration()
1673
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1674
-                                    ),
1675
-                                ),
1676
-                            )
1677
-                        ),
1678
-                )
1679
-            );
1680
-            // load template and add to output sent that gets filtered into the_content()
1681
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1682
-        }
1683
-    }
1684
-
1685
-
1686
-
1687
-    /**
1688
-     *    add_extra_finalize_registration_inputs
1689
-     *
1690
-     * @access    public
1691
-     * @param $next_step
1692
-     * @internal  param string $label
1693
-     * @return void
1694
-     */
1695
-    public function add_extra_finalize_registration_inputs($next_step)
1696
-    {
1697
-        if ($next_step === 'finalize_registration') {
1698
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1699
-        }
1700
-    }
1701
-
1702
-
1703
-
1704
-    /**
1705
-     *    display_registration_footer
1706
-     *
1707
-     * @access    public
1708
-     * @return    string
1709
-     */
1710
-    public static function display_registration_footer()
1711
-    {
1712
-        if (
1713
-        apply_filters(
1714
-            'FHEE__EE_Front__Controller__show_reg_footer',
1715
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1716
-        )
1717
-        ) {
1718
-            add_filter(
1719
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1720
-                function ($url) {
1721
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1722
-                }
1723
-            );
1724
-            echo apply_filters(
1725
-                'FHEE__EE_Front_Controller__display_registration_footer',
1726
-                \EEH_Template::powered_by_event_espresso(
1727
-                    '',
1728
-                    'espresso-registration-footer-dv',
1729
-                    array('utm_content' => 'registration_checkout')
1730
-                )
1731
-            );
1732
-        }
1733
-        return '';
1734
-    }
1735
-
1736
-
1737
-
1738
-    /**
1739
-     *    unlock_transaction
1740
-     *
1741
-     * @access    public
1742
-     * @return    void
1743
-     * @throws EE_Error
1744
-     */
1745
-    public function unlock_transaction()
1746
-    {
1747
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1748
-            $this->checkout->transaction->unlock();
1749
-        }
1750
-    }
1751
-
1752
-
1753
-
1754
-    /**
1755
-     *        _setup_redirect
1756
-     *
1757
-     * @access    private
1758
-     * @return void
1759
-     */
1760
-    private function _setup_redirect()
1761
-    {
1762
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1763
-            $this->checkout->redirect = true;
1764
-            if (empty($this->checkout->redirect_url)) {
1765
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1766
-            }
1767
-            $this->checkout->redirect_url = apply_filters(
1768
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1769
-                $this->checkout->redirect_url,
1770
-                $this->checkout
1771
-            );
1772
-        }
1773
-    }
1774
-
1775
-
1776
-
1777
-    /**
1778
-     *   handle ajax message responses and redirects
1779
-     *
1780
-     * @access public
1781
-     * @return void
1782
-     * @throws EE_Error
1783
-     */
1784
-    public function go_to_next_step()
1785
-    {
1786
-        if (EE_Registry::instance()->REQ->ajax) {
1787
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1788
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1789
-        }
1790
-        $this->unlock_transaction();
1791
-        // just return for these conditions
1792
-        if (
1793
-            $this->checkout->admin_request
1794
-            || $this->checkout->action === 'redirect_form'
1795
-            || $this->checkout->action === 'update_checkout'
1796
-        ) {
1797
-            return;
1798
-        }
1799
-        // AJAX response
1800
-        $this->_handle_json_response();
1801
-        // redirect to next step or the Thank You page
1802
-        $this->_handle_html_redirects();
1803
-        // hmmm... must be something wrong, so let's just display the form again !
1804
-        $this->_display_spco_reg_form();
1805
-    }
1806
-
1807
-
1808
-
1809
-    /**
1810
-     *   _handle_json_response
1811
-     *
1812
-     * @access protected
1813
-     * @return void
1814
-     */
1815
-    protected function _handle_json_response()
1816
-    {
1817
-        // if this is an ajax request
1818
-        if (EE_Registry::instance()->REQ->ajax) {
1819
-            // DEBUG LOG
1820
-            //$this->checkout->log(
1821
-            //	__CLASS__, __FUNCTION__, __LINE__,
1822
-            //	array(
1823
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1824
-            //		'redirect'                   => $this->checkout->redirect,
1825
-            //		'continue_reg'               => $this->checkout->continue_reg,
1826
-            //	)
1827
-            //);
1828
-            $this->checkout->json_response->set_registration_time_limit(
1829
-                $this->checkout->get_registration_time_limit()
1830
-            );
1831
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1832
-            // just send the ajax (
1833
-            $json_response = apply_filters(
1834
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1835
-                $this->checkout->json_response
1836
-            );
1837
-            echo $json_response;
1838
-            exit();
1839
-        }
1840
-    }
1841
-
1842
-
1843
-
1844
-    /**
1845
-     *   _handle_redirects
1846
-     *
1847
-     * @access protected
1848
-     * @return void
1849
-     */
1850
-    protected function _handle_html_redirects()
1851
-    {
1852
-        // going somewhere ?
1853
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1854
-            // store notices in a transient
1855
-            EE_Error::get_notices(false, true, true);
1856
-            // DEBUG LOG
1857
-            //$this->checkout->log(
1858
-            //	__CLASS__, __FUNCTION__, __LINE__,
1859
-            //	array(
1860
-            //		'headers_sent' => headers_sent(),
1861
-            //		'redirect_url'     => $this->checkout->redirect_url,
1862
-            //		'headers_list'    => headers_list(),
1863
-            //	)
1864
-            //);
1865
-            wp_safe_redirect($this->checkout->redirect_url);
1866
-            exit();
1867
-        }
1868
-    }
1869
-
1870
-
1871
-
1872
-    /**
1873
-     *   set_checkout_anchor
1874
-     *
1875
-     * @access public
1876
-     * @return void
1877
-     */
1878
-    public function set_checkout_anchor()
1879
-    {
1880
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1881
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
236
+			__('%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',
237
+				'event_espresso'),
238
+			'<h4 class="important-notice">',
239
+			'</h4>',
240
+			'<br />',
241
+			'<p>',
242
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
243
+			'">',
244
+			'</a>',
245
+			'</p>'
246
+		);
247
+	}
248
+
249
+
250
+
251
+	/**
252
+	 * load_reg_steps
253
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
254
+	 *
255
+	 * @access    private
256
+	 * @throws EE_Error
257
+	 */
258
+	public static function load_reg_steps()
259
+	{
260
+		static $reg_steps_loaded = false;
261
+		if ($reg_steps_loaded) {
262
+			return;
263
+		}
264
+		// filter list of reg_steps
265
+		$reg_steps_to_load = (array)apply_filters(
266
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
267
+			EED_Single_Page_Checkout::get_reg_steps()
268
+		);
269
+		// sort by key (order)
270
+		ksort($reg_steps_to_load);
271
+		// loop through folders
272
+		foreach ($reg_steps_to_load as $order => $reg_step) {
273
+			// we need a
274
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
275
+				// copy over to the reg_steps_array
276
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
277
+				// register custom key route for each reg step
278
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
279
+				EE_Config::register_route(
280
+					$reg_step['slug'],
281
+					'EED_Single_Page_Checkout',
282
+					'run',
283
+					'step'
284
+				);
285
+				// add AJAX or other hooks
286
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
287
+					// setup autoloaders if necessary
288
+					if ( ! class_exists($reg_step['class_name'])) {
289
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
290
+							$reg_step['file_path'],
291
+							true
292
+						);
293
+					}
294
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
295
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
296
+					}
297
+				}
298
+			}
299
+		}
300
+		$reg_steps_loaded = true;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 *    get_reg_steps
307
+	 *
308
+	 * @access    public
309
+	 * @return    array
310
+	 */
311
+	public static function get_reg_steps()
312
+	{
313
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
314
+		if (empty($reg_steps)) {
315
+			$reg_steps = array(
316
+				10  => array(
317
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
318
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
319
+					'slug'       => 'attendee_information',
320
+					'has_hooks'  => false,
321
+				),
322
+				20  => array(
323
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
324
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
325
+					'slug'       => 'registration_confirmation',
326
+					'has_hooks'  => false,
327
+				),
328
+				30  => array(
329
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
330
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
331
+					'slug'       => 'payment_options',
332
+					'has_hooks'  => true,
333
+				),
334
+				999 => array(
335
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
336
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
337
+					'slug'       => 'finalize_registration',
338
+					'has_hooks'  => false,
339
+				),
340
+			);
341
+		}
342
+		return $reg_steps;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 *    registration_checkout_for_admin
349
+	 *
350
+	 * @access    public
351
+	 * @return    string
352
+	 * @throws EE_Error
353
+	 */
354
+	public static function registration_checkout_for_admin()
355
+	{
356
+		EED_Single_Page_Checkout::load_request_handler();
357
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
358
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
359
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
360
+		EED_Single_Page_Checkout::instance()->_initialize();
361
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
362
+		return EE_Registry::instance()->REQ->get_output();
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 * process_registration_from_admin
369
+	 *
370
+	 * @access public
371
+	 * @return \EE_Transaction
372
+	 * @throws EE_Error
373
+	 */
374
+	public static function process_registration_from_admin()
375
+	{
376
+		EED_Single_Page_Checkout::load_request_handler();
377
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
378
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
379
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
380
+		EED_Single_Page_Checkout::instance()->_initialize();
381
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
382
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
383
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
384
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
385
+				if ($final_reg_step->process_reg_step()) {
386
+					$final_reg_step->set_completed();
387
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
388
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
389
+				}
390
+			}
391
+		}
392
+		return null;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 *    run
399
+	 *
400
+	 * @access    public
401
+	 * @param WP_Query $WP_Query
402
+	 * @return    void
403
+	 * @throws EE_Error
404
+	 */
405
+	public function run($WP_Query)
406
+	{
407
+		if (
408
+			$WP_Query instanceof WP_Query
409
+			&& $WP_Query->is_main_query()
410
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
411
+			&& $this->_is_reg_checkout()
412
+		) {
413
+			$this->_initialize();
414
+		}
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * determines whether current url matches reg page url
421
+	 *
422
+	 * @return bool
423
+	 */
424
+	protected function _is_reg_checkout()
425
+	{
426
+		// get current permalink for reg page without any extra query args
427
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
428
+		// get request URI for current request, but without the scheme or host
429
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
430
+		$current_request_uri = html_entity_decode($current_request_uri);
431
+		// get array of query args from the current request URI
432
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
433
+		// grab page id if it is set
434
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
435
+		// and remove the page id from the query args (we will re-add it later)
436
+		unset($query_args['page_id']);
437
+		// now strip all query args from current request URI
438
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
439
+		// and re-add the page id if it was set
440
+		if ($page_id) {
441
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
442
+		}
443
+		// remove slashes and ?
444
+		$current_request_uri = trim($current_request_uri, '?/');
445
+		// is current request URI part of the known full reg page URL ?
446
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * @param WP_Query $wp_query
453
+	 * @return    void
454
+	 * @throws EE_Error
455
+	 */
456
+	public static function init($wp_query)
457
+	{
458
+		EED_Single_Page_Checkout::instance()->run($wp_query);
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 *    _initialize - initial module setup
465
+	 *
466
+	 * @access    private
467
+	 * @throws EE_Error
468
+	 * @return    void
469
+	 */
470
+	private function _initialize()
471
+	{
472
+		// ensure SPCO doesn't run twice
473
+		if (EED_Single_Page_Checkout::$_initialized) {
474
+			return;
475
+		}
476
+		try {
477
+			EED_Single_Page_Checkout::load_reg_steps();
478
+			$this->_verify_session();
479
+			// setup the EE_Checkout object
480
+			$this->checkout = $this->_initialize_checkout();
481
+			// filter checkout
482
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
483
+			// get the $_GET
484
+			$this->_get_request_vars();
485
+			if ($this->_block_bots()) {
486
+				return;
487
+			}
488
+			// filter continue_reg
489
+			$this->checkout->continue_reg = apply_filters(
490
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
491
+				true,
492
+				$this->checkout
493
+			);
494
+			// load the reg steps array
495
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
496
+				EED_Single_Page_Checkout::$_initialized = true;
497
+				return;
498
+			}
499
+			// set the current step
500
+			$this->checkout->set_current_step($this->checkout->step);
501
+			// and the next step
502
+			$this->checkout->set_next_step();
503
+			// verify that everything has been setup correctly
504
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
505
+				EED_Single_Page_Checkout::$_initialized = true;
506
+				return;
507
+			}
508
+			// lock the transaction
509
+			$this->checkout->transaction->lock();
510
+			// make sure all of our cached objects are added to their respective model entity mappers
511
+			$this->checkout->refresh_all_entities();
512
+			// set amount owing
513
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
514
+			// initialize each reg step, which gives them the chance to potentially alter the process
515
+			$this->_initialize_reg_steps();
516
+			// DEBUG LOG
517
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
518
+			// get reg form
519
+			if( ! $this->_check_form_submission()) {
520
+				EED_Single_Page_Checkout::$_initialized = true;
521
+				return;
522
+			}
523
+			// checkout the action!!!
524
+			$this->_process_form_action();
525
+			// add some style and make it dance
526
+			$this->add_styles_and_scripts();
527
+			// kk... SPCO has successfully run
528
+			EED_Single_Page_Checkout::$_initialized = true;
529
+			// set no cache headers and constants
530
+			EE_System::do_not_cache();
531
+			// add anchor
532
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
533
+			// remove transaction lock
534
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
535
+		} catch (Exception $e) {
536
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
537
+		}
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 *    _verify_session
544
+	 * checks that the session is valid and not expired
545
+	 *
546
+	 * @access    private
547
+	 * @throws EE_Error
548
+	 */
549
+	private function _verify_session()
550
+	{
551
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
552
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
553
+		}
554
+		$clear_session_requested = filter_var(
555
+			EE_Registry::instance()->REQ->get('clear_session', false),
556
+			FILTER_VALIDATE_BOOLEAN
557
+		);
558
+		// is session still valid ?
559
+		if ($clear_session_requested
560
+			|| ( EE_Registry::instance()->SSN->expired()
561
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
562
+			)
563
+		) {
564
+			$this->checkout = new EE_Checkout();
565
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
566
+			// EE_Registry::instance()->SSN->reset_cart();
567
+			// EE_Registry::instance()->SSN->reset_checkout();
568
+			// EE_Registry::instance()->SSN->reset_transaction();
569
+			if (! $clear_session_requested) {
570
+				EE_Error::add_attention(
571
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
572
+					__FILE__, __FUNCTION__, __LINE__
573
+				);
574
+			}
575
+			// EE_Registry::instance()->SSN->reset_expired();
576
+		}
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 *    _initialize_checkout
583
+	 * loads and instantiates EE_Checkout
584
+	 *
585
+	 * @access    private
586
+	 * @throws EE_Error
587
+	 * @return EE_Checkout
588
+	 */
589
+	private function _initialize_checkout()
590
+	{
591
+		// look in session for existing checkout
592
+		/** @type EE_Checkout $checkout */
593
+		$checkout = EE_Registry::instance()->SSN->checkout();
594
+		// verify
595
+		if ( ! $checkout instanceof EE_Checkout) {
596
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
597
+			$checkout = EE_Registry::instance()->load_file(
598
+				SPCO_INC_PATH,
599
+				'EE_Checkout',
600
+				'class', array(),
601
+				false
602
+			);
603
+		} else {
604
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
605
+				$this->unlock_transaction();
606
+				wp_safe_redirect($checkout->redirect_url);
607
+				exit();
608
+			}
609
+		}
610
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
611
+		// verify again
612
+		if ( ! $checkout instanceof EE_Checkout) {
613
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
614
+		}
615
+		// reset anything that needs a clean slate for each request
616
+		$checkout->reset_for_current_request();
617
+		return $checkout;
618
+	}
619
+
620
+
621
+
622
+	/**
623
+	 *    _get_request_vars
624
+	 *
625
+	 * @access    private
626
+	 * @return    void
627
+	 * @throws EE_Error
628
+	 */
629
+	private function _get_request_vars()
630
+	{
631
+		// load classes
632
+		EED_Single_Page_Checkout::load_request_handler();
633
+		//make sure this request is marked as belonging to EE
634
+		EE_Registry::instance()->REQ->set_espresso_page(true);
635
+		// which step is being requested ?
636
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
637
+		// which step is being edited ?
638
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
639
+		// and what we're doing on the current step
640
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
641
+		// timestamp
642
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
643
+		// returning to edit ?
644
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
645
+		// add reg url link to registration query params
646
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
647
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
648
+		}
649
+		// or some other kind of revisit ?
650
+		$this->checkout->revisit = filter_var(
651
+			EE_Registry::instance()->REQ->get('revisit', false),
652
+			FILTER_VALIDATE_BOOLEAN
653
+		);
654
+		// and whether or not to generate a reg form for this request
655
+		$this->checkout->generate_reg_form = filter_var(
656
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
657
+			FILTER_VALIDATE_BOOLEAN
658
+		);
659
+		// and whether or not to process a reg form submission for this request
660
+		$this->checkout->process_form_submission = filter_var(
661
+			EE_Registry::instance()->REQ->get(
662
+				'process_form_submission',
663
+				$this->checkout->action === 'process_reg_step'
664
+			),
665
+			FILTER_VALIDATE_BOOLEAN
666
+		);
667
+		$this->checkout->process_form_submission = filter_var(
668
+			$this->checkout->action !== 'display_spco_reg_step'
669
+				? $this->checkout->process_form_submission
670
+				: false,
671
+			FILTER_VALIDATE_BOOLEAN
672
+		);
673
+		// $this->_display_request_vars();
674
+	}
675
+
676
+
677
+
678
+	/**
679
+	 *  _display_request_vars
680
+	 *
681
+	 * @access    protected
682
+	 * @return    void
683
+	 */
684
+	protected function _display_request_vars()
685
+	{
686
+		if ( ! WP_DEBUG) {
687
+			return;
688
+		}
689
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
690
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
691
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
692
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
693
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
694
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
695
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
696
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * _block_bots
703
+	 * checks that the incoming request has either of the following set:
704
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
705
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
706
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
707
+	 * then where you coming from man?
708
+	 *
709
+	 * @return boolean
710
+	 */
711
+	private function _block_bots()
712
+	{
713
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
714
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
715
+			return true;
716
+		}
717
+		return false;
718
+	}
719
+
720
+
721
+
722
+	/**
723
+	 *    _get_first_step
724
+	 *  gets slug for first step in $_reg_steps_array
725
+	 *
726
+	 * @access    private
727
+	 * @throws EE_Error
728
+	 * @return    string
729
+	 */
730
+	private function _get_first_step()
731
+	{
732
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
733
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 *    _load_and_instantiate_reg_steps
740
+	 *  instantiates each reg step based on the loaded reg_steps array
741
+	 *
742
+	 * @access    private
743
+	 * @throws EE_Error
744
+	 * @return    bool
745
+	 */
746
+	private function _load_and_instantiate_reg_steps()
747
+	{
748
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
749
+		// have reg_steps already been instantiated ?
750
+		if (
751
+			empty($this->checkout->reg_steps)
752
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
753
+		) {
754
+			// if not, then loop through raw reg steps array
755
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
756
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
757
+					return false;
758
+				}
759
+			}
760
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
761
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
762
+			// skip the registration_confirmation page ?
763
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
764
+				// just remove it from the reg steps array
765
+				$this->checkout->remove_reg_step('registration_confirmation', false);
766
+			} else if (
767
+				isset($this->checkout->reg_steps['registration_confirmation'])
768
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
769
+			) {
770
+				// set the order to something big like 100
771
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
772
+			}
773
+			// filter the array for good luck
774
+			$this->checkout->reg_steps = apply_filters(
775
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
776
+				$this->checkout->reg_steps
777
+			);
778
+			// finally re-sort based on the reg step class order properties
779
+			$this->checkout->sort_reg_steps();
780
+		} else {
781
+			foreach ($this->checkout->reg_steps as $reg_step) {
782
+				// set all current step stati to FALSE
783
+				$reg_step->set_is_current_step(false);
784
+			}
785
+		}
786
+		if (empty($this->checkout->reg_steps)) {
787
+			EE_Error::add_error(
788
+				__('No Reg Steps were loaded..', 'event_espresso'),
789
+				__FILE__, __FUNCTION__, __LINE__
790
+			);
791
+			return false;
792
+		}
793
+		// make reg step details available to JS
794
+		$this->checkout->set_reg_step_JSON_info();
795
+		return true;
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 *     _load_and_instantiate_reg_step
802
+	 *
803
+	 * @access    private
804
+	 * @param array $reg_step
805
+	 * @param int   $order
806
+	 * @return bool
807
+	 */
808
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
809
+	{
810
+		// we need a file_path, class_name, and slug to add a reg step
811
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
812
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
813
+			if (
814
+				$this->checkout->reg_url_link
815
+				&& $this->checkout->step !== $reg_step['slug']
816
+				&& $reg_step['slug'] !== 'finalize_registration'
817
+				// normally at this point we would NOT load the reg step, but this filter can change that
818
+				&& apply_filters(
819
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
820
+					true,
821
+					$reg_step,
822
+					$this->checkout
823
+				)
824
+			) {
825
+				return true;
826
+			}
827
+			// instantiate step class using file path and class name
828
+			$reg_step_obj = EE_Registry::instance()->load_file(
829
+				$reg_step['file_path'],
830
+				$reg_step['class_name'],
831
+				'class',
832
+				$this->checkout,
833
+				false
834
+			);
835
+			// did we gets the goods ?
836
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
837
+				// set reg step order based on config
838
+				$reg_step_obj->set_order($order);
839
+				// add instantiated reg step object to the master reg steps array
840
+				$this->checkout->add_reg_step($reg_step_obj);
841
+			} else {
842
+				EE_Error::add_error(
843
+					__('The current step could not be set.', 'event_espresso'),
844
+					__FILE__, __FUNCTION__, __LINE__
845
+				);
846
+				return false;
847
+			}
848
+		} else {
849
+			if (WP_DEBUG) {
850
+				EE_Error::add_error(
851
+					sprintf(
852
+						__(
853
+							'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',
854
+							'event_espresso'
855
+						),
856
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
857
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
858
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
859
+						'<ul>',
860
+						'<li>',
861
+						'</li>',
862
+						'</ul>'
863
+					),
864
+					__FILE__, __FUNCTION__, __LINE__
865
+				);
866
+			}
867
+			return false;
868
+		}
869
+		return true;
870
+	}
871
+
872
+
873
+	/**
874
+	 * _verify_transaction_and_get_registrations
875
+	 *
876
+	 * @access private
877
+	 * @return bool
878
+	 * @throws InvalidDataTypeException
879
+	 * @throws InvalidEntityException
880
+	 * @throws EE_Error
881
+	 */
882
+	private function _verify_transaction_and_get_registrations()
883
+	{
884
+		// was there already a valid transaction in the checkout from the session ?
885
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
886
+			// get transaction from db or session
887
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
888
+				? $this->_get_transaction_and_cart_for_previous_visit()
889
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
890
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
891
+				EE_Error::add_error(
892
+					__('Your Registration and Transaction information could not be retrieved from the db.',
893
+						'event_espresso'),
894
+					__FILE__, __FUNCTION__, __LINE__
895
+				);
896
+				$this->checkout->transaction = EE_Transaction::new_instance();
897
+				// add some style and make it dance
898
+				$this->add_styles_and_scripts();
899
+				EED_Single_Page_Checkout::$_initialized = true;
900
+				return false;
901
+			}
902
+			// and the registrations for the transaction
903
+			$this->_get_registrations($this->checkout->transaction);
904
+		}
905
+		return true;
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * _get_transaction_and_cart_for_previous_visit
912
+	 *
913
+	 * @access private
914
+	 * @return mixed EE_Transaction|NULL
915
+	 */
916
+	private function _get_transaction_and_cart_for_previous_visit()
917
+	{
918
+		/** @var $TXN_model EEM_Transaction */
919
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
920
+		// because the reg_url_link is present in the request,
921
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
922
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
923
+		// verify transaction
924
+		if ($transaction instanceof EE_Transaction) {
925
+			// and get the cart that was used for that transaction
926
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
927
+			return $transaction;
928
+		}
929
+		EE_Error::add_error(
930
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
931
+			__FILE__, __FUNCTION__, __LINE__
932
+		);
933
+		return null;
934
+
935
+	}
936
+
937
+
938
+
939
+	/**
940
+	 * _get_cart_for_transaction
941
+	 *
942
+	 * @access private
943
+	 * @param EE_Transaction $transaction
944
+	 * @return EE_Cart
945
+	 */
946
+	private function _get_cart_for_transaction($transaction)
947
+	{
948
+		return $this->checkout->get_cart_for_transaction($transaction);
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * get_cart_for_transaction
955
+	 *
956
+	 * @access public
957
+	 * @param EE_Transaction $transaction
958
+	 * @return EE_Cart
959
+	 */
960
+	public function get_cart_for_transaction(EE_Transaction $transaction)
961
+	{
962
+		return $this->checkout->get_cart_for_transaction($transaction);
963
+	}
964
+
965
+
966
+
967
+	/**
968
+	 * _get_transaction_and_cart_for_current_session
969
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
970
+	 *
971
+	 * @access private
972
+	 * @return EE_Transaction
973
+	 * @throws EE_Error
974
+	 */
975
+	private function _get_cart_for_current_session_and_setup_new_transaction()
976
+	{
977
+		//  if there's no transaction, then this is the FIRST visit to SPCO
978
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
979
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
980
+		// and then create a new transaction
981
+		$transaction = $this->_initialize_transaction();
982
+		// verify transaction
983
+		if ($transaction instanceof EE_Transaction) {
984
+			// save it so that we have an ID for other objects to use
985
+			$transaction->save();
986
+			// and save TXN data to the cart
987
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
988
+		} else {
989
+			EE_Error::add_error(
990
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
991
+				__FILE__, __FUNCTION__, __LINE__
992
+			);
993
+		}
994
+		return $transaction;
995
+	}
996
+
997
+
998
+
999
+	/**
1000
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
1001
+	 *
1002
+	 * @access private
1003
+	 * @return mixed EE_Transaction|NULL
1004
+	 */
1005
+	private function _initialize_transaction()
1006
+	{
1007
+		try {
1008
+			// ensure cart totals have been calculated
1009
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
1010
+			// grab the cart grand total
1011
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1012
+			// create new TXN
1013
+			$transaction = EE_Transaction::new_instance(
1014
+				array(
1015
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1016
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1017
+					'TXN_paid'      => 0,
1018
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1019
+				)
1020
+			);
1021
+			// save it so that we have an ID for other objects to use
1022
+			$transaction->save();
1023
+			// set cron job for following up on TXNs after their session has expired
1024
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1025
+				EE_Registry::instance()->SSN->expiration() + 1,
1026
+				$transaction->ID()
1027
+			);
1028
+			return $transaction;
1029
+		} catch (Exception $e) {
1030
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1031
+		}
1032
+		return null;
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * _get_registrations
1038
+	 *
1039
+	 * @access private
1040
+	 * @param EE_Transaction $transaction
1041
+	 * @return void
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidEntityException
1044
+	 * @throws EE_Error
1045
+	 */
1046
+	private function _get_registrations(EE_Transaction $transaction)
1047
+	{
1048
+		// first step: grab the registrants  { : o
1049
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1050
+		$this->checkout->total_ticket_count = count($registrations);
1051
+		// verify registrations have been set
1052
+		if (empty($registrations)) {
1053
+			// if no cached registrations, then check the db
1054
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1055
+			// still nothing ? well as long as this isn't a revisit
1056
+			if (empty($registrations) && ! $this->checkout->revisit) {
1057
+				// generate new registrations from scratch
1058
+				$registrations = $this->_initialize_registrations($transaction);
1059
+			}
1060
+		}
1061
+		// sort by their original registration order
1062
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1063
+		// then loop thru the array
1064
+		foreach ($registrations as $registration) {
1065
+			// verify each registration
1066
+			if ($registration instanceof EE_Registration) {
1067
+				// we display all attendee info for the primary registrant
1068
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1069
+					&& $registration->is_primary_registrant()
1070
+				) {
1071
+					$this->checkout->primary_revisit = true;
1072
+					break;
1073
+				}
1074
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1075
+					// but hide info if it doesn't belong to you
1076
+					$transaction->clear_cache('Registration', $registration->ID());
1077
+					$this->checkout->total_ticket_count--;
1078
+				}
1079
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1080
+			}
1081
+		}
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1087
+	 *
1088
+	 * @access private
1089
+	 * @param EE_Transaction $transaction
1090
+	 * @return    array
1091
+	 * @throws InvalidDataTypeException
1092
+	 * @throws InvalidEntityException
1093
+	 * @throws EE_Error
1094
+	 */
1095
+	private function _initialize_registrations(EE_Transaction $transaction)
1096
+	{
1097
+		$att_nmbr = 0;
1098
+		$registrations = array();
1099
+		if ($transaction instanceof EE_Transaction) {
1100
+			/** @type EE_Registration_Processor $registration_processor */
1101
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1102
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1103
+			// now let's add the cart items to the $transaction
1104
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1105
+				//do the following for each ticket of this type they selected
1106
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1107
+					$att_nmbr++;
1108
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1109
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1110
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1111
+						array(
1112
+							$transaction,
1113
+							$line_item,
1114
+							$att_nmbr,
1115
+							$this->checkout->total_ticket_count,
1116
+						)
1117
+					);
1118
+					// override capabilities for frontend registrations
1119
+					if ( ! is_admin()) {
1120
+						$CreateRegistrationCommand->setCapCheck(
1121
+							new PublicCapabilities('', 'create_new_registration')
1122
+						);
1123
+					}
1124
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1125
+					if ( ! $registration instanceof EE_Registration) {
1126
+						throw new InvalidEntityException($registration, 'EE_Registration');
1127
+					}
1128
+					$registrations[ $registration->ID() ] = $registration;
1129
+				}
1130
+			}
1131
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1132
+		}
1133
+		return $registrations;
1134
+	}
1135
+
1136
+
1137
+
1138
+	/**
1139
+	 * sorts registrations by REG_count
1140
+	 *
1141
+	 * @access public
1142
+	 * @param EE_Registration $reg_A
1143
+	 * @param EE_Registration $reg_B
1144
+	 * @return int
1145
+	 */
1146
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1147
+	{
1148
+		// this shouldn't ever happen within the same TXN, but oh well
1149
+		if ($reg_A->count() === $reg_B->count()) {
1150
+			return 0;
1151
+		}
1152
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 *    _final_verifications
1159
+	 * just makes sure that everything is set up correctly before proceeding
1160
+	 *
1161
+	 * @access    private
1162
+	 * @return    bool
1163
+	 * @throws EE_Error
1164
+	 */
1165
+	private function _final_verifications()
1166
+	{
1167
+		// filter checkout
1168
+		$this->checkout = apply_filters(
1169
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1170
+			$this->checkout
1171
+		);
1172
+		//verify that current step is still set correctly
1173
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1174
+			EE_Error::add_error(
1175
+				__('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'),
1176
+				__FILE__,
1177
+				__FUNCTION__,
1178
+				__LINE__
1179
+			);
1180
+			return false;
1181
+		}
1182
+		// if returning to SPCO, then verify that primary registrant is set
1183
+		if ( ! empty($this->checkout->reg_url_link)) {
1184
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1185
+			if ( ! $valid_registrant instanceof EE_Registration) {
1186
+				EE_Error::add_error(
1187
+					__('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'),
1188
+					__FILE__,
1189
+					__FUNCTION__,
1190
+					__LINE__
1191
+				);
1192
+				return false;
1193
+			}
1194
+			$valid_registrant = null;
1195
+			foreach (
1196
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1197
+			) {
1198
+				if (
1199
+					$registration instanceof EE_Registration
1200
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1201
+				) {
1202
+					$valid_registrant = $registration;
1203
+				}
1204
+			}
1205
+			if ( ! $valid_registrant instanceof EE_Registration) {
1206
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1207
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1208
+					// clear the session, mark the checkout as unverified, and try again
1209
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1210
+					EED_Single_Page_Checkout::$_initialized = false;
1211
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1212
+					$this->_initialize();
1213
+					EE_Error::reset_notices();
1214
+					return false;
1215
+				}
1216
+				EE_Error::add_error(
1217
+					__(
1218
+						'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.',
1219
+						'event_espresso'
1220
+					),
1221
+					__FILE__,
1222
+					__FUNCTION__,
1223
+					__LINE__
1224
+				);
1225
+				return false;
1226
+			}
1227
+		}
1228
+		// now that things have been kinda sufficiently verified,
1229
+		// let's add the checkout to the session so that it's available to other systems
1230
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1231
+		return true;
1232
+	}
1233
+
1234
+
1235
+
1236
+	/**
1237
+	 *    _initialize_reg_steps
1238
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1239
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1240
+	 *
1241
+	 * @access    private
1242
+	 * @param bool $reinitializing
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	private function _initialize_reg_steps($reinitializing = false)
1246
+	{
1247
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1248
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1249
+		foreach ($this->checkout->reg_steps as $reg_step) {
1250
+			if ( ! $reg_step->initialize_reg_step()) {
1251
+				// if not initialized then maybe this step is being removed...
1252
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1253
+					// if it was the current step, then we need to start over here
1254
+					$this->_initialize_reg_steps(true);
1255
+					return;
1256
+				}
1257
+				continue;
1258
+			}
1259
+			// add css and JS for current step
1260
+			$reg_step->enqueue_styles_and_scripts();
1261
+			// i18n
1262
+			$reg_step->translate_js_strings();
1263
+			if ($reg_step->is_current_step()) {
1264
+				// the text that appears on the reg step form submit button
1265
+				$reg_step->set_submit_button_text();
1266
+			}
1267
+		}
1268
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1269
+		do_action(
1270
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1271
+			$this->checkout->current_step
1272
+		);
1273
+	}
1274
+
1275
+
1276
+
1277
+	/**
1278
+	 * _check_form_submission
1279
+	 *
1280
+	 * @access private
1281
+	 * @return boolean
1282
+	 */
1283
+	private function _check_form_submission()
1284
+	{
1285
+		//does this request require the reg form to be generated ?
1286
+		if ($this->checkout->generate_reg_form) {
1287
+			// ever heard that song by Blue Rodeo ?
1288
+			try {
1289
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1290
+				// if not displaying a form, then check for form submission
1291
+				if (
1292
+					$this->checkout->process_form_submission
1293
+					&& $this->checkout->current_step->reg_form->was_submitted()
1294
+				) {
1295
+					// clear out any old data in case this step is being run again
1296
+					$this->checkout->current_step->set_valid_data(array());
1297
+					// capture submitted form data
1298
+					$this->checkout->current_step->reg_form->receive_form_submission(
1299
+						apply_filters(
1300
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1301
+							EE_Registry::instance()->REQ->params(),
1302
+							$this->checkout
1303
+						)
1304
+					);
1305
+					// validate submitted form data
1306
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1307
+						// thou shall not pass !!!
1308
+						$this->checkout->continue_reg = false;
1309
+						// any form validation errors?
1310
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1311
+							$submission_error_messages = array();
1312
+							// bad, bad, bad registrant
1313
+							foreach (
1314
+								$this->checkout->current_step->reg_form->get_validation_errors_accumulated()
1315
+								as $validation_error
1316
+							) {
1317
+								if ($validation_error instanceof EE_Validation_Error) {
1318
+									$submission_error_messages[] = sprintf(
1319
+										__('%s : %s', 'event_espresso'),
1320
+										$validation_error->get_form_section()->html_label_text(),
1321
+										$validation_error->getMessage()
1322
+									);
1323
+								}
1324
+							}
1325
+							EE_Error::add_error(
1326
+								implode('<br />', $submission_error_messages),
1327
+								__FILE__, __FUNCTION__, __LINE__
1328
+							);
1329
+						}
1330
+						// well not really... what will happen is
1331
+						// we'll just get redirected back to redo the current step
1332
+						$this->go_to_next_step();
1333
+						return false;
1334
+					}
1335
+				}
1336
+			} catch (EE_Error $e) {
1337
+				$e->get_error();
1338
+			}
1339
+		}
1340
+		return true;
1341
+	}
1342
+
1343
+
1344
+
1345
+	/**
1346
+	 * _process_action
1347
+	 *
1348
+	 * @access private
1349
+	 * @return void
1350
+	 * @throws EE_Error
1351
+	 */
1352
+	private function _process_form_action()
1353
+	{
1354
+		// what cha wanna do?
1355
+		switch ($this->checkout->action) {
1356
+			// AJAX next step reg form
1357
+			case 'display_spco_reg_step' :
1358
+				$this->checkout->redirect = false;
1359
+				if (EE_Registry::instance()->REQ->ajax) {
1360
+					$this->checkout->json_response->set_reg_step_html(
1361
+						$this->checkout->current_step->display_reg_form()
1362
+					);
1363
+				}
1364
+				break;
1365
+			default :
1366
+				// meh... do one of those other steps first
1367
+				if (
1368
+					! empty($this->checkout->action)
1369
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1370
+				) {
1371
+					// dynamically creates hook point like:
1372
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1373
+					do_action(
1374
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1375
+						$this->checkout->current_step
1376
+					);
1377
+					// call action on current step
1378
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1379
+						// good registrant, you get to proceed
1380
+						if (
1381
+							$this->checkout->current_step->success_message() !== ''
1382
+							&& apply_filters(
1383
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1384
+								false
1385
+							)
1386
+						) {
1387
+							EE_Error::add_success(
1388
+								$this->checkout->current_step->success_message()
1389
+								. '<br />' . $this->checkout->next_step->_instructions()
1390
+							);
1391
+						}
1392
+						// pack it up, pack it in...
1393
+						$this->_setup_redirect();
1394
+					}
1395
+					// dynamically creates hook point like:
1396
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1397
+					do_action(
1398
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1399
+						$this->checkout->current_step
1400
+					);
1401
+				} else {
1402
+					EE_Error::add_error(
1403
+						sprintf(
1404
+							__(
1405
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1406
+								'event_espresso'
1407
+							),
1408
+							$this->checkout->action,
1409
+							$this->checkout->current_step->name()
1410
+						),
1411
+						__FILE__,
1412
+						__FUNCTION__,
1413
+						__LINE__
1414
+					);
1415
+				}
1416
+			// end default
1417
+		}
1418
+		// store our progress so far
1419
+		$this->checkout->stash_transaction_and_checkout();
1420
+		// advance to the next step! If you pass GO, collect $200
1421
+		$this->go_to_next_step();
1422
+	}
1423
+
1424
+
1425
+
1426
+	/**
1427
+	 *        add_styles_and_scripts
1428
+	 *
1429
+	 * @access        public
1430
+	 * @return        void
1431
+	 */
1432
+	public function add_styles_and_scripts()
1433
+	{
1434
+		// i18n
1435
+		$this->translate_js_strings();
1436
+		if ($this->checkout->admin_request) {
1437
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1438
+		} else {
1439
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1440
+		}
1441
+	}
1442
+
1443
+
1444
+
1445
+	/**
1446
+	 *        translate_js_strings
1447
+	 *
1448
+	 * @access        public
1449
+	 * @return        void
1450
+	 */
1451
+	public function translate_js_strings()
1452
+	{
1453
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1454
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1455
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1456
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1457
+			'event_espresso'
1458
+		);
1459
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1460
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1461
+			'event_espresso'
1462
+		);
1463
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1464
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1465
+			'event_espresso'
1466
+		);
1467
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1468
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1469
+			'event_espresso'
1470
+		);
1471
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1472
+			'This registration step could not be completed. Please refresh the page and try again.',
1473
+			'event_espresso'
1474
+		);
1475
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1476
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1477
+			'event_espresso'
1478
+		);
1479
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1480
+			__(
1481
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1482
+				'event_espresso'
1483
+			),
1484
+			'<br/>',
1485
+			'<br/>'
1486
+		);
1487
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1488
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1489
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1490
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1491
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1492
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1493
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1494
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1495
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1496
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1497
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1498
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1499
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1500
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1501
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1502
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1503
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1504
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1505
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1506
+			__(
1507
+				'%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',
1508
+				'event_espresso'
1509
+			),
1510
+			'<h4 class="important-notice">',
1511
+			'</h4>',
1512
+			'<br />',
1513
+			'<p>',
1514
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1515
+			'">',
1516
+			'</a>',
1517
+			'</p>'
1518
+		);
1519
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1520
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1521
+			true
1522
+		);
1523
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1524
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1525
+		);
1526
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1527
+			'M d, Y H:i:s',
1528
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1529
+		);
1530
+	}
1531
+
1532
+
1533
+
1534
+	/**
1535
+	 *    enqueue_styles_and_scripts
1536
+	 *
1537
+	 * @access        public
1538
+	 * @return        void
1539
+	 * @throws EE_Error
1540
+	 */
1541
+	public function enqueue_styles_and_scripts()
1542
+	{
1543
+		// load css
1544
+		wp_register_style(
1545
+			'single_page_checkout',
1546
+			SPCO_CSS_URL . 'single_page_checkout.css',
1547
+			array('espresso_default'),
1548
+			EVENT_ESPRESSO_VERSION
1549
+		);
1550
+		wp_enqueue_style('single_page_checkout');
1551
+		// load JS
1552
+		wp_register_script(
1553
+			'jquery_plugin',
1554
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1555
+			array('jquery'),
1556
+			'1.0.1',
1557
+			true
1558
+		);
1559
+		wp_register_script(
1560
+			'jquery_countdown',
1561
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1562
+			array('jquery_plugin'),
1563
+			'2.0.2',
1564
+			true
1565
+		);
1566
+		wp_register_script(
1567
+			'single_page_checkout',
1568
+			SPCO_JS_URL . 'single_page_checkout.js',
1569
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1570
+			EVENT_ESPRESSO_VERSION,
1571
+			true
1572
+		);
1573
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1574
+			$this->checkout->registration_form->enqueue_js();
1575
+		}
1576
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1577
+			$this->checkout->current_step->reg_form->enqueue_js();
1578
+		}
1579
+		wp_enqueue_script('single_page_checkout');
1580
+		/**
1581
+		 * global action hook for enqueueing styles and scripts with
1582
+		 * spco calls.
1583
+		 */
1584
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1585
+		/**
1586
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1587
+		 * The hook will end up being something like:
1588
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1589
+		 */
1590
+		do_action(
1591
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1592
+			$this
1593
+		);
1594
+	}
1595
+
1596
+
1597
+
1598
+	/**
1599
+	 *    display the Registration Single Page Checkout Form
1600
+	 *
1601
+	 * @access    private
1602
+	 * @return    void
1603
+	 * @throws EE_Error
1604
+	 */
1605
+	private function _display_spco_reg_form()
1606
+	{
1607
+		// if registering via the admin, just display the reg form for the current step
1608
+		if ($this->checkout->admin_request) {
1609
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1610
+		} else {
1611
+			// add powered by EE msg
1612
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1613
+			$empty_cart = count(
1614
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1615
+			) < 1;
1616
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1617
+			$cookies_not_set_msg = '';
1618
+			if ($empty_cart) {
1619
+				$cookies_not_set_msg = apply_filters(
1620
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1621
+					sprintf(
1622
+						__(
1623
+							'%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',
1624
+							'event_espresso'
1625
+						),
1626
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1627
+						'</div>',
1628
+						'<h6 class="important-notice">',
1629
+						'</h6>',
1630
+						'<p>',
1631
+						'</p>',
1632
+						'<br />',
1633
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1634
+						'</a>'
1635
+					)
1636
+				);
1637
+			}
1638
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1639
+				array(
1640
+					'name'            => 'single-page-checkout',
1641
+					'html_id'         => 'ee-single-page-checkout-dv',
1642
+					'layout_strategy' =>
1643
+						new EE_Template_Layout(
1644
+							array(
1645
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1646
+								'template_args'        => array(
1647
+									'empty_cart'              => $empty_cart,
1648
+									'revisit'                 => $this->checkout->revisit,
1649
+									'reg_steps'               => $this->checkout->reg_steps,
1650
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1651
+										? $this->checkout->next_step->slug()
1652
+										: '',
1653
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1654
+									'empty_msg'               => apply_filters(
1655
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1656
+										sprintf(
1657
+											__(
1658
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1659
+												'event_espresso'
1660
+											),
1661
+											'<a href="'
1662
+											. get_post_type_archive_link('espresso_events')
1663
+											. '" title="',
1664
+											'">',
1665
+											'</a>'
1666
+										)
1667
+									),
1668
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1669
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1670
+									'session_expiration'      => gmdate(
1671
+										'M d, Y H:i:s',
1672
+										EE_Registry::instance()->SSN->expiration()
1673
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1674
+									),
1675
+								),
1676
+							)
1677
+						),
1678
+				)
1679
+			);
1680
+			// load template and add to output sent that gets filtered into the_content()
1681
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1682
+		}
1683
+	}
1684
+
1685
+
1686
+
1687
+	/**
1688
+	 *    add_extra_finalize_registration_inputs
1689
+	 *
1690
+	 * @access    public
1691
+	 * @param $next_step
1692
+	 * @internal  param string $label
1693
+	 * @return void
1694
+	 */
1695
+	public function add_extra_finalize_registration_inputs($next_step)
1696
+	{
1697
+		if ($next_step === 'finalize_registration') {
1698
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1699
+		}
1700
+	}
1701
+
1702
+
1703
+
1704
+	/**
1705
+	 *    display_registration_footer
1706
+	 *
1707
+	 * @access    public
1708
+	 * @return    string
1709
+	 */
1710
+	public static function display_registration_footer()
1711
+	{
1712
+		if (
1713
+		apply_filters(
1714
+			'FHEE__EE_Front__Controller__show_reg_footer',
1715
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1716
+		)
1717
+		) {
1718
+			add_filter(
1719
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1720
+				function ($url) {
1721
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1722
+				}
1723
+			);
1724
+			echo apply_filters(
1725
+				'FHEE__EE_Front_Controller__display_registration_footer',
1726
+				\EEH_Template::powered_by_event_espresso(
1727
+					'',
1728
+					'espresso-registration-footer-dv',
1729
+					array('utm_content' => 'registration_checkout')
1730
+				)
1731
+			);
1732
+		}
1733
+		return '';
1734
+	}
1735
+
1736
+
1737
+
1738
+	/**
1739
+	 *    unlock_transaction
1740
+	 *
1741
+	 * @access    public
1742
+	 * @return    void
1743
+	 * @throws EE_Error
1744
+	 */
1745
+	public function unlock_transaction()
1746
+	{
1747
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1748
+			$this->checkout->transaction->unlock();
1749
+		}
1750
+	}
1751
+
1752
+
1753
+
1754
+	/**
1755
+	 *        _setup_redirect
1756
+	 *
1757
+	 * @access    private
1758
+	 * @return void
1759
+	 */
1760
+	private function _setup_redirect()
1761
+	{
1762
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1763
+			$this->checkout->redirect = true;
1764
+			if (empty($this->checkout->redirect_url)) {
1765
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1766
+			}
1767
+			$this->checkout->redirect_url = apply_filters(
1768
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1769
+				$this->checkout->redirect_url,
1770
+				$this->checkout
1771
+			);
1772
+		}
1773
+	}
1774
+
1775
+
1776
+
1777
+	/**
1778
+	 *   handle ajax message responses and redirects
1779
+	 *
1780
+	 * @access public
1781
+	 * @return void
1782
+	 * @throws EE_Error
1783
+	 */
1784
+	public function go_to_next_step()
1785
+	{
1786
+		if (EE_Registry::instance()->REQ->ajax) {
1787
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1788
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1789
+		}
1790
+		$this->unlock_transaction();
1791
+		// just return for these conditions
1792
+		if (
1793
+			$this->checkout->admin_request
1794
+			|| $this->checkout->action === 'redirect_form'
1795
+			|| $this->checkout->action === 'update_checkout'
1796
+		) {
1797
+			return;
1798
+		}
1799
+		// AJAX response
1800
+		$this->_handle_json_response();
1801
+		// redirect to next step or the Thank You page
1802
+		$this->_handle_html_redirects();
1803
+		// hmmm... must be something wrong, so let's just display the form again !
1804
+		$this->_display_spco_reg_form();
1805
+	}
1806
+
1807
+
1808
+
1809
+	/**
1810
+	 *   _handle_json_response
1811
+	 *
1812
+	 * @access protected
1813
+	 * @return void
1814
+	 */
1815
+	protected function _handle_json_response()
1816
+	{
1817
+		// if this is an ajax request
1818
+		if (EE_Registry::instance()->REQ->ajax) {
1819
+			// DEBUG LOG
1820
+			//$this->checkout->log(
1821
+			//	__CLASS__, __FUNCTION__, __LINE__,
1822
+			//	array(
1823
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1824
+			//		'redirect'                   => $this->checkout->redirect,
1825
+			//		'continue_reg'               => $this->checkout->continue_reg,
1826
+			//	)
1827
+			//);
1828
+			$this->checkout->json_response->set_registration_time_limit(
1829
+				$this->checkout->get_registration_time_limit()
1830
+			);
1831
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1832
+			// just send the ajax (
1833
+			$json_response = apply_filters(
1834
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1835
+				$this->checkout->json_response
1836
+			);
1837
+			echo $json_response;
1838
+			exit();
1839
+		}
1840
+	}
1841
+
1842
+
1843
+
1844
+	/**
1845
+	 *   _handle_redirects
1846
+	 *
1847
+	 * @access protected
1848
+	 * @return void
1849
+	 */
1850
+	protected function _handle_html_redirects()
1851
+	{
1852
+		// going somewhere ?
1853
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1854
+			// store notices in a transient
1855
+			EE_Error::get_notices(false, true, true);
1856
+			// DEBUG LOG
1857
+			//$this->checkout->log(
1858
+			//	__CLASS__, __FUNCTION__, __LINE__,
1859
+			//	array(
1860
+			//		'headers_sent' => headers_sent(),
1861
+			//		'redirect_url'     => $this->checkout->redirect_url,
1862
+			//		'headers_list'    => headers_list(),
1863
+			//	)
1864
+			//);
1865
+			wp_safe_redirect($this->checkout->redirect_url);
1866
+			exit();
1867
+		}
1868
+	}
1869
+
1870
+
1871
+
1872
+	/**
1873
+	 *   set_checkout_anchor
1874
+	 *
1875
+	 * @access public
1876
+	 * @return void
1877
+	 */
1878
+	public function set_checkout_anchor()
1879
+	{
1880
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1881
+	}
1882 1882
 
1883 1883
 
1884 1884
 
Please login to merge, or discard this patch.