Completed
Branch BUG/escape-localized-variables (1bfc63)
by
unknown
10:49 queued 01:26
created
core/services/request/RequestInterface.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -16,146 +16,146 @@
 block discarded – undo
16 16
 interface RequestInterface extends RequestTypeContextCheckerInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @param RequestTypeContextCheckerInterface $type
21
-     */
22
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
-
24
-    /**
25
-     * @return array
26
-     */
27
-    public function getParams();
28
-
29
-
30
-    /**
31
-     * @return array
32
-     */
33
-    public function postParams();
34
-
35
-
36
-    /**
37
-     * @return array
38
-     */
39
-    public function cookieParams();
40
-
41
-
42
-    /**
43
-     * @return array
44
-     */
45
-    public function serverParams();
46
-
47
-
48
-    /**
49
-     * @return array
50
-     */
51
-    public function filesParams();
19
+	/**
20
+	 * @param RequestTypeContextCheckerInterface $type
21
+	 */
22
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
+
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function getParams();
28
+
29
+
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function postParams();
34
+
35
+
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function cookieParams();
40
+
41
+
42
+	/**
43
+	 * @return array
44
+	 */
45
+	public function serverParams();
46
+
47
+
48
+	/**
49
+	 * @return array
50
+	 */
51
+	public function filesParams();
52 52
 
53 53
 
54
-    /**
55
-     * returns contents of $_REQUEST
56
-     *
57
-     * @return array
58
-     */
59
-    public function requestParams();
54
+	/**
55
+	 * returns contents of $_REQUEST
56
+	 *
57
+	 * @return array
58
+	 */
59
+	public function requestParams();
60 60
 
61 61
 
62
-    /**
63
-     * @param string $key
64
-     * @param string $value
65
-     * @param bool   $override_ee
66
-     * @return    void
67
-     */
68
-    public function setRequestParam($key, $value, $override_ee = false);
62
+	/**
63
+	 * @param string $key
64
+	 * @param string $value
65
+	 * @param bool   $override_ee
66
+	 * @return    void
67
+	 */
68
+	public function setRequestParam($key, $value, $override_ee = false);
69 69
 
70 70
 
71
-    /**
72
-     * returns the value for a request param if the given key exists
73
-     *
74
-     * @param string $key
75
-     * @param null   $default
76
-     * @return mixed
77
-     */
78
-    public function getRequestParam($key, $default = null);
71
+	/**
72
+	 * returns the value for a request param if the given key exists
73
+	 *
74
+	 * @param string $key
75
+	 * @param null   $default
76
+	 * @return mixed
77
+	 */
78
+	public function getRequestParam($key, $default = null);
79 79
 
80 80
 
81
-    /**
82
-     * check if param exists
83
-     *
84
-     * @param string $key
85
-     * @return bool
86
-     */
87
-    public function requestParamIsSet($key);
81
+	/**
82
+	 * check if param exists
83
+	 *
84
+	 * @param string $key
85
+	 * @return bool
86
+	 */
87
+	public function requestParamIsSet($key);
88 88
 
89 89
 
90
-    /**
91
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
92
-     * and return the value for the first match found
93
-     * wildcards can be either of the following:
94
-     *      ? to represent a single character of any type
95
-     *      * to represent one or more characters of any type
96
-     *
97
-     * @param string     $pattern
98
-     * @param null|mixed $default
99
-     * @return false|int
100
-     */
101
-    public function getMatch($pattern, $default = null);
90
+	/**
91
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
92
+	 * and return the value for the first match found
93
+	 * wildcards can be either of the following:
94
+	 *      ? to represent a single character of any type
95
+	 *      * to represent one or more characters of any type
96
+	 *
97
+	 * @param string     $pattern
98
+	 * @param null|mixed $default
99
+	 * @return false|int
100
+	 */
101
+	public function getMatch($pattern, $default = null);
102 102
 
103 103
 
104
-    /**
105
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
106
-     * wildcards can be either of the following:
107
-     *      ? to represent a single character of any type
108
-     *      * to represent one or more characters of any type
109
-     * returns true if a match is found or false if not
110
-     *
111
-     * @param string $pattern
112
-     * @return false|int
113
-     */
114
-    public function matches($pattern);
104
+	/**
105
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
106
+	 * wildcards can be either of the following:
107
+	 *      ? to represent a single character of any type
108
+	 *      * to represent one or more characters of any type
109
+	 * returns true if a match is found or false if not
110
+	 *
111
+	 * @param string $pattern
112
+	 * @return false|int
113
+	 */
114
+	public function matches($pattern);
115 115
 
116 116
 
117
-    /**
118
-     * remove param
119
-     *
120
-     * @param string $key
121
-     * @param bool   $unset_from_global_too
122
-     */
123
-    public function unSetRequestParam($key, $unset_from_global_too = false);
117
+	/**
118
+	 * remove param
119
+	 *
120
+	 * @param string $key
121
+	 * @param bool   $unset_from_global_too
122
+	 */
123
+	public function unSetRequestParam($key, $unset_from_global_too = false);
124 124
 
125 125
 
126
-    /**
127
-     * @return string
128
-     */
129
-    public function ipAddress();
126
+	/**
127
+	 * @return string
128
+	 */
129
+	public function ipAddress();
130 130
 
131 131
 
132
-    /**
133
-     * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
134
-     * @return string
135
-     */
136
-    public function requestUri($relativeToWpRoot = false);
137
-
132
+	/**
133
+	 * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
134
+	 * @return string
135
+	 */
136
+	public function requestUri($relativeToWpRoot = false);
137
+
138 138
 
139
-    /**
140
-     * @return string
141
-     */
142
-    public function userAgent();
143
-
144
-
145
-    /**
146
-     * @param string $user_agent
147
-     */
148
-    public function setUserAgent($user_agent = '');
149
-
150
-
151
-    /**
152
-     * @return bool
153
-     */
154
-    public function isBot();
155
-
156
-
157
-    /**
158
-     * @param bool $is_bot
159
-     */
160
-    public function setIsBot($is_bot);
139
+	/**
140
+	 * @return string
141
+	 */
142
+	public function userAgent();
143
+
144
+
145
+	/**
146
+	 * @param string $user_agent
147
+	 */
148
+	public function setUserAgent($user_agent = '');
149
+
150
+
151
+	/**
152
+	 * @return bool
153
+	 */
154
+	public function isBot();
155
+
156
+
157
+	/**
158
+	 * @param bool $is_bot
159
+	 */
160
+	public function setIsBot($is_bot);
161 161
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 1 patch
Indentation   +1353 added lines, -1353 removed lines patch added patch discarded remove patch
@@ -13,1357 +13,1357 @@
 block discarded – undo
13 13
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
14 14
 {
15 15
 
16
-    /**
17
-     * cached value for the the logical active status for the event
18
-     *
19
-     * @see get_active_status()
20
-     * @var string
21
-     */
22
-    protected $_active_status = '';
23
-
24
-    /**
25
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
26
-     *
27
-     * @var EE_Datetime
28
-     */
29
-    protected $_Primary_Datetime;
30
-
31
-    /**
32
-     * @var EventSpacesCalculator $available_spaces_calculator
33
-     */
34
-    protected $available_spaces_calculator;
35
-
36
-
37
-    /**
38
-     * @param array  $props_n_values          incoming values
39
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
40
-     *                                        used.)
41
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
42
-     *                                        date_format and the second value is the time format
43
-     * @return EE_Event
44
-     * @throws EE_Error
45
-     */
46
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
47
-    {
48
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
49
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
50
-    }
51
-
52
-
53
-    /**
54
-     * @param array  $props_n_values  incoming values from the database
55
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
56
-     *                                the website will be used.
57
-     * @return EE_Event
58
-     * @throws EE_Error
59
-     */
60
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
61
-    {
62
-        return new self($props_n_values, true, $timezone);
63
-    }
64
-
65
-
66
-    /**
67
-     * @return EventSpacesCalculator
68
-     * @throws \EE_Error
69
-     */
70
-    public function getAvailableSpacesCalculator()
71
-    {
72
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
73
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
74
-        }
75
-        return $this->available_spaces_calculator;
76
-    }
77
-
78
-
79
-    /**
80
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
81
-     *
82
-     * @param string $field_name
83
-     * @param mixed  $field_value
84
-     * @param bool   $use_default
85
-     * @throws EE_Error
86
-     */
87
-    public function set($field_name, $field_value, $use_default = false)
88
-    {
89
-        switch ($field_name) {
90
-            case 'status':
91
-                $this->set_status($field_value, $use_default);
92
-                break;
93
-            default:
94
-                parent::set($field_name, $field_value, $use_default);
95
-        }
96
-    }
97
-
98
-
99
-    /**
100
-     *    set_status
101
-     * Checks if event status is being changed to SOLD OUT
102
-     * and updates event meta data with previous event status
103
-     * so that we can revert things if/when the event is no longer sold out
104
-     *
105
-     * @access public
106
-     * @param string $new_status
107
-     * @param bool   $use_default
108
-     * @return void
109
-     * @throws EE_Error
110
-     */
111
-    public function set_status($new_status = null, $use_default = false)
112
-    {
113
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
114
-        if (empty($new_status) && ! $use_default) {
115
-            return;
116
-        }
117
-        // get current Event status
118
-        $old_status = $this->status();
119
-        // if status has changed
120
-        if ($old_status !== $new_status) {
121
-            // TO sold_out
122
-            if ($new_status === EEM_Event::sold_out) {
123
-                // save the previous event status so that we can revert if the event is no longer sold out
124
-                $this->add_post_meta('_previous_event_status', $old_status);
125
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
126
-                // OR FROM  sold_out
127
-            } elseif ($old_status === EEM_Event::sold_out) {
128
-                $this->delete_post_meta('_previous_event_status');
129
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
130
-            }
131
-            // clear out the active status so that it gets reset the next time it is requested
132
-            $this->_active_status = null;
133
-            // update status
134
-            parent::set('status', $new_status, $use_default);
135
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
136
-            return;
137
-        }
138
-        // even though the old value matches the new value, it's still good to
139
-        // allow the parent set method to have a say
140
-        parent::set('status', $new_status, $use_default);
141
-    }
142
-
143
-
144
-    /**
145
-     * Gets all the datetimes for this event
146
-     *
147
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
148
-     * @return EE_Base_Class[]|EE_Datetime[]
149
-     * @throws EE_Error
150
-     */
151
-    public function datetimes($query_params = array())
152
-    {
153
-        return $this->get_many_related('Datetime', $query_params);
154
-    }
155
-
156
-
157
-    /**
158
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
159
-     *
160
-     * @return EE_Base_Class[]|EE_Datetime[]
161
-     * @throws EE_Error
162
-     */
163
-    public function datetimes_in_chronological_order()
164
-    {
165
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
166
-    }
167
-
168
-
169
-    /**
170
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
171
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
172
-     * after running our query, so that this timezone isn't set for EVERY query
173
-     * on EEM_Datetime for the rest of the request, no?
174
-     *
175
-     * @param boolean $show_expired whether or not to include expired events
176
-     * @param boolean $show_deleted whether or not to include deleted events
177
-     * @param null    $limit
178
-     * @return EE_Datetime[]
179
-     * @throws EE_Error
180
-     */
181
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
182
-    {
183
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
184
-            $this->ID(),
185
-            $show_expired,
186
-            $show_deleted,
187
-            $limit
188
-        );
189
-    }
190
-
191
-
192
-    /**
193
-     * Returns one related datetime. Mostly only used by some legacy code.
194
-     *
195
-     * @return EE_Base_Class|EE_Datetime
196
-     * @throws EE_Error
197
-     */
198
-    public function first_datetime()
199
-    {
200
-        return $this->get_first_related('Datetime');
201
-    }
202
-
203
-
204
-    /**
205
-     * Returns the 'primary' datetime for the event
206
-     *
207
-     * @param bool $try_to_exclude_expired
208
-     * @param bool $try_to_exclude_deleted
209
-     * @return EE_Datetime
210
-     * @throws EE_Error
211
-     */
212
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
213
-    {
214
-        if (! empty($this->_Primary_Datetime)) {
215
-            return $this->_Primary_Datetime;
216
-        }
217
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
218
-            $this->ID(),
219
-            $try_to_exclude_expired,
220
-            $try_to_exclude_deleted
221
-        );
222
-        return $this->_Primary_Datetime;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets all the tickets available for purchase of this event
228
-     *
229
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
230
-     * @return EE_Base_Class[]|EE_Ticket[]
231
-     * @throws EE_Error
232
-     */
233
-    public function tickets($query_params = array())
234
-    {
235
-        // first get all datetimes
236
-        $datetimes = $this->datetimes_ordered();
237
-        if (! $datetimes) {
238
-            return array();
239
-        }
240
-        $datetime_ids = array();
241
-        foreach ($datetimes as $datetime) {
242
-            $datetime_ids[] = $datetime->ID();
243
-        }
244
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
245
-        // if incoming $query_params has where conditions let's merge but not override existing.
246
-        if (is_array($query_params) && isset($query_params[0])) {
247
-            $where_params = array_merge($query_params[0], $where_params);
248
-            unset($query_params[0]);
249
-        }
250
-        // now add $where_params to $query_params
251
-        $query_params[0] = $where_params;
252
-        return EEM_Ticket::instance()->get_all($query_params);
253
-    }
254
-
255
-
256
-    /**
257
-     * get all unexpired untrashed tickets
258
-     *
259
-     * @return EE_Ticket[]
260
-     * @throws EE_Error
261
-     */
262
-    public function active_tickets()
263
-    {
264
-        return $this->tickets(
265
-            array(
266
-                array(
267
-                    'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
268
-                    'TKT_deleted'  => false,
269
-                ),
270
-            )
271
-        );
272
-    }
273
-
274
-
275
-    /**
276
-     * @return bool
277
-     * @throws EE_Error
278
-     */
279
-    public function additional_limit()
280
-    {
281
-        return $this->get('EVT_additional_limit');
282
-    }
283
-
284
-
285
-    /**
286
-     * @return bool
287
-     * @throws EE_Error
288
-     */
289
-    public function allow_overflow()
290
-    {
291
-        return $this->get('EVT_allow_overflow');
292
-    }
293
-
294
-
295
-    /**
296
-     * @return bool
297
-     * @throws EE_Error
298
-     */
299
-    public function created()
300
-    {
301
-        return $this->get('EVT_created');
302
-    }
303
-
304
-
305
-    /**
306
-     * @return bool
307
-     * @throws EE_Error
308
-     */
309
-    public function description()
310
-    {
311
-        return $this->get('EVT_desc');
312
-    }
313
-
314
-
315
-    /**
316
-     * Runs do_shortcode and wpautop on the description
317
-     *
318
-     * @return string of html
319
-     * @throws EE_Error
320
-     */
321
-    public function description_filtered()
322
-    {
323
-        return $this->get_pretty('EVT_desc');
324
-    }
325
-
326
-
327
-    /**
328
-     * @return bool
329
-     * @throws EE_Error
330
-     */
331
-    public function display_description()
332
-    {
333
-        return $this->get('EVT_display_desc');
334
-    }
335
-
336
-
337
-    /**
338
-     * @return bool
339
-     * @throws EE_Error
340
-     */
341
-    public function display_ticket_selector()
342
-    {
343
-        return (bool) $this->get('EVT_display_ticket_selector');
344
-    }
345
-
346
-
347
-    /**
348
-     * @return bool
349
-     * @throws EE_Error
350
-     */
351
-    public function external_url()
352
-    {
353
-        return $this->get('EVT_external_URL');
354
-    }
355
-
356
-
357
-    /**
358
-     * @return bool
359
-     * @throws EE_Error
360
-     */
361
-    public function member_only()
362
-    {
363
-        return $this->get('EVT_member_only');
364
-    }
365
-
366
-
367
-    /**
368
-     * @return bool
369
-     * @throws EE_Error
370
-     */
371
-    public function phone()
372
-    {
373
-        return $this->get('EVT_phone');
374
-    }
375
-
376
-
377
-    /**
378
-     * @return bool
379
-     * @throws EE_Error
380
-     */
381
-    public function modified()
382
-    {
383
-        return $this->get('EVT_modified');
384
-    }
385
-
386
-
387
-    /**
388
-     * @return bool
389
-     * @throws EE_Error
390
-     */
391
-    public function name()
392
-    {
393
-        return $this->get('EVT_name');
394
-    }
395
-
396
-
397
-    /**
398
-     * @return bool
399
-     * @throws EE_Error
400
-     */
401
-    public function order()
402
-    {
403
-        return $this->get('EVT_order');
404
-    }
405
-
406
-
407
-    /**
408
-     * @return bool|string
409
-     * @throws EE_Error
410
-     */
411
-    public function default_registration_status()
412
-    {
413
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
414
-        return ! empty($event_default_registration_status)
415
-            ? $event_default_registration_status
416
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
417
-    }
418
-
419
-
420
-    /**
421
-     * @param int  $num_words
422
-     * @param null $more
423
-     * @param bool $not_full_desc
424
-     * @return bool|string
425
-     * @throws EE_Error
426
-     */
427
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
428
-    {
429
-        $short_desc = $this->get('EVT_short_desc');
430
-        if (! empty($short_desc) || $not_full_desc) {
431
-            return $short_desc;
432
-        }
433
-        $full_desc = $this->get('EVT_desc');
434
-        return wp_trim_words($full_desc, $num_words, $more);
435
-    }
436
-
437
-
438
-    /**
439
-     * @return bool
440
-     * @throws EE_Error
441
-     */
442
-    public function slug()
443
-    {
444
-        return $this->get('EVT_slug');
445
-    }
446
-
447
-
448
-    /**
449
-     * @return bool
450
-     * @throws EE_Error
451
-     */
452
-    public function timezone_string()
453
-    {
454
-        return $this->get('EVT_timezone_string');
455
-    }
456
-
457
-
458
-    /**
459
-     * @return bool
460
-     * @throws EE_Error
461
-     */
462
-    public function visible_on()
463
-    {
464
-        return $this->get('EVT_visible_on');
465
-    }
466
-
467
-
468
-    /**
469
-     * @return int
470
-     * @throws EE_Error
471
-     */
472
-    public function wp_user()
473
-    {
474
-        return $this->get('EVT_wp_user');
475
-    }
476
-
477
-
478
-    /**
479
-     * @return bool
480
-     * @throws EE_Error
481
-     */
482
-    public function donations()
483
-    {
484
-        return $this->get('EVT_donations');
485
-    }
486
-
487
-
488
-    /**
489
-     * @param $limit
490
-     * @throws EE_Error
491
-     */
492
-    public function set_additional_limit($limit)
493
-    {
494
-        $this->set('EVT_additional_limit', $limit);
495
-    }
496
-
497
-
498
-    /**
499
-     * @param $created
500
-     * @throws EE_Error
501
-     */
502
-    public function set_created($created)
503
-    {
504
-        $this->set('EVT_created', $created);
505
-    }
506
-
507
-
508
-    /**
509
-     * @param $desc
510
-     * @throws EE_Error
511
-     */
512
-    public function set_description($desc)
513
-    {
514
-        $this->set('EVT_desc', $desc);
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $display_desc
520
-     * @throws EE_Error
521
-     */
522
-    public function set_display_description($display_desc)
523
-    {
524
-        $this->set('EVT_display_desc', $display_desc);
525
-    }
526
-
527
-
528
-    /**
529
-     * @param $display_ticket_selector
530
-     * @throws EE_Error
531
-     */
532
-    public function set_display_ticket_selector($display_ticket_selector)
533
-    {
534
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
535
-    }
536
-
537
-
538
-    /**
539
-     * @param $external_url
540
-     * @throws EE_Error
541
-     */
542
-    public function set_external_url($external_url)
543
-    {
544
-        $this->set('EVT_external_URL', $external_url);
545
-    }
546
-
547
-
548
-    /**
549
-     * @param $member_only
550
-     * @throws EE_Error
551
-     */
552
-    public function set_member_only($member_only)
553
-    {
554
-        $this->set('EVT_member_only', $member_only);
555
-    }
556
-
557
-
558
-    /**
559
-     * @param $event_phone
560
-     * @throws EE_Error
561
-     */
562
-    public function set_event_phone($event_phone)
563
-    {
564
-        $this->set('EVT_phone', $event_phone);
565
-    }
566
-
567
-
568
-    /**
569
-     * @param $modified
570
-     * @throws EE_Error
571
-     */
572
-    public function set_modified($modified)
573
-    {
574
-        $this->set('EVT_modified', $modified);
575
-    }
576
-
577
-
578
-    /**
579
-     * @param $name
580
-     * @throws EE_Error
581
-     */
582
-    public function set_name($name)
583
-    {
584
-        $this->set('EVT_name', $name);
585
-    }
586
-
587
-
588
-    /**
589
-     * @param $order
590
-     * @throws EE_Error
591
-     */
592
-    public function set_order($order)
593
-    {
594
-        $this->set('EVT_order', $order);
595
-    }
596
-
597
-
598
-    /**
599
-     * @param $short_desc
600
-     * @throws EE_Error
601
-     */
602
-    public function set_short_description($short_desc)
603
-    {
604
-        $this->set('EVT_short_desc', $short_desc);
605
-    }
606
-
607
-
608
-    /**
609
-     * @param $slug
610
-     * @throws EE_Error
611
-     */
612
-    public function set_slug($slug)
613
-    {
614
-        $this->set('EVT_slug', $slug);
615
-    }
616
-
617
-
618
-    /**
619
-     * @param $timezone_string
620
-     * @throws EE_Error
621
-     */
622
-    public function set_timezone_string($timezone_string)
623
-    {
624
-        $this->set('EVT_timezone_string', $timezone_string);
625
-    }
626
-
627
-
628
-    /**
629
-     * @param $visible_on
630
-     * @throws EE_Error
631
-     */
632
-    public function set_visible_on($visible_on)
633
-    {
634
-        $this->set('EVT_visible_on', $visible_on);
635
-    }
636
-
637
-
638
-    /**
639
-     * @param $wp_user
640
-     * @throws EE_Error
641
-     */
642
-    public function set_wp_user($wp_user)
643
-    {
644
-        $this->set('EVT_wp_user', $wp_user);
645
-    }
646
-
647
-
648
-    /**
649
-     * @param $default_registration_status
650
-     * @throws EE_Error
651
-     */
652
-    public function set_default_registration_status($default_registration_status)
653
-    {
654
-        $this->set('EVT_default_registration_status', $default_registration_status);
655
-    }
656
-
657
-
658
-    /**
659
-     * @param $donations
660
-     * @throws EE_Error
661
-     */
662
-    public function set_donations($donations)
663
-    {
664
-        $this->set('EVT_donations', $donations);
665
-    }
666
-
667
-
668
-    /**
669
-     * Adds a venue to this event
670
-     *
671
-     * @param EE_Venue /int $venue_id_or_obj
672
-     * @return EE_Base_Class|EE_Venue
673
-     * @throws EE_Error
674
-     */
675
-    public function add_venue($venue_id_or_obj)
676
-    {
677
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
678
-    }
679
-
680
-
681
-    /**
682
-     * Removes a venue from the event
683
-     *
684
-     * @param EE_Venue /int $venue_id_or_obj
685
-     * @return EE_Base_Class|EE_Venue
686
-     * @throws EE_Error
687
-     */
688
-    public function remove_venue($venue_id_or_obj)
689
-    {
690
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
691
-    }
692
-
693
-
694
-    /**
695
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
696
-     *
697
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
698
-     * @return EE_Base_Class[]|EE_Venue[]
699
-     * @throws EE_Error
700
-     */
701
-    public function venues($query_params = array())
702
-    {
703
-        return $this->get_many_related('Venue', $query_params);
704
-    }
705
-
706
-
707
-    /**
708
-     * check if event id is present and if event is published
709
-     *
710
-     * @access public
711
-     * @return boolean true yes, false no
712
-     * @throws EE_Error
713
-     */
714
-    private function _has_ID_and_is_published()
715
-    {
716
-        // first check if event id is present and not NULL,
717
-        // then check if this event is published (or any of the equivalent "published" statuses)
718
-        return
719
-            $this->ID() && $this->ID() !== null
720
-            && (
721
-                $this->status() === 'publish'
722
-                || $this->status() === EEM_Event::sold_out
723
-                || $this->status() === EEM_Event::postponed
724
-                || $this->status() === EEM_Event::cancelled
725
-            );
726
-    }
727
-
728
-
729
-    /**
730
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
731
-     *
732
-     * @access public
733
-     * @return boolean true yes, false no
734
-     * @throws EE_Error
735
-     */
736
-    public function is_upcoming()
737
-    {
738
-        // check if event id is present and if this event is published
739
-        if ($this->is_inactive()) {
740
-            return false;
741
-        }
742
-        // set initial value
743
-        $upcoming = false;
744
-        // next let's get all datetimes and loop through them
745
-        $datetimes = $this->datetimes_in_chronological_order();
746
-        foreach ($datetimes as $datetime) {
747
-            if ($datetime instanceof EE_Datetime) {
748
-                // if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
749
-                if ($datetime->is_expired()) {
750
-                    continue;
751
-                }
752
-                // if this dtt is active then we return false.
753
-                if ($datetime->is_active()) {
754
-                    return false;
755
-                }
756
-                // otherwise let's check upcoming status
757
-                $upcoming = $datetime->is_upcoming();
758
-            }
759
-        }
760
-        return $upcoming;
761
-    }
762
-
763
-
764
-    /**
765
-     * @return bool
766
-     * @throws EE_Error
767
-     */
768
-    public function is_active()
769
-    {
770
-        // check if event id is present and if this event is published
771
-        if ($this->is_inactive()) {
772
-            return false;
773
-        }
774
-        // set initial value
775
-        $active = false;
776
-        // next let's get all datetimes and loop through them
777
-        $datetimes = $this->datetimes_in_chronological_order();
778
-        foreach ($datetimes as $datetime) {
779
-            if ($datetime instanceof EE_Datetime) {
780
-                // if this dtt is expired then we continue cause one of the other datetimes might be active.
781
-                if ($datetime->is_expired()) {
782
-                    continue;
783
-                }
784
-                // if this dtt is upcoming then we return false.
785
-                if ($datetime->is_upcoming()) {
786
-                    return false;
787
-                }
788
-                // otherwise let's check active status
789
-                $active = $datetime->is_active();
790
-            }
791
-        }
792
-        return $active;
793
-    }
794
-
795
-
796
-    /**
797
-     * @return bool
798
-     * @throws EE_Error
799
-     */
800
-    public function is_expired()
801
-    {
802
-        // check if event id is present and if this event is published
803
-        if ($this->is_inactive()) {
804
-            return false;
805
-        }
806
-        // set initial value
807
-        $expired = false;
808
-        // first let's get all datetimes and loop through them
809
-        $datetimes = $this->datetimes_in_chronological_order();
810
-        foreach ($datetimes as $datetime) {
811
-            if ($datetime instanceof EE_Datetime) {
812
-                // if this dtt is upcoming or active then we return false.
813
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
814
-                    return false;
815
-                }
816
-                // otherwise let's check active status
817
-                $expired = $datetime->is_expired();
818
-            }
819
-        }
820
-        return $expired;
821
-    }
822
-
823
-
824
-    /**
825
-     * @return bool
826
-     * @throws EE_Error
827
-     */
828
-    public function is_inactive()
829
-    {
830
-        // check if event id is present and if this event is published
831
-        if ($this->_has_ID_and_is_published()) {
832
-            return false;
833
-        }
834
-        return true;
835
-    }
836
-
837
-
838
-    /**
839
-     * calculate spaces remaining based on "saleable" tickets
840
-     *
841
-     * @param array $tickets
842
-     * @param bool  $filtered
843
-     * @return int|float
844
-     * @throws EE_Error
845
-     * @throws DomainException
846
-     * @throws UnexpectedEntityException
847
-     */
848
-    public function spaces_remaining($tickets = array(), $filtered = true)
849
-    {
850
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
851
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
852
-        return $filtered
853
-            ? apply_filters(
854
-                'FHEE_EE_Event__spaces_remaining',
855
-                $spaces_remaining,
856
-                $this,
857
-                $tickets
858
-            )
859
-            : $spaces_remaining;
860
-    }
861
-
862
-
863
-    /**
864
-     *    perform_sold_out_status_check
865
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
866
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
867
-     *
868
-     * @return bool    return the ACTUAL sold out state.
869
-     * @throws EE_Error
870
-     * @throws DomainException
871
-     * @throws UnexpectedEntityException
872
-     */
873
-    public function perform_sold_out_status_check()
874
-    {
875
-        // get all tickets
876
-        $tickets = $this->tickets(
877
-            array(
878
-                'default_where_conditions' => 'none',
879
-                'order_by' => array('TKT_qty' => 'ASC'),
880
-            )
881
-        );
882
-        $all_expired = true;
883
-        foreach ($tickets as $ticket) {
884
-            if (! $ticket->is_expired()) {
885
-                $all_expired = false;
886
-                break;
887
-            }
888
-        }
889
-        // if all the tickets are just expired, then don't update the event status to sold out
890
-        if ($all_expired) {
891
-            return true;
892
-        }
893
-        $spaces_remaining = $this->spaces_remaining($tickets);
894
-        if ($spaces_remaining < 1) {
895
-            if ($this->status() !== EEM_Event::post_status_private) {
896
-                $this->set_status(EEM_Event::sold_out);
897
-                $this->save();
898
-            }
899
-            $sold_out = true;
900
-        } else {
901
-            $sold_out = false;
902
-            // was event previously marked as sold out ?
903
-            if ($this->status() === EEM_Event::sold_out) {
904
-                // revert status to previous value, if it was set
905
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
906
-                if ($previous_event_status) {
907
-                    $this->set_status($previous_event_status);
908
-                    $this->save();
909
-                }
910
-            }
911
-        }
912
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
913
-        return $sold_out;
914
-    }
915
-
916
-
917
-    /**
918
-     * This returns the total remaining spaces for sale on this event.
919
-     *
920
-     * @uses EE_Event::total_available_spaces()
921
-     * @return float|int
922
-     * @throws EE_Error
923
-     * @throws DomainException
924
-     * @throws UnexpectedEntityException
925
-     */
926
-    public function spaces_remaining_for_sale()
927
-    {
928
-        return $this->total_available_spaces(true);
929
-    }
930
-
931
-
932
-    /**
933
-     * This returns the total spaces available for an event
934
-     * while considering all the qtys on the tickets and the reg limits
935
-     * on the datetimes attached to this event.
936
-     *
937
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
938
-     *                              If this is false, then we return the most tickets that could ever be sold
939
-     *                              for this event with the datetime and tickets setup on the event under optimal
940
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
941
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
942
-     *                              may appear to equal remaining tickets.  However, the more tickets are
943
-     *                              sold out, the more accurate the "live" total is.
944
-     * @return float|int
945
-     * @throws EE_Error
946
-     * @throws DomainException
947
-     * @throws UnexpectedEntityException
948
-     */
949
-    public function total_available_spaces($consider_sold = false)
950
-    {
951
-        $spaces_available = $consider_sold
952
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
953
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
954
-        return apply_filters(
955
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
956
-            $spaces_available,
957
-            $this,
958
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
959
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
960
-        );
961
-    }
962
-
963
-
964
-    /**
965
-     * Checks if the event is set to sold out
966
-     *
967
-     * @param  bool $actual whether or not to perform calculations to not only figure the
968
-     *                      actual status but also to flip the status if necessary to sold
969
-     *                      out If false, we just check the existing status of the event
970
-     * @return boolean
971
-     * @throws EE_Error
972
-     */
973
-    public function is_sold_out($actual = false)
974
-    {
975
-        if (! $actual) {
976
-            return $this->status() === EEM_Event::sold_out;
977
-        }
978
-        return $this->perform_sold_out_status_check();
979
-    }
980
-
981
-
982
-    /**
983
-     * Checks if the event is marked as postponed
984
-     *
985
-     * @return boolean
986
-     */
987
-    public function is_postponed()
988
-    {
989
-        return $this->status() === EEM_Event::postponed;
990
-    }
991
-
992
-
993
-    /**
994
-     * Checks if the event is marked as cancelled
995
-     *
996
-     * @return boolean
997
-     */
998
-    public function is_cancelled()
999
-    {
1000
-        return $this->status() === EEM_Event::cancelled;
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1006
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1007
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1008
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1009
-     * the event is considered expired.
1010
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1011
-     * status set on the EVENT when it is not published and thus is done
1012
-     *
1013
-     * @param bool $reset
1014
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1015
-     * @throws EE_Error
1016
-     */
1017
-    public function get_active_status($reset = false)
1018
-    {
1019
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1020
-        if (! empty($this->_active_status) && ! $reset) {
1021
-            return $this->_active_status;
1022
-        }
1023
-        // first check if event id is present on this object
1024
-        if (! $this->ID()) {
1025
-            return false;
1026
-        }
1027
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1028
-        // if event is published:
1029
-        if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1030
-            // active?
1031
-            if (EEM_Datetime::instance()->get_datetime_count_for_status(
1032
-                EE_Datetime::active,
1033
-                $where_params_for_event
1034
-            ) > 0) {
1035
-                $this->_active_status = EE_Datetime::active;
1036
-            } else {
1037
-                // upcoming?
1038
-                if (EEM_Datetime::instance()->get_datetime_count_for_status(
1039
-                    EE_Datetime::upcoming,
1040
-                    $where_params_for_event
1041
-                ) > 0) {
1042
-                    $this->_active_status = EE_Datetime::upcoming;
1043
-                } else {
1044
-                    // expired?
1045
-                    if (EEM_Datetime::instance()->get_datetime_count_for_status(
1046
-                        EE_Datetime::expired,
1047
-                        $where_params_for_event
1048
-                    ) > 0
1049
-                    ) {
1050
-                        $this->_active_status = EE_Datetime::expired;
1051
-                    } else {
1052
-                        // it would be odd if things make it this far because it basically means there are no datetime's
1053
-                        // attached to the event.  So in this case it will just be considered inactive.
1054
-                        $this->_active_status = EE_Datetime::inactive;
1055
-                    }
1056
-                }
1057
-            }
1058
-        } else {
1059
-            // the event is not published, so let's just set it's active status according to its' post status
1060
-            switch ($this->status()) {
1061
-                case EEM_Event::sold_out:
1062
-                    $this->_active_status = EE_Datetime::sold_out;
1063
-                    break;
1064
-                case EEM_Event::cancelled:
1065
-                    $this->_active_status = EE_Datetime::cancelled;
1066
-                    break;
1067
-                case EEM_Event::postponed:
1068
-                    $this->_active_status = EE_Datetime::postponed;
1069
-                    break;
1070
-                default:
1071
-                    $this->_active_status = EE_Datetime::inactive;
1072
-            }
1073
-        }
1074
-        return $this->_active_status;
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     *    pretty_active_status
1080
-     *
1081
-     * @access public
1082
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1083
-     * @return mixed void|string
1084
-     * @throws EE_Error
1085
-     */
1086
-    public function pretty_active_status($echo = true)
1087
-    {
1088
-        $active_status = $this->get_active_status();
1089
-        $status = '<span class="ee-status event-active-status-'
1090
-                  . $active_status
1091
-                  . '">'
1092
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1093
-                  . '</span>';
1094
-        if ($echo) {
1095
-            echo $status;
1096
-            return '';
1097
-        }
1098
-        return $status;
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * @return bool|int
1104
-     * @throws EE_Error
1105
-     */
1106
-    public function get_number_of_tickets_sold()
1107
-    {
1108
-        $tkt_sold = 0;
1109
-        if (! $this->ID()) {
1110
-            return 0;
1111
-        }
1112
-        $datetimes = $this->datetimes();
1113
-        foreach ($datetimes as $datetime) {
1114
-            if ($datetime instanceof EE_Datetime) {
1115
-                $tkt_sold += $datetime->sold();
1116
-            }
1117
-        }
1118
-        return $tkt_sold;
1119
-    }
1120
-
1121
-
1122
-    /**
1123
-     * This just returns a count of all the registrations for this event
1124
-     *
1125
-     * @access  public
1126
-     * @return int
1127
-     * @throws EE_Error
1128
-     */
1129
-    public function get_count_of_all_registrations()
1130
-    {
1131
-        return EEM_Event::instance()->count_related($this, 'Registration');
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * This returns the ticket with the earliest start time that is
1137
-     * available for this event (across all datetimes attached to the event)
1138
-     *
1139
-     * @return EE_Base_Class|EE_Ticket|null
1140
-     * @throws EE_Error
1141
-     */
1142
-    public function get_ticket_with_earliest_start_time()
1143
-    {
1144
-        $where['Datetime.EVT_ID'] = $this->ID();
1145
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1146
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * This returns the ticket with the latest end time that is available
1152
-     * for this event (across all datetimes attached to the event)
1153
-     *
1154
-     * @return EE_Base_Class|EE_Ticket|null
1155
-     * @throws EE_Error
1156
-     */
1157
-    public function get_ticket_with_latest_end_time()
1158
-    {
1159
-        $where['Datetime.EVT_ID'] = $this->ID();
1160
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1161
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1162
-    }
1163
-
1164
-
1165
-    /**
1166
-     * This returns the number of different ticket types currently on sale for this event.
1167
-     *
1168
-     * @return int
1169
-     * @throws EE_Error
1170
-     */
1171
-    public function countTicketsOnSale()
1172
-    {
1173
-        $where = array(
1174
-            'Datetime.EVT_ID' => $this->ID(),
1175
-            'TKT_start_date'  => array('<', time()),
1176
-            'TKT_end_date'    => array('>', time()),
1177
-        );
1178
-        return EEM_Ticket::instance()->count(array($where));
1179
-    }
1180
-
1181
-
1182
-    /**
1183
-     * This returns whether there are any tickets on sale for this event.
1184
-     *
1185
-     * @return bool true = YES tickets on sale.
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function tickets_on_sale()
1189
-    {
1190
-        return $this->countTicketsOnSale() > 0;
1191
-    }
1192
-
1193
-
1194
-    /**
1195
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1196
-     * to check for an external URL first
1197
-     *
1198
-     * @return string
1199
-     * @throws EE_Error
1200
-     */
1201
-    public function get_permalink()
1202
-    {
1203
-        if ($this->external_url()) {
1204
-            return $this->external_url();
1205
-        }
1206
-        return parent::get_permalink();
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Gets the first term for 'espresso_event_categories' we can find
1212
-     *
1213
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1214
-     * @return EE_Base_Class|EE_Term|null
1215
-     * @throws EE_Error
1216
-     */
1217
-    public function first_event_category($query_params = array())
1218
-    {
1219
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1220
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1221
-        return EEM_Term::instance()->get_one($query_params);
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * Gets all terms for 'espresso_event_categories' we can find
1227
-     *
1228
-     * @param array $query_params
1229
-     * @return EE_Base_Class[]|EE_Term[]
1230
-     * @throws EE_Error
1231
-     */
1232
-    public function get_all_event_categories($query_params = array())
1233
-    {
1234
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1235
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1236
-        return EEM_Term::instance()->get_all($query_params);
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     * Adds a question group to this event
1242
-     *
1243
-     * @param EE_Question_Group|int $question_group_id_or_obj
1244
-     * @param bool                  $for_primary if true, the question group will be added for the primary
1245
-     *                                           registrant, if false will be added for others. default: false
1246
-     * @return EE_Base_Class|EE_Question_Group
1247
-     * @throws EE_Error
1248
-     */
1249
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1250
-    {
1251
-        $extra = $for_primary
1252
-            ? array('EQG_primary' => 1)
1253
-            : array();
1254
-        return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra);
1255
-    }
1256
-
1257
-
1258
-    /**
1259
-     * Removes a question group from the event
1260
-     *
1261
-     * @param EE_Question_Group|int $question_group_id_or_obj
1262
-     * @param bool                  $for_primary if true, the question group will be removed from the primary
1263
-     *                                           registrant, if false will be removed from others. default: false
1264
-     * @return EE_Base_Class|EE_Question_Group
1265
-     * @throws EE_Error
1266
-     */
1267
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1268
-    {
1269
-        $where = $for_primary
1270
-            ? array('EQG_primary' => 1)
1271
-            : array();
1272
-        return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where);
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Gets all the question groups, ordering them by QSG_order ascending
1278
-     *
1279
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1280
-     * @return EE_Base_Class[]|EE_Question_Group[]
1281
-     * @throws EE_Error
1282
-     */
1283
-    public function question_groups($query_params = array())
1284
-    {
1285
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1286
-        return $this->get_many_related('Question_Group', $query_params);
1287
-    }
1288
-
1289
-
1290
-    /**
1291
-     * Implementation for EEI_Has_Icon interface method.
1292
-     *
1293
-     * @see EEI_Visual_Representation for comments
1294
-     * @return string
1295
-     */
1296
-    public function get_icon()
1297
-    {
1298
-        return '<span class="dashicons dashicons-flag"></span>';
1299
-    }
1300
-
1301
-
1302
-    /**
1303
-     * Implementation for EEI_Admin_Links interface method.
1304
-     *
1305
-     * @see EEI_Admin_Links for comments
1306
-     * @return string
1307
-     * @throws EE_Error
1308
-     */
1309
-    public function get_admin_details_link()
1310
-    {
1311
-        return $this->get_admin_edit_link();
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Implementation for EEI_Admin_Links interface method.
1317
-     *
1318
-     * @see EEI_Admin_Links for comments
1319
-     * @return string
1320
-     * @throws EE_Error
1321
-     */
1322
-    public function get_admin_edit_link()
1323
-    {
1324
-        return EEH_URL::add_query_args_and_nonce(
1325
-            array(
1326
-                'page'   => 'espresso_events',
1327
-                'action' => 'edit',
1328
-                'post'   => $this->ID(),
1329
-            ),
1330
-            admin_url('admin.php')
1331
-        );
1332
-    }
1333
-
1334
-
1335
-    /**
1336
-     * Implementation for EEI_Admin_Links interface method.
1337
-     *
1338
-     * @see EEI_Admin_Links for comments
1339
-     * @return string
1340
-     */
1341
-    public function get_admin_settings_link()
1342
-    {
1343
-        return EEH_URL::add_query_args_and_nonce(
1344
-            array(
1345
-                'page'   => 'espresso_events',
1346
-                'action' => 'default_event_settings',
1347
-            ),
1348
-            admin_url('admin.php')
1349
-        );
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Implementation for EEI_Admin_Links interface method.
1355
-     *
1356
-     * @see EEI_Admin_Links for comments
1357
-     * @return string
1358
-     */
1359
-    public function get_admin_overview_link()
1360
-    {
1361
-        return EEH_URL::add_query_args_and_nonce(
1362
-            array(
1363
-                'page'   => 'espresso_events',
1364
-                'action' => 'default',
1365
-            ),
1366
-            admin_url('admin.php')
1367
-        );
1368
-    }
16
+	/**
17
+	 * cached value for the the logical active status for the event
18
+	 *
19
+	 * @see get_active_status()
20
+	 * @var string
21
+	 */
22
+	protected $_active_status = '';
23
+
24
+	/**
25
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
26
+	 *
27
+	 * @var EE_Datetime
28
+	 */
29
+	protected $_Primary_Datetime;
30
+
31
+	/**
32
+	 * @var EventSpacesCalculator $available_spaces_calculator
33
+	 */
34
+	protected $available_spaces_calculator;
35
+
36
+
37
+	/**
38
+	 * @param array  $props_n_values          incoming values
39
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
40
+	 *                                        used.)
41
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
42
+	 *                                        date_format and the second value is the time format
43
+	 * @return EE_Event
44
+	 * @throws EE_Error
45
+	 */
46
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
47
+	{
48
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
49
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
50
+	}
51
+
52
+
53
+	/**
54
+	 * @param array  $props_n_values  incoming values from the database
55
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
56
+	 *                                the website will be used.
57
+	 * @return EE_Event
58
+	 * @throws EE_Error
59
+	 */
60
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
61
+	{
62
+		return new self($props_n_values, true, $timezone);
63
+	}
64
+
65
+
66
+	/**
67
+	 * @return EventSpacesCalculator
68
+	 * @throws \EE_Error
69
+	 */
70
+	public function getAvailableSpacesCalculator()
71
+	{
72
+		if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
73
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
74
+		}
75
+		return $this->available_spaces_calculator;
76
+	}
77
+
78
+
79
+	/**
80
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
81
+	 *
82
+	 * @param string $field_name
83
+	 * @param mixed  $field_value
84
+	 * @param bool   $use_default
85
+	 * @throws EE_Error
86
+	 */
87
+	public function set($field_name, $field_value, $use_default = false)
88
+	{
89
+		switch ($field_name) {
90
+			case 'status':
91
+				$this->set_status($field_value, $use_default);
92
+				break;
93
+			default:
94
+				parent::set($field_name, $field_value, $use_default);
95
+		}
96
+	}
97
+
98
+
99
+	/**
100
+	 *    set_status
101
+	 * Checks if event status is being changed to SOLD OUT
102
+	 * and updates event meta data with previous event status
103
+	 * so that we can revert things if/when the event is no longer sold out
104
+	 *
105
+	 * @access public
106
+	 * @param string $new_status
107
+	 * @param bool   $use_default
108
+	 * @return void
109
+	 * @throws EE_Error
110
+	 */
111
+	public function set_status($new_status = null, $use_default = false)
112
+	{
113
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
114
+		if (empty($new_status) && ! $use_default) {
115
+			return;
116
+		}
117
+		// get current Event status
118
+		$old_status = $this->status();
119
+		// if status has changed
120
+		if ($old_status !== $new_status) {
121
+			// TO sold_out
122
+			if ($new_status === EEM_Event::sold_out) {
123
+				// save the previous event status so that we can revert if the event is no longer sold out
124
+				$this->add_post_meta('_previous_event_status', $old_status);
125
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
126
+				// OR FROM  sold_out
127
+			} elseif ($old_status === EEM_Event::sold_out) {
128
+				$this->delete_post_meta('_previous_event_status');
129
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
130
+			}
131
+			// clear out the active status so that it gets reset the next time it is requested
132
+			$this->_active_status = null;
133
+			// update status
134
+			parent::set('status', $new_status, $use_default);
135
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
136
+			return;
137
+		}
138
+		// even though the old value matches the new value, it's still good to
139
+		// allow the parent set method to have a say
140
+		parent::set('status', $new_status, $use_default);
141
+	}
142
+
143
+
144
+	/**
145
+	 * Gets all the datetimes for this event
146
+	 *
147
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
148
+	 * @return EE_Base_Class[]|EE_Datetime[]
149
+	 * @throws EE_Error
150
+	 */
151
+	public function datetimes($query_params = array())
152
+	{
153
+		return $this->get_many_related('Datetime', $query_params);
154
+	}
155
+
156
+
157
+	/**
158
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
159
+	 *
160
+	 * @return EE_Base_Class[]|EE_Datetime[]
161
+	 * @throws EE_Error
162
+	 */
163
+	public function datetimes_in_chronological_order()
164
+	{
165
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
166
+	}
167
+
168
+
169
+	/**
170
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
171
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
172
+	 * after running our query, so that this timezone isn't set for EVERY query
173
+	 * on EEM_Datetime for the rest of the request, no?
174
+	 *
175
+	 * @param boolean $show_expired whether or not to include expired events
176
+	 * @param boolean $show_deleted whether or not to include deleted events
177
+	 * @param null    $limit
178
+	 * @return EE_Datetime[]
179
+	 * @throws EE_Error
180
+	 */
181
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
182
+	{
183
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
184
+			$this->ID(),
185
+			$show_expired,
186
+			$show_deleted,
187
+			$limit
188
+		);
189
+	}
190
+
191
+
192
+	/**
193
+	 * Returns one related datetime. Mostly only used by some legacy code.
194
+	 *
195
+	 * @return EE_Base_Class|EE_Datetime
196
+	 * @throws EE_Error
197
+	 */
198
+	public function first_datetime()
199
+	{
200
+		return $this->get_first_related('Datetime');
201
+	}
202
+
203
+
204
+	/**
205
+	 * Returns the 'primary' datetime for the event
206
+	 *
207
+	 * @param bool $try_to_exclude_expired
208
+	 * @param bool $try_to_exclude_deleted
209
+	 * @return EE_Datetime
210
+	 * @throws EE_Error
211
+	 */
212
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
213
+	{
214
+		if (! empty($this->_Primary_Datetime)) {
215
+			return $this->_Primary_Datetime;
216
+		}
217
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
218
+			$this->ID(),
219
+			$try_to_exclude_expired,
220
+			$try_to_exclude_deleted
221
+		);
222
+		return $this->_Primary_Datetime;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets all the tickets available for purchase of this event
228
+	 *
229
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
230
+	 * @return EE_Base_Class[]|EE_Ticket[]
231
+	 * @throws EE_Error
232
+	 */
233
+	public function tickets($query_params = array())
234
+	{
235
+		// first get all datetimes
236
+		$datetimes = $this->datetimes_ordered();
237
+		if (! $datetimes) {
238
+			return array();
239
+		}
240
+		$datetime_ids = array();
241
+		foreach ($datetimes as $datetime) {
242
+			$datetime_ids[] = $datetime->ID();
243
+		}
244
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
245
+		// if incoming $query_params has where conditions let's merge but not override existing.
246
+		if (is_array($query_params) && isset($query_params[0])) {
247
+			$where_params = array_merge($query_params[0], $where_params);
248
+			unset($query_params[0]);
249
+		}
250
+		// now add $where_params to $query_params
251
+		$query_params[0] = $where_params;
252
+		return EEM_Ticket::instance()->get_all($query_params);
253
+	}
254
+
255
+
256
+	/**
257
+	 * get all unexpired untrashed tickets
258
+	 *
259
+	 * @return EE_Ticket[]
260
+	 * @throws EE_Error
261
+	 */
262
+	public function active_tickets()
263
+	{
264
+		return $this->tickets(
265
+			array(
266
+				array(
267
+					'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
268
+					'TKT_deleted'  => false,
269
+				),
270
+			)
271
+		);
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return bool
277
+	 * @throws EE_Error
278
+	 */
279
+	public function additional_limit()
280
+	{
281
+		return $this->get('EVT_additional_limit');
282
+	}
283
+
284
+
285
+	/**
286
+	 * @return bool
287
+	 * @throws EE_Error
288
+	 */
289
+	public function allow_overflow()
290
+	{
291
+		return $this->get('EVT_allow_overflow');
292
+	}
293
+
294
+
295
+	/**
296
+	 * @return bool
297
+	 * @throws EE_Error
298
+	 */
299
+	public function created()
300
+	{
301
+		return $this->get('EVT_created');
302
+	}
303
+
304
+
305
+	/**
306
+	 * @return bool
307
+	 * @throws EE_Error
308
+	 */
309
+	public function description()
310
+	{
311
+		return $this->get('EVT_desc');
312
+	}
313
+
314
+
315
+	/**
316
+	 * Runs do_shortcode and wpautop on the description
317
+	 *
318
+	 * @return string of html
319
+	 * @throws EE_Error
320
+	 */
321
+	public function description_filtered()
322
+	{
323
+		return $this->get_pretty('EVT_desc');
324
+	}
325
+
326
+
327
+	/**
328
+	 * @return bool
329
+	 * @throws EE_Error
330
+	 */
331
+	public function display_description()
332
+	{
333
+		return $this->get('EVT_display_desc');
334
+	}
335
+
336
+
337
+	/**
338
+	 * @return bool
339
+	 * @throws EE_Error
340
+	 */
341
+	public function display_ticket_selector()
342
+	{
343
+		return (bool) $this->get('EVT_display_ticket_selector');
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return bool
349
+	 * @throws EE_Error
350
+	 */
351
+	public function external_url()
352
+	{
353
+		return $this->get('EVT_external_URL');
354
+	}
355
+
356
+
357
+	/**
358
+	 * @return bool
359
+	 * @throws EE_Error
360
+	 */
361
+	public function member_only()
362
+	{
363
+		return $this->get('EVT_member_only');
364
+	}
365
+
366
+
367
+	/**
368
+	 * @return bool
369
+	 * @throws EE_Error
370
+	 */
371
+	public function phone()
372
+	{
373
+		return $this->get('EVT_phone');
374
+	}
375
+
376
+
377
+	/**
378
+	 * @return bool
379
+	 * @throws EE_Error
380
+	 */
381
+	public function modified()
382
+	{
383
+		return $this->get('EVT_modified');
384
+	}
385
+
386
+
387
+	/**
388
+	 * @return bool
389
+	 * @throws EE_Error
390
+	 */
391
+	public function name()
392
+	{
393
+		return $this->get('EVT_name');
394
+	}
395
+
396
+
397
+	/**
398
+	 * @return bool
399
+	 * @throws EE_Error
400
+	 */
401
+	public function order()
402
+	{
403
+		return $this->get('EVT_order');
404
+	}
405
+
406
+
407
+	/**
408
+	 * @return bool|string
409
+	 * @throws EE_Error
410
+	 */
411
+	public function default_registration_status()
412
+	{
413
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
414
+		return ! empty($event_default_registration_status)
415
+			? $event_default_registration_status
416
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @param int  $num_words
422
+	 * @param null $more
423
+	 * @param bool $not_full_desc
424
+	 * @return bool|string
425
+	 * @throws EE_Error
426
+	 */
427
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
428
+	{
429
+		$short_desc = $this->get('EVT_short_desc');
430
+		if (! empty($short_desc) || $not_full_desc) {
431
+			return $short_desc;
432
+		}
433
+		$full_desc = $this->get('EVT_desc');
434
+		return wp_trim_words($full_desc, $num_words, $more);
435
+	}
436
+
437
+
438
+	/**
439
+	 * @return bool
440
+	 * @throws EE_Error
441
+	 */
442
+	public function slug()
443
+	{
444
+		return $this->get('EVT_slug');
445
+	}
446
+
447
+
448
+	/**
449
+	 * @return bool
450
+	 * @throws EE_Error
451
+	 */
452
+	public function timezone_string()
453
+	{
454
+		return $this->get('EVT_timezone_string');
455
+	}
456
+
457
+
458
+	/**
459
+	 * @return bool
460
+	 * @throws EE_Error
461
+	 */
462
+	public function visible_on()
463
+	{
464
+		return $this->get('EVT_visible_on');
465
+	}
466
+
467
+
468
+	/**
469
+	 * @return int
470
+	 * @throws EE_Error
471
+	 */
472
+	public function wp_user()
473
+	{
474
+		return $this->get('EVT_wp_user');
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return bool
480
+	 * @throws EE_Error
481
+	 */
482
+	public function donations()
483
+	{
484
+		return $this->get('EVT_donations');
485
+	}
486
+
487
+
488
+	/**
489
+	 * @param $limit
490
+	 * @throws EE_Error
491
+	 */
492
+	public function set_additional_limit($limit)
493
+	{
494
+		$this->set('EVT_additional_limit', $limit);
495
+	}
496
+
497
+
498
+	/**
499
+	 * @param $created
500
+	 * @throws EE_Error
501
+	 */
502
+	public function set_created($created)
503
+	{
504
+		$this->set('EVT_created', $created);
505
+	}
506
+
507
+
508
+	/**
509
+	 * @param $desc
510
+	 * @throws EE_Error
511
+	 */
512
+	public function set_description($desc)
513
+	{
514
+		$this->set('EVT_desc', $desc);
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $display_desc
520
+	 * @throws EE_Error
521
+	 */
522
+	public function set_display_description($display_desc)
523
+	{
524
+		$this->set('EVT_display_desc', $display_desc);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @param $display_ticket_selector
530
+	 * @throws EE_Error
531
+	 */
532
+	public function set_display_ticket_selector($display_ticket_selector)
533
+	{
534
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
535
+	}
536
+
537
+
538
+	/**
539
+	 * @param $external_url
540
+	 * @throws EE_Error
541
+	 */
542
+	public function set_external_url($external_url)
543
+	{
544
+		$this->set('EVT_external_URL', $external_url);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param $member_only
550
+	 * @throws EE_Error
551
+	 */
552
+	public function set_member_only($member_only)
553
+	{
554
+		$this->set('EVT_member_only', $member_only);
555
+	}
556
+
557
+
558
+	/**
559
+	 * @param $event_phone
560
+	 * @throws EE_Error
561
+	 */
562
+	public function set_event_phone($event_phone)
563
+	{
564
+		$this->set('EVT_phone', $event_phone);
565
+	}
566
+
567
+
568
+	/**
569
+	 * @param $modified
570
+	 * @throws EE_Error
571
+	 */
572
+	public function set_modified($modified)
573
+	{
574
+		$this->set('EVT_modified', $modified);
575
+	}
576
+
577
+
578
+	/**
579
+	 * @param $name
580
+	 * @throws EE_Error
581
+	 */
582
+	public function set_name($name)
583
+	{
584
+		$this->set('EVT_name', $name);
585
+	}
586
+
587
+
588
+	/**
589
+	 * @param $order
590
+	 * @throws EE_Error
591
+	 */
592
+	public function set_order($order)
593
+	{
594
+		$this->set('EVT_order', $order);
595
+	}
596
+
597
+
598
+	/**
599
+	 * @param $short_desc
600
+	 * @throws EE_Error
601
+	 */
602
+	public function set_short_description($short_desc)
603
+	{
604
+		$this->set('EVT_short_desc', $short_desc);
605
+	}
606
+
607
+
608
+	/**
609
+	 * @param $slug
610
+	 * @throws EE_Error
611
+	 */
612
+	public function set_slug($slug)
613
+	{
614
+		$this->set('EVT_slug', $slug);
615
+	}
616
+
617
+
618
+	/**
619
+	 * @param $timezone_string
620
+	 * @throws EE_Error
621
+	 */
622
+	public function set_timezone_string($timezone_string)
623
+	{
624
+		$this->set('EVT_timezone_string', $timezone_string);
625
+	}
626
+
627
+
628
+	/**
629
+	 * @param $visible_on
630
+	 * @throws EE_Error
631
+	 */
632
+	public function set_visible_on($visible_on)
633
+	{
634
+		$this->set('EVT_visible_on', $visible_on);
635
+	}
636
+
637
+
638
+	/**
639
+	 * @param $wp_user
640
+	 * @throws EE_Error
641
+	 */
642
+	public function set_wp_user($wp_user)
643
+	{
644
+		$this->set('EVT_wp_user', $wp_user);
645
+	}
646
+
647
+
648
+	/**
649
+	 * @param $default_registration_status
650
+	 * @throws EE_Error
651
+	 */
652
+	public function set_default_registration_status($default_registration_status)
653
+	{
654
+		$this->set('EVT_default_registration_status', $default_registration_status);
655
+	}
656
+
657
+
658
+	/**
659
+	 * @param $donations
660
+	 * @throws EE_Error
661
+	 */
662
+	public function set_donations($donations)
663
+	{
664
+		$this->set('EVT_donations', $donations);
665
+	}
666
+
667
+
668
+	/**
669
+	 * Adds a venue to this event
670
+	 *
671
+	 * @param EE_Venue /int $venue_id_or_obj
672
+	 * @return EE_Base_Class|EE_Venue
673
+	 * @throws EE_Error
674
+	 */
675
+	public function add_venue($venue_id_or_obj)
676
+	{
677
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
678
+	}
679
+
680
+
681
+	/**
682
+	 * Removes a venue from the event
683
+	 *
684
+	 * @param EE_Venue /int $venue_id_or_obj
685
+	 * @return EE_Base_Class|EE_Venue
686
+	 * @throws EE_Error
687
+	 */
688
+	public function remove_venue($venue_id_or_obj)
689
+	{
690
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
691
+	}
692
+
693
+
694
+	/**
695
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
696
+	 *
697
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
698
+	 * @return EE_Base_Class[]|EE_Venue[]
699
+	 * @throws EE_Error
700
+	 */
701
+	public function venues($query_params = array())
702
+	{
703
+		return $this->get_many_related('Venue', $query_params);
704
+	}
705
+
706
+
707
+	/**
708
+	 * check if event id is present and if event is published
709
+	 *
710
+	 * @access public
711
+	 * @return boolean true yes, false no
712
+	 * @throws EE_Error
713
+	 */
714
+	private function _has_ID_and_is_published()
715
+	{
716
+		// first check if event id is present and not NULL,
717
+		// then check if this event is published (or any of the equivalent "published" statuses)
718
+		return
719
+			$this->ID() && $this->ID() !== null
720
+			&& (
721
+				$this->status() === 'publish'
722
+				|| $this->status() === EEM_Event::sold_out
723
+				|| $this->status() === EEM_Event::postponed
724
+				|| $this->status() === EEM_Event::cancelled
725
+			);
726
+	}
727
+
728
+
729
+	/**
730
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
731
+	 *
732
+	 * @access public
733
+	 * @return boolean true yes, false no
734
+	 * @throws EE_Error
735
+	 */
736
+	public function is_upcoming()
737
+	{
738
+		// check if event id is present and if this event is published
739
+		if ($this->is_inactive()) {
740
+			return false;
741
+		}
742
+		// set initial value
743
+		$upcoming = false;
744
+		// next let's get all datetimes and loop through them
745
+		$datetimes = $this->datetimes_in_chronological_order();
746
+		foreach ($datetimes as $datetime) {
747
+			if ($datetime instanceof EE_Datetime) {
748
+				// if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
749
+				if ($datetime->is_expired()) {
750
+					continue;
751
+				}
752
+				// if this dtt is active then we return false.
753
+				if ($datetime->is_active()) {
754
+					return false;
755
+				}
756
+				// otherwise let's check upcoming status
757
+				$upcoming = $datetime->is_upcoming();
758
+			}
759
+		}
760
+		return $upcoming;
761
+	}
762
+
763
+
764
+	/**
765
+	 * @return bool
766
+	 * @throws EE_Error
767
+	 */
768
+	public function is_active()
769
+	{
770
+		// check if event id is present and if this event is published
771
+		if ($this->is_inactive()) {
772
+			return false;
773
+		}
774
+		// set initial value
775
+		$active = false;
776
+		// next let's get all datetimes and loop through them
777
+		$datetimes = $this->datetimes_in_chronological_order();
778
+		foreach ($datetimes as $datetime) {
779
+			if ($datetime instanceof EE_Datetime) {
780
+				// if this dtt is expired then we continue cause one of the other datetimes might be active.
781
+				if ($datetime->is_expired()) {
782
+					continue;
783
+				}
784
+				// if this dtt is upcoming then we return false.
785
+				if ($datetime->is_upcoming()) {
786
+					return false;
787
+				}
788
+				// otherwise let's check active status
789
+				$active = $datetime->is_active();
790
+			}
791
+		}
792
+		return $active;
793
+	}
794
+
795
+
796
+	/**
797
+	 * @return bool
798
+	 * @throws EE_Error
799
+	 */
800
+	public function is_expired()
801
+	{
802
+		// check if event id is present and if this event is published
803
+		if ($this->is_inactive()) {
804
+			return false;
805
+		}
806
+		// set initial value
807
+		$expired = false;
808
+		// first let's get all datetimes and loop through them
809
+		$datetimes = $this->datetimes_in_chronological_order();
810
+		foreach ($datetimes as $datetime) {
811
+			if ($datetime instanceof EE_Datetime) {
812
+				// if this dtt is upcoming or active then we return false.
813
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
814
+					return false;
815
+				}
816
+				// otherwise let's check active status
817
+				$expired = $datetime->is_expired();
818
+			}
819
+		}
820
+		return $expired;
821
+	}
822
+
823
+
824
+	/**
825
+	 * @return bool
826
+	 * @throws EE_Error
827
+	 */
828
+	public function is_inactive()
829
+	{
830
+		// check if event id is present and if this event is published
831
+		if ($this->_has_ID_and_is_published()) {
832
+			return false;
833
+		}
834
+		return true;
835
+	}
836
+
837
+
838
+	/**
839
+	 * calculate spaces remaining based on "saleable" tickets
840
+	 *
841
+	 * @param array $tickets
842
+	 * @param bool  $filtered
843
+	 * @return int|float
844
+	 * @throws EE_Error
845
+	 * @throws DomainException
846
+	 * @throws UnexpectedEntityException
847
+	 */
848
+	public function spaces_remaining($tickets = array(), $filtered = true)
849
+	{
850
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
851
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
852
+		return $filtered
853
+			? apply_filters(
854
+				'FHEE_EE_Event__spaces_remaining',
855
+				$spaces_remaining,
856
+				$this,
857
+				$tickets
858
+			)
859
+			: $spaces_remaining;
860
+	}
861
+
862
+
863
+	/**
864
+	 *    perform_sold_out_status_check
865
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
866
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
867
+	 *
868
+	 * @return bool    return the ACTUAL sold out state.
869
+	 * @throws EE_Error
870
+	 * @throws DomainException
871
+	 * @throws UnexpectedEntityException
872
+	 */
873
+	public function perform_sold_out_status_check()
874
+	{
875
+		// get all tickets
876
+		$tickets = $this->tickets(
877
+			array(
878
+				'default_where_conditions' => 'none',
879
+				'order_by' => array('TKT_qty' => 'ASC'),
880
+			)
881
+		);
882
+		$all_expired = true;
883
+		foreach ($tickets as $ticket) {
884
+			if (! $ticket->is_expired()) {
885
+				$all_expired = false;
886
+				break;
887
+			}
888
+		}
889
+		// if all the tickets are just expired, then don't update the event status to sold out
890
+		if ($all_expired) {
891
+			return true;
892
+		}
893
+		$spaces_remaining = $this->spaces_remaining($tickets);
894
+		if ($spaces_remaining < 1) {
895
+			if ($this->status() !== EEM_Event::post_status_private) {
896
+				$this->set_status(EEM_Event::sold_out);
897
+				$this->save();
898
+			}
899
+			$sold_out = true;
900
+		} else {
901
+			$sold_out = false;
902
+			// was event previously marked as sold out ?
903
+			if ($this->status() === EEM_Event::sold_out) {
904
+				// revert status to previous value, if it was set
905
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
906
+				if ($previous_event_status) {
907
+					$this->set_status($previous_event_status);
908
+					$this->save();
909
+				}
910
+			}
911
+		}
912
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
913
+		return $sold_out;
914
+	}
915
+
916
+
917
+	/**
918
+	 * This returns the total remaining spaces for sale on this event.
919
+	 *
920
+	 * @uses EE_Event::total_available_spaces()
921
+	 * @return float|int
922
+	 * @throws EE_Error
923
+	 * @throws DomainException
924
+	 * @throws UnexpectedEntityException
925
+	 */
926
+	public function spaces_remaining_for_sale()
927
+	{
928
+		return $this->total_available_spaces(true);
929
+	}
930
+
931
+
932
+	/**
933
+	 * This returns the total spaces available for an event
934
+	 * while considering all the qtys on the tickets and the reg limits
935
+	 * on the datetimes attached to this event.
936
+	 *
937
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
938
+	 *                              If this is false, then we return the most tickets that could ever be sold
939
+	 *                              for this event with the datetime and tickets setup on the event under optimal
940
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
941
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
942
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
943
+	 *                              sold out, the more accurate the "live" total is.
944
+	 * @return float|int
945
+	 * @throws EE_Error
946
+	 * @throws DomainException
947
+	 * @throws UnexpectedEntityException
948
+	 */
949
+	public function total_available_spaces($consider_sold = false)
950
+	{
951
+		$spaces_available = $consider_sold
952
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
953
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
954
+		return apply_filters(
955
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
956
+			$spaces_available,
957
+			$this,
958
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
959
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
960
+		);
961
+	}
962
+
963
+
964
+	/**
965
+	 * Checks if the event is set to sold out
966
+	 *
967
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
968
+	 *                      actual status but also to flip the status if necessary to sold
969
+	 *                      out If false, we just check the existing status of the event
970
+	 * @return boolean
971
+	 * @throws EE_Error
972
+	 */
973
+	public function is_sold_out($actual = false)
974
+	{
975
+		if (! $actual) {
976
+			return $this->status() === EEM_Event::sold_out;
977
+		}
978
+		return $this->perform_sold_out_status_check();
979
+	}
980
+
981
+
982
+	/**
983
+	 * Checks if the event is marked as postponed
984
+	 *
985
+	 * @return boolean
986
+	 */
987
+	public function is_postponed()
988
+	{
989
+		return $this->status() === EEM_Event::postponed;
990
+	}
991
+
992
+
993
+	/**
994
+	 * Checks if the event is marked as cancelled
995
+	 *
996
+	 * @return boolean
997
+	 */
998
+	public function is_cancelled()
999
+	{
1000
+		return $this->status() === EEM_Event::cancelled;
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1006
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1007
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1008
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1009
+	 * the event is considered expired.
1010
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1011
+	 * status set on the EVENT when it is not published and thus is done
1012
+	 *
1013
+	 * @param bool $reset
1014
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1015
+	 * @throws EE_Error
1016
+	 */
1017
+	public function get_active_status($reset = false)
1018
+	{
1019
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1020
+		if (! empty($this->_active_status) && ! $reset) {
1021
+			return $this->_active_status;
1022
+		}
1023
+		// first check if event id is present on this object
1024
+		if (! $this->ID()) {
1025
+			return false;
1026
+		}
1027
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1028
+		// if event is published:
1029
+		if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1030
+			// active?
1031
+			if (EEM_Datetime::instance()->get_datetime_count_for_status(
1032
+				EE_Datetime::active,
1033
+				$where_params_for_event
1034
+			) > 0) {
1035
+				$this->_active_status = EE_Datetime::active;
1036
+			} else {
1037
+				// upcoming?
1038
+				if (EEM_Datetime::instance()->get_datetime_count_for_status(
1039
+					EE_Datetime::upcoming,
1040
+					$where_params_for_event
1041
+				) > 0) {
1042
+					$this->_active_status = EE_Datetime::upcoming;
1043
+				} else {
1044
+					// expired?
1045
+					if (EEM_Datetime::instance()->get_datetime_count_for_status(
1046
+						EE_Datetime::expired,
1047
+						$where_params_for_event
1048
+					) > 0
1049
+					) {
1050
+						$this->_active_status = EE_Datetime::expired;
1051
+					} else {
1052
+						// it would be odd if things make it this far because it basically means there are no datetime's
1053
+						// attached to the event.  So in this case it will just be considered inactive.
1054
+						$this->_active_status = EE_Datetime::inactive;
1055
+					}
1056
+				}
1057
+			}
1058
+		} else {
1059
+			// the event is not published, so let's just set it's active status according to its' post status
1060
+			switch ($this->status()) {
1061
+				case EEM_Event::sold_out:
1062
+					$this->_active_status = EE_Datetime::sold_out;
1063
+					break;
1064
+				case EEM_Event::cancelled:
1065
+					$this->_active_status = EE_Datetime::cancelled;
1066
+					break;
1067
+				case EEM_Event::postponed:
1068
+					$this->_active_status = EE_Datetime::postponed;
1069
+					break;
1070
+				default:
1071
+					$this->_active_status = EE_Datetime::inactive;
1072
+			}
1073
+		}
1074
+		return $this->_active_status;
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 *    pretty_active_status
1080
+	 *
1081
+	 * @access public
1082
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1083
+	 * @return mixed void|string
1084
+	 * @throws EE_Error
1085
+	 */
1086
+	public function pretty_active_status($echo = true)
1087
+	{
1088
+		$active_status = $this->get_active_status();
1089
+		$status = '<span class="ee-status event-active-status-'
1090
+				  . $active_status
1091
+				  . '">'
1092
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1093
+				  . '</span>';
1094
+		if ($echo) {
1095
+			echo $status;
1096
+			return '';
1097
+		}
1098
+		return $status;
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * @return bool|int
1104
+	 * @throws EE_Error
1105
+	 */
1106
+	public function get_number_of_tickets_sold()
1107
+	{
1108
+		$tkt_sold = 0;
1109
+		if (! $this->ID()) {
1110
+			return 0;
1111
+		}
1112
+		$datetimes = $this->datetimes();
1113
+		foreach ($datetimes as $datetime) {
1114
+			if ($datetime instanceof EE_Datetime) {
1115
+				$tkt_sold += $datetime->sold();
1116
+			}
1117
+		}
1118
+		return $tkt_sold;
1119
+	}
1120
+
1121
+
1122
+	/**
1123
+	 * This just returns a count of all the registrations for this event
1124
+	 *
1125
+	 * @access  public
1126
+	 * @return int
1127
+	 * @throws EE_Error
1128
+	 */
1129
+	public function get_count_of_all_registrations()
1130
+	{
1131
+		return EEM_Event::instance()->count_related($this, 'Registration');
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * This returns the ticket with the earliest start time that is
1137
+	 * available for this event (across all datetimes attached to the event)
1138
+	 *
1139
+	 * @return EE_Base_Class|EE_Ticket|null
1140
+	 * @throws EE_Error
1141
+	 */
1142
+	public function get_ticket_with_earliest_start_time()
1143
+	{
1144
+		$where['Datetime.EVT_ID'] = $this->ID();
1145
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1146
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * This returns the ticket with the latest end time that is available
1152
+	 * for this event (across all datetimes attached to the event)
1153
+	 *
1154
+	 * @return EE_Base_Class|EE_Ticket|null
1155
+	 * @throws EE_Error
1156
+	 */
1157
+	public function get_ticket_with_latest_end_time()
1158
+	{
1159
+		$where['Datetime.EVT_ID'] = $this->ID();
1160
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1161
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1162
+	}
1163
+
1164
+
1165
+	/**
1166
+	 * This returns the number of different ticket types currently on sale for this event.
1167
+	 *
1168
+	 * @return int
1169
+	 * @throws EE_Error
1170
+	 */
1171
+	public function countTicketsOnSale()
1172
+	{
1173
+		$where = array(
1174
+			'Datetime.EVT_ID' => $this->ID(),
1175
+			'TKT_start_date'  => array('<', time()),
1176
+			'TKT_end_date'    => array('>', time()),
1177
+		);
1178
+		return EEM_Ticket::instance()->count(array($where));
1179
+	}
1180
+
1181
+
1182
+	/**
1183
+	 * This returns whether there are any tickets on sale for this event.
1184
+	 *
1185
+	 * @return bool true = YES tickets on sale.
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function tickets_on_sale()
1189
+	{
1190
+		return $this->countTicketsOnSale() > 0;
1191
+	}
1192
+
1193
+
1194
+	/**
1195
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1196
+	 * to check for an external URL first
1197
+	 *
1198
+	 * @return string
1199
+	 * @throws EE_Error
1200
+	 */
1201
+	public function get_permalink()
1202
+	{
1203
+		if ($this->external_url()) {
1204
+			return $this->external_url();
1205
+		}
1206
+		return parent::get_permalink();
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Gets the first term for 'espresso_event_categories' we can find
1212
+	 *
1213
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1214
+	 * @return EE_Base_Class|EE_Term|null
1215
+	 * @throws EE_Error
1216
+	 */
1217
+	public function first_event_category($query_params = array())
1218
+	{
1219
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1220
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1221
+		return EEM_Term::instance()->get_one($query_params);
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * Gets all terms for 'espresso_event_categories' we can find
1227
+	 *
1228
+	 * @param array $query_params
1229
+	 * @return EE_Base_Class[]|EE_Term[]
1230
+	 * @throws EE_Error
1231
+	 */
1232
+	public function get_all_event_categories($query_params = array())
1233
+	{
1234
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1235
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1236
+		return EEM_Term::instance()->get_all($query_params);
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 * Adds a question group to this event
1242
+	 *
1243
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1244
+	 * @param bool                  $for_primary if true, the question group will be added for the primary
1245
+	 *                                           registrant, if false will be added for others. default: false
1246
+	 * @return EE_Base_Class|EE_Question_Group
1247
+	 * @throws EE_Error
1248
+	 */
1249
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1250
+	{
1251
+		$extra = $for_primary
1252
+			? array('EQG_primary' => 1)
1253
+			: array();
1254
+		return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra);
1255
+	}
1256
+
1257
+
1258
+	/**
1259
+	 * Removes a question group from the event
1260
+	 *
1261
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1262
+	 * @param bool                  $for_primary if true, the question group will be removed from the primary
1263
+	 *                                           registrant, if false will be removed from others. default: false
1264
+	 * @return EE_Base_Class|EE_Question_Group
1265
+	 * @throws EE_Error
1266
+	 */
1267
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1268
+	{
1269
+		$where = $for_primary
1270
+			? array('EQG_primary' => 1)
1271
+			: array();
1272
+		return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Gets all the question groups, ordering them by QSG_order ascending
1278
+	 *
1279
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1280
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1281
+	 * @throws EE_Error
1282
+	 */
1283
+	public function question_groups($query_params = array())
1284
+	{
1285
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1286
+		return $this->get_many_related('Question_Group', $query_params);
1287
+	}
1288
+
1289
+
1290
+	/**
1291
+	 * Implementation for EEI_Has_Icon interface method.
1292
+	 *
1293
+	 * @see EEI_Visual_Representation for comments
1294
+	 * @return string
1295
+	 */
1296
+	public function get_icon()
1297
+	{
1298
+		return '<span class="dashicons dashicons-flag"></span>';
1299
+	}
1300
+
1301
+
1302
+	/**
1303
+	 * Implementation for EEI_Admin_Links interface method.
1304
+	 *
1305
+	 * @see EEI_Admin_Links for comments
1306
+	 * @return string
1307
+	 * @throws EE_Error
1308
+	 */
1309
+	public function get_admin_details_link()
1310
+	{
1311
+		return $this->get_admin_edit_link();
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Implementation for EEI_Admin_Links interface method.
1317
+	 *
1318
+	 * @see EEI_Admin_Links for comments
1319
+	 * @return string
1320
+	 * @throws EE_Error
1321
+	 */
1322
+	public function get_admin_edit_link()
1323
+	{
1324
+		return EEH_URL::add_query_args_and_nonce(
1325
+			array(
1326
+				'page'   => 'espresso_events',
1327
+				'action' => 'edit',
1328
+				'post'   => $this->ID(),
1329
+			),
1330
+			admin_url('admin.php')
1331
+		);
1332
+	}
1333
+
1334
+
1335
+	/**
1336
+	 * Implementation for EEI_Admin_Links interface method.
1337
+	 *
1338
+	 * @see EEI_Admin_Links for comments
1339
+	 * @return string
1340
+	 */
1341
+	public function get_admin_settings_link()
1342
+	{
1343
+		return EEH_URL::add_query_args_and_nonce(
1344
+			array(
1345
+				'page'   => 'espresso_events',
1346
+				'action' => 'default_event_settings',
1347
+			),
1348
+			admin_url('admin.php')
1349
+		);
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Implementation for EEI_Admin_Links interface method.
1355
+	 *
1356
+	 * @see EEI_Admin_Links for comments
1357
+	 * @return string
1358
+	 */
1359
+	public function get_admin_overview_link()
1360
+	{
1361
+		return EEH_URL::add_query_args_and_nonce(
1362
+			array(
1363
+				'page'   => 'espresso_events',
1364
+				'action' => 'default',
1365
+			),
1366
+			admin_url('admin.php')
1367
+		);
1368
+	}
1369 1369
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Organization_Shortcodes.lib.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -19,139 +19,139 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    public function __construct()
23
-    {
24
-        parent::__construct();
25
-    }
26
-
27
-
28
-    protected function _init_props()
29
-    {
30
-        $this->label = esc_html__('Organization Shortcodes', 'event_espresso');
31
-        $this->description = esc_html__('All shortcodes specific to organization related data', 'event_espresso');
32
-        $this->_shortcodes = array(
33
-            '[COMPANY]'          => esc_html__('Event organization name', 'event_espresso'),
34
-            '[CO_ADD1]'          => esc_html__('Address 1 value for the organization', 'event_espresso'),
35
-            '[CO_ADD2]'          => esc_html__('Address 2 value for the organization', 'event_espresso'),
36
-            '[CO_CITY]'          => esc_html__('City the organization is in', 'event_espresso'),
37
-            '[CO_STATE]'         => esc_html__('State the organization is located in', 'event_espresso'),
38
-            '[CO_ZIP]'           => esc_html__('The zip code for the organization', 'event_espresso'),
39
-            '[CO_LOGO]'          => esc_html__('The logo image for the organization', 'event_espresso'),
40
-            '[CO_EMAIL]'         => esc_html__('The primary email address for the organization', 'event_espresso'),
41
-            '[CO_PHONE]'         => esc_html__('The phone number for the organization', 'event_espresso'),
42
-            '[CO_LOGO_URL]'      => esc_html__(
43
-                'Just the link to the image used as the logo for the organization',
44
-                'event_espresso'
45
-            ),
46
-            '[CO_FACEBOOK_URL]'  => esc_html__('Link to organization Facebook page', 'event_espresso'),
47
-            '[CO_TWITTER_URL]'   => esc_html__('Link to organization Twitter page', 'event_espresso'),
48
-            '[CO_PINTEREST_URL]' => esc_html__('Link to organization Pinterest page', 'event_espresso'),
49
-            '[CO_GOOGLE_URL]'    => esc_html__('Link to organization Google page', 'event_espresso'),
50
-            '[CO_LINKEDIN_URL]'  => esc_html__('Link to organization LinkedIn page', 'event_espresso'),
51
-            '[CO_INSTAGRAM_URL]' => esc_html__('Link to organization Instagram page', 'event_espresso'),
52
-            '[CO_TAX_NUMBER_*]'  => sprintf(
53
-                esc_html__(
54
-                    'This is the shortcode used for displaying any tax number for the company.  %1$sNote: This is a special dynamic shortcode.%2$s You can use the "prefix" parameter to indicate what the prefix for this tax number is.  It defaults to "VAT/Tax Number:".  To change this prefix you do the following format for this shortcode:  [CO_TAX_NUMBER_* prefix="GST: "] and that will output: GST: 12345t56.  Also take note that if you have NO number in your settings, the prefix is not output either.',
55
-                    'event_espresso'
56
-                ),
57
-                '<strong>',
58
-                '</strong>'
59
-            ),
60
-        );
61
-    }
62
-
63
-
64
-    protected function _parser($shortcode)
65
-    {
66
-
67
-        switch ($shortcode) {
68
-            case '[COMPANY]':
69
-                return EE_Registry::instance()->CFG->organization->get_pretty('name');
70
-                break;
71
-
72
-            case '[CO_ADD1]':
73
-                return EE_Registry::instance()->CFG->organization->get_pretty('address_1');
74
-                break;
75
-
76
-            case '[CO_ADD2]':
77
-                return EE_Registry::instance()->CFG->organization->get_pretty('address_2');
78
-                break;
79
-
80
-            case '[CO_CITY]':
81
-                return EE_Registry::instance()->CFG->organization->get_pretty('city');
82
-                break;
83
-
84
-            case '[CO_STATE]':
85
-                $state = EE_Registry::instance()->load_model('State')->get_one_by_ID(
86
-                    EE_Registry::instance()->CFG->organization->STA_ID
87
-                );
88
-                return $state instanceof EE_State ? $state->name() : '';
89
-                break;
90
-
91
-            case '[CO_ZIP]':
92
-                return EE_Registry::instance()->CFG->organization->get_pretty('zip');
93
-                break;
94
-
95
-            case '[CO_EMAIL]':
96
-                return EE_Registry::instance()->CFG->organization->get_pretty('email');
97
-                break;
98
-
99
-            case '[CO_PHONE]':
100
-                return EE_Registry::instance()->CFG->organization->get_pretty('phone');
101
-                break;
102
-
103
-            case '[CO_LOGO]':
104
-                return '<img src="'
105
-                       . EE_Registry::instance()->CFG->organization->get_pretty(
106
-                           'logo_url'
107
-                       ) . '" id="headerImage" />';
108
-                break;
109
-
110
-            case '[CO_LOGO_URL]':
111
-                return EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
112
-                break;
113
-
114
-            case '[CO_FACEBOOK_URL]':
115
-                return EE_Registry::instance()->CFG->organization->get_pretty('facebook');
116
-                break;
117
-
118
-            case '[CO_TWITTER_URL]':
119
-                return EE_Registry::instance()->CFG->organization->get_pretty('twitter');
120
-                break;
121
-
122
-            case '[CO_PINTEREST_URL]':
123
-                return EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
124
-                break;
125
-
126
-            case '[CO_LINKEDIN_URL]':
127
-                return EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
128
-                break;
129
-
130
-            case '[CO_GOOGLE_URL]':
131
-                return EE_Registry::instance()->CFG->organization->get_pretty('google');
132
-                break;
133
-
134
-            case '[CO_INSTAGRAM_URL]':
135
-                return EE_Registry::instance()->CFG->organization->get_pretty('instagram');
136
-                break;
137
-        }
138
-
139
-        // also allow for parameter shortcode
140
-        if (strpos($shortcode, '[CO_TAX_NUMBER_*') !== false) {
141
-            // first see if there is any company tax number set and bail early if not
142
-            $tax_number = EE_Registry::instance()->CFG->organization->vat;
143
-            if (empty($tax_number)) {
144
-                return '';
145
-            }
146
-
147
-            // see if there are any attributes.
148
-            $attrs = $this->_get_shortcode_attrs($shortcode);
149
-
150
-            // set custom attrs if present (or default)
151
-            $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
152
-            return $prefix . $tax_number;
153
-        }
154
-
155
-        return '';
156
-    }
22
+	public function __construct()
23
+	{
24
+		parent::__construct();
25
+	}
26
+
27
+
28
+	protected function _init_props()
29
+	{
30
+		$this->label = esc_html__('Organization Shortcodes', 'event_espresso');
31
+		$this->description = esc_html__('All shortcodes specific to organization related data', 'event_espresso');
32
+		$this->_shortcodes = array(
33
+			'[COMPANY]'          => esc_html__('Event organization name', 'event_espresso'),
34
+			'[CO_ADD1]'          => esc_html__('Address 1 value for the organization', 'event_espresso'),
35
+			'[CO_ADD2]'          => esc_html__('Address 2 value for the organization', 'event_espresso'),
36
+			'[CO_CITY]'          => esc_html__('City the organization is in', 'event_espresso'),
37
+			'[CO_STATE]'         => esc_html__('State the organization is located in', 'event_espresso'),
38
+			'[CO_ZIP]'           => esc_html__('The zip code for the organization', 'event_espresso'),
39
+			'[CO_LOGO]'          => esc_html__('The logo image for the organization', 'event_espresso'),
40
+			'[CO_EMAIL]'         => esc_html__('The primary email address for the organization', 'event_espresso'),
41
+			'[CO_PHONE]'         => esc_html__('The phone number for the organization', 'event_espresso'),
42
+			'[CO_LOGO_URL]'      => esc_html__(
43
+				'Just the link to the image used as the logo for the organization',
44
+				'event_espresso'
45
+			),
46
+			'[CO_FACEBOOK_URL]'  => esc_html__('Link to organization Facebook page', 'event_espresso'),
47
+			'[CO_TWITTER_URL]'   => esc_html__('Link to organization Twitter page', 'event_espresso'),
48
+			'[CO_PINTEREST_URL]' => esc_html__('Link to organization Pinterest page', 'event_espresso'),
49
+			'[CO_GOOGLE_URL]'    => esc_html__('Link to organization Google page', 'event_espresso'),
50
+			'[CO_LINKEDIN_URL]'  => esc_html__('Link to organization LinkedIn page', 'event_espresso'),
51
+			'[CO_INSTAGRAM_URL]' => esc_html__('Link to organization Instagram page', 'event_espresso'),
52
+			'[CO_TAX_NUMBER_*]'  => sprintf(
53
+				esc_html__(
54
+					'This is the shortcode used for displaying any tax number for the company.  %1$sNote: This is a special dynamic shortcode.%2$s You can use the "prefix" parameter to indicate what the prefix for this tax number is.  It defaults to "VAT/Tax Number:".  To change this prefix you do the following format for this shortcode:  [CO_TAX_NUMBER_* prefix="GST: "] and that will output: GST: 12345t56.  Also take note that if you have NO number in your settings, the prefix is not output either.',
55
+					'event_espresso'
56
+				),
57
+				'<strong>',
58
+				'</strong>'
59
+			),
60
+		);
61
+	}
62
+
63
+
64
+	protected function _parser($shortcode)
65
+	{
66
+
67
+		switch ($shortcode) {
68
+			case '[COMPANY]':
69
+				return EE_Registry::instance()->CFG->organization->get_pretty('name');
70
+				break;
71
+
72
+			case '[CO_ADD1]':
73
+				return EE_Registry::instance()->CFG->organization->get_pretty('address_1');
74
+				break;
75
+
76
+			case '[CO_ADD2]':
77
+				return EE_Registry::instance()->CFG->organization->get_pretty('address_2');
78
+				break;
79
+
80
+			case '[CO_CITY]':
81
+				return EE_Registry::instance()->CFG->organization->get_pretty('city');
82
+				break;
83
+
84
+			case '[CO_STATE]':
85
+				$state = EE_Registry::instance()->load_model('State')->get_one_by_ID(
86
+					EE_Registry::instance()->CFG->organization->STA_ID
87
+				);
88
+				return $state instanceof EE_State ? $state->name() : '';
89
+				break;
90
+
91
+			case '[CO_ZIP]':
92
+				return EE_Registry::instance()->CFG->organization->get_pretty('zip');
93
+				break;
94
+
95
+			case '[CO_EMAIL]':
96
+				return EE_Registry::instance()->CFG->organization->get_pretty('email');
97
+				break;
98
+
99
+			case '[CO_PHONE]':
100
+				return EE_Registry::instance()->CFG->organization->get_pretty('phone');
101
+				break;
102
+
103
+			case '[CO_LOGO]':
104
+				return '<img src="'
105
+					   . EE_Registry::instance()->CFG->organization->get_pretty(
106
+						   'logo_url'
107
+					   ) . '" id="headerImage" />';
108
+				break;
109
+
110
+			case '[CO_LOGO_URL]':
111
+				return EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
112
+				break;
113
+
114
+			case '[CO_FACEBOOK_URL]':
115
+				return EE_Registry::instance()->CFG->organization->get_pretty('facebook');
116
+				break;
117
+
118
+			case '[CO_TWITTER_URL]':
119
+				return EE_Registry::instance()->CFG->organization->get_pretty('twitter');
120
+				break;
121
+
122
+			case '[CO_PINTEREST_URL]':
123
+				return EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
124
+				break;
125
+
126
+			case '[CO_LINKEDIN_URL]':
127
+				return EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
128
+				break;
129
+
130
+			case '[CO_GOOGLE_URL]':
131
+				return EE_Registry::instance()->CFG->organization->get_pretty('google');
132
+				break;
133
+
134
+			case '[CO_INSTAGRAM_URL]':
135
+				return EE_Registry::instance()->CFG->organization->get_pretty('instagram');
136
+				break;
137
+		}
138
+
139
+		// also allow for parameter shortcode
140
+		if (strpos($shortcode, '[CO_TAX_NUMBER_*') !== false) {
141
+			// first see if there is any company tax number set and bail early if not
142
+			$tax_number = EE_Registry::instance()->CFG->organization->vat;
143
+			if (empty($tax_number)) {
144
+				return '';
145
+			}
146
+
147
+			// see if there are any attributes.
148
+			$attrs = $this->_get_shortcode_attrs($shortcode);
149
+
150
+			// set custom attrs if present (or default)
151
+			$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
152
+			return $prefix . $tax_number;
153
+		}
154
+
155
+		return '';
156
+	}
157 157
 }
Please login to merge, or discard this patch.
core/helpers/EEH_URL.helper.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -12,270 +12,270 @@
 block discarded – undo
12 12
 class EEH_URL
13 13
 {
14 14
 
15
-    /**
16
-     * _add_query_arg
17
-     * adds nonce to array of arguments then calls WP add_query_arg function
18
-     *
19
-     * @access public
20
-     * @param array  $args
21
-     * @param string $url
22
-     * @param bool   $exclude_nonce If true then the nonce will be excluded from the generated url.
23
-     * @return string
24
-     */
25
-    public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
26
-    {
27
-        // check that an action exists and add nonce
28
-        if (! $exclude_nonce) {
29
-            if (isset($args['action']) && ! empty($args['action'])) {
30
-                $args = array_merge(
31
-                    $args,
32
-                    array(
33
-                        $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')
34
-                    )
35
-                );
36
-            } else {
37
-                $args = array_merge(
38
-                    $args,
39
-                    array(
40
-                        'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')
41
-                    )
42
-                );
43
-            }
44
-        }
15
+	/**
16
+	 * _add_query_arg
17
+	 * adds nonce to array of arguments then calls WP add_query_arg function
18
+	 *
19
+	 * @access public
20
+	 * @param array  $args
21
+	 * @param string $url
22
+	 * @param bool   $exclude_nonce If true then the nonce will be excluded from the generated url.
23
+	 * @return string
24
+	 */
25
+	public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
26
+	{
27
+		// check that an action exists and add nonce
28
+		if (! $exclude_nonce) {
29
+			if (isset($args['action']) && ! empty($args['action'])) {
30
+				$args = array_merge(
31
+					$args,
32
+					array(
33
+						$args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')
34
+					)
35
+				);
36
+			} else {
37
+				$args = array_merge(
38
+					$args,
39
+					array(
40
+						'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce')
41
+					)
42
+				);
43
+			}
44
+		}
45 45
 
46
-        // finally, let's always add a return address (if present) :)
47
-        $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return'])
48
-            ? array_merge($args, array('return' => $_REQUEST['action']))
49
-            : $args;
46
+		// finally, let's always add a return address (if present) :)
47
+		$args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return'])
48
+			? array_merge($args, array('return' => $_REQUEST['action']))
49
+			: $args;
50 50
 
51
-        return add_query_arg($args, $url);
52
-    }
51
+		return add_query_arg($args, $url);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Returns whether not the remote file exists.
57
-     * Checking via GET because HEAD requests are blocked on some server configurations.
58
-     *
59
-     * @param string  $url
60
-     * @param array $args  the arguments that should be passed through to the wp_remote_request call.
61
-     * @return boolean
62
-     */
63
-    public static function remote_file_exists($url, $args = array())
64
-    {
65
-        $results = wp_remote_request(
66
-            $url,
67
-            array_merge(
68
-                array(
69
-                    'method'      => 'GET',
70
-                    'redirection' => 1,
71
-                ),
72
-                $args
73
-            )
74
-        );
75
-        if (! $results instanceof WP_Error &&
76
-            isset($results['response']) &&
77
-            isset($results['response']['code']) &&
78
-            $results['response']['code'] == '200') {
79
-            return true;
80
-        } else {
81
-            return false;
82
-        }
83
-    }
55
+	/**
56
+	 * Returns whether not the remote file exists.
57
+	 * Checking via GET because HEAD requests are blocked on some server configurations.
58
+	 *
59
+	 * @param string  $url
60
+	 * @param array $args  the arguments that should be passed through to the wp_remote_request call.
61
+	 * @return boolean
62
+	 */
63
+	public static function remote_file_exists($url, $args = array())
64
+	{
65
+		$results = wp_remote_request(
66
+			$url,
67
+			array_merge(
68
+				array(
69
+					'method'      => 'GET',
70
+					'redirection' => 1,
71
+				),
72
+				$args
73
+			)
74
+		);
75
+		if (! $results instanceof WP_Error &&
76
+			isset($results['response']) &&
77
+			isset($results['response']['code']) &&
78
+			$results['response']['code'] == '200') {
79
+			return true;
80
+		} else {
81
+			return false;
82
+		}
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     * refactor_url
88
-     * primarily used for removing the query string from a URL
89
-     *
90
-     * @param string $url
91
-     * @param bool   $remove_query  - TRUE (default) will strip off any URL params, ie: ?this=1&that=2
92
-     * @param bool   $base_url_only - TRUE will only return the scheme and host with no other parameters
93
-     * @return string
94
-     */
95
-    public static function refactor_url($url = '', $remove_query = true, $base_url_only = false)
96
-    {
97
-        // break apart incoming URL
98
-        $url_bits = parse_url($url);
99
-        // HTTP or HTTPS ?
100
-        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
101
-        // domain
102
-        $host = isset($url_bits['host']) ? $url_bits['host'] : '';
103
-        // if only the base URL is requested, then return that now
104
-        if ($base_url_only) {
105
-            return $scheme . $host;
106
-        }
107
-        $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
108
-        $user = isset($url_bits['user']) ? $url_bits['user'] : '';
109
-        $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
110
-        $pass = ($user || $pass) ? $pass . '@' : '';
111
-        $path = isset($url_bits['path']) ? $url_bits['path'] : '';
112
-        // if the query string is not required, then return what we have so far
113
-        if ($remove_query) {
114
-            return $scheme . $user . $pass . $host . $port . $path;
115
-        }
116
-        $query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
117
-        $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
118
-        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
119
-    }
86
+	/**
87
+	 * refactor_url
88
+	 * primarily used for removing the query string from a URL
89
+	 *
90
+	 * @param string $url
91
+	 * @param bool   $remove_query  - TRUE (default) will strip off any URL params, ie: ?this=1&that=2
92
+	 * @param bool   $base_url_only - TRUE will only return the scheme and host with no other parameters
93
+	 * @return string
94
+	 */
95
+	public static function refactor_url($url = '', $remove_query = true, $base_url_only = false)
96
+	{
97
+		// break apart incoming URL
98
+		$url_bits = parse_url($url);
99
+		// HTTP or HTTPS ?
100
+		$scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
101
+		// domain
102
+		$host = isset($url_bits['host']) ? $url_bits['host'] : '';
103
+		// if only the base URL is requested, then return that now
104
+		if ($base_url_only) {
105
+			return $scheme . $host;
106
+		}
107
+		$port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
108
+		$user = isset($url_bits['user']) ? $url_bits['user'] : '';
109
+		$pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
110
+		$pass = ($user || $pass) ? $pass . '@' : '';
111
+		$path = isset($url_bits['path']) ? $url_bits['path'] : '';
112
+		// if the query string is not required, then return what we have so far
113
+		if ($remove_query) {
114
+			return $scheme . $user . $pass . $host . $port . $path;
115
+		}
116
+		$query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
117
+		$fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
118
+		return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * get_query_string
124
-     * returns just the query string from a URL, formatted by default into an array of key value pairs
125
-     *
126
-     * @param string $url
127
-     * @param bool   $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will
128
-     *                         simply return the query string
129
-     * @return string|array
130
-     */
131
-    public static function get_query_string($url = '', $as_array = true)
132
-    {
133
-        // decode, then break apart incoming URL
134
-        $url_bits = parse_url(html_entity_decode($url));
135
-        // grab query string from URL
136
-        $query = isset($url_bits['query']) ? $url_bits['query'] : '';
137
-        // if we don't want the query string formatted into an array of key => value pairs, then just return it as is
138
-        if (! $as_array) {
139
-            return $query;
140
-        }
141
-        // if no query string exists then just return an empty array now
142
-        if (empty($query)) {
143
-            return array();
144
-        }
145
-        // empty array to hold results
146
-        $query_params = array();
147
-        // now break apart the query string into separate params
148
-        $query = explode('&', $query);
149
-        // loop thru our query params
150
-        foreach ($query as $query_args) {
151
-            // break apart the key value pairs
152
-            $query_args = explode('=', $query_args);
153
-            // and add to our results array
154
-            $query_params[ $query_args[0] ] = $query_args[1];
155
-        }
156
-        return $query_params;
157
-    }
122
+	/**
123
+	 * get_query_string
124
+	 * returns just the query string from a URL, formatted by default into an array of key value pairs
125
+	 *
126
+	 * @param string $url
127
+	 * @param bool   $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will
128
+	 *                         simply return the query string
129
+	 * @return string|array
130
+	 */
131
+	public static function get_query_string($url = '', $as_array = true)
132
+	{
133
+		// decode, then break apart incoming URL
134
+		$url_bits = parse_url(html_entity_decode($url));
135
+		// grab query string from URL
136
+		$query = isset($url_bits['query']) ? $url_bits['query'] : '';
137
+		// if we don't want the query string formatted into an array of key => value pairs, then just return it as is
138
+		if (! $as_array) {
139
+			return $query;
140
+		}
141
+		// if no query string exists then just return an empty array now
142
+		if (empty($query)) {
143
+			return array();
144
+		}
145
+		// empty array to hold results
146
+		$query_params = array();
147
+		// now break apart the query string into separate params
148
+		$query = explode('&', $query);
149
+		// loop thru our query params
150
+		foreach ($query as $query_args) {
151
+			// break apart the key value pairs
152
+			$query_args = explode('=', $query_args);
153
+			// and add to our results array
154
+			$query_params[ $query_args[0] ] = $query_args[1];
155
+		}
156
+		return $query_params;
157
+	}
158 158
 
159 159
 
160
-    /**
161
-     * prevent_prefetching
162
-     *
163
-     * @return void
164
-     */
165
-    public static function prevent_prefetching()
166
-    {
167
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes
168
-        // with the registration process
169
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
170
-    }
160
+	/**
161
+	 * prevent_prefetching
162
+	 *
163
+	 * @return void
164
+	 */
165
+	public static function prevent_prefetching()
166
+	{
167
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes
168
+		// with the registration process
169
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * This generates a unique site-specific string.
175
-     * An example usage for this string would be to save as a unique identifier for a record in the db for usage in
176
-     * urls.
177
-     *
178
-     * @param   string $prefix Use this to prefix the string with something.
179
-     * @return string
180
-     */
181
-    public static function generate_unique_token($prefix = '')
182
-    {
183
-        $token = md5(uniqid() . mt_rand());
184
-        return $prefix ? $prefix . '_' . $token : $token;
185
-    }
173
+	/**
174
+	 * This generates a unique site-specific string.
175
+	 * An example usage for this string would be to save as a unique identifier for a record in the db for usage in
176
+	 * urls.
177
+	 *
178
+	 * @param   string $prefix Use this to prefix the string with something.
179
+	 * @return string
180
+	 */
181
+	public static function generate_unique_token($prefix = '')
182
+	{
183
+		$token = md5(uniqid() . mt_rand());
184
+		return $prefix ? $prefix . '_' . $token : $token;
185
+	}
186 186
 
187 187
 
188
-    /**
189
-     * filter_input_server_url
190
-     * uses filter_input() to sanitize one of the INPUT_SERVER URL values
191
-     * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers
192
-     *
193
-     * @param string $server_variable
194
-     * @return string
195
-     */
196
-    public static function filter_input_server_url($server_variable = 'REQUEST_URI')
197
-    {
198
-        $URL              = '';
199
-        $server_variables = array(
200
-            'REQUEST_URI' => 1,
201
-            'HTTP_HOST'   => 1,
202
-            'PHP_SELF'    => 1,
203
-        );
204
-        $server_variable  = strtoupper($server_variable);
205
-        // whitelist INPUT_SERVER var
206
-        if (isset($server_variables[ $server_variable ])) {
207
-            $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
208
-            if (empty($URL)) {
209
-                // fallback sanitization if the above fails
210
-                $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]);
211
-            }
212
-        }
213
-        return $URL;
214
-    }
188
+	/**
189
+	 * filter_input_server_url
190
+	 * uses filter_input() to sanitize one of the INPUT_SERVER URL values
191
+	 * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers
192
+	 *
193
+	 * @param string $server_variable
194
+	 * @return string
195
+	 */
196
+	public static function filter_input_server_url($server_variable = 'REQUEST_URI')
197
+	{
198
+		$URL              = '';
199
+		$server_variables = array(
200
+			'REQUEST_URI' => 1,
201
+			'HTTP_HOST'   => 1,
202
+			'PHP_SELF'    => 1,
203
+		);
204
+		$server_variable  = strtoupper($server_variable);
205
+		// whitelist INPUT_SERVER var
206
+		if (isset($server_variables[ $server_variable ])) {
207
+			$URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
208
+			if (empty($URL)) {
209
+				// fallback sanitization if the above fails
210
+				$URL = wp_sanitize_redirect($_SERVER[ $server_variable ]);
211
+			}
212
+		}
213
+		return $URL;
214
+	}
215 215
 
216 216
 
217
-    /**
218
-     * Gets the current page's full URL.
219
-     *
220
-     * @return string
221
-     */
222
-    public static function current_url()
223
-    {
224
-        $url = '';
225
-        if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
226
-            $url = is_ssl() ? 'https://' : 'http://';
227
-            $url .= \EEH_URL::filter_input_server_url('HTTP_HOST');
228
-            $url .= \EEH_URL::filter_input_server_url('REQUEST_URI');
229
-        }
230
-        return $url;
231
-    }
217
+	/**
218
+	 * Gets the current page's full URL.
219
+	 *
220
+	 * @return string
221
+	 */
222
+	public static function current_url()
223
+	{
224
+		$url = '';
225
+		if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
226
+			$url = is_ssl() ? 'https://' : 'http://';
227
+			$url .= \EEH_URL::filter_input_server_url('HTTP_HOST');
228
+			$url .= \EEH_URL::filter_input_server_url('REQUEST_URI');
229
+		}
230
+		return $url;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it.
236
-     *
237
-     * @param array $query_parameters An array of query_parameters to remove from the current url.
238
-     * @since 4.9.46.rc.029
239
-     * @return string
240
-     */
241
-    public static function current_url_without_query_paramaters(array $query_parameters)
242
-    {
243
-        return remove_query_arg($query_parameters, EEH_URL::current_url());
244
-    }
234
+	/**
235
+	 * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it.
236
+	 *
237
+	 * @param array $query_parameters An array of query_parameters to remove from the current url.
238
+	 * @since 4.9.46.rc.029
239
+	 * @return string
240
+	 */
241
+	public static function current_url_without_query_paramaters(array $query_parameters)
242
+	{
243
+		return remove_query_arg($query_parameters, EEH_URL::current_url());
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     * @param string $location
249
-     * @param int    $status
250
-     * @param string $exit_notice
251
-     */
252
-    public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '')
253
-    {
254
-        EE_Error::get_notices(false, true);
255
-        wp_safe_redirect($location, $status);
256
-        exit($exit_notice);
257
-    }
247
+	/**
248
+	 * @param string $location
249
+	 * @param int    $status
250
+	 * @param string $exit_notice
251
+	 */
252
+	public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '')
253
+	{
254
+		EE_Error::get_notices(false, true);
255
+		wp_safe_redirect($location, $status);
256
+		exit($exit_notice);
257
+	}
258 258
 
259
-    /**
260
-     * Slugifies text for usage in a URL.
261
-     *
262
-     * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters,
263
-     * and WordPress chokes on them when used as CPT and custom taxonomy slugs.
264
-     *
265
-     * @since 4.9.66.p
266
-     * @param string $text
267
-     * @param string $fallback
268
-     * @return string which can be used in a URL
269
-     */
270
-    public static function slugify($text, $fallback)
271
-    {
272
-        // url decode after sanitizing title to restore unicode characters,
273
-        // see https://github.com/eventespresso/event-espresso-core/issues/575
274
-        return urldecode(
275
-            sanitize_title(
276
-                $text,
277
-                $fallback
278
-            )
279
-        );
280
-    }
259
+	/**
260
+	 * Slugifies text for usage in a URL.
261
+	 *
262
+	 * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters,
263
+	 * and WordPress chokes on them when used as CPT and custom taxonomy slugs.
264
+	 *
265
+	 * @since 4.9.66.p
266
+	 * @param string $text
267
+	 * @param string $fallback
268
+	 * @return string which can be used in a URL
269
+	 */
270
+	public static function slugify($text, $fallback)
271
+	{
272
+		// url decode after sanitizing title to restore unicode characters,
273
+		// see https://github.com/eventespresso/event-espresso-core/issues/575
274
+		return urldecode(
275
+			sanitize_title(
276
+				$text,
277
+				$fallback
278
+			)
279
+		);
280
+	}
281 281
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -25,12 +25,12 @@  discard block
 block discarded – undo
25 25
     public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false)
26 26
     {
27 27
         // check that an action exists and add nonce
28
-        if (! $exclude_nonce) {
28
+        if ( ! $exclude_nonce) {
29 29
             if (isset($args['action']) && ! empty($args['action'])) {
30 30
                 $args = array_merge(
31 31
                     $args,
32 32
                     array(
33
-                        $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce')
33
+                        $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce')
34 34
                     )
35 35
                 );
36 36
             } else {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 $args
73 73
             )
74 74
         );
75
-        if (! $results instanceof WP_Error &&
75
+        if ( ! $results instanceof WP_Error &&
76 76
             isset($results['response']) &&
77 77
             isset($results['response']['code']) &&
78 78
             $results['response']['code'] == '200') {
@@ -97,25 +97,25 @@  discard block
 block discarded – undo
97 97
         // break apart incoming URL
98 98
         $url_bits = parse_url($url);
99 99
         // HTTP or HTTPS ?
100
-        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://';
100
+        $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://';
101 101
         // domain
102 102
         $host = isset($url_bits['host']) ? $url_bits['host'] : '';
103 103
         // if only the base URL is requested, then return that now
104 104
         if ($base_url_only) {
105
-            return $scheme . $host;
105
+            return $scheme.$host;
106 106
         }
107
-        $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : '';
107
+        $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : '';
108 108
         $user = isset($url_bits['user']) ? $url_bits['user'] : '';
109
-        $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : '';
110
-        $pass = ($user || $pass) ? $pass . '@' : '';
109
+        $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : '';
110
+        $pass = ($user || $pass) ? $pass.'@' : '';
111 111
         $path = isset($url_bits['path']) ? $url_bits['path'] : '';
112 112
         // if the query string is not required, then return what we have so far
113 113
         if ($remove_query) {
114
-            return $scheme . $user . $pass . $host . $port . $path;
114
+            return $scheme.$user.$pass.$host.$port.$path;
115 115
         }
116
-        $query    = isset($url_bits['query']) ? '?' . $url_bits['query'] : '';
117
-        $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : '';
118
-        return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
116
+        $query    = isset($url_bits['query']) ? '?'.$url_bits['query'] : '';
117
+        $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : '';
118
+        return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
119 119
     }
120 120
 
121 121
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         // grab query string from URL
136 136
         $query = isset($url_bits['query']) ? $url_bits['query'] : '';
137 137
         // if we don't want the query string formatted into an array of key => value pairs, then just return it as is
138
-        if (! $as_array) {
138
+        if ( ! $as_array) {
139 139
             return $query;
140 140
         }
141 141
         // if no query string exists then just return an empty array now
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
             // break apart the key value pairs
152 152
             $query_args = explode('=', $query_args);
153 153
             // and add to our results array
154
-            $query_params[ $query_args[0] ] = $query_args[1];
154
+            $query_params[$query_args[0]] = $query_args[1];
155 155
         }
156 156
         return $query_params;
157 157
     }
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public static function generate_unique_token($prefix = '')
182 182
     {
183
-        $token = md5(uniqid() . mt_rand());
184
-        return $prefix ? $prefix . '_' . $token : $token;
183
+        $token = md5(uniqid().mt_rand());
184
+        return $prefix ? $prefix.'_'.$token : $token;
185 185
     }
186 186
 
187 187
 
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
             'HTTP_HOST'   => 1,
202 202
             'PHP_SELF'    => 1,
203 203
         );
204
-        $server_variable  = strtoupper($server_variable);
204
+        $server_variable = strtoupper($server_variable);
205 205
         // whitelist INPUT_SERVER var
206
-        if (isset($server_variables[ $server_variable ])) {
206
+        if (isset($server_variables[$server_variable])) {
207 207
             $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE);
208 208
             if (empty($URL)) {
209 209
                 // fallback sanitization if the above fails
210
-                $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]);
210
+                $URL = wp_sanitize_redirect($_SERVER[$server_variable]);
211 211
             }
212 212
         }
213 213
         return $URL;
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
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.83.rc.003');
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.83.rc.003');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -27,270 +27,270 @@
 block discarded – undo
27 27
 class InvisibleRecaptcha
28 28
 {
29 29
 
30
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
30
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
31 31
 
32
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
32
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
33 33
 
34
-    /**
35
-     * @var EE_Registration_Config $config
36
-     */
37
-    private $config;
34
+	/**
35
+	 * @var EE_Registration_Config $config
36
+	 */
37
+	private $config;
38 38
 
39
-    /**
40
-     * @var EE_Session $session
41
-     */
42
-    private $session;
39
+	/**
40
+	 * @var EE_Session $session
41
+	 */
42
+	private $session;
43 43
 
44
-    /**
45
-     * @var boolean $recaptcha_passed
46
-     */
47
-    private $recaptcha_passed;
44
+	/**
45
+	 * @var boolean $recaptcha_passed
46
+	 */
47
+	private $recaptcha_passed;
48 48
 
49 49
 
50
-    /**
51
-     * InvisibleRecaptcha constructor.
52
-     *
53
-     * @param EE_Registration_Config $registration_config
54
-     * @param EE_Session             $session
55
-     */
56
-    public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
-    {
58
-        $this->config = $registration_config;
59
-        $this->session = $session;
60
-    }
50
+	/**
51
+	 * InvisibleRecaptcha constructor.
52
+	 *
53
+	 * @param EE_Registration_Config $registration_config
54
+	 * @param EE_Session             $session
55
+	 */
56
+	public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
57
+	{
58
+		$this->config = $registration_config;
59
+		$this->session = $session;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return boolean
65
-     */
66
-    public function useInvisibleRecaptcha()
67
-    {
68
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
-    }
63
+	/**
64
+	 * @return boolean
65
+	 */
66
+	public function useInvisibleRecaptcha()
67
+	{
68
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * @param array $input_settings
74
-     * @return EE_Invisible_Recaptcha_Input
75
-     * @throws InvalidDataTypeException
76
-     * @throws InvalidInterfaceException
77
-     * @throws InvalidArgumentException
78
-     * @throws DomainException
79
-     */
80
-    public function getInput(array $input_settings = array())
81
-    {
82
-        return new EE_Invisible_Recaptcha_Input(
83
-            $input_settings,
84
-            $this->config
85
-        );
86
-    }
72
+	/**
73
+	 * @param array $input_settings
74
+	 * @return EE_Invisible_Recaptcha_Input
75
+	 * @throws InvalidDataTypeException
76
+	 * @throws InvalidInterfaceException
77
+	 * @throws InvalidArgumentException
78
+	 * @throws DomainException
79
+	 */
80
+	public function getInput(array $input_settings = array())
81
+	{
82
+		return new EE_Invisible_Recaptcha_Input(
83
+			$input_settings,
84
+			$this->config
85
+		);
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * @param array $input_settings
91
-     * @return string
92
-     * @throws EE_Error
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidInterfaceException
95
-     * @throws InvalidArgumentException
96
-     * @throws DomainException
97
-     */
98
-    public function getInputHtml(array $input_settings = array())
99
-    {
100
-        return $this->getInput($input_settings)->get_html_for_input();
101
-    }
89
+	/**
90
+	 * @param array $input_settings
91
+	 * @return string
92
+	 * @throws EE_Error
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidInterfaceException
95
+	 * @throws InvalidArgumentException
96
+	 * @throws DomainException
97
+	 */
98
+	public function getInputHtml(array $input_settings = array())
99
+	{
100
+		return $this->getInput($input_settings)->get_html_for_input();
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @param EE_Form_Section_Proper $form
106
-     * @param array                  $input_settings
107
-     * @throws EE_Error
108
-     * @throws InvalidArgumentException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws DomainException
112
-     */
113
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
-    {
115
-        $form->add_subsections(
116
-            array(
117
-                'espresso_recaptcha' => $this->getInput($input_settings),
118
-            ),
119
-            null,
120
-            false
121
-        );
122
-    }
104
+	/**
105
+	 * @param EE_Form_Section_Proper $form
106
+	 * @param array                  $input_settings
107
+	 * @throws EE_Error
108
+	 * @throws InvalidArgumentException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws DomainException
112
+	 */
113
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
114
+	{
115
+		$form->add_subsections(
116
+			array(
117
+				'espresso_recaptcha' => $this->getInput($input_settings),
118
+			),
119
+			null,
120
+			false
121
+		);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * @param RequestInterface $request
127
-     * @return boolean
128
-     * @throws InvalidArgumentException
129
-     * @throws InvalidDataTypeException
130
-     * @throws InvalidInterfaceException
131
-     * @throws RuntimeException
132
-     */
133
-    public function verifyToken(RequestInterface $request)
134
-    {
135
-        static $previous_recaptcha_response = array();
136
-        $grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137
-        // if this token has already been verified, then return previous response
138
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
-            return $previous_recaptcha_response[ $grecaptcha_response ];
140
-        }
141
-        // still here but no g-recaptcha-response ? - verification failed
142
-        if (! $grecaptcha_response) {
143
-            EE_Error::add_error(
144
-                sprintf(
145
-                    /* translators: 1: missing parameter */
146
-                    esc_html__(
147
-                        // @codingStandardsIgnoreStart
148
-                        'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.',
149
-                        // @codingStandardsIgnoreEnd
150
-                        'event_espresso'
151
-                    ),
152
-                    'g-recaptcha-response'
153
-                ),
154
-                __FILE__,
155
-                __FUNCTION__,
156
-                __LINE__
157
-            );
158
-            return false;
159
-        }
160
-        // will update to true if everything passes
161
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
162
-        $response                                            = wp_safe_remote_post(
163
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164
-            array(
165
-                'body' => array(
166
-                    'secret'   => $this->config->recaptcha_privatekey,
167
-                    'response' => $grecaptcha_response,
168
-                    'remoteip' => $request->ipAddress(),
169
-                ),
170
-            )
171
-        );
172
-        if ($response instanceof WP_Error) {
173
-            $this->generateError($response->get_error_messages());
174
-            return false;
175
-        }
176
-        $results = json_decode(wp_remote_retrieve_body($response), true);
177
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
-            $errors   = array_map(
179
-                array($this, 'getErrorCode'),
180
-                $results['error-codes']
181
-            );
182
-            if (isset($results['challenge_ts'])) {
183
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
184
-            }
185
-            $this->generateError(implode(' ', $errors), true);
186
-        }
187
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
188
-        add_action('shutdown', array($this, 'setSessionData'));
189
-        return true;
190
-    }
125
+	/**
126
+	 * @param RequestInterface $request
127
+	 * @return boolean
128
+	 * @throws InvalidArgumentException
129
+	 * @throws InvalidDataTypeException
130
+	 * @throws InvalidInterfaceException
131
+	 * @throws RuntimeException
132
+	 */
133
+	public function verifyToken(RequestInterface $request)
134
+	{
135
+		static $previous_recaptcha_response = array();
136
+		$grecaptcha_response = $request->getRequestParam('g-recaptcha-response');
137
+		// if this token has already been verified, then return previous response
138
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
139
+			return $previous_recaptcha_response[ $grecaptcha_response ];
140
+		}
141
+		// still here but no g-recaptcha-response ? - verification failed
142
+		if (! $grecaptcha_response) {
143
+			EE_Error::add_error(
144
+				sprintf(
145
+					/* translators: 1: missing parameter */
146
+					esc_html__(
147
+						// @codingStandardsIgnoreStart
148
+						'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Missing "%1$s". Please try again.',
149
+						// @codingStandardsIgnoreEnd
150
+						'event_espresso'
151
+					),
152
+					'g-recaptcha-response'
153
+				),
154
+				__FILE__,
155
+				__FUNCTION__,
156
+				__LINE__
157
+			);
158
+			return false;
159
+		}
160
+		// will update to true if everything passes
161
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
162
+		$response                                            = wp_safe_remote_post(
163
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
164
+			array(
165
+				'body' => array(
166
+					'secret'   => $this->config->recaptcha_privatekey,
167
+					'response' => $grecaptcha_response,
168
+					'remoteip' => $request->ipAddress(),
169
+				),
170
+			)
171
+		);
172
+		if ($response instanceof WP_Error) {
173
+			$this->generateError($response->get_error_messages());
174
+			return false;
175
+		}
176
+		$results = json_decode(wp_remote_retrieve_body($response), true);
177
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
178
+			$errors   = array_map(
179
+				array($this, 'getErrorCode'),
180
+				$results['error-codes']
181
+			);
182
+			if (isset($results['challenge_ts'])) {
183
+				$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
184
+			}
185
+			$this->generateError(implode(' ', $errors), true);
186
+		}
187
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
188
+		add_action('shutdown', array($this, 'setSessionData'));
189
+		return true;
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * @param string $error_response
195
-     * @param bool   $show_errors
196
-     * @return void
197
-     * @throws RuntimeException
198
-     */
199
-    public function generateError($error_response = '', $show_errors = false)
200
-    {
201
-        throw new RuntimeException(
202
-            sprintf(
203
-                esc_html__(
204
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
205
-                    'event_espresso'
206
-                ),
207
-                '<br />',
208
-                $show_errors || current_user_can('manage_options') ? $error_response : ''
209
-            )
210
-        );
211
-    }
193
+	/**
194
+	 * @param string $error_response
195
+	 * @param bool   $show_errors
196
+	 * @return void
197
+	 * @throws RuntimeException
198
+	 */
199
+	public function generateError($error_response = '', $show_errors = false)
200
+	{
201
+		throw new RuntimeException(
202
+			sprintf(
203
+				esc_html__(
204
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
205
+					'event_espresso'
206
+				),
207
+				'<br />',
208
+				$show_errors || current_user_can('manage_options') ? $error_response : ''
209
+			)
210
+		);
211
+	}
212 212
 
213 213
 
214
-    /**
215
-     * @param string $error_code
216
-     * @return string
217
-     */
218
-    public function getErrorCode(&$error_code)
219
-    {
220
-        $error_codes = array(
221
-            'missing-input-secret'   => 'The secret parameter is missing.',
222
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
223
-            'missing-input-response' => 'The response parameter is missing.',
224
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
225
-            'bad-request'            => 'The request is invalid or malformed.',
226
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227
-        );
228
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
229
-    }
214
+	/**
215
+	 * @param string $error_code
216
+	 * @return string
217
+	 */
218
+	public function getErrorCode(&$error_code)
219
+	{
220
+		$error_codes = array(
221
+			'missing-input-secret'   => 'The secret parameter is missing.',
222
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
223
+			'missing-input-response' => 'The response parameter is missing.',
224
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
225
+			'bad-request'            => 'The request is invalid or malformed.',
226
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
227
+		);
228
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
229
+	}
230 230
 
231 231
 
232
-    /**
233
-     * @return array
234
-     * @throws InvalidInterfaceException
235
-     * @throws InvalidDataTypeException
236
-     * @throws InvalidArgumentException
237
-     */
238
-    public function getLocalizedVars()
239
-    {
240
-        return (array) apply_filters(
241
-            'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
242
-            array(
243
-                'siteKey'          => $this->config->recaptcha_publickey,
244
-                'recaptcha_passed' => $this->recaptchaPassed(),
245
-                'wp_debug'         => WP_DEBUG,
246
-                'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
247
-                'failed_message'   => wp_strip_all_tags(
248
-                    __(
249
-                        'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.',
250
-                        'event_espresso'
251
-                    )
252
-                )
253
-            )
254
-        );
255
-    }
232
+	/**
233
+	 * @return array
234
+	 * @throws InvalidInterfaceException
235
+	 * @throws InvalidDataTypeException
236
+	 * @throws InvalidArgumentException
237
+	 */
238
+	public function getLocalizedVars()
239
+	{
240
+		return (array) apply_filters(
241
+			'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
242
+			array(
243
+				'siteKey'          => $this->config->recaptcha_publickey,
244
+				'recaptcha_passed' => $this->recaptchaPassed(),
245
+				'wp_debug'         => WP_DEBUG,
246
+				'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
247
+				'failed_message'   => wp_strip_all_tags(
248
+					__(
249
+						'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. Please try again.',
250
+						'event_espresso'
251
+					)
252
+				)
253
+			)
254
+		);
255
+	}
256 256
 
257 257
 
258
-    /**
259
-     * @return boolean
260
-     * @throws InvalidInterfaceException
261
-     * @throws InvalidDataTypeException
262
-     * @throws InvalidArgumentException
263
-     */
264
-    public function recaptchaPassed()
265
-    {
266
-        if ($this->recaptcha_passed !== null) {
267
-            return $this->recaptcha_passed;
268
-        }
269
-        // logged in means you have already passed a turing test of sorts
270
-        if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
271
-            $this->recaptcha_passed = true;
272
-            return $this->recaptcha_passed;
273
-        }
274
-        // was test already passed?
275
-        $this->recaptcha_passed = filter_var(
276
-            $this->session->get_session_data(
277
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
278
-            ),
279
-            FILTER_VALIDATE_BOOLEAN
280
-        );
281
-        return $this->recaptcha_passed;
282
-    }
258
+	/**
259
+	 * @return boolean
260
+	 * @throws InvalidInterfaceException
261
+	 * @throws InvalidDataTypeException
262
+	 * @throws InvalidArgumentException
263
+	 */
264
+	public function recaptchaPassed()
265
+	{
266
+		if ($this->recaptcha_passed !== null) {
267
+			return $this->recaptcha_passed;
268
+		}
269
+		// logged in means you have already passed a turing test of sorts
270
+		if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
271
+			$this->recaptcha_passed = true;
272
+			return $this->recaptcha_passed;
273
+		}
274
+		// was test already passed?
275
+		$this->recaptcha_passed = filter_var(
276
+			$this->session->get_session_data(
277
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
278
+			),
279
+			FILTER_VALIDATE_BOOLEAN
280
+		);
281
+		return $this->recaptcha_passed;
282
+	}
283 283
 
284 284
 
285
-    /**
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidDataTypeException
288
-     * @throws InvalidInterfaceException
289
-     */
290
-    public function setSessionData()
291
-    {
292
-        $this->session->set_session_data(
293
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
294
-        );
295
-    }
285
+	/**
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidDataTypeException
288
+	 * @throws InvalidInterfaceException
289
+	 */
290
+	public function setSessionData()
291
+	{
292
+		$this->session->set_session_data(
293
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
294
+		);
295
+	}
296 296
 }
Please login to merge, or discard this patch.
modules/batch/EED_Batch.module.php 2 patches
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -29,360 +29,360 @@
 block discarded – undo
29 29
 class EED_Batch extends EED_Module
30 30
 {
31 31
 
32
-    /**
33
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
34
-     * processes data only
35
-     */
36
-    const batch_job = 'job';
37
-    /**
38
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
39
-     * produces a file for download
40
-     */
41
-    const batch_file_job = 'file';
42
-    /**
43
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
44
-     * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
45
-     * at all
46
-     */
47
-    const batch_not_job = 'none';
32
+	/**
33
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
34
+	 * processes data only
35
+	 */
36
+	const batch_job = 'job';
37
+	/**
38
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
39
+	 * produces a file for download
40
+	 */
41
+	const batch_file_job = 'file';
42
+	/**
43
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
44
+	 * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
45
+	 * at all
46
+	 */
47
+	const batch_not_job = 'none';
48 48
 
49
-    /**
50
-     *
51
-     * @var string 'file', or 'job', or false to indicate its not a batch request at all
52
-     */
53
-    protected $_batch_request_type = null;
49
+	/**
50
+	 *
51
+	 * @var string 'file', or 'job', or false to indicate its not a batch request at all
52
+	 */
53
+	protected $_batch_request_type = null;
54 54
 
55
-    /**
56
-     * Because we want to use the response in both the localized JS and in the body
57
-     * we need to make this response available between method calls
58
-     *
59
-     * @var \EventEspressoBatchRequest\Helpers\JobStepResponse
60
-     */
61
-    protected $_job_step_response = null;
55
+	/**
56
+	 * Because we want to use the response in both the localized JS and in the body
57
+	 * we need to make this response available between method calls
58
+	 *
59
+	 * @var \EventEspressoBatchRequest\Helpers\JobStepResponse
60
+	 */
61
+	protected $_job_step_response = null;
62 62
 
63
-    /**
64
-     * @var LoaderInterface
65
-     */
66
-    protected $loader;
63
+	/**
64
+	 * @var LoaderInterface
65
+	 */
66
+	protected $loader;
67 67
 
68
-    /**
69
-     * Gets the batch instance
70
-     *
71
-     * @return EED_Batch
72
-     */
73
-    public static function instance()
74
-    {
75
-        return self::get_instance();
76
-    }
68
+	/**
69
+	 * Gets the batch instance
70
+	 *
71
+	 * @return EED_Batch
72
+	 */
73
+	public static function instance()
74
+	{
75
+		return self::get_instance();
76
+	}
77 77
 
78
-    /**
79
-     * Sets hooks to enable batch jobs on the frontend. Disabled by default
80
-     * because it's an attack vector and there are currently no implementations
81
-     */
82
-    public static function set_hooks()
83
-    {
84
-        // because this is a possibel attack vector, let's have this disabled until
85
-        // we at least have a real use for it on the frontend
86
-        if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
87
-            add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
88
-            add_filter('template_include', array(self::instance(), 'override_template'), 99);
89
-        }
90
-    }
78
+	/**
79
+	 * Sets hooks to enable batch jobs on the frontend. Disabled by default
80
+	 * because it's an attack vector and there are currently no implementations
81
+	 */
82
+	public static function set_hooks()
83
+	{
84
+		// because this is a possibel attack vector, let's have this disabled until
85
+		// we at least have a real use for it on the frontend
86
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
87
+			add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
88
+			add_filter('template_include', array(self::instance(), 'override_template'), 99);
89
+		}
90
+	}
91 91
 
92
-    /**
93
-     * Initializes some hooks for the admin in order to run batch jobs
94
-     */
95
-    public static function set_hooks_admin()
96
-    {
97
-        add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
98
-        add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
92
+	/**
93
+	 * Initializes some hooks for the admin in order to run batch jobs
94
+	 */
95
+	public static function set_hooks_admin()
96
+	{
97
+		add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
98
+		add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
99 99
 
100
-        // ajax
101
-        add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
102
-        add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
103
-        add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
104
-        add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
105
-    }
100
+		// ajax
101
+		add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
102
+		add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
103
+		add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
104
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
105
+	}
106 106
 
107
-    /**
108
-     * @since 4.9.80.p
109
-     * @return LoaderInterface
110
-     * @throws InvalidArgumentException
111
-     * @throws InvalidDataTypeException
112
-     * @throws InvalidInterfaceException
113
-     */
114
-    protected function getLoader()
115
-    {
116
-        if (!$this->loader instanceof LoaderInterface) {
117
-            $this->loader = LoaderFactory::getLoader();
118
-        }
119
-        return $this->loader;
120
-    }
107
+	/**
108
+	 * @since 4.9.80.p
109
+	 * @return LoaderInterface
110
+	 * @throws InvalidArgumentException
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws InvalidInterfaceException
113
+	 */
114
+	protected function getLoader()
115
+	{
116
+		if (!$this->loader instanceof LoaderInterface) {
117
+			$this->loader = LoaderFactory::getLoader();
118
+		}
119
+		return $this->loader;
120
+	}
121 121
 
122
-    /**
123
-     * Enqueues batch scripts on the frontend or admin, and creates a job
124
-     */
125
-    public function enqueue_scripts()
126
-    {
127
-        if (isset($_REQUEST['espresso_batch'])
128
-            ||
129
-            (
130
-                isset($_REQUEST['page'])
131
-                && $_REQUEST['page'] == 'espresso_batch'
132
-            )
133
-        ) {
134
-            if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
135
-                wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso'));
136
-            }
137
-            switch ($this->batch_request_type()) {
138
-                case self::batch_job:
139
-                    $this->enqueue_scripts_styles_batch_create();
140
-                    break;
141
-                case self::batch_file_job:
142
-                    $this->enqueue_scripts_styles_batch_file_create();
143
-                    break;
144
-            }
145
-        }
146
-    }
122
+	/**
123
+	 * Enqueues batch scripts on the frontend or admin, and creates a job
124
+	 */
125
+	public function enqueue_scripts()
126
+	{
127
+		if (isset($_REQUEST['espresso_batch'])
128
+			||
129
+			(
130
+				isset($_REQUEST['page'])
131
+				&& $_REQUEST['page'] == 'espresso_batch'
132
+			)
133
+		) {
134
+			if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
135
+				wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso'));
136
+			}
137
+			switch ($this->batch_request_type()) {
138
+				case self::batch_job:
139
+					$this->enqueue_scripts_styles_batch_create();
140
+					break;
141
+				case self::batch_file_job:
142
+					$this->enqueue_scripts_styles_batch_file_create();
143
+					break;
144
+			}
145
+		}
146
+	}
147 147
 
148
-    /**
149
-     * Create a batch job, enqueues a script to run it, and localizes some data for it
150
-     */
151
-    public function enqueue_scripts_styles_batch_create()
152
-    {
153
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
154
-        wp_enqueue_script(
155
-            'batch_runner_init',
156
-            BATCH_URL . 'assets/batch_runner_init.js',
157
-            array('batch_runner'),
158
-            EVENT_ESPRESSO_VERSION,
159
-            true
160
-        );
161
-        wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
162
-        wp_localize_script(
163
-            'batch_runner_init',
164
-            'ee_job_i18n',
165
-            array(
166
-                'return_url' => $_REQUEST['return_url'],
167
-            )
168
-        );
169
-    }
148
+	/**
149
+	 * Create a batch job, enqueues a script to run it, and localizes some data for it
150
+	 */
151
+	public function enqueue_scripts_styles_batch_create()
152
+	{
153
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
154
+		wp_enqueue_script(
155
+			'batch_runner_init',
156
+			BATCH_URL . 'assets/batch_runner_init.js',
157
+			array('batch_runner'),
158
+			EVENT_ESPRESSO_VERSION,
159
+			true
160
+		);
161
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
162
+		wp_localize_script(
163
+			'batch_runner_init',
164
+			'ee_job_i18n',
165
+			array(
166
+				'return_url' => $_REQUEST['return_url'],
167
+			)
168
+		);
169
+	}
170 170
 
171
-    /**
172
-     * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
173
-     */
174
-    public function enqueue_scripts_styles_batch_file_create()
175
-    {
176
-        // creates a job based on the request variable
177
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
178
-        wp_enqueue_script(
179
-            'batch_file_runner_init',
180
-            BATCH_URL . 'assets/batch_file_runner_init.js',
181
-            array('batch_runner'),
182
-            EVENT_ESPRESSO_VERSION,
183
-            true
184
-        );
185
-        wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
186
-        wp_localize_script(
187
-            'batch_file_runner_init',
188
-            'ee_job_i18n',
189
-            array(
190
-                'download_and_redirecting' => sprintf(
191
-                    wp_strip_all_tags(
192
-                        __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
193
-                    ),
194
-                    '<a href="' . $_REQUEST['return_url'] . '">',
195
-                    '</a>'
196
-                ),
197
-                'return_url'               => $_REQUEST['return_url'],
198
-            )
199
-        );
200
-    }
171
+	/**
172
+	 * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
173
+	 */
174
+	public function enqueue_scripts_styles_batch_file_create()
175
+	{
176
+		// creates a job based on the request variable
177
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
178
+		wp_enqueue_script(
179
+			'batch_file_runner_init',
180
+			BATCH_URL . 'assets/batch_file_runner_init.js',
181
+			array('batch_runner'),
182
+			EVENT_ESPRESSO_VERSION,
183
+			true
184
+		);
185
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
186
+		wp_localize_script(
187
+			'batch_file_runner_init',
188
+			'ee_job_i18n',
189
+			array(
190
+				'download_and_redirecting' => sprintf(
191
+					wp_strip_all_tags(
192
+						__('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
193
+					),
194
+					'<a href="' . $_REQUEST['return_url'] . '">',
195
+					'</a>'
196
+				),
197
+				'return_url'               => $_REQUEST['return_url'],
198
+			)
199
+		);
200
+	}
201 201
 
202
-    /**
203
-     * Enqueues scripts and styles common to any batch job, and creates
204
-     * a job from the request data, and stores the response in the
205
-     * $this->_job_step_response property
206
-     *
207
-     * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
208
-     */
209
-    protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
210
-    {
211
-        // just copy the bits of EE admin's eei18n that we need in the JS
212
-        EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
213
-            'An error occurred and the job has been stopped. Please refresh the page to try again.',
214
-            'event_espresso'
215
-        );
216
-        wp_register_script(
217
-            'progress_bar',
218
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
219
-            array('jquery'),
220
-            EVENT_ESPRESSO_VERSION,
221
-            true
222
-        );
223
-        wp_enqueue_style(
224
-            'progress_bar',
225
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
226
-            array(),
227
-            EVENT_ESPRESSO_VERSION
228
-        );
229
-        wp_enqueue_script(
230
-            'batch_runner',
231
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
232
-            array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
233
-            EVENT_ESPRESSO_VERSION,
234
-            true
235
-        );
236
-        $job_handler_classname = stripslashes($_GET['job_handler']);
237
-        $request_data = array_diff_key(
238
-            $_REQUEST,
239
-            array_flip(array('action', 'page', 'ee', 'batch'))
240
-        );
241
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
242
-        // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
243
-        $job_response = $batch_runner->create_job($job_handler_classname, $request_data);
244
-        // remember the response for later. We need it to display the page body
245
-        $this->_job_step_response = $job_response;
246
-        return $job_response;
247
-    }
202
+	/**
203
+	 * Enqueues scripts and styles common to any batch job, and creates
204
+	 * a job from the request data, and stores the response in the
205
+	 * $this->_job_step_response property
206
+	 *
207
+	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
208
+	 */
209
+	protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
210
+	{
211
+		// just copy the bits of EE admin's eei18n that we need in the JS
212
+		EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
213
+			'An error occurred and the job has been stopped. Please refresh the page to try again.',
214
+			'event_espresso'
215
+		);
216
+		wp_register_script(
217
+			'progress_bar',
218
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
219
+			array('jquery'),
220
+			EVENT_ESPRESSO_VERSION,
221
+			true
222
+		);
223
+		wp_enqueue_style(
224
+			'progress_bar',
225
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
226
+			array(),
227
+			EVENT_ESPRESSO_VERSION
228
+		);
229
+		wp_enqueue_script(
230
+			'batch_runner',
231
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
232
+			array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
233
+			EVENT_ESPRESSO_VERSION,
234
+			true
235
+		);
236
+		$job_handler_classname = stripslashes($_GET['job_handler']);
237
+		$request_data = array_diff_key(
238
+			$_REQUEST,
239
+			array_flip(array('action', 'page', 'ee', 'batch'))
240
+		);
241
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
242
+		// eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
243
+		$job_response = $batch_runner->create_job($job_handler_classname, $request_data);
244
+		// remember the response for later. We need it to display the page body
245
+		$this->_job_step_response = $job_response;
246
+		return $job_response;
247
+	}
248 248
 
249
-    /**
250
-     * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
251
-     *
252
-     * @param string $template
253
-     * @return string
254
-     */
255
-    public function override_template($template)
256
-    {
257
-        if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
258
-            return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
259
-        }
260
-        return $template;
261
-    }
249
+	/**
250
+	 * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
251
+	 *
252
+	 * @param string $template
253
+	 * @return string
254
+	 */
255
+	public function override_template($template)
256
+	{
257
+		if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
258
+			return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
259
+		}
260
+		return $template;
261
+	}
262 262
 
263
-    /**
264
-     * Adds an admin page which doesn't appear in the admin menu
265
-     */
266
-    public function register_admin_pages()
267
-    {
268
-        add_submenu_page(
269
-            '', // parent slug. we don't want this to actually appear in the menu
270
-            __('Batch Job', 'event_espresso'), // page title
271
-            'n/a', // menu title
272
-            'read', // we want this page to actually be accessible to anyone,
273
-            'espresso_batch', // menu slug
274
-            array(self::instance(), 'show_admin_page')
275
-        );
276
-    }
263
+	/**
264
+	 * Adds an admin page which doesn't appear in the admin menu
265
+	 */
266
+	public function register_admin_pages()
267
+	{
268
+		add_submenu_page(
269
+			'', // parent slug. we don't want this to actually appear in the menu
270
+			__('Batch Job', 'event_espresso'), // page title
271
+			'n/a', // menu title
272
+			'read', // we want this page to actually be accessible to anyone,
273
+			'espresso_batch', // menu slug
274
+			array(self::instance(), 'show_admin_page')
275
+		);
276
+	}
277 277
 
278
-    /**
279
-     * Renders the admin page, after most of the work was already done during enqueuing scripts
280
-     * of creating the job and localizing some data
281
-     */
282
-    public function show_admin_page()
283
-    {
284
-        echo EEH_Template::locate_template(
285
-            EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html',
286
-            array('batch_request_type' => $this->batch_request_type())
287
-        );
288
-    }
278
+	/**
279
+	 * Renders the admin page, after most of the work was already done during enqueuing scripts
280
+	 * of creating the job and localizing some data
281
+	 */
282
+	public function show_admin_page()
283
+	{
284
+		echo EEH_Template::locate_template(
285
+			EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html',
286
+			array('batch_request_type' => $this->batch_request_type())
287
+		);
288
+	}
289 289
 
290
-    /**
291
-     * Receives ajax calls for continuing a job
292
-     */
293
-    public function batch_continue()
294
-    {
295
-        $job_id = sanitize_text_field($_REQUEST['job_id']);
296
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
297
-        $response_obj = $batch_runner->continue_job($job_id);
298
-        $this->_return_json($response_obj->to_array());
299
-    }
290
+	/**
291
+	 * Receives ajax calls for continuing a job
292
+	 */
293
+	public function batch_continue()
294
+	{
295
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
296
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
297
+		$response_obj = $batch_runner->continue_job($job_id);
298
+		$this->_return_json($response_obj->to_array());
299
+	}
300 300
 
301
-    /**
302
-     * Receives the ajax call to cleanup a job
303
-     *
304
-     * @return type
305
-     */
306
-    public function batch_cleanup()
307
-    {
308
-        $job_id = sanitize_text_field($_REQUEST['job_id']);
309
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
310
-        $response_obj = $batch_runner->cleanup_job($job_id);
311
-        $this->_return_json($response_obj->to_array());
312
-    }
301
+	/**
302
+	 * Receives the ajax call to cleanup a job
303
+	 *
304
+	 * @return type
305
+	 */
306
+	public function batch_cleanup()
307
+	{
308
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
309
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
310
+		$response_obj = $batch_runner->cleanup_job($job_id);
311
+		$this->_return_json($response_obj->to_array());
312
+	}
313 313
 
314 314
 
315
-    /**
316
-     * Returns a json response
317
-     *
318
-     * @param array $data The data we want to send echo via in the JSON response's "data" element
319
-     *
320
-     * The returned json object is created from an array in the following format:
321
-     * array(
322
-     *    'notices' => '', // - contains any EE_Error formatted notices
323
-     *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
324
-     *    We're also going to include the template args with every package (so js can pick out any specific template
325
-     *    args that might be included in here)
326
-     *    'isEEajax' => true,//indicates this is a response from EE
327
-     * )
328
-     */
329
-    protected function _return_json($data)
330
-    {
331
-        $json = array(
332
-            'notices'  => EE_Error::get_notices(),
333
-            'data'     => $data,
334
-            'isEEajax' => true
335
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
336
-        );
315
+	/**
316
+	 * Returns a json response
317
+	 *
318
+	 * @param array $data The data we want to send echo via in the JSON response's "data" element
319
+	 *
320
+	 * The returned json object is created from an array in the following format:
321
+	 * array(
322
+	 *    'notices' => '', // - contains any EE_Error formatted notices
323
+	 *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
324
+	 *    We're also going to include the template args with every package (so js can pick out any specific template
325
+	 *    args that might be included in here)
326
+	 *    'isEEajax' => true,//indicates this is a response from EE
327
+	 * )
328
+	 */
329
+	protected function _return_json($data)
330
+	{
331
+		$json = array(
332
+			'notices'  => EE_Error::get_notices(),
333
+			'data'     => $data,
334
+			'isEEajax' => true
335
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
336
+		);
337 337
 
338 338
 
339
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
340
-        if (null === error_get_last() || ! headers_sent()) {
341
-            header('Content-Type: application/json; charset=UTF-8');
342
-        }
343
-        echo wp_json_encode($json);
344
-        exit();
345
-    }
339
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
340
+		if (null === error_get_last() || ! headers_sent()) {
341
+			header('Content-Type: application/json; charset=UTF-8');
342
+		}
343
+		echo wp_json_encode($json);
344
+		exit();
345
+	}
346 346
 
347
-    /**
348
-     * Gets the job step response which was done during the enqueuing of scripts
349
-     *
350
-     * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
351
-     */
352
-    public function job_step_response()
353
-    {
354
-        return $this->_job_step_response;
355
-    }
347
+	/**
348
+	 * Gets the job step response which was done during the enqueuing of scripts
349
+	 *
350
+	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
351
+	 */
352
+	public function job_step_response()
353
+	{
354
+		return $this->_job_step_response;
355
+	}
356 356
 
357
-    /**
358
-     * Gets the batch request type indicated in the $_REQUEST
359
-     *
360
-     * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
361
-     */
362
-    public function batch_request_type()
363
-    {
364
-        if ($this->_batch_request_type === null) {
365
-            if (isset($_GET['batch'])) {
366
-                if ($_GET['batch'] == self::batch_job) {
367
-                    $this->_batch_request_type = self::batch_job;
368
-                } elseif ($_GET['batch'] == self::batch_file_job) {
369
-                    $this->_batch_request_type = self::batch_file_job;
370
-                }
371
-            }
372
-            // if we didn't find that it was a batch request, indicate it wasn't
373
-            if ($this->_batch_request_type === null) {
374
-                $this->_batch_request_type = self::batch_not_job;
375
-            }
376
-        }
377
-        return $this->_batch_request_type;
378
-    }
357
+	/**
358
+	 * Gets the batch request type indicated in the $_REQUEST
359
+	 *
360
+	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
361
+	 */
362
+	public function batch_request_type()
363
+	{
364
+		if ($this->_batch_request_type === null) {
365
+			if (isset($_GET['batch'])) {
366
+				if ($_GET['batch'] == self::batch_job) {
367
+					$this->_batch_request_type = self::batch_job;
368
+				} elseif ($_GET['batch'] == self::batch_file_job) {
369
+					$this->_batch_request_type = self::batch_file_job;
370
+				}
371
+			}
372
+			// if we didn't find that it was a batch request, indicate it wasn't
373
+			if ($this->_batch_request_type === null) {
374
+				$this->_batch_request_type = self::batch_not_job;
375
+			}
376
+		}
377
+		return $this->_batch_request_type;
378
+	}
379 379
 
380
-    /**
381
-     * Unnecessary
382
-     *
383
-     * @param type $WP
384
-     */
385
-    public function run($WP)
386
-    {
387
-    }
380
+	/**
381
+	 * Unnecessary
382
+	 *
383
+	 * @param type $WP
384
+	 */
385
+	public function run($WP)
386
+	{
387
+	}
388 388
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     protected function getLoader()
115 115
     {
116
-        if (!$this->loader instanceof LoaderInterface) {
116
+        if ( ! $this->loader instanceof LoaderInterface) {
117 117
             $this->loader = LoaderFactory::getLoader();
118 118
         }
119 119
         return $this->loader;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
                 && $_REQUEST['page'] == 'espresso_batch'
132 132
             )
133 133
         ) {
134
-            if (! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
134
+            if ( ! isset($_REQUEST['default_nonce']) || ! wp_verify_nonce($_REQUEST['default_nonce'], 'default_nonce')) {
135 135
                 wp_die(esc_html__('The link you clicked to start the batch job has expired. Please go back and refresh the previous page.', 'event_espresso'));
136 136
             }
137 137
             switch ($this->batch_request_type()) {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
154 154
         wp_enqueue_script(
155 155
             'batch_runner_init',
156
-            BATCH_URL . 'assets/batch_runner_init.js',
156
+            BATCH_URL.'assets/batch_runner_init.js',
157 157
             array('batch_runner'),
158 158
             EVENT_ESPRESSO_VERSION,
159 159
             true
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
178 178
         wp_enqueue_script(
179 179
             'batch_file_runner_init',
180
-            BATCH_URL . 'assets/batch_file_runner_init.js',
180
+            BATCH_URL.'assets/batch_file_runner_init.js',
181 181
             array('batch_runner'),
182 182
             EVENT_ESPRESSO_VERSION,
183 183
             true
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     wp_strip_all_tags(
192 192
                         __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso')
193 193
                     ),
194
-                    '<a href="' . $_REQUEST['return_url'] . '">',
194
+                    '<a href="'.$_REQUEST['return_url'].'">',
195 195
                     '</a>'
196 196
                 ),
197 197
                 'return_url'               => $_REQUEST['return_url'],
@@ -209,26 +209,26 @@  discard block
 block discarded – undo
209 209
     protected function _enqueue_batch_job_scripts_and_styles_and_start_job()
210 210
     {
211 211
         // just copy the bits of EE admin's eei18n that we need in the JS
212
-        EE_Registry::$i18n_js_strings['batchJobError'] =  esc_html__(
212
+        EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__(
213 213
             'An error occurred and the job has been stopped. Please refresh the page to try again.',
214 214
             'event_espresso'
215 215
         );
216 216
         wp_register_script(
217 217
             'progress_bar',
218
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
218
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js',
219 219
             array('jquery'),
220 220
             EVENT_ESPRESSO_VERSION,
221 221
             true
222 222
         );
223 223
         wp_enqueue_style(
224 224
             'progress_bar',
225
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
225
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css',
226 226
             array(),
227 227
             EVENT_ESPRESSO_VERSION
228 228
         );
229 229
         wp_enqueue_script(
230 230
             'batch_runner',
231
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
231
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js',
232 232
             array('progress_bar', CoreAssetManager::JS_HANDLE_CORE),
233 233
             EVENT_ESPRESSO_VERSION,
234 234
             true
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     public function override_template($template)
256 256
     {
257 257
         if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
258
-            return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
258
+            return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html';
259 259
         }
260 260
         return $template;
261 261
     }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
     public function show_admin_page()
283 283
     {
284 284
         echo EEH_Template::locate_template(
285
-            EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html',
285
+            EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html',
286 286
             array('batch_request_type' => $this->batch_request_type())
287 287
         );
288 288
     }
Please login to merge, or discard this patch.