Completed
Branch BUG/11302/correct-error-messag... (694f28)
by
unknown
29:59 queued 17:10
created
core/db_classes/EE_Ticket.class.php 2 patches
Indentation   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * @param array  $props_n_values          incoming values
66
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
-     *                                        used.)
68
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
-     *                                        date_format and the second value is the time format
70
-     * @return EE_Ticket
71
-     * @throws \EE_Error
72
-     */
64
+	/**
65
+	 * @param array  $props_n_values          incoming values
66
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
+	 *                                        used.)
68
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
+	 *                                        date_format and the second value is the time format
70
+	 * @return EE_Ticket
71
+	 * @throws \EE_Error
72
+	 */
73 73
 	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74 74
 		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75 75
 		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
@@ -77,36 +77,36 @@  discard block
 block discarded – undo
77 77
 
78 78
 
79 79
 
80
-    /**
81
-     * @param array  $props_n_values  incoming values from the database
82
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
-     *                                the website will be used.
84
-     * @return EE_Ticket
85
-     * @throws \EE_Error
86
-     */
80
+	/**
81
+	 * @param array  $props_n_values  incoming values from the database
82
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
+	 *                                the website will be used.
84
+	 * @return EE_Ticket
85
+	 * @throws \EE_Error
86
+	 */
87 87
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88 88
 		return new self( $props_n_values, TRUE, $timezone );
89 89
 	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     * @throws \EE_Error
96
-     */
93
+	/**
94
+	 * @return bool
95
+	 * @throws \EE_Error
96
+	 */
97 97
 	public function parent() {
98 98
 		return $this->get( 'TKT_parent' );
99 99
 	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * return if a ticket has quantities available for purchase
105
-     *
106
-     * @param  int $DTT_ID the primary key for a particular datetime
107
-     * @return boolean
108
-     * @throws \EE_Error
109
-     */
103
+	/**
104
+	 * return if a ticket has quantities available for purchase
105
+	 *
106
+	 * @param  int $DTT_ID the primary key for a particular datetime
107
+	 * @return boolean
108
+	 * @throws \EE_Error
109
+	 */
110 110
 	public function available( $DTT_ID = 0 ) {
111 111
 		// are we checking availability for a particular datetime ?
112 112
 		if ( $DTT_ID ) {
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
-     *
129
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
-     * @return mixed status int if the display string isn't requested
132
-     * @throws \EE_Error
133
-     */
126
+	/**
127
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
+	 *
129
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
+	 * @return mixed status int if the display string isn't requested
132
+	 * @throws \EE_Error
133
+	 */
134 134
 	public function ticket_status( $display = FALSE, $remaining = null ) {
135 135
 		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136 136
 		if ( ! $remaining ) {
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
-     *
159
-     * @access public
160
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
-     * @return boolean         true = tickets remaining, false not.
162
-     * @throws \EE_Error
163
-     */
156
+	/**
157
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
+	 *
159
+	 * @access public
160
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
+	 * @return boolean         true = tickets remaining, false not.
162
+	 * @throws \EE_Error
163
+	 */
164 164
 	public function is_remaining( $DTT_ID = 0 ) {
165 165
 		$num_remaining = $this->remaining( $DTT_ID );
166 166
 		if ( $num_remaining === 0 ) {
@@ -174,76 +174,76 @@  discard block
 block discarded – undo
174 174
 
175 175
 
176 176
 
177
-    /**
178
-     * return the total number of tickets available for purchase
179
-     *
180
-     * @param  int $DTT_ID the primary key for a particular datetime.
181
-     *                     set to 0 for all related datetimes
182
-     * @return int
183
-     * @throws \EE_Error
184
-     */
177
+	/**
178
+	 * return the total number of tickets available for purchase
179
+	 *
180
+	 * @param  int $DTT_ID the primary key for a particular datetime.
181
+	 *                     set to 0 for all related datetimes
182
+	 * @return int
183
+	 * @throws \EE_Error
184
+	 */
185 185
 	public function remaining( $DTT_ID = 0 ) {
186 186
 		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
187 187
 	}
188 188
 
189 189
 
190 190
 
191
-    /**
192
-     * Gets min
193
-     *
194
-     * @return int
195
-     * @throws \EE_Error
196
-     */
191
+	/**
192
+	 * Gets min
193
+	 *
194
+	 * @return int
195
+	 * @throws \EE_Error
196
+	 */
197 197
 	public function min() {
198 198
 		return $this->get( 'TKT_min' );
199 199
 	}
200 200
 
201 201
 
202 202
 
203
-    /**
204
-     * return if a ticket is no longer available cause its available dates have expired.
205
-     *
206
-     * @return boolean
207
-     * @throws \EE_Error
208
-     */
203
+	/**
204
+	 * return if a ticket is no longer available cause its available dates have expired.
205
+	 *
206
+	 * @return boolean
207
+	 * @throws \EE_Error
208
+	 */
209 209
 	public function is_expired() {
210 210
 		return ( $this->get_raw( 'TKT_end_date' ) < time() );
211 211
 	}
212 212
 
213 213
 
214 214
 
215
-    /**
216
-     * Return if a ticket is yet to go on sale or not
217
-     *
218
-     * @return boolean
219
-     * @throws \EE_Error
220
-     */
215
+	/**
216
+	 * Return if a ticket is yet to go on sale or not
217
+	 *
218
+	 * @return boolean
219
+	 * @throws \EE_Error
220
+	 */
221 221
 	public function is_pending() {
222 222
 		return ( $this->get_raw( 'TKT_start_date' ) > time() );
223 223
 	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Return if a ticket is on sale or not
229
-     *
230
-     * @return boolean
231
-     * @throws \EE_Error
232
-     */
227
+	/**
228
+	 * Return if a ticket is on sale or not
229
+	 *
230
+	 * @return boolean
231
+	 * @throws \EE_Error
232
+	 */
233 233
 	public function is_on_sale() {
234 234
 		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
235 235
 	}
236 236
 
237 237
 
238 238
 
239
-    /**
240
-     * This returns the chronologically last datetime that this ticket is associated with
241
-     *
242
-     * @param string $dt_frmt
243
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
-     * @return string
245
-     * @throws \EE_Error
246
-     */
239
+	/**
240
+	 * This returns the chronologically last datetime that this ticket is associated with
241
+	 *
242
+	 * @param string $dt_frmt
243
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
+	 * @return string
245
+	 * @throws \EE_Error
246
+	 */
247 247
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248 248
 		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249 249
 		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     * This returns the chronologically first datetime that this ticket is associated with
258
-     *
259
-     * @return EE_Datetime
260
-     * @throws \EE_Error
261
-     */
256
+	/**
257
+	 * This returns the chronologically first datetime that this ticket is associated with
258
+	 *
259
+	 * @return EE_Datetime
260
+	 * @throws \EE_Error
261
+	 */
262 262
 	public function first_datetime() {
263 263
 		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264 264
 		return reset( $datetimes );
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 
267 267
 
268 268
 
269
-    /**
270
-     * Gets all the datetimes this ticket can be used for attending.
271
-     * Unless otherwise specified, orders datetimes by start date.
272
-     *
273
-     * @param array $query_params see EEM_Base::get_all()
274
-     * @return EE_Datetime[]|EE_Base_Class[]
275
-     * @throws \EE_Error
276
-     */
269
+	/**
270
+	 * Gets all the datetimes this ticket can be used for attending.
271
+	 * Unless otherwise specified, orders datetimes by start date.
272
+	 *
273
+	 * @param array $query_params see EEM_Base::get_all()
274
+	 * @return EE_Datetime[]|EE_Base_Class[]
275
+	 * @throws \EE_Error
276
+	 */
277 277
 	public function datetimes( $query_params = array() ) {
278 278
 		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279 279
 			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
 
284 284
 
285 285
 
286
-    /**
287
-     * This returns the chronologically last datetime that this ticket is associated with
288
-     *
289
-     * @return EE_Datetime
290
-     * @throws \EE_Error
291
-     */
286
+	/**
287
+	 * This returns the chronologically last datetime that this ticket is associated with
288
+	 *
289
+	 * @return EE_Datetime
290
+	 * @throws \EE_Error
291
+	 */
292 292
 	public function last_datetime() {
293 293
 		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294 294
 		return end( $datetimes );
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
 
297 297
 
298 298
 
299
-    /**
300
-     * This returns the total tickets sold depending on the given parameters.
301
-     *
302
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
306
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
-     * @return mixed (array|int)          how many tickets have sold
310
-     * @throws \EE_Error
311
-     */
299
+	/**
300
+	 * This returns the total tickets sold depending on the given parameters.
301
+	 *
302
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
306
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
+	 * @return mixed (array|int)          how many tickets have sold
310
+	 * @throws \EE_Error
311
+	 */
312 312
 	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 
334 334
 
335 335
 
336
-    /**
337
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
-     *
339
-     * @return EE_Ticket[]
340
-     * @throws \EE_Error
341
-     */
336
+	/**
337
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
+	 *
339
+	 * @return EE_Ticket[]
340
+	 * @throws \EE_Error
341
+	 */
342 342
 	protected function _all_tickets_sold() {
343 343
 		$datetimes = $this->get_many_related( 'Datetime' );
344 344
 		$tickets_sold = array();
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
 
356 356
 
357
-    /**
358
-     * This returns the base price object for the ticket.
359
-     *
360
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
-     * @throws \EE_Error
363
-     */
357
+	/**
358
+	 * This returns the base price object for the ticket.
359
+	 *
360
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
+	 * @throws \EE_Error
363
+	 */
364 364
 	public function base_price( $return_array = FALSE ) {
365 365
 		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+			? $this->get_many_related( 'Price', array( $_where ) )
368
+			: $this->get_first_related( 'Price', array( $_where ) );
369 369
 	}
370 370
 
371 371
 
372 372
 
373
-    /**
374
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
-     *
376
-     * @access public
377
-     * @return EE_Price[]
378
-     * @throws \EE_Error
379
-     */
373
+	/**
374
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
+	 *
376
+	 * @access public
377
+	 * @return EE_Price[]
378
+	 * @throws \EE_Error
379
+	 */
380 380
 	public function price_modifiers() {
381 381
 		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382 382
 		return $this->prices( $query_params );
@@ -384,132 +384,132 @@  discard block
 block discarded – undo
384 384
 
385 385
 
386 386
 
387
-    /**
388
-     * Gets all the prices that combine to form the final price of this ticket
389
-     *
390
-     * @param array $query_params like EEM_Base::get_all
391
-     * @return EE_Price[]|EE_Base_Class[]
392
-     * @throws \EE_Error
393
-     */
387
+	/**
388
+	 * Gets all the prices that combine to form the final price of this ticket
389
+	 *
390
+	 * @param array $query_params like EEM_Base::get_all
391
+	 * @return EE_Price[]|EE_Base_Class[]
392
+	 * @throws \EE_Error
393
+	 */
394 394
 	public function prices( $query_params = array() ) {
395 395
 		return $this->get_many_related( 'Price', $query_params );
396 396
 	}
397 397
 
398 398
 
399 399
 
400
-    /**
401
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
-     *
403
-     * @param array $query_params see EEM_Base::get_all()
404
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
405
-     * @throws \EE_Error
406
-     */
400
+	/**
401
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
+	 *
403
+	 * @param array $query_params see EEM_Base::get_all()
404
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
405
+	 * @throws \EE_Error
406
+	 */
407 407
 	public function datetime_tickets( $query_params = array() ) {
408 408
 		return $this->get_many_related( 'Datetime_Ticket', $query_params );
409 409
 	}
410 410
 
411 411
 
412 412
 
413
-    /**
414
-     * Gets all the datetimes from the db ordered by DTT_order
415
-     *
416
-     * @param boolean $show_expired
417
-     * @param boolean $show_deleted
418
-     * @return EE_Datetime[]
419
-     * @throws \EE_Error
420
-     */
413
+	/**
414
+	 * Gets all the datetimes from the db ordered by DTT_order
415
+	 *
416
+	 * @param boolean $show_expired
417
+	 * @param boolean $show_deleted
418
+	 * @return EE_Datetime[]
419
+	 * @throws \EE_Error
420
+	 */
421 421
 	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422 422
 		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
423 423
 	}
424 424
 
425 425
 
426 426
 
427
-    /**
428
-     * Gets ID
429
-     *
430
-     * @return string
431
-     * @throws \EE_Error
432
-     */
427
+	/**
428
+	 * Gets ID
429
+	 *
430
+	 * @return string
431
+	 * @throws \EE_Error
432
+	 */
433 433
 	public function ID() {
434 434
 		return $this->get( 'TKT_ID' );
435 435
 	}
436 436
 
437 437
 
438 438
 
439
-    /**
440
-     * get the author of the ticket.
441
-     *
442
-     * @since 4.5.0
443
-     * @return int
444
-     * @throws \EE_Error
445
-     */
439
+	/**
440
+	 * get the author of the ticket.
441
+	 *
442
+	 * @since 4.5.0
443
+	 * @return int
444
+	 * @throws \EE_Error
445
+	 */
446 446
 	public function wp_user() {
447 447
 		return $this->get('TKT_wp_user');
448 448
 	}
449 449
 
450 450
 
451 451
 
452
-    /**
453
-     * Gets the template for the ticket
454
-     *
455
-     * @return EE_Ticket_Template|EE_Base_Class
456
-     * @throws \EE_Error
457
-     */
452
+	/**
453
+	 * Gets the template for the ticket
454
+	 *
455
+	 * @return EE_Ticket_Template|EE_Base_Class
456
+	 * @throws \EE_Error
457
+	 */
458 458
 	public function template() {
459 459
 		return $this->get_first_related( 'Ticket_Template' );
460 460
 	}
461 461
 
462 462
 
463 463
 
464
-    /**
465
-     * Simply returns an array of EE_Price objects that are taxes.
466
-     *
467
-     * @return EE_Price[]
468
-     * @throws \EE_Error
469
-     */
464
+	/**
465
+	 * Simply returns an array of EE_Price objects that are taxes.
466
+	 *
467
+	 * @return EE_Price[]
468
+	 * @throws \EE_Error
469
+	 */
470 470
 	public function get_ticket_taxes_for_admin() {
471 471
 		return EE_Taxes::get_taxes_for_admin();
472 472
 	}
473 473
 
474 474
 
475 475
 
476
-    /**
477
-     * @return float
478
-     * @throws \EE_Error
479
-     */
476
+	/**
477
+	 * @return float
478
+	 * @throws \EE_Error
479
+	 */
480 480
 	public function ticket_price() {
481 481
 		return $this->get( 'TKT_price' );
482 482
 	}
483 483
 
484 484
 
485 485
 
486
-    /**
487
-     * @return mixed
488
-     * @throws \EE_Error
489
-     */
486
+	/**
487
+	 * @return mixed
488
+	 * @throws \EE_Error
489
+	 */
490 490
 	public function pretty_price() {
491 491
 		return $this->get_pretty( 'TKT_price' );
492 492
 	}
493 493
 
494 494
 
495 495
 
496
-    /**
497
-     * @return bool
498
-     * @throws \EE_Error
499
-     */
496
+	/**
497
+	 * @return bool
498
+	 * @throws \EE_Error
499
+	 */
500 500
 	public function is_free() {
501 501
 		return $this->get_ticket_total_with_taxes() === (float) 0;
502 502
 	}
503 503
 
504 504
 
505 505
 
506
-    /**
507
-     * get_ticket_total_with_taxes
508
-     *
509
-     * @param bool $no_cache
510
-     * @return float
511
-     * @throws \EE_Error
512
-     */
506
+	/**
507
+	 * get_ticket_total_with_taxes
508
+	 *
509
+	 * @param bool $no_cache
510
+	 * @return float
511
+	 * @throws \EE_Error
512
+	 */
513 513
 	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514 514
 		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
@@ -526,201 +526,201 @@  discard block
 block discarded – undo
526 526
 
527 527
 
528 528
 
529
-    /**
530
-     * @return float
531
-     * @throws \EE_Error
532
-     */
529
+	/**
530
+	 * @return float
531
+	 * @throws \EE_Error
532
+	 */
533 533
 	public function get_ticket_subtotal() {
534 534
 		return EE_Taxes::get_subtotal_for_admin( $this );
535 535
 	}
536 536
 
537 537
 
538 538
 
539
-    /**
540
-     * Returns the total taxes applied to this ticket
541
-     *
542
-     * @return float
543
-     * @throws \EE_Error
544
-     */
539
+	/**
540
+	 * Returns the total taxes applied to this ticket
541
+	 *
542
+	 * @return float
543
+	 * @throws \EE_Error
544
+	 */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546 546
 		return EE_Taxes::get_total_taxes_for_admin( $this );
547 547
 	}
548 548
 
549 549
 
550 550
 
551
-    /**
552
-     * Sets name
553
-     *
554
-     * @param string $name
555
-     * @throws \EE_Error
556
-     */
551
+	/**
552
+	 * Sets name
553
+	 *
554
+	 * @param string $name
555
+	 * @throws \EE_Error
556
+	 */
557 557
 	public function set_name( $name ) {
558 558
 		$this->set( 'TKT_name', $name );
559 559
 	}
560 560
 
561 561
 
562 562
 
563
-    /**
564
-     * Gets description
565
-     *
566
-     * @return string
567
-     * @throws \EE_Error
568
-     */
563
+	/**
564
+	 * Gets description
565
+	 *
566
+	 * @return string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public function description() {
570 570
 		return $this->get( 'TKT_description' );
571 571
 	}
572 572
 
573 573
 
574 574
 
575
-    /**
576
-     * Sets description
577
-     *
578
-     * @param string $description
579
-     * @throws \EE_Error
580
-     */
575
+	/**
576
+	 * Sets description
577
+	 *
578
+	 * @param string $description
579
+	 * @throws \EE_Error
580
+	 */
581 581
 	public function set_description( $description ) {
582 582
 		$this->set( 'TKT_description', $description );
583 583
 	}
584 584
 
585 585
 
586 586
 
587
-    /**
588
-     * Gets start_date
589
-     *
590
-     * @param string $dt_frmt
591
-     * @param string $tm_frmt
592
-     * @return string
593
-     * @throws \EE_Error
594
-     */
587
+	/**
588
+	 * Gets start_date
589
+	 *
590
+	 * @param string $dt_frmt
591
+	 * @param string $tm_frmt
592
+	 * @return string
593
+	 * @throws \EE_Error
594
+	 */
595 595
 	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596 596
 		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
597 597
 	}
598 598
 
599 599
 
600 600
 
601
-    /**
602
-     * Sets start_date
603
-     *
604
-     * @param string $start_date
605
-     * @return void
606
-     * @throws \EE_Error
607
-     */
601
+	/**
602
+	 * Sets start_date
603
+	 *
604
+	 * @param string $start_date
605
+	 * @return void
606
+	 * @throws \EE_Error
607
+	 */
608 608
 	public function set_start_date( $start_date ) {
609 609
 		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
610 610
 	}
611 611
 
612 612
 
613 613
 
614
-    /**
615
-     * Gets end_date
616
-     *
617
-     * @param string $dt_frmt
618
-     * @param string $tm_frmt
619
-     * @return string
620
-     * @throws \EE_Error
621
-     */
614
+	/**
615
+	 * Gets end_date
616
+	 *
617
+	 * @param string $dt_frmt
618
+	 * @param string $tm_frmt
619
+	 * @return string
620
+	 * @throws \EE_Error
621
+	 */
622 622
 	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623 623
 		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
624 624
 	}
625 625
 
626 626
 
627 627
 
628
-    /**
629
-     * Sets end_date
630
-     *
631
-     * @param string $end_date
632
-     * @return void
633
-     * @throws \EE_Error
634
-     */
628
+	/**
629
+	 * Sets end_date
630
+	 *
631
+	 * @param string $end_date
632
+	 * @return void
633
+	 * @throws \EE_Error
634
+	 */
635 635
 	public function set_end_date( $end_date ) {
636 636
 		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
637 637
 	}
638 638
 
639 639
 
640 640
 
641
-    /**
642
-     * Sets sell until time
643
-     *
644
-     * @since 4.5.0
645
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
-     * @throws \EE_Error
647
-     */
641
+	/**
642
+	 * Sets sell until time
643
+	 *
644
+	 * @since 4.5.0
645
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
+	 * @throws \EE_Error
647
+	 */
648 648
 	public function set_end_time( $time ) {
649 649
 		$this->_set_time_for( $time, 'TKT_end_date' );
650 650
 	}
651 651
 
652 652
 
653 653
 
654
-    /**
655
-     * Sets min
656
-     *
657
-     * @param int $min
658
-     * @return void
659
-     * @throws \EE_Error
660
-     */
654
+	/**
655
+	 * Sets min
656
+	 *
657
+	 * @param int $min
658
+	 * @return void
659
+	 * @throws \EE_Error
660
+	 */
661 661
 	public function set_min( $min ) {
662 662
 		$this->set( 'TKT_min', $min );
663 663
 	}
664 664
 
665 665
 
666 666
 
667
-    /**
668
-     * Gets max
669
-     *
670
-     * @return int
671
-     * @throws \EE_Error
672
-     */
667
+	/**
668
+	 * Gets max
669
+	 *
670
+	 * @return int
671
+	 * @throws \EE_Error
672
+	 */
673 673
 	public function max() {
674 674
 		return $this->get( 'TKT_max' );
675 675
 	}
676 676
 
677 677
 
678 678
 
679
-    /**
680
-     * Sets max
681
-     *
682
-     * @param int $max
683
-     * @return void
684
-     * @throws \EE_Error
685
-     */
679
+	/**
680
+	 * Sets max
681
+	 *
682
+	 * @param int $max
683
+	 * @return void
684
+	 * @throws \EE_Error
685
+	 */
686 686
 	public function set_max( $max ) {
687 687
 		$this->set( 'TKT_max', $max );
688 688
 	}
689 689
 
690 690
 
691 691
 
692
-    /**
693
-     * Sets price
694
-     *
695
-     * @param float $price
696
-     * @return void
697
-     * @throws \EE_Error
698
-     */
692
+	/**
693
+	 * Sets price
694
+	 *
695
+	 * @param float $price
696
+	 * @return void
697
+	 * @throws \EE_Error
698
+	 */
699 699
 	public function set_price( $price ) {
700 700
 		$this->set( 'TKT_price', $price );
701 701
 	}
702 702
 
703 703
 
704 704
 
705
-    /**
706
-     * Gets sold
707
-     *
708
-     * @return int
709
-     * @throws \EE_Error
710
-     */
705
+	/**
706
+	 * Gets sold
707
+	 *
708
+	 * @return int
709
+	 * @throws \EE_Error
710
+	 */
711 711
 	public function sold() {
712 712
 		return $this->get_raw( 'TKT_sold' );
713 713
 	}
714 714
 
715 715
 
716 716
 
717
-    /**
718
-     * Sets sold
719
-     *
720
-     * @param int $sold
721
-     * @return void
722
-     * @throws \EE_Error
723
-     */
717
+	/**
718
+	 * Sets sold
719
+	 *
720
+	 * @param int $sold
721
+	 * @return void
722
+	 * @throws \EE_Error
723
+	 */
724 724
 	public function set_sold( $sold ) {
725 725
 		// sold can not go below zero
726 726
 		$sold = max( 0, $sold );
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
 
730 730
 
731 731
 
732
-    /**
733
-     * increments sold by amount passed by $qty
734
-     *
735
-     * @param int $qty
736
-     * @return void
737
-     * @throws \EE_Error
738
-     */
732
+	/**
733
+	 * increments sold by amount passed by $qty
734
+	 *
735
+	 * @param int $qty
736
+	 * @return void
737
+	 * @throws \EE_Error
738
+	 */
739 739
 	public function increase_sold( $qty = 1 ) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
@@ -744,22 +744,22 @@  discard block
 block discarded – undo
744 744
 		$this->_increase_sold_for_datetimes( $qty );
745 745
 		$this->set_sold( $sold );
746 746
 		do_action(
747
-		    'AHEE__EE_Ticket__increase_sold',
748
-            $this,
749
-            $qty,
750
-            $sold
751
-        );
747
+			'AHEE__EE_Ticket__increase_sold',
748
+			$this,
749
+			$qty,
750
+			$sold
751
+		);
752 752
 	}
753 753
 
754 754
 
755 755
 
756
-    /**
757
-     * Increases sold on related datetimes
758
-     *
759
-     * @param int $qty
760
-     * @return void
761
-     * @throws \EE_Error
762
-     */
756
+	/**
757
+	 * Increases sold on related datetimes
758
+	 *
759
+	 * @param int $qty
760
+	 * @return void
761
+	 * @throws \EE_Error
762
+	 */
763 763
 	protected function _increase_sold_for_datetimes( $qty = 1 ) {
764 764
 		$datetimes = $this->datetimes();
765 765
 		if ( is_array( $datetimes ) ) {
@@ -774,34 +774,34 @@  discard block
 block discarded – undo
774 774
 
775 775
 
776 776
 
777
-    /**
778
-     * decrements (subtracts) sold by amount passed by $qty
779
-     *
780
-     * @param int $qty
781
-     * @return void
782
-     * @throws \EE_Error
783
-     */
777
+	/**
778
+	 * decrements (subtracts) sold by amount passed by $qty
779
+	 *
780
+	 * @param int $qty
781
+	 * @return void
782
+	 * @throws \EE_Error
783
+	 */
784 784
 	public function decrease_sold( $qty = 1 ) {
785 785
 		$sold = $this->sold() - $qty;
786 786
 		$this->_decrease_sold_for_datetimes( $qty );
787 787
 		$this->set_sold( $sold );
788
-        do_action(
789
-            'AHEE__EE_Ticket__decrease_sold',
790
-            $this,
791
-            $qty,
792
-            $sold
793
-        );
794
-    }
795
-
796
-
797
-
798
-    /**
799
-     * Decreases sold on related datetimes
800
-     *
801
-     * @param int $qty
802
-     * @return void
803
-     * @throws \EE_Error
804
-     */
788
+		do_action(
789
+			'AHEE__EE_Ticket__decrease_sold',
790
+			$this,
791
+			$qty,
792
+			$sold
793
+		);
794
+	}
795
+
796
+
797
+
798
+	/**
799
+	 * Decreases sold on related datetimes
800
+	 *
801
+	 * @param int $qty
802
+	 * @return void
803
+	 * @throws \EE_Error
804
+	 */
805 805
 	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
806 806
 		$datetimes = $this->datetimes();
807 807
 		if ( is_array( $datetimes ) ) {
@@ -816,25 +816,25 @@  discard block
 block discarded – undo
816 816
 
817 817
 
818 818
 
819
-    /**
820
-     * Gets qty of reserved tickets
821
-     *
822
-     * @return int
823
-     * @throws \EE_Error
824
-     */
819
+	/**
820
+	 * Gets qty of reserved tickets
821
+	 *
822
+	 * @return int
823
+	 * @throws \EE_Error
824
+	 */
825 825
 	public function reserved() {
826 826
 		return $this->get_raw( 'TKT_reserved' );
827 827
 	}
828 828
 
829 829
 
830 830
 
831
-    /**
832
-     * Sets reserved
833
-     *
834
-     * @param int $reserved
835
-     * @return void
836
-     * @throws \EE_Error
837
-     */
831
+	/**
832
+	 * Sets reserved
833
+	 *
834
+	 * @param int $reserved
835
+	 * @return void
836
+	 * @throws \EE_Error
837
+	 */
838 838
 	public function set_reserved( $reserved ) {
839 839
 		// reserved can not go below zero
840 840
 		$reserved = max( 0, (int) $reserved );
@@ -843,35 +843,35 @@  discard block
 block discarded – undo
843 843
 
844 844
 
845 845
 
846
-    /**
847
-     * increments reserved by amount passed by $qty
848
-     *
849
-     * @param int $qty
850
-     * @return void
851
-     * @throws \EE_Error
852
-     */
846
+	/**
847
+	 * increments reserved by amount passed by $qty
848
+	 *
849
+	 * @param int $qty
850
+	 * @return void
851
+	 * @throws \EE_Error
852
+	 */
853 853
 	public function increase_reserved( $qty = 1 ) {
854 854
 		$qty = absint( $qty );
855 855
 		$reserved = $this->reserved() + $qty;
856 856
 		$this->_increase_reserved_for_datetimes( $qty );
857 857
 		$this->set_reserved( $reserved );
858
-        do_action(
859
-            'AHEE__EE_Ticket__increase_reserved',
860
-            $this,
861
-            $qty,
862
-            $reserved
863
-        );
864
-    }
865
-
866
-
867
-
868
-    /**
869
-     * Increases sold on related datetimes
870
-     *
871
-     * @param int $qty
872
-     * @return void
873
-     * @throws \EE_Error
874
-     */
858
+		do_action(
859
+			'AHEE__EE_Ticket__increase_reserved',
860
+			$this,
861
+			$qty,
862
+			$reserved
863
+		);
864
+	}
865
+
866
+
867
+
868
+	/**
869
+	 * Increases sold on related datetimes
870
+	 *
871
+	 * @param int $qty
872
+	 * @return void
873
+	 * @throws \EE_Error
874
+	 */
875 875
 	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
876 876
 		$datetimes = $this->datetimes();
877 877
 		if ( is_array( $datetimes ) ) {
@@ -886,37 +886,37 @@  discard block
 block discarded – undo
886 886
 
887 887
 
888 888
 
889
-    /**
890
-     * decrements (subtracts) reserved by amount passed by $qty
891
-     *
892
-     * @param int  $qty
893
-     * @param bool $adjust_datetimes
894
-     * @return void
895
-     * @throws \EE_Error
896
-     */
889
+	/**
890
+	 * decrements (subtracts) reserved by amount passed by $qty
891
+	 *
892
+	 * @param int  $qty
893
+	 * @param bool $adjust_datetimes
894
+	 * @return void
895
+	 * @throws \EE_Error
896
+	 */
897 897
 	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
898 898
 		$reserved = $this->reserved() - absint( $qty );
899 899
 		if ( $adjust_datetimes ) {
900 900
 			$this->_decrease_reserved_for_datetimes( $qty );
901 901
 		}
902 902
 		$this->set_reserved( $reserved );
903
-        do_action(
904
-            'AHEE__EE_Ticket__decrease_reserved',
905
-            $this,
906
-            $qty,
907
-            $reserved
908
-        );
909
-    }
910
-
911
-
912
-
913
-    /**
914
-     * Increases sold on related datetimes
915
-     *
916
-     * @param int $qty
917
-     * @return void
918
-     * @throws \EE_Error
919
-     */
903
+		do_action(
904
+			'AHEE__EE_Ticket__decrease_reserved',
905
+			$this,
906
+			$qty,
907
+			$reserved
908
+		);
909
+	}
910
+
911
+
912
+
913
+	/**
914
+	 * Increases sold on related datetimes
915
+	 *
916
+	 * @param int $qty
917
+	 * @return void
918
+	 * @throws \EE_Error
919
+	 */
920 920
 	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
921 921
 		$datetimes = $this->datetimes();
922 922
 		if ( is_array( $datetimes ) ) {
@@ -931,18 +931,18 @@  discard block
 block discarded – undo
931 931
 
932 932
 
933 933
 
934
-    /**
935
-     * Gets ticket quantity
936
-     *
937
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
938
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
939
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
940
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
943
-     * @return int
944
-     * @throws \EE_Error
945
-     */
934
+	/**
935
+	 * Gets ticket quantity
936
+	 *
937
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
938
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
939
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
940
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
943
+	 * @return int
944
+	 * @throws \EE_Error
945
+	 */
946 946
 	public function qty( $context = '' ) {
947 947
 		switch ( $context ) {
948 948
 			case 'reg_limit' :
@@ -956,19 +956,19 @@  discard block
 block discarded – undo
956 956
 
957 957
 
958 958
 
959
-    /**
960
-     * Gets ticket quantity
961
-     *
962
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
963
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
964
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
965
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
966
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
967
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
968
-     *                            set to 0 for all related datetimes
969
-     * @return int
970
-     * @throws \EE_Error
971
-     */
959
+	/**
960
+	 * Gets ticket quantity
961
+	 *
962
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
963
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
964
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
965
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
966
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
967
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
968
+	 *                            set to 0 for all related datetimes
969
+	 * @return int
970
+	 * @throws \EE_Error
971
+	 */
972 972
 	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
973 973
 		$raw = $this->get_raw( 'TKT_qty' );
974 974
 		// return immediately if it's zero
@@ -1051,212 +1051,212 @@  discard block
 block discarded – undo
1051 1051
 
1052 1052
 
1053 1053
 
1054
-    /**
1055
-     * Gets uses
1056
-     *
1057
-     * @return int
1058
-     * @throws \EE_Error
1059
-     */
1054
+	/**
1055
+	 * Gets uses
1056
+	 *
1057
+	 * @return int
1058
+	 * @throws \EE_Error
1059
+	 */
1060 1060
 	public function uses() {
1061 1061
 		return $this->get( 'TKT_uses' );
1062 1062
 	}
1063 1063
 
1064 1064
 
1065 1065
 
1066
-    /**
1067
-     * Sets uses
1068
-     *
1069
-     * @param int $uses
1070
-     * @return void
1071
-     * @throws \EE_Error
1072
-     */
1066
+	/**
1067
+	 * Sets uses
1068
+	 *
1069
+	 * @param int $uses
1070
+	 * @return void
1071
+	 * @throws \EE_Error
1072
+	 */
1073 1073
 	public function set_uses( $uses ) {
1074 1074
 		$this->set( 'TKT_uses', $uses );
1075 1075
 	}
1076 1076
 
1077 1077
 
1078 1078
 
1079
-    /**
1080
-     * returns whether ticket is required or not.
1081
-     *
1082
-     * @return boolean
1083
-     * @throws \EE_Error
1084
-     */
1079
+	/**
1080
+	 * returns whether ticket is required or not.
1081
+	 *
1082
+	 * @return boolean
1083
+	 * @throws \EE_Error
1084
+	 */
1085 1085
 	public function required() {
1086 1086
 		return $this->get( 'TKT_required' );
1087 1087
 	}
1088 1088
 
1089 1089
 
1090 1090
 
1091
-    /**
1092
-     * sets the TKT_required property
1093
-     *
1094
-     * @param boolean $required
1095
-     * @return void
1096
-     * @throws \EE_Error
1097
-     */
1091
+	/**
1092
+	 * sets the TKT_required property
1093
+	 *
1094
+	 * @param boolean $required
1095
+	 * @return void
1096
+	 * @throws \EE_Error
1097
+	 */
1098 1098
 	public function set_required( $required ) {
1099 1099
 		$this->set( 'TKT_required', $required );
1100 1100
 	}
1101 1101
 
1102 1102
 
1103 1103
 
1104
-    /**
1105
-     * Gets taxable
1106
-     *
1107
-     * @return boolean
1108
-     * @throws \EE_Error
1109
-     */
1104
+	/**
1105
+	 * Gets taxable
1106
+	 *
1107
+	 * @return boolean
1108
+	 * @throws \EE_Error
1109
+	 */
1110 1110
 	public function taxable() {
1111 1111
 		return $this->get( 'TKT_taxable' );
1112 1112
 	}
1113 1113
 
1114 1114
 
1115 1115
 
1116
-    /**
1117
-     * Sets taxable
1118
-     *
1119
-     * @param boolean $taxable
1120
-     * @return void
1121
-     * @throws \EE_Error
1122
-     */
1116
+	/**
1117
+	 * Sets taxable
1118
+	 *
1119
+	 * @param boolean $taxable
1120
+	 * @return void
1121
+	 * @throws \EE_Error
1122
+	 */
1123 1123
 	public function set_taxable( $taxable ) {
1124 1124
 		$this->set( 'TKT_taxable', $taxable );
1125 1125
 	}
1126 1126
 
1127 1127
 
1128 1128
 
1129
-    /**
1130
-     * Gets is_default
1131
-     *
1132
-     * @return boolean
1133
-     * @throws \EE_Error
1134
-     */
1129
+	/**
1130
+	 * Gets is_default
1131
+	 *
1132
+	 * @return boolean
1133
+	 * @throws \EE_Error
1134
+	 */
1135 1135
 	public function is_default() {
1136 1136
 		return $this->get( 'TKT_is_default' );
1137 1137
 	}
1138 1138
 
1139 1139
 
1140 1140
 
1141
-    /**
1142
-     * Sets is_default
1143
-     *
1144
-     * @param boolean $is_default
1145
-     * @return void
1146
-     * @throws \EE_Error
1147
-     */
1141
+	/**
1142
+	 * Sets is_default
1143
+	 *
1144
+	 * @param boolean $is_default
1145
+	 * @return void
1146
+	 * @throws \EE_Error
1147
+	 */
1148 1148
 	public function set_is_default( $is_default ) {
1149 1149
 		$this->set( 'TKT_is_default', $is_default );
1150 1150
 	}
1151 1151
 
1152 1152
 
1153 1153
 
1154
-    /**
1155
-     * Gets order
1156
-     *
1157
-     * @return int
1158
-     * @throws \EE_Error
1159
-     */
1154
+	/**
1155
+	 * Gets order
1156
+	 *
1157
+	 * @return int
1158
+	 * @throws \EE_Error
1159
+	 */
1160 1160
 	public function order() {
1161 1161
 		return $this->get( 'TKT_order' );
1162 1162
 	}
1163 1163
 
1164 1164
 
1165 1165
 
1166
-    /**
1167
-     * Sets order
1168
-     *
1169
-     * @param int $order
1170
-     * @return void
1171
-     * @throws \EE_Error
1172
-     */
1166
+	/**
1167
+	 * Sets order
1168
+	 *
1169
+	 * @param int $order
1170
+	 * @return void
1171
+	 * @throws \EE_Error
1172
+	 */
1173 1173
 	public function set_order( $order ) {
1174 1174
 		$this->set( 'TKT_order', $order );
1175 1175
 	}
1176 1176
 
1177 1177
 
1178 1178
 
1179
-    /**
1180
-     * Gets row
1181
-     *
1182
-     * @return int
1183
-     * @throws \EE_Error
1184
-     */
1179
+	/**
1180
+	 * Gets row
1181
+	 *
1182
+	 * @return int
1183
+	 * @throws \EE_Error
1184
+	 */
1185 1185
 	public function row() {
1186 1186
 		return $this->get( 'TKT_row' );
1187 1187
 	}
1188 1188
 
1189 1189
 
1190 1190
 
1191
-    /**
1192
-     * Sets row
1193
-     *
1194
-     * @param int $row
1195
-     * @return void
1196
-     * @throws \EE_Error
1197
-     */
1191
+	/**
1192
+	 * Sets row
1193
+	 *
1194
+	 * @param int $row
1195
+	 * @return void
1196
+	 * @throws \EE_Error
1197
+	 */
1198 1198
 	public function set_row( $row ) {
1199 1199
 		$this->set( 'TKT_row', $row );
1200 1200
 	}
1201 1201
 
1202 1202
 
1203 1203
 
1204
-    /**
1205
-     * Gets deleted
1206
-     *
1207
-     * @return boolean
1208
-     * @throws \EE_Error
1209
-     */
1204
+	/**
1205
+	 * Gets deleted
1206
+	 *
1207
+	 * @return boolean
1208
+	 * @throws \EE_Error
1209
+	 */
1210 1210
 	public function deleted() {
1211 1211
 		return $this->get( 'TKT_deleted' );
1212 1212
 	}
1213 1213
 
1214 1214
 
1215 1215
 
1216
-    /**
1217
-     * Sets deleted
1218
-     *
1219
-     * @param boolean $deleted
1220
-     * @return void
1221
-     * @throws \EE_Error
1222
-     */
1216
+	/**
1217
+	 * Sets deleted
1218
+	 *
1219
+	 * @param boolean $deleted
1220
+	 * @return void
1221
+	 * @throws \EE_Error
1222
+	 */
1223 1223
 	public function set_deleted( $deleted ) {
1224 1224
 		$this->set( 'TKT_deleted', $deleted );
1225 1225
 	}
1226 1226
 
1227 1227
 
1228 1228
 
1229
-    /**
1230
-     * Gets parent
1231
-     *
1232
-     * @return int
1233
-     * @throws \EE_Error
1234
-     */
1229
+	/**
1230
+	 * Gets parent
1231
+	 *
1232
+	 * @return int
1233
+	 * @throws \EE_Error
1234
+	 */
1235 1235
 	public function parent_ID() {
1236 1236
 		return $this->get( 'TKT_parent' );
1237 1237
 	}
1238 1238
 
1239 1239
 
1240 1240
 
1241
-    /**
1242
-     * Sets parent
1243
-     *
1244
-     * @param int $parent
1245
-     * @return void
1246
-     * @throws \EE_Error
1247
-     */
1241
+	/**
1242
+	 * Sets parent
1243
+	 *
1244
+	 * @param int $parent
1245
+	 * @return void
1246
+	 * @throws \EE_Error
1247
+	 */
1248 1248
 	public function set_parent_ID( $parent ) {
1249 1249
 		$this->set( 'TKT_parent', $parent );
1250 1250
 	}
1251 1251
 
1252 1252
 
1253 1253
 
1254
-    /**
1255
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1256
-     *
1257
-     * @return string
1258
-     * @throws \EE_Error
1259
-     */
1254
+	/**
1255
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1256
+	 *
1257
+	 * @return string
1258
+	 * @throws \EE_Error
1259
+	 */
1260 1260
 	public function name_and_info() {
1261 1261
 		$times = array();
1262 1262
 		foreach ( $this->datetimes() as $datetime ) {
@@ -1267,67 +1267,67 @@  discard block
 block discarded – undo
1267 1267
 
1268 1268
 
1269 1269
 
1270
-    /**
1271
-     * Gets name
1272
-     *
1273
-     * @return string
1274
-     * @throws \EE_Error
1275
-     */
1270
+	/**
1271
+	 * Gets name
1272
+	 *
1273
+	 * @return string
1274
+	 * @throws \EE_Error
1275
+	 */
1276 1276
 	public function name() {
1277 1277
 		return $this->get( 'TKT_name' );
1278 1278
 	}
1279 1279
 
1280 1280
 
1281 1281
 
1282
-    /**
1283
-     * Gets price
1284
-     *
1285
-     * @return float
1286
-     * @throws \EE_Error
1287
-     */
1282
+	/**
1283
+	 * Gets price
1284
+	 *
1285
+	 * @return float
1286
+	 * @throws \EE_Error
1287
+	 */
1288 1288
 	public function price() {
1289 1289
 		return $this->get( 'TKT_price' );
1290 1290
 	}
1291 1291
 
1292 1292
 
1293 1293
 
1294
-    /**
1295
-     * Gets all the registrations for this ticket
1296
-     *
1297
-     * @param array $query_params like EEM_Base::get_all's
1298
-     * @return EE_Registration[]|EE_Base_Class[]
1299
-     * @throws \EE_Error
1300
-     */
1294
+	/**
1295
+	 * Gets all the registrations for this ticket
1296
+	 *
1297
+	 * @param array $query_params like EEM_Base::get_all's
1298
+	 * @return EE_Registration[]|EE_Base_Class[]
1299
+	 * @throws \EE_Error
1300
+	 */
1301 1301
 	public function registrations( $query_params = array() ) {
1302 1302
 		return $this->get_many_related( 'Registration', $query_params );
1303 1303
 	}
1304 1304
 
1305 1305
 
1306 1306
 
1307
-    /**
1308
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1309
-     * into account
1310
-     *
1311
-     * @return int
1312
-     * @throws \EE_Error
1313
-     */
1307
+	/**
1308
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1309
+	 * into account
1310
+	 *
1311
+	 * @return int
1312
+	 * @throws \EE_Error
1313
+	 */
1314 1314
 	public function update_tickets_sold() {
1315
-        $count_regs_for_this_ticket = $this->count_registrations(
1316
-            array(
1317
-                array(
1318
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1319
-                    'REG_deleted' => 0,
1320
-                ),
1321
-            )
1322
-        );
1323
-        $sold = $this->sold();
1324
-        if ($count_regs_for_this_ticket > $sold) {
1325
-            $this->increase_sold($count_regs_for_this_ticket - $sold);
1326
-            $this->save();
1327
-        } else if ($count_regs_for_this_ticket < $sold) {
1328
-            $this->decrease_sold($count_regs_for_this_ticket - $sold);
1329
-            $this->save();
1330
-        }
1315
+		$count_regs_for_this_ticket = $this->count_registrations(
1316
+			array(
1317
+				array(
1318
+					'STS_ID'      => EEM_Registration::status_id_approved,
1319
+					'REG_deleted' => 0,
1320
+				),
1321
+			)
1322
+		);
1323
+		$sold = $this->sold();
1324
+		if ($count_regs_for_this_ticket > $sold) {
1325
+			$this->increase_sold($count_regs_for_this_ticket - $sold);
1326
+			$this->save();
1327
+		} else if ($count_regs_for_this_ticket < $sold) {
1328
+			$this->decrease_sold($count_regs_for_this_ticket - $sold);
1329
+			$this->save();
1330
+		}
1331 1331
 		return $count_regs_for_this_ticket;
1332 1332
 	}
1333 1333
 
@@ -1355,21 +1355,21 @@  discard block
 block discarded – undo
1355 1355
 
1356 1356
 
1357 1357
 
1358
-    /**
1359
-     * Implementation of the EEI_Event_Relation interface method
1360
-     *
1361
-     * @see EEI_Event_Relation for comments
1362
-     * @return EE_Event
1363
-     * @throws \EE_Error
1364
-     * @throws UnexpectedEntityException
1365
-     */
1358
+	/**
1359
+	 * Implementation of the EEI_Event_Relation interface method
1360
+	 *
1361
+	 * @see EEI_Event_Relation for comments
1362
+	 * @return EE_Event
1363
+	 * @throws \EE_Error
1364
+	 * @throws UnexpectedEntityException
1365
+	 */
1366 1366
 	public function get_related_event() {
1367 1367
 		//get one datetime to use for getting the event
1368 1368
 		$datetime = $this->first_datetime();
1369 1369
 		if ( ! $datetime instanceof \EE_Datetime ) {
1370 1370
 			throw new UnexpectedEntityException(
1371 1371
 				$datetime,
1372
-                'EE_Datetime',
1372
+				'EE_Datetime',
1373 1373
 				sprintf(
1374 1374
 					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1375 1375
 					$this->name()
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
 		if ( ! $event instanceof \EE_Event ) {
1381 1381
 			throw new UnexpectedEntityException(
1382 1382
 				$event,
1383
-                'EE_Event',
1383
+				'EE_Event',
1384 1384
 				sprintf(
1385 1385
 					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1386 1386
 					$this->name()
@@ -1392,14 +1392,14 @@  discard block
 block discarded – undo
1392 1392
 
1393 1393
 
1394 1394
 
1395
-    /**
1396
-     * Implementation of the EEI_Event_Relation interface method
1397
-     *
1398
-     * @see EEI_Event_Relation for comments
1399
-     * @return string
1400
-     * @throws UnexpectedEntityException
1401
-     * @throws \EE_Error
1402
-     */
1395
+	/**
1396
+	 * Implementation of the EEI_Event_Relation interface method
1397
+	 *
1398
+	 * @see EEI_Event_Relation for comments
1399
+	 * @return string
1400
+	 * @throws UnexpectedEntityException
1401
+	 * @throws \EE_Error
1402
+	 */
1403 1403
 	public function get_event_name() {
1404 1404
 		$event = $this->get_related_event();
1405 1405
 		return $event instanceof EE_Event ? $event->name() : '';
@@ -1407,28 +1407,28 @@  discard block
 block discarded – undo
1407 1407
 
1408 1408
 
1409 1409
 
1410
-    /**
1411
-     * Implementation of the EEI_Event_Relation interface method
1412
-     *
1413
-     * @see EEI_Event_Relation for comments
1414
-     * @return int
1415
-     * @throws UnexpectedEntityException
1416
-     * @throws \EE_Error
1417
-     */
1410
+	/**
1411
+	 * Implementation of the EEI_Event_Relation interface method
1412
+	 *
1413
+	 * @see EEI_Event_Relation for comments
1414
+	 * @return int
1415
+	 * @throws UnexpectedEntityException
1416
+	 * @throws \EE_Error
1417
+	 */
1418 1418
 	public function get_event_ID() {
1419 1419
 		$event = $this->get_related_event();
1420 1420
 		return $event instanceof EE_Event ? $event->ID() : 0;
1421 1421
 	}
1422 1422
 
1423 1423
 
1424
-    /**
1425
-     * This simply returns whether a ticket can be permanently deleted or not.
1426
-     * The criteria for determining this is whether the ticket has any related registrations.
1427
-     * If there are none then it can be permanently deleted.
1428
-     *
1429
-     * @return bool
1430
-     */
1424
+	/**
1425
+	 * This simply returns whether a ticket can be permanently deleted or not.
1426
+	 * The criteria for determining this is whether the ticket has any related registrations.
1427
+	 * If there are none then it can be permanently deleted.
1428
+	 *
1429
+	 * @return bool
1430
+	 */
1431 1431
 	public function is_permanently_deleteable() {
1432
-	    return $this->count_registrations() === 0;
1433
-    }
1432
+		return $this->count_registrations() === 0;
1433
+	}
1434 1434
 } //end EE_Ticket class
Please login to merge, or discard this patch.
Spacing   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\UnexpectedEntityException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
      * @return EE_Ticket
71 71
      * @throws \EE_Error
72 72
      */
73
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
73
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
74
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
75
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
76 76
 	}
77 77
 
78 78
 
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
      * @return EE_Ticket
85 85
      * @throws \EE_Error
86 86
      */
87
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88
-		return new self( $props_n_values, TRUE, $timezone );
87
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
88
+		return new self($props_n_values, TRUE, $timezone);
89 89
 	}
90 90
 
91 91
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @throws \EE_Error
96 96
      */
97 97
 	public function parent() {
98
-		return $this->get( 'TKT_parent' );
98
+		return $this->get('TKT_parent');
99 99
 	}
100 100
 
101 101
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
      * @return boolean
108 108
      * @throws \EE_Error
109 109
      */
110
-	public function available( $DTT_ID = 0 ) {
110
+	public function available($DTT_ID = 0) {
111 111
 		// are we checking availability for a particular datetime ?
112
-		if ( $DTT_ID ) {
112
+		if ($DTT_ID) {
113 113
 			// get that datetime object
114
-			$datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) );
114
+			$datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
115 115
 			// if  ticket sales for this datetime have exceeded the reg limit...
116
-			if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) {
116
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
117 117
 				return FALSE;
118 118
 			}
119 119
 		}
@@ -131,22 +131,22 @@  discard block
 block discarded – undo
131 131
      * @return mixed status int if the display string isn't requested
132 132
      * @throws \EE_Error
133 133
      */
134
-	public function ticket_status( $display = FALSE, $remaining = null ) {
135
-		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136
-		if ( ! $remaining ) {
137
-			return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out;
134
+	public function ticket_status($display = FALSE, $remaining = null) {
135
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
136
+		if ( ! $remaining) {
137
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out;
138 138
 		}
139
-		if ( $this->get( 'TKT_deleted' ) ) {
140
-			return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived;
139
+		if ($this->get('TKT_deleted')) {
140
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived;
141 141
 		}
142
-		if ( $this->is_expired() ) {
143
-			return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired;
142
+		if ($this->is_expired()) {
143
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired;
144 144
 		}
145
-		if ( $this->is_pending() ) {
146
-			return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending;
145
+		if ($this->is_pending()) {
146
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending;
147 147
 		}
148
-		if ( $this->is_on_sale() ) {
149
-			return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale;
148
+		if ($this->is_on_sale()) {
149
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale;
150 150
 		}
151 151
 		return '';
152 152
 	}
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
      * @return boolean         true = tickets remaining, false not.
162 162
      * @throws \EE_Error
163 163
      */
164
-	public function is_remaining( $DTT_ID = 0 ) {
165
-		$num_remaining = $this->remaining( $DTT_ID );
166
-		if ( $num_remaining === 0 ) {
164
+	public function is_remaining($DTT_ID = 0) {
165
+		$num_remaining = $this->remaining($DTT_ID);
166
+		if ($num_remaining === 0) {
167 167
 			return FALSE;
168 168
 		}
169
-		if ( $num_remaining > 0 && $num_remaining < $this->min() ) {
169
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
170 170
 			return FALSE;
171 171
 		}
172 172
 		return TRUE;
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      * @return int
183 183
      * @throws \EE_Error
184 184
      */
185
-	public function remaining( $DTT_ID = 0 ) {
186
-		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
185
+	public function remaining($DTT_ID = 0) {
186
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
187 187
 	}
188 188
 
189 189
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @throws \EE_Error
196 196
      */
197 197
 	public function min() {
198
-		return $this->get( 'TKT_min' );
198
+		return $this->get('TKT_min');
199 199
 	}
200 200
 
201 201
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * @throws \EE_Error
208 208
      */
209 209
 	public function is_expired() {
210
-		return ( $this->get_raw( 'TKT_end_date' ) < time() );
210
+		return ($this->get_raw('TKT_end_date') < time());
211 211
 	}
212 212
 
213 213
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @throws \EE_Error
220 220
      */
221 221
 	public function is_pending() {
222
-		return ( $this->get_raw( 'TKT_start_date' ) > time() );
222
+		return ($this->get_raw('TKT_start_date') > time());
223 223
 	}
224 224
 
225 225
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @throws \EE_Error
232 232
      */
233 233
 	public function is_on_sale() {
234
-		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
234
+		return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
235 235
 	}
236 236
 
237 237
 
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
      * @return string
245 245
      * @throws \EE_Error
246 246
      */
247
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248
-		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249
-		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
247
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
248
+		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : '';
249
+		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
250 250
 
251
-		return $first_date && $last_date ? $first_date . $conjunction  . $last_date : '';
251
+		return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
252 252
 	}
253 253
 
254 254
 
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
      * @throws \EE_Error
261 261
      */
262 262
 	public function first_datetime() {
263
-		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264
-		return reset( $datetimes );
263
+		$datetimes = $this->datetimes(array('limit' => 1));
264
+		return reset($datetimes);
265 265
 	}
266 266
 
267 267
 
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
      * @return EE_Datetime[]|EE_Base_Class[]
275 275
      * @throws \EE_Error
276 276
      */
277
-	public function datetimes( $query_params = array() ) {
278
-		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279
-			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
277
+	public function datetimes($query_params = array()) {
278
+		if ( ! isset($query_params['order_by'])) {
279
+			$query_params['order_by']['DTT_order'] = 'ASC';
280 280
 		}
281
-		return $this->get_many_related( 'Datetime', $query_params );
281
+		return $this->get_many_related('Datetime', $query_params);
282 282
 	}
283 283
 
284 284
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
      * @throws \EE_Error
291 291
      */
292 292
 	public function last_datetime() {
293
-		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294
-		return end( $datetimes );
293
+		$datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
294
+		return end($datetimes);
295 295
 	}
296 296
 
297 297
 
@@ -309,22 +309,22 @@  discard block
 block discarded – undo
309 309
      * @return mixed (array|int)          how many tickets have sold
310 310
      * @throws \EE_Error
311 311
      */
312
-	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
312
+	public function tickets_sold($what = 'ticket', $dtt_id = NULL) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
315
-		switch ( $what ) {
315
+		switch ($what) {
316 316
 			case 'ticket' :
317
-				return $tickets_sold[ 'ticket' ];
317
+				return $tickets_sold['ticket'];
318 318
 				break;
319 319
 			case 'datetime' :
320
-				if ( empty( $tickets_sold[ 'datetime' ] ) ) {
320
+				if (empty($tickets_sold['datetime'])) {
321 321
 					return $total;
322 322
 				}
323
-				if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) {
324
-					EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
323
+				if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
324
+					EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
325 325
 					return $total;
326 326
 				}
327
-				return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ];
327
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
328 328
 				break;
329 329
 			default:
330 330
 				return $total;
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
      * @throws \EE_Error
341 341
      */
342 342
 	protected function _all_tickets_sold() {
343
-		$datetimes = $this->get_many_related( 'Datetime' );
343
+		$datetimes = $this->get_many_related('Datetime');
344 344
 		$tickets_sold = array();
345
-		if ( ! empty( $datetimes ) ) {
346
-			foreach ( $datetimes as $datetime ) {
347
-				$tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' );
345
+		if ( ! empty($datetimes)) {
346
+			foreach ($datetimes as $datetime) {
347
+				$tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
348 348
 			}
349 349
 		}
350 350
 		//Tickets sold
351
-		$tickets_sold[ 'ticket' ] = $this->sold();
351
+		$tickets_sold['ticket'] = $this->sold();
352 352
 		return $tickets_sold;
353 353
 	}
354 354
 
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
      * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362 362
      * @throws \EE_Error
363 363
      */
364
-	public function base_price( $return_array = FALSE ) {
365
-		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
364
+	public function base_price($return_array = FALSE) {
365
+		$_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+            ? $this->get_many_related('Price', array($_where))
368
+            : $this->get_first_related('Price', array($_where));
369 369
 	}
370 370
 
371 371
 
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
      * @throws \EE_Error
379 379
      */
380 380
 	public function price_modifiers() {
381
-		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382
-		return $this->prices( $query_params );
381
+		$query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax))));
382
+		return $this->prices($query_params);
383 383
 	}
384 384
 
385 385
 
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
      * @return EE_Price[]|EE_Base_Class[]
392 392
      * @throws \EE_Error
393 393
      */
394
-	public function prices( $query_params = array() ) {
395
-		return $this->get_many_related( 'Price', $query_params );
394
+	public function prices($query_params = array()) {
395
+		return $this->get_many_related('Price', $query_params);
396 396
 	}
397 397
 
398 398
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
      * @return EE_Datetime_Ticket|EE_Base_Class[]
405 405
      * @throws \EE_Error
406 406
      */
407
-	public function datetime_tickets( $query_params = array() ) {
408
-		return $this->get_many_related( 'Datetime_Ticket', $query_params );
407
+	public function datetime_tickets($query_params = array()) {
408
+		return $this->get_many_related('Datetime_Ticket', $query_params);
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
      * @return EE_Datetime[]
419 419
      * @throws \EE_Error
420 420
      */
421
-	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422
-		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
421
+	public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) {
422
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted);
423 423
 	}
424 424
 
425 425
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @throws \EE_Error
432 432
      */
433 433
 	public function ID() {
434
-		return $this->get( 'TKT_ID' );
434
+		return $this->get('TKT_ID');
435 435
 	}
436 436
 
437 437
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
      * @throws \EE_Error
457 457
      */
458 458
 	public function template() {
459
-		return $this->get_first_related( 'Ticket_Template' );
459
+		return $this->get_first_related('Ticket_Template');
460 460
 	}
461 461
 
462 462
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      * @throws \EE_Error
479 479
      */
480 480
 	public function ticket_price() {
481
-		return $this->get( 'TKT_price' );
481
+		return $this->get('TKT_price');
482 482
 	}
483 483
 
484 484
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      * @throws \EE_Error
489 489
      */
490 490
 	public function pretty_price() {
491
-		return $this->get_pretty( 'TKT_price' );
491
+		return $this->get_pretty('TKT_price');
492 492
 	}
493 493
 
494 494
 
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
      * @return float
511 511
      * @throws \EE_Error
512 512
      */
513
-	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514
-		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
513
+	public function get_ticket_total_with_taxes($no_cache = FALSE) {
514
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
516 516
 		}
517 517
 		return (float) $this->_ticket_total_with_taxes;
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 
521 521
 
522 522
 	public function ensure_TKT_Price_correct() {
523
-		$this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) );
523
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
524 524
 		$this->save();
525 525
 	}
526 526
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      * @throws \EE_Error
532 532
      */
533 533
 	public function get_ticket_subtotal() {
534
-		return EE_Taxes::get_subtotal_for_admin( $this );
534
+		return EE_Taxes::get_subtotal_for_admin($this);
535 535
 	}
536 536
 
537 537
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
      * @throws \EE_Error
544 544
      */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546
-		return EE_Taxes::get_total_taxes_for_admin( $this );
546
+		return EE_Taxes::get_total_taxes_for_admin($this);
547 547
 	}
548 548
 
549 549
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
      * @param string $name
555 555
      * @throws \EE_Error
556 556
      */
557
-	public function set_name( $name ) {
558
-		$this->set( 'TKT_name', $name );
557
+	public function set_name($name) {
558
+		$this->set('TKT_name', $name);
559 559
 	}
560 560
 
561 561
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * @throws \EE_Error
568 568
      */
569 569
 	public function description() {
570
-		return $this->get( 'TKT_description' );
570
+		return $this->get('TKT_description');
571 571
 	}
572 572
 
573 573
 
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
      * @param string $description
579 579
      * @throws \EE_Error
580 580
      */
581
-	public function set_description( $description ) {
582
-		$this->set( 'TKT_description', $description );
581
+	public function set_description($description) {
582
+		$this->set('TKT_description', $description);
583 583
 	}
584 584
 
585 585
 
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
      * @return string
593 593
      * @throws \EE_Error
594 594
      */
595
-	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596
-		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
595
+	public function start_date($dt_frmt = '', $tm_frmt = '') {
596
+		return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
597 597
 	}
598 598
 
599 599
 
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
      * @return void
606 606
      * @throws \EE_Error
607 607
      */
608
-	public function set_start_date( $start_date ) {
609
-		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
608
+	public function set_start_date($start_date) {
609
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
610 610
 	}
611 611
 
612 612
 
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
      * @return string
620 620
      * @throws \EE_Error
621 621
      */
622
-	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623
-		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
622
+	public function end_date($dt_frmt = '', $tm_frmt = '') {
623
+		return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
624 624
 	}
625 625
 
626 626
 
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
      * @return void
633 633
      * @throws \EE_Error
634 634
      */
635
-	public function set_end_date( $end_date ) {
636
-		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
635
+	public function set_end_date($end_date) {
636
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
637 637
 	}
638 638
 
639 639
 
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
      * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646 646
      * @throws \EE_Error
647 647
      */
648
-	public function set_end_time( $time ) {
649
-		$this->_set_time_for( $time, 'TKT_end_date' );
648
+	public function set_end_time($time) {
649
+		$this->_set_time_for($time, 'TKT_end_date');
650 650
 	}
651 651
 
652 652
 
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
      * @return void
659 659
      * @throws \EE_Error
660 660
      */
661
-	public function set_min( $min ) {
662
-		$this->set( 'TKT_min', $min );
661
+	public function set_min($min) {
662
+		$this->set('TKT_min', $min);
663 663
 	}
664 664
 
665 665
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      * @throws \EE_Error
672 672
      */
673 673
 	public function max() {
674
-		return $this->get( 'TKT_max' );
674
+		return $this->get('TKT_max');
675 675
 	}
676 676
 
677 677
 
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
      * @return void
684 684
      * @throws \EE_Error
685 685
      */
686
-	public function set_max( $max ) {
687
-		$this->set( 'TKT_max', $max );
686
+	public function set_max($max) {
687
+		$this->set('TKT_max', $max);
688 688
 	}
689 689
 
690 690
 
@@ -696,8 +696,8 @@  discard block
 block discarded – undo
696 696
      * @return void
697 697
      * @throws \EE_Error
698 698
      */
699
-	public function set_price( $price ) {
700
-		$this->set( 'TKT_price', $price );
699
+	public function set_price($price) {
700
+		$this->set('TKT_price', $price);
701 701
 	}
702 702
 
703 703
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
      * @throws \EE_Error
710 710
      */
711 711
 	public function sold() {
712
-		return $this->get_raw( 'TKT_sold' );
712
+		return $this->get_raw('TKT_sold');
713 713
 	}
714 714
 
715 715
 
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
      * @return void
722 722
      * @throws \EE_Error
723 723
      */
724
-	public function set_sold( $sold ) {
724
+	public function set_sold($sold) {
725 725
 		// sold can not go below zero
726
-		$sold = max( 0, $sold );
727
-		$this->set( 'TKT_sold', $sold );
726
+		$sold = max(0, $sold);
727
+		$this->set('TKT_sold', $sold);
728 728
 	}
729 729
 
730 730
 
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
      * @return void
737 737
      * @throws \EE_Error
738 738
      */
739
-	public function increase_sold( $qty = 1 ) {
739
+	public function increase_sold($qty = 1) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
742 742
 		// via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
743
-		$this->decrease_reserved( $qty, false );
744
-		$this->_increase_sold_for_datetimes( $qty );
745
-		$this->set_sold( $sold );
743
+		$this->decrease_reserved($qty, false);
744
+		$this->_increase_sold_for_datetimes($qty);
745
+		$this->set_sold($sold);
746 746
 		do_action(
747 747
 		    'AHEE__EE_Ticket__increase_sold',
748 748
             $this,
@@ -760,12 +760,12 @@  discard block
 block discarded – undo
760 760
      * @return void
761 761
      * @throws \EE_Error
762 762
      */
763
-	protected function _increase_sold_for_datetimes( $qty = 1 ) {
763
+	protected function _increase_sold_for_datetimes($qty = 1) {
764 764
 		$datetimes = $this->datetimes();
765
-		if ( is_array( $datetimes ) ) {
766
-			foreach ( $datetimes as $datetime ) {
767
-				if ( $datetime instanceof EE_Datetime ) {
768
-					$datetime->increase_sold( $qty );
765
+		if (is_array($datetimes)) {
766
+			foreach ($datetimes as $datetime) {
767
+				if ($datetime instanceof EE_Datetime) {
768
+					$datetime->increase_sold($qty);
769 769
 					$datetime->save();
770 770
 				}
771 771
 			}
@@ -781,10 +781,10 @@  discard block
 block discarded – undo
781 781
      * @return void
782 782
      * @throws \EE_Error
783 783
      */
784
-	public function decrease_sold( $qty = 1 ) {
784
+	public function decrease_sold($qty = 1) {
785 785
 		$sold = $this->sold() - $qty;
786
-		$this->_decrease_sold_for_datetimes( $qty );
787
-		$this->set_sold( $sold );
786
+		$this->_decrease_sold_for_datetimes($qty);
787
+		$this->set_sold($sold);
788 788
         do_action(
789 789
             'AHEE__EE_Ticket__decrease_sold',
790 790
             $this,
@@ -802,12 +802,12 @@  discard block
 block discarded – undo
802 802
      * @return void
803 803
      * @throws \EE_Error
804 804
      */
805
-	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
805
+	protected function _decrease_sold_for_datetimes($qty = 1) {
806 806
 		$datetimes = $this->datetimes();
807
-		if ( is_array( $datetimes ) ) {
808
-			foreach ( $datetimes as $datetime ) {
809
-				if ( $datetime instanceof EE_Datetime ) {
810
-					$datetime->decrease_sold( $qty );
807
+		if (is_array($datetimes)) {
808
+			foreach ($datetimes as $datetime) {
809
+				if ($datetime instanceof EE_Datetime) {
810
+					$datetime->decrease_sold($qty);
811 811
 					$datetime->save();
812 812
 				}
813 813
 			}
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
      * @throws \EE_Error
824 824
      */
825 825
 	public function reserved() {
826
-		return $this->get_raw( 'TKT_reserved' );
826
+		return $this->get_raw('TKT_reserved');
827 827
 	}
828 828
 
829 829
 
@@ -835,10 +835,10 @@  discard block
 block discarded – undo
835 835
      * @return void
836 836
      * @throws \EE_Error
837 837
      */
838
-	public function set_reserved( $reserved ) {
838
+	public function set_reserved($reserved) {
839 839
 		// reserved can not go below zero
840
-		$reserved = max( 0, (int) $reserved );
841
-		$this->set( 'TKT_reserved', $reserved );
840
+		$reserved = max(0, (int) $reserved);
841
+		$this->set('TKT_reserved', $reserved);
842 842
 	}
843 843
 
844 844
 
@@ -850,11 +850,11 @@  discard block
 block discarded – undo
850 850
      * @return void
851 851
      * @throws \EE_Error
852 852
      */
853
-	public function increase_reserved( $qty = 1 ) {
854
-		$qty = absint( $qty );
853
+	public function increase_reserved($qty = 1) {
854
+		$qty = absint($qty);
855 855
 		$reserved = $this->reserved() + $qty;
856
-		$this->_increase_reserved_for_datetimes( $qty );
857
-		$this->set_reserved( $reserved );
856
+		$this->_increase_reserved_for_datetimes($qty);
857
+		$this->set_reserved($reserved);
858 858
         do_action(
859 859
             'AHEE__EE_Ticket__increase_reserved',
860 860
             $this,
@@ -872,12 +872,12 @@  discard block
 block discarded – undo
872 872
      * @return void
873 873
      * @throws \EE_Error
874 874
      */
875
-	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
875
+	protected function _increase_reserved_for_datetimes($qty = 1) {
876 876
 		$datetimes = $this->datetimes();
877
-		if ( is_array( $datetimes ) ) {
878
-			foreach ( $datetimes as $datetime ) {
879
-				if ( $datetime instanceof EE_Datetime ) {
880
-					$datetime->increase_reserved( $qty );
877
+		if (is_array($datetimes)) {
878
+			foreach ($datetimes as $datetime) {
879
+				if ($datetime instanceof EE_Datetime) {
880
+					$datetime->increase_reserved($qty);
881 881
 					$datetime->save();
882 882
 				}
883 883
 			}
@@ -894,12 +894,12 @@  discard block
 block discarded – undo
894 894
      * @return void
895 895
      * @throws \EE_Error
896 896
      */
897
-	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
898
-		$reserved = $this->reserved() - absint( $qty );
899
-		if ( $adjust_datetimes ) {
900
-			$this->_decrease_reserved_for_datetimes( $qty );
897
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true) {
898
+		$reserved = $this->reserved() - absint($qty);
899
+		if ($adjust_datetimes) {
900
+			$this->_decrease_reserved_for_datetimes($qty);
901 901
 		}
902
-		$this->set_reserved( $reserved );
902
+		$this->set_reserved($reserved);
903 903
         do_action(
904 904
             'AHEE__EE_Ticket__decrease_reserved',
905 905
             $this,
@@ -917,12 +917,12 @@  discard block
 block discarded – undo
917 917
      * @return void
918 918
      * @throws \EE_Error
919 919
      */
920
-	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
920
+	protected function _decrease_reserved_for_datetimes($qty = 1) {
921 921
 		$datetimes = $this->datetimes();
922
-		if ( is_array( $datetimes ) ) {
923
-			foreach ( $datetimes as $datetime ) {
924
-				if ( $datetime instanceof EE_Datetime ) {
925
-					$datetime->decrease_reserved( $qty );
922
+		if (is_array($datetimes)) {
923
+			foreach ($datetimes as $datetime) {
924
+				if ($datetime instanceof EE_Datetime) {
925
+					$datetime->decrease_reserved($qty);
926 926
 					$datetime->save();
927 927
 				}
928 928
 			}
@@ -943,14 +943,14 @@  discard block
 block discarded – undo
943 943
      * @return int
944 944
      * @throws \EE_Error
945 945
      */
946
-	public function qty( $context = '' ) {
947
-		switch ( $context ) {
946
+	public function qty($context = '') {
947
+		switch ($context) {
948 948
 			case 'reg_limit' :
949 949
 				return $this->real_quantity_on_ticket();
950 950
 			case 'saleable' :
951
-				return $this->real_quantity_on_ticket( 'saleable' );
951
+				return $this->real_quantity_on_ticket('saleable');
952 952
 			default:
953
-				return $this->get_raw( 'TKT_qty' );
953
+				return $this->get_raw('TKT_qty');
954 954
 		}
955 955
 	}
956 956
 
@@ -969,15 +969,15 @@  discard block
 block discarded – undo
969 969
      * @return int
970 970
      * @throws \EE_Error
971 971
      */
972
-	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
973
-		$raw = $this->get_raw( 'TKT_qty' );
972
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) {
973
+		$raw = $this->get_raw('TKT_qty');
974 974
 		// return immediately if it's zero
975
-		if ( $raw === 0 ) {
975
+		if ($raw === 0) {
976 976
 			return $raw;
977 977
 		}
978 978
 		//echo "\n\n<br />Ticket: " . $this->name() . '<br />';
979 979
 		// ensure qty doesn't exceed raw value for THIS ticket
980
-		$qty = min( EE_INF, $raw );
980
+		$qty = min(EE_INF, $raw);
981 981
 		//echo "\n . qty: " . $qty . '<br />';
982 982
 		// calculate this ticket's total sales and reservations
983 983
 		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
@@ -986,23 +986,23 @@  discard block
 block discarded – undo
986 986
 		//echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
987 987
 		// first we need to calculate the maximum number of tickets available for the datetime
988 988
 		// do we want data for one datetime or all of them ?
989
-		$query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array();
990
-		$datetimes = $this->datetimes( $query_params );
991
-		if ( is_array( $datetimes ) && ! empty( $datetimes ) ) {
992
-			foreach ( $datetimes as $datetime ) {
993
-				if ( $datetime instanceof EE_Datetime ) {
989
+		$query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
990
+		$datetimes = $this->datetimes($query_params);
991
+		if (is_array($datetimes) && ! empty($datetimes)) {
992
+			foreach ($datetimes as $datetime) {
993
+				if ($datetime instanceof EE_Datetime) {
994 994
 					$datetime->refresh_from_db();
995 995
 					//echo "\n . . datetime name: " . $datetime->name() . '<br />';
996 996
 					//echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
997 997
 					// initialize with no restrictions for each datetime
998 998
 					// but adjust datetime qty based on datetime reg limit
999
-					$datetime_qty = min( EE_INF, $datetime->reg_limit() );
999
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
1000 1000
 					//echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1001 1001
 					//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1002 1002
 					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
1003 1003
 					// and reservations for this datetime, that do NOT include sales and reservations
1004 1004
 					// for this ticket (so we add $this->sold() and $this->reserved() back in)
1005
-					if ( $context === 'saleable' ) {
1005
+					if ($context === 'saleable') {
1006 1006
 						$datetime_qty = max(
1007 1007
 							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1008 1008
 							0
@@ -1014,16 +1014,16 @@  discard block
 block discarded – undo
1014 1014
 						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1015 1015
 						//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1016 1016
 					}
1017
-					$qty = min( $datetime_qty, $qty );
1017
+					$qty = min($datetime_qty, $qty);
1018 1018
 					//echo "\n . . qty: " . $qty . '<br />';
1019 1019
 				}
1020 1020
 			}
1021 1021
 		}
1022 1022
 		// NOW that we know the  maximum number of tickets available for the datetime
1023 1023
 		// we can finally factor in the details for this specific ticket
1024
-		if ( $qty > 0 && $context === 'saleable' ) {
1024
+		if ($qty > 0 && $context === 'saleable') {
1025 1025
 			// and subtract the sales for THIS ticket
1026
-			$qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 );
1026
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1027 1027
 			//echo "\n . qty: " . $qty . '<br />';
1028 1028
 		}
1029 1029
 		//echo "\nFINAL QTY: " . $qty . "<br /><br />";
@@ -1039,14 +1039,14 @@  discard block
 block discarded – undo
1039 1039
 	 * @return void
1040 1040
 	 * @throws \EE_Error
1041 1041
 	 */
1042
-	public function set_qty( $qty ) {
1042
+	public function set_qty($qty) {
1043 1043
 		$datetimes = $this->datetimes();
1044
-		foreach ( $datetimes as $datetime ) {
1045
-			if ( $datetime instanceof EE_Datetime ) {
1046
-				$qty = min( $qty, $datetime->reg_limit() );
1044
+		foreach ($datetimes as $datetime) {
1045
+			if ($datetime instanceof EE_Datetime) {
1046
+				$qty = min($qty, $datetime->reg_limit());
1047 1047
 			}
1048 1048
 		}
1049
-		$this->set( 'TKT_qty', $qty );
1049
+		$this->set('TKT_qty', $qty);
1050 1050
 	}
1051 1051
 
1052 1052
 
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
      * @throws \EE_Error
1059 1059
      */
1060 1060
 	public function uses() {
1061
-		return $this->get( 'TKT_uses' );
1061
+		return $this->get('TKT_uses');
1062 1062
 	}
1063 1063
 
1064 1064
 
@@ -1070,8 +1070,8 @@  discard block
 block discarded – undo
1070 1070
      * @return void
1071 1071
      * @throws \EE_Error
1072 1072
      */
1073
-	public function set_uses( $uses ) {
1074
-		$this->set( 'TKT_uses', $uses );
1073
+	public function set_uses($uses) {
1074
+		$this->set('TKT_uses', $uses);
1075 1075
 	}
1076 1076
 
1077 1077
 
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
      * @throws \EE_Error
1084 1084
      */
1085 1085
 	public function required() {
1086
-		return $this->get( 'TKT_required' );
1086
+		return $this->get('TKT_required');
1087 1087
 	}
1088 1088
 
1089 1089
 
@@ -1095,8 +1095,8 @@  discard block
 block discarded – undo
1095 1095
      * @return void
1096 1096
      * @throws \EE_Error
1097 1097
      */
1098
-	public function set_required( $required ) {
1099
-		$this->set( 'TKT_required', $required );
1098
+	public function set_required($required) {
1099
+		$this->set('TKT_required', $required);
1100 1100
 	}
1101 1101
 
1102 1102
 
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
      * @throws \EE_Error
1109 1109
      */
1110 1110
 	public function taxable() {
1111
-		return $this->get( 'TKT_taxable' );
1111
+		return $this->get('TKT_taxable');
1112 1112
 	}
1113 1113
 
1114 1114
 
@@ -1120,8 +1120,8 @@  discard block
 block discarded – undo
1120 1120
      * @return void
1121 1121
      * @throws \EE_Error
1122 1122
      */
1123
-	public function set_taxable( $taxable ) {
1124
-		$this->set( 'TKT_taxable', $taxable );
1123
+	public function set_taxable($taxable) {
1124
+		$this->set('TKT_taxable', $taxable);
1125 1125
 	}
1126 1126
 
1127 1127
 
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
      * @throws \EE_Error
1134 1134
      */
1135 1135
 	public function is_default() {
1136
-		return $this->get( 'TKT_is_default' );
1136
+		return $this->get('TKT_is_default');
1137 1137
 	}
1138 1138
 
1139 1139
 
@@ -1145,8 +1145,8 @@  discard block
 block discarded – undo
1145 1145
      * @return void
1146 1146
      * @throws \EE_Error
1147 1147
      */
1148
-	public function set_is_default( $is_default ) {
1149
-		$this->set( 'TKT_is_default', $is_default );
1148
+	public function set_is_default($is_default) {
1149
+		$this->set('TKT_is_default', $is_default);
1150 1150
 	}
1151 1151
 
1152 1152
 
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
      * @throws \EE_Error
1159 1159
      */
1160 1160
 	public function order() {
1161
-		return $this->get( 'TKT_order' );
1161
+		return $this->get('TKT_order');
1162 1162
 	}
1163 1163
 
1164 1164
 
@@ -1170,8 +1170,8 @@  discard block
 block discarded – undo
1170 1170
      * @return void
1171 1171
      * @throws \EE_Error
1172 1172
      */
1173
-	public function set_order( $order ) {
1174
-		$this->set( 'TKT_order', $order );
1173
+	public function set_order($order) {
1174
+		$this->set('TKT_order', $order);
1175 1175
 	}
1176 1176
 
1177 1177
 
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
      * @throws \EE_Error
1184 1184
      */
1185 1185
 	public function row() {
1186
-		return $this->get( 'TKT_row' );
1186
+		return $this->get('TKT_row');
1187 1187
 	}
1188 1188
 
1189 1189
 
@@ -1195,8 +1195,8 @@  discard block
 block discarded – undo
1195 1195
      * @return void
1196 1196
      * @throws \EE_Error
1197 1197
      */
1198
-	public function set_row( $row ) {
1199
-		$this->set( 'TKT_row', $row );
1198
+	public function set_row($row) {
1199
+		$this->set('TKT_row', $row);
1200 1200
 	}
1201 1201
 
1202 1202
 
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
      * @throws \EE_Error
1209 1209
      */
1210 1210
 	public function deleted() {
1211
-		return $this->get( 'TKT_deleted' );
1211
+		return $this->get('TKT_deleted');
1212 1212
 	}
1213 1213
 
1214 1214
 
@@ -1220,8 +1220,8 @@  discard block
 block discarded – undo
1220 1220
      * @return void
1221 1221
      * @throws \EE_Error
1222 1222
      */
1223
-	public function set_deleted( $deleted ) {
1224
-		$this->set( 'TKT_deleted', $deleted );
1223
+	public function set_deleted($deleted) {
1224
+		$this->set('TKT_deleted', $deleted);
1225 1225
 	}
1226 1226
 
1227 1227
 
@@ -1233,7 +1233,7 @@  discard block
 block discarded – undo
1233 1233
      * @throws \EE_Error
1234 1234
      */
1235 1235
 	public function parent_ID() {
1236
-		return $this->get( 'TKT_parent' );
1236
+		return $this->get('TKT_parent');
1237 1237
 	}
1238 1238
 
1239 1239
 
@@ -1245,8 +1245,8 @@  discard block
 block discarded – undo
1245 1245
      * @return void
1246 1246
      * @throws \EE_Error
1247 1247
      */
1248
-	public function set_parent_ID( $parent ) {
1249
-		$this->set( 'TKT_parent', $parent );
1248
+	public function set_parent_ID($parent) {
1249
+		$this->set('TKT_parent', $parent);
1250 1250
 	}
1251 1251
 
1252 1252
 
@@ -1259,10 +1259,10 @@  discard block
 block discarded – undo
1259 1259
      */
1260 1260
 	public function name_and_info() {
1261 1261
 		$times = array();
1262
-		foreach ( $this->datetimes() as $datetime ) {
1262
+		foreach ($this->datetimes() as $datetime) {
1263 1263
 			$times[] = $datetime->start_date_and_time();
1264 1264
 		}
1265
-		return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price();
1265
+		return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1266 1266
 	}
1267 1267
 
1268 1268
 
@@ -1274,7 +1274,7 @@  discard block
 block discarded – undo
1274 1274
      * @throws \EE_Error
1275 1275
      */
1276 1276
 	public function name() {
1277
-		return $this->get( 'TKT_name' );
1277
+		return $this->get('TKT_name');
1278 1278
 	}
1279 1279
 
1280 1280
 
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
      * @throws \EE_Error
1287 1287
      */
1288 1288
 	public function price() {
1289
-		return $this->get( 'TKT_price' );
1289
+		return $this->get('TKT_price');
1290 1290
 	}
1291 1291
 
1292 1292
 
@@ -1298,8 +1298,8 @@  discard block
 block discarded – undo
1298 1298
      * @return EE_Registration[]|EE_Base_Class[]
1299 1299
      * @throws \EE_Error
1300 1300
      */
1301
-	public function registrations( $query_params = array() ) {
1302
-		return $this->get_many_related( 'Registration', $query_params );
1301
+	public function registrations($query_params = array()) {
1302
+		return $this->get_many_related('Registration', $query_params);
1303 1303
 	}
1304 1304
 
1305 1305
 
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
 	 * @param array $query_params like EEM_Base::get_all's
1339 1339
 	 * @return int
1340 1340
 	 */
1341
-	public function count_registrations( $query_params = array() ) {
1341
+	public function count_registrations($query_params = array()) {
1342 1342
 		return $this->count_related('Registration', $query_params);
1343 1343
 	}
1344 1344
 
@@ -1366,23 +1366,23 @@  discard block
 block discarded – undo
1366 1366
 	public function get_related_event() {
1367 1367
 		//get one datetime to use for getting the event
1368 1368
 		$datetime = $this->first_datetime();
1369
-		if ( ! $datetime instanceof \EE_Datetime ) {
1369
+		if ( ! $datetime instanceof \EE_Datetime) {
1370 1370
 			throw new UnexpectedEntityException(
1371 1371
 				$datetime,
1372 1372
                 'EE_Datetime',
1373 1373
 				sprintf(
1374
-					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1374
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1375 1375
 					$this->name()
1376 1376
 				)
1377 1377
 			);
1378 1378
 		}
1379 1379
 		$event = $datetime->event();
1380
-		if ( ! $event instanceof \EE_Event ) {
1380
+		if ( ! $event instanceof \EE_Event) {
1381 1381
 			throw new UnexpectedEntityException(
1382 1382
 				$event,
1383 1383
                 'EE_Event',
1384 1384
 				sprintf(
1385
-					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1385
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1386 1386
 					$this->name()
1387 1387
 				)
1388 1388
 			);
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         EE_Maintenance_Mode $maintenance_mode = null
133 133
     ) {
134 134
         // check if class object is instantiated
135
-        if (! self::$_instance instanceof EE_System) {
135
+        if ( ! self::$_instance instanceof EE_System) {
136 136
             self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137 137
         }
138 138
         return self::$_instance;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     {
299 299
         // set autoloaders for all of the classes implementing EEI_Plugin_API
300 300
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
301
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
301
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
302 302
     }
303 303
 
304 304
 
@@ -317,14 +317,14 @@  discard block
 block discarded – undo
317 317
         $load_callback,
318 318
         $plugin_file_constant
319 319
     ) {
320
-        if (! defined($version_constant)) {
320
+        if ( ! defined($version_constant)) {
321 321
             return;
322 322
         }
323 323
         $addon_version = constant($version_constant);
324 324
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
325 325
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
326
-            if (! function_exists('deactivate_plugins')) {
327
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
326
+            if ( ! function_exists('deactivate_plugins')) {
327
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
328 328
             }
329 329
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
330 330
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                     $addon_name,
338 338
                     $min_version_required
339 339
                 ),
340
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
340
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
341 341
             );
342 342
             EE_Error::get_notices(false, true);
343 343
         }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
                 && in_array($_GET['action'], array('activate', 'activate-selected'), true)
390 390
             )
391 391
         ) {
392
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
392
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
393 393
         }
394 394
         do_action('AHEE__EE_System__load_espresso_addons__complete');
395 395
     }
@@ -497,11 +497,11 @@  discard block
 block discarded – undo
497 497
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498 498
     {
499 499
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
-        if (! $espresso_db_update) {
500
+        if ( ! $espresso_db_update) {
501 501
             $espresso_db_update = get_option('espresso_db_update');
502 502
         }
503 503
         // check that option is an array
504
-        if (! is_array($espresso_db_update)) {
504
+        if ( ! is_array($espresso_db_update)) {
505 505
             // if option is FALSE, then it never existed
506 506
             if ($espresso_db_update === false) {
507 507
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
      */
607 607
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
608 608
     {
609
-        if (! $version_history) {
609
+        if ( ! $version_history) {
610 610
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
611 611
         }
612 612
         if ($current_version_to_add === null) {
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         if ($activation_history_for_addon) {
705 705
             //it exists, so this isn't a completely new install
706 706
             //check if this version already in that list of previously installed versions
707
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
707
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
708 708
                 //it a version we haven't seen before
709 709
                 if ($version_is_higher === 1) {
710 710
                     $req_type = EE_System::req_type_upgrade;
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
             foreach ($activation_history as $version => $times_activated) {
785 785
                 //check there is a record of when this version was activated. Otherwise,
786 786
                 //mark it as unknown
787
-                if (! $times_activated) {
787
+                if ( ! $times_activated) {
788 788
                     $times_activated = array('unknown-date');
789 789
                 }
790 790
                 if (is_string($times_activated)) {
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
     private function _parse_model_names()
885 885
     {
886 886
         //get all the files in the EE_MODELS folder that end in .model.php
887
-        $models = glob(EE_MODELS . '*.model.php');
887
+        $models = glob(EE_MODELS.'*.model.php');
888 888
         $model_names = array();
889 889
         $non_abstract_db_models = array();
890 890
         foreach ($models as $model) {
@@ -914,8 +914,8 @@  discard block
 block discarded – undo
914 914
      */
915 915
     private function _maybe_brew_regular()
916 916
     {
917
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
918
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
917
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
918
+            require_once EE_CAFF_PATH.'brewing_regular.php';
919 919
         }
920 920
     }
921 921
 
@@ -966,17 +966,17 @@  discard block
 block discarded – undo
966 966
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967 967
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
968 968
         );
969
-        if (! empty($class_names)) {
969
+        if ( ! empty($class_names)) {
970 970
             $msg = __(
971 971
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972 972
                 'event_espresso'
973 973
             );
974 974
             $msg .= '<ul>';
975 975
             foreach ($class_names as $class_name) {
976
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
976
+                $msg .= '<li><b>Event Espresso - '.str_replace(
977 977
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
978 978
                         $class_name
979
-                    ) . '</b></li>';
979
+                    ).'</b></li>';
980 980
             }
981 981
             $msg .= '</ul>';
982 982
             $msg .= __(
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
     private function _deactivate_incompatible_addons()
1048 1048
     {
1049 1049
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1050
-        if (! empty($incompatible_addons)) {
1050
+        if ( ! empty($incompatible_addons)) {
1051 1051
             $active_plugins = get_option('active_plugins', array());
1052 1052
             foreach ($active_plugins as $active_plugin) {
1053 1053
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1108,10 +1108,10 @@  discard block
 block discarded – undo
1108 1108
     {
1109 1109
         do_action('AHEE__EE_System__load_controllers__start');
1110 1110
         // let's get it started
1111
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
1111
+        if ( ! is_admin() && ! $this->maintenance_mode->level()) {
1112 1112
             do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1113 1113
             $this->loader->getShared('EE_Front_Controller');
1114
-        } else if (! EE_FRONT_AJAX) {
1114
+        } else if ( ! EE_FRONT_AJAX) {
1115 1115
             do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1116 1116
             $this->loader->getShared('EE_Admin');
1117 1117
         }
@@ -1132,8 +1132,8 @@  discard block
 block discarded – undo
1132 1132
         $this->loader->getShared('EE_Session');
1133 1133
         do_action('AHEE__EE_System__core_loaded_and_ready');
1134 1134
         // load_espresso_template_tags
1135
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1136
-            require_once(EE_PUBLIC . 'template_tags.php');
1135
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
1136
+            require_once(EE_PUBLIC.'template_tags.php');
1137 1137
         }
1138 1138
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1139 1139
         $this->loader->getShared('EventEspresso\core\services\assets\Registry');
@@ -1195,13 +1195,13 @@  discard block
 block discarded – undo
1195 1195
     public static function do_not_cache()
1196 1196
     {
1197 1197
         // set no cache constants
1198
-        if (! defined('DONOTCACHEPAGE')) {
1198
+        if ( ! defined('DONOTCACHEPAGE')) {
1199 1199
             define('DONOTCACHEPAGE', true);
1200 1200
         }
1201
-        if (! defined('DONOTCACHCEOBJECT')) {
1201
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1202 1202
             define('DONOTCACHCEOBJECT', true);
1203 1203
         }
1204
-        if (! defined('DONOTCACHEDB')) {
1204
+        if ( ! defined('DONOTCACHEDB')) {
1205 1205
             define('DONOTCACHEDB', true);
1206 1206
         }
1207 1207
         // add no cache headers
Please login to merge, or discard this patch.
Indentation   +1236 added lines, -1236 removed lines patch added patch discarded remove patch
@@ -21,1242 +21,1242 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
-     */
28
-    const req_type_normal = 0;
29
-
30
-    /**
31
-     * Indicates this is a brand new installation of EE so we should install
32
-     * tables and default data etc
33
-     */
34
-    const req_type_new_activation = 1;
35
-
36
-    /**
37
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
-     * and we just exited maintenance mode). We MUST check the database is setup properly
39
-     * and that default data is setup too
40
-     */
41
-    const req_type_reactivation = 2;
42
-
43
-    /**
44
-     * indicates that EE has been upgraded since its previous request.
45
-     * We may have data migration scripts to call and will want to trigger maintenance mode
46
-     */
47
-    const req_type_upgrade = 3;
48
-
49
-    /**
50
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
-     */
52
-    const req_type_downgrade = 4;
53
-
54
-    /**
55
-     * @deprecated since version 4.6.0.dev.006
56
-     * Now whenever a new_activation is detected the request type is still just
57
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
-     * (Specifically, when the migration manager indicates migrations are finished
61
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
-     */
63
-    const req_type_activation_but_not_installed = 5;
64
-
65
-    /**
66
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
-     */
68
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
-
70
-
71
-    /**
72
-     * @var EE_System $_instance
73
-     */
74
-    private static $_instance;
75
-
76
-    /**
77
-     * @var EE_Registry $registry
78
-     */
79
-    private $registry;
80
-
81
-    /**
82
-     * @var LoaderInterface $loader
83
-     */
84
-    private $loader;
85
-
86
-    /**
87
-     * @var EE_Capabilities $capabilities
88
-     */
89
-    private $capabilities;
90
-
91
-    /**
92
-     * @var EE_Request $request
93
-     */
94
-    private $request;
95
-
96
-    /**
97
-     * @var EE_Maintenance_Mode $maintenance_mode
98
-     */
99
-    private $maintenance_mode;
100
-
101
-    /**
102
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
103
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
104
-     *
105
-     * @var int $_req_type
106
-     */
107
-    private $_req_type;
108
-
109
-    /**
110
-     * Whether or not there was a non-micro version change in EE core version during this request
111
-     *
112
-     * @var boolean $_major_version_change
113
-     */
114
-    private $_major_version_change = false;
115
-
116
-
117
-
118
-    /**
119
-     * @singleton method used to instantiate class object
120
-     * @param EE_Registry|null         $registry
121
-     * @param LoaderInterface|null     $loader
122
-     * @param EE_Capabilities|null     $capabilities
123
-     * @param EE_Request|null          $request
124
-     * @param EE_Maintenance_Mode|null $maintenance_mode
125
-     * @return EE_System
126
-     */
127
-    public static function instance(
128
-        EE_Registry $registry = null,
129
-        LoaderInterface $loader = null,
130
-        EE_Capabilities $capabilities = null,
131
-        EE_Request $request = null,
132
-        EE_Maintenance_Mode $maintenance_mode = null
133
-    ) {
134
-        // check if class object is instantiated
135
-        if (! self::$_instance instanceof EE_System) {
136
-            self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137
-        }
138
-        return self::$_instance;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * resets the instance and returns it
145
-     *
146
-     * @return EE_System
147
-     */
148
-    public static function reset()
149
-    {
150
-        self::$_instance->_req_type = null;
151
-        //make sure none of the old hooks are left hanging around
152
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
153
-        //we need to reset the migration manager in order for it to detect DMSs properly
154
-        EE_Data_Migration_Manager::reset();
155
-        self::instance()->detect_activations_or_upgrades();
156
-        self::instance()->perform_activations_upgrades_and_migrations();
157
-        return self::instance();
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * sets hooks for running rest of system
164
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
165
-     * starting EE Addons from any other point may lead to problems
166
-     *
167
-     * @param EE_Registry         $registry
168
-     * @param LoaderInterface     $loader
169
-     * @param EE_Capabilities     $capabilities
170
-     * @param EE_Request          $request
171
-     * @param EE_Maintenance_Mode $maintenance_mode
172
-     */
173
-    private function __construct(
174
-        EE_Registry $registry,
175
-        LoaderInterface $loader,
176
-        EE_Capabilities $capabilities,
177
-        EE_Request $request,
178
-        EE_Maintenance_Mode $maintenance_mode
179
-    ) {
180
-        $this->registry = $registry;
181
-        $this->loader = $loader;
182
-        $this->capabilities = $capabilities;
183
-        $this->request = $request;
184
-        $this->maintenance_mode = $maintenance_mode;
185
-        do_action('AHEE__EE_System__construct__begin', $this);
186
-        add_action(
187
-            'AHEE__EE_Bootstrap__load_espresso_addons',
188
-            array($this, 'loadCapabilities'),
189
-            5
190
-        );
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCommandBus'),
194
-            7
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadPluginApi'),
199
-            9
200
-        );
201
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
202
-        add_action(
203
-            'AHEE__EE_Bootstrap__load_espresso_addons',
204
-            array($this, 'load_espresso_addons')
205
-        );
206
-        // when an ee addon is activated, we want to call the core hook(s) again
207
-        // because the newly-activated addon didn't get a chance to run at all
208
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
209
-        // detect whether install or upgrade
210
-        add_action(
211
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
212
-            array($this, 'detect_activations_or_upgrades'),
213
-            3
214
-        );
215
-        // load EE_Config, EE_Textdomain, etc
216
-        add_action(
217
-            'AHEE__EE_Bootstrap__load_core_configuration',
218
-            array($this, 'load_core_configuration'),
219
-            5
220
-        );
221
-        // load EE_Config, EE_Textdomain, etc
222
-        add_action(
223
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
224
-            array($this, 'register_shortcodes_modules_and_widgets'),
225
-            7
226
-        );
227
-        // you wanna get going? I wanna get going... let's get going!
228
-        add_action(
229
-            'AHEE__EE_Bootstrap__brew_espresso',
230
-            array($this, 'brew_espresso'),
231
-            9
232
-        );
233
-        //other housekeeping
234
-        //exclude EE critical pages from wp_list_pages
235
-        add_filter(
236
-            'wp_list_pages_excludes',
237
-            array($this, 'remove_pages_from_wp_list_pages'),
238
-            10
239
-        );
240
-        // ALL EE Addons should use the following hook point to attach their initial setup too
241
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
242
-        do_action('AHEE__EE_System__construct__complete', $this);
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * load and setup EE_Capabilities
249
-     *
250
-     * @return void
251
-     * @throws EE_Error
252
-     */
253
-    public function loadCapabilities()
254
-    {
255
-        $this->loader->getShared('EE_Capabilities');
256
-        add_action(
257
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
258
-            function() {
259
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
260
-            }
261
-        );
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     * create and cache the CommandBus, and also add middleware
268
-     * The CapChecker middleware requires the use of EE_Capabilities
269
-     * which is why we need to load the CommandBus after Caps are set up
270
-     *
271
-     * @return void
272
-     * @throws EE_Error
273
-     */
274
-    public function loadCommandBus()
275
-    {
276
-        $this->loader->getShared(
277
-            'CommandBusInterface',
278
-            array(
279
-                null,
280
-                apply_filters(
281
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
282
-                    array(
283
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
284
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
285
-                    )
286
-                ),
287
-            )
288
-        );
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * @return void
295
-     * @throws EE_Error
296
-     */
297
-    public function loadPluginApi()
298
-    {
299
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
300
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
301
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
302
-    }
303
-
304
-
305
-    /**
306
-     * @param string $addon_name
307
-     * @param string $version_constant
308
-     * @param string $min_version_required
309
-     * @param string $load_callback
310
-     * @param string $plugin_file_constant
311
-     * @return void
312
-     */
313
-    private function deactivateIncompatibleAddon(
314
-        $addon_name,
315
-        $version_constant,
316
-        $min_version_required,
317
-        $load_callback,
318
-        $plugin_file_constant
319
-    ) {
320
-        if (! defined($version_constant)) {
321
-            return;
322
-        }
323
-        $addon_version = constant($version_constant);
324
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
325
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
326
-            if (! function_exists('deactivate_plugins')) {
327
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
328
-            }
329
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
330
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
331
-            EE_Error::add_error(
332
-                sprintf(
333
-                    esc_html__(
334
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
335
-                        'event_espresso'
336
-                    ),
337
-                    $addon_name,
338
-                    $min_version_required
339
-                ),
340
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
341
-            );
342
-            EE_Error::get_notices(false, true);
343
-        }
344
-    }
345
-
346
-
347
-    /**
348
-     * load_espresso_addons
349
-     * allow addons to load first so that they can set hooks for running DMS's, etc
350
-     * this is hooked into both:
351
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
352
-     *        which runs during the WP 'plugins_loaded' action at priority 5
353
-     *    and the WP 'activate_plugin' hook point
354
-     *
355
-     * @access public
356
-     * @return void
357
-     */
358
-    public function load_espresso_addons()
359
-    {
360
-        $this->deactivateIncompatibleAddon(
361
-            'Wait Lists',
362
-            'EE_WAIT_LISTS_VERSION',
363
-            '1.0.0.beta.074',
364
-            'load_espresso_wait_lists',
365
-            'EE_WAIT_LISTS_PLUGIN_FILE'
366
-        );
367
-        $this->deactivateIncompatibleAddon(
368
-            'Automated Upcoming Event Notifications',
369
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
370
-            '1.0.0.beta.091',
371
-            'load_espresso_automated_upcoming_event_notification',
372
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
373
-        );
374
-        do_action('AHEE__EE_System__load_espresso_addons');
375
-        //if the WP API basic auth plugin isn't already loaded, load it now.
376
-        //We want it for mobile apps. Just include the entire plugin
377
-        //also, don't load the basic auth when a plugin is getting activated, because
378
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
379
-        //and causes a fatal error
380
-        if (
381
-            ! (
382
-                isset($_GET['activate'])
383
-                && $_GET['activate'] === 'true'
384
-            )
385
-            && ! function_exists('json_basic_auth_handler')
386
-            && ! function_exists('json_basic_auth_error')
387
-            && ! (
388
-                isset($_GET['action'])
389
-                && in_array($_GET['action'], array('activate', 'activate-selected'), true)
390
-            )
391
-        ) {
392
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
393
-        }
394
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * detect_activations_or_upgrades
401
-     * Checks for activation or upgrade of core first;
402
-     * then also checks if any registered addons have been activated or upgraded
403
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
404
-     * which runs during the WP 'plugins_loaded' action at priority 3
405
-     *
406
-     * @access public
407
-     * @return void
408
-     */
409
-    public function detect_activations_or_upgrades()
410
-    {
411
-        //first off: let's make sure to handle core
412
-        $this->detect_if_activation_or_upgrade();
413
-        foreach ($this->registry->addons as $addon) {
414
-            if ($addon instanceof EE_Addon) {
415
-                //detect teh request type for that addon
416
-                $addon->detect_activation_or_upgrade();
417
-            }
418
-        }
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * detect_if_activation_or_upgrade
425
-     * Takes care of detecting whether this is a brand new install or code upgrade,
426
-     * and either setting up the DB or setting up maintenance mode etc.
427
-     *
428
-     * @access public
429
-     * @return void
430
-     */
431
-    public function detect_if_activation_or_upgrade()
432
-    {
433
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
434
-        // check if db has been updated, or if its a brand-new installation
435
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
436
-        $request_type = $this->detect_req_type($espresso_db_update);
437
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
438
-        switch ($request_type) {
439
-            case EE_System::req_type_new_activation:
440
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
441
-                $this->_handle_core_version_change($espresso_db_update);
442
-                break;
443
-            case EE_System::req_type_reactivation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_upgrade:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
449
-                //migrations may be required now that we've upgraded
450
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
451
-                $this->_handle_core_version_change($espresso_db_update);
452
-                //				echo "done upgrade";die;
453
-                break;
454
-            case EE_System::req_type_downgrade:
455
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
456
-                //its possible migrations are no longer required
457
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
458
-                $this->_handle_core_version_change($espresso_db_update);
459
-                break;
460
-            case EE_System::req_type_normal:
461
-            default:
462
-                //				$this->_maybe_redirect_to_ee_about();
463
-                break;
464
-        }
465
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     * Updates the list of installed versions and sets hooks for
472
-     * initializing the database later during the request
473
-     *
474
-     * @param array $espresso_db_update
475
-     */
476
-    private function _handle_core_version_change($espresso_db_update)
477
-    {
478
-        $this->update_list_of_installed_versions($espresso_db_update);
479
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
480
-        add_action(
481
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
482
-            array($this, 'initialize_db_if_no_migrations_required')
483
-        );
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
490
-     * information about what versions of EE have been installed and activated,
491
-     * NOT necessarily the state of the database
492
-     *
493
-     * @param mixed $espresso_db_update the value of the WordPress option.
494
-     *                                            If not supplied, fetches it from the options table
495
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
496
-     */
497
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498
-    {
499
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
-        if (! $espresso_db_update) {
501
-            $espresso_db_update = get_option('espresso_db_update');
502
-        }
503
-        // check that option is an array
504
-        if (! is_array($espresso_db_update)) {
505
-            // if option is FALSE, then it never existed
506
-            if ($espresso_db_update === false) {
507
-                // make $espresso_db_update an array and save option with autoload OFF
508
-                $espresso_db_update = array();
509
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
510
-            } else {
511
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
512
-                $espresso_db_update = array($espresso_db_update => array());
513
-                update_option('espresso_db_update', $espresso_db_update);
514
-            }
515
-        } else {
516
-            $corrected_db_update = array();
517
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
518
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
519
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
520
-                    //the key is an int, and the value IS NOT an array
521
-                    //so it must be numerically-indexed, where values are versions installed...
522
-                    //fix it!
523
-                    $version_string = $should_be_array;
524
-                    $corrected_db_update[$version_string] = array('unknown-date');
525
-                } else {
526
-                    //ok it checks out
527
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
528
-                }
529
-            }
530
-            $espresso_db_update = $corrected_db_update;
531
-            update_option('espresso_db_update', $espresso_db_update);
532
-        }
533
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
534
-        return $espresso_db_update;
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * Does the traditional work of setting up the plugin's database and adding default data.
541
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
542
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
543
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
544
-     * so that it will be done when migrations are finished
545
-     *
546
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
547
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
548
-     *                                       This is a resource-intensive job
549
-     *                                       so we prefer to only do it when necessary
550
-     * @return void
551
-     * @throws EE_Error
552
-     */
553
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
554
-    {
555
-        $request_type = $this->detect_req_type();
556
-        //only initialize system if we're not in maintenance mode.
557
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
558
-            update_option('ee_flush_rewrite_rules', true);
559
-            if ($verify_schema) {
560
-                EEH_Activation::initialize_db_and_folders();
561
-            }
562
-            EEH_Activation::initialize_db_content();
563
-            EEH_Activation::system_initialization();
564
-            if ($initialize_addons_too) {
565
-                $this->initialize_addons();
566
-            }
567
-        } else {
568
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
569
-        }
570
-        if ($request_type === EE_System::req_type_new_activation
571
-            || $request_type === EE_System::req_type_reactivation
572
-            || (
573
-                $request_type === EE_System::req_type_upgrade
574
-                && $this->is_major_version_change()
575
-            )
576
-        ) {
577
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
578
-        }
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     * Initializes the db for all registered addons
585
-     *
586
-     * @throws EE_Error
587
-     */
588
-    public function initialize_addons()
589
-    {
590
-        //foreach registered addon, make sure its db is up-to-date too
591
-        foreach ($this->registry->addons as $addon) {
592
-            if ($addon instanceof EE_Addon) {
593
-                $addon->initialize_db_if_no_migrations_required();
594
-            }
595
-        }
596
-    }
597
-
598
-
599
-
600
-    /**
601
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
602
-     *
603
-     * @param    array  $version_history
604
-     * @param    string $current_version_to_add version to be added to the version history
605
-     * @return    boolean success as to whether or not this option was changed
606
-     */
607
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
608
-    {
609
-        if (! $version_history) {
610
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
611
-        }
612
-        if ($current_version_to_add === null) {
613
-            $current_version_to_add = espresso_version();
614
-        }
615
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
616
-        // re-save
617
-        return update_option('espresso_db_update', $version_history);
618
-    }
619
-
620
-
621
-
622
-    /**
623
-     * Detects if the current version indicated in the has existed in the list of
624
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
625
-     *
626
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
627
-     *                                  If not supplied, fetches it from the options table.
628
-     *                                  Also, caches its result so later parts of the code can also know whether
629
-     *                                  there's been an update or not. This way we can add the current version to
630
-     *                                  espresso_db_update, but still know if this is a new install or not
631
-     * @return int one of the constants on EE_System::req_type_
632
-     */
633
-    public function detect_req_type($espresso_db_update = null)
634
-    {
635
-        if ($this->_req_type === null) {
636
-            $espresso_db_update = ! empty($espresso_db_update)
637
-                ? $espresso_db_update
638
-                : $this->fix_espresso_db_upgrade_option();
639
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
640
-                $espresso_db_update,
641
-                'ee_espresso_activation', espresso_version()
642
-            );
643
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
644
-        }
645
-        return $this->_req_type;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * Returns whether or not there was a non-micro version change (ie, change in either
652
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
653
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
654
-     *
655
-     * @param $activation_history
656
-     * @return bool
657
-     */
658
-    private function _detect_major_version_change($activation_history)
659
-    {
660
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
661
-        $previous_version_parts = explode('.', $previous_version);
662
-        $current_version_parts = explode('.', espresso_version());
663
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
664
-               && ($previous_version_parts[0] !== $current_version_parts[0]
665
-                   || $previous_version_parts[1] !== $current_version_parts[1]
666
-               );
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     * Returns true if either the major or minor version of EE changed during this request.
673
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
674
-     *
675
-     * @return bool
676
-     */
677
-    public function is_major_version_change()
678
-    {
679
-        return $this->_major_version_change;
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
686
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
687
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
688
-     * just activated to (for core that will always be espresso_version())
689
-     *
690
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
691
-     *                                                 ee plugin. for core that's 'espresso_db_update'
692
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
693
-     *                                                 indicate that this plugin was just activated
694
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
695
-     *                                                 espresso_version())
696
-     * @return int one of the constants on EE_System::req_type_*
697
-     */
698
-    public static function detect_req_type_given_activation_history(
699
-        $activation_history_for_addon,
700
-        $activation_indicator_option_name,
701
-        $version_to_upgrade_to
702
-    ) {
703
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
704
-        if ($activation_history_for_addon) {
705
-            //it exists, so this isn't a completely new install
706
-            //check if this version already in that list of previously installed versions
707
-            if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
708
-                //it a version we haven't seen before
709
-                if ($version_is_higher === 1) {
710
-                    $req_type = EE_System::req_type_upgrade;
711
-                } else {
712
-                    $req_type = EE_System::req_type_downgrade;
713
-                }
714
-                delete_option($activation_indicator_option_name);
715
-            } else {
716
-                // its not an update. maybe a reactivation?
717
-                if (get_option($activation_indicator_option_name, false)) {
718
-                    if ($version_is_higher === -1) {
719
-                        $req_type = EE_System::req_type_downgrade;
720
-                    } else if ($version_is_higher === 0) {
721
-                        //we've seen this version before, but it's an activation. must be a reactivation
722
-                        $req_type = EE_System::req_type_reactivation;
723
-                    } else {//$version_is_higher === 1
724
-                        $req_type = EE_System::req_type_upgrade;
725
-                    }
726
-                    delete_option($activation_indicator_option_name);
727
-                } else {
728
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
729
-                    if ($version_is_higher === -1) {
730
-                        $req_type = EE_System::req_type_downgrade;
731
-                    } else if ($version_is_higher === 0) {
732
-                        //we've seen this version before and it's not an activation. its normal request
733
-                        $req_type = EE_System::req_type_normal;
734
-                    } else {//$version_is_higher === 1
735
-                        $req_type = EE_System::req_type_upgrade;
736
-                    }
737
-                }
738
-            }
739
-        } else {
740
-            //brand new install
741
-            $req_type = EE_System::req_type_new_activation;
742
-            delete_option($activation_indicator_option_name);
743
-        }
744
-        return $req_type;
745
-    }
746
-
747
-
748
-
749
-    /**
750
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
751
-     * the $activation_history_for_addon
752
-     *
753
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
754
-     *                                             sometimes containing 'unknown-date'
755
-     * @param string $version_to_upgrade_to        (current version)
756
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
757
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
758
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
759
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
760
-     */
761
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
762
-    {
763
-        //find the most recently-activated version
764
-        $most_recently_active_version =
765
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
766
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
767
-    }
768
-
769
-
770
-
771
-    /**
772
-     * Gets the most recently active version listed in the activation history,
773
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
774
-     *
775
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
776
-     *                                   sometimes containing 'unknown-date'
777
-     * @return string
778
-     */
779
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
780
-    {
781
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
782
-        $most_recently_active_version = '0.0.0.dev.000';
783
-        if (is_array($activation_history)) {
784
-            foreach ($activation_history as $version => $times_activated) {
785
-                //check there is a record of when this version was activated. Otherwise,
786
-                //mark it as unknown
787
-                if (! $times_activated) {
788
-                    $times_activated = array('unknown-date');
789
-                }
790
-                if (is_string($times_activated)) {
791
-                    $times_activated = array($times_activated);
792
-                }
793
-                foreach ($times_activated as $an_activation) {
794
-                    if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
795
-                        $most_recently_active_version = $version;
796
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
797
-                            ? '1970-01-01 00:00:00'
798
-                            : $an_activation;
799
-                    }
800
-                }
801
-            }
802
-        }
803
-        return $most_recently_active_version;
804
-    }
805
-
806
-
807
-
808
-    /**
809
-     * This redirects to the about EE page after activation
810
-     *
811
-     * @return void
812
-     */
813
-    public function redirect_to_about_ee()
814
-    {
815
-        $notices = EE_Error::get_notices(false);
816
-        //if current user is an admin and it's not an ajax or rest request
817
-        if (
818
-            ! (defined('DOING_AJAX') && DOING_AJAX)
819
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
820
-            && ! isset($notices['errors'])
821
-            && apply_filters(
822
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
823
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
824
-            )
825
-        ) {
826
-            $query_params = array('page' => 'espresso_about');
827
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
828
-                $query_params['new_activation'] = true;
829
-            }
830
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
831
-                $query_params['reactivation'] = true;
832
-            }
833
-            $url = add_query_arg($query_params, admin_url('admin.php'));
834
-            wp_safe_redirect($url);
835
-            exit();
836
-        }
837
-    }
838
-
839
-
840
-
841
-    /**
842
-     * load_core_configuration
843
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
844
-     * which runs during the WP 'plugins_loaded' action at priority 5
845
-     *
846
-     * @return void
847
-     * @throws ReflectionException
848
-     */
849
-    public function load_core_configuration()
850
-    {
851
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
852
-        $this->loader->getShared('EE_Load_Textdomain');
853
-        //load textdomain
854
-        EE_Load_Textdomain::load_textdomain();
855
-        // load and setup EE_Config and EE_Network_Config
856
-        $config = $this->loader->getShared('EE_Config');
857
-        $this->loader->getShared('EE_Network_Config');
858
-        // setup autoloaders
859
-        // enable logging?
860
-        if ($config->admin->use_full_logging) {
861
-            $this->loader->getShared('EE_Log');
862
-        }
863
-        // check for activation errors
864
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
865
-        if ($activation_errors) {
866
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
867
-            update_option('ee_plugin_activation_errors', false);
868
-        }
869
-        // get model names
870
-        $this->_parse_model_names();
871
-        //load caf stuff a chance to play during the activation process too.
872
-        $this->_maybe_brew_regular();
873
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
874
-    }
875
-
876
-
877
-
878
-    /**
879
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
880
-     *
881
-     * @return void
882
-     * @throws ReflectionException
883
-     */
884
-    private function _parse_model_names()
885
-    {
886
-        //get all the files in the EE_MODELS folder that end in .model.php
887
-        $models = glob(EE_MODELS . '*.model.php');
888
-        $model_names = array();
889
-        $non_abstract_db_models = array();
890
-        foreach ($models as $model) {
891
-            // get model classname
892
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
893
-            $short_name = str_replace('EEM_', '', $classname);
894
-            $reflectionClass = new ReflectionClass($classname);
895
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
896
-                $non_abstract_db_models[$short_name] = $classname;
897
-            }
898
-            $model_names[$short_name] = $classname;
899
-        }
900
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
901
-        $this->registry->non_abstract_db_models = apply_filters(
902
-            'FHEE__EE_System__parse_implemented_model_names',
903
-            $non_abstract_db_models
904
-        );
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
911
-     * that need to be setup before our EE_System launches.
912
-     *
913
-     * @return void
914
-     */
915
-    private function _maybe_brew_regular()
916
-    {
917
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
918
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
919
-        }
920
-    }
921
-
922
-
923
-
924
-    /**
925
-     * register_shortcodes_modules_and_widgets
926
-     * generate lists of shortcodes and modules, then verify paths and classes
927
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
928
-     * which runs during the WP 'plugins_loaded' action at priority 7
929
-     *
930
-     * @access public
931
-     * @return void
932
-     * @throws Exception
933
-     */
934
-    public function register_shortcodes_modules_and_widgets()
935
-    {
936
-        try {
937
-            // load, register, and add shortcodes the new way
938
-            $this->loader->getShared(
939
-                'EventEspresso\core\services\shortcodes\ShortcodesManager',
940
-                array(
941
-                    // and the old way, but we'll put it under control of the new system
942
-                    EE_Config::getLegacyShortcodesManager()
943
-                )
944
-            );
945
-        } catch (Exception $exception) {
946
-            new ExceptionStackTraceDisplay($exception);
947
-        }
948
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
949
-        // check for addons using old hook point
950
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
951
-            $this->_incompatible_addon_error();
952
-        }
953
-    }
954
-
955
-
956
-
957
-    /**
958
-     * _incompatible_addon_error
959
-     *
960
-     * @access public
961
-     * @return void
962
-     */
963
-    private function _incompatible_addon_error()
964
-    {
965
-        // get array of classes hooking into here
966
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
968
-        );
969
-        if (! empty($class_names)) {
970
-            $msg = __(
971
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972
-                'event_espresso'
973
-            );
974
-            $msg .= '<ul>';
975
-            foreach ($class_names as $class_name) {
976
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
977
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
978
-                        $class_name
979
-                    ) . '</b></li>';
980
-            }
981
-            $msg .= '</ul>';
982
-            $msg .= __(
983
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
984
-                'event_espresso'
985
-            );
986
-            // save list of incompatible addons to wp-options for later use
987
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
988
-            if (is_admin()) {
989
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
990
-            }
991
-        }
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     * brew_espresso
998
-     * begins the process of setting hooks for initializing EE in the correct order
999
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1000
-     * which runs during the WP 'plugins_loaded' action at priority 9
1001
-     *
1002
-     * @return void
1003
-     */
1004
-    public function brew_espresso()
1005
-    {
1006
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1007
-        // load some final core systems
1008
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1009
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1010
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1011
-        add_action('init', array($this, 'load_controllers'), 7);
1012
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1013
-        add_action('init', array($this, 'initialize'), 10);
1014
-        add_action('init', array($this, 'initialize_last'), 100);
1015
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1016
-            // pew pew pew
1017
-            $this->loader->getShared('EE_PUE');
1018
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1019
-        }
1020
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1021
-    }
1022
-
1023
-
1024
-
1025
-    /**
1026
-     *    set_hooks_for_core
1027
-     *
1028
-     * @access public
1029
-     * @return    void
1030
-     * @throws EE_Error
1031
-     */
1032
-    public function set_hooks_for_core()
1033
-    {
1034
-        $this->_deactivate_incompatible_addons();
1035
-        do_action('AHEE__EE_System__set_hooks_for_core');
1036
-        //caps need to be initialized on every request so that capability maps are set.
1037
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1038
-        $this->registry->CAP->init_caps();
1039
-    }
1040
-
1041
-
1042
-
1043
-    /**
1044
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1045
-     * deactivates any addons considered incompatible with the current version of EE
1046
-     */
1047
-    private function _deactivate_incompatible_addons()
1048
-    {
1049
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1050
-        if (! empty($incompatible_addons)) {
1051
-            $active_plugins = get_option('active_plugins', array());
1052
-            foreach ($active_plugins as $active_plugin) {
1053
-                foreach ($incompatible_addons as $incompatible_addon) {
1054
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1055
-                        unset($_GET['activate']);
1056
-                        espresso_deactivate_plugin($active_plugin);
1057
-                    }
1058
-                }
1059
-            }
1060
-        }
1061
-    }
1062
-
1063
-
1064
-
1065
-    /**
1066
-     *    perform_activations_upgrades_and_migrations
1067
-     *
1068
-     * @access public
1069
-     * @return    void
1070
-     */
1071
-    public function perform_activations_upgrades_and_migrations()
1072
-    {
1073
-        //first check if we had previously attempted to setup EE's directories but failed
1074
-        if (EEH_Activation::upload_directories_incomplete()) {
1075
-            EEH_Activation::create_upload_directories();
1076
-        }
1077
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1078
-    }
1079
-
1080
-
1081
-
1082
-    /**
1083
-     *    load_CPTs_and_session
1084
-     *
1085
-     * @access public
1086
-     * @return    void
1087
-     */
1088
-    public function load_CPTs_and_session()
1089
-    {
1090
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1091
-        // register Custom Post Types
1092
-        $this->loader->getShared('EE_Register_CPTs');
1093
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * load_controllers
1100
-     * this is the best place to load any additional controllers that needs access to EE core.
1101
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1102
-     * time
1103
-     *
1104
-     * @access public
1105
-     * @return void
1106
-     */
1107
-    public function load_controllers()
1108
-    {
1109
-        do_action('AHEE__EE_System__load_controllers__start');
1110
-        // let's get it started
1111
-        if (! is_admin() && ! $this->maintenance_mode->level()) {
1112
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1113
-            $this->loader->getShared('EE_Front_Controller');
1114
-        } else if (! EE_FRONT_AJAX) {
1115
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1116
-            $this->loader->getShared('EE_Admin');
1117
-        }
1118
-        do_action('AHEE__EE_System__load_controllers__complete');
1119
-    }
1120
-
1121
-
1122
-
1123
-    /**
1124
-     * core_loaded_and_ready
1125
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1126
-     *
1127
-     * @access public
1128
-     * @return void
1129
-     */
1130
-    public function core_loaded_and_ready()
1131
-    {
1132
-        $this->loader->getShared('EE_Session');
1133
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1134
-        // load_espresso_template_tags
1135
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1136
-            require_once(EE_PUBLIC . 'template_tags.php');
1137
-        }
1138
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1139
-        $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1140
-    }
1141
-
1142
-
1143
-
1144
-    /**
1145
-     * initialize
1146
-     * this is the best place to begin initializing client code
1147
-     *
1148
-     * @access public
1149
-     * @return void
1150
-     */
1151
-    public function initialize()
1152
-    {
1153
-        do_action('AHEE__EE_System__initialize');
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     * initialize_last
1160
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1161
-     * initialize has done so
1162
-     *
1163
-     * @access public
1164
-     * @return void
1165
-     */
1166
-    public function initialize_last()
1167
-    {
1168
-        do_action('AHEE__EE_System__initialize_last');
1169
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1170
-    }
1171
-
1172
-
1173
-
1174
-    /**
1175
-     * @return void
1176
-     * @throws EE_Error
1177
-     */
1178
-    public function addEspressoToolbar()
1179
-    {
1180
-        $this->loader->getShared(
1181
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1182
-            array($this->registry->CAP)
1183
-        );
1184
-    }
1185
-
1186
-
1187
-
1188
-    /**
1189
-     * do_not_cache
1190
-     * sets no cache headers and defines no cache constants for WP plugins
1191
-     *
1192
-     * @access public
1193
-     * @return void
1194
-     */
1195
-    public static function do_not_cache()
1196
-    {
1197
-        // set no cache constants
1198
-        if (! defined('DONOTCACHEPAGE')) {
1199
-            define('DONOTCACHEPAGE', true);
1200
-        }
1201
-        if (! defined('DONOTCACHCEOBJECT')) {
1202
-            define('DONOTCACHCEOBJECT', true);
1203
-        }
1204
-        if (! defined('DONOTCACHEDB')) {
1205
-            define('DONOTCACHEDB', true);
1206
-        }
1207
-        // add no cache headers
1208
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1209
-        // plus a little extra for nginx and Google Chrome
1210
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1211
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1212
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1213
-    }
1214
-
1215
-
1216
-
1217
-    /**
1218
-     *    extra_nocache_headers
1219
-     *
1220
-     * @access    public
1221
-     * @param $headers
1222
-     * @return    array
1223
-     */
1224
-    public static function extra_nocache_headers($headers)
1225
-    {
1226
-        // for NGINX
1227
-        $headers['X-Accel-Expires'] = 0;
1228
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1229
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1230
-        return $headers;
1231
-    }
1232
-
1233
-
1234
-
1235
-    /**
1236
-     *    nocache_headers
1237
-     *
1238
-     * @access    public
1239
-     * @return    void
1240
-     */
1241
-    public static function nocache_headers()
1242
-    {
1243
-        nocache_headers();
1244
-    }
1245
-
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1251
-     * never returned with the function.
1252
-     *
1253
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1254
-     * @return array
1255
-     */
1256
-    public function remove_pages_from_wp_list_pages($exclude_array)
1257
-    {
1258
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1259
-    }
24
+	/**
25
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
26
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
27
+	 */
28
+	const req_type_normal = 0;
29
+
30
+	/**
31
+	 * Indicates this is a brand new installation of EE so we should install
32
+	 * tables and default data etc
33
+	 */
34
+	const req_type_new_activation = 1;
35
+
36
+	/**
37
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
38
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
39
+	 * and that default data is setup too
40
+	 */
41
+	const req_type_reactivation = 2;
42
+
43
+	/**
44
+	 * indicates that EE has been upgraded since its previous request.
45
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
46
+	 */
47
+	const req_type_upgrade = 3;
48
+
49
+	/**
50
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
51
+	 */
52
+	const req_type_downgrade = 4;
53
+
54
+	/**
55
+	 * @deprecated since version 4.6.0.dev.006
56
+	 * Now whenever a new_activation is detected the request type is still just
57
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
58
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
59
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
60
+	 * (Specifically, when the migration manager indicates migrations are finished
61
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
62
+	 */
63
+	const req_type_activation_but_not_installed = 5;
64
+
65
+	/**
66
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
67
+	 */
68
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
69
+
70
+
71
+	/**
72
+	 * @var EE_System $_instance
73
+	 */
74
+	private static $_instance;
75
+
76
+	/**
77
+	 * @var EE_Registry $registry
78
+	 */
79
+	private $registry;
80
+
81
+	/**
82
+	 * @var LoaderInterface $loader
83
+	 */
84
+	private $loader;
85
+
86
+	/**
87
+	 * @var EE_Capabilities $capabilities
88
+	 */
89
+	private $capabilities;
90
+
91
+	/**
92
+	 * @var EE_Request $request
93
+	 */
94
+	private $request;
95
+
96
+	/**
97
+	 * @var EE_Maintenance_Mode $maintenance_mode
98
+	 */
99
+	private $maintenance_mode;
100
+
101
+	/**
102
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
103
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
104
+	 *
105
+	 * @var int $_req_type
106
+	 */
107
+	private $_req_type;
108
+
109
+	/**
110
+	 * Whether or not there was a non-micro version change in EE core version during this request
111
+	 *
112
+	 * @var boolean $_major_version_change
113
+	 */
114
+	private $_major_version_change = false;
115
+
116
+
117
+
118
+	/**
119
+	 * @singleton method used to instantiate class object
120
+	 * @param EE_Registry|null         $registry
121
+	 * @param LoaderInterface|null     $loader
122
+	 * @param EE_Capabilities|null     $capabilities
123
+	 * @param EE_Request|null          $request
124
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
125
+	 * @return EE_System
126
+	 */
127
+	public static function instance(
128
+		EE_Registry $registry = null,
129
+		LoaderInterface $loader = null,
130
+		EE_Capabilities $capabilities = null,
131
+		EE_Request $request = null,
132
+		EE_Maintenance_Mode $maintenance_mode = null
133
+	) {
134
+		// check if class object is instantiated
135
+		if (! self::$_instance instanceof EE_System) {
136
+			self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode);
137
+		}
138
+		return self::$_instance;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * resets the instance and returns it
145
+	 *
146
+	 * @return EE_System
147
+	 */
148
+	public static function reset()
149
+	{
150
+		self::$_instance->_req_type = null;
151
+		//make sure none of the old hooks are left hanging around
152
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
153
+		//we need to reset the migration manager in order for it to detect DMSs properly
154
+		EE_Data_Migration_Manager::reset();
155
+		self::instance()->detect_activations_or_upgrades();
156
+		self::instance()->perform_activations_upgrades_and_migrations();
157
+		return self::instance();
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * sets hooks for running rest of system
164
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
165
+	 * starting EE Addons from any other point may lead to problems
166
+	 *
167
+	 * @param EE_Registry         $registry
168
+	 * @param LoaderInterface     $loader
169
+	 * @param EE_Capabilities     $capabilities
170
+	 * @param EE_Request          $request
171
+	 * @param EE_Maintenance_Mode $maintenance_mode
172
+	 */
173
+	private function __construct(
174
+		EE_Registry $registry,
175
+		LoaderInterface $loader,
176
+		EE_Capabilities $capabilities,
177
+		EE_Request $request,
178
+		EE_Maintenance_Mode $maintenance_mode
179
+	) {
180
+		$this->registry = $registry;
181
+		$this->loader = $loader;
182
+		$this->capabilities = $capabilities;
183
+		$this->request = $request;
184
+		$this->maintenance_mode = $maintenance_mode;
185
+		do_action('AHEE__EE_System__construct__begin', $this);
186
+		add_action(
187
+			'AHEE__EE_Bootstrap__load_espresso_addons',
188
+			array($this, 'loadCapabilities'),
189
+			5
190
+		);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCommandBus'),
194
+			7
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadPluginApi'),
199
+			9
200
+		);
201
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
202
+		add_action(
203
+			'AHEE__EE_Bootstrap__load_espresso_addons',
204
+			array($this, 'load_espresso_addons')
205
+		);
206
+		// when an ee addon is activated, we want to call the core hook(s) again
207
+		// because the newly-activated addon didn't get a chance to run at all
208
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
209
+		// detect whether install or upgrade
210
+		add_action(
211
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
212
+			array($this, 'detect_activations_or_upgrades'),
213
+			3
214
+		);
215
+		// load EE_Config, EE_Textdomain, etc
216
+		add_action(
217
+			'AHEE__EE_Bootstrap__load_core_configuration',
218
+			array($this, 'load_core_configuration'),
219
+			5
220
+		);
221
+		// load EE_Config, EE_Textdomain, etc
222
+		add_action(
223
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
224
+			array($this, 'register_shortcodes_modules_and_widgets'),
225
+			7
226
+		);
227
+		// you wanna get going? I wanna get going... let's get going!
228
+		add_action(
229
+			'AHEE__EE_Bootstrap__brew_espresso',
230
+			array($this, 'brew_espresso'),
231
+			9
232
+		);
233
+		//other housekeeping
234
+		//exclude EE critical pages from wp_list_pages
235
+		add_filter(
236
+			'wp_list_pages_excludes',
237
+			array($this, 'remove_pages_from_wp_list_pages'),
238
+			10
239
+		);
240
+		// ALL EE Addons should use the following hook point to attach their initial setup too
241
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
242
+		do_action('AHEE__EE_System__construct__complete', $this);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * load and setup EE_Capabilities
249
+	 *
250
+	 * @return void
251
+	 * @throws EE_Error
252
+	 */
253
+	public function loadCapabilities()
254
+	{
255
+		$this->loader->getShared('EE_Capabilities');
256
+		add_action(
257
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
258
+			function() {
259
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
260
+			}
261
+		);
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 * create and cache the CommandBus, and also add middleware
268
+	 * The CapChecker middleware requires the use of EE_Capabilities
269
+	 * which is why we need to load the CommandBus after Caps are set up
270
+	 *
271
+	 * @return void
272
+	 * @throws EE_Error
273
+	 */
274
+	public function loadCommandBus()
275
+	{
276
+		$this->loader->getShared(
277
+			'CommandBusInterface',
278
+			array(
279
+				null,
280
+				apply_filters(
281
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
282
+					array(
283
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
284
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
285
+					)
286
+				),
287
+			)
288
+		);
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * @return void
295
+	 * @throws EE_Error
296
+	 */
297
+	public function loadPluginApi()
298
+	{
299
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
300
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
301
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
302
+	}
303
+
304
+
305
+	/**
306
+	 * @param string $addon_name
307
+	 * @param string $version_constant
308
+	 * @param string $min_version_required
309
+	 * @param string $load_callback
310
+	 * @param string $plugin_file_constant
311
+	 * @return void
312
+	 */
313
+	private function deactivateIncompatibleAddon(
314
+		$addon_name,
315
+		$version_constant,
316
+		$min_version_required,
317
+		$load_callback,
318
+		$plugin_file_constant
319
+	) {
320
+		if (! defined($version_constant)) {
321
+			return;
322
+		}
323
+		$addon_version = constant($version_constant);
324
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
325
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
326
+			if (! function_exists('deactivate_plugins')) {
327
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
328
+			}
329
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
330
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
331
+			EE_Error::add_error(
332
+				sprintf(
333
+					esc_html__(
334
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
335
+						'event_espresso'
336
+					),
337
+					$addon_name,
338
+					$min_version_required
339
+				),
340
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
341
+			);
342
+			EE_Error::get_notices(false, true);
343
+		}
344
+	}
345
+
346
+
347
+	/**
348
+	 * load_espresso_addons
349
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
350
+	 * this is hooked into both:
351
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
352
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
353
+	 *    and the WP 'activate_plugin' hook point
354
+	 *
355
+	 * @access public
356
+	 * @return void
357
+	 */
358
+	public function load_espresso_addons()
359
+	{
360
+		$this->deactivateIncompatibleAddon(
361
+			'Wait Lists',
362
+			'EE_WAIT_LISTS_VERSION',
363
+			'1.0.0.beta.074',
364
+			'load_espresso_wait_lists',
365
+			'EE_WAIT_LISTS_PLUGIN_FILE'
366
+		);
367
+		$this->deactivateIncompatibleAddon(
368
+			'Automated Upcoming Event Notifications',
369
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
370
+			'1.0.0.beta.091',
371
+			'load_espresso_automated_upcoming_event_notification',
372
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
373
+		);
374
+		do_action('AHEE__EE_System__load_espresso_addons');
375
+		//if the WP API basic auth plugin isn't already loaded, load it now.
376
+		//We want it for mobile apps. Just include the entire plugin
377
+		//also, don't load the basic auth when a plugin is getting activated, because
378
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
379
+		//and causes a fatal error
380
+		if (
381
+			! (
382
+				isset($_GET['activate'])
383
+				&& $_GET['activate'] === 'true'
384
+			)
385
+			&& ! function_exists('json_basic_auth_handler')
386
+			&& ! function_exists('json_basic_auth_error')
387
+			&& ! (
388
+				isset($_GET['action'])
389
+				&& in_array($_GET['action'], array('activate', 'activate-selected'), true)
390
+			)
391
+		) {
392
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
393
+		}
394
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * detect_activations_or_upgrades
401
+	 * Checks for activation or upgrade of core first;
402
+	 * then also checks if any registered addons have been activated or upgraded
403
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
404
+	 * which runs during the WP 'plugins_loaded' action at priority 3
405
+	 *
406
+	 * @access public
407
+	 * @return void
408
+	 */
409
+	public function detect_activations_or_upgrades()
410
+	{
411
+		//first off: let's make sure to handle core
412
+		$this->detect_if_activation_or_upgrade();
413
+		foreach ($this->registry->addons as $addon) {
414
+			if ($addon instanceof EE_Addon) {
415
+				//detect teh request type for that addon
416
+				$addon->detect_activation_or_upgrade();
417
+			}
418
+		}
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * detect_if_activation_or_upgrade
425
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
426
+	 * and either setting up the DB or setting up maintenance mode etc.
427
+	 *
428
+	 * @access public
429
+	 * @return void
430
+	 */
431
+	public function detect_if_activation_or_upgrade()
432
+	{
433
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
434
+		// check if db has been updated, or if its a brand-new installation
435
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
436
+		$request_type = $this->detect_req_type($espresso_db_update);
437
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
438
+		switch ($request_type) {
439
+			case EE_System::req_type_new_activation:
440
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
441
+				$this->_handle_core_version_change($espresso_db_update);
442
+				break;
443
+			case EE_System::req_type_reactivation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_upgrade:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
449
+				//migrations may be required now that we've upgraded
450
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
451
+				$this->_handle_core_version_change($espresso_db_update);
452
+				//				echo "done upgrade";die;
453
+				break;
454
+			case EE_System::req_type_downgrade:
455
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
456
+				//its possible migrations are no longer required
457
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
458
+				$this->_handle_core_version_change($espresso_db_update);
459
+				break;
460
+			case EE_System::req_type_normal:
461
+			default:
462
+				//				$this->_maybe_redirect_to_ee_about();
463
+				break;
464
+		}
465
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 * Updates the list of installed versions and sets hooks for
472
+	 * initializing the database later during the request
473
+	 *
474
+	 * @param array $espresso_db_update
475
+	 */
476
+	private function _handle_core_version_change($espresso_db_update)
477
+	{
478
+		$this->update_list_of_installed_versions($espresso_db_update);
479
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
480
+		add_action(
481
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
482
+			array($this, 'initialize_db_if_no_migrations_required')
483
+		);
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
490
+	 * information about what versions of EE have been installed and activated,
491
+	 * NOT necessarily the state of the database
492
+	 *
493
+	 * @param mixed $espresso_db_update the value of the WordPress option.
494
+	 *                                            If not supplied, fetches it from the options table
495
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
496
+	 */
497
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
498
+	{
499
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
500
+		if (! $espresso_db_update) {
501
+			$espresso_db_update = get_option('espresso_db_update');
502
+		}
503
+		// check that option is an array
504
+		if (! is_array($espresso_db_update)) {
505
+			// if option is FALSE, then it never existed
506
+			if ($espresso_db_update === false) {
507
+				// make $espresso_db_update an array and save option with autoload OFF
508
+				$espresso_db_update = array();
509
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
510
+			} else {
511
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
512
+				$espresso_db_update = array($espresso_db_update => array());
513
+				update_option('espresso_db_update', $espresso_db_update);
514
+			}
515
+		} else {
516
+			$corrected_db_update = array();
517
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
518
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
519
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
520
+					//the key is an int, and the value IS NOT an array
521
+					//so it must be numerically-indexed, where values are versions installed...
522
+					//fix it!
523
+					$version_string = $should_be_array;
524
+					$corrected_db_update[$version_string] = array('unknown-date');
525
+				} else {
526
+					//ok it checks out
527
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
528
+				}
529
+			}
530
+			$espresso_db_update = $corrected_db_update;
531
+			update_option('espresso_db_update', $espresso_db_update);
532
+		}
533
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
534
+		return $espresso_db_update;
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * Does the traditional work of setting up the plugin's database and adding default data.
541
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
542
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
543
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
544
+	 * so that it will be done when migrations are finished
545
+	 *
546
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
547
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
548
+	 *                                       This is a resource-intensive job
549
+	 *                                       so we prefer to only do it when necessary
550
+	 * @return void
551
+	 * @throws EE_Error
552
+	 */
553
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
554
+	{
555
+		$request_type = $this->detect_req_type();
556
+		//only initialize system if we're not in maintenance mode.
557
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
558
+			update_option('ee_flush_rewrite_rules', true);
559
+			if ($verify_schema) {
560
+				EEH_Activation::initialize_db_and_folders();
561
+			}
562
+			EEH_Activation::initialize_db_content();
563
+			EEH_Activation::system_initialization();
564
+			if ($initialize_addons_too) {
565
+				$this->initialize_addons();
566
+			}
567
+		} else {
568
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
569
+		}
570
+		if ($request_type === EE_System::req_type_new_activation
571
+			|| $request_type === EE_System::req_type_reactivation
572
+			|| (
573
+				$request_type === EE_System::req_type_upgrade
574
+				&& $this->is_major_version_change()
575
+			)
576
+		) {
577
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
578
+		}
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 * Initializes the db for all registered addons
585
+	 *
586
+	 * @throws EE_Error
587
+	 */
588
+	public function initialize_addons()
589
+	{
590
+		//foreach registered addon, make sure its db is up-to-date too
591
+		foreach ($this->registry->addons as $addon) {
592
+			if ($addon instanceof EE_Addon) {
593
+				$addon->initialize_db_if_no_migrations_required();
594
+			}
595
+		}
596
+	}
597
+
598
+
599
+
600
+	/**
601
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
602
+	 *
603
+	 * @param    array  $version_history
604
+	 * @param    string $current_version_to_add version to be added to the version history
605
+	 * @return    boolean success as to whether or not this option was changed
606
+	 */
607
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
608
+	{
609
+		if (! $version_history) {
610
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
611
+		}
612
+		if ($current_version_to_add === null) {
613
+			$current_version_to_add = espresso_version();
614
+		}
615
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
616
+		// re-save
617
+		return update_option('espresso_db_update', $version_history);
618
+	}
619
+
620
+
621
+
622
+	/**
623
+	 * Detects if the current version indicated in the has existed in the list of
624
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
625
+	 *
626
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
627
+	 *                                  If not supplied, fetches it from the options table.
628
+	 *                                  Also, caches its result so later parts of the code can also know whether
629
+	 *                                  there's been an update or not. This way we can add the current version to
630
+	 *                                  espresso_db_update, but still know if this is a new install or not
631
+	 * @return int one of the constants on EE_System::req_type_
632
+	 */
633
+	public function detect_req_type($espresso_db_update = null)
634
+	{
635
+		if ($this->_req_type === null) {
636
+			$espresso_db_update = ! empty($espresso_db_update)
637
+				? $espresso_db_update
638
+				: $this->fix_espresso_db_upgrade_option();
639
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
640
+				$espresso_db_update,
641
+				'ee_espresso_activation', espresso_version()
642
+			);
643
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
644
+		}
645
+		return $this->_req_type;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * Returns whether or not there was a non-micro version change (ie, change in either
652
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
653
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
654
+	 *
655
+	 * @param $activation_history
656
+	 * @return bool
657
+	 */
658
+	private function _detect_major_version_change($activation_history)
659
+	{
660
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
661
+		$previous_version_parts = explode('.', $previous_version);
662
+		$current_version_parts = explode('.', espresso_version());
663
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
664
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
665
+				   || $previous_version_parts[1] !== $current_version_parts[1]
666
+			   );
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 * Returns true if either the major or minor version of EE changed during this request.
673
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
674
+	 *
675
+	 * @return bool
676
+	 */
677
+	public function is_major_version_change()
678
+	{
679
+		return $this->_major_version_change;
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
686
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
687
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
688
+	 * just activated to (for core that will always be espresso_version())
689
+	 *
690
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
691
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
692
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
693
+	 *                                                 indicate that this plugin was just activated
694
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
695
+	 *                                                 espresso_version())
696
+	 * @return int one of the constants on EE_System::req_type_*
697
+	 */
698
+	public static function detect_req_type_given_activation_history(
699
+		$activation_history_for_addon,
700
+		$activation_indicator_option_name,
701
+		$version_to_upgrade_to
702
+	) {
703
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
704
+		if ($activation_history_for_addon) {
705
+			//it exists, so this isn't a completely new install
706
+			//check if this version already in that list of previously installed versions
707
+			if (! isset($activation_history_for_addon[$version_to_upgrade_to])) {
708
+				//it a version we haven't seen before
709
+				if ($version_is_higher === 1) {
710
+					$req_type = EE_System::req_type_upgrade;
711
+				} else {
712
+					$req_type = EE_System::req_type_downgrade;
713
+				}
714
+				delete_option($activation_indicator_option_name);
715
+			} else {
716
+				// its not an update. maybe a reactivation?
717
+				if (get_option($activation_indicator_option_name, false)) {
718
+					if ($version_is_higher === -1) {
719
+						$req_type = EE_System::req_type_downgrade;
720
+					} else if ($version_is_higher === 0) {
721
+						//we've seen this version before, but it's an activation. must be a reactivation
722
+						$req_type = EE_System::req_type_reactivation;
723
+					} else {//$version_is_higher === 1
724
+						$req_type = EE_System::req_type_upgrade;
725
+					}
726
+					delete_option($activation_indicator_option_name);
727
+				} else {
728
+					//we've seen this version before and the activation indicate doesn't show it was just activated
729
+					if ($version_is_higher === -1) {
730
+						$req_type = EE_System::req_type_downgrade;
731
+					} else if ($version_is_higher === 0) {
732
+						//we've seen this version before and it's not an activation. its normal request
733
+						$req_type = EE_System::req_type_normal;
734
+					} else {//$version_is_higher === 1
735
+						$req_type = EE_System::req_type_upgrade;
736
+					}
737
+				}
738
+			}
739
+		} else {
740
+			//brand new install
741
+			$req_type = EE_System::req_type_new_activation;
742
+			delete_option($activation_indicator_option_name);
743
+		}
744
+		return $req_type;
745
+	}
746
+
747
+
748
+
749
+	/**
750
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
751
+	 * the $activation_history_for_addon
752
+	 *
753
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
754
+	 *                                             sometimes containing 'unknown-date'
755
+	 * @param string $version_to_upgrade_to        (current version)
756
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
757
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
758
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
759
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
760
+	 */
761
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
762
+	{
763
+		//find the most recently-activated version
764
+		$most_recently_active_version =
765
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
766
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
767
+	}
768
+
769
+
770
+
771
+	/**
772
+	 * Gets the most recently active version listed in the activation history,
773
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
774
+	 *
775
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
776
+	 *                                   sometimes containing 'unknown-date'
777
+	 * @return string
778
+	 */
779
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
780
+	{
781
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
782
+		$most_recently_active_version = '0.0.0.dev.000';
783
+		if (is_array($activation_history)) {
784
+			foreach ($activation_history as $version => $times_activated) {
785
+				//check there is a record of when this version was activated. Otherwise,
786
+				//mark it as unknown
787
+				if (! $times_activated) {
788
+					$times_activated = array('unknown-date');
789
+				}
790
+				if (is_string($times_activated)) {
791
+					$times_activated = array($times_activated);
792
+				}
793
+				foreach ($times_activated as $an_activation) {
794
+					if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
795
+						$most_recently_active_version = $version;
796
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
797
+							? '1970-01-01 00:00:00'
798
+							: $an_activation;
799
+					}
800
+				}
801
+			}
802
+		}
803
+		return $most_recently_active_version;
804
+	}
805
+
806
+
807
+
808
+	/**
809
+	 * This redirects to the about EE page after activation
810
+	 *
811
+	 * @return void
812
+	 */
813
+	public function redirect_to_about_ee()
814
+	{
815
+		$notices = EE_Error::get_notices(false);
816
+		//if current user is an admin and it's not an ajax or rest request
817
+		if (
818
+			! (defined('DOING_AJAX') && DOING_AJAX)
819
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
820
+			&& ! isset($notices['errors'])
821
+			&& apply_filters(
822
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
823
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
824
+			)
825
+		) {
826
+			$query_params = array('page' => 'espresso_about');
827
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
828
+				$query_params['new_activation'] = true;
829
+			}
830
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
831
+				$query_params['reactivation'] = true;
832
+			}
833
+			$url = add_query_arg($query_params, admin_url('admin.php'));
834
+			wp_safe_redirect($url);
835
+			exit();
836
+		}
837
+	}
838
+
839
+
840
+
841
+	/**
842
+	 * load_core_configuration
843
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
844
+	 * which runs during the WP 'plugins_loaded' action at priority 5
845
+	 *
846
+	 * @return void
847
+	 * @throws ReflectionException
848
+	 */
849
+	public function load_core_configuration()
850
+	{
851
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
852
+		$this->loader->getShared('EE_Load_Textdomain');
853
+		//load textdomain
854
+		EE_Load_Textdomain::load_textdomain();
855
+		// load and setup EE_Config and EE_Network_Config
856
+		$config = $this->loader->getShared('EE_Config');
857
+		$this->loader->getShared('EE_Network_Config');
858
+		// setup autoloaders
859
+		// enable logging?
860
+		if ($config->admin->use_full_logging) {
861
+			$this->loader->getShared('EE_Log');
862
+		}
863
+		// check for activation errors
864
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
865
+		if ($activation_errors) {
866
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
867
+			update_option('ee_plugin_activation_errors', false);
868
+		}
869
+		// get model names
870
+		$this->_parse_model_names();
871
+		//load caf stuff a chance to play during the activation process too.
872
+		$this->_maybe_brew_regular();
873
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
874
+	}
875
+
876
+
877
+
878
+	/**
879
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
880
+	 *
881
+	 * @return void
882
+	 * @throws ReflectionException
883
+	 */
884
+	private function _parse_model_names()
885
+	{
886
+		//get all the files in the EE_MODELS folder that end in .model.php
887
+		$models = glob(EE_MODELS . '*.model.php');
888
+		$model_names = array();
889
+		$non_abstract_db_models = array();
890
+		foreach ($models as $model) {
891
+			// get model classname
892
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
893
+			$short_name = str_replace('EEM_', '', $classname);
894
+			$reflectionClass = new ReflectionClass($classname);
895
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
896
+				$non_abstract_db_models[$short_name] = $classname;
897
+			}
898
+			$model_names[$short_name] = $classname;
899
+		}
900
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
901
+		$this->registry->non_abstract_db_models = apply_filters(
902
+			'FHEE__EE_System__parse_implemented_model_names',
903
+			$non_abstract_db_models
904
+		);
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
911
+	 * that need to be setup before our EE_System launches.
912
+	 *
913
+	 * @return void
914
+	 */
915
+	private function _maybe_brew_regular()
916
+	{
917
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
918
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
919
+		}
920
+	}
921
+
922
+
923
+
924
+	/**
925
+	 * register_shortcodes_modules_and_widgets
926
+	 * generate lists of shortcodes and modules, then verify paths and classes
927
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
928
+	 * which runs during the WP 'plugins_loaded' action at priority 7
929
+	 *
930
+	 * @access public
931
+	 * @return void
932
+	 * @throws Exception
933
+	 */
934
+	public function register_shortcodes_modules_and_widgets()
935
+	{
936
+		try {
937
+			// load, register, and add shortcodes the new way
938
+			$this->loader->getShared(
939
+				'EventEspresso\core\services\shortcodes\ShortcodesManager',
940
+				array(
941
+					// and the old way, but we'll put it under control of the new system
942
+					EE_Config::getLegacyShortcodesManager()
943
+				)
944
+			);
945
+		} catch (Exception $exception) {
946
+			new ExceptionStackTraceDisplay($exception);
947
+		}
948
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
949
+		// check for addons using old hook point
950
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
951
+			$this->_incompatible_addon_error();
952
+		}
953
+	}
954
+
955
+
956
+
957
+	/**
958
+	 * _incompatible_addon_error
959
+	 *
960
+	 * @access public
961
+	 * @return void
962
+	 */
963
+	private function _incompatible_addon_error()
964
+	{
965
+		// get array of classes hooking into here
966
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
968
+		);
969
+		if (! empty($class_names)) {
970
+			$msg = __(
971
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972
+				'event_espresso'
973
+			);
974
+			$msg .= '<ul>';
975
+			foreach ($class_names as $class_name) {
976
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
977
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
978
+						$class_name
979
+					) . '</b></li>';
980
+			}
981
+			$msg .= '</ul>';
982
+			$msg .= __(
983
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
984
+				'event_espresso'
985
+			);
986
+			// save list of incompatible addons to wp-options for later use
987
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
988
+			if (is_admin()) {
989
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
990
+			}
991
+		}
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 * brew_espresso
998
+	 * begins the process of setting hooks for initializing EE in the correct order
999
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1000
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1001
+	 *
1002
+	 * @return void
1003
+	 */
1004
+	public function brew_espresso()
1005
+	{
1006
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1007
+		// load some final core systems
1008
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1009
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1010
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1011
+		add_action('init', array($this, 'load_controllers'), 7);
1012
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1013
+		add_action('init', array($this, 'initialize'), 10);
1014
+		add_action('init', array($this, 'initialize_last'), 100);
1015
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1016
+			// pew pew pew
1017
+			$this->loader->getShared('EE_PUE');
1018
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1019
+		}
1020
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1021
+	}
1022
+
1023
+
1024
+
1025
+	/**
1026
+	 *    set_hooks_for_core
1027
+	 *
1028
+	 * @access public
1029
+	 * @return    void
1030
+	 * @throws EE_Error
1031
+	 */
1032
+	public function set_hooks_for_core()
1033
+	{
1034
+		$this->_deactivate_incompatible_addons();
1035
+		do_action('AHEE__EE_System__set_hooks_for_core');
1036
+		//caps need to be initialized on every request so that capability maps are set.
1037
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1038
+		$this->registry->CAP->init_caps();
1039
+	}
1040
+
1041
+
1042
+
1043
+	/**
1044
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1045
+	 * deactivates any addons considered incompatible with the current version of EE
1046
+	 */
1047
+	private function _deactivate_incompatible_addons()
1048
+	{
1049
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1050
+		if (! empty($incompatible_addons)) {
1051
+			$active_plugins = get_option('active_plugins', array());
1052
+			foreach ($active_plugins as $active_plugin) {
1053
+				foreach ($incompatible_addons as $incompatible_addon) {
1054
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1055
+						unset($_GET['activate']);
1056
+						espresso_deactivate_plugin($active_plugin);
1057
+					}
1058
+				}
1059
+			}
1060
+		}
1061
+	}
1062
+
1063
+
1064
+
1065
+	/**
1066
+	 *    perform_activations_upgrades_and_migrations
1067
+	 *
1068
+	 * @access public
1069
+	 * @return    void
1070
+	 */
1071
+	public function perform_activations_upgrades_and_migrations()
1072
+	{
1073
+		//first check if we had previously attempted to setup EE's directories but failed
1074
+		if (EEH_Activation::upload_directories_incomplete()) {
1075
+			EEH_Activation::create_upload_directories();
1076
+		}
1077
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1078
+	}
1079
+
1080
+
1081
+
1082
+	/**
1083
+	 *    load_CPTs_and_session
1084
+	 *
1085
+	 * @access public
1086
+	 * @return    void
1087
+	 */
1088
+	public function load_CPTs_and_session()
1089
+	{
1090
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1091
+		// register Custom Post Types
1092
+		$this->loader->getShared('EE_Register_CPTs');
1093
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * load_controllers
1100
+	 * this is the best place to load any additional controllers that needs access to EE core.
1101
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1102
+	 * time
1103
+	 *
1104
+	 * @access public
1105
+	 * @return void
1106
+	 */
1107
+	public function load_controllers()
1108
+	{
1109
+		do_action('AHEE__EE_System__load_controllers__start');
1110
+		// let's get it started
1111
+		if (! is_admin() && ! $this->maintenance_mode->level()) {
1112
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1113
+			$this->loader->getShared('EE_Front_Controller');
1114
+		} else if (! EE_FRONT_AJAX) {
1115
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1116
+			$this->loader->getShared('EE_Admin');
1117
+		}
1118
+		do_action('AHEE__EE_System__load_controllers__complete');
1119
+	}
1120
+
1121
+
1122
+
1123
+	/**
1124
+	 * core_loaded_and_ready
1125
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1126
+	 *
1127
+	 * @access public
1128
+	 * @return void
1129
+	 */
1130
+	public function core_loaded_and_ready()
1131
+	{
1132
+		$this->loader->getShared('EE_Session');
1133
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1134
+		// load_espresso_template_tags
1135
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
1136
+			require_once(EE_PUBLIC . 'template_tags.php');
1137
+		}
1138
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1139
+		$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1140
+	}
1141
+
1142
+
1143
+
1144
+	/**
1145
+	 * initialize
1146
+	 * this is the best place to begin initializing client code
1147
+	 *
1148
+	 * @access public
1149
+	 * @return void
1150
+	 */
1151
+	public function initialize()
1152
+	{
1153
+		do_action('AHEE__EE_System__initialize');
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 * initialize_last
1160
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1161
+	 * initialize has done so
1162
+	 *
1163
+	 * @access public
1164
+	 * @return void
1165
+	 */
1166
+	public function initialize_last()
1167
+	{
1168
+		do_action('AHEE__EE_System__initialize_last');
1169
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1170
+	}
1171
+
1172
+
1173
+
1174
+	/**
1175
+	 * @return void
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	public function addEspressoToolbar()
1179
+	{
1180
+		$this->loader->getShared(
1181
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1182
+			array($this->registry->CAP)
1183
+		);
1184
+	}
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 * do_not_cache
1190
+	 * sets no cache headers and defines no cache constants for WP plugins
1191
+	 *
1192
+	 * @access public
1193
+	 * @return void
1194
+	 */
1195
+	public static function do_not_cache()
1196
+	{
1197
+		// set no cache constants
1198
+		if (! defined('DONOTCACHEPAGE')) {
1199
+			define('DONOTCACHEPAGE', true);
1200
+		}
1201
+		if (! defined('DONOTCACHCEOBJECT')) {
1202
+			define('DONOTCACHCEOBJECT', true);
1203
+		}
1204
+		if (! defined('DONOTCACHEDB')) {
1205
+			define('DONOTCACHEDB', true);
1206
+		}
1207
+		// add no cache headers
1208
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1209
+		// plus a little extra for nginx and Google Chrome
1210
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1211
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1212
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1213
+	}
1214
+
1215
+
1216
+
1217
+	/**
1218
+	 *    extra_nocache_headers
1219
+	 *
1220
+	 * @access    public
1221
+	 * @param $headers
1222
+	 * @return    array
1223
+	 */
1224
+	public static function extra_nocache_headers($headers)
1225
+	{
1226
+		// for NGINX
1227
+		$headers['X-Accel-Expires'] = 0;
1228
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1229
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1230
+		return $headers;
1231
+	}
1232
+
1233
+
1234
+
1235
+	/**
1236
+	 *    nocache_headers
1237
+	 *
1238
+	 * @access    public
1239
+	 * @return    void
1240
+	 */
1241
+	public static function nocache_headers()
1242
+	{
1243
+		nocache_headers();
1244
+	}
1245
+
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1251
+	 * never returned with the function.
1252
+	 *
1253
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1254
+	 * @return array
1255
+	 */
1256
+	public function remove_pages_from_wp_list_pages($exclude_array)
1257
+	{
1258
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1259
+	}
1260 1260
 
1261 1261
 
1262 1262
 
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +930 added lines, -930 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * Event Espresso
@@ -16,35 +16,35 @@  discard block
 block discarded – undo
16 16
 
17 17
 
18 18
 if ( ! function_exists('espresso_get_template_part')) {
19
-    /**
20
-     * espresso_get_template_part
21
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
22
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
23
-     *
24
-     * @param string $slug The slug name for the generic template.
25
-     * @param string $name The name of the specialised template.
26
-     * @return string        the html output for the formatted money value
27
-     */
28
-    function espresso_get_template_part($slug = null, $name = null)
29
-    {
30
-        EEH_Template::get_template_part($slug, $name);
31
-    }
19
+	/**
20
+	 * espresso_get_template_part
21
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
22
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
23
+	 *
24
+	 * @param string $slug The slug name for the generic template.
25
+	 * @param string $name The name of the specialised template.
26
+	 * @return string        the html output for the formatted money value
27
+	 */
28
+	function espresso_get_template_part($slug = null, $name = null)
29
+	{
30
+		EEH_Template::get_template_part($slug, $name);
31
+	}
32 32
 }
33 33
 
34 34
 
35 35
 if ( ! function_exists('espresso_get_object_css_class')) {
36
-    /**
37
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38
-     *
39
-     * @param EE_Base_Class $object the EE object the css class is being generated for
40
-     * @param  string       $prefix added to the beginning of the generated class
41
-     * @param  string       $suffix added to the end of the generated class
42
-     * @return string
43
-     */
44
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
45
-    {
46
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47
-    }
36
+	/**
37
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38
+	 *
39
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
40
+	 * @param  string       $prefix added to the beginning of the generated class
41
+	 * @param  string       $suffix added to the end of the generated class
42
+	 * @return string
43
+	 */
44
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
45
+	{
46
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47
+	}
48 48
 }
49 49
 
50 50
 
@@ -59,650 +59,650 @@  discard block
 block discarded – undo
59 59
 class EEH_Template
60 60
 {
61 61
 
62
-    private static $_espresso_themes = array();
63
-
64
-
65
-    /**
66
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
67
-     *
68
-     * @return boolean
69
-     */
70
-    public static function is_espresso_theme()
71
-    {
72
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
73
-    }
74
-
75
-    /**
76
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
77
-     *    load it's functions.php file ( if not already loaded )
78
-     *
79
-     * @return void
80
-     */
81
-    public static function load_espresso_theme_functions()
82
-    {
83
-        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
86
-            }
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
93
-     *
94
-     * @return array
95
-     */
96
-    public static function get_espresso_themes()
97
-    {
98
-        if (empty(EEH_Template::$_espresso_themes)) {
99
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
100
-            if (empty($espresso_themes)) {
101
-                return array();
102
-            }
103
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
104
-                unset($espresso_themes[$key]);
105
-            }
106
-            EEH_Template::$_espresso_themes = array();
107
-            foreach ($espresso_themes as $espresso_theme) {
108
-                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
109
-            }
110
-        }
111
-        return EEH_Template::$_espresso_themes;
112
-    }
113
-
114
-
115
-    /**
116
-     * EEH_Template::get_template_part
117
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
118
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
119
-     * filtering based off of the entire template part name
120
-     *
121
-     * @param string $slug The slug name for the generic template.
122
-     * @param string $name The name of the specialised template.
123
-     * @param array  $template_args
124
-     * @param bool   $return_string
125
-     * @return string        the html output for the formatted money value
126
-     */
127
-    public static function get_template_part(
128
-        $slug = null,
129
-        $name = null,
130
-        $template_args = array(),
131
-        $return_string = false
132
-    ) {
133
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134
-        $templates = array();
135
-        $name      = (string)$name;
136
-        if ($name != '') {
137
-            $templates[] = "{$slug}-{$name}.php";
138
-        }
139
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
140
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
141
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
142
-        }
143
-    }
144
-
145
-
146
-    /**
147
-     *    locate_template
148
-     *    locate a template file by looking in the following places, in the following order:
149
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
150
-     *        <assumed full absolute server path>
151
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
152
-     *        <server path up to>/wp-content/uploads/espresso/templates/
153
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
154
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
155
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
156
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
157
-     *        Example:
158
-     *          You are using the WordPress Twenty Sixteen theme,
159
-     *        and you want to customize the "some-event.template.php" template,
160
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
161
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
162
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
163
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
164
-     *        /relative/path/to/some-event.template.php
165
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
166
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
167
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
168
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
169
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
170
-     *          Had you passed an absolute path to your template that was in some other location,
171
-     *        ie: "/absolute/path/to/some-event.template.php"
172
-     *          then the search would have been :
173
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
174
-     *        /absolute/path/to/some-event.template.php
175
-     *          and stopped there upon finding it in the second location
176
-     *
177
-     * @param array|string $templates       array of template file names including extension (or just a single string)
178
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
179
-     * @param  boolean     $load            whether to pass the located template path on to the
180
-     *                                      EEH_Template::display_template() method or simply return it
181
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
182
-     *                                      string
183
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
184
-     *                                      generate a custom template or not. Used in places where you don't actually
185
-     *                                      load the template, you just want to know if there's a custom version of it.
186
-     * @return mixed
187
-     */
188
-    public static function locate_template(
189
-        $templates = array(),
190
-        $template_args = array(),
191
-        $load = true,
192
-        $return_string = true,
193
-        $check_if_custom = false
194
-    ) {
195
-        // first use WP locate_template to check for template in the current theme folder
196
-        $template_path = locate_template($templates);
197
-
198
-        if ($check_if_custom && ! empty($template_path)) {
199
-            return true;
200
-        }
201
-
202
-        // not in the theme
203
-        if (empty($template_path)) {
204
-            // not even a template to look for ?
205
-            if (empty($templates)) {
206
-                // get post_type
207
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
208
-                // get array of EE Custom Post Types
209
-                $EE_CPTs = EE_Register_CPTs::get_CPTs();
210
-                // build template name based on request
211
-                if (isset($EE_CPTs[$post_type])) {
212
-                    $archive_or_single = is_archive() ? 'archive' : '';
213
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
214
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
215
-                }
216
-            }
217
-            // currently active EE template theme
218
-            $current_theme = EE_Config::get_current_theme();
219
-
220
-            // array of paths to folders that may contain templates
221
-            $template_folder_paths = array(
222
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
224
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
225
-                EVENT_ESPRESSO_TEMPLATE_DIR,
226
-            );
227
-
228
-            //add core plugin folders for checking only if we're not $check_if_custom
229
-            if ( ! $check_if_custom) {
230
-                $core_paths            = array(
231
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
-                    EE_PUBLIC . $current_theme,
233
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
-                    EE_TEMPLATES . $current_theme,
235
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236
-                    EE_PLUGIN_DIR_PATH,
237
-                );
238
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
239
-            }
240
-
241
-            // now filter that array
242
-            $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths',
243
-                $template_folder_paths);
244
-            $templates             = is_array($templates) ? $templates : array($templates);
245
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
246
-            // array to hold all possible template paths
247
-            $full_template_paths = array();
248
-
249
-            // loop through $templates
250
-            foreach ($templates as $template) {
251
-                // normalize directory separators
252
-                $template                      = EEH_File::standardise_directory_separators($template);
253
-                $file_name                     = basename($template);
254
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
255
-                // while looping through all template folder paths
256
-                foreach ($template_folder_paths as $template_folder_path) {
257
-                    // normalize directory separators
258
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
259
-                    // determine if any common base path exists between the two paths
260
-                    $common_base_path = EEH_Template::_find_common_base_path(
261
-                        array($template_folder_path, $template_path_minus_file_name)
262
-                    );
263
-                    if ($common_base_path !== '') {
264
-                        // both paths have a common base, so just tack the filename onto our search path
265
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
266
-                    } else {
267
-                        // no common base path, so let's just concatenate
268
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
269
-                    }
270
-                    // build up our template locations array by adding our resolved paths
271
-                    $full_template_paths[] = $resolved_path;
272
-                }
273
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274
-                array_unshift($full_template_paths, $template);
275
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
277
-            }
278
-            // filter final array of full template paths
279
-            $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths, $file_name);
281
-            // now loop through our final array of template location paths and check each location
282
-            foreach ((array)$full_template_paths as $full_template_path) {
283
-                if (is_readable($full_template_path)) {
284
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285
-                    break;
286
-                }
287
-            }
288
-        }
289
-
290
-        // hook that can be used to display the full template path that will be used
291
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
292
-
293
-        // if we got it and you want to see it...
294
-        if ($template_path && $load && ! $check_if_custom) {
295
-            if ($return_string) {
296
-                return EEH_Template::display_template($template_path, $template_args, true);
297
-            } else {
298
-                EEH_Template::display_template($template_path, $template_args, false);
299
-            }
300
-        }
301
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
302
-    }
303
-
304
-
305
-    /**
306
-     * _find_common_base_path
307
-     * given two paths, this determines if there is a common base path between the two
308
-     *
309
-     * @param array $paths
310
-     * @return string
311
-     */
312
-    protected static function _find_common_base_path($paths)
313
-    {
314
-        $last_offset      = 0;
315
-        $common_base_path = '';
316
-        while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
317
-            $dir_length = $index - $last_offset + 1;
318
-            $directory  = substr($paths[0], $last_offset, $dir_length);
319
-            foreach ($paths as $path) {
320
-                if (substr($path, $last_offset, $dir_length) != $directory) {
321
-                    return $common_base_path;
322
-                }
323
-            }
324
-            $common_base_path .= $directory;
325
-            $last_offset = $index + 1;
326
-        }
327
-        return substr($common_base_path, 0, -1);
328
-    }
329
-
330
-
331
-    /**
332
-     * load and display a template
333
-     *
334
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
335
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
336
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
337
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
338
-     *                                      not found or is not readable
339
-     * @return mixed string
340
-     * @throws \DomainException
341
-     */
62
+	private static $_espresso_themes = array();
63
+
64
+
65
+	/**
66
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
67
+	 *
68
+	 * @return boolean
69
+	 */
70
+	public static function is_espresso_theme()
71
+	{
72
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
73
+	}
74
+
75
+	/**
76
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
77
+	 *    load it's functions.php file ( if not already loaded )
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function load_espresso_theme_functions()
82
+	{
83
+		if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
86
+			}
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
93
+	 *
94
+	 * @return array
95
+	 */
96
+	public static function get_espresso_themes()
97
+	{
98
+		if (empty(EEH_Template::$_espresso_themes)) {
99
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
100
+			if (empty($espresso_themes)) {
101
+				return array();
102
+			}
103
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
104
+				unset($espresso_themes[$key]);
105
+			}
106
+			EEH_Template::$_espresso_themes = array();
107
+			foreach ($espresso_themes as $espresso_theme) {
108
+				EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
109
+			}
110
+		}
111
+		return EEH_Template::$_espresso_themes;
112
+	}
113
+
114
+
115
+	/**
116
+	 * EEH_Template::get_template_part
117
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
118
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
119
+	 * filtering based off of the entire template part name
120
+	 *
121
+	 * @param string $slug The slug name for the generic template.
122
+	 * @param string $name The name of the specialised template.
123
+	 * @param array  $template_args
124
+	 * @param bool   $return_string
125
+	 * @return string        the html output for the formatted money value
126
+	 */
127
+	public static function get_template_part(
128
+		$slug = null,
129
+		$name = null,
130
+		$template_args = array(),
131
+		$return_string = false
132
+	) {
133
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134
+		$templates = array();
135
+		$name      = (string)$name;
136
+		if ($name != '') {
137
+			$templates[] = "{$slug}-{$name}.php";
138
+		}
139
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
140
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
141
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
142
+		}
143
+	}
144
+
145
+
146
+	/**
147
+	 *    locate_template
148
+	 *    locate a template file by looking in the following places, in the following order:
149
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
150
+	 *        <assumed full absolute server path>
151
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
152
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
153
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
154
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
155
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
156
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
157
+	 *        Example:
158
+	 *          You are using the WordPress Twenty Sixteen theme,
159
+	 *        and you want to customize the "some-event.template.php" template,
160
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
161
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
162
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
163
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
164
+	 *        /relative/path/to/some-event.template.php
165
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
166
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
167
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
168
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
169
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
170
+	 *          Had you passed an absolute path to your template that was in some other location,
171
+	 *        ie: "/absolute/path/to/some-event.template.php"
172
+	 *          then the search would have been :
173
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
174
+	 *        /absolute/path/to/some-event.template.php
175
+	 *          and stopped there upon finding it in the second location
176
+	 *
177
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
178
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
179
+	 * @param  boolean     $load            whether to pass the located template path on to the
180
+	 *                                      EEH_Template::display_template() method or simply return it
181
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
182
+	 *                                      string
183
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
184
+	 *                                      generate a custom template or not. Used in places where you don't actually
185
+	 *                                      load the template, you just want to know if there's a custom version of it.
186
+	 * @return mixed
187
+	 */
188
+	public static function locate_template(
189
+		$templates = array(),
190
+		$template_args = array(),
191
+		$load = true,
192
+		$return_string = true,
193
+		$check_if_custom = false
194
+	) {
195
+		// first use WP locate_template to check for template in the current theme folder
196
+		$template_path = locate_template($templates);
197
+
198
+		if ($check_if_custom && ! empty($template_path)) {
199
+			return true;
200
+		}
201
+
202
+		// not in the theme
203
+		if (empty($template_path)) {
204
+			// not even a template to look for ?
205
+			if (empty($templates)) {
206
+				// get post_type
207
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
208
+				// get array of EE Custom Post Types
209
+				$EE_CPTs = EE_Register_CPTs::get_CPTs();
210
+				// build template name based on request
211
+				if (isset($EE_CPTs[$post_type])) {
212
+					$archive_or_single = is_archive() ? 'archive' : '';
213
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
214
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
215
+				}
216
+			}
217
+			// currently active EE template theme
218
+			$current_theme = EE_Config::get_current_theme();
219
+
220
+			// array of paths to folders that may contain templates
221
+			$template_folder_paths = array(
222
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
224
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
225
+				EVENT_ESPRESSO_TEMPLATE_DIR,
226
+			);
227
+
228
+			//add core plugin folders for checking only if we're not $check_if_custom
229
+			if ( ! $check_if_custom) {
230
+				$core_paths            = array(
231
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
+					EE_PUBLIC . $current_theme,
233
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
+					EE_TEMPLATES . $current_theme,
235
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236
+					EE_PLUGIN_DIR_PATH,
237
+				);
238
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
239
+			}
240
+
241
+			// now filter that array
242
+			$template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths',
243
+				$template_folder_paths);
244
+			$templates             = is_array($templates) ? $templates : array($templates);
245
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
246
+			// array to hold all possible template paths
247
+			$full_template_paths = array();
248
+
249
+			// loop through $templates
250
+			foreach ($templates as $template) {
251
+				// normalize directory separators
252
+				$template                      = EEH_File::standardise_directory_separators($template);
253
+				$file_name                     = basename($template);
254
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
255
+				// while looping through all template folder paths
256
+				foreach ($template_folder_paths as $template_folder_path) {
257
+					// normalize directory separators
258
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
259
+					// determine if any common base path exists between the two paths
260
+					$common_base_path = EEH_Template::_find_common_base_path(
261
+						array($template_folder_path, $template_path_minus_file_name)
262
+					);
263
+					if ($common_base_path !== '') {
264
+						// both paths have a common base, so just tack the filename onto our search path
265
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
266
+					} else {
267
+						// no common base path, so let's just concatenate
268
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
269
+					}
270
+					// build up our template locations array by adding our resolved paths
271
+					$full_template_paths[] = $resolved_path;
272
+				}
273
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274
+				array_unshift($full_template_paths, $template);
275
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
+				array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
277
+			}
278
+			// filter final array of full template paths
279
+			$full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths, $file_name);
281
+			// now loop through our final array of template location paths and check each location
282
+			foreach ((array)$full_template_paths as $full_template_path) {
283
+				if (is_readable($full_template_path)) {
284
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285
+					break;
286
+				}
287
+			}
288
+		}
289
+
290
+		// hook that can be used to display the full template path that will be used
291
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
292
+
293
+		// if we got it and you want to see it...
294
+		if ($template_path && $load && ! $check_if_custom) {
295
+			if ($return_string) {
296
+				return EEH_Template::display_template($template_path, $template_args, true);
297
+			} else {
298
+				EEH_Template::display_template($template_path, $template_args, false);
299
+			}
300
+		}
301
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
302
+	}
303
+
304
+
305
+	/**
306
+	 * _find_common_base_path
307
+	 * given two paths, this determines if there is a common base path between the two
308
+	 *
309
+	 * @param array $paths
310
+	 * @return string
311
+	 */
312
+	protected static function _find_common_base_path($paths)
313
+	{
314
+		$last_offset      = 0;
315
+		$common_base_path = '';
316
+		while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
317
+			$dir_length = $index - $last_offset + 1;
318
+			$directory  = substr($paths[0], $last_offset, $dir_length);
319
+			foreach ($paths as $path) {
320
+				if (substr($path, $last_offset, $dir_length) != $directory) {
321
+					return $common_base_path;
322
+				}
323
+			}
324
+			$common_base_path .= $directory;
325
+			$last_offset = $index + 1;
326
+		}
327
+		return substr($common_base_path, 0, -1);
328
+	}
329
+
330
+
331
+	/**
332
+	 * load and display a template
333
+	 *
334
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
335
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
336
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
337
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
338
+	 *                                      not found or is not readable
339
+	 * @return mixed string
340
+	 * @throws \DomainException
341
+	 */
342 342
 	public static function display_template(
343
-        $template_path    = false,
344
-        $template_args    = array(),
345
-        $return_string    = false,
346
-        $throw_exceptions = false
347
-    ) {
348
-
349
-        /**
350
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
351
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
352
-         * the display_template method are templates we DON'T want modified (usually because of js
353
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
354
-         * using this.
355
-         *
356
-         * @since 4.6.0
357
-         */
358
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
359
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
360
-
361
-        // you gimme nuttin - YOU GET NUTTIN !!
362
-        if ( ! $template_path || ! is_readable($template_path)) {
363
-            return '';
364
-        }
365
-        // if $template_args are not in an array, then make it so
366
-        if ( ! is_array($template_args) && ! is_object($template_args)) {
367
-            $template_args = array($template_args);
368
-        }
369
-        extract( $template_args, EXTR_SKIP );
370
-        // ignore whether template is accessible ?
371
-        if ( $throw_exceptions && ! is_readable( $template_path ) ) {
372
-            throw new \DomainException(
373
-                    esc_html__(
374
-                            'Invalid, unreadable, or missing file.',
375
-                            'event_espresso'
376
-                    )
377
-            );
378
-        }
379
-
380
-
381
-        if ($return_string) {
382
-            // because we want to return a string, we are going to capture the output
383
-            ob_start();
384
-            include($template_path);
385
-            return ob_get_clean();
386
-        } else {
387
-            include($template_path);
388
-        }
389
-        return '';
390
-    }
391
-
392
-
393
-    /**
394
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
395
-     *
396
-     * @param EE_Base_Class $object the EE object the css class is being generated for
397
-     * @param  string       $prefix added to the beginning of the generated class
398
-     * @param  string       $suffix added to the end of the generated class
399
-     * @return string
400
-     */
401
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
402
-    {
403
-        // in the beginning...
404
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
405
-        // da muddle
406
-        $class = '';
407
-        // the end
408
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
409
-        // is the passed object an EE object ?
410
-        if ($object instanceof EE_Base_Class) {
411
-            // grab the exact type of object
412
-            $obj_class = get_class($object);
413
-            // depending on the type of object...
414
-            switch ($obj_class) {
415
-                // no specifics just yet...
416
-                default :
417
-                    $class = strtolower(str_replace('_', '-', $obj_class));
418
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
419
-
420
-            }
421
-        }
422
-        return $prefix . $class . $suffix;
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * EEH_Template::format_currency
429
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
430
-     * the country currency settings from the supplied country ISO code
431
-     *
432
-     * @param  float   $amount       raw money value
433
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
434
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
435
-     * @param string   $CNT_ISO      2 letter ISO code for a country
436
-     * @param string   $cur_code_span_class
437
-     * @return string        the html output for the formatted money value
438
-     * @throws \EE_Error
439
-     */
440
-    public static function format_currency(
441
-        $amount = null,
442
-        $return_raw = false,
443
-        $display_code = true,
444
-        $CNT_ISO = '',
445
-        $cur_code_span_class = 'currency-code'
446
-    ) {
447
-        // ensure amount was received
448
-        if ($amount === null) {
449
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
450
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
451
-            return '';
452
-        }
453
-        //ensure amount is float
454
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
455
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
456
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
457
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
458
-        // still a number or was amount converted to a string like "free" ?
459
-        if (is_float($amount_formatted)) {
460
-            // was a country ISO code passed ? if so generate currency config object for that country
461
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
462
-            // verify results
463
-            if ( ! $mny instanceof EE_Currency_Config) {
464
-                // set default config country currency settings
465
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
466
-                    ? EE_Registry::instance()->CFG->currency
467
-                    : new EE_Currency_Config();
468
-            }
469
-            // format float
470
-            $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
471
-            // add formatting ?
472
-            if ( ! $return_raw) {
473
-                // add currency sign
474
-                if ($mny->sign_b4) {
475
-                    if ($amount >= 0) {
476
-                        $amount_formatted = $mny->sign . $amount_formatted;
477
-                    } else {
478
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
479
-                    }
480
-
481
-                } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
483
-                }
484
-
485
-                // filter to allow global setting of display_code
486
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
-
488
-                // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
-            }
491
-            // filter results
492
-            $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
493
-                $amount_formatted, $mny, $return_raw);
494
-        }
495
-        // clean up vars
496
-        unset($mny);
497
-        // return formatted currency amount
498
-        return $amount_formatted;
499
-    }
500
-
501
-
502
-    /**
503
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
504
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
505
-     * related status model or model object (i.e. in documentation etc.)
506
-     *
507
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
508
-     *                            match, then 'Unknown' will be returned.
509
-     * @param  boolean $plural    Whether to return plural or not
510
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
511
-     * @return string             The localized label for the status id.
512
-     */
513
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
514
-    {
515
-        /** @type EEM_Status $EEM_Status */
516
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
517
-        $status     = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural,
518
-            $schema);
519
-        return $status[$status_id];
520
-    }
521
-
522
-
523
-    /**
524
-     * This helper just returns a button or link for the given parameters
525
-     *
526
-     * @param  string $url   the url for the link, note that `esc_url` will be called on it
527
-     * @param  string $label What is the label you want displayed for the button
528
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
529
-     * @param string  $icon
530
-     * @param string  $title
531
-     * @return string the html output for the button
532
-     */
533
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
534
-    {
535
-        $icon_html = '';
536
-        if ( ! empty($icon)) {
537
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
538
-            $dashicons = array_filter($dashicons);
539
-            $count     = count($dashicons);
540
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
541
-            foreach ($dashicons as $dashicon) {
542
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
543
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
544
-            }
545
-            $icon_html .= $count > 1 ? '</span>' : '';
546
-        }
547
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
548
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
549
-        return $button;
550
-    }
551
-
552
-
553
-    /**
554
-     * This returns a generated link that will load the related help tab on admin pages.
555
-     *
556
-     * @param  string     $help_tab_id the id for the connected help tab
557
-     * @param bool|string $page        The page identifier for the page the help tab is on
558
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
559
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
560
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
561
-     * @return string              generated link
562
-     */
563
-    public static function get_help_tab_link(
564
-        $help_tab_id,
565
-        $page = false,
566
-        $action = false,
567
-        $icon_style = false,
568
-        $help_text = false
569
-    ) {
570
-
571
-        if ( ! $page) {
572
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
573
-        }
574
-
575
-        if ( ! $action) {
576
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
577
-        }
578
-
579
-        $action = empty($action) ? 'default' : $action;
580
-
581
-
582
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
583
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
584
-        $help_text    = ! $help_text ? '' : $help_text;
585
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
586
-                'event_espresso') . '" > ' . $help_text . ' </a>';
587
-    }
588
-
589
-
590
-    /**
591
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
592
-     *
593
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
594
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
595
-     * @param EE_Help_Tour
596
-     * @return string         html
597
-     */
598
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
599
-    {
600
-        $id    = $tour->get_slug();
601
-        $stops = $tour->get_stops();
602
-
603
-        $content = '<ol style="display:none" id="' . $id . '">';
604
-
605
-        foreach ($stops as $stop) {
606
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
607
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
608
-
609
-            //if container is set to modal then let's make sure we set the options accordingly
610
-            if (empty($data_id) && empty($data_class)) {
611
-                $stop['options']['modal']  = true;
612
-                $stop['options']['expose'] = true;
613
-            }
614
-
615
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
616
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
617
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
618
-
619
-            //options
620
-            if (isset($stop['options']) && is_array($stop['options'])) {
621
-                $options = ' data-options="';
622
-                foreach ($stop['options'] as $option => $value) {
623
-                    $options .= $option . ':' . $value . ';';
624
-                }
625
-                $options .= '"';
626
-            } else {
627
-                $options = '';
628
-            }
629
-
630
-            //let's put all together
631
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
632
-        }
633
-
634
-        $content .= '</ol>';
635
-        return $content;
636
-    }
637
-
638
-
639
-    /**
640
-     * This is a helper method to generate a status legend for a given status array.
641
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
642
-     * status_array.
643
-     *
644
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
645
-     *                               array(
646
-     *                               'status_item' => 'status_name'
647
-     *                               )
648
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
649
-     *                               the legend.
650
-     * @throws EE_Error
651
-     * @return string               html structure for status.
652
-     */
653
-    public static function status_legend($status_array, $active_status = '')
654
-    {
655
-        if ( ! is_array($status_array)) {
656
-            throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
657
-                'event_espresso'));
658
-        }
659
-
660
-        $setup_array = array();
661
-        foreach ($status_array as $item => $status) {
662
-            $setup_array[$item] = array(
663
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
664
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
665
-                'status' => $status,
666
-            );
667
-        }
668
-
669
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
670
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
671
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
672
-        foreach ($setup_array as $item => $details) {
673
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
674
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
675
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
676
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
677
-            $content .= '</dt>' . "\n";
678
-        }
679
-        $content .= '</dl>' . "\n";
680
-        $content .= '</div>' . "\n";
681
-        return $content;
682
-    }
683
-
684
-
685
-    /**
686
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
687
-     * that's nice for presenting in the wp admin
688
-     *
689
-     * @param mixed $data
690
-     * @return string
691
-     */
692
-    public static function layout_array_as_table($data)
693
-    {
694
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
695
-            $data = (array)$data;
696
-        }
697
-        ob_start();
698
-        if (is_array($data)) {
699
-            if (EEH_Array::is_associative_array($data)) {
700
-                ?>
343
+		$template_path    = false,
344
+		$template_args    = array(),
345
+		$return_string    = false,
346
+		$throw_exceptions = false
347
+	) {
348
+
349
+		/**
350
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
351
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
352
+		 * the display_template method are templates we DON'T want modified (usually because of js
353
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
354
+		 * using this.
355
+		 *
356
+		 * @since 4.6.0
357
+		 */
358
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
359
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
360
+
361
+		// you gimme nuttin - YOU GET NUTTIN !!
362
+		if ( ! $template_path || ! is_readable($template_path)) {
363
+			return '';
364
+		}
365
+		// if $template_args are not in an array, then make it so
366
+		if ( ! is_array($template_args) && ! is_object($template_args)) {
367
+			$template_args = array($template_args);
368
+		}
369
+		extract( $template_args, EXTR_SKIP );
370
+		// ignore whether template is accessible ?
371
+		if ( $throw_exceptions && ! is_readable( $template_path ) ) {
372
+			throw new \DomainException(
373
+					esc_html__(
374
+							'Invalid, unreadable, or missing file.',
375
+							'event_espresso'
376
+					)
377
+			);
378
+		}
379
+
380
+
381
+		if ($return_string) {
382
+			// because we want to return a string, we are going to capture the output
383
+			ob_start();
384
+			include($template_path);
385
+			return ob_get_clean();
386
+		} else {
387
+			include($template_path);
388
+		}
389
+		return '';
390
+	}
391
+
392
+
393
+	/**
394
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
395
+	 *
396
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
397
+	 * @param  string       $prefix added to the beginning of the generated class
398
+	 * @param  string       $suffix added to the end of the generated class
399
+	 * @return string
400
+	 */
401
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
402
+	{
403
+		// in the beginning...
404
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
405
+		// da muddle
406
+		$class = '';
407
+		// the end
408
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
409
+		// is the passed object an EE object ?
410
+		if ($object instanceof EE_Base_Class) {
411
+			// grab the exact type of object
412
+			$obj_class = get_class($object);
413
+			// depending on the type of object...
414
+			switch ($obj_class) {
415
+				// no specifics just yet...
416
+				default :
417
+					$class = strtolower(str_replace('_', '-', $obj_class));
418
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
419
+
420
+			}
421
+		}
422
+		return $prefix . $class . $suffix;
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * EEH_Template::format_currency
429
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
430
+	 * the country currency settings from the supplied country ISO code
431
+	 *
432
+	 * @param  float   $amount       raw money value
433
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
434
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
435
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
436
+	 * @param string   $cur_code_span_class
437
+	 * @return string        the html output for the formatted money value
438
+	 * @throws \EE_Error
439
+	 */
440
+	public static function format_currency(
441
+		$amount = null,
442
+		$return_raw = false,
443
+		$display_code = true,
444
+		$CNT_ISO = '',
445
+		$cur_code_span_class = 'currency-code'
446
+	) {
447
+		// ensure amount was received
448
+		if ($amount === null) {
449
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
450
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
451
+			return '';
452
+		}
453
+		//ensure amount is float
454
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
455
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
456
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
457
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
458
+		// still a number or was amount converted to a string like "free" ?
459
+		if (is_float($amount_formatted)) {
460
+			// was a country ISO code passed ? if so generate currency config object for that country
461
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
462
+			// verify results
463
+			if ( ! $mny instanceof EE_Currency_Config) {
464
+				// set default config country currency settings
465
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
466
+					? EE_Registry::instance()->CFG->currency
467
+					: new EE_Currency_Config();
468
+			}
469
+			// format float
470
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
471
+			// add formatting ?
472
+			if ( ! $return_raw) {
473
+				// add currency sign
474
+				if ($mny->sign_b4) {
475
+					if ($amount >= 0) {
476
+						$amount_formatted = $mny->sign . $amount_formatted;
477
+					} else {
478
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
479
+					}
480
+
481
+				} else {
482
+					$amount_formatted = $amount_formatted . $mny->sign;
483
+				}
484
+
485
+				// filter to allow global setting of display_code
486
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487
+
488
+				// add currency code ?
489
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
490
+			}
491
+			// filter results
492
+			$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
493
+				$amount_formatted, $mny, $return_raw);
494
+		}
495
+		// clean up vars
496
+		unset($mny);
497
+		// return formatted currency amount
498
+		return $amount_formatted;
499
+	}
500
+
501
+
502
+	/**
503
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
504
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
505
+	 * related status model or model object (i.e. in documentation etc.)
506
+	 *
507
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
508
+	 *                            match, then 'Unknown' will be returned.
509
+	 * @param  boolean $plural    Whether to return plural or not
510
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
511
+	 * @return string             The localized label for the status id.
512
+	 */
513
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
514
+	{
515
+		/** @type EEM_Status $EEM_Status */
516
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
517
+		$status     = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural,
518
+			$schema);
519
+		return $status[$status_id];
520
+	}
521
+
522
+
523
+	/**
524
+	 * This helper just returns a button or link for the given parameters
525
+	 *
526
+	 * @param  string $url   the url for the link, note that `esc_url` will be called on it
527
+	 * @param  string $label What is the label you want displayed for the button
528
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
529
+	 * @param string  $icon
530
+	 * @param string  $title
531
+	 * @return string the html output for the button
532
+	 */
533
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
534
+	{
535
+		$icon_html = '';
536
+		if ( ! empty($icon)) {
537
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
538
+			$dashicons = array_filter($dashicons);
539
+			$count     = count($dashicons);
540
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
541
+			foreach ($dashicons as $dashicon) {
542
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
543
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
544
+			}
545
+			$icon_html .= $count > 1 ? '</span>' : '';
546
+		}
547
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
548
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
549
+		return $button;
550
+	}
551
+
552
+
553
+	/**
554
+	 * This returns a generated link that will load the related help tab on admin pages.
555
+	 *
556
+	 * @param  string     $help_tab_id the id for the connected help tab
557
+	 * @param bool|string $page        The page identifier for the page the help tab is on
558
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
559
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
560
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
561
+	 * @return string              generated link
562
+	 */
563
+	public static function get_help_tab_link(
564
+		$help_tab_id,
565
+		$page = false,
566
+		$action = false,
567
+		$icon_style = false,
568
+		$help_text = false
569
+	) {
570
+
571
+		if ( ! $page) {
572
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
573
+		}
574
+
575
+		if ( ! $action) {
576
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
577
+		}
578
+
579
+		$action = empty($action) ? 'default' : $action;
580
+
581
+
582
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
583
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
584
+		$help_text    = ! $help_text ? '' : $help_text;
585
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
586
+				'event_espresso') . '" > ' . $help_text . ' </a>';
587
+	}
588
+
589
+
590
+	/**
591
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
592
+	 *
593
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
594
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
595
+	 * @param EE_Help_Tour
596
+	 * @return string         html
597
+	 */
598
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
599
+	{
600
+		$id    = $tour->get_slug();
601
+		$stops = $tour->get_stops();
602
+
603
+		$content = '<ol style="display:none" id="' . $id . '">';
604
+
605
+		foreach ($stops as $stop) {
606
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
607
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
608
+
609
+			//if container is set to modal then let's make sure we set the options accordingly
610
+			if (empty($data_id) && empty($data_class)) {
611
+				$stop['options']['modal']  = true;
612
+				$stop['options']['expose'] = true;
613
+			}
614
+
615
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
616
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
617
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
618
+
619
+			//options
620
+			if (isset($stop['options']) && is_array($stop['options'])) {
621
+				$options = ' data-options="';
622
+				foreach ($stop['options'] as $option => $value) {
623
+					$options .= $option . ':' . $value . ';';
624
+				}
625
+				$options .= '"';
626
+			} else {
627
+				$options = '';
628
+			}
629
+
630
+			//let's put all together
631
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
632
+		}
633
+
634
+		$content .= '</ol>';
635
+		return $content;
636
+	}
637
+
638
+
639
+	/**
640
+	 * This is a helper method to generate a status legend for a given status array.
641
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
642
+	 * status_array.
643
+	 *
644
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
645
+	 *                               array(
646
+	 *                               'status_item' => 'status_name'
647
+	 *                               )
648
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
649
+	 *                               the legend.
650
+	 * @throws EE_Error
651
+	 * @return string               html structure for status.
652
+	 */
653
+	public static function status_legend($status_array, $active_status = '')
654
+	{
655
+		if ( ! is_array($status_array)) {
656
+			throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
657
+				'event_espresso'));
658
+		}
659
+
660
+		$setup_array = array();
661
+		foreach ($status_array as $item => $status) {
662
+			$setup_array[$item] = array(
663
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
664
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
665
+				'status' => $status,
666
+			);
667
+		}
668
+
669
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
670
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
671
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
672
+		foreach ($setup_array as $item => $details) {
673
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
674
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
675
+			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
676
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
677
+			$content .= '</dt>' . "\n";
678
+		}
679
+		$content .= '</dl>' . "\n";
680
+		$content .= '</div>' . "\n";
681
+		return $content;
682
+	}
683
+
684
+
685
+	/**
686
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
687
+	 * that's nice for presenting in the wp admin
688
+	 *
689
+	 * @param mixed $data
690
+	 * @return string
691
+	 */
692
+	public static function layout_array_as_table($data)
693
+	{
694
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
695
+			$data = (array)$data;
696
+		}
697
+		ob_start();
698
+		if (is_array($data)) {
699
+			if (EEH_Array::is_associative_array($data)) {
700
+				?>
701 701
                 <table class="widefat">
702 702
                     <tbody>
703 703
                     <?php
704
-                    foreach ($data as $data_key => $data_values) {
705
-                        ?>
704
+					foreach ($data as $data_key => $data_values) {
705
+						?>
706 706
                         <tr>
707 707
                             <td>
708 708
                                 <?php echo $data_key; ?>
@@ -712,248 +712,248 @@  discard block
 block discarded – undo
712 712
                             </td>
713 713
                         </tr>
714 714
                         <?php
715
-                    } ?>
715
+					} ?>
716 716
                     </tbody>
717 717
                 </table>
718 718
                 <?php
719
-            } else {
720
-                ?>
719
+			} else {
720
+				?>
721 721
                 <ul>
722 722
                     <?php
723
-                    foreach ($data as $datum) {
724
-                        echo "<li>";
725
-                        echo self::layout_array_as_table($datum);
726
-                        echo "</li>";
727
-                    } ?>
723
+					foreach ($data as $datum) {
724
+						echo "<li>";
725
+						echo self::layout_array_as_table($datum);
726
+						echo "</li>";
727
+					} ?>
728 728
                 </ul>
729 729
                 <?php
730
-            }
731
-        } else {
732
-            //simple value
733
-            echo esc_html($data);
734
-        }
735
-        return ob_get_clean();
736
-    }
737
-
738
-
739
-    /**
740
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
741
-     *
742
-     * @since 4.4.0
743
-     * @see   self:get_paging_html() for argument docs.
744
-     * @param        $total_items
745
-     * @param        $current
746
-     * @param        $per_page
747
-     * @param        $url
748
-     * @param bool   $show_num_field
749
-     * @param string $paged_arg_name
750
-     * @param array  $items_label
751
-     * @return string
752
-     */
753
-    public static function paging_html(
754
-        $total_items,
755
-        $current,
756
-        $per_page,
757
-        $url,
758
-        $show_num_field = true,
759
-        $paged_arg_name = 'paged',
760
-        $items_label = array()
761
-    ) {
762
-        echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name,
763
-            $items_label);
764
-    }
765
-
766
-
767
-    /**
768
-     * A method for generating paging similar to WP_List_Table
769
-     *
770
-     * @since    4.4.0
771
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
772
-     * @param  integer $total_items     How many total items there are to page.
773
-     * @param  integer $current         What the current page is.
774
-     * @param  integer $per_page        How many items per page.
775
-     * @param  string  $url             What the base url for page links is.
776
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
777
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
778
-     * @param  array   $items_label     An array of singular/plural values for the items label:
779
-     *                                  array(
780
-     *                                  'single' => 'item',
781
-     *                                  'plural' => 'items'
782
-     *                                  )
783
-     * @return  string
784
-     */
785
-    public static function get_paging_html(
786
-        $total_items,
787
-        $current,
788
-        $per_page,
789
-        $url,
790
-        $show_num_field = true,
791
-        $paged_arg_name = 'paged',
792
-        $items_label = array()
793
-    ) {
794
-        $page_links     = array();
795
-        $disable_first  = $disable_last = '';
796
-        $total_items    = (int)$total_items;
797
-        $per_page       = (int)$per_page;
798
-        $current        = (int)$current;
799
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
800
-
801
-        //filter items_label
802
-        $items_label = apply_filters(
803
-            'FHEE__EEH_Template__get_paging_html__items_label',
804
-            $items_label
805
-        );
806
-
807
-        if (empty($items_label)
808
-            || ! is_array($items_label)
809
-            || ! isset($items_label['single'])
810
-            || ! isset($items_label['plural'])
811
-        ) {
812
-            $items_label = array(
813
-                'single' => __('1 item', 'event_espresso'),
814
-                'plural' => __('%s items', 'event_espresso'),
815
-            );
816
-        } else {
817
-            $items_label = array(
818
-                'single' => '1 ' . esc_html($items_label['single']),
819
-                'plural' => '%s ' . esc_html($items_label['plural']),
820
-            );
821
-        }
822
-
823
-        $total_pages = ceil($total_items / $per_page);
824
-
825
-        if ($total_pages <= 1) {
826
-            return '';
827
-        }
828
-
829
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
830
-
831
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
832
-
833
-        if ($current === 1) {
834
-            $disable_first = ' disabled';
835
-        }
836
-        if ($current == $total_pages) {
837
-            $disable_last = ' disabled';
838
-        }
839
-
840
-        $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
841
-            'first-page' . $disable_first,
842
-            esc_attr__('Go to the first page'),
843
-            esc_url(remove_query_arg($paged_arg_name, $url)),
844
-            '&laquo;'
845
-        );
846
-
847
-        $page_links[] = sprintf(
848
-            '<a class="%s" title="%s" href="%s">%s</a>',
849
-            'prev-page' . $disable_first,
850
-            esc_attr__('Go to the previous page'),
851
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
852
-            '&lsaquo;'
853
-        );
854
-
855
-        if ( ! $show_num_field) {
856
-            $html_current_page = $current;
857
-        } else {
858
-            $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
859
-                esc_attr__('Current page'),
860
-                $current,
861
-                strlen($total_pages)
862
-            );
863
-        }
864
-
865
-        $html_total_pages = sprintf(
866
-            '<span class="total-pages">%s</span>',
867
-            number_format_i18n($total_pages)
868
-        );
869
-        $page_links[]     = sprintf(
870
-            _x('%3$s%1$s of %2$s%4$s', 'paging'),
871
-            $html_current_page,
872
-            $html_total_pages,
873
-            '<span class="paging-input">',
874
-            '</span>'
875
-        );
876
-
877
-        $page_links[] = sprintf(
878
-            '<a class="%s" title="%s" href="%s">%s</a>',
879
-            'next-page' . $disable_last,
880
-            esc_attr__('Go to the next page'),
881
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
882
-            '&rsaquo;'
883
-        );
884
-
885
-        $page_links[] = sprintf(
886
-            '<a class="%s" title="%s" href="%s">%s</a>',
887
-            'last-page' . $disable_last,
888
-            esc_attr__('Go to the last page'),
889
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
890
-            '&raquo;'
891
-        );
892
-
893
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
894
-        // set page class
895
-        if ($total_pages) {
896
-            $page_class = $total_pages < 2 ? ' one-page' : '';
897
-        } else {
898
-            $page_class = ' no-pages';
899
-        }
900
-
901
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
902
-    }
903
-
904
-
905
-    /**
906
-     * @param string $wrap_class
907
-     * @param string $wrap_id
908
-     * @return string
909
-     */
910
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
911
-    {
912
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
913
-        if (
914
-            ! $admin &&
915
-            ! apply_filters(
916
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
917
-                EE_Registry::instance()->CFG->admin->show_reg_footer
918
-            )
919
-        ) {
920
-            return '';
921
-        }
922
-        $tag        = $admin ? 'span' : 'div';
923
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
924
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
925
-        $attributes .= ! empty($wrap_class)
926
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
927
-            : ' class="powered-by-event-espresso-credit"';
928
-        $query_args = array_merge(
929
-            array(
930
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
931
-                'utm_source'   => 'powered_by_event_espresso',
932
-                'utm_medium'   => 'link',
933
-                'utm_campaign' => 'powered_by',
934
-            ),
935
-            $query_args
936
-        );
937
-        $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
938
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
939
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
940
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
941
-        return (string)apply_filters(
942
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
943
-            sprintf(
944
-                esc_html_x(
945
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
946
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
947
-                    'event_espresso'
948
-                ),
949
-                "<{$tag}{$attributes}>",
950
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
951
-                $admin ? '' : '<br />'
952
-            ),
953
-            $wrap_class,
954
-            $wrap_id
955
-        );
956
-    }
730
+			}
731
+		} else {
732
+			//simple value
733
+			echo esc_html($data);
734
+		}
735
+		return ob_get_clean();
736
+	}
737
+
738
+
739
+	/**
740
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
741
+	 *
742
+	 * @since 4.4.0
743
+	 * @see   self:get_paging_html() for argument docs.
744
+	 * @param        $total_items
745
+	 * @param        $current
746
+	 * @param        $per_page
747
+	 * @param        $url
748
+	 * @param bool   $show_num_field
749
+	 * @param string $paged_arg_name
750
+	 * @param array  $items_label
751
+	 * @return string
752
+	 */
753
+	public static function paging_html(
754
+		$total_items,
755
+		$current,
756
+		$per_page,
757
+		$url,
758
+		$show_num_field = true,
759
+		$paged_arg_name = 'paged',
760
+		$items_label = array()
761
+	) {
762
+		echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name,
763
+			$items_label);
764
+	}
765
+
766
+
767
+	/**
768
+	 * A method for generating paging similar to WP_List_Table
769
+	 *
770
+	 * @since    4.4.0
771
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
772
+	 * @param  integer $total_items     How many total items there are to page.
773
+	 * @param  integer $current         What the current page is.
774
+	 * @param  integer $per_page        How many items per page.
775
+	 * @param  string  $url             What the base url for page links is.
776
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
777
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
778
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
779
+	 *                                  array(
780
+	 *                                  'single' => 'item',
781
+	 *                                  'plural' => 'items'
782
+	 *                                  )
783
+	 * @return  string
784
+	 */
785
+	public static function get_paging_html(
786
+		$total_items,
787
+		$current,
788
+		$per_page,
789
+		$url,
790
+		$show_num_field = true,
791
+		$paged_arg_name = 'paged',
792
+		$items_label = array()
793
+	) {
794
+		$page_links     = array();
795
+		$disable_first  = $disable_last = '';
796
+		$total_items    = (int)$total_items;
797
+		$per_page       = (int)$per_page;
798
+		$current        = (int)$current;
799
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
800
+
801
+		//filter items_label
802
+		$items_label = apply_filters(
803
+			'FHEE__EEH_Template__get_paging_html__items_label',
804
+			$items_label
805
+		);
806
+
807
+		if (empty($items_label)
808
+			|| ! is_array($items_label)
809
+			|| ! isset($items_label['single'])
810
+			|| ! isset($items_label['plural'])
811
+		) {
812
+			$items_label = array(
813
+				'single' => __('1 item', 'event_espresso'),
814
+				'plural' => __('%s items', 'event_espresso'),
815
+			);
816
+		} else {
817
+			$items_label = array(
818
+				'single' => '1 ' . esc_html($items_label['single']),
819
+				'plural' => '%s ' . esc_html($items_label['plural']),
820
+			);
821
+		}
822
+
823
+		$total_pages = ceil($total_items / $per_page);
824
+
825
+		if ($total_pages <= 1) {
826
+			return '';
827
+		}
828
+
829
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
830
+
831
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
832
+
833
+		if ($current === 1) {
834
+			$disable_first = ' disabled';
835
+		}
836
+		if ($current == $total_pages) {
837
+			$disable_last = ' disabled';
838
+		}
839
+
840
+		$page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
841
+			'first-page' . $disable_first,
842
+			esc_attr__('Go to the first page'),
843
+			esc_url(remove_query_arg($paged_arg_name, $url)),
844
+			'&laquo;'
845
+		);
846
+
847
+		$page_links[] = sprintf(
848
+			'<a class="%s" title="%s" href="%s">%s</a>',
849
+			'prev-page' . $disable_first,
850
+			esc_attr__('Go to the previous page'),
851
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
852
+			'&lsaquo;'
853
+		);
854
+
855
+		if ( ! $show_num_field) {
856
+			$html_current_page = $current;
857
+		} else {
858
+			$html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
859
+				esc_attr__('Current page'),
860
+				$current,
861
+				strlen($total_pages)
862
+			);
863
+		}
864
+
865
+		$html_total_pages = sprintf(
866
+			'<span class="total-pages">%s</span>',
867
+			number_format_i18n($total_pages)
868
+		);
869
+		$page_links[]     = sprintf(
870
+			_x('%3$s%1$s of %2$s%4$s', 'paging'),
871
+			$html_current_page,
872
+			$html_total_pages,
873
+			'<span class="paging-input">',
874
+			'</span>'
875
+		);
876
+
877
+		$page_links[] = sprintf(
878
+			'<a class="%s" title="%s" href="%s">%s</a>',
879
+			'next-page' . $disable_last,
880
+			esc_attr__('Go to the next page'),
881
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
882
+			'&rsaquo;'
883
+		);
884
+
885
+		$page_links[] = sprintf(
886
+			'<a class="%s" title="%s" href="%s">%s</a>',
887
+			'last-page' . $disable_last,
888
+			esc_attr__('Go to the last page'),
889
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
890
+			'&raquo;'
891
+		);
892
+
893
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
894
+		// set page class
895
+		if ($total_pages) {
896
+			$page_class = $total_pages < 2 ? ' one-page' : '';
897
+		} else {
898
+			$page_class = ' no-pages';
899
+		}
900
+
901
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
902
+	}
903
+
904
+
905
+	/**
906
+	 * @param string $wrap_class
907
+	 * @param string $wrap_id
908
+	 * @return string
909
+	 */
910
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
911
+	{
912
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
913
+		if (
914
+			! $admin &&
915
+			! apply_filters(
916
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
917
+				EE_Registry::instance()->CFG->admin->show_reg_footer
918
+			)
919
+		) {
920
+			return '';
921
+		}
922
+		$tag        = $admin ? 'span' : 'div';
923
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
924
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
925
+		$attributes .= ! empty($wrap_class)
926
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
927
+			: ' class="powered-by-event-espresso-credit"';
928
+		$query_args = array_merge(
929
+			array(
930
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
931
+				'utm_source'   => 'powered_by_event_espresso',
932
+				'utm_medium'   => 'link',
933
+				'utm_campaign' => 'powered_by',
934
+			),
935
+			$query_args
936
+		);
937
+		$powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
938
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
939
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
940
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
941
+		return (string)apply_filters(
942
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
943
+			sprintf(
944
+				esc_html_x(
945
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
946
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
947
+					'event_espresso'
948
+				),
949
+				"<{$tag}{$attributes}>",
950
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
951
+				$admin ? '' : '<br />'
952
+			),
953
+			$wrap_class,
954
+			$wrap_id
955
+		);
956
+	}
957 957
 
958 958
 
959 959
 } //end EEH_Template class
@@ -962,33 +962,33 @@  discard block
 block discarded – undo
962 962
 
963 963
 
964 964
 if ( ! function_exists('espresso_pagination')) {
965
-    /**
966
-     *    espresso_pagination
967
-     *
968
-     * @access    public
969
-     * @return    void
970
-     */
971
-    function espresso_pagination()
972
-    {
973
-        global $wp_query;
974
-        $big        = 999999999; // need an unlikely integer
975
-        $pagination = paginate_links(
976
-            array(
977
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
978
-                'format'       => '?paged=%#%',
979
-                'current'      => max(1, get_query_var('paged')),
980
-                'total'        => $wp_query->max_num_pages,
981
-                'show_all'     => true,
982
-                'end_size'     => 10,
983
-                'mid_size'     => 6,
984
-                'prev_next'    => true,
985
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
986
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
987
-                'type'         => 'plain',
988
-                'add_args'     => false,
989
-                'add_fragment' => '',
990
-            )
991
-        );
992
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
993
-    }
965
+	/**
966
+	 *    espresso_pagination
967
+	 *
968
+	 * @access    public
969
+	 * @return    void
970
+	 */
971
+	function espresso_pagination()
972
+	{
973
+		global $wp_query;
974
+		$big        = 999999999; // need an unlikely integer
975
+		$pagination = paginate_links(
976
+			array(
977
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
978
+				'format'       => '?paged=%#%',
979
+				'current'      => max(1, get_query_var('paged')),
980
+				'total'        => $wp_query->max_num_pages,
981
+				'show_all'     => true,
982
+				'end_size'     => 10,
983
+				'mid_size'     => 6,
984
+				'prev_next'    => true,
985
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
986
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
987
+				'type'         => 'plain',
988
+				'add_args'     => false,
989
+				'add_fragment' => '',
990
+			)
991
+		);
992
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
993
+	}
994 994
 }
995 995
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 /**
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     public static function load_espresso_theme_functions()
82 82
     {
83 83
         if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
84
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) {
85
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php');
86 86
             }
87 87
         }
88 88
     }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     public static function get_espresso_themes()
97 97
     {
98 98
         if (empty(EEH_Template::$_espresso_themes)) {
99
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
99
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
100 100
             if (empty($espresso_themes)) {
101 101
                 return array();
102 102
             }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     ) {
133 133
         do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134 134
         $templates = array();
135
-        $name      = (string)$name;
135
+        $name      = (string) $name;
136 136
         if ($name != '') {
137 137
             $templates[] = "{$slug}-{$name}.php";
138 138
         }
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
                 if (isset($EE_CPTs[$post_type])) {
212 212
                     $archive_or_single = is_archive() ? 'archive' : '';
213 213
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
214
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
214
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
215 215
                 }
216 216
             }
217 217
             // currently active EE template theme
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
             // array of paths to folders that may contain templates
221 221
             $template_folder_paths = array(
222 222
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
223
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
224 224
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
225 225
                 EVENT_ESPRESSO_TEMPLATE_DIR,
226 226
             );
227 227
 
228 228
             //add core plugin folders for checking only if we're not $check_if_custom
229 229
             if ( ! $check_if_custom) {
230
-                $core_paths            = array(
230
+                $core_paths = array(
231 231
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
-                    EE_PUBLIC . $current_theme,
232
+                    EE_PUBLIC.$current_theme,
233 233
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
-                    EE_TEMPLATES . $current_theme,
234
+                    EE_TEMPLATES.$current_theme,
235 235
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236 236
                     EE_PLUGIN_DIR_PATH,
237 237
                 );
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
                     );
263 263
                     if ($common_base_path !== '') {
264 264
                         // both paths have a common base, so just tack the filename onto our search path
265
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
266 266
                     } else {
267 267
                         // no common base path, so let's just concatenate
268
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
269 269
                     }
270 270
                     // build up our template locations array by adding our resolved paths
271 271
                     $full_template_paths[] = $resolved_path;
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274 274
                 array_unshift($full_template_paths, $template);
275 275
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
276
+                array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name);
277 277
             }
278 278
             // filter final array of full template paths
279 279
             $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280 280
                 $full_template_paths, $file_name);
281 281
             // now loop through our final array of template location paths and check each location
282
-            foreach ((array)$full_template_paths as $full_template_path) {
282
+            foreach ((array) $full_template_paths as $full_template_path) {
283 283
                 if (is_readable($full_template_path)) {
284 284
                     $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285 285
                     break;
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
         if ( ! is_array($template_args) && ! is_object($template_args)) {
367 367
             $template_args = array($template_args);
368 368
         }
369
-        extract( $template_args, EXTR_SKIP );
369
+        extract($template_args, EXTR_SKIP);
370 370
         // ignore whether template is accessible ?
371
-        if ( $throw_exceptions && ! is_readable( $template_path ) ) {
371
+        if ($throw_exceptions && ! is_readable($template_path)) {
372 372
             throw new \DomainException(
373 373
                     esc_html__(
374 374
                             'Invalid, unreadable, or missing file.',
@@ -401,11 +401,11 @@  discard block
 block discarded – undo
401 401
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
402 402
     {
403 403
         // in the beginning...
404
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
404
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
405 405
         // da muddle
406 406
         $class = '';
407 407
         // the end
408
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
408
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
409 409
         // is the passed object an EE object ?
410 410
         if ($object instanceof EE_Base_Class) {
411 411
             // grab the exact type of object
@@ -415,11 +415,11 @@  discard block
 block discarded – undo
415 415
                 // no specifics just yet...
416 416
                 default :
417 417
                     $class = strtolower(str_replace('_', '-', $obj_class));
418
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
418
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
419 419
 
420 420
             }
421 421
         }
422
-        return $prefix . $class . $suffix;
422
+        return $prefix.$class.$suffix;
423 423
     }
424 424
 
425 425
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
             return '';
452 452
         }
453 453
         //ensure amount is float
454
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
454
+        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
455 455
         $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
456 456
         // filter raw amount (allows 0.00 to be changed to "free" for example)
457 457
         $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
@@ -473,20 +473,20 @@  discard block
 block discarded – undo
473 473
                 // add currency sign
474 474
                 if ($mny->sign_b4) {
475 475
                     if ($amount >= 0) {
476
-                        $amount_formatted = $mny->sign . $amount_formatted;
476
+                        $amount_formatted = $mny->sign.$amount_formatted;
477 477
                     } else {
478
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
478
+                        $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
479 479
                     }
480 480
 
481 481
                 } else {
482
-                    $amount_formatted = $amount_formatted . $mny->sign;
482
+                    $amount_formatted = $amount_formatted.$mny->sign;
483 483
                 }
484 484
 
485 485
                 // filter to allow global setting of display_code
486 486
                 $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
487 487
 
488 488
                 // add currency code ?
489
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
489
+                $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
490 490
             }
491 491
             // filter results
492 492
             $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
541 541
             foreach ($dashicons as $dashicon) {
542 542
                 $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
543
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
543
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
544 544
             }
545 545
             $icon_html .= $count > 1 ? '</span>' : '';
546 546
         }
547
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
548
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
547
+        $label  = ! empty($icon) ? $icon_html.$label : $label;
548
+        $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
549 549
         return $button;
550 550
     }
551 551
 
@@ -579,11 +579,11 @@  discard block
 block discarded – undo
579 579
         $action = empty($action) ? 'default' : $action;
580 580
 
581 581
 
582
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
582
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
583 583
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
584 584
         $help_text    = ! $help_text ? '' : $help_text;
585
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
586
-                'event_espresso') . '" > ' . $help_text . ' </a>';
585
+        return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
586
+                'event_espresso').'" > '.$help_text.' </a>';
587 587
     }
588 588
 
589 589
 
@@ -600,11 +600,11 @@  discard block
 block discarded – undo
600 600
         $id    = $tour->get_slug();
601 601
         $stops = $tour->get_stops();
602 602
 
603
-        $content = '<ol style="display:none" id="' . $id . '">';
603
+        $content = '<ol style="display:none" id="'.$id.'">';
604 604
 
605 605
         foreach ($stops as $stop) {
606
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
607
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
606
+            $data_id    = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
607
+            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
608 608
 
609 609
             //if container is set to modal then let's make sure we set the options accordingly
610 610
             if (empty($data_id) && empty($data_class)) {
@@ -612,15 +612,15 @@  discard block
 block discarded – undo
612 612
                 $stop['options']['expose'] = true;
613 613
             }
614 614
 
615
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
616
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
615
+            $custom_class  = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
616
+            $button_text   = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
617 617
             $inner_content = isset($stop['content']) ? $stop['content'] : '';
618 618
 
619 619
             //options
620 620
             if (isset($stop['options']) && is_array($stop['options'])) {
621 621
                 $options = ' data-options="';
622 622
                 foreach ($stop['options'] as $option => $value) {
623
-                    $options .= $option . ':' . $value . ';';
623
+                    $options .= $option.':'.$value.';';
624 624
                 }
625 625
                 $options .= '"';
626 626
             } else {
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
             }
629 629
 
630 630
             //let's put all together
631
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
631
+            $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
632 632
         }
633 633
 
634 634
         $content .= '</ol>';
@@ -660,24 +660,24 @@  discard block
 block discarded – undo
660 660
         $setup_array = array();
661 661
         foreach ($status_array as $item => $status) {
662 662
             $setup_array[$item] = array(
663
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
663
+                'class'  => 'ee-status-legend ee-status-legend-'.$status,
664 664
                 'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
665 665
                 'status' => $status,
666 666
             );
667 667
         }
668 668
 
669
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
670
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
671
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
669
+        $content = '<div class="ee-list-table-legend-container">'."\n";
670
+        $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n";
671
+        $content .= '<dl class="ee-list-table-legend">'."\n\t";
672 672
         foreach ($setup_array as $item => $details) {
673 673
             $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
674
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
675
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
676
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
677
-            $content .= '</dt>' . "\n";
674
+            $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
675
+            $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t";
676
+            $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
677
+            $content .= '</dt>'."\n";
678 678
         }
679
-        $content .= '</dl>' . "\n";
680
-        $content .= '</div>' . "\n";
679
+        $content .= '</dl>'."\n";
680
+        $content .= '</div>'."\n";
681 681
         return $content;
682 682
     }
683 683
 
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
     public static function layout_array_as_table($data)
693 693
     {
694 694
         if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
695
-            $data = (array)$data;
695
+            $data = (array) $data;
696 696
         }
697 697
         ob_start();
698 698
         if (is_array($data)) {
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
     ) {
794 794
         $page_links     = array();
795 795
         $disable_first  = $disable_last = '';
796
-        $total_items    = (int)$total_items;
797
-        $per_page       = (int)$per_page;
798
-        $current        = (int)$current;
796
+        $total_items    = (int) $total_items;
797
+        $per_page       = (int) $per_page;
798
+        $current        = (int) $current;
799 799
         $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
800 800
 
801 801
         //filter items_label
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
             );
816 816
         } else {
817 817
             $items_label = array(
818
-                'single' => '1 ' . esc_html($items_label['single']),
819
-                'plural' => '%s ' . esc_html($items_label['plural']),
818
+                'single' => '1 '.esc_html($items_label['single']),
819
+                'plural' => '%s '.esc_html($items_label['plural']),
820 820
             );
821 821
         }
822 822
 
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 
829 829
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
830 830
 
831
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
831
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
832 832
 
833 833
         if ($current === 1) {
834 834
             $disable_first = ' disabled';
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
         }
839 839
 
840 840
         $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
841
-            'first-page' . $disable_first,
841
+            'first-page'.$disable_first,
842 842
             esc_attr__('Go to the first page'),
843 843
             esc_url(remove_query_arg($paged_arg_name, $url)),
844 844
             '&laquo;'
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 
847 847
         $page_links[] = sprintf(
848 848
             '<a class="%s" title="%s" href="%s">%s</a>',
849
-            'prev-page' . $disable_first,
849
+            'prev-page'.$disable_first,
850 850
             esc_attr__('Go to the previous page'),
851 851
             esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
852 852
             '&lsaquo;'
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
             '<span class="total-pages">%s</span>',
867 867
             number_format_i18n($total_pages)
868 868
         );
869
-        $page_links[]     = sprintf(
869
+        $page_links[] = sprintf(
870 870
             _x('%3$s%1$s of %2$s%4$s', 'paging'),
871 871
             $html_current_page,
872 872
             $html_total_pages,
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 
877 877
         $page_links[] = sprintf(
878 878
             '<a class="%s" title="%s" href="%s">%s</a>',
879
-            'next-page' . $disable_last,
879
+            'next-page'.$disable_last,
880 880
             esc_attr__('Go to the next page'),
881 881
             esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
882 882
             '&rsaquo;'
@@ -884,13 +884,13 @@  discard block
 block discarded – undo
884 884
 
885 885
         $page_links[] = sprintf(
886 886
             '<a class="%s" title="%s" href="%s">%s</a>',
887
-            'last-page' . $disable_last,
887
+            'last-page'.$disable_last,
888 888
             esc_attr__('Go to the last page'),
889 889
             esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
890 890
             '&raquo;'
891 891
         );
892 892
 
893
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
893
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
894 894
         // set page class
895 895
         if ($total_pages) {
896 896
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             $page_class = ' no-pages';
899 899
         }
900 900
 
901
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
901
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
902 902
     }
903 903
 
904 904
 
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
             $query_args
936 936
         );
937 937
         $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
938
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
938
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso');
939 939
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
940 940
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
941
-        return (string)apply_filters(
941
+        return (string) apply_filters(
942 942
             'FHEE__EEH_Template__powered_by_event_espresso__html',
943 943
             sprintf(
944 944
                 esc_html_x(
@@ -989,6 +989,6 @@  discard block
 block discarded – undo
989 989
                 'add_fragment' => '',
990 990
             )
991 991
         );
992
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
992
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
993 993
     }
994 994
 }
995 995
\ No newline at end of file
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\database\TableAnalysis;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 /**
10 10
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -29,268 +29,268 @@  discard block
 block discarded – undo
29 29
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
30 30
 {
31 31
 
32
-    /**
33
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
-     */
35
-    protected $_table_analysis;
36
-
37
-
38
-    /**
39
-     * EE_Brewing_Regular constructor.
40
-     * @throws \DomainException
41
-     * @throws \EE_Error
42
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
43
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
44
-     * @throws \InvalidArgumentException
45
-     */
46
-    public function __construct(TableAnalysis $table_analysis)
47
-    {
48
-        $this->_table_analysis = $table_analysis;
49
-        if (defined('EE_CAFF_PATH')) {
50
-            // activation
51
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
52
-            // load caff init
53
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
54
-            // remove the "powered by" credit link from receipts and invoices
55
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
56
-            // add caffeinated modules
57
-            add_filter(
58
-                'FHEE__EE_Config__register_modules__modules_to_register',
59
-                array($this, 'caffeinated_modules_to_register')
60
-            );
61
-            // load caff scripts
62
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
63
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
64
-            //add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
65
-            EE_Register_Payment_Method::register(
66
-                'caffeinated_payment_methods',
67
-                array(
68
-                    'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR)
69
-                )
70
-            );
71
-            // caffeinated constructed
72
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
73
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
74
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
75
-        }
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
82
-     *
83
-     * @param array $paths original helper paths array
84
-     * @return array             new array of paths
85
-     */
86
-    public function caf_helper_paths($paths)
87
-    {
88
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
89
-        return $paths;
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
96
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
97
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
98
-     * This action should only be called when EE 4.x.0.P is initially activated.
99
-     * Right now the only CAF content are these global prices. If there's more in the future, then
100
-     * we should probably create a caf file to contain it all instead just a function like this.
101
-     * Right now, we ASSUME the only price types in the system are default ones
102
-     *
103
-     * @global wpdb $wpdb
104
-     */
105
-    public function initialize_caf_db_content()
106
-    {
107
-        global $wpdb;
108
-        //use same method of getting creator id as the version introducing the change
109
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
110
-        $price_type_table = $wpdb->prefix . "esp_price_type";
111
-        $price_table = $wpdb->prefix . "esp_price";
112
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
113
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
114
-            $tax_price_type_count = $wpdb->get_var($SQL);
115
-            if ($tax_price_type_count <= 1) {
116
-                $wpdb->insert(
117
-                    $price_type_table,
118
-                    array(
119
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
120
-                        'PBT_ID'         => 4,
121
-                        'PRT_is_percent' => true,
122
-                        'PRT_order'      => 60,
123
-                        'PRT_deleted'    => false,
124
-                        'PRT_wp_user'    => $default_creator_id,
125
-                    ),
126
-                    array(
127
-                        '%s',//PRT_name
128
-                        '%d',//PBT_id
129
-                        '%d',//PRT_is_percent
130
-                        '%d',//PRT_order
131
-                        '%d',//PRT_deleted
132
-                        '%d', //PRT_wp_user
133
-                    )
134
-                );
135
-                //federal tax
136
-                $result = $wpdb->insert(
137
-                    $price_type_table,
138
-                    array(
139
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
140
-                        'PBT_ID'         => 4,
141
-                        'PRT_is_percent' => true,
142
-                        'PRT_order'      => 70,
143
-                        'PRT_deleted'    => false,
144
-                        'PRT_wp_user'    => $default_creator_id,
145
-                    ),
146
-                    array(
147
-                        '%s',//PRT_name
148
-                        '%d',//PBT_id
149
-                        '%d',//PRT_is_percent
150
-                        '%d',//PRT_order
151
-                        '%d',//PRT_deleted
152
-                        '%d' //PRT_wp_user
153
-                    )
154
-                );
155
-                if ($result) {
156
-                    $wpdb->insert(
157
-                        $price_table,
158
-                        array(
159
-                            'PRT_ID'         => $wpdb->insert_id,
160
-                            'PRC_amount'     => 15.00,
161
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
162
-                            'PRC_desc'       => '',
163
-                            'PRC_is_default' => true,
164
-                            'PRC_overrides'  => null,
165
-                            'PRC_deleted'    => false,
166
-                            'PRC_order'      => 50,
167
-                            'PRC_parent'     => null,
168
-                            'PRC_wp_user'    => $default_creator_id,
169
-                        ),
170
-                        array(
171
-                            '%d',//PRT_id
172
-                            '%f',//PRC_amount
173
-                            '%s',//PRC_name
174
-                            '%s',//PRC_desc
175
-                            '%d',//PRC_is_default
176
-                            '%d',//PRC_overrides
177
-                            '%d',//PRC_deleted
178
-                            '%d',//PRC_order
179
-                            '%d',//PRC_parent
180
-                            '%d' //PRC_wp_user
181
-                        )
182
-                    );
183
-                }
184
-            }
185
-        }
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     *    caffeinated_modules_to_register
192
-     *
193
-     * @access public
194
-     * @param array $modules_to_register
195
-     * @return array
196
-     */
197
-    public function caffeinated_modules_to_register($modules_to_register = array())
198
-    {
199
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
200
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
201
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
202
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
203
-            }
204
-        }
205
-        return $modules_to_register;
206
-    }
207
-
208
-
209
-
210
-    public function caffeinated_init()
211
-    {
212
-        // EE_Register_CPTs hooks
213
-        add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
214
-        add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
215
-        add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
216
-        EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
217
-        // caffeinated_init__complete hook
218
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
219
-    }
220
-
221
-
222
-
223
-    public function enqueue_caffeinated_scripts()
224
-    {
225
-        // sound of crickets...
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * callbacks below here
232
-     *
233
-     * @param array $taxonomy_array
234
-     * @return array
235
-     */
236
-    public function filter_taxonomies(array $taxonomy_array)
237
-    {
238
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
239
-        return $taxonomy_array;
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * @param array $cpt_array
246
-     * @return mixed
247
-     */
248
-    public function filter_cpts(array $cpt_array)
249
-    {
250
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
251
-        return $cpt_array;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * @param array $menuitems
258
-     * @return array
259
-     */
260
-    public function nav_metabox_items(array $menuitems)
261
-    {
262
-        $menuitems[] = array(
263
-            'title'       => __('Venue List', 'event_espresso'),
264
-            'url'         => get_post_type_archive_link('espresso_venues'),
265
-            'description' => __('Archive page for all venues.', 'event_espresso'),
266
-        );
267
-        return $menuitems;
268
-    }
269
-
270
-
271
-    /**
272
-     * Gets the injected table analyzer, or throws an exception
273
-     *
274
-     * @return TableAnalysis
275
-     * @throws \EE_Error
276
-     */
277
-    protected function _get_table_analysis()
278
-    {
279
-        if ($this->_table_analysis instanceof TableAnalysis) {
280
-            return $this->_table_analysis;
281
-        } else {
282
-            throw new \EE_Error(
283
-                sprintf(
284
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
285
-                    get_class($this)
286
-                )
287
-            );
288
-        }
289
-    }
32
+	/**
33
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
34
+	 */
35
+	protected $_table_analysis;
36
+
37
+
38
+	/**
39
+	 * EE_Brewing_Regular constructor.
40
+	 * @throws \DomainException
41
+	 * @throws \EE_Error
42
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
43
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
44
+	 * @throws \InvalidArgumentException
45
+	 */
46
+	public function __construct(TableAnalysis $table_analysis)
47
+	{
48
+		$this->_table_analysis = $table_analysis;
49
+		if (defined('EE_CAFF_PATH')) {
50
+			// activation
51
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
52
+			// load caff init
53
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
54
+			// remove the "powered by" credit link from receipts and invoices
55
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
56
+			// add caffeinated modules
57
+			add_filter(
58
+				'FHEE__EE_Config__register_modules__modules_to_register',
59
+				array($this, 'caffeinated_modules_to_register')
60
+			);
61
+			// load caff scripts
62
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
63
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
64
+			//add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
65
+			EE_Register_Payment_Method::register(
66
+				'caffeinated_payment_methods',
67
+				array(
68
+					'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR)
69
+				)
70
+			);
71
+			// caffeinated constructed
72
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
73
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
74
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
75
+		}
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
82
+	 *
83
+	 * @param array $paths original helper paths array
84
+	 * @return array             new array of paths
85
+	 */
86
+	public function caf_helper_paths($paths)
87
+	{
88
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
89
+		return $paths;
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
96
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
97
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
98
+	 * This action should only be called when EE 4.x.0.P is initially activated.
99
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
100
+	 * we should probably create a caf file to contain it all instead just a function like this.
101
+	 * Right now, we ASSUME the only price types in the system are default ones
102
+	 *
103
+	 * @global wpdb $wpdb
104
+	 */
105
+	public function initialize_caf_db_content()
106
+	{
107
+		global $wpdb;
108
+		//use same method of getting creator id as the version introducing the change
109
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
110
+		$price_type_table = $wpdb->prefix . "esp_price_type";
111
+		$price_table = $wpdb->prefix . "esp_price";
112
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
113
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
114
+			$tax_price_type_count = $wpdb->get_var($SQL);
115
+			if ($tax_price_type_count <= 1) {
116
+				$wpdb->insert(
117
+					$price_type_table,
118
+					array(
119
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
120
+						'PBT_ID'         => 4,
121
+						'PRT_is_percent' => true,
122
+						'PRT_order'      => 60,
123
+						'PRT_deleted'    => false,
124
+						'PRT_wp_user'    => $default_creator_id,
125
+					),
126
+					array(
127
+						'%s',//PRT_name
128
+						'%d',//PBT_id
129
+						'%d',//PRT_is_percent
130
+						'%d',//PRT_order
131
+						'%d',//PRT_deleted
132
+						'%d', //PRT_wp_user
133
+					)
134
+				);
135
+				//federal tax
136
+				$result = $wpdb->insert(
137
+					$price_type_table,
138
+					array(
139
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
140
+						'PBT_ID'         => 4,
141
+						'PRT_is_percent' => true,
142
+						'PRT_order'      => 70,
143
+						'PRT_deleted'    => false,
144
+						'PRT_wp_user'    => $default_creator_id,
145
+					),
146
+					array(
147
+						'%s',//PRT_name
148
+						'%d',//PBT_id
149
+						'%d',//PRT_is_percent
150
+						'%d',//PRT_order
151
+						'%d',//PRT_deleted
152
+						'%d' //PRT_wp_user
153
+					)
154
+				);
155
+				if ($result) {
156
+					$wpdb->insert(
157
+						$price_table,
158
+						array(
159
+							'PRT_ID'         => $wpdb->insert_id,
160
+							'PRC_amount'     => 15.00,
161
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
162
+							'PRC_desc'       => '',
163
+							'PRC_is_default' => true,
164
+							'PRC_overrides'  => null,
165
+							'PRC_deleted'    => false,
166
+							'PRC_order'      => 50,
167
+							'PRC_parent'     => null,
168
+							'PRC_wp_user'    => $default_creator_id,
169
+						),
170
+						array(
171
+							'%d',//PRT_id
172
+							'%f',//PRC_amount
173
+							'%s',//PRC_name
174
+							'%s',//PRC_desc
175
+							'%d',//PRC_is_default
176
+							'%d',//PRC_overrides
177
+							'%d',//PRC_deleted
178
+							'%d',//PRC_order
179
+							'%d',//PRC_parent
180
+							'%d' //PRC_wp_user
181
+						)
182
+					);
183
+				}
184
+			}
185
+		}
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 *    caffeinated_modules_to_register
192
+	 *
193
+	 * @access public
194
+	 * @param array $modules_to_register
195
+	 * @return array
196
+	 */
197
+	public function caffeinated_modules_to_register($modules_to_register = array())
198
+	{
199
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
200
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
201
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
202
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
203
+			}
204
+		}
205
+		return $modules_to_register;
206
+	}
207
+
208
+
209
+
210
+	public function caffeinated_init()
211
+	{
212
+		// EE_Register_CPTs hooks
213
+		add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10);
214
+		add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10);
215
+		add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10);
216
+		EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false);
217
+		// caffeinated_init__complete hook
218
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
219
+	}
220
+
221
+
222
+
223
+	public function enqueue_caffeinated_scripts()
224
+	{
225
+		// sound of crickets...
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * callbacks below here
232
+	 *
233
+	 * @param array $taxonomy_array
234
+	 * @return array
235
+	 */
236
+	public function filter_taxonomies(array $taxonomy_array)
237
+	{
238
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
239
+		return $taxonomy_array;
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * @param array $cpt_array
246
+	 * @return mixed
247
+	 */
248
+	public function filter_cpts(array $cpt_array)
249
+	{
250
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
251
+		return $cpt_array;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * @param array $menuitems
258
+	 * @return array
259
+	 */
260
+	public function nav_metabox_items(array $menuitems)
261
+	{
262
+		$menuitems[] = array(
263
+			'title'       => __('Venue List', 'event_espresso'),
264
+			'url'         => get_post_type_archive_link('espresso_venues'),
265
+			'description' => __('Archive page for all venues.', 'event_espresso'),
266
+		);
267
+		return $menuitems;
268
+	}
269
+
270
+
271
+	/**
272
+	 * Gets the injected table analyzer, or throws an exception
273
+	 *
274
+	 * @return TableAnalysis
275
+	 * @throws \EE_Error
276
+	 */
277
+	protected function _get_table_analysis()
278
+	{
279
+		if ($this->_table_analysis instanceof TableAnalysis) {
280
+			return $this->_table_analysis;
281
+		} else {
282
+			throw new \EE_Error(
283
+				sprintf(
284
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
285
+					get_class($this)
286
+				)
287
+			);
288
+		}
289
+	}
290 290
 }
291 291
 
292 292
 
293 293
 
294 294
 $brewing = new EE_Brewing_Regular(
295
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
295
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
296 296
 );
297 297
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
  * define and use the hook in a specific caffeinated/whatever class or file.
13 13
  */
14 14
 // defined some new constants related to caffeinated folder
15
-define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/');
16
-define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS);
17
-define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS);
18
-define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS);
15
+define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/');
16
+define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS);
17
+define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS);
18
+define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS);
19 19
 
20 20
 
21 21
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             EE_Register_Payment_Method::register(
66 66
                 'caffeinated_payment_methods',
67 67
                 array(
68
-                    'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR)
68
+                    'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR)
69 69
                 )
70 70
             );
71 71
             // caffeinated constructed
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function caf_helper_paths($paths)
87 87
     {
88
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
88
+        $paths[] = EE_CAF_CORE.'helpers'.DS;
89 89
         return $paths;
90 90
     }
91 91
 
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
         global $wpdb;
108 108
         //use same method of getting creator id as the version introducing the change
109 109
         $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
110
-        $price_type_table = $wpdb->prefix . "esp_price_type";
111
-        $price_table = $wpdb->prefix . "esp_price";
110
+        $price_type_table = $wpdb->prefix."esp_price_type";
111
+        $price_table = $wpdb->prefix."esp_price";
112 112
         if ($this->_get_table_analysis()->tableExists($price_type_table)) {
113
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
113
+            $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; //include trashed price types
114 114
             $tax_price_type_count = $wpdb->get_var($SQL);
115 115
             if ($tax_price_type_count <= 1) {
116 116
                 $wpdb->insert(
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
                         'PRT_wp_user'    => $default_creator_id,
125 125
                     ),
126 126
                     array(
127
-                        '%s',//PRT_name
128
-                        '%d',//PBT_id
129
-                        '%d',//PRT_is_percent
130
-                        '%d',//PRT_order
131
-                        '%d',//PRT_deleted
127
+                        '%s', //PRT_name
128
+                        '%d', //PBT_id
129
+                        '%d', //PRT_is_percent
130
+                        '%d', //PRT_order
131
+                        '%d', //PRT_deleted
132 132
                         '%d', //PRT_wp_user
133 133
                     )
134 134
                 );
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
                         'PRT_wp_user'    => $default_creator_id,
145 145
                     ),
146 146
                     array(
147
-                        '%s',//PRT_name
148
-                        '%d',//PBT_id
149
-                        '%d',//PRT_is_percent
150
-                        '%d',//PRT_order
151
-                        '%d',//PRT_deleted
147
+                        '%s', //PRT_name
148
+                        '%d', //PBT_id
149
+                        '%d', //PRT_is_percent
150
+                        '%d', //PRT_order
151
+                        '%d', //PRT_deleted
152 152
                         '%d' //PRT_wp_user
153 153
                     )
154 154
                 );
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
                             'PRC_wp_user'    => $default_creator_id,
169 169
                         ),
170 170
                         array(
171
-                            '%d',//PRT_id
172
-                            '%f',//PRC_amount
173
-                            '%s',//PRC_name
174
-                            '%s',//PRC_desc
175
-                            '%d',//PRC_is_default
176
-                            '%d',//PRC_overrides
177
-                            '%d',//PRC_deleted
178
-                            '%d',//PRC_order
179
-                            '%d',//PRC_parent
171
+                            '%d', //PRT_id
172
+                            '%f', //PRC_amount
173
+                            '%s', //PRC_name
174
+                            '%s', //PRC_desc
175
+                            '%d', //PRC_is_default
176
+                            '%d', //PRC_overrides
177
+                            '%d', //PRC_deleted
178
+                            '%d', //PRC_order
179
+                            '%d', //PRC_parent
180 180
                             '%d' //PRC_wp_user
181 181
                         )
182 182
                     );
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public function caffeinated_modules_to_register($modules_to_register = array())
198 198
     {
199
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
200
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
199
+        if (is_readable(EE_CAFF_PATH.'modules')) {
200
+            $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR);
201 201
             if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
202 202
                 $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
203 203
             }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Capabilities.lib.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 use EventEspresso\core\services\loaders\LoaderFactory;
11 11
 
12 12
 if (! defined('EVENT_ESPRESSO_VERSION')) {
13
-    exit('No direct script access allowed');
13
+	exit('No direct script access allowed');
14 14
 }
15 15
 
16 16
 /**
@@ -24,189 +24,189 @@  discard block
 block discarded – undo
24 24
 class EE_Register_Capabilities implements EEI_Plugin_API
25 25
 {
26 26
 
27
-    /**
28
-     * Holds the settings for a specific registration.
29
-     *
30
-     * @var array
31
-     */
32
-    protected static $_registry = array();
27
+	/**
28
+	 * Holds the settings for a specific registration.
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected static $_registry = array();
33 33
 
34 34
 
35
-    /**
36
-     * Used to register capability items with EE core.
37
-     *
38
-     * @since 4.5.0
39
-     * @param string $cap_reference                                                       usually will be a class name
40
-     *                                                                                    that references capability
41
-     *                                                                                    related items setup for
42
-     *                                                                                    something.
43
-     * @param array  $setup_args                                                          {
44
-     *                                                                                    An array of items related to
45
-     *                                                                                    registering capabilities.
46
-     * @type array   $capabilities                                                        An array mapping capability
47
-     *       strings to core WP Role. Something like: array(
48
-     *                                                                                    'administrator'    => array(
49
-     *                                                                                    'read_cap', 'edit_cap',
50
-     *                                                                                    'delete_cap'),
51
-     *                                                                                    'author'                =>
52
-     *                                                                                    array( 'read_cap' )
53
-     *                                                                                    ).
54
-     * @type array   $capability_maps                                                     EE_Meta_Capability_Map[]
55
-     * @see   EE_Capabilities.php for php docs on these objects.
56
-     *                                                                                    Should be indexed by the
57
-     *                                                                                    classname for the capability
58
-     *                                                                                    map and values representing
59
-     *                                                                                    the arguments for the map.
60
-     *                                                                                    }
61
-     * @throws EE_Error
62
-     * @return void
63
-     */
64
-    public static function register($cap_reference = null, $setup_args = array())
65
-    {
66
-        //required fields MUST be present, so let's make sure they are.
67
-        if ($cap_reference === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
68
-            throw new EE_Error(
69
-                __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
70
-                    'event_espresso')
71
-            );
72
-        }
73
-        //make sure we don't register twice
74
-        if (isset(self::$_registry[$cap_reference])) {
75
-            return;
76
-        }
77
-        //make sure this is not registered too late or too early.
78
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
79
-            EE_Error::doing_it_wrong(__METHOD__,
80
-                sprintf(__('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
81
-                    'event_espresso'), $cap_reference), '4.5.0');
82
-        }
83
-        //some preliminary sanitization and setting to the $_registry property
84
-        self::$_registry[ $cap_reference ] = array(
85
-            'caps'               => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
86
-                ? $setup_args['capabilities']
87
-                : array(),
88
-            'cap_maps'           => isset($setup_args['capability_maps'])
89
-                ? $setup_args['capability_maps']
90
-                : array(),
91
-        );
92
-        //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
93
-        add_filter(
94
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
95
-            array('EE_Register_Capabilities', 'register_capabilities')
96
-        );
97
-        //add filter for cap maps
98
-        add_filter(
99
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
100
-            array('EE_Register_Capabilities', 'register_cap_maps')
101
-        );
102
-    }
35
+	/**
36
+	 * Used to register capability items with EE core.
37
+	 *
38
+	 * @since 4.5.0
39
+	 * @param string $cap_reference                                                       usually will be a class name
40
+	 *                                                                                    that references capability
41
+	 *                                                                                    related items setup for
42
+	 *                                                                                    something.
43
+	 * @param array  $setup_args                                                          {
44
+	 *                                                                                    An array of items related to
45
+	 *                                                                                    registering capabilities.
46
+	 * @type array   $capabilities                                                        An array mapping capability
47
+	 *       strings to core WP Role. Something like: array(
48
+	 *                                                                                    'administrator'    => array(
49
+	 *                                                                                    'read_cap', 'edit_cap',
50
+	 *                                                                                    'delete_cap'),
51
+	 *                                                                                    'author'                =>
52
+	 *                                                                                    array( 'read_cap' )
53
+	 *                                                                                    ).
54
+	 * @type array   $capability_maps                                                     EE_Meta_Capability_Map[]
55
+	 * @see   EE_Capabilities.php for php docs on these objects.
56
+	 *                                                                                    Should be indexed by the
57
+	 *                                                                                    classname for the capability
58
+	 *                                                                                    map and values representing
59
+	 *                                                                                    the arguments for the map.
60
+	 *                                                                                    }
61
+	 * @throws EE_Error
62
+	 * @return void
63
+	 */
64
+	public static function register($cap_reference = null, $setup_args = array())
65
+	{
66
+		//required fields MUST be present, so let's make sure they are.
67
+		if ($cap_reference === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) {
68
+			throw new EE_Error(
69
+				__('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".',
70
+					'event_espresso')
71
+			);
72
+		}
73
+		//make sure we don't register twice
74
+		if (isset(self::$_registry[$cap_reference])) {
75
+			return;
76
+		}
77
+		//make sure this is not registered too late or too early.
78
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
79
+			EE_Error::doing_it_wrong(__METHOD__,
80
+				sprintf(__('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
81
+					'event_espresso'), $cap_reference), '4.5.0');
82
+		}
83
+		//some preliminary sanitization and setting to the $_registry property
84
+		self::$_registry[ $cap_reference ] = array(
85
+			'caps'               => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
86
+				? $setup_args['capabilities']
87
+				: array(),
88
+			'cap_maps'           => isset($setup_args['capability_maps'])
89
+				? $setup_args['capability_maps']
90
+				: array(),
91
+		);
92
+		//set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once)
93
+		add_filter(
94
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
95
+			array('EE_Register_Capabilities', 'register_capabilities')
96
+		);
97
+		//add filter for cap maps
98
+		add_filter(
99
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
100
+			array('EE_Register_Capabilities', 'register_cap_maps')
101
+		);
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter.
107
-     * Takes care of registering additional capabilities to the caps map.   Note, that this also on the initial
108
-     * registration ensures that new capabilities are added to existing roles.
109
-     *
110
-     * @param array $incoming_caps The original caps map.
111
-     * @return array merged in new caps.
112
-     */
113
-    public static function register_capabilities($incoming_caps)
114
-    {
115
-        foreach (self::$_registry as $cap_reference => $caps_and_cap_map) {
116
-            $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
117
-        }
118
-        return $incoming_caps;
119
-    }
105
+	/**
106
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter.
107
+	 * Takes care of registering additional capabilities to the caps map.   Note, that this also on the initial
108
+	 * registration ensures that new capabilities are added to existing roles.
109
+	 *
110
+	 * @param array $incoming_caps The original caps map.
111
+	 * @return array merged in new caps.
112
+	 */
113
+	public static function register_capabilities($incoming_caps)
114
+	{
115
+		foreach (self::$_registry as $cap_reference => $caps_and_cap_map) {
116
+			$incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']);
117
+		}
118
+		return $incoming_caps;
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of
124
-     * capability maps for the WP meta_caps filter called in EE_Capabilities.
125
-     *
126
-     * @since 4.5.0
127
-     * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array.
128
-     * @return EE_Meta_Capability_Map[]
129
-     * @throws EE_Error
130
-     */
131
-    public static function register_cap_maps($cap_maps)
132
-    {
133
-        //loop through and instantiate cap maps.
134
-        foreach (self::$_registry as $cap_reference => $setup) {
135
-            if (! isset($setup['cap_maps'])) {
136
-                continue;
137
-            }
138
-            foreach ($setup['cap_maps'] as $cap_class => $args) {
122
+	/**
123
+	 * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of
124
+	 * capability maps for the WP meta_caps filter called in EE_Capabilities.
125
+	 *
126
+	 * @since 4.5.0
127
+	 * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array.
128
+	 * @return EE_Meta_Capability_Map[]
129
+	 * @throws EE_Error
130
+	 */
131
+	public static function register_cap_maps($cap_maps)
132
+	{
133
+		//loop through and instantiate cap maps.
134
+		foreach (self::$_registry as $cap_reference => $setup) {
135
+			if (! isset($setup['cap_maps'])) {
136
+				continue;
137
+			}
138
+			foreach ($setup['cap_maps'] as $cap_class => $args) {
139 139
 
140
-                /**
141
-                 * account for cases where capability maps may be indexed
142
-                 * numerically to allow for the same map class to be utilized
143
-                 * In those cases, maps will be setup in an array like:
144
-                 * array(
145
-                 *    0 => array( 'EE_Meta_Capability' => array(
146
-                 *        'ee_edit_cap', array( 'Object_Name',
147
-                 *        'ee_edit_published_cap',
148
-                 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
149
-                 *        ) )
150
-                 *    1 => ...
151
-                 * )
152
-                 * instead of:
153
-                 * array(
154
-                 *    'EE_Meta_Capability' => array(
155
-                 *        'ee_edit_cap', array( 'Object_Name',
156
-                 *        'ee_edit_published_cap',
157
-                 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
158
-                 *        ),
159
-                 *    ...
160
-                 * )
161
-                 */
162
-                if (is_numeric($cap_class)) {
163
-                    $cap_class = key($args);
164
-                    $args      = $args[$cap_class];
165
-                }
140
+				/**
141
+				 * account for cases where capability maps may be indexed
142
+				 * numerically to allow for the same map class to be utilized
143
+				 * In those cases, maps will be setup in an array like:
144
+				 * array(
145
+				 *    0 => array( 'EE_Meta_Capability' => array(
146
+				 *        'ee_edit_cap', array( 'Object_Name',
147
+				 *        'ee_edit_published_cap',
148
+				 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
149
+				 *        ) )
150
+				 *    1 => ...
151
+				 * )
152
+				 * instead of:
153
+				 * array(
154
+				 *    'EE_Meta_Capability' => array(
155
+				 *        'ee_edit_cap', array( 'Object_Name',
156
+				 *        'ee_edit_published_cap',
157
+				 *        'ee_edit_others_cap', 'ee_edit_private_cap' )
158
+				 *        ),
159
+				 *    ...
160
+				 * )
161
+				 */
162
+				if (is_numeric($cap_class)) {
163
+					$cap_class = key($args);
164
+					$args      = $args[$cap_class];
165
+				}
166 166
 
167
-                if (! class_exists($cap_class)) {
168
-                    throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
169
-                        'event_espresso'), $cap_reference));
170
-                }
167
+				if (! class_exists($cap_class)) {
168
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
169
+						'event_espresso'), $cap_reference));
170
+				}
171 171
 
172
-                if (count($args) !== 2) {
173
-                    throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.',
174
-                        'event_espresso'), $cap_reference));
175
-                }
176
-                $cap_maps[] = new $cap_class($args[0], $args[1]);
177
-            }
178
-        }
179
-        return $cap_maps;
180
-    }
172
+				if (count($args) !== 2) {
173
+					throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments.  The array should have two values the first being a string and the second an array.',
174
+						'event_espresso'), $cap_reference));
175
+				}
176
+				$cap_maps[] = new $cap_class($args[0], $args[1]);
177
+			}
178
+		}
179
+		return $cap_maps;
180
+	}
181 181
 
182 182
 
183
-    /**
184
-     * @param string $cap_reference
185
-     * @throws EE_Error
186
-     * @throws \InvalidArgumentException
187
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
188
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
189
-     */
190
-    public static function deregister($cap_reference = '')
191
-    {
192
-        if (! empty(self::$_registry[$cap_reference])) {
193
-            if (! empty(self::$_registry[ $cap_reference ]['caps'])) {
194
-                //if it's too early to remove capabilities, wait to do this until core is loaded and ready
195
-                $caps_to_remove = self::$_registry[ $cap_reference ]['caps'];
196
-                if (did_action('AHEE__EE_System__core_loaded_and_ready')) {
197
-                    $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
198
-                    $capabilities->removeCaps($caps_to_remove);
199
-                } else {
200
-                    add_action(
201
-                        'AHEE__EE_System__core_loaded_and_ready',
202
-                        function () use ($caps_to_remove) {
203
-                            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
204
-                            $capabilities->removeCaps($caps_to_remove);
205
-                        }
206
-                    );
207
-                }
208
-            }
209
-            unset(self::$_registry[$cap_reference]);
210
-        }
211
-    }
183
+	/**
184
+	 * @param string $cap_reference
185
+	 * @throws EE_Error
186
+	 * @throws \InvalidArgumentException
187
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
188
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
189
+	 */
190
+	public static function deregister($cap_reference = '')
191
+	{
192
+		if (! empty(self::$_registry[$cap_reference])) {
193
+			if (! empty(self::$_registry[ $cap_reference ]['caps'])) {
194
+				//if it's too early to remove capabilities, wait to do this until core is loaded and ready
195
+				$caps_to_remove = self::$_registry[ $cap_reference ]['caps'];
196
+				if (did_action('AHEE__EE_System__core_loaded_and_ready')) {
197
+					$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
198
+					$capabilities->removeCaps($caps_to_remove);
199
+				} else {
200
+					add_action(
201
+						'AHEE__EE_System__core_loaded_and_ready',
202
+						function () use ($caps_to_remove) {
203
+							$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
204
+							$capabilities->removeCaps($caps_to_remove);
205
+						}
206
+					);
207
+				}
208
+			}
209
+			unset(self::$_registry[$cap_reference]);
210
+		}
211
+	}
212 212
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 use EventEspresso\core\services\loaders\LoaderFactory;
11 11
 
12
-if (! defined('EVENT_ESPRESSO_VERSION')) {
12
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
13 13
     exit('No direct script access allowed');
14 14
 }
15 15
 
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
             return;
76 76
         }
77 77
         //make sure this is not registered too late or too early.
78
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
78
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) {
79 79
             EE_Error::doing_it_wrong(__METHOD__,
80 80
                 sprintf(__('%s has been registered too late.  Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.',
81 81
                     'event_espresso'), $cap_reference), '4.5.0');
82 82
         }
83 83
         //some preliminary sanitization and setting to the $_registry property
84
-        self::$_registry[ $cap_reference ] = array(
84
+        self::$_registry[$cap_reference] = array(
85 85
             'caps'               => isset($setup_args['capabilities']) && is_array($setup_args['capabilities'])
86 86
                 ? $setup_args['capabilities']
87 87
                 : array(),
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     {
133 133
         //loop through and instantiate cap maps.
134 134
         foreach (self::$_registry as $cap_reference => $setup) {
135
-            if (! isset($setup['cap_maps'])) {
135
+            if ( ! isset($setup['cap_maps'])) {
136 136
                 continue;
137 137
             }
138 138
             foreach ($setup['cap_maps'] as $cap_class => $args) {
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                     $args      = $args[$cap_class];
165 165
                 }
166 166
 
167
-                if (! class_exists($cap_class)) {
167
+                if ( ! class_exists($cap_class)) {
168 168
                     throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly.  Capability map arrays must be indexed by capability map classname, and an array for the class arguments',
169 169
                         'event_espresso'), $cap_reference));
170 170
                 }
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public static function deregister($cap_reference = '')
191 191
     {
192
-        if (! empty(self::$_registry[$cap_reference])) {
193
-            if (! empty(self::$_registry[ $cap_reference ]['caps'])) {
192
+        if ( ! empty(self::$_registry[$cap_reference])) {
193
+            if ( ! empty(self::$_registry[$cap_reference]['caps'])) {
194 194
                 //if it's too early to remove capabilities, wait to do this until core is loaded and ready
195
-                $caps_to_remove = self::$_registry[ $cap_reference ]['caps'];
195
+                $caps_to_remove = self::$_registry[$cap_reference]['caps'];
196 196
                 if (did_action('AHEE__EE_System__core_loaded_and_ready')) {
197 197
                     $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
198 198
                     $capabilities->removeCaps($caps_to_remove);
199 199
                 } else {
200 200
                     add_action(
201 201
                         'AHEE__EE_System__core_loaded_and_ready',
202
-                        function () use ($caps_to_remove) {
202
+                        function() use ($caps_to_remove) {
203 203
                             $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
204 204
                             $capabilities->removeCaps($caps_to_remove);
205 205
                         }
Please login to merge, or discard this patch.
core/db_classes/EE_Question.class.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 		$new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) );
446 446
 		$new_question->set_system_ID( null );
447 447
 		$new_question->set_wp_user( get_current_user_id() );
448
-                //if we're duplicating a trashed question, assume we don't want the new one to be trashed
449
-                $new_question->set_deleted( false );
448
+				//if we're duplicating a trashed question, assume we don't want the new one to be trashed
449
+				$new_question->set_deleted( false );
450 450
 		$success = $new_question->save();
451 451
 		if( $success ) {
452 452
 			//we don't totally want to duplicate the question options, because we want them to be for the NEW question
@@ -501,8 +501,8 @@  discard block
 block discarded – undo
501 501
 		}
502 502
 		// has this question been answered ?
503 503
 		if ( $answer instanceof EE_Answer
504
-             && $answer->value() !== ''
505
-        ) {
504
+			 && $answer->value() !== ''
505
+		) {
506 506
 			//answer gets htmlspecialchars called on it, undo that please
507 507
 			//because the form input's display strategy may call esc_attr too
508 508
 			//which also does html special characters
@@ -516,10 +516,10 @@  discard block
 block discarded – undo
516 516
 		}
517 517
 		$max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() );
518 518
 		if( in_array(
519
-		    $this->type(),
520
-            EEM_Question::instance()->questionTypesWithMaxLength(),
521
-            true
522
-        ) ) {
519
+			$this->type(),
520
+			EEM_Question::instance()->questionTypesWithMaxLength(),
521
+			true
522
+		) ) {
523 523
 			$input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy(
524 524
 				null,
525 525
 				min( $max_max_for_question, $this->max() )
@@ -632,17 +632,17 @@  discard block
 block discarded – undo
632 632
 
633 633
 
634 634
 
635
-    /**
636
-     * Returns whether or not this question type should have question option entries
637
-     * @return bool
638
-     */
635
+	/**
636
+	 * Returns whether or not this question type should have question option entries
637
+	 * @return bool
638
+	 */
639 639
 	public function should_have_question_options()
640
-    {
641
-        return in_array(
642
-            $this->type(),
643
-            $this->_model->question_types_with_options(),
644
-            true
645
-        );
646
-    }
640
+	{
641
+		return in_array(
642
+			$this->type(),
643
+			$this->_model->question_types_with_options(),
644
+			true
645
+		);
646
+	}
647 647
 
648 648
 }
Please login to merge, or discard this patch.
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 *                             		    date_format and the second value is the time format
38 38
 	 * @return EE_Question
39 39
 	 */
40
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
41
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
42
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
40
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
41
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
42
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
43 43
 	}
44 44
 
45 45
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 *                          		the website will be used.
51 51
 	 * @return EE_Question
52 52
 	 */
53
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
54
-		return new self( $props_n_values, TRUE, $timezone );
53
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
54
+		return new self($props_n_values, TRUE, $timezone);
55 55
 	}
56 56
 
57 57
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @access        public
63 63
 	 * @param string $QST_display_text
64 64
 	 */
65
-	public function set_display_text( $QST_display_text = '' ) {
66
-		$this->set( 'QST_display_text', $QST_display_text );
65
+	public function set_display_text($QST_display_text = '') {
66
+		$this->set('QST_display_text', $QST_display_text);
67 67
 	}
68 68
 
69 69
 
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @access        public
75 75
 	 * @param        string $QST_admin_label
76 76
 	 */
77
-	public function set_admin_label( $QST_admin_label = '' ) {
78
-		$this->set( 'QST_admin_label', $QST_admin_label );
77
+	public function set_admin_label($QST_admin_label = '') {
78
+		$this->set('QST_admin_label', $QST_admin_label);
79 79
 	}
80 80
 
81 81
 
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @access        public
87 87
 	 * @param        mixed $QST_system
88 88
 	 */
89
-	public function set_system_ID( $QST_system = '' ) {
90
-		$this->set( 'QST_system', $QST_system );
89
+	public function set_system_ID($QST_system = '') {
90
+		$this->set('QST_system', $QST_system);
91 91
 	}
92 92
 
93 93
 
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 * @access        public
99 99
 	 * @param        string $QST_type
100 100
 	 */
101
-	public function set_question_type( $QST_type = '' ) {
102
-		$this->set( 'QST_type', $QST_type );
101
+	public function set_question_type($QST_type = '') {
102
+		$this->set('QST_type', $QST_type);
103 103
 	}
104 104
 
105 105
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 * @access        public
111 111
 	 * @param        bool $QST_required
112 112
 	 */
113
-	public function set_required( $QST_required = FALSE ) {
114
-		$this->set( 'QST_required', $QST_required );
113
+	public function set_required($QST_required = FALSE) {
114
+		$this->set('QST_required', $QST_required);
115 115
 	}
116 116
 
117 117
 
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 	 * @access        public
123 123
 	 * @param        string $QST_required_text
124 124
 	 */
125
-	public function set_required_text( $QST_required_text = '' ) {
126
-		$this->set( 'QST_required_text', $QST_required_text );
125
+	public function set_required_text($QST_required_text = '') {
126
+		$this->set('QST_required_text', $QST_required_text);
127 127
 	}
128 128
 
129 129
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	 * @access        public
135 135
 	 * @param        int $QST_order
136 136
 	 */
137
-	public function set_order( $QST_order = 0 ) {
138
-		$this->set( 'QST_order', $QST_order );
137
+	public function set_order($QST_order = 0) {
138
+		$this->set('QST_order', $QST_order);
139 139
 	}
140 140
 
141 141
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 	 * @access        public
147 147
 	 * @param        bool $QST_admin_only
148 148
 	 */
149
-	public function set_admin_only( $QST_admin_only = FALSE ) {
150
-		$this->set( 'QST_admin_only', $QST_admin_only );
149
+	public function set_admin_only($QST_admin_only = FALSE) {
150
+		$this->set('QST_admin_only', $QST_admin_only);
151 151
 	}
152 152
 
153 153
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @access        public
159 159
 	 * @param        int $QST_wp_user
160 160
 	 */
161
-	public function set_wp_user( $QST_wp_user = 1 ) {
162
-		$this->set( 'QST_wp_user', $QST_wp_user );
161
+	public function set_wp_user($QST_wp_user = 1) {
162
+		$this->set('QST_wp_user', $QST_wp_user);
163 163
 	}
164 164
 
165 165
 
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * @access        public
176 176
 	 * @param 	bool $QST_deleted
177 177
 	 */
178
-	public function set_deleted( $QST_deleted = FALSE ) {
179
-		$this->set( 'QST_deleted', $QST_deleted );
178
+	public function set_deleted($QST_deleted = FALSE) {
179
+		$this->set('QST_deleted', $QST_deleted);
180 180
 	}
181 181
 
182 182
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @return string
188 188
 	 */
189 189
 	public function display_text() {
190
-		return $this->get( 'QST_display_text' );
190
+		return $this->get('QST_display_text');
191 191
 	}
192 192
 
193 193
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return string
199 199
 	 */
200 200
 	public function admin_label() {
201
-		return $this->get( 'QST_admin_label' );
201
+		return $this->get('QST_admin_label');
202 202
 	}
203 203
 
204 204
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @return string
210 210
 	 */
211 211
 	public function system_ID() {
212
-		return $this->get( 'QST_system' );
212
+		return $this->get('QST_system');
213 213
 	}
214 214
 
215 215
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * @return boolean
221 221
 	 */
222 222
 	public function required() {
223
-		return $this->get( 'QST_required' );
223
+		return $this->get('QST_required');
224 224
 	}
225 225
 
226 226
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 * @return string
233 233
 	 */
234 234
 	public function required_text() {
235
-		return $this->get( 'QST_required_text' );
235
+		return $this->get('QST_required_text');
236 236
 	}
237 237
 
238 238
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * @return string
244 244
 	 */
245 245
 	public function type() {
246
-		return $this->get( 'QST_type' );
246
+		return $this->get('QST_type');
247 247
 	}
248 248
 
249 249
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @return int
256 256
 	 */
257 257
 	public function order() {
258
-		return $this->get( 'QST_order' );
258
+		return $this->get('QST_order');
259 259
 	}
260 260
 
261 261
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return boolean
268 268
 	 */
269 269
 	public function admin_only() {
270
-		return $this->get( 'QST_admin_only' );
270
+		return $this->get('QST_admin_only');
271 271
 	}
272 272
 
273 273
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @return int
279 279
 	 */
280 280
 	public function wp_user() {
281
-		return $this->get( 'QST_wp_user' );
281
+		return $this->get('QST_wp_user');
282 282
 	}
283 283
 
284 284
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	 * @return boolean
290 290
 	 */
291 291
 	public function deleted() {
292
-		return $this->get( 'QST_deleted' );
292
+		return $this->get('QST_deleted');
293 293
 	}
294 294
 
295 295
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @return EE_Answer[]
300 300
 	 */
301 301
 	public function answers() {
302
-		return $this->get_many_related( 'Answer' );
302
+		return $this->get_many_related('Answer');
303 303
 	}
304 304
 
305 305
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @return boolean true = has answers, false = no answers.
310 310
 	 */
311 311
 	public function has_answers() {
312
-		return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE;
312
+		return $this->count_related('Answer') > 0 ? TRUE : FALSE;
313 313
 	}
314 314
 
315 315
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @return EE_Question_Group[]
320 320
 	 */
321 321
 	public function question_groups() {
322
-		return $this->get_many_related( 'Question_Group' );
322
+		return $this->get_many_related('Question_Group');
323 323
 	}
324 324
 
325 325
 
@@ -333,24 +333,24 @@  discard block
 block discarded – undo
333 333
 	 *                                                       whether it was trashed or not.
334 334
 	 * @return EE_Question_Option[]
335 335
 	 */
336
-	public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) {
337
-		if ( ! $this->ID() ) {
336
+	public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) {
337
+		if ( ! $this->ID()) {
338 338
 			return array();
339 339
 		}
340 340
 		$query_params = array();
341
-		if ( $selected_value_to_always_include ) {
342
-			if ( is_array( $selected_value_to_always_include ) ) {
343
-				$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include );
341
+		if ($selected_value_to_always_include) {
342
+			if (is_array($selected_value_to_always_include)) {
343
+				$query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include);
344 344
 			} else {
345
-				$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include;
345
+				$query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include;
346 346
 			}
347 347
 		}
348
-		if ( $notDeletedOptionsOnly ) {
349
-			$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE;
348
+		if ($notDeletedOptionsOnly) {
349
+			$query_params[0]['OR*options-query']['QSO_deleted'] = FALSE;
350 350
 		}
351 351
 		//order by QSO_order
352
-		$query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' );
353
-		return $this->get_many_related( 'Question_Option', $query_params );
352
+		$query_params['order_by'] = array('QSO_order' => 'ASC');
353
+		return $this->get_many_related('Question_Option', $query_params);
354 354
 	}
355 355
 
356 356
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 * @return \EE_Question_Option[]
361 361
 	 */
362 362
 	public function temp_options() {
363
-		return $this->_model_relations[ 'Question_Option' ];
363
+		return $this->_model_relations['Question_Option'];
364 364
 	}
365 365
 
366 366
 
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param EE_Question_Option $option
372 372
 	 * @return boolean success
373 373
 	 */
374
-	public function add_option( EE_Question_Option $option ) {
375
-		return $this->_add_relation_to( $option, 'Question_Option' );
374
+	public function add_option(EE_Question_Option $option) {
375
+		return $this->_add_relation_to($option, 'Question_Option');
376 376
 	}
377 377
 
378 378
 
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 	 * @param EE_Question_Option $option
383 383
 	 * @return boolean success
384 384
 	 */
385
-	public function add_temp_option( EE_Question_Option $option ) {
386
-		$this->_model_relations[ 'Question_Option' ][ ] = $option;
385
+	public function add_temp_option(EE_Question_Option $option) {
386
+		$this->_model_relations['Question_Option'][] = $option;
387 387
 		return TRUE;
388 388
 	}
389 389
 
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	 * @param EE_Question_Option $option
395 395
 	 * @return boolean success
396 396
 	 */
397
-	public function remove_option( EE_Question_Option $option ) {
398
-		return $this->_remove_relation_to( $option, 'Question_Option' );
397
+	public function remove_option(EE_Question_Option $option) {
398
+		return $this->_remove_relation_to($option, 'Question_Option');
399 399
 	}
400 400
 
401 401
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 * @return bool
405 405
 	 */
406 406
 	public function is_system_question() {
407
-		$system_ID = $this->get( 'QST_system' );
408
-		return ! empty( $system_ID ) ? TRUE : FALSE;
407
+		$system_ID = $this->get('QST_system');
408
+		return ! empty($system_ID) ? TRUE : FALSE;
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 */
419 419
 	public function set_order_to_latest() {
420 420
 		$latest_order = $this->get_model()->get_latest_question_order();
421
-		$latest_order ++;
422
-		$this->set( 'QST_order', $latest_order );
421
+		$latest_order++;
422
+		$this->set('QST_order', $latest_order);
423 423
 	}
424 424
 
425 425
 
@@ -438,20 +438,20 @@  discard block
 block discarded – undo
438 438
 	 * Duplicates this question and its question options
439 439
 	 * @return \EE_Question
440 440
 	 */
441
-	public function duplicate( $options = array() ) {
441
+	public function duplicate($options = array()) {
442 442
 		$new_question = clone $this;
443
-		$new_question->set( 'QST_ID', null );
444
-		$new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) );
445
-		$new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) );
446
-		$new_question->set_system_ID( null );
447
-		$new_question->set_wp_user( get_current_user_id() );
443
+		$new_question->set('QST_ID', null);
444
+		$new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text()));
445
+		$new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label()));
446
+		$new_question->set_system_ID(null);
447
+		$new_question->set_wp_user(get_current_user_id());
448 448
                 //if we're duplicating a trashed question, assume we don't want the new one to be trashed
449
-                $new_question->set_deleted( false );
449
+                $new_question->set_deleted(false);
450 450
 		$success = $new_question->save();
451
-		if( $success ) {
451
+		if ($success) {
452 452
 			//we don't totally want to duplicate the question options, because we want them to be for the NEW question
453
-			foreach( $this->options() as $question_option ) {
454
-				$question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) );
453
+			foreach ($this->options() as $question_option) {
454
+				$question_option->duplicate(array('QST_ID' => $new_question->ID()));
455 455
 			}
456 456
 			return $new_question;
457 457
 		} else {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 * @return int|float
465 465
 	 */
466 466
 	public function max() {
467
-		return $this->get( 'QST_max' );
467
+		return $this->get('QST_max');
468 468
 	}
469 469
 
470 470
 	/**
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
 	 * @param int|float $new_max
473 473
 	 * @return void
474 474
 	 */
475
-	public function set_max( $new_max ) {
476
-		$this->set( 'QST_max', $new_max );
475
+	public function set_max($new_max) {
476
+		$this->set('QST_max', $new_max);
477 477
 	}
478 478
 
479 479
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 	 * @param array $input_constructor_args
486 486
 	 * @return EE_Form_Input_Base
487 487
 	 */
488
-	public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) {
488
+	public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) {
489 489
 		$identifier = $this->is_system_question() ? $this->system_ID() : $this->ID();
490 490
 
491 491
 		$input_constructor_args = array_merge(
@@ -496,33 +496,33 @@  discard block
 block discarded – undo
496 496
 				),
497 497
 				$input_constructor_args
498 498
 			);
499
-		if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) {
500
-			$answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() );
499
+		if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) {
500
+			$answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID());
501 501
 		}
502 502
 		// has this question been answered ?
503
-		if ( $answer instanceof EE_Answer
503
+		if ($answer instanceof EE_Answer
504 504
              && $answer->value() !== ''
505 505
         ) {
506 506
 			//answer gets htmlspecialchars called on it, undo that please
507 507
 			//because the form input's display strategy may call esc_attr too
508 508
 			//which also does html special characters
509 509
 			$values_with_html_special_chars = $answer->value();
510
-			if( is_array( $values_with_html_special_chars ) ) {
511
-				$default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars );
510
+			if (is_array($values_with_html_special_chars)) {
511
+				$default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars);
512 512
 			} else {
513
-				$default_value = htmlspecialchars_decode( $values_with_html_special_chars );
513
+				$default_value = htmlspecialchars_decode($values_with_html_special_chars);
514 514
 			}
515 515
 			$input_constructor_args['default'] = $default_value;
516 516
 		}
517
-		$max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() );
518
-		if( in_array(
517
+		$max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID());
518
+		if (in_array(
519 519
 		    $this->type(),
520 520
             EEM_Question::instance()->questionTypesWithMaxLength(),
521 521
             true
522
-        ) ) {
523
-			$input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy(
522
+        )) {
523
+			$input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy(
524 524
 				null,
525
-				min( $max_max_for_question, $this->max() )
525
+				min($max_max_for_question, $this->max())
526 526
 			);
527 527
 		}
528 528
 		$input_constructor_args = apply_filters(
@@ -534,22 +534,22 @@  discard block
 block discarded – undo
534 534
 		);
535 535
 
536 536
 		$result = null;
537
-		switch ( $this->type() ) {
537
+		switch ($this->type()) {
538 538
 			// Text
539 539
 			case EEM_Question::QST_type_text :
540
-				$result = new EE_Text_Input( $input_constructor_args );
540
+				$result = new EE_Text_Input($input_constructor_args);
541 541
 				break;
542 542
 			// Textarea
543 543
 			case EEM_Question::QST_type_textarea :
544
-				$result = new EE_Text_Area_Input( $input_constructor_args );
544
+				$result = new EE_Text_Area_Input($input_constructor_args);
545 545
 				break;
546 546
 			// Radio Buttons
547 547
 			case EEM_Question::QST_type_radio :
548
-				$result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args );
548
+				$result = new EE_Radio_Button_Input($this->options(), $input_constructor_args);
549 549
 				break;
550 550
 			// Dropdown
551 551
 			case EEM_Question::QST_type_dropdown :
552
-				$result = new EE_Select_Input( $this->options(), $input_constructor_args );
552
+				$result = new EE_Select_Input($this->options(), $input_constructor_args);
553 553
 				break;
554 554
 			// State Dropdown
555 555
 			case EEM_Question::QST_type_state :
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 					$registration,
561 561
 					$answer
562 562
 				);				
563
-				$result = new EE_State_Select_Input( $state_options, $input_constructor_args );
563
+				$result = new EE_State_Select_Input($state_options, $input_constructor_args);
564 564
 				break;
565 565
 			// Country Dropdown
566 566
 			case EEM_Question::QST_type_country :
@@ -571,47 +571,47 @@  discard block
 block discarded – undo
571 571
 					$registration,
572 572
 					$answer
573 573
 				);
574
-				$result = new EE_Country_Select_Input( $country_options, $input_constructor_args );
574
+				$result = new EE_Country_Select_Input($country_options, $input_constructor_args);
575 575
 				break;
576 576
 			// Checkboxes
577 577
 			case EEM_Question::QST_type_checkbox :
578
-				$result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args );
578
+				$result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args);
579 579
 				break;
580 580
 			// Date
581 581
 			case EEM_Question::QST_type_date :
582
-				$result = new EE_Datepicker_Input( $input_constructor_args );
582
+				$result = new EE_Datepicker_Input($input_constructor_args);
583 583
 				break;
584 584
 			case EEM_Question::QST_type_html_textarea :
585
-				$input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy();
586
-				$result =  new EE_Text_Area_Input( $input_constructor_args );
587
-				$result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' );
585
+				$input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy();
586
+				$result = new EE_Text_Area_Input($input_constructor_args);
587
+				$result->remove_validation_strategy('EE_Plaintext_Validation_Strategy');
588 588
 				break;
589 589
 			case EEM_Question::QST_type_email :
590
-				$result = new EE_Email_Input( $input_constructor_args );
590
+				$result = new EE_Email_Input($input_constructor_args);
591 591
 				break;
592 592
 			case EEM_Question::QST_type_us_phone :
593
-				$result = new EE_Phone_Input( $input_constructor_args );
593
+				$result = new EE_Phone_Input($input_constructor_args);
594 594
 				break;
595 595
 			case EEM_Question::QST_type_int :
596
-				$result = new EE_Integer_Input( $input_constructor_args );
596
+				$result = new EE_Integer_Input($input_constructor_args);
597 597
 				break;
598 598
 			case EEM_Question::QST_type_decimal :
599
-				$result = new EE_Float_Input( $input_constructor_args );
599
+				$result = new EE_Float_Input($input_constructor_args);
600 600
 				break;
601 601
 			case EEM_Question::QST_type_url :
602
-				$input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy();
603
-				$result = new EE_Text_Input( $input_constructor_args );
602
+				$input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy();
603
+				$result = new EE_Text_Input($input_constructor_args);
604 604
 				break;
605 605
 			case EEM_Question::QST_type_year :
606 606
 				$result = new EE_Year_Input(
607 607
 						$input_constructor_args,
608
-						apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ),
609
-						apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ),
610
-						apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this )
608
+						apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this),
609
+						apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this),
610
+						apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this)
611 611
 						);
612 612
 				break;
613 613
 			case EEM_Question::QST_type_multi_select :
614
-				$result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args );
614
+				$result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args);
615 615
 				break;
616 616
 			// fallback
617 617
 			default :
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 					$this,
623 623
 					$input_constructor_args
624 624
 				);
625
-				if( ! $default_input ){
626
-					$default_input = new EE_Text_Input( $input_constructor_args );
625
+				if ( ! $default_input) {
626
+					$default_input = new EE_Text_Input($input_constructor_args);
627 627
 				}
628 628
 				$result = $default_input;
629 629
 		}
630
-		return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer );
630
+		return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer);
631 631
 	}
632 632
 
633 633
 
Please login to merge, or discard this patch.
core/db_models/EEM_Question.model.php 2 patches
Indentation   +426 added lines, -426 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php');
5 5
 require_once(EE_CLASSES . 'EE_Question.class.php');
@@ -16,431 +16,431 @@  discard block
 block discarded – undo
16 16
 class EEM_Question extends EEM_Soft_Delete_Base
17 17
 {
18 18
 
19
-    // constant used to indicate that the question type is COUNTRY
20
-    const QST_type_country = 'COUNTRY';
21
-
22
-    // constant used to indicate that the question type is DATE
23
-    const QST_type_date = 'DATE';
24
-
25
-    // constant used to indicate that the question type is DROPDOWN
26
-    const QST_type_dropdown = 'DROPDOWN';
27
-
28
-    // constant used to indicate that the question type is CHECKBOX
29
-    const QST_type_checkbox = 'CHECKBOX';
30
-
31
-    // constant used to indicate that the question type is RADIO_BTN
32
-    const QST_type_radio = 'RADIO_BTN';
33
-
34
-    // constant used to indicate that the question type is STATE
35
-    const QST_type_state = 'STATE';
36
-
37
-    // constant used to indicate that the question type is TEXT
38
-    const QST_type_text = 'TEXT';
39
-
40
-    // constant used to indicate that the question type is TEXTAREA
41
-    const QST_type_textarea = 'TEXTAREA';
42
-
43
-    // constant used to indicate that the question type is a TEXTAREA that allows simple html
44
-    const QST_type_html_textarea = 'HTML_TEXTAREA';
45
-
46
-    // constant used to indicate that the question type is an email input
47
-    const QST_type_email = 'EMAIL';
48
-
49
-    // constant used to indicate that the question type is a US-formatted phone number
50
-    const QST_type_us_phone = 'US_PHONE';
51
-
52
-    // constant used to indicate that the question type is an integer (whole number)
53
-    const QST_type_int = 'INTEGER';
54
-
55
-    // constant used to indicate that the question type is a decimal (float)
56
-    const QST_type_decimal = 'DECIMAL';
57
-
58
-    // constant used to indicate that the question type is a valid URL
59
-    const QST_type_url = 'URL';
60
-
61
-    // constant used to indicate that the question type is a YEAR
62
-    const QST_type_year = 'YEAR';
63
-
64
-    // constant used to indicate that the question type is a multi-select
65
-    const QST_type_multi_select = 'MULTI_SELECT';
66
-
67
-    /**
68
-     * Question types that are interchangeable, even after answers have been provided for them.
69
-     * Top-level keys are category slugs, next level is an array of question types. If question types
70
-     * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
71
-     *
72
-     * @access protected
73
-     * @var array $_question_type_categories {
74
-     * @type string $text
75
-     * @type string $single -answer-enum
76
-     * @type string $multi -answer-enum
77
-     *                    }
78
-     */
79
-    protected $_question_type_categories = array();
80
-
81
-    /**
82
-     * lists all the question types which should be allowed. Ideally, this will be extensible.
83
-     *
84
-     * @access protected
85
-     * @var array $_allowed_question_types
86
-     */
87
-    protected $_allowed_question_types = array();
88
-
89
-    /**
90
-     * brief descriptions for all the question types
91
-     *
92
-     * @access protected
93
-     * @var EEM_Question $_instance
94
-     */
95
-    protected $_question_descriptions;
96
-
97
-
98
-    /**
99
-     * Question types that should have an admin-defined max input length
100
-     * @var array
101
-     */
102
-    protected $question_types_with_max_lengh;
103
-
104
-
105
-    // private instance of the Attendee object
106
-    protected static $_instance = NULL;
107
-
108
-
109
-    /**
110
-     * EEM_Question constructor.
111
-     *
112
-     * @param null $timezone
113
-     */
114
-    protected function __construct($timezone = NULL)
115
-    {
116
-        $this->singular_item = __('Question', 'event_espresso');
117
-        $this->plural_item = __('Questions', 'event_espresso');
118
-        $this->_allowed_question_types = apply_filters(
119
-            'FHEE__EEM_Question__construct__allowed_question_types',
120
-            array(
121
-                EEM_Question::QST_type_text => __('Text', 'event_espresso'),
122
-                EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'),
123
-                EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'),
124
-                EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'),
125
-                EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'),
126
-                EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'),
127
-                EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'),
128
-                EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'),
129
-                EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'),
130
-                EEM_Question::QST_type_email => __('Email', 'event_espresso'),
131
-                EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'),
132
-                EEM_Question::QST_type_decimal => __('Number', 'event_espresso'),
133
-                EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'),
134
-                EEM_Question::QST_type_url => __('URL', 'event_espresso'),
135
-                EEM_Question::QST_type_year => __('Year', 'event_espresso'),
136
-                EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso')
137
-            )
138
-        );
139
-        $this->_question_descriptions = apply_filters(
140
-            'FHEE__EEM_Question__construct__allowed_question_types',
141
-            array(
142
-                EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'),
143
-                EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'),
144
-                EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'),
145
-                EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'),
146
-                EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'),
147
-                EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'),
148
-                EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'),
149
-                EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'),
150
-                EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'),
151
-                EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'),
152
-                EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'),
153
-                EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'),
154
-                EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'),
155
-                EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'),
156
-                EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'),
157
-                EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso')
158
-            )
159
-        );
160
-        $this->_question_type_categories = (array)apply_filters(
161
-            'FHEE__EEM_Question__construct__question_type_categories',
162
-            array(
163
-                'text' => array(
164
-                    EEM_Question::QST_type_text,
165
-                    EEM_Question::QST_type_textarea,
166
-                    EEM_Question::QST_type_date,
167
-                    EEM_Question::QST_type_html_textarea,
168
-                    EEM_Question::QST_type_email,
169
-                    EEM_Question::QST_type_us_phone,
170
-                    EEM_Question::QST_type_decimal,
171
-                    EEM_Question::QST_type_int,
172
-                    EEM_Question::QST_type_url,
173
-                    EEM_Question::QST_type_year
174
-                ),
175
-                'single-answer-enum' => array(
176
-                    EEM_Question::QST_type_radio,
177
-                    EEM_Question::QST_type_dropdown
178
-                ),
179
-                'multi-answer-enum' => array(
180
-                    EEM_Question::QST_type_checkbox,
181
-                    EEM_Question::QST_type_multi_select
182
-                )
183
-            )
184
-        );
185
-        $this->question_types_with_max_lengh = apply_filters(
186
-            'FHEE__EEM_Question___construct__question_types_with_max_length',
187
-            array(
188
-                EEM_Question::QST_type_text,
189
-                EEM_Question::QST_type_textarea,
190
-                EEM_Question::QST_type_html_textarea
191
-            )
192
-        );
193
-
194
-        $this->_tables = array(
195
-            'Question' => new EE_Primary_Table('esp_question', 'QST_ID')
196
-        );
197
-        $this->_fields = array(
198
-            'Question' => array(
199
-                'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')),
200
-                'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''),
201
-                'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''),
202
-                'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''),
203
-                'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types),
204
-                'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false),
205
-                'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''),
206
-                'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0),
207
-                'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false),
208
-                'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF),
209
-                'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false),
210
-                'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false)
211
-            )
212
-        );
213
-        $this->_model_relations = array(
214
-            'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'),
215
-            'Question_Option' => new EE_Has_Many_Relation(),
216
-            'Answer' => new EE_Has_Many_Relation(),
217
-            'WP_User' => new EE_Belongs_To_Relation(),
218
-            //for QST_order column
219
-            'Question_Group_Question' => new EE_Has_Many_Relation()
220
-        );
221
-        //this model is generally available for reading
222
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
223
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system');
224
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system');
225
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system');
226
-        parent::__construct($timezone);
227
-    }
228
-
229
-    /**
230
-     * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE'
231
-     * but they can be extended
232
-     * @return string[]
233
-     */
234
-    public function allowed_question_types()
235
-    {
236
-        return $this->_allowed_question_types;
237
-    }
238
-
239
-    /**
240
-     * Gets all the question types in the same category
241
-     * @param string $question_type one of EEM_Question::allowed_question_types(
242
-     * @return string[] like EEM_Question::allowed_question_types()
243
-     */
244
-    public function question_types_in_same_category($question_type)
245
-    {
246
-        $question_types = array($question_type);
247
-        foreach ($this->_question_type_categories as $category => $question_types_in_category) {
248
-            if (in_array($question_type, $question_types_in_category)) {
249
-                $question_types = $question_types_in_category;
250
-                break;
251
-            }
252
-        }
253
-
254
-        return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
255
-    }
256
-
257
-    /**
258
-     * Determines if the given question type is in the given question type category
259
-     * @param string $question_type one of EEM_Question::allowed_question_types()
260
-     * @param string $category one of the top-level keys of EEM_Question::question_type_categories()
261
-     * @return boolean
262
-     */
263
-    public function question_type_is_in_category($question_type, $category)
264
-    {
265
-        if (!isset($this->_question_type_categories[$category])) {
266
-            return false;
267
-        }
268
-        return in_array($question_type, $this->_question_type_categories[$category]);
269
-    }
270
-
271
-
272
-    /**
273
-     * Returns all the question types in the given category
274
-     * @param string $category
275
-     * @return array|mixed
276
-     */
277
-    public function question_types_in_category($category)
278
-    {
279
-        if (isset($this->_question_type_categories[$category])) {
280
-            return $this->_question_type_categories[$category];
281
-        }
282
-        return array();
283
-    }
284
-
285
-
286
-    /**
287
-     * Returns all the question types that should have question options
288
-     * @return array
289
-     */
290
-    public function question_types_with_options()
291
-    {
292
-        return array_merge(
293
-            $this->question_types_in_category('single-answer-enum'),
294
-            $this->question_types_in_category('multi-answer-enum')
295
-        );
296
-    }
297
-
298
-    /**
299
-     * Returns the question type categories 2d array
300
-     * @return array see EEM_Question::_question_type_categories
301
-     */
302
-    public function question_type_categories()
303
-    {
304
-        return $this->_question_type_categories;
305
-    }
306
-
307
-    /**
308
-     * Returns an array of all the QST_system values that can be allowed in the system question group
309
-     * identified by $system_question_group_id
310
-     * @param string $system_question_group_id QSG_system
311
-     * @return array of system question names (QST_system)
312
-     */
313
-    public function allowed_system_questions_in_system_question_group($system_question_group_id)
314
-    {
315
-        $question_system_ids = array();
316
-        switch ($system_question_group_id) {
317
-            case EEM_Question_Group::system_personal:
318
-                $question_system_ids = array(
319
-                    EEM_Attendee::system_question_fname,
320
-                    EEM_Attendee::system_question_lname,
321
-                    EEM_Attendee::system_question_email,
322
-                    EEM_Attendee::system_question_phone
323
-                );
324
-                break;
325
-            case EEM_Question_Group::system_address:
326
-                $question_system_ids = array(
327
-                    EEM_Attendee::system_question_address,
328
-                    EEM_Attendee::system_question_address2,
329
-                    EEM_Attendee::system_question_city,
330
-                    EEM_Attendee::system_question_state,
331
-                    EEM_Attendee::system_question_country,
332
-                    EEM_Attendee::system_question_zip,
333
-                    EEM_Attendee::system_question_phone
334
-                );
335
-                break;
336
-        }
337
-        return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id);
338
-    }
339
-
340
-    /**
341
-     * Returns an array of all the QST_system values that are required in the system question group
342
-     * identified by $system_question_group_id
343
-     * @param string $system_question_group_id QSG_system
344
-     * @return array of system question names (QST_system)
345
-     */
346
-    public function required_system_questions_in_system_question_group($system_question_group_id)
347
-    {
348
-        $question_system_ids = null;
349
-        switch ($system_question_group_id) {
350
-            case EEM_Question_Group::system_personal:
351
-                $question_system_ids = array(
352
-                    EEM_Attendee::system_question_fname,
353
-                    EEM_Attendee::system_question_email,
354
-                );
355
-                break;
356
-            default:
357
-                $question_system_ids = array();
358
-        }
359
-        return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id);
360
-    }
361
-
362
-
363
-    /**
364
-     * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
365
-     * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
366
-     * @param $QST_system
367
-     * @return int of QST_ID for the question that corresponds to that QST_system
368
-     */
369
-    public function get_Question_ID_from_system_string($QST_system)
370
-    {
371
-        return $this->get_var(array(array('QST_system' => $QST_system)));
372
-    }
373
-
374
-
375
-    /**
376
-     * searches the db for the question with the latest question order and returns that value.
377
-     * @access public
378
-     * @return int
379
-     */
380
-    public function get_latest_question_order()
381
-    {
382
-        $columns_to_select = array(
383
-            'max_order' => array("MAX(QST_order)", "%d")
384
-        );
385
-        $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select);
386
-        return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
387
-    }
388
-
389
-    /**
390
-     * Returns an array where keys are system question QST_system values,
391
-     * and values are the highest question max the admin can set on the question
392
-     * (aka the "max max"; eg, a site admin can change the zip question to have a max
393
-     * of 5, but no larger than 12)
394
-     * @return array
395
-     */
396
-    public function system_question_maxes()
397
-    {
398
-        return array(
399
-            'fname' => 45,
400
-            'lname' => 45,
401
-            'address' => 255,
402
-            'address2' => 255,
403
-            'city' => 45,
404
-            'zip' => 12,
405
-            'email' => 255,
406
-            'phone' => 45,
407
-        );
408
-    }
409
-
410
-    /**
411
-     * Given a QST_system value, gets the question's largest allowable max input.
412
-     * @see Registration_Form_Admin_Page::system_question_maxes()
413
-     * @param string $system_question_value
414
-     * @return int|float
415
-     */
416
-    public function absolute_max_for_system_question($system_question_value)
417
-    {
418
-        $maxes = $this->system_question_maxes();
419
-        if (isset($maxes[$system_question_value])) {
420
-            return $maxes[$system_question_value];
421
-        } else {
422
-            return EE_INF;
423
-        }
424
-    }
425
-
426
-
427
-    /**
428
-     * @return array
429
-     */
430
-    public function question_descriptions()
431
-    {
432
-        return $this->_question_descriptions;
433
-    }
434
-
435
-
436
-    /**
437
-     * Returns all the question types that should have an admin-defined max input length
438
-     * @return array
439
-     */
440
-    public function questionTypesWithMaxLength()
441
-    {
442
-        return (array)$this->question_types_with_max_lengh;
443
-    }
19
+	// constant used to indicate that the question type is COUNTRY
20
+	const QST_type_country = 'COUNTRY';
21
+
22
+	// constant used to indicate that the question type is DATE
23
+	const QST_type_date = 'DATE';
24
+
25
+	// constant used to indicate that the question type is DROPDOWN
26
+	const QST_type_dropdown = 'DROPDOWN';
27
+
28
+	// constant used to indicate that the question type is CHECKBOX
29
+	const QST_type_checkbox = 'CHECKBOX';
30
+
31
+	// constant used to indicate that the question type is RADIO_BTN
32
+	const QST_type_radio = 'RADIO_BTN';
33
+
34
+	// constant used to indicate that the question type is STATE
35
+	const QST_type_state = 'STATE';
36
+
37
+	// constant used to indicate that the question type is TEXT
38
+	const QST_type_text = 'TEXT';
39
+
40
+	// constant used to indicate that the question type is TEXTAREA
41
+	const QST_type_textarea = 'TEXTAREA';
42
+
43
+	// constant used to indicate that the question type is a TEXTAREA that allows simple html
44
+	const QST_type_html_textarea = 'HTML_TEXTAREA';
45
+
46
+	// constant used to indicate that the question type is an email input
47
+	const QST_type_email = 'EMAIL';
48
+
49
+	// constant used to indicate that the question type is a US-formatted phone number
50
+	const QST_type_us_phone = 'US_PHONE';
51
+
52
+	// constant used to indicate that the question type is an integer (whole number)
53
+	const QST_type_int = 'INTEGER';
54
+
55
+	// constant used to indicate that the question type is a decimal (float)
56
+	const QST_type_decimal = 'DECIMAL';
57
+
58
+	// constant used to indicate that the question type is a valid URL
59
+	const QST_type_url = 'URL';
60
+
61
+	// constant used to indicate that the question type is a YEAR
62
+	const QST_type_year = 'YEAR';
63
+
64
+	// constant used to indicate that the question type is a multi-select
65
+	const QST_type_multi_select = 'MULTI_SELECT';
66
+
67
+	/**
68
+	 * Question types that are interchangeable, even after answers have been provided for them.
69
+	 * Top-level keys are category slugs, next level is an array of question types. If question types
70
+	 * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
71
+	 *
72
+	 * @access protected
73
+	 * @var array $_question_type_categories {
74
+	 * @type string $text
75
+	 * @type string $single -answer-enum
76
+	 * @type string $multi -answer-enum
77
+	 *                    }
78
+	 */
79
+	protected $_question_type_categories = array();
80
+
81
+	/**
82
+	 * lists all the question types which should be allowed. Ideally, this will be extensible.
83
+	 *
84
+	 * @access protected
85
+	 * @var array $_allowed_question_types
86
+	 */
87
+	protected $_allowed_question_types = array();
88
+
89
+	/**
90
+	 * brief descriptions for all the question types
91
+	 *
92
+	 * @access protected
93
+	 * @var EEM_Question $_instance
94
+	 */
95
+	protected $_question_descriptions;
96
+
97
+
98
+	/**
99
+	 * Question types that should have an admin-defined max input length
100
+	 * @var array
101
+	 */
102
+	protected $question_types_with_max_lengh;
103
+
104
+
105
+	// private instance of the Attendee object
106
+	protected static $_instance = NULL;
107
+
108
+
109
+	/**
110
+	 * EEM_Question constructor.
111
+	 *
112
+	 * @param null $timezone
113
+	 */
114
+	protected function __construct($timezone = NULL)
115
+	{
116
+		$this->singular_item = __('Question', 'event_espresso');
117
+		$this->plural_item = __('Questions', 'event_espresso');
118
+		$this->_allowed_question_types = apply_filters(
119
+			'FHEE__EEM_Question__construct__allowed_question_types',
120
+			array(
121
+				EEM_Question::QST_type_text => __('Text', 'event_espresso'),
122
+				EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'),
123
+				EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'),
124
+				EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'),
125
+				EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'),
126
+				EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'),
127
+				EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'),
128
+				EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'),
129
+				EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'),
130
+				EEM_Question::QST_type_email => __('Email', 'event_espresso'),
131
+				EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'),
132
+				EEM_Question::QST_type_decimal => __('Number', 'event_espresso'),
133
+				EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'),
134
+				EEM_Question::QST_type_url => __('URL', 'event_espresso'),
135
+				EEM_Question::QST_type_year => __('Year', 'event_espresso'),
136
+				EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso')
137
+			)
138
+		);
139
+		$this->_question_descriptions = apply_filters(
140
+			'FHEE__EEM_Question__construct__allowed_question_types',
141
+			array(
142
+				EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'),
143
+				EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'),
144
+				EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'),
145
+				EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'),
146
+				EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'),
147
+				EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'),
148
+				EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'),
149
+				EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'),
150
+				EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'),
151
+				EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'),
152
+				EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'),
153
+				EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'),
154
+				EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'),
155
+				EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'),
156
+				EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'),
157
+				EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso')
158
+			)
159
+		);
160
+		$this->_question_type_categories = (array)apply_filters(
161
+			'FHEE__EEM_Question__construct__question_type_categories',
162
+			array(
163
+				'text' => array(
164
+					EEM_Question::QST_type_text,
165
+					EEM_Question::QST_type_textarea,
166
+					EEM_Question::QST_type_date,
167
+					EEM_Question::QST_type_html_textarea,
168
+					EEM_Question::QST_type_email,
169
+					EEM_Question::QST_type_us_phone,
170
+					EEM_Question::QST_type_decimal,
171
+					EEM_Question::QST_type_int,
172
+					EEM_Question::QST_type_url,
173
+					EEM_Question::QST_type_year
174
+				),
175
+				'single-answer-enum' => array(
176
+					EEM_Question::QST_type_radio,
177
+					EEM_Question::QST_type_dropdown
178
+				),
179
+				'multi-answer-enum' => array(
180
+					EEM_Question::QST_type_checkbox,
181
+					EEM_Question::QST_type_multi_select
182
+				)
183
+			)
184
+		);
185
+		$this->question_types_with_max_lengh = apply_filters(
186
+			'FHEE__EEM_Question___construct__question_types_with_max_length',
187
+			array(
188
+				EEM_Question::QST_type_text,
189
+				EEM_Question::QST_type_textarea,
190
+				EEM_Question::QST_type_html_textarea
191
+			)
192
+		);
193
+
194
+		$this->_tables = array(
195
+			'Question' => new EE_Primary_Table('esp_question', 'QST_ID')
196
+		);
197
+		$this->_fields = array(
198
+			'Question' => array(
199
+				'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')),
200
+				'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''),
201
+				'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''),
202
+				'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''),
203
+				'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types),
204
+				'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false),
205
+				'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''),
206
+				'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0),
207
+				'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false),
208
+				'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF),
209
+				'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false),
210
+				'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false)
211
+			)
212
+		);
213
+		$this->_model_relations = array(
214
+			'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'),
215
+			'Question_Option' => new EE_Has_Many_Relation(),
216
+			'Answer' => new EE_Has_Many_Relation(),
217
+			'WP_User' => new EE_Belongs_To_Relation(),
218
+			//for QST_order column
219
+			'Question_Group_Question' => new EE_Has_Many_Relation()
220
+		);
221
+		//this model is generally available for reading
222
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
223
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system');
224
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system');
225
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system');
226
+		parent::__construct($timezone);
227
+	}
228
+
229
+	/**
230
+	 * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE'
231
+	 * but they can be extended
232
+	 * @return string[]
233
+	 */
234
+	public function allowed_question_types()
235
+	{
236
+		return $this->_allowed_question_types;
237
+	}
238
+
239
+	/**
240
+	 * Gets all the question types in the same category
241
+	 * @param string $question_type one of EEM_Question::allowed_question_types(
242
+	 * @return string[] like EEM_Question::allowed_question_types()
243
+	 */
244
+	public function question_types_in_same_category($question_type)
245
+	{
246
+		$question_types = array($question_type);
247
+		foreach ($this->_question_type_categories as $category => $question_types_in_category) {
248
+			if (in_array($question_type, $question_types_in_category)) {
249
+				$question_types = $question_types_in_category;
250
+				break;
251
+			}
252
+		}
253
+
254
+		return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
255
+	}
256
+
257
+	/**
258
+	 * Determines if the given question type is in the given question type category
259
+	 * @param string $question_type one of EEM_Question::allowed_question_types()
260
+	 * @param string $category one of the top-level keys of EEM_Question::question_type_categories()
261
+	 * @return boolean
262
+	 */
263
+	public function question_type_is_in_category($question_type, $category)
264
+	{
265
+		if (!isset($this->_question_type_categories[$category])) {
266
+			return false;
267
+		}
268
+		return in_array($question_type, $this->_question_type_categories[$category]);
269
+	}
270
+
271
+
272
+	/**
273
+	 * Returns all the question types in the given category
274
+	 * @param string $category
275
+	 * @return array|mixed
276
+	 */
277
+	public function question_types_in_category($category)
278
+	{
279
+		if (isset($this->_question_type_categories[$category])) {
280
+			return $this->_question_type_categories[$category];
281
+		}
282
+		return array();
283
+	}
284
+
285
+
286
+	/**
287
+	 * Returns all the question types that should have question options
288
+	 * @return array
289
+	 */
290
+	public function question_types_with_options()
291
+	{
292
+		return array_merge(
293
+			$this->question_types_in_category('single-answer-enum'),
294
+			$this->question_types_in_category('multi-answer-enum')
295
+		);
296
+	}
297
+
298
+	/**
299
+	 * Returns the question type categories 2d array
300
+	 * @return array see EEM_Question::_question_type_categories
301
+	 */
302
+	public function question_type_categories()
303
+	{
304
+		return $this->_question_type_categories;
305
+	}
306
+
307
+	/**
308
+	 * Returns an array of all the QST_system values that can be allowed in the system question group
309
+	 * identified by $system_question_group_id
310
+	 * @param string $system_question_group_id QSG_system
311
+	 * @return array of system question names (QST_system)
312
+	 */
313
+	public function allowed_system_questions_in_system_question_group($system_question_group_id)
314
+	{
315
+		$question_system_ids = array();
316
+		switch ($system_question_group_id) {
317
+			case EEM_Question_Group::system_personal:
318
+				$question_system_ids = array(
319
+					EEM_Attendee::system_question_fname,
320
+					EEM_Attendee::system_question_lname,
321
+					EEM_Attendee::system_question_email,
322
+					EEM_Attendee::system_question_phone
323
+				);
324
+				break;
325
+			case EEM_Question_Group::system_address:
326
+				$question_system_ids = array(
327
+					EEM_Attendee::system_question_address,
328
+					EEM_Attendee::system_question_address2,
329
+					EEM_Attendee::system_question_city,
330
+					EEM_Attendee::system_question_state,
331
+					EEM_Attendee::system_question_country,
332
+					EEM_Attendee::system_question_zip,
333
+					EEM_Attendee::system_question_phone
334
+				);
335
+				break;
336
+		}
337
+		return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id);
338
+	}
339
+
340
+	/**
341
+	 * Returns an array of all the QST_system values that are required in the system question group
342
+	 * identified by $system_question_group_id
343
+	 * @param string $system_question_group_id QSG_system
344
+	 * @return array of system question names (QST_system)
345
+	 */
346
+	public function required_system_questions_in_system_question_group($system_question_group_id)
347
+	{
348
+		$question_system_ids = null;
349
+		switch ($system_question_group_id) {
350
+			case EEM_Question_Group::system_personal:
351
+				$question_system_ids = array(
352
+					EEM_Attendee::system_question_fname,
353
+					EEM_Attendee::system_question_email,
354
+				);
355
+				break;
356
+			default:
357
+				$question_system_ids = array();
358
+		}
359
+		return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id);
360
+	}
361
+
362
+
363
+	/**
364
+	 * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
365
+	 * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
366
+	 * @param $QST_system
367
+	 * @return int of QST_ID for the question that corresponds to that QST_system
368
+	 */
369
+	public function get_Question_ID_from_system_string($QST_system)
370
+	{
371
+		return $this->get_var(array(array('QST_system' => $QST_system)));
372
+	}
373
+
374
+
375
+	/**
376
+	 * searches the db for the question with the latest question order and returns that value.
377
+	 * @access public
378
+	 * @return int
379
+	 */
380
+	public function get_latest_question_order()
381
+	{
382
+		$columns_to_select = array(
383
+			'max_order' => array("MAX(QST_order)", "%d")
384
+		);
385
+		$max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select);
386
+		return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
387
+	}
388
+
389
+	/**
390
+	 * Returns an array where keys are system question QST_system values,
391
+	 * and values are the highest question max the admin can set on the question
392
+	 * (aka the "max max"; eg, a site admin can change the zip question to have a max
393
+	 * of 5, but no larger than 12)
394
+	 * @return array
395
+	 */
396
+	public function system_question_maxes()
397
+	{
398
+		return array(
399
+			'fname' => 45,
400
+			'lname' => 45,
401
+			'address' => 255,
402
+			'address2' => 255,
403
+			'city' => 45,
404
+			'zip' => 12,
405
+			'email' => 255,
406
+			'phone' => 45,
407
+		);
408
+	}
409
+
410
+	/**
411
+	 * Given a QST_system value, gets the question's largest allowable max input.
412
+	 * @see Registration_Form_Admin_Page::system_question_maxes()
413
+	 * @param string $system_question_value
414
+	 * @return int|float
415
+	 */
416
+	public function absolute_max_for_system_question($system_question_value)
417
+	{
418
+		$maxes = $this->system_question_maxes();
419
+		if (isset($maxes[$system_question_value])) {
420
+			return $maxes[$system_question_value];
421
+		} else {
422
+			return EE_INF;
423
+		}
424
+	}
425
+
426
+
427
+	/**
428
+	 * @return array
429
+	 */
430
+	public function question_descriptions()
431
+	{
432
+		return $this->_question_descriptions;
433
+	}
434
+
435
+
436
+	/**
437
+	 * Returns all the question types that should have an admin-defined max input length
438
+	 * @return array
439
+	 */
440
+	public function questionTypesWithMaxLength()
441
+	{
442
+		return (array)$this->question_types_with_max_lengh;
443
+	}
444 444
 
445 445
 
446 446
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php');
5
-require_once(EE_CLASSES . 'EE_Question.class.php');
4
+require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php');
5
+require_once(EE_CLASSES.'EE_Question.class.php');
6 6
 
7 7
 
8 8
 /**
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                 EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso')
158 158
             )
159 159
         );
160
-        $this->_question_type_categories = (array)apply_filters(
160
+        $this->_question_type_categories = (array) apply_filters(
161 161
             'FHEE__EEM_Question__construct__question_type_categories',
162 162
             array(
163 163
                 'text' => array(
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      */
263 263
     public function question_type_is_in_category($question_type, $category)
264 264
     {
265
-        if (!isset($this->_question_type_categories[$category])) {
265
+        if ( ! isset($this->_question_type_categories[$category])) {
266 266
             return false;
267 267
         }
268 268
         return in_array($question_type, $this->_question_type_categories[$category]);
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
      */
440 440
     public function questionTypesWithMaxLength()
441 441
     {
442
-        return (array)$this->question_types_with_max_lengh;
442
+        return (array) $this->question_types_with_max_lengh;
443 443
     }
444 444
 
445 445
 
Please login to merge, or discard this patch.
admin_pages/registration_form/Registration_Form_Admin_Page.core.php 2 patches
Indentation   +665 added lines, -665 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -28,621 +28,621 @@  discard block
 block discarded – undo
28 28
 class Registration_Form_Admin_Page extends EE_Admin_Page
29 29
 {
30 30
 
31
-    /**
32
-     * _question
33
-     * holds the specific question object for the question details screen
34
-     *
35
-     * @var EE_Question $_question
36
-     */
37
-    protected $_question;
38
-
39
-    /**
40
-     * _question_group
41
-     * holds the specific question group object for the question group details screen
42
-     *
43
-     * @var EE_Question_Group $_question_group
44
-     */
45
-    protected $_question_group;
46
-
47
-    /**
48
-     *_question_model EEM_Question model instance (for queries)
49
-     *
50
-     * @var EEM_Question $_question_model ;
51
-     */
52
-    protected $_question_model;
53
-
54
-    /**
55
-     * _question_group_model EEM_Question_group instance (for queries)
56
-     *
57
-     * @var EEM_Question_Group $_question_group_model
58
-     */
59
-    protected $_question_group_model;
60
-
61
-
62
-    /**
63
-     * @Constructor
64
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
65
-     * @access public
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        require_once(EE_MODELS . 'EEM_Question.model.php');
70
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
71
-        $this->_question_model       = EEM_Question::instance();
72
-        $this->_question_group_model = EEM_Question_Group::instance();
73
-        parent::__construct($routing);
74
-    }
75
-
76
-
77
-    protected function _init_page_props()
78
-    {
79
-        $this->page_slug        = REGISTRATION_FORM_PG_SLUG;
80
-        $this->page_label       = esc_html__('Registration Form', 'event_espresso');
81
-        $this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
82
-        $this->_admin_base_path = REGISTRATION_FORM_ADMIN;
83
-    }
84
-
85
-
86
-    protected function _ajax_hooks()
87
-    {
88
-    }
89
-
90
-
91
-    protected function _define_page_props()
92
-    {
93
-        $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
94
-        $this->_labels           = array(
95
-            'buttons' => array(
96
-                'edit_question' => esc_html__('Edit Question', 'event_espresso'),
97
-            ),
98
-        );
99
-    }
100
-
101
-
102
-    /**
103
-     *_set_page_routes
104
-     */
105
-    protected function _set_page_routes()
106
-    {
107
-        $qst_id             = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
108
-        $this->_page_routes = array(
109
-            'default' => array(
110
-                'func'       => '_questions_overview_list_table',
111
-                'capability' => 'ee_read_questions',
112
-            ),
113
-
114
-            'edit_question' => array(
115
-                'func'       => '_edit_question',
116
-                'capability' => 'ee_edit_question',
117
-                'obj_id'     => $qst_id,
118
-                'args'       => array('edit'),
119
-            ),
120
-
121
-            'question_groups' => array(
122
-                'func'       => '_questions_groups_preview',
123
-                'capability' => 'ee_read_question_groups',
124
-            ),
125
-
126
-            'update_question' => array(
127
-                'func'       => '_insert_or_update_question',
128
-                'args'       => array('new_question' => false),
129
-                'capability' => 'ee_edit_question',
130
-                'obj_id'     => $qst_id,
131
-                'noheader'   => true,
132
-            ),
133
-        );
134
-    }
135
-
136
-
137
-    protected function _set_page_config()
138
-    {
139
-        $this->_page_config = array(
140
-            'default' => array(
141
-                'nav'           => array(
142
-                    'label' => esc_html__('Questions', 'event_espresso'),
143
-                    'order' => 10,
144
-                ),
145
-                'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
146
-                'metaboxes'     => $this->_default_espresso_metaboxes,
147
-                'help_tabs'     => array(
148
-                    'registration_form_questions_overview_help_tab'                           => array(
149
-                        'title'    => esc_html__('Questions Overview', 'event_espresso'),
150
-                        'filename' => 'registration_form_questions_overview',
151
-                    ),
152
-                    'registration_form_questions_overview_table_column_headings_help_tab'     => array(
153
-                        'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
154
-                        'filename' => 'registration_form_questions_overview_table_column_headings',
155
-                    ),
156
-                    'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array(
157
-                        'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
158
-                        'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
159
-                    ),
160
-                ),
161
-                'help_tour'     => array('Registration_Form_Questions_Overview_Help_Tour'),
162
-                'require_nonce' => false,
163
-                'qtips'         => array(
164
-                    'EE_Registration_Form_Tips',
165
-                )/**/
166
-            ),
167
-
168
-            'question_groups' => array(
169
-                'nav'           => array(
170
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
171
-                    'order' => 20,
172
-                ),
173
-                'metaboxes'     => $this->_default_espresso_metaboxes,
174
-                'help_tabs'     => array(
175
-                    'registration_form_question_groups_help_tab' => array(
176
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
177
-                        'filename' => 'registration_form_question_groups',
178
-                    ),
179
-                ),
180
-                'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
181
-                'require_nonce' => false,
182
-            ),
183
-
184
-            'edit_question' => array(
185
-                'nav'           => array(
186
-                    'label'      => esc_html__('Edit Question', 'event_espresso'),
187
-                    'order'      => 15,
188
-                    'persistent' => false,
189
-                    'url'        => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']),
190
-                        $this->_current_page_view_url) : $this->_admin_base_url,
191
-                ),
192
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
193
-                'help_tabs'     => array(
194
-                    'registration_form_edit_question_group_help_tab' => array(
195
-                        'title'    => esc_html__('Edit Question', 'event_espresso'),
196
-                        'filename' => 'registration_form_edit_question',
197
-                    ),
198
-                ),
199
-                'help_tour'     => array('Registration_Form_Edit_Question_Help_Tour'),
200
-                'require_nonce' => false,
201
-            ),
202
-        );
203
-    }
204
-
205
-
206
-    protected function _add_screen_options()
207
-    {
208
-        //todo
209
-    }
210
-
211
-    protected function _add_screen_options_default()
212
-    {
213
-        $page_title              = $this->_admin_page_title;
214
-        $this->_admin_page_title = esc_html__('Questions', 'event_espresso');
215
-        $this->_per_page_screen_option();
216
-        $this->_admin_page_title = $page_title;
217
-    }
218
-
219
-    protected function _add_screen_options_question_groups()
220
-    {
221
-        $page_title              = $this->_admin_page_title;
222
-        $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
223
-        $this->_per_page_screen_option();
224
-        $this->_admin_page_title = $page_title;
225
-    }
226
-
227
-    //none of the below group are currently used for Event Categories
228
-    protected function _add_feature_pointers()
229
-    {
230
-    }
231
-
232
-    public function load_scripts_styles()
233
-    {
234
-        wp_register_style('espresso_registration',
235
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236
-        wp_enqueue_style('espresso_registration');
237
-    }
238
-
239
-    public function admin_init()
240
-    {
241
-    }
242
-
243
-    public function admin_notices()
244
-    {
245
-    }
246
-
247
-    public function admin_footer_scripts()
248
-    {
249
-    }
250
-
251
-
252
-    public function load_scripts_styles_default()
253
-    {
254
-    }
255
-
256
-
257
-    public function load_scripts_styles_add_question()
258
-    {
259
-        $this->load_scripts_styles_question_details();
260
-    }
261
-
262
-    public function load_scripts_styles_edit_question()
263
-    {
264
-        $this->load_scripts_styles_question_details();
265
-    }
266
-
267
-    /**
268
-     * Loads the JS required for adding or editing a question
269
-     */
270
-    protected function load_scripts_styles_question_details()
271
-    {
272
-        $this->load_scripts_styles_forms();
273
-        wp_register_script('espresso_registration_form_single',
274
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
275
-            EVENT_ESPRESSO_VERSION, true);
276
-        wp_enqueue_script('espresso_registration_form_single');
277
-        wp_localize_script(
278
-            'espresso_registration_form_single',
279
-            'ee_question_data',
280
-            array(
281
-                'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(),
282
-                'question_type_with_options' => EEM_Question::instance()->question_types_with_options()
283
-            )
284
-        );
285
-    }
286
-
287
-
288
-    public function recaptcha_info_help_tab()
289
-    {
290
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
291
-        EEH_Template::display_template($template, array());
292
-    }
293
-
294
-
295
-    public function load_scripts_styles_forms()
296
-    {
297
-        //styles
298
-        wp_enqueue_style('espresso-ui-theme');
299
-        //scripts
300
-        wp_enqueue_script('ee_admin_js');
301
-    }
302
-
303
-
304
-    protected function _set_list_table_views_default()
305
-    {
306
-        $this->_views = array(
307
-            'all' => array(
308
-                'slug'  => 'all',
309
-                'label' => esc_html__('View All Questions', 'event_espresso'),
310
-                'count' => 0,
31
+	/**
32
+	 * _question
33
+	 * holds the specific question object for the question details screen
34
+	 *
35
+	 * @var EE_Question $_question
36
+	 */
37
+	protected $_question;
38
+
39
+	/**
40
+	 * _question_group
41
+	 * holds the specific question group object for the question group details screen
42
+	 *
43
+	 * @var EE_Question_Group $_question_group
44
+	 */
45
+	protected $_question_group;
46
+
47
+	/**
48
+	 *_question_model EEM_Question model instance (for queries)
49
+	 *
50
+	 * @var EEM_Question $_question_model ;
51
+	 */
52
+	protected $_question_model;
53
+
54
+	/**
55
+	 * _question_group_model EEM_Question_group instance (for queries)
56
+	 *
57
+	 * @var EEM_Question_Group $_question_group_model
58
+	 */
59
+	protected $_question_group_model;
60
+
61
+
62
+	/**
63
+	 * @Constructor
64
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
65
+	 * @access public
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		require_once(EE_MODELS . 'EEM_Question.model.php');
70
+		require_once(EE_MODELS . 'EEM_Question_Group.model.php');
71
+		$this->_question_model       = EEM_Question::instance();
72
+		$this->_question_group_model = EEM_Question_Group::instance();
73
+		parent::__construct($routing);
74
+	}
75
+
76
+
77
+	protected function _init_page_props()
78
+	{
79
+		$this->page_slug        = REGISTRATION_FORM_PG_SLUG;
80
+		$this->page_label       = esc_html__('Registration Form', 'event_espresso');
81
+		$this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
82
+		$this->_admin_base_path = REGISTRATION_FORM_ADMIN;
83
+	}
84
+
85
+
86
+	protected function _ajax_hooks()
87
+	{
88
+	}
89
+
90
+
91
+	protected function _define_page_props()
92
+	{
93
+		$this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
94
+		$this->_labels           = array(
95
+			'buttons' => array(
96
+				'edit_question' => esc_html__('Edit Question', 'event_espresso'),
97
+			),
98
+		);
99
+	}
100
+
101
+
102
+	/**
103
+	 *_set_page_routes
104
+	 */
105
+	protected function _set_page_routes()
106
+	{
107
+		$qst_id             = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
108
+		$this->_page_routes = array(
109
+			'default' => array(
110
+				'func'       => '_questions_overview_list_table',
111
+				'capability' => 'ee_read_questions',
112
+			),
113
+
114
+			'edit_question' => array(
115
+				'func'       => '_edit_question',
116
+				'capability' => 'ee_edit_question',
117
+				'obj_id'     => $qst_id,
118
+				'args'       => array('edit'),
119
+			),
120
+
121
+			'question_groups' => array(
122
+				'func'       => '_questions_groups_preview',
123
+				'capability' => 'ee_read_question_groups',
124
+			),
125
+
126
+			'update_question' => array(
127
+				'func'       => '_insert_or_update_question',
128
+				'args'       => array('new_question' => false),
129
+				'capability' => 'ee_edit_question',
130
+				'obj_id'     => $qst_id,
131
+				'noheader'   => true,
132
+			),
133
+		);
134
+	}
135
+
136
+
137
+	protected function _set_page_config()
138
+	{
139
+		$this->_page_config = array(
140
+			'default' => array(
141
+				'nav'           => array(
142
+					'label' => esc_html__('Questions', 'event_espresso'),
143
+					'order' => 10,
144
+				),
145
+				'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
146
+				'metaboxes'     => $this->_default_espresso_metaboxes,
147
+				'help_tabs'     => array(
148
+					'registration_form_questions_overview_help_tab'                           => array(
149
+						'title'    => esc_html__('Questions Overview', 'event_espresso'),
150
+						'filename' => 'registration_form_questions_overview',
151
+					),
152
+					'registration_form_questions_overview_table_column_headings_help_tab'     => array(
153
+						'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
154
+						'filename' => 'registration_form_questions_overview_table_column_headings',
155
+					),
156
+					'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array(
157
+						'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
158
+						'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
159
+					),
160
+				),
161
+				'help_tour'     => array('Registration_Form_Questions_Overview_Help_Tour'),
162
+				'require_nonce' => false,
163
+				'qtips'         => array(
164
+					'EE_Registration_Form_Tips',
165
+				)/**/
166
+			),
167
+
168
+			'question_groups' => array(
169
+				'nav'           => array(
170
+					'label' => esc_html__('Question Groups', 'event_espresso'),
171
+					'order' => 20,
172
+				),
173
+				'metaboxes'     => $this->_default_espresso_metaboxes,
174
+				'help_tabs'     => array(
175
+					'registration_form_question_groups_help_tab' => array(
176
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
177
+						'filename' => 'registration_form_question_groups',
178
+					),
179
+				),
180
+				'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
181
+				'require_nonce' => false,
182
+			),
183
+
184
+			'edit_question' => array(
185
+				'nav'           => array(
186
+					'label'      => esc_html__('Edit Question', 'event_espresso'),
187
+					'order'      => 15,
188
+					'persistent' => false,
189
+					'url'        => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']),
190
+						$this->_current_page_view_url) : $this->_admin_base_url,
191
+				),
192
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
193
+				'help_tabs'     => array(
194
+					'registration_form_edit_question_group_help_tab' => array(
195
+						'title'    => esc_html__('Edit Question', 'event_espresso'),
196
+						'filename' => 'registration_form_edit_question',
197
+					),
198
+				),
199
+				'help_tour'     => array('Registration_Form_Edit_Question_Help_Tour'),
200
+				'require_nonce' => false,
201
+			),
202
+		);
203
+	}
204
+
205
+
206
+	protected function _add_screen_options()
207
+	{
208
+		//todo
209
+	}
210
+
211
+	protected function _add_screen_options_default()
212
+	{
213
+		$page_title              = $this->_admin_page_title;
214
+		$this->_admin_page_title = esc_html__('Questions', 'event_espresso');
215
+		$this->_per_page_screen_option();
216
+		$this->_admin_page_title = $page_title;
217
+	}
218
+
219
+	protected function _add_screen_options_question_groups()
220
+	{
221
+		$page_title              = $this->_admin_page_title;
222
+		$this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
223
+		$this->_per_page_screen_option();
224
+		$this->_admin_page_title = $page_title;
225
+	}
226
+
227
+	//none of the below group are currently used for Event Categories
228
+	protected function _add_feature_pointers()
229
+	{
230
+	}
231
+
232
+	public function load_scripts_styles()
233
+	{
234
+		wp_register_style('espresso_registration',
235
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236
+		wp_enqueue_style('espresso_registration');
237
+	}
238
+
239
+	public function admin_init()
240
+	{
241
+	}
242
+
243
+	public function admin_notices()
244
+	{
245
+	}
246
+
247
+	public function admin_footer_scripts()
248
+	{
249
+	}
250
+
251
+
252
+	public function load_scripts_styles_default()
253
+	{
254
+	}
255
+
256
+
257
+	public function load_scripts_styles_add_question()
258
+	{
259
+		$this->load_scripts_styles_question_details();
260
+	}
261
+
262
+	public function load_scripts_styles_edit_question()
263
+	{
264
+		$this->load_scripts_styles_question_details();
265
+	}
266
+
267
+	/**
268
+	 * Loads the JS required for adding or editing a question
269
+	 */
270
+	protected function load_scripts_styles_question_details()
271
+	{
272
+		$this->load_scripts_styles_forms();
273
+		wp_register_script('espresso_registration_form_single',
274
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
275
+			EVENT_ESPRESSO_VERSION, true);
276
+		wp_enqueue_script('espresso_registration_form_single');
277
+		wp_localize_script(
278
+			'espresso_registration_form_single',
279
+			'ee_question_data',
280
+			array(
281
+				'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(),
282
+				'question_type_with_options' => EEM_Question::instance()->question_types_with_options()
283
+			)
284
+		);
285
+	}
286
+
287
+
288
+	public function recaptcha_info_help_tab()
289
+	{
290
+		$template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
291
+		EEH_Template::display_template($template, array());
292
+	}
293
+
294
+
295
+	public function load_scripts_styles_forms()
296
+	{
297
+		//styles
298
+		wp_enqueue_style('espresso-ui-theme');
299
+		//scripts
300
+		wp_enqueue_script('ee_admin_js');
301
+	}
302
+
303
+
304
+	protected function _set_list_table_views_default()
305
+	{
306
+		$this->_views = array(
307
+			'all' => array(
308
+				'slug'  => 'all',
309
+				'label' => esc_html__('View All Questions', 'event_espresso'),
310
+				'count' => 0,
311 311
 //				'bulk_action' => array(
312 312
 //					'trash_questions' => esc_html__('Trash', 'event_espresso'),
313 313
 //					)
314
-            ),
315
-        );
316
-
317
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
318
-            'espresso_registration_form_trash_questions')
319
-        ) {
320
-            $this->_views['trash'] = array(
321
-                'slug'  => 'trash',
322
-                'label' => esc_html__('Trash', 'event_espresso'),
323
-                'count' => 0,
314
+			),
315
+		);
316
+
317
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
318
+			'espresso_registration_form_trash_questions')
319
+		) {
320
+			$this->_views['trash'] = array(
321
+				'slug'  => 'trash',
322
+				'label' => esc_html__('Trash', 'event_espresso'),
323
+				'count' => 0,
324 324
 //				'bulk_action' => array(
325 325
 //					'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'),
326 326
 //					'restore_questions' => esc_html__('Restore', 'event_espresso'),
327
-            );
328
-        }
329
-    }
330
-
331
-    /**
332
-     * This just previews the question groups tab that comes in caffeinated.
333
-     *
334
-     * @return string html
335
-     */
336
-    protected function _questions_groups_preview()
337
-    {
338
-        $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
339
-        $this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
340
-                'event_espresso') . '" />';
341
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
342
-                'event_espresso') . '</strong>';
343
-        $this->display_admin_caf_preview_page('question_groups_tab');
344
-    }
345
-
346
-
347
-    /**
348
-     * Extracts the question field's values from the POST request to update or insert them
349
-     *
350
-     * @param \EEM_Base $model
351
-     * @return array where each key is the name of a model's field/db column, and each value is its value.
352
-     */
353
-    protected function _set_column_values_for(EEM_Base $model)
354
-    {
355
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
356
-        $set_column_values = array();
357
-
358
-        //some initial checks for proper values.
359
-        //if QST_admin_only, then no matter what QST_required is we disable.
360
-        if (! empty($this->_req_data['QST_admin_only'])) {
361
-            $this->_req_data['QST_required'] = 0;
362
-        }
363
-        //if the question shouldn't have a max length, don't let them set one
364
-        if (! isset(
365
-            $this->_req_data['QST_type'],
366
-                $this->_req_data['QST_max']
367
-            )
368
-            || ! in_array(
369
-            $this->_req_data['QST_type'],
370
-            EEM_Question::instance()->questionTypesWithMaxLength(),
371
-            true)
372
-        ) {
373
-            //they're not allowed to set the max
374
-            $this->_req_data['QST_max'] = null;
375
-        }
376
-        foreach ($model->field_settings() as $fieldName => $settings) {
377
-            // basically if QSG_identifier is empty or not set
378
-            if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
379
-                $QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
380
-                $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
327
+			);
328
+		}
329
+	}
330
+
331
+	/**
332
+	 * This just previews the question groups tab that comes in caffeinated.
333
+	 *
334
+	 * @return string html
335
+	 */
336
+	protected function _questions_groups_preview()
337
+	{
338
+		$this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
339
+		$this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
340
+				'event_espresso') . '" />';
341
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
342
+				'event_espresso') . '</strong>';
343
+		$this->display_admin_caf_preview_page('question_groups_tab');
344
+	}
345
+
346
+
347
+	/**
348
+	 * Extracts the question field's values from the POST request to update or insert them
349
+	 *
350
+	 * @param \EEM_Base $model
351
+	 * @return array where each key is the name of a model's field/db column, and each value is its value.
352
+	 */
353
+	protected function _set_column_values_for(EEM_Base $model)
354
+	{
355
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
356
+		$set_column_values = array();
357
+
358
+		//some initial checks for proper values.
359
+		//if QST_admin_only, then no matter what QST_required is we disable.
360
+		if (! empty($this->_req_data['QST_admin_only'])) {
361
+			$this->_req_data['QST_required'] = 0;
362
+		}
363
+		//if the question shouldn't have a max length, don't let them set one
364
+		if (! isset(
365
+			$this->_req_data['QST_type'],
366
+				$this->_req_data['QST_max']
367
+			)
368
+			|| ! in_array(
369
+			$this->_req_data['QST_type'],
370
+			EEM_Question::instance()->questionTypesWithMaxLength(),
371
+			true)
372
+		) {
373
+			//they're not allowed to set the max
374
+			$this->_req_data['QST_max'] = null;
375
+		}
376
+		foreach ($model->field_settings() as $fieldName => $settings) {
377
+			// basically if QSG_identifier is empty or not set
378
+			if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
379
+				$QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
380
+				$set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
381 381
 //				dd($set_column_values);
382
-            } //if the admin label is blank, use a slug version of the question text
383
-            else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
384
-                $QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
385
-                $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
386
-            } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
387
-                $set_column_values[$fieldName] = 0;
388
-            } else if ($fieldName === 'QST_max') {
389
-                $qst_system = EEM_Question::instance()->get_var(
390
-                    array(
391
-                        array(
392
-                            'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0,
393
-                        ),
394
-                    ),
395
-                    'QST_system');
396
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
397
-                if (empty($this->_req_data['QST_max']) ||
398
-                    $this->_req_data['QST_max'] > $max_max
399
-                ) {
400
-                    $set_column_values[$fieldName] = $max_max;
401
-                }
402
-            }
403
-
404
-
405
-            //only add a property to the array if it's not null (otherwise the model should just use the default value)
406
-            if (
407
-                ! isset($set_column_values[$fieldName]) &&
408
-                isset($this->_req_data[$fieldName])
409
-            ) {
410
-                $set_column_values[$fieldName] = $this->_req_data[$fieldName];
411
-            }
412
-
413
-        }
414
-        return $set_column_values;//validation fo this data to be performed by the model before insertion.
415
-    }
416
-
417
-
418
-    /**
419
-     *_questions_overview_list_table
420
-     */
421
-    protected function _questions_overview_list_table()
422
-    {
423
-        $this->_search_btn_label = esc_html__('Questions', 'event_espresso');
424
-        $this->display_admin_list_table_page_with_sidebar();
425
-    }
426
-
427
-
428
-    /**
429
-     * _edit_question
430
-     */
431
-    protected function _edit_question()
432
-    {
433
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
434
-        $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false;
435
-
436
-        switch ($this->_req_action) {
437
-            case 'add_question' :
438
-                $this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
439
-                break;
440
-            case 'edit_question' :
441
-                $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
442
-                break;
443
-            default :
444
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
445
-        }
446
-
447
-        // add PRC_ID to title if editing
448
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
449
-        if ($ID) {
450
-            $question                 = $this->_question_model->get_one_by_ID($ID);
451
-            $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
452
-            $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
453
-        } else {
454
-            $question = EE_Question::new_instance();
455
-            $question->set_order_to_latest();
456
-            $this->_set_add_edit_form_tags('insert_question');
457
-        }
458
-        if( $question->system_ID() === EEM_Attendee::system_question_phone ){
459
-            $question_types = array_intersect_key(
460
-                EEM_Question::instance()->allowed_question_types(),
461
-                array_flip(
462
-                    array(
463
-                        EEM_Question::QST_type_text,
464
-                        EEM_Question::QST_type_us_phone
465
-                    )
466
-                )
467
-            );
468
-        } else {
469
-            $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types();
470
-        }
471
-        $this->_template_args['QST_ID']                     = $ID;
472
-        $this->_template_args['question']                   = $question;
473
-        $this->_template_args['question_types']             = $question_types;
474
-        $this->_template_args['max_max']                    = EEM_Question::instance()->absolute_max_for_system_question(
475
-            $question->system_ID()
476
-        );
477
-        $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
478
-        $this->_set_publish_post_box_vars('id', $ID);
479
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
480
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
481
-            $this->_template_args, true
482
-        );
483
-
484
-        // the details template wrapper
485
-        $this->display_admin_page_with_sidebar();
486
-    }
487
-
488
-
489
-    /**
490
-     * @return string
491
-     */
492
-    protected function _get_question_type_descriptions()
493
-    {
494
-        EE_Registry::instance()->load_helper('HTML');
495
-        $descriptions               = '';
496
-        $question_type_descriptions = EEM_Question::instance()->question_descriptions();
497
-        foreach ($question_type_descriptions as $type => $question_type_description) {
498
-            if ($type == 'HTML_TEXTAREA') {
499
-                $html = new EE_Simple_HTML_Validation_Strategy();
500
-                $question_type_description .= sprintf(
501
-                    esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
502
-                    '<br/>',
503
-                    $html->get_list_of_allowed_tags()
504
-                );
505
-            }
506
-            $descriptions .= EEH_HTML::p(
507
-                $question_type_description,
508
-                'question_type_description-' . $type,
509
-                'question_type_description description',
510
-                'display:none;'
511
-            );
512
-        }
513
-        return $descriptions;
514
-    }
515
-
516
-
517
-    /**
518
-     * @param bool|true $new_question
519
-     * @throws \EE_Error
520
-     */
521
-    protected function _insert_or_update_question($new_question = true)
522
-    {
523
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
-        $set_column_values = $this->_set_column_values_for($this->_question_model);
525
-        if ($new_question) {
526
-            $question = EE_Question::new_instance($set_column_values);
527
-            $action_desc = 'added';
528
-        } else {
529
-            $question     = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID']));
530
-            foreach($set_column_values as $field => $new_value) {
531
-                $question->set($field, $new_value);
532
-            }
533
-            $action_desc = 'updated';
534
-        }
535
-        $success = $question->save();
536
-        $ID = $question->ID();
537
-        if ($ID && $question->should_have_question_options()) {
538
-            //save the related options
539
-            //trash removed options, save old ones
540
-            //get list of all options
541
-            $options  = $question->options();
542
-            if (! empty($options)) {
543
-                foreach ($options as $option_ID => $option) {
544
-                    $option_req_index = $this->_get_option_req_data_index($option_ID);
545
-                    if ($option_req_index !== false) {
546
-                        $option->save($this->_req_data['question_options'][$option_req_index]);
547
-                    } else {
548
-                        //not found, remove it
549
-                        $option->delete();
550
-                    }
551
-                }
552
-            }
553
-            //save new related options
554
-            foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
555
-                //skip $index that is from our sample
556
-                if ( $index === 'xxcountxx' ) {
557
-                    continue;
558
-                }
559
-                //note we allow saving blank options.
560
-                if (empty($option_req_data['QSO_ID'])
561
-                ) {//no ID! save it!
562
-                    $new_option = EE_Question_Option::new_instance(array(
563
-                        'QSO_value' => $option_req_data['QSO_value'],
564
-                        'QSO_desc'  => $option_req_data['QSO_desc'],
565
-                        'QSO_order' => $option_req_data['QSO_order'],
566
-                        'QST_ID'    => $question->ID(),
567
-                    ));
568
-                    $new_option->save();
569
-                }
570
-            }
571
-        }
572
-        $query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
573
-        if ($success !== false) {
574
-            $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
575
-                $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'),
576
-                $this->_question_model->item_name());
577
-            EE_Error::add_success($msg);
578
-        }
579
-
580
-        $this->_redirect_after_action(false, '', $action_desc, $query_args, true);
581
-    }
582
-
583
-
584
-    /**
585
-     * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
586
-     * by ID
587
-     * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
588
-     * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
589
-     *
590
-     * @param int $ID of the question option to find
591
-     * @return int index in question_options array if successful, FALSE if unsuccessful
592
-     */
593
-    protected function _get_option_req_data_index($ID)
594
-    {
595
-        $req_data_for_question_options = $this->_req_data['question_options'];
596
-        foreach ($req_data_for_question_options as $num => $option_data) {
597
-            if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
598
-                return $num;
599
-            }
600
-        }
601
-        return false;
602
-    }
603
-
604
-
605
-
606
-
607
-    /***********/
608
-    /* QUERIES */
609
-    /**
610
-     * For internal use in getting all the query parameters
611
-     * (because it's pretty well the same between question, question groups,
612
-     * and for both when searching for trashed and untrashed ones)
613
-     *
614
-     * @param EEM_Base $model either EEM_Question or EEM_Question_Group
615
-     * @param int      $per_page
616
-     * @param int      $current_page
617
-     * @return array lik EEM_Base::get_all's $query_params parameter
618
-     */
619
-    protected function get_query_params($model, $per_page = 10, $current_page = 10)
620
-    {
621
-        $query_params             = array();
622
-        $offset                   = ($current_page - 1) * $per_page;
623
-        $query_params['limit']    = array($offset, $per_page);
624
-        $order                    = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
625
-        $orderby_field            = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
626
-        $field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
627
-        $query_params['order_by'] = array($field_to_order_by => $order);
628
-        $search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
629
-        if (! empty($search_string)) {
630
-            if ($model instanceof EEM_Question_Group) {
631
-                $query_params[0] = array(
632
-                    'OR' => array(
633
-                        'QSG_name' => array('LIKE', "%$search_string%"),
634
-                        'QSG_desc' => array('LIKE', "%$search_string%"),
635
-                    ),
636
-                );
637
-            } else {
638
-                $query_params[0] = array(
639
-                    'QST_display_text' => array('LIKE', "%$search_string%"),
640
-                );
641
-            }
642
-        }
643
-
644
-        //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
645
-        /*if ( $model instanceof EEM_Question_Group ) {
382
+			} //if the admin label is blank, use a slug version of the question text
383
+			else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
384
+				$QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
385
+				$set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
386
+			} else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
387
+				$set_column_values[$fieldName] = 0;
388
+			} else if ($fieldName === 'QST_max') {
389
+				$qst_system = EEM_Question::instance()->get_var(
390
+					array(
391
+						array(
392
+							'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0,
393
+						),
394
+					),
395
+					'QST_system');
396
+				$max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
397
+				if (empty($this->_req_data['QST_max']) ||
398
+					$this->_req_data['QST_max'] > $max_max
399
+				) {
400
+					$set_column_values[$fieldName] = $max_max;
401
+				}
402
+			}
403
+
404
+
405
+			//only add a property to the array if it's not null (otherwise the model should just use the default value)
406
+			if (
407
+				! isset($set_column_values[$fieldName]) &&
408
+				isset($this->_req_data[$fieldName])
409
+			) {
410
+				$set_column_values[$fieldName] = $this->_req_data[$fieldName];
411
+			}
412
+
413
+		}
414
+		return $set_column_values;//validation fo this data to be performed by the model before insertion.
415
+	}
416
+
417
+
418
+	/**
419
+	 *_questions_overview_list_table
420
+	 */
421
+	protected function _questions_overview_list_table()
422
+	{
423
+		$this->_search_btn_label = esc_html__('Questions', 'event_espresso');
424
+		$this->display_admin_list_table_page_with_sidebar();
425
+	}
426
+
427
+
428
+	/**
429
+	 * _edit_question
430
+	 */
431
+	protected function _edit_question()
432
+	{
433
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
434
+		$ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false;
435
+
436
+		switch ($this->_req_action) {
437
+			case 'add_question' :
438
+				$this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
439
+				break;
440
+			case 'edit_question' :
441
+				$this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
442
+				break;
443
+			default :
444
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
445
+		}
446
+
447
+		// add PRC_ID to title if editing
448
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
449
+		if ($ID) {
450
+			$question                 = $this->_question_model->get_one_by_ID($ID);
451
+			$additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
452
+			$this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
453
+		} else {
454
+			$question = EE_Question::new_instance();
455
+			$question->set_order_to_latest();
456
+			$this->_set_add_edit_form_tags('insert_question');
457
+		}
458
+		if( $question->system_ID() === EEM_Attendee::system_question_phone ){
459
+			$question_types = array_intersect_key(
460
+				EEM_Question::instance()->allowed_question_types(),
461
+				array_flip(
462
+					array(
463
+						EEM_Question::QST_type_text,
464
+						EEM_Question::QST_type_us_phone
465
+					)
466
+				)
467
+			);
468
+		} else {
469
+			$question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types();
470
+		}
471
+		$this->_template_args['QST_ID']                     = $ID;
472
+		$this->_template_args['question']                   = $question;
473
+		$this->_template_args['question_types']             = $question_types;
474
+		$this->_template_args['max_max']                    = EEM_Question::instance()->absolute_max_for_system_question(
475
+			$question->system_ID()
476
+		);
477
+		$this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
478
+		$this->_set_publish_post_box_vars('id', $ID);
479
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
480
+			REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
481
+			$this->_template_args, true
482
+		);
483
+
484
+		// the details template wrapper
485
+		$this->display_admin_page_with_sidebar();
486
+	}
487
+
488
+
489
+	/**
490
+	 * @return string
491
+	 */
492
+	protected function _get_question_type_descriptions()
493
+	{
494
+		EE_Registry::instance()->load_helper('HTML');
495
+		$descriptions               = '';
496
+		$question_type_descriptions = EEM_Question::instance()->question_descriptions();
497
+		foreach ($question_type_descriptions as $type => $question_type_description) {
498
+			if ($type == 'HTML_TEXTAREA') {
499
+				$html = new EE_Simple_HTML_Validation_Strategy();
500
+				$question_type_description .= sprintf(
501
+					esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
502
+					'<br/>',
503
+					$html->get_list_of_allowed_tags()
504
+				);
505
+			}
506
+			$descriptions .= EEH_HTML::p(
507
+				$question_type_description,
508
+				'question_type_description-' . $type,
509
+				'question_type_description description',
510
+				'display:none;'
511
+			);
512
+		}
513
+		return $descriptions;
514
+	}
515
+
516
+
517
+	/**
518
+	 * @param bool|true $new_question
519
+	 * @throws \EE_Error
520
+	 */
521
+	protected function _insert_or_update_question($new_question = true)
522
+	{
523
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
524
+		$set_column_values = $this->_set_column_values_for($this->_question_model);
525
+		if ($new_question) {
526
+			$question = EE_Question::new_instance($set_column_values);
527
+			$action_desc = 'added';
528
+		} else {
529
+			$question     = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID']));
530
+			foreach($set_column_values as $field => $new_value) {
531
+				$question->set($field, $new_value);
532
+			}
533
+			$action_desc = 'updated';
534
+		}
535
+		$success = $question->save();
536
+		$ID = $question->ID();
537
+		if ($ID && $question->should_have_question_options()) {
538
+			//save the related options
539
+			//trash removed options, save old ones
540
+			//get list of all options
541
+			$options  = $question->options();
542
+			if (! empty($options)) {
543
+				foreach ($options as $option_ID => $option) {
544
+					$option_req_index = $this->_get_option_req_data_index($option_ID);
545
+					if ($option_req_index !== false) {
546
+						$option->save($this->_req_data['question_options'][$option_req_index]);
547
+					} else {
548
+						//not found, remove it
549
+						$option->delete();
550
+					}
551
+				}
552
+			}
553
+			//save new related options
554
+			foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
555
+				//skip $index that is from our sample
556
+				if ( $index === 'xxcountxx' ) {
557
+					continue;
558
+				}
559
+				//note we allow saving blank options.
560
+				if (empty($option_req_data['QSO_ID'])
561
+				) {//no ID! save it!
562
+					$new_option = EE_Question_Option::new_instance(array(
563
+						'QSO_value' => $option_req_data['QSO_value'],
564
+						'QSO_desc'  => $option_req_data['QSO_desc'],
565
+						'QSO_order' => $option_req_data['QSO_order'],
566
+						'QST_ID'    => $question->ID(),
567
+					));
568
+					$new_option->save();
569
+				}
570
+			}
571
+		}
572
+		$query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
573
+		if ($success !== false) {
574
+			$msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
575
+				$this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'),
576
+				$this->_question_model->item_name());
577
+			EE_Error::add_success($msg);
578
+		}
579
+
580
+		$this->_redirect_after_action(false, '', $action_desc, $query_args, true);
581
+	}
582
+
583
+
584
+	/**
585
+	 * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
586
+	 * by ID
587
+	 * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
588
+	 * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
589
+	 *
590
+	 * @param int $ID of the question option to find
591
+	 * @return int index in question_options array if successful, FALSE if unsuccessful
592
+	 */
593
+	protected function _get_option_req_data_index($ID)
594
+	{
595
+		$req_data_for_question_options = $this->_req_data['question_options'];
596
+		foreach ($req_data_for_question_options as $num => $option_data) {
597
+			if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
598
+				return $num;
599
+			}
600
+		}
601
+		return false;
602
+	}
603
+
604
+
605
+
606
+
607
+	/***********/
608
+	/* QUERIES */
609
+	/**
610
+	 * For internal use in getting all the query parameters
611
+	 * (because it's pretty well the same between question, question groups,
612
+	 * and for both when searching for trashed and untrashed ones)
613
+	 *
614
+	 * @param EEM_Base $model either EEM_Question or EEM_Question_Group
615
+	 * @param int      $per_page
616
+	 * @param int      $current_page
617
+	 * @return array lik EEM_Base::get_all's $query_params parameter
618
+	 */
619
+	protected function get_query_params($model, $per_page = 10, $current_page = 10)
620
+	{
621
+		$query_params             = array();
622
+		$offset                   = ($current_page - 1) * $per_page;
623
+		$query_params['limit']    = array($offset, $per_page);
624
+		$order                    = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
625
+		$orderby_field            = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
626
+		$field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
627
+		$query_params['order_by'] = array($field_to_order_by => $order);
628
+		$search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
629
+		if (! empty($search_string)) {
630
+			if ($model instanceof EEM_Question_Group) {
631
+				$query_params[0] = array(
632
+					'OR' => array(
633
+						'QSG_name' => array('LIKE', "%$search_string%"),
634
+						'QSG_desc' => array('LIKE', "%$search_string%"),
635
+					),
636
+				);
637
+			} else {
638
+				$query_params[0] = array(
639
+					'QST_display_text' => array('LIKE', "%$search_string%"),
640
+				);
641
+			}
642
+		}
643
+
644
+		//capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
645
+		/*if ( $model instanceof EEM_Question_Group ) {
646 646
             if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) {
647 647
                 $query_params[0] = array(
648 648
                     'AND' => array(
@@ -672,62 +672,62 @@  discard block
 block discarded – undo
672 672
             }
673 673
         }/**/
674 674
 
675
-        return $query_params;
676
-
677
-    }
678
-
679
-
680
-    /**
681
-     * @param int        $per_page
682
-     * @param int        $current_page
683
-     * @param bool|false $count
684
-     * @return \EE_Soft_Delete_Base_Class[]|int
685
-     */
686
-    public function get_questions($per_page = 10, $current_page = 1, $count = false)
687
-    {
688
-        $QST          = EEM_Question::instance();
689
-        $query_params = $this->get_query_params($QST, $per_page, $current_page);
690
-        if ($count) {
691
-            $where   = isset($query_params[0]) ? array($query_params[0]) : array();
692
-            $results = $QST->count($where);
693
-        } else {
694
-            $results = $QST->get_all($query_params);
695
-        }
696
-        return $results;
697
-
698
-    }
699
-
700
-
701
-    /**
702
-     * @param            $per_page
703
-     * @param int        $current_page
704
-     * @param bool|false $count
705
-     * @return \EE_Soft_Delete_Base_Class[]|int
706
-     */
707
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
708
-    {
709
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
710
-        $where        = isset($query_params[0]) ? array($query_params[0]) : array();
711
-        $questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
712
-        return $questions;
713
-    }
714
-
715
-
716
-    /**
717
-     * @param            $per_page
718
-     * @param int        $current_page
719
-     * @param bool|false $count
720
-     * @return \EE_Soft_Delete_Base_Class[]
721
-     */
722
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
723
-    {
724
-        /** @type EEM_Question_Group $questionGroupModel */
725
-        $questionGroupModel = EEM_Question_Group::instance();
726
-        //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
727
-        return $questionGroupModel->get_all(
728
-            $this->get_query_params($questionGroupModel, $per_page, $current_page)
729
-        );
730
-    }
675
+		return $query_params;
676
+
677
+	}
678
+
679
+
680
+	/**
681
+	 * @param int        $per_page
682
+	 * @param int        $current_page
683
+	 * @param bool|false $count
684
+	 * @return \EE_Soft_Delete_Base_Class[]|int
685
+	 */
686
+	public function get_questions($per_page = 10, $current_page = 1, $count = false)
687
+	{
688
+		$QST          = EEM_Question::instance();
689
+		$query_params = $this->get_query_params($QST, $per_page, $current_page);
690
+		if ($count) {
691
+			$where   = isset($query_params[0]) ? array($query_params[0]) : array();
692
+			$results = $QST->count($where);
693
+		} else {
694
+			$results = $QST->get_all($query_params);
695
+		}
696
+		return $results;
697
+
698
+	}
699
+
700
+
701
+	/**
702
+	 * @param            $per_page
703
+	 * @param int        $current_page
704
+	 * @param bool|false $count
705
+	 * @return \EE_Soft_Delete_Base_Class[]|int
706
+	 */
707
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
708
+	{
709
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
710
+		$where        = isset($query_params[0]) ? array($query_params[0]) : array();
711
+		$questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
712
+		return $questions;
713
+	}
714
+
715
+
716
+	/**
717
+	 * @param            $per_page
718
+	 * @param int        $current_page
719
+	 * @param bool|false $count
720
+	 * @return \EE_Soft_Delete_Base_Class[]
721
+	 */
722
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
723
+	{
724
+		/** @type EEM_Question_Group $questionGroupModel */
725
+		$questionGroupModel = EEM_Question_Group::instance();
726
+		//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
727
+		return $questionGroupModel->get_all(
728
+			$this->get_query_params($questionGroupModel, $per_page, $current_page)
729
+		);
730
+	}
731 731
 
732 732
 
733 733
 } //ends Registration_Form_Admin_Page class
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function __construct($routing = true)
68 68
     {
69
-        require_once(EE_MODELS . 'EEM_Question.model.php');
70
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
69
+        require_once(EE_MODELS.'EEM_Question.model.php');
70
+        require_once(EE_MODELS.'EEM_Question_Group.model.php');
71 71
         $this->_question_model       = EEM_Question::instance();
72 72
         $this->_question_group_model = EEM_Question_Group::instance();
73 73
         parent::__construct($routing);
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     public function load_scripts_styles()
233 233
     {
234 234
         wp_register_style('espresso_registration',
235
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
235
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236 236
         wp_enqueue_style('espresso_registration');
237 237
     }
238 238
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
     {
272 272
         $this->load_scripts_styles_forms();
273 273
         wp_register_script('espresso_registration_form_single',
274
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
274
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
275 275
             EVENT_ESPRESSO_VERSION, true);
276 276
         wp_enqueue_script('espresso_registration_form_single');
277 277
         wp_localize_script(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 
288 288
     public function recaptcha_info_help_tab()
289 289
     {
290
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
290
+        $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php';
291 291
         EEH_Template::display_template($template, array());
292 292
     }
293 293
 
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
     protected function _questions_groups_preview()
337 337
     {
338 338
         $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
339
-        $this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
340
-                'event_espresso') . '" />';
341
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
342
-                'event_espresso') . '</strong>';
339
+        $this->_template_args['preview_img']  = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot',
340
+                'event_espresso').'" />';
341
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
342
+                'event_espresso').'</strong>';
343 343
         $this->display_admin_caf_preview_page('question_groups_tab');
344 344
     }
345 345
 
@@ -357,11 +357,11 @@  discard block
 block discarded – undo
357 357
 
358 358
         //some initial checks for proper values.
359 359
         //if QST_admin_only, then no matter what QST_required is we disable.
360
-        if (! empty($this->_req_data['QST_admin_only'])) {
360
+        if ( ! empty($this->_req_data['QST_admin_only'])) {
361 361
             $this->_req_data['QST_required'] = 0;
362 362
         }
363 363
         //if the question shouldn't have a max length, don't let them set one
364
-        if (! isset(
364
+        if ( ! isset(
365 365
             $this->_req_data['QST_type'],
366 366
                 $this->_req_data['QST_max']
367 367
             )
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
             // basically if QSG_identifier is empty or not set
378 378
             if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
379 379
                 $QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
380
-                $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
380
+                $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true);
381 381
 //				dd($set_column_values);
382 382
             } //if the admin label is blank, use a slug version of the question text
383 383
             else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
384 384
                 $QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
385 385
                 $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
386
-            } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
386
+            } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) {
387 387
                 $set_column_values[$fieldName] = 0;
388 388
             } else if ($fieldName === 'QST_max') {
389 389
                 $qst_system = EEM_Question::instance()->get_var(
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
                         ),
394 394
                     ),
395 395
                     'QST_system');
396
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
396
+                $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
397 397
                 if (empty($this->_req_data['QST_max']) ||
398 398
                     $this->_req_data['QST_max'] > $max_max
399 399
                 ) {
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
             }
412 412
 
413 413
         }
414
-        return $set_column_values;//validation fo this data to be performed by the model before insertion.
414
+        return $set_column_values; //validation fo this data to be performed by the model before insertion.
415 415
     }
416 416
 
417 417
 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
         }
446 446
 
447 447
         // add PRC_ID to title if editing
448
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
448
+        $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title;
449 449
         if ($ID) {
450 450
             $question                 = $this->_question_model->get_one_by_ID($ID);
451 451
             $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
             $question->set_order_to_latest();
456 456
             $this->_set_add_edit_form_tags('insert_question');
457 457
         }
458
-        if( $question->system_ID() === EEM_Attendee::system_question_phone ){
458
+        if ($question->system_ID() === EEM_Attendee::system_question_phone) {
459 459
             $question_types = array_intersect_key(
460 460
                 EEM_Question::instance()->allowed_question_types(),
461 461
                 array_flip(
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
         $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
478 478
         $this->_set_publish_post_box_vars('id', $ID);
479 479
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
480
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
480
+            REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php',
481 481
             $this->_template_args, true
482 482
         );
483 483
 
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
             }
506 506
             $descriptions .= EEH_HTML::p(
507 507
                 $question_type_description,
508
-                'question_type_description-' . $type,
508
+                'question_type_description-'.$type,
509 509
                 'question_type_description description',
510 510
                 'display:none;'
511 511
             );
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
             $question = EE_Question::new_instance($set_column_values);
527 527
             $action_desc = 'added';
528 528
         } else {
529
-            $question     = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID']));
530
-            foreach($set_column_values as $field => $new_value) {
529
+            $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID']));
530
+            foreach ($set_column_values as $field => $new_value) {
531 531
                 $question->set($field, $new_value);
532 532
             }
533 533
             $action_desc = 'updated';
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
             //save the related options
539 539
             //trash removed options, save old ones
540 540
             //get list of all options
541
-            $options  = $question->options();
542
-            if (! empty($options)) {
541
+            $options = $question->options();
542
+            if ( ! empty($options)) {
543 543
                 foreach ($options as $option_ID => $option) {
544 544
                     $option_req_index = $this->_get_option_req_data_index($option_ID);
545 545
                     if ($option_req_index !== false) {
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
             //save new related options
554 554
             foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
555 555
                 //skip $index that is from our sample
556
-                if ( $index === 'xxcountxx' ) {
556
+                if ($index === 'xxcountxx') {
557 557
                     continue;
558 558
                 }
559 559
                 //note we allow saving blank options.
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
     {
595 595
         $req_data_for_question_options = $this->_req_data['question_options'];
596 596
         foreach ($req_data_for_question_options as $num => $option_data) {
597
-            if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
597
+            if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) {
598 598
                 return $num;
599 599
             }
600 600
         }
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
         $field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
627 627
         $query_params['order_by'] = array($field_to_order_by => $order);
628 628
         $search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
629
-        if (! empty($search_string)) {
629
+        if ( ! empty($search_string)) {
630 630
             if ($model instanceof EEM_Question_Group) {
631 631
                 $query_params[0] = array(
632 632
                     'OR' => array(
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 2 patches
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -21,724 +21,724 @@
 block discarded – undo
21 21
 abstract class EE_PMT_Base
22 22
 {
23 23
 
24
-    const onsite = 'on-site';
25
-    const offsite = 'off-site';
26
-    const offline = 'off-line';
27
-
28
-    /**
29
-     * @var EE_Payment_Method
30
-     */
31
-    protected $_pm_instance = NULL;
32
-
33
-    /**
34
-     * @var boolean
35
-     */
36
-    protected $_requires_https = FALSE;
37
-
38
-    /**
39
-     * @var boolean
40
-     */
41
-    protected $_has_billing_form;
42
-
43
-    /**
44
-     * @var EE_Gateway
45
-     */
46
-    protected $_gateway = NULL;
47
-
48
-    /**
49
-     * @var EE_Payment_Method_Form
50
-     */
51
-    protected $_settings_form = NULL;
52
-
53
-    /**
54
-     * @var EE_Form_Section_Proper
55
-     */
56
-    protected $_billing_form = NULL;
57
-
58
-    /**
59
-     * @var boolean
60
-     */
61
-    protected $_cache_billing_form = TRUE;
62
-
63
-    /**
64
-     * String of the absolute path to the folder containing this file, with a trailing slash.
65
-     * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
-     * @var string
67
-     */
68
-    protected $_file_folder = NULL;
69
-
70
-    /**
71
-     * String to the absolute URL to this file (useful for getting its web-accessible resources
72
-     * like images, js, or css)
73
-     * @var string
74
-     */
75
-    protected $_file_url = NULL;
76
-
77
-    /**
78
-     * Pretty name for the payment method
79
-     * @var string
80
-     */
81
-    protected $_pretty_name = NULL;
82
-
83
-    /**
84
-     *
85
-     * @var string
86
-     */
87
-    protected $_default_button_url = NULL;
88
-
89
-    /**
90
-     *
91
-     * @var string
92
-     */
93
-    protected $_default_description = NULL;
94
-
95
-
96
-    /**
97
-     *
98
-     * @param EE_Payment_Method $pm_instance
99
-     * @throws EE_Error
100
-     * @return EE_PMT_Base
101
-     */
102
-    function __construct($pm_instance = NULL)
103
-    {
104
-        if ($pm_instance instanceof EE_Payment_Method) {
105
-            $this->set_instance($pm_instance);
106
-        }
107
-        if ($this->_gateway) {
108
-            $this->_gateway->set_payment_model(EEM_Payment::instance());
109
-            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
-            $this->_gateway->set_template_helper(new EEH_Template());
111
-            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
-            $this->_gateway->set_money_helper(new EEH_Money());
113
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
-            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
-        }
117
-        if (!isset($this->_has_billing_form)) {
118
-            // by default, On Site gateways have a billing form
119
-            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
-                $this->set_has_billing_form(true);
121
-            } else {
122
-                $this->set_has_billing_form(false);
123
-            }
124
-        }
125
-
126
-        if (!$this->_pretty_name) {
127
-            throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
-        }
129
-        //if the child didn't specify a default button, use the credit card one
130
-        if ($this->_default_button_url === NULL) {
131
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
-        }
133
-    }
134
-
135
-
136
-    /**
137
-     * @param boolean $has_billing_form
138
-     */
139
-    public function set_has_billing_form($has_billing_form)
140
-    {
141
-        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
-    }
143
-
144
-
145
-    /**
146
-     * sets the file_folder property
147
-     */
148
-    protected function _set_file_folder()
149
-    {
150
-        $reflector = new ReflectionClass(get_class($this));
151
-        $fn = $reflector->getFileName();
152
-        $this->_file_folder = dirname($fn) . DS;
153
-    }
154
-
155
-
156
-    /**
157
-     * sets the file URL with a trailing slash for this PMT
158
-     */
159
-    protected function _set_file_url()
160
-    {
161
-        $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
-        $file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
-        $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
-        $this->_file_url = $file_path;
165
-    }
166
-
167
-    /**
168
-     * Gets the default description on all payment methods of this type
169
-     * @return string
170
-     */
171
-    public function default_description()
172
-    {
173
-        return $this->_default_description;
174
-    }
175
-
176
-
177
-    /**
178
-     * Returns the folder containing the PMT child class, with a trailing slash
179
-     * @return string
180
-     */
181
-    public function file_folder()
182
-    {
183
-        if (!$this->_file_folder) {
184
-            $this->_set_file_folder();
185
-        }
186
-        return $this->_file_folder;
187
-    }
188
-
189
-
190
-    /**
191
-     * @return string
192
-     */
193
-    public function file_url()
194
-    {
195
-        if (!$this->_file_url) {
196
-            $this->_set_file_url();
197
-        }
198
-        return $this->_file_url;
199
-    }
200
-
201
-
202
-    /**
203
-     * Sets the payment method instance this payment method type is for.
204
-     * Its important teh payment method instance is set before
205
-     * @param EE_Payment_Method $payment_method_instance
206
-     */
207
-    function set_instance($payment_method_instance)
208
-    {
209
-        $this->_pm_instance = $payment_method_instance;
210
-        //if they have already requested the settings form, make sure its
211
-        //data matches this model object
212
-        if ($this->_settings_form) {
213
-            $this->settings_form()->populate_model_obj($payment_method_instance);
214
-        }
215
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
-            $this->_gateway->set_settings($payment_method_instance->settings_array());
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * Gets teh form for displaying to admins where they setup the payment method
223
-     * @return EE_Payment_Method_Form
224
-     */
225
-    function settings_form()
226
-    {
227
-        if (!$this->_settings_form) {
228
-            $this->_settings_form = $this->generate_new_settings_form();
229
-            $this->_settings_form->set_payment_method_type($this);
230
-            //if we have already assigned a model object to this pmt, make
231
-            //sure its reflected in teh form we just generated
232
-            if ($this->_pm_instance) {
233
-                $this->_settings_form->populate_model_obj($this->_pm_instance);
234
-            }
235
-        }
236
-        return $this->_settings_form;
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets the form for all the settings related to this payment method type
242
-     * @return EE_Payment_Method_Form
243
-     */
244
-    abstract function generate_new_settings_form();
245
-
246
-
247
-    /**
248
-     * Sets the form for settings. This may be useful if we have already received
249
-     * a form submission and have form data it in, and want to use it anytime we're showing
250
-     * this payment method type's settings form later in the request
251
-     * @param EE_Payment_Method_Form $form
252
-     */
253
-    public function set_settings_form($form)
254
-    {
255
-        $this->_settings_form = $form;
256
-    }
257
-
258
-
259
-    /**
260
-     * @return boolean
261
-     */
262
-    public function has_billing_form()
263
-    {
264
-        return $this->_has_billing_form;
265
-    }
266
-
267
-
268
-    /**
269
-     * Gets the form for displaying to attendees where they can enter their billing info
270
-     * which will be sent to teh gateway (can be null)
271
-     *
272
-     * @param \EE_Transaction $transaction
273
-     * @param array $extra_args
274
-     * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
-     */
276
-    public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
-    {
278
-        // has billing form already been regenerated ? or overwrite cache?
279
-        if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
-            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
-        }
282
-        //if we know who the attendee is, and this is a billing form
283
-        //that uses attendee info, populate it
284
-        if (
285
-        apply_filters(
286
-            'FHEE__populate_billing_form_fields_from_attendee',
287
-            (
288
-                $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
-                && $transaction instanceof EE_Transaction
290
-                && $transaction->primary_registration() instanceof EE_Registration
291
-                && $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
-            ),
293
-            $this->_billing_form,
294
-            $transaction
295
-        )
296
-        ) {
297
-            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
298
-        }
299
-        return $this->_billing_form;
300
-    }
301
-
302
-
303
-    /**
304
-     * Creates the billing form for this payment method type
305
-     * @param \EE_Transaction $transaction
306
-     * @return \EE_Billing_Info_Form
307
-     */
308
-    abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
-
310
-
311
-    /**
312
-     * apply_billing_form_debug_settings
313
-     * applies debug data to the form
314
-     *
315
-     * @param \EE_Billing_Info_Form $billing_form
316
-     * @return \EE_Billing_Info_Form
317
-     */
318
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
-    {
320
-        return $billing_form;
321
-    }
322
-
323
-
324
-    /**
325
-     * Sets the billing form for this payment method type. You may want to use this
326
-     * if you have form
327
-     * @param EE_Payment_Method $form
328
-     */
329
-    public function set_billing_form($form)
330
-    {
331
-        $this->_billing_form = $form;
332
-    }
333
-
334
-
335
-    /**
336
-     * Returns whether or not this payment method requires HTTPS to be used
337
-     * @return boolean
338
-     */
339
-    function requires_https()
340
-    {
341
-        return $this->_requires_https;
342
-    }
343
-
344
-
345
-    /**
346
-     *
347
-     * @param EE_Transaction $transaction
348
-     * @param float $amount
349
-     * @param EE_Billing_Info_Form $billing_info
350
-     * @param string $return_url
351
-     * @param string $fail_url
352
-     * @param string $method
353
-     * @param bool $by_admin
354
-     * @return EE_Payment
355
-     * @throws EE_Error
356
-     */
357
-    function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
-    {
359
-        // @todo: add surcharge for the payment method, if any
360
-        if ($this->_gateway) {
361
-            //there is a gateway, so we're going to make a payment object
362
-            //but wait! do they already have a payment in progress that we thought was failed?
363
-            $duplicate_properties = array(
364
-                'STS_ID' => EEM_Payment::status_id_failed,
365
-                'TXN_ID' => $transaction->ID(),
366
-                'PMD_ID' => $this->_pm_instance->ID(),
367
-                'PAY_source' => $method,
368
-                'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
-                'PAY_gateway_response' => null,
370
-            );
371
-            $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
-            //if we didn't already have a payment in progress for the same thing,
373
-            //then we actually want to make a new payment
374
-            if (!$payment instanceof EE_Payment) {
375
-                $payment = EE_Payment::new_instance(
376
-                    array_merge(
377
-                        $duplicate_properties,
378
-                        array(
379
-                            'PAY_timestamp' => time(),
380
-                            'PAY_txn_id_chq_nmbr' => null,
381
-                            'PAY_po_number' => null,
382
-                            'PAY_extra_accntng' => null,
383
-                            'PAY_details' => null,
384
-                        )
385
-                    )
386
-                );
387
-            }
388
-            //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
-            $payment->save();
390
-            $billing_values = $this->_get_billing_values_from_form($billing_info);
391
-
392
-            //  Offsite Gateway
393
-            if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
-
395
-                $payment = $this->_gateway->set_redirection_info(
396
-                    $payment,
397
-                    $billing_values,
398
-                    $return_url,
399
-                    EE_Config::instance()->core->txn_page_url(
400
-                        array(
401
-                            'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
-                            'ee_payment_method' => $this->_pm_instance->slug()
403
-                        )
404
-                    ),
405
-                    $fail_url
406
-                );
407
-                $payment->save();
408
-                //  Onsite Gateway
409
-            } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
-
411
-                $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
-                $payment->save();
413
-
414
-            } else {
415
-                throw new EE_Error(
416
-                    sprintf(
417
-                        __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
418
-                        get_class($this),
419
-                        gettype($this->_gateway)
420
-                    )
421
-                );
422
-            }
423
-
424
-        } else {
425
-            // no gateway provided
426
-            // there is no payment. Must be an offline gateway
427
-            // create a payment object anyways, but dont save it
428
-            $payment = EE_Payment::new_instance(
429
-                array(
430
-                    'STS_ID' => EEM_Payment::status_id_pending,
431
-                    'TXN_ID' => $transaction->ID(),
432
-                    'PMD_ID' => $transaction->payment_method_ID(),
433
-                    'PAY_amount' => 0.00,
434
-                    'PAY_timestamp' => time(),
435
-                )
436
-            );
437
-
438
-        }
439
-
440
-        // if there is billing info, clean it and save it now
441
-        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
-            $this->_save_billing_info_to_attendee($billing_info, $transaction);
443
-        }
444
-
445
-        return $payment;
446
-    }
447
-
448
-    /**
449
-     * Gets the values we want to pass onto the gateway. Normally these
450
-     * are just the 'pretty' values, but there may be times the data may need
451
-     * a  little massaging. Proper subsections will become arrays of inputs
452
-     * @param EE_Billing_Info_Form $billing_form
453
-     * @return array
454
-     */
455
-    protected function _get_billing_values_from_form($billing_form)
456
-    {
457
-        if ($billing_form instanceof EE_Form_Section_Proper) {
458
-            return $billing_form->input_pretty_values(true);
459
-        } else {
460
-            return NULL;
461
-        }
462
-    }
463
-
464
-
465
-    /**
466
-     * Handles an instant payment notification when the transaction is known (by default).
467
-     * @param array $req_data
468
-     * @param EE_Transaction $transaction
469
-     * @return EE_Payment
470
-     * @throws EE_Error
471
-     */
472
-    public function handle_ipn($req_data, $transaction)
473
-    {
474
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
-        if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
-            throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
-
478
-        }
479
-        $payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
-        return $payment;
481
-    }
482
-
483
-
484
-    /**
485
-     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
-     * cleans it first.
487
-     * @param EE_Billing_Attendee_Info_Form $billing_form
488
-     * @param EE_Transaction $transaction
489
-     * @return boolean success
490
-     */
491
-    protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
-    {
493
-        if (!$transaction || !$transaction instanceof EE_Transaction) {
494
-            EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
-            return false;
496
-        }
497
-        $primary_reg = $transaction->primary_registration();
498
-        if (!$primary_reg) {
499
-            EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
-            return false;
501
-        }
502
-        $attendee = $primary_reg->attendee();
503
-        if (!$attendee) {
504
-            EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
-            return false;
506
-        }
507
-        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
-
509
-    }
510
-
511
-
512
-    /**
513
-     * Gets the payment this IPN is for. Children may often want to
514
-     * override this to inspect the request
515
-     * @param EE_Transaction $transaction
516
-     * @param array $req_data
517
-     * @return EE_Payment
518
-     */
519
-    protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
-    {
521
-        return $transaction->last_payment();
522
-    }
523
-
524
-
525
-    /**
526
-     * In case generic code cannot provide the payment processor with a specific payment method
527
-     * and transaction, it will try calling this method on each activate payment method.
528
-     * If the payment method is able to identify the request as being for it, it should fetch
529
-     * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
-     * handle the IPN
531
-     * @param array $req_data
532
-     * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
-     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
-     * @throws EE_Error
535
-     */
536
-    public function handle_unclaimed_ipn($req_data = array())
537
-    {
538
-        throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
-    }
540
-
541
-
542
-    /**
543
-     * Logic to be accomplished when the payment attempt is complete.
544
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
-     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
-     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
-     * we're dealing with. Returns that last payment (if there is one)
549
-     *
550
-     * @param EE_Transaction $transaction
551
-     * @return EE_Payment
552
-     */
553
-    public function finalize_payment_for($transaction)
554
-    {
555
-        return $transaction->last_payment();
556
-    }
557
-
558
-
559
-    /**
560
-     * Whether or not this payment method's gateway supports sending refund requests
561
-     * @return boolean
562
-     */
563
-    public function supports_sending_refunds()
564
-    {
565
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
-            return $this->_gateway->supports_sending_refunds();
567
-        } else {
568
-            return false;
569
-        }
570
-    }
571
-
572
-
573
-    /**
574
-     *
575
-     * @param EE_Payment $payment
576
-     * @param array $refund_info
577
-     * @throws EE_Error
578
-     * @return EE_Payment
579
-     */
580
-    public function process_refund(EE_Payment $payment, $refund_info = array())
581
-    {
582
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
-            return $this->_gateway->do_direct_refund($payment, $refund_info);
584
-        } else {
585
-            throw new EE_Error(
586
-                sprintf(
587
-                    __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
-                    get_class($this)
589
-                )
590
-            );
591
-        }
592
-    }
593
-
594
-
595
-    /**
596
-     * Returns one the class's constants onsite,offsite, or offline, depending on this
597
-     * payment method's gateway.
598
-     * @return string
599
-     * @throws EE_Error
600
-     */
601
-    public function payment_occurs()
602
-    {
603
-        if (!$this->_gateway) {
604
-            return EE_PMT_Base::offline;
605
-        } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
-            return EE_PMT_Base::onsite;
607
-        } elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
-            return EE_PMT_Base::offsite;
609
-        } else {
610
-            throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * For adding any html output ab ove the payment overview.
617
-     * Many gateways won't want ot display anything, so this function just returns an empty string.
618
-     * Other gateways may want to override this, such as offline gateways.
619
-     * @param EE_Payment $payment
620
-     * @return string
621
-     */
622
-    public function payment_overview_content(EE_Payment $payment)
623
-    {
624
-        return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
-    }
626
-
627
-
628
-    /**
629
-     * @return array where keys are the help tab name,
630
-     * values are: array {
631
-     * @type string $title i18n name for the help tab
632
-     * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
-     * @type array $template_args any arguments you want passed to the template file while rendering.
634
-     *                Keys will be variable names and values with be their values.
635
-     */
636
-    public function help_tabs_config()
637
-    {
638
-        return array();
639
-    }
640
-
641
-
642
-    /**
643
-     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
-     * the payment method's table's PMT_type column)
645
-     * @return string
646
-     */
647
-    public function system_name()
648
-    {
649
-        $classname = get_class($this);
650
-        return str_replace("EE_PMT_", '', $classname);
651
-    }
652
-
653
-
654
-    /**
655
-     * A pretty i18n version of the PMT name
656
-     * @return string
657
-     */
658
-    public function pretty_name()
659
-    {
660
-        return $this->_pretty_name;
661
-    }
662
-
663
-
664
-    /**
665
-     * Gets the default absolute URL to the payment method type's button
666
-     * @return string
667
-     */
668
-    public function default_button_url()
669
-    {
670
-        return $this->_default_button_url;
671
-    }
672
-
673
-
674
-    /**
675
-     * Gets the gateway used by this payment method (if any)
676
-     * @return EE_Gateway
677
-     */
678
-    public function get_gateway()
679
-    {
680
-        return $this->_gateway;
681
-    }
682
-
683
-
684
-    /**
685
-     * @return string html for the link to a help tab
686
-     */
687
-    public function get_help_tab_link()
688
-    {
689
-        return EEH_Template::get_help_tab_link($this->get_help_tab_name());
690
-    }
691
-
692
-
693
-    /**
694
-     * Returns the name of the help tab for this PMT
695
-     * @return string
696
-     */
697
-    public function get_help_tab_name()
698
-    {
699
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
700
-    }
701
-
702
-    /**
703
-     * The name of the wp capability that should be associated with the usage of
704
-     * this PMT by an admin
705
-     * @return string
706
-     */
707
-    public function cap_name()
708
-    {
709
-        return 'ee_payment_method_' . strtolower($this->system_name());
710
-    }
711
-
712
-    /**
713
-     * Called by client code to tell the gateway that if it wants to change
714
-     * the transaction or line items or registrations related to teh payment it already
715
-     * processed (we think, but possibly not) that now's the time to do it.
716
-     * It is expected that gateways will store any info they need for this on the PAY_details,
717
-     * or maybe an extra meta value
718
-     * @param EE_Payment $payment
719
-     * @return void
720
-     */
721
-    public function update_txn_based_on_payment($payment)
722
-    {
723
-        if ($this->_gateway instanceof EE_Gateway) {
724
-            $this->_gateway->update_txn_based_on_payment($payment);
725
-        }
726
-    }
727
-
728
-    /**
729
-     * Returns a string of HTML describing this payment method type for an admin,
730
-     * primarily intended for them to read before activating it.
731
-     * The easiest way to set this is to create a folder 'templates' alongside
732
-     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
733
-     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
734
-     * then you'd create a file named "templates" in the same folder as it, and name the file
735
-     * "foo_bar_intro.template.php", and its content will be returned by this method
736
-     * @return string
737
-     */
738
-    public function introductory_html()
739
-    {
740
-        return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741
-    }
24
+	const onsite = 'on-site';
25
+	const offsite = 'off-site';
26
+	const offline = 'off-line';
27
+
28
+	/**
29
+	 * @var EE_Payment_Method
30
+	 */
31
+	protected $_pm_instance = NULL;
32
+
33
+	/**
34
+	 * @var boolean
35
+	 */
36
+	protected $_requires_https = FALSE;
37
+
38
+	/**
39
+	 * @var boolean
40
+	 */
41
+	protected $_has_billing_form;
42
+
43
+	/**
44
+	 * @var EE_Gateway
45
+	 */
46
+	protected $_gateway = NULL;
47
+
48
+	/**
49
+	 * @var EE_Payment_Method_Form
50
+	 */
51
+	protected $_settings_form = NULL;
52
+
53
+	/**
54
+	 * @var EE_Form_Section_Proper
55
+	 */
56
+	protected $_billing_form = NULL;
57
+
58
+	/**
59
+	 * @var boolean
60
+	 */
61
+	protected $_cache_billing_form = TRUE;
62
+
63
+	/**
64
+	 * String of the absolute path to the folder containing this file, with a trailing slash.
65
+	 * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
+	 * @var string
67
+	 */
68
+	protected $_file_folder = NULL;
69
+
70
+	/**
71
+	 * String to the absolute URL to this file (useful for getting its web-accessible resources
72
+	 * like images, js, or css)
73
+	 * @var string
74
+	 */
75
+	protected $_file_url = NULL;
76
+
77
+	/**
78
+	 * Pretty name for the payment method
79
+	 * @var string
80
+	 */
81
+	protected $_pretty_name = NULL;
82
+
83
+	/**
84
+	 *
85
+	 * @var string
86
+	 */
87
+	protected $_default_button_url = NULL;
88
+
89
+	/**
90
+	 *
91
+	 * @var string
92
+	 */
93
+	protected $_default_description = NULL;
94
+
95
+
96
+	/**
97
+	 *
98
+	 * @param EE_Payment_Method $pm_instance
99
+	 * @throws EE_Error
100
+	 * @return EE_PMT_Base
101
+	 */
102
+	function __construct($pm_instance = NULL)
103
+	{
104
+		if ($pm_instance instanceof EE_Payment_Method) {
105
+			$this->set_instance($pm_instance);
106
+		}
107
+		if ($this->_gateway) {
108
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
109
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
+			$this->_gateway->set_template_helper(new EEH_Template());
111
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
+			$this->_gateway->set_money_helper(new EEH_Money());
113
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
+			do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
+		}
117
+		if (!isset($this->_has_billing_form)) {
118
+			// by default, On Site gateways have a billing form
119
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
+				$this->set_has_billing_form(true);
121
+			} else {
122
+				$this->set_has_billing_form(false);
123
+			}
124
+		}
125
+
126
+		if (!$this->_pretty_name) {
127
+			throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
+		}
129
+		//if the child didn't specify a default button, use the credit card one
130
+		if ($this->_default_button_url === NULL) {
131
+			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
+		}
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param boolean $has_billing_form
138
+	 */
139
+	public function set_has_billing_form($has_billing_form)
140
+	{
141
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
+	}
143
+
144
+
145
+	/**
146
+	 * sets the file_folder property
147
+	 */
148
+	protected function _set_file_folder()
149
+	{
150
+		$reflector = new ReflectionClass(get_class($this));
151
+		$fn = $reflector->getFileName();
152
+		$this->_file_folder = dirname($fn) . DS;
153
+	}
154
+
155
+
156
+	/**
157
+	 * sets the file URL with a trailing slash for this PMT
158
+	 */
159
+	protected function _set_file_url()
160
+	{
161
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
+		$this->_file_url = $file_path;
165
+	}
166
+
167
+	/**
168
+	 * Gets the default description on all payment methods of this type
169
+	 * @return string
170
+	 */
171
+	public function default_description()
172
+	{
173
+		return $this->_default_description;
174
+	}
175
+
176
+
177
+	/**
178
+	 * Returns the folder containing the PMT child class, with a trailing slash
179
+	 * @return string
180
+	 */
181
+	public function file_folder()
182
+	{
183
+		if (!$this->_file_folder) {
184
+			$this->_set_file_folder();
185
+		}
186
+		return $this->_file_folder;
187
+	}
188
+
189
+
190
+	/**
191
+	 * @return string
192
+	 */
193
+	public function file_url()
194
+	{
195
+		if (!$this->_file_url) {
196
+			$this->_set_file_url();
197
+		}
198
+		return $this->_file_url;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Sets the payment method instance this payment method type is for.
204
+	 * Its important teh payment method instance is set before
205
+	 * @param EE_Payment_Method $payment_method_instance
206
+	 */
207
+	function set_instance($payment_method_instance)
208
+	{
209
+		$this->_pm_instance = $payment_method_instance;
210
+		//if they have already requested the settings form, make sure its
211
+		//data matches this model object
212
+		if ($this->_settings_form) {
213
+			$this->settings_form()->populate_model_obj($payment_method_instance);
214
+		}
215
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
+			$this->_gateway->set_settings($payment_method_instance->settings_array());
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * Gets teh form for displaying to admins where they setup the payment method
223
+	 * @return EE_Payment_Method_Form
224
+	 */
225
+	function settings_form()
226
+	{
227
+		if (!$this->_settings_form) {
228
+			$this->_settings_form = $this->generate_new_settings_form();
229
+			$this->_settings_form->set_payment_method_type($this);
230
+			//if we have already assigned a model object to this pmt, make
231
+			//sure its reflected in teh form we just generated
232
+			if ($this->_pm_instance) {
233
+				$this->_settings_form->populate_model_obj($this->_pm_instance);
234
+			}
235
+		}
236
+		return $this->_settings_form;
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets the form for all the settings related to this payment method type
242
+	 * @return EE_Payment_Method_Form
243
+	 */
244
+	abstract function generate_new_settings_form();
245
+
246
+
247
+	/**
248
+	 * Sets the form for settings. This may be useful if we have already received
249
+	 * a form submission and have form data it in, and want to use it anytime we're showing
250
+	 * this payment method type's settings form later in the request
251
+	 * @param EE_Payment_Method_Form $form
252
+	 */
253
+	public function set_settings_form($form)
254
+	{
255
+		$this->_settings_form = $form;
256
+	}
257
+
258
+
259
+	/**
260
+	 * @return boolean
261
+	 */
262
+	public function has_billing_form()
263
+	{
264
+		return $this->_has_billing_form;
265
+	}
266
+
267
+
268
+	/**
269
+	 * Gets the form for displaying to attendees where they can enter their billing info
270
+	 * which will be sent to teh gateway (can be null)
271
+	 *
272
+	 * @param \EE_Transaction $transaction
273
+	 * @param array $extra_args
274
+	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
+	 */
276
+	public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
+	{
278
+		// has billing form already been regenerated ? or overwrite cache?
279
+		if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
+		}
282
+		//if we know who the attendee is, and this is a billing form
283
+		//that uses attendee info, populate it
284
+		if (
285
+		apply_filters(
286
+			'FHEE__populate_billing_form_fields_from_attendee',
287
+			(
288
+				$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
+				&& $transaction instanceof EE_Transaction
290
+				&& $transaction->primary_registration() instanceof EE_Registration
291
+				&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
+			),
293
+			$this->_billing_form,
294
+			$transaction
295
+		)
296
+		) {
297
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
298
+		}
299
+		return $this->_billing_form;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Creates the billing form for this payment method type
305
+	 * @param \EE_Transaction $transaction
306
+	 * @return \EE_Billing_Info_Form
307
+	 */
308
+	abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
+
310
+
311
+	/**
312
+	 * apply_billing_form_debug_settings
313
+	 * applies debug data to the form
314
+	 *
315
+	 * @param \EE_Billing_Info_Form $billing_form
316
+	 * @return \EE_Billing_Info_Form
317
+	 */
318
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
+	{
320
+		return $billing_form;
321
+	}
322
+
323
+
324
+	/**
325
+	 * Sets the billing form for this payment method type. You may want to use this
326
+	 * if you have form
327
+	 * @param EE_Payment_Method $form
328
+	 */
329
+	public function set_billing_form($form)
330
+	{
331
+		$this->_billing_form = $form;
332
+	}
333
+
334
+
335
+	/**
336
+	 * Returns whether or not this payment method requires HTTPS to be used
337
+	 * @return boolean
338
+	 */
339
+	function requires_https()
340
+	{
341
+		return $this->_requires_https;
342
+	}
343
+
344
+
345
+	/**
346
+	 *
347
+	 * @param EE_Transaction $transaction
348
+	 * @param float $amount
349
+	 * @param EE_Billing_Info_Form $billing_info
350
+	 * @param string $return_url
351
+	 * @param string $fail_url
352
+	 * @param string $method
353
+	 * @param bool $by_admin
354
+	 * @return EE_Payment
355
+	 * @throws EE_Error
356
+	 */
357
+	function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
+	{
359
+		// @todo: add surcharge for the payment method, if any
360
+		if ($this->_gateway) {
361
+			//there is a gateway, so we're going to make a payment object
362
+			//but wait! do they already have a payment in progress that we thought was failed?
363
+			$duplicate_properties = array(
364
+				'STS_ID' => EEM_Payment::status_id_failed,
365
+				'TXN_ID' => $transaction->ID(),
366
+				'PMD_ID' => $this->_pm_instance->ID(),
367
+				'PAY_source' => $method,
368
+				'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
+				'PAY_gateway_response' => null,
370
+			);
371
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
+			//if we didn't already have a payment in progress for the same thing,
373
+			//then we actually want to make a new payment
374
+			if (!$payment instanceof EE_Payment) {
375
+				$payment = EE_Payment::new_instance(
376
+					array_merge(
377
+						$duplicate_properties,
378
+						array(
379
+							'PAY_timestamp' => time(),
380
+							'PAY_txn_id_chq_nmbr' => null,
381
+							'PAY_po_number' => null,
382
+							'PAY_extra_accntng' => null,
383
+							'PAY_details' => null,
384
+						)
385
+					)
386
+				);
387
+			}
388
+			//make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
+			$payment->save();
390
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
391
+
392
+			//  Offsite Gateway
393
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
+
395
+				$payment = $this->_gateway->set_redirection_info(
396
+					$payment,
397
+					$billing_values,
398
+					$return_url,
399
+					EE_Config::instance()->core->txn_page_url(
400
+						array(
401
+							'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
+							'ee_payment_method' => $this->_pm_instance->slug()
403
+						)
404
+					),
405
+					$fail_url
406
+				);
407
+				$payment->save();
408
+				//  Onsite Gateway
409
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
+
411
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
+				$payment->save();
413
+
414
+			} else {
415
+				throw new EE_Error(
416
+					sprintf(
417
+						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
418
+						get_class($this),
419
+						gettype($this->_gateway)
420
+					)
421
+				);
422
+			}
423
+
424
+		} else {
425
+			// no gateway provided
426
+			// there is no payment. Must be an offline gateway
427
+			// create a payment object anyways, but dont save it
428
+			$payment = EE_Payment::new_instance(
429
+				array(
430
+					'STS_ID' => EEM_Payment::status_id_pending,
431
+					'TXN_ID' => $transaction->ID(),
432
+					'PMD_ID' => $transaction->payment_method_ID(),
433
+					'PAY_amount' => 0.00,
434
+					'PAY_timestamp' => time(),
435
+				)
436
+			);
437
+
438
+		}
439
+
440
+		// if there is billing info, clean it and save it now
441
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
443
+		}
444
+
445
+		return $payment;
446
+	}
447
+
448
+	/**
449
+	 * Gets the values we want to pass onto the gateway. Normally these
450
+	 * are just the 'pretty' values, but there may be times the data may need
451
+	 * a  little massaging. Proper subsections will become arrays of inputs
452
+	 * @param EE_Billing_Info_Form $billing_form
453
+	 * @return array
454
+	 */
455
+	protected function _get_billing_values_from_form($billing_form)
456
+	{
457
+		if ($billing_form instanceof EE_Form_Section_Proper) {
458
+			return $billing_form->input_pretty_values(true);
459
+		} else {
460
+			return NULL;
461
+		}
462
+	}
463
+
464
+
465
+	/**
466
+	 * Handles an instant payment notification when the transaction is known (by default).
467
+	 * @param array $req_data
468
+	 * @param EE_Transaction $transaction
469
+	 * @return EE_Payment
470
+	 * @throws EE_Error
471
+	 */
472
+	public function handle_ipn($req_data, $transaction)
473
+	{
474
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
+		if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
+			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
+
478
+		}
479
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
+		return $payment;
481
+	}
482
+
483
+
484
+	/**
485
+	 * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
+	 * cleans it first.
487
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
488
+	 * @param EE_Transaction $transaction
489
+	 * @return boolean success
490
+	 */
491
+	protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
+	{
493
+		if (!$transaction || !$transaction instanceof EE_Transaction) {
494
+			EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
+			return false;
496
+		}
497
+		$primary_reg = $transaction->primary_registration();
498
+		if (!$primary_reg) {
499
+			EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
+			return false;
501
+		}
502
+		$attendee = $primary_reg->attendee();
503
+		if (!$attendee) {
504
+			EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
+			return false;
506
+		}
507
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
+
509
+	}
510
+
511
+
512
+	/**
513
+	 * Gets the payment this IPN is for. Children may often want to
514
+	 * override this to inspect the request
515
+	 * @param EE_Transaction $transaction
516
+	 * @param array $req_data
517
+	 * @return EE_Payment
518
+	 */
519
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
+	{
521
+		return $transaction->last_payment();
522
+	}
523
+
524
+
525
+	/**
526
+	 * In case generic code cannot provide the payment processor with a specific payment method
527
+	 * and transaction, it will try calling this method on each activate payment method.
528
+	 * If the payment method is able to identify the request as being for it, it should fetch
529
+	 * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
+	 * handle the IPN
531
+	 * @param array $req_data
532
+	 * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
+	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
+	 * @throws EE_Error
535
+	 */
536
+	public function handle_unclaimed_ipn($req_data = array())
537
+	{
538
+		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
+	}
540
+
541
+
542
+	/**
543
+	 * Logic to be accomplished when the payment attempt is complete.
544
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
+	 * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
+	 * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
+	 * we're dealing with. Returns that last payment (if there is one)
549
+	 *
550
+	 * @param EE_Transaction $transaction
551
+	 * @return EE_Payment
552
+	 */
553
+	public function finalize_payment_for($transaction)
554
+	{
555
+		return $transaction->last_payment();
556
+	}
557
+
558
+
559
+	/**
560
+	 * Whether or not this payment method's gateway supports sending refund requests
561
+	 * @return boolean
562
+	 */
563
+	public function supports_sending_refunds()
564
+	{
565
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
+			return $this->_gateway->supports_sending_refunds();
567
+		} else {
568
+			return false;
569
+		}
570
+	}
571
+
572
+
573
+	/**
574
+	 *
575
+	 * @param EE_Payment $payment
576
+	 * @param array $refund_info
577
+	 * @throws EE_Error
578
+	 * @return EE_Payment
579
+	 */
580
+	public function process_refund(EE_Payment $payment, $refund_info = array())
581
+	{
582
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
584
+		} else {
585
+			throw new EE_Error(
586
+				sprintf(
587
+					__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
+					get_class($this)
589
+				)
590
+			);
591
+		}
592
+	}
593
+
594
+
595
+	/**
596
+	 * Returns one the class's constants onsite,offsite, or offline, depending on this
597
+	 * payment method's gateway.
598
+	 * @return string
599
+	 * @throws EE_Error
600
+	 */
601
+	public function payment_occurs()
602
+	{
603
+		if (!$this->_gateway) {
604
+			return EE_PMT_Base::offline;
605
+		} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
+			return EE_PMT_Base::onsite;
607
+		} elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
+			return EE_PMT_Base::offsite;
609
+		} else {
610
+			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * For adding any html output ab ove the payment overview.
617
+	 * Many gateways won't want ot display anything, so this function just returns an empty string.
618
+	 * Other gateways may want to override this, such as offline gateways.
619
+	 * @param EE_Payment $payment
620
+	 * @return string
621
+	 */
622
+	public function payment_overview_content(EE_Payment $payment)
623
+	{
624
+		return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
+	}
626
+
627
+
628
+	/**
629
+	 * @return array where keys are the help tab name,
630
+	 * values are: array {
631
+	 * @type string $title i18n name for the help tab
632
+	 * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
+	 * @type array $template_args any arguments you want passed to the template file while rendering.
634
+	 *                Keys will be variable names and values with be their values.
635
+	 */
636
+	public function help_tabs_config()
637
+	{
638
+		return array();
639
+	}
640
+
641
+
642
+	/**
643
+	 * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
+	 * the payment method's table's PMT_type column)
645
+	 * @return string
646
+	 */
647
+	public function system_name()
648
+	{
649
+		$classname = get_class($this);
650
+		return str_replace("EE_PMT_", '', $classname);
651
+	}
652
+
653
+
654
+	/**
655
+	 * A pretty i18n version of the PMT name
656
+	 * @return string
657
+	 */
658
+	public function pretty_name()
659
+	{
660
+		return $this->_pretty_name;
661
+	}
662
+
663
+
664
+	/**
665
+	 * Gets the default absolute URL to the payment method type's button
666
+	 * @return string
667
+	 */
668
+	public function default_button_url()
669
+	{
670
+		return $this->_default_button_url;
671
+	}
672
+
673
+
674
+	/**
675
+	 * Gets the gateway used by this payment method (if any)
676
+	 * @return EE_Gateway
677
+	 */
678
+	public function get_gateway()
679
+	{
680
+		return $this->_gateway;
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return string html for the link to a help tab
686
+	 */
687
+	public function get_help_tab_link()
688
+	{
689
+		return EEH_Template::get_help_tab_link($this->get_help_tab_name());
690
+	}
691
+
692
+
693
+	/**
694
+	 * Returns the name of the help tab for this PMT
695
+	 * @return string
696
+	 */
697
+	public function get_help_tab_name()
698
+	{
699
+		return 'ee_' . strtolower($this->system_name()) . '_help_tab';
700
+	}
701
+
702
+	/**
703
+	 * The name of the wp capability that should be associated with the usage of
704
+	 * this PMT by an admin
705
+	 * @return string
706
+	 */
707
+	public function cap_name()
708
+	{
709
+		return 'ee_payment_method_' . strtolower($this->system_name());
710
+	}
711
+
712
+	/**
713
+	 * Called by client code to tell the gateway that if it wants to change
714
+	 * the transaction or line items or registrations related to teh payment it already
715
+	 * processed (we think, but possibly not) that now's the time to do it.
716
+	 * It is expected that gateways will store any info they need for this on the PAY_details,
717
+	 * or maybe an extra meta value
718
+	 * @param EE_Payment $payment
719
+	 * @return void
720
+	 */
721
+	public function update_txn_based_on_payment($payment)
722
+	{
723
+		if ($this->_gateway instanceof EE_Gateway) {
724
+			$this->_gateway->update_txn_based_on_payment($payment);
725
+		}
726
+	}
727
+
728
+	/**
729
+	 * Returns a string of HTML describing this payment method type for an admin,
730
+	 * primarily intended for them to read before activating it.
731
+	 * The easiest way to set this is to create a folder 'templates' alongside
732
+	 * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
733
+	 * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
734
+	 * then you'd create a file named "templates" in the same folder as it, and name the file
735
+	 * "foo_bar_intro.template.php", and its content will be returned by this method
736
+	 * @return string
737
+	 */
738
+	public function introductory_html()
739
+	{
740
+		return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741
+	}
742 742
 
743 743
 
744 744
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115 115
             do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116 116
         }
117
-        if (!isset($this->_has_billing_form)) {
117
+        if ( ! isset($this->_has_billing_form)) {
118 118
             // by default, On Site gateways have a billing form
119 119
             if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120 120
                 $this->set_has_billing_form(true);
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
             }
124 124
         }
125 125
 
126
-        if (!$this->_pretty_name) {
126
+        if ( ! $this->_pretty_name) {
127 127
             throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128 128
         }
129 129
         //if the child didn't specify a default button, use the credit card one
130 130
         if ($this->_default_button_url === NULL) {
131
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
131
+            $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png';
132 132
         }
133 133
     }
134 134
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     {
150 150
         $reflector = new ReflectionClass(get_class($this));
151 151
         $fn = $reflector->getFileName();
152
-        $this->_file_folder = dirname($fn) . DS;
152
+        $this->_file_folder = dirname($fn).DS;
153 153
     }
154 154
 
155 155
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function file_folder()
182 182
     {
183
-        if (!$this->_file_folder) {
183
+        if ( ! $this->_file_folder) {
184 184
             $this->_set_file_folder();
185 185
         }
186 186
         return $this->_file_folder;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function file_url()
194 194
     {
195
-        if (!$this->_file_url) {
195
+        if ( ! $this->_file_url) {
196 196
             $this->_set_file_url();
197 197
         }
198 198
         return $this->_file_url;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     function settings_form()
226 226
     {
227
-        if (!$this->_settings_form) {
227
+        if ( ! $this->_settings_form) {
228 228
             $this->_settings_form = $this->generate_new_settings_form();
229 229
             $this->_settings_form->set_payment_method_type($this);
230 230
             //if we have already assigned a model object to this pmt, make
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277 277
     {
278 278
         // has billing form already been regenerated ? or overwrite cache?
279
-        if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
279
+        if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
280 280
             $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281 281
         }
282 282
         //if we know who the attendee is, and this is a billing form
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
             $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372 372
             //if we didn't already have a payment in progress for the same thing,
373 373
             //then we actually want to make a new payment
374
-            if (!$payment instanceof EE_Payment) {
374
+            if ( ! $payment instanceof EE_Payment) {
375 375
                 $payment = EE_Payment::new_instance(
376 376
                     array_merge(
377 377
                         $duplicate_properties,
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
     public function handle_ipn($req_data, $transaction)
473 473
     {
474 474
         $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
-        if (!$this->_gateway instanceof EE_Offsite_Gateway) {
475
+        if ( ! $this->_gateway instanceof EE_Offsite_Gateway) {
476 476
             throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477 477
 
478 478
         }
@@ -490,17 +490,17 @@  discard block
 block discarded – undo
490 490
      */
491 491
     protected function _save_billing_info_to_attendee($billing_form, $transaction)
492 492
     {
493
-        if (!$transaction || !$transaction instanceof EE_Transaction) {
493
+        if ( ! $transaction || ! $transaction instanceof EE_Transaction) {
494 494
             EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495 495
             return false;
496 496
         }
497 497
         $primary_reg = $transaction->primary_registration();
498
-        if (!$primary_reg) {
498
+        if ( ! $primary_reg) {
499 499
             EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500 500
             return false;
501 501
         }
502 502
         $attendee = $primary_reg->attendee();
503
-        if (!$attendee) {
503
+        if ( ! $attendee) {
504 504
             EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505 505
             return false;
506 506
         }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
      */
601 601
     public function payment_occurs()
602 602
     {
603
-        if (!$this->_gateway) {
603
+        if ( ! $this->_gateway) {
604 604
             return EE_PMT_Base::offline;
605 605
         } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606 606
             return EE_PMT_Base::onsite;
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
      */
622 622
     public function payment_overview_content(EE_Payment $payment)
623 623
     {
624
-        return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
624
+        return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625 625
     }
626 626
 
627 627
 
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
      */
697 697
     public function get_help_tab_name()
698 698
     {
699
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
699
+        return 'ee_'.strtolower($this->system_name()).'_help_tab';
700 700
     }
701 701
 
702 702
     /**
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
      */
707 707
     public function cap_name()
708 708
     {
709
-        return 'ee_payment_method_' . strtolower($this->system_name());
709
+        return 'ee_payment_method_'.strtolower($this->system_name());
710 710
     }
711 711
 
712 712
     /**
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
      */
738 738
     public function introductory_html()
739 739
     {
740
-        return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
740
+        return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741 741
     }
742 742
 
743 743
 
Please login to merge, or discard this patch.