@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * allowed) |
561 | 561 | * |
562 | 562 | * @param string $datetime_string mysql timestamp in UTC |
563 | - * @return mixed null | DateTime |
|
563 | + * @return null|DbSafeDateTime null | DateTime |
|
564 | 564 | * @throws \EE_Error |
565 | 565 | */ |
566 | 566 | public function prepare_for_set_from_db($datetime_string) |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @param \DateTimeZone $DateTimeZone |
714 | 714 | * @param int $time |
715 | - * @return mixed |
|
715 | + * @return integer |
|
716 | 716 | * @throws \DomainException |
717 | 717 | */ |
718 | 718 | public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | /** |
754 | 754 | * Gets the default datetime object from the field's default time |
755 | 755 | * @since 4.9.66.p |
756 | - * @return DbSafeDateTime|null |
|
756 | + * @return DateTime|null |
|
757 | 757 | * @throws InvalidArgumentException |
758 | 758 | * @throws InvalidDataTypeException |
759 | 759 | * @throws InvalidInterfaceException |
@@ -15,769 +15,769 @@ |
||
15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | - * |
|
22 | - * @type string unix_timestamp_regex |
|
23 | - */ |
|
24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type string mysql_timestamp_format |
|
28 | - */ |
|
29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @type string mysql_date_format |
|
33 | - */ |
|
34 | - const mysql_date_format = 'Y-m-d'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @type string mysql_time_format |
|
38 | - */ |
|
39 | - const mysql_time_format = 'H:i:s'; |
|
40 | - |
|
41 | - /** |
|
42 | - * Const for using in the default value. If the field's default is set to this, |
|
43 | - * then we will return the time of calling `get_default_value()`, not |
|
44 | - * just the current time at construction |
|
45 | - */ |
|
46 | - const now = 'now'; |
|
47 | - |
|
48 | - /** |
|
49 | - * The following properties hold the default formats for date and time. |
|
50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | - * However they can also be overridden later by the set_format() method |
|
52 | - * (and corresponding set_date_format, set_time_format methods); |
|
53 | - */ |
|
54 | - /** |
|
55 | - * @type string $_date_format |
|
56 | - */ |
|
57 | - protected $_date_format = ''; |
|
58 | - |
|
59 | - /** |
|
60 | - * @type string $_time_format |
|
61 | - */ |
|
62 | - protected $_time_format = ''; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type string $_pretty_date_format |
|
66 | - */ |
|
67 | - protected $_pretty_date_format = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type string $_pretty_time_format |
|
71 | - */ |
|
72 | - protected $_pretty_time_format = ''; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type DateTimeZone $_DateTimeZone |
|
76 | - */ |
|
77 | - protected $_DateTimeZone; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | - */ |
|
82 | - protected $_UTC_DateTimeZone; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
86 | - */ |
|
87 | - protected $_blog_DateTimeZone; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | - * and time returned via getters. |
|
94 | - * |
|
95 | - * @var mixed (null|string) |
|
96 | - */ |
|
97 | - protected $_date_time_output; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * timezone string |
|
102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - protected $_timezone_string; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | - * offsets for comparison purposes). |
|
114 | - * |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - protected $_blog_offset; |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $table_column |
|
123 | - * @param string $nice_name |
|
124 | - * @param bool $nullable |
|
125 | - * @param string $default_value |
|
126 | - * @param string $timezone_string |
|
127 | - * @param string $date_format |
|
128 | - * @param string $time_format |
|
129 | - * @param string $pretty_date_format |
|
130 | - * @param string $pretty_time_format |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $table_column, |
|
136 | - $nice_name, |
|
137 | - $nullable, |
|
138 | - $default_value, |
|
139 | - $timezone_string = '', |
|
140 | - $date_format = '', |
|
141 | - $time_format = '', |
|
142 | - $pretty_date_format = '', |
|
143 | - $pretty_time_format = '' |
|
144 | - ) { |
|
145 | - |
|
146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | - |
|
151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | - $this->set_timezone($timezone_string); |
|
153 | - $this->setSchemaFormat('date-time'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return DateTimeZone |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public function get_UTC_DateTimeZone() |
|
162 | - { |
|
163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | - ? $this->_UTC_DateTimeZone |
|
165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return DateTimeZone |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - public function get_blog_DateTimeZone() |
|
174 | - { |
|
175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | - ? $this->_blog_DateTimeZone |
|
177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | - * |
|
184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | - * timestamp |
|
186 | - * @return DateTime |
|
187 | - */ |
|
188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | - { |
|
190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | - * |
|
198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | - * @return string The final assembled format string. |
|
200 | - */ |
|
201 | - protected function _get_date_time_output($pretty = false) |
|
202 | - { |
|
203 | - |
|
204 | - switch ($this->_date_time_output) { |
|
205 | - case 'time': |
|
206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | - break; |
|
208 | - |
|
209 | - case 'date': |
|
210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | - break; |
|
212 | - |
|
213 | - default: |
|
214 | - return $pretty |
|
215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | - * returned (using the format properties) |
|
224 | - * |
|
225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
226 | - * Any other value will be set but will always result |
|
227 | - * in both 'date' and 'time' being returned. |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - public function set_date_time_output($what = null) |
|
231 | - { |
|
232 | - $this->_date_time_output = $what; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | - * We also set some other properties in this method. |
|
241 | - * |
|
242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
243 | - * http://www.php.net/manual/en/timezones.php |
|
244 | - * @return void |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function set_timezone($timezone_string) |
|
250 | - { |
|
251 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
252 | - // leave the timezone AS-IS if we already have one and |
|
253 | - // the function arg didn't provide one |
|
254 | - return; |
|
255 | - } |
|
256 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
257 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
258 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * _create_timezone_object_from_timezone_name |
|
264 | - * |
|
265 | - * @access protected |
|
266 | - * @param string $timezone_string |
|
267 | - * @return \DateTimeZone |
|
268 | - * @throws InvalidArgumentException |
|
269 | - * @throws InvalidDataTypeException |
|
270 | - * @throws InvalidInterfaceException |
|
271 | - */ |
|
272 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
273 | - { |
|
274 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * This just returns whatever is set for the current timezone. |
|
280 | - * |
|
281 | - * @access public |
|
282 | - * @return string timezone string |
|
283 | - */ |
|
284 | - public function get_timezone() |
|
285 | - { |
|
286 | - return $this->_timezone_string; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * set the $_date_format property |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
295 | - * @param bool $pretty Whether to set pretty format or not. |
|
296 | - * @return void |
|
297 | - */ |
|
298 | - public function set_date_format($format, $pretty = false) |
|
299 | - { |
|
300 | - if ($pretty) { |
|
301 | - $this->_pretty_date_format = $format; |
|
302 | - } else { |
|
303 | - $this->_date_format = $format; |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * return the $_date_format property value. |
|
310 | - * |
|
311 | - * @param bool $pretty Whether to get pretty format or not. |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function get_date_format($pretty = false) |
|
315 | - { |
|
316 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * set the $_time_format property |
|
322 | - * |
|
323 | - * @access public |
|
324 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
325 | - * @param bool $pretty Whether to set pretty format or not. |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public function set_time_format($format, $pretty = false) |
|
329 | - { |
|
330 | - if ($pretty) { |
|
331 | - $this->_pretty_time_format = $format; |
|
332 | - } else { |
|
333 | - $this->_time_format = $format; |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * return the $_time_format property value. |
|
340 | - * |
|
341 | - * @param bool $pretty Whether to get pretty format or not. |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public function get_time_format($pretty = false) |
|
345 | - { |
|
346 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * set the $_pretty_date_format property |
|
352 | - * |
|
353 | - * @access public |
|
354 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
355 | - * @return void |
|
356 | - */ |
|
357 | - public function set_pretty_date_format($format) |
|
358 | - { |
|
359 | - $this->_pretty_date_format = $format; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * set the $_pretty_time_format property |
|
365 | - * |
|
366 | - * @access public |
|
367 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - public function set_pretty_time_format($format) |
|
371 | - { |
|
372 | - $this->_pretty_time_format = $format; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Only sets the time portion of the datetime. |
|
378 | - * |
|
379 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
380 | - * @param DateTime $current current DateTime object for the datetime field |
|
381 | - * @return DateTime |
|
382 | - */ |
|
383 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
384 | - { |
|
385 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
386 | - // Otherwise parse the string. |
|
387 | - if ($time_to_set_string instanceof DateTime) { |
|
388 | - $parsed = array( |
|
389 | - 'hour' => $time_to_set_string->format('H'), |
|
390 | - 'minute' => $time_to_set_string->format('i'), |
|
391 | - 'second' => $time_to_set_string->format('s'), |
|
392 | - ); |
|
393 | - } else { |
|
394 | - // parse incoming string |
|
395 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
396 | - } |
|
397 | - EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
398 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Only sets the date portion of the datetime. |
|
404 | - * |
|
405 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
406 | - * @param DateTime $current current DateTime object for the datetime field |
|
407 | - * @return DateTime |
|
408 | - */ |
|
409 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
410 | - { |
|
411 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
412 | - // Otherwise parse the string. |
|
413 | - if ($date_to_set_string instanceof DateTime) { |
|
414 | - $parsed = array( |
|
415 | - 'year' => $date_to_set_string->format('Y'), |
|
416 | - 'month' => $date_to_set_string->format('m'), |
|
417 | - 'day' => $date_to_set_string->format('d'), |
|
418 | - ); |
|
419 | - } else { |
|
420 | - // parse incoming string |
|
421 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
422 | - } |
|
423 | - EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
424 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
430 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
431 | - * |
|
432 | - * @param DateTime $DateTime |
|
433 | - * @return string formatted date time for given timezone |
|
434 | - * @throws \EE_Error |
|
435 | - */ |
|
436 | - public function prepare_for_get($DateTime) |
|
437 | - { |
|
438 | - return $this->_prepare_for_display($DateTime); |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
444 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
445 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
446 | - * abbreviation to the date_string. |
|
447 | - * |
|
448 | - * @param mixed $DateTime |
|
449 | - * @param null $schema |
|
450 | - * @return string |
|
451 | - * @throws \EE_Error |
|
452 | - */ |
|
453 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
454 | - { |
|
455 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
461 | - * timezone). |
|
462 | - * |
|
463 | - * @param DateTime $DateTime |
|
464 | - * @param bool|string $schema |
|
465 | - * @return string |
|
466 | - * @throws \EE_Error |
|
467 | - */ |
|
468 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
469 | - { |
|
470 | - if (! $DateTime instanceof DateTime) { |
|
471 | - if ($this->_nullable) { |
|
472 | - return ''; |
|
473 | - } else { |
|
474 | - if (WP_DEBUG) { |
|
475 | - throw new EE_Error( |
|
476 | - sprintf( |
|
477 | - __( |
|
478 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
479 | - 'event_espresso' |
|
480 | - ), |
|
481 | - $this->_nicename |
|
482 | - ) |
|
483 | - ); |
|
484 | - } else { |
|
485 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
486 | - EE_Error::add_error( |
|
487 | - sprintf( |
|
488 | - __( |
|
489 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
490 | - 'event_espresso' |
|
491 | - ), |
|
492 | - $this->_nicename |
|
493 | - ) |
|
494 | - ); |
|
495 | - } |
|
496 | - } |
|
497 | - } |
|
498 | - $format_string = $this->_get_date_time_output($schema); |
|
499 | - EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
500 | - if ($schema) { |
|
501 | - if ($this->_display_timezone()) { |
|
502 | - // must be explicit because schema could equal true. |
|
503 | - if ($schema === 'no_html') { |
|
504 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
505 | - } else { |
|
506 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
507 | - } |
|
508 | - } else { |
|
509 | - $timezone_string = ''; |
|
510 | - } |
|
511 | - |
|
512 | - return $DateTime->format($format_string) . $timezone_string; |
|
513 | - } |
|
514 | - return $DateTime->format($format_string); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
520 | - * timezone). |
|
521 | - * |
|
522 | - * @param mixed $datetime_value u |
|
523 | - * @return string mysql timestamp in UTC |
|
524 | - * @throws \EE_Error |
|
525 | - */ |
|
526 | - public function prepare_for_use_in_db($datetime_value) |
|
527 | - { |
|
528 | - // we allow an empty value or DateTime object, but nothing else. |
|
529 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
530 | - throw new EE_Error( |
|
531 | - sprintf( |
|
532 | - __( |
|
533 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
18 | + /** |
|
19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | + * |
|
22 | + * @type string unix_timestamp_regex |
|
23 | + */ |
|
24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type string mysql_timestamp_format |
|
28 | + */ |
|
29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @type string mysql_date_format |
|
33 | + */ |
|
34 | + const mysql_date_format = 'Y-m-d'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @type string mysql_time_format |
|
38 | + */ |
|
39 | + const mysql_time_format = 'H:i:s'; |
|
40 | + |
|
41 | + /** |
|
42 | + * Const for using in the default value. If the field's default is set to this, |
|
43 | + * then we will return the time of calling `get_default_value()`, not |
|
44 | + * just the current time at construction |
|
45 | + */ |
|
46 | + const now = 'now'; |
|
47 | + |
|
48 | + /** |
|
49 | + * The following properties hold the default formats for date and time. |
|
50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | + * However they can also be overridden later by the set_format() method |
|
52 | + * (and corresponding set_date_format, set_time_format methods); |
|
53 | + */ |
|
54 | + /** |
|
55 | + * @type string $_date_format |
|
56 | + */ |
|
57 | + protected $_date_format = ''; |
|
58 | + |
|
59 | + /** |
|
60 | + * @type string $_time_format |
|
61 | + */ |
|
62 | + protected $_time_format = ''; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type string $_pretty_date_format |
|
66 | + */ |
|
67 | + protected $_pretty_date_format = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type string $_pretty_time_format |
|
71 | + */ |
|
72 | + protected $_pretty_time_format = ''; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type DateTimeZone $_DateTimeZone |
|
76 | + */ |
|
77 | + protected $_DateTimeZone; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | + */ |
|
82 | + protected $_UTC_DateTimeZone; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
86 | + */ |
|
87 | + protected $_blog_DateTimeZone; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | + * and time returned via getters. |
|
94 | + * |
|
95 | + * @var mixed (null|string) |
|
96 | + */ |
|
97 | + protected $_date_time_output; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * timezone string |
|
102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + protected $_timezone_string; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | + * offsets for comparison purposes). |
|
114 | + * |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + protected $_blog_offset; |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $table_column |
|
123 | + * @param string $nice_name |
|
124 | + * @param bool $nullable |
|
125 | + * @param string $default_value |
|
126 | + * @param string $timezone_string |
|
127 | + * @param string $date_format |
|
128 | + * @param string $time_format |
|
129 | + * @param string $pretty_date_format |
|
130 | + * @param string $pretty_time_format |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $table_column, |
|
136 | + $nice_name, |
|
137 | + $nullable, |
|
138 | + $default_value, |
|
139 | + $timezone_string = '', |
|
140 | + $date_format = '', |
|
141 | + $time_format = '', |
|
142 | + $pretty_date_format = '', |
|
143 | + $pretty_time_format = '' |
|
144 | + ) { |
|
145 | + |
|
146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | + |
|
151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | + $this->set_timezone($timezone_string); |
|
153 | + $this->setSchemaFormat('date-time'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return DateTimeZone |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public function get_UTC_DateTimeZone() |
|
162 | + { |
|
163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | + ? $this->_UTC_DateTimeZone |
|
165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return DateTimeZone |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + public function get_blog_DateTimeZone() |
|
174 | + { |
|
175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | + ? $this->_blog_DateTimeZone |
|
177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | + * |
|
184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | + * timestamp |
|
186 | + * @return DateTime |
|
187 | + */ |
|
188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | + { |
|
190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | + * |
|
198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | + * @return string The final assembled format string. |
|
200 | + */ |
|
201 | + protected function _get_date_time_output($pretty = false) |
|
202 | + { |
|
203 | + |
|
204 | + switch ($this->_date_time_output) { |
|
205 | + case 'time': |
|
206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | + break; |
|
208 | + |
|
209 | + case 'date': |
|
210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | + break; |
|
212 | + |
|
213 | + default: |
|
214 | + return $pretty |
|
215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | + * returned (using the format properties) |
|
224 | + * |
|
225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
226 | + * Any other value will be set but will always result |
|
227 | + * in both 'date' and 'time' being returned. |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + public function set_date_time_output($what = null) |
|
231 | + { |
|
232 | + $this->_date_time_output = $what; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | + * We also set some other properties in this method. |
|
241 | + * |
|
242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
243 | + * http://www.php.net/manual/en/timezones.php |
|
244 | + * @return void |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function set_timezone($timezone_string) |
|
250 | + { |
|
251 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
252 | + // leave the timezone AS-IS if we already have one and |
|
253 | + // the function arg didn't provide one |
|
254 | + return; |
|
255 | + } |
|
256 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
257 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
258 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * _create_timezone_object_from_timezone_name |
|
264 | + * |
|
265 | + * @access protected |
|
266 | + * @param string $timezone_string |
|
267 | + * @return \DateTimeZone |
|
268 | + * @throws InvalidArgumentException |
|
269 | + * @throws InvalidDataTypeException |
|
270 | + * @throws InvalidInterfaceException |
|
271 | + */ |
|
272 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
273 | + { |
|
274 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * This just returns whatever is set for the current timezone. |
|
280 | + * |
|
281 | + * @access public |
|
282 | + * @return string timezone string |
|
283 | + */ |
|
284 | + public function get_timezone() |
|
285 | + { |
|
286 | + return $this->_timezone_string; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * set the $_date_format property |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
295 | + * @param bool $pretty Whether to set pretty format or not. |
|
296 | + * @return void |
|
297 | + */ |
|
298 | + public function set_date_format($format, $pretty = false) |
|
299 | + { |
|
300 | + if ($pretty) { |
|
301 | + $this->_pretty_date_format = $format; |
|
302 | + } else { |
|
303 | + $this->_date_format = $format; |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * return the $_date_format property value. |
|
310 | + * |
|
311 | + * @param bool $pretty Whether to get pretty format or not. |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function get_date_format($pretty = false) |
|
315 | + { |
|
316 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * set the $_time_format property |
|
322 | + * |
|
323 | + * @access public |
|
324 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
325 | + * @param bool $pretty Whether to set pretty format or not. |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public function set_time_format($format, $pretty = false) |
|
329 | + { |
|
330 | + if ($pretty) { |
|
331 | + $this->_pretty_time_format = $format; |
|
332 | + } else { |
|
333 | + $this->_time_format = $format; |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * return the $_time_format property value. |
|
340 | + * |
|
341 | + * @param bool $pretty Whether to get pretty format or not. |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public function get_time_format($pretty = false) |
|
345 | + { |
|
346 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * set the $_pretty_date_format property |
|
352 | + * |
|
353 | + * @access public |
|
354 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
355 | + * @return void |
|
356 | + */ |
|
357 | + public function set_pretty_date_format($format) |
|
358 | + { |
|
359 | + $this->_pretty_date_format = $format; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * set the $_pretty_time_format property |
|
365 | + * |
|
366 | + * @access public |
|
367 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + public function set_pretty_time_format($format) |
|
371 | + { |
|
372 | + $this->_pretty_time_format = $format; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Only sets the time portion of the datetime. |
|
378 | + * |
|
379 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
380 | + * @param DateTime $current current DateTime object for the datetime field |
|
381 | + * @return DateTime |
|
382 | + */ |
|
383 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
384 | + { |
|
385 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
386 | + // Otherwise parse the string. |
|
387 | + if ($time_to_set_string instanceof DateTime) { |
|
388 | + $parsed = array( |
|
389 | + 'hour' => $time_to_set_string->format('H'), |
|
390 | + 'minute' => $time_to_set_string->format('i'), |
|
391 | + 'second' => $time_to_set_string->format('s'), |
|
392 | + ); |
|
393 | + } else { |
|
394 | + // parse incoming string |
|
395 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
396 | + } |
|
397 | + EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
398 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Only sets the date portion of the datetime. |
|
404 | + * |
|
405 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
406 | + * @param DateTime $current current DateTime object for the datetime field |
|
407 | + * @return DateTime |
|
408 | + */ |
|
409 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
410 | + { |
|
411 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
412 | + // Otherwise parse the string. |
|
413 | + if ($date_to_set_string instanceof DateTime) { |
|
414 | + $parsed = array( |
|
415 | + 'year' => $date_to_set_string->format('Y'), |
|
416 | + 'month' => $date_to_set_string->format('m'), |
|
417 | + 'day' => $date_to_set_string->format('d'), |
|
418 | + ); |
|
419 | + } else { |
|
420 | + // parse incoming string |
|
421 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
422 | + } |
|
423 | + EEH_DTT_Helper::setTimezone($current, $this->_DateTimeZone); |
|
424 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
430 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
431 | + * |
|
432 | + * @param DateTime $DateTime |
|
433 | + * @return string formatted date time for given timezone |
|
434 | + * @throws \EE_Error |
|
435 | + */ |
|
436 | + public function prepare_for_get($DateTime) |
|
437 | + { |
|
438 | + return $this->_prepare_for_display($DateTime); |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
444 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
445 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
446 | + * abbreviation to the date_string. |
|
447 | + * |
|
448 | + * @param mixed $DateTime |
|
449 | + * @param null $schema |
|
450 | + * @return string |
|
451 | + * @throws \EE_Error |
|
452 | + */ |
|
453 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
454 | + { |
|
455 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
461 | + * timezone). |
|
462 | + * |
|
463 | + * @param DateTime $DateTime |
|
464 | + * @param bool|string $schema |
|
465 | + * @return string |
|
466 | + * @throws \EE_Error |
|
467 | + */ |
|
468 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
469 | + { |
|
470 | + if (! $DateTime instanceof DateTime) { |
|
471 | + if ($this->_nullable) { |
|
472 | + return ''; |
|
473 | + } else { |
|
474 | + if (WP_DEBUG) { |
|
475 | + throw new EE_Error( |
|
476 | + sprintf( |
|
477 | + __( |
|
478 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
479 | + 'event_espresso' |
|
480 | + ), |
|
481 | + $this->_nicename |
|
482 | + ) |
|
483 | + ); |
|
484 | + } else { |
|
485 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
486 | + EE_Error::add_error( |
|
487 | + sprintf( |
|
488 | + __( |
|
489 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
490 | + 'event_espresso' |
|
491 | + ), |
|
492 | + $this->_nicename |
|
493 | + ) |
|
494 | + ); |
|
495 | + } |
|
496 | + } |
|
497 | + } |
|
498 | + $format_string = $this->_get_date_time_output($schema); |
|
499 | + EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
500 | + if ($schema) { |
|
501 | + if ($this->_display_timezone()) { |
|
502 | + // must be explicit because schema could equal true. |
|
503 | + if ($schema === 'no_html') { |
|
504 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
505 | + } else { |
|
506 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
507 | + } |
|
508 | + } else { |
|
509 | + $timezone_string = ''; |
|
510 | + } |
|
511 | + |
|
512 | + return $DateTime->format($format_string) . $timezone_string; |
|
513 | + } |
|
514 | + return $DateTime->format($format_string); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
520 | + * timezone). |
|
521 | + * |
|
522 | + * @param mixed $datetime_value u |
|
523 | + * @return string mysql timestamp in UTC |
|
524 | + * @throws \EE_Error |
|
525 | + */ |
|
526 | + public function prepare_for_use_in_db($datetime_value) |
|
527 | + { |
|
528 | + // we allow an empty value or DateTime object, but nothing else. |
|
529 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
530 | + throw new EE_Error( |
|
531 | + sprintf( |
|
532 | + __( |
|
533 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
534 | 534 | DateTime object, instead of: %1$s %2$s', |
535 | - 'event_espresso' |
|
536 | - ), |
|
537 | - '<br />', |
|
538 | - print_r($datetime_value, true) |
|
539 | - ) |
|
540 | - ); |
|
541 | - } |
|
542 | - |
|
543 | - if ($datetime_value instanceof DateTime) { |
|
544 | - if (! $datetime_value instanceof DbSafeDateTime) { |
|
545 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
546 | - } |
|
547 | - EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone()); |
|
548 | - return $datetime_value->format( |
|
549 | - EE_Datetime_Field::mysql_timestamp_format |
|
550 | - ); |
|
551 | - } |
|
552 | - |
|
553 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
554 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
560 | - * allowed) |
|
561 | - * |
|
562 | - * @param string $datetime_string mysql timestamp in UTC |
|
563 | - * @return mixed null | DateTime |
|
564 | - * @throws \EE_Error |
|
565 | - */ |
|
566 | - public function prepare_for_set_from_db($datetime_string) |
|
567 | - { |
|
568 | - // if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
569 | - if (empty($datetime_string) && $this->_nullable) { |
|
570 | - return null; |
|
571 | - } |
|
572 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
573 | - if (empty($datetime_string)) { |
|
574 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
575 | - } else { |
|
576 | - $DateTime = DateTime::createFromFormat( |
|
577 | - EE_Datetime_Field::mysql_timestamp_format, |
|
578 | - $datetime_string, |
|
579 | - $this->get_UTC_DateTimeZone() |
|
580 | - ); |
|
581 | - if ($DateTime instanceof \DateTime) { |
|
582 | - $DateTime = new DbSafeDateTime( |
|
583 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
584 | - $this->get_UTC_DateTimeZone() |
|
585 | - ); |
|
586 | - } |
|
587 | - } |
|
588 | - |
|
589 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
590 | - // if still no datetime object, then let's just use now |
|
591 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
592 | - } |
|
593 | - // THEN apply the field's set DateTimeZone |
|
594 | - EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
595 | - return $DateTime; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
601 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
602 | - * If so, then true. |
|
603 | - * |
|
604 | - * @return bool true for yes false for no |
|
605 | - * @throws \EE_Error |
|
606 | - */ |
|
607 | - protected function _display_timezone() |
|
608 | - { |
|
609 | - |
|
610 | - // first let's do a comparison of timezone strings. |
|
611 | - // If they match then we can get out without any further calculations |
|
612 | - $blog_string = get_option('timezone_string'); |
|
613 | - if ($blog_string === $this->_timezone_string) { |
|
614 | - return false; |
|
615 | - } |
|
616 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
617 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
618 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
619 | - // now compare |
|
620 | - return $blog_offset !== $this_offset; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
626 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
627 | - * with. |
|
628 | - * |
|
629 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
630 | - * in the format that is set on the date_field (or DateTime |
|
631 | - * object)! |
|
632 | - * @return DateTime |
|
633 | - */ |
|
634 | - protected function _get_date_object($date_string) |
|
635 | - { |
|
636 | - // first if this is an empty date_string and nullable is allowed, just return null. |
|
637 | - if ($this->_nullable && empty($date_string)) { |
|
638 | - return null; |
|
639 | - } |
|
640 | - |
|
641 | - // if incoming date |
|
642 | - if ($date_string instanceof DateTime) { |
|
643 | - EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone); |
|
644 | - return $date_string; |
|
645 | - } |
|
646 | - // if empty date_string and made it here. |
|
647 | - // Return a datetime object for now in the given timezone. |
|
648 | - if (empty($date_string)) { |
|
649 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
650 | - } |
|
651 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
652 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
653 | - try { |
|
654 | - // This is operating under the assumption that the incoming Unix timestamp |
|
655 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
656 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
657 | - $DateTime->setTimestamp($date_string); |
|
658 | - |
|
659 | - return $DateTime; |
|
660 | - } catch (Exception $e) { |
|
661 | - // should be rare, but if things got fooled then let's just continue |
|
662 | - } |
|
663 | - } |
|
664 | - // not a unix timestamp. So we will use the set format on this object and set timezone to |
|
665 | - // create the DateTime object. |
|
666 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
667 | - try { |
|
668 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
669 | - if ($DateTime instanceof DateTime) { |
|
670 | - $DateTime = new DbSafeDateTime( |
|
671 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
672 | - $this->_DateTimeZone |
|
673 | - ); |
|
674 | - } |
|
675 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
676 | - throw new EE_Error( |
|
677 | - sprintf( |
|
678 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
679 | - $date_string, |
|
680 | - $format |
|
681 | - ) |
|
682 | - ); |
|
683 | - } |
|
684 | - } catch (Exception $e) { |
|
685 | - // if we made it here then likely then something went really wrong. |
|
686 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
687 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
688 | - } |
|
689 | - |
|
690 | - return $DateTime; |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * get_timezone_transitions |
|
697 | - * |
|
698 | - * @param \DateTimeZone $DateTimeZone |
|
699 | - * @param int $time |
|
700 | - * @param bool $first_only |
|
701 | - * @return mixed |
|
702 | - */ |
|
703 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
704 | - { |
|
705 | - return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * get_timezone_offset |
|
712 | - * |
|
713 | - * @param \DateTimeZone $DateTimeZone |
|
714 | - * @param int $time |
|
715 | - * @return mixed |
|
716 | - * @throws \DomainException |
|
717 | - */ |
|
718 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
719 | - { |
|
720 | - return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
726 | - * |
|
727 | - * @param string $timezone_string |
|
728 | - * @return string abbreviation |
|
729 | - * @throws \EE_Error |
|
730 | - */ |
|
731 | - public function get_timezone_abbrev($timezone_string) |
|
732 | - { |
|
733 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
734 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
735 | - |
|
736 | - return $dateTime->format('T'); |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Overrides the parent to allow for having a dynamic "now" value |
|
741 | - * |
|
742 | - * @return mixed |
|
743 | - */ |
|
744 | - public function get_default_value() |
|
745 | - { |
|
746 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
747 | - return time(); |
|
748 | - } else { |
|
749 | - return parent::get_default_value(); |
|
750 | - } |
|
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * Gets the default datetime object from the field's default time |
|
755 | - * @since 4.9.66.p |
|
756 | - * @return DbSafeDateTime|null |
|
757 | - * @throws InvalidArgumentException |
|
758 | - * @throws InvalidDataTypeException |
|
759 | - * @throws InvalidInterfaceException |
|
760 | - */ |
|
761 | - public function getDefaultDateTimeObj() |
|
762 | - { |
|
763 | - $default_raw = $this->get_default_value(); |
|
764 | - if ($default_raw instanceof DateTime) { |
|
765 | - return $default_raw; |
|
766 | - } elseif (is_null($default_raw)) { |
|
767 | - return $default_raw; |
|
768 | - } else { |
|
769 | - return new DbSafeDateTime( |
|
770 | - $this->get_default_value(), |
|
771 | - EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone()) |
|
772 | - ); |
|
773 | - } |
|
774 | - } |
|
775 | - |
|
776 | - public function getSchemaDescription() |
|
777 | - { |
|
778 | - return sprintf( |
|
779 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
780 | - $this->get_nicename() |
|
781 | - ); |
|
782 | - } |
|
535 | + 'event_espresso' |
|
536 | + ), |
|
537 | + '<br />', |
|
538 | + print_r($datetime_value, true) |
|
539 | + ) |
|
540 | + ); |
|
541 | + } |
|
542 | + |
|
543 | + if ($datetime_value instanceof DateTime) { |
|
544 | + if (! $datetime_value instanceof DbSafeDateTime) { |
|
545 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
546 | + } |
|
547 | + EEH_DTT_Helper::setTimezone($datetime_value, $this->get_UTC_DateTimeZone()); |
|
548 | + return $datetime_value->format( |
|
549 | + EE_Datetime_Field::mysql_timestamp_format |
|
550 | + ); |
|
551 | + } |
|
552 | + |
|
553 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
554 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
560 | + * allowed) |
|
561 | + * |
|
562 | + * @param string $datetime_string mysql timestamp in UTC |
|
563 | + * @return mixed null | DateTime |
|
564 | + * @throws \EE_Error |
|
565 | + */ |
|
566 | + public function prepare_for_set_from_db($datetime_string) |
|
567 | + { |
|
568 | + // if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
569 | + if (empty($datetime_string) && $this->_nullable) { |
|
570 | + return null; |
|
571 | + } |
|
572 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
573 | + if (empty($datetime_string)) { |
|
574 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
575 | + } else { |
|
576 | + $DateTime = DateTime::createFromFormat( |
|
577 | + EE_Datetime_Field::mysql_timestamp_format, |
|
578 | + $datetime_string, |
|
579 | + $this->get_UTC_DateTimeZone() |
|
580 | + ); |
|
581 | + if ($DateTime instanceof \DateTime) { |
|
582 | + $DateTime = new DbSafeDateTime( |
|
583 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
584 | + $this->get_UTC_DateTimeZone() |
|
585 | + ); |
|
586 | + } |
|
587 | + } |
|
588 | + |
|
589 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
590 | + // if still no datetime object, then let's just use now |
|
591 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
592 | + } |
|
593 | + // THEN apply the field's set DateTimeZone |
|
594 | + EEH_DTT_Helper::setTimezone($DateTime, $this->_DateTimeZone); |
|
595 | + return $DateTime; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
601 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
602 | + * If so, then true. |
|
603 | + * |
|
604 | + * @return bool true for yes false for no |
|
605 | + * @throws \EE_Error |
|
606 | + */ |
|
607 | + protected function _display_timezone() |
|
608 | + { |
|
609 | + |
|
610 | + // first let's do a comparison of timezone strings. |
|
611 | + // If they match then we can get out without any further calculations |
|
612 | + $blog_string = get_option('timezone_string'); |
|
613 | + if ($blog_string === $this->_timezone_string) { |
|
614 | + return false; |
|
615 | + } |
|
616 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
617 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
618 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
619 | + // now compare |
|
620 | + return $blog_offset !== $this_offset; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
626 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
627 | + * with. |
|
628 | + * |
|
629 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
630 | + * in the format that is set on the date_field (or DateTime |
|
631 | + * object)! |
|
632 | + * @return DateTime |
|
633 | + */ |
|
634 | + protected function _get_date_object($date_string) |
|
635 | + { |
|
636 | + // first if this is an empty date_string and nullable is allowed, just return null. |
|
637 | + if ($this->_nullable && empty($date_string)) { |
|
638 | + return null; |
|
639 | + } |
|
640 | + |
|
641 | + // if incoming date |
|
642 | + if ($date_string instanceof DateTime) { |
|
643 | + EEH_DTT_Helper::setTimezone($date_string, $this->_DateTimeZone); |
|
644 | + return $date_string; |
|
645 | + } |
|
646 | + // if empty date_string and made it here. |
|
647 | + // Return a datetime object for now in the given timezone. |
|
648 | + if (empty($date_string)) { |
|
649 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
650 | + } |
|
651 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
652 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
653 | + try { |
|
654 | + // This is operating under the assumption that the incoming Unix timestamp |
|
655 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
656 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
657 | + $DateTime->setTimestamp($date_string); |
|
658 | + |
|
659 | + return $DateTime; |
|
660 | + } catch (Exception $e) { |
|
661 | + // should be rare, but if things got fooled then let's just continue |
|
662 | + } |
|
663 | + } |
|
664 | + // not a unix timestamp. So we will use the set format on this object and set timezone to |
|
665 | + // create the DateTime object. |
|
666 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
667 | + try { |
|
668 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
669 | + if ($DateTime instanceof DateTime) { |
|
670 | + $DateTime = new DbSafeDateTime( |
|
671 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
672 | + $this->_DateTimeZone |
|
673 | + ); |
|
674 | + } |
|
675 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
676 | + throw new EE_Error( |
|
677 | + sprintf( |
|
678 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
679 | + $date_string, |
|
680 | + $format |
|
681 | + ) |
|
682 | + ); |
|
683 | + } |
|
684 | + } catch (Exception $e) { |
|
685 | + // if we made it here then likely then something went really wrong. |
|
686 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
687 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
688 | + } |
|
689 | + |
|
690 | + return $DateTime; |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * get_timezone_transitions |
|
697 | + * |
|
698 | + * @param \DateTimeZone $DateTimeZone |
|
699 | + * @param int $time |
|
700 | + * @param bool $first_only |
|
701 | + * @return mixed |
|
702 | + */ |
|
703 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
704 | + { |
|
705 | + return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * get_timezone_offset |
|
712 | + * |
|
713 | + * @param \DateTimeZone $DateTimeZone |
|
714 | + * @param int $time |
|
715 | + * @return mixed |
|
716 | + * @throws \DomainException |
|
717 | + */ |
|
718 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
719 | + { |
|
720 | + return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
726 | + * |
|
727 | + * @param string $timezone_string |
|
728 | + * @return string abbreviation |
|
729 | + * @throws \EE_Error |
|
730 | + */ |
|
731 | + public function get_timezone_abbrev($timezone_string) |
|
732 | + { |
|
733 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
734 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
735 | + |
|
736 | + return $dateTime->format('T'); |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Overrides the parent to allow for having a dynamic "now" value |
|
741 | + * |
|
742 | + * @return mixed |
|
743 | + */ |
|
744 | + public function get_default_value() |
|
745 | + { |
|
746 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
747 | + return time(); |
|
748 | + } else { |
|
749 | + return parent::get_default_value(); |
|
750 | + } |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Gets the default datetime object from the field's default time |
|
755 | + * @since 4.9.66.p |
|
756 | + * @return DbSafeDateTime|null |
|
757 | + * @throws InvalidArgumentException |
|
758 | + * @throws InvalidDataTypeException |
|
759 | + * @throws InvalidInterfaceException |
|
760 | + */ |
|
761 | + public function getDefaultDateTimeObj() |
|
762 | + { |
|
763 | + $default_raw = $this->get_default_value(); |
|
764 | + if ($default_raw instanceof DateTime) { |
|
765 | + return $default_raw; |
|
766 | + } elseif (is_null($default_raw)) { |
|
767 | + return $default_raw; |
|
768 | + } else { |
|
769 | + return new DbSafeDateTime( |
|
770 | + $this->get_default_value(), |
|
771 | + EEH_DTT_Helper::get_valid_timezone_string($this->get_timezone()) |
|
772 | + ); |
|
773 | + } |
|
774 | + } |
|
775 | + |
|
776 | + public function getSchemaDescription() |
|
777 | + { |
|
778 | + return sprintf( |
|
779 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
780 | + $this->get_nicename() |
|
781 | + ); |
|
782 | + } |
|
783 | 783 | } |
@@ -23,22 +23,22 @@ |
||
23 | 23 | class Attendee extends Calculations_Base |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @param array $wpdb_row |
|
28 | - * @param WP_REST_Request $request |
|
29 | - * @param Base $controller |
|
30 | - * @since 4.9.66.p |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
|
34 | - { |
|
35 | - if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) { |
|
36 | - $email_address = $wpdb_row['Attendee_Meta.ATT_email']; |
|
37 | - } |
|
38 | - if (empty($email_address)) { |
|
39 | - return ''; |
|
40 | - } |
|
41 | - $avatar = get_avatar_url($email_address); |
|
42 | - return $avatar ? $avatar : ''; |
|
43 | - } |
|
26 | + /** |
|
27 | + * @param array $wpdb_row |
|
28 | + * @param WP_REST_Request $request |
|
29 | + * @param Base $controller |
|
30 | + * @since 4.9.66.p |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public static function userAvatar(array $wpdb_row, WP_REST_Request $request, Base $controller) |
|
34 | + { |
|
35 | + if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) { |
|
36 | + $email_address = $wpdb_row['Attendee_Meta.ATT_email']; |
|
37 | + } |
|
38 | + if (empty($email_address)) { |
|
39 | + return ''; |
|
40 | + } |
|
41 | + $avatar = get_avatar_url($email_address); |
|
42 | + return $avatar ? $avatar : ''; |
|
43 | + } |
|
44 | 44 | } |
@@ -12,285 +12,285 @@ |
||
12 | 12 | class EEH_URL |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * _add_query_arg |
|
17 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @param array $args |
|
21 | - * @param string $url |
|
22 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
26 | - { |
|
27 | - if (empty($url)) { |
|
28 | - $user_msg = esc_html__( |
|
29 | - 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
30 | - 'event_espresso' |
|
31 | - ); |
|
32 | - $dev_msg = $user_msg . "\n" |
|
33 | - . sprintf( |
|
34 | - esc_html__( |
|
35 | - 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
36 | - 'event_espresso' |
|
37 | - ), |
|
38 | - __CLASS__ . '::add_query_args_and_nonce' |
|
39 | - ); |
|
40 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
41 | - } |
|
42 | - // check that an action exists and add nonce |
|
43 | - if (! $exclude_nonce) { |
|
44 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
45 | - $args = array_merge( |
|
46 | - $args, |
|
47 | - array( |
|
48 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
49 | - ) |
|
50 | - ); |
|
51 | - } else { |
|
52 | - $args = array_merge( |
|
53 | - $args, |
|
54 | - array( |
|
55 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
59 | - } |
|
15 | + /** |
|
16 | + * _add_query_arg |
|
17 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @param array $args |
|
21 | + * @param string $url |
|
22 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
26 | + { |
|
27 | + if (empty($url)) { |
|
28 | + $user_msg = esc_html__( |
|
29 | + 'An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', |
|
30 | + 'event_espresso' |
|
31 | + ); |
|
32 | + $dev_msg = $user_msg . "\n" |
|
33 | + . sprintf( |
|
34 | + esc_html__( |
|
35 | + 'In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s method.', |
|
36 | + 'event_espresso' |
|
37 | + ), |
|
38 | + __CLASS__ . '::add_query_args_and_nonce' |
|
39 | + ); |
|
40 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
41 | + } |
|
42 | + // check that an action exists and add nonce |
|
43 | + if (! $exclude_nonce) { |
|
44 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
45 | + $args = array_merge( |
|
46 | + $args, |
|
47 | + array( |
|
48 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
49 | + ) |
|
50 | + ); |
|
51 | + } else { |
|
52 | + $args = array_merge( |
|
53 | + $args, |
|
54 | + array( |
|
55 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - // finally, let's always add a return address (if present) :) |
|
62 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
63 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
64 | - : $args; |
|
61 | + // finally, let's always add a return address (if present) :) |
|
62 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
63 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
64 | + : $args; |
|
65 | 65 | |
66 | - return add_query_arg($args, $url); |
|
67 | - } |
|
66 | + return add_query_arg($args, $url); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * Returns whether not the remote file exists. |
|
72 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
73 | - * |
|
74 | - * @param string $url |
|
75 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
76 | - * @return boolean |
|
77 | - */ |
|
78 | - public static function remote_file_exists($url, $args = array()) |
|
79 | - { |
|
80 | - $results = wp_remote_request( |
|
81 | - $url, |
|
82 | - array_merge( |
|
83 | - array( |
|
84 | - 'method' => 'GET', |
|
85 | - 'redirection' => 1, |
|
86 | - ), |
|
87 | - $args |
|
88 | - ) |
|
89 | - ); |
|
90 | - if (! $results instanceof WP_Error && |
|
91 | - isset($results['response']) && |
|
92 | - isset($results['response']['code']) && |
|
93 | - $results['response']['code'] == '200') { |
|
94 | - return true; |
|
95 | - } else { |
|
96 | - return false; |
|
97 | - } |
|
98 | - } |
|
70 | + /** |
|
71 | + * Returns whether not the remote file exists. |
|
72 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
73 | + * |
|
74 | + * @param string $url |
|
75 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
76 | + * @return boolean |
|
77 | + */ |
|
78 | + public static function remote_file_exists($url, $args = array()) |
|
79 | + { |
|
80 | + $results = wp_remote_request( |
|
81 | + $url, |
|
82 | + array_merge( |
|
83 | + array( |
|
84 | + 'method' => 'GET', |
|
85 | + 'redirection' => 1, |
|
86 | + ), |
|
87 | + $args |
|
88 | + ) |
|
89 | + ); |
|
90 | + if (! $results instanceof WP_Error && |
|
91 | + isset($results['response']) && |
|
92 | + isset($results['response']['code']) && |
|
93 | + $results['response']['code'] == '200') { |
|
94 | + return true; |
|
95 | + } else { |
|
96 | + return false; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * refactor_url |
|
103 | - * primarily used for removing the query string from a URL |
|
104 | - * |
|
105 | - * @param string $url |
|
106 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
107 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
111 | - { |
|
112 | - // break apart incoming URL |
|
113 | - $url_bits = parse_url($url); |
|
114 | - // HTTP or HTTPS ? |
|
115 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
116 | - // domain |
|
117 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
118 | - // if only the base URL is requested, then return that now |
|
119 | - if ($base_url_only) { |
|
120 | - return $scheme . $host; |
|
121 | - } |
|
122 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
123 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
124 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
125 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
126 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
127 | - // if the query string is not required, then return what we have so far |
|
128 | - if ($remove_query) { |
|
129 | - return $scheme . $user . $pass . $host . $port . $path; |
|
130 | - } |
|
131 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
132 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
133 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
134 | - } |
|
101 | + /** |
|
102 | + * refactor_url |
|
103 | + * primarily used for removing the query string from a URL |
|
104 | + * |
|
105 | + * @param string $url |
|
106 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
107 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
111 | + { |
|
112 | + // break apart incoming URL |
|
113 | + $url_bits = parse_url($url); |
|
114 | + // HTTP or HTTPS ? |
|
115 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
116 | + // domain |
|
117 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
118 | + // if only the base URL is requested, then return that now |
|
119 | + if ($base_url_only) { |
|
120 | + return $scheme . $host; |
|
121 | + } |
|
122 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
123 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
124 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
125 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
126 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
127 | + // if the query string is not required, then return what we have so far |
|
128 | + if ($remove_query) { |
|
129 | + return $scheme . $user . $pass . $host . $port . $path; |
|
130 | + } |
|
131 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
132 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
133 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | |
137 | - /** |
|
138 | - * get_query_string |
|
139 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
140 | - * |
|
141 | - * @param string $url |
|
142 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
143 | - * simply return the query string |
|
144 | - * @return string|array |
|
145 | - */ |
|
146 | - public static function get_query_string($url = '', $as_array = true) |
|
147 | - { |
|
148 | - // decode, then break apart incoming URL |
|
149 | - $url_bits = parse_url(html_entity_decode($url)); |
|
150 | - // grab query string from URL |
|
151 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
152 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
153 | - if (! $as_array) { |
|
154 | - return $query; |
|
155 | - } |
|
156 | - // if no query string exists then just return an empty array now |
|
157 | - if (empty($query)) { |
|
158 | - return array(); |
|
159 | - } |
|
160 | - // empty array to hold results |
|
161 | - $query_params = array(); |
|
162 | - // now break apart the query string into separate params |
|
163 | - $query = explode('&', $query); |
|
164 | - // loop thru our query params |
|
165 | - foreach ($query as $query_args) { |
|
166 | - // break apart the key value pairs |
|
167 | - $query_args = explode('=', $query_args); |
|
168 | - // and add to our results array |
|
169 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
170 | - } |
|
171 | - return $query_params; |
|
172 | - } |
|
137 | + /** |
|
138 | + * get_query_string |
|
139 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
140 | + * |
|
141 | + * @param string $url |
|
142 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
143 | + * simply return the query string |
|
144 | + * @return string|array |
|
145 | + */ |
|
146 | + public static function get_query_string($url = '', $as_array = true) |
|
147 | + { |
|
148 | + // decode, then break apart incoming URL |
|
149 | + $url_bits = parse_url(html_entity_decode($url)); |
|
150 | + // grab query string from URL |
|
151 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
152 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
153 | + if (! $as_array) { |
|
154 | + return $query; |
|
155 | + } |
|
156 | + // if no query string exists then just return an empty array now |
|
157 | + if (empty($query)) { |
|
158 | + return array(); |
|
159 | + } |
|
160 | + // empty array to hold results |
|
161 | + $query_params = array(); |
|
162 | + // now break apart the query string into separate params |
|
163 | + $query = explode('&', $query); |
|
164 | + // loop thru our query params |
|
165 | + foreach ($query as $query_args) { |
|
166 | + // break apart the key value pairs |
|
167 | + $query_args = explode('=', $query_args); |
|
168 | + // and add to our results array |
|
169 | + $query_params[ $query_args[0] ] = $query_args[1]; |
|
170 | + } |
|
171 | + return $query_params; |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * prevent_prefetching |
|
177 | - * |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public static function prevent_prefetching() |
|
181 | - { |
|
182 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
183 | - // with the registration process |
|
184 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
185 | - } |
|
175 | + /** |
|
176 | + * prevent_prefetching |
|
177 | + * |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public static function prevent_prefetching() |
|
181 | + { |
|
182 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
183 | + // with the registration process |
|
184 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | - /** |
|
189 | - * This generates a unique site-specific string. |
|
190 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
191 | - * urls. |
|
192 | - * |
|
193 | - * @param string $prefix Use this to prefix the string with something. |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public static function generate_unique_token($prefix = '') |
|
197 | - { |
|
198 | - $token = md5(uniqid() . mt_rand()); |
|
199 | - return $prefix ? $prefix . '_' . $token : $token; |
|
200 | - } |
|
188 | + /** |
|
189 | + * This generates a unique site-specific string. |
|
190 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
191 | + * urls. |
|
192 | + * |
|
193 | + * @param string $prefix Use this to prefix the string with something. |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public static function generate_unique_token($prefix = '') |
|
197 | + { |
|
198 | + $token = md5(uniqid() . mt_rand()); |
|
199 | + return $prefix ? $prefix . '_' . $token : $token; |
|
200 | + } |
|
201 | 201 | |
202 | 202 | |
203 | - /** |
|
204 | - * filter_input_server_url |
|
205 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
206 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
207 | - * |
|
208 | - * @param string $server_variable |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
212 | - { |
|
213 | - $URL = ''; |
|
214 | - $server_variables = array( |
|
215 | - 'REQUEST_URI' => 1, |
|
216 | - 'HTTP_HOST' => 1, |
|
217 | - 'PHP_SELF' => 1, |
|
218 | - ); |
|
219 | - $server_variable = strtoupper($server_variable); |
|
220 | - // whitelist INPUT_SERVER var |
|
221 | - if (isset($server_variables[ $server_variable ])) { |
|
222 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
223 | - if (empty($URL)) { |
|
224 | - // fallback sanitization if the above fails |
|
225 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
226 | - } |
|
227 | - } |
|
228 | - return $URL; |
|
229 | - } |
|
203 | + /** |
|
204 | + * filter_input_server_url |
|
205 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
206 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
207 | + * |
|
208 | + * @param string $server_variable |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
212 | + { |
|
213 | + $URL = ''; |
|
214 | + $server_variables = array( |
|
215 | + 'REQUEST_URI' => 1, |
|
216 | + 'HTTP_HOST' => 1, |
|
217 | + 'PHP_SELF' => 1, |
|
218 | + ); |
|
219 | + $server_variable = strtoupper($server_variable); |
|
220 | + // whitelist INPUT_SERVER var |
|
221 | + if (isset($server_variables[ $server_variable ])) { |
|
222 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
223 | + if (empty($URL)) { |
|
224 | + // fallback sanitization if the above fails |
|
225 | + $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
226 | + } |
|
227 | + } |
|
228 | + return $URL; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | - /** |
|
233 | - * Gets the current page's full URL. |
|
234 | - * |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public static function current_url() |
|
238 | - { |
|
239 | - $url = ''; |
|
240 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
241 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
242 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
243 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
244 | - } |
|
245 | - return $url; |
|
246 | - } |
|
232 | + /** |
|
233 | + * Gets the current page's full URL. |
|
234 | + * |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public static function current_url() |
|
238 | + { |
|
239 | + $url = ''; |
|
240 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
241 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
242 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
243 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
244 | + } |
|
245 | + return $url; |
|
246 | + } |
|
247 | 247 | |
248 | 248 | |
249 | - /** |
|
250 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
251 | - * |
|
252 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
253 | - * @since 4.9.46.rc.029 |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
257 | - { |
|
258 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
259 | - } |
|
249 | + /** |
|
250 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
251 | + * |
|
252 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
253 | + * @since 4.9.46.rc.029 |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
257 | + { |
|
258 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * @param string $location |
|
264 | - * @param int $status |
|
265 | - * @param string $exit_notice |
|
266 | - */ |
|
267 | - public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
268 | - { |
|
269 | - EE_Error::get_notices(false, true); |
|
270 | - wp_safe_redirect($location, $status); |
|
271 | - exit($exit_notice); |
|
272 | - } |
|
262 | + /** |
|
263 | + * @param string $location |
|
264 | + * @param int $status |
|
265 | + * @param string $exit_notice |
|
266 | + */ |
|
267 | + public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
268 | + { |
|
269 | + EE_Error::get_notices(false, true); |
|
270 | + wp_safe_redirect($location, $status); |
|
271 | + exit($exit_notice); |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * Slugifies text for usage in a URL. |
|
276 | - * |
|
277 | - * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
278 | - * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
279 | - * |
|
280 | - * @since 4.9.66.p |
|
281 | - * @param string $text |
|
282 | - * @param string $fallback |
|
283 | - * @return string which can be used in a URL |
|
284 | - */ |
|
285 | - public static function slugify($text, $fallback) |
|
286 | - { |
|
287 | - // url decode after sanitizing title to restore unicode characters, |
|
288 | - // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
289 | - return urldecode( |
|
290 | - sanitize_title( |
|
291 | - $text, |
|
292 | - $fallback |
|
293 | - ) |
|
294 | - ); |
|
295 | - } |
|
274 | + /** |
|
275 | + * Slugifies text for usage in a URL. |
|
276 | + * |
|
277 | + * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
278 | + * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
279 | + * |
|
280 | + * @since 4.9.66.p |
|
281 | + * @param string $text |
|
282 | + * @param string $fallback |
|
283 | + * @return string which can be used in a URL |
|
284 | + */ |
|
285 | + public static function slugify($text, $fallback) |
|
286 | + { |
|
287 | + // url decode after sanitizing title to restore unicode characters, |
|
288 | + // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
289 | + return urldecode( |
|
290 | + sanitize_title( |
|
291 | + $text, |
|
292 | + $fallback |
|
293 | + ) |
|
294 | + ); |
|
295 | + } |
|
296 | 296 | } |
@@ -15,1800 +15,1800 @@ |
||
15 | 15 | class EED_Single_Page_Checkout extends EED_Module |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * $_initialized - has the SPCO controller already been initialized ? |
|
20 | - * |
|
21 | - * @access private |
|
22 | - * @var bool $_initialized |
|
23 | - */ |
|
24 | - private static $_initialized = false; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
29 | - * |
|
30 | - * @access private |
|
31 | - * @var bool $_valid_checkout |
|
32 | - */ |
|
33 | - private static $_checkout_verified = true; |
|
34 | - |
|
35 | - /** |
|
36 | - * $_reg_steps_array - holds initial array of reg steps |
|
37 | - * |
|
38 | - * @access private |
|
39 | - * @var array $_reg_steps_array |
|
40 | - */ |
|
41 | - private static $_reg_steps_array = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @var EE_Checkout $checkout |
|
48 | - */ |
|
49 | - public $checkout; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return EED_Module|EED_Single_Page_Checkout |
|
54 | - */ |
|
55 | - public static function instance() |
|
56 | - { |
|
57 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
58 | - return parent::get_instance(__CLASS__); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return EE_CART |
|
64 | - */ |
|
65 | - public function cart() |
|
66 | - { |
|
67 | - return $this->checkout->cart; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return EE_Transaction |
|
73 | - */ |
|
74 | - public function transaction() |
|
75 | - { |
|
76 | - return $this->checkout->transaction; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
82 | - * |
|
83 | - * @access public |
|
84 | - * @return void |
|
85 | - * @throws EE_Error |
|
86 | - */ |
|
87 | - public static function set_hooks() |
|
88 | - { |
|
89 | - EED_Single_Page_Checkout::set_definitions(); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @return void |
|
98 | - * @throws EE_Error |
|
99 | - */ |
|
100 | - public static function set_hooks_admin() |
|
101 | - { |
|
102 | - EED_Single_Page_Checkout::set_definitions(); |
|
103 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
104 | - return; |
|
105 | - } |
|
106 | - // going to start an output buffer in case anything gets accidentally output |
|
107 | - // that might disrupt our JSON response |
|
108 | - ob_start(); |
|
109 | - EED_Single_Page_Checkout::load_request_handler(); |
|
110 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
111 | - // set ajax hooks |
|
112 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
113 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
114 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
115 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
116 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
117 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * process ajax request |
|
123 | - * |
|
124 | - * @param string $ajax_action |
|
125 | - * @throws EE_Error |
|
126 | - */ |
|
127 | - public static function process_ajax_request($ajax_action) |
|
128 | - { |
|
129 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
130 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * ajax display registration step |
|
136 | - * |
|
137 | - * @throws EE_Error |
|
138 | - */ |
|
139 | - public static function display_reg_step() |
|
140 | - { |
|
141 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * ajax process registration step |
|
147 | - * |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - public static function process_reg_step() |
|
151 | - { |
|
152 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * ajax process registration step |
|
158 | - * |
|
159 | - * @throws EE_Error |
|
160 | - */ |
|
161 | - public static function update_reg_step() |
|
162 | - { |
|
163 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * update_checkout |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @return void |
|
172 | - * @throws EE_Error |
|
173 | - */ |
|
174 | - public static function update_checkout() |
|
175 | - { |
|
176 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * load_request_handler |
|
182 | - * |
|
183 | - * @access public |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public static function load_request_handler() |
|
187 | - { |
|
188 | - // load core Request_Handler class |
|
189 | - if (EE_Registry::instance()->REQ !== null) { |
|
190 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * set_definitions |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @return void |
|
200 | - * @throws EE_Error |
|
201 | - */ |
|
202 | - public static function set_definitions() |
|
203 | - { |
|
204 | - if (defined('SPCO_BASE_PATH')) { |
|
205 | - return; |
|
206 | - } |
|
207 | - define( |
|
208 | - 'SPCO_BASE_PATH', |
|
209 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
210 | - ); |
|
211 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
212 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
213 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
214 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
215 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
216 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
217 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
218 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
219 | - ); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * load_reg_steps |
|
225 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
226 | - * |
|
227 | - * @access private |
|
228 | - * @throws EE_Error |
|
229 | - */ |
|
230 | - public static function load_reg_steps() |
|
231 | - { |
|
232 | - static $reg_steps_loaded = false; |
|
233 | - if ($reg_steps_loaded) { |
|
234 | - return; |
|
235 | - } |
|
236 | - // filter list of reg_steps |
|
237 | - $reg_steps_to_load = (array) apply_filters( |
|
238 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
239 | - EED_Single_Page_Checkout::get_reg_steps() |
|
240 | - ); |
|
241 | - // sort by key (order) |
|
242 | - ksort($reg_steps_to_load); |
|
243 | - // loop through folders |
|
244 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
245 | - // we need a |
|
246 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
247 | - // copy over to the reg_steps_array |
|
248 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
249 | - // register custom key route for each reg step |
|
250 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
251 | - EE_Config::register_route( |
|
252 | - $reg_step['slug'], |
|
253 | - 'EED_Single_Page_Checkout', |
|
254 | - 'run', |
|
255 | - 'step' |
|
256 | - ); |
|
257 | - // add AJAX or other hooks |
|
258 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
259 | - // setup autoloaders if necessary |
|
260 | - if (! class_exists($reg_step['class_name'])) { |
|
261 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
262 | - $reg_step['file_path'], |
|
263 | - true |
|
264 | - ); |
|
265 | - } |
|
266 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
267 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
268 | - } |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
272 | - $reg_steps_loaded = true; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * get_reg_steps |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @return array |
|
281 | - */ |
|
282 | - public static function get_reg_steps() |
|
283 | - { |
|
284 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
285 | - if (empty($reg_steps)) { |
|
286 | - $reg_steps = array( |
|
287 | - 10 => array( |
|
288 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
289 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
290 | - 'slug' => 'attendee_information', |
|
291 | - 'has_hooks' => false, |
|
292 | - ), |
|
293 | - 30 => array( |
|
294 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
295 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
296 | - 'slug' => 'payment_options', |
|
297 | - 'has_hooks' => true, |
|
298 | - ), |
|
299 | - 999 => array( |
|
300 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
301 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
302 | - 'slug' => 'finalize_registration', |
|
303 | - 'has_hooks' => false, |
|
304 | - ), |
|
305 | - ); |
|
306 | - } |
|
307 | - return $reg_steps; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * registration_checkout_for_admin |
|
313 | - * |
|
314 | - * @access public |
|
315 | - * @return string |
|
316 | - * @throws EE_Error |
|
317 | - */ |
|
318 | - public static function registration_checkout_for_admin() |
|
319 | - { |
|
320 | - EED_Single_Page_Checkout::load_request_handler(); |
|
321 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
322 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
323 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
324 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
325 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
326 | - return EE_Registry::instance()->REQ->get_output(); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * process_registration_from_admin |
|
332 | - * |
|
333 | - * @access public |
|
334 | - * @return \EE_Transaction |
|
335 | - * @throws EE_Error |
|
336 | - */ |
|
337 | - public static function process_registration_from_admin() |
|
338 | - { |
|
339 | - EED_Single_Page_Checkout::load_request_handler(); |
|
340 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
341 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
342 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
343 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
344 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
345 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
346 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
347 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
348 | - if ($final_reg_step->process_reg_step()) { |
|
349 | - $final_reg_step->set_completed(); |
|
350 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
351 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - return null; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * run |
|
361 | - * |
|
362 | - * @access public |
|
363 | - * @param WP_Query $WP_Query |
|
364 | - * @return void |
|
365 | - * @throws EE_Error |
|
366 | - */ |
|
367 | - public function run($WP_Query) |
|
368 | - { |
|
369 | - if ($WP_Query instanceof WP_Query |
|
370 | - && $WP_Query->is_main_query() |
|
371 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
372 | - && $this->_is_reg_checkout() |
|
373 | - ) { |
|
374 | - $this->_initialize(); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * determines whether current url matches reg page url |
|
381 | - * |
|
382 | - * @return bool |
|
383 | - */ |
|
384 | - protected function _is_reg_checkout() |
|
385 | - { |
|
386 | - // get current permalink for reg page without any extra query args |
|
387 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
388 | - // get request URI for current request, but without the scheme or host |
|
389 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
390 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
391 | - // get array of query args from the current request URI |
|
392 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
393 | - // grab page id if it is set |
|
394 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
395 | - // and remove the page id from the query args (we will re-add it later) |
|
396 | - unset($query_args['page_id']); |
|
397 | - // now strip all query args from current request URI |
|
398 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
399 | - // and re-add the page id if it was set |
|
400 | - if ($page_id) { |
|
401 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
402 | - } |
|
403 | - // remove slashes and ? |
|
404 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
405 | - // is current request URI part of the known full reg page URL ? |
|
406 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * @param WP_Query $wp_query |
|
412 | - * @return void |
|
413 | - * @throws EE_Error |
|
414 | - */ |
|
415 | - public static function init($wp_query) |
|
416 | - { |
|
417 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * _initialize - initial module setup |
|
423 | - * |
|
424 | - * @access private |
|
425 | - * @throws EE_Error |
|
426 | - * @return void |
|
427 | - */ |
|
428 | - private function _initialize() |
|
429 | - { |
|
430 | - // ensure SPCO doesn't run twice |
|
431 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
432 | - return; |
|
433 | - } |
|
434 | - try { |
|
435 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
436 | - $this->_verify_session(); |
|
437 | - // setup the EE_Checkout object |
|
438 | - $this->checkout = $this->_initialize_checkout(); |
|
439 | - // filter checkout |
|
440 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
441 | - // get the $_GET |
|
442 | - $this->_get_request_vars(); |
|
443 | - if ($this->_block_bots()) { |
|
444 | - return; |
|
445 | - } |
|
446 | - // filter continue_reg |
|
447 | - $this->checkout->continue_reg = apply_filters( |
|
448 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
449 | - true, |
|
450 | - $this->checkout |
|
451 | - ); |
|
452 | - // load the reg steps array |
|
453 | - if (! $this->_load_and_instantiate_reg_steps()) { |
|
454 | - EED_Single_Page_Checkout::$_initialized = true; |
|
455 | - return; |
|
456 | - } |
|
457 | - // set the current step |
|
458 | - $this->checkout->set_current_step($this->checkout->step); |
|
459 | - // and the next step |
|
460 | - $this->checkout->set_next_step(); |
|
461 | - // verify that everything has been setup correctly |
|
462 | - if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
463 | - EED_Single_Page_Checkout::$_initialized = true; |
|
464 | - return; |
|
465 | - } |
|
466 | - // lock the transaction |
|
467 | - $this->checkout->transaction->lock(); |
|
468 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
469 | - $this->checkout->refresh_all_entities(); |
|
470 | - // set amount owing |
|
471 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
472 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
473 | - $this->_initialize_reg_steps(); |
|
474 | - // DEBUG LOG |
|
475 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
476 | - // get reg form |
|
477 | - if (! $this->_check_form_submission()) { |
|
478 | - EED_Single_Page_Checkout::$_initialized = true; |
|
479 | - return; |
|
480 | - } |
|
481 | - // checkout the action!!! |
|
482 | - $this->_process_form_action(); |
|
483 | - // add some style and make it dance |
|
484 | - $this->add_styles_and_scripts(); |
|
485 | - // kk... SPCO has successfully run |
|
486 | - EED_Single_Page_Checkout::$_initialized = true; |
|
487 | - // set no cache headers and constants |
|
488 | - EE_System::do_not_cache(); |
|
489 | - // add anchor |
|
490 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
491 | - // remove transaction lock |
|
492 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
493 | - } catch (Exception $e) { |
|
494 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * _verify_session |
|
501 | - * checks that the session is valid and not expired |
|
502 | - * |
|
503 | - * @access private |
|
504 | - * @throws EE_Error |
|
505 | - */ |
|
506 | - private function _verify_session() |
|
507 | - { |
|
508 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
509 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
510 | - } |
|
511 | - $clear_session_requested = filter_var( |
|
512 | - EE_Registry::instance()->REQ->get('clear_session', false), |
|
513 | - FILTER_VALIDATE_BOOLEAN |
|
514 | - ); |
|
515 | - // is session still valid ? |
|
516 | - if ($clear_session_requested |
|
517 | - || (EE_Registry::instance()->SSN->expired() |
|
518 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
519 | - ) |
|
520 | - ) { |
|
521 | - $this->checkout = new EE_Checkout(); |
|
522 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
523 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
524 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
525 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
526 | - if (! $clear_session_requested) { |
|
527 | - EE_Error::add_attention( |
|
528 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
529 | - __FILE__, |
|
530 | - __FUNCTION__, |
|
531 | - __LINE__ |
|
532 | - ); |
|
533 | - } |
|
534 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * _initialize_checkout |
|
541 | - * loads and instantiates EE_Checkout |
|
542 | - * |
|
543 | - * @access private |
|
544 | - * @throws EE_Error |
|
545 | - * @return EE_Checkout |
|
546 | - */ |
|
547 | - private function _initialize_checkout() |
|
548 | - { |
|
549 | - // look in session for existing checkout |
|
550 | - /** @type EE_Checkout $checkout */ |
|
551 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
552 | - // verify |
|
553 | - if (! $checkout instanceof EE_Checkout) { |
|
554 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
555 | - $checkout = EE_Registry::instance()->load_file( |
|
556 | - SPCO_INC_PATH, |
|
557 | - 'EE_Checkout', |
|
558 | - 'class', |
|
559 | - array(), |
|
560 | - false |
|
561 | - ); |
|
562 | - } else { |
|
563 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
564 | - $this->unlock_transaction(); |
|
565 | - wp_safe_redirect($checkout->redirect_url); |
|
566 | - exit(); |
|
567 | - } |
|
568 | - } |
|
569 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
570 | - // verify again |
|
571 | - if (! $checkout instanceof EE_Checkout) { |
|
572 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
573 | - } |
|
574 | - // reset anything that needs a clean slate for each request |
|
575 | - $checkout->reset_for_current_request(); |
|
576 | - return $checkout; |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * _get_request_vars |
|
582 | - * |
|
583 | - * @access private |
|
584 | - * @return void |
|
585 | - * @throws EE_Error |
|
586 | - */ |
|
587 | - private function _get_request_vars() |
|
588 | - { |
|
589 | - // load classes |
|
590 | - EED_Single_Page_Checkout::load_request_handler(); |
|
591 | - // make sure this request is marked as belonging to EE |
|
592 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
593 | - // which step is being requested ? |
|
594 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
595 | - // which step is being edited ? |
|
596 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
597 | - // and what we're doing on the current step |
|
598 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
599 | - // timestamp |
|
600 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
601 | - // returning to edit ? |
|
602 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
603 | - // add reg url link to registration query params |
|
604 | - if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
605 | - $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
606 | - } |
|
607 | - // or some other kind of revisit ? |
|
608 | - $this->checkout->revisit = filter_var( |
|
609 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
610 | - FILTER_VALIDATE_BOOLEAN |
|
611 | - ); |
|
612 | - // and whether or not to generate a reg form for this request |
|
613 | - $this->checkout->generate_reg_form = filter_var( |
|
614 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
615 | - FILTER_VALIDATE_BOOLEAN |
|
616 | - ); |
|
617 | - // and whether or not to process a reg form submission for this request |
|
618 | - $this->checkout->process_form_submission = filter_var( |
|
619 | - EE_Registry::instance()->REQ->get( |
|
620 | - 'process_form_submission', |
|
621 | - $this->checkout->action === 'process_reg_step' |
|
622 | - ), |
|
623 | - FILTER_VALIDATE_BOOLEAN |
|
624 | - ); |
|
625 | - $this->checkout->process_form_submission = filter_var( |
|
626 | - $this->checkout->action !== 'display_spco_reg_step' |
|
627 | - ? $this->checkout->process_form_submission |
|
628 | - : false, |
|
629 | - FILTER_VALIDATE_BOOLEAN |
|
630 | - ); |
|
631 | - // $this->_display_request_vars(); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * _display_request_vars |
|
637 | - * |
|
638 | - * @access protected |
|
639 | - * @return void |
|
640 | - */ |
|
641 | - protected function _display_request_vars() |
|
642 | - { |
|
643 | - if (! WP_DEBUG) { |
|
644 | - return; |
|
645 | - } |
|
646 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
647 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
648 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
649 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
650 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
651 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
652 | - EEH_Debug_Tools::printr( |
|
653 | - $this->checkout->generate_reg_form, |
|
654 | - '$this->checkout->generate_reg_form', |
|
655 | - __FILE__, |
|
656 | - __LINE__ |
|
657 | - ); |
|
658 | - EEH_Debug_Tools::printr( |
|
659 | - $this->checkout->process_form_submission, |
|
660 | - '$this->checkout->process_form_submission', |
|
661 | - __FILE__, |
|
662 | - __LINE__ |
|
663 | - ); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * _block_bots |
|
669 | - * checks that the incoming request has either of the following set: |
|
670 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
671 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
672 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
673 | - * then where you coming from man? |
|
674 | - * |
|
675 | - * @return boolean |
|
676 | - */ |
|
677 | - private function _block_bots() |
|
678 | - { |
|
679 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
680 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
681 | - return true; |
|
682 | - } |
|
683 | - return false; |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * _get_first_step |
|
689 | - * gets slug for first step in $_reg_steps_array |
|
690 | - * |
|
691 | - * @access private |
|
692 | - * @throws EE_Error |
|
693 | - * @return string |
|
694 | - */ |
|
695 | - private function _get_first_step() |
|
696 | - { |
|
697 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
698 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * instantiates each reg step based on the loaded reg_steps array |
|
704 | - * |
|
705 | - * @return bool |
|
706 | - * @throws EE_Error |
|
707 | - * @throws InvalidArgumentException |
|
708 | - * @throws InvalidDataTypeException |
|
709 | - * @throws InvalidInterfaceException |
|
710 | - */ |
|
711 | - private function _load_and_instantiate_reg_steps() |
|
712 | - { |
|
713 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
714 | - // have reg_steps already been instantiated ? |
|
715 | - if (empty($this->checkout->reg_steps) |
|
716 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
717 | - ) { |
|
718 | - // if not, then loop through raw reg steps array |
|
719 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
720 | - if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
721 | - return false; |
|
722 | - } |
|
723 | - } |
|
724 | - if (isset($this->checkout->reg_steps['registration_confirmation'])) { |
|
725 | - // skip the registration_confirmation page ? |
|
726 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
727 | - // just remove it from the reg steps array |
|
728 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
729 | - } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
730 | - ) { |
|
731 | - // set the order to something big like 100 |
|
732 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
733 | - } |
|
734 | - } |
|
735 | - // filter the array for good luck |
|
736 | - $this->checkout->reg_steps = apply_filters( |
|
737 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
738 | - $this->checkout->reg_steps |
|
739 | - ); |
|
740 | - // finally re-sort based on the reg step class order properties |
|
741 | - $this->checkout->sort_reg_steps(); |
|
742 | - } else { |
|
743 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
744 | - // set all current step stati to FALSE |
|
745 | - $reg_step->set_is_current_step(false); |
|
746 | - } |
|
747 | - } |
|
748 | - if (empty($this->checkout->reg_steps)) { |
|
749 | - EE_Error::add_error( |
|
750 | - __('No Reg Steps were loaded..', 'event_espresso'), |
|
751 | - __FILE__, |
|
752 | - __FUNCTION__, |
|
753 | - __LINE__ |
|
754 | - ); |
|
755 | - return false; |
|
756 | - } |
|
757 | - // make reg step details available to JS |
|
758 | - $this->checkout->set_reg_step_JSON_info(); |
|
759 | - return true; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * _load_and_instantiate_reg_step |
|
765 | - * |
|
766 | - * @access private |
|
767 | - * @param array $reg_step |
|
768 | - * @param int $order |
|
769 | - * @return bool |
|
770 | - */ |
|
771 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
772 | - { |
|
773 | - // we need a file_path, class_name, and slug to add a reg step |
|
774 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
775 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
776 | - if ($this->checkout->reg_url_link |
|
777 | - && $this->checkout->step !== $reg_step['slug'] |
|
778 | - && $reg_step['slug'] !== 'finalize_registration' |
|
779 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
780 | - && apply_filters( |
|
781 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
782 | - true, |
|
783 | - $reg_step, |
|
784 | - $this->checkout |
|
785 | - ) |
|
786 | - ) { |
|
787 | - return true; |
|
788 | - } |
|
789 | - // instantiate step class using file path and class name |
|
790 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
791 | - $reg_step['file_path'], |
|
792 | - $reg_step['class_name'], |
|
793 | - 'class', |
|
794 | - $this->checkout, |
|
795 | - false |
|
796 | - ); |
|
797 | - // did we gets the goods ? |
|
798 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
799 | - // set reg step order based on config |
|
800 | - $reg_step_obj->set_order($order); |
|
801 | - // add instantiated reg step object to the master reg steps array |
|
802 | - $this->checkout->add_reg_step($reg_step_obj); |
|
803 | - } else { |
|
804 | - EE_Error::add_error( |
|
805 | - __('The current step could not be set.', 'event_espresso'), |
|
806 | - __FILE__, |
|
807 | - __FUNCTION__, |
|
808 | - __LINE__ |
|
809 | - ); |
|
810 | - return false; |
|
811 | - } |
|
812 | - } else { |
|
813 | - if (WP_DEBUG) { |
|
814 | - EE_Error::add_error( |
|
815 | - sprintf( |
|
816 | - __( |
|
817 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
818 | - 'event_espresso' |
|
819 | - ), |
|
820 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
821 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
822 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
823 | - '<ul>', |
|
824 | - '<li>', |
|
825 | - '</li>', |
|
826 | - '</ul>' |
|
827 | - ), |
|
828 | - __FILE__, |
|
829 | - __FUNCTION__, |
|
830 | - __LINE__ |
|
831 | - ); |
|
832 | - } |
|
833 | - return false; |
|
834 | - } |
|
835 | - return true; |
|
836 | - } |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * _verify_transaction_and_get_registrations |
|
841 | - * |
|
842 | - * @access private |
|
843 | - * @return bool |
|
844 | - * @throws InvalidDataTypeException |
|
845 | - * @throws InvalidEntityException |
|
846 | - * @throws EE_Error |
|
847 | - */ |
|
848 | - private function _verify_transaction_and_get_registrations() |
|
849 | - { |
|
850 | - // was there already a valid transaction in the checkout from the session ? |
|
851 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
852 | - // get transaction from db or session |
|
853 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
854 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
855 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
856 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
857 | - EE_Error::add_error( |
|
858 | - __( |
|
859 | - 'Your Registration and Transaction information could not be retrieved from the db.', |
|
860 | - 'event_espresso' |
|
861 | - ), |
|
862 | - __FILE__, |
|
863 | - __FUNCTION__, |
|
864 | - __LINE__ |
|
865 | - ); |
|
866 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
867 | - // add some style and make it dance |
|
868 | - $this->add_styles_and_scripts(); |
|
869 | - EED_Single_Page_Checkout::$_initialized = true; |
|
870 | - return false; |
|
871 | - } |
|
872 | - // and the registrations for the transaction |
|
873 | - $this->_get_registrations($this->checkout->transaction); |
|
874 | - } |
|
875 | - return true; |
|
876 | - } |
|
877 | - |
|
878 | - |
|
879 | - /** |
|
880 | - * _get_transaction_and_cart_for_previous_visit |
|
881 | - * |
|
882 | - * @access private |
|
883 | - * @return mixed EE_Transaction|NULL |
|
884 | - */ |
|
885 | - private function _get_transaction_and_cart_for_previous_visit() |
|
886 | - { |
|
887 | - /** @var $TXN_model EEM_Transaction */ |
|
888 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
889 | - // because the reg_url_link is present in the request, |
|
890 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
891 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
892 | - // verify transaction |
|
893 | - if ($transaction instanceof EE_Transaction) { |
|
894 | - // and get the cart that was used for that transaction |
|
895 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
896 | - return $transaction; |
|
897 | - } |
|
898 | - EE_Error::add_error( |
|
899 | - __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
900 | - __FILE__, |
|
901 | - __FUNCTION__, |
|
902 | - __LINE__ |
|
903 | - ); |
|
904 | - return null; |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * _get_cart_for_transaction |
|
910 | - * |
|
911 | - * @access private |
|
912 | - * @param EE_Transaction $transaction |
|
913 | - * @return EE_Cart |
|
914 | - */ |
|
915 | - private function _get_cart_for_transaction($transaction) |
|
916 | - { |
|
917 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * get_cart_for_transaction |
|
923 | - * |
|
924 | - * @access public |
|
925 | - * @param EE_Transaction $transaction |
|
926 | - * @return EE_Cart |
|
927 | - */ |
|
928 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
929 | - { |
|
930 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * _get_transaction_and_cart_for_current_session |
|
936 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
937 | - * |
|
938 | - * @access private |
|
939 | - * @return EE_Transaction |
|
940 | - * @throws EE_Error |
|
941 | - */ |
|
942 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
943 | - { |
|
944 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
945 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
946 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
947 | - // and then create a new transaction |
|
948 | - $transaction = $this->_initialize_transaction(); |
|
949 | - // verify transaction |
|
950 | - if ($transaction instanceof EE_Transaction) { |
|
951 | - // save it so that we have an ID for other objects to use |
|
952 | - $transaction->save(); |
|
953 | - // and save TXN data to the cart |
|
954 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
955 | - } else { |
|
956 | - EE_Error::add_error( |
|
957 | - __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
958 | - __FILE__, |
|
959 | - __FUNCTION__, |
|
960 | - __LINE__ |
|
961 | - ); |
|
962 | - } |
|
963 | - return $transaction; |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
969 | - * |
|
970 | - * @access private |
|
971 | - * @return mixed EE_Transaction|NULL |
|
972 | - */ |
|
973 | - private function _initialize_transaction() |
|
974 | - { |
|
975 | - try { |
|
976 | - // ensure cart totals have been calculated |
|
977 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
978 | - // grab the cart grand total |
|
979 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
980 | - // create new TXN |
|
981 | - $transaction = EE_Transaction::new_instance( |
|
982 | - array( |
|
983 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
984 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
985 | - 'TXN_paid' => 0, |
|
986 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
987 | - ) |
|
988 | - ); |
|
989 | - // save it so that we have an ID for other objects to use |
|
990 | - $transaction->save(); |
|
991 | - // set cron job for following up on TXNs after their session has expired |
|
992 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
993 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
994 | - $transaction->ID() |
|
995 | - ); |
|
996 | - return $transaction; |
|
997 | - } catch (Exception $e) { |
|
998 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
999 | - } |
|
1000 | - return null; |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * _get_registrations |
|
1006 | - * |
|
1007 | - * @access private |
|
1008 | - * @param EE_Transaction $transaction |
|
1009 | - * @return void |
|
1010 | - * @throws InvalidDataTypeException |
|
1011 | - * @throws InvalidEntityException |
|
1012 | - * @throws EE_Error |
|
1013 | - */ |
|
1014 | - private function _get_registrations(EE_Transaction $transaction) |
|
1015 | - { |
|
1016 | - // first step: grab the registrants { : o |
|
1017 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1018 | - $this->checkout->total_ticket_count = count($registrations); |
|
1019 | - // verify registrations have been set |
|
1020 | - if (empty($registrations)) { |
|
1021 | - // if no cached registrations, then check the db |
|
1022 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1023 | - // still nothing ? well as long as this isn't a revisit |
|
1024 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
1025 | - // generate new registrations from scratch |
|
1026 | - $registrations = $this->_initialize_registrations($transaction); |
|
1027 | - } |
|
1028 | - } |
|
1029 | - // sort by their original registration order |
|
1030 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1031 | - // then loop thru the array |
|
1032 | - foreach ($registrations as $registration) { |
|
1033 | - // verify each registration |
|
1034 | - if ($registration instanceof EE_Registration) { |
|
1035 | - // we display all attendee info for the primary registrant |
|
1036 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1037 | - && $registration->is_primary_registrant() |
|
1038 | - ) { |
|
1039 | - $this->checkout->primary_revisit = true; |
|
1040 | - break; |
|
1041 | - } |
|
1042 | - if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1043 | - // but hide info if it doesn't belong to you |
|
1044 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1045 | - $this->checkout->total_ticket_count--; |
|
1046 | - } |
|
1047 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1048 | - } |
|
1049 | - } |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1055 | - * |
|
1056 | - * @access private |
|
1057 | - * @param EE_Transaction $transaction |
|
1058 | - * @return array |
|
1059 | - * @throws InvalidDataTypeException |
|
1060 | - * @throws InvalidEntityException |
|
1061 | - * @throws EE_Error |
|
1062 | - */ |
|
1063 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1064 | - { |
|
1065 | - $att_nmbr = 0; |
|
1066 | - $registrations = array(); |
|
1067 | - if ($transaction instanceof EE_Transaction) { |
|
1068 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1069 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1070 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1071 | - // now let's add the cart items to the $transaction |
|
1072 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1073 | - // do the following for each ticket of this type they selected |
|
1074 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1075 | - $att_nmbr++; |
|
1076 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1077 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1078 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1079 | - array( |
|
1080 | - $transaction, |
|
1081 | - $line_item, |
|
1082 | - $att_nmbr, |
|
1083 | - $this->checkout->total_ticket_count, |
|
1084 | - ) |
|
1085 | - ); |
|
1086 | - // override capabilities for frontend registrations |
|
1087 | - if (! is_admin()) { |
|
1088 | - $CreateRegistrationCommand->setCapCheck( |
|
1089 | - new PublicCapabilities('', 'create_new_registration') |
|
1090 | - ); |
|
1091 | - } |
|
1092 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1093 | - if (! $registration instanceof EE_Registration) { |
|
1094 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1095 | - } |
|
1096 | - $registrations[ $registration->ID() ] = $registration; |
|
1097 | - } |
|
1098 | - } |
|
1099 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1100 | - } |
|
1101 | - return $registrations; |
|
1102 | - } |
|
1103 | - |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * sorts registrations by REG_count |
|
1107 | - * |
|
1108 | - * @access public |
|
1109 | - * @param EE_Registration $reg_A |
|
1110 | - * @param EE_Registration $reg_B |
|
1111 | - * @return int |
|
1112 | - */ |
|
1113 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1114 | - { |
|
1115 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1116 | - if ($reg_A->count() === $reg_B->count()) { |
|
1117 | - return 0; |
|
1118 | - } |
|
1119 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1120 | - } |
|
1121 | - |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * _final_verifications |
|
1125 | - * just makes sure that everything is set up correctly before proceeding |
|
1126 | - * |
|
1127 | - * @access private |
|
1128 | - * @return bool |
|
1129 | - * @throws EE_Error |
|
1130 | - */ |
|
1131 | - private function _final_verifications() |
|
1132 | - { |
|
1133 | - // filter checkout |
|
1134 | - $this->checkout = apply_filters( |
|
1135 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1136 | - $this->checkout |
|
1137 | - ); |
|
1138 | - // verify that current step is still set correctly |
|
1139 | - if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1140 | - EE_Error::add_error( |
|
1141 | - __( |
|
1142 | - 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', |
|
1143 | - 'event_espresso' |
|
1144 | - ), |
|
1145 | - __FILE__, |
|
1146 | - __FUNCTION__, |
|
1147 | - __LINE__ |
|
1148 | - ); |
|
1149 | - return false; |
|
1150 | - } |
|
1151 | - // if returning to SPCO, then verify that primary registrant is set |
|
1152 | - if (! empty($this->checkout->reg_url_link)) { |
|
1153 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1154 | - if (! $valid_registrant instanceof EE_Registration) { |
|
1155 | - EE_Error::add_error( |
|
1156 | - __( |
|
1157 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', |
|
1158 | - 'event_espresso' |
|
1159 | - ), |
|
1160 | - __FILE__, |
|
1161 | - __FUNCTION__, |
|
1162 | - __LINE__ |
|
1163 | - ); |
|
1164 | - return false; |
|
1165 | - } |
|
1166 | - $valid_registrant = null; |
|
1167 | - foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1168 | - if ($registration instanceof EE_Registration |
|
1169 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1170 | - ) { |
|
1171 | - $valid_registrant = $registration; |
|
1172 | - } |
|
1173 | - } |
|
1174 | - if (! $valid_registrant instanceof EE_Registration) { |
|
1175 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1176 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1177 | - // clear the session, mark the checkout as unverified, and try again |
|
1178 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1179 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1180 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1181 | - $this->_initialize(); |
|
1182 | - EE_Error::reset_notices(); |
|
1183 | - return false; |
|
1184 | - } |
|
1185 | - EE_Error::add_error( |
|
1186 | - __( |
|
1187 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
1188 | - 'event_espresso' |
|
1189 | - ), |
|
1190 | - __FILE__, |
|
1191 | - __FUNCTION__, |
|
1192 | - __LINE__ |
|
1193 | - ); |
|
1194 | - return false; |
|
1195 | - } |
|
1196 | - } |
|
1197 | - // now that things have been kinda sufficiently verified, |
|
1198 | - // let's add the checkout to the session so that it's available to other systems |
|
1199 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1200 | - return true; |
|
1201 | - } |
|
1202 | - |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * _initialize_reg_steps |
|
1206 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1207 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1208 | - * |
|
1209 | - * @access private |
|
1210 | - * @param bool $reinitializing |
|
1211 | - * @throws EE_Error |
|
1212 | - */ |
|
1213 | - private function _initialize_reg_steps($reinitializing = false) |
|
1214 | - { |
|
1215 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1216 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1217 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1218 | - if (! $reg_step->initialize_reg_step()) { |
|
1219 | - // if not initialized then maybe this step is being removed... |
|
1220 | - if (! $reinitializing && $reg_step->is_current_step()) { |
|
1221 | - // if it was the current step, then we need to start over here |
|
1222 | - $this->_initialize_reg_steps(true); |
|
1223 | - return; |
|
1224 | - } |
|
1225 | - continue; |
|
1226 | - } |
|
1227 | - // add css and JS for current step |
|
1228 | - $reg_step->enqueue_styles_and_scripts(); |
|
1229 | - // i18n |
|
1230 | - $reg_step->translate_js_strings(); |
|
1231 | - if ($reg_step->is_current_step()) { |
|
1232 | - // the text that appears on the reg step form submit button |
|
1233 | - $reg_step->set_submit_button_text(); |
|
1234 | - } |
|
1235 | - } |
|
1236 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1237 | - do_action( |
|
1238 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1239 | - $this->checkout->current_step |
|
1240 | - ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * _check_form_submission |
|
1246 | - * |
|
1247 | - * @access private |
|
1248 | - * @return boolean |
|
1249 | - */ |
|
1250 | - private function _check_form_submission() |
|
1251 | - { |
|
1252 | - // does this request require the reg form to be generated ? |
|
1253 | - if ($this->checkout->generate_reg_form) { |
|
1254 | - // ever heard that song by Blue Rodeo ? |
|
1255 | - try { |
|
1256 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1257 | - // if not displaying a form, then check for form submission |
|
1258 | - if ($this->checkout->process_form_submission |
|
1259 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1260 | - ) { |
|
1261 | - // clear out any old data in case this step is being run again |
|
1262 | - $this->checkout->current_step->set_valid_data(array()); |
|
1263 | - // capture submitted form data |
|
1264 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1265 | - apply_filters( |
|
1266 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1267 | - EE_Registry::instance()->REQ->params(), |
|
1268 | - $this->checkout |
|
1269 | - ) |
|
1270 | - ); |
|
1271 | - // validate submitted form data |
|
1272 | - if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1273 | - // thou shall not pass !!! |
|
1274 | - $this->checkout->continue_reg = false; |
|
1275 | - // any form validation errors? |
|
1276 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1277 | - EE_Error::add_error( |
|
1278 | - $this->checkout->current_step->reg_form->submission_error_message(), |
|
1279 | - __FILE__, |
|
1280 | - __FUNCTION__, |
|
1281 | - __LINE__ |
|
1282 | - ); |
|
1283 | - } |
|
1284 | - // well not really... what will happen is |
|
1285 | - // we'll just get redirected back to redo the current step |
|
1286 | - $this->go_to_next_step(); |
|
1287 | - return false; |
|
1288 | - } |
|
1289 | - } |
|
1290 | - } catch (EE_Error $e) { |
|
1291 | - $e->get_error(); |
|
1292 | - } |
|
1293 | - } |
|
1294 | - return true; |
|
1295 | - } |
|
1296 | - |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * _process_action |
|
1300 | - * |
|
1301 | - * @access private |
|
1302 | - * @return void |
|
1303 | - * @throws EE_Error |
|
1304 | - */ |
|
1305 | - private function _process_form_action() |
|
1306 | - { |
|
1307 | - // what cha wanna do? |
|
1308 | - switch ($this->checkout->action) { |
|
1309 | - // AJAX next step reg form |
|
1310 | - case 'display_spco_reg_step': |
|
1311 | - $this->checkout->redirect = false; |
|
1312 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1313 | - $this->checkout->json_response->set_reg_step_html( |
|
1314 | - $this->checkout->current_step->display_reg_form() |
|
1315 | - ); |
|
1316 | - } |
|
1317 | - break; |
|
1318 | - default: |
|
1319 | - // meh... do one of those other steps first |
|
1320 | - if (! empty($this->checkout->action) |
|
1321 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1322 | - ) { |
|
1323 | - // dynamically creates hook point like: |
|
1324 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1325 | - do_action( |
|
1326 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1327 | - $this->checkout->current_step |
|
1328 | - ); |
|
1329 | - // call action on current step |
|
1330 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1331 | - // good registrant, you get to proceed |
|
1332 | - if ($this->checkout->current_step->success_message() !== '' |
|
1333 | - && apply_filters( |
|
1334 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1335 | - false |
|
1336 | - ) |
|
1337 | - ) { |
|
1338 | - EE_Error::add_success( |
|
1339 | - $this->checkout->current_step->success_message() |
|
1340 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1341 | - ); |
|
1342 | - } |
|
1343 | - // pack it up, pack it in... |
|
1344 | - $this->_setup_redirect(); |
|
1345 | - } |
|
1346 | - // dynamically creates hook point like: |
|
1347 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1348 | - do_action( |
|
1349 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1350 | - $this->checkout->current_step |
|
1351 | - ); |
|
1352 | - } else { |
|
1353 | - EE_Error::add_error( |
|
1354 | - sprintf( |
|
1355 | - __( |
|
1356 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1357 | - 'event_espresso' |
|
1358 | - ), |
|
1359 | - $this->checkout->action, |
|
1360 | - $this->checkout->current_step->name() |
|
1361 | - ), |
|
1362 | - __FILE__, |
|
1363 | - __FUNCTION__, |
|
1364 | - __LINE__ |
|
1365 | - ); |
|
1366 | - } |
|
1367 | - // end default |
|
1368 | - } |
|
1369 | - // store our progress so far |
|
1370 | - $this->checkout->stash_transaction_and_checkout(); |
|
1371 | - // advance to the next step! If you pass GO, collect $200 |
|
1372 | - $this->go_to_next_step(); |
|
1373 | - } |
|
1374 | - |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * add_styles_and_scripts |
|
1378 | - * |
|
1379 | - * @access public |
|
1380 | - * @return void |
|
1381 | - */ |
|
1382 | - public function add_styles_and_scripts() |
|
1383 | - { |
|
1384 | - // i18n |
|
1385 | - $this->translate_js_strings(); |
|
1386 | - if ($this->checkout->admin_request) { |
|
1387 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1388 | - } else { |
|
1389 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1390 | - } |
|
1391 | - } |
|
1392 | - |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * translate_js_strings |
|
1396 | - * |
|
1397 | - * @access public |
|
1398 | - * @return void |
|
1399 | - */ |
|
1400 | - public function translate_js_strings() |
|
1401 | - { |
|
1402 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1403 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1404 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1405 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1406 | - 'event_espresso' |
|
1407 | - ); |
|
1408 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1409 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1410 | - 'event_espresso' |
|
1411 | - ); |
|
1412 | - EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1413 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1414 | - 'event_espresso' |
|
1415 | - ); |
|
1416 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1417 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1418 | - 'event_espresso' |
|
1419 | - ); |
|
1420 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1421 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
1422 | - 'event_espresso' |
|
1423 | - ); |
|
1424 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1425 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1426 | - 'event_espresso' |
|
1427 | - ); |
|
1428 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1429 | - __( |
|
1430 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1431 | - 'event_espresso' |
|
1432 | - ), |
|
1433 | - '<br/>', |
|
1434 | - '<br/>' |
|
1435 | - ); |
|
1436 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1437 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1438 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1439 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1440 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1441 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1442 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1443 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1444 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1445 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1446 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1447 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1448 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1449 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1450 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1451 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1452 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1453 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1454 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
1455 | - ); |
|
1456 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1457 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1458 | - true |
|
1459 | - ); |
|
1460 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1461 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1462 | - ); |
|
1463 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1464 | - 'M d, Y H:i:s', |
|
1465 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1466 | - ); |
|
1467 | - } |
|
1468 | - |
|
1469 | - |
|
1470 | - /** |
|
1471 | - * enqueue_styles_and_scripts |
|
1472 | - * |
|
1473 | - * @access public |
|
1474 | - * @return void |
|
1475 | - * @throws EE_Error |
|
1476 | - */ |
|
1477 | - public function enqueue_styles_and_scripts() |
|
1478 | - { |
|
1479 | - // load css |
|
1480 | - wp_register_style( |
|
1481 | - 'single_page_checkout', |
|
1482 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1483 | - array('espresso_default'), |
|
1484 | - EVENT_ESPRESSO_VERSION |
|
1485 | - ); |
|
1486 | - wp_enqueue_style('single_page_checkout'); |
|
1487 | - // load JS |
|
1488 | - wp_register_script( |
|
1489 | - 'jquery_plugin', |
|
1490 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1491 | - array('jquery'), |
|
1492 | - '1.0.1', |
|
1493 | - true |
|
1494 | - ); |
|
1495 | - wp_register_script( |
|
1496 | - 'jquery_countdown', |
|
1497 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1498 | - array('jquery_plugin'), |
|
1499 | - '2.1.0', |
|
1500 | - true |
|
1501 | - ); |
|
1502 | - wp_register_script( |
|
1503 | - 'single_page_checkout', |
|
1504 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1505 | - array('espresso_core', 'underscore', 'ee_form_section_validation'), |
|
1506 | - EVENT_ESPRESSO_VERSION, |
|
1507 | - true |
|
1508 | - ); |
|
1509 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1510 | - $this->checkout->registration_form->enqueue_js(); |
|
1511 | - } |
|
1512 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1513 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1514 | - } |
|
1515 | - wp_enqueue_script('single_page_checkout'); |
|
1516 | - if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { |
|
1517 | - wp_enqueue_script('jquery_countdown'); |
|
1518 | - } |
|
1519 | - /** |
|
1520 | - * global action hook for enqueueing styles and scripts with |
|
1521 | - * spco calls. |
|
1522 | - */ |
|
1523 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1524 | - /** |
|
1525 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1526 | - * The hook will end up being something like: |
|
1527 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1528 | - */ |
|
1529 | - do_action( |
|
1530 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1531 | - $this |
|
1532 | - ); |
|
1533 | - } |
|
1534 | - |
|
1535 | - |
|
1536 | - /** |
|
1537 | - * display the Registration Single Page Checkout Form |
|
1538 | - * |
|
1539 | - * @access private |
|
1540 | - * @return void |
|
1541 | - * @throws EE_Error |
|
1542 | - */ |
|
1543 | - private function _display_spco_reg_form() |
|
1544 | - { |
|
1545 | - // if registering via the admin, just display the reg form for the current step |
|
1546 | - if ($this->checkout->admin_request) { |
|
1547 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1548 | - } else { |
|
1549 | - // add powered by EE msg |
|
1550 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1551 | - $empty_cart = count($this->checkout->transaction |
|
1552 | - ->registrations($this->checkout->reg_cache_where_params)) < 1; |
|
1553 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1554 | - $cookies_not_set_msg = ''; |
|
1555 | - if ($empty_cart) { |
|
1556 | - $cookies_not_set_msg = apply_filters( |
|
1557 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1558 | - sprintf( |
|
1559 | - __( |
|
1560 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1561 | - 'event_espresso' |
|
1562 | - ), |
|
1563 | - '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
1564 | - '</div>', |
|
1565 | - '<h6 class="important-notice">', |
|
1566 | - '</h6>', |
|
1567 | - '<p>', |
|
1568 | - '</p>', |
|
1569 | - '<br />', |
|
1570 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1571 | - '</a>' |
|
1572 | - ) |
|
1573 | - ); |
|
1574 | - } |
|
1575 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1576 | - array( |
|
1577 | - 'name' => 'single-page-checkout', |
|
1578 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1579 | - 'layout_strategy' => |
|
1580 | - new EE_Template_Layout( |
|
1581 | - array( |
|
1582 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1583 | - 'template_args' => array( |
|
1584 | - 'empty_cart' => $empty_cart, |
|
1585 | - 'revisit' => $this->checkout->revisit, |
|
1586 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1587 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1588 | - ? $this->checkout->next_step->slug() |
|
1589 | - : '', |
|
1590 | - 'empty_msg' => apply_filters( |
|
1591 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1592 | - sprintf( |
|
1593 | - __( |
|
1594 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1595 | - 'event_espresso' |
|
1596 | - ), |
|
1597 | - '<a href="' |
|
1598 | - . get_post_type_archive_link('espresso_events') |
|
1599 | - . '" title="', |
|
1600 | - '">', |
|
1601 | - '</a>' |
|
1602 | - ) |
|
1603 | - ), |
|
1604 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1605 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1606 | - 'session_expiration' => gmdate( |
|
1607 | - 'M d, Y H:i:s', |
|
1608 | - EE_Registry::instance()->SSN->expiration() |
|
1609 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1610 | - ), |
|
1611 | - ), |
|
1612 | - ) |
|
1613 | - ), |
|
1614 | - ) |
|
1615 | - ); |
|
1616 | - // load template and add to output sent that gets filtered into the_content() |
|
1617 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1618 | - } |
|
1619 | - } |
|
1620 | - |
|
1621 | - |
|
1622 | - /** |
|
1623 | - * add_extra_finalize_registration_inputs |
|
1624 | - * |
|
1625 | - * @access public |
|
1626 | - * @param $next_step |
|
1627 | - * @internal param string $label |
|
1628 | - * @return void |
|
1629 | - */ |
|
1630 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1631 | - { |
|
1632 | - if ($next_step === 'finalize_registration') { |
|
1633 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1634 | - } |
|
1635 | - } |
|
1636 | - |
|
1637 | - |
|
1638 | - /** |
|
1639 | - * display_registration_footer |
|
1640 | - * |
|
1641 | - * @access public |
|
1642 | - * @return string |
|
1643 | - */ |
|
1644 | - public static function display_registration_footer() |
|
1645 | - { |
|
1646 | - if (apply_filters( |
|
1647 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1648 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1649 | - )) { |
|
1650 | - add_filter( |
|
1651 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1652 | - function ($url) { |
|
1653 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1654 | - } |
|
1655 | - ); |
|
1656 | - echo apply_filters( |
|
1657 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1658 | - \EEH_Template::powered_by_event_espresso( |
|
1659 | - '', |
|
1660 | - 'espresso-registration-footer-dv', |
|
1661 | - array('utm_content' => 'registration_checkout') |
|
1662 | - ) |
|
1663 | - ); |
|
1664 | - } |
|
1665 | - return ''; |
|
1666 | - } |
|
1667 | - |
|
1668 | - |
|
1669 | - /** |
|
1670 | - * unlock_transaction |
|
1671 | - * |
|
1672 | - * @access public |
|
1673 | - * @return void |
|
1674 | - * @throws EE_Error |
|
1675 | - */ |
|
1676 | - public function unlock_transaction() |
|
1677 | - { |
|
1678 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1679 | - $this->checkout->transaction->unlock(); |
|
1680 | - } |
|
1681 | - } |
|
1682 | - |
|
1683 | - |
|
1684 | - /** |
|
1685 | - * _setup_redirect |
|
1686 | - * |
|
1687 | - * @access private |
|
1688 | - * @return void |
|
1689 | - */ |
|
1690 | - private function _setup_redirect() |
|
1691 | - { |
|
1692 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1693 | - $this->checkout->redirect = true; |
|
1694 | - if (empty($this->checkout->redirect_url)) { |
|
1695 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1696 | - } |
|
1697 | - $this->checkout->redirect_url = apply_filters( |
|
1698 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1699 | - $this->checkout->redirect_url, |
|
1700 | - $this->checkout |
|
1701 | - ); |
|
1702 | - } |
|
1703 | - } |
|
1704 | - |
|
1705 | - |
|
1706 | - /** |
|
1707 | - * handle ajax message responses and redirects |
|
1708 | - * |
|
1709 | - * @access public |
|
1710 | - * @return void |
|
1711 | - * @throws EE_Error |
|
1712 | - */ |
|
1713 | - public function go_to_next_step() |
|
1714 | - { |
|
1715 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1716 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1717 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1718 | - } |
|
1719 | - $this->unlock_transaction(); |
|
1720 | - // just return for these conditions |
|
1721 | - if ($this->checkout->admin_request |
|
1722 | - || $this->checkout->action === 'redirect_form' |
|
1723 | - || $this->checkout->action === 'update_checkout' |
|
1724 | - ) { |
|
1725 | - return; |
|
1726 | - } |
|
1727 | - // AJAX response |
|
1728 | - $this->_handle_json_response(); |
|
1729 | - // redirect to next step or the Thank You page |
|
1730 | - $this->_handle_html_redirects(); |
|
1731 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1732 | - $this->_display_spco_reg_form(); |
|
1733 | - } |
|
1734 | - |
|
1735 | - |
|
1736 | - /** |
|
1737 | - * _handle_json_response |
|
1738 | - * |
|
1739 | - * @access protected |
|
1740 | - * @return void |
|
1741 | - */ |
|
1742 | - protected function _handle_json_response() |
|
1743 | - { |
|
1744 | - // if this is an ajax request |
|
1745 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1746 | - $this->checkout->json_response->set_registration_time_limit( |
|
1747 | - $this->checkout->get_registration_time_limit() |
|
1748 | - ); |
|
1749 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1750 | - // just send the ajax ( |
|
1751 | - $json_response = apply_filters( |
|
1752 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1753 | - $this->checkout->json_response |
|
1754 | - ); |
|
1755 | - echo $json_response; |
|
1756 | - exit(); |
|
1757 | - } |
|
1758 | - } |
|
1759 | - |
|
1760 | - |
|
1761 | - /** |
|
1762 | - * _handle_redirects |
|
1763 | - * |
|
1764 | - * @access protected |
|
1765 | - * @return void |
|
1766 | - */ |
|
1767 | - protected function _handle_html_redirects() |
|
1768 | - { |
|
1769 | - // going somewhere ? |
|
1770 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1771 | - // store notices in a transient |
|
1772 | - EE_Error::get_notices(false, true, true); |
|
1773 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1774 | - exit(); |
|
1775 | - } |
|
1776 | - } |
|
1777 | - |
|
1778 | - |
|
1779 | - /** |
|
1780 | - * set_checkout_anchor |
|
1781 | - * |
|
1782 | - * @access public |
|
1783 | - * @return void |
|
1784 | - */ |
|
1785 | - public function set_checkout_anchor() |
|
1786 | - { |
|
1787 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1788 | - } |
|
1789 | - |
|
1790 | - /** |
|
1791 | - * getRegistrationExpirationNotice |
|
1792 | - * |
|
1793 | - * @since 4.9.59.p |
|
1794 | - * @access public |
|
1795 | - * @return string |
|
1796 | - */ |
|
1797 | - public static function getRegistrationExpirationNotice() |
|
1798 | - { |
|
1799 | - return sprintf( |
|
1800 | - __( |
|
1801 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s', |
|
1802 | - 'event_espresso' |
|
1803 | - ), |
|
1804 | - '<h4 class="important-notice">', |
|
1805 | - '</h4>', |
|
1806 | - '<br />', |
|
1807 | - '<p>', |
|
1808 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1809 | - '">', |
|
1810 | - '</a>', |
|
1811 | - '</p>' |
|
1812 | - ); |
|
1813 | - } |
|
18 | + /** |
|
19 | + * $_initialized - has the SPCO controller already been initialized ? |
|
20 | + * |
|
21 | + * @access private |
|
22 | + * @var bool $_initialized |
|
23 | + */ |
|
24 | + private static $_initialized = false; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
29 | + * |
|
30 | + * @access private |
|
31 | + * @var bool $_valid_checkout |
|
32 | + */ |
|
33 | + private static $_checkout_verified = true; |
|
34 | + |
|
35 | + /** |
|
36 | + * $_reg_steps_array - holds initial array of reg steps |
|
37 | + * |
|
38 | + * @access private |
|
39 | + * @var array $_reg_steps_array |
|
40 | + */ |
|
41 | + private static $_reg_steps_array = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @var EE_Checkout $checkout |
|
48 | + */ |
|
49 | + public $checkout; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return EED_Module|EED_Single_Page_Checkout |
|
54 | + */ |
|
55 | + public static function instance() |
|
56 | + { |
|
57 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
58 | + return parent::get_instance(__CLASS__); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return EE_CART |
|
64 | + */ |
|
65 | + public function cart() |
|
66 | + { |
|
67 | + return $this->checkout->cart; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return EE_Transaction |
|
73 | + */ |
|
74 | + public function transaction() |
|
75 | + { |
|
76 | + return $this->checkout->transaction; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
82 | + * |
|
83 | + * @access public |
|
84 | + * @return void |
|
85 | + * @throws EE_Error |
|
86 | + */ |
|
87 | + public static function set_hooks() |
|
88 | + { |
|
89 | + EED_Single_Page_Checkout::set_definitions(); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @return void |
|
98 | + * @throws EE_Error |
|
99 | + */ |
|
100 | + public static function set_hooks_admin() |
|
101 | + { |
|
102 | + EED_Single_Page_Checkout::set_definitions(); |
|
103 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
104 | + return; |
|
105 | + } |
|
106 | + // going to start an output buffer in case anything gets accidentally output |
|
107 | + // that might disrupt our JSON response |
|
108 | + ob_start(); |
|
109 | + EED_Single_Page_Checkout::load_request_handler(); |
|
110 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
111 | + // set ajax hooks |
|
112 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
113 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
114 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
115 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
116 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
117 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * process ajax request |
|
123 | + * |
|
124 | + * @param string $ajax_action |
|
125 | + * @throws EE_Error |
|
126 | + */ |
|
127 | + public static function process_ajax_request($ajax_action) |
|
128 | + { |
|
129 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
130 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * ajax display registration step |
|
136 | + * |
|
137 | + * @throws EE_Error |
|
138 | + */ |
|
139 | + public static function display_reg_step() |
|
140 | + { |
|
141 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * ajax process registration step |
|
147 | + * |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + public static function process_reg_step() |
|
151 | + { |
|
152 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * ajax process registration step |
|
158 | + * |
|
159 | + * @throws EE_Error |
|
160 | + */ |
|
161 | + public static function update_reg_step() |
|
162 | + { |
|
163 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * update_checkout |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @return void |
|
172 | + * @throws EE_Error |
|
173 | + */ |
|
174 | + public static function update_checkout() |
|
175 | + { |
|
176 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * load_request_handler |
|
182 | + * |
|
183 | + * @access public |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public static function load_request_handler() |
|
187 | + { |
|
188 | + // load core Request_Handler class |
|
189 | + if (EE_Registry::instance()->REQ !== null) { |
|
190 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * set_definitions |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @return void |
|
200 | + * @throws EE_Error |
|
201 | + */ |
|
202 | + public static function set_definitions() |
|
203 | + { |
|
204 | + if (defined('SPCO_BASE_PATH')) { |
|
205 | + return; |
|
206 | + } |
|
207 | + define( |
|
208 | + 'SPCO_BASE_PATH', |
|
209 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
210 | + ); |
|
211 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
212 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
213 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
214 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
215 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
216 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
217 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
218 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
219 | + ); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * load_reg_steps |
|
225 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
226 | + * |
|
227 | + * @access private |
|
228 | + * @throws EE_Error |
|
229 | + */ |
|
230 | + public static function load_reg_steps() |
|
231 | + { |
|
232 | + static $reg_steps_loaded = false; |
|
233 | + if ($reg_steps_loaded) { |
|
234 | + return; |
|
235 | + } |
|
236 | + // filter list of reg_steps |
|
237 | + $reg_steps_to_load = (array) apply_filters( |
|
238 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
239 | + EED_Single_Page_Checkout::get_reg_steps() |
|
240 | + ); |
|
241 | + // sort by key (order) |
|
242 | + ksort($reg_steps_to_load); |
|
243 | + // loop through folders |
|
244 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
245 | + // we need a |
|
246 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
247 | + // copy over to the reg_steps_array |
|
248 | + EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
249 | + // register custom key route for each reg step |
|
250 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
251 | + EE_Config::register_route( |
|
252 | + $reg_step['slug'], |
|
253 | + 'EED_Single_Page_Checkout', |
|
254 | + 'run', |
|
255 | + 'step' |
|
256 | + ); |
|
257 | + // add AJAX or other hooks |
|
258 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
259 | + // setup autoloaders if necessary |
|
260 | + if (! class_exists($reg_step['class_name'])) { |
|
261 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
262 | + $reg_step['file_path'], |
|
263 | + true |
|
264 | + ); |
|
265 | + } |
|
266 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
267 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
268 | + } |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | + $reg_steps_loaded = true; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * get_reg_steps |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @return array |
|
281 | + */ |
|
282 | + public static function get_reg_steps() |
|
283 | + { |
|
284 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
285 | + if (empty($reg_steps)) { |
|
286 | + $reg_steps = array( |
|
287 | + 10 => array( |
|
288 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
289 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
290 | + 'slug' => 'attendee_information', |
|
291 | + 'has_hooks' => false, |
|
292 | + ), |
|
293 | + 30 => array( |
|
294 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
295 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
296 | + 'slug' => 'payment_options', |
|
297 | + 'has_hooks' => true, |
|
298 | + ), |
|
299 | + 999 => array( |
|
300 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
301 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
302 | + 'slug' => 'finalize_registration', |
|
303 | + 'has_hooks' => false, |
|
304 | + ), |
|
305 | + ); |
|
306 | + } |
|
307 | + return $reg_steps; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * registration_checkout_for_admin |
|
313 | + * |
|
314 | + * @access public |
|
315 | + * @return string |
|
316 | + * @throws EE_Error |
|
317 | + */ |
|
318 | + public static function registration_checkout_for_admin() |
|
319 | + { |
|
320 | + EED_Single_Page_Checkout::load_request_handler(); |
|
321 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
322 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
323 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
324 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
325 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
326 | + return EE_Registry::instance()->REQ->get_output(); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * process_registration_from_admin |
|
332 | + * |
|
333 | + * @access public |
|
334 | + * @return \EE_Transaction |
|
335 | + * @throws EE_Error |
|
336 | + */ |
|
337 | + public static function process_registration_from_admin() |
|
338 | + { |
|
339 | + EED_Single_Page_Checkout::load_request_handler(); |
|
340 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
341 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
342 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
343 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
344 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
345 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
346 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
347 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
348 | + if ($final_reg_step->process_reg_step()) { |
|
349 | + $final_reg_step->set_completed(); |
|
350 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
351 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + return null; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * run |
|
361 | + * |
|
362 | + * @access public |
|
363 | + * @param WP_Query $WP_Query |
|
364 | + * @return void |
|
365 | + * @throws EE_Error |
|
366 | + */ |
|
367 | + public function run($WP_Query) |
|
368 | + { |
|
369 | + if ($WP_Query instanceof WP_Query |
|
370 | + && $WP_Query->is_main_query() |
|
371 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
372 | + && $this->_is_reg_checkout() |
|
373 | + ) { |
|
374 | + $this->_initialize(); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * determines whether current url matches reg page url |
|
381 | + * |
|
382 | + * @return bool |
|
383 | + */ |
|
384 | + protected function _is_reg_checkout() |
|
385 | + { |
|
386 | + // get current permalink for reg page without any extra query args |
|
387 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
388 | + // get request URI for current request, but without the scheme or host |
|
389 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
390 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
391 | + // get array of query args from the current request URI |
|
392 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
393 | + // grab page id if it is set |
|
394 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
395 | + // and remove the page id from the query args (we will re-add it later) |
|
396 | + unset($query_args['page_id']); |
|
397 | + // now strip all query args from current request URI |
|
398 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
399 | + // and re-add the page id if it was set |
|
400 | + if ($page_id) { |
|
401 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
402 | + } |
|
403 | + // remove slashes and ? |
|
404 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
405 | + // is current request URI part of the known full reg page URL ? |
|
406 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * @param WP_Query $wp_query |
|
412 | + * @return void |
|
413 | + * @throws EE_Error |
|
414 | + */ |
|
415 | + public static function init($wp_query) |
|
416 | + { |
|
417 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * _initialize - initial module setup |
|
423 | + * |
|
424 | + * @access private |
|
425 | + * @throws EE_Error |
|
426 | + * @return void |
|
427 | + */ |
|
428 | + private function _initialize() |
|
429 | + { |
|
430 | + // ensure SPCO doesn't run twice |
|
431 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
432 | + return; |
|
433 | + } |
|
434 | + try { |
|
435 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
436 | + $this->_verify_session(); |
|
437 | + // setup the EE_Checkout object |
|
438 | + $this->checkout = $this->_initialize_checkout(); |
|
439 | + // filter checkout |
|
440 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
441 | + // get the $_GET |
|
442 | + $this->_get_request_vars(); |
|
443 | + if ($this->_block_bots()) { |
|
444 | + return; |
|
445 | + } |
|
446 | + // filter continue_reg |
|
447 | + $this->checkout->continue_reg = apply_filters( |
|
448 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
449 | + true, |
|
450 | + $this->checkout |
|
451 | + ); |
|
452 | + // load the reg steps array |
|
453 | + if (! $this->_load_and_instantiate_reg_steps()) { |
|
454 | + EED_Single_Page_Checkout::$_initialized = true; |
|
455 | + return; |
|
456 | + } |
|
457 | + // set the current step |
|
458 | + $this->checkout->set_current_step($this->checkout->step); |
|
459 | + // and the next step |
|
460 | + $this->checkout->set_next_step(); |
|
461 | + // verify that everything has been setup correctly |
|
462 | + if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
463 | + EED_Single_Page_Checkout::$_initialized = true; |
|
464 | + return; |
|
465 | + } |
|
466 | + // lock the transaction |
|
467 | + $this->checkout->transaction->lock(); |
|
468 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
469 | + $this->checkout->refresh_all_entities(); |
|
470 | + // set amount owing |
|
471 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
472 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
473 | + $this->_initialize_reg_steps(); |
|
474 | + // DEBUG LOG |
|
475 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
476 | + // get reg form |
|
477 | + if (! $this->_check_form_submission()) { |
|
478 | + EED_Single_Page_Checkout::$_initialized = true; |
|
479 | + return; |
|
480 | + } |
|
481 | + // checkout the action!!! |
|
482 | + $this->_process_form_action(); |
|
483 | + // add some style and make it dance |
|
484 | + $this->add_styles_and_scripts(); |
|
485 | + // kk... SPCO has successfully run |
|
486 | + EED_Single_Page_Checkout::$_initialized = true; |
|
487 | + // set no cache headers and constants |
|
488 | + EE_System::do_not_cache(); |
|
489 | + // add anchor |
|
490 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
491 | + // remove transaction lock |
|
492 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
493 | + } catch (Exception $e) { |
|
494 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * _verify_session |
|
501 | + * checks that the session is valid and not expired |
|
502 | + * |
|
503 | + * @access private |
|
504 | + * @throws EE_Error |
|
505 | + */ |
|
506 | + private function _verify_session() |
|
507 | + { |
|
508 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
509 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
510 | + } |
|
511 | + $clear_session_requested = filter_var( |
|
512 | + EE_Registry::instance()->REQ->get('clear_session', false), |
|
513 | + FILTER_VALIDATE_BOOLEAN |
|
514 | + ); |
|
515 | + // is session still valid ? |
|
516 | + if ($clear_session_requested |
|
517 | + || (EE_Registry::instance()->SSN->expired() |
|
518 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
519 | + ) |
|
520 | + ) { |
|
521 | + $this->checkout = new EE_Checkout(); |
|
522 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
523 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
524 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
525 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
526 | + if (! $clear_session_requested) { |
|
527 | + EE_Error::add_attention( |
|
528 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
529 | + __FILE__, |
|
530 | + __FUNCTION__, |
|
531 | + __LINE__ |
|
532 | + ); |
|
533 | + } |
|
534 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * _initialize_checkout |
|
541 | + * loads and instantiates EE_Checkout |
|
542 | + * |
|
543 | + * @access private |
|
544 | + * @throws EE_Error |
|
545 | + * @return EE_Checkout |
|
546 | + */ |
|
547 | + private function _initialize_checkout() |
|
548 | + { |
|
549 | + // look in session for existing checkout |
|
550 | + /** @type EE_Checkout $checkout */ |
|
551 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
552 | + // verify |
|
553 | + if (! $checkout instanceof EE_Checkout) { |
|
554 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
555 | + $checkout = EE_Registry::instance()->load_file( |
|
556 | + SPCO_INC_PATH, |
|
557 | + 'EE_Checkout', |
|
558 | + 'class', |
|
559 | + array(), |
|
560 | + false |
|
561 | + ); |
|
562 | + } else { |
|
563 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
564 | + $this->unlock_transaction(); |
|
565 | + wp_safe_redirect($checkout->redirect_url); |
|
566 | + exit(); |
|
567 | + } |
|
568 | + } |
|
569 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
570 | + // verify again |
|
571 | + if (! $checkout instanceof EE_Checkout) { |
|
572 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
573 | + } |
|
574 | + // reset anything that needs a clean slate for each request |
|
575 | + $checkout->reset_for_current_request(); |
|
576 | + return $checkout; |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * _get_request_vars |
|
582 | + * |
|
583 | + * @access private |
|
584 | + * @return void |
|
585 | + * @throws EE_Error |
|
586 | + */ |
|
587 | + private function _get_request_vars() |
|
588 | + { |
|
589 | + // load classes |
|
590 | + EED_Single_Page_Checkout::load_request_handler(); |
|
591 | + // make sure this request is marked as belonging to EE |
|
592 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
593 | + // which step is being requested ? |
|
594 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
595 | + // which step is being edited ? |
|
596 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
597 | + // and what we're doing on the current step |
|
598 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
599 | + // timestamp |
|
600 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
601 | + // returning to edit ? |
|
602 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
603 | + // add reg url link to registration query params |
|
604 | + if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
605 | + $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
606 | + } |
|
607 | + // or some other kind of revisit ? |
|
608 | + $this->checkout->revisit = filter_var( |
|
609 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
610 | + FILTER_VALIDATE_BOOLEAN |
|
611 | + ); |
|
612 | + // and whether or not to generate a reg form for this request |
|
613 | + $this->checkout->generate_reg_form = filter_var( |
|
614 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
615 | + FILTER_VALIDATE_BOOLEAN |
|
616 | + ); |
|
617 | + // and whether or not to process a reg form submission for this request |
|
618 | + $this->checkout->process_form_submission = filter_var( |
|
619 | + EE_Registry::instance()->REQ->get( |
|
620 | + 'process_form_submission', |
|
621 | + $this->checkout->action === 'process_reg_step' |
|
622 | + ), |
|
623 | + FILTER_VALIDATE_BOOLEAN |
|
624 | + ); |
|
625 | + $this->checkout->process_form_submission = filter_var( |
|
626 | + $this->checkout->action !== 'display_spco_reg_step' |
|
627 | + ? $this->checkout->process_form_submission |
|
628 | + : false, |
|
629 | + FILTER_VALIDATE_BOOLEAN |
|
630 | + ); |
|
631 | + // $this->_display_request_vars(); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * _display_request_vars |
|
637 | + * |
|
638 | + * @access protected |
|
639 | + * @return void |
|
640 | + */ |
|
641 | + protected function _display_request_vars() |
|
642 | + { |
|
643 | + if (! WP_DEBUG) { |
|
644 | + return; |
|
645 | + } |
|
646 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
647 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
648 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
649 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
650 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
651 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
652 | + EEH_Debug_Tools::printr( |
|
653 | + $this->checkout->generate_reg_form, |
|
654 | + '$this->checkout->generate_reg_form', |
|
655 | + __FILE__, |
|
656 | + __LINE__ |
|
657 | + ); |
|
658 | + EEH_Debug_Tools::printr( |
|
659 | + $this->checkout->process_form_submission, |
|
660 | + '$this->checkout->process_form_submission', |
|
661 | + __FILE__, |
|
662 | + __LINE__ |
|
663 | + ); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * _block_bots |
|
669 | + * checks that the incoming request has either of the following set: |
|
670 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
671 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
672 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
673 | + * then where you coming from man? |
|
674 | + * |
|
675 | + * @return boolean |
|
676 | + */ |
|
677 | + private function _block_bots() |
|
678 | + { |
|
679 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
680 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
681 | + return true; |
|
682 | + } |
|
683 | + return false; |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * _get_first_step |
|
689 | + * gets slug for first step in $_reg_steps_array |
|
690 | + * |
|
691 | + * @access private |
|
692 | + * @throws EE_Error |
|
693 | + * @return string |
|
694 | + */ |
|
695 | + private function _get_first_step() |
|
696 | + { |
|
697 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
698 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * instantiates each reg step based on the loaded reg_steps array |
|
704 | + * |
|
705 | + * @return bool |
|
706 | + * @throws EE_Error |
|
707 | + * @throws InvalidArgumentException |
|
708 | + * @throws InvalidDataTypeException |
|
709 | + * @throws InvalidInterfaceException |
|
710 | + */ |
|
711 | + private function _load_and_instantiate_reg_steps() |
|
712 | + { |
|
713 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
714 | + // have reg_steps already been instantiated ? |
|
715 | + if (empty($this->checkout->reg_steps) |
|
716 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
717 | + ) { |
|
718 | + // if not, then loop through raw reg steps array |
|
719 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
720 | + if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
721 | + return false; |
|
722 | + } |
|
723 | + } |
|
724 | + if (isset($this->checkout->reg_steps['registration_confirmation'])) { |
|
725 | + // skip the registration_confirmation page ? |
|
726 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
727 | + // just remove it from the reg steps array |
|
728 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
729 | + } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
730 | + ) { |
|
731 | + // set the order to something big like 100 |
|
732 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
733 | + } |
|
734 | + } |
|
735 | + // filter the array for good luck |
|
736 | + $this->checkout->reg_steps = apply_filters( |
|
737 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
738 | + $this->checkout->reg_steps |
|
739 | + ); |
|
740 | + // finally re-sort based on the reg step class order properties |
|
741 | + $this->checkout->sort_reg_steps(); |
|
742 | + } else { |
|
743 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
744 | + // set all current step stati to FALSE |
|
745 | + $reg_step->set_is_current_step(false); |
|
746 | + } |
|
747 | + } |
|
748 | + if (empty($this->checkout->reg_steps)) { |
|
749 | + EE_Error::add_error( |
|
750 | + __('No Reg Steps were loaded..', 'event_espresso'), |
|
751 | + __FILE__, |
|
752 | + __FUNCTION__, |
|
753 | + __LINE__ |
|
754 | + ); |
|
755 | + return false; |
|
756 | + } |
|
757 | + // make reg step details available to JS |
|
758 | + $this->checkout->set_reg_step_JSON_info(); |
|
759 | + return true; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * _load_and_instantiate_reg_step |
|
765 | + * |
|
766 | + * @access private |
|
767 | + * @param array $reg_step |
|
768 | + * @param int $order |
|
769 | + * @return bool |
|
770 | + */ |
|
771 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
772 | + { |
|
773 | + // we need a file_path, class_name, and slug to add a reg step |
|
774 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
775 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
776 | + if ($this->checkout->reg_url_link |
|
777 | + && $this->checkout->step !== $reg_step['slug'] |
|
778 | + && $reg_step['slug'] !== 'finalize_registration' |
|
779 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
780 | + && apply_filters( |
|
781 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
782 | + true, |
|
783 | + $reg_step, |
|
784 | + $this->checkout |
|
785 | + ) |
|
786 | + ) { |
|
787 | + return true; |
|
788 | + } |
|
789 | + // instantiate step class using file path and class name |
|
790 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
791 | + $reg_step['file_path'], |
|
792 | + $reg_step['class_name'], |
|
793 | + 'class', |
|
794 | + $this->checkout, |
|
795 | + false |
|
796 | + ); |
|
797 | + // did we gets the goods ? |
|
798 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
799 | + // set reg step order based on config |
|
800 | + $reg_step_obj->set_order($order); |
|
801 | + // add instantiated reg step object to the master reg steps array |
|
802 | + $this->checkout->add_reg_step($reg_step_obj); |
|
803 | + } else { |
|
804 | + EE_Error::add_error( |
|
805 | + __('The current step could not be set.', 'event_espresso'), |
|
806 | + __FILE__, |
|
807 | + __FUNCTION__, |
|
808 | + __LINE__ |
|
809 | + ); |
|
810 | + return false; |
|
811 | + } |
|
812 | + } else { |
|
813 | + if (WP_DEBUG) { |
|
814 | + EE_Error::add_error( |
|
815 | + sprintf( |
|
816 | + __( |
|
817 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
818 | + 'event_espresso' |
|
819 | + ), |
|
820 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
821 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
822 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
823 | + '<ul>', |
|
824 | + '<li>', |
|
825 | + '</li>', |
|
826 | + '</ul>' |
|
827 | + ), |
|
828 | + __FILE__, |
|
829 | + __FUNCTION__, |
|
830 | + __LINE__ |
|
831 | + ); |
|
832 | + } |
|
833 | + return false; |
|
834 | + } |
|
835 | + return true; |
|
836 | + } |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * _verify_transaction_and_get_registrations |
|
841 | + * |
|
842 | + * @access private |
|
843 | + * @return bool |
|
844 | + * @throws InvalidDataTypeException |
|
845 | + * @throws InvalidEntityException |
|
846 | + * @throws EE_Error |
|
847 | + */ |
|
848 | + private function _verify_transaction_and_get_registrations() |
|
849 | + { |
|
850 | + // was there already a valid transaction in the checkout from the session ? |
|
851 | + if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
852 | + // get transaction from db or session |
|
853 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
854 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
855 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
856 | + if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
857 | + EE_Error::add_error( |
|
858 | + __( |
|
859 | + 'Your Registration and Transaction information could not be retrieved from the db.', |
|
860 | + 'event_espresso' |
|
861 | + ), |
|
862 | + __FILE__, |
|
863 | + __FUNCTION__, |
|
864 | + __LINE__ |
|
865 | + ); |
|
866 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
867 | + // add some style and make it dance |
|
868 | + $this->add_styles_and_scripts(); |
|
869 | + EED_Single_Page_Checkout::$_initialized = true; |
|
870 | + return false; |
|
871 | + } |
|
872 | + // and the registrations for the transaction |
|
873 | + $this->_get_registrations($this->checkout->transaction); |
|
874 | + } |
|
875 | + return true; |
|
876 | + } |
|
877 | + |
|
878 | + |
|
879 | + /** |
|
880 | + * _get_transaction_and_cart_for_previous_visit |
|
881 | + * |
|
882 | + * @access private |
|
883 | + * @return mixed EE_Transaction|NULL |
|
884 | + */ |
|
885 | + private function _get_transaction_and_cart_for_previous_visit() |
|
886 | + { |
|
887 | + /** @var $TXN_model EEM_Transaction */ |
|
888 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
889 | + // because the reg_url_link is present in the request, |
|
890 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
891 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
892 | + // verify transaction |
|
893 | + if ($transaction instanceof EE_Transaction) { |
|
894 | + // and get the cart that was used for that transaction |
|
895 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
896 | + return $transaction; |
|
897 | + } |
|
898 | + EE_Error::add_error( |
|
899 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
900 | + __FILE__, |
|
901 | + __FUNCTION__, |
|
902 | + __LINE__ |
|
903 | + ); |
|
904 | + return null; |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * _get_cart_for_transaction |
|
910 | + * |
|
911 | + * @access private |
|
912 | + * @param EE_Transaction $transaction |
|
913 | + * @return EE_Cart |
|
914 | + */ |
|
915 | + private function _get_cart_for_transaction($transaction) |
|
916 | + { |
|
917 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * get_cart_for_transaction |
|
923 | + * |
|
924 | + * @access public |
|
925 | + * @param EE_Transaction $transaction |
|
926 | + * @return EE_Cart |
|
927 | + */ |
|
928 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
929 | + { |
|
930 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * _get_transaction_and_cart_for_current_session |
|
936 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
937 | + * |
|
938 | + * @access private |
|
939 | + * @return EE_Transaction |
|
940 | + * @throws EE_Error |
|
941 | + */ |
|
942 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
943 | + { |
|
944 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
945 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
946 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
947 | + // and then create a new transaction |
|
948 | + $transaction = $this->_initialize_transaction(); |
|
949 | + // verify transaction |
|
950 | + if ($transaction instanceof EE_Transaction) { |
|
951 | + // save it so that we have an ID for other objects to use |
|
952 | + $transaction->save(); |
|
953 | + // and save TXN data to the cart |
|
954 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
955 | + } else { |
|
956 | + EE_Error::add_error( |
|
957 | + __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
958 | + __FILE__, |
|
959 | + __FUNCTION__, |
|
960 | + __LINE__ |
|
961 | + ); |
|
962 | + } |
|
963 | + return $transaction; |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
969 | + * |
|
970 | + * @access private |
|
971 | + * @return mixed EE_Transaction|NULL |
|
972 | + */ |
|
973 | + private function _initialize_transaction() |
|
974 | + { |
|
975 | + try { |
|
976 | + // ensure cart totals have been calculated |
|
977 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
978 | + // grab the cart grand total |
|
979 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
980 | + // create new TXN |
|
981 | + $transaction = EE_Transaction::new_instance( |
|
982 | + array( |
|
983 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
984 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
985 | + 'TXN_paid' => 0, |
|
986 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
987 | + ) |
|
988 | + ); |
|
989 | + // save it so that we have an ID for other objects to use |
|
990 | + $transaction->save(); |
|
991 | + // set cron job for following up on TXNs after their session has expired |
|
992 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
993 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
994 | + $transaction->ID() |
|
995 | + ); |
|
996 | + return $transaction; |
|
997 | + } catch (Exception $e) { |
|
998 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
999 | + } |
|
1000 | + return null; |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * _get_registrations |
|
1006 | + * |
|
1007 | + * @access private |
|
1008 | + * @param EE_Transaction $transaction |
|
1009 | + * @return void |
|
1010 | + * @throws InvalidDataTypeException |
|
1011 | + * @throws InvalidEntityException |
|
1012 | + * @throws EE_Error |
|
1013 | + */ |
|
1014 | + private function _get_registrations(EE_Transaction $transaction) |
|
1015 | + { |
|
1016 | + // first step: grab the registrants { : o |
|
1017 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1018 | + $this->checkout->total_ticket_count = count($registrations); |
|
1019 | + // verify registrations have been set |
|
1020 | + if (empty($registrations)) { |
|
1021 | + // if no cached registrations, then check the db |
|
1022 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1023 | + // still nothing ? well as long as this isn't a revisit |
|
1024 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
1025 | + // generate new registrations from scratch |
|
1026 | + $registrations = $this->_initialize_registrations($transaction); |
|
1027 | + } |
|
1028 | + } |
|
1029 | + // sort by their original registration order |
|
1030 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1031 | + // then loop thru the array |
|
1032 | + foreach ($registrations as $registration) { |
|
1033 | + // verify each registration |
|
1034 | + if ($registration instanceof EE_Registration) { |
|
1035 | + // we display all attendee info for the primary registrant |
|
1036 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1037 | + && $registration->is_primary_registrant() |
|
1038 | + ) { |
|
1039 | + $this->checkout->primary_revisit = true; |
|
1040 | + break; |
|
1041 | + } |
|
1042 | + if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1043 | + // but hide info if it doesn't belong to you |
|
1044 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1045 | + $this->checkout->total_ticket_count--; |
|
1046 | + } |
|
1047 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1048 | + } |
|
1049 | + } |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1055 | + * |
|
1056 | + * @access private |
|
1057 | + * @param EE_Transaction $transaction |
|
1058 | + * @return array |
|
1059 | + * @throws InvalidDataTypeException |
|
1060 | + * @throws InvalidEntityException |
|
1061 | + * @throws EE_Error |
|
1062 | + */ |
|
1063 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1064 | + { |
|
1065 | + $att_nmbr = 0; |
|
1066 | + $registrations = array(); |
|
1067 | + if ($transaction instanceof EE_Transaction) { |
|
1068 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1069 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1070 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1071 | + // now let's add the cart items to the $transaction |
|
1072 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1073 | + // do the following for each ticket of this type they selected |
|
1074 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1075 | + $att_nmbr++; |
|
1076 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1077 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1078 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1079 | + array( |
|
1080 | + $transaction, |
|
1081 | + $line_item, |
|
1082 | + $att_nmbr, |
|
1083 | + $this->checkout->total_ticket_count, |
|
1084 | + ) |
|
1085 | + ); |
|
1086 | + // override capabilities for frontend registrations |
|
1087 | + if (! is_admin()) { |
|
1088 | + $CreateRegistrationCommand->setCapCheck( |
|
1089 | + new PublicCapabilities('', 'create_new_registration') |
|
1090 | + ); |
|
1091 | + } |
|
1092 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1093 | + if (! $registration instanceof EE_Registration) { |
|
1094 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1095 | + } |
|
1096 | + $registrations[ $registration->ID() ] = $registration; |
|
1097 | + } |
|
1098 | + } |
|
1099 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1100 | + } |
|
1101 | + return $registrations; |
|
1102 | + } |
|
1103 | + |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * sorts registrations by REG_count |
|
1107 | + * |
|
1108 | + * @access public |
|
1109 | + * @param EE_Registration $reg_A |
|
1110 | + * @param EE_Registration $reg_B |
|
1111 | + * @return int |
|
1112 | + */ |
|
1113 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1114 | + { |
|
1115 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1116 | + if ($reg_A->count() === $reg_B->count()) { |
|
1117 | + return 0; |
|
1118 | + } |
|
1119 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1120 | + } |
|
1121 | + |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * _final_verifications |
|
1125 | + * just makes sure that everything is set up correctly before proceeding |
|
1126 | + * |
|
1127 | + * @access private |
|
1128 | + * @return bool |
|
1129 | + * @throws EE_Error |
|
1130 | + */ |
|
1131 | + private function _final_verifications() |
|
1132 | + { |
|
1133 | + // filter checkout |
|
1134 | + $this->checkout = apply_filters( |
|
1135 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1136 | + $this->checkout |
|
1137 | + ); |
|
1138 | + // verify that current step is still set correctly |
|
1139 | + if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1140 | + EE_Error::add_error( |
|
1141 | + __( |
|
1142 | + 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', |
|
1143 | + 'event_espresso' |
|
1144 | + ), |
|
1145 | + __FILE__, |
|
1146 | + __FUNCTION__, |
|
1147 | + __LINE__ |
|
1148 | + ); |
|
1149 | + return false; |
|
1150 | + } |
|
1151 | + // if returning to SPCO, then verify that primary registrant is set |
|
1152 | + if (! empty($this->checkout->reg_url_link)) { |
|
1153 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1154 | + if (! $valid_registrant instanceof EE_Registration) { |
|
1155 | + EE_Error::add_error( |
|
1156 | + __( |
|
1157 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', |
|
1158 | + 'event_espresso' |
|
1159 | + ), |
|
1160 | + __FILE__, |
|
1161 | + __FUNCTION__, |
|
1162 | + __LINE__ |
|
1163 | + ); |
|
1164 | + return false; |
|
1165 | + } |
|
1166 | + $valid_registrant = null; |
|
1167 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1168 | + if ($registration instanceof EE_Registration |
|
1169 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1170 | + ) { |
|
1171 | + $valid_registrant = $registration; |
|
1172 | + } |
|
1173 | + } |
|
1174 | + if (! $valid_registrant instanceof EE_Registration) { |
|
1175 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1176 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1177 | + // clear the session, mark the checkout as unverified, and try again |
|
1178 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1179 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1180 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1181 | + $this->_initialize(); |
|
1182 | + EE_Error::reset_notices(); |
|
1183 | + return false; |
|
1184 | + } |
|
1185 | + EE_Error::add_error( |
|
1186 | + __( |
|
1187 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
1188 | + 'event_espresso' |
|
1189 | + ), |
|
1190 | + __FILE__, |
|
1191 | + __FUNCTION__, |
|
1192 | + __LINE__ |
|
1193 | + ); |
|
1194 | + return false; |
|
1195 | + } |
|
1196 | + } |
|
1197 | + // now that things have been kinda sufficiently verified, |
|
1198 | + // let's add the checkout to the session so that it's available to other systems |
|
1199 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1200 | + return true; |
|
1201 | + } |
|
1202 | + |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * _initialize_reg_steps |
|
1206 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1207 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1208 | + * |
|
1209 | + * @access private |
|
1210 | + * @param bool $reinitializing |
|
1211 | + * @throws EE_Error |
|
1212 | + */ |
|
1213 | + private function _initialize_reg_steps($reinitializing = false) |
|
1214 | + { |
|
1215 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1216 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1217 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1218 | + if (! $reg_step->initialize_reg_step()) { |
|
1219 | + // if not initialized then maybe this step is being removed... |
|
1220 | + if (! $reinitializing && $reg_step->is_current_step()) { |
|
1221 | + // if it was the current step, then we need to start over here |
|
1222 | + $this->_initialize_reg_steps(true); |
|
1223 | + return; |
|
1224 | + } |
|
1225 | + continue; |
|
1226 | + } |
|
1227 | + // add css and JS for current step |
|
1228 | + $reg_step->enqueue_styles_and_scripts(); |
|
1229 | + // i18n |
|
1230 | + $reg_step->translate_js_strings(); |
|
1231 | + if ($reg_step->is_current_step()) { |
|
1232 | + // the text that appears on the reg step form submit button |
|
1233 | + $reg_step->set_submit_button_text(); |
|
1234 | + } |
|
1235 | + } |
|
1236 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1237 | + do_action( |
|
1238 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1239 | + $this->checkout->current_step |
|
1240 | + ); |
|
1241 | + } |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * _check_form_submission |
|
1246 | + * |
|
1247 | + * @access private |
|
1248 | + * @return boolean |
|
1249 | + */ |
|
1250 | + private function _check_form_submission() |
|
1251 | + { |
|
1252 | + // does this request require the reg form to be generated ? |
|
1253 | + if ($this->checkout->generate_reg_form) { |
|
1254 | + // ever heard that song by Blue Rodeo ? |
|
1255 | + try { |
|
1256 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1257 | + // if not displaying a form, then check for form submission |
|
1258 | + if ($this->checkout->process_form_submission |
|
1259 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1260 | + ) { |
|
1261 | + // clear out any old data in case this step is being run again |
|
1262 | + $this->checkout->current_step->set_valid_data(array()); |
|
1263 | + // capture submitted form data |
|
1264 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1265 | + apply_filters( |
|
1266 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1267 | + EE_Registry::instance()->REQ->params(), |
|
1268 | + $this->checkout |
|
1269 | + ) |
|
1270 | + ); |
|
1271 | + // validate submitted form data |
|
1272 | + if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1273 | + // thou shall not pass !!! |
|
1274 | + $this->checkout->continue_reg = false; |
|
1275 | + // any form validation errors? |
|
1276 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1277 | + EE_Error::add_error( |
|
1278 | + $this->checkout->current_step->reg_form->submission_error_message(), |
|
1279 | + __FILE__, |
|
1280 | + __FUNCTION__, |
|
1281 | + __LINE__ |
|
1282 | + ); |
|
1283 | + } |
|
1284 | + // well not really... what will happen is |
|
1285 | + // we'll just get redirected back to redo the current step |
|
1286 | + $this->go_to_next_step(); |
|
1287 | + return false; |
|
1288 | + } |
|
1289 | + } |
|
1290 | + } catch (EE_Error $e) { |
|
1291 | + $e->get_error(); |
|
1292 | + } |
|
1293 | + } |
|
1294 | + return true; |
|
1295 | + } |
|
1296 | + |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * _process_action |
|
1300 | + * |
|
1301 | + * @access private |
|
1302 | + * @return void |
|
1303 | + * @throws EE_Error |
|
1304 | + */ |
|
1305 | + private function _process_form_action() |
|
1306 | + { |
|
1307 | + // what cha wanna do? |
|
1308 | + switch ($this->checkout->action) { |
|
1309 | + // AJAX next step reg form |
|
1310 | + case 'display_spco_reg_step': |
|
1311 | + $this->checkout->redirect = false; |
|
1312 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1313 | + $this->checkout->json_response->set_reg_step_html( |
|
1314 | + $this->checkout->current_step->display_reg_form() |
|
1315 | + ); |
|
1316 | + } |
|
1317 | + break; |
|
1318 | + default: |
|
1319 | + // meh... do one of those other steps first |
|
1320 | + if (! empty($this->checkout->action) |
|
1321 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1322 | + ) { |
|
1323 | + // dynamically creates hook point like: |
|
1324 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1325 | + do_action( |
|
1326 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1327 | + $this->checkout->current_step |
|
1328 | + ); |
|
1329 | + // call action on current step |
|
1330 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1331 | + // good registrant, you get to proceed |
|
1332 | + if ($this->checkout->current_step->success_message() !== '' |
|
1333 | + && apply_filters( |
|
1334 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1335 | + false |
|
1336 | + ) |
|
1337 | + ) { |
|
1338 | + EE_Error::add_success( |
|
1339 | + $this->checkout->current_step->success_message() |
|
1340 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1341 | + ); |
|
1342 | + } |
|
1343 | + // pack it up, pack it in... |
|
1344 | + $this->_setup_redirect(); |
|
1345 | + } |
|
1346 | + // dynamically creates hook point like: |
|
1347 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1348 | + do_action( |
|
1349 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1350 | + $this->checkout->current_step |
|
1351 | + ); |
|
1352 | + } else { |
|
1353 | + EE_Error::add_error( |
|
1354 | + sprintf( |
|
1355 | + __( |
|
1356 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1357 | + 'event_espresso' |
|
1358 | + ), |
|
1359 | + $this->checkout->action, |
|
1360 | + $this->checkout->current_step->name() |
|
1361 | + ), |
|
1362 | + __FILE__, |
|
1363 | + __FUNCTION__, |
|
1364 | + __LINE__ |
|
1365 | + ); |
|
1366 | + } |
|
1367 | + // end default |
|
1368 | + } |
|
1369 | + // store our progress so far |
|
1370 | + $this->checkout->stash_transaction_and_checkout(); |
|
1371 | + // advance to the next step! If you pass GO, collect $200 |
|
1372 | + $this->go_to_next_step(); |
|
1373 | + } |
|
1374 | + |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * add_styles_and_scripts |
|
1378 | + * |
|
1379 | + * @access public |
|
1380 | + * @return void |
|
1381 | + */ |
|
1382 | + public function add_styles_and_scripts() |
|
1383 | + { |
|
1384 | + // i18n |
|
1385 | + $this->translate_js_strings(); |
|
1386 | + if ($this->checkout->admin_request) { |
|
1387 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1388 | + } else { |
|
1389 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1390 | + } |
|
1391 | + } |
|
1392 | + |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * translate_js_strings |
|
1396 | + * |
|
1397 | + * @access public |
|
1398 | + * @return void |
|
1399 | + */ |
|
1400 | + public function translate_js_strings() |
|
1401 | + { |
|
1402 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1403 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1404 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1405 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1406 | + 'event_espresso' |
|
1407 | + ); |
|
1408 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1409 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1410 | + 'event_espresso' |
|
1411 | + ); |
|
1412 | + EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1413 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1414 | + 'event_espresso' |
|
1415 | + ); |
|
1416 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1417 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1418 | + 'event_espresso' |
|
1419 | + ); |
|
1420 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1421 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
1422 | + 'event_espresso' |
|
1423 | + ); |
|
1424 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1425 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1426 | + 'event_espresso' |
|
1427 | + ); |
|
1428 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1429 | + __( |
|
1430 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1431 | + 'event_espresso' |
|
1432 | + ), |
|
1433 | + '<br/>', |
|
1434 | + '<br/>' |
|
1435 | + ); |
|
1436 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1437 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1438 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1439 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1440 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1441 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1442 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1443 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1444 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1445 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1446 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1447 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1448 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1449 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1450 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1451 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1452 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1453 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1454 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
|
1455 | + ); |
|
1456 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1457 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1458 | + true |
|
1459 | + ); |
|
1460 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1461 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1462 | + ); |
|
1463 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1464 | + 'M d, Y H:i:s', |
|
1465 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1466 | + ); |
|
1467 | + } |
|
1468 | + |
|
1469 | + |
|
1470 | + /** |
|
1471 | + * enqueue_styles_and_scripts |
|
1472 | + * |
|
1473 | + * @access public |
|
1474 | + * @return void |
|
1475 | + * @throws EE_Error |
|
1476 | + */ |
|
1477 | + public function enqueue_styles_and_scripts() |
|
1478 | + { |
|
1479 | + // load css |
|
1480 | + wp_register_style( |
|
1481 | + 'single_page_checkout', |
|
1482 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
1483 | + array('espresso_default'), |
|
1484 | + EVENT_ESPRESSO_VERSION |
|
1485 | + ); |
|
1486 | + wp_enqueue_style('single_page_checkout'); |
|
1487 | + // load JS |
|
1488 | + wp_register_script( |
|
1489 | + 'jquery_plugin', |
|
1490 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1491 | + array('jquery'), |
|
1492 | + '1.0.1', |
|
1493 | + true |
|
1494 | + ); |
|
1495 | + wp_register_script( |
|
1496 | + 'jquery_countdown', |
|
1497 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1498 | + array('jquery_plugin'), |
|
1499 | + '2.1.0', |
|
1500 | + true |
|
1501 | + ); |
|
1502 | + wp_register_script( |
|
1503 | + 'single_page_checkout', |
|
1504 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
1505 | + array('espresso_core', 'underscore', 'ee_form_section_validation'), |
|
1506 | + EVENT_ESPRESSO_VERSION, |
|
1507 | + true |
|
1508 | + ); |
|
1509 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1510 | + $this->checkout->registration_form->enqueue_js(); |
|
1511 | + } |
|
1512 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1513 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1514 | + } |
|
1515 | + wp_enqueue_script('single_page_checkout'); |
|
1516 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { |
|
1517 | + wp_enqueue_script('jquery_countdown'); |
|
1518 | + } |
|
1519 | + /** |
|
1520 | + * global action hook for enqueueing styles and scripts with |
|
1521 | + * spco calls. |
|
1522 | + */ |
|
1523 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1524 | + /** |
|
1525 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1526 | + * The hook will end up being something like: |
|
1527 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1528 | + */ |
|
1529 | + do_action( |
|
1530 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1531 | + $this |
|
1532 | + ); |
|
1533 | + } |
|
1534 | + |
|
1535 | + |
|
1536 | + /** |
|
1537 | + * display the Registration Single Page Checkout Form |
|
1538 | + * |
|
1539 | + * @access private |
|
1540 | + * @return void |
|
1541 | + * @throws EE_Error |
|
1542 | + */ |
|
1543 | + private function _display_spco_reg_form() |
|
1544 | + { |
|
1545 | + // if registering via the admin, just display the reg form for the current step |
|
1546 | + if ($this->checkout->admin_request) { |
|
1547 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1548 | + } else { |
|
1549 | + // add powered by EE msg |
|
1550 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1551 | + $empty_cart = count($this->checkout->transaction |
|
1552 | + ->registrations($this->checkout->reg_cache_where_params)) < 1; |
|
1553 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1554 | + $cookies_not_set_msg = ''; |
|
1555 | + if ($empty_cart) { |
|
1556 | + $cookies_not_set_msg = apply_filters( |
|
1557 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1558 | + sprintf( |
|
1559 | + __( |
|
1560 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1561 | + 'event_espresso' |
|
1562 | + ), |
|
1563 | + '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
1564 | + '</div>', |
|
1565 | + '<h6 class="important-notice">', |
|
1566 | + '</h6>', |
|
1567 | + '<p>', |
|
1568 | + '</p>', |
|
1569 | + '<br />', |
|
1570 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1571 | + '</a>' |
|
1572 | + ) |
|
1573 | + ); |
|
1574 | + } |
|
1575 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1576 | + array( |
|
1577 | + 'name' => 'single-page-checkout', |
|
1578 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1579 | + 'layout_strategy' => |
|
1580 | + new EE_Template_Layout( |
|
1581 | + array( |
|
1582 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1583 | + 'template_args' => array( |
|
1584 | + 'empty_cart' => $empty_cart, |
|
1585 | + 'revisit' => $this->checkout->revisit, |
|
1586 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1587 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1588 | + ? $this->checkout->next_step->slug() |
|
1589 | + : '', |
|
1590 | + 'empty_msg' => apply_filters( |
|
1591 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1592 | + sprintf( |
|
1593 | + __( |
|
1594 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1595 | + 'event_espresso' |
|
1596 | + ), |
|
1597 | + '<a href="' |
|
1598 | + . get_post_type_archive_link('espresso_events') |
|
1599 | + . '" title="', |
|
1600 | + '">', |
|
1601 | + '</a>' |
|
1602 | + ) |
|
1603 | + ), |
|
1604 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1605 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1606 | + 'session_expiration' => gmdate( |
|
1607 | + 'M d, Y H:i:s', |
|
1608 | + EE_Registry::instance()->SSN->expiration() |
|
1609 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1610 | + ), |
|
1611 | + ), |
|
1612 | + ) |
|
1613 | + ), |
|
1614 | + ) |
|
1615 | + ); |
|
1616 | + // load template and add to output sent that gets filtered into the_content() |
|
1617 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1618 | + } |
|
1619 | + } |
|
1620 | + |
|
1621 | + |
|
1622 | + /** |
|
1623 | + * add_extra_finalize_registration_inputs |
|
1624 | + * |
|
1625 | + * @access public |
|
1626 | + * @param $next_step |
|
1627 | + * @internal param string $label |
|
1628 | + * @return void |
|
1629 | + */ |
|
1630 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1631 | + { |
|
1632 | + if ($next_step === 'finalize_registration') { |
|
1633 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1634 | + } |
|
1635 | + } |
|
1636 | + |
|
1637 | + |
|
1638 | + /** |
|
1639 | + * display_registration_footer |
|
1640 | + * |
|
1641 | + * @access public |
|
1642 | + * @return string |
|
1643 | + */ |
|
1644 | + public static function display_registration_footer() |
|
1645 | + { |
|
1646 | + if (apply_filters( |
|
1647 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1648 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1649 | + )) { |
|
1650 | + add_filter( |
|
1651 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1652 | + function ($url) { |
|
1653 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1654 | + } |
|
1655 | + ); |
|
1656 | + echo apply_filters( |
|
1657 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1658 | + \EEH_Template::powered_by_event_espresso( |
|
1659 | + '', |
|
1660 | + 'espresso-registration-footer-dv', |
|
1661 | + array('utm_content' => 'registration_checkout') |
|
1662 | + ) |
|
1663 | + ); |
|
1664 | + } |
|
1665 | + return ''; |
|
1666 | + } |
|
1667 | + |
|
1668 | + |
|
1669 | + /** |
|
1670 | + * unlock_transaction |
|
1671 | + * |
|
1672 | + * @access public |
|
1673 | + * @return void |
|
1674 | + * @throws EE_Error |
|
1675 | + */ |
|
1676 | + public function unlock_transaction() |
|
1677 | + { |
|
1678 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1679 | + $this->checkout->transaction->unlock(); |
|
1680 | + } |
|
1681 | + } |
|
1682 | + |
|
1683 | + |
|
1684 | + /** |
|
1685 | + * _setup_redirect |
|
1686 | + * |
|
1687 | + * @access private |
|
1688 | + * @return void |
|
1689 | + */ |
|
1690 | + private function _setup_redirect() |
|
1691 | + { |
|
1692 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1693 | + $this->checkout->redirect = true; |
|
1694 | + if (empty($this->checkout->redirect_url)) { |
|
1695 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1696 | + } |
|
1697 | + $this->checkout->redirect_url = apply_filters( |
|
1698 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1699 | + $this->checkout->redirect_url, |
|
1700 | + $this->checkout |
|
1701 | + ); |
|
1702 | + } |
|
1703 | + } |
|
1704 | + |
|
1705 | + |
|
1706 | + /** |
|
1707 | + * handle ajax message responses and redirects |
|
1708 | + * |
|
1709 | + * @access public |
|
1710 | + * @return void |
|
1711 | + * @throws EE_Error |
|
1712 | + */ |
|
1713 | + public function go_to_next_step() |
|
1714 | + { |
|
1715 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1716 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1717 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1718 | + } |
|
1719 | + $this->unlock_transaction(); |
|
1720 | + // just return for these conditions |
|
1721 | + if ($this->checkout->admin_request |
|
1722 | + || $this->checkout->action === 'redirect_form' |
|
1723 | + || $this->checkout->action === 'update_checkout' |
|
1724 | + ) { |
|
1725 | + return; |
|
1726 | + } |
|
1727 | + // AJAX response |
|
1728 | + $this->_handle_json_response(); |
|
1729 | + // redirect to next step or the Thank You page |
|
1730 | + $this->_handle_html_redirects(); |
|
1731 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1732 | + $this->_display_spco_reg_form(); |
|
1733 | + } |
|
1734 | + |
|
1735 | + |
|
1736 | + /** |
|
1737 | + * _handle_json_response |
|
1738 | + * |
|
1739 | + * @access protected |
|
1740 | + * @return void |
|
1741 | + */ |
|
1742 | + protected function _handle_json_response() |
|
1743 | + { |
|
1744 | + // if this is an ajax request |
|
1745 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1746 | + $this->checkout->json_response->set_registration_time_limit( |
|
1747 | + $this->checkout->get_registration_time_limit() |
|
1748 | + ); |
|
1749 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1750 | + // just send the ajax ( |
|
1751 | + $json_response = apply_filters( |
|
1752 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1753 | + $this->checkout->json_response |
|
1754 | + ); |
|
1755 | + echo $json_response; |
|
1756 | + exit(); |
|
1757 | + } |
|
1758 | + } |
|
1759 | + |
|
1760 | + |
|
1761 | + /** |
|
1762 | + * _handle_redirects |
|
1763 | + * |
|
1764 | + * @access protected |
|
1765 | + * @return void |
|
1766 | + */ |
|
1767 | + protected function _handle_html_redirects() |
|
1768 | + { |
|
1769 | + // going somewhere ? |
|
1770 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1771 | + // store notices in a transient |
|
1772 | + EE_Error::get_notices(false, true, true); |
|
1773 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1774 | + exit(); |
|
1775 | + } |
|
1776 | + } |
|
1777 | + |
|
1778 | + |
|
1779 | + /** |
|
1780 | + * set_checkout_anchor |
|
1781 | + * |
|
1782 | + * @access public |
|
1783 | + * @return void |
|
1784 | + */ |
|
1785 | + public function set_checkout_anchor() |
|
1786 | + { |
|
1787 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1788 | + } |
|
1789 | + |
|
1790 | + /** |
|
1791 | + * getRegistrationExpirationNotice |
|
1792 | + * |
|
1793 | + * @since 4.9.59.p |
|
1794 | + * @access public |
|
1795 | + * @return string |
|
1796 | + */ |
|
1797 | + public static function getRegistrationExpirationNotice() |
|
1798 | + { |
|
1799 | + return sprintf( |
|
1800 | + __( |
|
1801 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s', |
|
1802 | + 'event_espresso' |
|
1803 | + ), |
|
1804 | + '<h4 class="important-notice">', |
|
1805 | + '</h4>', |
|
1806 | + '<br />', |
|
1807 | + '<p>', |
|
1808 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1809 | + '">', |
|
1810 | + '</a>', |
|
1811 | + '</p>' |
|
1812 | + ); |
|
1813 | + } |
|
1814 | 1814 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | public static function set_hooks_admin() |
101 | 101 | { |
102 | 102 | EED_Single_Page_Checkout::set_definitions(); |
103 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
103 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
104 | 104 | return; |
105 | 105 | } |
106 | 106 | // going to start an output buffer in case anything gets accidentally output |
@@ -206,14 +206,14 @@ discard block |
||
206 | 206 | } |
207 | 207 | define( |
208 | 208 | 'SPCO_BASE_PATH', |
209 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
209 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS |
|
210 | 210 | ); |
211 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
212 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
213 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
214 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
215 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
216 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
211 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
212 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
213 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
214 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
215 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
216 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
217 | 217 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
218 | 218 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice( |
219 | 219 | ); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | // we need a |
246 | 246 | if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
247 | 247 | // copy over to the reg_steps_array |
248 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
248 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
249 | 249 | // register custom key route for each reg step |
250 | 250 | // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
251 | 251 | EE_Config::register_route( |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | // add AJAX or other hooks |
258 | 258 | if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
259 | 259 | // setup autoloaders if necessary |
260 | - if (! class_exists($reg_step['class_name'])) { |
|
260 | + if ( ! class_exists($reg_step['class_name'])) { |
|
261 | 261 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
262 | 262 | $reg_step['file_path'], |
263 | 263 | true |
@@ -285,19 +285,19 @@ discard block |
||
285 | 285 | if (empty($reg_steps)) { |
286 | 286 | $reg_steps = array( |
287 | 287 | 10 => array( |
288 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
288 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
289 | 289 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
290 | 290 | 'slug' => 'attendee_information', |
291 | 291 | 'has_hooks' => false, |
292 | 292 | ), |
293 | 293 | 30 => array( |
294 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
294 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
295 | 295 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
296 | 296 | 'slug' => 'payment_options', |
297 | 297 | 'has_hooks' => true, |
298 | 298 | ), |
299 | 299 | 999 => array( |
300 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
300 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
301 | 301 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
302 | 302 | 'slug' => 'finalize_registration', |
303 | 303 | 'has_hooks' => false, |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | $this->checkout |
451 | 451 | ); |
452 | 452 | // load the reg steps array |
453 | - if (! $this->_load_and_instantiate_reg_steps()) { |
|
453 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
454 | 454 | EED_Single_Page_Checkout::$_initialized = true; |
455 | 455 | return; |
456 | 456 | } |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | // and the next step |
460 | 460 | $this->checkout->set_next_step(); |
461 | 461 | // verify that everything has been setup correctly |
462 | - if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
462 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
463 | 463 | EED_Single_Page_Checkout::$_initialized = true; |
464 | 464 | return; |
465 | 465 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | // DEBUG LOG |
475 | 475 | // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
476 | 476 | // get reg form |
477 | - if (! $this->_check_form_submission()) { |
|
477 | + if ( ! $this->_check_form_submission()) { |
|
478 | 478 | EED_Single_Page_Checkout::$_initialized = true; |
479 | 479 | return; |
480 | 480 | } |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | */ |
506 | 506 | private function _verify_session() |
507 | 507 | { |
508 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
508 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
509 | 509 | throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
510 | 510 | } |
511 | 511 | $clear_session_requested = filter_var( |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | // EE_Registry::instance()->SSN->reset_cart(); |
524 | 524 | // EE_Registry::instance()->SSN->reset_checkout(); |
525 | 525 | // EE_Registry::instance()->SSN->reset_transaction(); |
526 | - if (! $clear_session_requested) { |
|
526 | + if ( ! $clear_session_requested) { |
|
527 | 527 | EE_Error::add_attention( |
528 | 528 | EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
529 | 529 | __FILE__, |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | /** @type EE_Checkout $checkout */ |
551 | 551 | $checkout = EE_Registry::instance()->SSN->checkout(); |
552 | 552 | // verify |
553 | - if (! $checkout instanceof EE_Checkout) { |
|
553 | + if ( ! $checkout instanceof EE_Checkout) { |
|
554 | 554 | // instantiate EE_Checkout object for handling the properties of the current checkout process |
555 | 555 | $checkout = EE_Registry::instance()->load_file( |
556 | 556 | SPCO_INC_PATH, |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | } |
569 | 569 | $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
570 | 570 | // verify again |
571 | - if (! $checkout instanceof EE_Checkout) { |
|
571 | + if ( ! $checkout instanceof EE_Checkout) { |
|
572 | 572 | throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
573 | 573 | } |
574 | 574 | // reset anything that needs a clean slate for each request |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | */ |
641 | 641 | protected function _display_request_vars() |
642 | 642 | { |
643 | - if (! WP_DEBUG) { |
|
643 | + if ( ! WP_DEBUG) { |
|
644 | 644 | return; |
645 | 645 | } |
646 | 646 | EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | ) { |
718 | 718 | // if not, then loop through raw reg steps array |
719 | 719 | foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
720 | - if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
720 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
721 | 721 | return false; |
722 | 722 | } |
723 | 723 | } |
@@ -848,12 +848,12 @@ discard block |
||
848 | 848 | private function _verify_transaction_and_get_registrations() |
849 | 849 | { |
850 | 850 | // was there already a valid transaction in the checkout from the session ? |
851 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
851 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
852 | 852 | // get transaction from db or session |
853 | 853 | $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
854 | 854 | ? $this->_get_transaction_and_cart_for_previous_visit() |
855 | 855 | : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
856 | - if (! $this->checkout->transaction instanceof EE_Transaction) { |
|
856 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
857 | 857 | EE_Error::add_error( |
858 | 858 | __( |
859 | 859 | 'Your Registration and Transaction information could not be retrieved from the db.', |
@@ -1084,16 +1084,16 @@ discard block |
||
1084 | 1084 | ) |
1085 | 1085 | ); |
1086 | 1086 | // override capabilities for frontend registrations |
1087 | - if (! is_admin()) { |
|
1087 | + if ( ! is_admin()) { |
|
1088 | 1088 | $CreateRegistrationCommand->setCapCheck( |
1089 | 1089 | new PublicCapabilities('', 'create_new_registration') |
1090 | 1090 | ); |
1091 | 1091 | } |
1092 | 1092 | $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
1093 | - if (! $registration instanceof EE_Registration) { |
|
1093 | + if ( ! $registration instanceof EE_Registration) { |
|
1094 | 1094 | throw new InvalidEntityException($registration, 'EE_Registration'); |
1095 | 1095 | } |
1096 | - $registrations[ $registration->ID() ] = $registration; |
|
1096 | + $registrations[$registration->ID()] = $registration; |
|
1097 | 1097 | } |
1098 | 1098 | } |
1099 | 1099 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | $this->checkout |
1137 | 1137 | ); |
1138 | 1138 | // verify that current step is still set correctly |
1139 | - if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1139 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1140 | 1140 | EE_Error::add_error( |
1141 | 1141 | __( |
1142 | 1142 | 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', |
@@ -1149,9 +1149,9 @@ discard block |
||
1149 | 1149 | return false; |
1150 | 1150 | } |
1151 | 1151 | // if returning to SPCO, then verify that primary registrant is set |
1152 | - if (! empty($this->checkout->reg_url_link)) { |
|
1152 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1153 | 1153 | $valid_registrant = $this->checkout->transaction->primary_registration(); |
1154 | - if (! $valid_registrant instanceof EE_Registration) { |
|
1154 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1155 | 1155 | EE_Error::add_error( |
1156 | 1156 | __( |
1157 | 1157 | 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', |
@@ -1171,7 +1171,7 @@ discard block |
||
1171 | 1171 | $valid_registrant = $registration; |
1172 | 1172 | } |
1173 | 1173 | } |
1174 | - if (! $valid_registrant instanceof EE_Registration) { |
|
1174 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1175 | 1175 | // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
1176 | 1176 | if (EED_Single_Page_Checkout::$_checkout_verified) { |
1177 | 1177 | // clear the session, mark the checkout as unverified, and try again |
@@ -1215,9 +1215,9 @@ discard block |
||
1215 | 1215 | $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
1216 | 1216 | // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
1217 | 1217 | foreach ($this->checkout->reg_steps as $reg_step) { |
1218 | - if (! $reg_step->initialize_reg_step()) { |
|
1218 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1219 | 1219 | // if not initialized then maybe this step is being removed... |
1220 | - if (! $reinitializing && $reg_step->is_current_step()) { |
|
1220 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1221 | 1221 | // if it was the current step, then we need to start over here |
1222 | 1222 | $this->_initialize_reg_steps(true); |
1223 | 1223 | return; |
@@ -1269,7 +1269,7 @@ discard block |
||
1269 | 1269 | ) |
1270 | 1270 | ); |
1271 | 1271 | // validate submitted form data |
1272 | - if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1272 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1273 | 1273 | // thou shall not pass !!! |
1274 | 1274 | $this->checkout->continue_reg = false; |
1275 | 1275 | // any form validation errors? |
@@ -1317,7 +1317,7 @@ discard block |
||
1317 | 1317 | break; |
1318 | 1318 | default: |
1319 | 1319 | // meh... do one of those other steps first |
1320 | - if (! empty($this->checkout->action) |
|
1320 | + if ( ! empty($this->checkout->action) |
|
1321 | 1321 | && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
1322 | 1322 | ) { |
1323 | 1323 | // dynamically creates hook point like: |
@@ -1337,7 +1337,7 @@ discard block |
||
1337 | 1337 | ) { |
1338 | 1338 | EE_Error::add_success( |
1339 | 1339 | $this->checkout->current_step->success_message() |
1340 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1340 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
1341 | 1341 | ); |
1342 | 1342 | } |
1343 | 1343 | // pack it up, pack it in... |
@@ -1479,7 +1479,7 @@ discard block |
||
1479 | 1479 | // load css |
1480 | 1480 | wp_register_style( |
1481 | 1481 | 'single_page_checkout', |
1482 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1482 | + SPCO_CSS_URL.'single_page_checkout.css', |
|
1483 | 1483 | array('espresso_default'), |
1484 | 1484 | EVENT_ESPRESSO_VERSION |
1485 | 1485 | ); |
@@ -1487,21 +1487,21 @@ discard block |
||
1487 | 1487 | // load JS |
1488 | 1488 | wp_register_script( |
1489 | 1489 | 'jquery_plugin', |
1490 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1490 | + EE_THIRD_PARTY_URL.'jquery .plugin.min.js', |
|
1491 | 1491 | array('jquery'), |
1492 | 1492 | '1.0.1', |
1493 | 1493 | true |
1494 | 1494 | ); |
1495 | 1495 | wp_register_script( |
1496 | 1496 | 'jquery_countdown', |
1497 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1497 | + EE_THIRD_PARTY_URL.'jquery .countdown.min.js', |
|
1498 | 1498 | array('jquery_plugin'), |
1499 | 1499 | '2.1.0', |
1500 | 1500 | true |
1501 | 1501 | ); |
1502 | 1502 | wp_register_script( |
1503 | 1503 | 'single_page_checkout', |
1504 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1504 | + SPCO_JS_URL.'single_page_checkout.js', |
|
1505 | 1505 | array('espresso_core', 'underscore', 'ee_form_section_validation'), |
1506 | 1506 | EVENT_ESPRESSO_VERSION, |
1507 | 1507 | true |
@@ -1527,7 +1527,7 @@ discard block |
||
1527 | 1527 | * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
1528 | 1528 | */ |
1529 | 1529 | do_action( |
1530 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1530 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), |
|
1531 | 1531 | $this |
1532 | 1532 | ); |
1533 | 1533 | } |
@@ -1579,7 +1579,7 @@ discard block |
||
1579 | 1579 | 'layout_strategy' => |
1580 | 1580 | new EE_Template_Layout( |
1581 | 1581 | array( |
1582 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1582 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
1583 | 1583 | 'template_args' => array( |
1584 | 1584 | 'empty_cart' => $empty_cart, |
1585 | 1585 | 'revisit' => $this->checkout->revisit, |
@@ -1649,7 +1649,7 @@ discard block |
||
1649 | 1649 | )) { |
1650 | 1650 | add_filter( |
1651 | 1651 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
1652 | - function ($url) { |
|
1652 | + function($url) { |
|
1653 | 1653 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
1654 | 1654 | } |
1655 | 1655 | ); |
@@ -1805,7 +1805,7 @@ discard block |
||
1805 | 1805 | '</h4>', |
1806 | 1806 | '<br />', |
1807 | 1807 | '<p>', |
1808 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1808 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1809 | 1809 | '">', |
1810 | 1810 | '</a>', |
1811 | 1811 | '</p>' |
@@ -23,495 +23,495 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class EE_Gateway |
25 | 25 | { |
26 | - /** |
|
27 | - * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | - * that ALL currencies are supported by this gateway |
|
29 | - */ |
|
30 | - const all_currencies_supported = 'all_currencies_supported'; |
|
31 | - /** |
|
32 | - * Where values are 3-letter currency codes |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $_currencies_supported = array(); |
|
37 | - /** |
|
38 | - * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | - * admin in EE's wp-admin page) |
|
40 | - * |
|
41 | - * @var boolean |
|
42 | - */ |
|
43 | - protected $_supports_sending_refunds = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | - * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | - * |
|
49 | - * @var boolean |
|
50 | - */ |
|
51 | - protected $_supports_receiving_refunds = false; |
|
52 | - /** |
|
53 | - * Model for querying for existing payments |
|
54 | - * |
|
55 | - * @var EEMI_Payment |
|
56 | - */ |
|
57 | - protected $_pay_model; |
|
58 | - |
|
59 | - /** |
|
60 | - * Model used for adding to the payments log |
|
61 | - * |
|
62 | - * @var EEMI_Payment_Log |
|
63 | - */ |
|
64 | - protected $_pay_log; |
|
65 | - |
|
66 | - /** |
|
67 | - * Used for formatting some input to gateways |
|
68 | - * |
|
69 | - * @var EEHI_Template |
|
70 | - */ |
|
71 | - protected $_template; |
|
72 | - |
|
73 | - /** |
|
74 | - * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | - * |
|
76 | - * @var EEHI_Money |
|
77 | - */ |
|
78 | - protected $_money; |
|
79 | - |
|
80 | - /** |
|
81 | - * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | - * |
|
83 | - * @var EEHI_Line_Item |
|
84 | - */ |
|
85 | - protected $_line_item; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var GatewayDataFormatterInterface |
|
89 | - */ |
|
90 | - protected $_gateway_data_formatter; |
|
91 | - |
|
92 | - /** |
|
93 | - * @var FormatterInterface |
|
94 | - */ |
|
95 | - protected $_unsupported_character_remover; |
|
96 | - |
|
97 | - /** |
|
98 | - * The ID of the payment method using this gateway |
|
99 | - * |
|
100 | - * @var int |
|
101 | - */ |
|
102 | - protected $_ID; |
|
103 | - |
|
104 | - /** |
|
105 | - * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | - */ |
|
107 | - protected $_debug_mode; |
|
108 | - /** |
|
109 | - * |
|
110 | - * @var string $_name name to show for this payment method |
|
111 | - */ |
|
112 | - protected $_name; |
|
113 | - /** |
|
114 | - * |
|
115 | - * @var string name to show fir this payment method to admin-type users |
|
116 | - */ |
|
117 | - protected $_admin_name; |
|
118 | - |
|
119 | - /** |
|
120 | - * @return EE_Gateway |
|
121 | - */ |
|
122 | - public function __construct() |
|
123 | - { |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * We don't want to serialize models as they often have circular structures |
|
128 | - * (eg a payment model has a reference to each payment model object; and most |
|
129 | - * payments have a transaction, most transactions have a payment method; |
|
130 | - * most payment methods have a payment method type; most payment method types |
|
131 | - * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | - * beginning again) |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function __sleep() |
|
137 | - { |
|
138 | - $properties = get_object_vars($this); |
|
139 | - unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | - return array_keys($properties); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns whether or not this gateway should support SENDING refunds |
|
145 | - * see $_supports_sending_refunds |
|
146 | - * |
|
147 | - * @return boolean |
|
148 | - */ |
|
149 | - public function supports_sending_refunds() |
|
150 | - { |
|
151 | - return $this->_supports_sending_refunds; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | - * see $_supports_receiving_refunds |
|
157 | - * |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - public function supports_receiving_refunds() |
|
161 | - { |
|
162 | - return $this->_supports_receiving_refunds; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Tries to refund the payment specified, taking into account the extra |
|
168 | - * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | - * this should just throw an exception. |
|
170 | - * |
|
171 | - * @param EE_Payment $payment |
|
172 | - * @param array $refund_info |
|
173 | - * @return EE_Payment for the refund |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | - { |
|
178 | - return null; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | - * etc |
|
185 | - * |
|
186 | - * @param array $settings_array |
|
187 | - */ |
|
188 | - public function set_settings($settings_array) |
|
189 | - { |
|
190 | - foreach ($settings_array as $name => $value) { |
|
191 | - $property_name = "_" . $name; |
|
192 | - $this->{$property_name} = $value; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * See this class description |
|
198 | - * |
|
199 | - * @param EEMI_Payment $payment_model |
|
200 | - */ |
|
201 | - public function set_payment_model($payment_model) |
|
202 | - { |
|
203 | - $this->_pay_model = $payment_model; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * See this class description |
|
208 | - * |
|
209 | - * @param EEMI_Payment_Log $payment_log_model |
|
210 | - */ |
|
211 | - public function set_payment_log($payment_log_model) |
|
212 | - { |
|
213 | - $this->_pay_log = $payment_log_model; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * See this class description |
|
218 | - * |
|
219 | - * @param EEHI_Template $template_helper |
|
220 | - */ |
|
221 | - public function set_template_helper($template_helper) |
|
222 | - { |
|
223 | - $this->_template = $template_helper; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * See this class description |
|
228 | - * |
|
229 | - * @param EEHI_Line_Item $line_item_helper |
|
230 | - */ |
|
231 | - public function set_line_item_helper($line_item_helper) |
|
232 | - { |
|
233 | - $this->_line_item = $line_item_helper; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * See this class description |
|
238 | - * |
|
239 | - * @param EEHI_Money $money_helper |
|
240 | - */ |
|
241 | - public function set_money_helper($money_helper) |
|
242 | - { |
|
243 | - $this->_money = $money_helper; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets the gateway data formatter helper |
|
249 | - * |
|
250 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | - * @throws InvalidEntityException if it's not set properly |
|
252 | - */ |
|
253 | - public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | - { |
|
255 | - if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | - throw new InvalidEntityException( |
|
257 | - is_object($gateway_data_formatter) |
|
258 | - ? get_class($gateway_data_formatter) |
|
259 | - : esc_html__('Not an object', 'event_espresso'), |
|
260 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | - ); |
|
262 | - } |
|
263 | - $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Gets the gateway data formatter |
|
268 | - * |
|
269 | - * @return GatewayDataFormatterInterface |
|
270 | - * @throws InvalidEntityException if it's not set properly |
|
271 | - */ |
|
272 | - protected function _get_gateway_formatter() |
|
273 | - { |
|
274 | - if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | - throw new InvalidEntityException( |
|
276 | - is_object($this->_gateway_data_formatter) |
|
277 | - ? get_class($this->_gateway_data_formatter) |
|
278 | - : esc_html__('Not an object', 'event_espresso'), |
|
279 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | - ); |
|
281 | - } |
|
282 | - return $this->_gateway_data_formatter; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Sets the helper which will remove unsupported characters for most gateways |
|
288 | - * |
|
289 | - * @param FormatterInterface $formatter |
|
290 | - * @return FormatterInterface |
|
291 | - * @throws InvalidEntityException |
|
292 | - */ |
|
293 | - public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | - { |
|
295 | - if (! $formatter instanceof FormatterInterface) { |
|
296 | - throw new InvalidEntityException( |
|
297 | - is_object($formatter) |
|
298 | - ? get_class($formatter) |
|
299 | - : esc_html__('Not an object', 'event_espresso'), |
|
300 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | - ); |
|
302 | - } |
|
303 | - $this->_unsupported_character_remover = $formatter; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | - * |
|
309 | - * @return FormatterInterface |
|
310 | - * @throws InvalidEntityException |
|
311 | - */ |
|
312 | - protected function _get_unsupported_character_remover() |
|
313 | - { |
|
314 | - if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | - throw new InvalidEntityException( |
|
316 | - is_object($this->_unsupported_character_remover) |
|
317 | - ? get_class($this->_unsupported_character_remover) |
|
318 | - : esc_html__('Not an object', 'event_espresso'), |
|
319 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | - ); |
|
321 | - } |
|
322 | - return $this->_unsupported_character_remover; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param $message |
|
328 | - * @param $payment |
|
329 | - */ |
|
330 | - public function log($message, $object_logged) |
|
331 | - { |
|
332 | - if ($object_logged instanceof EEI_Payment) { |
|
333 | - $type = 'Payment'; |
|
334 | - $id = $object_logged->ID(); |
|
335 | - } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | - $type = 'Transaction'; |
|
337 | - $id = $object_logged->ID(); |
|
338 | - } else { |
|
339 | - $type = 'Payment_Method'; |
|
340 | - $id = $this->_ID; |
|
341 | - } |
|
342 | - // only log if we're going to store it for longer than the minimum time |
|
343 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | - if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | - $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Formats the amount so it can generally be sent to gateways |
|
351 | - * |
|
352 | - * @param float $amount |
|
353 | - * @return string |
|
354 | - * @deprecated since 4.9.31 insetad use |
|
355 | - * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | - */ |
|
357 | - public function format_currency($amount) |
|
358 | - { |
|
359 | - return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Returns either an array of all the currency codes supported, |
|
364 | - * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | - * |
|
366 | - * @return mixed array or string |
|
367 | - */ |
|
368 | - public function currencies_supported() |
|
369 | - { |
|
370 | - return $this->_currencies_supported; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | - * can be used to determine if some more complex line items, like promotions, |
|
376 | - * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | - * about creating an itemized list of purchases and instead only send the total due) |
|
378 | - * |
|
379 | - * @param EE_Transaction $transaction |
|
380 | - * @return float |
|
381 | - */ |
|
382 | - protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | - { |
|
384 | - $total_line_item = $transaction->total_line_item(); |
|
385 | - $total = 0; |
|
386 | - foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | - $total += max($item_line_item->total(), 0); |
|
388 | - } |
|
389 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | - $total += max($tax_line_item->total(), 0); |
|
391 | - } |
|
392 | - return $total; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Determines whether or not we can easily itemize the transaction using only |
|
397 | - * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | - * |
|
399 | - * @param EEI_Payment $payment |
|
400 | - * @return boolean |
|
401 | - */ |
|
402 | - protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | - { |
|
404 | - return $this->_money->compare_floats( |
|
405 | - $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | - $payment->transaction()->total() |
|
407 | - ) |
|
408 | - && $this->_money->compare_floats( |
|
409 | - $payment->amount(), |
|
410 | - $payment->transaction()->total() |
|
411 | - ); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Handles updating the transaction and any other related data based on the payment. |
|
416 | - * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | - * but doing so on those functions might be too early. It's possible that the changes |
|
418 | - * you make to teh transaction or registration or line items may just get overwritten |
|
419 | - * at that point. Instead, you should store any info you need on the payment during those |
|
420 | - * functions, and use that information at this step, which client code will decide |
|
421 | - * for you when it should be called. |
|
422 | - * |
|
423 | - * @param EE_Payment $payment |
|
424 | - * @return void |
|
425 | - */ |
|
426 | - public function update_txn_based_on_payment($payment) |
|
427 | - { |
|
428 | - // maybe update the transaction or line items or registrations |
|
429 | - // but most gateways don't need to do this, because they only update the payment |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | - * |
|
435 | - * @param EEI_Payment $payment |
|
436 | - * @return EEI_Event|null |
|
437 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | - */ |
|
439 | - protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | - { |
|
441 | - return $payment->get_first_event(); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets the name of the first event for which is being paid |
|
446 | - * |
|
447 | - * @param EEI_Payment $payment |
|
448 | - * @return string |
|
449 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | - */ |
|
451 | - protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | - { |
|
453 | - return $payment->get_first_event_name(); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | - * |
|
459 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | - * @param EE_Payment $payment |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | - { |
|
465 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | - * |
|
471 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | - * @param EEI_Payment $payment |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | - { |
|
477 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Gets the name to use for a line item when sending line items to the gateway |
|
482 | - * |
|
483 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | - * @param EEI_Line_Item $line_item |
|
485 | - * @param EEI_Payment $payment |
|
486 | - * @return string |
|
487 | - */ |
|
488 | - protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
489 | - { |
|
490 | - return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Gets the description to use for a line item when sending line items to the gateway |
|
495 | - * |
|
496 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | - * @param EEI_Line_Item $line_item |
|
498 | - * @param EEI_Payment $payment |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
502 | - { |
|
503 | - return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Gets the order description that should generlly be sent to gateways |
|
508 | - * |
|
509 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | - * @param EEI_Payment $payment |
|
511 | - * @return type |
|
512 | - */ |
|
513 | - protected function _format_order_description(EEI_Payment $payment) |
|
514 | - { |
|
515 | - return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | - } |
|
26 | + /** |
|
27 | + * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | + * that ALL currencies are supported by this gateway |
|
29 | + */ |
|
30 | + const all_currencies_supported = 'all_currencies_supported'; |
|
31 | + /** |
|
32 | + * Where values are 3-letter currency codes |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $_currencies_supported = array(); |
|
37 | + /** |
|
38 | + * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | + * admin in EE's wp-admin page) |
|
40 | + * |
|
41 | + * @var boolean |
|
42 | + */ |
|
43 | + protected $_supports_sending_refunds = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | + * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | + * |
|
49 | + * @var boolean |
|
50 | + */ |
|
51 | + protected $_supports_receiving_refunds = false; |
|
52 | + /** |
|
53 | + * Model for querying for existing payments |
|
54 | + * |
|
55 | + * @var EEMI_Payment |
|
56 | + */ |
|
57 | + protected $_pay_model; |
|
58 | + |
|
59 | + /** |
|
60 | + * Model used for adding to the payments log |
|
61 | + * |
|
62 | + * @var EEMI_Payment_Log |
|
63 | + */ |
|
64 | + protected $_pay_log; |
|
65 | + |
|
66 | + /** |
|
67 | + * Used for formatting some input to gateways |
|
68 | + * |
|
69 | + * @var EEHI_Template |
|
70 | + */ |
|
71 | + protected $_template; |
|
72 | + |
|
73 | + /** |
|
74 | + * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | + * |
|
76 | + * @var EEHI_Money |
|
77 | + */ |
|
78 | + protected $_money; |
|
79 | + |
|
80 | + /** |
|
81 | + * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | + * |
|
83 | + * @var EEHI_Line_Item |
|
84 | + */ |
|
85 | + protected $_line_item; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var GatewayDataFormatterInterface |
|
89 | + */ |
|
90 | + protected $_gateway_data_formatter; |
|
91 | + |
|
92 | + /** |
|
93 | + * @var FormatterInterface |
|
94 | + */ |
|
95 | + protected $_unsupported_character_remover; |
|
96 | + |
|
97 | + /** |
|
98 | + * The ID of the payment method using this gateway |
|
99 | + * |
|
100 | + * @var int |
|
101 | + */ |
|
102 | + protected $_ID; |
|
103 | + |
|
104 | + /** |
|
105 | + * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | + */ |
|
107 | + protected $_debug_mode; |
|
108 | + /** |
|
109 | + * |
|
110 | + * @var string $_name name to show for this payment method |
|
111 | + */ |
|
112 | + protected $_name; |
|
113 | + /** |
|
114 | + * |
|
115 | + * @var string name to show fir this payment method to admin-type users |
|
116 | + */ |
|
117 | + protected $_admin_name; |
|
118 | + |
|
119 | + /** |
|
120 | + * @return EE_Gateway |
|
121 | + */ |
|
122 | + public function __construct() |
|
123 | + { |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * We don't want to serialize models as they often have circular structures |
|
128 | + * (eg a payment model has a reference to each payment model object; and most |
|
129 | + * payments have a transaction, most transactions have a payment method; |
|
130 | + * most payment methods have a payment method type; most payment method types |
|
131 | + * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | + * beginning again) |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function __sleep() |
|
137 | + { |
|
138 | + $properties = get_object_vars($this); |
|
139 | + unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | + return array_keys($properties); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns whether or not this gateway should support SENDING refunds |
|
145 | + * see $_supports_sending_refunds |
|
146 | + * |
|
147 | + * @return boolean |
|
148 | + */ |
|
149 | + public function supports_sending_refunds() |
|
150 | + { |
|
151 | + return $this->_supports_sending_refunds; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | + * see $_supports_receiving_refunds |
|
157 | + * |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + public function supports_receiving_refunds() |
|
161 | + { |
|
162 | + return $this->_supports_receiving_refunds; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Tries to refund the payment specified, taking into account the extra |
|
168 | + * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | + * this should just throw an exception. |
|
170 | + * |
|
171 | + * @param EE_Payment $payment |
|
172 | + * @param array $refund_info |
|
173 | + * @return EE_Payment for the refund |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | + { |
|
178 | + return null; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | + * etc |
|
185 | + * |
|
186 | + * @param array $settings_array |
|
187 | + */ |
|
188 | + public function set_settings($settings_array) |
|
189 | + { |
|
190 | + foreach ($settings_array as $name => $value) { |
|
191 | + $property_name = "_" . $name; |
|
192 | + $this->{$property_name} = $value; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * See this class description |
|
198 | + * |
|
199 | + * @param EEMI_Payment $payment_model |
|
200 | + */ |
|
201 | + public function set_payment_model($payment_model) |
|
202 | + { |
|
203 | + $this->_pay_model = $payment_model; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * See this class description |
|
208 | + * |
|
209 | + * @param EEMI_Payment_Log $payment_log_model |
|
210 | + */ |
|
211 | + public function set_payment_log($payment_log_model) |
|
212 | + { |
|
213 | + $this->_pay_log = $payment_log_model; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * See this class description |
|
218 | + * |
|
219 | + * @param EEHI_Template $template_helper |
|
220 | + */ |
|
221 | + public function set_template_helper($template_helper) |
|
222 | + { |
|
223 | + $this->_template = $template_helper; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * See this class description |
|
228 | + * |
|
229 | + * @param EEHI_Line_Item $line_item_helper |
|
230 | + */ |
|
231 | + public function set_line_item_helper($line_item_helper) |
|
232 | + { |
|
233 | + $this->_line_item = $line_item_helper; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * See this class description |
|
238 | + * |
|
239 | + * @param EEHI_Money $money_helper |
|
240 | + */ |
|
241 | + public function set_money_helper($money_helper) |
|
242 | + { |
|
243 | + $this->_money = $money_helper; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets the gateway data formatter helper |
|
249 | + * |
|
250 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | + * @throws InvalidEntityException if it's not set properly |
|
252 | + */ |
|
253 | + public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | + { |
|
255 | + if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | + throw new InvalidEntityException( |
|
257 | + is_object($gateway_data_formatter) |
|
258 | + ? get_class($gateway_data_formatter) |
|
259 | + : esc_html__('Not an object', 'event_espresso'), |
|
260 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | + ); |
|
262 | + } |
|
263 | + $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Gets the gateway data formatter |
|
268 | + * |
|
269 | + * @return GatewayDataFormatterInterface |
|
270 | + * @throws InvalidEntityException if it's not set properly |
|
271 | + */ |
|
272 | + protected function _get_gateway_formatter() |
|
273 | + { |
|
274 | + if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | + throw new InvalidEntityException( |
|
276 | + is_object($this->_gateway_data_formatter) |
|
277 | + ? get_class($this->_gateway_data_formatter) |
|
278 | + : esc_html__('Not an object', 'event_espresso'), |
|
279 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | + ); |
|
281 | + } |
|
282 | + return $this->_gateway_data_formatter; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Sets the helper which will remove unsupported characters for most gateways |
|
288 | + * |
|
289 | + * @param FormatterInterface $formatter |
|
290 | + * @return FormatterInterface |
|
291 | + * @throws InvalidEntityException |
|
292 | + */ |
|
293 | + public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | + { |
|
295 | + if (! $formatter instanceof FormatterInterface) { |
|
296 | + throw new InvalidEntityException( |
|
297 | + is_object($formatter) |
|
298 | + ? get_class($formatter) |
|
299 | + : esc_html__('Not an object', 'event_espresso'), |
|
300 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | + ); |
|
302 | + } |
|
303 | + $this->_unsupported_character_remover = $formatter; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | + * |
|
309 | + * @return FormatterInterface |
|
310 | + * @throws InvalidEntityException |
|
311 | + */ |
|
312 | + protected function _get_unsupported_character_remover() |
|
313 | + { |
|
314 | + if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | + throw new InvalidEntityException( |
|
316 | + is_object($this->_unsupported_character_remover) |
|
317 | + ? get_class($this->_unsupported_character_remover) |
|
318 | + : esc_html__('Not an object', 'event_espresso'), |
|
319 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | + ); |
|
321 | + } |
|
322 | + return $this->_unsupported_character_remover; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param $message |
|
328 | + * @param $payment |
|
329 | + */ |
|
330 | + public function log($message, $object_logged) |
|
331 | + { |
|
332 | + if ($object_logged instanceof EEI_Payment) { |
|
333 | + $type = 'Payment'; |
|
334 | + $id = $object_logged->ID(); |
|
335 | + } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | + $type = 'Transaction'; |
|
337 | + $id = $object_logged->ID(); |
|
338 | + } else { |
|
339 | + $type = 'Payment_Method'; |
|
340 | + $id = $this->_ID; |
|
341 | + } |
|
342 | + // only log if we're going to store it for longer than the minimum time |
|
343 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | + if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | + $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Formats the amount so it can generally be sent to gateways |
|
351 | + * |
|
352 | + * @param float $amount |
|
353 | + * @return string |
|
354 | + * @deprecated since 4.9.31 insetad use |
|
355 | + * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | + */ |
|
357 | + public function format_currency($amount) |
|
358 | + { |
|
359 | + return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Returns either an array of all the currency codes supported, |
|
364 | + * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | + * |
|
366 | + * @return mixed array or string |
|
367 | + */ |
|
368 | + public function currencies_supported() |
|
369 | + { |
|
370 | + return $this->_currencies_supported; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | + * can be used to determine if some more complex line items, like promotions, |
|
376 | + * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | + * about creating an itemized list of purchases and instead only send the total due) |
|
378 | + * |
|
379 | + * @param EE_Transaction $transaction |
|
380 | + * @return float |
|
381 | + */ |
|
382 | + protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | + { |
|
384 | + $total_line_item = $transaction->total_line_item(); |
|
385 | + $total = 0; |
|
386 | + foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | + $total += max($item_line_item->total(), 0); |
|
388 | + } |
|
389 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | + $total += max($tax_line_item->total(), 0); |
|
391 | + } |
|
392 | + return $total; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Determines whether or not we can easily itemize the transaction using only |
|
397 | + * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | + * |
|
399 | + * @param EEI_Payment $payment |
|
400 | + * @return boolean |
|
401 | + */ |
|
402 | + protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | + { |
|
404 | + return $this->_money->compare_floats( |
|
405 | + $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | + $payment->transaction()->total() |
|
407 | + ) |
|
408 | + && $this->_money->compare_floats( |
|
409 | + $payment->amount(), |
|
410 | + $payment->transaction()->total() |
|
411 | + ); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Handles updating the transaction and any other related data based on the payment. |
|
416 | + * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | + * but doing so on those functions might be too early. It's possible that the changes |
|
418 | + * you make to teh transaction or registration or line items may just get overwritten |
|
419 | + * at that point. Instead, you should store any info you need on the payment during those |
|
420 | + * functions, and use that information at this step, which client code will decide |
|
421 | + * for you when it should be called. |
|
422 | + * |
|
423 | + * @param EE_Payment $payment |
|
424 | + * @return void |
|
425 | + */ |
|
426 | + public function update_txn_based_on_payment($payment) |
|
427 | + { |
|
428 | + // maybe update the transaction or line items or registrations |
|
429 | + // but most gateways don't need to do this, because they only update the payment |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | + * |
|
435 | + * @param EEI_Payment $payment |
|
436 | + * @return EEI_Event|null |
|
437 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | + */ |
|
439 | + protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | + { |
|
441 | + return $payment->get_first_event(); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets the name of the first event for which is being paid |
|
446 | + * |
|
447 | + * @param EEI_Payment $payment |
|
448 | + * @return string |
|
449 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | + */ |
|
451 | + protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | + { |
|
453 | + return $payment->get_first_event_name(); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | + * |
|
459 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | + * @param EE_Payment $payment |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | + { |
|
465 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | + * |
|
471 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | + * @param EEI_Payment $payment |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | + { |
|
477 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Gets the name to use for a line item when sending line items to the gateway |
|
482 | + * |
|
483 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | + * @param EEI_Line_Item $line_item |
|
485 | + * @param EEI_Payment $payment |
|
486 | + * @return string |
|
487 | + */ |
|
488 | + protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
489 | + { |
|
490 | + return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Gets the description to use for a line item when sending line items to the gateway |
|
495 | + * |
|
496 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | + * @param EEI_Line_Item $line_item |
|
498 | + * @param EEI_Payment $payment |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
502 | + { |
|
503 | + return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Gets the order description that should generlly be sent to gateways |
|
508 | + * |
|
509 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | + * @param EEI_Payment $payment |
|
511 | + * @return type |
|
512 | + */ |
|
513 | + protected function _format_order_description(EEI_Payment $payment) |
|
514 | + { |
|
515 | + return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | + } |
|
517 | 517 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | // check if class object is instantiated |
187 | 187 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
188 | 188 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
189 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
190 | 190 | self::$_instance = new self( |
191 | 191 | $cache_storage, |
192 | 192 | $lifespan, |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
220 | 220 | // (which currently fires on the init hook at priority 9), |
221 | 221 | // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
222 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | $this->session_lifespan = $lifespan; |
226 | 226 | $this->request = $request; |
227 | - if (! defined('ESPRESSO_SESSION')) { |
|
227 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
228 | 228 | define('ESPRESSO_SESSION', true); |
229 | 229 | } |
230 | 230 | // retrieve session options from db |
231 | 231 | $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
232 | - if (! empty($session_settings)) { |
|
232 | + if ( ! empty($session_settings)) { |
|
233 | 233 | // cycle though existing session options |
234 | 234 | foreach ($session_settings as $var_name => $session_setting) { |
235 | 235 | // set values for class properties |
236 | - $var_name = '_' . $var_name; |
|
236 | + $var_name = '_'.$var_name; |
|
237 | 237 | $this->{$var_name} = $session_setting; |
238 | 238 | } |
239 | 239 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | public function open_session() |
293 | 293 | { |
294 | 294 | // check for existing session and retrieve it from db |
295 | - if (! $this->_espresso_session()) { |
|
295 | + if ( ! $this->_espresso_session()) { |
|
296 | 296 | // or just start a new one |
297 | 297 | $this->_create_espresso_session(); |
298 | 298 | } |
@@ -365,9 +365,9 @@ discard block |
||
365 | 365 | // set some defaults |
366 | 366 | foreach ($this->_default_session_vars as $key => $default_var) { |
367 | 367 | if (is_array($default_var)) { |
368 | - $this->_session_data[ $key ] = array(); |
|
368 | + $this->_session_data[$key] = array(); |
|
369 | 369 | } else { |
370 | - $this->_session_data[ $key ] = ''; |
|
370 | + $this->_session_data[$key] = ''; |
|
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
@@ -498,8 +498,8 @@ discard block |
||
498 | 498 | $this->reset_checkout(); |
499 | 499 | $this->reset_transaction(); |
500 | 500 | } |
501 | - if (! empty($key)) { |
|
502 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
501 | + if ( ! empty($key)) { |
|
502 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null; |
|
503 | 503 | } |
504 | 504 | return $this->_session_data; |
505 | 505 | } |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | return false; |
528 | 528 | } |
529 | 529 | foreach ($data as $key => $value) { |
530 | - if (isset($this->_default_session_vars[ $key ])) { |
|
530 | + if (isset($this->_default_session_vars[$key])) { |
|
531 | 531 | EE_Error::add_error( |
532 | 532 | sprintf( |
533 | 533 | esc_html__( |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | ); |
543 | 543 | return false; |
544 | 544 | } |
545 | - $this->_session_data[ $key ] = $value; |
|
545 | + $this->_session_data[$key] = $value; |
|
546 | 546 | } |
547 | 547 | return true; |
548 | 548 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | $this->_user_agent = $this->request->userAgent(); |
576 | 576 | // now let's retrieve what's in the db |
577 | 577 | $session_data = $this->_retrieve_session_data(); |
578 | - if (! empty($session_data)) { |
|
578 | + if ( ! empty($session_data)) { |
|
579 | 579 | // get the current time in UTC |
580 | 580 | $this->_time = $this->_time !== null ? $this->_time : time(); |
581 | 581 | // and reset the session expiration |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | // set initial site access time and the session expiration |
587 | 587 | $this->_set_init_access_and_expiration(); |
588 | 588 | // set referer |
589 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
589 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
590 | 590 | ? esc_attr($_SERVER['HTTP_REFERER']) |
591 | 591 | : ''; |
592 | 592 | // no previous session = go back and create one (on top of the data above) |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | */ |
624 | 624 | protected function _retrieve_session_data() |
625 | 625 | { |
626 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
626 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
627 | 627 | try { |
628 | 628 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
629 | 629 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | } |
633 | 633 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
634 | 634 | $hash_check = $this->cache_storage->get( |
635 | - EE_Session::hash_check_prefix . $this->_sid, |
|
635 | + EE_Session::hash_check_prefix.$this->_sid, |
|
636 | 636 | false |
637 | 637 | ); |
638 | 638 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
643 | 643 | 'event_espresso' |
644 | 644 | ), |
645 | - EE_Session::session_id_prefix . $this->_sid |
|
645 | + EE_Session::session_id_prefix.$this->_sid |
|
646 | 646 | ), |
647 | 647 | __FILE__, |
648 | 648 | __FUNCTION__, |
@@ -656,17 +656,17 @@ discard block |
||
656 | 656 | $row = $wpdb->get_row( |
657 | 657 | $wpdb->prepare( |
658 | 658 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
659 | - '_transient_' . $ssn_key |
|
659 | + '_transient_'.$ssn_key |
|
660 | 660 | ) |
661 | 661 | ); |
662 | 662 | $session_data = is_object($row) ? $row->option_value : null; |
663 | 663 | if ($session_data) { |
664 | 664 | $session_data = preg_replace_callback( |
665 | 665 | '!s:(d+):"(.*?)";!', |
666 | - function ($match) { |
|
666 | + function($match) { |
|
667 | 667 | return $match[1] === strlen($match[2]) |
668 | 668 | ? $match[0] |
669 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
669 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
670 | 670 | }, |
671 | 671 | $session_data |
672 | 672 | ); |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | $session_data = $this->encryption instanceof EE_Encryption |
678 | 678 | ? $this->encryption->base64_string_decode($session_data) |
679 | 679 | : $session_data; |
680 | - if (! is_array($session_data)) { |
|
680 | + if ( ! is_array($session_data)) { |
|
681 | 681 | try { |
682 | 682 | $session_data = maybe_unserialize($session_data); |
683 | 683 | } catch (Exception $e) { |
@@ -691,21 +691,21 @@ discard block |
||
691 | 691 | . '</pre><br>' |
692 | 692 | . $this->find_serialize_error($session_data) |
693 | 693 | : ''; |
694 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
694 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
695 | 695 | throw new InvalidSessionDataException($msg, 0, $e); |
696 | 696 | } |
697 | 697 | } |
698 | 698 | // just a check to make sure the session array is indeed an array |
699 | - if (! is_array($session_data)) { |
|
699 | + if ( ! is_array($session_data)) { |
|
700 | 700 | // no?!?! then something is wrong |
701 | 701 | $msg = esc_html__( |
702 | 702 | 'The session data is missing, invalid, or corrupted.', |
703 | 703 | 'event_espresso' |
704 | 704 | ); |
705 | 705 | $msg .= WP_DEBUG |
706 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
706 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
707 | 707 | : ''; |
708 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
708 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
709 | 709 | throw new InvalidSessionDataException($msg); |
710 | 710 | } |
711 | 711 | if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | if (isset($_REQUEST['EESID'])) { |
733 | 733 | $session_id = sanitize_text_field($_REQUEST['EESID']); |
734 | 734 | } else { |
735 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
735 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
736 | 736 | } |
737 | 737 | return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
738 | 738 | } |
@@ -835,19 +835,19 @@ discard block |
||
835 | 835 | $page_visit = $this->_get_page_visit(); |
836 | 836 | if ($page_visit) { |
837 | 837 | // set pages visited where the first will be the http referrer |
838 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
838 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
839 | 839 | // we'll only save the last 10 page visits. |
840 | 840 | $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
841 | 841 | } |
842 | 842 | break; |
843 | 843 | default: |
844 | 844 | // carry any other data over |
845 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
845 | + $session_data[$key] = $this->_session_data[$key]; |
|
846 | 846 | } |
847 | 847 | } |
848 | 848 | $this->_session_data = $session_data; |
849 | 849 | // creating a new session does not require saving to the db just yet |
850 | - if (! $new_session) { |
|
850 | + if ( ! $new_session) { |
|
851 | 851 | // ready? let's save |
852 | 852 | if ($this->_save_session_to_db()) { |
853 | 853 | return true; |
@@ -888,8 +888,8 @@ discard block |
||
888 | 888 | isset($this->_session_data['ee_notices']) |
889 | 889 | && ( |
890 | 890 | ! empty($this->_session_data['ee_notices']['attention']) |
891 | - || !empty($this->_session_data['ee_notices']['errors']) |
|
892 | - || !empty($this->_session_data['ee_notices']['success']) |
|
891 | + || ! empty($this->_session_data['ee_notices']['errors']) |
|
892 | + || ! empty($this->_session_data['ee_notices']['success']) |
|
893 | 893 | ) |
894 | 894 | ); |
895 | 895 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | } |
919 | 919 | $transaction = $this->transaction(); |
920 | 920 | if ($transaction instanceof EE_Transaction) { |
921 | - if (! $transaction->ID()) { |
|
921 | + if ( ! $transaction->ID()) { |
|
922 | 922 | $transaction->save(); |
923 | 923 | } |
924 | 924 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -932,14 +932,14 @@ discard block |
||
932 | 932 | // maybe save hash check |
933 | 933 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
934 | 934 | $this->cache_storage->add( |
935 | - EE_Session::hash_check_prefix . $this->_sid, |
|
935 | + EE_Session::hash_check_prefix.$this->_sid, |
|
936 | 936 | md5($session_data), |
937 | 937 | $this->session_lifespan->inSeconds() |
938 | 938 | ); |
939 | 939 | } |
940 | 940 | // we're using the Transient API for storing session data, |
941 | 941 | return $this->cache_storage->add( |
942 | - EE_Session::session_id_prefix . $this->_sid, |
|
942 | + EE_Session::session_id_prefix.$this->_sid, |
|
943 | 943 | $session_data, |
944 | 944 | $this->session_lifespan->inSeconds() |
945 | 945 | ); |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | */ |
954 | 954 | public function _get_page_visit() |
955 | 955 | { |
956 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
956 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
957 | 957 | // check for request url |
958 | 958 | if (isset($_SERVER['REQUEST_URI'])) { |
959 | 959 | $http_host = ''; |
@@ -969,14 +969,14 @@ discard block |
||
969 | 969 | // check for page_id in SERVER REQUEST |
970 | 970 | if (isset($_REQUEST['page_id'])) { |
971 | 971 | // rebuild $e_reg without any of the extra parameters |
972 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
972 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
973 | 973 | } |
974 | 974 | // check for $e_reg in SERVER REQUEST |
975 | 975 | if (isset($_REQUEST['ee'])) { |
976 | 976 | // rebuild $e_reg without any of the extra parameters |
977 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
977 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
978 | 978 | } |
979 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
979 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
980 | 980 | } |
981 | 981 | return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
982 | 982 | } |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
1015 | 1015 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
1016 | 1016 | // </h3>'; |
1017 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1017 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
1018 | 1018 | $this->reset_cart(); |
1019 | 1019 | $this->reset_checkout(); |
1020 | 1020 | $this->reset_transaction(); |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | public function reset_data($data_to_reset = array(), $show_all_notices = false) |
1037 | 1037 | { |
1038 | 1038 | // if $data_to_reset is not in an array, then put it in one |
1039 | - if (! is_array($data_to_reset)) { |
|
1039 | + if ( ! is_array($data_to_reset)) { |
|
1040 | 1040 | $data_to_reset = array($data_to_reset); |
1041 | 1041 | } |
1042 | 1042 | // nothing ??? go home! |
@@ -1056,11 +1056,11 @@ discard block |
||
1056 | 1056 | // since $data_to_reset is an array, cycle through the values |
1057 | 1057 | foreach ($data_to_reset as $reset) { |
1058 | 1058 | // first check to make sure it is a valid session var |
1059 | - if (isset($this->_session_data[ $reset ])) { |
|
1059 | + if (isset($this->_session_data[$reset])) { |
|
1060 | 1060 | // then check to make sure it is not a default var |
1061 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1061 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
1062 | 1062 | // remove session var |
1063 | - unset($this->_session_data[ $reset ]); |
|
1063 | + unset($this->_session_data[$reset]); |
|
1064 | 1064 | if ($show_all_notices) { |
1065 | 1065 | EE_Error::add_success( |
1066 | 1066 | sprintf( |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | // or use that for the new transient cleanup query limit |
1162 | 1162 | add_filter( |
1163 | 1163 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
1164 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1164 | + function() use ($expired_session_transient_delete_query_limit) { |
|
1165 | 1165 | return $expired_session_transient_delete_query_limit; |
1166 | 1166 | } |
1167 | 1167 | ); |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | $error = '<pre>'; |
1180 | 1180 | $data2 = preg_replace_callback( |
1181 | 1181 | '!s:(\d+):"(.*?)";!', |
1182 | - function ($match) { |
|
1182 | + function($match) { |
|
1183 | 1183 | return ($match[1] === strlen($match[2])) |
1184 | 1184 | ? $match[0] |
1185 | 1185 | : 's:' |
@@ -1191,13 +1191,13 @@ discard block |
||
1191 | 1191 | $data1 |
1192 | 1192 | ); |
1193 | 1193 | $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
1194 | - $error .= $data1 . PHP_EOL; |
|
1195 | - $error .= $data2 . PHP_EOL; |
|
1194 | + $error .= $data1.PHP_EOL; |
|
1195 | + $error .= $data2.PHP_EOL; |
|
1196 | 1196 | for ($i = 0; $i < $max; $i++) { |
1197 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1198 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1199 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1200 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1197 | + if (@$data1[$i] !== @$data2[$i]) { |
|
1198 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
1199 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
1200 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
1201 | 1201 | $start = ($i - 20); |
1202 | 1202 | $start = ($start < 0) ? 0 : $start; |
1203 | 1203 | $length = 40; |
@@ -1212,7 +1212,7 @@ discard block |
||
1212 | 1212 | $error .= "\t-> Section Data1 = "; |
1213 | 1213 | $error .= substr_replace( |
1214 | 1214 | substr($data1, $start, $length), |
1215 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1215 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
1216 | 1216 | $rpoint, |
1217 | 1217 | $rlength |
1218 | 1218 | ); |
@@ -1220,7 +1220,7 @@ discard block |
||
1220 | 1220 | $error .= "\t-> Section Data2 = "; |
1221 | 1221 | $error .= substr_replace( |
1222 | 1222 | substr($data2, $start, $length), |
1223 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1223 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
1224 | 1224 | $rpoint, |
1225 | 1225 | $rlength |
1226 | 1226 | ); |
@@ -1251,7 +1251,7 @@ discard block |
||
1251 | 1251 | public function garbageCollection() |
1252 | 1252 | { |
1253 | 1253 | // only perform during regular requests if last garbage collection was over an hour ago |
1254 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1254 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1255 | 1255 | $this->_last_gc = time(); |
1256 | 1256 | $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
1257 | 1257 | /** @type WPDB $wpdb */ |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | // AND option_value < 1508368198 LIMIT 50 |
1287 | 1287 | $expired_sessions = $wpdb->get_col($SQL); |
1288 | 1288 | // valid results? |
1289 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1289 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1290 | 1290 | $this->cache_storage->deleteMany($expired_sessions, true); |
1291 | 1291 | } |
1292 | 1292 | } |
@@ -23,1254 +23,1254 @@ discard block |
||
23 | 23 | class EE_Session implements SessionIdentifierInterface |
24 | 24 | { |
25 | 25 | |
26 | - const session_id_prefix = 'ee_ssn_'; |
|
27 | - |
|
28 | - const hash_check_prefix = 'ee_shc_'; |
|
29 | - |
|
30 | - const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
31 | - |
|
32 | - const STATUS_CLOSED = 0; |
|
33 | - |
|
34 | - const STATUS_OPEN = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * instance of the EE_Session object |
|
38 | - * |
|
39 | - * @var EE_Session |
|
40 | - */ |
|
41 | - private static $_instance; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var CacheStorageInterface $cache_storage |
|
45 | - */ |
|
46 | - protected $cache_storage; |
|
47 | - |
|
48 | - /** |
|
49 | - * EE_Encryption object |
|
50 | - * |
|
51 | - * @var EE_Encryption |
|
52 | - */ |
|
53 | - protected $encryption; |
|
54 | - |
|
55 | - /** |
|
56 | - * the session id |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - private $_sid; |
|
61 | - |
|
62 | - /** |
|
63 | - * session id salt |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - private $_sid_salt; |
|
68 | - |
|
69 | - /** |
|
70 | - * session data |
|
71 | - * |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - private $_session_data = array(); |
|
75 | - |
|
76 | - /** |
|
77 | - * how long an EE session lasts |
|
78 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
79 | - * |
|
80 | - * @var SessionLifespan $session_lifespan |
|
81 | - */ |
|
82 | - private $session_lifespan; |
|
83 | - |
|
84 | - /** |
|
85 | - * session expiration time as Unix timestamp in GMT |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - private $_expiration; |
|
90 | - |
|
91 | - /** |
|
92 | - * whether or not session has expired at some point |
|
93 | - * |
|
94 | - * @var boolean |
|
95 | - */ |
|
96 | - private $_expired = false; |
|
97 | - |
|
98 | - /** |
|
99 | - * current time as Unix timestamp in GMT |
|
100 | - * |
|
101 | - * @var int |
|
102 | - */ |
|
103 | - private $_time; |
|
104 | - |
|
105 | - /** |
|
106 | - * whether to encrypt session data |
|
107 | - * |
|
108 | - * @var bool |
|
109 | - */ |
|
110 | - private $_use_encryption; |
|
111 | - |
|
112 | - /** |
|
113 | - * well... according to the server... |
|
114 | - * |
|
115 | - * @var null |
|
116 | - */ |
|
117 | - private $_user_agent; |
|
118 | - |
|
119 | - /** |
|
120 | - * do you really trust the server ? |
|
121 | - * |
|
122 | - * @var null |
|
123 | - */ |
|
124 | - private $_ip_address; |
|
125 | - |
|
126 | - /** |
|
127 | - * current WP user_id |
|
128 | - * |
|
129 | - * @var null |
|
130 | - */ |
|
131 | - private $_wp_user_id; |
|
132 | - |
|
133 | - /** |
|
134 | - * array for defining default session vars |
|
135 | - * |
|
136 | - * @var array |
|
137 | - */ |
|
138 | - private $_default_session_vars = array( |
|
139 | - 'id' => null, |
|
140 | - 'user_id' => null, |
|
141 | - 'ip_address' => null, |
|
142 | - 'user_agent' => null, |
|
143 | - 'init_access' => null, |
|
144 | - 'last_access' => null, |
|
145 | - 'expiration' => null, |
|
146 | - 'pages_visited' => array(), |
|
147 | - ); |
|
148 | - |
|
149 | - /** |
|
150 | - * timestamp for when last garbage collection cycle was performed |
|
151 | - * |
|
152 | - * @var int $_last_gc |
|
153 | - */ |
|
154 | - private $_last_gc; |
|
155 | - |
|
156 | - /** |
|
157 | - * @var RequestInterface $request |
|
158 | - */ |
|
159 | - protected $request; |
|
160 | - |
|
161 | - /** |
|
162 | - * whether session is active or not |
|
163 | - * |
|
164 | - * @var int $status |
|
165 | - */ |
|
166 | - private $status = EE_Session::STATUS_CLOSED; |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @singleton method used to instantiate class object |
|
171 | - * @param CacheStorageInterface $cache_storage |
|
172 | - * @param SessionLifespan|null $lifespan |
|
173 | - * @param RequestInterface $request |
|
174 | - * @param EE_Encryption $encryption |
|
175 | - * @return EE_Session |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws InvalidDataTypeException |
|
178 | - * @throws InvalidInterfaceException |
|
179 | - */ |
|
180 | - public static function instance( |
|
181 | - CacheStorageInterface $cache_storage = null, |
|
182 | - SessionLifespan $lifespan = null, |
|
183 | - RequestInterface $request = null, |
|
184 | - EE_Encryption $encryption = null |
|
185 | - ) { |
|
186 | - // check if class object is instantiated |
|
187 | - // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
188 | - // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
190 | - self::$_instance = new self( |
|
191 | - $cache_storage, |
|
192 | - $lifespan, |
|
193 | - $request, |
|
194 | - $encryption |
|
195 | - ); |
|
196 | - } |
|
197 | - return self::$_instance; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * protected constructor to prevent direct creation |
|
203 | - * |
|
204 | - * @param CacheStorageInterface $cache_storage |
|
205 | - * @param SessionLifespan $lifespan |
|
206 | - * @param RequestInterface $request |
|
207 | - * @param EE_Encryption $encryption |
|
208 | - * @throws InvalidArgumentException |
|
209 | - * @throws InvalidDataTypeException |
|
210 | - * @throws InvalidInterfaceException |
|
211 | - */ |
|
212 | - protected function __construct( |
|
213 | - CacheStorageInterface $cache_storage, |
|
214 | - SessionLifespan $lifespan, |
|
215 | - RequestInterface $request, |
|
216 | - EE_Encryption $encryption = null |
|
217 | - ) { |
|
218 | - // session loading is turned ON by default, |
|
219 | - // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
220 | - // (which currently fires on the init hook at priority 9), |
|
221 | - // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
223 | - return; |
|
224 | - } |
|
225 | - $this->session_lifespan = $lifespan; |
|
226 | - $this->request = $request; |
|
227 | - if (! defined('ESPRESSO_SESSION')) { |
|
228 | - define('ESPRESSO_SESSION', true); |
|
229 | - } |
|
230 | - // retrieve session options from db |
|
231 | - $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
232 | - if (! empty($session_settings)) { |
|
233 | - // cycle though existing session options |
|
234 | - foreach ($session_settings as $var_name => $session_setting) { |
|
235 | - // set values for class properties |
|
236 | - $var_name = '_' . $var_name; |
|
237 | - $this->{$var_name} = $session_setting; |
|
238 | - } |
|
239 | - } |
|
240 | - $this->cache_storage = $cache_storage; |
|
241 | - // are we using encryption? |
|
242 | - $this->_use_encryption = $encryption instanceof EE_Encryption |
|
243 | - && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
244 | - // encrypt data via: $this->encryption->encrypt(); |
|
245 | - $this->encryption = $encryption; |
|
246 | - // filter hook allows outside functions/classes/plugins to change default empty cart |
|
247 | - $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
248 | - array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
249 | - // apply default session vars |
|
250 | - $this->_set_defaults(); |
|
251 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
252 | - // check request for 'clear_session' param |
|
253 | - add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
254 | - // once everything is all said and done, |
|
255 | - add_action('shutdown', array($this, 'update'), 100); |
|
256 | - add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
257 | - $this->configure_garbage_collection_filters(); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @return bool |
|
263 | - * @throws InvalidArgumentException |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws InvalidInterfaceException |
|
266 | - */ |
|
267 | - public static function isLoadedAndActive() |
|
268 | - { |
|
269 | - return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
270 | - && EE_Session::instance() instanceof EE_Session |
|
271 | - && EE_Session::instance()->isActive(); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return bool |
|
277 | - */ |
|
278 | - public function isActive() |
|
279 | - { |
|
280 | - return $this->status === EE_Session::STATUS_OPEN; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @return void |
|
286 | - * @throws EE_Error |
|
287 | - * @throws InvalidArgumentException |
|
288 | - * @throws InvalidDataTypeException |
|
289 | - * @throws InvalidInterfaceException |
|
290 | - * @throws InvalidSessionDataException |
|
291 | - */ |
|
292 | - public function open_session() |
|
293 | - { |
|
294 | - // check for existing session and retrieve it from db |
|
295 | - if (! $this->_espresso_session()) { |
|
296 | - // or just start a new one |
|
297 | - $this->_create_espresso_session(); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - public function expired() |
|
306 | - { |
|
307 | - return $this->_expired; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @return void |
|
313 | - */ |
|
314 | - public function reset_expired() |
|
315 | - { |
|
316 | - $this->_expired = false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @return int |
|
322 | - */ |
|
323 | - public function expiration() |
|
324 | - { |
|
325 | - return $this->_expiration; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @return int |
|
331 | - */ |
|
332 | - public function extension() |
|
333 | - { |
|
334 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param int $time number of seconds to add to session expiration |
|
340 | - */ |
|
341 | - public function extend_expiration($time = 0) |
|
342 | - { |
|
343 | - $time = $time ? $time : $this->extension(); |
|
344 | - $this->_expiration += absint($time); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @return int |
|
350 | - */ |
|
351 | - public function lifespan() |
|
352 | - { |
|
353 | - return $this->session_lifespan->inSeconds(); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * This just sets some defaults for the _session data property |
|
359 | - * |
|
360 | - * @access private |
|
361 | - * @return void |
|
362 | - */ |
|
363 | - private function _set_defaults() |
|
364 | - { |
|
365 | - // set some defaults |
|
366 | - foreach ($this->_default_session_vars as $key => $default_var) { |
|
367 | - if (is_array($default_var)) { |
|
368 | - $this->_session_data[ $key ] = array(); |
|
369 | - } else { |
|
370 | - $this->_session_data[ $key ] = ''; |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @retrieve session data |
|
378 | - * @access public |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function id() |
|
382 | - { |
|
383 | - return $this->_sid; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param \EE_Cart $cart |
|
389 | - * @return bool |
|
390 | - */ |
|
391 | - public function set_cart(EE_Cart $cart) |
|
392 | - { |
|
393 | - $this->_session_data['cart'] = $cart; |
|
394 | - return true; |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * reset_cart |
|
400 | - */ |
|
401 | - public function reset_cart() |
|
402 | - { |
|
403 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
404 | - $this->_session_data['cart'] = null; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @return \EE_Cart |
|
410 | - */ |
|
411 | - public function cart() |
|
412 | - { |
|
413 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
414 | - ? $this->_session_data['cart'] |
|
415 | - : null; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @param \EE_Checkout $checkout |
|
421 | - * @return bool |
|
422 | - */ |
|
423 | - public function set_checkout(EE_Checkout $checkout) |
|
424 | - { |
|
425 | - $this->_session_data['checkout'] = $checkout; |
|
426 | - return true; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * reset_checkout |
|
432 | - */ |
|
433 | - public function reset_checkout() |
|
434 | - { |
|
435 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
436 | - $this->_session_data['checkout'] = null; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * @return \EE_Checkout |
|
442 | - */ |
|
443 | - public function checkout() |
|
444 | - { |
|
445 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
446 | - ? $this->_session_data['checkout'] |
|
447 | - : null; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param \EE_Transaction $transaction |
|
453 | - * @return bool |
|
454 | - * @throws EE_Error |
|
455 | - */ |
|
456 | - public function set_transaction(EE_Transaction $transaction) |
|
457 | - { |
|
458 | - // first remove the session from the transaction before we save the transaction in the session |
|
459 | - $transaction->set_txn_session_data(null); |
|
460 | - $this->_session_data['transaction'] = $transaction; |
|
461 | - return true; |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * reset_transaction |
|
467 | - */ |
|
468 | - public function reset_transaction() |
|
469 | - { |
|
470 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
471 | - $this->_session_data['transaction'] = null; |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * @return \EE_Transaction |
|
477 | - */ |
|
478 | - public function transaction() |
|
479 | - { |
|
480 | - return isset($this->_session_data['transaction']) |
|
481 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
482 | - ? $this->_session_data['transaction'] |
|
483 | - : null; |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * retrieve session data |
|
489 | - * |
|
490 | - * @param null $key |
|
491 | - * @param bool $reset_cache |
|
492 | - * @return array |
|
493 | - */ |
|
494 | - public function get_session_data($key = null, $reset_cache = false) |
|
495 | - { |
|
496 | - if ($reset_cache) { |
|
497 | - $this->reset_cart(); |
|
498 | - $this->reset_checkout(); |
|
499 | - $this->reset_transaction(); |
|
500 | - } |
|
501 | - if (! empty($key)) { |
|
502 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
503 | - } |
|
504 | - return $this->_session_data; |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * Returns TRUE on success, FALSE on fail |
|
510 | - * |
|
511 | - * @param array $data |
|
512 | - * @return bool |
|
513 | - */ |
|
514 | - public function set_session_data($data) |
|
515 | - { |
|
516 | - // nothing ??? bad data ??? go home! |
|
517 | - if (empty($data) || ! is_array($data)) { |
|
518 | - EE_Error::add_error( |
|
519 | - esc_html__( |
|
520 | - 'No session data or invalid session data was provided.', |
|
521 | - 'event_espresso' |
|
522 | - ), |
|
523 | - __FILE__, |
|
524 | - __FUNCTION__, |
|
525 | - __LINE__ |
|
526 | - ); |
|
527 | - return false; |
|
528 | - } |
|
529 | - foreach ($data as $key => $value) { |
|
530 | - if (isset($this->_default_session_vars[ $key ])) { |
|
531 | - EE_Error::add_error( |
|
532 | - sprintf( |
|
533 | - esc_html__( |
|
534 | - 'Sorry! %s is a default session datum and can not be reset.', |
|
535 | - 'event_espresso' |
|
536 | - ), |
|
537 | - $key |
|
538 | - ), |
|
539 | - __FILE__, |
|
540 | - __FUNCTION__, |
|
541 | - __LINE__ |
|
542 | - ); |
|
543 | - return false; |
|
544 | - } |
|
545 | - $this->_session_data[ $key ] = $value; |
|
546 | - } |
|
547 | - return true; |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * @initiate session |
|
553 | - * @access private |
|
554 | - * @return TRUE on success, FALSE on fail |
|
555 | - * @throws EE_Error |
|
556 | - * @throws InvalidArgumentException |
|
557 | - * @throws InvalidDataTypeException |
|
558 | - * @throws InvalidInterfaceException |
|
559 | - * @throws InvalidSessionDataException |
|
560 | - */ |
|
561 | - private function _espresso_session() |
|
562 | - { |
|
563 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
564 | - // check that session has started |
|
565 | - if (session_id() === '') { |
|
566 | - // starts a new session if one doesn't already exist, or re-initiates an existing one |
|
567 | - session_start(); |
|
568 | - } |
|
569 | - $this->status = EE_Session::STATUS_OPEN; |
|
570 | - // get our modified session ID |
|
571 | - $this->_sid = $this->_generate_session_id(); |
|
572 | - // and the visitors IP |
|
573 | - $this->_ip_address = $this->request->ipAddress(); |
|
574 | - // set the "user agent" |
|
575 | - $this->_user_agent = $this->request->userAgent(); |
|
576 | - // now let's retrieve what's in the db |
|
577 | - $session_data = $this->_retrieve_session_data(); |
|
578 | - if (! empty($session_data)) { |
|
579 | - // get the current time in UTC |
|
580 | - $this->_time = $this->_time !== null ? $this->_time : time(); |
|
581 | - // and reset the session expiration |
|
582 | - $this->_expiration = isset($session_data['expiration']) |
|
583 | - ? $session_data['expiration'] |
|
584 | - : $this->_time + $this->session_lifespan->inSeconds(); |
|
585 | - } else { |
|
586 | - // set initial site access time and the session expiration |
|
587 | - $this->_set_init_access_and_expiration(); |
|
588 | - // set referer |
|
589 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
590 | - ? esc_attr($_SERVER['HTTP_REFERER']) |
|
591 | - : ''; |
|
592 | - // no previous session = go back and create one (on top of the data above) |
|
593 | - return false; |
|
594 | - } |
|
595 | - // now the user agent |
|
596 | - if ($session_data['user_agent'] !== $this->_user_agent) { |
|
597 | - return false; |
|
598 | - } |
|
599 | - // wait a minute... how old are you? |
|
600 | - if ($this->_time > $this->_expiration) { |
|
601 | - // yer too old fer me! |
|
602 | - $this->_expired = true; |
|
603 | - // wipe out everything that isn't a default session datum |
|
604 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
605 | - } |
|
606 | - // make event espresso session data available to plugin |
|
607 | - $this->_session_data = array_merge($this->_session_data, $session_data); |
|
608 | - return true; |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * _get_session_data |
|
614 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
615 | - * databases |
|
616 | - * |
|
617 | - * @return array |
|
618 | - * @throws EE_Error |
|
619 | - * @throws InvalidArgumentException |
|
620 | - * @throws InvalidSessionDataException |
|
621 | - * @throws InvalidDataTypeException |
|
622 | - * @throws InvalidInterfaceException |
|
623 | - */ |
|
624 | - protected function _retrieve_session_data() |
|
625 | - { |
|
626 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
627 | - try { |
|
628 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
629 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
630 | - if (empty($session_data)) { |
|
631 | - return array(); |
|
632 | - } |
|
633 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
634 | - $hash_check = $this->cache_storage->get( |
|
635 | - EE_Session::hash_check_prefix . $this->_sid, |
|
636 | - false |
|
637 | - ); |
|
638 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
639 | - EE_Error::add_error( |
|
640 | - sprintf( |
|
641 | - __( |
|
642 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
643 | - 'event_espresso' |
|
644 | - ), |
|
645 | - EE_Session::session_id_prefix . $this->_sid |
|
646 | - ), |
|
647 | - __FILE__, |
|
648 | - __FUNCTION__, |
|
649 | - __LINE__ |
|
650 | - ); |
|
651 | - } |
|
652 | - } |
|
653 | - } catch (Exception $e) { |
|
654 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
655 | - global $wpdb; |
|
656 | - $row = $wpdb->get_row( |
|
657 | - $wpdb->prepare( |
|
658 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
659 | - '_transient_' . $ssn_key |
|
660 | - ) |
|
661 | - ); |
|
662 | - $session_data = is_object($row) ? $row->option_value : null; |
|
663 | - if ($session_data) { |
|
664 | - $session_data = preg_replace_callback( |
|
665 | - '!s:(d+):"(.*?)";!', |
|
666 | - function ($match) { |
|
667 | - return $match[1] === strlen($match[2]) |
|
668 | - ? $match[0] |
|
669 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
670 | - }, |
|
671 | - $session_data |
|
672 | - ); |
|
673 | - } |
|
674 | - $session_data = maybe_unserialize($session_data); |
|
675 | - } |
|
676 | - // in case the data is encoded... try to decode it |
|
677 | - $session_data = $this->encryption instanceof EE_Encryption |
|
678 | - ? $this->encryption->base64_string_decode($session_data) |
|
679 | - : $session_data; |
|
680 | - if (! is_array($session_data)) { |
|
681 | - try { |
|
682 | - $session_data = maybe_unserialize($session_data); |
|
683 | - } catch (Exception $e) { |
|
684 | - $msg = esc_html__( |
|
685 | - 'An error occurred while attempting to unserialize the session data.', |
|
686 | - 'event_espresso' |
|
687 | - ); |
|
688 | - $msg .= WP_DEBUG |
|
689 | - ? '<br><pre>' |
|
690 | - . print_r($session_data, true) |
|
691 | - . '</pre><br>' |
|
692 | - . $this->find_serialize_error($session_data) |
|
693 | - : ''; |
|
694 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
695 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
696 | - } |
|
697 | - } |
|
698 | - // just a check to make sure the session array is indeed an array |
|
699 | - if (! is_array($session_data)) { |
|
700 | - // no?!?! then something is wrong |
|
701 | - $msg = esc_html__( |
|
702 | - 'The session data is missing, invalid, or corrupted.', |
|
703 | - 'event_espresso' |
|
704 | - ); |
|
705 | - $msg .= WP_DEBUG |
|
706 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
707 | - : ''; |
|
708 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
709 | - throw new InvalidSessionDataException($msg); |
|
710 | - } |
|
711 | - if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
712 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
713 | - $session_data['transaction'] |
|
714 | - ); |
|
715 | - } |
|
716 | - return $session_data; |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * _generate_session_id |
|
722 | - * Retrieves the PHP session id either directly from the PHP session, |
|
723 | - * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
724 | - * The session id is then salted and hashed (mmm sounds tasty) |
|
725 | - * so that it can be safely used as a $_REQUEST param |
|
726 | - * |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - protected function _generate_session_id() |
|
730 | - { |
|
731 | - // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
732 | - if (isset($_REQUEST['EESID'])) { |
|
733 | - $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
734 | - } else { |
|
735 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
736 | - } |
|
737 | - return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
738 | - } |
|
739 | - |
|
740 | - |
|
741 | - /** |
|
742 | - * _get_sid_salt |
|
743 | - * |
|
744 | - * @return string |
|
745 | - */ |
|
746 | - protected function _get_sid_salt() |
|
747 | - { |
|
748 | - // was session id salt already saved to db ? |
|
749 | - if (empty($this->_sid_salt)) { |
|
750 | - // no? then maybe use WP defined constant |
|
751 | - if (defined('AUTH_SALT')) { |
|
752 | - $this->_sid_salt = AUTH_SALT; |
|
753 | - } |
|
754 | - // if salt doesn't exist or is too short |
|
755 | - if (strlen($this->_sid_salt) < 32) { |
|
756 | - // create a new one |
|
757 | - $this->_sid_salt = wp_generate_password(64); |
|
758 | - } |
|
759 | - // and save it as a permanent session setting |
|
760 | - $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
761 | - } |
|
762 | - return $this->_sid_salt; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * _set_init_access_and_expiration |
|
768 | - * |
|
769 | - * @return void |
|
770 | - */ |
|
771 | - protected function _set_init_access_and_expiration() |
|
772 | - { |
|
773 | - $this->_time = time(); |
|
774 | - $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
775 | - // set initial site access time |
|
776 | - $this->_session_data['init_access'] = $this->_time; |
|
777 | - // and the session expiration |
|
778 | - $this->_session_data['expiration'] = $this->_expiration; |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * @update session data prior to saving to the db |
|
784 | - * @access public |
|
785 | - * @param bool $new_session |
|
786 | - * @return TRUE on success, FALSE on fail |
|
787 | - * @throws EE_Error |
|
788 | - * @throws InvalidArgumentException |
|
789 | - * @throws InvalidDataTypeException |
|
790 | - * @throws InvalidInterfaceException |
|
791 | - */ |
|
792 | - public function update($new_session = false) |
|
793 | - { |
|
794 | - $this->_session_data = $this->_session_data !== null |
|
795 | - && is_array($this->_session_data) |
|
796 | - && isset($this->_session_data['id']) |
|
797 | - ? $this->_session_data |
|
798 | - : array(); |
|
799 | - if (empty($this->_session_data)) { |
|
800 | - $this->_set_defaults(); |
|
801 | - } |
|
802 | - $session_data = array(); |
|
803 | - foreach ($this->_session_data as $key => $value) { |
|
804 | - switch ($key) { |
|
805 | - case 'id': |
|
806 | - // session ID |
|
807 | - $session_data['id'] = $this->_sid; |
|
808 | - break; |
|
809 | - case 'ip_address': |
|
810 | - // visitor ip address |
|
811 | - $session_data['ip_address'] = $this->request->ipAddress(); |
|
812 | - break; |
|
813 | - case 'user_agent': |
|
814 | - // visitor user_agent |
|
815 | - $session_data['user_agent'] = $this->_user_agent; |
|
816 | - break; |
|
817 | - case 'init_access': |
|
818 | - $session_data['init_access'] = absint($value); |
|
819 | - break; |
|
820 | - case 'last_access': |
|
821 | - // current access time |
|
822 | - $session_data['last_access'] = $this->_time; |
|
823 | - break; |
|
824 | - case 'expiration': |
|
825 | - // when the session expires |
|
826 | - $session_data['expiration'] = ! empty($this->_expiration) |
|
827 | - ? $this->_expiration |
|
828 | - : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
829 | - break; |
|
830 | - case 'user_id': |
|
831 | - // current user if logged in |
|
832 | - $session_data['user_id'] = $this->_wp_user_id(); |
|
833 | - break; |
|
834 | - case 'pages_visited': |
|
835 | - $page_visit = $this->_get_page_visit(); |
|
836 | - if ($page_visit) { |
|
837 | - // set pages visited where the first will be the http referrer |
|
838 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
839 | - // we'll only save the last 10 page visits. |
|
840 | - $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
841 | - } |
|
842 | - break; |
|
843 | - default: |
|
844 | - // carry any other data over |
|
845 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
846 | - } |
|
847 | - } |
|
848 | - $this->_session_data = $session_data; |
|
849 | - // creating a new session does not require saving to the db just yet |
|
850 | - if (! $new_session) { |
|
851 | - // ready? let's save |
|
852 | - if ($this->_save_session_to_db()) { |
|
853 | - return true; |
|
854 | - } |
|
855 | - return false; |
|
856 | - } |
|
857 | - // meh, why not? |
|
858 | - return true; |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * @create session data array |
|
864 | - * @access public |
|
865 | - * @return bool |
|
866 | - * @throws EE_Error |
|
867 | - * @throws InvalidArgumentException |
|
868 | - * @throws InvalidDataTypeException |
|
869 | - * @throws InvalidInterfaceException |
|
870 | - */ |
|
871 | - private function _create_espresso_session() |
|
872 | - { |
|
873 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
874 | - // use the update function for now with $new_session arg set to TRUE |
|
875 | - return $this->update(true) ? true : false; |
|
876 | - } |
|
877 | - |
|
878 | - /** |
|
879 | - * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good |
|
880 | - * too). This is used when determining if we want to save the session or not. |
|
881 | - * @since 4.9.67.p |
|
882 | - * @return bool |
|
883 | - */ |
|
884 | - private function sessionHasStuffWorthSaving() |
|
885 | - { |
|
886 | - return $this->cart() instanceof EE_Cart |
|
887 | - || ( |
|
888 | - isset($this->_session_data['ee_notices']) |
|
889 | - && ( |
|
890 | - ! empty($this->_session_data['ee_notices']['attention']) |
|
891 | - || !empty($this->_session_data['ee_notices']['errors']) |
|
892 | - || !empty($this->_session_data['ee_notices']['success']) |
|
893 | - ) |
|
894 | - ); |
|
895 | - } |
|
896 | - /** |
|
897 | - * _save_session_to_db |
|
898 | - * |
|
899 | - * @param bool $clear_session |
|
900 | - * @return string |
|
901 | - * @throws EE_Error |
|
902 | - * @throws InvalidArgumentException |
|
903 | - * @throws InvalidDataTypeException |
|
904 | - * @throws InvalidInterfaceException |
|
905 | - */ |
|
906 | - private function _save_session_to_db($clear_session = false) |
|
907 | - { |
|
908 | - // don't save sessions for crawlers |
|
909 | - // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
910 | - if ($this->request->isBot() |
|
911 | - || ( |
|
912 | - ! $clear_session |
|
913 | - && ! $this->sessionHasStuffWorthSaving() |
|
914 | - && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true) |
|
915 | - ) |
|
916 | - ) { |
|
917 | - return false; |
|
918 | - } |
|
919 | - $transaction = $this->transaction(); |
|
920 | - if ($transaction instanceof EE_Transaction) { |
|
921 | - if (! $transaction->ID()) { |
|
922 | - $transaction->save(); |
|
923 | - } |
|
924 | - $this->_session_data['transaction'] = $transaction->ID(); |
|
925 | - } |
|
926 | - // then serialize all of our session data |
|
927 | - $session_data = serialize($this->_session_data); |
|
928 | - // do we need to also encode it to avoid corrupted data when saved to the db? |
|
929 | - $session_data = $this->_use_encryption |
|
930 | - ? $this->encryption->base64_string_encode($session_data) |
|
931 | - : $session_data; |
|
932 | - // maybe save hash check |
|
933 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
934 | - $this->cache_storage->add( |
|
935 | - EE_Session::hash_check_prefix . $this->_sid, |
|
936 | - md5($session_data), |
|
937 | - $this->session_lifespan->inSeconds() |
|
938 | - ); |
|
939 | - } |
|
940 | - // we're using the Transient API for storing session data, |
|
941 | - return $this->cache_storage->add( |
|
942 | - EE_Session::session_id_prefix . $this->_sid, |
|
943 | - $session_data, |
|
944 | - $this->session_lifespan->inSeconds() |
|
945 | - ); |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * @get the full page request the visitor is accessing |
|
951 | - * @access public |
|
952 | - * @return string |
|
953 | - */ |
|
954 | - public function _get_page_visit() |
|
955 | - { |
|
956 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
957 | - // check for request url |
|
958 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
959 | - $http_host = ''; |
|
960 | - $page_id = '?'; |
|
961 | - $e_reg = ''; |
|
962 | - $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
963 | - $ru_bits = explode('?', $request_uri); |
|
964 | - $request_uri = $ru_bits[0]; |
|
965 | - // check for and grab host as well |
|
966 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
967 | - $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
968 | - } |
|
969 | - // check for page_id in SERVER REQUEST |
|
970 | - if (isset($_REQUEST['page_id'])) { |
|
971 | - // rebuild $e_reg without any of the extra parameters |
|
972 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
973 | - } |
|
974 | - // check for $e_reg in SERVER REQUEST |
|
975 | - if (isset($_REQUEST['ee'])) { |
|
976 | - // rebuild $e_reg without any of the extra parameters |
|
977 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
978 | - } |
|
979 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
980 | - } |
|
981 | - return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @the current wp user id |
|
987 | - * @access public |
|
988 | - * @return int |
|
989 | - */ |
|
990 | - public function _wp_user_id() |
|
991 | - { |
|
992 | - // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
993 | - $this->_wp_user_id = get_current_user_id(); |
|
994 | - return $this->_wp_user_id; |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * Clear EE_Session data |
|
1000 | - * |
|
1001 | - * @access public |
|
1002 | - * @param string $class |
|
1003 | - * @param string $function |
|
1004 | - * @return void |
|
1005 | - * @throws EE_Error |
|
1006 | - * @throws InvalidArgumentException |
|
1007 | - * @throws InvalidDataTypeException |
|
1008 | - * @throws InvalidInterfaceException |
|
1009 | - */ |
|
1010 | - public function clear_session($class = '', $function = '') |
|
1011 | - { |
|
26 | + const session_id_prefix = 'ee_ssn_'; |
|
27 | + |
|
28 | + const hash_check_prefix = 'ee_shc_'; |
|
29 | + |
|
30 | + const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
31 | + |
|
32 | + const STATUS_CLOSED = 0; |
|
33 | + |
|
34 | + const STATUS_OPEN = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * instance of the EE_Session object |
|
38 | + * |
|
39 | + * @var EE_Session |
|
40 | + */ |
|
41 | + private static $_instance; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var CacheStorageInterface $cache_storage |
|
45 | + */ |
|
46 | + protected $cache_storage; |
|
47 | + |
|
48 | + /** |
|
49 | + * EE_Encryption object |
|
50 | + * |
|
51 | + * @var EE_Encryption |
|
52 | + */ |
|
53 | + protected $encryption; |
|
54 | + |
|
55 | + /** |
|
56 | + * the session id |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + private $_sid; |
|
61 | + |
|
62 | + /** |
|
63 | + * session id salt |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + private $_sid_salt; |
|
68 | + |
|
69 | + /** |
|
70 | + * session data |
|
71 | + * |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + private $_session_data = array(); |
|
75 | + |
|
76 | + /** |
|
77 | + * how long an EE session lasts |
|
78 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
79 | + * |
|
80 | + * @var SessionLifespan $session_lifespan |
|
81 | + */ |
|
82 | + private $session_lifespan; |
|
83 | + |
|
84 | + /** |
|
85 | + * session expiration time as Unix timestamp in GMT |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + private $_expiration; |
|
90 | + |
|
91 | + /** |
|
92 | + * whether or not session has expired at some point |
|
93 | + * |
|
94 | + * @var boolean |
|
95 | + */ |
|
96 | + private $_expired = false; |
|
97 | + |
|
98 | + /** |
|
99 | + * current time as Unix timestamp in GMT |
|
100 | + * |
|
101 | + * @var int |
|
102 | + */ |
|
103 | + private $_time; |
|
104 | + |
|
105 | + /** |
|
106 | + * whether to encrypt session data |
|
107 | + * |
|
108 | + * @var bool |
|
109 | + */ |
|
110 | + private $_use_encryption; |
|
111 | + |
|
112 | + /** |
|
113 | + * well... according to the server... |
|
114 | + * |
|
115 | + * @var null |
|
116 | + */ |
|
117 | + private $_user_agent; |
|
118 | + |
|
119 | + /** |
|
120 | + * do you really trust the server ? |
|
121 | + * |
|
122 | + * @var null |
|
123 | + */ |
|
124 | + private $_ip_address; |
|
125 | + |
|
126 | + /** |
|
127 | + * current WP user_id |
|
128 | + * |
|
129 | + * @var null |
|
130 | + */ |
|
131 | + private $_wp_user_id; |
|
132 | + |
|
133 | + /** |
|
134 | + * array for defining default session vars |
|
135 | + * |
|
136 | + * @var array |
|
137 | + */ |
|
138 | + private $_default_session_vars = array( |
|
139 | + 'id' => null, |
|
140 | + 'user_id' => null, |
|
141 | + 'ip_address' => null, |
|
142 | + 'user_agent' => null, |
|
143 | + 'init_access' => null, |
|
144 | + 'last_access' => null, |
|
145 | + 'expiration' => null, |
|
146 | + 'pages_visited' => array(), |
|
147 | + ); |
|
148 | + |
|
149 | + /** |
|
150 | + * timestamp for when last garbage collection cycle was performed |
|
151 | + * |
|
152 | + * @var int $_last_gc |
|
153 | + */ |
|
154 | + private $_last_gc; |
|
155 | + |
|
156 | + /** |
|
157 | + * @var RequestInterface $request |
|
158 | + */ |
|
159 | + protected $request; |
|
160 | + |
|
161 | + /** |
|
162 | + * whether session is active or not |
|
163 | + * |
|
164 | + * @var int $status |
|
165 | + */ |
|
166 | + private $status = EE_Session::STATUS_CLOSED; |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @singleton method used to instantiate class object |
|
171 | + * @param CacheStorageInterface $cache_storage |
|
172 | + * @param SessionLifespan|null $lifespan |
|
173 | + * @param RequestInterface $request |
|
174 | + * @param EE_Encryption $encryption |
|
175 | + * @return EE_Session |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws InvalidDataTypeException |
|
178 | + * @throws InvalidInterfaceException |
|
179 | + */ |
|
180 | + public static function instance( |
|
181 | + CacheStorageInterface $cache_storage = null, |
|
182 | + SessionLifespan $lifespan = null, |
|
183 | + RequestInterface $request = null, |
|
184 | + EE_Encryption $encryption = null |
|
185 | + ) { |
|
186 | + // check if class object is instantiated |
|
187 | + // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
188 | + // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
189 | + if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
190 | + self::$_instance = new self( |
|
191 | + $cache_storage, |
|
192 | + $lifespan, |
|
193 | + $request, |
|
194 | + $encryption |
|
195 | + ); |
|
196 | + } |
|
197 | + return self::$_instance; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * protected constructor to prevent direct creation |
|
203 | + * |
|
204 | + * @param CacheStorageInterface $cache_storage |
|
205 | + * @param SessionLifespan $lifespan |
|
206 | + * @param RequestInterface $request |
|
207 | + * @param EE_Encryption $encryption |
|
208 | + * @throws InvalidArgumentException |
|
209 | + * @throws InvalidDataTypeException |
|
210 | + * @throws InvalidInterfaceException |
|
211 | + */ |
|
212 | + protected function __construct( |
|
213 | + CacheStorageInterface $cache_storage, |
|
214 | + SessionLifespan $lifespan, |
|
215 | + RequestInterface $request, |
|
216 | + EE_Encryption $encryption = null |
|
217 | + ) { |
|
218 | + // session loading is turned ON by default, |
|
219 | + // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
220 | + // (which currently fires on the init hook at priority 9), |
|
221 | + // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
222 | + if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
223 | + return; |
|
224 | + } |
|
225 | + $this->session_lifespan = $lifespan; |
|
226 | + $this->request = $request; |
|
227 | + if (! defined('ESPRESSO_SESSION')) { |
|
228 | + define('ESPRESSO_SESSION', true); |
|
229 | + } |
|
230 | + // retrieve session options from db |
|
231 | + $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
232 | + if (! empty($session_settings)) { |
|
233 | + // cycle though existing session options |
|
234 | + foreach ($session_settings as $var_name => $session_setting) { |
|
235 | + // set values for class properties |
|
236 | + $var_name = '_' . $var_name; |
|
237 | + $this->{$var_name} = $session_setting; |
|
238 | + } |
|
239 | + } |
|
240 | + $this->cache_storage = $cache_storage; |
|
241 | + // are we using encryption? |
|
242 | + $this->_use_encryption = $encryption instanceof EE_Encryption |
|
243 | + && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
244 | + // encrypt data via: $this->encryption->encrypt(); |
|
245 | + $this->encryption = $encryption; |
|
246 | + // filter hook allows outside functions/classes/plugins to change default empty cart |
|
247 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
248 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
249 | + // apply default session vars |
|
250 | + $this->_set_defaults(); |
|
251 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
252 | + // check request for 'clear_session' param |
|
253 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
254 | + // once everything is all said and done, |
|
255 | + add_action('shutdown', array($this, 'update'), 100); |
|
256 | + add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
257 | + $this->configure_garbage_collection_filters(); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @return bool |
|
263 | + * @throws InvalidArgumentException |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws InvalidInterfaceException |
|
266 | + */ |
|
267 | + public static function isLoadedAndActive() |
|
268 | + { |
|
269 | + return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
270 | + && EE_Session::instance() instanceof EE_Session |
|
271 | + && EE_Session::instance()->isActive(); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return bool |
|
277 | + */ |
|
278 | + public function isActive() |
|
279 | + { |
|
280 | + return $this->status === EE_Session::STATUS_OPEN; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @return void |
|
286 | + * @throws EE_Error |
|
287 | + * @throws InvalidArgumentException |
|
288 | + * @throws InvalidDataTypeException |
|
289 | + * @throws InvalidInterfaceException |
|
290 | + * @throws InvalidSessionDataException |
|
291 | + */ |
|
292 | + public function open_session() |
|
293 | + { |
|
294 | + // check for existing session and retrieve it from db |
|
295 | + if (! $this->_espresso_session()) { |
|
296 | + // or just start a new one |
|
297 | + $this->_create_espresso_session(); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + public function expired() |
|
306 | + { |
|
307 | + return $this->_expired; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @return void |
|
313 | + */ |
|
314 | + public function reset_expired() |
|
315 | + { |
|
316 | + $this->_expired = false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @return int |
|
322 | + */ |
|
323 | + public function expiration() |
|
324 | + { |
|
325 | + return $this->_expiration; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @return int |
|
331 | + */ |
|
332 | + public function extension() |
|
333 | + { |
|
334 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param int $time number of seconds to add to session expiration |
|
340 | + */ |
|
341 | + public function extend_expiration($time = 0) |
|
342 | + { |
|
343 | + $time = $time ? $time : $this->extension(); |
|
344 | + $this->_expiration += absint($time); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @return int |
|
350 | + */ |
|
351 | + public function lifespan() |
|
352 | + { |
|
353 | + return $this->session_lifespan->inSeconds(); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * This just sets some defaults for the _session data property |
|
359 | + * |
|
360 | + * @access private |
|
361 | + * @return void |
|
362 | + */ |
|
363 | + private function _set_defaults() |
|
364 | + { |
|
365 | + // set some defaults |
|
366 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
367 | + if (is_array($default_var)) { |
|
368 | + $this->_session_data[ $key ] = array(); |
|
369 | + } else { |
|
370 | + $this->_session_data[ $key ] = ''; |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @retrieve session data |
|
378 | + * @access public |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function id() |
|
382 | + { |
|
383 | + return $this->_sid; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param \EE_Cart $cart |
|
389 | + * @return bool |
|
390 | + */ |
|
391 | + public function set_cart(EE_Cart $cart) |
|
392 | + { |
|
393 | + $this->_session_data['cart'] = $cart; |
|
394 | + return true; |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * reset_cart |
|
400 | + */ |
|
401 | + public function reset_cart() |
|
402 | + { |
|
403 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
404 | + $this->_session_data['cart'] = null; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @return \EE_Cart |
|
410 | + */ |
|
411 | + public function cart() |
|
412 | + { |
|
413 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
414 | + ? $this->_session_data['cart'] |
|
415 | + : null; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @param \EE_Checkout $checkout |
|
421 | + * @return bool |
|
422 | + */ |
|
423 | + public function set_checkout(EE_Checkout $checkout) |
|
424 | + { |
|
425 | + $this->_session_data['checkout'] = $checkout; |
|
426 | + return true; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * reset_checkout |
|
432 | + */ |
|
433 | + public function reset_checkout() |
|
434 | + { |
|
435 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
436 | + $this->_session_data['checkout'] = null; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * @return \EE_Checkout |
|
442 | + */ |
|
443 | + public function checkout() |
|
444 | + { |
|
445 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
446 | + ? $this->_session_data['checkout'] |
|
447 | + : null; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param \EE_Transaction $transaction |
|
453 | + * @return bool |
|
454 | + * @throws EE_Error |
|
455 | + */ |
|
456 | + public function set_transaction(EE_Transaction $transaction) |
|
457 | + { |
|
458 | + // first remove the session from the transaction before we save the transaction in the session |
|
459 | + $transaction->set_txn_session_data(null); |
|
460 | + $this->_session_data['transaction'] = $transaction; |
|
461 | + return true; |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * reset_transaction |
|
467 | + */ |
|
468 | + public function reset_transaction() |
|
469 | + { |
|
470 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
471 | + $this->_session_data['transaction'] = null; |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * @return \EE_Transaction |
|
477 | + */ |
|
478 | + public function transaction() |
|
479 | + { |
|
480 | + return isset($this->_session_data['transaction']) |
|
481 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
482 | + ? $this->_session_data['transaction'] |
|
483 | + : null; |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * retrieve session data |
|
489 | + * |
|
490 | + * @param null $key |
|
491 | + * @param bool $reset_cache |
|
492 | + * @return array |
|
493 | + */ |
|
494 | + public function get_session_data($key = null, $reset_cache = false) |
|
495 | + { |
|
496 | + if ($reset_cache) { |
|
497 | + $this->reset_cart(); |
|
498 | + $this->reset_checkout(); |
|
499 | + $this->reset_transaction(); |
|
500 | + } |
|
501 | + if (! empty($key)) { |
|
502 | + return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
503 | + } |
|
504 | + return $this->_session_data; |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * Returns TRUE on success, FALSE on fail |
|
510 | + * |
|
511 | + * @param array $data |
|
512 | + * @return bool |
|
513 | + */ |
|
514 | + public function set_session_data($data) |
|
515 | + { |
|
516 | + // nothing ??? bad data ??? go home! |
|
517 | + if (empty($data) || ! is_array($data)) { |
|
518 | + EE_Error::add_error( |
|
519 | + esc_html__( |
|
520 | + 'No session data or invalid session data was provided.', |
|
521 | + 'event_espresso' |
|
522 | + ), |
|
523 | + __FILE__, |
|
524 | + __FUNCTION__, |
|
525 | + __LINE__ |
|
526 | + ); |
|
527 | + return false; |
|
528 | + } |
|
529 | + foreach ($data as $key => $value) { |
|
530 | + if (isset($this->_default_session_vars[ $key ])) { |
|
531 | + EE_Error::add_error( |
|
532 | + sprintf( |
|
533 | + esc_html__( |
|
534 | + 'Sorry! %s is a default session datum and can not be reset.', |
|
535 | + 'event_espresso' |
|
536 | + ), |
|
537 | + $key |
|
538 | + ), |
|
539 | + __FILE__, |
|
540 | + __FUNCTION__, |
|
541 | + __LINE__ |
|
542 | + ); |
|
543 | + return false; |
|
544 | + } |
|
545 | + $this->_session_data[ $key ] = $value; |
|
546 | + } |
|
547 | + return true; |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * @initiate session |
|
553 | + * @access private |
|
554 | + * @return TRUE on success, FALSE on fail |
|
555 | + * @throws EE_Error |
|
556 | + * @throws InvalidArgumentException |
|
557 | + * @throws InvalidDataTypeException |
|
558 | + * @throws InvalidInterfaceException |
|
559 | + * @throws InvalidSessionDataException |
|
560 | + */ |
|
561 | + private function _espresso_session() |
|
562 | + { |
|
563 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
564 | + // check that session has started |
|
565 | + if (session_id() === '') { |
|
566 | + // starts a new session if one doesn't already exist, or re-initiates an existing one |
|
567 | + session_start(); |
|
568 | + } |
|
569 | + $this->status = EE_Session::STATUS_OPEN; |
|
570 | + // get our modified session ID |
|
571 | + $this->_sid = $this->_generate_session_id(); |
|
572 | + // and the visitors IP |
|
573 | + $this->_ip_address = $this->request->ipAddress(); |
|
574 | + // set the "user agent" |
|
575 | + $this->_user_agent = $this->request->userAgent(); |
|
576 | + // now let's retrieve what's in the db |
|
577 | + $session_data = $this->_retrieve_session_data(); |
|
578 | + if (! empty($session_data)) { |
|
579 | + // get the current time in UTC |
|
580 | + $this->_time = $this->_time !== null ? $this->_time : time(); |
|
581 | + // and reset the session expiration |
|
582 | + $this->_expiration = isset($session_data['expiration']) |
|
583 | + ? $session_data['expiration'] |
|
584 | + : $this->_time + $this->session_lifespan->inSeconds(); |
|
585 | + } else { |
|
586 | + // set initial site access time and the session expiration |
|
587 | + $this->_set_init_access_and_expiration(); |
|
588 | + // set referer |
|
589 | + $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
590 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
591 | + : ''; |
|
592 | + // no previous session = go back and create one (on top of the data above) |
|
593 | + return false; |
|
594 | + } |
|
595 | + // now the user agent |
|
596 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
597 | + return false; |
|
598 | + } |
|
599 | + // wait a minute... how old are you? |
|
600 | + if ($this->_time > $this->_expiration) { |
|
601 | + // yer too old fer me! |
|
602 | + $this->_expired = true; |
|
603 | + // wipe out everything that isn't a default session datum |
|
604 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
605 | + } |
|
606 | + // make event espresso session data available to plugin |
|
607 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
608 | + return true; |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * _get_session_data |
|
614 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
615 | + * databases |
|
616 | + * |
|
617 | + * @return array |
|
618 | + * @throws EE_Error |
|
619 | + * @throws InvalidArgumentException |
|
620 | + * @throws InvalidSessionDataException |
|
621 | + * @throws InvalidDataTypeException |
|
622 | + * @throws InvalidInterfaceException |
|
623 | + */ |
|
624 | + protected function _retrieve_session_data() |
|
625 | + { |
|
626 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
627 | + try { |
|
628 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
629 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
630 | + if (empty($session_data)) { |
|
631 | + return array(); |
|
632 | + } |
|
633 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
634 | + $hash_check = $this->cache_storage->get( |
|
635 | + EE_Session::hash_check_prefix . $this->_sid, |
|
636 | + false |
|
637 | + ); |
|
638 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
639 | + EE_Error::add_error( |
|
640 | + sprintf( |
|
641 | + __( |
|
642 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
643 | + 'event_espresso' |
|
644 | + ), |
|
645 | + EE_Session::session_id_prefix . $this->_sid |
|
646 | + ), |
|
647 | + __FILE__, |
|
648 | + __FUNCTION__, |
|
649 | + __LINE__ |
|
650 | + ); |
|
651 | + } |
|
652 | + } |
|
653 | + } catch (Exception $e) { |
|
654 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
655 | + global $wpdb; |
|
656 | + $row = $wpdb->get_row( |
|
657 | + $wpdb->prepare( |
|
658 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
659 | + '_transient_' . $ssn_key |
|
660 | + ) |
|
661 | + ); |
|
662 | + $session_data = is_object($row) ? $row->option_value : null; |
|
663 | + if ($session_data) { |
|
664 | + $session_data = preg_replace_callback( |
|
665 | + '!s:(d+):"(.*?)";!', |
|
666 | + function ($match) { |
|
667 | + return $match[1] === strlen($match[2]) |
|
668 | + ? $match[0] |
|
669 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
670 | + }, |
|
671 | + $session_data |
|
672 | + ); |
|
673 | + } |
|
674 | + $session_data = maybe_unserialize($session_data); |
|
675 | + } |
|
676 | + // in case the data is encoded... try to decode it |
|
677 | + $session_data = $this->encryption instanceof EE_Encryption |
|
678 | + ? $this->encryption->base64_string_decode($session_data) |
|
679 | + : $session_data; |
|
680 | + if (! is_array($session_data)) { |
|
681 | + try { |
|
682 | + $session_data = maybe_unserialize($session_data); |
|
683 | + } catch (Exception $e) { |
|
684 | + $msg = esc_html__( |
|
685 | + 'An error occurred while attempting to unserialize the session data.', |
|
686 | + 'event_espresso' |
|
687 | + ); |
|
688 | + $msg .= WP_DEBUG |
|
689 | + ? '<br><pre>' |
|
690 | + . print_r($session_data, true) |
|
691 | + . '</pre><br>' |
|
692 | + . $this->find_serialize_error($session_data) |
|
693 | + : ''; |
|
694 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
695 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
696 | + } |
|
697 | + } |
|
698 | + // just a check to make sure the session array is indeed an array |
|
699 | + if (! is_array($session_data)) { |
|
700 | + // no?!?! then something is wrong |
|
701 | + $msg = esc_html__( |
|
702 | + 'The session data is missing, invalid, or corrupted.', |
|
703 | + 'event_espresso' |
|
704 | + ); |
|
705 | + $msg .= WP_DEBUG |
|
706 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
707 | + : ''; |
|
708 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
709 | + throw new InvalidSessionDataException($msg); |
|
710 | + } |
|
711 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
712 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
713 | + $session_data['transaction'] |
|
714 | + ); |
|
715 | + } |
|
716 | + return $session_data; |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * _generate_session_id |
|
722 | + * Retrieves the PHP session id either directly from the PHP session, |
|
723 | + * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
724 | + * The session id is then salted and hashed (mmm sounds tasty) |
|
725 | + * so that it can be safely used as a $_REQUEST param |
|
726 | + * |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + protected function _generate_session_id() |
|
730 | + { |
|
731 | + // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
732 | + if (isset($_REQUEST['EESID'])) { |
|
733 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
734 | + } else { |
|
735 | + $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
736 | + } |
|
737 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
738 | + } |
|
739 | + |
|
740 | + |
|
741 | + /** |
|
742 | + * _get_sid_salt |
|
743 | + * |
|
744 | + * @return string |
|
745 | + */ |
|
746 | + protected function _get_sid_salt() |
|
747 | + { |
|
748 | + // was session id salt already saved to db ? |
|
749 | + if (empty($this->_sid_salt)) { |
|
750 | + // no? then maybe use WP defined constant |
|
751 | + if (defined('AUTH_SALT')) { |
|
752 | + $this->_sid_salt = AUTH_SALT; |
|
753 | + } |
|
754 | + // if salt doesn't exist or is too short |
|
755 | + if (strlen($this->_sid_salt) < 32) { |
|
756 | + // create a new one |
|
757 | + $this->_sid_salt = wp_generate_password(64); |
|
758 | + } |
|
759 | + // and save it as a permanent session setting |
|
760 | + $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
761 | + } |
|
762 | + return $this->_sid_salt; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * _set_init_access_and_expiration |
|
768 | + * |
|
769 | + * @return void |
|
770 | + */ |
|
771 | + protected function _set_init_access_and_expiration() |
|
772 | + { |
|
773 | + $this->_time = time(); |
|
774 | + $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
775 | + // set initial site access time |
|
776 | + $this->_session_data['init_access'] = $this->_time; |
|
777 | + // and the session expiration |
|
778 | + $this->_session_data['expiration'] = $this->_expiration; |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * @update session data prior to saving to the db |
|
784 | + * @access public |
|
785 | + * @param bool $new_session |
|
786 | + * @return TRUE on success, FALSE on fail |
|
787 | + * @throws EE_Error |
|
788 | + * @throws InvalidArgumentException |
|
789 | + * @throws InvalidDataTypeException |
|
790 | + * @throws InvalidInterfaceException |
|
791 | + */ |
|
792 | + public function update($new_session = false) |
|
793 | + { |
|
794 | + $this->_session_data = $this->_session_data !== null |
|
795 | + && is_array($this->_session_data) |
|
796 | + && isset($this->_session_data['id']) |
|
797 | + ? $this->_session_data |
|
798 | + : array(); |
|
799 | + if (empty($this->_session_data)) { |
|
800 | + $this->_set_defaults(); |
|
801 | + } |
|
802 | + $session_data = array(); |
|
803 | + foreach ($this->_session_data as $key => $value) { |
|
804 | + switch ($key) { |
|
805 | + case 'id': |
|
806 | + // session ID |
|
807 | + $session_data['id'] = $this->_sid; |
|
808 | + break; |
|
809 | + case 'ip_address': |
|
810 | + // visitor ip address |
|
811 | + $session_data['ip_address'] = $this->request->ipAddress(); |
|
812 | + break; |
|
813 | + case 'user_agent': |
|
814 | + // visitor user_agent |
|
815 | + $session_data['user_agent'] = $this->_user_agent; |
|
816 | + break; |
|
817 | + case 'init_access': |
|
818 | + $session_data['init_access'] = absint($value); |
|
819 | + break; |
|
820 | + case 'last_access': |
|
821 | + // current access time |
|
822 | + $session_data['last_access'] = $this->_time; |
|
823 | + break; |
|
824 | + case 'expiration': |
|
825 | + // when the session expires |
|
826 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
827 | + ? $this->_expiration |
|
828 | + : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
829 | + break; |
|
830 | + case 'user_id': |
|
831 | + // current user if logged in |
|
832 | + $session_data['user_id'] = $this->_wp_user_id(); |
|
833 | + break; |
|
834 | + case 'pages_visited': |
|
835 | + $page_visit = $this->_get_page_visit(); |
|
836 | + if ($page_visit) { |
|
837 | + // set pages visited where the first will be the http referrer |
|
838 | + $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
839 | + // we'll only save the last 10 page visits. |
|
840 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
841 | + } |
|
842 | + break; |
|
843 | + default: |
|
844 | + // carry any other data over |
|
845 | + $session_data[ $key ] = $this->_session_data[ $key ]; |
|
846 | + } |
|
847 | + } |
|
848 | + $this->_session_data = $session_data; |
|
849 | + // creating a new session does not require saving to the db just yet |
|
850 | + if (! $new_session) { |
|
851 | + // ready? let's save |
|
852 | + if ($this->_save_session_to_db()) { |
|
853 | + return true; |
|
854 | + } |
|
855 | + return false; |
|
856 | + } |
|
857 | + // meh, why not? |
|
858 | + return true; |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * @create session data array |
|
864 | + * @access public |
|
865 | + * @return bool |
|
866 | + * @throws EE_Error |
|
867 | + * @throws InvalidArgumentException |
|
868 | + * @throws InvalidDataTypeException |
|
869 | + * @throws InvalidInterfaceException |
|
870 | + */ |
|
871 | + private function _create_espresso_session() |
|
872 | + { |
|
873 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
874 | + // use the update function for now with $new_session arg set to TRUE |
|
875 | + return $this->update(true) ? true : false; |
|
876 | + } |
|
877 | + |
|
878 | + /** |
|
879 | + * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good |
|
880 | + * too). This is used when determining if we want to save the session or not. |
|
881 | + * @since 4.9.67.p |
|
882 | + * @return bool |
|
883 | + */ |
|
884 | + private function sessionHasStuffWorthSaving() |
|
885 | + { |
|
886 | + return $this->cart() instanceof EE_Cart |
|
887 | + || ( |
|
888 | + isset($this->_session_data['ee_notices']) |
|
889 | + && ( |
|
890 | + ! empty($this->_session_data['ee_notices']['attention']) |
|
891 | + || !empty($this->_session_data['ee_notices']['errors']) |
|
892 | + || !empty($this->_session_data['ee_notices']['success']) |
|
893 | + ) |
|
894 | + ); |
|
895 | + } |
|
896 | + /** |
|
897 | + * _save_session_to_db |
|
898 | + * |
|
899 | + * @param bool $clear_session |
|
900 | + * @return string |
|
901 | + * @throws EE_Error |
|
902 | + * @throws InvalidArgumentException |
|
903 | + * @throws InvalidDataTypeException |
|
904 | + * @throws InvalidInterfaceException |
|
905 | + */ |
|
906 | + private function _save_session_to_db($clear_session = false) |
|
907 | + { |
|
908 | + // don't save sessions for crawlers |
|
909 | + // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
910 | + if ($this->request->isBot() |
|
911 | + || ( |
|
912 | + ! $clear_session |
|
913 | + && ! $this->sessionHasStuffWorthSaving() |
|
914 | + && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true) |
|
915 | + ) |
|
916 | + ) { |
|
917 | + return false; |
|
918 | + } |
|
919 | + $transaction = $this->transaction(); |
|
920 | + if ($transaction instanceof EE_Transaction) { |
|
921 | + if (! $transaction->ID()) { |
|
922 | + $transaction->save(); |
|
923 | + } |
|
924 | + $this->_session_data['transaction'] = $transaction->ID(); |
|
925 | + } |
|
926 | + // then serialize all of our session data |
|
927 | + $session_data = serialize($this->_session_data); |
|
928 | + // do we need to also encode it to avoid corrupted data when saved to the db? |
|
929 | + $session_data = $this->_use_encryption |
|
930 | + ? $this->encryption->base64_string_encode($session_data) |
|
931 | + : $session_data; |
|
932 | + // maybe save hash check |
|
933 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
934 | + $this->cache_storage->add( |
|
935 | + EE_Session::hash_check_prefix . $this->_sid, |
|
936 | + md5($session_data), |
|
937 | + $this->session_lifespan->inSeconds() |
|
938 | + ); |
|
939 | + } |
|
940 | + // we're using the Transient API for storing session data, |
|
941 | + return $this->cache_storage->add( |
|
942 | + EE_Session::session_id_prefix . $this->_sid, |
|
943 | + $session_data, |
|
944 | + $this->session_lifespan->inSeconds() |
|
945 | + ); |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * @get the full page request the visitor is accessing |
|
951 | + * @access public |
|
952 | + * @return string |
|
953 | + */ |
|
954 | + public function _get_page_visit() |
|
955 | + { |
|
956 | + $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
957 | + // check for request url |
|
958 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
959 | + $http_host = ''; |
|
960 | + $page_id = '?'; |
|
961 | + $e_reg = ''; |
|
962 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
963 | + $ru_bits = explode('?', $request_uri); |
|
964 | + $request_uri = $ru_bits[0]; |
|
965 | + // check for and grab host as well |
|
966 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
967 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
968 | + } |
|
969 | + // check for page_id in SERVER REQUEST |
|
970 | + if (isset($_REQUEST['page_id'])) { |
|
971 | + // rebuild $e_reg without any of the extra parameters |
|
972 | + $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
973 | + } |
|
974 | + // check for $e_reg in SERVER REQUEST |
|
975 | + if (isset($_REQUEST['ee'])) { |
|
976 | + // rebuild $e_reg without any of the extra parameters |
|
977 | + $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
978 | + } |
|
979 | + $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
980 | + } |
|
981 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @the current wp user id |
|
987 | + * @access public |
|
988 | + * @return int |
|
989 | + */ |
|
990 | + public function _wp_user_id() |
|
991 | + { |
|
992 | + // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
993 | + $this->_wp_user_id = get_current_user_id(); |
|
994 | + return $this->_wp_user_id; |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * Clear EE_Session data |
|
1000 | + * |
|
1001 | + * @access public |
|
1002 | + * @param string $class |
|
1003 | + * @param string $function |
|
1004 | + * @return void |
|
1005 | + * @throws EE_Error |
|
1006 | + * @throws InvalidArgumentException |
|
1007 | + * @throws InvalidDataTypeException |
|
1008 | + * @throws InvalidInterfaceException |
|
1009 | + */ |
|
1010 | + public function clear_session($class = '', $function = '') |
|
1011 | + { |
|
1012 | 1012 | // echo ' |
1013 | 1013 | // <h3 style="color:#999;line-height:.9em;"> |
1014 | 1014 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
1015 | 1015 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
1016 | 1016 | // </h3>'; |
1017 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1018 | - $this->reset_cart(); |
|
1019 | - $this->reset_checkout(); |
|
1020 | - $this->reset_transaction(); |
|
1021 | - // wipe out everything that isn't a default session datum |
|
1022 | - $this->reset_data(array_keys($this->_session_data)); |
|
1023 | - // reset initial site access time and the session expiration |
|
1024 | - $this->_set_init_access_and_expiration(); |
|
1025 | - $this->_save_session_to_db(true); |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
1031 | - * |
|
1032 | - * @param array|mixed $data_to_reset |
|
1033 | - * @param bool $show_all_notices |
|
1034 | - * @return bool |
|
1035 | - */ |
|
1036 | - public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
1037 | - { |
|
1038 | - // if $data_to_reset is not in an array, then put it in one |
|
1039 | - if (! is_array($data_to_reset)) { |
|
1040 | - $data_to_reset = array($data_to_reset); |
|
1041 | - } |
|
1042 | - // nothing ??? go home! |
|
1043 | - if (empty($data_to_reset)) { |
|
1044 | - EE_Error::add_error( |
|
1045 | - __( |
|
1046 | - 'No session data could be reset, because no session var name was provided.', |
|
1047 | - 'event_espresso' |
|
1048 | - ), |
|
1049 | - __FILE__, |
|
1050 | - __FUNCTION__, |
|
1051 | - __LINE__ |
|
1052 | - ); |
|
1053 | - return false; |
|
1054 | - } |
|
1055 | - $return_value = true; |
|
1056 | - // since $data_to_reset is an array, cycle through the values |
|
1057 | - foreach ($data_to_reset as $reset) { |
|
1058 | - // first check to make sure it is a valid session var |
|
1059 | - if (isset($this->_session_data[ $reset ])) { |
|
1060 | - // then check to make sure it is not a default var |
|
1061 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1062 | - // remove session var |
|
1063 | - unset($this->_session_data[ $reset ]); |
|
1064 | - if ($show_all_notices) { |
|
1065 | - EE_Error::add_success( |
|
1066 | - sprintf( |
|
1067 | - __('The session variable %s was removed.', 'event_espresso'), |
|
1068 | - $reset |
|
1069 | - ), |
|
1070 | - __FILE__, |
|
1071 | - __FUNCTION__, |
|
1072 | - __LINE__ |
|
1073 | - ); |
|
1074 | - } |
|
1075 | - } else { |
|
1076 | - // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
1077 | - if ($show_all_notices) { |
|
1078 | - EE_Error::add_error( |
|
1079 | - sprintf( |
|
1080 | - __( |
|
1081 | - 'Sorry! %s is a default session datum and can not be reset.', |
|
1082 | - 'event_espresso' |
|
1083 | - ), |
|
1084 | - $reset |
|
1085 | - ), |
|
1086 | - __FILE__, |
|
1087 | - __FUNCTION__, |
|
1088 | - __LINE__ |
|
1089 | - ); |
|
1090 | - } |
|
1091 | - $return_value = false; |
|
1092 | - } |
|
1093 | - } elseif ($show_all_notices) { |
|
1094 | - // oops! that session var does not exist! |
|
1095 | - EE_Error::add_error( |
|
1096 | - sprintf( |
|
1097 | - __( |
|
1098 | - 'The session item provided, %s, is invalid or does not exist.', |
|
1099 | - 'event_espresso' |
|
1100 | - ), |
|
1101 | - $reset |
|
1102 | - ), |
|
1103 | - __FILE__, |
|
1104 | - __FUNCTION__, |
|
1105 | - __LINE__ |
|
1106 | - ); |
|
1107 | - $return_value = false; |
|
1108 | - } |
|
1109 | - } // end of foreach |
|
1110 | - return $return_value; |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * wp_loaded |
|
1116 | - * |
|
1117 | - * @access public |
|
1118 | - * @throws EE_Error |
|
1119 | - * @throws InvalidDataTypeException |
|
1120 | - * @throws InvalidInterfaceException |
|
1121 | - * @throws InvalidArgumentException |
|
1122 | - */ |
|
1123 | - public function wp_loaded() |
|
1124 | - { |
|
1125 | - if ($this->request->requestParamIsSet('clear_session')) { |
|
1126 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
1127 | - } |
|
1128 | - } |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * Used to reset the entire object (for tests). |
|
1133 | - * |
|
1134 | - * @since 4.3.0 |
|
1135 | - * @throws EE_Error |
|
1136 | - * @throws InvalidDataTypeException |
|
1137 | - * @throws InvalidInterfaceException |
|
1138 | - * @throws InvalidArgumentException |
|
1139 | - */ |
|
1140 | - public function reset_instance() |
|
1141 | - { |
|
1142 | - $this->clear_session(); |
|
1143 | - self::$_instance = null; |
|
1144 | - } |
|
1145 | - |
|
1146 | - |
|
1147 | - public function configure_garbage_collection_filters() |
|
1148 | - { |
|
1149 | - // run old filter we had for controlling session cleanup |
|
1150 | - $expired_session_transient_delete_query_limit = absint( |
|
1151 | - apply_filters( |
|
1152 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1153 | - 50 |
|
1154 | - ) |
|
1155 | - ); |
|
1156 | - // is there a value? or one that is different than the default 50 records? |
|
1157 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
1158 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1159 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1160 | - } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
1161 | - // or use that for the new transient cleanup query limit |
|
1162 | - add_filter( |
|
1163 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1164 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1165 | - return $expired_session_transient_delete_query_limit; |
|
1166 | - } |
|
1167 | - ); |
|
1168 | - } |
|
1169 | - } |
|
1170 | - |
|
1171 | - |
|
1172 | - /** |
|
1173 | - * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
1174 | - * @param $data1 |
|
1175 | - * @return string |
|
1176 | - */ |
|
1177 | - private function find_serialize_error($data1) |
|
1178 | - { |
|
1179 | - $error = '<pre>'; |
|
1180 | - $data2 = preg_replace_callback( |
|
1181 | - '!s:(\d+):"(.*?)";!', |
|
1182 | - function ($match) { |
|
1183 | - return ($match[1] === strlen($match[2])) |
|
1184 | - ? $match[0] |
|
1185 | - : 's:' |
|
1186 | - . strlen($match[2]) |
|
1187 | - . ':"' |
|
1188 | - . $match[2] |
|
1189 | - . '";'; |
|
1190 | - }, |
|
1191 | - $data1 |
|
1192 | - ); |
|
1193 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1194 | - $error .= $data1 . PHP_EOL; |
|
1195 | - $error .= $data2 . PHP_EOL; |
|
1196 | - for ($i = 0; $i < $max; $i++) { |
|
1197 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1198 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1199 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1200 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1201 | - $start = ($i - 20); |
|
1202 | - $start = ($start < 0) ? 0 : $start; |
|
1203 | - $length = 40; |
|
1204 | - $point = $max - $i; |
|
1205 | - if ($point < 20) { |
|
1206 | - $rlength = 1; |
|
1207 | - $rpoint = -$point; |
|
1208 | - } else { |
|
1209 | - $rpoint = $length - 20; |
|
1210 | - $rlength = 1; |
|
1211 | - } |
|
1212 | - $error .= "\t-> Section Data1 = "; |
|
1213 | - $error .= substr_replace( |
|
1214 | - substr($data1, $start, $length), |
|
1215 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1216 | - $rpoint, |
|
1217 | - $rlength |
|
1218 | - ); |
|
1219 | - $error .= PHP_EOL; |
|
1220 | - $error .= "\t-> Section Data2 = "; |
|
1221 | - $error .= substr_replace( |
|
1222 | - substr($data2, $start, $length), |
|
1223 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1224 | - $rpoint, |
|
1225 | - $rlength |
|
1226 | - ); |
|
1227 | - $error .= PHP_EOL; |
|
1228 | - } |
|
1229 | - } |
|
1230 | - $error .= '</pre>'; |
|
1231 | - return $error; |
|
1232 | - } |
|
1233 | - |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * Saves an array of settings used for configuring aspects of session behaviour |
|
1237 | - * |
|
1238 | - * @param array $updated_settings |
|
1239 | - */ |
|
1240 | - private function updateSessionSettings(array $updated_settings = array()) |
|
1241 | - { |
|
1242 | - // add existing settings, but only if not included in incoming $updated_settings array |
|
1243 | - $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
1244 | - update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
1245 | - } |
|
1246 | - |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * garbage_collection |
|
1250 | - */ |
|
1251 | - public function garbageCollection() |
|
1252 | - { |
|
1253 | - // only perform during regular requests if last garbage collection was over an hour ago |
|
1254 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1255 | - $this->_last_gc = time(); |
|
1256 | - $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
1257 | - /** @type WPDB $wpdb */ |
|
1258 | - global $wpdb; |
|
1259 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
1260 | - $expired_session_transient_delete_query_limit = absint( |
|
1261 | - apply_filters( |
|
1262 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1263 | - 50 |
|
1264 | - ) |
|
1265 | - ); |
|
1266 | - // non-zero LIMIT means take out the trash |
|
1267 | - if ($expired_session_transient_delete_query_limit) { |
|
1268 | - $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
1269 | - $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
1270 | - // since transient expiration timestamps are set in the future, we can compare against NOW |
|
1271 | - // but we only want to pick up any trash that's been around for more than a day |
|
1272 | - $expiration = time() - DAY_IN_SECONDS; |
|
1273 | - $SQL = " |
|
1017 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1018 | + $this->reset_cart(); |
|
1019 | + $this->reset_checkout(); |
|
1020 | + $this->reset_transaction(); |
|
1021 | + // wipe out everything that isn't a default session datum |
|
1022 | + $this->reset_data(array_keys($this->_session_data)); |
|
1023 | + // reset initial site access time and the session expiration |
|
1024 | + $this->_set_init_access_and_expiration(); |
|
1025 | + $this->_save_session_to_db(true); |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
1031 | + * |
|
1032 | + * @param array|mixed $data_to_reset |
|
1033 | + * @param bool $show_all_notices |
|
1034 | + * @return bool |
|
1035 | + */ |
|
1036 | + public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
1037 | + { |
|
1038 | + // if $data_to_reset is not in an array, then put it in one |
|
1039 | + if (! is_array($data_to_reset)) { |
|
1040 | + $data_to_reset = array($data_to_reset); |
|
1041 | + } |
|
1042 | + // nothing ??? go home! |
|
1043 | + if (empty($data_to_reset)) { |
|
1044 | + EE_Error::add_error( |
|
1045 | + __( |
|
1046 | + 'No session data could be reset, because no session var name was provided.', |
|
1047 | + 'event_espresso' |
|
1048 | + ), |
|
1049 | + __FILE__, |
|
1050 | + __FUNCTION__, |
|
1051 | + __LINE__ |
|
1052 | + ); |
|
1053 | + return false; |
|
1054 | + } |
|
1055 | + $return_value = true; |
|
1056 | + // since $data_to_reset is an array, cycle through the values |
|
1057 | + foreach ($data_to_reset as $reset) { |
|
1058 | + // first check to make sure it is a valid session var |
|
1059 | + if (isset($this->_session_data[ $reset ])) { |
|
1060 | + // then check to make sure it is not a default var |
|
1061 | + if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1062 | + // remove session var |
|
1063 | + unset($this->_session_data[ $reset ]); |
|
1064 | + if ($show_all_notices) { |
|
1065 | + EE_Error::add_success( |
|
1066 | + sprintf( |
|
1067 | + __('The session variable %s was removed.', 'event_espresso'), |
|
1068 | + $reset |
|
1069 | + ), |
|
1070 | + __FILE__, |
|
1071 | + __FUNCTION__, |
|
1072 | + __LINE__ |
|
1073 | + ); |
|
1074 | + } |
|
1075 | + } else { |
|
1076 | + // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
1077 | + if ($show_all_notices) { |
|
1078 | + EE_Error::add_error( |
|
1079 | + sprintf( |
|
1080 | + __( |
|
1081 | + 'Sorry! %s is a default session datum and can not be reset.', |
|
1082 | + 'event_espresso' |
|
1083 | + ), |
|
1084 | + $reset |
|
1085 | + ), |
|
1086 | + __FILE__, |
|
1087 | + __FUNCTION__, |
|
1088 | + __LINE__ |
|
1089 | + ); |
|
1090 | + } |
|
1091 | + $return_value = false; |
|
1092 | + } |
|
1093 | + } elseif ($show_all_notices) { |
|
1094 | + // oops! that session var does not exist! |
|
1095 | + EE_Error::add_error( |
|
1096 | + sprintf( |
|
1097 | + __( |
|
1098 | + 'The session item provided, %s, is invalid or does not exist.', |
|
1099 | + 'event_espresso' |
|
1100 | + ), |
|
1101 | + $reset |
|
1102 | + ), |
|
1103 | + __FILE__, |
|
1104 | + __FUNCTION__, |
|
1105 | + __LINE__ |
|
1106 | + ); |
|
1107 | + $return_value = false; |
|
1108 | + } |
|
1109 | + } // end of foreach |
|
1110 | + return $return_value; |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * wp_loaded |
|
1116 | + * |
|
1117 | + * @access public |
|
1118 | + * @throws EE_Error |
|
1119 | + * @throws InvalidDataTypeException |
|
1120 | + * @throws InvalidInterfaceException |
|
1121 | + * @throws InvalidArgumentException |
|
1122 | + */ |
|
1123 | + public function wp_loaded() |
|
1124 | + { |
|
1125 | + if ($this->request->requestParamIsSet('clear_session')) { |
|
1126 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
1127 | + } |
|
1128 | + } |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * Used to reset the entire object (for tests). |
|
1133 | + * |
|
1134 | + * @since 4.3.0 |
|
1135 | + * @throws EE_Error |
|
1136 | + * @throws InvalidDataTypeException |
|
1137 | + * @throws InvalidInterfaceException |
|
1138 | + * @throws InvalidArgumentException |
|
1139 | + */ |
|
1140 | + public function reset_instance() |
|
1141 | + { |
|
1142 | + $this->clear_session(); |
|
1143 | + self::$_instance = null; |
|
1144 | + } |
|
1145 | + |
|
1146 | + |
|
1147 | + public function configure_garbage_collection_filters() |
|
1148 | + { |
|
1149 | + // run old filter we had for controlling session cleanup |
|
1150 | + $expired_session_transient_delete_query_limit = absint( |
|
1151 | + apply_filters( |
|
1152 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1153 | + 50 |
|
1154 | + ) |
|
1155 | + ); |
|
1156 | + // is there a value? or one that is different than the default 50 records? |
|
1157 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
1158 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1159 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1160 | + } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
1161 | + // or use that for the new transient cleanup query limit |
|
1162 | + add_filter( |
|
1163 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1164 | + function () use ($expired_session_transient_delete_query_limit) { |
|
1165 | + return $expired_session_transient_delete_query_limit; |
|
1166 | + } |
|
1167 | + ); |
|
1168 | + } |
|
1169 | + } |
|
1170 | + |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
1174 | + * @param $data1 |
|
1175 | + * @return string |
|
1176 | + */ |
|
1177 | + private function find_serialize_error($data1) |
|
1178 | + { |
|
1179 | + $error = '<pre>'; |
|
1180 | + $data2 = preg_replace_callback( |
|
1181 | + '!s:(\d+):"(.*?)";!', |
|
1182 | + function ($match) { |
|
1183 | + return ($match[1] === strlen($match[2])) |
|
1184 | + ? $match[0] |
|
1185 | + : 's:' |
|
1186 | + . strlen($match[2]) |
|
1187 | + . ':"' |
|
1188 | + . $match[2] |
|
1189 | + . '";'; |
|
1190 | + }, |
|
1191 | + $data1 |
|
1192 | + ); |
|
1193 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1194 | + $error .= $data1 . PHP_EOL; |
|
1195 | + $error .= $data2 . PHP_EOL; |
|
1196 | + for ($i = 0; $i < $max; $i++) { |
|
1197 | + if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1198 | + $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1199 | + $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1200 | + $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1201 | + $start = ($i - 20); |
|
1202 | + $start = ($start < 0) ? 0 : $start; |
|
1203 | + $length = 40; |
|
1204 | + $point = $max - $i; |
|
1205 | + if ($point < 20) { |
|
1206 | + $rlength = 1; |
|
1207 | + $rpoint = -$point; |
|
1208 | + } else { |
|
1209 | + $rpoint = $length - 20; |
|
1210 | + $rlength = 1; |
|
1211 | + } |
|
1212 | + $error .= "\t-> Section Data1 = "; |
|
1213 | + $error .= substr_replace( |
|
1214 | + substr($data1, $start, $length), |
|
1215 | + "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1216 | + $rpoint, |
|
1217 | + $rlength |
|
1218 | + ); |
|
1219 | + $error .= PHP_EOL; |
|
1220 | + $error .= "\t-> Section Data2 = "; |
|
1221 | + $error .= substr_replace( |
|
1222 | + substr($data2, $start, $length), |
|
1223 | + "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1224 | + $rpoint, |
|
1225 | + $rlength |
|
1226 | + ); |
|
1227 | + $error .= PHP_EOL; |
|
1228 | + } |
|
1229 | + } |
|
1230 | + $error .= '</pre>'; |
|
1231 | + return $error; |
|
1232 | + } |
|
1233 | + |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * Saves an array of settings used for configuring aspects of session behaviour |
|
1237 | + * |
|
1238 | + * @param array $updated_settings |
|
1239 | + */ |
|
1240 | + private function updateSessionSettings(array $updated_settings = array()) |
|
1241 | + { |
|
1242 | + // add existing settings, but only if not included in incoming $updated_settings array |
|
1243 | + $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
1244 | + update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
1245 | + } |
|
1246 | + |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * garbage_collection |
|
1250 | + */ |
|
1251 | + public function garbageCollection() |
|
1252 | + { |
|
1253 | + // only perform during regular requests if last garbage collection was over an hour ago |
|
1254 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1255 | + $this->_last_gc = time(); |
|
1256 | + $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
1257 | + /** @type WPDB $wpdb */ |
|
1258 | + global $wpdb; |
|
1259 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
1260 | + $expired_session_transient_delete_query_limit = absint( |
|
1261 | + apply_filters( |
|
1262 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1263 | + 50 |
|
1264 | + ) |
|
1265 | + ); |
|
1266 | + // non-zero LIMIT means take out the trash |
|
1267 | + if ($expired_session_transient_delete_query_limit) { |
|
1268 | + $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
1269 | + $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
1270 | + // since transient expiration timestamps are set in the future, we can compare against NOW |
|
1271 | + // but we only want to pick up any trash that's been around for more than a day |
|
1272 | + $expiration = time() - DAY_IN_SECONDS; |
|
1273 | + $SQL = " |
|
1274 | 1274 | SELECT option_name |
1275 | 1275 | FROM {$wpdb->options} |
1276 | 1276 | WHERE |
@@ -1279,17 +1279,17 @@ discard block |
||
1279 | 1279 | AND option_value < {$expiration} |
1280 | 1280 | LIMIT {$expired_session_transient_delete_query_limit} |
1281 | 1281 | "; |
1282 | - // produces something like: |
|
1283 | - // SELECT option_name FROM wp_options |
|
1284 | - // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
1285 | - // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
1286 | - // AND option_value < 1508368198 LIMIT 50 |
|
1287 | - $expired_sessions = $wpdb->get_col($SQL); |
|
1288 | - // valid results? |
|
1289 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1290 | - $this->cache_storage->deleteMany($expired_sessions, true); |
|
1291 | - } |
|
1292 | - } |
|
1293 | - } |
|
1294 | - } |
|
1282 | + // produces something like: |
|
1283 | + // SELECT option_name FROM wp_options |
|
1284 | + // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
1285 | + // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
1286 | + // AND option_value < 1508368198 LIMIT 50 |
|
1287 | + $expired_sessions = $wpdb->get_col($SQL); |
|
1288 | + // valid results? |
|
1289 | + if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1290 | + $this->cache_storage->deleteMany($expired_sessions, true); |
|
1291 | + } |
|
1292 | + } |
|
1293 | + } |
|
1294 | + } |
|
1295 | 1295 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.001'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.001'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |